@mozaic-ds/chart 0.1.0-beta.0 → 0.1.0-beta.1
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 +1955 -1816
- package/dist/mozaic-chart.umd.cjs +11 -11
- package/dist/style.css +1 -1
- package/package.json +22 -22
- package/src/components/bar/BarChart.stories.ts +7 -0
- package/src/components/bar/BarChart.vue +60 -8
- package/src/components/doughnut/DoughnutChart.stories.ts +2 -0
- package/src/components/doughnut/DoughnutChart.vue +98 -51
- package/src/components/line/LineChart.vue +46 -3
- package/src/components/radar/RadarChart.vue +59 -15
- package/src/services/BarChartFunctions.ts +16 -20
- package/src/services/ChartsCommonLegend.ts +20 -25
- package/src/services/ColorFunctions.ts +4 -0
- package/src/services/DoughnutChartFunctions.ts +24 -17
- package/src/services/GenericTooltipService.ts +39 -32
- package/src/services/patterns/ChartDesign.ts +15 -9
- package/src/services/patterns/patternCircles.ts +63 -50
- package/src/services/patterns/patternDashedDiagonals.ts +46 -32
- package/src/services/patterns/patternDiagonals.ts +85 -71
- package/src/services/patterns/patternSquares.ts +56 -44
- package/src/services/patterns/patternVerticalLines.ts +41 -28
- package/src/services/patterns/patternZigzag.ts +20 -7
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.container[data-v-
|
|
1
|
+
.container[data-v-d13d8a6b]{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-weight:400;font-family:Roboto,sans-serif}.main[data-v-d13d8a6b]{display:flex;flex-direction:column;justify-content:center;align-items:center;margin-bottom:20px}.container[data-v-d03b50b1]{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-weight:400;font-family:Roboto,sans-serif}.main[data-v-d03b50b1]{display:flex;flex-direction:column;justify-content:center;align-items:center}.container[data-v-ecb2ed0e]{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-weight:400;font-family:Roboto,sans-serif}.main[data-v-ecb2ed0e]{display:flex;flex-direction:column;justify-content:center;align-items:center;margin-bottom:20px}.container[data-v-9ec69ee9]{-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;font-weight:400;font-family:Roboto,sans-serif}.main[data-v-9ec69ee9]{height:600px;display:flex;flex-direction:column;justify-content:center;align-items:center}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mozaic-ds/chart",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "vue-tsc && vite build",
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"npm:publishBeta": "npm publish --tag beta --access public",
|
|
15
15
|
"prepublishOnly": "npm run build",
|
|
16
16
|
"preview": "vite preview",
|
|
17
|
-
"release": "
|
|
18
|
-
"release:beta": "
|
|
17
|
+
"release": "release-it",
|
|
18
|
+
"release:beta": "release-it --preRelease=beta",
|
|
19
19
|
"storybook": "storybook dev -p 6006",
|
|
20
|
-
"test": "vitest"
|
|
20
|
+
"test": "vitest --run"
|
|
21
21
|
},
|
|
22
22
|
"bugs": {
|
|
23
23
|
"url": "https://github.com/adeo/mozaic-chart/issues"
|
|
@@ -37,36 +37,36 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@mozaic-ds/vue-3": "0.49.3",
|
|
40
|
-
"
|
|
40
|
+
"chart.js": "^4.3.3",
|
|
41
|
+
"vue": "^3.2.41",
|
|
42
|
+
"vue-chartjs": "5.2.0"
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
43
|
-
"@babel/core": "^7.22.
|
|
45
|
+
"@babel/core": "^7.22.10",
|
|
44
46
|
"@release-it/conventional-changelog": "^7.0.0",
|
|
45
|
-
"@storybook/addon-essentials": "^7.0
|
|
46
|
-
"@storybook/addon-interactions": "^7.0
|
|
47
|
-
"@storybook/addon-links": "^7.0
|
|
48
|
-
"@storybook/blocks": "^7.0
|
|
47
|
+
"@storybook/addon-essentials": "^7.3.0",
|
|
48
|
+
"@storybook/addon-interactions": "^7.3.0",
|
|
49
|
+
"@storybook/addon-links": "^7.3.0",
|
|
50
|
+
"@storybook/blocks": "^7.3.0",
|
|
49
51
|
"@storybook/testing-library": "^0.2.0",
|
|
50
|
-
"@storybook/vue3": "^7.0
|
|
51
|
-
"@storybook/vue3-vite": "^7.0
|
|
52
|
+
"@storybook/vue3": "^7.3.0",
|
|
53
|
+
"@storybook/vue3-vite": "^7.3.0",
|
|
52
54
|
"@vitejs/plugin-vue": "^4.2.3",
|
|
53
|
-
"@vitest/coverage-
|
|
54
|
-
"@vue/test-utils": "^2.4.
|
|
55
|
-
"babel-loader": "^9.1.
|
|
56
|
-
"
|
|
57
|
-
"chromatic": "^6.19.9",
|
|
55
|
+
"@vitest/coverage-v8": "^0.34.1",
|
|
56
|
+
"@vue/test-utils": "^2.4.1",
|
|
57
|
+
"babel-loader": "^9.1.3",
|
|
58
|
+
"chromatic": "^6.22.0",
|
|
58
59
|
"dotenv-cli": "^7.2.1",
|
|
59
60
|
"jsdom": "^22.1.0",
|
|
60
61
|
"react": "^18.2.0",
|
|
61
62
|
"react-dom": "^18.2.0",
|
|
62
63
|
"release-it": "^16.1.3",
|
|
63
|
-
"storybook": "^7.0
|
|
64
|
+
"storybook": "^7.3.0",
|
|
64
65
|
"typescript": "^5.1.6",
|
|
65
|
-
"vite": "^4.
|
|
66
|
-
"vitest": "^0.
|
|
67
|
-
"vue-chartjs": "5.2.0",
|
|
66
|
+
"vite": "^4.4.9",
|
|
67
|
+
"vitest": "^0.34.1",
|
|
68
68
|
"vue-loader": "^17.2.2",
|
|
69
|
-
"vue-tsc": "^1.8.
|
|
69
|
+
"vue-tsc": "^1.8.8"
|
|
70
70
|
},
|
|
71
71
|
"keywords": [
|
|
72
72
|
"Adeo",
|
|
@@ -18,7 +18,10 @@ export const Default = {
|
|
|
18
18
|
rawTitle: "Bar title",
|
|
19
19
|
firstTooltip: "content",
|
|
20
20
|
secondTooltip: "content2",
|
|
21
|
+
disableAccessibility: false,
|
|
22
|
+
newPatternsOrder: [0,4,1,2,3,5],
|
|
21
23
|
labels: ["Data One", "Data Two", "Data Three"],
|
|
24
|
+
colourSet: 0,
|
|
22
25
|
datasets: [
|
|
23
26
|
{
|
|
24
27
|
label: "Data One",
|
|
@@ -72,6 +75,7 @@ export const MultipleData = {
|
|
|
72
75
|
rawTitle: "Test title",
|
|
73
76
|
firstTooltip: "content",
|
|
74
77
|
secondTooltip: "content2",
|
|
78
|
+
disableAccessibility: false,
|
|
75
79
|
labels: [
|
|
76
80
|
"Data One",
|
|
77
81
|
"Data Two",
|
|
@@ -86,6 +90,7 @@ export const MultipleData = {
|
|
|
86
90
|
"Data Eleven",
|
|
87
91
|
"Data Twelve",
|
|
88
92
|
],
|
|
93
|
+
colourSet: 1,
|
|
89
94
|
datasets: [
|
|
90
95
|
{
|
|
91
96
|
label: "Data One",
|
|
@@ -228,9 +233,11 @@ export const StackedBarChart = {
|
|
|
228
233
|
height: "400px",
|
|
229
234
|
firstTooltip: "content",
|
|
230
235
|
secondTooltip: "content2",
|
|
236
|
+
disableAccessibility: false,
|
|
231
237
|
rawTitle: "Stacked Bar Chart Title",
|
|
232
238
|
stacked: true,
|
|
233
239
|
labels: ["Category One", "Category Two", "Category Three"],
|
|
240
|
+
colourSet: 3,
|
|
234
241
|
datasets: [
|
|
235
242
|
{
|
|
236
243
|
label: "Dataset One",
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="container">
|
|
3
3
|
<div class="main">
|
|
4
|
-
<Bar
|
|
4
|
+
<Bar
|
|
5
5
|
v-if="chartData"
|
|
6
|
-
ref="barChartRef"
|
|
7
|
-
:data="chartData"
|
|
6
|
+
ref="barChartRef"
|
|
7
|
+
:data="chartData"
|
|
8
8
|
:options="options"
|
|
9
9
|
:plugins="htmlLegendPlugin"
|
|
10
10
|
:style="{ width, height }"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
<script setup lang="ts">
|
|
21
21
|
import { computed, ref, watch, PropType } from 'vue';
|
|
22
22
|
import type { Ref } from 'vue';
|
|
23
|
-
import { Bar } from 'vue-chartjs';
|
|
23
|
+
import { Bar, Chart } from 'vue-chartjs';
|
|
24
24
|
import barChartFunctions from '../../services/BarChartFunctions';
|
|
25
25
|
import type { Context } from '../../services/GenericTooltipService';
|
|
26
26
|
import { GenericTooltipService } from '../../services/GenericTooltipService';
|
|
@@ -29,6 +29,7 @@ import { formatTicks, formatWithThousandsSeprators } from '../../services/Format
|
|
|
29
29
|
import { BarElement, CategoryScale, Chart as ChartJS, Legend, LinearScale, Title, Tooltip, Plugin } from 'chart.js';
|
|
30
30
|
import { ButtonName } from '../../types/ButtonName';
|
|
31
31
|
import { BarData } from "../../types/BarData";
|
|
32
|
+
import ChartDesign from '../../services/patterns/ChartDesign';
|
|
32
33
|
|
|
33
34
|
ChartJS.register(
|
|
34
35
|
Title,
|
|
@@ -39,6 +40,11 @@ ChartJS.register(
|
|
|
39
40
|
LinearScale
|
|
40
41
|
);
|
|
41
42
|
|
|
43
|
+
const {
|
|
44
|
+
colourSets,
|
|
45
|
+
patternsStandardList
|
|
46
|
+
} = ChartDesign();
|
|
47
|
+
|
|
42
48
|
const legendContainer = ref(null);
|
|
43
49
|
const selectMode = ref(false);
|
|
44
50
|
const barDataProps = defineProps({
|
|
@@ -58,6 +64,22 @@ const barDataProps = defineProps({
|
|
|
58
64
|
type: Array as PropType<string[]>,
|
|
59
65
|
default: () => []
|
|
60
66
|
},
|
|
67
|
+
// colourSet props is used to choose the colour set of the charts as defined in the Figma prototypes.
|
|
68
|
+
// 7 colour sets are currently defined :
|
|
69
|
+
// - Default 0 corresponds to the current one
|
|
70
|
+
// - 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
|
|
71
|
+
// Remark : All the sets are defined in /src/services/patterns/ChartDesign.ts
|
|
72
|
+
colourSet: {
|
|
73
|
+
type: Number,
|
|
74
|
+
default: 0
|
|
75
|
+
},
|
|
76
|
+
// 6 patterns exist and are not randomly given but follow the order defined in patternsStandardList /src/services/patterns/ChartDesign.ts
|
|
77
|
+
// Additionally, a pattern has only one possible colour per colour set as defined in the Figma prototype.
|
|
78
|
+
// In some use cases, the chart may need to show a different orders of these patterns, this can be changed using the props newPatternsOrder
|
|
79
|
+
newPatternsOrder: {
|
|
80
|
+
type: Array as PropType<number[]>,
|
|
81
|
+
default: () => [0,1,2,3,4,5]
|
|
82
|
+
},
|
|
61
83
|
datasets: {
|
|
62
84
|
type: Array as PropType<BarData[]>,
|
|
63
85
|
default: () => []
|
|
@@ -86,6 +108,11 @@ const barDataProps = defineProps({
|
|
|
86
108
|
type: Boolean,
|
|
87
109
|
default: false,
|
|
88
110
|
},
|
|
111
|
+
// disable accessibility patterns
|
|
112
|
+
disableAccessibility: {
|
|
113
|
+
type: Boolean,
|
|
114
|
+
default: false,
|
|
115
|
+
},
|
|
89
116
|
firstTooltip: {
|
|
90
117
|
type: String,
|
|
91
118
|
default: 'content'
|
|
@@ -96,6 +123,22 @@ const barDataProps = defineProps({
|
|
|
96
123
|
}
|
|
97
124
|
})
|
|
98
125
|
|
|
126
|
+
// computed to make the colors list reactive to the props
|
|
127
|
+
const patternsColors = computed(() => {
|
|
128
|
+
return barDataProps.newPatternsOrder.length !== patternsStandardList.length
|
|
129
|
+
? colourSets[barDataProps.colourSet]
|
|
130
|
+
: barDataProps.newPatternsOrder.map((id) => {
|
|
131
|
+
return colourSets[barDataProps.colourSet][id]
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// computed to make the patterns list reactive to the props
|
|
136
|
+
const patternsOrderedList = computed(() => {return barDataProps.newPatternsOrder.length !== patternsStandardList.length
|
|
137
|
+
? patternsStandardList
|
|
138
|
+
: barDataProps.newPatternsOrder.map((id)=> {return patternsStandardList[id]})});
|
|
139
|
+
|
|
140
|
+
const disablePattern = computed(() => {return barDataProps.disableAccessibility})
|
|
141
|
+
|
|
99
142
|
const {
|
|
100
143
|
onHoverIndex,
|
|
101
144
|
barChartRef,
|
|
@@ -117,6 +160,9 @@ const chartData = computed(() => {
|
|
|
117
160
|
})
|
|
118
161
|
),
|
|
119
162
|
barDataProps.stacked,
|
|
163
|
+
barDataProps.disableAccessibility,
|
|
164
|
+
patternsColors.value,
|
|
165
|
+
patternsOrderedList.value,
|
|
120
166
|
0
|
|
121
167
|
)
|
|
122
168
|
};
|
|
@@ -147,7 +193,7 @@ const getChartData = (index: number, indexOfValueToHide: number | null, isStacke
|
|
|
147
193
|
if (indexOfValueToHide && indexOfOthersLabelIfNull.value) {
|
|
148
194
|
data.splice(indexOfOthersLabelIfNull.value, 1);
|
|
149
195
|
}
|
|
150
|
-
|
|
196
|
+
|
|
151
197
|
return data.map((data: { rate: number }) => data.rate);
|
|
152
198
|
};
|
|
153
199
|
|
|
@@ -202,14 +248,17 @@ const options = computed(() => ({
|
|
|
202
248
|
chartType: TooltipChartType.BAR_CHART,
|
|
203
249
|
firstLineLabel: xValue,
|
|
204
250
|
secondLineLabel: yValue
|
|
205
|
-
}
|
|
251
|
+
},
|
|
252
|
+
patternsColors.value,
|
|
253
|
+
patternsOrderedList.value,
|
|
254
|
+
barDataProps.disableAccessibility
|
|
206
255
|
);
|
|
207
256
|
}
|
|
208
257
|
}
|
|
209
258
|
},
|
|
210
259
|
scales: {
|
|
211
260
|
x: {
|
|
212
|
-
stacked: true,
|
|
261
|
+
stacked: true,
|
|
213
262
|
},
|
|
214
263
|
y: {
|
|
215
264
|
stacked: true,
|
|
@@ -223,11 +272,14 @@ const options = computed(() => ({
|
|
|
223
272
|
}
|
|
224
273
|
}));
|
|
225
274
|
|
|
226
|
-
const htmlLegendPlugin = privateGetHtmlLegendPlugin(legendContainer, selectMode);
|
|
275
|
+
const htmlLegendPlugin = ref(privateGetHtmlLegendPlugin(legendContainer, selectMode, disablePattern, patternsColors, patternsOrderedList));
|
|
227
276
|
|
|
228
277
|
watch(onHoverIndex, () => {
|
|
229
278
|
reloadChart();
|
|
230
279
|
}, { deep: true });
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
231
283
|
</script>
|
|
232
284
|
|
|
233
285
|
<style scoped>
|
|
@@ -16,6 +16,7 @@ export const Default = {
|
|
|
16
16
|
height: "400px",
|
|
17
17
|
width: "400px",
|
|
18
18
|
labels: ["Data One", "Data Two"],
|
|
19
|
+
disableAccessibility: false,
|
|
19
20
|
data: [
|
|
20
21
|
{
|
|
21
22
|
value: 2771824.19,
|
|
@@ -44,6 +45,7 @@ export const MultipleData = {
|
|
|
44
45
|
"Data Six",
|
|
45
46
|
],
|
|
46
47
|
maxValues: 3,
|
|
48
|
+
disableAccessibility: false,
|
|
47
49
|
data: [
|
|
48
50
|
{
|
|
49
51
|
value: 2771824.19,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="container">
|
|
3
3
|
<div class="main">
|
|
4
|
-
<Doughnut
|
|
5
|
-
v-if="doughnutChartData"
|
|
6
|
-
ref='doughnutRef'
|
|
4
|
+
<Doughnut
|
|
5
|
+
v-if="doughnutChartData"
|
|
6
|
+
ref='doughnutRef'
|
|
7
7
|
:data='doughnutChartData as ChartData<"doughnut", number[], unknown>'
|
|
8
|
-
:options='options'
|
|
8
|
+
:options='options'
|
|
9
9
|
:plugins='htmlLegendPlugin'
|
|
10
10
|
:cssClasses:="cssClasses"
|
|
11
11
|
:max-values="maxValues"
|
|
@@ -45,19 +45,19 @@ ChartJS.register(
|
|
|
45
45
|
);
|
|
46
46
|
|
|
47
47
|
const {
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
colourSets,
|
|
49
|
+
patternsStandardList
|
|
50
50
|
} = ChartDesign();
|
|
51
51
|
|
|
52
52
|
const {
|
|
53
53
|
onHoverIndex,
|
|
54
54
|
doughnutRef,
|
|
55
|
-
|
|
55
|
+
getBackgroundColor,
|
|
56
56
|
privateGetHtmlLegendPlugin,
|
|
57
57
|
getOnHoverOptions,
|
|
58
58
|
groupDataAfterNthValue,
|
|
59
59
|
getDoughnutLabels,
|
|
60
|
-
|
|
60
|
+
getBorderColor
|
|
61
61
|
} = doughnutChartFunction();
|
|
62
62
|
const selectMode = ref(false);
|
|
63
63
|
const legendContainer = ref<HTMLElement | null>(null);
|
|
@@ -79,6 +79,27 @@ const doughnutDataProps = defineProps({
|
|
|
79
79
|
default: '',
|
|
80
80
|
type: String,
|
|
81
81
|
},
|
|
82
|
+
// disable accessibility patterns
|
|
83
|
+
disableAccessibility: {
|
|
84
|
+
type: Boolean,
|
|
85
|
+
default: false
|
|
86
|
+
},
|
|
87
|
+
// colourSet props is used to choose the colour set of the charts as defined in the Figma prototypes.
|
|
88
|
+
// 7 colour sets are currently defined :
|
|
89
|
+
// - Default 0 corresponds to the current one
|
|
90
|
+
// - 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
|
|
91
|
+
// Remark : All the sets are defined in /src/services/patterns/ChartDesign.ts
|
|
92
|
+
colourSet: {
|
|
93
|
+
default:'0',
|
|
94
|
+
type: Number
|
|
95
|
+
},
|
|
96
|
+
// 6 patterns exist and are not randomly given but follow the order defined in patternsStandardList /src/services/patterns/ChartDesign.ts
|
|
97
|
+
// Additionally, a pattern has only one possible colour per colour set as defined in the Figma prototype.
|
|
98
|
+
// In some use cases, the chart may need to show a different orders of these patterns, this can be changed using the props newPatternsOrder
|
|
99
|
+
newPatternsOrder: {
|
|
100
|
+
type: Array as PropType<number[]>,
|
|
101
|
+
default: () => [0,1,2,3,4,5]
|
|
102
|
+
},
|
|
82
103
|
width: {
|
|
83
104
|
type: String,
|
|
84
105
|
default: '400px',
|
|
@@ -102,6 +123,23 @@ const doughnutDataProps = defineProps({
|
|
|
102
123
|
},
|
|
103
124
|
})
|
|
104
125
|
|
|
126
|
+
const patternsColors = computed( () => {
|
|
127
|
+
return doughnutDataProps.newPatternsOrder.length !== 6
|
|
128
|
+
? colourSets[doughnutDataProps.colourSet]
|
|
129
|
+
: doughnutDataProps.newPatternsOrder.map((id) => {
|
|
130
|
+
return colourSets[doughnutDataProps.colourSet][id]
|
|
131
|
+
})
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const patternsOrderedList = computed(() => {
|
|
135
|
+
return doughnutDataProps.newPatternsOrder.length !== 6
|
|
136
|
+
? patternsStandardList
|
|
137
|
+
: doughnutDataProps.newPatternsOrder.map((id) => {
|
|
138
|
+
return patternsStandardList[id]
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
|
|
105
143
|
const doughnutChartData = computed(() => {
|
|
106
144
|
return {
|
|
107
145
|
labels: getDoughnutLabels(doughnutDataProps.labels,
|
|
@@ -109,7 +147,8 @@ const doughnutChartData = computed(() => {
|
|
|
109
147
|
datasets: [
|
|
110
148
|
{
|
|
111
149
|
data: groupDataAfterNthValue(doughnutDataProps.data, doughnutDataProps.maxValues).map((x: GenericData) => x.rate),
|
|
112
|
-
backgroundColor:
|
|
150
|
+
backgroundColor: getBackgroundColor(patternsColors.value, patternsOrderedList.value, doughnutDataProps.disableAccessibility),
|
|
151
|
+
borderColor: getBorderColor(patternsColors.value)
|
|
113
152
|
}
|
|
114
153
|
]
|
|
115
154
|
}
|
|
@@ -120,7 +159,7 @@ const getTooltipData = (context: Context) => {
|
|
|
120
159
|
if (!dataIndex) {
|
|
121
160
|
return '';
|
|
122
161
|
}
|
|
123
|
-
const tooltipData =
|
|
162
|
+
const tooltipData =
|
|
124
163
|
groupDataAfterNthValue(doughnutDataProps.data, doughnutDataProps.maxValues)[dataIndex];
|
|
125
164
|
const rate = formatWithThousandsSeprators(tooltipData.rate);
|
|
126
165
|
const value = formatWithThousandsSeprators(tooltipData.value);
|
|
@@ -133,62 +172,70 @@ function getSpacing () {
|
|
|
133
172
|
}
|
|
134
173
|
|
|
135
174
|
// @ts-ignore
|
|
136
|
-
const options = computed(() =>
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
175
|
+
const options = computed(() => {
|
|
176
|
+
const colors = patternsColors.value;
|
|
177
|
+
const patterns = patternsOrderedList.value;
|
|
178
|
+
return {
|
|
179
|
+
onHover: getOnHoverOptions(),
|
|
180
|
+
plugins: {
|
|
181
|
+
legend: {
|
|
182
|
+
display: false,
|
|
183
|
+
// @ts-ignore
|
|
184
|
+
position: 'bottom' as const,
|
|
185
|
+
align: 'start' as const,
|
|
186
|
+
labels: {
|
|
187
|
+
pointStyle: 'rectRounded',
|
|
188
|
+
usePointStyle: true
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
title: {
|
|
192
|
+
display: false
|
|
193
|
+
},
|
|
194
|
+
tooltip: {
|
|
195
|
+
enabled: false,
|
|
196
|
+
external: function (context: Context) {
|
|
197
|
+
new GenericTooltipService().createTooltip(
|
|
198
|
+
context,
|
|
199
|
+
getTooltipData,
|
|
200
|
+
{
|
|
201
|
+
chartType: TooltipChartType.DOUGHNUT
|
|
202
|
+
},
|
|
203
|
+
colors,
|
|
204
|
+
patterns,
|
|
205
|
+
disablePattern.value
|
|
206
|
+
);
|
|
207
|
+
}
|
|
147
208
|
}
|
|
148
209
|
},
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
context,
|
|
157
|
-
getTooltipData,
|
|
158
|
-
{
|
|
159
|
-
chartType: TooltipChartType.DOUGHNUT
|
|
160
|
-
}
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
},
|
|
165
|
-
radius: '90%',
|
|
166
|
-
cutout: '70%',
|
|
167
|
-
borderWidth: 3,
|
|
168
|
-
borderColor: function (context: any) {
|
|
169
|
-
return (onHoverIndex.value !== null && context.dataIndex !== (onHoverIndex.value))
|
|
170
|
-
? patternsColorsLowerOpacity[context.dataIndex]
|
|
171
|
-
: patternsColors[context.dataIndex];
|
|
172
|
-
},
|
|
173
|
-
spacing: getSpacing(),
|
|
174
|
-
hoverOffset: 4
|
|
175
|
-
}));
|
|
210
|
+
radius: '90%',
|
|
211
|
+
cutout: '70%',
|
|
212
|
+
borderWidth: 3,
|
|
213
|
+
spacing: getSpacing(),
|
|
214
|
+
hoverOffset: 4
|
|
215
|
+
}
|
|
216
|
+
});
|
|
176
217
|
|
|
177
218
|
const doughnutDataAndLabels = {
|
|
178
219
|
data: doughnutDataProps.data,
|
|
179
220
|
labels: doughnutDataProps.labels
|
|
180
221
|
}
|
|
222
|
+
const disablePattern = computed(() => {return doughnutDataProps.disableAccessibility})
|
|
181
223
|
|
|
182
|
-
const htmlLegendPlugin = computed(() => privateGetHtmlLegendPlugin(legendContainer, selectMode, doughnutDataProps.maxValues, doughnutDataAndLabels));
|
|
224
|
+
const htmlLegendPlugin = computed(() => privateGetHtmlLegendPlugin(legendContainer, selectMode, disablePattern, patternsColors, patternsOrderedList, doughnutDataProps.maxValues, doughnutDataAndLabels));
|
|
183
225
|
|
|
184
226
|
onMounted(() =>{
|
|
185
|
-
getBackgroundColor();
|
|
227
|
+
getBackgroundColor(patternsColors.value, patternsOrderedList.value, doughnutDataProps.disableAccessibility);
|
|
186
228
|
});
|
|
187
229
|
watch(onHoverIndex, (newValue, oldValue) => {
|
|
188
230
|
if (newValue !== oldValue) {
|
|
189
|
-
getBackgroundColor();
|
|
231
|
+
getBackgroundColor(patternsColors.value, patternsOrderedList.value, doughnutDataProps.disableAccessibility);
|
|
190
232
|
}
|
|
191
233
|
});
|
|
234
|
+
|
|
235
|
+
watch(disablePattern, () => {
|
|
236
|
+
getBackgroundColor(patternsColors.value, patternsOrderedList.value, doughnutDataProps.disableAccessibility)
|
|
237
|
+
});
|
|
238
|
+
|
|
192
239
|
</script>
|
|
193
240
|
|
|
194
241
|
<style scoped>
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
import { TooltipChartType } from '../../types/TooltipChartType';
|
|
29
29
|
import { formatTicks } from '../../services/FormatUtilities';
|
|
30
30
|
import type { ChartItem } from '../../services/ChartsCommonLegend';
|
|
31
|
+
import ChartDesign from '../../services/patterns/ChartDesign';
|
|
31
32
|
|
|
32
33
|
import {
|
|
33
34
|
createHtmlLegendItemText,
|
|
@@ -60,6 +61,12 @@
|
|
|
60
61
|
LinearScale
|
|
61
62
|
);
|
|
62
63
|
|
|
64
|
+
const {
|
|
65
|
+
colourSets,
|
|
66
|
+
patternsStandardList
|
|
67
|
+
} = ChartDesign();
|
|
68
|
+
|
|
69
|
+
|
|
63
70
|
const legendContainer = ref(null);
|
|
64
71
|
const selectMode = ref(false);
|
|
65
72
|
const lineDataProps = defineProps({
|
|
@@ -79,6 +86,27 @@
|
|
|
79
86
|
type: String,
|
|
80
87
|
default: '400px',
|
|
81
88
|
},
|
|
89
|
+
// disable accessibility patterns
|
|
90
|
+
disableAccessibility: {
|
|
91
|
+
type: Boolean,
|
|
92
|
+
default: false
|
|
93
|
+
},
|
|
94
|
+
// colourSet props is used to choose the colour set of the charts as defined in the Figma prototypes.
|
|
95
|
+
// 7 colour sets are currently defined :
|
|
96
|
+
// - Default 0 corresponds to the current one
|
|
97
|
+
// - 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
|
|
98
|
+
// Remark : All the sets are defined in /src/services/patterns/ChartDesign.ts
|
|
99
|
+
colourSet: {
|
|
100
|
+
type: Number,
|
|
101
|
+
default: 0
|
|
102
|
+
},
|
|
103
|
+
// 6 patterns exist and are not randomly given but follow the order defined in patternsStandardList /src/services/patterns/ChartDesign.ts
|
|
104
|
+
// Additionally, a pattern has only one possible colour per colour set as defined in the Figma prototype.
|
|
105
|
+
// In some use cases, the chart may need to show a different orders of these patterns, this can be changed using the props newPatternsOrder
|
|
106
|
+
newPatternsOrder: {
|
|
107
|
+
type: Array as PropType<number[]>,
|
|
108
|
+
default: () => [0,1,2,3,4,5]
|
|
109
|
+
},
|
|
82
110
|
lines: {
|
|
83
111
|
type: Array as PropType<LineData[]>,
|
|
84
112
|
default: () => {},
|
|
@@ -101,6 +129,15 @@
|
|
|
101
129
|
},
|
|
102
130
|
})
|
|
103
131
|
|
|
132
|
+
const patternsColors = computed(() => lineDataProps.newPatternsOrder.length !== 6
|
|
133
|
+
? colourSets[lineDataProps.colourSet]
|
|
134
|
+
: lineDataProps.newPatternsOrder.map((id)=> {return colourSets[lineDataProps.colourSet][id]})
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
const patternsOrderedList = lineDataProps.newPatternsOrder.length !== 6
|
|
138
|
+
? patternsStandardList
|
|
139
|
+
: lineDataProps.newPatternsOrder.map((id)=> {return patternsStandardList[id]})
|
|
140
|
+
|
|
104
141
|
const getTooltipData = (context: Context) => {
|
|
105
142
|
const datasetIndex = context.tooltip.dataPoints[0].datasetIndex;
|
|
106
143
|
const dataIndex = context.tooltip.dataPoints[0].dataIndex;
|
|
@@ -124,7 +161,7 @@
|
|
|
124
161
|
datasets: [
|
|
125
162
|
{
|
|
126
163
|
type: 'line' as const,
|
|
127
|
-
borderColor:
|
|
164
|
+
borderColor: patternsColors.value[0],
|
|
128
165
|
pointStyle: 'rectRot',
|
|
129
166
|
pointBackgroundColor: '#FFFFFF',
|
|
130
167
|
pointRadius: 5,
|
|
@@ -134,7 +171,7 @@
|
|
|
134
171
|
},
|
|
135
172
|
{
|
|
136
173
|
type: 'line' as const,
|
|
137
|
-
borderColor:
|
|
174
|
+
borderColor: patternsColors.value[1],
|
|
138
175
|
pointStyle: 'circle',
|
|
139
176
|
pointBackgroundColor: '#FFFFFF',
|
|
140
177
|
pointRadius: 5,
|
|
@@ -202,12 +239,18 @@
|
|
|
202
239
|
chartType: TooltipChartType.LINE_CHART,
|
|
203
240
|
firstLineLabel: tooltipFirstLine,
|
|
204
241
|
secondLineLabel: tooltipValueAttribute.value
|
|
205
|
-
}
|
|
242
|
+
},
|
|
243
|
+
patternsColors.value,
|
|
244
|
+
patternsOrderedList,
|
|
245
|
+
lineDataProps.disableAccessibility
|
|
206
246
|
);
|
|
207
247
|
}
|
|
208
248
|
}
|
|
209
249
|
},
|
|
210
250
|
scales: {
|
|
251
|
+
x: {
|
|
252
|
+
offset: true,
|
|
253
|
+
},
|
|
211
254
|
y: {
|
|
212
255
|
type: 'linear' as const,
|
|
213
256
|
display: true,
|