@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,119 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { BarChart } from './bar-chart';
|
|
3
|
+
import { Container } from '../../helpers/container';
|
|
4
|
+
|
|
5
|
+
const style = {
|
|
6
|
+
height: '1000px',
|
|
7
|
+
width: '1000px',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const chart = {
|
|
11
|
+
data: {
|
|
12
|
+
labels: ['monday', 'tuesday', 'wednesday', 'friday'],
|
|
13
|
+
datasets: [
|
|
14
|
+
{
|
|
15
|
+
label: 'some data',
|
|
16
|
+
borderColor: ['red', 'purple', 'black', 'rgba(255,255,64,0.3)'],
|
|
17
|
+
backgroundColor: [
|
|
18
|
+
'white',
|
|
19
|
+
'transparent',
|
|
20
|
+
'red',
|
|
21
|
+
'rgba(255,255,64,0.9)',
|
|
22
|
+
],
|
|
23
|
+
borderWidth: 4,
|
|
24
|
+
borderRadius: 50,
|
|
25
|
+
borderSkipped: false,
|
|
26
|
+
data: [[20, 40], 30, [-10, 11], 42],
|
|
27
|
+
stack: 1,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
label: 'some other data',
|
|
31
|
+
borderColor: ['purple', 'orange'],
|
|
32
|
+
backgroundColor: ['orange', 'purple'],
|
|
33
|
+
borderWidth: 10,
|
|
34
|
+
borderSkipped: false,
|
|
35
|
+
data: [1, 8, 22, 19],
|
|
36
|
+
stack: 1,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
label: 'some otter data',
|
|
40
|
+
yAxisID: 'y2',
|
|
41
|
+
data: [10, 20, 22, 19],
|
|
42
|
+
stack: 2,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
options: {
|
|
47
|
+
title: 'Look at those bars!',
|
|
48
|
+
axes: {
|
|
49
|
+
x: [
|
|
50
|
+
{
|
|
51
|
+
label: 'x data',
|
|
52
|
+
gridLines: {
|
|
53
|
+
drawOnChartArea: false,
|
|
54
|
+
},
|
|
55
|
+
unit: 'day',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
y: [
|
|
59
|
+
{
|
|
60
|
+
label: 'y data',
|
|
61
|
+
position: 'right',
|
|
62
|
+
color: '#a30125',
|
|
63
|
+
unit: 'm',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
position: 'left',
|
|
67
|
+
color: '#011fa3',
|
|
68
|
+
gridLines: {
|
|
69
|
+
drawOnChartArea: false,
|
|
70
|
+
},
|
|
71
|
+
unit: 'otters',
|
|
72
|
+
stepSize: 1,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
additionalAxesOptions: {
|
|
77
|
+
beginAtZero: true,
|
|
78
|
+
stacked: true,
|
|
79
|
+
reverse: true,
|
|
80
|
+
suggestedMin: -15,
|
|
81
|
+
},
|
|
82
|
+
chartStyling: {
|
|
83
|
+
width: 1200,
|
|
84
|
+
height: 800,
|
|
85
|
+
performanceMode: false,
|
|
86
|
+
},
|
|
87
|
+
graph: {
|
|
88
|
+
showDataLabels: true,
|
|
89
|
+
showMinorGridlines: true,
|
|
90
|
+
},
|
|
91
|
+
annotations: {
|
|
92
|
+
showAnnotations: true,
|
|
93
|
+
controlAnnotation: true,
|
|
94
|
+
annotationsData: [
|
|
95
|
+
{
|
|
96
|
+
annotationAxis: 'y',
|
|
97
|
+
label: '0',
|
|
98
|
+
value: 0,
|
|
99
|
+
color: 'rgba(128, 32, 196, 0.5)',
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
legend: {
|
|
104
|
+
position: 'top',
|
|
105
|
+
align: 'start',
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export const BarChartKitchenSink = () => (
|
|
111
|
+
<Container style={style}>
|
|
112
|
+
<BarChart chart={chart} />
|
|
113
|
+
</Container>
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
export default {
|
|
117
|
+
title: 'Bar Chart Kitchen Sink',
|
|
118
|
+
component: BarChartKitchenSink,
|
|
119
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { AlignOptions } from '../../helpers/enums';
|
|
2
|
+
import { AUTO, DEFAULT_DARK_MODE_COLOR } 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
|
+
color: options.chartStyling.darkMode
|
|
39
|
+
? DEFAULT_DARK_MODE_COLOR
|
|
40
|
+
: undefined,
|
|
41
|
+
}
|
|
42
|
+
: { display: false };
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default getBarChartDataLabels;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { AxisType, ScaleType } from '../../helpers/enums';
|
|
2
|
+
import {
|
|
3
|
+
getAxisPosition,
|
|
4
|
+
isVertical,
|
|
5
|
+
generateRandomColor,
|
|
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';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {import('./bar-chart.interface').IBarChartData} chart - chart data
|
|
18
|
+
* @param {'x'|'y'} axisType
|
|
19
|
+
* @param {import('./bar-chart.interface').IBarChartAxes} [currentScales]
|
|
20
|
+
*/
|
|
21
|
+
const getBarChartAxis = (chart, axisType, currentScales) => {
|
|
22
|
+
const isDirectionVertical = isVertical(chart.options.direction);
|
|
23
|
+
|
|
24
|
+
const axisData = currentScales || chart.options.axes[axisType][0];
|
|
25
|
+
const isDirectionCompatibleWithAxisType =
|
|
26
|
+
(isDirectionVertical && axisType === AxisType.Y) ||
|
|
27
|
+
(!isDirectionVertical && axisType === AxisType.X);
|
|
28
|
+
|
|
29
|
+
const grid = axisData?.gridLines || {};
|
|
30
|
+
|
|
31
|
+
const getScaleType = () => {
|
|
32
|
+
const scaleType = chart.data.labels ? ScaleType.Category : ScaleType.Linear;
|
|
33
|
+
const axisWithScale = isDirectionVertical ? AxisType.X : AxisType.Y;
|
|
34
|
+
return axisType === axisWithScale
|
|
35
|
+
? scaleType
|
|
36
|
+
: chart.options.additionalAxesOptions.chartScaleType;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const getReverse = () => {
|
|
40
|
+
const axisWithReverse = isDirectionVertical ? AxisType.Y : AxisType.X;
|
|
41
|
+
return axisType === axisWithReverse
|
|
42
|
+
? chart.options.additionalAxesOptions.reverse
|
|
43
|
+
: false;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const getTicks = () => {
|
|
47
|
+
const areLogarithmicTicks =
|
|
48
|
+
isDirectionCompatibleWithAxisType &&
|
|
49
|
+
chart.options.additionalAxesOptions.chartScaleType ===
|
|
50
|
+
ScaleType.Logarithmic;
|
|
51
|
+
|
|
52
|
+
if (areLogarithmicTicks) {
|
|
53
|
+
return {
|
|
54
|
+
callback: (tick) => {
|
|
55
|
+
return LOGARITHMIC_STEPS.includes(tick) ? tick.toLocaleString() : '';
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
} else {
|
|
59
|
+
return {
|
|
60
|
+
color:
|
|
61
|
+
axisData.color ||
|
|
62
|
+
(chart.options.chartStyling.darkMode
|
|
63
|
+
? DEFAULT_DARK_MODE_COLOR
|
|
64
|
+
: DEFAULT_COLOR),
|
|
65
|
+
stepSize:
|
|
66
|
+
axisData.stepSize || chart.options.additionalAxesOptions.stepSize,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
type: getScaleType(),
|
|
73
|
+
position: axisData.position,
|
|
74
|
+
beginAtZero: chart.options.additionalAxesOptions.beginAtZero,
|
|
75
|
+
reverse: getReverse(),
|
|
76
|
+
suggestedMax: chart.options?.additionalAxesOptions?.suggestedMax,
|
|
77
|
+
suggestedMin: chart.options?.additionalAxesOptions?.suggestedMin,
|
|
78
|
+
min: isDirectionCompatibleWithAxisType
|
|
79
|
+
? chart.options?.additionalAxesOptions?.min
|
|
80
|
+
: undefined,
|
|
81
|
+
max: isDirectionCompatibleWithAxisType
|
|
82
|
+
? chart.options?.additionalAxesOptions?.max
|
|
83
|
+
: undefined,
|
|
84
|
+
title: {
|
|
85
|
+
display: axisData.label?.length || axisData.unit?.length,
|
|
86
|
+
text: axisData.label || axisData.unit,
|
|
87
|
+
padding: 0,
|
|
88
|
+
color: chart.options.chartStyling.darkMode
|
|
89
|
+
? DEFAULT_DARK_MODE_COLOR
|
|
90
|
+
: undefined,
|
|
91
|
+
},
|
|
92
|
+
ticks: getTicks(),
|
|
93
|
+
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
|
+
...grid,
|
|
101
|
+
},
|
|
102
|
+
stacked: chart.options.additionalAxesOptions.stacked,
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @param {import('./bar-chart.interface').IBarChartData} chart - chart data
|
|
108
|
+
* @param {'x'|'y'} axisType
|
|
109
|
+
*/
|
|
110
|
+
const getBarChartAxes = (chart, axisType) => {
|
|
111
|
+
const axesData = chart.options.axes[axisType];
|
|
112
|
+
const axes = axesData.reduce((acc, curr, i) => {
|
|
113
|
+
const axisData = curr;
|
|
114
|
+
const color =
|
|
115
|
+
curr.color ||
|
|
116
|
+
(chart.options.chartStyling.darkMode ? DARK_MODE_COLORS[i] : COLORS[i]) ||
|
|
117
|
+
generateRandomColor(COLORS);
|
|
118
|
+
axisData.color = color;
|
|
119
|
+
axisData.position = curr.position || getAxisPosition(axisType, i);
|
|
120
|
+
|
|
121
|
+
const axis = getBarChartAxis(chart, axisType, axisData);
|
|
122
|
+
return { ...acc, [axisType + (i + 1)]: axis };
|
|
123
|
+
}, {});
|
|
124
|
+
return axes;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @param {import('./bar-chart.interface').IBarChartData} chart - chart data
|
|
129
|
+
*/
|
|
130
|
+
const getBarChartScales = (chart) => {
|
|
131
|
+
const hasMultipleXAxes = chart.options.axes.x?.length > 1;
|
|
132
|
+
const hasMultipleYAxes = chart.options.axes.y?.length > 1;
|
|
133
|
+
|
|
134
|
+
const xAxesScales = hasMultipleXAxes
|
|
135
|
+
? getBarChartAxes(chart, AxisType.X)
|
|
136
|
+
: { x: getBarChartAxis(chart, AxisType.X) };
|
|
137
|
+
const yAxesScales = hasMultipleYAxes
|
|
138
|
+
? getBarChartAxes(chart, AxisType.Y)
|
|
139
|
+
: { y: getBarChartAxis(chart, AxisType.Y) };
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
...xAxesScales,
|
|
143
|
+
...yAxesScales,
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export default getBarChartScales;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {
|
|
2
|
+
afterLabelCallback,
|
|
3
|
+
getTooltipLabel,
|
|
4
|
+
isVertical,
|
|
5
|
+
} from '../../helpers/chart-utils';
|
|
6
|
+
import { ChartHoverMode, TooltipLabel } from '../../helpers/enums';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {import('./bar-chart.interface').IBarChartOptions} options - bar chart options object
|
|
10
|
+
*/
|
|
11
|
+
const getBarChartToolTips = (options) => {
|
|
12
|
+
const getTooltipLabels = (dataset) => {
|
|
13
|
+
const isDirectionVertical = isVertical(options.direction);
|
|
14
|
+
const { x, y } = options.axes;
|
|
15
|
+
|
|
16
|
+
const xIndex = dataset.xAxisID?.length > 1 ? dataset.xAxisID[1] - 1 : 0;
|
|
17
|
+
const yIndex = dataset.yAxisID?.length > 1 ? dataset.yAxisID[1] - 1 : 0;
|
|
18
|
+
const xAxis = isDirectionVertical ? x[xIndex] : y[yIndex];
|
|
19
|
+
const yAxis = isDirectionVertical ? y[yIndex] : x[xIndex];
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
titleAxisLabel: xAxis?.label || '',
|
|
23
|
+
valueAxisLabel: yAxis?.label || '',
|
|
24
|
+
titleLabel: TooltipLabel.X,
|
|
25
|
+
valueLabel: TooltipLabel.Y,
|
|
26
|
+
titleUnit: xAxis?.unit || '',
|
|
27
|
+
valueUnit: yAxis?.unit || '',
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const titleCallback = (tooltipItem, data) => {
|
|
32
|
+
const barLabel = tooltipItem[0]?.label || '';
|
|
33
|
+
const labels = getTooltipLabels(tooltipItem[0].dataset);
|
|
34
|
+
const { titleAxisLabel, titleUnit } = labels;
|
|
35
|
+
const axisLabel =
|
|
36
|
+
!titleAxisLabel && !titleUnit ? '' : `${titleAxisLabel || titleUnit}: `;
|
|
37
|
+
return axisLabel + barLabel;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const labelCallback = (tooltipItem) => {
|
|
41
|
+
const { showLabelsInTooltips } = options.tooltip;
|
|
42
|
+
let label = tooltipItem.dataset?.label || '';
|
|
43
|
+
|
|
44
|
+
const labels = getTooltipLabels(tooltipItem.dataset);
|
|
45
|
+
const { valueUnit, valueAxisLabel } = labels;
|
|
46
|
+
|
|
47
|
+
const getTooltipItemValue = () => {
|
|
48
|
+
const { formattedValue } = tooltipItem;
|
|
49
|
+
const labelNumber = Number(formattedValue);
|
|
50
|
+
|
|
51
|
+
let labelNumberFormatted;
|
|
52
|
+
if (Math.abs(labelNumber) < 1) {
|
|
53
|
+
labelNumberFormatted = labelNumber.toPrecision(3);
|
|
54
|
+
} else {
|
|
55
|
+
labelNumberFormatted = Number.isInteger(labelNumber)
|
|
56
|
+
? labelNumber
|
|
57
|
+
: labelNumber.toFixed(3);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let tooltipItemValue = '';
|
|
61
|
+
if (typeof tooltipItem.raw === 'number') {
|
|
62
|
+
tooltipItemValue = labelNumberFormatted;
|
|
63
|
+
}
|
|
64
|
+
if (Array.isArray(tooltipItem.raw)) {
|
|
65
|
+
tooltipItemValue = tooltipItem.raw.reduce((acc, curr, i) => {
|
|
66
|
+
return i === 0 ? `${acc} ${curr}` : `${acc}, ${curr}`;
|
|
67
|
+
}, '');
|
|
68
|
+
}
|
|
69
|
+
if (typeof tooltipItem.raw === 'object') {
|
|
70
|
+
tooltipItemValue = formattedValue;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return tooltipItemValue;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const hideValueAxisLabel =
|
|
77
|
+
label === valueAxisLabel || valueAxisLabel.includes(label);
|
|
78
|
+
|
|
79
|
+
const tooltipItemValue = getTooltipItemValue();
|
|
80
|
+
const unit = valueUnit ? `[${valueUnit}] ` : '';
|
|
81
|
+
const valAxisLabel = hideValueAxisLabel ? '' : valueAxisLabel;
|
|
82
|
+
const tooltipLabel = getTooltipLabel(tooltipItem, showLabelsInTooltips);
|
|
83
|
+
|
|
84
|
+
return `${label}: ${tooltipItemValue} ${unit}${valAxisLabel}${tooltipLabel}`;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
enabled: options.tooltip.tooltips,
|
|
89
|
+
mode: ChartHoverMode.Nearest,
|
|
90
|
+
intersect: true,
|
|
91
|
+
padding: 8,
|
|
92
|
+
callbacks: {
|
|
93
|
+
title: titleCallback,
|
|
94
|
+
label: labelCallback,
|
|
95
|
+
afterLabel: afterLabelCallback,
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export default getBarChartToolTips;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FaCog } from 'react-icons/fa';
|
|
3
|
+
import { Popover, Button } from '@oliasoft-open-source/react-ui-library';
|
|
4
|
+
import { Layer } from './Layer';
|
|
5
|
+
|
|
6
|
+
export const Controls = ({
|
|
7
|
+
zoomEnabled,
|
|
8
|
+
onToggleZoom,
|
|
9
|
+
panEnabled,
|
|
10
|
+
onTogglePan,
|
|
11
|
+
legendEnabled,
|
|
12
|
+
onToggleLegend,
|
|
13
|
+
onResetAxes,
|
|
14
|
+
pointsEnabled,
|
|
15
|
+
onTogglePoints,
|
|
16
|
+
lineEnabled,
|
|
17
|
+
onToggleLine,
|
|
18
|
+
axes,
|
|
19
|
+
onSetAxisValue,
|
|
20
|
+
onDownload,
|
|
21
|
+
closeOnOutsideClick,
|
|
22
|
+
}) => {
|
|
23
|
+
return (
|
|
24
|
+
<Popover
|
|
25
|
+
placement="bottom-start"
|
|
26
|
+
closeOnOutsideClick={closeOnOutsideClick}
|
|
27
|
+
showCloseButton
|
|
28
|
+
overflowContainer
|
|
29
|
+
content={
|
|
30
|
+
<Layer
|
|
31
|
+
zoomEnabled={zoomEnabled}
|
|
32
|
+
onToggleZoom={onToggleZoom}
|
|
33
|
+
panEnabled={panEnabled}
|
|
34
|
+
onTogglePan={onTogglePan}
|
|
35
|
+
onResetAxes={onResetAxes}
|
|
36
|
+
legendEnabled={legendEnabled}
|
|
37
|
+
onToggleLegend={onToggleLegend}
|
|
38
|
+
pointsEnabled={pointsEnabled}
|
|
39
|
+
onTogglePoints={onTogglePoints}
|
|
40
|
+
lineEnabled={lineEnabled}
|
|
41
|
+
onToggleLine={onToggleLine}
|
|
42
|
+
axes={axes}
|
|
43
|
+
onSetAxisValue={onSetAxisValue}
|
|
44
|
+
onDownload={onDownload}
|
|
45
|
+
/>
|
|
46
|
+
}
|
|
47
|
+
>
|
|
48
|
+
<Button
|
|
49
|
+
name="example"
|
|
50
|
+
colored="muted"
|
|
51
|
+
onClick={() => {}}
|
|
52
|
+
basic
|
|
53
|
+
round
|
|
54
|
+
small
|
|
55
|
+
icon={<FaCog />}
|
|
56
|
+
/>
|
|
57
|
+
</Popover>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
.layer {
|
|
2
|
+
width: 200px;
|
|
3
|
+
}
|
|
4
|
+
.help {
|
|
5
|
+
font-size: 0.8rem;
|
|
6
|
+
color: #666;
|
|
7
|
+
|
|
8
|
+
p {
|
|
9
|
+
margin-bottom: 5px;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.reset {
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
span {
|
|
17
|
+
margin-left: 5px;
|
|
18
|
+
font-size: 10px;
|
|
19
|
+
color: #666;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
//import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { HiOutlineDocumentDownload } from 'react-icons/hi';
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
Toggle,
|
|
7
|
+
Spacer,
|
|
8
|
+
Field,
|
|
9
|
+
Input,
|
|
10
|
+
InputGroup,
|
|
11
|
+
InputGroupAddon,
|
|
12
|
+
Text,
|
|
13
|
+
} from '@oliasoft-open-source/react-ui-library';
|
|
14
|
+
//import translations from '~common/Internationalisation/translation-map.json';
|
|
15
|
+
//import { InputWarningType } from '~common/const/warning-messages';
|
|
16
|
+
import styles from './Controls.module.less';
|
|
17
|
+
|
|
18
|
+
export const Layer = ({
|
|
19
|
+
zoomEnabled,
|
|
20
|
+
onToggleZoom,
|
|
21
|
+
panEnabled,
|
|
22
|
+
onTogglePan,
|
|
23
|
+
onResetAxes,
|
|
24
|
+
legendEnabled,
|
|
25
|
+
onToggleLegend,
|
|
26
|
+
pointsEnabled,
|
|
27
|
+
onTogglePoints,
|
|
28
|
+
lineEnabled,
|
|
29
|
+
onToggleLine,
|
|
30
|
+
axes,
|
|
31
|
+
onSetAxisValue,
|
|
32
|
+
onDownload,
|
|
33
|
+
}) => {
|
|
34
|
+
// TODO: implement usetranslation
|
|
35
|
+
//const { t } = useTranslation();
|
|
36
|
+
return (
|
|
37
|
+
<div className={styles.layer}>
|
|
38
|
+
<Toggle
|
|
39
|
+
small
|
|
40
|
+
name="enablePoints"
|
|
41
|
+
label="Enable Points" //{t(translations.showPoints)} temporary static value before translation is implemented
|
|
42
|
+
checked={pointsEnabled}
|
|
43
|
+
onChange={onTogglePoints}
|
|
44
|
+
/>
|
|
45
|
+
<Spacer height={8} />
|
|
46
|
+
<Toggle
|
|
47
|
+
small
|
|
48
|
+
name="enableLine"
|
|
49
|
+
label="Show line"
|
|
50
|
+
checked={lineEnabled}
|
|
51
|
+
onChange={onToggleLine}
|
|
52
|
+
/>
|
|
53
|
+
<Spacer height={8} />
|
|
54
|
+
<Toggle
|
|
55
|
+
small
|
|
56
|
+
name="enableLegend"
|
|
57
|
+
label="Enable Legend" //{t(translations.showLegend)} temporary static value before translation is implemented
|
|
58
|
+
checked={legendEnabled}
|
|
59
|
+
onChange={onToggleLegend}
|
|
60
|
+
/>
|
|
61
|
+
<Spacer height={8} />
|
|
62
|
+
<Toggle
|
|
63
|
+
small
|
|
64
|
+
name="enableZoom"
|
|
65
|
+
label="Enable Zoom" //{t(translations.enableZoom)} temporary static value before translation is implemented
|
|
66
|
+
checked={zoomEnabled}
|
|
67
|
+
onChange={onToggleZoom}
|
|
68
|
+
/>
|
|
69
|
+
<Spacer height={8} />
|
|
70
|
+
<Toggle
|
|
71
|
+
small
|
|
72
|
+
name="enablePan"
|
|
73
|
+
label="Enable Pan" //{t(translations.enablePan)} temporary static value before translation is implemented
|
|
74
|
+
checked={panEnabled}
|
|
75
|
+
onChange={onTogglePan}
|
|
76
|
+
/>
|
|
77
|
+
<Spacer height={10} />
|
|
78
|
+
{(zoomEnabled || panEnabled) && (
|
|
79
|
+
<>
|
|
80
|
+
<div className={styles.help}>
|
|
81
|
+
{zoomEnabled && (
|
|
82
|
+
<p>
|
|
83
|
+
<strong>Zoom: </strong>
|
|
84
|
+
<span>click and drag</span>
|
|
85
|
+
</p>
|
|
86
|
+
)}
|
|
87
|
+
{panEnabled && (
|
|
88
|
+
<p>
|
|
89
|
+
<strong>Pan: </strong>
|
|
90
|
+
<span>click and drag</span>
|
|
91
|
+
</p>
|
|
92
|
+
)}
|
|
93
|
+
<p>
|
|
94
|
+
<strong>Change axis: </strong>
|
|
95
|
+
<span>hold shit key</span>
|
|
96
|
+
</p>
|
|
97
|
+
</div>
|
|
98
|
+
<Spacer height={10} />
|
|
99
|
+
</>
|
|
100
|
+
)}
|
|
101
|
+
{axes.map((axis, i) => (
|
|
102
|
+
<Field key={i} label={axis.label || ''}>
|
|
103
|
+
<InputGroup small>
|
|
104
|
+
<Input
|
|
105
|
+
name="min"
|
|
106
|
+
value={axis.min.inputValue}
|
|
107
|
+
error={
|
|
108
|
+
!axis.min.valid
|
|
109
|
+
? 'WARNING' //t(InputWarningType.MustBeNumericAndLessThanMax)
|
|
110
|
+
: undefined
|
|
111
|
+
}
|
|
112
|
+
size={5}
|
|
113
|
+
width="100%"
|
|
114
|
+
onChange={(evt) =>
|
|
115
|
+
onSetAxisValue({
|
|
116
|
+
name: evt.target.name,
|
|
117
|
+
value: evt.target.value,
|
|
118
|
+
id: axis.id,
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
disabled={zoomEnabled || panEnabled}
|
|
122
|
+
/>
|
|
123
|
+
<InputGroupAddon>
|
|
124
|
+
To
|
|
125
|
+
{/*t(translations.to)*/}
|
|
126
|
+
</InputGroupAddon>
|
|
127
|
+
<Input
|
|
128
|
+
name="max"
|
|
129
|
+
value={axis.max.inputValue}
|
|
130
|
+
error={
|
|
131
|
+
!axis.max.valid
|
|
132
|
+
? 'Warning' //t(InputWarningType.MustBeNumericAndGreaterThanMin)
|
|
133
|
+
: undefined
|
|
134
|
+
}
|
|
135
|
+
size={5}
|
|
136
|
+
width="100%"
|
|
137
|
+
onChange={(evt) =>
|
|
138
|
+
onSetAxisValue({
|
|
139
|
+
name: evt.target.name,
|
|
140
|
+
value: evt.target.value,
|
|
141
|
+
id: axis.id,
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
disabled={zoomEnabled || panEnabled}
|
|
145
|
+
/>
|
|
146
|
+
</InputGroup>
|
|
147
|
+
</Field>
|
|
148
|
+
))}
|
|
149
|
+
<Field>
|
|
150
|
+
<Button
|
|
151
|
+
small
|
|
152
|
+
name="resetAxes"
|
|
153
|
+
label="Reset Axes"
|
|
154
|
+
onClick={onResetAxes}
|
|
155
|
+
/>{' '}
|
|
156
|
+
<Text small muted>
|
|
157
|
+
or click on canvas
|
|
158
|
+
</Text>
|
|
159
|
+
</Field>
|
|
160
|
+
<Spacer height={8} />
|
|
161
|
+
<Button
|
|
162
|
+
label="Download PNG" //{t(translations.downloadPNG)}
|
|
163
|
+
small
|
|
164
|
+
onClick={onDownload}
|
|
165
|
+
icon={<HiOutlineDocumentDownload />}
|
|
166
|
+
/>
|
|
167
|
+
</div>
|
|
168
|
+
);
|
|
169
|
+
};
|