@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.
- package/README.md +1 -1
- package/dist/mozaic-chart.js +2303 -2109
- package/dist/mozaic-chart.umd.cjs +9 -9
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/assets/base.css +1 -1
- package/src/components/bar/BarChart.stories.ts +99 -99
- package/src/components/bar/BarChart.vue +70 -53
- package/src/components/bar/index.ts +3 -3
- package/src/components/bubble/BubbleChart.stories.ts +12 -12
- package/src/components/bubble/BubbleChart.vue +118 -91
- package/src/components/bubble/index.ts +3 -3
- package/src/components/doughnut/DoughnutChart.stories.ts +38 -37
- package/src/components/doughnut/DoughnutChart.vue +89 -71
- package/src/components/doughnut/index.ts +3 -3
- package/src/components/index.ts +4 -4
- package/src/components/line/LineChart.stories.ts +38 -38
- package/src/components/line/LineChart.vue +54 -51
- package/src/components/line/index.ts +3 -3
- package/src/components/mixed/MixedBarLineChart.stories.ts +15 -15
- package/src/components/mixed/MixedBarLineChart.vue +44 -44
- package/src/components/mixed/index.ts +1 -1
- package/src/components/radar/RadarChart.stories.ts +100 -100
- package/src/components/radar/RadarChart.vue +41 -34
- package/src/components/radar/index.ts +3 -3
- package/src/main.ts +14 -7
- package/src/plugin.ts +9 -9
- package/src/services/BarChartFunctions.ts +133 -35
- package/src/services/BubbleTooltipService.ts +58 -56
- package/src/services/ChartsCommonLegend.ts +271 -127
- package/src/services/ColorFunctions.ts +1 -1
- package/src/services/DoughnutChartFunctions.ts +42 -13
- package/src/services/FormatUtilities.ts +28 -14
- package/src/services/GenericTooltipService.ts +125 -65
- package/src/services/MixedBarLineFunctions.ts +46 -44
- package/src/services/PatternFunctions.ts +25 -18
- package/src/services/RadarChartFunctions.ts +5 -5
- package/src/services/patterns/ChartDesign.ts +35 -24
- package/src/services/patterns/patternCircles.ts +63 -36
- package/src/services/patterns/patternDashedDiagonals.ts +64 -57
- package/src/services/patterns/patternDiagonals.ts +138 -106
- package/src/services/patterns/patternSquares.ts +86 -80
- package/src/services/patterns/patternVerticalLines.ts +76 -69
- package/src/services/patterns/patternZigzag.ts +92 -85
- package/src/stories/Changelog.mdx +2 -2
- package/src/stories/Contributing.mdx +2 -2
- package/src/stories/GettingStarted.mdx +5 -5
- package/src/stories/SupportAndOnboarding.mdx +6 -6
- package/src/types/AxisDefinition.ts +0 -2
- package/src/types/Chart.ts +9 -7
- package/src/types/DoughnutData.ts +8 -0
- package/src/types/GenericData.ts +10 -10
- package/src/types/LineChart.ts +4 -4
- package/src/types/RadarData.ts +33 -29
- package/src/types/TooltipChartType.ts +7 -7
- package/src/vite-env.d.ts +3 -3
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {Ref} from 'vue';
|
|
2
|
-
import type {HTMLLegendPlugin} from
|
|
3
|
-
import type {ChartOptions} from 'chart.js';
|
|
1
|
+
import type { Ref } from 'vue';
|
|
2
|
+
import type { HTMLLegendPlugin } from '../types/Chart';
|
|
3
|
+
import type { ChartOptions } from 'chart.js';
|
|
4
4
|
import PatternFunctions from './PatternFunctions';
|
|
5
|
-
import {formatValueAndRate} from './FormatUtilities';
|
|
5
|
+
import { formatValueAndRate } from './FormatUtilities';
|
|
6
6
|
import QuestionMarkSvg from '@mozaic-ds/icons/svg/Navigation_Notification_Question_24px.svg';
|
|
7
7
|
|
|
8
8
|
const { getPatternCanvas } = PatternFunctions();
|
|
@@ -14,21 +14,28 @@ export const LEGEND_BOX_POINT_SIZE = 6;
|
|
|
14
14
|
export const LEGEND_BOX_BORDER = '2px';
|
|
15
15
|
|
|
16
16
|
export interface Chart {
|
|
17
|
-
update
|
|
17
|
+
update(): void;
|
|
18
18
|
|
|
19
|
-
toggleDataVisibility
|
|
19
|
+
toggleDataVisibility(datasetIndex: number): void;
|
|
20
20
|
|
|
21
|
-
isDatasetVisible
|
|
21
|
+
isDatasetVisible(datasetIndex: number): boolean;
|
|
22
22
|
|
|
23
23
|
getDataVisibility(index: number): boolean;
|
|
24
24
|
|
|
25
|
-
setDatasetVisibility
|
|
25
|
+
setDatasetVisibility(datasetIndex: number, visible: boolean): void;
|
|
26
26
|
|
|
27
|
-
plugins: HTMLLegendPlugin
|
|
27
|
+
plugins: HTMLLegendPlugin;
|
|
28
28
|
|
|
29
|
-
options:
|
|
29
|
+
options:
|
|
30
|
+
| ChartOptions<'radar'>
|
|
31
|
+
| ChartOptions<'doughnut'>
|
|
32
|
+
| ChartOptions<'bar'>
|
|
33
|
+
| ChartOptions<'line'>;
|
|
30
34
|
|
|
31
|
-
config: {
|
|
35
|
+
config: {
|
|
36
|
+
type?: string;
|
|
37
|
+
data: { labels: string[]; datasets: unknown[]; data?: unknown[] };
|
|
38
|
+
};
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
export interface ChartItem {
|
|
@@ -43,56 +50,110 @@ export interface ChartItem {
|
|
|
43
50
|
lineCap?: string;
|
|
44
51
|
}
|
|
45
52
|
|
|
46
|
-
export function getHtmlLegendPlugin(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
export function getHtmlLegendPlugin(
|
|
54
|
+
legendContainer: Ref,
|
|
55
|
+
selectMode: Ref<boolean>,
|
|
56
|
+
onHoverIndex: any,
|
|
57
|
+
disableAccessibility: Ref<boolean>,
|
|
58
|
+
patternsColors: Ref<string[]>,
|
|
59
|
+
patternsList: Ref<
|
|
60
|
+
((
|
|
61
|
+
hover: boolean,
|
|
62
|
+
color: string,
|
|
63
|
+
disableAccessibility: boolean
|
|
64
|
+
) => CanvasPattern)[]
|
|
65
|
+
>,
|
|
66
|
+
enableHoverFeature: Ref<boolean>,
|
|
67
|
+
maxValueToDisplay?: number,
|
|
68
|
+
chartData?: any
|
|
69
|
+
): HTMLLegendPlugin {
|
|
70
|
+
return {
|
|
71
|
+
id: 'htmlLegend',
|
|
72
|
+
afterUpdate(chart: any) {
|
|
73
|
+
const isDoughnut: boolean = chart.config.type === 'doughnut';
|
|
74
|
+
const flexDirection = isDoughnut ? 'column' : 'row';
|
|
75
|
+
const ul: HTMLLIElement = getOrCreateLegendList(
|
|
76
|
+
legendContainer,
|
|
77
|
+
flexDirection
|
|
78
|
+
);
|
|
79
|
+
ul.style.margin = '1.375rem 1.0625rem';
|
|
80
|
+
while (ul.firstChild) {
|
|
81
|
+
ul.firstChild.remove();
|
|
82
|
+
}
|
|
83
|
+
const items: ChartItem[] =
|
|
84
|
+
chart.options.plugins.legend.labels.generateLabels(chart);
|
|
85
|
+
items.forEach((item: ChartItem): void => {
|
|
50
86
|
const isDoughnut: boolean = chart.config.type === 'doughnut';
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const isOthersElement: boolean = index + 1 === maxValueToDisplay ? true : false;
|
|
64
|
-
li.style.marginTop = '12px';
|
|
65
|
-
if (isOthersElement) {
|
|
66
|
-
li.style.position = 'relative';
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
li.style.marginRight = '10px'
|
|
70
|
-
}
|
|
71
|
-
li.style.width = 'max-content';
|
|
72
|
-
li.style.cursor = 'pointer';
|
|
73
|
-
let liContent: HTMLElement;
|
|
74
|
-
if (!selectMode.value) {
|
|
75
|
-
liContent = createLegendElementWithPatterns(item, chart, onHoverIndex, disableAccessibility.value, patternsColors.value, patternsList.value, enableHoverFeature.value);
|
|
76
|
-
} else {
|
|
77
|
-
liContent = createLegendElementWithCheckbox(chart, item, selectMode, onHoverIndex, patternsColors.value, enableHoverFeature.value);
|
|
87
|
+
const index: number = isDoughnut ? item.index : item.datasetIndex;
|
|
88
|
+
const li: HTMLElement = createHtmlLegendListElement(
|
|
89
|
+
chart,
|
|
90
|
+
selectMode,
|
|
91
|
+
index
|
|
92
|
+
);
|
|
93
|
+
if (isDoughnut) {
|
|
94
|
+
const isOthersElement: boolean =
|
|
95
|
+
index + 1 === maxValueToDisplay ? true : false;
|
|
96
|
+
li.style.marginTop = '12px';
|
|
97
|
+
if (isOthersElement) {
|
|
98
|
+
li.style.position = 'relative';
|
|
78
99
|
}
|
|
79
|
-
|
|
80
|
-
li.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
100
|
+
} else {
|
|
101
|
+
li.style.marginRight = '10px';
|
|
102
|
+
}
|
|
103
|
+
li.style.width = 'max-content';
|
|
104
|
+
li.style.cursor = 'pointer';
|
|
105
|
+
let liContent: HTMLElement;
|
|
106
|
+
if (!selectMode.value) {
|
|
107
|
+
liContent = createLegendElementWithPatterns(
|
|
108
|
+
item,
|
|
109
|
+
chart,
|
|
110
|
+
onHoverIndex,
|
|
111
|
+
disableAccessibility.value,
|
|
112
|
+
patternsColors.value,
|
|
113
|
+
patternsList.value,
|
|
114
|
+
enableHoverFeature.value
|
|
115
|
+
);
|
|
116
|
+
} else {
|
|
117
|
+
liContent = createLegendElementWithCheckbox(
|
|
118
|
+
chart,
|
|
119
|
+
item,
|
|
120
|
+
selectMode,
|
|
121
|
+
onHoverIndex,
|
|
122
|
+
patternsColors.value,
|
|
123
|
+
enableHoverFeature.value
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
liContent.style.boxSizing = 'border-box';
|
|
127
|
+
li.appendChild(liContent);
|
|
128
|
+
li.appendChild(createHtmlLegendItemText(item));
|
|
129
|
+
if (
|
|
130
|
+
isDoughnut &&
|
|
131
|
+
maxValueToDisplay &&
|
|
132
|
+
hasOthersTooltipToDisplay(chartData, maxValueToDisplay, index)
|
|
133
|
+
) {
|
|
134
|
+
li.appendChild(createTooltipAndItsIcon(chartData, maxValueToDisplay));
|
|
135
|
+
}
|
|
136
|
+
ul.appendChild(li);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
};
|
|
89
140
|
}
|
|
90
141
|
|
|
91
|
-
export function hasOthersTooltipToDisplay
|
|
92
|
-
|
|
142
|
+
export function hasOthersTooltipToDisplay(
|
|
143
|
+
doughnutData: any,
|
|
144
|
+
maxValueToDisplay: number,
|
|
145
|
+
index: number
|
|
146
|
+
) {
|
|
147
|
+
return (
|
|
148
|
+
doughnutData.data.length > maxValueToDisplay &&
|
|
149
|
+
index === maxValueToDisplay - 1
|
|
150
|
+
);
|
|
93
151
|
}
|
|
94
152
|
|
|
95
|
-
export function createTooltipAndItsIcon
|
|
153
|
+
export function createTooltipAndItsIcon(
|
|
154
|
+
doughnutData: any,
|
|
155
|
+
maxValueToDisplay: number
|
|
156
|
+
): HTMLDivElement {
|
|
96
157
|
const iconTopWrapper = document.createElement('div');
|
|
97
158
|
const iconWrapper = document.createElement('div');
|
|
98
159
|
const icon = document.createElement('img');
|
|
@@ -101,7 +162,8 @@ export function createTooltipAndItsIcon (doughnutData: any, maxValueToDisplay: n
|
|
|
101
162
|
icon.src = QuestionMarkSvg;
|
|
102
163
|
icon.style.top = '0';
|
|
103
164
|
icon.style.width = '1.5rem';
|
|
104
|
-
icon.style.filter =
|
|
165
|
+
icon.style.filter =
|
|
166
|
+
'invert(38%) sepia(19%) saturate(18%) hue-rotate(337deg) brightness(97%) contrast(85%)';
|
|
105
167
|
iconWrapper.style.position = 'relative';
|
|
106
168
|
iconWrapper.style.display = 'flex';
|
|
107
169
|
const tooltip = createLegendOthersTooltip(doughnutData, maxValueToDisplay);
|
|
@@ -117,9 +179,12 @@ export function createTooltipAndItsIcon (doughnutData: any, maxValueToDisplay: n
|
|
|
117
179
|
return iconTopWrapper;
|
|
118
180
|
}
|
|
119
181
|
|
|
120
|
-
function createLegendOthersTooltip
|
|
182
|
+
function createLegendOthersTooltip(
|
|
183
|
+
doughnutData: any,
|
|
184
|
+
maxValueToDisplay: number
|
|
185
|
+
) {
|
|
121
186
|
const tooltip = document.createElement('div');
|
|
122
|
-
tooltip.style.visibility= 'hidden';
|
|
187
|
+
tooltip.style.visibility = 'hidden';
|
|
123
188
|
tooltip.style.position = 'absolute';
|
|
124
189
|
tooltip.style.zIndex = '10';
|
|
125
190
|
tooltip.style.width = '350px';
|
|
@@ -135,9 +200,13 @@ function createLegendOthersTooltip (doughnutData: any, maxValueToDisplay: number
|
|
|
135
200
|
return tooltip;
|
|
136
201
|
}
|
|
137
202
|
|
|
138
|
-
function addOthersTooltipLines
|
|
139
|
-
|
|
140
|
-
|
|
203
|
+
function addOthersTooltipLines(
|
|
204
|
+
doughnutData: any,
|
|
205
|
+
maxValueToDisplay: number,
|
|
206
|
+
tooltip: HTMLDivElement
|
|
207
|
+
) {
|
|
208
|
+
const startIndex = maxValueToDisplay - 1;
|
|
209
|
+
doughnutData.data.slice(startIndex).forEach((_ignore: any, index: number) => {
|
|
141
210
|
const dataIndex = startIndex + index;
|
|
142
211
|
const textWrapper = document.createElement('div');
|
|
143
212
|
textWrapper.style.display = 'flex';
|
|
@@ -147,69 +216,103 @@ doughnutData.data.slice(startIndex).forEach((_ignore: any, index: number) => {
|
|
|
147
216
|
const label = document.createElement('span');
|
|
148
217
|
label.appendChild(document.createTextNode(doughnutData.labels[dataIndex]));
|
|
149
218
|
const value = document.createElement('span');
|
|
150
|
-
value.appendChild(
|
|
219
|
+
value.appendChild(
|
|
220
|
+
document.createTextNode(formatValueAndRate(doughnutData, dataIndex))
|
|
221
|
+
);
|
|
151
222
|
textWrapper.appendChild(label);
|
|
152
223
|
textWrapper.appendChild(value);
|
|
153
224
|
tooltip.appendChild(textWrapper);
|
|
154
|
-
}
|
|
155
|
-
);
|
|
225
|
+
});
|
|
156
226
|
}
|
|
157
227
|
|
|
158
|
-
export function createLegendElementWithPatterns
|
|
159
|
-
|
|
160
|
-
:
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
228
|
+
export function createLegendElementWithPatterns(
|
|
229
|
+
item: ChartItem,
|
|
230
|
+
chart: Chart,
|
|
231
|
+
onHoverIndex: any | null,
|
|
232
|
+
disableAccessibility: boolean,
|
|
233
|
+
patternsColors: string[],
|
|
234
|
+
patternsList: ((
|
|
235
|
+
hover: boolean,
|
|
236
|
+
color: string,
|
|
237
|
+
disableAccessibility: boolean
|
|
238
|
+
) => CanvasPattern)[],
|
|
239
|
+
enableHoverFeature: boolean
|
|
240
|
+
): HTMLElement {
|
|
241
|
+
const isDoughnut: boolean = chart.config.type === 'doughnut';
|
|
242
|
+
const index: number = isDoughnut ? item.index : item.datasetIndex;
|
|
243
|
+
const img: HTMLImageElement = new Image();
|
|
244
|
+
const boxSpan: HTMLElement = createHtmlLegendLine(item, chart.config.type);
|
|
245
|
+
const pattern: CanvasPattern = patternsList[index](
|
|
246
|
+
false,
|
|
247
|
+
patternsColors[index],
|
|
248
|
+
disableAccessibility
|
|
249
|
+
);
|
|
250
|
+
const patternCanvas: HTMLCanvasElement = getPatternCanvas(pattern);
|
|
251
|
+
img.src = patternCanvas.toDataURL();
|
|
252
|
+
boxSpan.style.background = `url(${img.src})`;
|
|
253
|
+
boxSpan.style.backgroundSize = 'cover';
|
|
254
|
+
boxSpan.style.borderColor = patternsColors[index];
|
|
255
|
+
boxSpan.style.borderWidth = LEGEND_BOX_BORDER;
|
|
172
256
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
257
|
+
if (enableHoverFeature) {
|
|
258
|
+
boxSpan.onmouseover = (): void => {
|
|
259
|
+
isDoughnut
|
|
260
|
+
? (onHoverIndex.value = index)
|
|
261
|
+
: (onHoverIndex.dataSetIndex = index);
|
|
262
|
+
};
|
|
263
|
+
boxSpan.onmouseleave = (): void => {
|
|
264
|
+
isDoughnut
|
|
265
|
+
? (onHoverIndex.value = null)
|
|
266
|
+
: (onHoverIndex.dataSetIndex = -1);
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
return boxSpan;
|
|
182
270
|
}
|
|
183
271
|
|
|
184
|
-
export function createLegendElementWithCheckbox
|
|
185
|
-
|
|
272
|
+
export function createLegendElementWithCheckbox(
|
|
273
|
+
chart: Chart,
|
|
274
|
+
item: ChartItem,
|
|
275
|
+
selectMode: Ref<boolean>,
|
|
276
|
+
onHoverIndex: any | null,
|
|
277
|
+
patternsColors: string[],
|
|
278
|
+
enableHoverFeature: boolean
|
|
279
|
+
): HTMLElement {
|
|
186
280
|
const isDoughnut: boolean = chart.config.type === 'doughnut';
|
|
187
281
|
const index: number = isDoughnut ? item.index : item.datasetIndex;
|
|
188
|
-
const checkbox: HTMLElement = createLegendCheckbox(
|
|
282
|
+
const checkbox: HTMLElement = createLegendCheckbox(
|
|
283
|
+
chart,
|
|
284
|
+
item,
|
|
285
|
+
patternsColors
|
|
286
|
+
);
|
|
189
287
|
const labels = chart.config.data.labels;
|
|
190
|
-
const allCheckBoxesVisible: boolean =
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return checkbox;
|
|
288
|
+
const allCheckBoxesVisible: boolean = labels.every((_, index: number) =>
|
|
289
|
+
chart.getDataVisibility(index)
|
|
290
|
+
);
|
|
291
|
+
if (allCheckBoxesVisible) {
|
|
292
|
+
if (isDoughnut) {
|
|
293
|
+
selectMode.value = false;
|
|
294
|
+
onHoverIndex.value = -1;
|
|
198
295
|
}
|
|
296
|
+
return checkbox;
|
|
297
|
+
}
|
|
199
298
|
if (enableHoverFeature) {
|
|
200
|
-
checkbox.onmouseover = ():void => {
|
|
201
|
-
isDoughnut
|
|
299
|
+
checkbox.onmouseover = (): void => {
|
|
300
|
+
isDoughnut
|
|
301
|
+
? (onHoverIndex.value = index)
|
|
302
|
+
: (onHoverIndex.dataSetIndex = index);
|
|
202
303
|
chart.update();
|
|
203
304
|
};
|
|
204
305
|
checkbox.onmouseleave = (): void => {
|
|
205
|
-
isDoughnut
|
|
306
|
+
isDoughnut
|
|
307
|
+
? (onHoverIndex.value = null)
|
|
308
|
+
: (onHoverIndex.dataSetIndex = -1);
|
|
206
309
|
chart.update();
|
|
207
310
|
};
|
|
208
311
|
}
|
|
209
312
|
return checkbox;
|
|
210
313
|
}
|
|
211
314
|
|
|
212
|
-
export function createHtmlLegendItemText
|
|
315
|
+
export function createHtmlLegendItemText(item: ChartItem) {
|
|
213
316
|
const textContainer = document.createElement('p');
|
|
214
317
|
textContainer.style.color = item.fontColor;
|
|
215
318
|
textContainer.style.fontSize = `${LEGEND_FONT_SIZE}px`;
|
|
@@ -221,7 +324,10 @@ export function createHtmlLegendItemText (item: ChartItem) {
|
|
|
221
324
|
return textContainer;
|
|
222
325
|
}
|
|
223
326
|
|
|
224
|
-
export function createHtmlLegendLine
|
|
327
|
+
export function createHtmlLegendLine(
|
|
328
|
+
item: ChartItem,
|
|
329
|
+
type: string | undefined
|
|
330
|
+
) {
|
|
225
331
|
const boxSpan = document.createElement('div');
|
|
226
332
|
if (type !== 'doughnut') {
|
|
227
333
|
boxSpan.style.background = 'rgba(0, 0, 0, 0.1)';
|
|
@@ -239,7 +345,7 @@ export function createHtmlLegendLine (item: ChartItem, type: string | undefined)
|
|
|
239
345
|
return boxSpan;
|
|
240
346
|
}
|
|
241
347
|
|
|
242
|
-
export function createHtmlLegendDatasetSquare
|
|
348
|
+
export function createHtmlLegendDatasetSquare(item: ChartItem) {
|
|
243
349
|
const divPoint = document.createElement('div');
|
|
244
350
|
divPoint.style.height = LEGEND_BOX_POINT_SIZE + 'px';
|
|
245
351
|
divPoint.style.width = LEGEND_BOX_POINT_SIZE + 'px';
|
|
@@ -250,8 +356,11 @@ export function createHtmlLegendDatasetSquare (item: ChartItem) {
|
|
|
250
356
|
return divPoint;
|
|
251
357
|
}
|
|
252
358
|
|
|
253
|
-
export function createHtmlLegendListElement
|
|
254
|
-
|
|
359
|
+
export function createHtmlLegendListElement(
|
|
360
|
+
chart: Chart,
|
|
361
|
+
selectMode: Ref,
|
|
362
|
+
elementIndex: number
|
|
363
|
+
) {
|
|
255
364
|
const li: HTMLElement = document.createElement('li');
|
|
256
365
|
li.style.alignItems = 'center';
|
|
257
366
|
li.style.cursor = selectMode.value ? '' : 'pointer';
|
|
@@ -269,41 +378,57 @@ export function createHtmlLegendListElement
|
|
|
269
378
|
return li;
|
|
270
379
|
}
|
|
271
380
|
|
|
272
|
-
export function addCheckboxStyle
|
|
381
|
+
export function addCheckboxStyle(
|
|
382
|
+
isDataSetVisible: boolean,
|
|
383
|
+
item: ChartItem,
|
|
384
|
+
checkbox: Element,
|
|
385
|
+
patternColor: string
|
|
386
|
+
) {
|
|
273
387
|
let backgroundColor = '#fff';
|
|
274
388
|
let borderColor = '#666';
|
|
275
389
|
if (isDataSetVisible) {
|
|
276
390
|
//Default white for patterns chart
|
|
277
|
-
backgroundColor = isDefaultWhiteColor(item.strokeStyle)
|
|
278
|
-
|
|
391
|
+
backgroundColor = isDefaultWhiteColor(item.strokeStyle)
|
|
392
|
+
? patternColor
|
|
393
|
+
: item.strokeStyle;
|
|
394
|
+
borderColor = isDefaultWhiteColor(item.strokeStyle)
|
|
395
|
+
? patternColor
|
|
396
|
+
: item.strokeStyle;
|
|
279
397
|
checkbox.setAttribute('checked', '' + isDataSetVisible);
|
|
280
398
|
}
|
|
281
399
|
checkbox.setAttribute('class', 'mc-checkbox__input');
|
|
282
|
-
checkbox.setAttribute(
|
|
400
|
+
checkbox.setAttribute(
|
|
401
|
+
'style',
|
|
402
|
+
`background-color: ${backgroundColor};
|
|
283
403
|
min-width: ${LEGEND_BOX_SIZE};
|
|
284
404
|
min-height: ${LEGEND_BOX_SIZE};
|
|
285
405
|
margin-right: ${LEGEND_LABEL_LEFT_MARGIN};
|
|
286
|
-
border-color: ${borderColor};`
|
|
406
|
+
border-color: ${borderColor};`
|
|
407
|
+
);
|
|
287
408
|
}
|
|
288
409
|
|
|
289
|
-
export function createLegendCheckbox
|
|
410
|
+
export function createLegendCheckbox(
|
|
411
|
+
chart: Chart,
|
|
412
|
+
item: ChartItem,
|
|
413
|
+
patternsColors: string[]
|
|
414
|
+
) {
|
|
290
415
|
const isDoughnut: boolean = chart.config.type === 'doughnut';
|
|
291
416
|
const index: number = isDoughnut ? item.index : item.datasetIndex;
|
|
292
417
|
const checkbox = document.createElement('input');
|
|
293
418
|
checkbox.setAttribute('type', 'checkbox');
|
|
294
419
|
checkbox.setAttribute('data-test-id', `legend-checkbox-${index}`);
|
|
295
420
|
const isDataSetVisible = isChartDataVisible(chart, index);
|
|
296
|
-
const patternColor = patternsColors? patternsColors[index]:undefined;
|
|
421
|
+
const patternColor = patternsColors ? patternsColors[index] : undefined;
|
|
297
422
|
addCheckboxStyle(isDataSetVisible, item, checkbox, patternColor as string);
|
|
298
423
|
return checkbox;
|
|
299
424
|
}
|
|
300
425
|
|
|
301
|
-
function isMonoDataSetChart
|
|
426
|
+
function isMonoDataSetChart(chart: Chart) {
|
|
302
427
|
const { type } = chart.config;
|
|
303
428
|
return type === 'pie' || type === 'doughnut';
|
|
304
429
|
}
|
|
305
430
|
|
|
306
|
-
function getChartsData
|
|
431
|
+
function getChartsData(chart: any) {
|
|
307
432
|
let dataSets: unknown[] = chart.config.data.datasets;
|
|
308
433
|
if (isMonoDataSetChart(chart)) {
|
|
309
434
|
dataSets = chart.config.data.datasets[0].data;
|
|
@@ -311,7 +436,11 @@ function getChartsData (chart: any) {
|
|
|
311
436
|
return dataSets;
|
|
312
437
|
}
|
|
313
438
|
|
|
314
|
-
export function hideAllButThis
|
|
439
|
+
export function hideAllButThis(
|
|
440
|
+
chart: Chart,
|
|
441
|
+
elementIndex: number,
|
|
442
|
+
selectMode: Ref
|
|
443
|
+
) {
|
|
315
444
|
if (!selectMode.value) {
|
|
316
445
|
const dataSets: unknown[] = getChartsData(chart);
|
|
317
446
|
selectMode.value = true;
|
|
@@ -323,7 +452,7 @@ export function hideAllButThis (chart: Chart, elementIndex: number, selectMode:
|
|
|
323
452
|
}
|
|
324
453
|
}
|
|
325
454
|
|
|
326
|
-
function allDataVisible
|
|
455
|
+
function allDataVisible(chart: Chart): boolean {
|
|
327
456
|
let allVisible = true;
|
|
328
457
|
const chartsData: unknown[] = getChartsData(chart);
|
|
329
458
|
chartsData.forEach((_data, dataIndex) => {
|
|
@@ -340,11 +469,18 @@ function isChartDataVisible(chart: Chart, dataIndex: number): boolean {
|
|
|
340
469
|
}
|
|
341
470
|
}
|
|
342
471
|
|
|
343
|
-
export function switchItemVisibility
|
|
472
|
+
export function switchItemVisibility(
|
|
473
|
+
chart: Chart,
|
|
474
|
+
elementIndex: number,
|
|
475
|
+
selectMode?: Ref
|
|
476
|
+
) {
|
|
344
477
|
if (isMonoDataSetChart(chart)) {
|
|
345
478
|
chart.toggleDataVisibility(elementIndex);
|
|
346
479
|
} else {
|
|
347
|
-
chart.setDatasetVisibility(
|
|
480
|
+
chart.setDatasetVisibility(
|
|
481
|
+
elementIndex,
|
|
482
|
+
!chart.isDatasetVisible(elementIndex)
|
|
483
|
+
);
|
|
348
484
|
}
|
|
349
485
|
|
|
350
486
|
if (selectMode && allDataVisible(chart)) {
|
|
@@ -353,8 +489,10 @@ export function switchItemVisibility (chart: Chart, elementIndex: number, select
|
|
|
353
489
|
chart.update();
|
|
354
490
|
}
|
|
355
491
|
|
|
356
|
-
|
|
357
|
-
|
|
492
|
+
export function createLegendElementWithSquareArea(
|
|
493
|
+
item: ChartItem,
|
|
494
|
+
mainSerieFirstDataset?: boolean
|
|
495
|
+
) {
|
|
358
496
|
const liContent = createHtmlLegendLine(item, '');
|
|
359
497
|
const divPoint = createHtmlLegendDatasetSquare(item);
|
|
360
498
|
const index = item.index || item.datasetIndex;
|
|
@@ -362,16 +500,22 @@ export function createLegendElementWithSquareArea (item: ChartItem, mainSerieFir
|
|
|
362
500
|
divPoint.style.width = '10px';
|
|
363
501
|
divPoint.style.height = '10px';
|
|
364
502
|
if (index % 2 === 0) {
|
|
365
|
-
mainSerieFirstDataset
|
|
503
|
+
mainSerieFirstDataset
|
|
504
|
+
? (divPoint.style.borderRadius = '25px')
|
|
505
|
+
: (divPoint.style.transform = 'rotate(45deg)');
|
|
366
506
|
} else {
|
|
367
|
-
mainSerieFirstDataset
|
|
507
|
+
mainSerieFirstDataset
|
|
508
|
+
? (divPoint.style.transform = 'rotate(45deg)')
|
|
509
|
+
: (divPoint.style.borderRadius = '25px');
|
|
368
510
|
}
|
|
369
511
|
liContent.appendChild(divPoint);
|
|
370
512
|
return liContent;
|
|
371
513
|
}
|
|
372
514
|
|
|
373
|
-
|
|
374
|
-
|
|
515
|
+
export function getOrCreateLegendList(
|
|
516
|
+
legendContainer: Ref,
|
|
517
|
+
flexDirection: string
|
|
518
|
+
) {
|
|
375
519
|
let listContainer = legendContainer.value?.querySelector('ul');
|
|
376
520
|
if (!listContainer) {
|
|
377
521
|
listContainer = document.createElement('ul');
|
|
@@ -384,6 +528,6 @@ export function getOrCreateLegendList (legendContainer: Ref, flexDirection: stri
|
|
|
384
528
|
return listContainer;
|
|
385
529
|
}
|
|
386
530
|
|
|
387
|
-
function isDefaultWhiteColor(color: string){
|
|
531
|
+
function isDefaultWhiteColor(color: string) {
|
|
388
532
|
return color === '#00000000';
|
|
389
|
-
}
|
|
533
|
+
}
|