@gitlab/ui 56.3.0 → 56.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/components/charts/area/area.js +17 -3
- package/dist/components/charts/bar/bar.js +17 -3
- package/dist/components/charts/chart/chart.js +3 -0
- package/dist/components/charts/column/column.js +17 -3
- package/dist/components/charts/discrete_scatter/discrete_scatter.js +17 -2
- package/dist/components/charts/gauge/gauge.js +1 -1
- package/dist/components/charts/heatmap/heatmap.js +17 -3
- package/dist/components/charts/line/line.js +17 -3
- package/dist/components/charts/sparkline/sparkline.js +11 -4
- package/dist/components/charts/stacked_column/stacked_column.js +17 -3
- package/dist/utils/charts/constants.js +5 -1
- package/package.json +5 -5
- package/src/components/charts/area/area.spec.js +9 -0
- package/src/components/charts/area/area.stories.js +3 -0
- package/src/components/charts/area/area.vue +22 -2
- package/src/components/charts/bar/bar.spec.js +11 -2
- package/src/components/charts/bar/bar.stories.js +21 -7
- package/src/components/charts/bar/bar.vue +22 -3
- package/src/components/charts/chart/chart.vue +3 -0
- package/src/components/charts/column/column.stories.js +3 -0
- package/src/components/charts/column/column.vue +26 -3
- package/src/components/charts/column/column_chart.spec.js +9 -0
- package/src/components/charts/discrete_scatter/discrete_scatter.spec.js +41 -0
- package/src/components/charts/discrete_scatter/discrete_scatter.stories.js +3 -0
- package/src/components/charts/discrete_scatter/discrete_scatter.vue +22 -2
- package/src/components/charts/gauge/gauge.stories.js +5 -2
- package/src/components/charts/gauge/gauge.vue +1 -3
- package/src/components/charts/heatmap/heatmap.spec.js +25 -5
- package/src/components/charts/heatmap/heatmap.stories.js +3 -0
- package/src/components/charts/heatmap/heatmap.vue +22 -3
- package/src/components/charts/line/line.spec.js +9 -0
- package/src/components/charts/line/line.stories.js +3 -0
- package/src/components/charts/line/line.vue +22 -2
- package/src/components/charts/sparkline/sparkline.spec.js +28 -1
- package/src/components/charts/sparkline/sparkline.stories.js +18 -10
- package/src/components/charts/sparkline/sparkline.vue +14 -3
- package/src/components/charts/stacked_column/stacked_column.spec.js +9 -0
- package/src/components/charts/stacked_column/stacked_column.stories.js +3 -0
- package/src/components/charts/stacked_column/stacked_column.vue +22 -2
- package/src/utils/charts/constants.js +4 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { shallowMount } from '@vue/test-utils';
|
|
2
2
|
import { waitForAnimationFrame } from '~/utils/test_utils';
|
|
3
|
+
import { HEIGHT_AUTO_HORIZONTAL_LAYOUT_CLASSES } from '~/utils/charts/constants';
|
|
3
4
|
import { createMockChartInstance, ChartTooltipStub } from '~helpers/chart_stubs';
|
|
5
|
+
import { expectHeightAutoClasses } from '~helpers/chart_height';
|
|
4
6
|
import Chart from '../chart/chart.vue';
|
|
5
7
|
import SparklineChart from './sparkline.vue';
|
|
6
8
|
|
|
@@ -25,11 +27,12 @@ jest.mock('~/directives/resize_observer/resize_observer', () => ({
|
|
|
25
27
|
describe('sparkline chart component', () => {
|
|
26
28
|
let wrapper;
|
|
27
29
|
let componentOptions;
|
|
28
|
-
const factory = () => {
|
|
30
|
+
const factory = (props = {}) => {
|
|
29
31
|
componentOptions = {
|
|
30
32
|
propsData: {
|
|
31
33
|
data: [[]],
|
|
32
34
|
variant: null,
|
|
35
|
+
...props,
|
|
33
36
|
},
|
|
34
37
|
scopedSlots: { latestSeriesEntry: jest.fn() },
|
|
35
38
|
stubs: {
|
|
@@ -43,6 +46,7 @@ describe('sparkline chart component', () => {
|
|
|
43
46
|
// helpers
|
|
44
47
|
const getByTestId = (id) => wrapper.find(`[data-testid="${id}"]`);
|
|
45
48
|
const getChart = () => wrapper.findComponent(Chart);
|
|
49
|
+
const getChartContainer = () => getByTestId('chart-container');
|
|
46
50
|
|
|
47
51
|
const getTooltip = () => wrapper.findComponent(ChartTooltipStub);
|
|
48
52
|
const getTooltipTitle = () => getByTestId('tooltip-title');
|
|
@@ -212,4 +216,27 @@ describe('sparkline chart component', () => {
|
|
|
212
216
|
expect(getChartOptions().series[0].smooth).toBe(smooth);
|
|
213
217
|
});
|
|
214
218
|
});
|
|
219
|
+
|
|
220
|
+
describe('height', () => {
|
|
221
|
+
expectHeightAutoClasses({
|
|
222
|
+
createComponent: factory,
|
|
223
|
+
findContainer: getChartContainer,
|
|
224
|
+
findChart: getChart,
|
|
225
|
+
classes: HEIGHT_AUTO_HORIZONTAL_LAYOUT_CLASSES,
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe('sparkline root element style', () => {
|
|
229
|
+
it('does not set the root element style to height full', () => {
|
|
230
|
+
factory();
|
|
231
|
+
|
|
232
|
+
expect(wrapper.element.classList.value).not.toContain('gl-h-full');
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('set the root element style to height full when height is "auto"', () => {
|
|
236
|
+
factory({ height: 'auto' });
|
|
237
|
+
|
|
238
|
+
expect(wrapper.element.classList.value).toContain('gl-h-full');
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
});
|
|
215
242
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GlSparklineChart } from '../../../charts';
|
|
2
2
|
import { colorFromDefaultPalette } from '../../../utils/charts/theme';
|
|
3
|
+
import { makeContainer } from '../../../utils/story_decorators/container';
|
|
3
4
|
import readme from './sparkline.md';
|
|
4
5
|
|
|
5
6
|
const chartData = [
|
|
@@ -38,16 +39,15 @@ const Template = (args) => ({
|
|
|
38
39
|
components: { GlSparklineChart },
|
|
39
40
|
props: Object.keys(args),
|
|
40
41
|
template: `
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
</div>`,
|
|
42
|
+
<gl-sparkline-chart
|
|
43
|
+
:data="data"
|
|
44
|
+
:height="height"
|
|
45
|
+
:tooltip-label="tooltipLabel"
|
|
46
|
+
:show-last-y-value="showLastYValue"
|
|
47
|
+
:gradient="gradient"
|
|
48
|
+
:smooth="smooth"
|
|
49
|
+
/>
|
|
50
|
+
`,
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
export const Default = Template.bind({});
|
|
@@ -62,6 +62,14 @@ WithChartColorGradient.args = generateProps({ gradient: customGradient });
|
|
|
62
62
|
export const WithSmoothing = Template.bind({});
|
|
63
63
|
WithSmoothing.args = generateProps({ smooth: 0.5 });
|
|
64
64
|
|
|
65
|
+
export const AutoHeight = Template.bind({});
|
|
66
|
+
Object.assign(AutoHeight, {
|
|
67
|
+
args: generateProps({
|
|
68
|
+
height: 'auto',
|
|
69
|
+
}),
|
|
70
|
+
decorators: [makeContainer({ height: '300px' })],
|
|
71
|
+
});
|
|
72
|
+
|
|
65
73
|
export default {
|
|
66
74
|
title: 'charts/sparkline-chart',
|
|
67
75
|
component: GlSparklineChart,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
mergeSeriesToOptions,
|
|
9
9
|
symbolSize,
|
|
10
10
|
} from '../../../utils/charts/config';
|
|
11
|
+
import { HEIGHT_AUTO_HORIZONTAL_LAYOUT_CLASSES } from '../../../utils/charts/constants';
|
|
11
12
|
import Chart from '../chart/chart.vue';
|
|
12
13
|
import ChartTooltip from '../tooltip/tooltip.vue';
|
|
13
14
|
|
|
@@ -49,10 +50,10 @@ export default {
|
|
|
49
50
|
default: '',
|
|
50
51
|
},
|
|
51
52
|
/**
|
|
52
|
-
* Sets the chart's height in
|
|
53
|
+
* Sets the chart's height in pixels. Set to `"auto"` to use the height of the container.
|
|
53
54
|
*/
|
|
54
55
|
height: {
|
|
55
|
-
type: Number,
|
|
56
|
+
type: [Number, String],
|
|
56
57
|
required: false,
|
|
57
58
|
default: 50,
|
|
58
59
|
},
|
|
@@ -169,6 +170,9 @@ export default {
|
|
|
169
170
|
|
|
170
171
|
return latestEntry[1];
|
|
171
172
|
},
|
|
173
|
+
autoHeight() {
|
|
174
|
+
return this.height === 'auto';
|
|
175
|
+
},
|
|
172
176
|
},
|
|
173
177
|
methods: {
|
|
174
178
|
onChartCreated(chartInstance) {
|
|
@@ -215,6 +219,7 @@ export default {
|
|
|
215
219
|
}
|
|
216
220
|
},
|
|
217
221
|
},
|
|
222
|
+
HEIGHT_AUTO_HORIZONTAL_LAYOUT_CLASSES,
|
|
218
223
|
};
|
|
219
224
|
</script>
|
|
220
225
|
|
|
@@ -222,12 +227,18 @@ export default {
|
|
|
222
227
|
<div
|
|
223
228
|
v-resize-observer="handleResize"
|
|
224
229
|
class="gl-display-flex gl-align-items-center"
|
|
230
|
+
:class="{ 'gl-h-full': autoHeight }"
|
|
225
231
|
@mouseleave="hideTooltip"
|
|
226
232
|
>
|
|
227
233
|
<slot name="default"></slot>
|
|
228
|
-
<div
|
|
234
|
+
<div
|
|
235
|
+
data-testid="chart-container"
|
|
236
|
+
class="gl-flex-grow-1 gl-relative"
|
|
237
|
+
:class="{ [$options.HEIGHT_AUTO_HORIZONTAL_LAYOUT_CLASSES]: autoHeight }"
|
|
238
|
+
>
|
|
229
239
|
<chart
|
|
230
240
|
v-bind="$attrs"
|
|
241
|
+
:class="{ 'gl-flex-grow-1': autoHeight }"
|
|
231
242
|
:height="height"
|
|
232
243
|
:options="options"
|
|
233
244
|
@created="onChartCreated"
|
|
@@ -2,6 +2,7 @@ import { shallowMount } from '@vue/test-utils';
|
|
|
2
2
|
|
|
3
3
|
import TooltipDefaultFormat from '~/components/shared_components/charts/tooltip_default_format.vue';
|
|
4
4
|
import { createMockChartInstance, ChartTooltipStub } from '~helpers/chart_stubs';
|
|
5
|
+
import { expectHeightAutoClasses } from '~helpers/chart_height';
|
|
5
6
|
import { LEGEND_LAYOUT_INLINE, LEGEND_LAYOUT_TABLE } from '~/utils/charts/constants';
|
|
6
7
|
import {
|
|
7
8
|
mockDefaultStackedLineData,
|
|
@@ -279,4 +280,12 @@ describe('stacked column chart component', () => {
|
|
|
279
280
|
});
|
|
280
281
|
});
|
|
281
282
|
});
|
|
283
|
+
|
|
284
|
+
describe('height', () => {
|
|
285
|
+
expectHeightAutoClasses({
|
|
286
|
+
createComponent: (props) => createShallowWrapper({ props }),
|
|
287
|
+
findContainer: () => wrapper,
|
|
288
|
+
findChart,
|
|
289
|
+
});
|
|
290
|
+
});
|
|
282
291
|
});
|
|
@@ -20,6 +20,7 @@ const template = `
|
|
|
20
20
|
:y-axis-title="yAxisTitle"
|
|
21
21
|
:secondary-data="secondaryData"
|
|
22
22
|
:secondary-data-title="secondaryDataTitle"
|
|
23
|
+
:height="height"
|
|
23
24
|
/>
|
|
24
25
|
`;
|
|
25
26
|
|
|
@@ -36,6 +37,7 @@ const generateProps = ({
|
|
|
36
37
|
presentation = columnOptions.stacked,
|
|
37
38
|
secondaryData = [],
|
|
38
39
|
secondaryDataTitle = '',
|
|
40
|
+
height = null,
|
|
39
41
|
} = {}) => ({
|
|
40
42
|
bars,
|
|
41
43
|
lines,
|
|
@@ -47,6 +49,7 @@ const generateProps = ({
|
|
|
47
49
|
yAxisTitle,
|
|
48
50
|
secondaryDataTitle,
|
|
49
51
|
secondaryData,
|
|
52
|
+
height,
|
|
50
53
|
});
|
|
51
54
|
|
|
52
55
|
const Template = (args, { argTypes }) => ({
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
LEGEND_MAX_TEXT,
|
|
20
20
|
CHART_TYPE_LINE,
|
|
21
21
|
ANNOTATION_TOOLTIP_TOP_OFFSET,
|
|
22
|
+
HEIGHT_AUTO_CLASSES,
|
|
22
23
|
} from '../../../utils/charts/constants';
|
|
23
24
|
import { colorFromDefaultPalette } from '../../../utils/charts/theme';
|
|
24
25
|
import { columnOptions } from '../../../utils/constants';
|
|
@@ -136,6 +137,14 @@ export default {
|
|
|
136
137
|
required: false,
|
|
137
138
|
default: null,
|
|
138
139
|
},
|
|
140
|
+
/**
|
|
141
|
+
* Sets the chart's height in pixels. Set to `"auto"` to use the height of the container.
|
|
142
|
+
*/
|
|
143
|
+
height: {
|
|
144
|
+
type: [Number, String],
|
|
145
|
+
required: false,
|
|
146
|
+
default: null,
|
|
147
|
+
},
|
|
139
148
|
},
|
|
140
149
|
data() {
|
|
141
150
|
return {
|
|
@@ -246,6 +255,9 @@ export default {
|
|
|
246
255
|
return acc;
|
|
247
256
|
}, []);
|
|
248
257
|
},
|
|
258
|
+
autoHeight() {
|
|
259
|
+
return this.height === 'auto';
|
|
260
|
+
},
|
|
249
261
|
},
|
|
250
262
|
beforeDestroy() {
|
|
251
263
|
this.chart.getDom().removeEventListener('mousemove', this.debouncedMoveShowTooltip);
|
|
@@ -295,11 +307,19 @@ export default {
|
|
|
295
307
|
}
|
|
296
308
|
},
|
|
297
309
|
},
|
|
310
|
+
HEIGHT_AUTO_CLASSES,
|
|
298
311
|
};
|
|
299
312
|
</script>
|
|
300
313
|
<template>
|
|
301
|
-
<div class="position-relative">
|
|
302
|
-
<chart
|
|
314
|
+
<div class="position-relative" :class="{ [$options.HEIGHT_AUTO_CLASSES]: autoHeight }">
|
|
315
|
+
<chart
|
|
316
|
+
v-bind="$attrs"
|
|
317
|
+
:class="{ 'gl-flex-grow-1': autoHeight }"
|
|
318
|
+
:height="height"
|
|
319
|
+
:options="options"
|
|
320
|
+
v-on="$listeners"
|
|
321
|
+
@created="onCreated"
|
|
322
|
+
/>
|
|
303
323
|
<chart-tooltip
|
|
304
324
|
v-if="chart"
|
|
305
325
|
:show="showTooltip"
|
|
@@ -63,3 +63,7 @@ export const arrowSymbol = 'path://m5 229 5 8h-10z';
|
|
|
63
63
|
// Constants for the type property of charts
|
|
64
64
|
export const CHART_TYPE_BAR = 'bar';
|
|
65
65
|
export const CHART_TYPE_LINE = 'line';
|
|
66
|
+
|
|
67
|
+
// Constants for height "auto"
|
|
68
|
+
export const HEIGHT_AUTO_CLASSES = 'gl-display-flex gl-flex-direction-column gl-h-full';
|
|
69
|
+
export const HEIGHT_AUTO_HORIZONTAL_LAYOUT_CLASSES = 'gl-display-flex gl-h-full';
|