Commit 2f5995f5 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo Committed by Jose Ivan Vargas

Update tasks by type stacked column data

Updates the stacked column chart data
for the tasks by type chart
parent 81e87cd5
...@@ -17,10 +17,13 @@ export default { ...@@ -17,10 +17,13 @@ export default {
}, },
}, },
computed: { computed: {
seriesData() { barSeriesData() {
return { return [
full: this.formattedData.keys.map((val, idx) => [val, this.formattedData.values[idx]]), {
}; name: 'full',
data: this.formattedData.keys.map((val, idx) => [val, this.formattedData.values[idx]]),
},
];
}, },
}, },
}; };
...@@ -30,7 +33,7 @@ export default { ...@@ -30,7 +33,7 @@ export default {
<div class="gl-xs-w-full"> <div class="gl-xs-w-full">
<gl-column-chart <gl-column-chart
v-if="formattedData.keys" v-if="formattedData.keys"
:data="seriesData" :bars="barSeriesData"
:x-axis-title="__('Value')" :x-axis-title="__('Value')"
:y-axis-title="__('Number of events')" :y-axis-title="__('Number of events')"
:x-axis-type="'category'" :x-axis-type="'category'"
......
...@@ -35,18 +35,14 @@ export default { ...@@ -35,18 +35,14 @@ export default {
}; };
}, },
computed: { computed: {
chartData() { barChartData() {
const queryData = this.graphData.metrics.reduce((acc, query) => { return this.graphData.metrics.reduce((acc, query) => {
const series = makeDataSeries(query.result || [], { const series = makeDataSeries(query.result || [], {
name: this.formatLegendLabel(query), name: this.formatLegendLabel(query),
}); });
return acc.concat(series); return acc.concat(series);
}, []); }, []);
return {
values: queryData[0].data,
};
}, },
chartOptions() { chartOptions() {
const xAxis = getTimeAxisOptions({ timezone: this.timezone }); const xAxis = getTimeAxisOptions({ timezone: this.timezone });
...@@ -109,7 +105,7 @@ export default { ...@@ -109,7 +105,7 @@ export default {
<gl-column-chart <gl-column-chart
ref="columnChart" ref="columnChart"
v-bind="$attrs" v-bind="$attrs"
:data="chartData" :bars="barChartData"
:option="chartOptions" :option="chartOptions"
:width="width" :width="width"
:height="height" :height="height"
......
...@@ -61,14 +61,16 @@ export default { ...@@ -61,14 +61,16 @@ export default {
}, },
computed: { computed: {
chartData() { chartData() {
return this.graphData.metrics.map(({ result }) => { return this.graphData.metrics
// This needs a fix. Not only metrics[0] should be shown. .map(({ label: name, result }) => {
// See https://gitlab.com/gitlab-org/gitlab/-/issues/220492 // This needs a fix. Not only metrics[0] should be shown.
if (!result || result.length === 0) { // See https://gitlab.com/gitlab-org/gitlab/-/issues/220492
return []; if (!result || result.length === 0) {
} return [];
return result[0].values.map(val => val[1]); }
}); return { name, data: result[0].values.map(val => val[1]) };
})
.slice(0, 1);
}, },
xAxisTitle() { xAxisTitle() {
return this.graphData.x_label !== undefined ? this.graphData.x_label : ''; return this.graphData.x_label !== undefined ? this.graphData.x_label : '';
...@@ -136,7 +138,7 @@ export default { ...@@ -136,7 +138,7 @@ export default {
<gl-stacked-column-chart <gl-stacked-column-chart
ref="chart" ref="chart"
v-bind="$attrs" v-bind="$attrs"
:data="chartData" :bars="chartData"
:option="chartOptions" :option="chartOptions"
:x-axis-title="xAxisTitle" :x-axis-title="xAxisTitle"
:y-axis-title="yAxisTitle" :y-axis-title="yAxisTitle"
...@@ -144,7 +146,6 @@ export default { ...@@ -144,7 +146,6 @@ export default {
:group-by="groupBy" :group-by="groupBy"
:width="width" :width="width"
:height="height" :height="height"
:series-names="seriesNames"
:legend-layout="legendLayout" :legend-layout="legendLayout"
:legend-average-text="legendAverageText" :legend-average-text="legendAverageText"
:legend-current-text="legendCurrentText" :legend-current-text="legendCurrentText"
......
...@@ -5,6 +5,8 @@ import { __ } from '~/locale'; ...@@ -5,6 +5,8 @@ import { __ } from '~/locale';
import CodeCoverage from '../components/code_coverage.vue'; import CodeCoverage from '../components/code_coverage.vue';
import SeriesDataMixin from './series_data_mixin'; import SeriesDataMixin from './series_data_mixin';
const seriesDataToBarData = raw => Object.entries(raw).map(([name, data]) => ({ name, data }));
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
waitForCSSLoaded(() => { waitForCSSLoaded(() => {
const languagesContainer = document.getElementById('js-languages-chart'); const languagesContainer = document.getElementById('js-languages-chart');
...@@ -41,13 +43,13 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -41,13 +43,13 @@ document.addEventListener('DOMContentLoaded', () => {
}, },
computed: { computed: {
seriesData() { seriesData() {
return { full: this.chartData.map(d => [d.label, d.value]) }; return [{ name: 'full', data: this.chartData.map(d => [d.label, d.value]) }];
}, },
}, },
render(h) { render(h) {
return h(GlColumnChart, { return h(GlColumnChart, {
props: { props: {
data: this.seriesData, bars: this.seriesData,
xAxisTitle: __('Used programming language'), xAxisTitle: __('Used programming language'),
yAxisTitle: __('Percentage'), yAxisTitle: __('Percentage'),
xAxisType: 'category', xAxisType: 'category',
...@@ -86,7 +88,7 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -86,7 +88,7 @@ document.addEventListener('DOMContentLoaded', () => {
render(h) { render(h) {
return h(GlColumnChart, { return h(GlColumnChart, {
props: { props: {
data: this.seriesData, bars: seriesDataToBarData(this.seriesData),
xAxisTitle: __('Day of month'), xAxisTitle: __('Day of month'),
yAxisTitle: __('No. of commits'), yAxisTitle: __('No. of commits'),
xAxisType: 'category', xAxisType: 'category',
...@@ -113,13 +115,13 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -113,13 +115,13 @@ document.addEventListener('DOMContentLoaded', () => {
acc.push([key, weekDays[key]]); acc.push([key, weekDays[key]]);
return acc; return acc;
}, []); }, []);
return { full: data }; return [{ name: 'full', data }];
}, },
}, },
render(h) { render(h) {
return h(GlColumnChart, { return h(GlColumnChart, {
props: { props: {
data: this.seriesData, bars: this.seriesData,
xAxisTitle: __('Weekday'), xAxisTitle: __('Weekday'),
yAxisTitle: __('No. of commits'), yAxisTitle: __('No. of commits'),
xAxisType: 'category', xAxisType: 'category',
...@@ -143,7 +145,7 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -143,7 +145,7 @@ document.addEventListener('DOMContentLoaded', () => {
render(h) { render(h) {
return h(GlColumnChart, { return h(GlColumnChart, {
props: { props: {
data: this.seriesData, bars: seriesDataToBarData(this.seriesData),
xAxisTitle: __('Hour (UTC)'), xAxisTitle: __('Hour (UTC)'),
yAxisTitle: __('No. of commits'), yAxisTitle: __('No. of commits'),
xAxisType: 'category', xAxisType: 'category',
......
...@@ -45,9 +45,12 @@ export default { ...@@ -45,9 +45,12 @@ export default {
}, },
data() { data() {
return { return {
timesChartTransformedData: { timesChartTransformedData: [
full: this.mergeLabelsAndValues(this.timesChartData.labels, this.timesChartData.values), {
}, name: 'full',
data: this.mergeLabelsAndValues(this.timesChartData.labels, this.timesChartData.values),
},
],
}; };
}, },
computed: { computed: {
...@@ -128,7 +131,7 @@ export default { ...@@ -128,7 +131,7 @@ export default {
<gl-column-chart <gl-column-chart
:height="$options.chartContainerHeight" :height="$options.chartContainerHeight"
:option="$options.timesChartOptions" :option="$options.timesChartOptions"
:data="timesChartTransformedData" :bars="timesChartTransformedData"
:y-axis-title="__('Minutes')" :y-axis-title="__('Minutes')"
:x-axis-title="__('Commit')" :x-axis-title="__('Commit')"
x-axis-type="category" x-axis-type="category"
......
...@@ -65,7 +65,7 @@ export default { ...@@ -65,7 +65,7 @@ export default {
}; };
}, },
seriesData() { seriesData() {
return { full: this.chartData }; return [{ name: 'full', data: this.chartData }];
}, },
}, },
methods: { methods: {
...@@ -102,7 +102,7 @@ export default { ...@@ -102,7 +102,7 @@ export default {
v-bind="$attrs" v-bind="$attrs"
:width="width" :width="width"
:height="height" :height="height"
:data="seriesData" :bars="seriesData"
:x-axis-title="xAxisTitle" :x-axis-title="xAxisTitle"
:y-axis-title="yAxisTitle" :y-axis-title="yAxisTitle"
x-axis-type="category" x-axis-type="category"
......
...@@ -15,21 +15,16 @@ export default { ...@@ -15,21 +15,16 @@ export default {
type: Array, type: Array,
required: true, required: true,
}, },
seriesNames: {
type: Array,
required: true,
},
}, },
}; };
</script> </script>
<template> <template>
<gl-stacked-column-chart <gl-stacked-column-chart
:data="data" :bars="data"
:group-by="groupBy" :group-by="groupBy"
x-axis-type="category" x-axis-type="category"
y-axis-type="value" y-axis-type="value"
:x-axis-title="__('Date')" :x-axis-title="__('Date')"
:y-axis-title="s__('CycleAnalytics|Number of tasks')" :y-axis-title="s__('CycleAnalytics|Number of tasks')"
:series-names="seriesNames"
/> />
</template> </template>
...@@ -87,7 +87,6 @@ export default { ...@@ -87,7 +87,6 @@ export default {
v-if="hasData" v-if="hasData"
:data="tasksByTypeChartData.data" :data="tasksByTypeChartData.data"
:group-by="tasksByTypeChartData.groupBy" :group-by="tasksByTypeChartData.groupBy"
:series-names="tasksByTypeChartData.seriesNames"
/> />
<gl-alert v-else variant="info" :dismissible="false" class="gl-mt-3"> <gl-alert v-else variant="info" :dismissible="false" class="gl-mt-3">
{{ error }} {{ error }}
......
...@@ -21,5 +21,5 @@ export const tasksByTypeChartData = ({ data = [] } = {}, _, rootState = {}) => { ...@@ -21,5 +21,5 @@ export const tasksByTypeChartData = ({ data = [] } = {}, _, rootState = {}) => {
startDate, startDate,
endDate, endDate,
}) })
: { groupBy: [], data: [], seriesNames: [] }; : { groupBy: [], data: [] };
}; };
...@@ -253,7 +253,6 @@ export const getTasksByTypeData = ({ data = [], startDate = null, endDate = null ...@@ -253,7 +253,6 @@ export const getTasksByTypeData = ({ data = [], startDate = null, endDate = null
return { return {
groupBy: [], groupBy: [],
data: [], data: [],
seriesNames: [],
}; };
} }
...@@ -269,14 +268,19 @@ export const getTasksByTypeData = ({ data = [], startDate = null, endDate = null ...@@ -269,14 +268,19 @@ export const getTasksByTypeData = ({ data = [], startDate = null, endDate = null
const transformed = data.reduce( const transformed = data.reduce(
(acc, curr) => { (acc, curr) => {
const { const {
label: { title }, label: { title: name },
series, series,
} = curr; } = curr;
acc.seriesNames = [...acc.seriesNames, title];
acc.data = [ acc.data = [
...acc.data, ...acc.data,
// adds 0 values for each data point and overrides with data from the series {
flattenTaskByTypeSeries({ ...zeroValuesForEachDataPoint, ...Object.fromEntries(series) }), name,
// adds 0 values for each data point and overrides with data from the series
data: flattenTaskByTypeSeries({
...zeroValuesForEachDataPoint,
...Object.fromEntries(series),
}),
},
]; ];
return acc; return acc;
}, },
......
...@@ -206,7 +206,7 @@ export default { ...@@ -206,7 +206,7 @@ export default {
:chart-data="getColumnChartData(chartKeys.main)" :chart-data="getColumnChartData(chartKeys.main)"
> >
<gl-column-chart <gl-column-chart
:data="{ full: getColumnChartData(chartKeys.main) }" :bars="[{ name: 'full', data: getColumnChartData(chartKeys.main) }]"
:option="getColumnChartOption(chartKeys.main)" :option="getColumnChartOption(chartKeys.main)"
:y-axis-title="__('Merge requests')" :y-axis-title="__('Merge requests')"
:x-axis-title="__('Days')" :x-axis-title="__('Days')"
...@@ -257,7 +257,7 @@ export default { ...@@ -257,7 +257,7 @@ export default {
" "
> >
<gl-column-chart <gl-column-chart
:data="{ full: getColumnChartData(chartKeys.timeBasedHistogram) }" :bars="[{ name: 'full', data: getColumnChartData(chartKeys.timeBasedHistogram) }]"
:option="getColumnChartOption(chartKeys.timeBasedHistogram)" :option="getColumnChartOption(chartKeys.timeBasedHistogram)"
:y-axis-title="s__('ProductivityAnalytics|Merge requests')" :y-axis-title="s__('ProductivityAnalytics|Merge requests')"
:x-axis-title="s__('ProductivityAnalytics|Hours')" :x-axis-title="s__('ProductivityAnalytics|Hours')"
...@@ -283,7 +283,7 @@ export default { ...@@ -283,7 +283,7 @@ export default {
" "
> >
<gl-column-chart <gl-column-chart
:data="{ full: getColumnChartData(chartKeys.commitBasedHistogram) }" :bars="[{ name: 'full', data: getColumnChartData(chartKeys.commitBasedHistogram) }]"
:option="getColumnChartOption(chartKeys.commitBasedHistogram)" :option="getColumnChartOption(chartKeys.commitBasedHistogram)"
:y-axis-title="s__('ProductivityAanalytics|Merge requests')" :y-axis-title="s__('ProductivityAanalytics|Merge requests')"
:x-axis-title="getMetricLabel(chartKeys.commitBasedHistogram)" :x-axis-title="getMetricLabel(chartKeys.commitBasedHistogram)"
......
...@@ -134,7 +134,7 @@ export default { ...@@ -134,7 +134,7 @@ export default {
v-if="loaded && isColumnChart" v-if="loaded && isColumnChart"
v-bind="$attrs" v-bind="$attrs"
:height="$options.height" :height="$options.height"
:data="data.datasets" :bars="data.datasets"
x-axis-type="category" x-axis-type="category"
:x-axis-title="data.xAxisTitle" :x-axis-title="data.xAxisTitle"
:y-axis-title="data.yAxisTitle" :y-axis-title="data.yAxisTitle"
...@@ -145,9 +145,8 @@ export default { ...@@ -145,9 +145,8 @@ export default {
v-else-if="loaded && isStackedColumnChart" v-else-if="loaded && isStackedColumnChart"
v-bind="$attrs" v-bind="$attrs"
:height="$options.height" :height="$options.height"
:data="data.datasets" :bars="data.datasets"
:group-by="data.labels" :group-by="data.labels"
:series-names="data.seriesNames"
x-axis-type="category" x-axis-type="category"
:x-axis-title="data.xAxisTitle" :x-axis-title="data.xAxisTitle"
:y-axis-title="data.yAxisTitle" :y-axis-title="data.yAxisTitle"
......
...@@ -31,10 +31,21 @@ export const transformChartDataForGlCharts = ( ...@@ -31,10 +31,21 @@ export const transformChartDataForGlCharts = (
}; };
switch (type) { switch (type) {
case CHART_TYPES.BAR:
formattedData.datasets = [
{
name: 'all',
data: labels.map((label, i) => [label, datasets[0].data[i]]),
},
];
break;
case CHART_TYPES.STACKED_BAR: case CHART_TYPES.STACKED_BAR:
formattedData.datasets = datasets.map(dataset => dataset.data); formattedData.datasets.push(
formattedData.seriesNames = datasets.map(dataset => dataset.label); ...datasets.map(dataset => ({
name: dataset.label,
data: dataset.data,
})),
);
break; break;
case CHART_TYPES.LINE: case CHART_TYPES.LINE:
formattedData.datasets.push( formattedData.datasets.push(
...@@ -48,7 +59,6 @@ export const transformChartDataForGlCharts = ( ...@@ -48,7 +59,6 @@ export const transformChartDataForGlCharts = (
default: default:
formattedData.datasets = { all: labels.map((label, i) => [label, datasets[0].data[i]]) }; formattedData.datasets = { all: labels.map((label, i) => [label, datasets[0].data[i]]) };
} }
return formattedData; return formattedData;
}; };
......
...@@ -182,7 +182,7 @@ export default { ...@@ -182,7 +182,7 @@ export default {
<gl-column-chart <gl-column-chart
data-qa-selector="issues_analytics_graph" data-qa-selector="issues_analytics_graph"
:data="{ Full: data }" :bars="[{ name: 'Full', data }]"
:option="chartOptions" :option="chartOptions"
:y-axis-title="s__('IssuesAnalytics|Issues opened')" :y-axis-title="s__('IssuesAnalytics|Issues opened')"
:x-axis-title="s__('IssuesAnalytics|Last 12 months') + ' (' + chartDateRange + ')'" :x-axis-title="s__('IssuesAnalytics|Last 12 months') + ' (' + chartDateRange + ')'"
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
exports[`Contribution Analytics Column Chart matches the snapshot 1`] = ` exports[`Contribution Analytics Column Chart matches the snapshot 1`] = `
<div> <div>
<gl-column-chart-stub <gl-column-chart-stub
bars="" bars="[object Object]"
data="[object Object]" data="[object Object]"
height="350" height="350"
lines="" lines=""
......
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
exports[`TasksByTypeChart no data available should render the no data available message 1`] = `"<gl-stacked-column-chart-stub data=\\"\\" bars=\\"\\" lines=\\"\\" secondarydata=\\"\\" option=\\"[object Object]\\" presentation=\\"stacked\\" groupby=\\"\\" xaxistype=\\"category\\" xaxistitle=\\"Date\\" yaxistitle=\\"Number of tasks\\" secondarydatatitle=\\"\\" seriesnames=\\"\\" legendaveragetext=\\"Avg\\" legendmaxtext=\\"Max\\" legendmintext=\\"Min\\" legendcurrenttext=\\"Current\\" legendlayout=\\"inline\\" y-axis-type=\\"value\\"></gl-stacked-column-chart-stub>"`; exports[`TasksByTypeChart no data available should render the no data available message 1`] = `"<gl-stacked-column-chart-stub data=\\"\\" bars=\\"\\" lines=\\"\\" secondarydata=\\"\\" option=\\"[object Object]\\" presentation=\\"stacked\\" groupby=\\"\\" xaxistype=\\"category\\" xaxistitle=\\"Date\\" yaxistitle=\\"Number of tasks\\" secondarydatatitle=\\"\\" seriesnames=\\"\\" legendaveragetext=\\"Avg\\" legendmaxtext=\\"Max\\" legendmintext=\\"Min\\" legendcurrenttext=\\"Current\\" legendlayout=\\"inline\\" y-axis-type=\\"value\\"></gl-stacked-column-chart-stub>"`;
exports[`TasksByTypeChart with data available should render the loading chart 1`] = `"<gl-stacked-column-chart-stub data=\\"0,1,2,5,2,3,2,4,1\\" bars=\\"\\" lines=\\"\\" secondarydata=\\"\\" option=\\"[object Object]\\" presentation=\\"stacked\\" groupby=\\"Group 1,Group 2,Group 3\\" xaxistype=\\"category\\" xaxistitle=\\"Date\\" yaxistitle=\\"Number of tasks\\" secondarydatatitle=\\"\\" seriesnames=\\"Cool label,Normal label\\" legendaveragetext=\\"Avg\\" legendmaxtext=\\"Max\\" legendmintext=\\"Min\\" legendcurrenttext=\\"Current\\" legendlayout=\\"inline\\" y-axis-type=\\"value\\"></gl-stacked-column-chart-stub>"`; exports[`TasksByTypeChart with data available should render the loading chart 1`] = `"<gl-stacked-column-chart-stub data=\\"\\" bars=\\"0,1,2,5,2,3,2,4,1\\" lines=\\"\\" secondarydata=\\"\\" option=\\"[object Object]\\" presentation=\\"stacked\\" groupby=\\"Group 1,Group 2,Group 3\\" xaxistype=\\"category\\" xaxistitle=\\"Date\\" yaxistitle=\\"Number of tasks\\" secondarydatatitle=\\"\\" seriesnames=\\"Cool label,Normal label\\" legendaveragetext=\\"Avg\\" legendmaxtext=\\"Max\\" legendmintext=\\"Min\\" legendcurrenttext=\\"Current\\" legendlayout=\\"inline\\" y-axis-type=\\"value\\"></gl-stacked-column-chart-stub>"`;
...@@ -83,7 +83,7 @@ describe('TypeOfWorkCharts', () => { ...@@ -83,7 +83,7 @@ describe('TypeOfWorkCharts', () => {
beforeEach(() => { beforeEach(() => {
wrapper = createComponent({ wrapper = createComponent({
initialGetters: { initialGetters: {
tasksByTypeChartData: () => ({ groupBy: [], data: [], seriesNames: [] }), tasksByTypeChartData: () => ({ groupBy: [], data: [] }),
}, },
}); });
}); });
......
...@@ -19,7 +19,7 @@ describe('Type of work getters', () => { ...@@ -19,7 +19,7 @@ describe('Type of work getters', () => {
describe('with no data', () => { describe('with no data', () => {
it('returns all required properties', () => { it('returns all required properties', () => {
expect(tasksByTypeChartData()).toEqual({ groupBy: [], data: [], seriesNames: [] }); expect(tasksByTypeChartData()).toEqual({ groupBy: [], data: [] });
}); });
}); });
}); });
......
...@@ -227,10 +227,15 @@ describe('Cycle analytics utils', () => { ...@@ -227,10 +227,15 @@ describe('Cycle analytics utils', () => {
describe('getTasksByTypeData', () => { describe('getTasksByTypeData', () => {
let transformed = {}; let transformed = {};
const groupBy = getDatesInRange(startDate, endDate, toYmd); const groupBy = getDatesInRange(startDate, endDate, toYmd);
// only return the values, drop the date which is the first paramater // only return the values, drop the date which is the first paramater
const extractSeriesValues = ({ series }) => series.map(kv => kv[1]); const extractSeriesValues = ({ label: { title: name }, series }) => {
return {
name,
data: series.map(kv => kv[1]),
};
};
const data = rawTasksByTypeData.map(extractSeriesValues); const data = rawTasksByTypeData.map(extractSeriesValues);
const labels = rawTasksByTypeData.map(d => { const labels = rawTasksByTypeData.map(d => {
...@@ -241,7 +246,7 @@ describe('Cycle analytics utils', () => { ...@@ -241,7 +246,7 @@ describe('Cycle analytics utils', () => {
it('will return blank arrays if given no data', () => { it('will return blank arrays if given no data', () => {
[{ data: [], startDate, endDate }, [], {}].forEach(chartData => { [{ data: [], startDate, endDate }, [], {}].forEach(chartData => {
transformed = getTasksByTypeData(chartData); transformed = getTasksByTypeData(chartData);
['seriesNames', 'data', 'groupBy'].forEach(key => { ['data', 'groupBy'].forEach(key => {
expect(transformed[key]).toEqual([]); expect(transformed[key]).toEqual([]);
}); });
}); });
...@@ -253,17 +258,11 @@ describe('Cycle analytics utils', () => { ...@@ -253,17 +258,11 @@ describe('Cycle analytics utils', () => {
}); });
it('will return an object with the properties needed for the chart', () => { it('will return an object with the properties needed for the chart', () => {
['seriesNames', 'data', 'groupBy'].forEach(key => { ['data', 'groupBy'].forEach(key => {
expect(transformed).toHaveProperty(key); expect(transformed).toHaveProperty(key);
}); });
}); });
describe('seriesNames', () => {
it('returns the names of all the labels in the dataset', () => {
expect(transformed.seriesNames).toEqual(labels);
});
});
describe('groupBy', () => { describe('groupBy', () => {
it('returns the date groupBy as an array', () => { it('returns the date groupBy as an array', () => {
expect(transformed.groupBy).toEqual(groupBy); expect(transformed.groupBy).toEqual(groupBy);
...@@ -289,7 +288,7 @@ describe('Cycle analytics utils', () => { ...@@ -289,7 +288,7 @@ describe('Cycle analytics utils', () => {
it('contains a value for each day in the groupBy', () => { it('contains a value for each day in the groupBy', () => {
transformed.data.forEach(d => { transformed.data.forEach(d => {
expect(d).toHaveLength(transformed.groupBy.length); expect(d.data).toHaveLength(transformed.groupBy.length);
}); });
}); });
}); });
......
...@@ -12,9 +12,12 @@ export const chartInfo = { ...@@ -12,9 +12,12 @@ export const chartInfo = {
export const barChartData = { export const barChartData = {
labels: ['January', 'February'], labels: ['January', 'February'],
datasets: { datasets: [
all: [['January', 1], ['February', 2]], {
}, name: 'all',
data: [['January', 1], ['February', 2]],
},
],
xAxisTitle: 'Months', xAxisTitle: 'Months',
yAxisTitle: 'Issues', yAxisTitle: 'Issues',
}; };
...@@ -37,8 +40,16 @@ export const lineChartData = { ...@@ -37,8 +40,16 @@ export const lineChartData = {
export const stackedBarChartData = { export const stackedBarChartData = {
labels: ['January', 'February'], labels: ['January', 'February'],
datasets: [[1, 2], [1, 2]], datasets: [
seriesNames: ['Series 1', 'Series 2'], {
name: 'Series 1',
data: [1, 2],
},
{
name: 'Series 2',
data: [1, 2],
},
],
xAxisTitle: 'Months', xAxisTitle: 'Months',
yAxisTitle: 'Issues', yAxisTitle: 'Issues',
}; };
......
...@@ -39,22 +39,9 @@ describe('Insights helpers', () => { ...@@ -39,22 +39,9 @@ describe('Insights helpers', () => {
datasets: [{ label: 'Dataset 1', data: [1] }, { label: 'Dataset 2', data: [2] }], datasets: [{ label: 'Dataset 1', data: [1] }, { label: 'Dataset 2', data: [2] }],
}; };
expect(transformChartDataForGlCharts(chart, data).datasets).toEqual([[1], [2]]); expect(transformChartDataForGlCharts(chart, data).datasets).toEqual([
}); { name: 'Dataset 1', data: [1] },
{ name: 'Dataset 2', data: [2] },
it('copies the dataset labels to seriesNames for stacked bar charts', () => {
const chart = {
type: CHART_TYPES.STACKED_BAR,
query: { group_by: 'month', issuable_type: 'issue' },
};
const data = {
labels: ['January', 'February'],
datasets: [{ label: 'Dataset 1', data: [1] }, { label: 'Dataset 2', data: [2] }],
};
expect(transformChartDataForGlCharts(chart, data).seriesNames).toEqual([
'Dataset 1',
'Dataset 2',
]); ]);
}); });
...@@ -74,7 +61,7 @@ describe('Insights helpers', () => { ...@@ -74,7 +61,7 @@ describe('Insights helpers', () => {
]); ]);
}); });
it('creates an object of all containing an array of label / data pairs for bar charts', () => { it('creates an array of objects containing an array of label / data pairs and a name for bar charts', () => {
const chart = { const chart = {
type: CHART_TYPES.BAR, type: CHART_TYPES.BAR,
query: { group_by: 'month', issuable_type: 'issue' }, query: { group_by: 'month', issuable_type: 'issue' },
...@@ -84,9 +71,9 @@ describe('Insights helpers', () => { ...@@ -84,9 +71,9 @@ describe('Insights helpers', () => {
datasets: [{ data: [1, 2] }], datasets: [{ data: [1, 2] }],
}; };
expect(transformChartDataForGlCharts(chart, data).datasets).toEqual({ expect(transformChartDataForGlCharts(chart, data).datasets).toEqual([
all: [['January', 1], ['February', 2]], { name: 'all', data: [['January', 1], ['February', 2]] },
}); ]);
}); });
it('creates an object of all containing an array of label / data pairs for pie charts', () => { it('creates an object of all containing an array of label / data pairs for pie charts', () => {
......
...@@ -107,11 +107,11 @@ describe('Insights mutations', () => { ...@@ -107,11 +107,11 @@ describe('Insights mutations', () => {
}; };
const transformedData = { const transformedData = {
datasets: [[1], [2]], datasets: [{ name: 'Dataset 1', data: [1] }, { name: 'Dataset 2', data: [2] }],
labels: ['January', 'February'], labels: ['January', 'February'],
xAxisTitle: 'Months', xAxisTitle: 'Months',
yAxisTitle: 'Issues', yAxisTitle: 'Issues',
seriesNames: ['Dataset 1', 'Dataset 2'], seriesNames: [],
}; };
beforeEach(() => { beforeEach(() => {
......
...@@ -30,6 +30,7 @@ describe('Column component', () => { ...@@ -30,6 +30,7 @@ describe('Column component', () => {
}, },
metrics: [ metrics: [
{ {
label: 'Mock data',
result: [ result: [
{ {
metric: {}, metric: {},
...@@ -96,7 +97,7 @@ describe('Column component', () => { ...@@ -96,7 +97,7 @@ describe('Column component', () => {
describe('wrapped components', () => { describe('wrapped components', () => {
describe('GitLab UI column chart', () => { describe('GitLab UI column chart', () => {
it('receives data properties needed for proper chart render', () => { it('receives data properties needed for proper chart render', () => {
expect(chartProps('data').values).toEqual(dataValues); expect(chartProps('bars')).toEqual([{ name: 'Mock data', data: dataValues }]);
}); });
it('passes the y axis name correctly', () => { it('passes the y axis name correctly', () => {
......
...@@ -44,19 +44,19 @@ describe('Stacked column chart component', () => { ...@@ -44,19 +44,19 @@ describe('Stacked column chart component', () => {
}); });
it('data should match the graphData y value for each series', () => { it('data should match the graphData y value for each series', () => {
const data = findChart().props('data'); const data = findChart().props('bars');
data.forEach((series, index) => { data.forEach((series, index) => {
const { values } = stackedColumnMockedData.metrics[index].result[0]; const { values } = stackedColumnMockedData.metrics[index].result[0];
expect(series).toEqual(values.map(value => value[1])); expect(series.data).toEqual(values.map(value => value[1]));
}); });
}); });
it('series names should be the same as the graphData metrics labels', () => { it('data should be the same length as the graphData metrics labels', () => {
const seriesNames = findChart().props('seriesNames'); const barDataProp = findChart().props('bars');
expect(seriesNames).toHaveLength(stackedColumnMockedData.metrics.length); expect(barDataProp).toHaveLength(stackedColumnMockedData.metrics.length);
seriesNames.forEach((name, index) => { barDataProp.forEach(({ name }, index) => {
expect(stackedColumnMockedData.metrics[index].label).toBe(name); expect(stackedColumnMockedData.metrics[index].label).toBe(name);
}); });
}); });
......
...@@ -45,7 +45,7 @@ describe('ProjectsPipelinesChartsApp', () => { ...@@ -45,7 +45,7 @@ describe('ProjectsPipelinesChartsApp', () => {
expect(chart.exists()).toBeTruthy(); expect(chart.exists()).toBeTruthy();
expect(chart.props('yAxisTitle')).toBe('Minutes'); expect(chart.props('yAxisTitle')).toBe('Minutes');
expect(chart.props('xAxisTitle')).toBe('Commit'); expect(chart.props('xAxisTitle')).toBe('Commit');
expect(chart.props('data')).toBe(wrapper.vm.timesChartTransformedData); expect(chart.props('bars')).toBe(wrapper.vm.timesChartTransformedData);
expect(chart.props('option')).toBe(wrapper.vm.$options.timesChartOptions); expect(chart.props('option')).toBe(wrapper.vm.$options.timesChartOptions);
}); });
}); });
......
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