debian-mirror-gitlab/app/assets/javascripts/monitoring/components/charts/heatmap.vue

79 lines
1.8 KiB
Vue
Raw Normal View History

2019-12-26 22:10:19 +05:30
<script>
2020-03-13 15:44:24 +05:30
import { GlResizeObserverDirective } from '@gitlab/ui';
2019-12-26 22:10:19 +05:30
import { GlHeatmap } from '@gitlab/ui/dist/charts';
import dateformat from 'dateformat';
import { graphDataValidatorForValues } from '../../utils';
export default {
components: {
GlHeatmap,
},
2020-03-13 15:44:24 +05:30
directives: {
GlResizeObserverDirective,
},
2019-12-26 22:10:19 +05:30
props: {
graphData: {
type: Object,
required: true,
validator: graphDataValidatorForValues.bind(null, false),
},
2020-03-13 15:44:24 +05:30
},
data() {
return {
width: 0,
};
2019-12-26 22:10:19 +05:30
},
computed: {
chartData() {
2020-01-01 13:55:28 +05:30
return this.metrics.result.reduce(
2019-12-26 22:10:19 +05:30
(acc, result, i) => [...acc, ...result.values.map((value, j) => [i, j, value[1]])],
[],
);
},
xAxisName() {
return this.graphData.x_label || '';
},
yAxisName() {
return this.graphData.y_label || '';
},
xAxisLabels() {
2020-01-01 13:55:28 +05:30
return this.metrics.result.map(res => Object.values(res.metric)[0]);
2019-12-26 22:10:19 +05:30
},
yAxisLabels() {
return this.result.values.map(val => {
const [yLabel] = val;
return dateformat(new Date(yLabel), 'HH:MM:ss');
});
},
result() {
2020-01-01 13:55:28 +05:30
return this.metrics.result[0];
2019-12-26 22:10:19 +05:30
},
2020-01-01 13:55:28 +05:30
metrics() {
return this.graphData.metrics[0];
2019-12-26 22:10:19 +05:30
},
},
2020-03-13 15:44:24 +05:30
methods: {
onResize() {
if (this.$refs.heatmapChart) return;
const { width } = this.$refs.heatmapChart.$el.getBoundingClientRect();
this.width = width;
},
},
2019-12-26 22:10:19 +05:30
};
</script>
<template>
2020-04-08 14:13:33 +05:30
<div v-gl-resize-observer-directive="onResize" class="col-12 col-lg-6">
2020-03-13 15:44:24 +05:30
<gl-heatmap
ref="heatmapChart"
v-bind="$attrs"
:data-series="chartData"
:x-axis-name="xAxisName"
:y-axis-name="yAxisName"
:x-axis-labels="xAxisLabels"
:y-axis-labels="yAxisLabels"
:width="width"
/>
2019-12-26 22:10:19 +05:30
</div>
</template>