2019-09-30 21:07:59 +05:30
|
|
|
<script>
|
2020-03-13 15:44:24 +05:30
|
|
|
import { GlResizeObserverDirective } from '@gitlab/ui';
|
2019-09-30 21:07:59 +05:30
|
|
|
import { GlColumnChart } from '@gitlab/ui/dist/charts';
|
|
|
|
import { getSvgIconPathContent } from '~/lib/utils/icon_utils';
|
|
|
|
import { chartHeight } from '../../constants';
|
|
|
|
import { makeDataSeries } from '~/helpers/monitor_helper';
|
|
|
|
import { graphDataValidatorForValues } from '../../utils';
|
2020-06-23 00:09:42 +05:30
|
|
|
import { getTimeAxisOptions, getYAxisOptions, getChartGrid } from './options';
|
|
|
|
import { timezones } from '../../format_date';
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
GlColumnChart,
|
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
directives: {
|
|
|
|
GlResizeObserverDirective,
|
|
|
|
},
|
2019-09-30 21:07:59 +05:30
|
|
|
props: {
|
|
|
|
graphData: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
validator: graphDataValidatorForValues.bind(null, false),
|
|
|
|
},
|
2020-06-23 00:09:42 +05:30
|
|
|
timezone: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: timezones.LOCAL,
|
|
|
|
},
|
2019-09-30 21:07:59 +05:30
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
width: 0,
|
|
|
|
height: chartHeight,
|
|
|
|
svgs: {},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
chartData() {
|
2020-01-01 13:55:28 +05:30
|
|
|
const queryData = this.graphData.metrics.reduce((acc, query) => {
|
|
|
|
const series = makeDataSeries(query.result || [], {
|
2019-09-30 21:07:59 +05:30
|
|
|
name: this.formatLegendLabel(query),
|
|
|
|
});
|
|
|
|
|
|
|
|
return acc.concat(series);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return {
|
|
|
|
values: queryData[0].data,
|
|
|
|
};
|
|
|
|
},
|
2020-04-08 14:13:33 +05:30
|
|
|
chartOptions() {
|
2020-06-23 00:09:42 +05:30
|
|
|
const xAxis = getTimeAxisOptions({ timezone: this.timezone });
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
const yAxis = {
|
|
|
|
...getYAxisOptions(this.graphData.yAxis),
|
|
|
|
scale: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
grid: getChartGrid(),
|
2020-06-23 00:09:42 +05:30
|
|
|
xAxis,
|
2020-04-08 14:13:33 +05:30
|
|
|
yAxis,
|
2020-06-23 00:09:42 +05:30
|
|
|
dataZoom: [this.dataZoomConfig],
|
2020-04-08 14:13:33 +05:30
|
|
|
};
|
|
|
|
},
|
2019-09-30 21:07:59 +05:30
|
|
|
xAxisTitle() {
|
2020-01-01 13:55:28 +05:30
|
|
|
return this.graphData.metrics[0].result[0].x_label !== undefined
|
|
|
|
? this.graphData.metrics[0].result[0].x_label
|
2019-09-30 21:07:59 +05:30
|
|
|
: '';
|
|
|
|
},
|
|
|
|
yAxisTitle() {
|
2020-04-08 14:13:33 +05:30
|
|
|
return this.chartOptions.yAxis.name;
|
2019-09-30 21:07:59 +05:30
|
|
|
},
|
|
|
|
xAxisType() {
|
|
|
|
return this.graphData.x_type !== undefined ? this.graphData.x_type : 'category';
|
|
|
|
},
|
|
|
|
dataZoomConfig() {
|
|
|
|
const handleIcon = this.svgs['scroll-handle'];
|
|
|
|
|
|
|
|
return handleIcon ? { handleIcon } : {};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.setSvg('scroll-handle');
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
formatLegendLabel(query) {
|
2020-04-22 19:07:51 +05:30
|
|
|
return query.label;
|
2019-09-30 21:07:59 +05:30
|
|
|
},
|
|
|
|
onResize() {
|
2020-03-13 15:44:24 +05:30
|
|
|
if (!this.$refs.columnChart) return;
|
2019-09-30 21:07:59 +05:30
|
|
|
const { width } = this.$refs.columnChart.$el.getBoundingClientRect();
|
|
|
|
this.width = width;
|
|
|
|
},
|
|
|
|
setSvg(name) {
|
|
|
|
getSvgIconPathContent(name)
|
|
|
|
.then(path => {
|
|
|
|
if (path) {
|
|
|
|
this.$set(this.svgs, name, `path://${path}`);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<template>
|
2020-04-08 14:13:33 +05:30
|
|
|
<div v-gl-resize-observer-directive="onResize">
|
2019-09-30 21:07:59 +05:30
|
|
|
<gl-column-chart
|
|
|
|
ref="columnChart"
|
|
|
|
v-bind="$attrs"
|
|
|
|
:data="chartData"
|
|
|
|
:option="chartOptions"
|
|
|
|
:width="width"
|
|
|
|
:height="height"
|
|
|
|
:x-axis-title="xAxisTitle"
|
|
|
|
:y-axis-title="yAxisTitle"
|
|
|
|
:x-axis-type="xAxisType"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</template>
|