@gitlab/ui 71.9.1 → 71.10.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 +11 -22
- package/dist/components/charts/bar/bar.js +3 -4
- package/dist/components/charts/column/column.js +5 -22
- package/dist/components/charts/heatmap/heatmap.js +4 -9
- package/dist/components/charts/line/line.js +11 -22
- package/dist/tokens/css/tokens.css +1 -1
- package/dist/tokens/css/tokens.dark.css +1 -1
- package/dist/tokens/js/tokens.dark.js +1 -1
- package/dist/tokens/js/tokens.js +1 -1
- package/dist/tokens/scss/_tokens.dark.scss +1 -1
- package/dist/tokens/scss/_tokens.scss +1 -1
- package/package.json +1 -1
- package/src/components/charts/area/area.spec.js +82 -7
- package/src/components/charts/area/area.stories.js +24 -6
- package/src/components/charts/area/area.vue +21 -27
- package/src/components/charts/bar/bar.spec.js +7 -43
- package/src/components/charts/bar/bar.vue +3 -4
- package/src/components/charts/column/__snapshots__/column_chart.spec.js.snap +0 -12
- package/src/components/charts/column/column.vue +1 -23
- package/src/components/charts/column/column_chart.spec.js +13 -27
- package/src/components/charts/heatmap/heatmap.vue +4 -14
- package/src/components/charts/line/line.spec.js +120 -38
- package/src/components/charts/line/line.stories.js +21 -4
- package/src/components/charts/line/line.vue +21 -32
|
@@ -27,8 +27,6 @@ import {
|
|
|
27
27
|
mergeSeriesToOptions,
|
|
28
28
|
mergeAnnotationAxisToOptions,
|
|
29
29
|
lineStyle,
|
|
30
|
-
// eslint-disable-next-line import/no-deprecated
|
|
31
|
-
getDefaultTooltipContent,
|
|
32
30
|
} from '../../../utils/charts/config';
|
|
33
31
|
import {
|
|
34
32
|
LEGEND_LAYOUT_INLINE,
|
|
@@ -41,7 +39,6 @@ import {
|
|
|
41
39
|
} from '../../../utils/charts/constants';
|
|
42
40
|
import { colorFromDefaultPalette } from '../../../utils/charts/theme';
|
|
43
41
|
import { seriesHasAnnotations, isDataPointAnnotation } from '../../../utils/charts/utils';
|
|
44
|
-
import TooltipDefaultFormat from '../../shared_components/charts/tooltip_default_format.vue';
|
|
45
42
|
import Chart from '../chart/chart.vue';
|
|
46
43
|
import ChartLegend from '../legend/legend.vue';
|
|
47
44
|
import ChartTooltip from '../tooltip/tooltip.vue';
|
|
@@ -52,7 +49,6 @@ export default {
|
|
|
52
49
|
Chart,
|
|
53
50
|
ChartLegend,
|
|
54
51
|
ChartTooltip,
|
|
55
|
-
TooltipDefaultFormat,
|
|
56
52
|
},
|
|
57
53
|
inheritAttrs: false,
|
|
58
54
|
props: {
|
|
@@ -85,6 +81,12 @@ export default {
|
|
|
85
81
|
required: false,
|
|
86
82
|
default: null,
|
|
87
83
|
},
|
|
84
|
+
/**
|
|
85
|
+
* Callback called when showing or refreshing a tooltip.
|
|
86
|
+
* **Deprecated:** Use slots `#tooltip-title`, `#tooltip-content` or `#tooltip-value`.
|
|
87
|
+
*
|
|
88
|
+
* @deprecated Use slots `#tooltip-title`, `#tooltip-content` or `#tooltip-value`.
|
|
89
|
+
*/
|
|
88
90
|
formatTooltipText: {
|
|
89
91
|
type: Function,
|
|
90
92
|
required: false,
|
|
@@ -139,8 +141,6 @@ export default {
|
|
|
139
141
|
// https://gitlab.com/gitlab-org/gitlab-ui/-/issues/618
|
|
140
142
|
return {
|
|
141
143
|
chart: null,
|
|
142
|
-
dataTooltipTitle: '',
|
|
143
|
-
dataTooltipContent: {},
|
|
144
144
|
showAnnotationsTooltip: false,
|
|
145
145
|
annotationsTooltipTitle: '',
|
|
146
146
|
annotationsTooltipContent: '',
|
|
@@ -148,7 +148,6 @@ export default {
|
|
|
148
148
|
left: '0',
|
|
149
149
|
top: '0',
|
|
150
150
|
},
|
|
151
|
-
selectedFormatTooltipText: this.formatTooltipText || this.defaultFormatTooltipText,
|
|
152
151
|
};
|
|
153
152
|
},
|
|
154
153
|
computed: {
|
|
@@ -195,7 +194,7 @@ export default {
|
|
|
195
194
|
type: 'solid',
|
|
196
195
|
},
|
|
197
196
|
label: {
|
|
198
|
-
formatter: this.
|
|
197
|
+
formatter: this.formatTooltipText,
|
|
199
198
|
},
|
|
200
199
|
},
|
|
201
200
|
},
|
|
@@ -265,13 +264,6 @@ export default {
|
|
|
265
264
|
this.chart.off('mouseover', this.onChartMouseOver);
|
|
266
265
|
},
|
|
267
266
|
methods: {
|
|
268
|
-
defaultFormatTooltipText(params) {
|
|
269
|
-
// eslint-disable-next-line import/no-deprecated
|
|
270
|
-
const { xLabels, tooltipContent } = getDefaultTooltipContent(params, this.options.yAxis.name);
|
|
271
|
-
|
|
272
|
-
this.$set(this, 'dataTooltipContent', tooltipContent);
|
|
273
|
-
this.dataTooltipTitle = xLabels.join(', ');
|
|
274
|
-
},
|
|
275
267
|
defaultAnnotationTooltipText(params) {
|
|
276
268
|
return {
|
|
277
269
|
title: params.data.xAxis,
|
|
@@ -318,9 +310,6 @@ export default {
|
|
|
318
310
|
};
|
|
319
311
|
}
|
|
320
312
|
},
|
|
321
|
-
onLabelChange(params) {
|
|
322
|
-
this.selectedFormatTooltipText(params);
|
|
323
|
-
},
|
|
324
313
|
},
|
|
325
314
|
HEIGHT_AUTO_CLASSES,
|
|
326
315
|
};
|
|
@@ -351,16 +340,21 @@ export default {
|
|
|
351
340
|
</template>
|
|
352
341
|
<div>{{ annotationsTooltipContent }}</div>
|
|
353
342
|
</chart-tooltip>
|
|
354
|
-
<chart-tooltip
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
343
|
+
<chart-tooltip
|
|
344
|
+
v-if="chart"
|
|
345
|
+
ref="dataTooltip"
|
|
346
|
+
:chart="chart"
|
|
347
|
+
:use-default-tooltip-formatter="!formatTooltipText"
|
|
348
|
+
>
|
|
349
|
+
<template v-if="$scopedSlots['tooltip-title']" #title="scope">
|
|
350
|
+
<slot name="tooltip-title" v-bind="scope"></slot>
|
|
351
|
+
</template>
|
|
352
|
+
<template v-if="$scopedSlots['tooltip-content']" #default="scope">
|
|
353
|
+
<slot name="tooltip-content" v-bind="scope"></slot>
|
|
354
|
+
</template>
|
|
355
|
+
<template v-if="$scopedSlots['tooltip-value']" #tooltip-value="scope">
|
|
356
|
+
<slot name="tooltip-value" v-bind="scope"></slot>
|
|
361
357
|
</template>
|
|
362
|
-
<slot v-if="formatTooltipText" name="tooltip-content"></slot>
|
|
363
|
-
<tooltip-default-format v-else :tooltip-content="dataTooltipContent" />
|
|
364
358
|
</chart-tooltip>
|
|
365
359
|
<chart-legend
|
|
366
360
|
v-if="compiledOptions"
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { shallowMount } from '@vue/test-utils';
|
|
2
|
-
import TooltipDefaultFormat from '~/components/shared_components/charts/tooltip_default_format.vue';
|
|
3
2
|
import { createMockChartInstance } from '~helpers/chart_stubs';
|
|
4
3
|
import { expectHeightAutoClasses } from '~helpers/chart_height';
|
|
5
4
|
import Chart from '../chart/chart.vue';
|
|
5
|
+
import ChartTooltip from '../tooltip/tooltip.vue';
|
|
6
6
|
import BarChart from './bar.vue';
|
|
7
7
|
|
|
8
8
|
let mockChartInstance;
|
|
@@ -27,15 +27,14 @@ describe('Bar chart component', () => {
|
|
|
27
27
|
let wrapper;
|
|
28
28
|
|
|
29
29
|
const findChart = () => wrapper.findComponent(Chart);
|
|
30
|
+
const findChartTooltip = () => wrapper.findComponent(ChartTooltip);
|
|
31
|
+
|
|
30
32
|
const getOptions = () => findChart().props('options');
|
|
31
33
|
const emitChartCreated = () => findChart().vm.$emit('created', mockChartInstance);
|
|
32
34
|
|
|
33
35
|
const createComponent = (props = {}) => {
|
|
34
36
|
wrapper = shallowMount(BarChart, {
|
|
35
37
|
propsData: { ...defaultChartProps, ...props },
|
|
36
|
-
stubs: {
|
|
37
|
-
'tooltip-default-format': TooltipDefaultFormat,
|
|
38
|
-
},
|
|
39
38
|
});
|
|
40
39
|
};
|
|
41
40
|
|
|
@@ -75,45 +74,10 @@ describe('Bar chart component', () => {
|
|
|
75
74
|
defaultChartProps.data.Office.map(([, name]) => expect(formatter(name)).toMatchSnapshot());
|
|
76
75
|
});
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
seriesData: [
|
|
83
|
-
{
|
|
84
|
-
seriesId: 'Office',
|
|
85
|
-
data: [100, 'Jim'],
|
|
86
|
-
value: [100, 'Jim'],
|
|
87
|
-
},
|
|
88
|
-
],
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
it('calls custom method and returns title with y labels', () => {
|
|
92
|
-
const getDefaultTooltipContentReturnVal = { yLabels: [], tooltipContent: {} };
|
|
93
|
-
|
|
94
|
-
// stub the method
|
|
95
|
-
wrapper.vm.getDefaultTooltipContent = jest
|
|
96
|
-
.fn()
|
|
97
|
-
.mockReturnValue(getDefaultTooltipContentReturnVal);
|
|
98
|
-
|
|
99
|
-
// label formatter is triggered here which should eventually call
|
|
100
|
-
// getDefaultTooltipContent
|
|
101
|
-
getOptions().yAxis.axisPointer.label.formatter(labelParams);
|
|
102
|
-
|
|
103
|
-
return wrapper.vm.$nextTick(() => {
|
|
104
|
-
expect(wrapper.vm.getDefaultTooltipContent).toHaveBeenCalled();
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('sets accurate tooltip title and content state', () => {
|
|
109
|
-
getOptions().yAxis.axisPointer.label.formatter(labelParams);
|
|
110
|
-
|
|
111
|
-
return wrapper.vm.$nextTick(() => {
|
|
112
|
-
expect(wrapper.vm.tooltipTitle).toBe(labelParams.value);
|
|
113
|
-
expect(wrapper.vm.tooltipContent[defaultChartProps.xAxisTitle].value).toBe(
|
|
114
|
-
labelParams.seriesData[0].data[0]
|
|
115
|
-
);
|
|
116
|
-
});
|
|
77
|
+
it('configures chart tooltip', () => {
|
|
78
|
+
expect(findChartTooltip().props()).toMatchObject({
|
|
79
|
+
chart: mockChartInstance,
|
|
80
|
+
useDefaultTooltipFormatter: false,
|
|
117
81
|
});
|
|
118
82
|
});
|
|
119
83
|
});
|
|
@@ -173,21 +173,20 @@ export default {
|
|
|
173
173
|
this.$emit('created', chart);
|
|
174
174
|
},
|
|
175
175
|
onLabelChange(params) {
|
|
176
|
-
const { yLabels, tooltipContent } = this.
|
|
176
|
+
const { yLabels, tooltipContent } = this.getTooltipContent(params, this.xAxisTitle);
|
|
177
177
|
|
|
178
178
|
this.$set(this, 'tooltipContent', tooltipContent);
|
|
179
179
|
this.tooltipTitle = yLabels.join(', ');
|
|
180
180
|
},
|
|
181
181
|
/**
|
|
182
|
-
*
|
|
183
|
-
* However, for bar charts, the tooltip should be against x-axis values.
|
|
182
|
+
* For bar charts, the tooltip should be against x-axis values.
|
|
184
183
|
* This method will be removed after https://gitlab.com/gitlab-org/gitlab-ui/-/issues/674
|
|
185
184
|
*
|
|
186
185
|
* @param {Object} params series data
|
|
187
186
|
* @param {String} xAxisTitle x-axis title
|
|
188
187
|
* @returns {Object} tooltip title and content
|
|
189
188
|
*/
|
|
190
|
-
|
|
189
|
+
getTooltipContent(params, xAxisTitle = null) {
|
|
191
190
|
const seriesDataLength = params.seriesData.length;
|
|
192
191
|
const { yLabels, tooltipContent } = params.seriesData.reduce(
|
|
193
192
|
(acc, chartItem) => {
|
|
@@ -69,10 +69,6 @@ Object {
|
|
|
69
69
|
"show": false,
|
|
70
70
|
},
|
|
71
71
|
"axisPointer": Object {
|
|
72
|
-
"label": Object {
|
|
73
|
-
"formatter": [Function],
|
|
74
|
-
},
|
|
75
|
-
"show": true,
|
|
76
72
|
"type": "none",
|
|
77
73
|
},
|
|
78
74
|
"boundaryGap": true,
|
|
@@ -161,10 +157,6 @@ Object {
|
|
|
161
157
|
"show": false,
|
|
162
158
|
},
|
|
163
159
|
"axisPointer": Object {
|
|
164
|
-
"label": Object {
|
|
165
|
-
"formatter": [Function],
|
|
166
|
-
},
|
|
167
|
-
"show": true,
|
|
168
160
|
"type": "none",
|
|
169
161
|
},
|
|
170
162
|
"boundaryGap": true,
|
|
@@ -290,10 +282,6 @@ Object {
|
|
|
290
282
|
"show": false,
|
|
291
283
|
},
|
|
292
284
|
"axisPointer": Object {
|
|
293
|
-
"label": Object {
|
|
294
|
-
"formatter": [Function],
|
|
295
|
-
},
|
|
296
|
-
"show": true,
|
|
297
285
|
"type": "none",
|
|
298
286
|
},
|
|
299
287
|
"boundaryGap": true,
|
|
@@ -8,15 +8,12 @@ import {
|
|
|
8
8
|
yAxis,
|
|
9
9
|
dataZoomAdjustments,
|
|
10
10
|
mergeSeriesToOptions,
|
|
11
|
-
// eslint-disable-next-line import/no-deprecated
|
|
12
|
-
getDefaultTooltipContent,
|
|
13
11
|
generateBarSeries,
|
|
14
12
|
generateLineSeries,
|
|
15
13
|
} from '../../../utils/charts/config';
|
|
16
14
|
import { CHART_TYPE_LINE, HEIGHT_AUTO_CLASSES } from '../../../utils/charts/constants';
|
|
17
15
|
import { colorFromDefaultPalette } from '../../../utils/charts/theme';
|
|
18
16
|
import { columnOptions } from '../../../utils/constants';
|
|
19
|
-
import TooltipDefaultFormat from '../../shared_components/charts/tooltip_default_format.vue';
|
|
20
17
|
import Chart from '../chart/chart.vue';
|
|
21
18
|
import ChartTooltip from '../tooltip/tooltip.vue';
|
|
22
19
|
|
|
@@ -33,7 +30,6 @@ export default {
|
|
|
33
30
|
components: {
|
|
34
31
|
Chart,
|
|
35
32
|
ChartTooltip,
|
|
36
|
-
TooltipDefaultFormat,
|
|
37
33
|
},
|
|
38
34
|
inheritAttrs: false,
|
|
39
35
|
props: {
|
|
@@ -87,8 +83,6 @@ export default {
|
|
|
87
83
|
data() {
|
|
88
84
|
return {
|
|
89
85
|
chart: null,
|
|
90
|
-
tooltipTitle: '',
|
|
91
|
-
tooltipContent: {},
|
|
92
86
|
};
|
|
93
87
|
},
|
|
94
88
|
computed: {
|
|
@@ -141,11 +135,7 @@ export default {
|
|
|
141
135
|
show: false,
|
|
142
136
|
},
|
|
143
137
|
axisPointer: {
|
|
144
|
-
show: true,
|
|
145
138
|
type: 'none',
|
|
146
|
-
label: {
|
|
147
|
-
formatter: this.onLabelChange,
|
|
148
|
-
},
|
|
149
139
|
},
|
|
150
140
|
name: this.xAxisTitle,
|
|
151
141
|
type: this.xAxisType,
|
|
@@ -180,13 +170,6 @@ export default {
|
|
|
180
170
|
this.chart = chart;
|
|
181
171
|
this.$emit('created', chart);
|
|
182
172
|
},
|
|
183
|
-
onLabelChange(params) {
|
|
184
|
-
// eslint-disable-next-line import/no-deprecated
|
|
185
|
-
const { xLabels, tooltipContent } = getDefaultTooltipContent(params, this.yAxisTitle);
|
|
186
|
-
|
|
187
|
-
this.$set(this, 'tooltipContent', tooltipContent);
|
|
188
|
-
this.tooltipTitle = xLabels.join(', ');
|
|
189
|
-
},
|
|
190
173
|
},
|
|
191
174
|
HEIGHT_AUTO_CLASSES,
|
|
192
175
|
};
|
|
@@ -201,11 +184,6 @@ export default {
|
|
|
201
184
|
v-on="$listeners"
|
|
202
185
|
@created="onCreated"
|
|
203
186
|
/>
|
|
204
|
-
<chart-tooltip v-if="chart" :chart="chart"
|
|
205
|
-
<template #title>
|
|
206
|
-
<div>{{ tooltipTitle }} ({{ xAxisTitle }})</div>
|
|
207
|
-
</template>
|
|
208
|
-
<tooltip-default-format :tooltip-content="tooltipContent" />
|
|
209
|
-
</chart-tooltip>
|
|
187
|
+
<chart-tooltip v-if="chart" :chart="chart" :use-default-tooltip-formatter="true" />
|
|
210
188
|
</div>
|
|
211
189
|
</template>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { shallowMount } from '@vue/test-utils';
|
|
2
|
-
import { createMockChartInstance
|
|
2
|
+
import { createMockChartInstance } from '~helpers/chart_stubs';
|
|
3
3
|
import { expectHeightAutoClasses } from '~helpers/chart_height';
|
|
4
4
|
import {
|
|
5
5
|
mockDefaultLineData,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
mockDefaultStackedBarData,
|
|
9
9
|
} from '../../../utils/charts/mock_data';
|
|
10
10
|
import Chart from '../chart/chart.vue';
|
|
11
|
+
import ChartTooltip from '../tooltip/tooltip.vue';
|
|
11
12
|
import ColumnChart from './column.vue';
|
|
12
13
|
|
|
13
14
|
let mockChartInstance;
|
|
@@ -27,36 +28,28 @@ describe('column chart component', () => {
|
|
|
27
28
|
|
|
28
29
|
const chartItemClickedSpy = jest.fn();
|
|
29
30
|
const findChart = () => wrapper.findComponent(Chart);
|
|
30
|
-
const
|
|
31
|
-
|
|
31
|
+
const findChartTooltip = () => wrapper.findComponent(ChartTooltip);
|
|
32
|
+
|
|
33
|
+
const emitChartCreated = () => findChart().vm.$emit('created', mockChartInstance);
|
|
32
34
|
|
|
33
35
|
const factory = (props = defaultChartProps, slots = {}) => {
|
|
34
36
|
wrapper = shallowMount(ColumnChart, {
|
|
35
37
|
propsData: { ...props },
|
|
36
|
-
stubs: {
|
|
37
|
-
'chart-tooltip': ChartTooltipStub,
|
|
38
|
-
},
|
|
39
38
|
listeners: {
|
|
40
39
|
chartItemClicked: chartItemClickedSpy,
|
|
41
40
|
},
|
|
42
|
-
data() {
|
|
43
|
-
return {
|
|
44
|
-
chart: mockChartInstance,
|
|
45
|
-
};
|
|
46
|
-
},
|
|
47
41
|
slots,
|
|
48
42
|
});
|
|
49
43
|
};
|
|
50
44
|
|
|
51
45
|
beforeEach(() => {
|
|
52
|
-
mockChartInstance = createMockChartInstance();
|
|
53
|
-
|
|
54
46
|
factory();
|
|
47
|
+
|
|
48
|
+
mockChartInstance = createMockChartInstance();
|
|
49
|
+
emitChartCreated();
|
|
55
50
|
});
|
|
56
51
|
|
|
57
52
|
it('emits "created" when onCreated is called', () => {
|
|
58
|
-
wrapper.vm.onCreated(wrapper.vm.chart);
|
|
59
|
-
|
|
60
53
|
expect(wrapper.emitted('created')).toHaveLength(1);
|
|
61
54
|
});
|
|
62
55
|
|
|
@@ -126,18 +119,11 @@ describe('column chart component', () => {
|
|
|
126
119
|
});
|
|
127
120
|
|
|
128
121
|
describe('tooltip', () => {
|
|
129
|
-
it('
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
getChartOptions().xAxis.axisPointer.label.formatter(params);
|
|
135
|
-
|
|
136
|
-
await wrapper.vm.$nextTick();
|
|
137
|
-
|
|
138
|
-
const expectedTooltipTitle = `${params.seriesData[0].value[0]} (${defaultChartProps.xAxisTitle})`;
|
|
139
|
-
|
|
140
|
-
expect(findTooltip().text()).toContain(expectedTooltipTitle);
|
|
122
|
+
it('configures chart tooltip', async () => {
|
|
123
|
+
expect(findChartTooltip().props()).toMatchObject({
|
|
124
|
+
chart: mockChartInstance,
|
|
125
|
+
useDefaultTooltipFormatter: true,
|
|
126
|
+
});
|
|
141
127
|
});
|
|
142
128
|
});
|
|
143
129
|
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
<script>
|
|
3
3
|
import merge from 'lodash/merge';
|
|
4
4
|
import { WHITE, GRAY_100 } from '../../../../dist/tokens/js/tokens';
|
|
5
|
-
|
|
6
|
-
import { getDefaultTooltipContent } from '../../../utils/charts/config';
|
|
5
|
+
import { getTooltipTitle, getTooltipContent } from '../../../utils/charts/config';
|
|
7
6
|
import { HEIGHT_AUTO_CLASSES } from '../../../utils/charts/constants';
|
|
8
7
|
import { heatmapHues } from '../../../utils/charts/theme';
|
|
9
8
|
import { engineeringNotation } from '../../../utils/number_utils';
|
|
@@ -223,14 +222,8 @@ export default {
|
|
|
223
222
|
},
|
|
224
223
|
methods: {
|
|
225
224
|
defaultFormatTooltipText(params) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
params,
|
|
229
|
-
this.computedOptions.yAxis.name
|
|
230
|
-
);
|
|
231
|
-
|
|
232
|
-
this.$set(this.tooltip, 'content', tooltipContent);
|
|
233
|
-
this.tooltip.title = xLabels.join(', ');
|
|
225
|
+
this.tooltip.title = getTooltipTitle(params, this.computedOptions.xAxis.name);
|
|
226
|
+
this.tooltip.content = getTooltipContent(params, this.computedOptions.yAxis.name);
|
|
234
227
|
},
|
|
235
228
|
onCreated(chart) {
|
|
236
229
|
this.chart = chart;
|
|
@@ -268,10 +261,7 @@ export default {
|
|
|
268
261
|
<chart-tooltip v-if="chart" :chart="chart" :top="tooltip.top" :left="tooltip.left">
|
|
269
262
|
<template #title>
|
|
270
263
|
<slot v-if="formatTooltipText" name="tooltip-title"></slot>
|
|
271
|
-
<div v-else>
|
|
272
|
-
{{ tooltip.title }}
|
|
273
|
-
<template v-if="computedOptions.xAxis.name">({{ computedOptions.xAxis.name }})</template>
|
|
274
|
-
</div>
|
|
264
|
+
<div v-else>{{ tooltip.title }}</div>
|
|
275
265
|
</template>
|
|
276
266
|
<slot v-if="formatTooltipText" name="tooltip-content"></slot>
|
|
277
267
|
<tooltip-default-format v-else :tooltip-content="tooltip.content" />
|
|
@@ -2,7 +2,11 @@ import { nextTick } from 'vue';
|
|
|
2
2
|
import { shallowMount } from '@vue/test-utils';
|
|
3
3
|
|
|
4
4
|
import { LEGEND_LAYOUT_INLINE, LEGEND_LAYOUT_TABLE } from '~/utils/charts/constants';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
createMockChartInstance,
|
|
7
|
+
ChartTooltipStub,
|
|
8
|
+
chartTooltipStubData,
|
|
9
|
+
} from '~helpers/chart_stubs';
|
|
6
10
|
import { expectHeightAutoClasses } from '~helpers/chart_height';
|
|
7
11
|
|
|
8
12
|
import Chart from '../chart/chart.vue';
|
|
@@ -27,10 +31,13 @@ describe('line component', () => {
|
|
|
27
31
|
|
|
28
32
|
const emitChartCreated = () => findChart().vm.$emit('created', mockChartInstance);
|
|
29
33
|
|
|
30
|
-
const createShallowWrapper = (props = {},
|
|
34
|
+
const createShallowWrapper = ({ props = {}, ...options } = {}) => {
|
|
31
35
|
wrapper = shallowMount(LineChart, {
|
|
32
36
|
propsData: { option, data: [], ...props },
|
|
33
|
-
|
|
37
|
+
stubs: {
|
|
38
|
+
'chart-tooltip': ChartTooltipStub,
|
|
39
|
+
},
|
|
40
|
+
...options,
|
|
34
41
|
});
|
|
35
42
|
emitChartCreated();
|
|
36
43
|
};
|
|
@@ -59,12 +66,14 @@ describe('line component', () => {
|
|
|
59
66
|
|
|
60
67
|
it('are displayed if passed via annotations props', async () => {
|
|
61
68
|
createShallowWrapper({
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
props: {
|
|
70
|
+
annotations: [
|
|
71
|
+
{
|
|
72
|
+
min: '',
|
|
73
|
+
max: '',
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
},
|
|
68
77
|
});
|
|
69
78
|
|
|
70
79
|
await nextTick();
|
|
@@ -74,20 +83,22 @@ describe('line component', () => {
|
|
|
74
83
|
|
|
75
84
|
it('are displayed if passed via option props', async () => {
|
|
76
85
|
createShallowWrapper({
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
props: {
|
|
87
|
+
option: {
|
|
88
|
+
series: [
|
|
89
|
+
{
|
|
90
|
+
name: 'annotations',
|
|
91
|
+
markPoint: {
|
|
92
|
+
data: [
|
|
93
|
+
{
|
|
94
|
+
xAxis: 10,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
data: [],
|
|
87
99
|
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
],
|
|
100
|
+
],
|
|
101
|
+
},
|
|
91
102
|
},
|
|
92
103
|
});
|
|
93
104
|
|
|
@@ -112,8 +123,8 @@ describe('line component', () => {
|
|
|
112
123
|
},
|
|
113
124
|
};
|
|
114
125
|
|
|
115
|
-
createShallowWrapper(
|
|
116
|
-
{
|
|
126
|
+
createShallowWrapper({
|
|
127
|
+
props: {
|
|
117
128
|
annotations: [
|
|
118
129
|
{
|
|
119
130
|
min: '',
|
|
@@ -121,12 +132,7 @@ describe('line component', () => {
|
|
|
121
132
|
},
|
|
122
133
|
],
|
|
123
134
|
},
|
|
124
|
-
|
|
125
|
-
stubs: {
|
|
126
|
-
'chart-tooltip': ChartTooltipStub,
|
|
127
|
-
},
|
|
128
|
-
}
|
|
129
|
-
);
|
|
135
|
+
});
|
|
130
136
|
|
|
131
137
|
wrapper.vm.onChartDataPointMouseOver(params);
|
|
132
138
|
|
|
@@ -137,13 +143,83 @@ describe('line component', () => {
|
|
|
137
143
|
});
|
|
138
144
|
});
|
|
139
145
|
|
|
140
|
-
describe('data tooltip
|
|
141
|
-
|
|
146
|
+
describe('data tooltip', () => {
|
|
147
|
+
it('is initialized', async () => {
|
|
142
148
|
createShallowWrapper();
|
|
149
|
+
|
|
150
|
+
await nextTick();
|
|
151
|
+
|
|
152
|
+
expect(findDataTooltip().props()).toMatchObject({
|
|
153
|
+
useDefaultTooltipFormatter: true,
|
|
154
|
+
chart: mockChartInstance,
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe('is customized via slots', () => {
|
|
159
|
+
const { params, title, content } = chartTooltipStubData;
|
|
160
|
+
|
|
161
|
+
it('customizes tooltip value', async () => {
|
|
162
|
+
const tooltipValueSlot = jest.fn().mockReturnValue('Value');
|
|
163
|
+
|
|
164
|
+
createShallowWrapper({
|
|
165
|
+
scopedSlots: {
|
|
166
|
+
'tooltip-value': tooltipValueSlot,
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
await nextTick();
|
|
170
|
+
|
|
171
|
+
expect(tooltipValueSlot).toHaveBeenCalledWith({ value: 9 });
|
|
172
|
+
expect(findDataTooltip().text()).toBe('Value');
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('customizes title', async () => {
|
|
176
|
+
const tooltipTitleSlot = jest.fn().mockReturnValue('Title');
|
|
177
|
+
|
|
178
|
+
createShallowWrapper({
|
|
179
|
+
scopedSlots: {
|
|
180
|
+
'tooltip-title': tooltipTitleSlot,
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
await nextTick();
|
|
184
|
+
|
|
185
|
+
expect(tooltipTitleSlot).toHaveBeenCalledWith({
|
|
186
|
+
params,
|
|
187
|
+
title,
|
|
188
|
+
});
|
|
189
|
+
expect(findDataTooltip().text()).toBe('Title');
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('customizes content', async () => {
|
|
193
|
+
const tooltipContentSlot = jest.fn().mockReturnValue('Title');
|
|
194
|
+
|
|
195
|
+
createShallowWrapper({
|
|
196
|
+
scopedSlots: {
|
|
197
|
+
'tooltip-content': tooltipContentSlot,
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
await nextTick();
|
|
201
|
+
|
|
202
|
+
expect(tooltipContentSlot).toHaveBeenCalledWith({
|
|
203
|
+
params,
|
|
204
|
+
content,
|
|
205
|
+
});
|
|
206
|
+
expect(findDataTooltip().text()).toBe('Title');
|
|
207
|
+
});
|
|
143
208
|
});
|
|
144
209
|
|
|
145
|
-
it('is
|
|
146
|
-
|
|
210
|
+
it('is customized via formatting function', async () => {
|
|
211
|
+
createShallowWrapper({
|
|
212
|
+
props: {
|
|
213
|
+
formatTooltipText: jest.fn(),
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
await nextTick();
|
|
218
|
+
|
|
219
|
+
expect(findDataTooltip().props()).toMatchObject({
|
|
220
|
+
useDefaultTooltipFormatter: false,
|
|
221
|
+
chart: mockChartInstance,
|
|
222
|
+
});
|
|
147
223
|
});
|
|
148
224
|
});
|
|
149
225
|
|
|
@@ -158,7 +234,9 @@ describe('line component', () => {
|
|
|
158
234
|
|
|
159
235
|
it('is inline if correct prop value is set', async () => {
|
|
160
236
|
createShallowWrapper({
|
|
161
|
-
|
|
237
|
+
props: {
|
|
238
|
+
legendLayout: LEGEND_LAYOUT_INLINE,
|
|
239
|
+
},
|
|
162
240
|
});
|
|
163
241
|
|
|
164
242
|
await nextTick();
|
|
@@ -168,7 +246,9 @@ describe('line component', () => {
|
|
|
168
246
|
|
|
169
247
|
it('is tabular if correct prop value is set', async () => {
|
|
170
248
|
createShallowWrapper({
|
|
171
|
-
|
|
249
|
+
props: {
|
|
250
|
+
legendLayout: LEGEND_LAYOUT_TABLE,
|
|
251
|
+
},
|
|
172
252
|
});
|
|
173
253
|
|
|
174
254
|
await nextTick();
|
|
@@ -177,7 +257,9 @@ describe('line component', () => {
|
|
|
177
257
|
});
|
|
178
258
|
it('can be hidden', async () => {
|
|
179
259
|
createShallowWrapper({
|
|
180
|
-
|
|
260
|
+
props: {
|
|
261
|
+
showLegend: false,
|
|
262
|
+
},
|
|
181
263
|
});
|
|
182
264
|
|
|
183
265
|
await nextTick();
|
|
@@ -188,7 +270,7 @@ describe('line component', () => {
|
|
|
188
270
|
|
|
189
271
|
describe('height', () => {
|
|
190
272
|
expectHeightAutoClasses({
|
|
191
|
-
createComponent: createShallowWrapper,
|
|
273
|
+
createComponent: (props) => createShallowWrapper({ props }),
|
|
192
274
|
findContainer: () => wrapper,
|
|
193
275
|
findChart,
|
|
194
276
|
});
|