All files / ee/app/assets/javascripts/burndown_chart/components burndown_chart.vue

60.61% Statements 20/33
43.75% Branches 7/16
50% Functions 5/10
60.61% Lines 20/33

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159  7x 7x 7x   7x 7x                                                                                         8x                       7x 7x 7x           7x             7x 5x 10x 5x 5x 5x   5x                       7x     7x                                                                           45x                                        
<script>
import { GlResizeObserverDirective as GlResizeObserver } from '@gitlab/ui';
import { GlLineChart } from '@gitlab/ui/dist/charts';
import dateFormat from 'dateformat';
import { merge } from 'lodash';
import { __, n__, s__, sprintf } from '~/locale';
import commonChartOptions from './common_chart_options';
 
export default {
  directives: {
    GlResizeObserver,
  },
  components: {
    GlLineChart,
  },
  props: {
    startDate: {
      type: String,
      required: true,
    },
    dueDate: {
      type: String,
      required: true,
    },
    openIssuesCount: {
      type: Array,
      required: false,
      default: () => [],
    },
    openIssuesWeight: {
      type: Array,
      required: false,
      default: () => [],
    },
    issuesSelected: {
      type: Boolean,
      required: false,
      default: true,
    },
    showTitle: {
      type: Boolean,
      required: false,
      default: true,
    },
    loading: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  data() {
    return {
      tooltip: {
        title: '',
        content: '',
      },
    };
  },
  computed: {
    dataSeries() {
      let name;
      let data;
 
E      if (this.issuesSelected) {
        name = s__('BurndownChartLabel|Open issues');
        data = this.openIssuesCount;
      } else {
        name = s__('BurndownChartLabel|Open issue weight');
        data = this.openIssuesWeight;
      }
 
      const series = [
        {
          name,
          data,
        },
      ];
 
      if (data.length > 0) {
        const zeroStart = [this.startDate, 0];
        const firstNonZero = data.find((dataObj) => dataObj[1] !== 0) || zeroStart;
        const idealStart = [this.startDate, firstNonZero[1]];
        const idealEnd = [this.dueDate, 0];
        const idealData = [idealStart, idealEnd];
 
        series.push({
          name: __('Guideline'),
          data: idealData,
          silent: true,
          symbolSize: 0,
          lineStyle: {
            color: '#ddd',
            type: 'dashed',
          },
        });
      }
 
      return series;
    },
    options() {
      return merge({}, commonChartOptions, {
        xAxis: {
          min: this.startDate,
          max: this.dueDate,
        },
        yAxis: {
          name: this.issuesSelected ? __('Total issues') : __('Total weight'),
        },
      });
    },
  },
  methods: {
    setChart(chart) {
      this.chart = chart;
    },
    onResize() {
      this.chart?.resize();
    },
    formatTooltipText(params) {
      const [seriesData] = params.seriesData;
      if (!seriesData) {
        return;
      }
 
      this.tooltip.title = dateFormat(params.value, 'dd mmm yyyy');
 
      if (this.issuesSelected) {
        this.tooltip.content = n__('%d open issue', '%d open issues', seriesData.value[1]);
      } else {
        this.tooltip.content = sprintf(__('%{total} open issue weight'), {
          total: seriesData.value[1],
        });
      }
    },
  },
};
</script>
 
<template>
  <div data-qa-selector="burndown_chart">
    <div v-if="showTitle" class="burndown-header d-flex align-items-center">
      <h3>{{ __('Burndown chart') }}</h3>
    </div>
    <gl-line-chart
      v-if="!loading"
      v-gl-resize-observer="onResize"
      class="burndown-chart js-burndown-chart"
      :data="dataSeries"
      :option="options"
      :format-tooltip-text="formatTooltipText"
      :include-legend-avg-max="false"
      @created="setChart"
    >
      <template #tooltip-title>{{ tooltip.title }}</template>
      <template #tooltip-content>{{ tooltip.content }}</template>
    </gl-line-chart>
  </div>
</template>