@mozaic-ds/chart 0.1.0-beta.29 → 0.1.0-beta.30

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.
Files changed (56) hide show
  1. package/README.md +1 -1
  2. package/dist/mozaic-chart.js +2303 -2109
  3. package/dist/mozaic-chart.umd.cjs +9 -9
  4. package/dist/style.css +1 -1
  5. package/package.json +1 -1
  6. package/src/assets/base.css +1 -1
  7. package/src/components/bar/BarChart.stories.ts +99 -99
  8. package/src/components/bar/BarChart.vue +70 -53
  9. package/src/components/bar/index.ts +3 -3
  10. package/src/components/bubble/BubbleChart.stories.ts +12 -12
  11. package/src/components/bubble/BubbleChart.vue +118 -91
  12. package/src/components/bubble/index.ts +3 -3
  13. package/src/components/doughnut/DoughnutChart.stories.ts +38 -37
  14. package/src/components/doughnut/DoughnutChart.vue +89 -71
  15. package/src/components/doughnut/index.ts +3 -3
  16. package/src/components/index.ts +4 -4
  17. package/src/components/line/LineChart.stories.ts +38 -38
  18. package/src/components/line/LineChart.vue +54 -51
  19. package/src/components/line/index.ts +3 -3
  20. package/src/components/mixed/MixedBarLineChart.stories.ts +15 -15
  21. package/src/components/mixed/MixedBarLineChart.vue +44 -44
  22. package/src/components/mixed/index.ts +1 -1
  23. package/src/components/radar/RadarChart.stories.ts +100 -100
  24. package/src/components/radar/RadarChart.vue +41 -34
  25. package/src/components/radar/index.ts +3 -3
  26. package/src/main.ts +14 -7
  27. package/src/plugin.ts +9 -9
  28. package/src/services/BarChartFunctions.ts +133 -35
  29. package/src/services/BubbleTooltipService.ts +58 -56
  30. package/src/services/ChartsCommonLegend.ts +271 -127
  31. package/src/services/ColorFunctions.ts +1 -1
  32. package/src/services/DoughnutChartFunctions.ts +42 -13
  33. package/src/services/FormatUtilities.ts +28 -14
  34. package/src/services/GenericTooltipService.ts +125 -65
  35. package/src/services/MixedBarLineFunctions.ts +46 -44
  36. package/src/services/PatternFunctions.ts +25 -18
  37. package/src/services/RadarChartFunctions.ts +5 -5
  38. package/src/services/patterns/ChartDesign.ts +35 -24
  39. package/src/services/patterns/patternCircles.ts +63 -36
  40. package/src/services/patterns/patternDashedDiagonals.ts +64 -57
  41. package/src/services/patterns/patternDiagonals.ts +138 -106
  42. package/src/services/patterns/patternSquares.ts +86 -80
  43. package/src/services/patterns/patternVerticalLines.ts +76 -69
  44. package/src/services/patterns/patternZigzag.ts +92 -85
  45. package/src/stories/Changelog.mdx +2 -2
  46. package/src/stories/Contributing.mdx +2 -2
  47. package/src/stories/GettingStarted.mdx +5 -5
  48. package/src/stories/SupportAndOnboarding.mdx +6 -6
  49. package/src/types/AxisDefinition.ts +0 -2
  50. package/src/types/Chart.ts +9 -7
  51. package/src/types/DoughnutData.ts +8 -0
  52. package/src/types/GenericData.ts +10 -10
  53. package/src/types/LineChart.ts +4 -4
  54. package/src/types/RadarData.ts +33 -29
  55. package/src/types/TooltipChartType.ts +7 -7
  56. package/src/vite-env.d.ts +3 -3
@@ -17,16 +17,28 @@
17
17
  </template>
18
18
 
19
19
  <script setup lang="ts">
20
- import type {Ref} from 'vue';
21
- import {computed, PropType, ref, watch} from 'vue';
22
- import {Bar} from 'vue-chartjs';
20
+ import type { Ref } from 'vue';
21
+ import { computed, PropType, ref, watch } from 'vue';
22
+ import { Bar } from 'vue-chartjs';
23
23
  import barChartFunctions from '../../services/BarChartFunctions';
24
- import type {Context} from '../../services/GenericTooltipService';
25
- import {GenericTooltipService} from '../../services/GenericTooltipService';
26
- import {TooltipChartType} from '../../types/TooltipChartType';
27
- import {formatTicks, formatWithThousandsSeprators,} from '../../services/FormatUtilities';
28
- import {BarElement, CategoryScale, Chart as ChartJS, Legend, LinearScale, Plugin, Title, Tooltip,} from 'chart.js';
29
- import {BarData} from '../../types/BarData';
24
+ import type { Context } from '../../services/GenericTooltipService';
25
+ import { GenericTooltipService } from '../../services/GenericTooltipService';
26
+ import { TooltipChartType } from '../../types/TooltipChartType';
27
+ import {
28
+ formatTicks,
29
+ formatWithThousandsSeprators
30
+ } from '../../services/FormatUtilities';
31
+ import {
32
+ BarElement,
33
+ CategoryScale,
34
+ Chart as ChartJS,
35
+ Legend,
36
+ LinearScale,
37
+ Plugin,
38
+ Title,
39
+ Tooltip
40
+ } from 'chart.js';
41
+ import { BarData } from '../../types/BarData';
30
42
  import ChartDesign from '../../services/patterns/ChartDesign';
31
43
 
32
44
  ChartJS.register(
@@ -48,21 +60,21 @@ const barDataProps = defineProps({
48
60
  */
49
61
  chartId: {
50
62
  type: String,
51
- default: 'radar-chart',
63
+ default: 'radar-chart'
52
64
  },
53
65
  /**
54
66
  * Unit of values on canvas Y axis
55
67
  */
56
68
  unit: {
57
69
  type: String,
58
- default: '%',
70
+ default: '%'
59
71
  },
60
72
  /**
61
73
  * Labels used to label the index axis (default x axes). See [Data structures documentation](https://www.chartjs.org/docs/latest/general/data-structures.html)
62
74
  */
63
75
  labels: {
64
76
  type: Array as PropType<string[]>,
65
- default: () => [],
77
+ default: () => []
66
78
  },
67
79
  /**
68
80
  * Used to choose the colour set of the charts as defined in the Figma prototypes.
@@ -73,7 +85,7 @@ const barDataProps = defineProps({
73
85
  */
74
86
  colourSet: {
75
87
  type: Number,
76
- default: 0,
88
+ default: 0
77
89
  },
78
90
  /**
79
91
  * 6 patterns exist and are not randomly given but follow the order defined in [patternsStandardList](/src/services/patterns/ChartDesign.ts)
@@ -82,7 +94,7 @@ const barDataProps = defineProps({
82
94
  */
83
95
  newPatternsOrder: {
84
96
  type: Array as PropType<number[]>,
85
- default: () => [0, 1, 2, 3, 4, 5],
97
+ default: () => [0, 1, 2, 3, 4, 5]
86
98
  },
87
99
  /**
88
100
  * Value of the `datasets` key present in the `data` object passed to the Chart config
@@ -90,92 +102,92 @@ const barDataProps = defineProps({
90
102
  */
91
103
  datasets: {
92
104
  type: Array as PropType<BarData[]>,
93
- default: () => [],
105
+ default: () => []
94
106
  },
95
107
  /**
96
108
  * Value of the `width` css property used to define the width of the <canvas> element
97
109
  */
98
110
  width: {
99
111
  type: String,
100
- default: '400px',
112
+ default: '400px'
101
113
  },
102
114
  /**
103
115
  * Value of the `height` css property used to define the height of the <canvas> element
104
116
  */
105
117
  height: {
106
118
  type: String,
107
- default: '300px',
119
+ default: '300px'
108
120
  },
109
121
  /**
110
122
  * Add custom CSS classes to the <canvas> element
111
123
  */
112
124
  cssClasses: {
113
125
  type: String,
114
- default: undefined,
126
+ default: undefined
115
127
  },
116
128
  /**
117
129
  * Add custom CSS styles to the <canvas> element
118
130
  */
119
131
  styles: {
120
132
  type: Object as PropType<Partial<CSSStyleDeclaration>>,
121
- default: () => {},
133
+ default: () => {}
122
134
  },
123
135
  /**
124
136
  * Value of the `plugins` key passed to the Chart config
125
137
  */
126
138
  plugins: {
127
139
  type: Array as PropType<Plugin<'bar'>[]>,
128
- default: () => [],
140
+ default: () => []
129
141
  },
130
142
  /**
131
143
  * Activates "stacked" mode
132
144
  */
133
145
  stacked: {
134
146
  type: Boolean,
135
- default: false,
147
+ default: false
136
148
  },
137
149
  /**
138
150
  * Disable accessibility patterns
139
151
  */
140
152
  disableAccessibility: {
141
153
  type: Boolean,
142
- default: false,
154
+ default: false
143
155
  },
144
156
  /**
145
157
  * Enable hover feature (may cause strange behavior when used with width and height in %)
146
158
  */
147
- enableHoverFeature: {
159
+ enableHoverFeature: {
148
160
  type: Boolean,
149
- default: false,
161
+ default: false
150
162
  },
151
163
  /**
152
164
  * X axis title
153
165
  */
154
- xAxisTitle: {
166
+ xAxisTitle: {
155
167
  type: String,
156
- default: null,
168
+ default: null
157
169
  },
158
170
  /**
159
171
  * Y axis title
160
172
  */
161
- yAxisTitle: {
173
+ yAxisTitle: {
162
174
  type: String,
163
- default: null,
175
+ default: null
164
176
  },
165
177
  /**
166
178
  * Label of the first line in the Tooltip
167
179
  */
168
180
  tooltipFirstLineLabel: {
169
181
  type: String,
170
- default: 'content',
182
+ default: 'content'
171
183
  },
172
184
  /**
173
185
  * Label of the second line in the Tooltip
174
186
  */
175
187
  tooltipSecondLineLabel: {
176
188
  type: String,
177
- default: 'content2',
178
- },
189
+ default: 'content2'
190
+ }
179
191
  });
180
192
 
181
193
  // computed to make the colors list reactive to the props
@@ -202,7 +214,7 @@ const disablePattern = computed(() => {
202
214
 
203
215
  const enableHover = computed(() => {
204
216
  return barDataProps.enableHoverFeature;
205
- })
217
+ });
206
218
 
207
219
  const {
208
220
  onHoverIndex,
@@ -210,7 +222,7 @@ const {
210
222
  reloadChart,
211
223
  getOnHoverOptions,
212
224
  getStackedDatasets,
213
- privateGetHtmlLegendPlugin,
225
+ privateGetHtmlLegendPlugin
214
226
  } = barChartFunctions();
215
227
 
216
228
  const chartData = computed(() => {
@@ -229,7 +241,7 @@ const chartData = computed(() => {
229
241
  patternsColors.value,
230
242
  patternsOrderedList.value,
231
243
  0
232
- ),
244
+ )
233
245
  };
234
246
  });
235
247
 
@@ -259,13 +271,14 @@ const getChartData = (
259
271
  index: number,
260
272
  indexOfValueToHide: number | null,
261
273
  isStacked: boolean = false
262
- ) : number []=> {
274
+ ): number[] => {
263
275
  const data = Object.assign([], barDataProps.datasets[index].data);
264
276
  if (indexOfValueToHide && indexOfOthersLabelIfNull.value) {
265
277
  data.splice(indexOfOthersLabelIfNull.value, 1);
266
278
  }
267
279
 
268
- return data.map((data: { rate?: number, amount?: number}) =>
280
+ return data.map(
281
+ (data: { rate?: number; amount?: number }) =>
269
282
  (barDataProps.unit === '%' ? data.rate : data.amount) as number
270
283
  );
271
284
  };
@@ -296,11 +309,11 @@ const getChartLabels = (indexOfValueToHide: number | null) => {
296
309
 
297
310
  const options = computed(() => ({
298
311
  // eslint-disable-next-line
299
- onHover: barDataProps.enableHoverFeature? getOnHoverOptions() : () => {},
312
+ onHover: barDataProps.enableHoverFeature ? getOnHoverOptions() : () => {},
300
313
  elements: {
301
314
  bar: {
302
- borderSkipped: false,
303
- },
315
+ borderSkipped: false
316
+ }
304
317
  },
305
318
  maxBarThickness: 64,
306
319
  categoryPercentage: 0.6,
@@ -308,10 +321,10 @@ const options = computed(() => ({
308
321
  responsive: true,
309
322
  maintainAspectRatio: false,
310
323
  legend: {
311
- display: false,
324
+ display: false
312
325
  },
313
326
  title: {
314
- display: false,
327
+ display: false
315
328
  },
316
329
  datalabels: {
317
330
  display: false
@@ -320,8 +333,12 @@ const options = computed(() => ({
320
333
  enabled: false,
321
334
  position: 'nearest' as const,
322
335
  external: function (context: Context) {
323
- const dataIndex: number = context.tooltip.dataPoints?.[0].dataIndex || 0;
324
- if (!barDataProps.labels[dataIndex] || barDataProps.labels[dataIndex] === '') {
336
+ const dataIndex: number =
337
+ context.tooltip.dataPoints?.[0].dataIndex || 0;
338
+ if (
339
+ !barDataProps.labels[dataIndex] ||
340
+ barDataProps.labels[dataIndex] === ''
341
+ ) {
325
342
  return;
326
343
  }
327
344
  new GenericTooltipService().createTooltip(
@@ -330,14 +347,14 @@ const options = computed(() => ({
330
347
  {
331
348
  chartType: TooltipChartType.BAR_CHART,
332
349
  firstLineLabel: xValue,
333
- secondLineLabel: yValue,
350
+ secondLineLabel: yValue
334
351
  },
335
352
  patternsColors.value,
336
353
  patternsOrderedList.value,
337
354
  barDataProps.disableAccessibility
338
355
  );
339
- },
340
- },
356
+ }
357
+ }
341
358
  },
342
359
  scales: {
343
360
  x: {
@@ -345,7 +362,7 @@ const options = computed(() => ({
345
362
  title: {
346
363
  display: barDataProps.xAxisTitle !== null,
347
364
  text: barDataProps.xAxisTitle
348
- },
365
+ }
349
366
  },
350
367
  y: {
351
368
  stacked: barDataProps.stacked,
@@ -360,13 +377,13 @@ const options = computed(() => ({
360
377
  : formatWithThousandsSeprators(val as number) +
361
378
  ' ' +
362
379
  barDataProps.unit;
363
- },
364
- },
365
- },
366
- },
380
+ }
381
+ }
382
+ }
383
+ }
367
384
  }));
368
385
 
369
- const htmlLegendPlugin = computed(() =>
386
+ const htmlLegendPlugin = computed(() => [
370
387
  privateGetHtmlLegendPlugin(
371
388
  legendContainer,
372
389
  selectMode,
@@ -375,7 +392,7 @@ const htmlLegendPlugin = computed(() =>
375
392
  patternsOrderedList,
376
393
  enableHover
377
394
  )
378
- );
395
+ ]);
379
396
 
380
397
  watch(
381
398
  onHoverIndex,
@@ -1,8 +1,8 @@
1
- import type { App } from "vue";
2
- import BarChart from "./BarChart.vue";
1
+ import type { App } from 'vue';
2
+ import BarChart from './BarChart.vue';
3
3
 
4
4
  BarChart.install = (app: App) => {
5
- app.component("BarChart", BarChart);
5
+ app.component('BarChart', BarChart);
6
6
  };
7
7
 
8
8
  export { BarChart };
@@ -1,11 +1,11 @@
1
1
  // BubbleChart.stories.ts
2
2
 
3
- import type { Meta, StoryObj } from "@storybook/vue3";
4
- import BubbleChart from "./BubbleChart.vue";
3
+ import type { Meta, StoryObj } from '@storybook/vue3';
4
+ import BubbleChart from './BubbleChart.vue';
5
5
 
6
6
  const meta = {
7
- title: "Charts/Bubble",
8
- component: BubbleChart,
7
+ title: 'Charts/Bubble',
8
+ component: BubbleChart
9
9
  } satisfies Meta<typeof BubbleChart>;
10
10
 
11
11
  export default meta;
@@ -13,11 +13,11 @@ type Story = StoryObj<typeof meta>;
13
13
 
14
14
  export const Default = {
15
15
  args: {
16
- width: "800px",
17
- height: "500px",
18
- labels: ['Serie 1','Serie 2', 'Serie 3', 'Serie 4'],
16
+ width: '800px',
17
+ height: '500px',
18
+ labels: ['Serie 1', 'Serie 2', 'Serie 3', 'Serie 4'],
19
19
  colours: [0, 4, 1, 2],
20
- shapes: ['rectRot', 'triangle','circle','rect'],
20
+ shapes: ['rectRot', 'triangle', 'circle', 'rect'],
21
21
  colourSet: 4,
22
22
  datasets: [
23
23
  [
@@ -59,8 +59,8 @@ export const Default = {
59
59
  }
60
60
  ]
61
61
  ],
62
- xAxis: {title: 'Data 1', unit: '€'},
63
- yAxis: {title: 'Data 2', unit: 'D'},
64
- rAxis: {title: 'Data 3', unit: '%'}
65
- },
62
+ xAxis: { title: 'Data 1', unit: '€' },
63
+ yAxis: { title: 'Data 2', unit: 'D' },
64
+ rAxis: { title: 'Data 3', unit: '%' }
65
+ }
66
66
  } satisfies Story;