Commit 13d202a2 authored by wortschi's avatar wortschi

Improve data zoom on contribution analytics

- This adds a data-based datazoom configuration, i.e., the more items
we have, the smaller the shown frame should be.

Changelog: added
EE: true
parent 15708400
...@@ -50,3 +50,22 @@ export const extractPaginationQueryParameters = (url = '') => { ...@@ -50,3 +50,22 @@ export const extractPaginationQueryParameters = (url = '') => {
page: page?.value || null, page: page?.value || null,
}; };
}; };
export const getDataZoomOption = ({
totalItems = 0,
maxItemsPerPage = 40,
dataZoom = [{ type: 'slider', bottom: 10, start: 0 }],
}) => {
if (totalItems <= maxItemsPerPage) {
return {};
}
const intervalEnd = Math.ceil((maxItemsPerPage / totalItems) * 100);
return dataZoom.map((item) => {
return {
...item,
end: intervalEnd,
};
});
};
<script> <script>
import { GlResizeObserverDirective } from '@gitlab/ui'; import { GlResizeObserverDirective } from '@gitlab/ui';
import { GlColumnChart } from '@gitlab/ui/dist/charts'; import { GlColumnChart } from '@gitlab/ui/dist/charts';
import { getDataZoomOption } from '~/analytics/shared/utils';
import { getSvgIconPathContent } from '~/lib/utils/icon_utils'; import { getSvgIconPathContent } from '~/lib/utils/icon_utils';
import { truncateWidth } from '~/lib/utils/text_utility'; import { truncateWidth } from '~/lib/utils/text_utility';
...@@ -42,14 +43,26 @@ export default { ...@@ -42,14 +43,26 @@ export default {
}; };
}, },
computed: { computed: {
dataZoomConfig() { handleIcon() {
const handleIcon = this.svgs['scroll-handle']; return this.svgs['scroll-handle'] ? { handleIcon: this.svgs['scroll-handle'] } : {};
},
dataZoomOption() {
const dataZoom = [
{
type: 'slider',
bottom: 10,
start: 0,
...this.handleIcon,
},
];
return handleIcon ? { handleIcon } : {}; return {
dataZoom: getDataZoomOption({ totalItems: this.chartData.length, dataZoom }),
};
}, },
chartOptions() { chartOptions() {
return { return {
dataZoom: [this.dataZoomConfig], ...this.dataZoomOption,
height: INNER_CHART_HEIGHT, height: INNER_CHART_HEIGHT,
xAxis: { xAxis: {
axisLabel: { axisLabel: {
......
...@@ -2,6 +2,7 @@ import { ...@@ -2,6 +2,7 @@ import {
filterBySearchTerm, filterBySearchTerm,
extractFilterQueryParameters, extractFilterQueryParameters,
extractPaginationQueryParameters, extractPaginationQueryParameters,
getDataZoomOption,
} from '~/analytics/shared/utils'; } from '~/analytics/shared/utils';
import { objectToQuery } from '~/lib/utils/url_utility'; import { objectToQuery } from '~/lib/utils/url_utility';
...@@ -126,3 +127,52 @@ describe('extractPaginationQueryParameters', () => { ...@@ -126,3 +127,52 @@ describe('extractPaginationQueryParameters', () => {
}); });
}); });
}); });
describe('getDataZoomOption', () => {
it('returns an empty object when totalItems <= maxItemsPerPage', () => {
const totalItems = 10;
const maxItemsPerPage = 20;
expect(getDataZoomOption({ totalItems, maxItemsPerPage })).toEqual({});
});
describe('when totalItems > maxItemsPerPage', () => {
const totalItems = 30;
const maxItemsPerPage = 20;
it('properly computes the end interval for the default datazoom config', () => {
const expected = [
{
type: 'slider',
bottom: 10,
start: 0,
end: 67,
},
];
expect(getDataZoomOption({ totalItems, maxItemsPerPage })).toEqual(expected);
});
it('properly computes the end interval for a custom datazoom config', () => {
const dataZoom = [
{ type: 'slider', bottom: 0, start: 0 },
{ type: 'inside', start: 0 },
];
const expected = [
{
type: 'slider',
bottom: 0,
start: 0,
end: 67,
},
{
type: 'inside',
start: 0,
end: 67,
},
];
expect(getDataZoomOption({ totalItems, maxItemsPerPage, dataZoom })).toEqual(expected);
});
});
});
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