Commit 2d0cf663 authored by Fatih Acet's avatar Fatih Acet

Merge branch 'jivanvl-support-column-charts' into 'master'

Add support for column charts

See merge request gitlab-org/gitlab!23903
parents a329f535 54e1d5db
<script> <script>
import { GlResizeObserverDirective } from '@gitlab/ui';
import { GlColumnChart } from '@gitlab/ui/dist/charts'; import { GlColumnChart } from '@gitlab/ui/dist/charts';
import { debounceByAnimationFrame } from '~/lib/utils/common_utils';
import { getSvgIconPathContent } from '~/lib/utils/icon_utils'; import { getSvgIconPathContent } from '~/lib/utils/icon_utils';
import { chartHeight } from '../../constants'; import { chartHeight } from '../../constants';
import { makeDataSeries } from '~/helpers/monitor_helper'; import { makeDataSeries } from '~/helpers/monitor_helper';
...@@ -10,24 +10,21 @@ export default { ...@@ -10,24 +10,21 @@ export default {
components: { components: {
GlColumnChart, GlColumnChart,
}, },
inheritAttrs: false, directives: {
GlResizeObserverDirective,
},
props: { props: {
graphData: { graphData: {
type: Object, type: Object,
required: true, required: true,
validator: graphDataValidatorForValues.bind(null, false), validator: graphDataValidatorForValues.bind(null, false),
}, },
containerWidth: {
type: Number,
required: true,
},
}, },
data() { data() {
return { return {
width: 0, width: 0,
height: chartHeight, height: chartHeight,
svgs: {}, svgs: {},
debouncedResizeCallback: {},
}; };
}, },
computed: { computed: {
...@@ -68,15 +65,7 @@ export default { ...@@ -68,15 +65,7 @@ export default {
}; };
}, },
}, },
watch: {
containerWidth: 'onResize',
},
beforeDestroy() {
window.removeEventListener('resize', this.debouncedResizeCallback);
},
created() { created() {
this.debouncedResizeCallback = debounceByAnimationFrame(this.onResize);
window.addEventListener('resize', this.debouncedResizeCallback);
this.setSvg('scroll-handle'); this.setSvg('scroll-handle');
}, },
methods: { methods: {
...@@ -84,6 +73,7 @@ export default { ...@@ -84,6 +73,7 @@ export default {
return `${query.label}`; return `${query.label}`;
}, },
onResize() { onResize() {
if (!this.$refs.columnChart) return;
const { width } = this.$refs.columnChart.$el.getBoundingClientRect(); const { width } = this.$refs.columnChart.$el.getBoundingClientRect();
this.width = width; this.width = width;
}, },
...@@ -100,7 +90,7 @@ export default { ...@@ -100,7 +90,7 @@ export default {
}; };
</script> </script>
<template> <template>
<div class="prometheus-graph"> <div v-gl-resize-observer-directive="onResize" class="prometheus-graph">
<div class="prometheus-graph-header"> <div class="prometheus-graph-header">
<h5 ref="graphTitle" class="prometheus-graph-title">{{ graphData.title }}</h5> <h5 ref="graphTitle" class="prometheus-graph-title">{{ graphData.title }}</h5>
<div ref="graphWidgets" class="prometheus-graph-widgets"><slot></slot></div> <div ref="graphWidgets" class="prometheus-graph-widgets"><slot></slot></div>
......
...@@ -14,6 +14,7 @@ import MonitorTimeSeriesChart from './charts/time_series.vue'; ...@@ -14,6 +14,7 @@ import MonitorTimeSeriesChart from './charts/time_series.vue';
import MonitorAnomalyChart from './charts/anomaly.vue'; import MonitorAnomalyChart from './charts/anomaly.vue';
import MonitorSingleStatChart from './charts/single_stat.vue'; import MonitorSingleStatChart from './charts/single_stat.vue';
import MonitorHeatmapChart from './charts/heatmap.vue'; import MonitorHeatmapChart from './charts/heatmap.vue';
import MonitorColumnChart from './charts/column.vue';
import MonitorEmptyChart from './charts/empty_chart.vue'; import MonitorEmptyChart from './charts/empty_chart.vue';
import TrackEventDirective from '~/vue_shared/directives/track_event'; import TrackEventDirective from '~/vue_shared/directives/track_event';
import { downloadCSVOptions, generateLinkToChartOptions } from '../utils'; import { downloadCSVOptions, generateLinkToChartOptions } from '../utils';
...@@ -21,6 +22,7 @@ import { downloadCSVOptions, generateLinkToChartOptions } from '../utils'; ...@@ -21,6 +22,7 @@ import { downloadCSVOptions, generateLinkToChartOptions } from '../utils';
export default { export default {
components: { components: {
MonitorSingleStatChart, MonitorSingleStatChart,
MonitorColumnChart,
MonitorHeatmapChart, MonitorHeatmapChart,
MonitorEmptyChart, MonitorEmptyChart,
Icon, Icon,
...@@ -116,6 +118,10 @@ export default { ...@@ -116,6 +118,10 @@ export default {
:graph-data="graphData" :graph-data="graphData"
:container-width="dashboardWidth" :container-width="dashboardWidth"
/> />
<monitor-column-chart
v-else-if="isPanelType('column') && graphDataHasMetrics"
:graph-data="graphData"
/>
<component <component
:is="monitorChartComponent" :is="monitorChartComponent"
v-else-if="graphDataHasMetrics" v-else-if="graphDataHasMetrics"
......
---
title: Add support for column charts
merge_request: 23903
author:
type: changed
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment