@gitlab/ui 108.6.0 → 108.7.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 CHANGED
@@ -1,3 +1,10 @@
1
+ # [108.7.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v108.6.0...v108.7.0) (2025-02-26)
2
+
3
+
4
+ ### Features
5
+
6
+ * **GlStackedColumnChart:** Simplify chart tooltip API ([837c638](https://gitlab.com/gitlab-org/gitlab-ui/commit/837c638616a4cf1856482859b04a8315f2c99b65))
7
+
1
8
  # [108.6.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v108.5.0...v108.6.0) (2025-02-26)
2
9
 
3
10
 
@@ -3,10 +3,10 @@ import { yAxis, generateBarSeries, generateLineSeries, defaultChartOptions, grid
3
3
  import { LEGEND_AVERAGE_TEXT, LEGEND_MAX_TEXT, LEGEND_MIN_TEXT, LEGEND_CURRENT_TEXT, LEGEND_LAYOUT_INLINE, LEGEND_LAYOUT_TABLE, 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 ChartLegend from '../legend/legend';
9
8
  import ChartTooltip from '../tooltip/tooltip';
9
+ import TooltipDefaultFormat from '../../shared_components/charts/tooltip_default_format';
10
10
  import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
11
11
 
12
12
  const yAxisDefaults = {
@@ -112,6 +112,12 @@ var script = {
112
112
  return [LEGEND_LAYOUT_INLINE, LEGEND_LAYOUT_TABLE].indexOf(layout) !== -1;
113
113
  }
114
114
  },
115
+ /**
116
+ * Callback called when showing or refreshing a tooltip.
117
+ * **Deprecated:** Use slots `#tooltip-title`, `#tooltip-content` or `#tooltip-value`.
118
+ *
119
+ * @deprecated Use slots `#tooltip-title`, `#tooltip-content` or `#tooltip-value`.
120
+ */
115
121
  formatTooltipText: {
116
122
  type: Function,
117
123
  required: false,
@@ -133,9 +139,7 @@ var script = {
133
139
  },
134
140
  data() {
135
141
  return {
136
- chart: null,
137
- tooltipTitle: '',
138
- tooltipContent: {}
142
+ chart: null
139
143
  };
140
144
  },
141
145
  computed: {
@@ -216,7 +220,7 @@ var script = {
216
220
  show: true,
217
221
  type: 'none',
218
222
  label: {
219
- formatter: this.onLabelChange
223
+ formatter: this.formatTooltipText
220
224
  }
221
225
  },
222
226
  data: this.groupBy,
@@ -272,28 +276,34 @@ var script = {
272
276
  this.chart = chart;
273
277
  this.$emit('created', chart);
274
278
  },
275
- defaultFormatTooltipText(params) {
276
- const {
277
- tooltipContent
278
- } = params.seriesData.reverse().reduce((acc, bar) => {
279
- acc.tooltipContent[bar.seriesName] = {
280
- value: bar.value,
281
- index: bar.seriesIndex,
282
- color: this.getColor(bar.seriesIndex)
283
- };
284
- return acc;
285
- }, {
286
- tooltipContent: {}
287
- });
288
- this.tooltipTitle = params.value;
289
- this.$set(this, 'tooltipContent', tooltipContent);
279
+ getTooltipTitle(_ref4) {
280
+ var _options$xAxis, _options$xAxis$;
281
+ let {
282
+ params
283
+ } = _ref4;
284
+ if (!params) return '';
285
+ const options = this.chart.getOption();
286
+ const titleAxisName = options === null || options === void 0 ? void 0 : (_options$xAxis = options.xAxis) === null || _options$xAxis === void 0 ? void 0 : (_options$xAxis$ = _options$xAxis[0]) === null || _options$xAxis$ === void 0 ? void 0 : _options$xAxis$.name;
287
+ return titleAxisName ? `${params.value} (${titleAxisName})` : params.value;
290
288
  },
291
- onLabelChange(params) {
292
- if (this.formatTooltipText) {
293
- this.formatTooltipText(params);
294
- } else {
295
- this.defaultFormatTooltipText(params);
296
- }
289
+ getTooltipContent(_ref5) {
290
+ let {
291
+ params
292
+ } = _ref5;
293
+ if (!params) return {};
294
+ const tooltipContentEntries = params.seriesData.toSorted((a, b) => b.seriesIndex - a.seriesIndex) // Invert stacking order so it matches chart (see https://github.com/apache/echarts/issues/14700)
295
+ .map(_ref6 => {
296
+ let {
297
+ seriesName = '',
298
+ value,
299
+ borderColor
300
+ } = _ref6;
301
+ return [seriesName, {
302
+ value,
303
+ color: borderColor
304
+ }];
305
+ });
306
+ return Object.fromEntries(tooltipContentEntries);
297
307
  }
298
308
  },
299
309
  HEIGHT_AUTO_CLASSES
@@ -305,7 +315,7 @@ const __vue_script__ = script;
305
315
  /* template */
306
316
  var __vue_render__ = function () {
307
317
  var _obj;
308
- 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 [_vm._t("tooltip-title",function(){return [_vm._v(_vm._s(_vm.tooltipTitle)+" ("+_vm._s(_vm.xAxisTitle)+")")]})]},proxy:true}],null,true)},[_vm._v(" "),_vm._t("tooltip-content",function(){return [_c('tooltip-default-format',{attrs:{"tooltip-content":_vm.tooltipContent}})]})],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,"min-text":_vm.legendMinText,"max-text":_vm.legendMaxText,"average-text":_vm.legendAverageText,"current-text":_vm.legendCurrentText,"layout":_vm.legendLayout}}):_vm._e()],1)};
318
+ 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":!_vm.formatTooltipText},scopedSlots:_vm._u([{key:"title",fn:function(scope){return [_vm._t("tooltip-title",function(){return [_vm._v(_vm._s(_vm.getTooltipTitle(scope)))]},null,scope)]}},{key:"default",fn:function(scope){return [_vm._t("tooltip-content",function(){return [_c('tooltip-default-format',{attrs:{"tooltip-content":_vm.getTooltipContent(scope)},scopedSlots:_vm._u([(_vm.$scopedSlots['tooltip-value'])?{key:"tooltip-value",fn:function(valueScope){return [_vm._t("tooltip-value",null,null,valueScope)]}}:null],null,true)})]},null,scope)]}}],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)};
309
319
  var __vue_staticRenderFns__ = [];
310
320
 
311
321
  /* style */
@@ -500,10 +500,11 @@ const getTooltipContent = function () {
500
500
  }
501
501
  return seriesData.reduce((acc, _ref7) => {
502
502
  let {
503
- value: [, yValue],
503
+ value,
504
504
  seriesName,
505
505
  color
506
506
  } = _ref7;
507
+ const yValue = value[1];
507
508
  acc[seriesName] = {
508
509
  value: yValue,
509
510
  color
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/ui",
3
- "version": "108.6.0",
3
+ "version": "108.7.0",
4
4
  "description": "GitLab UI Components",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -22,10 +22,10 @@ import {
22
22
  } from '../../../utils/charts/constants';
23
23
  import { colorFromDefaultPalette } from '../../../utils/charts/theme';
24
24
  import { columnOptions } from '../../../utils/constants';
25
- import TooltipDefaultFormat from '../../shared_components/charts/tooltip_default_format.vue';
26
25
  import Chart from '../chart/chart.vue';
27
26
  import ChartLegend from '../legend/legend.vue';
28
27
  import ChartTooltip from '../tooltip/tooltip.vue';
28
+ import TooltipDefaultFormat from '../../shared_components/charts/tooltip_default_format.vue';
29
29
 
30
30
  const yAxisDefaults = {
31
31
  ...yAxis,
@@ -131,6 +131,12 @@ export default {
131
131
  return [LEGEND_LAYOUT_INLINE, LEGEND_LAYOUT_TABLE].indexOf(layout) !== -1;
132
132
  },
133
133
  },
134
+ /**
135
+ * Callback called when showing or refreshing a tooltip.
136
+ * **Deprecated:** Use slots `#tooltip-title`, `#tooltip-content` or `#tooltip-value`.
137
+ *
138
+ * @deprecated Use slots `#tooltip-title`, `#tooltip-content` or `#tooltip-value`.
139
+ */
134
140
  formatTooltipText: {
135
141
  type: Function,
136
142
  required: false,
@@ -153,8 +159,6 @@ export default {
153
159
  data() {
154
160
  return {
155
161
  chart: null,
156
- tooltipTitle: '',
157
- tooltipContent: {},
158
162
  };
159
163
  },
160
164
  computed: {
@@ -206,7 +210,7 @@ export default {
206
210
  show: true,
207
211
  type: 'none',
208
212
  label: {
209
- formatter: this.onLabelChange,
213
+ formatter: this.formatTooltipText,
210
214
  },
211
215
  },
212
216
  data: this.groupBy,
@@ -265,31 +269,24 @@ export default {
265
269
  this.chart = chart;
266
270
  this.$emit('created', chart);
267
271
  },
268
- defaultFormatTooltipText(params) {
269
- const { tooltipContent } = params.seriesData.reverse().reduce(
270
- (acc, bar) => {
271
- acc.tooltipContent[bar.seriesName] = {
272
- value: bar.value,
273
- index: bar.seriesIndex,
274
- color: this.getColor(bar.seriesIndex),
275
- };
276
-
277
- return acc;
278
- },
279
- {
280
- tooltipContent: {},
281
- }
282
- );
272
+ getTooltipTitle({ params }) {
273
+ if (!params) return '';
283
274
 
284
- this.tooltipTitle = params.value;
285
- this.$set(this, 'tooltipContent', tooltipContent);
275
+ const options = this.chart.getOption();
276
+ const titleAxisName = options?.xAxis?.[0]?.name;
277
+ return titleAxisName ? `${params.value} (${titleAxisName})` : params.value;
286
278
  },
287
- onLabelChange(params) {
288
- if (this.formatTooltipText) {
289
- this.formatTooltipText(params);
290
- } else {
291
- this.defaultFormatTooltipText(params);
292
- }
279
+ getTooltipContent({ params }) {
280
+ if (!params) return {};
281
+
282
+ const tooltipContentEntries = params.seriesData
283
+ .toSorted((a, b) => b.seriesIndex - a.seriesIndex) // Invert stacking order so it matches chart (see https://github.com/apache/echarts/issues/14700)
284
+ .map(({ seriesName = '', value, borderColor }) => [
285
+ seriesName,
286
+ { value, color: borderColor },
287
+ ]);
288
+
289
+ return Object.fromEntries(tooltipContentEntries);
293
290
  },
294
291
  },
295
292
  HEIGHT_AUTO_CLASSES,
@@ -305,14 +302,19 @@ export default {
305
302
  v-on="$listeners"
306
303
  @created="onCreated"
307
304
  />
308
- <chart-tooltip v-if="chart" :chart="chart">
309
- <template #title>
310
- <slot name="tooltip-title">{{ tooltipTitle }} ({{ xAxisTitle }})</slot>
305
+ <chart-tooltip v-if="chart" :chart="chart" :use-default-tooltip-formatter="!formatTooltipText">
306
+ <template #title="scope">
307
+ <slot name="tooltip-title" v-bind="scope">{{ getTooltipTitle(scope) }}</slot>
308
+ </template>
309
+ <template #default="scope">
310
+ <slot name="tooltip-content" v-bind="scope">
311
+ <tooltip-default-format :tooltip-content="getTooltipContent(scope)">
312
+ <template v-if="$scopedSlots['tooltip-value']" #tooltip-value="valueScope">
313
+ <slot name="tooltip-value" v-bind="valueScope"></slot>
314
+ </template>
315
+ </tooltip-default-format>
316
+ </slot>
311
317
  </template>
312
-
313
- <slot name="tooltip-content">
314
- <tooltip-default-format :tooltip-content="tooltipContent" />
315
- </slot>
316
318
  </chart-tooltip>
317
319
  <chart-legend
318
320
  v-if="compiledOptions"
@@ -469,7 +469,8 @@ export const getTooltipContent = (params = null, valueAxisName = null) => {
469
469
  };
470
470
  }
471
471
 
472
- return seriesData.reduce((acc, { value: [, yValue], seriesName, color }) => {
472
+ return seriesData.reduce((acc, { value, seriesName, color }) => {
473
+ const yValue = value[1];
473
474
  acc[seriesName] = { value: yValue, color };
474
475
  return acc;
475
476
  }, {});