@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
@@ -2,20 +2,20 @@
2
2
  <div class="container">
3
3
  <div class="main">
4
4
  <Bubble
5
- v-if="chartData"
6
- ref="bubbleChartRef"
7
- :id="chartId"
8
- :data="chartData"
9
- :options="options"
10
- :class="cssClasses"
11
- :style="[{ width, height, cursor: 'pointer' }, styles]"
5
+ v-if="chartData"
6
+ ref="bubbleChartRef"
7
+ :id="chartId"
8
+ :data="chartData"
9
+ :options="options"
10
+ :class="cssClasses"
11
+ :style="[{ width, height, cursor: 'pointer' }, styles]"
12
12
  />
13
13
  </div>
14
14
  <div class="chart-legend">
15
15
  <img
16
- src="../../assets/img/bubbles.svg"
17
- :alt="rAxis.title"
18
- class="bubble-icon mu-mr-025"
16
+ src="../../assets/img/bubbles.svg"
17
+ :alt="rAxis.title"
18
+ class="bubble-icon mu-mr-025"
19
19
  />
20
20
  <div class="size-legend-label">
21
21
  {{ rAxis.title }}
@@ -25,30 +25,38 @@
25
25
  </template>
26
26
 
27
27
  <script setup lang="ts">
28
- import {computed, PropType} from 'vue';
29
- import {Bubble} from 'vue-chartjs';
28
+ import { computed, PropType } from 'vue';
29
+ import { Bubble } from 'vue-chartjs';
30
30
  import ChartDataLabels from 'chartjs-plugin-datalabels';
31
- import {addAlpha} from '../../services/ColorFunctions';
31
+ import { addAlpha } from '../../services/ColorFunctions';
32
32
 
33
- import {CategoryScale, Chart as ChartJS, Legend, LinearScale, Plugin, PointElement, Title, Tooltip,} from 'chart.js';
33
+ import {
34
+ CategoryScale,
35
+ Chart as ChartJS,
36
+ Legend,
37
+ LinearScale,
38
+ Plugin,
39
+ PointElement,
40
+ Title,
41
+ Tooltip
42
+ } from 'chart.js';
34
43
  import ChartDesign from '../../services/patterns/ChartDesign';
35
- import {Context} from '../../services/GenericTooltipService';
36
- import {BubbleTooltipService} from '../../services/BubbleTooltipService';
37
- import {formatWithThousandsSeprators} from '../../services/FormatUtilities';
38
- import {AxisDefinition} from '../../types/AxisDefinition';
44
+ import { Context } from '../../services/GenericTooltipService';
45
+ import { BubbleTooltipService } from '../../services/BubbleTooltipService';
46
+ import { formatWithThousandsSeprators } from '../../services/FormatUtilities';
47
+ import { AxisDefinition } from '../../types/AxisDefinition';
39
48
 
40
49
  ChartJS.register(
41
- Title,
42
- Tooltip,
43
- Legend,
44
- PointElement,
45
- CategoryScale,
46
- LinearScale,
47
- ChartDataLabels
50
+ Title,
51
+ Tooltip,
52
+ Legend,
53
+ PointElement,
54
+ CategoryScale,
55
+ LinearScale,
56
+ ChartDataLabels
48
57
  );
49
58
 
50
- const {colourSets} = ChartDesign();
51
-
59
+ const { colourSets } = ChartDesign();
52
60
 
53
61
  const bubbleDataProps = defineProps({
54
62
  /**
@@ -56,14 +64,14 @@ const bubbleDataProps = defineProps({
56
64
  */
57
65
  chartId: {
58
66
  type: String,
59
- default: 'bubble-chart',
67
+ default: 'bubble-chart'
60
68
  },
61
69
  /**
62
70
  * Labels used to label the series. See [Data structures documentation](https://www.chartjs.org/docs/latest/general/data-structures.html)
63
71
  */
64
72
  labels: {
65
73
  type: Array as PropType<string[]>,
66
- default: () => [],
74
+ default: () => []
67
75
  },
68
76
  /**
69
77
  * Used to choose the colour set of the charts as defined in the Figma prototypes.
@@ -74,7 +82,7 @@ const bubbleDataProps = defineProps({
74
82
  */
75
83
  colourSet: {
76
84
  type: Number,
77
- default: 0,
85
+ default: 0
78
86
  },
79
87
  /**
80
88
  * 6 colors exist in the colourSet (0 to 5)
@@ -82,7 +90,7 @@ const bubbleDataProps = defineProps({
82
90
  */
83
91
  colours: {
84
92
  type: Array as PropType<number[]>,
85
- default: () => [],
93
+ default: () => []
86
94
  },
87
95
  /**
88
96
  * In some use cases, you may need to specify the shapes for each dataset
@@ -91,64 +99,63 @@ const bubbleDataProps = defineProps({
91
99
  */
92
100
  shapes: {
93
101
  type: Array as PropType<string[]>,
94
- default: () => [],
102
+ default: () => []
95
103
  },
96
104
  /**
97
105
  * Value of the `datasets` key present in the `data` object passed to the Chart config
98
106
  */
99
107
  datasets: {
100
108
  type: Array as PropType<any[]>,
101
- default: () => [],
109
+ default: () => []
102
110
  },
103
111
  /**
104
112
  * Value of the `width` css property used to define the width of the <canvas> element
105
113
  */
106
114
  width: {
107
115
  type: String,
108
- default: '400px',
116
+ default: '400px'
109
117
  },
110
118
  /**
111
119
  * Value of the `height` css property used to define the height of the <canvas> element
112
120
  */
113
121
  height: {
114
122
  type: String,
115
- default: '300px',
123
+ default: '300px'
116
124
  },
117
125
  /**
118
126
  * Add custom CSS classes to the <canvas> element
119
127
  */
120
128
  cssClasses: {
121
129
  type: String,
122
- default: undefined,
130
+ default: undefined
123
131
  },
124
132
  /**
125
133
  * Add custom CSS styles to the <canvas> element
126
134
  */
127
135
  styles: {
128
136
  type: Object as PropType<Partial<CSSStyleDeclaration>>,
129
- default: () => {
130
- },
137
+ default: () => {}
131
138
  },
132
139
  /**
133
140
  * Minimum size for a bubble
134
141
  */
135
142
  bubbleMin: {
136
143
  type: Number,
137
- default: 10,
144
+ default: 10
138
145
  },
139
146
  /**
140
147
  * Maximum size for a bubble
141
148
  */
142
149
  bubbleMax: {
143
150
  type: Number,
144
- default: 40,
151
+ default: 40
145
152
  },
146
153
  /**
147
154
  * Value of the `plugins` key passed to the Chart config
148
155
  */
149
156
  plugins: {
150
157
  type: Array as PropType<Plugin<any>[]>,
151
- default: () => [],
158
+ default: () => []
152
159
  },
153
160
  /**
154
161
  * If set to true the label of the dataserie will be shown on top of the bubble
@@ -163,7 +170,7 @@ const bubbleDataProps = defineProps({
163
170
  xAxis: {
164
171
  type: Object as PropType<AxisDefinition>,
165
172
  default: null,
166
- required: true,
173
+ required: true
167
174
  },
168
175
  /**
169
176
  * Y axis data : title and unit
@@ -171,7 +178,7 @@ const bubbleDataProps = defineProps({
171
178
  yAxis: {
172
179
  type: Object as PropType<AxisDefinition>,
173
180
  default: null,
174
- required: true,
181
+ required: true
175
182
  },
176
183
  /**
177
184
  * X axis data : title and unit
@@ -179,7 +186,7 @@ const bubbleDataProps = defineProps({
179
186
  rAxis: {
180
187
  type: Object as PropType<AxisDefinition>,
181
188
  default: null,
182
- required: true,
189
+ required: true
183
190
  },
184
191
  /**
185
192
  * Show axis labels
@@ -187,54 +194,57 @@ const bubbleDataProps = defineProps({
187
194
  displayAxisLabels: {
188
195
  type: Boolean,
189
196
  default: true
190
- },
197
+ }
191
198
  });
192
199
 
193
200
  const normalizeDatasets = function (dataSets: Array<Array<any>>) {
194
- const rValues: Array<number> = []
201
+ const rValues: Array<number> = [];
195
202
  dataSets.forEach((dataSerie: Array<any>) => {
196
203
  dataSerie.forEach((item: any) => {
197
- rValues.push(item.r)
198
- })
199
- })
200
- const max = Math.max(...rValues)
201
- const min = Math.min(...rValues)
202
- const rMax = bubbleDataProps.bubbleMax
203
- const rMin = bubbleDataProps.bubbleMin
204
+ rValues.push(item.r);
205
+ });
206
+ });
207
+ const max = Math.max(...rValues);
208
+ const min = Math.min(...rValues);
209
+ const rMax = bubbleDataProps.bubbleMax;
210
+ const rMin = bubbleDataProps.bubbleMin;
204
211
 
205
212
  return dataSets.map((dataSerie: Array<any>) => {
206
213
  if (max === min) {
207
- return dataSerie.map((item) => {
214
+ return dataSerie.map((item) => {
208
215
  return {
209
216
  x: item.x,
210
217
  y: item.y,
211
218
  r: rMin + (rMax - rMin) / 2
212
- }
213
- })
219
+ };
220
+ });
214
221
  } else {
215
- return dataSerie.map((item) => {
222
+ return dataSerie.map((item) => {
216
223
  return {
217
224
  x: item.x,
218
225
  y: item.y,
219
- r: rMin + (item.r - min) * (rMax - rMin) / (max - min)
220
- }
221
- })
222
- }
223
- })
224
- }
226
+ r: rMin + ((item.r - min) * (rMax - rMin)) / (max - min)
227
+ };
228
+ });
229
+ }
230
+ });
231
+ };
225
232
 
226
233
  const chartData = computed(() => {
227
-
228
234
  const chartColourSet = colourSets[bubbleDataProps.colourSet];
229
235
  return {
230
- datasets:
231
- normalizeDatasets(bubbleDataProps.datasets).map((data, index) => ({
232
- data: data,
233
- pointStyle: bubbleDataProps.shapes[index],
234
- backgroundColor: addAlpha(chartColourSet[bubbleDataProps.colours[index]], 0.2),
235
- borderColor: chartColourSet[bubbleDataProps.colours[index]],
236
- label: bubbleDataProps.labels[index],
237
- }))
236
+ datasets: normalizeDatasets(bubbleDataProps.datasets).map(
237
+ (data, index) => ({
238
+ data: data,
239
+ pointStyle: bubbleDataProps.shapes[index],
240
+ backgroundColor: addAlpha(
241
+ chartColourSet[bubbleDataProps.colours[index]],
242
+ 0.2
243
+ ),
244
+ borderColor: chartColourSet[bubbleDataProps.colours[index]],
245
+ label: bubbleDataProps.labels[index]
246
+ })
247
+ )
238
248
  };
239
249
  });
240
250
 
@@ -247,31 +257,34 @@ const options = computed(() => ({
247
257
  title: {
248
258
  display: bubbleDataProps.displayAxisLabels,
249
259
  text: bubbleDataProps.xAxis.title
250
- },
260
+ }
251
261
  },
252
262
  y: {
253
263
  offset: true,
254
264
  title: {
255
265
  display: bubbleDataProps.displayAxisLabels,
256
266
  text: bubbleDataProps.yAxis.title
257
- },
267
+ }
258
268
  }
259
269
  },
260
270
  plugins: {
261
271
  responsive: true,
262
272
  maintainAspectRatio: false,
263
273
  legend: {
264
- display: false,
274
+ display: false
265
275
  },
266
276
  title: {
267
- display: false,
277
+ display: false
268
278
  },
269
279
  datalabels: {
270
280
  display: bubbleDataProps.displayBubbleLabel,
271
281
  anchor: 'end' as const,
272
282
  align: 'end' as const,
273
283
  color: 'black',
274
- formatter: function <T extends { dataset: any }>(_value: any, context: T) {
284
+ formatter: function <T extends { dataset: any }>(
285
+ _value: any,
286
+ context: T
287
+ ) {
275
288
  return context.dataset.label;
276
289
  },
277
290
  padding: 0
@@ -280,22 +293,37 @@ const options = computed(() => ({
280
293
  enabled: false,
281
294
  position: 'nearest' as const,
282
295
  external: function (context: Context) {
283
- const datasetIndex: number = context.tooltip?.dataPoints?.[0].datasetIndex || 0;
284
- const dataIndex: number = context.tooltip.dataPoints?.[0].dataIndex || 0;
285
- const currentBubble: { x: number, y: number, r: number } = bubbleDataProps.datasets[datasetIndex][dataIndex];
296
+ const datasetIndex: number =
297
+ context.tooltip?.dataPoints?.[0].datasetIndex || 0;
298
+ const dataIndex: number =
299
+ context.tooltip.dataPoints?.[0].dataIndex || 0;
300
+ const currentBubble: { x: number; y: number; r: number } =
301
+ bubbleDataProps.datasets[datasetIndex][dataIndex];
286
302
  new BubbleTooltipService().createBubbleTooltip(
287
- context,
288
- [{label: bubbleDataProps.xAxis.title, value: `${formatWithThousandsSeprators(currentBubble.x)}`, unit: bubbleDataProps.xAxis?.unit},
289
- {label: bubbleDataProps.yAxis.title, value: `${formatWithThousandsSeprators(currentBubble.y)}`, unit: bubbleDataProps.yAxis?.unit},
290
- {label: bubbleDataProps.rAxis.title, value: `${formatWithThousandsSeprators(currentBubble.r)}`, unit: bubbleDataProps.rAxis?.unit}
291
- ],
292
- bubbleDataProps.labels[datasetIndex],
303
+ context,
304
+ [
305
+ {
306
+ label: bubbleDataProps.xAxis.title,
307
+ value: `${formatWithThousandsSeprators(currentBubble.x)}`,
308
+ unit: bubbleDataProps.xAxis?.unit
309
+ },
310
+ {
311
+ label: bubbleDataProps.yAxis.title,
312
+ value: `${formatWithThousandsSeprators(currentBubble.y)}`,
313
+ unit: bubbleDataProps.yAxis?.unit
314
+ },
315
+ {
316
+ label: bubbleDataProps.rAxis.title,
317
+ value: `${formatWithThousandsSeprators(currentBubble.r)}`,
318
+ unit: bubbleDataProps.rAxis?.unit
319
+ }
320
+ ],
321
+ bubbleDataProps.labels[datasetIndex]
293
322
  );
294
- },
295
- },
296
- },
323
+ }
324
+ }
325
+ }
297
326
  }));
298
-
299
327
  </script>
300
328
 
301
329
  <style lang="scss">
@@ -332,5 +360,4 @@ const options = computed(() => ({
332
360
  width: 16px;
333
361
  height: 16px;
334
362
  }
335
-
336
363
  </style>
@@ -1,8 +1,8 @@
1
- import type { App } from "vue";
2
- import BubbleChart from "./BubbleChart.vue";
1
+ import type { App } from 'vue';
2
+ import BubbleChart from './BubbleChart.vue';
3
3
 
4
4
  BubbleChart.install = (app: App) => {
5
- app.component("BubbleChart", BubbleChart);
5
+ app.component('BubbleChart', BubbleChart);
6
6
  };
7
7
 
8
8
  export { BubbleChart };
@@ -1,11 +1,11 @@
1
1
  // DoughnutChart.stories.ts;
2
2
 
3
- import type { Meta, StoryObj } from "@storybook/vue3";
4
- import DoughnutChart from "./DoughnutChart.vue";
3
+ import type { Meta, StoryObj } from '@storybook/vue3';
4
+ import DoughnutChart from './DoughnutChart.vue';
5
5
 
6
6
  const meta = {
7
- title: "Charts/Doughnut",
8
- component: DoughnutChart,
7
+ title: 'Charts/Doughnut',
8
+ component: DoughnutChart
9
9
  } satisfies Meta<typeof DoughnutChart>;
10
10
 
11
11
  export default meta;
@@ -13,71 +13,72 @@ type Story = StoryObj<typeof meta>;
13
13
 
14
14
  export const Default = {
15
15
  args: {
16
- height: "400px",
17
- width: "400px",
18
- labels: ["Data One", "Data Two"],
16
+ height: '400px',
17
+ width: '400px',
18
+ labels: ['Data One', 'Data Two'],
19
+ enableCenteredLabel: true,
19
20
  disableAccessibility: false,
20
21
  data: [
21
22
  {
22
23
  value: 2771824.19,
23
- unit: "",
24
- rate: 30.186240355262925,
24
+ unit: '',
25
+ rate: 30.186240355262925
25
26
  },
26
27
  {
27
28
  value: 1715453.65,
28
- unit: "",
29
- rate: 18.68195550931139,
30
- },
29
+ unit: '',
30
+ rate: 18.68195550931139
31
+ }
31
32
  ],
32
- maxValues: 2,
33
- },
33
+ maxValues: 2
34
+ }
34
35
  } satisfies Story;
35
36
 
36
37
  export const MultipleData = {
37
38
  args: {
38
- height: "400px",
39
- width: "400px",
39
+ height: '400px',
40
+ width: '400px',
40
41
  labels: [
41
- "Data One",
42
- "Data Two",
43
- "Data Three",
44
- "Data Four",
45
- "Data Five",
46
- "Data Six",
42
+ 'Data One',
43
+ 'Data Two',
44
+ 'Data Three',
45
+ 'Data Four',
46
+ 'Data Five',
47
+ 'Data Six'
47
48
  ],
48
49
  maxValues: 3,
49
50
  disableAccessibility: false,
50
51
  data: [
51
52
  {
52
53
  value: 2771824.19,
53
- unit: "",
54
- rate: 30.186240355262925,
54
+ unit: '',
55
+ rate: 30.186240355262925
55
56
  },
56
57
  {
57
58
  value: 1715453.65,
58
- unit: "",
59
- rate: 18.68195550931139,
59
+ unit: '',
60
+ rate: 18.68195550931139
60
61
  },
61
62
  {
62
63
  value: 1651575.28,
63
- unit: "",
64
- rate: 17.986295287685856,
64
+ unit: '',
65
+ rate: 17.986295287685856
65
66
  },
66
67
  {
67
68
  value: 1168958.3,
68
- unit: "",
69
- rate: 12.730409214402426,
69
+ unit: '',
70
+ rate: 12.730409214402426
70
71
  },
71
72
  {
72
73
  value: 949837.87,
73
- unit: "",
74
- rate: 10.34410275579238,
74
+ unit: '',
75
+ rate: 10.34410275579238
75
76
  },
76
77
  {
77
78
  value: 924760.17,
78
- unit: "",
79
- rate: 10.070996877545035,
80
- },
81
- ],
82
- },
79
+ unit: '',
80
+ rate: 10.070996877545035
81
+ }
82
+ ]
83
+ }
83
84
  } satisfies Story;