Commit 8894e27c authored by Anshul Riyal's avatar Anshul Riyal

Refactored time series chart responsiveness

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/81454
parent 6172b14a
<script> <script>
import { GlLink, GlTooltip, GlResizeObserverDirective, GlIcon } from '@gitlab/ui'; import { GlLink, GlTooltip, GlIcon } from '@gitlab/ui';
import { GlAreaChart, GlLineChart, GlChartSeriesLabel } from '@gitlab/ui/dist/charts'; import { GlAreaChart, GlLineChart, GlChartSeriesLabel } from '@gitlab/ui/dist/charts';
import { isEmpty, omit, throttle } from 'lodash'; import { isEmpty, omit, throttle } from 'lodash';
import { makeDataSeries } from '~/helpers/monitor_helper'; import { makeDataSeries } from '~/helpers/monitor_helper';
...@@ -28,9 +28,6 @@ export default { ...@@ -28,9 +28,6 @@ export default {
GlLink, GlLink,
GlIcon, GlIcon,
}, },
directives: {
GlResizeObserverDirective,
},
inheritAttrs: false, inheritAttrs: false,
props: { props: {
graphData: { graphData: {
...@@ -366,64 +363,58 @@ export default { ...@@ -366,64 +363,58 @@ export default {
eChart.off('datazoom'); eChart.off('datazoom');
eChart.on('datazoom', this.throttledDatazoom); eChart.on('datazoom', this.throttledDatazoom);
}, },
onResize() {
if (!this.$refs.chart) return;
const { width } = this.$refs.chart.$el.getBoundingClientRect();
this.width = width;
},
}, },
}; };
</script> </script>
<template> <template>
<div v-gl-resize-observer-directive="onResize"> <component
<component :is="glChartComponent"
:is="glChartComponent" ref="chart"
ref="chart" v-bind="$attrs"
v-bind="$attrs" :responsive="true"
:group-id="groupId" :group-id="groupId"
:data="chartData" :data="chartData"
:option="chartOptions" :option="chartOptions"
:format-tooltip-text="formatTooltipText" :format-tooltip-text="formatTooltipText"
:format-annotations-tooltip-text="formatAnnotationsTooltipText" :format-annotations-tooltip-text="formatAnnotationsTooltipText"
:width="width" :width="width"
:height="height" :height="height"
:legend-layout="legendLayout" :legend-layout="legendLayout"
:legend-average-text="legendAverageText" :legend-average-text="legendAverageText"
:legend-current-text="legendCurrentText" :legend-current-text="legendCurrentText"
:legend-max-text="legendMaxText" :legend-max-text="legendMaxText"
:legend-min-text="legendMinText" :legend-min-text="legendMinText"
@created="onChartCreated" @created="onChartCreated"
@updated="onChartUpdated" @updated="onChartUpdated"
> >
<template #tooltip-title> <template #tooltip-title>
<template v-if="tooltip.type === 'deployments'"> <template v-if="tooltip.type === 'deployments'">
{{ __('Deployed') }} {{ __('Deployed') }}
</template>
<div v-else class="text-nowrap">
{{ tooltip.title }}
</div>
</template> </template>
<template #tooltip-content> <div v-else class="text-nowrap">
<div v-if="tooltip.type === 'deployments'" class="d-flex align-items-center"> {{ tooltip.title }}
<gl-icon name="commit" class="mr-2" /> </div>
<gl-link :href="tooltip.commitUrl">{{ tooltip.sha }}</gl-link> </template>
</div> <template #tooltip-content>
<template v-else> <div v-if="tooltip.type === 'deployments'" class="d-flex align-items-center">
<div <gl-icon name="commit" class="mr-2" />
v-for="(content, key) in tooltip.content" <gl-link :href="tooltip.commitUrl">{{ tooltip.sha }}</gl-link>
:key="key" </div>
class="d-flex justify-content-between" <template v-else>
> <div
<gl-chart-series-label :color="isMultiSeries ? content.color : ''"> v-for="(content, key) in tooltip.content"
{{ content.name }} :key="key"
</gl-chart-series-label> class="d-flex justify-content-between"
<div class="gl-ml-7"> >
{{ content.value }} <gl-chart-series-label :color="isMultiSeries ? content.color : ''">
</div> {{ content.name }}
</gl-chart-series-label>
<div class="gl-ml-7">
{{ content.value }}
</div> </div>
</template> </div>
</template> </template>
</component> </template>
</div> </component>
</template> </template>
...@@ -335,21 +335,6 @@ describe('Time series component', () => { ...@@ -335,21 +335,6 @@ describe('Time series component', () => {
expect(formattedTooltipData.content).toBe(annotationsMetadata.tooltipData.content); expect(formattedTooltipData.content).toBe(annotationsMetadata.tooltipData.content);
}); });
}); });
describe('onResize', () => {
const mockWidth = 233;
beforeEach(() => {
jest.spyOn(Element.prototype, 'getBoundingClientRect').mockImplementation(() => ({
width: mockWidth,
}));
wrapper.vm.onResize();
});
it('sets area chart width', () => {
expect(wrapper.vm.width).toBe(mockWidth);
});
});
}); });
describe('computed', () => { describe('computed', () => {
......
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