@oliasoft-open-source/charts-library 2.17.6 → 2.18.0-beta-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +40398 -0
- package/dist/style.css +177 -0
- package/package.json +26 -34
- package/index.js +0 -14
- package/release-notes.md +0 -310
- package/src/assets/icons/line-and-point.svg +0 -1
- package/src/assets/icons/line-only.svg +0 -1
- package/src/assets/icons/list-hide.svg +0 -1
- package/src/assets/icons/point-only.svg +0 -1
- package/src/components/bar-chart/bar-chart-prop-types.js +0 -209
- package/src/components/bar-chart/bar-chart.interface.ts +0 -91
- package/src/components/bar-chart/bar-chart.jsx +0 -247
- package/src/components/bar-chart/bar-chart.module.less +0 -61
- package/src/components/bar-chart/get-bar-chart-data-labels.js +0 -42
- package/src/components/bar-chart/get-bar-chart-scales.js +0 -123
- package/src/components/bar-chart/get-bar-chart-tooltips.js +0 -102
- package/src/components/controls/axes-options/axes-options.jsx +0 -270
- package/src/components/line-chart/constants/default-translations.js +0 -24
- package/src/components/line-chart/constants/line-chart-consts.js +0 -12
- package/src/components/line-chart/controls/axes-options/action-types.js +0 -5
- package/src/components/line-chart/controls/axes-options/axes-options-form-state.js +0 -97
- package/src/components/line-chart/controls/controls.jsx +0 -174
- package/src/components/line-chart/controls/controls.module.less +0 -12
- package/src/components/line-chart/controls/drag-options.jsx +0 -112
- package/src/components/line-chart/controls/legend-options.jsx +0 -36
- package/src/components/line-chart/controls/line-options.jsx +0 -64
- package/src/components/line-chart/hooks/use-chart-functions.js +0 -257
- package/src/components/line-chart/hooks/use-chart-options.js +0 -181
- package/src/components/line-chart/hooks/use-chart-plugins.js +0 -35
- package/src/components/line-chart/hooks/use-toggle-handler.js +0 -33
- package/src/components/line-chart/initialize/config.js +0 -23
- package/src/components/line-chart/initialize/initialize-line-chart.js +0 -25
- package/src/components/line-chart/line-chart-prop-types.js +0 -292
- package/src/components/line-chart/line-chart.interface.ts +0 -121
- package/src/components/line-chart/line-chart.jsx +0 -161
- package/src/components/line-chart/line-chart.module.less +0 -77
- package/src/components/line-chart/plugins/chart-area-text-plugin.js +0 -246
- package/src/components/line-chart/plugins/line-chart.minor-gridlines-plugin.js +0 -88
- package/src/components/line-chart/plugins/plugin-constants.js +0 -11
- package/src/components/line-chart/state/action-types.js +0 -12
- package/src/components/line-chart/state/initial-state.js +0 -89
- package/src/components/line-chart/state/line-chart-reducer.js +0 -100
- package/src/components/line-chart/state/manage-state-in-local-storage.js +0 -86
- package/src/components/line-chart/state/use-chart-state.js +0 -141
- package/src/components/line-chart/utils/axis-scales/axis-scales.js +0 -165
- package/src/components/line-chart/utils/datalabels-alignment/get-alignment-condition.js +0 -13
- package/src/components/line-chart/utils/datalabels-alignment/get-alignment-data.js +0 -20
- package/src/components/line-chart/utils/datalabels-alignment/get-datalabels-position.js +0 -25
- package/src/components/line-chart/utils/generate-line-chart-datasets.js +0 -114
- package/src/components/line-chart/utils/get-axes-ranges-from-chart.js +0 -13
- package/src/components/line-chart/utils/get-line-chart-data-labels.js +0 -21
- package/src/components/line-chart/utils/get-line-chart-scales.js +0 -120
- package/src/components/line-chart/utils/get-line-chart-tooltips.js +0 -94
- package/src/components/line-chart/utils/line-chart-utils.js +0 -77
- package/src/components/line-chart/utils/translations/get-translations.js +0 -17
- package/src/components/pie-chart/pie-chart-prop-types.js +0 -111
- package/src/components/pie-chart/pie-chart-utils.js +0 -32
- package/src/components/pie-chart/pie-chart.interface.ts +0 -61
- package/src/components/pie-chart/pie-chart.jsx +0 -450
- package/src/components/pie-chart/pie-chart.module.less +0 -61
- package/src/components/scatter-chart/scatter-chart.intefrace.ts +0 -33
- package/src/components/scatter-chart/scatter-chart.jsx +0 -21
- package/src/components/scatter-chart/scatter-chart.module.less +0 -4
- package/src/helpers/chart-border-plugin.js +0 -19
- package/src/helpers/chart-consts.js +0 -64
- package/src/helpers/chart-interface.ts +0 -94
- package/src/helpers/chart-utils.js +0 -182
- package/src/helpers/container.jsx +0 -60
- package/src/helpers/disabled-context.js +0 -8
- package/src/helpers/enums.js +0 -96
- package/src/helpers/get-chart-annotation.js +0 -106
- package/src/helpers/get-custom-legend-plugin-example.js +0 -80
- package/src/helpers/get-draggableData.js +0 -32
- package/src/helpers/range/estimate-data-series-have-close-values.js +0 -54
- package/src/helpers/range/range.js +0 -100
- package/src/helpers/text.js +0 -6
- package/src/style/external.less +0 -4
- 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 +0 -27
- package/src/style/global.less +0 -43
- package/src/style/reset/reset.less +0 -28
- package/src/style/shared.less +0 -11
- package/src/style/variables.less +0 -91
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import PropTypes from 'prop-types';
|
|
2
|
-
|
|
3
|
-
export const BarChartPropTypes = {
|
|
4
|
-
chart: PropTypes.shape({
|
|
5
|
-
testId: PropTypes.string,
|
|
6
|
-
data: PropTypes.object.isRequired,
|
|
7
|
-
options: PropTypes.shape({
|
|
8
|
-
title: PropTypes.oneOfType([
|
|
9
|
-
PropTypes.string,
|
|
10
|
-
PropTypes.arrayOf(PropTypes.string),
|
|
11
|
-
]),
|
|
12
|
-
direction: PropTypes.oneOf(['vertical', 'horizontal']),
|
|
13
|
-
axes: PropTypes.shape({
|
|
14
|
-
x: PropTypes.arrayOf(
|
|
15
|
-
PropTypes.shape({
|
|
16
|
-
label: PropTypes.string,
|
|
17
|
-
position: PropTypes.oneOf(['top', 'bottom']),
|
|
18
|
-
color: PropTypes.string,
|
|
19
|
-
unit: PropTypes.string,
|
|
20
|
-
}),
|
|
21
|
-
),
|
|
22
|
-
y: PropTypes.arrayOf(
|
|
23
|
-
PropTypes.shape({
|
|
24
|
-
label: PropTypes.string,
|
|
25
|
-
position: PropTypes.oneOf(['left', 'right']),
|
|
26
|
-
color: PropTypes.string,
|
|
27
|
-
unit: PropTypes.string,
|
|
28
|
-
}),
|
|
29
|
-
),
|
|
30
|
-
}),
|
|
31
|
-
additionalAxesOptions: PropTypes.shape({
|
|
32
|
-
chartScaleType: PropTypes.oneOf(['linear', 'logarithmic']),
|
|
33
|
-
reverse: PropTypes.bool,
|
|
34
|
-
beginAtZero: PropTypes.bool,
|
|
35
|
-
stepSize: PropTypes.number,
|
|
36
|
-
stacked: PropTypes.bool,
|
|
37
|
-
suggestedMin: PropTypes.number,
|
|
38
|
-
suggestedMax: PropTypes.number,
|
|
39
|
-
min: PropTypes.number,
|
|
40
|
-
max: PropTypes.number,
|
|
41
|
-
}),
|
|
42
|
-
chartStyling: PropTypes.shape({
|
|
43
|
-
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
44
|
-
height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
45
|
-
maintainAspectRatio: PropTypes.bool,
|
|
46
|
-
staticChartHeight: PropTypes.bool,
|
|
47
|
-
performanceMode: PropTypes.bool,
|
|
48
|
-
}),
|
|
49
|
-
tooltip: PropTypes.shape({
|
|
50
|
-
tooltips: PropTypes.bool,
|
|
51
|
-
showLabelsInTooltips: PropTypes.bool,
|
|
52
|
-
}),
|
|
53
|
-
graph: PropTypes.shape({
|
|
54
|
-
showDataLabels: PropTypes.bool,
|
|
55
|
-
showMinorGridlines: PropTypes.bool,
|
|
56
|
-
}),
|
|
57
|
-
annotations: PropTypes.shape({
|
|
58
|
-
showAnnotations: PropTypes.bool,
|
|
59
|
-
controlAnnotation: PropTypes.bool,
|
|
60
|
-
annotationsData: PropTypes.arrayOf(
|
|
61
|
-
PropTypes.shape({
|
|
62
|
-
annotationAxis: PropTypes.oneOf(['x', 'y']),
|
|
63
|
-
label: PropTypes.string,
|
|
64
|
-
color: PropTypes.string,
|
|
65
|
-
value: PropTypes.number,
|
|
66
|
-
endValue: PropTypes.number,
|
|
67
|
-
}),
|
|
68
|
-
),
|
|
69
|
-
}),
|
|
70
|
-
legend: PropTypes.shape({
|
|
71
|
-
display: PropTypes.bool,
|
|
72
|
-
position: PropTypes.oneOf(['top', 'bottom', 'right']),
|
|
73
|
-
align: PropTypes.oneOf(['start', 'center', 'end']),
|
|
74
|
-
customLegend: PropTypes.shape({
|
|
75
|
-
customLegendPlugin: PropTypes.object,
|
|
76
|
-
customLegendContainerID: PropTypes.string,
|
|
77
|
-
}),
|
|
78
|
-
}),
|
|
79
|
-
chartOptions: PropTypes.shape({
|
|
80
|
-
enableZoom: PropTypes.bool,
|
|
81
|
-
enablePan: PropTypes.bool,
|
|
82
|
-
}),
|
|
83
|
-
interactions: PropTypes.shape({
|
|
84
|
-
onLegendClick: PropTypes.func,
|
|
85
|
-
onBarHover: PropTypes.func,
|
|
86
|
-
onBarUnhover: PropTypes.func,
|
|
87
|
-
}),
|
|
88
|
-
dragData: PropTypes.shape({
|
|
89
|
-
enableDragData: PropTypes.bool,
|
|
90
|
-
showTooltip: PropTypes.bool,
|
|
91
|
-
roundPoints: PropTypes.bool,
|
|
92
|
-
dragX: PropTypes.bool,
|
|
93
|
-
dragY: PropTypes.bool,
|
|
94
|
-
onDragStart: PropTypes.func,
|
|
95
|
-
onDrag: PropTypes.func,
|
|
96
|
-
onDragEnd: PropTypes.func,
|
|
97
|
-
}),
|
|
98
|
-
}),
|
|
99
|
-
}).isRequired,
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export const getDefaultProps = (props) => {
|
|
103
|
-
// Add missing nested objects
|
|
104
|
-
props.chart.options = props.chart.options || {};
|
|
105
|
-
props.chart.options.axes = props.chart.options.axes || {};
|
|
106
|
-
props.chart.options.additionalAxesOptions =
|
|
107
|
-
props.chart.options.additionalAxesOptions || {};
|
|
108
|
-
props.chart.options.chartStyling = props.chart.options.chartStyling || {};
|
|
109
|
-
props.chart.options.tooltip = props.chart.options.tooltip || {};
|
|
110
|
-
props.chart.options.graph = props.chart.options.graph || {};
|
|
111
|
-
props.chart.options.annotations = props.chart.options.annotations || {};
|
|
112
|
-
props.chart.options.legend = props.chart.options.legend || {};
|
|
113
|
-
props.chart.options.legend.customLegend = props.chart.options.legend
|
|
114
|
-
.customLegend || { customLegendPlugin: null, customLegendContainerID: '' };
|
|
115
|
-
props.chart.options.chartOptions = props.chart.options.chartOptions || {};
|
|
116
|
-
props.chart.options.interactions = props.chart.options.interactions || {};
|
|
117
|
-
props.chart.options.dragData = props.chart.options.dragData || {};
|
|
118
|
-
// Set defaults for missing properties
|
|
119
|
-
const chart = {
|
|
120
|
-
testId: props.chart.testId ?? null,
|
|
121
|
-
data: props.chart.data,
|
|
122
|
-
options: {
|
|
123
|
-
title: props.chart.options.title || '',
|
|
124
|
-
direction: props.chart.options.direction || 'vertical',
|
|
125
|
-
axes: {
|
|
126
|
-
x: props.chart.options.axes.x || [{}],
|
|
127
|
-
y: props.chart.options.axes.y || [{}],
|
|
128
|
-
},
|
|
129
|
-
additionalAxesOptions: {
|
|
130
|
-
chartScaleType:
|
|
131
|
-
props.chart.options.additionalAxesOptions.chartScaleType || 'linear',
|
|
132
|
-
reverse: props.chart.options.additionalAxesOptions.reverse || false,
|
|
133
|
-
stacked: props.chart.options.additionalAxesOptions.stacked || false,
|
|
134
|
-
beginAtZero:
|
|
135
|
-
props.chart.options.additionalAxesOptions.beginAtZero != null
|
|
136
|
-
? props.chart.options.additionalAxesOptions.beginAtZero
|
|
137
|
-
: true,
|
|
138
|
-
stepSize: props.chart.options.additionalAxesOptions.stepSize,
|
|
139
|
-
suggestedMin: props.chart.options.additionalAxesOptions.suggestedMin,
|
|
140
|
-
suggestedMax: props.chart.options.additionalAxesOptions.suggestedMax,
|
|
141
|
-
min: props.chart.options.additionalAxesOptions.min,
|
|
142
|
-
max: props.chart.options.additionalAxesOptions.max,
|
|
143
|
-
},
|
|
144
|
-
chartStyling: {
|
|
145
|
-
width: props.chart.options.chartStyling.width,
|
|
146
|
-
height: props.chart.options.chartStyling.height,
|
|
147
|
-
maintainAspectRatio:
|
|
148
|
-
props.chart.options.chartStyling.maintainAspectRatio || false,
|
|
149
|
-
staticChartHeight:
|
|
150
|
-
props.chart.options.chartStyling.staticChartHeight || false,
|
|
151
|
-
performanceMode:
|
|
152
|
-
props.chart.options.chartStyling.performanceMode != null
|
|
153
|
-
? props.chart.options.chartStyling.performanceMode
|
|
154
|
-
: true,
|
|
155
|
-
},
|
|
156
|
-
tooltip: {
|
|
157
|
-
tooltips:
|
|
158
|
-
props.chart.options.tooltip.tooltips != null
|
|
159
|
-
? props.chart.options.tooltip.tooltips
|
|
160
|
-
: true,
|
|
161
|
-
showLabelsInTooltips:
|
|
162
|
-
props.chart.options.tooltip.showLabelsInTooltips || false,
|
|
163
|
-
},
|
|
164
|
-
graph: {
|
|
165
|
-
showDataLabels: props.chart.options.graph.showDataLabels || false,
|
|
166
|
-
showMinorGridlines:
|
|
167
|
-
props.chart.options.graph.showMinorGridlines || false,
|
|
168
|
-
},
|
|
169
|
-
annotations: {
|
|
170
|
-
showAnnotations:
|
|
171
|
-
props.chart.options.annotations.showAnnotations != null
|
|
172
|
-
? props.chart.options.annotations.showAnnotations
|
|
173
|
-
: true,
|
|
174
|
-
controlAnnotation:
|
|
175
|
-
props.chart.options.annotations.controlAnnotation || false,
|
|
176
|
-
annotationsData: props.chart.options.annotations.annotationsData || [],
|
|
177
|
-
},
|
|
178
|
-
legend: {
|
|
179
|
-
display:
|
|
180
|
-
props.chart.options.legend.display != null
|
|
181
|
-
? props.chart.options.legend.display
|
|
182
|
-
: true,
|
|
183
|
-
position: props.chart.options.legend.position || 'bottom',
|
|
184
|
-
align: props.chart.options.legend.align || 'center',
|
|
185
|
-
customLegend: props.chart.options.legend.customLegend,
|
|
186
|
-
},
|
|
187
|
-
chartOptions: {
|
|
188
|
-
enableZoom: props.chart.options.chartOptions.enableZoom || false,
|
|
189
|
-
enablePan: props.chart.options.chartOptions.enablePan || false,
|
|
190
|
-
},
|
|
191
|
-
interactions: {
|
|
192
|
-
onLegendClick: props.chart.options.interactions.onLegendClick,
|
|
193
|
-
onBarHover: props.chart.options.interactions.onBarHover,
|
|
194
|
-
onBarUnhover: props.chart.options.interactions.onBarUnhover,
|
|
195
|
-
},
|
|
196
|
-
dragData: {
|
|
197
|
-
enableDragData: props.chart.options.dragData.enableDragData || false,
|
|
198
|
-
showTooltip: props.chart.options.dragData.showTooltip || true,
|
|
199
|
-
roundPoints: props.chart.options.dragData.roundPoints || true,
|
|
200
|
-
dragX: props.chart.options.dragData.dragX || true,
|
|
201
|
-
dragY: props.chart.options.dragData.dragY || true,
|
|
202
|
-
onDragStart: props.chart.options.dragData.onDragStart,
|
|
203
|
-
onDrag: props.chart.options.dragData.onDrag,
|
|
204
|
-
onDragEnd: props.chart.options.dragData.onDragEnd,
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
};
|
|
208
|
-
return chart;
|
|
209
|
-
};
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IChartAnnotations,
|
|
3
|
-
IChartDraggableData,
|
|
4
|
-
IChartInteractions,
|
|
5
|
-
IChartLegend,
|
|
6
|
-
IChartStyling
|
|
7
|
-
} from "../../helpers/chart-interface";
|
|
8
|
-
|
|
9
|
-
export interface IChartOptions {
|
|
10
|
-
enableZoom: boolean;
|
|
11
|
-
enablePan: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface IBarChartGraph {
|
|
15
|
-
showDataLabels: boolean;
|
|
16
|
-
showMinorGridlines: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface IBarChartTooltip {
|
|
20
|
-
tooltips: boolean;
|
|
21
|
-
showLabelsInTooltips: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface IBarChartAdditionalAxesOptions {
|
|
25
|
-
chartScaleType: 'linear' | 'logarithmic';
|
|
26
|
-
reverse: boolean;
|
|
27
|
-
beginAtZero: boolean;
|
|
28
|
-
stepSize: number;
|
|
29
|
-
stacked: boolean;
|
|
30
|
-
suggestedMin: number;
|
|
31
|
-
suggestedMax:number;
|
|
32
|
-
min: number;
|
|
33
|
-
max: number;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface IBarChartAxes<PositionType> {
|
|
37
|
-
label: string;
|
|
38
|
-
position: PositionType;
|
|
39
|
-
color: string;
|
|
40
|
-
unit: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface IBarChartOptions {
|
|
44
|
-
title: string | string[];
|
|
45
|
-
direction: 'vertical' | 'horizontal';
|
|
46
|
-
axes: {
|
|
47
|
-
x: IBarChartAxes<'top' | 'bottom'>[];
|
|
48
|
-
y: IBarChartAxes<'left' | 'right'>[];
|
|
49
|
-
};
|
|
50
|
-
additionalAxesOptions: IBarChartAdditionalAxesOptions;
|
|
51
|
-
chartStyling: IChartStyling;
|
|
52
|
-
tooltip: IBarChartTooltip;
|
|
53
|
-
graph: IBarChartGraph;
|
|
54
|
-
annotations: IChartAnnotations;
|
|
55
|
-
legend: IChartLegend;
|
|
56
|
-
chartOptions: IChartOptions;
|
|
57
|
-
interactions: IChartInteractions;
|
|
58
|
-
draggableData :IChartDraggableData;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface IBarDataPoint {
|
|
62
|
-
x: number;
|
|
63
|
-
y: number;
|
|
64
|
-
label?: string;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export interface IBarChartDataset {
|
|
68
|
-
label?: string;
|
|
69
|
-
data: number[] | number[][] | IBarDataPoint[];
|
|
70
|
-
borderSkipped?: string;
|
|
71
|
-
backgroundColor?: string[];
|
|
72
|
-
borderColor?: string[];
|
|
73
|
-
borderRadius?: number;
|
|
74
|
-
borderWidth?: number;
|
|
75
|
-
yAxisID?: string;
|
|
76
|
-
stack?: number;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface IBarChartData {
|
|
80
|
-
//TODO: revisit data interface definition after project is more stable
|
|
81
|
-
testId: string | null;
|
|
82
|
-
data: {
|
|
83
|
-
labels?: string[],
|
|
84
|
-
datasets: IBarChartDataset[]
|
|
85
|
-
} | any;
|
|
86
|
-
options: IBarChartOptions;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export interface IBarChartProps {
|
|
90
|
-
chart: IBarChartData;
|
|
91
|
-
}
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import React, { useRef, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
BarElement,
|
|
4
|
-
CategoryScale,
|
|
5
|
-
Chart as ChartJS,
|
|
6
|
-
Filler,
|
|
7
|
-
Legend,
|
|
8
|
-
LinearScale,
|
|
9
|
-
LogarithmicScale,
|
|
10
|
-
Title,
|
|
11
|
-
Tooltip,
|
|
12
|
-
} from 'chart.js';
|
|
13
|
-
import { Bar } from 'react-chartjs-2';
|
|
14
|
-
import zoomPlugin from 'chartjs-plugin-zoom';
|
|
15
|
-
import dataLabelsPlugin from 'chartjs-plugin-datalabels';
|
|
16
|
-
import annotationPlugin from 'chartjs-plugin-annotation';
|
|
17
|
-
import dragDataPlugin from 'chartjs-plugin-dragdata';
|
|
18
|
-
|
|
19
|
-
import styles from './bar-chart.module.less';
|
|
20
|
-
import { BarChartPropTypes, getDefaultProps } from './bar-chart-prop-types';
|
|
21
|
-
import getBarChartScales from './get-bar-chart-scales';
|
|
22
|
-
import getBarChartToolTips from './get-bar-chart-tooltips';
|
|
23
|
-
import getBarChartDataLabels from './get-bar-chart-data-labels';
|
|
24
|
-
import getAnnotation from '../../helpers/get-chart-annotation';
|
|
25
|
-
import {
|
|
26
|
-
getTitle,
|
|
27
|
-
isVertical,
|
|
28
|
-
setAnnotations,
|
|
29
|
-
generateRandomColor,
|
|
30
|
-
getClassName,
|
|
31
|
-
getPlugins,
|
|
32
|
-
getLegend,
|
|
33
|
-
setDefaultTheme,
|
|
34
|
-
} from '../../helpers/chart-utils';
|
|
35
|
-
import {
|
|
36
|
-
ALPHA_CHANEL,
|
|
37
|
-
ANIMATION_DURATION,
|
|
38
|
-
AUTO,
|
|
39
|
-
COLORS,
|
|
40
|
-
CUSTOM_LEGEND_PLUGIN_NAME,
|
|
41
|
-
BORDER_COLOR,
|
|
42
|
-
} from '../../helpers/chart-consts';
|
|
43
|
-
import {
|
|
44
|
-
AxisType,
|
|
45
|
-
ChartHoverMode,
|
|
46
|
-
ChartType,
|
|
47
|
-
PointStyle,
|
|
48
|
-
} from '../../helpers/enums';
|
|
49
|
-
import getDraggableData from '../../helpers/get-draggableData';
|
|
50
|
-
|
|
51
|
-
ChartJS.register(
|
|
52
|
-
LinearScale,
|
|
53
|
-
CategoryScale,
|
|
54
|
-
LogarithmicScale,
|
|
55
|
-
BarElement,
|
|
56
|
-
Legend,
|
|
57
|
-
Tooltip,
|
|
58
|
-
Title,
|
|
59
|
-
Filler,
|
|
60
|
-
zoomPlugin,
|
|
61
|
-
dataLabelsPlugin,
|
|
62
|
-
annotationPlugin,
|
|
63
|
-
dragDataPlugin,
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* this is a bar chart component
|
|
68
|
-
* @param {import('./bar-chart.interface').IBarChartProps} props
|
|
69
|
-
*/
|
|
70
|
-
const BarChart = (props) => {
|
|
71
|
-
setDefaultTheme();
|
|
72
|
-
const chartRef = useRef(null);
|
|
73
|
-
const [pointHover, setPointHover] = useState(false);
|
|
74
|
-
const chart = getDefaultProps(props);
|
|
75
|
-
const { options, testId } = chart;
|
|
76
|
-
const { annotations, chartStyling, interactions, graph } = chart.options;
|
|
77
|
-
|
|
78
|
-
const [visibleAnnotationsIndices, setVisibleAnnotationsIndices] = useState(
|
|
79
|
-
setAnnotations(annotations.annotationsData),
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
const generateBarChartDatasets = (datasets) => {
|
|
83
|
-
const barDatasetsCopy = [...datasets];
|
|
84
|
-
|
|
85
|
-
// Add annotations to dataset to have them appear in legend.
|
|
86
|
-
if (
|
|
87
|
-
annotations.controlAnnotation &&
|
|
88
|
-
annotations.showAnnotations &&
|
|
89
|
-
annotations.annotationsData?.length
|
|
90
|
-
) {
|
|
91
|
-
annotations.annotationsData.forEach((annotation, index) => {
|
|
92
|
-
barDatasetsCopy.push({
|
|
93
|
-
isAnnotation: true,
|
|
94
|
-
label: annotation.label,
|
|
95
|
-
annotationIndex: index,
|
|
96
|
-
backgroundColor: annotation.color || COLORS[index],
|
|
97
|
-
borderColor: annotation.color || COLORS[index],
|
|
98
|
-
data: [],
|
|
99
|
-
type: ChartType.Bar,
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const generatedDatasets = barDatasetsCopy.map((barDataset, index) => {
|
|
105
|
-
const colorSchema = COLORS;
|
|
106
|
-
const colors = barDataset.data.map((_, i) => {
|
|
107
|
-
const colorSelectionIndex = datasets.length > 1 ? index : i;
|
|
108
|
-
return colorSchema[colorSelectionIndex] || generateRandomColor(COLORS);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const backgroundColors =
|
|
112
|
-
barDataset.backgroundColor ||
|
|
113
|
-
colors.map((color) => color + ALPHA_CHANEL);
|
|
114
|
-
|
|
115
|
-
return {
|
|
116
|
-
...barDataset,
|
|
117
|
-
borderWidth: parseFloat(barDataset.borderWidth) || '1',
|
|
118
|
-
borderColor: barDataset.borderColor || colors,
|
|
119
|
-
backgroundColor: backgroundColors,
|
|
120
|
-
};
|
|
121
|
-
});
|
|
122
|
-
return generatedDatasets;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const generatedDatasets = generateBarChartDatasets(chart.data.datasets);
|
|
126
|
-
|
|
127
|
-
const legendClick = (e, legendItem) => {
|
|
128
|
-
const index = legendItem.datasetIndex;
|
|
129
|
-
const chartInstance = chartRef.current;
|
|
130
|
-
const { datasets } = chartInstance.data;
|
|
131
|
-
const dataset = datasets[index];
|
|
132
|
-
const meta = chartInstance.getDatasetMeta(index);
|
|
133
|
-
meta.hidden = meta.hidden === null ? !dataset.hidden : null;
|
|
134
|
-
|
|
135
|
-
if (annotations.controlAnnotation && dataset.isAnnotation) {
|
|
136
|
-
const { annotationIndex } = dataset;
|
|
137
|
-
if (visibleAnnotationsIndices.includes(annotationIndex)) {
|
|
138
|
-
setVisibleAnnotationsIndices(
|
|
139
|
-
visibleAnnotationsIndices.filter((ann) => ann !== annotationIndex),
|
|
140
|
-
);
|
|
141
|
-
} else {
|
|
142
|
-
setVisibleAnnotationsIndices([
|
|
143
|
-
...visibleAnnotationsIndices,
|
|
144
|
-
annotationIndex,
|
|
145
|
-
]);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Show/hide entire display group
|
|
150
|
-
if (dataset.displayGroup) {
|
|
151
|
-
datasets.forEach((ds, ix) => {
|
|
152
|
-
if (ds.displayGroup !== dataset.displayGroup) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
chartInstance.getDatasetMeta(ix).hidden = meta.hidden;
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (interactions.onLegendClick) {
|
|
160
|
-
interactions.onLegendClick(legendItem?.text, legendItem.hidden);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
chartInstance.update();
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
const onClick = (evt, elements, chartInstance) => {
|
|
167
|
-
chartInstance.resetZoom();
|
|
168
|
-
// TODO: Restore redux-logic for zoom
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
const onHover = (evt, hoveredItems, chartInstance) => {
|
|
172
|
-
if (pointHover && !hoveredItems?.length) {
|
|
173
|
-
setPointHover(false);
|
|
174
|
-
if (interactions.onBarUnhover) {
|
|
175
|
-
interactions.onBarUnhover(evt);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
if (!pointHover && hoveredItems?.length) {
|
|
179
|
-
setPointHover(true);
|
|
180
|
-
if (interactions.onBarHover) {
|
|
181
|
-
const { index, datasetIndex } = hoveredItems[0];
|
|
182
|
-
const generatedDataset = generatedDatasets;
|
|
183
|
-
interactions.onBarHover(evt, datasetIndex, index, generatedDataset);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
return (
|
|
189
|
-
<div
|
|
190
|
-
className={getClassName(chartStyling, styles)}
|
|
191
|
-
style={{
|
|
192
|
-
width: chartStyling.width || AUTO,
|
|
193
|
-
height: chartStyling.height || AUTO,
|
|
194
|
-
}}
|
|
195
|
-
data-testid={testId}
|
|
196
|
-
>
|
|
197
|
-
<Bar
|
|
198
|
-
ref={chartRef}
|
|
199
|
-
data={{
|
|
200
|
-
labels: chart.data.labels.length ? chart.data.labels : [''],
|
|
201
|
-
datasets: generatedDatasets,
|
|
202
|
-
}}
|
|
203
|
-
options={{
|
|
204
|
-
onClick,
|
|
205
|
-
onHover,
|
|
206
|
-
indexAxis: isVertical(options.direction) ? AxisType.X : AxisType.Y,
|
|
207
|
-
maintainAspectRatio: chartStyling.maintainAspectRatio,
|
|
208
|
-
animation: chartStyling.performanceMode
|
|
209
|
-
? false
|
|
210
|
-
: {
|
|
211
|
-
duration: ANIMATION_DURATION.FAST,
|
|
212
|
-
},
|
|
213
|
-
hover: {
|
|
214
|
-
mode: ChartHoverMode.Nearest,
|
|
215
|
-
intersect: true,
|
|
216
|
-
},
|
|
217
|
-
elements: {
|
|
218
|
-
bar: { pointStyle: PointStyle.Circle },
|
|
219
|
-
},
|
|
220
|
-
scales: getBarChartScales(chart),
|
|
221
|
-
plugins: {
|
|
222
|
-
title: getTitle(options),
|
|
223
|
-
datalabels: getBarChartDataLabels(options),
|
|
224
|
-
annotation: getAnnotation(options, {
|
|
225
|
-
showAnnotationLineIndex: visibleAnnotationsIndices,
|
|
226
|
-
}),
|
|
227
|
-
tooltip: getBarChartToolTips(options),
|
|
228
|
-
legend: getLegend(options, legendClick),
|
|
229
|
-
[CUSTOM_LEGEND_PLUGIN_NAME]: options.legend.customLegend
|
|
230
|
-
.customLegendPlugin && {
|
|
231
|
-
containerID: options.legend.customLegend.customLegendContainerID,
|
|
232
|
-
},
|
|
233
|
-
chartAreaBorder: {
|
|
234
|
-
borderColor: BORDER_COLOR,
|
|
235
|
-
},
|
|
236
|
-
dragData: getDraggableData(options),
|
|
237
|
-
},
|
|
238
|
-
}}
|
|
239
|
-
plugins={getPlugins(graph, options.legend)}
|
|
240
|
-
/>
|
|
241
|
-
</div>
|
|
242
|
-
);
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
BarChart.propTypes = BarChartPropTypes;
|
|
246
|
-
|
|
247
|
-
export { BarChart };
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
html[data-theme='dark'] .chart canvas {
|
|
2
|
-
// Flip chart colors if dark mode enabled
|
|
3
|
-
filter: invert(1) hue-rotate(180deg);
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
.chart {
|
|
7
|
-
border: 1px solid rgba(255, 255, 255, 0);
|
|
8
|
-
padding-top: 10px;
|
|
9
|
-
position: relative;
|
|
10
|
-
|
|
11
|
-
canvas {
|
|
12
|
-
width: 100% !important; // Fix for resizing bug
|
|
13
|
-
height: 100% !important; // Remove if stretched when maintainAspectRatio=true
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
&.fixedHeight {
|
|
17
|
-
display: flex;
|
|
18
|
-
align-items: flex-start;
|
|
19
|
-
justify-content: flex-start;
|
|
20
|
-
height: auto;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
&.stretchHeight {
|
|
24
|
-
display: flex;
|
|
25
|
-
align-items: stretch;
|
|
26
|
-
justify-content: stretch;
|
|
27
|
-
height: 100%;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
&:focus {
|
|
31
|
-
border: 1px solid #85b7d9;
|
|
32
|
-
outline: none; // Remove dotted outline on FF
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
&::-moz-focus-inner {
|
|
36
|
-
border: 0; // Remove dotted outline on FF
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.zoomForm {
|
|
41
|
-
position: absolute;
|
|
42
|
-
display: flex;
|
|
43
|
-
align-items: center;
|
|
44
|
-
justify-content: center;
|
|
45
|
-
top: 0;
|
|
46
|
-
right: 0;
|
|
47
|
-
|
|
48
|
-
.zoomReset {
|
|
49
|
-
margin-left: 10px;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
.help {
|
|
53
|
-
margin-left: 5px;
|
|
54
|
-
line-height: 0; // Strip whitespace from icon
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
.autoWeight {
|
|
59
|
-
width: auto;
|
|
60
|
-
height: auto;
|
|
61
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { AlignOptions } from '../../helpers/enums';
|
|
2
|
-
import { AUTO } from '../../helpers/chart-consts';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @param {import('./bar-chart.interface').IBarChartOptions} options - bar chart options object
|
|
6
|
-
*/
|
|
7
|
-
const getBarChartDataLabels = (options) => {
|
|
8
|
-
const { beginAtZero, reverse } = options.additionalAxesOptions;
|
|
9
|
-
|
|
10
|
-
const formatterCallback = (value, context) => {
|
|
11
|
-
const { dataset, dataIndex } = context;
|
|
12
|
-
const dataElement = dataset.data[dataIndex];
|
|
13
|
-
|
|
14
|
-
let dataLabel = '';
|
|
15
|
-
if (typeof dataElement === 'number') {
|
|
16
|
-
dataLabel = Number.isInteger(dataElement)
|
|
17
|
-
? dataElement
|
|
18
|
-
: dataElement.toFixed(2);
|
|
19
|
-
}
|
|
20
|
-
if (Array.isArray(dataElement)) {
|
|
21
|
-
dataLabel = dataElement.reduce((acc, curr, i) => {
|
|
22
|
-
return i === 0 ? `${acc} ${curr}` : `${acc}, ${curr}`;
|
|
23
|
-
}, '');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return dataLabel;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const beginAtNotZeroAlign = reverse ? AlignOptions.End : AlignOptions.Start;
|
|
30
|
-
const beginAtNotZeroAnchor = reverse ? AlignOptions.Start : AlignOptions.End;
|
|
31
|
-
|
|
32
|
-
return options.graph.showDataLabels
|
|
33
|
-
? {
|
|
34
|
-
display: AUTO,
|
|
35
|
-
align: beginAtZero ? AlignOptions.Center : beginAtNotZeroAlign,
|
|
36
|
-
anchor: beginAtZero ? AlignOptions.Center : beginAtNotZeroAnchor,
|
|
37
|
-
formatter: formatterCallback,
|
|
38
|
-
}
|
|
39
|
-
: { display: false };
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export default getBarChartDataLabels;
|