@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
@@ -1,8 +1,8 @@
1
- import type {Ref} from 'vue';
2
- import type {HTMLLegendPlugin} from "../types/Chart";
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 (): void;
17
+ update(): void;
18
18
 
19
- toggleDataVisibility (datasetIndex: number): void;
19
+ toggleDataVisibility(datasetIndex: number): void;
20
20
 
21
- isDatasetVisible (datasetIndex: number): boolean;
21
+ isDatasetVisible(datasetIndex: number): boolean;
22
22
 
23
23
  getDataVisibility(index: number): boolean;
24
24
 
25
- setDatasetVisibility (datasetIndex: number, visible: boolean): void;
25
+ setDatasetVisibility(datasetIndex: number, visible: boolean): void;
26
26
 
27
- plugins: HTMLLegendPlugin,
27
+ plugins: HTMLLegendPlugin;
28
28
 
29
- options: ChartOptions<'radar'> | ChartOptions<'doughnut'> | ChartOptions<'bar'> | ChartOptions<'line'>,
29
+ options:
30
+ | ChartOptions<'radar'>
31
+ | ChartOptions<'doughnut'>
32
+ | ChartOptions<'bar'>
33
+ | ChartOptions<'line'>;
30
34
 
31
- config: { type?: string, data: { labels: string[] ,datasets: unknown[], data?: unknown[] } },
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(legendContainer: Ref, selectMode: Ref<boolean>, onHoverIndex: any, disableAccessibility: Ref<boolean>, patternsColors: Ref<string[]>, patternsList: Ref<((hover: boolean, color: string, disableAccessibility: boolean) => CanvasPattern)[]>, enableHoverFeature: Ref<boolean>, maxValueToDisplay?: number, chartData?: any): HTMLLegendPlugin[] {
47
- return [{
48
- id: 'htmlLegend',
49
- afterUpdate (chart: any) {
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 flexDirection = isDoughnut ? 'column' : 'row';
52
- const ul: HTMLLIElement = getOrCreateLegendList(legendContainer, flexDirection);
53
- ul.style.margin = '1.375rem 1.0625rem';
54
- while (ul.firstChild) {
55
- ul.firstChild.remove();
56
- }
57
- const items: ChartItem[] = chart.options.plugins.legend.labels.generateLabels(chart);
58
- items.forEach((item: ChartItem): void => {
59
- const isDoughnut: boolean = chart.config.type === 'doughnut';
60
- const index: number = isDoughnut ? item.index : item.datasetIndex;
61
- const li: HTMLElement = createHtmlLegendListElement(chart, selectMode, index);
62
- if (isDoughnut) {
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
- liContent.style.boxSizing = 'border-box';
80
- li.appendChild(liContent);
81
- li.appendChild(createHtmlLegendItemText(item));
82
- if (isDoughnut && maxValueToDisplay && hasOthersTooltipToDisplay(chartData, maxValueToDisplay, index)) {
83
- li.appendChild(createTooltipAndItsIcon(chartData, maxValueToDisplay));
84
- }
85
- ul.appendChild(li);
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 (doughnutData: any, maxValueToDisplay: number, index: number) {
92
- return doughnutData.data.length > maxValueToDisplay && index === maxValueToDisplay - 1;
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 (doughnutData: any, maxValueToDisplay: number): HTMLDivElement {
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 = 'invert(38%) sepia(19%) saturate(18%) hue-rotate(337deg) brightness(97%) contrast(85%)';
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 (doughnutData: any, maxValueToDisplay: number) {
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 (doughnutData: any, maxValueToDisplay: number, tooltip: HTMLDivElement) {
139
- const startIndex = maxValueToDisplay - 1;
140
- doughnutData.data.slice(startIndex).forEach((_ignore: any, index: number) => {
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(document.createTextNode(formatValueAndRate(doughnutData, dataIndex)));
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
- (item: ChartItem, chart: Chart, onHoverIndex: any | null, disableAccessibility: boolean, patternsColors: string[], patternsList: ((hover: boolean, color: string, disableAccessibility: boolean) => CanvasPattern)[], enableHoverFeature: boolean)
160
- : HTMLElement {
161
- const isDoughnut: boolean = chart.config.type === 'doughnut';
162
- const index: number = isDoughnut ? item.index : item.datasetIndex;
163
- const img: HTMLImageElement = new Image();
164
- const boxSpan: HTMLElement = createHtmlLegendLine(item, chart.config.type);
165
- const pattern: CanvasPattern = patternsList[index](false, patternsColors[index], disableAccessibility);
166
- const patternCanvas: HTMLCanvasElement = getPatternCanvas(pattern);
167
- img.src = patternCanvas.toDataURL();
168
- boxSpan.style.background = `url(${img.src})`;
169
- boxSpan.style.backgroundSize = 'cover';
170
- boxSpan.style.borderColor = patternsColors[index];
171
- boxSpan.style.borderWidth = LEGEND_BOX_BORDER;
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
- if (enableHoverFeature) {
174
- boxSpan.onmouseover = ():void => {
175
- isDoughnut ? onHoverIndex.value = index : onHoverIndex.dataSetIndex = index;
176
- };
177
- boxSpan.onmouseleave = (): void => {
178
- isDoughnut ? onHoverIndex.value = null : onHoverIndex.dataSetIndex = -1;
179
- };
180
- }
181
- return boxSpan;
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
- (chart: Chart, item: ChartItem, selectMode: Ref<boolean>, onHoverIndex: any | null, patternsColors: string[], enableHoverFeature: boolean): HTMLElement {
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(chart, item, patternsColors);
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
- labels.every((label: string, index: number) => chart.getDataVisibility(index));
192
- if (allCheckBoxesVisible) {
193
- if (isDoughnut) {
194
- selectMode.value = false;
195
- onHoverIndex.value = -1;
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 ? onHoverIndex.value = index : onHoverIndex.dataSetIndex = index;
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 ? onHoverIndex.value = null : onHoverIndex.dataSetIndex = -1;
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 (item: ChartItem) {
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 (item: ChartItem, type: string | undefined) {
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 (item: ChartItem) {
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
- (chart: Chart, selectMode: Ref, elementIndex: number) {
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 (isDataSetVisible: boolean, item: ChartItem, checkbox: Element, patternColor: string) {
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)? patternColor: item.strokeStyle;
278
- borderColor = isDefaultWhiteColor(item.strokeStyle)? patternColor: item.strokeStyle;
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('style', `background-color: ${backgroundColor};
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 (chart: Chart, item: ChartItem, patternsColors: string[]) {
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 (chart: Chart) {
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 (chart: any) {
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 (chart: Chart, elementIndex: number, selectMode: Ref) {
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 (chart: Chart): boolean {
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 (chart: Chart, elementIndex: number, selectMode?: Ref) {
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(elementIndex, !chart.isDatasetVisible(elementIndex));
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
- export function createLegendElementWithSquareArea (item: ChartItem, mainSerieFirstDataset?: boolean,) {
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 ? divPoint.style.borderRadius = '25px' : divPoint.style.transform = 'rotate(45deg)';
503
+ mainSerieFirstDataset
504
+ ? (divPoint.style.borderRadius = '25px')
505
+ : (divPoint.style.transform = 'rotate(45deg)');
366
506
  } else {
367
- mainSerieFirstDataset ? divPoint.style.transform = 'rotate(45deg)' : divPoint.style.borderRadius = '25px';
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
- export function getOrCreateLegendList (legendContainer: Ref, flexDirection: string) {
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
+ }
@@ -1,4 +1,4 @@
1
1
  export function addAlpha(color: string, opacity: number) {
2
2
  const _opacity = Math.round(Math.min(Math.max(opacity || 1, 0), 1) * 255);
3
3
  return color + _opacity.toString(16).toUpperCase();
4
- }
4
+ }