@gitlab/ui 122.4.0 → 122.5.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/dist/components/charts/bar/bar.js +3 -58
- package/dist/components/charts/shared/tooltip/tooltip.js +26 -7
- package/dist/utils/charts/config.js +26 -7
- package/package.json +1 -1
- package/src/components/charts/bar/bar.vue +14 -55
- package/src/components/charts/shared/tooltip/tooltip.vue +29 -6
- package/src/utils/charts/config.js +22 -11
|
@@ -5,7 +5,6 @@ import { CHART_DEFAULT_SERIES_STACK, HEIGHT_AUTO_CLASSES } from '../../../utils/
|
|
|
5
5
|
import { colorFromDefaultPalette } from '../../../utils/charts/theme';
|
|
6
6
|
import { engineeringNotation } from '../../../utils/number_utils';
|
|
7
7
|
import { hexToRgba } from '../../../utils/utils';
|
|
8
|
-
import TooltipDefaultFormat from '../shared/tooltip/tooltip_default_format/tooltip_default_format';
|
|
9
8
|
import Chart from '../chart/chart';
|
|
10
9
|
import ChartTooltip from '../shared/tooltip/tooltip';
|
|
11
10
|
import { stackedPresentationOptions } from '../../../utils/constants';
|
|
@@ -63,8 +62,7 @@ var script = {
|
|
|
63
62
|
name: 'GlBarChart',
|
|
64
63
|
components: {
|
|
65
64
|
Chart,
|
|
66
|
-
ChartTooltip
|
|
67
|
-
TooltipDefaultFormat
|
|
65
|
+
ChartTooltip
|
|
68
66
|
},
|
|
69
67
|
inheritAttrs: false,
|
|
70
68
|
props: {
|
|
@@ -112,9 +110,7 @@ var script = {
|
|
|
112
110
|
},
|
|
113
111
|
data() {
|
|
114
112
|
return {
|
|
115
|
-
chart: null
|
|
116
|
-
tooltipTitle: '',
|
|
117
|
-
tooltipContent: {}
|
|
113
|
+
chart: null
|
|
118
114
|
};
|
|
119
115
|
},
|
|
120
116
|
computed: {
|
|
@@ -154,13 +150,6 @@ var script = {
|
|
|
154
150
|
type: 'category',
|
|
155
151
|
axisTick: {
|
|
156
152
|
show: true
|
|
157
|
-
},
|
|
158
|
-
axisPointer: {
|
|
159
|
-
show: true,
|
|
160
|
-
type: 'none',
|
|
161
|
-
label: {
|
|
162
|
-
formatter: this.onLabelChange
|
|
163
|
-
}
|
|
164
153
|
}
|
|
165
154
|
}
|
|
166
155
|
}, this.option, dataZoomAdjustments(this.option.dataZoom));
|
|
@@ -176,50 +165,6 @@ var script = {
|
|
|
176
165
|
onCreated(chart) {
|
|
177
166
|
this.chart = chart;
|
|
178
167
|
this.$emit('created', chart);
|
|
179
|
-
},
|
|
180
|
-
onLabelChange(params) {
|
|
181
|
-
const {
|
|
182
|
-
yLabels,
|
|
183
|
-
tooltipContent
|
|
184
|
-
} = this.getTooltipContent(params, this.xAxisTitle);
|
|
185
|
-
this.$set(this, 'tooltipContent', tooltipContent);
|
|
186
|
-
this.tooltipTitle = yLabels.join(', ');
|
|
187
|
-
},
|
|
188
|
-
/**
|
|
189
|
-
* For bar charts, the tooltip should be against x-axis values.
|
|
190
|
-
* This method will be removed after https://gitlab.com/gitlab-org/gitlab-ui/-/issues/674
|
|
191
|
-
*
|
|
192
|
-
* @param {Object} params series data
|
|
193
|
-
* @param {String} xAxisTitle x-axis title
|
|
194
|
-
* @returns {Object} tooltip title and content
|
|
195
|
-
*/
|
|
196
|
-
getTooltipContent(params) {
|
|
197
|
-
let xAxisTitle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
198
|
-
const seriesDataLength = params.seriesData.length;
|
|
199
|
-
const {
|
|
200
|
-
yLabels,
|
|
201
|
-
tooltipContent
|
|
202
|
-
} = params.seriesData.reduce((acc, chartItem) => {
|
|
203
|
-
const [value, title] = chartItem.value || [];
|
|
204
|
-
// The x axis title is used instead of y axis
|
|
205
|
-
const seriesName = seriesDataLength === 1 && xAxisTitle ? xAxisTitle : chartItem.seriesName;
|
|
206
|
-
const color = seriesDataLength === 1 ? '' : chartItem.color;
|
|
207
|
-
acc.tooltipContent[seriesName] = {
|
|
208
|
-
value,
|
|
209
|
-
color
|
|
210
|
-
};
|
|
211
|
-
if (!acc.yLabels.includes(title)) {
|
|
212
|
-
acc.yLabels.push(title);
|
|
213
|
-
}
|
|
214
|
-
return acc;
|
|
215
|
-
}, {
|
|
216
|
-
yLabels: [],
|
|
217
|
-
tooltipContent: {}
|
|
218
|
-
});
|
|
219
|
-
return {
|
|
220
|
-
yLabels,
|
|
221
|
-
tooltipContent
|
|
222
|
-
};
|
|
223
168
|
}
|
|
224
169
|
},
|
|
225
170
|
HEIGHT_AUTO_CLASSES
|
|
@@ -231,7 +176,7 @@ const __vue_script__ = script;
|
|
|
231
176
|
/* template */
|
|
232
177
|
var __vue_render__ = function () {
|
|
233
178
|
var _obj;
|
|
234
|
-
var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"gl-relative",class:( _obj = {}, _obj[_vm.$options.HEIGHT_AUTO_CLASSES] = _vm.autoHeight, _obj )},[_c('chart',_vm._g(_vm._b({class:{ 'gl-grow': _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},scopedSlots:_vm._u([{key:"title",fn:function(){return [
|
|
179
|
+
var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"gl-relative",class:( _obj = {}, _obj[_vm.$options.HEIGHT_AUTO_CLASSES] = _vm.autoHeight, _obj )},[_c('chart',_vm._g(_vm._b({class:{ 'gl-grow': _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,"dimension-axis":"yAxis"},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()],1)};
|
|
235
180
|
var __vue_staticRenderFns__ = [];
|
|
236
181
|
|
|
237
182
|
/* style */
|
|
@@ -3,7 +3,7 @@ import { uid, debounceByAnimationFrame } from '../../../../utils/utils';
|
|
|
3
3
|
import GlPopover from '../../../base/popover/popover';
|
|
4
4
|
import { popoverPlacements } from '../../../../utils/constants';
|
|
5
5
|
import { TOOLTIP_LEFT_OFFSET, TOOLTIP_TOP_OFFSET } from '../../../../utils/charts/constants';
|
|
6
|
-
import { getTooltipTitle, getTooltipContent } from '../../../../utils/charts/config';
|
|
6
|
+
import { getTooltipAxisConfig, getTooltipTitle, getTooltipContent } from '../../../../utils/charts/config';
|
|
7
7
|
import TooltipDefaultFormat from './tooltip_default_format/tooltip_default_format';
|
|
8
8
|
import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
|
|
9
9
|
|
|
@@ -125,6 +125,20 @@ var script = {
|
|
|
125
125
|
type: Boolean,
|
|
126
126
|
required: false,
|
|
127
127
|
default: false
|
|
128
|
+
},
|
|
129
|
+
/**
|
|
130
|
+
* Specifies which axis contains the dimensional data used in the tooltip.
|
|
131
|
+
* When `xAxis`, x-axis value becomes the tooltip's title and
|
|
132
|
+
* y-axis values become the tooltip's values.
|
|
133
|
+
* When `yAxis`, roles are reversed.
|
|
134
|
+
*/
|
|
135
|
+
dimensionAxis: {
|
|
136
|
+
type: String,
|
|
137
|
+
required: false,
|
|
138
|
+
default: 'xAxis',
|
|
139
|
+
validator(value) {
|
|
140
|
+
return value === 'xAxis' || value === 'yAxis';
|
|
141
|
+
}
|
|
128
142
|
}
|
|
129
143
|
},
|
|
130
144
|
data() {
|
|
@@ -209,17 +223,22 @@ var script = {
|
|
|
209
223
|
}
|
|
210
224
|
if (this.useDefaultTooltipFormatter) {
|
|
211
225
|
this.chart.setOption({
|
|
212
|
-
|
|
226
|
+
[this.dimensionAxis]: {
|
|
213
227
|
axisPointer: {
|
|
214
228
|
show: true,
|
|
215
229
|
label: {
|
|
216
230
|
formatter: params => {
|
|
217
|
-
var _options$
|
|
231
|
+
var _options$this$dimensi, _options$this$dimensi2, _options$valueAxis, _options$valueAxis$;
|
|
218
232
|
const options = this.chart.getOption();
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
233
|
+
const {
|
|
234
|
+
dimensionIndex,
|
|
235
|
+
metricIndex,
|
|
236
|
+
valueAxis
|
|
237
|
+
} = getTooltipAxisConfig(this.dimensionAxis);
|
|
238
|
+
const titleAxisName = (_options$this$dimensi = options[this.dimensionAxis]) === null || _options$this$dimensi === void 0 ? void 0 : (_options$this$dimensi2 = _options$this$dimensi[0]) === null || _options$this$dimensi2 === void 0 ? void 0 : _options$this$dimensi2.name;
|
|
239
|
+
const valueAxisName = (_options$valueAxis = options[valueAxis]) === null || _options$valueAxis === void 0 ? void 0 : (_options$valueAxis$ = _options$valueAxis[0]) === null || _options$valueAxis$ === void 0 ? void 0 : _options$valueAxis$.name;
|
|
240
|
+
this.title = getTooltipTitle(params, titleAxisName, dimensionIndex);
|
|
241
|
+
this.content = getTooltipContent(params, valueAxisName, metricIndex);
|
|
223
242
|
this.params = params;
|
|
224
243
|
}
|
|
225
244
|
}
|
|
@@ -468,24 +468,44 @@ const generateLineSeries = _ref5 => {
|
|
|
468
468
|
}
|
|
469
469
|
};
|
|
470
470
|
};
|
|
471
|
+
const getTooltipAxisConfig = dimensionAxis => {
|
|
472
|
+
if (!['xAxis', 'yAxis'].includes(dimensionAxis)) {
|
|
473
|
+
throw new Error(`\`dimensionAxis\` must be "xAxis" or "yAxis", received ${dimensionAxis}`);
|
|
474
|
+
}
|
|
475
|
+
if (dimensionAxis === 'xAxis') {
|
|
476
|
+
return {
|
|
477
|
+
dimensionIndex: 0,
|
|
478
|
+
metricIndex: 1,
|
|
479
|
+
valueAxis: 'yAxis'
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
return {
|
|
483
|
+
dimensionIndex: 1,
|
|
484
|
+
metricIndex: 0,
|
|
485
|
+
valueAxis: 'xAxis'
|
|
486
|
+
};
|
|
487
|
+
};
|
|
471
488
|
const getTooltipTitle = function () {
|
|
472
489
|
let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
473
490
|
let titleAxisName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
491
|
+
let dimensionIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
474
492
|
if (!params) return '';
|
|
475
493
|
const title = params.seriesData.reduce((acc, _ref6) => {
|
|
476
494
|
let {
|
|
477
495
|
value
|
|
478
496
|
} = _ref6;
|
|
479
|
-
|
|
497
|
+
const dimension = value[dimensionIndex];
|
|
498
|
+
if (acc.includes(dimension)) {
|
|
480
499
|
return acc;
|
|
481
500
|
}
|
|
482
|
-
return [...acc,
|
|
501
|
+
return [...acc, dimension];
|
|
483
502
|
}, []).join(', ');
|
|
484
503
|
return titleAxisName ? `${title} (${titleAxisName})` : title;
|
|
485
504
|
};
|
|
486
505
|
const getTooltipContent = function () {
|
|
487
506
|
let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
488
507
|
let valueAxisName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
508
|
+
let metricIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
489
509
|
if (!params) {
|
|
490
510
|
return {};
|
|
491
511
|
}
|
|
@@ -494,12 +514,12 @@ const getTooltipContent = function () {
|
|
|
494
514
|
} = params;
|
|
495
515
|
if (seriesData.length === 1) {
|
|
496
516
|
const {
|
|
497
|
-
value
|
|
517
|
+
value,
|
|
498
518
|
seriesName
|
|
499
519
|
} = seriesData[0];
|
|
500
520
|
return {
|
|
501
521
|
[valueAxisName || seriesName]: {
|
|
502
|
-
value:
|
|
522
|
+
value: value[metricIndex],
|
|
503
523
|
color: '' // ignore color when showing a single series
|
|
504
524
|
}
|
|
505
525
|
};
|
|
@@ -510,9 +530,8 @@ const getTooltipContent = function () {
|
|
|
510
530
|
seriesName,
|
|
511
531
|
color
|
|
512
532
|
} = _ref7;
|
|
513
|
-
const yValue = value[1];
|
|
514
533
|
acc[seriesName] = {
|
|
515
|
-
value:
|
|
534
|
+
value: value[metricIndex],
|
|
516
535
|
color
|
|
517
536
|
};
|
|
518
537
|
return acc;
|
|
@@ -560,4 +579,4 @@ const getDefaultTooltipContent = function (params) {
|
|
|
560
579
|
};
|
|
561
580
|
};
|
|
562
581
|
|
|
563
|
-
export { annotationsYAxisCoords, axes, dataZoomAdjustments, defaultAreaOpacity, defaultChartOptions, defaultFontSize, defaultHeight, defaultWidth, generateAnnotationSeries, generateBarSeries, generateLineSeries, getAnnotationsConfig, getDataZoomConfig, getDefaultTooltipContent, getThresholdConfig, getTooltipContent, getTooltipTitle, grid, gridWithSecondaryYAxis, lineStyle, mergeAnnotationAxisToOptions, mergeSeriesToOptions, parseAnnotations, symbolSize, toolboxHeight, validRenderers, xAxis, yAxis };
|
|
582
|
+
export { annotationsYAxisCoords, axes, dataZoomAdjustments, defaultAreaOpacity, defaultChartOptions, defaultFontSize, defaultHeight, defaultWidth, generateAnnotationSeries, generateBarSeries, generateLineSeries, getAnnotationsConfig, getDataZoomConfig, getDefaultTooltipContent, getThresholdConfig, getTooltipAxisConfig, getTooltipContent, getTooltipTitle, grid, gridWithSecondaryYAxis, lineStyle, mergeAnnotationAxisToOptions, mergeSeriesToOptions, parseAnnotations, symbolSize, toolboxHeight, validRenderers, xAxis, yAxis };
|
package/package.json
CHANGED
|
@@ -7,7 +7,6 @@ import { CHART_DEFAULT_SERIES_STACK, HEIGHT_AUTO_CLASSES } from '../../../utils/
|
|
|
7
7
|
import { colorFromDefaultPalette } from '../../../utils/charts/theme';
|
|
8
8
|
import { engineeringNotation } from '../../../utils/number_utils';
|
|
9
9
|
import { hexToRgba } from '../../../utils/utils';
|
|
10
|
-
import TooltipDefaultFormat from '../shared/tooltip/tooltip_default_format/tooltip_default_format.vue';
|
|
11
10
|
import Chart from '../chart/chart.vue';
|
|
12
11
|
import ChartTooltip from '../shared/tooltip/tooltip.vue';
|
|
13
12
|
import { stackedPresentationOptions } from '../../../utils/constants';
|
|
@@ -64,7 +63,6 @@ export default {
|
|
|
64
63
|
components: {
|
|
65
64
|
Chart,
|
|
66
65
|
ChartTooltip,
|
|
67
|
-
TooltipDefaultFormat,
|
|
68
66
|
},
|
|
69
67
|
inheritAttrs: false,
|
|
70
68
|
props: {
|
|
@@ -113,8 +111,6 @@ export default {
|
|
|
113
111
|
data() {
|
|
114
112
|
return {
|
|
115
113
|
chart: null,
|
|
116
|
-
tooltipTitle: '',
|
|
117
|
-
tooltipContent: {},
|
|
118
114
|
};
|
|
119
115
|
},
|
|
120
116
|
computed: {
|
|
@@ -162,13 +158,6 @@ export default {
|
|
|
162
158
|
axisTick: {
|
|
163
159
|
show: true,
|
|
164
160
|
},
|
|
165
|
-
axisPointer: {
|
|
166
|
-
show: true,
|
|
167
|
-
type: 'none',
|
|
168
|
-
label: {
|
|
169
|
-
formatter: this.onLabelChange,
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
161
|
},
|
|
173
162
|
},
|
|
174
163
|
this.option,
|
|
@@ -187,46 +176,6 @@ export default {
|
|
|
187
176
|
this.chart = chart;
|
|
188
177
|
this.$emit('created', chart);
|
|
189
178
|
},
|
|
190
|
-
onLabelChange(params) {
|
|
191
|
-
const { yLabels, tooltipContent } = this.getTooltipContent(params, this.xAxisTitle);
|
|
192
|
-
|
|
193
|
-
this.$set(this, 'tooltipContent', tooltipContent);
|
|
194
|
-
this.tooltipTitle = yLabels.join(', ');
|
|
195
|
-
},
|
|
196
|
-
/**
|
|
197
|
-
* For bar charts, the tooltip should be against x-axis values.
|
|
198
|
-
* This method will be removed after https://gitlab.com/gitlab-org/gitlab-ui/-/issues/674
|
|
199
|
-
*
|
|
200
|
-
* @param {Object} params series data
|
|
201
|
-
* @param {String} xAxisTitle x-axis title
|
|
202
|
-
* @returns {Object} tooltip title and content
|
|
203
|
-
*/
|
|
204
|
-
getTooltipContent(params, xAxisTitle = null) {
|
|
205
|
-
const seriesDataLength = params.seriesData.length;
|
|
206
|
-
const { yLabels, tooltipContent } = params.seriesData.reduce(
|
|
207
|
-
(acc, chartItem) => {
|
|
208
|
-
const [value, title] = chartItem.value || [];
|
|
209
|
-
// The x axis title is used instead of y axis
|
|
210
|
-
const seriesName =
|
|
211
|
-
seriesDataLength === 1 && xAxisTitle ? xAxisTitle : chartItem.seriesName;
|
|
212
|
-
const color = seriesDataLength === 1 ? '' : chartItem.color;
|
|
213
|
-
acc.tooltipContent[seriesName] = {
|
|
214
|
-
value,
|
|
215
|
-
color,
|
|
216
|
-
};
|
|
217
|
-
if (!acc.yLabels.includes(title)) {
|
|
218
|
-
acc.yLabels.push(title);
|
|
219
|
-
}
|
|
220
|
-
return acc;
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
yLabels: [],
|
|
224
|
-
tooltipContent: {},
|
|
225
|
-
},
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
return { yLabels, tooltipContent };
|
|
229
|
-
},
|
|
230
179
|
},
|
|
231
180
|
HEIGHT_AUTO_CLASSES,
|
|
232
181
|
};
|
|
@@ -242,11 +191,21 @@ export default {
|
|
|
242
191
|
v-on="$listeners"
|
|
243
192
|
@created="onCreated"
|
|
244
193
|
/>
|
|
245
|
-
<chart-tooltip
|
|
246
|
-
|
|
247
|
-
|
|
194
|
+
<chart-tooltip
|
|
195
|
+
v-if="chart"
|
|
196
|
+
:chart="chart"
|
|
197
|
+
:use-default-tooltip-formatter="true"
|
|
198
|
+
dimension-axis="yAxis"
|
|
199
|
+
>
|
|
200
|
+
<template v-if="$scopedSlots['tooltip-title']" #title="scope">
|
|
201
|
+
<slot name="tooltip-title" v-bind="scope"></slot>
|
|
202
|
+
</template>
|
|
203
|
+
<template v-if="$scopedSlots['tooltip-content']" #default="scope">
|
|
204
|
+
<slot name="tooltip-content" v-bind="scope"></slot>
|
|
205
|
+
</template>
|
|
206
|
+
<template v-if="$scopedSlots['tooltip-value']" #tooltip-value="scope">
|
|
207
|
+
<slot name="tooltip-value" v-bind="scope"></slot>
|
|
248
208
|
</template>
|
|
249
|
-
<tooltip-default-format :tooltip-content="tooltipContent" />
|
|
250
209
|
</chart-tooltip>
|
|
251
210
|
</div>
|
|
252
211
|
</template>
|
|
@@ -5,7 +5,11 @@ import { uid, debounceByAnimationFrame } from '../../../../utils/utils';
|
|
|
5
5
|
import GlPopover from '../../../base/popover/popover.vue';
|
|
6
6
|
import { popoverPlacements } from '../../../../utils/constants';
|
|
7
7
|
import { TOOLTIP_LEFT_OFFSET, TOOLTIP_TOP_OFFSET } from '../../../../utils/charts/constants';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
getTooltipTitle,
|
|
10
|
+
getTooltipContent,
|
|
11
|
+
getTooltipAxisConfig,
|
|
12
|
+
} from '../../../../utils/charts/config';
|
|
9
13
|
|
|
10
14
|
import TooltipDefaultFormat from './tooltip_default_format/tooltip_default_format.vue';
|
|
11
15
|
|
|
@@ -127,6 +131,20 @@ export default {
|
|
|
127
131
|
required: false,
|
|
128
132
|
default: false,
|
|
129
133
|
},
|
|
134
|
+
/**
|
|
135
|
+
* Specifies which axis contains the dimensional data used in the tooltip.
|
|
136
|
+
* When `xAxis`, x-axis value becomes the tooltip's title and
|
|
137
|
+
* y-axis values become the tooltip's values.
|
|
138
|
+
* When `yAxis`, roles are reversed.
|
|
139
|
+
*/
|
|
140
|
+
dimensionAxis: {
|
|
141
|
+
type: String,
|
|
142
|
+
required: false,
|
|
143
|
+
default: 'xAxis',
|
|
144
|
+
validator(value) {
|
|
145
|
+
return value === 'xAxis' || value === 'yAxis';
|
|
146
|
+
},
|
|
147
|
+
},
|
|
130
148
|
},
|
|
131
149
|
data() {
|
|
132
150
|
return {
|
|
@@ -208,17 +226,22 @@ export default {
|
|
|
208
226
|
|
|
209
227
|
if (this.useDefaultTooltipFormatter) {
|
|
210
228
|
this.chart.setOption({
|
|
211
|
-
|
|
229
|
+
[this.dimensionAxis]: {
|
|
212
230
|
axisPointer: {
|
|
213
231
|
show: true,
|
|
214
232
|
label: {
|
|
215
233
|
formatter: (params) => {
|
|
216
234
|
const options = this.chart.getOption();
|
|
217
|
-
const titleAxisName = options.xAxis?.[0]?.name;
|
|
218
|
-
const valueAxisName = options.yAxis?.[0]?.name;
|
|
219
235
|
|
|
220
|
-
|
|
221
|
-
|
|
236
|
+
const { dimensionIndex, metricIndex, valueAxis } = getTooltipAxisConfig(
|
|
237
|
+
this.dimensionAxis,
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
const titleAxisName = options[this.dimensionAxis]?.[0]?.name;
|
|
241
|
+
const valueAxisName = options[valueAxis]?.[0]?.name;
|
|
242
|
+
|
|
243
|
+
this.title = getTooltipTitle(params, titleAxisName, dimensionIndex);
|
|
244
|
+
this.content = getTooltipContent(params, valueAxisName, metricIndex);
|
|
222
245
|
this.params = params;
|
|
223
246
|
},
|
|
224
247
|
},
|
|
@@ -432,22 +432,36 @@ export const generateLineSeries = ({ name, color, data = [], yAxisIndex = 0 }) =
|
|
|
432
432
|
itemStyle: { color },
|
|
433
433
|
});
|
|
434
434
|
|
|
435
|
-
export const
|
|
435
|
+
export const getTooltipAxisConfig = (dimensionAxis) => {
|
|
436
|
+
if (!['xAxis', 'yAxis'].includes(dimensionAxis)) {
|
|
437
|
+
throw new Error(`\`dimensionAxis\` must be "xAxis" or "yAxis", received ${dimensionAxis}`);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
if (dimensionAxis === 'xAxis') {
|
|
441
|
+
return { dimensionIndex: 0, metricIndex: 1, valueAxis: 'yAxis' };
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
return { dimensionIndex: 1, metricIndex: 0, valueAxis: 'xAxis' };
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
export const getTooltipTitle = (params = null, titleAxisName = null, dimensionIndex = 0) => {
|
|
436
448
|
if (!params) return '';
|
|
437
449
|
|
|
438
450
|
const title = params.seriesData
|
|
439
451
|
.reduce((acc, { value }) => {
|
|
440
|
-
|
|
452
|
+
const dimension = value[dimensionIndex];
|
|
453
|
+
|
|
454
|
+
if (acc.includes(dimension)) {
|
|
441
455
|
return acc;
|
|
442
456
|
}
|
|
443
|
-
return [...acc,
|
|
457
|
+
return [...acc, dimension];
|
|
444
458
|
}, [])
|
|
445
459
|
.join(', ');
|
|
446
460
|
|
|
447
461
|
return titleAxisName ? `${title} (${titleAxisName})` : title;
|
|
448
462
|
};
|
|
449
463
|
|
|
450
|
-
export const getTooltipContent = (params = null, valueAxisName = null) => {
|
|
464
|
+
export const getTooltipContent = (params = null, valueAxisName = null, metricIndex = 1) => {
|
|
451
465
|
if (!params) {
|
|
452
466
|
return {};
|
|
453
467
|
}
|
|
@@ -455,22 +469,19 @@ export const getTooltipContent = (params = null, valueAxisName = null) => {
|
|
|
455
469
|
const { seriesData } = params;
|
|
456
470
|
|
|
457
471
|
if (seriesData.length === 1) {
|
|
458
|
-
const {
|
|
459
|
-
value: [, yValue],
|
|
460
|
-
seriesName,
|
|
461
|
-
} = seriesData[0];
|
|
472
|
+
const { value, seriesName } = seriesData[0];
|
|
462
473
|
|
|
463
474
|
return {
|
|
464
475
|
[valueAxisName || seriesName]: {
|
|
465
|
-
value:
|
|
476
|
+
value: value[metricIndex],
|
|
466
477
|
color: '', // ignore color when showing a single series
|
|
467
478
|
},
|
|
468
479
|
};
|
|
469
480
|
}
|
|
470
481
|
|
|
471
482
|
return seriesData.reduce((acc, { value, seriesName, color }) => {
|
|
472
|
-
|
|
473
|
-
|
|
483
|
+
acc[seriesName] = { value: value[metricIndex], color };
|
|
484
|
+
|
|
474
485
|
return acc;
|
|
475
486
|
}, {});
|
|
476
487
|
};
|