@mozaic-ds/chart 0.1.0-beta.2 → 0.1.0-beta.22
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/dist/mozaic-chart.js +4107 -2476
- package/dist/mozaic-chart.umd.cjs +17 -11
- package/dist/style.css +1 -1
- package/package.json +23 -10
- package/src/assets/img/bubbles.svg +4 -0
- package/src/components/bar/BarChart.stories.ts +12 -10
- package/src/components/bar/BarChart.vue +248 -141
- package/src/components/bubble/BubbleChart.stories.ts +66 -0
- package/src/components/bubble/BubbleChart.vue +326 -0
- package/src/components/bubble/index.ts +8 -0
- package/src/components/doughnut/DoughnutChart.stories.ts +1 -0
- package/src/components/doughnut/DoughnutChart.vue +182 -101
- package/src/components/line/LineChart.stories.ts +2 -1
- package/src/components/line/LineChart.vue +331 -258
- package/src/components/mixed/MixedBarLineChart.stories.ts +91 -0
- package/src/components/mixed/MixedBarLineChart.vue +411 -0
- package/src/components/mixed/index.ts +8 -0
- package/src/components/radar/RadarChart.stories.ts +2 -2
- package/src/components/radar/RadarChart.vue +203 -157
- package/src/main.ts +3 -1
- package/src/plugin.ts +2 -0
- package/src/services/BarChartFunctions.ts +10 -7
- package/src/services/BubbleTooltipService.ts +65 -0
- package/src/services/ChartsCommonLegend.ts +86 -58
- package/src/services/DoughnutChartFunctions.ts +107 -59
- package/src/services/FormatUtilities.ts +1 -1
- package/src/services/GenericTooltipService.ts +25 -10
- package/src/services/MixedBarLineFunctions.ts +258 -0
- package/src/services/RadarChartFunctions.ts +33 -12
- package/src/stories/Changelog.mdx +6 -0
- package/src/stories/Contributing.mdx +101 -0
- package/src/stories/GettingStarted.mdx +92 -0
- package/src/stories/SupportAndOnboarding.mdx +44 -0
- package/src/types/AxisDefinition.ts +6 -0
- package/src/types/BarData.ts +1 -0
- package/src/types/MixedBarLineData.ts +7 -0
- package/src/types/TooltipChartType.ts +1 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="container">
|
|
3
|
+
<div class="main">
|
|
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]"
|
|
12
|
+
/>
|
|
13
|
+
</div>
|
|
14
|
+
<div class="chart-legend">
|
|
15
|
+
<img
|
|
16
|
+
src="../../assets/img/bubbles.svg"
|
|
17
|
+
:alt="rAxis.title"
|
|
18
|
+
class="bubble-icon mu-mr-025"
|
|
19
|
+
/>
|
|
20
|
+
<div class="size-legend-label">
|
|
21
|
+
{{ rAxis.title }}
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
24
|
+
</div>
|
|
25
|
+
</template>
|
|
26
|
+
|
|
27
|
+
<script setup lang="ts">
|
|
28
|
+
import {computed, PropType} from 'vue';
|
|
29
|
+
import {Bubble} from 'vue-chartjs';
|
|
30
|
+
import ChartDataLabels from 'chartjs-plugin-datalabels';
|
|
31
|
+
import {addAlpha} from '../../services/ColorFunctions';
|
|
32
|
+
|
|
33
|
+
import {CategoryScale, Chart as ChartJS, Legend, LinearScale, Plugin, PointElement, Title, Tooltip,} from 'chart.js';
|
|
34
|
+
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';
|
|
39
|
+
|
|
40
|
+
ChartJS.register(
|
|
41
|
+
Title,
|
|
42
|
+
Tooltip,
|
|
43
|
+
Legend,
|
|
44
|
+
PointElement,
|
|
45
|
+
CategoryScale,
|
|
46
|
+
LinearScale,
|
|
47
|
+
ChartDataLabels
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const {colourSets} = ChartDesign();
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
const bubbleDataProps = defineProps({
|
|
54
|
+
/**
|
|
55
|
+
* Value of the id attribute present on the <canvas> tag element the chart
|
|
56
|
+
*/
|
|
57
|
+
chartId: {
|
|
58
|
+
type: String,
|
|
59
|
+
default: 'bubble-chart',
|
|
60
|
+
},
|
|
61
|
+
/**
|
|
62
|
+
* Labels used to label the series. See [Data structures documentation](https://www.chartjs.org/docs/latest/general/data-structures.html)
|
|
63
|
+
*/
|
|
64
|
+
labels: {
|
|
65
|
+
type: Array as PropType<string[]>,
|
|
66
|
+
default: () => [],
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* Used to choose the colour set of the charts as defined in the Figma prototypes.
|
|
70
|
+
* 7 colour sets are currently defined:
|
|
71
|
+
* - Default 0 corresponds to the current one
|
|
72
|
+
* - 1 to 6 corresponds to the "new" [colour sets](https://www.figma.com/file/Hn6PyvnR385Ta0XN3KqOI9/04.-Dataviz---Documentation-(read-only)?type=design&node-id=1-69316&mode=design&t=sDytQ5BipsryWkuA-0)
|
|
73
|
+
* Note: All the sets are defined in /src/services/patterns/ChartDesign.ts
|
|
74
|
+
*/
|
|
75
|
+
colourSet: {
|
|
76
|
+
type: Number,
|
|
77
|
+
default: 0,
|
|
78
|
+
},
|
|
79
|
+
/**
|
|
80
|
+
* 6 colors exist in the colourSet (0 to 5)
|
|
81
|
+
* In some use cases, you may need to specify the colours for each dataset
|
|
82
|
+
*/
|
|
83
|
+
colours: {
|
|
84
|
+
type: Array as PropType<number[]>,
|
|
85
|
+
default: () => [],
|
|
86
|
+
},
|
|
87
|
+
/**
|
|
88
|
+
* In some use cases, you may need to specify the shapes for each dataset
|
|
89
|
+
* Default shape is circle, implementation is done using the Point Styles of chartjs :
|
|
90
|
+
* cf. https://www.chartjs.org/docs/latest/configuration/elements.html#point-styles
|
|
91
|
+
*/
|
|
92
|
+
shapes: {
|
|
93
|
+
type: Array as PropType<string[]>,
|
|
94
|
+
default: () => [],
|
|
95
|
+
},
|
|
96
|
+
/**
|
|
97
|
+
* Value of the `datasets` key present in the `data` object passed to the Chart config
|
|
98
|
+
*/
|
|
99
|
+
datasets: {
|
|
100
|
+
type: Array as PropType<any[]>,
|
|
101
|
+
default: () => [],
|
|
102
|
+
},
|
|
103
|
+
/**
|
|
104
|
+
* Value of the `width` css property used to define the width of the <canvas> element
|
|
105
|
+
*/
|
|
106
|
+
width: {
|
|
107
|
+
type: String,
|
|
108
|
+
default: '400px',
|
|
109
|
+
},
|
|
110
|
+
/**
|
|
111
|
+
* Value of the `height` css property used to define the height of the <canvas> element
|
|
112
|
+
*/
|
|
113
|
+
height: {
|
|
114
|
+
type: String,
|
|
115
|
+
default: '300px',
|
|
116
|
+
},
|
|
117
|
+
/**
|
|
118
|
+
* Add custom CSS classes to the <canvas> element
|
|
119
|
+
*/
|
|
120
|
+
cssClasses: {
|
|
121
|
+
type: String,
|
|
122
|
+
default: undefined,
|
|
123
|
+
},
|
|
124
|
+
/**
|
|
125
|
+
* Add custom CSS styles to the <canvas> element
|
|
126
|
+
*/
|
|
127
|
+
styles: {
|
|
128
|
+
type: Object as PropType<Partial<CSSStyleDeclaration>>,
|
|
129
|
+
default: () => {
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
/**
|
|
133
|
+
* Minimum size for a bubble
|
|
134
|
+
*/
|
|
135
|
+
bubbleMin: {
|
|
136
|
+
type: Number,
|
|
137
|
+
default: 10,
|
|
138
|
+
},
|
|
139
|
+
/**
|
|
140
|
+
* Maximum size for a bubble
|
|
141
|
+
*/
|
|
142
|
+
bubbleMax: {
|
|
143
|
+
type: Number,
|
|
144
|
+
default: 40,
|
|
145
|
+
},
|
|
146
|
+
/**
|
|
147
|
+
* Value of the `plugins` key passed to the Chart config
|
|
148
|
+
*/
|
|
149
|
+
plugins: {
|
|
150
|
+
type: Array as PropType<Plugin<any>[]>,
|
|
151
|
+
default: () => [],
|
|
152
|
+
},
|
|
153
|
+
/**
|
|
154
|
+
* If set to true the label of the dataserie will be shown on top of the bubble
|
|
155
|
+
*/
|
|
156
|
+
displayBubbleLabel: {
|
|
157
|
+
type: Boolean,
|
|
158
|
+
default: false
|
|
159
|
+
},
|
|
160
|
+
/**
|
|
161
|
+
* X axis data : title and unit
|
|
162
|
+
*/
|
|
163
|
+
xAxis: {
|
|
164
|
+
type: Object as PropType<AxisDefinition>,
|
|
165
|
+
default: null,
|
|
166
|
+
required: true,
|
|
167
|
+
},
|
|
168
|
+
/**
|
|
169
|
+
* Y axis data : title and unit
|
|
170
|
+
*/
|
|
171
|
+
yAxis: {
|
|
172
|
+
type: Object as PropType<AxisDefinition>,
|
|
173
|
+
default: null,
|
|
174
|
+
required: true,
|
|
175
|
+
},
|
|
176
|
+
/**
|
|
177
|
+
* X axis data : title and unit
|
|
178
|
+
*/
|
|
179
|
+
rAxis: {
|
|
180
|
+
type: Object as PropType<AxisDefinition>,
|
|
181
|
+
default: null,
|
|
182
|
+
required: true,
|
|
183
|
+
},
|
|
184
|
+
/**
|
|
185
|
+
* Show axis labels
|
|
186
|
+
*/
|
|
187
|
+
displayAxisLabels: {
|
|
188
|
+
type: Boolean,
|
|
189
|
+
default: true
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const normalizeDatasets = function (dataSets: Array<Array<any>>) {
|
|
194
|
+
const rValues: Array<number> = []
|
|
195
|
+
dataSets.forEach((dataSerie: Array<any>) => {
|
|
196
|
+
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
|
+
|
|
205
|
+
return dataSets.map((dataSerie: Array<any>) => {
|
|
206
|
+
return dataSerie.map((item) => {
|
|
207
|
+
return {
|
|
208
|
+
x: item.x,
|
|
209
|
+
y: item.y,
|
|
210
|
+
r: rMin + (item.r - min) * (rMax - rMin) / (max - min)
|
|
211
|
+
}
|
|
212
|
+
})
|
|
213
|
+
})
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const chartData = computed(() => {
|
|
217
|
+
|
|
218
|
+
const chartColourSet = colourSets[bubbleDataProps.colourSet];
|
|
219
|
+
return {
|
|
220
|
+
datasets:
|
|
221
|
+
normalizeDatasets(bubbleDataProps.datasets).map((data, index) => ({
|
|
222
|
+
data: data,
|
|
223
|
+
pointStyle: bubbleDataProps.shapes[index],
|
|
224
|
+
backgroundColor: addAlpha(chartColourSet[bubbleDataProps.colours[index]], 0.2),
|
|
225
|
+
borderColor: chartColourSet[bubbleDataProps.colours[index]],
|
|
226
|
+
label: bubbleDataProps.labels[index],
|
|
227
|
+
}))
|
|
228
|
+
};
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const options = computed(() => ({
|
|
232
|
+
responsive: false,
|
|
233
|
+
// eslint-disable-next-line
|
|
234
|
+
scales: {
|
|
235
|
+
x: {
|
|
236
|
+
offset: true,
|
|
237
|
+
title: {
|
|
238
|
+
display: bubbleDataProps.displayAxisLabels,
|
|
239
|
+
text: bubbleDataProps.xAxis.title
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
y: {
|
|
243
|
+
offset: true,
|
|
244
|
+
title: {
|
|
245
|
+
display: bubbleDataProps.displayAxisLabels,
|
|
246
|
+
text: bubbleDataProps.yAxis.title
|
|
247
|
+
},
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
plugins: {
|
|
251
|
+
responsive: true,
|
|
252
|
+
maintainAspectRatio: false,
|
|
253
|
+
legend: {
|
|
254
|
+
display: false,
|
|
255
|
+
},
|
|
256
|
+
title: {
|
|
257
|
+
display: false,
|
|
258
|
+
},
|
|
259
|
+
datalabels: {
|
|
260
|
+
display: bubbleDataProps.displayBubbleLabel,
|
|
261
|
+
anchor: 'end' as const,
|
|
262
|
+
align: 'end' as const,
|
|
263
|
+
color: 'black',
|
|
264
|
+
formatter: function <T extends { dataset: any }>(_value: any, context: T) {
|
|
265
|
+
return context.dataset.label;
|
|
266
|
+
},
|
|
267
|
+
padding: 0
|
|
268
|
+
},
|
|
269
|
+
tooltip: {
|
|
270
|
+
enabled: false,
|
|
271
|
+
position: 'nearest' as const,
|
|
272
|
+
external: function (context: Context) {
|
|
273
|
+
const datasetIndex: number = context.tooltip?.dataPoints?.[0].datasetIndex || 0;
|
|
274
|
+
const dataIndex: number = context.tooltip.dataPoints?.[0].dataIndex || 0;
|
|
275
|
+
const currentBubble: { x: number, y: number, r: number } = bubbleDataProps.datasets[datasetIndex][dataIndex];
|
|
276
|
+
new BubbleTooltipService().createBubbleTooltip(
|
|
277
|
+
context,
|
|
278
|
+
[{label: bubbleDataProps.xAxis.title, value: `${formatWithThousandsSeprators(currentBubble.x)}`, unit: bubbleDataProps.xAxis?.unit},
|
|
279
|
+
{label: bubbleDataProps.yAxis.title, value: `${formatWithThousandsSeprators(currentBubble.y)}`, unit: bubbleDataProps.yAxis?.unit},
|
|
280
|
+
{label: bubbleDataProps.rAxis.title, value: `${formatWithThousandsSeprators(currentBubble.r)}`, unit: bubbleDataProps.rAxis?.unit}
|
|
281
|
+
],
|
|
282
|
+
bubbleDataProps.labels[datasetIndex],
|
|
283
|
+
);
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
}));
|
|
288
|
+
|
|
289
|
+
</script>
|
|
290
|
+
|
|
291
|
+
<style lang="scss">
|
|
292
|
+
@import 'settings-tools/all-settings';
|
|
293
|
+
@import 'components/c.checkbox';
|
|
294
|
+
</style>
|
|
295
|
+
|
|
296
|
+
<style scoped>
|
|
297
|
+
.container {
|
|
298
|
+
-moz-osx-font-smoothing: grayscale;
|
|
299
|
+
-webkit-font-smoothing: antialiased;
|
|
300
|
+
font-weight: 400;
|
|
301
|
+
font-family: 'Roboto', sans-serif;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
.main {
|
|
305
|
+
display: flex;
|
|
306
|
+
flex-direction: column;
|
|
307
|
+
justify-content: center;
|
|
308
|
+
align-items: center;
|
|
309
|
+
margin-bottom: 20px;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
.chart-legend {
|
|
313
|
+
display: flex;
|
|
314
|
+
gap: 4px;
|
|
315
|
+
font-size: 14px;
|
|
316
|
+
align-items: center;
|
|
317
|
+
margin: 1.375rem 1.0625rem;
|
|
318
|
+
color: rgb(102, 102, 102);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
.bubble-icon {
|
|
322
|
+
width: 16px;
|
|
323
|
+
height: 16px;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
</style>
|