@mozaic-ds/chart 0.1.0-beta.0 → 0.1.0-beta.10
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 +3390 -2582
- package/dist/mozaic-chart.umd.cjs +11 -11
- package/dist/style.css +1 -1
- package/package.json +38 -24
- package/src/components/bar/BarChart.stories.ts +13 -9
- package/src/components/bar/BarChart.vue +234 -106
- package/src/components/bar/index.ts +8 -0
- package/src/components/doughnut/DoughnutChart.stories.ts +3 -0
- package/src/components/doughnut/DoughnutChart.vue +205 -95
- package/src/components/doughnut/index.ts +8 -0
- package/src/components/index.ts +4 -0
- package/src/components/line/LineChart.stories.ts +0 -1
- package/src/components/line/LineChart.vue +310 -219
- package/src/components/line/index.ts +8 -0
- package/src/components/mixed/MixedBarLineChart.stories.ts +87 -0
- package/src/components/mixed/MixedBarLineChart.vue +404 -0
- package/src/components/mixed/index.ts +8 -0
- package/src/components/radar/RadarChart.stories.ts +2 -2
- package/src/components/radar/RadarChart.vue +231 -126
- package/src/components/radar/index.ts +8 -0
- package/src/main.ts +2 -1
- package/src/plugin.ts +19 -0
- package/src/services/BarChartFunctions.ts +16 -20
- package/src/services/ChartsCommonLegend.ts +54 -47
- package/src/services/ColorFunctions.ts +4 -0
- package/src/services/DoughnutChartFunctions.ts +111 -59
- package/src/services/FormatUtilities.ts +1 -1
- package/src/services/GenericTooltipService.ts +55 -34
- package/src/services/MixedBarLineFunctions.ts +280 -0
- package/src/services/RadarChartFunctions.ts +13 -11
- 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/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/MixedBarLineData.ts +7 -0
- package/src/types/TooltipChartType.ts +1 -0
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="container">
|
|
3
|
-
<div class=
|
|
3
|
+
<div class="main">
|
|
4
4
|
<Radar
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
:style='{ height, cursor:"pointer",}'
|
|
5
|
+
v-if="radarData"
|
|
6
|
+
:id="chartId"
|
|
7
|
+
:data="radarData"
|
|
8
|
+
:options="chartOptions"
|
|
9
|
+
:plugins="radarPlugins"
|
|
10
|
+
:class="cssClasses"
|
|
11
|
+
:style="[{ height, cursor: 'pointer' }, styles]"
|
|
13
12
|
/>
|
|
14
13
|
</div>
|
|
15
|
-
<div ref=
|
|
14
|
+
<div ref="legendContainer" class="legendContainer" />
|
|
16
15
|
</div>
|
|
17
16
|
</template>
|
|
18
17
|
|
|
19
|
-
<script setup lang=
|
|
18
|
+
<script setup lang="ts">
|
|
20
19
|
import { PropType, ref, computed } from 'vue';
|
|
21
20
|
import type { Area } from '../../types/RadarData';
|
|
22
21
|
import { Radar } from 'vue-chartjs';
|
|
23
22
|
import type { ActiveElement, ChartData } from 'chart.js';
|
|
24
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
Context,
|
|
25
|
+
GenericTooltipService,
|
|
26
|
+
} from '../../services/GenericTooltipService';
|
|
25
27
|
import { formatWithThousandsSeprators } from '../../services/FormatUtilities';
|
|
26
28
|
import { TooltipChartType } from '../../types/TooltipChartType';
|
|
27
29
|
import { drawLabels } from '../../services/RadarChartFunctions';
|
|
28
30
|
import type { Chart, ChartItem } from '../../services/ChartsCommonLegend';
|
|
31
|
+
import { addAlpha } from '../../services/ColorFunctions';
|
|
29
32
|
import {
|
|
30
33
|
Chart as ChartJS,
|
|
31
34
|
Filler,
|
|
@@ -35,7 +38,7 @@ import {
|
|
|
35
38
|
RadialLinearScale,
|
|
36
39
|
Title,
|
|
37
40
|
Tooltip,
|
|
38
|
-
Plugin
|
|
41
|
+
Plugin,
|
|
39
42
|
} from 'chart.js';
|
|
40
43
|
|
|
41
44
|
import {
|
|
@@ -45,9 +48,11 @@ import {
|
|
|
45
48
|
createLegendElementWithSquareArea,
|
|
46
49
|
getOrCreateLegendList,
|
|
47
50
|
hideAllButThis,
|
|
48
|
-
switchItemVisibility
|
|
51
|
+
switchItemVisibility,
|
|
49
52
|
} from '../../services/ChartsCommonLegend';
|
|
50
53
|
|
|
54
|
+
import ChartDesign from '../../services/patterns/ChartDesign';
|
|
55
|
+
|
|
51
56
|
ChartJS.register(
|
|
52
57
|
Title,
|
|
53
58
|
Tooltip,
|
|
@@ -55,88 +60,164 @@ ChartJS.register(
|
|
|
55
60
|
RadialLinearScale,
|
|
56
61
|
LineElement,
|
|
57
62
|
PointElement,
|
|
58
|
-
Filler
|
|
63
|
+
Filler
|
|
59
64
|
);
|
|
65
|
+
|
|
66
|
+
const { colourSets, patternsStandardList } = ChartDesign();
|
|
67
|
+
|
|
60
68
|
const radarComponentChartProps = defineProps({
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Value of the id attribute present on the <canvas> tag element the chart
|
|
71
|
+
*/
|
|
72
|
+
chartId: {
|
|
73
|
+
type: String,
|
|
74
|
+
default: 'radar-chart',
|
|
75
|
+
},
|
|
76
|
+
/**
|
|
77
|
+
* Value of the `height` css property used to define the height of the <canvas> element
|
|
78
|
+
*/
|
|
79
|
+
height: {
|
|
80
|
+
type: String,
|
|
81
|
+
default: '400px',
|
|
82
|
+
},
|
|
83
|
+
/**
|
|
84
|
+
* Labels used to label the index axis (default x axes). See [Data structures documentation](https://www.chartjs.org/docs/latest/general/data-structures.html)
|
|
85
|
+
*/
|
|
86
|
+
labels: {
|
|
70
87
|
type: Array as PropType<string[]>,
|
|
71
|
-
default: () => []
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
default: () => [],
|
|
89
|
+
},
|
|
90
|
+
/**
|
|
91
|
+
* Disable accessibility patterns
|
|
92
|
+
*/
|
|
93
|
+
disableAccessibility: {
|
|
94
|
+
type: Boolean,
|
|
95
|
+
default: false,
|
|
96
|
+
},
|
|
97
|
+
/**
|
|
98
|
+
* Used to choose the colour set of the charts as defined in the Figma prototypes.
|
|
99
|
+
* 7 colour sets are currently defined:
|
|
100
|
+
* - Default 0 corresponds to the current one
|
|
101
|
+
* - 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)
|
|
102
|
+
* Note: All the sets are defined in /src/services/patterns/ChartDesign.ts
|
|
103
|
+
*/
|
|
104
|
+
colourSet: {
|
|
105
|
+
type: Number,
|
|
106
|
+
default: 0,
|
|
107
|
+
},
|
|
108
|
+
/**
|
|
109
|
+
* 6 patterns exist and are not randomly given but follow the order defined in [patternsStandardList](/src/services/patterns/ChartDesign.ts)
|
|
110
|
+
* Additionally, a pattern has only one possible colour per colour set as defined in the Figma prototype.
|
|
111
|
+
* In some use cases, the chart may need to show a different orders of these patterns, this can be changed using the props newPatternsOrder
|
|
112
|
+
*/
|
|
113
|
+
newPatternsOrder: {
|
|
114
|
+
type: Array as PropType<number[]>,
|
|
115
|
+
default: () => [0, 1, 2, 3, 4, 5],
|
|
116
|
+
},
|
|
117
|
+
/**
|
|
118
|
+
* Value of the `datasets` key present in the `data` object passed to the Chart config
|
|
119
|
+
*/
|
|
120
|
+
datasets: {
|
|
121
|
+
type: Array as PropType<Area[]>,
|
|
122
|
+
default: () => [],
|
|
123
|
+
},
|
|
124
|
+
/**
|
|
125
|
+
* Add custom CSS classes to the <canvas> element
|
|
126
|
+
*/
|
|
127
|
+
cssClasses: {
|
|
128
|
+
default: '',
|
|
129
|
+
type: String,
|
|
130
|
+
},
|
|
131
|
+
/**
|
|
132
|
+
* Add custom CSS styles to the <canvas> element
|
|
133
|
+
*/
|
|
134
|
+
styles: {
|
|
135
|
+
type: Object as PropType<Partial<CSSStyleDeclaration>>,
|
|
136
|
+
default: () => {},
|
|
137
|
+
},
|
|
138
|
+
/**
|
|
139
|
+
* Value of the `plugins` key passed to the Chart config
|
|
140
|
+
*/
|
|
141
|
+
plugins: {
|
|
142
|
+
type: Array as PropType<Plugin<'radar'>[]>,
|
|
143
|
+
default: () => [],
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const patternsColors = computed(() =>
|
|
148
|
+
radarComponentChartProps.newPatternsOrder.length !== 6
|
|
149
|
+
? colourSets[radarComponentChartProps.colourSet]
|
|
150
|
+
: radarComponentChartProps.newPatternsOrder.map((id) => {
|
|
151
|
+
return colourSets[radarComponentChartProps.colourSet][id];
|
|
152
|
+
})
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
const patternsOrderedList = computed(() =>
|
|
156
|
+
radarComponentChartProps.newPatternsOrder.length !== 6
|
|
157
|
+
? patternsStandardList
|
|
158
|
+
: radarComponentChartProps.newPatternsOrder.map((id) => {
|
|
159
|
+
return patternsStandardList[id];
|
|
160
|
+
})
|
|
161
|
+
);
|
|
162
|
+
|
|
90
163
|
const radarData = computed<ChartData<'radar'>>(() => ({
|
|
91
164
|
labels: getRadarLabels(),
|
|
92
165
|
datasets: [
|
|
93
166
|
{
|
|
94
|
-
label:
|
|
95
|
-
backgroundColor:
|
|
96
|
-
borderColor:
|
|
97
|
-
pointBackgroundColor: '#
|
|
98
|
-
pointBorderColor:
|
|
167
|
+
label: radarComponentChartProps.datasets[0].label,
|
|
168
|
+
backgroundColor: addAlpha(patternsColors.value[0], 0.1),
|
|
169
|
+
borderColor: patternsColors.value[0],
|
|
170
|
+
pointBackgroundColor: '#FFFFFF',
|
|
171
|
+
pointBorderColor: patternsColors.value[0],
|
|
99
172
|
pointBorderWidth: 2,
|
|
100
173
|
borderWidth: 2,
|
|
101
174
|
pointHitRadius: 55,
|
|
102
175
|
pointRadius: 5,
|
|
103
|
-
pointHoverBackgroundColor:
|
|
104
|
-
pointHoverBorderColor:
|
|
105
|
-
data: radarComponentChartProps.
|
|
176
|
+
pointHoverBackgroundColor: patternsColors.value[0],
|
|
177
|
+
pointHoverBorderColor: patternsColors.value[0],
|
|
178
|
+
data: radarComponentChartProps.datasets[0].areaData.map(
|
|
179
|
+
(x: { position: number }) => x.position
|
|
180
|
+
),
|
|
106
181
|
},
|
|
107
182
|
{
|
|
108
|
-
label:
|
|
109
|
-
backgroundColor:
|
|
110
|
-
borderColor:
|
|
111
|
-
pointBackgroundColor: '
|
|
112
|
-
pointBorderColor:
|
|
183
|
+
label: radarComponentChartProps.datasets[1].label,
|
|
184
|
+
backgroundColor: addAlpha(patternsColors.value[1], 0.1),
|
|
185
|
+
borderColor: patternsColors.value[1],
|
|
186
|
+
pointBackgroundColor: '#FFFFFF',
|
|
187
|
+
pointBorderColor: patternsColors.value[1],
|
|
113
188
|
pointBorderWidth: 2,
|
|
114
189
|
borderWidth: 2,
|
|
115
190
|
pointHitRadius: 55,
|
|
116
191
|
pointRadius: 5,
|
|
117
192
|
pointStyle: 'rectRot',
|
|
118
|
-
pointHoverBackgroundColor:
|
|
119
|
-
pointHoverBorderColor:
|
|
120
|
-
data: radarComponentChartProps.
|
|
121
|
-
|
|
122
|
-
|
|
193
|
+
pointHoverBackgroundColor: patternsColors.value[1],
|
|
194
|
+
pointHoverBorderColor: patternsColors.value[1],
|
|
195
|
+
data: radarComponentChartProps.datasets[1].areaData.map(
|
|
196
|
+
(x: { position: number }) => x.position
|
|
197
|
+
),
|
|
198
|
+
},
|
|
199
|
+
],
|
|
123
200
|
}));
|
|
124
201
|
|
|
125
202
|
const chartOptions: any = {
|
|
126
|
-
|
|
203
|
+
onClick: (
|
|
204
|
+
_ingnore: unknown,
|
|
205
|
+
clickedElements: ActiveElement[],
|
|
206
|
+
chart: Chart
|
|
207
|
+
) => {
|
|
127
208
|
if (clickedElements[0]) {
|
|
128
209
|
hideAllButThis(chart, clickedElements[0].datasetIndex, selectMode);
|
|
129
210
|
}
|
|
130
211
|
},
|
|
131
212
|
plugins: {
|
|
132
213
|
htmlLegend: {
|
|
133
|
-
containerID: 'legend-container'
|
|
214
|
+
containerID: 'legend-container',
|
|
134
215
|
},
|
|
135
216
|
legend: {
|
|
136
|
-
display: false
|
|
217
|
+
display: false,
|
|
137
218
|
},
|
|
138
219
|
title: {
|
|
139
|
-
display: false
|
|
220
|
+
display: false,
|
|
140
221
|
},
|
|
141
222
|
tooltip: {
|
|
142
223
|
enabled: false,
|
|
@@ -145,60 +226,75 @@ const chartOptions: any = {
|
|
|
145
226
|
new GenericTooltipService().createTooltip(
|
|
146
227
|
context,
|
|
147
228
|
getTooltipData,
|
|
148
|
-
{ chartType: TooltipChartType.RADAR }
|
|
229
|
+
{ chartType: TooltipChartType.RADAR },
|
|
230
|
+
patternsColors.value,
|
|
231
|
+
patternsOrderedList.value,
|
|
232
|
+
radarComponentChartProps.disableAccessibility
|
|
149
233
|
);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
234
|
+
},
|
|
235
|
+
},
|
|
152
236
|
},
|
|
153
237
|
layout: {
|
|
154
|
-
padding:
|
|
238
|
+
padding: {
|
|
239
|
+
left: 130,
|
|
240
|
+
right: 95,
|
|
241
|
+
top: 95,
|
|
242
|
+
bottom: 95,
|
|
243
|
+
},
|
|
155
244
|
},
|
|
156
245
|
scales: {
|
|
157
246
|
r: {
|
|
158
247
|
min: 0,
|
|
159
248
|
max: 100,
|
|
160
249
|
pointLabels: {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
250
|
+
display: false,
|
|
251
|
+
font: {
|
|
252
|
+
weight: 400,
|
|
253
|
+
family: 'Roboto',
|
|
254
|
+
},
|
|
165
255
|
},
|
|
166
256
|
ticks: {
|
|
167
257
|
display: false,
|
|
168
|
-
stepSize: 25
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
258
|
+
stepSize: 25,
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
};
|
|
173
263
|
const legendContainer = ref(null);
|
|
174
264
|
const selectMode = ref(false);
|
|
175
|
-
function splitLabelIfTooLong
|
|
176
|
-
const radarLimitLabelLength =
|
|
177
|
-
if (
|
|
178
|
-
|
|
265
|
+
function splitLabelIfTooLong(axisLabel: string, buildValue: string) {
|
|
266
|
+
const radarLimitLabelLength = 9;
|
|
267
|
+
if (
|
|
268
|
+
axisLabel.length > radarLimitLabelLength &&
|
|
269
|
+
axisLabel.includes(' ', radarLimitLabelLength)
|
|
270
|
+
) {
|
|
271
|
+
const indexOfFirstSpaceAfterLimit: number = axisLabel.indexOf(
|
|
272
|
+
' ',
|
|
273
|
+
radarLimitLabelLength
|
|
274
|
+
);
|
|
179
275
|
return [
|
|
180
276
|
axisLabel.substring(0, indexOfFirstSpaceAfterLimit),
|
|
181
277
|
axisLabel.substring(indexOfFirstSpaceAfterLimit),
|
|
182
|
-
buildValue
|
|
278
|
+
buildValue,
|
|
183
279
|
];
|
|
184
280
|
}
|
|
185
|
-
return [
|
|
186
|
-
axisLabel,
|
|
187
|
-
buildValue
|
|
188
|
-
];
|
|
281
|
+
return [axisLabel, buildValue];
|
|
189
282
|
}
|
|
190
283
|
const getRadarLabels = () => {
|
|
191
284
|
return radarComponentChartProps.labels.map((label: string, index: number) => {
|
|
192
|
-
const buildValue = radarComponentChartProps.
|
|
193
|
-
|
|
285
|
+
const buildValue = radarComponentChartProps.datasets[0].areaData[index]
|
|
286
|
+
.value
|
|
287
|
+
? `${formatNumber(
|
|
288
|
+
radarComponentChartProps.datasets[0].areaData[index].value + ''
|
|
289
|
+
)} ${radarComponentChartProps.datasets[0].areaData[index].unit}`
|
|
194
290
|
: 'No Data';
|
|
195
291
|
return splitLabelIfTooLong(label, buildValue);
|
|
196
292
|
});
|
|
197
|
-
}
|
|
293
|
+
};
|
|
198
294
|
const formatNumber = (numberFromJson: string) => {
|
|
199
295
|
return formatWithThousandsSeprators(parseFloat(numberFromJson));
|
|
200
296
|
};
|
|
201
|
-
function createLegendElementWithCheckbox
|
|
297
|
+
function createLegendElementWithCheckbox(chart: any, item: ChartItem) {
|
|
202
298
|
const liContent = createLegendCheckbox(chart, item);
|
|
203
299
|
liContent.onclick = (e: Event) => {
|
|
204
300
|
switchItemVisibility(chart, item.datasetIndex, selectMode);
|
|
@@ -207,44 +303,53 @@ function createLegendElementWithCheckbox (chart: any, item: ChartItem) {
|
|
|
207
303
|
return liContent;
|
|
208
304
|
}
|
|
209
305
|
|
|
210
|
-
const radarPlugins = [
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
ul.firstChild
|
|
216
|
-
|
|
217
|
-
const items = chart.options.plugins.legend.labels.generateLabels(chart).reverse();
|
|
218
|
-
items.forEach((item: ChartItem) => {
|
|
219
|
-
const li = createHtmlLegendListElement(chart, selectMode, item.datasetIndex);
|
|
220
|
-
let liContent;
|
|
221
|
-
li.style.marginRight = '0.625rem';
|
|
222
|
-
if (!selectMode.value) {
|
|
223
|
-
liContent = createLegendElementWithSquareArea(item);
|
|
224
|
-
} else {
|
|
225
|
-
liContent = createLegendElementWithCheckbox(chart, item);
|
|
306
|
+
const radarPlugins = [
|
|
307
|
+
{
|
|
308
|
+
id: 'htmlLegend',
|
|
309
|
+
afterUpdate(chart: any) {
|
|
310
|
+
const ul = getOrCreateLegendList(legendContainer, 'row');
|
|
311
|
+
while (ul.firstChild) {
|
|
312
|
+
ul.firstChild.remove();
|
|
226
313
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
314
|
+
const items = chart.options.plugins.legend.labels
|
|
315
|
+
.generateLabels(chart)
|
|
316
|
+
.reverse();
|
|
317
|
+
items.forEach((item: ChartItem) => {
|
|
318
|
+
const li = createHtmlLegendListElement(
|
|
319
|
+
chart,
|
|
320
|
+
selectMode,
|
|
321
|
+
item.datasetIndex
|
|
322
|
+
);
|
|
323
|
+
let liContent;
|
|
324
|
+
li.style.marginRight = '0.625rem';
|
|
325
|
+
if (!selectMode.value) {
|
|
326
|
+
liContent = createLegendElementWithSquareArea(item, null, true);
|
|
327
|
+
} else {
|
|
328
|
+
liContent = createLegendElementWithCheckbox(chart, item);
|
|
329
|
+
}
|
|
330
|
+
li.appendChild(liContent);
|
|
331
|
+
li.appendChild(createHtmlLegendItemText(item));
|
|
332
|
+
ul.appendChild(li);
|
|
333
|
+
});
|
|
334
|
+
},
|
|
236
335
|
},
|
|
237
|
-
|
|
336
|
+
{
|
|
337
|
+
id: 'radarLabelPlugin',
|
|
338
|
+
beforeDraw(chart: any) {
|
|
339
|
+
drawLabels(chart, radarComponentChartProps);
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
];
|
|
238
343
|
|
|
239
344
|
const getTooltipData = (context: Context): string => {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
345
|
+
const datasetIndex = context.tooltip.dataPoints[0].datasetIndex as number;
|
|
346
|
+
const dataIndex = context.tooltip.dataPoints[0].dataIndex as number;
|
|
347
|
+
const data = radarComponentChartProps.datasets[datasetIndex];
|
|
348
|
+
return (
|
|
349
|
+
data.areaData[dataIndex].value.toFixed(2) +
|
|
350
|
+
' ' +
|
|
351
|
+
data.areaData[dataIndex].unit
|
|
352
|
+
);
|
|
248
353
|
};
|
|
249
354
|
</script>
|
|
250
355
|
|
|
@@ -262,4 +367,4 @@ const getTooltipData = (context: Context): string => {
|
|
|
262
367
|
justify-content: center;
|
|
263
368
|
align-items: center;
|
|
264
369
|
}
|
|
265
|
-
</style>
|
|
370
|
+
</style>
|
package/src/main.ts
CHANGED
|
@@ -2,5 +2,6 @@ import BarChart from "./components/bar/BarChart.vue";
|
|
|
2
2
|
import DoughnutChart from "./components/doughnut/DoughnutChart.vue";
|
|
3
3
|
import LineChart from "./components/line/LineChart.vue";
|
|
4
4
|
import RadarChart from "./components/radar/RadarChart.vue";
|
|
5
|
+
import MixedBarLineChart from "./components/mixed/MixedBarLineChart.vue";
|
|
5
6
|
|
|
6
|
-
export { BarChart, DoughnutChart, LineChart, RadarChart };
|
|
7
|
+
export { BarChart, DoughnutChart, LineChart, RadarChart, MixedBarLineChart };
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { App } from "vue";
|
|
2
|
+
import * as Components from "./components";
|
|
3
|
+
|
|
4
|
+
const MozaicChart = {
|
|
5
|
+
install: (app: App, options: {}) => {
|
|
6
|
+
Object.keys(Components).forEach((name) => {
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
app.component(name, Components[name]);
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default MozaicChart;
|
|
14
|
+
|
|
15
|
+
export { BarChart } from "./components/bar";
|
|
16
|
+
export { DoughnutChart } from "./components/doughnut";
|
|
17
|
+
export { LineChart } from "./components/line";
|
|
18
|
+
export { RadarChart } from "./components/radar";
|
|
19
|
+
export { MixedBarLineChart } from "./components/mixed";
|
|
@@ -4,14 +4,9 @@ import {
|
|
|
4
4
|
getHtmlLegendPlugin
|
|
5
5
|
} from './ChartsCommonLegend';
|
|
6
6
|
import PatternFunctions from './PatternFunctions';
|
|
7
|
-
import
|
|
7
|
+
import { addAlpha } from './ColorFunctions';
|
|
8
8
|
|
|
9
9
|
const { getPatternIndexWithShift } = PatternFunctions();
|
|
10
|
-
const {
|
|
11
|
-
patternsColors,
|
|
12
|
-
patternsColorsLowerOpacity,
|
|
13
|
-
patternsStandardList
|
|
14
|
-
} = ChartDesign();
|
|
15
10
|
|
|
16
11
|
interface Dataset {
|
|
17
12
|
data: any,
|
|
@@ -27,8 +22,8 @@ export default function () {
|
|
|
27
22
|
});
|
|
28
23
|
|
|
29
24
|
|
|
30
|
-
function privateGetHtmlLegendPlugin(legendContainer: Ref, selectMode: Ref<boolean>) {
|
|
31
|
-
return getHtmlLegendPlugin(legendContainer, selectMode, onHoverIndex);
|
|
25
|
+
function privateGetHtmlLegendPlugin(legendContainer: Ref, selectMode: Ref<boolean>, disableAccessibility: Ref<boolean>, patternsColors: Ref<string[]>, patternsList: Ref<((hover: boolean, color: string, disableAccessibility: boolean) => CanvasPattern)[]>) {
|
|
26
|
+
return getHtmlLegendPlugin(legendContainer, selectMode, onHoverIndex, disableAccessibility, patternsColors, patternsList);
|
|
32
27
|
}
|
|
33
28
|
// Hack to force the chart to reload on Hover
|
|
34
29
|
function reloadChart () {
|
|
@@ -36,16 +31,18 @@ export default function () {
|
|
|
36
31
|
borderWidth.value = 3;
|
|
37
32
|
}
|
|
38
33
|
|
|
39
|
-
function getStackedDatasets (datasets: Dataset[], stackDatasets: boolean, patternShifting?: number) {
|
|
34
|
+
function getStackedDatasets (datasets: Dataset[], stackDatasets: boolean, disableAccessibility: boolean, patternsColors: string[], patternsList: ((hover: boolean, color: string, disableAccessibility: boolean) => CanvasPattern)[], patternShifting?: number) {
|
|
35
|
+
// Hack to force refresh
|
|
36
|
+
const borderWithValue = borderWidth.value;
|
|
40
37
|
return datasets.map((dataset, index) => {
|
|
41
38
|
return {
|
|
42
39
|
borderColor: function (context: any) {
|
|
43
|
-
return getBorderColor(index, context.index, patternShifting);
|
|
40
|
+
return disableAccessibility ? '#00000000' : getBorderColor(index, context.index, patternsColors, patternShifting);
|
|
44
41
|
},
|
|
45
42
|
backgroundColor: function (context: any) {
|
|
46
|
-
return getPattern(index, context.index, patternShifting);
|
|
43
|
+
return getPattern(index, context.index, disableAccessibility, patternsColors, patternsList, patternShifting);
|
|
47
44
|
},
|
|
48
|
-
borderWidth:
|
|
45
|
+
borderWidth: function () {return disableAccessibility ? 1 : borderWithValue},
|
|
49
46
|
data: dataset.data,
|
|
50
47
|
label: dataset.label,
|
|
51
48
|
stack: `Stack ${stackDatasets ? '0' : index}`
|
|
@@ -53,26 +50,25 @@ export default function () {
|
|
|
53
50
|
});
|
|
54
51
|
}
|
|
55
52
|
|
|
56
|
-
function getDatasets (firstDataSet: Dataset, secondDataSet: Dataset) {
|
|
57
|
-
|
|
58
|
-
return getStacked;
|
|
53
|
+
function getDatasets (firstDataSet: Dataset, secondDataSet: Dataset, patternsColors: string[], patternsList: ((hover: boolean, color: string, disableAccessibility: boolean) => CanvasPattern)[], disableAccessibility: boolean) {
|
|
54
|
+
return getStackedDatasets([firstDataSet, secondDataSet], false, disableAccessibility, patternsColors, patternsList);
|
|
59
55
|
}
|
|
60
56
|
|
|
61
|
-
function getBorderColor (dataSetIndex: number, contextIndex: number, patternShifting?: number) {
|
|
57
|
+
function getBorderColor (dataSetIndex: number, contextIndex: number, patternsColors: string[], patternShifting?: number) {
|
|
62
58
|
const index = getPatternIndexWithShift(dataSetIndex, patternShifting);
|
|
63
59
|
if (displayFullOpacity(dataSetIndex, contextIndex)) {
|
|
64
60
|
return patternsColors[index];
|
|
65
61
|
} else {
|
|
66
|
-
return
|
|
62
|
+
return addAlpha(patternsColors[index],0.2);
|
|
67
63
|
}
|
|
68
64
|
}
|
|
69
65
|
|
|
70
|
-
function getPattern (dataSetIndex: number, contextIndex: number, patternShifting?: number) {
|
|
66
|
+
function getPattern (dataSetIndex: number, contextIndex: number, disableAccessibility: boolean, patternsColors: string[], patternsList: ((hover: boolean, color: string, disableAccessibility: boolean) => CanvasPattern)[], patternShifting?: number) {
|
|
71
67
|
const index = getPatternIndexWithShift(dataSetIndex, patternShifting);
|
|
72
68
|
if (displayFullOpacity(dataSetIndex, contextIndex)) {
|
|
73
|
-
return
|
|
69
|
+
return patternsList[index](false, patternsColors[index], disableAccessibility);
|
|
74
70
|
} else {
|
|
75
|
-
return
|
|
71
|
+
return patternsList[index](true, patternsColors[index], disableAccessibility);
|
|
76
72
|
}
|
|
77
73
|
}
|
|
78
74
|
|