@gitlab/ui 122.3.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.
@@ -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 [_c('div',[_vm._v(_vm._s(_vm.tooltipTitle)+" ("+_vm._s(_vm.yAxisTitle)+")")])]},proxy:true}],null,false,1644826356)},[_vm._v(" "),_c('tooltip-default-format',{attrs:{"tooltip-content":_vm.tooltipContent}})],1):_vm._e()],1)};
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
- xAxis: {
226
+ [this.dimensionAxis]: {
213
227
  axisPointer: {
214
228
  show: true,
215
229
  label: {
216
230
  formatter: params => {
217
- var _options$xAxis, _options$xAxis$, _options$yAxis, _options$yAxis$;
231
+ var _options$this$dimensi, _options$this$dimensi2, _options$valueAxis, _options$valueAxis$;
218
232
  const options = this.chart.getOption();
219
- const titleAxisName = (_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;
220
- const valueAxisName = (_options$yAxis = options.yAxis) === null || _options$yAxis === void 0 ? void 0 : (_options$yAxis$ = _options$yAxis[0]) === null || _options$yAxis$ === void 0 ? void 0 : _options$yAxis$.name;
221
- this.title = getTooltipTitle(params, titleAxisName);
222
- this.content = getTooltipContent(params, valueAxisName);
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
  }