@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
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [71.10.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v71.9.1...v71.10.0) (2023-12-13)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **GlLineChart, GlAreaChart:** Simplify chart tooltip API ([3658fb6](https://gitlab.com/gitlab-org/gitlab-ui/commit/3658fb6b3efb4a396703e7697d415541ec3aa417))
|
|
7
|
+
|
|
1
8
|
## [71.9.1](https://gitlab.com/gitlab-org/gitlab-ui/compare/v71.9.0...v71.9.1) (2023-12-13)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import merge from 'lodash/merge';
|
|
2
|
-
import { defaultAreaOpacity, lineStyle, getThresholdConfig, generateAnnotationSeries, defaultChartOptions, dataZoomAdjustments, mergeSeriesToOptions, mergeAnnotationAxisToOptions, grid
|
|
2
|
+
import { defaultAreaOpacity, lineStyle, getThresholdConfig, generateAnnotationSeries, defaultChartOptions, dataZoomAdjustments, mergeSeriesToOptions, mergeAnnotationAxisToOptions, grid } from '../../../utils/charts/config';
|
|
3
3
|
import { LEGEND_AVERAGE_TEXT, LEGEND_MAX_TEXT, LEGEND_MIN_TEXT, LEGEND_CURRENT_TEXT, LEGEND_LAYOUT_INLINE, LEGEND_LAYOUT_TABLE, HEIGHT_AUTO_CLASSES } from '../../../utils/charts/constants';
|
|
4
4
|
import { colorFromDefaultPalette } from '../../../utils/charts/theme';
|
|
5
5
|
import { seriesHasAnnotations, isDataPointAnnotation } from '../../../utils/charts/utils';
|
|
6
|
-
import TooltipDefaultFormat from '../../shared_components/charts/tooltip_default_format';
|
|
7
6
|
import Chart from '../chart/chart';
|
|
8
7
|
import ChartLegend from '../legend/legend';
|
|
9
8
|
import ChartTooltip from '../tooltip/tooltip';
|
|
@@ -15,8 +14,7 @@ var script = {
|
|
|
15
14
|
components: {
|
|
16
15
|
Chart,
|
|
17
16
|
ChartLegend,
|
|
18
|
-
ChartTooltip
|
|
19
|
-
TooltipDefaultFormat
|
|
17
|
+
ChartTooltip
|
|
20
18
|
},
|
|
21
19
|
inheritAttrs: false,
|
|
22
20
|
props: {
|
|
@@ -49,6 +47,12 @@ var script = {
|
|
|
49
47
|
required: false,
|
|
50
48
|
default: null
|
|
51
49
|
},
|
|
50
|
+
/**
|
|
51
|
+
* Callback called when showing or refreshing a tooltip.
|
|
52
|
+
* **Deprecated:** Use slots `#tooltip-title`, `#tooltip-content` or `#tooltip-value`.
|
|
53
|
+
*
|
|
54
|
+
* @deprecated Use slots `#tooltip-title`, `#tooltip-content` or `#tooltip-value`.
|
|
55
|
+
*/
|
|
52
56
|
formatTooltipText: {
|
|
53
57
|
type: Function,
|
|
54
58
|
required: false,
|
|
@@ -103,16 +107,13 @@ var script = {
|
|
|
103
107
|
// https://gitlab.com/gitlab-org/gitlab-ui/-/issues/618
|
|
104
108
|
return {
|
|
105
109
|
chart: null,
|
|
106
|
-
dataTooltipTitle: '',
|
|
107
|
-
dataTooltipContent: {},
|
|
108
110
|
showAnnotationsTooltip: false,
|
|
109
111
|
annotationsTooltipTitle: '',
|
|
110
112
|
annotationsTooltipContent: '',
|
|
111
113
|
annotationsTooltipPosition: {
|
|
112
114
|
left: '0',
|
|
113
115
|
top: '0'
|
|
114
|
-
}
|
|
115
|
-
selectedFormatTooltipText: this.formatTooltipText || this.defaultFormatTooltipText
|
|
116
|
+
}
|
|
116
117
|
};
|
|
117
118
|
},
|
|
118
119
|
computed: {
|
|
@@ -153,7 +154,7 @@ var script = {
|
|
|
153
154
|
type: 'solid'
|
|
154
155
|
},
|
|
155
156
|
label: {
|
|
156
|
-
formatter: this.
|
|
157
|
+
formatter: this.formatTooltipText
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
160
|
},
|
|
@@ -215,15 +216,6 @@ var script = {
|
|
|
215
216
|
this.chart.off('mouseover', this.onChartMouseOver);
|
|
216
217
|
},
|
|
217
218
|
methods: {
|
|
218
|
-
defaultFormatTooltipText(params) {
|
|
219
|
-
// eslint-disable-next-line import/no-deprecated
|
|
220
|
-
const {
|
|
221
|
-
xLabels,
|
|
222
|
-
tooltipContent
|
|
223
|
-
} = getDefaultTooltipContent(params, this.options.yAxis.name);
|
|
224
|
-
this.$set(this, 'dataTooltipContent', tooltipContent);
|
|
225
|
-
this.dataTooltipTitle = xLabels.join(', ');
|
|
226
|
-
},
|
|
227
219
|
defaultAnnotationTooltipText(params) {
|
|
228
220
|
var _params$data$tooltipD;
|
|
229
221
|
return {
|
|
@@ -273,9 +265,6 @@ var script = {
|
|
|
273
265
|
top: `${event.event.zrY}px`
|
|
274
266
|
};
|
|
275
267
|
}
|
|
276
|
-
},
|
|
277
|
-
onLabelChange(params) {
|
|
278
|
-
this.selectedFormatTooltipText(params);
|
|
279
268
|
}
|
|
280
269
|
},
|
|
281
270
|
HEIGHT_AUTO_CLASSES
|
|
@@ -287,7 +276,7 @@ const __vue_script__ = script;
|
|
|
287
276
|
/* template */
|
|
288
277
|
var __vue_render__ = function () {
|
|
289
278
|
var _obj;
|
|
290
|
-
var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"position-relative",class:( _obj = {}, _obj[_vm.$options.HEIGHT_AUTO_CLASSES] = _vm.autoHeight, _obj )},[_c('chart',_vm._g(_vm._b({class:{ 'gl-flex-grow-1': _vm.autoHeight },attrs:{"height":_vm.height,"options":_vm.options},on:{"created":_vm.onCreated}},'chart',_vm.$attrs,false),_vm.$listeners)),_vm._v(" "),(_vm.shouldShowAnnotationsTooltip)?_c('chart-tooltip',{ref:"annotationsTooltip",attrs:{"id":"annotationsTooltip","show":_vm.showAnnotationsTooltip,"top":_vm.annotationsTooltipPosition.top,"left":_vm.annotationsTooltipPosition.left,"chart":_vm.chart,"placement":"bottom"},scopedSlots:_vm._u([{key:"title",fn:function(){return [_c('div',[_vm._v(_vm._s(_vm.annotationsTooltipTitle))])]},proxy:true}],null,false,1889294429)},[_vm._v(" "),_c('div',[_vm._v(_vm._s(_vm.annotationsTooltipContent))])]):_vm._e(),_vm._v(" "),(_vm.chart)?_c('chart-tooltip',{ref:"dataTooltip",attrs:{"chart":_vm.chart},scopedSlots:_vm._u([{key:"title",fn:function(){return [
|
|
279
|
+
var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"position-relative",class:( _obj = {}, _obj[_vm.$options.HEIGHT_AUTO_CLASSES] = _vm.autoHeight, _obj )},[_c('chart',_vm._g(_vm._b({class:{ 'gl-flex-grow-1': _vm.autoHeight },attrs:{"height":_vm.height,"options":_vm.options},on:{"created":_vm.onCreated}},'chart',_vm.$attrs,false),_vm.$listeners)),_vm._v(" "),(_vm.shouldShowAnnotationsTooltip)?_c('chart-tooltip',{ref:"annotationsTooltip",attrs:{"id":"annotationsTooltip","show":_vm.showAnnotationsTooltip,"top":_vm.annotationsTooltipPosition.top,"left":_vm.annotationsTooltipPosition.left,"chart":_vm.chart,"placement":"bottom"},scopedSlots:_vm._u([{key:"title",fn:function(){return [_c('div',[_vm._v(_vm._s(_vm.annotationsTooltipTitle))])]},proxy:true}],null,false,1889294429)},[_vm._v(" "),_c('div',[_vm._v(_vm._s(_vm.annotationsTooltipContent))])]):_vm._e(),_vm._v(" "),(_vm.chart)?_c('chart-tooltip',{ref:"dataTooltip",attrs:{"chart":_vm.chart,"use-default-tooltip-formatter":!_vm.formatTooltipText},scopedSlots:_vm._u([(_vm.$scopedSlots['tooltip-title'])?{key:"title",fn:function(scope){return [_vm._t("tooltip-title",null,null,scope)]}}:null,(_vm.$scopedSlots['tooltip-content'])?{key:"default",fn:function(scope){return [_vm._t("tooltip-content",null,null,scope)]}}:null,(_vm.$scopedSlots['tooltip-value'])?{key:"tooltip-value",fn:function(scope){return [_vm._t("tooltip-value",null,null,scope)]}}:null],null,true)}):_vm._e(),_vm._v(" "),(_vm.compiledOptions)?_c('chart-legend',{style:(_vm.legendStyle),attrs:{"chart":_vm.chart,"series-info":_vm.seriesInfo,"text-style":_vm.compiledOptions.textStyle,"min-text":_vm.legendMinText,"max-text":_vm.legendMaxText,"average-text":_vm.legendAverageText,"current-text":_vm.legendCurrentText,"layout":_vm.legendLayout}}):_vm._e()],1)};
|
|
291
280
|
var __vue_staticRenderFns__ = [];
|
|
292
281
|
|
|
293
282
|
/* style */
|
|
@@ -168,20 +168,19 @@ var script = {
|
|
|
168
168
|
const {
|
|
169
169
|
yLabels,
|
|
170
170
|
tooltipContent
|
|
171
|
-
} = this.
|
|
171
|
+
} = this.getTooltipContent(params, this.xAxisTitle);
|
|
172
172
|
this.$set(this, 'tooltipContent', tooltipContent);
|
|
173
173
|
this.tooltipTitle = yLabels.join(', ');
|
|
174
174
|
},
|
|
175
175
|
/**
|
|
176
|
-
*
|
|
177
|
-
* However, for bar charts, the tooltip should be against x-axis values.
|
|
176
|
+
* For bar charts, the tooltip should be against x-axis values.
|
|
178
177
|
* This method will be removed after https://gitlab.com/gitlab-org/gitlab-ui/-/issues/674
|
|
179
178
|
*
|
|
180
179
|
* @param {Object} params series data
|
|
181
180
|
* @param {String} xAxisTitle x-axis title
|
|
182
181
|
* @returns {Object} tooltip title and content
|
|
183
182
|
*/
|
|
184
|
-
|
|
183
|
+
getTooltipContent(params) {
|
|
185
184
|
let xAxisTitle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
186
185
|
const seriesDataLength = params.seriesData.length;
|
|
187
186
|
const {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import merge from 'lodash/merge';
|
|
2
|
-
import { yAxis, generateBarSeries, generateLineSeries, defaultChartOptions, gridWithSecondaryYAxis, grid, dataZoomAdjustments, mergeSeriesToOptions
|
|
2
|
+
import { yAxis, generateBarSeries, generateLineSeries, defaultChartOptions, gridWithSecondaryYAxis, grid, dataZoomAdjustments, mergeSeriesToOptions } from '../../../utils/charts/config';
|
|
3
3
|
import { CHART_TYPE_LINE, HEIGHT_AUTO_CLASSES } from '../../../utils/charts/constants';
|
|
4
4
|
import { colorFromDefaultPalette } from '../../../utils/charts/theme';
|
|
5
5
|
import { columnOptions } from '../../../utils/constants';
|
|
6
|
-
import TooltipDefaultFormat from '../../shared_components/charts/tooltip_default_format';
|
|
7
6
|
import Chart from '../chart/chart';
|
|
8
7
|
import ChartTooltip from '../tooltip/tooltip';
|
|
9
8
|
import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
|
|
@@ -20,8 +19,7 @@ var script = {
|
|
|
20
19
|
name: 'GlColumnChart',
|
|
21
20
|
components: {
|
|
22
21
|
Chart,
|
|
23
|
-
ChartTooltip
|
|
24
|
-
TooltipDefaultFormat
|
|
22
|
+
ChartTooltip
|
|
25
23
|
},
|
|
26
24
|
inheritAttrs: false,
|
|
27
25
|
props: {
|
|
@@ -74,9 +72,7 @@ var script = {
|
|
|
74
72
|
},
|
|
75
73
|
data() {
|
|
76
74
|
return {
|
|
77
|
-
chart: null
|
|
78
|
-
tooltipTitle: '',
|
|
79
|
-
tooltipContent: {}
|
|
75
|
+
chart: null
|
|
80
76
|
};
|
|
81
77
|
},
|
|
82
78
|
computed: {
|
|
@@ -158,11 +154,7 @@ var script = {
|
|
|
158
154
|
show: false
|
|
159
155
|
},
|
|
160
156
|
axisPointer: {
|
|
161
|
-
|
|
162
|
-
type: 'none',
|
|
163
|
-
label: {
|
|
164
|
-
formatter: this.onLabelChange
|
|
165
|
-
}
|
|
157
|
+
type: 'none'
|
|
166
158
|
},
|
|
167
159
|
name: this.xAxisTitle,
|
|
168
160
|
type: this.xAxisType
|
|
@@ -188,15 +180,6 @@ var script = {
|
|
|
188
180
|
onCreated(chart) {
|
|
189
181
|
this.chart = chart;
|
|
190
182
|
this.$emit('created', chart);
|
|
191
|
-
},
|
|
192
|
-
onLabelChange(params) {
|
|
193
|
-
// eslint-disable-next-line import/no-deprecated
|
|
194
|
-
const {
|
|
195
|
-
xLabels,
|
|
196
|
-
tooltipContent
|
|
197
|
-
} = getDefaultTooltipContent(params, this.yAxisTitle);
|
|
198
|
-
this.$set(this, 'tooltipContent', tooltipContent);
|
|
199
|
-
this.tooltipTitle = xLabels.join(', ');
|
|
200
183
|
}
|
|
201
184
|
},
|
|
202
185
|
HEIGHT_AUTO_CLASSES
|
|
@@ -208,7 +191,7 @@ const __vue_script__ = script;
|
|
|
208
191
|
/* template */
|
|
209
192
|
var __vue_render__ = function () {
|
|
210
193
|
var _obj;
|
|
211
|
-
var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"position-relative",class:( _obj = {}, _obj[_vm.$options.HEIGHT_AUTO_CLASSES] = _vm.autoHeight, _obj )},[_c('chart',_vm._g(_vm._b({class:{ 'gl-flex-grow-1': _vm.autoHeight },attrs:{"height":_vm.height,"options":_vm.options},on:{"created":_vm.onCreated}},'chart',_vm.$attrs,false),_vm.$listeners)),_vm._v(" "),(_vm.chart)?_c('chart-tooltip',{attrs:{"chart":_vm.chart
|
|
194
|
+
var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"position-relative",class:( _obj = {}, _obj[_vm.$options.HEIGHT_AUTO_CLASSES] = _vm.autoHeight, _obj )},[_c('chart',_vm._g(_vm._b({class:{ 'gl-flex-grow-1': _vm.autoHeight },attrs:{"height":_vm.height,"options":_vm.options},on:{"created":_vm.onCreated}},'chart',_vm.$attrs,false),_vm.$listeners)),_vm._v(" "),(_vm.chart)?_c('chart-tooltip',{attrs:{"chart":_vm.chart,"use-default-tooltip-formatter":true}}):_vm._e()],1)};
|
|
212
195
|
var __vue_staticRenderFns__ = [];
|
|
213
196
|
|
|
214
197
|
/* style */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import merge from 'lodash/merge';
|
|
2
2
|
import { GRAY_100, WHITE } from '../../../../dist/tokens/js/tokens';
|
|
3
|
-
import {
|
|
3
|
+
import { getTooltipTitle, getTooltipContent } from '../../../utils/charts/config';
|
|
4
4
|
import { HEIGHT_AUTO_CLASSES } from '../../../utils/charts/constants';
|
|
5
5
|
import { heatmapHues } from '../../../utils/charts/theme';
|
|
6
6
|
import { engineeringNotation } from '../../../utils/number_utils';
|
|
@@ -223,13 +223,8 @@ var script = {
|
|
|
223
223
|
},
|
|
224
224
|
methods: {
|
|
225
225
|
defaultFormatTooltipText(params) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
xLabels,
|
|
229
|
-
tooltipContent
|
|
230
|
-
} = getDefaultTooltipContent(params, this.computedOptions.yAxis.name);
|
|
231
|
-
this.$set(this.tooltip, 'content', tooltipContent);
|
|
232
|
-
this.tooltip.title = xLabels.join(', ');
|
|
226
|
+
this.tooltip.title = getTooltipTitle(params, this.computedOptions.xAxis.name);
|
|
227
|
+
this.tooltip.content = getTooltipContent(params, this.computedOptions.yAxis.name);
|
|
233
228
|
},
|
|
234
229
|
onCreated(chart) {
|
|
235
230
|
this.chart = chart;
|
|
@@ -265,7 +260,7 @@ const __vue_script__ = script;
|
|
|
265
260
|
/* template */
|
|
266
261
|
var __vue_render__ = function () {
|
|
267
262
|
var _obj;
|
|
268
|
-
var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"gl-heatmap",class:( _obj = {}, _obj[_vm.$options.HEIGHT_AUTO_CLASSES] = _vm.autoHeight, _obj )},[_c('chart',_vm._g(_vm._b({class:{ 'gl-flex-grow-1': _vm.autoHeight },attrs:{"height":_vm.height,"options":_vm.computedOptions},on:{"created":_vm.onCreated}},'chart',_vm.$attrs,false),_vm.$listeners)),_vm._v(" "),(_vm.chart)?_c('chart-tooltip',{attrs:{"chart":_vm.chart,"top":_vm.tooltip.top,"left":_vm.tooltip.left},scopedSlots:_vm._u([{key:"title",fn:function(){return [(_vm.formatTooltipText)?_vm._t("tooltip-title"):_c('div',[_vm._v(
|
|
263
|
+
var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"gl-heatmap",class:( _obj = {}, _obj[_vm.$options.HEIGHT_AUTO_CLASSES] = _vm.autoHeight, _obj )},[_c('chart',_vm._g(_vm._b({class:{ 'gl-flex-grow-1': _vm.autoHeight },attrs:{"height":_vm.height,"options":_vm.computedOptions},on:{"created":_vm.onCreated}},'chart',_vm.$attrs,false),_vm.$listeners)),_vm._v(" "),(_vm.chart)?_c('chart-tooltip',{attrs:{"chart":_vm.chart,"top":_vm.tooltip.top,"left":_vm.tooltip.left},scopedSlots:_vm._u([{key:"title",fn:function(){return [(_vm.formatTooltipText)?_vm._t("tooltip-title"):_c('div',[_vm._v(_vm._s(_vm.tooltip.title))])]},proxy:true}],null,true)},[_vm._v(" "),(_vm.formatTooltipText)?_vm._t("tooltip-content"):_c('tooltip-default-format',{attrs:{"tooltip-content":_vm.tooltip.content}})],2):_vm._e(),_vm._v(" "),(_vm.compiledOptions)?_c('chart-legend',{style:(_vm.legendStyle),attrs:{"chart":_vm.chart,"series-info":_vm.seriesInfo,"text-style":_vm.compiledOptions.textStyle,"max-text":_vm.legendMaxText,"average-text":_vm.legendAverageText}}):_vm._e()],1)};
|
|
269
264
|
var __vue_staticRenderFns__ = [];
|
|
270
265
|
|
|
271
266
|
/* style */
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import merge from 'lodash/merge';
|
|
2
2
|
import { GRAY_200 } from '../../../../dist/tokens/js/tokens';
|
|
3
|
-
import { symbolSize, lineStyle, getThresholdConfig, generateAnnotationSeries, defaultChartOptions, dataZoomAdjustments, mergeSeriesToOptions, mergeAnnotationAxisToOptions, grid
|
|
3
|
+
import { symbolSize, lineStyle, getThresholdConfig, generateAnnotationSeries, defaultChartOptions, dataZoomAdjustments, mergeSeriesToOptions, mergeAnnotationAxisToOptions, grid } from '../../../utils/charts/config';
|
|
4
4
|
import { LEGEND_AVERAGE_TEXT, LEGEND_MAX_TEXT, LEGEND_MIN_TEXT, LEGEND_CURRENT_TEXT, LEGEND_LAYOUT_INLINE, LEGEND_LAYOUT_TABLE, HEIGHT_AUTO_CLASSES } from '../../../utils/charts/constants';
|
|
5
5
|
import { colorFromDefaultPalette } from '../../../utils/charts/theme';
|
|
6
6
|
import { seriesHasAnnotations, isDataPointAnnotation } from '../../../utils/charts/utils';
|
|
7
|
-
import TooltipDefaultFormat from '../../shared_components/charts/tooltip_default_format';
|
|
8
7
|
import Chart from '../chart/chart';
|
|
9
8
|
import ChartLegend from '../legend/legend';
|
|
10
9
|
import ChartTooltip from '../tooltip/tooltip';
|
|
@@ -16,8 +15,7 @@ var script = {
|
|
|
16
15
|
components: {
|
|
17
16
|
Chart,
|
|
18
17
|
ChartLegend,
|
|
19
|
-
ChartTooltip
|
|
20
|
-
TooltipDefaultFormat
|
|
18
|
+
ChartTooltip
|
|
21
19
|
},
|
|
22
20
|
inheritAttrs: false,
|
|
23
21
|
props: {
|
|
@@ -45,6 +43,12 @@ var script = {
|
|
|
45
43
|
required: false,
|
|
46
44
|
default: true
|
|
47
45
|
},
|
|
46
|
+
/**
|
|
47
|
+
* Callback called when showing or refreshing a tooltip.
|
|
48
|
+
* **Deprecated:** Use slots `#tooltip-title`, `#tooltip-content` or `#tooltip-value`.
|
|
49
|
+
*
|
|
50
|
+
* @deprecated Use slots `#tooltip-title`, `#tooltip-content` or `#tooltip-value`.
|
|
51
|
+
*/
|
|
48
52
|
formatTooltipText: {
|
|
49
53
|
type: Function,
|
|
50
54
|
required: false,
|
|
@@ -99,16 +103,13 @@ var script = {
|
|
|
99
103
|
// https://gitlab.com/gitlab-org/gitlab-ui/-/issues/618
|
|
100
104
|
return {
|
|
101
105
|
chart: null,
|
|
102
|
-
dataTooltipTitle: '',
|
|
103
|
-
dataTooltipContent: {},
|
|
104
106
|
showAnnotationsTooltip: false,
|
|
105
107
|
annotationsTooltipTitle: '',
|
|
106
108
|
annotationsTooltipContent: '',
|
|
107
109
|
annotationsTooltipPosition: {
|
|
108
110
|
left: '0',
|
|
109
111
|
top: '0'
|
|
110
|
-
}
|
|
111
|
-
selectedFormatTooltipText: this.formatTooltipText || this.defaultFormatTooltipText
|
|
112
|
+
}
|
|
112
113
|
};
|
|
113
114
|
},
|
|
114
115
|
computed: {
|
|
@@ -145,7 +146,7 @@ var script = {
|
|
|
145
146
|
axisPointer: {
|
|
146
147
|
show: true,
|
|
147
148
|
label: {
|
|
148
|
-
formatter: this.
|
|
149
|
+
formatter: this.formatTooltipText
|
|
149
150
|
}
|
|
150
151
|
},
|
|
151
152
|
axisTick: {
|
|
@@ -211,15 +212,6 @@ var script = {
|
|
|
211
212
|
this.chart.off('mouseover', this.onChartDataPointMouseOver);
|
|
212
213
|
},
|
|
213
214
|
methods: {
|
|
214
|
-
defaultFormatTooltipText(params) {
|
|
215
|
-
// eslint-disable-next-line import/no-deprecated
|
|
216
|
-
const {
|
|
217
|
-
xLabels,
|
|
218
|
-
tooltipContent
|
|
219
|
-
} = getDefaultTooltipContent(params, this.options.yAxis.name);
|
|
220
|
-
this.$set(this, 'dataTooltipContent', tooltipContent);
|
|
221
|
-
this.dataTooltipTitle = xLabels.join(', ');
|
|
222
|
-
},
|
|
223
215
|
defaultAnnotationTooltipText(params) {
|
|
224
216
|
var _params$data$tooltipD;
|
|
225
217
|
return {
|
|
@@ -270,9 +262,6 @@ var script = {
|
|
|
270
262
|
top: `${event.event.zrY}px`
|
|
271
263
|
};
|
|
272
264
|
}
|
|
273
|
-
},
|
|
274
|
-
onLabelChange(params) {
|
|
275
|
-
this.selectedFormatTooltipText(params);
|
|
276
265
|
}
|
|
277
266
|
},
|
|
278
267
|
HEIGHT_AUTO_CLASSES
|
|
@@ -284,7 +273,7 @@ const __vue_script__ = script;
|
|
|
284
273
|
/* template */
|
|
285
274
|
var __vue_render__ = function () {
|
|
286
275
|
var _obj;
|
|
287
|
-
var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"position-relative",class:( _obj = {}, _obj[_vm.$options.HEIGHT_AUTO_CLASSES] = _vm.autoHeight, _obj )},[_c('chart',_vm._g(_vm._b({class:{ 'gl-flex-grow-1': _vm.autoHeight },attrs:{"height":_vm.height,"options":_vm.options},on:{"created":_vm.onCreated}},'chart',_vm.$attrs,false),_vm.$listeners)),_vm._v(" "),(_vm.shouldShowAnnotationsTooltip)?_c('chart-tooltip',{ref:"annotationsTooltip",attrs:{"id":"annotationsTooltip","show":_vm.showAnnotationsTooltip,"chart":_vm.chart,"top":_vm.annotationsTooltipPosition.top,"left":_vm.annotationsTooltipPosition.left,"placement":"bottom"},scopedSlots:_vm._u([{key:"title",fn:function(){return [_c('div',[_vm._v(_vm._s(_vm.annotationsTooltipTitle))])]},proxy:true}],null,false,1889294429)},[_vm._v(" "),_c('div',[_vm._v(_vm._s(_vm.annotationsTooltipContent))])]):_vm._e(),_vm._v(" "),(_vm.chart)?_c('chart-tooltip',{ref:"dataTooltip",attrs:{"chart":_vm.chart},scopedSlots:_vm._u([{key:"title",fn:function(){return [
|
|
276
|
+
var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"position-relative",class:( _obj = {}, _obj[_vm.$options.HEIGHT_AUTO_CLASSES] = _vm.autoHeight, _obj )},[_c('chart',_vm._g(_vm._b({class:{ 'gl-flex-grow-1': _vm.autoHeight },attrs:{"height":_vm.height,"options":_vm.options},on:{"created":_vm.onCreated}},'chart',_vm.$attrs,false),_vm.$listeners)),_vm._v(" "),(_vm.shouldShowAnnotationsTooltip)?_c('chart-tooltip',{ref:"annotationsTooltip",attrs:{"id":"annotationsTooltip","show":_vm.showAnnotationsTooltip,"chart":_vm.chart,"top":_vm.annotationsTooltipPosition.top,"left":_vm.annotationsTooltipPosition.left,"placement":"bottom"},scopedSlots:_vm._u([{key:"title",fn:function(){return [_c('div',[_vm._v(_vm._s(_vm.annotationsTooltipTitle))])]},proxy:true}],null,false,1889294429)},[_vm._v(" "),_c('div',[_vm._v(_vm._s(_vm.annotationsTooltipContent))])]):_vm._e(),_vm._v(" "),(_vm.chart)?_c('chart-tooltip',{ref:"dataTooltip",attrs:{"chart":_vm.chart,"use-default-tooltip-formatter":!_vm.formatTooltipText},scopedSlots:_vm._u([(_vm.$scopedSlots['tooltip-title'])?{key:"title",fn:function(scope){return [_vm._t("tooltip-title",null,null,scope)]}}:null,(_vm.$scopedSlots['tooltip-content'])?{key:"default",fn:function(scope){return [_vm._t("tooltip-content",null,null,scope)]}}:null,(_vm.$scopedSlots['tooltip-value'])?{key:"tooltip-value",fn:function(scope){return [_vm._t("tooltip-value",null,null,scope)]}}:null],null,true)}):_vm._e(),_vm._v(" "),(_vm.hasLegend)?_c('chart-legend',{style:(_vm.legendStyle),attrs:{"chart":_vm.chart,"series-info":_vm.seriesInfo,"text-style":_vm.compiledOptions.textStyle,"min-text":_vm.legendMinText,"max-text":_vm.legendMaxText,"average-text":_vm.legendAverageText,"current-text":_vm.legendCurrentText,"layout":_vm.legendLayout}}):_vm._e()],1)};
|
|
288
277
|
var __vue_staticRenderFns__ = [];
|
|
289
278
|
|
|
290
279
|
/* style */
|
package/dist/tokens/js/tokens.js
CHANGED
package/package.json
CHANGED
|
@@ -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
|
import Chart from '../chart/chart.vue';
|
|
8
12
|
import ChartLegend from '../legend/legend.vue';
|
|
@@ -24,13 +28,13 @@ describe('area component', () => {
|
|
|
24
28
|
|
|
25
29
|
const emitChartCreated = () => findChart().vm.$emit('created', mockChartInstance);
|
|
26
30
|
|
|
27
|
-
const createShallowWrapper = ({ props = {},
|
|
31
|
+
const createShallowWrapper = ({ props = {}, ...options } = {}) => {
|
|
28
32
|
wrapper = shallowMount(AreaChart, {
|
|
29
33
|
propsData: { option: { series: [] }, data: [], ...props },
|
|
30
34
|
stubs: {
|
|
31
35
|
'chart-tooltip': ChartTooltipStub,
|
|
32
36
|
},
|
|
33
|
-
|
|
37
|
+
...options,
|
|
34
38
|
});
|
|
35
39
|
emitChartCreated();
|
|
36
40
|
};
|
|
@@ -136,13 +140,84 @@ describe('area component', () => {
|
|
|
136
140
|
});
|
|
137
141
|
});
|
|
138
142
|
|
|
139
|
-
describe('data tooltip
|
|
140
|
-
|
|
143
|
+
describe('data tooltip', () => {
|
|
144
|
+
it('is initialized', async () => {
|
|
141
145
|
createShallowWrapper();
|
|
146
|
+
|
|
147
|
+
await nextTick();
|
|
148
|
+
|
|
149
|
+
expect(findDataTooltip().props()).toMatchObject({
|
|
150
|
+
useDefaultTooltipFormatter: true,
|
|
151
|
+
chart: mockChartInstance,
|
|
152
|
+
});
|
|
142
153
|
});
|
|
143
154
|
|
|
144
|
-
|
|
145
|
-
|
|
155
|
+
describe('is customized via slots', () => {
|
|
156
|
+
const { params, title, content } = chartTooltipStubData;
|
|
157
|
+
const value = params.seriesData[0].value[1];
|
|
158
|
+
|
|
159
|
+
it('customizes tooltip value', async () => {
|
|
160
|
+
const tooltipValueSlot = jest.fn().mockReturnValue('Value');
|
|
161
|
+
|
|
162
|
+
createShallowWrapper({
|
|
163
|
+
scopedSlots: {
|
|
164
|
+
'tooltip-value': tooltipValueSlot,
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
await nextTick();
|
|
168
|
+
|
|
169
|
+
expect(tooltipValueSlot).toHaveBeenCalledWith({ value });
|
|
170
|
+
expect(findDataTooltip().text()).toBe('Value');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('customizes title', async () => {
|
|
174
|
+
const tooltipTitleSlot = jest.fn().mockReturnValue('Title');
|
|
175
|
+
|
|
176
|
+
createShallowWrapper({
|
|
177
|
+
scopedSlots: {
|
|
178
|
+
'tooltip-title': tooltipTitleSlot,
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
await nextTick();
|
|
182
|
+
|
|
183
|
+
expect(tooltipTitleSlot).toHaveBeenCalledWith({
|
|
184
|
+
params,
|
|
185
|
+
title,
|
|
186
|
+
});
|
|
187
|
+
expect(findDataTooltip().text()).toBe('Title');
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('customizes content', async () => {
|
|
191
|
+
const tooltipContentSlot = jest.fn().mockReturnValue('Title');
|
|
192
|
+
|
|
193
|
+
createShallowWrapper({
|
|
194
|
+
scopedSlots: {
|
|
195
|
+
'tooltip-content': tooltipContentSlot,
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
await nextTick();
|
|
199
|
+
|
|
200
|
+
expect(tooltipContentSlot).toHaveBeenCalledWith({
|
|
201
|
+
params,
|
|
202
|
+
content,
|
|
203
|
+
});
|
|
204
|
+
expect(findDataTooltip().text()).toBe('Title');
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('is customized via formatting function', async () => {
|
|
209
|
+
createShallowWrapper({
|
|
210
|
+
props: {
|
|
211
|
+
formatTooltipText: jest.fn(),
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
await nextTick();
|
|
216
|
+
|
|
217
|
+
expect(findDataTooltip().props()).toMatchObject({
|
|
218
|
+
useDefaultTooltipFormatter: false,
|
|
219
|
+
chart: mockChartInstance,
|
|
220
|
+
});
|
|
146
221
|
});
|
|
147
222
|
});
|
|
148
223
|
|
|
@@ -7,6 +7,9 @@ import { timeSeriesDateFormatter } from '../../../utils/charts/utils';
|
|
|
7
7
|
import { generateTimeSeries } from '../../../utils/data_utils';
|
|
8
8
|
import { disableControls } from '../../../utils/stories_utils';
|
|
9
9
|
|
|
10
|
+
const components = {
|
|
11
|
+
GlAreaChart,
|
|
12
|
+
};
|
|
10
13
|
const defaultData = [
|
|
11
14
|
{
|
|
12
15
|
name: 'First Series',
|
|
@@ -29,7 +32,7 @@ const defaultOptions = {
|
|
|
29
32
|
},
|
|
30
33
|
};
|
|
31
34
|
|
|
32
|
-
const template = `<gl-area-chart
|
|
35
|
+
const template = (content) => `<gl-area-chart
|
|
33
36
|
:data="data"
|
|
34
37
|
:option="option"
|
|
35
38
|
:thresholds="thresholds"
|
|
@@ -37,7 +40,9 @@ const template = `<gl-area-chart
|
|
|
37
40
|
:includeLegendAvgMax="includeLegendAvgMax"
|
|
38
41
|
:height="height"
|
|
39
42
|
:legendSeriesInfo="legendSeriesInfo"
|
|
40
|
-
|
|
43
|
+
>
|
|
44
|
+
${content}
|
|
45
|
+
</gl-area-chart>`;
|
|
41
46
|
|
|
42
47
|
const generateProps = ({
|
|
43
48
|
data = defaultData,
|
|
@@ -58,11 +63,9 @@ const generateProps = ({
|
|
|
58
63
|
});
|
|
59
64
|
|
|
60
65
|
const Template = (args, { argTypes }) => ({
|
|
61
|
-
components
|
|
62
|
-
GlAreaChart,
|
|
63
|
-
},
|
|
66
|
+
components,
|
|
64
67
|
props: Object.keys(argTypes),
|
|
65
|
-
template,
|
|
68
|
+
template: template(),
|
|
66
69
|
});
|
|
67
70
|
|
|
68
71
|
export const Default = Template.bind({});
|
|
@@ -175,6 +178,21 @@ WithCustomLegendItems.args = generateProps({
|
|
|
175
178
|
],
|
|
176
179
|
});
|
|
177
180
|
|
|
181
|
+
export const WithCustomTooltip = (_args, { argTypes }) => ({
|
|
182
|
+
props: Object.keys(argTypes),
|
|
183
|
+
components,
|
|
184
|
+
template: template(`
|
|
185
|
+
<template #tooltip-title="{ params }">{{params && params.value}}</template>
|
|
186
|
+
<template #tooltip-content="{ params }">
|
|
187
|
+
<div v-if="params">{{params.seriesData[0].seriesName}}: {{params.seriesData[0].value[1]}}</div>
|
|
188
|
+
</template>
|
|
189
|
+
`),
|
|
190
|
+
});
|
|
191
|
+
WithCustomTooltip.args = generateProps();
|
|
192
|
+
WithCustomTooltip.parameters = {
|
|
193
|
+
storyshots: { disable: true },
|
|
194
|
+
};
|
|
195
|
+
|
|
178
196
|
export default {
|
|
179
197
|
title: 'charts/area-chart',
|
|
180
198
|
component: GlAreaChart,
|