@oliasoft-open-source/charts-library 2.2.0 → 2.2.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/package.json +1 -1
- package/release-notes.md +4 -0
- package/src/components/bar-chart/bar-chart-prop-types.js +0 -2
- package/src/components/bar-chart/bar-chart.jsx +4 -15
- package/src/components/bar-chart/bar-chart.module.less +5 -0
- package/src/components/bar-chart/bar-chart.stories.jsx +0 -35
- package/src/components/bar-chart/get-bar-chart-data-labels.js +1 -4
- package/src/components/bar-chart/get-bar-chart-scales.js +2 -26
- package/src/components/line-chart/get-line-chart-data-labels.js +1 -4
- package/src/components/line-chart/get-line-chart-scales.js +2 -20
- package/src/components/line-chart/line-chart-prop-types.js +0 -2
- package/src/components/line-chart/line-chart.jsx +5 -20
- package/src/components/line-chart/line-chart.module.less +5 -0
- package/src/components/line-chart/line-chart.stories.jsx +0 -14
- package/src/components/pie-chart/pie-chart-prop-types.js +0 -2
- package/src/components/pie-chart/pie-chart-utils.js +0 -23
- package/src/components/pie-chart/pie-chart.interface.ts +0 -1
- package/src/components/pie-chart/pie-chart.jsx +5 -30
- package/src/components/pie-chart/pie-chart.module.less +5 -0
- package/src/components/pie-chart/pie-chart.stories.jsx +0 -35
- package/src/components/scatter-chart/scatter-chart.jsx +9 -1
- package/src/components/scatter-chart/scatter-chart.module.less +4 -0
- package/src/helpers/chart-consts.js +1 -25
- package/src/helpers/chart-interface.ts +0 -1
- package/src/helpers/chart-utils.js +12 -5
- package/src/helpers/get-chart-annotation.js +2 -9
- package/src/helpers/get-custom-legend-plugin-example.js +0 -1
package/package.json
CHANGED
package/release-notes.md
CHANGED
|
@@ -45,7 +45,6 @@ export const BarChartPropTypes = {
|
|
|
45
45
|
maintainAspectRatio: PropTypes.bool,
|
|
46
46
|
staticChartHeight: PropTypes.bool,
|
|
47
47
|
performanceMode: PropTypes.bool,
|
|
48
|
-
darkMode: PropTypes.bool,
|
|
49
48
|
}),
|
|
50
49
|
tooltip: PropTypes.shape({
|
|
51
50
|
tooltips: PropTypes.bool,
|
|
@@ -142,7 +141,6 @@ export const getDefaultProps = (props) => {
|
|
|
142
141
|
props.chart.options.chartStyling.performanceMode != null
|
|
143
142
|
? props.chart.options.chartStyling.performanceMode
|
|
144
143
|
: true,
|
|
145
|
-
darkMode: props.chart.options.chartStyling.darkMode || false,
|
|
146
144
|
},
|
|
147
145
|
tooltip: {
|
|
148
146
|
tooltips:
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useRef, useState } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
BarElement,
|
|
4
4
|
CategoryScale,
|
|
5
5
|
Chart as ChartJS,
|
|
6
|
-
defaults,
|
|
7
6
|
Filler,
|
|
8
7
|
Legend,
|
|
9
8
|
LinearScale,
|
|
@@ -30,6 +29,7 @@ import {
|
|
|
30
29
|
getClassName,
|
|
31
30
|
getPlugins,
|
|
32
31
|
getLegend,
|
|
32
|
+
setDefaultTheme,
|
|
33
33
|
} from '../../helpers/chart-utils';
|
|
34
34
|
import {
|
|
35
35
|
ALPHA_CHANEL,
|
|
@@ -37,12 +37,6 @@ import {
|
|
|
37
37
|
AUTO,
|
|
38
38
|
COLORS,
|
|
39
39
|
CUSTOM_LEGEND_PLUGIN_NAME,
|
|
40
|
-
DARK_MODE_COLORS,
|
|
41
|
-
DEFAULT_COLOR,
|
|
42
|
-
DEFAULT_DARK_MODE_BORDER_COLOR,
|
|
43
|
-
DEFAULT_DARK_MODE_COLOR,
|
|
44
|
-
DEFAULT_FONT_FAMILY,
|
|
45
|
-
DEFAULT_FONT_SIZE,
|
|
46
40
|
} from '../../helpers/chart-consts';
|
|
47
41
|
import {
|
|
48
42
|
AxisType,
|
|
@@ -65,17 +59,12 @@ ChartJS.register(
|
|
|
65
59
|
annotationPlugin,
|
|
66
60
|
);
|
|
67
61
|
|
|
68
|
-
defaults.font.size = DEFAULT_FONT_SIZE;
|
|
69
|
-
defaults.color = DEFAULT_COLOR;
|
|
70
|
-
defaults.font.family = DEFAULT_FONT_FAMILY;
|
|
71
|
-
defaults.darkModeColor = DEFAULT_DARK_MODE_COLOR;
|
|
72
|
-
defaults.darkModeBorderColor = DEFAULT_DARK_MODE_BORDER_COLOR;
|
|
73
|
-
|
|
74
62
|
/**
|
|
75
63
|
* this is a bar chart component
|
|
76
64
|
* @param {import('./bar-chart.interface').IBarChartProps} props
|
|
77
65
|
*/
|
|
78
66
|
const BarChart = (props) => {
|
|
67
|
+
setDefaultTheme();
|
|
79
68
|
const chartRef = useRef(null);
|
|
80
69
|
const [pointHover, setPointHover] = useState(false);
|
|
81
70
|
const chart = getDefaultProps(props);
|
|
@@ -109,7 +98,7 @@ const BarChart = (props) => {
|
|
|
109
98
|
}
|
|
110
99
|
|
|
111
100
|
const generatedDatasets = barDatasetsCopy.map((barDataset, index) => {
|
|
112
|
-
const colorSchema =
|
|
101
|
+
const colorSchema = COLORS;
|
|
113
102
|
const colors = barDataset.data.map((_, i) => {
|
|
114
103
|
const colorSelectionIndex = datasets.length > 1 ? index : i;
|
|
115
104
|
return colorSchema[colorSelectionIndex] || generateRandomColor(COLORS);
|
|
@@ -321,38 +321,6 @@ const controlAnnotationChart = {
|
|
|
321
321
|
},
|
|
322
322
|
};
|
|
323
323
|
|
|
324
|
-
const darkMode = {
|
|
325
|
-
data: {
|
|
326
|
-
labels: labels1,
|
|
327
|
-
datasets: [dataset1_1a, dataset1_2a, dataset1_3a],
|
|
328
|
-
},
|
|
329
|
-
options: {
|
|
330
|
-
title: 'Dark mode',
|
|
331
|
-
axes: {
|
|
332
|
-
x: [
|
|
333
|
-
{
|
|
334
|
-
label: 'X',
|
|
335
|
-
},
|
|
336
|
-
],
|
|
337
|
-
},
|
|
338
|
-
chartStyling: {
|
|
339
|
-
darkMode: true,
|
|
340
|
-
},
|
|
341
|
-
graph: {
|
|
342
|
-
showDataLabels: true,
|
|
343
|
-
showMinorGridlines: true,
|
|
344
|
-
},
|
|
345
|
-
annotations: {
|
|
346
|
-
annotationsData: [
|
|
347
|
-
{
|
|
348
|
-
label: 'Annotation 1',
|
|
349
|
-
value: 6,
|
|
350
|
-
},
|
|
351
|
-
],
|
|
352
|
-
},
|
|
353
|
-
},
|
|
354
|
-
};
|
|
355
|
-
|
|
356
324
|
const legendRight = {
|
|
357
325
|
data: {
|
|
358
326
|
labels: labels1,
|
|
@@ -469,9 +437,6 @@ AnnotationsInLegend.args = { chart: controlAnnotationChart };
|
|
|
469
437
|
export const Animated = Template.bind({});
|
|
470
438
|
Animated.args = { chart: animatedChart };
|
|
471
439
|
|
|
472
|
-
export const DarkMode = Template.bind({});
|
|
473
|
-
DarkMode.args = { chart: darkMode };
|
|
474
|
-
|
|
475
440
|
export const CustomLegend = TemplateWithCustomLegendContainer.bind({});
|
|
476
441
|
CustomLegend.args = {
|
|
477
442
|
chart: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AlignOptions } from '../../helpers/enums';
|
|
2
|
-
import { AUTO
|
|
2
|
+
import { AUTO } from '../../helpers/chart-consts';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @param {import('./bar-chart.interface').IBarChartOptions} options - bar chart options object
|
|
@@ -35,9 +35,6 @@ const getBarChartDataLabels = (options) => {
|
|
|
35
35
|
align: beginAtZero ? AlignOptions.Center : beginAtNotZeroAlign,
|
|
36
36
|
anchor: beginAtZero ? AlignOptions.Center : beginAtNotZeroAnchor,
|
|
37
37
|
formatter: formatterCallback,
|
|
38
|
-
color: options.chartStyling.darkMode
|
|
39
|
-
? DEFAULT_DARK_MODE_COLOR
|
|
40
|
-
: undefined,
|
|
41
38
|
}
|
|
42
39
|
: { display: false };
|
|
43
40
|
};
|
|
@@ -4,14 +4,7 @@ import {
|
|
|
4
4
|
isVertical,
|
|
5
5
|
generateRandomColor,
|
|
6
6
|
} from '../../helpers/chart-utils';
|
|
7
|
-
import {
|
|
8
|
-
COLORS,
|
|
9
|
-
DARK_MODE_COLORS,
|
|
10
|
-
DEFAULT_COLOR,
|
|
11
|
-
DEFAULT_DARK_MODE_BORDER_COLOR,
|
|
12
|
-
DEFAULT_DARK_MODE_COLOR,
|
|
13
|
-
LOGARITHMIC_STEPS,
|
|
14
|
-
} from '../../helpers/chart-consts';
|
|
7
|
+
import { COLORS, LOGARITHMIC_STEPS } from '../../helpers/chart-consts';
|
|
15
8
|
|
|
16
9
|
/**
|
|
17
10
|
* @param {import('./bar-chart.interface').IBarChartData} chart - chart data
|
|
@@ -57,11 +50,6 @@ const getBarChartAxis = (chart, axisType, currentScales) => {
|
|
|
57
50
|
};
|
|
58
51
|
} else {
|
|
59
52
|
return {
|
|
60
|
-
color:
|
|
61
|
-
axisData.color ||
|
|
62
|
-
(chart.options.chartStyling.darkMode
|
|
63
|
-
? DEFAULT_DARK_MODE_COLOR
|
|
64
|
-
: DEFAULT_COLOR),
|
|
65
53
|
stepSize:
|
|
66
54
|
axisData.stepSize || chart.options.additionalAxesOptions.stepSize,
|
|
67
55
|
};
|
|
@@ -85,18 +73,9 @@ const getBarChartAxis = (chart, axisType, currentScales) => {
|
|
|
85
73
|
display: axisData.label?.length || axisData.unit?.length,
|
|
86
74
|
text: axisData.label || axisData.unit,
|
|
87
75
|
padding: 0,
|
|
88
|
-
color: chart.options.chartStyling.darkMode
|
|
89
|
-
? DEFAULT_DARK_MODE_COLOR
|
|
90
|
-
: undefined,
|
|
91
76
|
},
|
|
92
77
|
ticks: getTicks(),
|
|
93
78
|
grid: {
|
|
94
|
-
color: chart.options.chartStyling.darkMode
|
|
95
|
-
? DEFAULT_DARK_MODE_BORDER_COLOR
|
|
96
|
-
: undefined,
|
|
97
|
-
borderColor: chart.options.chartStyling.darkMode
|
|
98
|
-
? DEFAULT_DARK_MODE_BORDER_COLOR
|
|
99
|
-
: undefined,
|
|
100
79
|
...grid,
|
|
101
80
|
},
|
|
102
81
|
stacked: chart.options.additionalAxesOptions.stacked,
|
|
@@ -111,10 +90,7 @@ const getBarChartAxes = (chart, axisType) => {
|
|
|
111
90
|
const axesData = chart.options.axes[axisType];
|
|
112
91
|
const axes = axesData.reduce((acc, curr, i) => {
|
|
113
92
|
const axisData = curr;
|
|
114
|
-
const color =
|
|
115
|
-
curr.color ||
|
|
116
|
-
(chart.options.chartStyling.darkMode ? DARK_MODE_COLORS[i] : COLORS[i]) ||
|
|
117
|
-
generateRandomColor(COLORS);
|
|
93
|
+
const color = curr.color || COLORS[i] || generateRandomColor(COLORS);
|
|
118
94
|
axisData.color = color;
|
|
119
95
|
axisData.position = curr.position || getAxisPosition(axisType, i);
|
|
120
96
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AUTO
|
|
1
|
+
import { AUTO } from '../../helpers/chart-consts';
|
|
2
2
|
import { AlignOptions, PointType } from '../../helpers/enums';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -14,9 +14,6 @@ const getLineChartDataLabels = (options) => {
|
|
|
14
14
|
: AlignOptions.End,
|
|
15
15
|
formatter: (value, context) =>
|
|
16
16
|
context.dataset.data[context.dataIndex].label || '',
|
|
17
|
-
color: options.chartStyling.darkMode
|
|
18
|
-
? DEFAULT_DARK_MODE_COLOR
|
|
19
|
-
: undefined,
|
|
20
17
|
}
|
|
21
18
|
: { display: false };
|
|
22
19
|
};
|
|
@@ -2,14 +2,7 @@ import {
|
|
|
2
2
|
generateRandomColor,
|
|
3
3
|
getAxisPosition,
|
|
4
4
|
} from '../../helpers/chart-utils';
|
|
5
|
-
import {
|
|
6
|
-
COLORS,
|
|
7
|
-
DARK_MODE_COLORS,
|
|
8
|
-
DEFAULT_COLOR,
|
|
9
|
-
DEFAULT_DARK_MODE_BORDER_COLOR,
|
|
10
|
-
DEFAULT_DARK_MODE_COLOR,
|
|
11
|
-
LOGARITHMIC_STEPS,
|
|
12
|
-
} from '../../helpers/chart-consts';
|
|
5
|
+
import { COLORS, LOGARITHMIC_STEPS } from '../../helpers/chart-consts';
|
|
13
6
|
import { truncateDecimals } from './line-chart-utils';
|
|
14
7
|
import { AxisType, ScaleType } from '../../helpers/enums';
|
|
15
8
|
|
|
@@ -50,9 +43,6 @@ const getLineChartAxis = (options, axisType, state, currentScales, i = 0) => {
|
|
|
50
43
|
},
|
|
51
44
|
}
|
|
52
45
|
: {
|
|
53
|
-
color:
|
|
54
|
-
axisData.color ||
|
|
55
|
-
(chartStyling.darkMode ? DEFAULT_DARK_MODE_COLOR : DEFAULT_COLOR),
|
|
56
46
|
stepSize:
|
|
57
47
|
axisData.stepSize ||
|
|
58
48
|
(axisType === AxisType.Y ? additionalAxesOptions.stepSize : null),
|
|
@@ -73,14 +63,9 @@ const getLineChartAxis = (options, axisType, state, currentScales, i = 0) => {
|
|
|
73
63
|
display: axisData.label?.length,
|
|
74
64
|
text: axisData.label,
|
|
75
65
|
padding: 0,
|
|
76
|
-
color: chartStyling.darkMode ? DEFAULT_DARK_MODE_BORDER_COLOR : undefined,
|
|
77
66
|
},
|
|
78
67
|
ticks: getTicks(),
|
|
79
68
|
grid: {
|
|
80
|
-
color: chartStyling.darkMode ? DEFAULT_DARK_MODE_BORDER_COLOR : undefined,
|
|
81
|
-
borderColor: chartStyling.darkMode
|
|
82
|
-
? DEFAULT_DARK_MODE_BORDER_COLOR
|
|
83
|
-
: undefined,
|
|
84
69
|
...axisData.gridLines,
|
|
85
70
|
},
|
|
86
71
|
};
|
|
@@ -95,10 +80,7 @@ const getLineChartAxes = (options, axisType, state) => {
|
|
|
95
80
|
const axesData = options.axes[axisType];
|
|
96
81
|
const axes = axesData.reduce((acc, curr, i) => {
|
|
97
82
|
const axisData = curr;
|
|
98
|
-
axisData.color =
|
|
99
|
-
curr.color ||
|
|
100
|
-
(options.chartStyling.darkMode ? DARK_MODE_COLORS[i] : COLORS[i]) ||
|
|
101
|
-
generateRandomColor(COLORS);
|
|
83
|
+
axisData.color = curr.color || COLORS[i] || generateRandomColor(COLORS);
|
|
102
84
|
axisData.position = curr.position || getAxisPosition(axisType, i);
|
|
103
85
|
|
|
104
86
|
const axis = getLineChartAxis(options, axisType, state, axisData, i);
|
|
@@ -50,7 +50,6 @@ export const LineChartPropTypes = {
|
|
|
50
50
|
maintainAspectRatio: PropTypes.bool,
|
|
51
51
|
staticChartHeight: PropTypes.bool,
|
|
52
52
|
performanceMode: PropTypes.bool,
|
|
53
|
-
darkMode: PropTypes.bool,
|
|
54
53
|
squareAspectRatio: PropTypes.bool,
|
|
55
54
|
}),
|
|
56
55
|
tooltip: PropTypes.shape({
|
|
@@ -149,7 +148,6 @@ export const getDefaultProps = (props) => {
|
|
|
149
148
|
props.chart.options.chartStyling.staticChartHeight || false,
|
|
150
149
|
performanceMode:
|
|
151
150
|
props.chart.options.chartStyling.performanceMode ?? true,
|
|
152
|
-
darkMode: props.chart.options.chartStyling.darkMode || false,
|
|
153
151
|
squareAspectRatio:
|
|
154
152
|
props.chart.options.chartStyling.squareAspectRatio || false,
|
|
155
153
|
},
|
|
@@ -2,7 +2,6 @@ import React, { useEffect, useReducer, useRef } from 'react';
|
|
|
2
2
|
import {
|
|
3
3
|
CategoryScale,
|
|
4
4
|
Chart as ChartJS,
|
|
5
|
-
defaults,
|
|
6
5
|
Filler,
|
|
7
6
|
Legend,
|
|
8
7
|
LinearScale,
|
|
@@ -55,18 +54,13 @@ import {
|
|
|
55
54
|
getLegend,
|
|
56
55
|
getPlugins,
|
|
57
56
|
getTitle,
|
|
57
|
+
setDefaultTheme,
|
|
58
58
|
} from '../../helpers/chart-utils';
|
|
59
59
|
import {
|
|
60
60
|
ANIMATION_DURATION,
|
|
61
61
|
AUTO,
|
|
62
62
|
COLORS,
|
|
63
63
|
CUSTOM_LEGEND_PLUGIN_NAME,
|
|
64
|
-
DARK_MODE_COLORS,
|
|
65
|
-
DEFAULT_COLOR,
|
|
66
|
-
DEFAULT_DARK_MODE_BORDER_COLOR,
|
|
67
|
-
DEFAULT_DARK_MODE_COLOR,
|
|
68
|
-
DEFAULT_FONT_FAMILY,
|
|
69
|
-
DEFAULT_FONT_SIZE,
|
|
70
64
|
} from '../../helpers/chart-consts';
|
|
71
65
|
import {
|
|
72
66
|
AxisType,
|
|
@@ -91,17 +85,12 @@ ChartJS.register(
|
|
|
91
85
|
annotationPlugin,
|
|
92
86
|
);
|
|
93
87
|
|
|
94
|
-
defaults.font.size = DEFAULT_FONT_SIZE;
|
|
95
|
-
defaults.color = DEFAULT_COLOR;
|
|
96
|
-
defaults.font.family = DEFAULT_FONT_FAMILY;
|
|
97
|
-
defaults.darkModeColor = DEFAULT_DARK_MODE_COLOR;
|
|
98
|
-
defaults.darkModeBorderColor = DEFAULT_DARK_MODE_BORDER_COLOR;
|
|
99
|
-
|
|
100
88
|
/**
|
|
101
89
|
* this is a line chart component
|
|
102
90
|
* @param {import('./line-chart.interface').ILineChartProps} props
|
|
103
91
|
*/
|
|
104
92
|
const LineChart = (props) => {
|
|
93
|
+
setDefaultTheme();
|
|
105
94
|
const chartRef = useRef(null);
|
|
106
95
|
let pointHover = false;
|
|
107
96
|
const chart = getDefaultProps(props);
|
|
@@ -177,9 +166,7 @@ const LineChart = (props) => {
|
|
|
177
166
|
annotations.annotationsData?.length
|
|
178
167
|
) {
|
|
179
168
|
annotations.annotationsData.forEach((annotation, index) => {
|
|
180
|
-
const color =
|
|
181
|
-
annotation.color ||
|
|
182
|
-
(chartStyling.darkMode ? DARK_MODE_COLORS[index] : COLORS[index]);
|
|
169
|
+
const color = annotation.color || COLORS[index];
|
|
183
170
|
copyDataset.push({
|
|
184
171
|
isAnnotation: true,
|
|
185
172
|
label: annotation.label,
|
|
@@ -221,9 +208,7 @@ const LineChart = (props) => {
|
|
|
221
208
|
const pointHoverRadius = line.pointHoverRadius
|
|
222
209
|
? parseFloat(line.pointHoverRadius)
|
|
223
210
|
: DEFAULT_HOVER_RADIUS;
|
|
224
|
-
const indexedColor =
|
|
225
|
-
? DARK_MODE_COLORS[i]
|
|
226
|
-
: COLORS[i];
|
|
211
|
+
const indexedColor = COLORS[i];
|
|
227
212
|
|
|
228
213
|
return {
|
|
229
214
|
...line,
|
|
@@ -310,7 +295,7 @@ const LineChart = (props) => {
|
|
|
310
295
|
const { ctx } = chart;
|
|
311
296
|
ctx.save();
|
|
312
297
|
ctx.globalCompositeOperation = 'destination-over';
|
|
313
|
-
ctx.fillStyle =
|
|
298
|
+
ctx.fillStyle = 'white';
|
|
314
299
|
ctx.fillRect(0, 0, chart.width, chart.height);
|
|
315
300
|
ctx.restore();
|
|
316
301
|
|
|
@@ -419,17 +419,3 @@ SquareAspectRatio.args = {
|
|
|
419
419
|
},
|
|
420
420
|
},
|
|
421
421
|
};
|
|
422
|
-
|
|
423
|
-
export const DarkMode = Template.bind({});
|
|
424
|
-
DarkMode.args = {
|
|
425
|
-
chart: {
|
|
426
|
-
...basicChart,
|
|
427
|
-
options: {
|
|
428
|
-
...basicChart.options,
|
|
429
|
-
chartStyling: {
|
|
430
|
-
...basicChart.options.chartStyling,
|
|
431
|
-
darkMode: true,
|
|
432
|
-
},
|
|
433
|
-
},
|
|
434
|
-
},
|
|
435
|
-
};
|
|
@@ -18,7 +18,6 @@ export const PieChartPropTypes = {
|
|
|
18
18
|
maintainAspectRatio: PropTypes.bool,
|
|
19
19
|
staticChartHeight: PropTypes.bool,
|
|
20
20
|
performanceMode: PropTypes.bool,
|
|
21
|
-
darkMode: PropTypes.bool,
|
|
22
21
|
}),
|
|
23
22
|
tooltip: PropTypes.shape({
|
|
24
23
|
tooltips: PropTypes.bool,
|
|
@@ -74,7 +73,6 @@ export const getDefaultProps = (props) => {
|
|
|
74
73
|
props.chart.options.chartStyling.performanceMode != null
|
|
75
74
|
? props.chart.options.chartStyling.performanceMode
|
|
76
75
|
: true,
|
|
77
|
-
darkMode: props.chart.options.chartStyling.darkMode || false,
|
|
78
76
|
},
|
|
79
77
|
tooltip: {
|
|
80
78
|
tooltips:
|
|
@@ -21,29 +21,6 @@ export const colors = [
|
|
|
21
21
|
'#3b3eac',
|
|
22
22
|
];
|
|
23
23
|
|
|
24
|
-
export const colorsDarkmode = [
|
|
25
|
-
'#578fff',
|
|
26
|
-
'#ff5026',
|
|
27
|
-
'#ff9900',
|
|
28
|
-
'#24ff31',
|
|
29
|
-
'#ff00ff',
|
|
30
|
-
'#00c5ff',
|
|
31
|
-
'#f7407d',
|
|
32
|
-
'#99ff00',
|
|
33
|
-
'#ff4040',
|
|
34
|
-
'#51a7fc',
|
|
35
|
-
'#f26bf2',
|
|
36
|
-
'#36f8ff',
|
|
37
|
-
'#ffff19',
|
|
38
|
-
'#9c6bff',
|
|
39
|
-
'#ff8b17',
|
|
40
|
-
'#ff1212',
|
|
41
|
-
'#fa29ff',
|
|
42
|
-
'#54ffaa',
|
|
43
|
-
'#80b0ff',
|
|
44
|
-
'#595eff',
|
|
45
|
-
];
|
|
46
|
-
|
|
47
24
|
export const generateRandomColor = () => {
|
|
48
25
|
const color = `#${Math.floor(Math.random() * 16777215).toString(16)}`;
|
|
49
26
|
if (colors.includes(color)) {
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
ArcElement,
|
|
5
5
|
CategoryScale,
|
|
6
6
|
Chart as ChartJS,
|
|
7
|
-
defaults,
|
|
8
7
|
Filler,
|
|
9
8
|
Legend,
|
|
10
9
|
LinearScale,
|
|
@@ -17,13 +16,9 @@ import dataLabelsPlugin from 'chartjs-plugin-datalabels';
|
|
|
17
16
|
import { Pie } from 'react-chartjs-2';
|
|
18
17
|
|
|
19
18
|
import styles from './pie-chart.module.less';
|
|
20
|
-
import { colors,
|
|
19
|
+
import { colors, generateRandomColor } from './pie-chart-utils';
|
|
21
20
|
import { getDefaultProps, PieChartPropTypes } from './pie-chart-prop-types';
|
|
22
|
-
import {
|
|
23
|
-
DEFAULT_COLOR,
|
|
24
|
-
DEFAULT_DARK_MODE_BORDER_COLOR,
|
|
25
|
-
DEFAULT_DARK_MODE_COLOR,
|
|
26
|
-
} from '../../helpers/chart-consts';
|
|
21
|
+
import { setDefaultTheme } from '../../helpers/chart-utils';
|
|
27
22
|
|
|
28
23
|
ChartJS.register(
|
|
29
24
|
LinearScale,
|
|
@@ -38,12 +33,6 @@ ChartJS.register(
|
|
|
38
33
|
dataLabelsPlugin,
|
|
39
34
|
);
|
|
40
35
|
|
|
41
|
-
defaults.font.size = 13;
|
|
42
|
-
defaults.color = DEFAULT_COLOR;
|
|
43
|
-
defaults.font.family = '"Lato", sans-serif';
|
|
44
|
-
defaults.darkModeColor = DEFAULT_DARK_MODE_COLOR;
|
|
45
|
-
defaults.darkModeBorderColor = DEFAULT_DARK_MODE_BORDER_COLOR;
|
|
46
|
-
|
|
47
36
|
/**
|
|
48
37
|
* this is a pie chart component
|
|
49
38
|
* @param {} props
|
|
@@ -51,6 +40,7 @@ defaults.darkModeBorderColor = DEFAULT_DARK_MODE_BORDER_COLOR;
|
|
|
51
40
|
* ./pie-chart.interface
|
|
52
41
|
*/
|
|
53
42
|
const PieChart = (props) => {
|
|
43
|
+
setDefaultTheme();
|
|
54
44
|
const chart = getDefaultProps(props);
|
|
55
45
|
const chartRef = useRef(null);
|
|
56
46
|
const [pointHover, setPointHover] = useState(false);
|
|
@@ -90,15 +80,9 @@ const PieChart = (props) => {
|
|
|
90
80
|
|
|
91
81
|
const generatedDatasets = copyDataset.map((pieDataset, index) => {
|
|
92
82
|
const borderWidth = parseFloat(pieDataset.borderWidth) || '1';
|
|
93
|
-
const
|
|
83
|
+
const color = pieDataset.data.map(
|
|
94
84
|
(pie, i) => colors[i] || generateRandomColor(),
|
|
95
85
|
);
|
|
96
|
-
const colorDarkmode = pieDataset.data.map(
|
|
97
|
-
(pie, i) => colorsDarkmode[i] || generateRandomColor(),
|
|
98
|
-
);
|
|
99
|
-
const color = options.chartStyling.darkMode
|
|
100
|
-
? colorDarkmode
|
|
101
|
-
: colorLightmode;
|
|
102
86
|
const borderColor = pieDataset.borderColor || color;
|
|
103
87
|
const backgroundColor =
|
|
104
88
|
pieDataset.backgroundColor ||
|
|
@@ -120,10 +104,7 @@ const PieChart = (props) => {
|
|
|
120
104
|
return options.title !== ''
|
|
121
105
|
? {
|
|
122
106
|
display: true,
|
|
123
|
-
text: options.title,
|
|
124
|
-
color: options.chartStyling.darkMode
|
|
125
|
-
? defaults.darkModeColor
|
|
126
|
-
: undefined,
|
|
107
|
+
text: chart.options.title,
|
|
127
108
|
}
|
|
128
109
|
: {};
|
|
129
110
|
};
|
|
@@ -244,9 +225,6 @@ const PieChart = (props) => {
|
|
|
244
225
|
: label;
|
|
245
226
|
return dataLabel;
|
|
246
227
|
},
|
|
247
|
-
color: options.chartStyling.darkMode
|
|
248
|
-
? defaults.darkModeColor
|
|
249
|
-
: undefined,
|
|
250
228
|
}
|
|
251
229
|
: {
|
|
252
230
|
display: false,
|
|
@@ -355,9 +333,6 @@ const PieChart = (props) => {
|
|
|
355
333
|
boxHeight: 6,
|
|
356
334
|
boxWidth: 6,
|
|
357
335
|
usePointStyle: true,
|
|
358
|
-
color: options.chartStyling.darkMode
|
|
359
|
-
? defaults.darkModeColor
|
|
360
|
-
: undefined,
|
|
361
336
|
filter: (item, data) => {
|
|
362
337
|
if (!options.legend.useDataset) return true;
|
|
363
338
|
return !data.datasets[item.index]?.hideLegend;
|
|
@@ -102,38 +102,6 @@ const dataLabelssTooltips = {
|
|
|
102
102
|
},
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
-
const darkMode = {
|
|
106
|
-
data: {
|
|
107
|
-
labels: labels1,
|
|
108
|
-
datasets: [dataset1, dataset2, dataset3],
|
|
109
|
-
},
|
|
110
|
-
options: {
|
|
111
|
-
title: 'Dark mode',
|
|
112
|
-
axes: {
|
|
113
|
-
x: [
|
|
114
|
-
{
|
|
115
|
-
label: 'X',
|
|
116
|
-
},
|
|
117
|
-
],
|
|
118
|
-
},
|
|
119
|
-
chartStyling: {
|
|
120
|
-
darkMode: true,
|
|
121
|
-
},
|
|
122
|
-
graph: {
|
|
123
|
-
showDataLabels: true,
|
|
124
|
-
showMinorGridlines: true,
|
|
125
|
-
},
|
|
126
|
-
annotations: {
|
|
127
|
-
annotationsData: [
|
|
128
|
-
{
|
|
129
|
-
label: 'Annotation 1',
|
|
130
|
-
value: 6,
|
|
131
|
-
},
|
|
132
|
-
],
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
};
|
|
136
|
-
|
|
137
105
|
const hoverOffsetChart = {
|
|
138
106
|
data: {
|
|
139
107
|
labels: labels1,
|
|
@@ -229,6 +197,3 @@ HoverOffset.args = { chart: hoverOffsetChart };
|
|
|
229
197
|
|
|
230
198
|
export const SegmentOffset = Template.bind({});
|
|
231
199
|
HoverOffset.args = { chart: offsetChart };
|
|
232
|
-
|
|
233
|
-
export const DarkMode = Template.bind({});
|
|
234
|
-
DarkMode.args = { chart: darkMode };
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Scatter } from 'react-chartjs-2';
|
|
3
3
|
|
|
4
|
+
import { setDefaultTheme } from '../../helpers/chart-utils';
|
|
5
|
+
import styles from './scatter-chart.module.less';
|
|
6
|
+
|
|
4
7
|
/**
|
|
5
8
|
*
|
|
6
9
|
* @param {import('./scatter-chart.intefrace').IScatterChartProps} props
|
|
7
10
|
*/
|
|
8
11
|
const ScatterChart = (props) => {
|
|
12
|
+
setDefaultTheme();
|
|
9
13
|
const { data, options, testId = null } = props.chart;
|
|
10
|
-
return
|
|
14
|
+
return (
|
|
15
|
+
<div className={styles.chart}>
|
|
16
|
+
<Scatter options={options} data={data} data-testid={testId} />
|
|
17
|
+
</div>
|
|
18
|
+
);
|
|
11
19
|
};
|
|
12
20
|
|
|
13
21
|
export default ScatterChart;
|
|
@@ -4,10 +4,9 @@ export const BORDER_WIDTH = {
|
|
|
4
4
|
};
|
|
5
5
|
|
|
6
6
|
export const ANNOTATION_DASH = [10, 2];
|
|
7
|
+
export const DEFAULT_BORDER_COLOR = 'rgba(0,0,0,0.1)';
|
|
7
8
|
export const DEFAULT_FONT_SIZE = 13;
|
|
8
9
|
export const DEFAULT_FONT_FAMILY = '"Lato", sans-serif';
|
|
9
|
-
export const DEFAULT_DARK_MODE_COLOR = 'rgba(255,255,255,.87)';
|
|
10
|
-
export const DEFAULT_DARK_MODE_BORDER_COLOR = 'rgba(255,255,255,0.1)';
|
|
11
10
|
export const DEFAULT_COLOR = 'rgba(0,0,0,.87)';
|
|
12
11
|
export const LEGEND_LABEL_BOX_SIZE = 6;
|
|
13
12
|
|
|
@@ -36,29 +35,6 @@ export const COLORS = [
|
|
|
36
35
|
'#3b3eac',
|
|
37
36
|
];
|
|
38
37
|
|
|
39
|
-
export const DARK_MODE_COLORS = [
|
|
40
|
-
'#578fff',
|
|
41
|
-
'#ff5026',
|
|
42
|
-
'#ff9900',
|
|
43
|
-
'#24ff31',
|
|
44
|
-
'#ff00ff',
|
|
45
|
-
'#00c5ff',
|
|
46
|
-
'#f7407d',
|
|
47
|
-
'#99ff00',
|
|
48
|
-
'#ff4040',
|
|
49
|
-
'#51a7fc',
|
|
50
|
-
'#f26bf2',
|
|
51
|
-
'#36f8ff',
|
|
52
|
-
'#ffff19',
|
|
53
|
-
'#9c6bff',
|
|
54
|
-
'#ff8b17',
|
|
55
|
-
'#ff1212',
|
|
56
|
-
'#fa29ff',
|
|
57
|
-
'#54ffaa',
|
|
58
|
-
'#80b0ff',
|
|
59
|
-
'#595eff',
|
|
60
|
-
];
|
|
61
|
-
|
|
62
38
|
/**
|
|
63
39
|
* @type {string}
|
|
64
40
|
* @desc equivalent of 0.6 rgba alpha chanel
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { defaults } from 'chart.js';
|
|
1
2
|
import cx from 'classnames';
|
|
2
3
|
import { chartMinorGridlinesPlugin } from '../components/line-chart/line-chart.minor-gridlines-plugin';
|
|
3
4
|
import {
|
|
4
5
|
CUSTOM_LEGEND_PLUGIN_NAME,
|
|
6
|
+
DEFAULT_BORDER_COLOR,
|
|
5
7
|
DEFAULT_CHART_NAME,
|
|
6
|
-
|
|
8
|
+
DEFAULT_COLOR,
|
|
9
|
+
DEFAULT_FONT_FAMILY,
|
|
10
|
+
DEFAULT_FONT_SIZE,
|
|
7
11
|
LEGEND_LABEL_BOX_SIZE,
|
|
8
12
|
WHITE_COLOR_AS_DECIMAL,
|
|
9
13
|
} from './chart-consts';
|
|
@@ -92,9 +96,6 @@ export const getTitle = (options) => {
|
|
|
92
96
|
? {
|
|
93
97
|
display: true,
|
|
94
98
|
text: options.title,
|
|
95
|
-
color: options.chartStyling.darkMode
|
|
96
|
-
? DEFAULT_DARK_MODE_COLOR
|
|
97
|
-
: undefined,
|
|
98
99
|
}
|
|
99
100
|
: {};
|
|
100
101
|
};
|
|
@@ -164,7 +165,6 @@ export const getLegend = (options, clickHandler, state = null) => {
|
|
|
164
165
|
boxHeight: LEGEND_LABEL_BOX_SIZE,
|
|
165
166
|
boxWidth: LEGEND_LABEL_BOX_SIZE,
|
|
166
167
|
usePointStyle: true,
|
|
167
|
-
color: chartStyling.darkMode ? DEFAULT_DARK_MODE_COLOR : undefined,
|
|
168
168
|
filter: (item, data) => !data.datasets[item.datasetIndex].hideLegend,
|
|
169
169
|
},
|
|
170
170
|
onClick: clickHandler,
|
|
@@ -196,3 +196,10 @@ export const getChartFileName = (axes) => {
|
|
|
196
196
|
}, []);
|
|
197
197
|
return axesLabels.join('_');
|
|
198
198
|
};
|
|
199
|
+
|
|
200
|
+
export const setDefaultTheme = () => {
|
|
201
|
+
defaults.font.size = DEFAULT_FONT_SIZE;
|
|
202
|
+
defaults.font.family = DEFAULT_FONT_FAMILY;
|
|
203
|
+
defaults.color = DEFAULT_COLOR;
|
|
204
|
+
defaults.borderColor = DEFAULT_BORDER_COLOR;
|
|
205
|
+
};
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { AxisType, ChartType, CursorStyle, Position } from './enums';
|
|
2
|
-
import {
|
|
3
|
-
ANNOTATION_DASH,
|
|
4
|
-
BORDER_WIDTH,
|
|
5
|
-
COLORS,
|
|
6
|
-
DARK_MODE_COLORS,
|
|
7
|
-
} from './chart-consts';
|
|
2
|
+
import { ANNOTATION_DASH, BORDER_WIDTH, COLORS } from './chart-consts';
|
|
8
3
|
|
|
9
4
|
const annotationEnter = ({ element }, { chart }) => {
|
|
10
5
|
if (element.options.scaleID?.includes(AxisType.X)) {
|
|
@@ -30,7 +25,6 @@ const annotationLeave = ({ element }, { chart }) => {
|
|
|
30
25
|
*/
|
|
31
26
|
const generateAnnotations = (options, state) => {
|
|
32
27
|
const { annotationsData } = options.annotations;
|
|
33
|
-
const isDarkModeOn = options.chartStyling.darkMode;
|
|
34
28
|
|
|
35
29
|
const annotations = annotationsData?.reduce((acc, curr, i) => {
|
|
36
30
|
if (!state?.showAnnotationLineIndex?.includes(i)) {
|
|
@@ -42,8 +36,7 @@ const generateAnnotations = (options, state) => {
|
|
|
42
36
|
return options.axes[axisType]?.length > 1 ? `${axisType}1` : axisType;
|
|
43
37
|
};
|
|
44
38
|
|
|
45
|
-
const color =
|
|
46
|
-
curr?.color || (isDarkModeOn ? DARK_MODE_COLORS[i] : COLORS[i]);
|
|
39
|
+
const color = curr?.color || COLORS[i];
|
|
47
40
|
|
|
48
41
|
const annotation = {
|
|
49
42
|
...curr,
|
|
@@ -65,7 +65,6 @@ export const getCustomLegendPlugin = (customLegendContainerID) => ({
|
|
|
65
65
|
|
|
66
66
|
// Text
|
|
67
67
|
const textContainer = document.createElement('p');
|
|
68
|
-
textContainer.style.color = item.fontColor;
|
|
69
68
|
textContainer.style.margin = 0;
|
|
70
69
|
textContainer.style.padding = 0;
|
|
71
70
|
textContainer.style.textDecoration = item.hidden ? 'line-through' : '';
|