@oliasoft-open-source/charts-library 2.0.0
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/.eslintignore +2 -0
- package/.eslintrc.js +129 -0
- package/.gitlab-ci.yml +77 -0
- package/.husky/pre-commit +4 -0
- package/.prettierignore +3 -0
- package/.prettierrc +4 -0
- package/.storybook/main.js +40 -0
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/babel.config.js +29 -0
- package/index.js +9 -0
- package/jest.config.js +9 -0
- package/package.json +96 -0
- package/src/components/bar-chart/bar-chart-prop-types.js +181 -0
- package/src/components/bar-chart/bar-chart.interface.ts +83 -0
- package/src/components/bar-chart/bar-chart.jsx +247 -0
- package/src/components/bar-chart/bar-chart.module.less +56 -0
- package/src/components/bar-chart/basic.stories.jsx +752 -0
- package/src/components/bar-chart/charts.stories.jsx +119 -0
- package/src/components/bar-chart/get-bar-chart-data-labels.js +45 -0
- package/src/components/bar-chart/get-bar-chart-scales.js +147 -0
- package/src/components/bar-chart/get-bar-chart-tooltips.js +100 -0
- package/src/components/line-chart/Controls/Controls.jsx +59 -0
- package/src/components/line-chart/Controls/Controls.module.less +21 -0
- package/src/components/line-chart/Controls/Layer.jsx +169 -0
- package/src/components/line-chart/basic.stories.jsx +735 -0
- package/src/components/line-chart/charts.stories.jsx +264 -0
- package/src/components/line-chart/get-line-chart-data-labels.js +24 -0
- package/src/components/line-chart/get-line-chart-scales.js +131 -0
- package/src/components/line-chart/get-line-chart-tooltips.js +91 -0
- package/src/components/line-chart/line-chart-consts.js +6 -0
- package/src/components/line-chart/line-chart-prop-types.js +187 -0
- package/src/components/line-chart/line-chart-utils.js +163 -0
- package/src/components/line-chart/line-chart.interface.ts +103 -0
- package/src/components/line-chart/line-chart.jsx +423 -0
- package/src/components/line-chart/line-chart.minor-gridlines-plugin.js +78 -0
- package/src/components/line-chart/line-chart.minor-gridlines-plugin.test.js +34 -0
- package/src/components/line-chart/line-chart.module.less +56 -0
- package/src/components/line-chart/state/action-types.js +9 -0
- package/src/components/line-chart/state/initial-state.js +51 -0
- package/src/components/line-chart/state/line-chart-reducer.js +115 -0
- package/src/components/line-chart/stories/shapes/cubes.stories.jsx +326 -0
- package/src/components/line-chart/stories/shapes/pyramid.stories.jsx +189 -0
- package/src/components/line-chart/stories/shapes/round.stories.jsx +339 -0
- package/src/components/line-chart/stories/shapes/triangle.stories.jsx +166 -0
- package/src/components/pie-chart/basic.stories.jsx +390 -0
- package/src/components/pie-chart/charts.stories.jsx +66 -0
- package/src/components/pie-chart/pie-chart-prop-types.js +111 -0
- package/src/components/pie-chart/pie-chart-utils.js +55 -0
- package/src/components/pie-chart/pie-chart.interface.ts +61 -0
- package/src/components/pie-chart/pie-chart.jsx +477 -0
- package/src/components/pie-chart/pie-chart.module.less +56 -0
- package/src/components/scatter-chart/scatter-chart.intefrace.ts +32 -0
- package/src/components/scatter-chart/scatter-chart.jsx +13 -0
- package/src/components/scatter-chart/scatter.stories.jsx +196 -0
- package/src/helpers/chart-consts.js +82 -0
- package/src/helpers/chart-interface.ts +54 -0
- package/src/helpers/chart-utils.js +178 -0
- package/src/helpers/container.jsx +60 -0
- package/src/helpers/disabled-context.js +8 -0
- package/src/helpers/enums.js +84 -0
- package/src/helpers/get-chart-annotation.js +91 -0
- package/src/helpers/styles.js +68 -0
- package/src/helpers/text.js +6 -0
- package/src/style/external.less +4 -0
- package/src/style/fonts/lato/Lato-Bold.woff2 +0 -0
- package/src/style/fonts/lato/Lato-BoldItalic.woff2 +0 -0
- package/src/style/fonts/lato/Lato-Italic.woff2 +0 -0
- package/src/style/fonts/lato/Lato-Regular.woff2 +0 -0
- package/src/style/fonts.less +27 -0
- package/src/style/global.less +43 -0
- package/src/style/reset/reset.less +28 -0
- package/src/style/shared.less +24 -0
- package/src/style/variables.less +91 -0
- package/webpack/webpack.common.js +39 -0
- package/webpack/webpack.common.rules.js +107 -0
- package/webpack/webpack.dev.js +22 -0
- package/webpack/webpack.prod.js +23 -0
- package/webpack/webpack.resolve.js +22 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Container } from '../../helpers/container';
|
|
3
|
+
import ScatterChart from './scatter-chart';
|
|
4
|
+
|
|
5
|
+
const style = {
|
|
6
|
+
height: '1000px',
|
|
7
|
+
width: '1000px',
|
|
8
|
+
colorOrange: '#ED9860',
|
|
9
|
+
colorLightGray: '#C8C8C8',
|
|
10
|
+
colorDarkGray: '#595959',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const dataPoints = [
|
|
14
|
+
{ x: 15.5, y: 0, label: '' },
|
|
15
|
+
{ x: 75, y: 13, label: '' },
|
|
16
|
+
{ x: 110, y: 85, label: '' },
|
|
17
|
+
{ x: 212.5, y: 100, label: '' },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
const dataPoints2 = [
|
|
21
|
+
{ x: 0, y: 15, label: '' },
|
|
22
|
+
{ x: 90, y: 15, label: '' },
|
|
23
|
+
{ x: 130, y: 75, label: '' },
|
|
24
|
+
{ x: 212.5, y: 115, label: '' },
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const dataPoints3 = [
|
|
28
|
+
{ x: 0, y: 0, label: '' },
|
|
29
|
+
{ x: 120, y: 75, label: '' },
|
|
30
|
+
{ x: 155, y: 50, label: '' },
|
|
31
|
+
{ x: 250, y: 115, label: '' },
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
const datasetMultiLines = [
|
|
35
|
+
{
|
|
36
|
+
label: 'Line 1',
|
|
37
|
+
data: dataPoints,
|
|
38
|
+
borderColor: style.colorOrange,
|
|
39
|
+
backgroundColor: style.colorOrange,
|
|
40
|
+
showLine: true,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
label: 'Line 2',
|
|
44
|
+
data: dataPoints2,
|
|
45
|
+
borderColor: style.colorLightGray,
|
|
46
|
+
backgroundColor: style.colorLightGray,
|
|
47
|
+
showLine: true,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
label: 'Line 3',
|
|
51
|
+
data: dataPoints3,
|
|
52
|
+
borderColor: style.colorDarkGray,
|
|
53
|
+
backgroundColor: style.colorDarkGray,
|
|
54
|
+
showLine: true,
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const chartDefault = {
|
|
59
|
+
data: {
|
|
60
|
+
datasets: [
|
|
61
|
+
{
|
|
62
|
+
label: 'Default chart',
|
|
63
|
+
data: dataPoints,
|
|
64
|
+
borderColor: style.colorOrange,
|
|
65
|
+
backgroundColor: style.colorOrange,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const chartWithLine = {
|
|
72
|
+
data: {
|
|
73
|
+
datasets: [
|
|
74
|
+
{
|
|
75
|
+
label: 'Default chart',
|
|
76
|
+
data: dataPoints,
|
|
77
|
+
borderColor: style.colorOrange,
|
|
78
|
+
backgroundColor: style.colorOrange,
|
|
79
|
+
showLine: true,
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const multiLines = {
|
|
86
|
+
data: {
|
|
87
|
+
datasets: datasetMultiLines,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const chartReverse = {
|
|
92
|
+
data: {
|
|
93
|
+
datasets: datasetMultiLines,
|
|
94
|
+
},
|
|
95
|
+
options: {
|
|
96
|
+
scales: { y: { reverse: true } },
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const chartLegendRight = {
|
|
101
|
+
data: {
|
|
102
|
+
datasets: datasetMultiLines,
|
|
103
|
+
},
|
|
104
|
+
options: {
|
|
105
|
+
plugins: {
|
|
106
|
+
legend: {
|
|
107
|
+
position: 'right',
|
|
108
|
+
},
|
|
109
|
+
title: {
|
|
110
|
+
display: true,
|
|
111
|
+
text: name || '',
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const chartResponsive = {
|
|
118
|
+
data: {
|
|
119
|
+
datasets: datasetMultiLines,
|
|
120
|
+
},
|
|
121
|
+
options: {
|
|
122
|
+
responsive: true,
|
|
123
|
+
maintainAspectRatio: false,
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
export default {
|
|
127
|
+
title: 'Scatter Chart',
|
|
128
|
+
component: ScatterChart,
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const Default = () => (
|
|
132
|
+
<Container style={style}>
|
|
133
|
+
<ScatterChart chart={chartDefault} />
|
|
134
|
+
</Container>
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
export const Linear = () => (
|
|
138
|
+
<Container style={style}>
|
|
139
|
+
<ScatterChart chart={chartWithLine} />
|
|
140
|
+
</Container>
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
export const MultiLines = () => (
|
|
144
|
+
<Container style={style}>
|
|
145
|
+
<ScatterChart chart={multiLines} />
|
|
146
|
+
</Container>
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
export const Reverse = () => (
|
|
150
|
+
<Container style={style}>
|
|
151
|
+
<ScatterChart chart={chartReverse} />
|
|
152
|
+
</Container>
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
export const LegendRight = () => (
|
|
156
|
+
<Container style={style}>
|
|
157
|
+
<ScatterChart chart={chartLegendRight} />
|
|
158
|
+
</Container>
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
export const Responsive = () => (
|
|
162
|
+
<Container>
|
|
163
|
+
<div
|
|
164
|
+
style={{
|
|
165
|
+
width: '50%',
|
|
166
|
+
height: '50%',
|
|
167
|
+
}}
|
|
168
|
+
>
|
|
169
|
+
<ScatterChart
|
|
170
|
+
chart={{
|
|
171
|
+
data: multiLines.data,
|
|
172
|
+
options: {
|
|
173
|
+
responsive: true,
|
|
174
|
+
maintainAspectRatio: false,
|
|
175
|
+
},
|
|
176
|
+
}}
|
|
177
|
+
/>
|
|
178
|
+
</div>
|
|
179
|
+
|
|
180
|
+
<div
|
|
181
|
+
style={{
|
|
182
|
+
width: '50%',
|
|
183
|
+
height: '50%',
|
|
184
|
+
}}
|
|
185
|
+
>
|
|
186
|
+
<ScatterChart
|
|
187
|
+
chart={{
|
|
188
|
+
data: multiLines.data,
|
|
189
|
+
options: {
|
|
190
|
+
responsive: true,
|
|
191
|
+
},
|
|
192
|
+
}}
|
|
193
|
+
/>
|
|
194
|
+
</div>
|
|
195
|
+
</Container>
|
|
196
|
+
);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export const BORDER_WIDTH = {
|
|
2
|
+
INITIAL: 2,
|
|
3
|
+
HOVERED: 6,
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export const ANNOTATION_DASH = [10, 2];
|
|
7
|
+
export const DEFAULT_FONT_SIZE = 13;
|
|
8
|
+
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
|
+
export const DEFAULT_COLOR = 'rgba(0,0,0,.87)';
|
|
12
|
+
export const LEGEND_LABEL_BOX_SIZE = 6;
|
|
13
|
+
|
|
14
|
+
export const LOGARITHMIC_STEPS = [1, 10, 100, 1000, 10000];
|
|
15
|
+
|
|
16
|
+
export const COLORS = [
|
|
17
|
+
'#3366cc',
|
|
18
|
+
'#dc3912',
|
|
19
|
+
'#ff9900',
|
|
20
|
+
'#109618',
|
|
21
|
+
'#990099',
|
|
22
|
+
'#0099c6',
|
|
23
|
+
'#dd4477',
|
|
24
|
+
'#66aa00',
|
|
25
|
+
'#b82e2e',
|
|
26
|
+
'#316395',
|
|
27
|
+
'#994499',
|
|
28
|
+
'#22aa99',
|
|
29
|
+
'#aaaa11',
|
|
30
|
+
'#6633cc',
|
|
31
|
+
'#e67300',
|
|
32
|
+
'#8b0707',
|
|
33
|
+
'#651067',
|
|
34
|
+
'#329262',
|
|
35
|
+
'#5574a6',
|
|
36
|
+
'#3b3eac',
|
|
37
|
+
];
|
|
38
|
+
|
|
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
|
+
/**
|
|
63
|
+
* @type {string}
|
|
64
|
+
* @desc equivalent of 0.6 rgba alpha chanel
|
|
65
|
+
*/
|
|
66
|
+
export const ALPHA_CHANEL = '99';
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @type {number}
|
|
70
|
+
* @desc #FFFFFF as decimal number
|
|
71
|
+
*/
|
|
72
|
+
export const WHITE_COLOR_AS_DECIMAL = 16777215;
|
|
73
|
+
|
|
74
|
+
export const AUTO = 'auto';
|
|
75
|
+
|
|
76
|
+
export const ANIMATION_DURATION = {
|
|
77
|
+
NO: 0,
|
|
78
|
+
SLOW: 400,
|
|
79
|
+
FAST: 1000,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const DEFAULT_CHART_NAME = 'new_chart';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export interface IChartAnnotationsData {
|
|
2
|
+
annotationAxis: 'x' | 'y';
|
|
3
|
+
label: string;
|
|
4
|
+
color: string;
|
|
5
|
+
value: number;
|
|
6
|
+
endValue: number
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export interface IChartAnnotations {
|
|
10
|
+
showAnnotations: boolean;
|
|
11
|
+
controlAnnotation: boolean;
|
|
12
|
+
annotationsData: IChartAnnotationsData[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface IChartStyling {
|
|
16
|
+
width: number | string;
|
|
17
|
+
height: number | string;
|
|
18
|
+
maintainAspectRatio: boolean;
|
|
19
|
+
staticChartHeight: boolean;
|
|
20
|
+
performanceMode: boolean;
|
|
21
|
+
darkMode: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface IChartLegend {
|
|
25
|
+
display: boolean;
|
|
26
|
+
position: 'top' | 'bottom' | 'right';
|
|
27
|
+
align: 'start' | 'center' | 'end';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface IChartInteractions {
|
|
31
|
+
onLegendClick: () => any;
|
|
32
|
+
onPointHover: () => any;
|
|
33
|
+
onPointUnhover: () => any;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface IInitialState {
|
|
37
|
+
zoomEnabled?: boolean;
|
|
38
|
+
panEnabled?: boolean;
|
|
39
|
+
pointsEnabled?: boolean;
|
|
40
|
+
lineEnabled?: boolean;
|
|
41
|
+
legendEnabled?: boolean;
|
|
42
|
+
axes?: {id: string, label: string | any, min?: {}, max?: {}}[];
|
|
43
|
+
showAnnotationLineIndex: [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface IChartPlugins {
|
|
47
|
+
legend: {
|
|
48
|
+
position: 'top' | 'right' | 'bottom' | 'left';
|
|
49
|
+
}
|
|
50
|
+
title: {
|
|
51
|
+
display: boolean;
|
|
52
|
+
text: string;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import cx from 'classnames';
|
|
2
|
+
import { chartMinorGridlinesPlugin } from '../components/line-chart/line-chart.minor-gridlines-plugin';
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_CHART_NAME,
|
|
5
|
+
DEFAULT_DARK_MODE_COLOR,
|
|
6
|
+
LEGEND_LABEL_BOX_SIZE,
|
|
7
|
+
WHITE_COLOR_AS_DECIMAL,
|
|
8
|
+
} from './chart-consts';
|
|
9
|
+
import { AxisType, ChartDirection, Position } from './enums';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {import('../components/bar-chart/bar-chart.interface').IBarChartGraph |
|
|
13
|
+
* import('../components/line-chart/line-chart.interface').ILineChartGraph } graph - graph data from chart options
|
|
14
|
+
* @return {[]}
|
|
15
|
+
*/
|
|
16
|
+
export const getPlugins = (graph) => {
|
|
17
|
+
let plugins = [];
|
|
18
|
+
if (graph.showMinorGridlines) {
|
|
19
|
+
plugins.push(chartMinorGridlinesPlugin);
|
|
20
|
+
}
|
|
21
|
+
return plugins;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const getAxisValue = (value) => {
|
|
25
|
+
if (value !== undefined) {
|
|
26
|
+
if (value === '-') {
|
|
27
|
+
return {
|
|
28
|
+
inputValue: value,
|
|
29
|
+
displayValue: '',
|
|
30
|
+
value: '',
|
|
31
|
+
valid: false,
|
|
32
|
+
};
|
|
33
|
+
} else {
|
|
34
|
+
return {
|
|
35
|
+
inputValue: value.toString(),
|
|
36
|
+
displayValue: value,
|
|
37
|
+
value,
|
|
38
|
+
valid: true,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
return {
|
|
43
|
+
valid: true /* default always valid, for unknowable reasons */,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {string[]} colors - color schema
|
|
50
|
+
* @return {string} - random color
|
|
51
|
+
*/
|
|
52
|
+
export const generateRandomColor = (colors) => {
|
|
53
|
+
const color = `#${Math.floor(Math.random() * WHITE_COLOR_AS_DECIMAL).toString(
|
|
54
|
+
16,
|
|
55
|
+
)}`;
|
|
56
|
+
if (colors.includes(color)) {
|
|
57
|
+
return generateRandomColor(colors);
|
|
58
|
+
} else {
|
|
59
|
+
colors.push(color);
|
|
60
|
+
return color;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {import('./chart-interface').IChartAnnotationsData[]} annotationsData
|
|
66
|
+
* @return {number[]|*[]}
|
|
67
|
+
*/
|
|
68
|
+
export const setAnnotations = (annotationsData) => {
|
|
69
|
+
return annotationsData?.length ? annotationsData.map((v, i) => i) : [];
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @param {import('../components/bar-chart/bar-chart.interface').IBarChartOptions |
|
|
74
|
+
* import('../components/line-chart/line-chart.interface').ILineChartOptions} options - chart options object
|
|
75
|
+
* @return {{color: (string|undefined), display: boolean, text}|{}}
|
|
76
|
+
*/
|
|
77
|
+
export const getTitle = (options) => {
|
|
78
|
+
return options.title !== ''
|
|
79
|
+
? {
|
|
80
|
+
display: true,
|
|
81
|
+
text: options.title,
|
|
82
|
+
color: options.chartStyling.darkMode
|
|
83
|
+
? DEFAULT_DARK_MODE_COLOR
|
|
84
|
+
: undefined,
|
|
85
|
+
}
|
|
86
|
+
: {};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @function isVertical
|
|
91
|
+
* @param {'vertical'|'horizontal'|string} direction
|
|
92
|
+
* @return {boolean} returns true if chart direction is vertical
|
|
93
|
+
*/
|
|
94
|
+
export const isVertical = (direction) => {
|
|
95
|
+
return direction === ChartDirection.Vertical;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @param {'x'|'y'} axisType
|
|
100
|
+
* @param {number} i - index
|
|
101
|
+
* @return {'top'|'bottom'|'left'|'right'|*}
|
|
102
|
+
*/
|
|
103
|
+
export const getAxisPosition = (axisType, i) => {
|
|
104
|
+
const [positionA, positionB] =
|
|
105
|
+
axisType === AxisType.Y
|
|
106
|
+
? [Position.Left, Position.Right]
|
|
107
|
+
: [Position.Top, Position.Bottom];
|
|
108
|
+
return i % 2 === 0 ? positionA : positionB;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @param {import('../helpers/chart-interface').IChartStyling} chartStyling
|
|
113
|
+
* @param {Object} styles - styles imported form .less file
|
|
114
|
+
* @return {string} - class name
|
|
115
|
+
*/
|
|
116
|
+
export const getClassName = (chartStyling, styles) => {
|
|
117
|
+
const { width, height, staticChartHeight } = chartStyling;
|
|
118
|
+
let heightStyles = '';
|
|
119
|
+
if (width || height) {
|
|
120
|
+
heightStyles = '';
|
|
121
|
+
} else {
|
|
122
|
+
heightStyles = staticChartHeight
|
|
123
|
+
? styles?.fixedHeight
|
|
124
|
+
: styles?.stretchHeight;
|
|
125
|
+
}
|
|
126
|
+
return cx(styles.chart, heightStyles);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
*
|
|
131
|
+
* @param {import('../components/bar-chart/bar-chart.interface').IBarChartOptions |
|
|
132
|
+
* import('../components/line-chart/line-chart.interface').ILineChartOptions} options - chart options object
|
|
133
|
+
* @param {function} clickHandler - on click callback
|
|
134
|
+
* @param {import('./chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
|
|
135
|
+
* @returns {*}
|
|
136
|
+
*/
|
|
137
|
+
export const getLegend = (options, clickHandler, state = null) => {
|
|
138
|
+
const { legend, chartStyling } = options;
|
|
139
|
+
return {
|
|
140
|
+
position: legend.position || Position.Top,
|
|
141
|
+
display: state ? state.legendEnabled : legend.display,
|
|
142
|
+
align: legend.align,
|
|
143
|
+
labels: {
|
|
144
|
+
boxHeight: LEGEND_LABEL_BOX_SIZE,
|
|
145
|
+
boxWidth: LEGEND_LABEL_BOX_SIZE,
|
|
146
|
+
usePointStyle: true,
|
|
147
|
+
color: chartStyling.darkMode ? DEFAULT_DARK_MODE_COLOR : undefined,
|
|
148
|
+
filter: (item, data) => !data.datasets[item.datasetIndex].hideLegend,
|
|
149
|
+
},
|
|
150
|
+
onClick: clickHandler,
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export const afterLabelCallback = (tooltipItem) => {
|
|
155
|
+
const { error } = tooltipItem.dataset.data[tooltipItem?.dataIndex];
|
|
156
|
+
return error ? `Error: ${Math.round(error * 10000) / 10000}` : '';
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const getTooltipLabel = (tooltipItem, showLabelsInTooltips) => {
|
|
160
|
+
const datasetDataLabel =
|
|
161
|
+
tooltipItem.dataset.data[tooltipItem.dataIndex]?.label;
|
|
162
|
+
const dataLabel = Array.isArray(datasetDataLabel)
|
|
163
|
+
? datasetDataLabel.join(' , ')
|
|
164
|
+
: datasetDataLabel;
|
|
165
|
+
return showLabelsInTooltips && dataLabel?.length ? ` (${dataLabel})` : '';
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
//TODO: consider returning chart name instead of axis names
|
|
169
|
+
export const getChartFileName = (axes) => {
|
|
170
|
+
if (!axes) {
|
|
171
|
+
return DEFAULT_CHART_NAME;
|
|
172
|
+
}
|
|
173
|
+
const axesLabels = axes.reduce((acc, cur, index) => {
|
|
174
|
+
const labelWithNoSpace = cur.label?.replace(/\s/g, '_') || index;
|
|
175
|
+
return [...acc, labelWithNoSpace];
|
|
176
|
+
}, []);
|
|
177
|
+
return axesLabels.join('_');
|
|
178
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
import '../style/reset/reset.less';
|
|
5
|
+
import '../style/global.less';
|
|
6
|
+
|
|
7
|
+
const outerContainerStyle = {
|
|
8
|
+
margin: '50px',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const Container = ({
|
|
12
|
+
style,
|
|
13
|
+
children,
|
|
14
|
+
margin,
|
|
15
|
+
deprecatedMessage,
|
|
16
|
+
warningMessage,
|
|
17
|
+
}) => {
|
|
18
|
+
return (
|
|
19
|
+
<div style={margin ? outerContainerStyle : {}}>
|
|
20
|
+
{deprecatedMessage ? (
|
|
21
|
+
<div
|
|
22
|
+
style={{
|
|
23
|
+
border: '1px solid red',
|
|
24
|
+
color: 'red',
|
|
25
|
+
padding: '10px',
|
|
26
|
+
marginBottom: '20px',
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
{deprecatedMessage}
|
|
30
|
+
</div>
|
|
31
|
+
) : null}
|
|
32
|
+
{warningMessage ? (
|
|
33
|
+
<div
|
|
34
|
+
style={{
|
|
35
|
+
border: '1px solid orange',
|
|
36
|
+
color: 'orange',
|
|
37
|
+
padding: '10px',
|
|
38
|
+
marginBottom: '20px',
|
|
39
|
+
}}
|
|
40
|
+
>
|
|
41
|
+
{warningMessage}
|
|
42
|
+
</div>
|
|
43
|
+
) : null}
|
|
44
|
+
<div style={style}>{children}</div>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
Container.defaultProps = {
|
|
50
|
+
style: {},
|
|
51
|
+
margin: true,
|
|
52
|
+
deprecatedMessage: null,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
Container.propTypes = {
|
|
56
|
+
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
57
|
+
children: PropTypes.node.isRequired,
|
|
58
|
+
margin: PropTypes.bool,
|
|
59
|
+
deprecatedMessage: PropTypes.string,
|
|
60
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @enum {string}
|
|
3
|
+
*/
|
|
4
|
+
export const AxisType = Object.freeze({
|
|
5
|
+
X: 'x',
|
|
6
|
+
Y: 'y',
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @enum {string}
|
|
11
|
+
*/
|
|
12
|
+
export const Position = Object.freeze({
|
|
13
|
+
Bottom: 'bottom',
|
|
14
|
+
Top: 'top',
|
|
15
|
+
Left: 'left',
|
|
16
|
+
Right: 'right',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @enum {string}
|
|
21
|
+
*/
|
|
22
|
+
export const ChartType = Object.freeze({
|
|
23
|
+
Line: 'line',
|
|
24
|
+
Bar: 'bar',
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @enum {string}
|
|
29
|
+
*/
|
|
30
|
+
export const CursorStyle = Object.freeze({
|
|
31
|
+
Pointer: 'pointer',
|
|
32
|
+
Initial: 'initial',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @enum {string}
|
|
37
|
+
*/
|
|
38
|
+
export const ScaleType = Object.freeze({
|
|
39
|
+
Category: 'category', //TODO: verify
|
|
40
|
+
Linear: 'linear',
|
|
41
|
+
Logarithmic: 'logarithmic',
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @enum {string}
|
|
46
|
+
*/
|
|
47
|
+
export const ChartDirection = Object.freeze({
|
|
48
|
+
Vertical: 'vertical',
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @enum {string}
|
|
53
|
+
*/
|
|
54
|
+
export const TooltipLabel = Object.freeze({
|
|
55
|
+
Y: 'yLabel',
|
|
56
|
+
X: 'xLabel',
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export const AlignOptions = Object.freeze({
|
|
60
|
+
End: 'end',
|
|
61
|
+
Start: 'start',
|
|
62
|
+
Center: 'center',
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export const PointType = Object.freeze({
|
|
66
|
+
Casing: 'casing',
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export const PointStyle = Object.freeze({
|
|
70
|
+
Circle: 'circle',
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export const ChartHoverMode = Object.freeze({
|
|
74
|
+
Nearest: 'nearest',
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export const PanZoomMode = Object.freeze({
|
|
78
|
+
X: 'x',
|
|
79
|
+
Y: 'y',
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
export const Key = Object.freeze({
|
|
83
|
+
Shift: 'Shift',
|
|
84
|
+
});
|