Commit 522b3056 authored by Simon Knox's avatar Simon Knox

Fix occasionally missing burndown charts

Should also fix flaky feature spec. Sometimes both charts
were ending up with 0 width calculated. Not entirely sure
of reason but not setting the width at all seems like the
appropriate solution.

Changelog: fixed
EE: true
parent b7a71ef2
<script> <script>
import { GlResizeObserverDirective as GlResizeObserver } from '@gitlab/ui';
import { GlLineChart } from '@gitlab/ui/dist/charts'; import { GlLineChart } from '@gitlab/ui/dist/charts';
import dateFormat from 'dateformat'; import dateFormat from 'dateformat';
import { merge } from 'lodash'; import { merge } from 'lodash';
import { __, n__, s__, sprintf } from '~/locale'; import { __, n__, s__, sprintf } from '~/locale';
import ResizableChartContainer from '~/vue_shared/components/resizable_chart/resizable_chart_container.vue';
import commonChartOptions from './common_chart_options'; import commonChartOptions from './common_chart_options';
export default { export default {
directives: {
GlResizeObserver,
},
components: { components: {
GlLineChart, GlLineChart,
ResizableChartContainer,
}, },
props: { props: {
startDate: { startDate: {
...@@ -106,6 +108,12 @@ export default { ...@@ -106,6 +108,12 @@ export default {
}, },
}, },
methods: { methods: {
setChart(chart) {
this.chart = chart;
},
onResize() {
this.chart?.resize();
},
formatTooltipText(params) { formatTooltipText(params) {
const [seriesData] = params.seriesData; const [seriesData] = params.seriesData;
if (!seriesData) { if (!seriesData) {
...@@ -131,18 +139,18 @@ export default { ...@@ -131,18 +139,18 @@ export default {
<div v-if="showTitle" class="burndown-header d-flex align-items-center"> <div v-if="showTitle" class="burndown-header d-flex align-items-center">
<h3>{{ __('Burndown chart') }}</h3> <h3>{{ __('Burndown chart') }}</h3>
</div> </div>
<resizable-chart-container v-if="!loading" class="burndown-chart js-burndown-chart">
<gl-line-chart <gl-line-chart
slot-scope="{ width }" v-if="!loading"
:width="width" v-gl-resize-observer="onResize"
class="burndown-chart js-burndown-chart"
:data="dataSeries" :data="dataSeries"
:option="options" :option="options"
:format-tooltip-text="formatTooltipText" :format-tooltip-text="formatTooltipText"
:include-legend-avg-max="false" :include-legend-avg-max="false"
@created="setChart"
> >
<template slot="tooltip-title">{{ tooltip.title }}</template> <template slot="tooltip-title">{{ tooltip.title }}</template>
<template slot="tooltip-content">{{ tooltip.content }}</template> <template slot="tooltip-content">{{ tooltip.content }}</template>
</gl-line-chart> </gl-line-chart>
</resizable-chart-container>
</div> </div>
</template> </template>
<script> <script>
import { GlResizeObserverDirective as GlResizeObserver } from '@gitlab/ui';
import { GlLineChart } from '@gitlab/ui/dist/charts'; import { GlLineChart } from '@gitlab/ui/dist/charts';
import dateFormat from 'dateformat'; import dateFormat from 'dateformat';
import { merge } from 'lodash'; import { merge } from 'lodash';
import { __, n__, sprintf } from '~/locale'; import { __, n__, sprintf } from '~/locale';
import ResizableChartContainer from '~/vue_shared/components/resizable_chart/resizable_chart_container.vue';
import commonChartOptions from './common_chart_options'; import commonChartOptions from './common_chart_options';
export default { export default {
directives: {
GlResizeObserver,
},
components: { components: {
GlLineChart, GlLineChart,
ResizableChartContainer,
}, },
props: { props: {
startDate: { startDate: {
...@@ -83,7 +85,14 @@ export default { ...@@ -83,7 +85,14 @@ export default {
}); });
}, },
}, },
methods: { methods: {
setChart(chart) {
this.chart = chart;
},
onResize() {
this.chart?.resize();
},
// transform the object to a chart-friendly array of date + value // transform the object to a chart-friendly array of date + value
transform(key) { transform(key) {
return this.burnupData.map((val) => [val.date, val[key]]); return this.burnupData.map((val) => [val.date, val[key]]);
...@@ -119,14 +128,15 @@ export default { ...@@ -119,14 +128,15 @@ export default {
<div class="burndown-header d-flex align-items-center"> <div class="burndown-header d-flex align-items-center">
<h3>{{ __('Burnup chart') }}</h3> <h3>{{ __('Burnup chart') }}</h3>
</div> </div>
<resizable-chart-container v-if="!loading" class="js-burnup-chart">
<gl-line-chart <gl-line-chart
slot-scope="{ width }" v-if="!loading"
:width="width" v-gl-resize-observer="onResize"
class="js-burnup-chart"
:data="dataSeries" :data="dataSeries"
:option="options" :option="options"
:format-tooltip-text="formatTooltipText" :format-tooltip-text="formatTooltipText"
:include-legend-avg-max="false" :include-legend-avg-max="false"
@created="setChart"
> >
<template slot="tooltip-title">{{ tooltip.title }}</template> <template slot="tooltip-title">{{ tooltip.title }}</template>
<template slot="tooltip-content"> <template slot="tooltip-content">
...@@ -134,6 +144,5 @@ export default { ...@@ -134,6 +144,5 @@ export default {
<div>{{ tooltip.completed }}</div> <div>{{ tooltip.completed }}</div>
</template> </template>
</gl-line-chart> </gl-line-chart>
</resizable-chart-container>
</div> </div>
</template> </template>
---
title: Fix occasionally invisible burndown charts
merge_request: 61335
author:
type: fixed
import { GlLineChart } from '@gitlab/ui/dist/charts'; import { GlLineChart } from '@gitlab/ui/dist/charts';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import BurndownChart from 'ee/burndown_chart/components/burndown_chart.vue'; import BurndownChart from 'ee/burndown_chart/components/burndown_chart.vue';
import ResizableChartContainer from '~/vue_shared/components/resizable_chart/resizable_chart_container.vue';
describe('burndown_chart', () => { describe('burndown_chart', () => {
let wrapper; let wrapper;
...@@ -21,9 +20,6 @@ describe('burndown_chart', () => { ...@@ -21,9 +20,6 @@ describe('burndown_chart', () => {
...defaultProps, ...defaultProps,
...props, ...props,
}, },
stubs: {
ResizableChartContainer,
},
}); });
}; };
......
import { GlLineChart } from '@gitlab/ui/dist/charts'; import { GlLineChart } from '@gitlab/ui/dist/charts';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import BurnupChart from 'ee/burndown_chart/components/burnup_chart.vue'; import BurnupChart from 'ee/burndown_chart/components/burnup_chart.vue';
import ResizableChartContainer from '~/vue_shared/components/resizable_chart/resizable_chart_container.vue';
import { day1, day2, day3 } from '../mock_data'; import { day1, day2, day3 } from '../mock_data';
describe('Burnup chart', () => { describe('Burnup chart', () => {
...@@ -20,9 +19,6 @@ describe('Burnup chart', () => { ...@@ -20,9 +19,6 @@ describe('Burnup chart', () => {
...defaultProps, ...defaultProps,
...props, ...props,
}, },
stubs: {
ResizableChartContainer,
},
}); });
}; };
......
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