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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

88 lines
1.9 KiB
Vue
Raw Normal View History

2020-04-22 19:07:51 +05:30
<script>
import { GlBarChart } from '@gitlab/ui/dist/charts';
import { getSvgIconPathContent } from '~/lib/utils/icon_utils';
import { chartHeight } from '../../constants';
import { barChartsDataParser, graphDataValidatorForValues } from '../../utils';
export default {
components: {
GlBarChart,
},
props: {
graphData: {
type: Object,
required: true,
validator: graphDataValidatorForValues.bind(null, false),
},
},
data() {
return {
width: 0,
height: chartHeight,
svgs: {},
};
},
computed: {
chartData() {
return barChartsDataParser(this.graphData.metrics);
},
chartOptions() {
return {
dataZoom: [this.dataZoomConfig],
};
},
xAxisTitle() {
const { xLabel = '' } = this.graphData;
return xLabel;
},
yAxisTitle() {
2022-06-21 17:19:12 +05:30
const { y_label: yLabel = '' } = this.graphData;
return yLabel;
2020-04-22 19:07:51 +05:30
},
xAxisType() {
2022-06-21 17:19:12 +05:30
const { x_type: xType = 'value' } = this.graphData;
return xType;
2020-04-22 19:07:51 +05:30
},
dataZoomConfig() {
const handleIcon = this.svgs['scroll-handle'];
return handleIcon ? { handleIcon } : {};
},
},
created() {
this.setSvg('scroll-handle');
},
methods: {
formatLegendLabel(query) {
return query.label;
},
setSvg(name) {
getSvgIconPathContent(name)
2021-03-08 18:12:59 +05:30
.then((path) => {
2020-04-22 19:07:51 +05:30
if (path) {
this.$set(this.svgs, name, `path://${path}`);
}
})
2021-03-08 18:12:59 +05:30
.catch((e) => {
2020-04-22 19:07:51 +05:30
// eslint-disable-next-line no-console, @gitlab/require-i18n-strings
console.error('SVG could not be rendered correctly: ', e);
});
},
},
};
</script>
<template>
2022-05-07 20:08:51 +05:30
<gl-bar-chart
ref="barChart"
v-bind="$attrs"
:responsive="true"
:data="chartData"
:option="chartOptions"
:width="width"
:height="height"
:x-axis-title="xAxisTitle"
:y-axis-title="yAxisTitle"
:x-axis-type="xAxisType"
/>
2020-04-22 19:07:51 +05:30
</template>