@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.
@@ -56,7 +56,7 @@ const defaultOptions = {
56
56
  },
57
57
  };
58
58
 
59
- const template = `<gl-line-chart
59
+ const template = (content = '') => `<gl-line-chart
60
60
  :data="data"
61
61
  :option="option"
62
62
  :thresholds="thresholds"
@@ -64,7 +64,9 @@ const template = `<gl-line-chart
64
64
  :includeLegendAvgMax="includeLegendAvgMax"
65
65
  :showLegend="showLegend"
66
66
  :height="height"
67
- />`;
67
+ >
68
+ ${content}
69
+ </gl-line-chart>`;
68
70
 
69
71
  const generateProps = ({
70
72
  data = defaultData,
@@ -87,7 +89,7 @@ const generateProps = ({
87
89
  const Template = (_args, { argTypes }) => ({
88
90
  props: Object.keys(argTypes),
89
91
  components,
90
- template,
92
+ template: template(),
91
93
  });
92
94
 
93
95
  export const Default = Template.bind({});
@@ -99,7 +101,7 @@ WithThreshold.args = generateProps({
99
101
  });
100
102
 
101
103
  export const WithAnnotationsAsProps = Template.bind({});
102
- WithAnnotationsAsProps.storyNane = 'with annotations as props (recommended)';
104
+ WithAnnotationsAsProps.storyName = 'with annotations as props (recommended)';
103
105
  WithAnnotationsAsProps.args = generateProps({
104
106
  ...mockAnnotationsConfigs,
105
107
  data: [
@@ -200,6 +202,21 @@ NoLegend.args = generateProps({
200
202
  showLegend: false,
201
203
  });
202
204
 
205
+ export const WithCustomTooltip = (_args, { argTypes }) => ({
206
+ props: Object.keys(argTypes),
207
+ components,
208
+ template: template(`
209
+ <template #tooltip-title="{ params }">{{params && params.value}}</template>
210
+ <template #tooltip-content="{ params }">
211
+ <div v-for="p in params && params.seriesData">{{p.seriesName}}: {{p.value[1]}}</div>
212
+ </template>
213
+ `),
214
+ });
215
+ WithCustomTooltip.args = generateProps();
216
+ WithCustomTooltip.parameters = {
217
+ storyshots: { disable: true },
218
+ };
219
+
203
220
  export default {
204
221
  title: 'charts/line-chart',
205
222
  component: GlLineChart,
@@ -30,8 +30,6 @@ import {
30
30
  mergeSeriesToOptions,
31
31
  mergeAnnotationAxisToOptions,
32
32
  lineStyle,
33
- // eslint-disable-next-line import/no-deprecated
34
- getDefaultTooltipContent,
35
33
  } from '../../../utils/charts/config';
36
34
  import {
37
35
  LEGEND_LAYOUT_INLINE,
@@ -44,7 +42,6 @@ import {
44
42
  } from '../../../utils/charts/constants';
45
43
  import { colorFromDefaultPalette } from '../../../utils/charts/theme';
46
44
  import { seriesHasAnnotations, isDataPointAnnotation } from '../../../utils/charts/utils';
47
- import TooltipDefaultFormat from '../../shared_components/charts/tooltip_default_format.vue';
48
45
  import Chart from '../chart/chart.vue';
49
46
  import ChartLegend from '../legend/legend.vue';
50
47
  import ChartTooltip from '../tooltip/tooltip.vue';
@@ -55,7 +52,6 @@ export default {
55
52
  Chart,
56
53
  ChartLegend,
57
54
  ChartTooltip,
58
- TooltipDefaultFormat,
59
55
  },
60
56
  inheritAttrs: false,
61
57
  props: {
@@ -83,6 +79,12 @@ export default {
83
79
  required: false,
84
80
  default: true,
85
81
  },
82
+ /**
83
+ * Callback called when showing or refreshing a tooltip.
84
+ * **Deprecated:** Use slots `#tooltip-title`, `#tooltip-content` or `#tooltip-value`.
85
+ *
86
+ * @deprecated Use slots `#tooltip-title`, `#tooltip-content` or `#tooltip-value`.
87
+ */
86
88
  formatTooltipText: {
87
89
  type: Function,
88
90
  required: false,
@@ -137,8 +139,6 @@ export default {
137
139
  // https://gitlab.com/gitlab-org/gitlab-ui/-/issues/618
138
140
  return {
139
141
  chart: null,
140
- dataTooltipTitle: '',
141
- dataTooltipContent: {},
142
142
  showAnnotationsTooltip: false,
143
143
  annotationsTooltipTitle: '',
144
144
  annotationsTooltipContent: '',
@@ -146,7 +146,6 @@ export default {
146
146
  left: '0',
147
147
  top: '0',
148
148
  },
149
- selectedFormatTooltipText: this.formatTooltipText || this.defaultFormatTooltipText,
150
149
  };
151
150
  },
152
151
  computed: {
@@ -187,7 +186,7 @@ export default {
187
186
  axisPointer: {
188
187
  show: true,
189
188
  label: {
190
- formatter: this.onLabelChange,
189
+ formatter: this.formatTooltipText,
191
190
  },
192
191
  },
193
192
  axisTick: {
@@ -260,13 +259,6 @@ export default {
260
259
  this.chart.off('mouseover', this.onChartDataPointMouseOver);
261
260
  },
262
261
  methods: {
263
- defaultFormatTooltipText(params) {
264
- // eslint-disable-next-line import/no-deprecated
265
- const { xLabels, tooltipContent } = getDefaultTooltipContent(params, this.options.yAxis.name);
266
-
267
- this.$set(this, 'dataTooltipContent', tooltipContent);
268
- this.dataTooltipTitle = xLabels.join(', ');
269
- },
270
262
  defaultAnnotationTooltipText(params) {
271
263
  return {
272
264
  title: params.data.xAxis,
@@ -314,9 +306,6 @@ export default {
314
306
  };
315
307
  }
316
308
  },
317
- onLabelChange(params) {
318
- this.selectedFormatTooltipText(params);
319
- },
320
309
  },
321
310
  HEIGHT_AUTO_CLASSES,
322
311
  };
@@ -347,21 +336,21 @@ export default {
347
336
  </template>
348
337
  <div>{{ annotationsTooltipContent }}</div>
349
338
  </chart-tooltip>
350
- <chart-tooltip v-if="chart" ref="dataTooltip" :chart="chart">
351
- <template #title>
352
- <slot v-if="formatTooltipText" name="tooltip-title"></slot>
353
- <div v-else>
354
- {{ dataTooltipTitle }}
355
- <template v-if="options.xAxis.name">({{ options.xAxis.name }})</template>
356
- </div>
339
+ <chart-tooltip
340
+ v-if="chart"
341
+ ref="dataTooltip"
342
+ :chart="chart"
343
+ :use-default-tooltip-formatter="!formatTooltipText"
344
+ >
345
+ <template v-if="$scopedSlots['tooltip-title']" #title="scope">
346
+ <slot name="tooltip-title" v-bind="scope"></slot>
347
+ </template>
348
+ <template v-if="$scopedSlots['tooltip-content']" #default="scope">
349
+ <slot name="tooltip-content" v-bind="scope"></slot>
350
+ </template>
351
+ <template v-if="$scopedSlots['tooltip-value']" #tooltip-value="scope">
352
+ <slot name="tooltip-value" v-bind="scope"></slot>
357
353
  </template>
358
- <slot v-if="formatTooltipText" name="tooltip-content"></slot>
359
- <tooltip-default-format v-else :tooltip-content="dataTooltipContent">
360
- <template v-if="$scopedSlots['tooltip-value']" #tooltip-value="scope">
361
- <!-- @slot Tooltip value formatter -->
362
- <slot name="tooltip-value" v-bind="scope"></slot>
363
- </template>
364
- </tooltip-default-format>
365
354
  </chart-tooltip>
366
355
  <chart-legend
367
356
  v-if="hasLegend"