@oliasoft-open-source/charts-library 2.10.1 → 2.11.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/package.json +7 -7
- package/release-notes.md +8 -0
- package/src/components/bar-chart/bar-chart-prop-types.js +21 -0
- package/src/components/bar-chart/bar-chart.interface.ts +8 -1
- package/src/components/bar-chart/bar-chart.jsx +4 -0
- package/src/components/controls/controls.jsx +8 -0
- package/src/components/controls/drag-options.jsx +75 -19
- package/src/components/line-chart/line-chart-prop-types.js +21 -0
- package/src/components/line-chart/line-chart.interface.ts +2 -1
- package/src/components/line-chart/line-chart.jsx +12 -0
- package/src/components/line-chart/state/action-types.js +2 -0
- package/src/components/line-chart/state/initial-state.js +1 -0
- package/src/components/line-chart/state/line-chart-reducer.js +34 -7
- package/src/helpers/chart-interface.ts +12 -0
- package/src/helpers/get-draggableData.js +32 -0
- package/src/style/shared.less +2 -15
- package/src/helpers/styles.js +0 -68
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oliasoft-open-source/charts-library",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0",
|
|
4
4
|
"description": "React Chart Library (based on Chart.js and react-chart-js-2)",
|
|
5
5
|
"homepage": "https://gitlab.com/oliasoft-open-source/charts-library",
|
|
6
6
|
"bugs": {
|
|
@@ -36,19 +36,21 @@
|
|
|
36
36
|
"chart.js": "^3.9.1",
|
|
37
37
|
"chartjs-plugin-annotation": "^1.4.0",
|
|
38
38
|
"chartjs-plugin-datalabels": "^2.1.0",
|
|
39
|
+
"chartjs-plugin-dragdata": "^2.2.5",
|
|
39
40
|
"chartjs-plugin-zoom": "^1.2.1",
|
|
40
41
|
"classnames": "^2.3.1",
|
|
41
42
|
"fraction.js": "^4.2.0",
|
|
42
|
-
"
|
|
43
|
+
"lodash": "^4",
|
|
43
44
|
"react-base64-downloader": "^2.1.7",
|
|
44
|
-
"react-chartjs-2": "^4.3.1"
|
|
45
|
+
"react-chartjs-2": "^4.3.1",
|
|
46
|
+
"react-icons": "^4"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
49
|
"@babel/core": "^7.18.13",
|
|
48
50
|
"@babel/eslint-parser": "^7.18.9",
|
|
49
51
|
"@babel/preset-env": "^7.18.10",
|
|
50
52
|
"@babel/preset-react": "^7.18.6",
|
|
51
|
-
"@oliasoft-open-source/react-ui-library": "
|
|
53
|
+
"@oliasoft-open-source/react-ui-library": "3.3.11-beta-1",
|
|
52
54
|
"@oliasoft-open-source/units": "^2",
|
|
53
55
|
"@storybook/addon-actions": "^6.5.10",
|
|
54
56
|
"@storybook/addon-docs": "^6.5.10",
|
|
@@ -86,7 +88,6 @@
|
|
|
86
88
|
"prop-types": "^15",
|
|
87
89
|
"react": "^17",
|
|
88
90
|
"react-dom": "^17",
|
|
89
|
-
"react-icons": "^4",
|
|
90
91
|
"storybook-dark-mode": "^1.1.0",
|
|
91
92
|
"terser-webpack-plugin": "^5.3.6",
|
|
92
93
|
"webpack": "^5.74.0",
|
|
@@ -100,7 +101,6 @@
|
|
|
100
101
|
"immer": "^9",
|
|
101
102
|
"prop-types": "^15",
|
|
102
103
|
"react": "^17",
|
|
103
|
-
"react-dom": "^17"
|
|
104
|
-
"react-icons": "^4"
|
|
104
|
+
"react-dom": "^17"
|
|
105
105
|
}
|
|
106
106
|
}
|
package/release-notes.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Charts Library Release Notes
|
|
2
2
|
|
|
3
|
+
## 2.11.0
|
|
4
|
+
|
|
5
|
+
- added dragData feature(plugin-https://github.com/chrispahm/chartjs-plugin-dragData)
|
|
6
|
+
|
|
7
|
+
## 2.10.2
|
|
8
|
+
|
|
9
|
+
- remove dead `less-vars-to-js` package ([OW-11017](https://oliasoft.atlassian.net/browse/OW-11017))
|
|
10
|
+
|
|
3
11
|
## 2.10.1
|
|
4
12
|
|
|
5
13
|
- Use `peerDependencies` for common versions of shared packages like `units` and `react-ui-library` so reduce double
|
|
@@ -85,6 +85,16 @@ export const BarChartPropTypes = {
|
|
|
85
85
|
onBarHover: PropTypes.func,
|
|
86
86
|
onBarUnhover: PropTypes.func,
|
|
87
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
|
+
}),
|
|
88
98
|
}),
|
|
89
99
|
}).isRequired,
|
|
90
100
|
};
|
|
@@ -104,6 +114,7 @@ export const getDefaultProps = (props) => {
|
|
|
104
114
|
.customLegend || { customLegendPlugin: null, customLegendContainerID: '' };
|
|
105
115
|
props.chart.options.chartOptions = props.chart.options.chartOptions || {};
|
|
106
116
|
props.chart.options.interactions = props.chart.options.interactions || {};
|
|
117
|
+
props.chart.options.dragData = props.chart.options.dragData || {};
|
|
107
118
|
// Set defaults for missing properties
|
|
108
119
|
const chart = {
|
|
109
120
|
testId: props.chart.testId ?? null,
|
|
@@ -182,6 +193,16 @@ export const getDefaultProps = (props) => {
|
|
|
182
193
|
onBarHover: props.chart.options.interactions.onBarHover,
|
|
183
194
|
onBarUnhover: props.chart.options.interactions.onBarUnhover,
|
|
184
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
|
+
},
|
|
185
206
|
},
|
|
186
207
|
};
|
|
187
208
|
return chart;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
IChartAnnotations,
|
|
3
|
+
IChartDraggableData,
|
|
4
|
+
IChartInteractions,
|
|
5
|
+
IChartLegend,
|
|
6
|
+
IChartStyling
|
|
7
|
+
} from "../../helpers/chart-interface";
|
|
2
8
|
|
|
3
9
|
export interface IChartOptions {
|
|
4
10
|
enableZoom: boolean;
|
|
@@ -49,6 +55,7 @@ export interface IBarChartOptions {
|
|
|
49
55
|
legend: IChartLegend;
|
|
50
56
|
chartOptions: IChartOptions;
|
|
51
57
|
interactions: IChartInteractions;
|
|
58
|
+
draggableData :IChartDraggableData;
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
export interface IBarDataPoint {
|
|
@@ -14,6 +14,7 @@ import { Bar } from 'react-chartjs-2';
|
|
|
14
14
|
import zoomPlugin from 'chartjs-plugin-zoom';
|
|
15
15
|
import dataLabelsPlugin from 'chartjs-plugin-datalabels';
|
|
16
16
|
import annotationPlugin from 'chartjs-plugin-annotation';
|
|
17
|
+
import dragDataPlugin from 'chartjs-plugin-dragdata';
|
|
17
18
|
|
|
18
19
|
import styles from './bar-chart.module.less';
|
|
19
20
|
import { BarChartPropTypes, getDefaultProps } from './bar-chart-prop-types';
|
|
@@ -45,6 +46,7 @@ import {
|
|
|
45
46
|
ChartType,
|
|
46
47
|
PointStyle,
|
|
47
48
|
} from '../../helpers/enums';
|
|
49
|
+
import getDraggableData from '../../helpers/get-draggableData';
|
|
48
50
|
|
|
49
51
|
ChartJS.register(
|
|
50
52
|
LinearScale,
|
|
@@ -58,6 +60,7 @@ ChartJS.register(
|
|
|
58
60
|
zoomPlugin,
|
|
59
61
|
dataLabelsPlugin,
|
|
60
62
|
annotationPlugin,
|
|
63
|
+
dragDataPlugin,
|
|
61
64
|
);
|
|
62
65
|
|
|
63
66
|
/**
|
|
@@ -230,6 +233,7 @@ const BarChart = (props) => {
|
|
|
230
233
|
chartAreaBorder: {
|
|
231
234
|
borderColor: BORDER_COLOR,
|
|
232
235
|
},
|
|
236
|
+
dragData: getDraggableData(options),
|
|
233
237
|
},
|
|
234
238
|
}}
|
|
235
239
|
plugins={getPlugins(graph, options.legend)}
|
|
@@ -34,6 +34,10 @@ const Controls = ({
|
|
|
34
34
|
subheaderComponent,
|
|
35
35
|
table,
|
|
36
36
|
zoomEnabled,
|
|
37
|
+
enableDragPoints,
|
|
38
|
+
isDragDataAllowed,
|
|
39
|
+
onToggleDragPoints,
|
|
40
|
+
onDisableDragOptions,
|
|
37
41
|
}) => {
|
|
38
42
|
return (
|
|
39
43
|
<>
|
|
@@ -65,6 +69,10 @@ const Controls = ({
|
|
|
65
69
|
zoomEnabled={zoomEnabled}
|
|
66
70
|
onTogglePan={onTogglePan}
|
|
67
71
|
onToggleZoom={onToggleZoom}
|
|
72
|
+
enableDragPoints={enableDragPoints}
|
|
73
|
+
isDragDataAllowed={isDragDataAllowed}
|
|
74
|
+
onToggleDragPoints={onToggleDragPoints}
|
|
75
|
+
onDisableDragOptions={onDisableDragOptions}
|
|
68
76
|
/>
|
|
69
77
|
<Tooltip text="Download as PNG" placement="bottom-end">
|
|
70
78
|
<Button
|
|
@@ -2,17 +2,39 @@ import React from 'react';
|
|
|
2
2
|
import {
|
|
3
3
|
Button,
|
|
4
4
|
Flex,
|
|
5
|
+
Menu,
|
|
5
6
|
Text,
|
|
6
7
|
Tooltip,
|
|
7
8
|
} from '@oliasoft-open-source/react-ui-library';
|
|
8
9
|
import { RiDragMove2Line, RiForbidLine, RiZoomInLine } from 'react-icons/ri';
|
|
10
|
+
import { TbHandStop } from 'react-icons/all';
|
|
9
11
|
|
|
10
12
|
export const DragOptions = ({
|
|
11
13
|
onTogglePan,
|
|
12
14
|
onToggleZoom,
|
|
13
15
|
panEnabled,
|
|
14
16
|
zoomEnabled,
|
|
17
|
+
enableDragPoints,
|
|
18
|
+
isDragDataAllowed,
|
|
19
|
+
onToggleDragPoints,
|
|
20
|
+
onDisableDragOptions,
|
|
15
21
|
}) => {
|
|
22
|
+
const handleToggleZoom = () => {
|
|
23
|
+
if (isDragDataAllowed) {
|
|
24
|
+
onToggleZoom();
|
|
25
|
+
} else {
|
|
26
|
+
onToggleZoom();
|
|
27
|
+
onTogglePan();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const handleToggleDragPoints = () => {
|
|
32
|
+
if (isDragDataAllowed) {
|
|
33
|
+
onDisableDragOptions();
|
|
34
|
+
} else {
|
|
35
|
+
onToggleZoom();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
16
38
|
// TODO: Translate strings
|
|
17
39
|
const options = [
|
|
18
40
|
{
|
|
@@ -29,10 +51,7 @@ export const DragOptions = ({
|
|
|
29
51
|
),
|
|
30
52
|
icon: <RiZoomInLine />,
|
|
31
53
|
selected: zoomEnabled,
|
|
32
|
-
onClick:
|
|
33
|
-
onToggleZoom();
|
|
34
|
-
onTogglePan();
|
|
35
|
-
},
|
|
54
|
+
onClick: handleToggleZoom,
|
|
36
55
|
},
|
|
37
56
|
{
|
|
38
57
|
label: (
|
|
@@ -48,30 +67,67 @@ export const DragOptions = ({
|
|
|
48
67
|
),
|
|
49
68
|
icon: <RiDragMove2Line />,
|
|
50
69
|
selected: panEnabled,
|
|
51
|
-
onClick:
|
|
52
|
-
onTogglePan();
|
|
53
|
-
},
|
|
70
|
+
onClick: onTogglePan,
|
|
54
71
|
},
|
|
72
|
+
...(isDragDataAllowed
|
|
73
|
+
? [
|
|
74
|
+
{
|
|
75
|
+
label: 'Drag to move points',
|
|
76
|
+
icon: <TbHandStop />,
|
|
77
|
+
selected: enableDragPoints,
|
|
78
|
+
type: 'Option',
|
|
79
|
+
onClick: onToggleDragPoints,
|
|
80
|
+
},
|
|
81
|
+
]
|
|
82
|
+
: []),
|
|
55
83
|
{
|
|
56
84
|
label: 'Drag disabled',
|
|
57
85
|
icon: <RiForbidLine />,
|
|
58
|
-
selected: !zoomEnabled && !panEnabled,
|
|
59
|
-
onClick:
|
|
60
|
-
onToggleZoom();
|
|
61
|
-
},
|
|
86
|
+
selected: !zoomEnabled && !panEnabled && !enableDragPoints,
|
|
87
|
+
onClick: handleToggleDragPoints,
|
|
62
88
|
},
|
|
63
89
|
];
|
|
90
|
+
|
|
64
91
|
const selectedOption = options.filter((option) => option.selected)[0];
|
|
92
|
+
const optionsWithDragPoints = options.map(
|
|
93
|
+
({ icon, label, onClick, selected }) => ({
|
|
94
|
+
icon,
|
|
95
|
+
label,
|
|
96
|
+
type: 'Option',
|
|
97
|
+
onClick,
|
|
98
|
+
disabled: selected,
|
|
99
|
+
}),
|
|
100
|
+
);
|
|
101
|
+
|
|
65
102
|
return (
|
|
66
103
|
<Tooltip text={selectedOption.label} placement="bottom-end">
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
104
|
+
{!isDragDataAllowed ? (
|
|
105
|
+
<Button
|
|
106
|
+
small
|
|
107
|
+
basic
|
|
108
|
+
colored="muted"
|
|
109
|
+
round
|
|
110
|
+
icon={selectedOption.icon}
|
|
111
|
+
onClick={selectedOption.onClick}
|
|
112
|
+
/>
|
|
113
|
+
) : (
|
|
114
|
+
<Menu
|
|
115
|
+
menu={{
|
|
116
|
+
component: (
|
|
117
|
+
<Button
|
|
118
|
+
small
|
|
119
|
+
basic
|
|
120
|
+
colored="muted"
|
|
121
|
+
round
|
|
122
|
+
icon={selectedOption.icon}
|
|
123
|
+
/>
|
|
124
|
+
),
|
|
125
|
+
label: 'Select',
|
|
126
|
+
sections: optionsWithDragPoints,
|
|
127
|
+
trigger: 'Component',
|
|
128
|
+
}}
|
|
129
|
+
/>
|
|
130
|
+
)}
|
|
75
131
|
</Tooltip>
|
|
76
132
|
);
|
|
77
133
|
};
|
|
@@ -106,6 +106,16 @@ export const LineChartPropTypes = {
|
|
|
106
106
|
onPointUnhover: PropTypes.func,
|
|
107
107
|
onAnimationComplete: PropTypes.func,
|
|
108
108
|
}),
|
|
109
|
+
dragData: PropTypes.shape({
|
|
110
|
+
enableDragData: PropTypes.bool,
|
|
111
|
+
showTooltip: PropTypes.bool,
|
|
112
|
+
roundPoints: PropTypes.bool,
|
|
113
|
+
dragX: PropTypes.bool,
|
|
114
|
+
dragY: PropTypes.bool,
|
|
115
|
+
onDragStart: PropTypes.func,
|
|
116
|
+
onDrag: PropTypes.func,
|
|
117
|
+
onDragEnd: PropTypes.func,
|
|
118
|
+
}),
|
|
109
119
|
}),
|
|
110
120
|
}).isRequired,
|
|
111
121
|
};
|
|
@@ -125,6 +135,7 @@ export const getDefaultProps = (props) => {
|
|
|
125
135
|
.customLegend || { customLegendPlugin: null, customLegendContainerID: '' };
|
|
126
136
|
props.chart.options.chartOptions = props.chart.options.chartOptions || {};
|
|
127
137
|
props.chart.options.interactions = props.chart.options.interactions || {};
|
|
138
|
+
props.chart.options.dragData = props.chart.options.dragData || {};
|
|
128
139
|
// Set defaults for missing properties
|
|
129
140
|
const chart = {
|
|
130
141
|
testId: props.chart.testId ?? null,
|
|
@@ -206,6 +217,16 @@ export const getDefaultProps = (props) => {
|
|
|
206
217
|
onAnimationComplete:
|
|
207
218
|
props.chart.options.interactions.onAnimationComplete,
|
|
208
219
|
},
|
|
220
|
+
dragData: {
|
|
221
|
+
enableDragData: props.chart.options.dragData.enableDragData || false,
|
|
222
|
+
showTooltip: props.chart.options.dragData.showTooltip || true,
|
|
223
|
+
roundPoints: props.chart.options.dragData.roundPoints || true,
|
|
224
|
+
dragX: props.chart.options.dragData.dragX || true,
|
|
225
|
+
dragY: props.chart.options.dragData.dragY || true,
|
|
226
|
+
onDragStart: props.chart.options.dragData.onDragStart,
|
|
227
|
+
onDrag: props.chart.options.dragData.onDrag,
|
|
228
|
+
onDragEnd: props.chart.options.dragData.onDragEnd,
|
|
229
|
+
},
|
|
209
230
|
},
|
|
210
231
|
};
|
|
211
232
|
return chart;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
IChartAnnotations,
|
|
2
|
+
IChartAnnotations, IChartDraggableData,
|
|
3
3
|
IChartInteractions,
|
|
4
4
|
IChartLegend,
|
|
5
5
|
IChartStyling,
|
|
@@ -68,6 +68,7 @@ export interface ILineChartOptions {
|
|
|
68
68
|
legend: IChartLegend;
|
|
69
69
|
chartOptions: IChartOptions;
|
|
70
70
|
interactions: IChartInteractions;
|
|
71
|
+
draggableData :IChartDraggableData;
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
export interface IDataPoint {
|
|
@@ -15,6 +15,7 @@ import { Line } from 'react-chartjs-2';
|
|
|
15
15
|
import zoomPlugin from 'chartjs-plugin-zoom';
|
|
16
16
|
import dataLabelsPlugin from 'chartjs-plugin-datalabels';
|
|
17
17
|
import annotationPlugin from 'chartjs-plugin-annotation';
|
|
18
|
+
import dragDataPlugin from 'chartjs-plugin-dragdata';
|
|
18
19
|
import { triggerBase64Download } from 'react-base64-downloader';
|
|
19
20
|
import styles from './line-chart.module.less';
|
|
20
21
|
import { reducer } from './state/line-chart-reducer';
|
|
@@ -31,6 +32,8 @@ import {
|
|
|
31
32
|
SAVE_INITIAL_AXES_RANGES,
|
|
32
33
|
UPDATE_AXES_RANGES,
|
|
33
34
|
RESET_AXES_RANGES,
|
|
35
|
+
TOGGLE_DRAG_POINTS,
|
|
36
|
+
DISABLE_DRAG_OPTIONS,
|
|
34
37
|
} from './state/action-types';
|
|
35
38
|
import Controls from '../controls/controls';
|
|
36
39
|
import { getDefaultProps, LineChartPropTypes } from './line-chart-prop-types';
|
|
@@ -69,6 +72,7 @@ import {
|
|
|
69
72
|
PanZoomMode,
|
|
70
73
|
PointStyle,
|
|
71
74
|
} from '../../helpers/enums';
|
|
75
|
+
import getDraggableData from '../../helpers/get-draggableData';
|
|
72
76
|
import { getAxesRangesFromChart } from './get-axes-ranges-from-chart';
|
|
73
77
|
import { generateAxisId } from './line-chart-utils';
|
|
74
78
|
import { autoScale } from './axis-scales/axis-scales';
|
|
@@ -86,6 +90,7 @@ ChartJS.register(
|
|
|
86
90
|
zoomPlugin,
|
|
87
91
|
dataLabelsPlugin,
|
|
88
92
|
annotationPlugin,
|
|
93
|
+
dragDataPlugin,
|
|
89
94
|
);
|
|
90
95
|
|
|
91
96
|
/**
|
|
@@ -108,6 +113,7 @@ const LineChart = (props) => {
|
|
|
108
113
|
graph,
|
|
109
114
|
interactions,
|
|
110
115
|
legend,
|
|
116
|
+
dragData,
|
|
111
117
|
} = options;
|
|
112
118
|
const { showLine, showPoints, enableZoom, enablePan } = chartOptions;
|
|
113
119
|
|
|
@@ -449,12 +455,17 @@ const LineChart = (props) => {
|
|
|
449
455
|
subheaderComponent={subheaderComponent}
|
|
450
456
|
table={table}
|
|
451
457
|
zoomEnabled={state.zoomEnabled}
|
|
458
|
+
enableDragPoints={state.enableDragPoints}
|
|
459
|
+
isDragDataAllowed={dragData.enableDragData}
|
|
460
|
+
onToggleDragPoints={() => dispatch({ type: TOGGLE_DRAG_POINTS })}
|
|
461
|
+
onDisableDragOptions={() => dispatch({ type: DISABLE_DRAG_OPTIONS })}
|
|
452
462
|
/>
|
|
453
463
|
{table && state.showTable ? (
|
|
454
464
|
<div className={styles.table}>{table}</div>
|
|
455
465
|
) : (
|
|
456
466
|
<div className={styles.canvas}>
|
|
457
467
|
<Line
|
|
468
|
+
key={state.enableDragPoints}
|
|
458
469
|
ref={chartRef}
|
|
459
470
|
data={{
|
|
460
471
|
datasets: generatedDatasets,
|
|
@@ -516,6 +527,7 @@ const LineChart = (props) => {
|
|
|
516
527
|
chartAreaBorder: {
|
|
517
528
|
borderColor: BORDER_COLOR,
|
|
518
529
|
},
|
|
530
|
+
...(state.enableDragPoints ? getDraggableData(options) : {}),
|
|
519
531
|
},
|
|
520
532
|
events: [
|
|
521
533
|
'mousemove',
|
|
@@ -9,3 +9,5 @@ export const TOGGLE_TABLE = 'TOGGLE_TABLE';
|
|
|
9
9
|
export const SAVE_INITIAL_AXES_RANGES = 'SAVE_INITIAL_AXES_RANGES';
|
|
10
10
|
export const RESET_AXES_RANGES = 'RESET_AXES_RANGES';
|
|
11
11
|
export const UPDATE_AXES_RANGES = 'UPDATE_AXES_RANGES';
|
|
12
|
+
export const TOGGLE_DRAG_POINTS = 'TOGGLE_DRAG_POINTS';
|
|
13
|
+
export const DISABLE_DRAG_OPTIONS = 'DISABLE_DRAG_OPTIONS';
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { produce } from 'immer';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
TOGGLE_LINE,
|
|
7
|
-
TOGGLE_LEGEND,
|
|
3
|
+
DISABLE_DRAG_OPTIONS,
|
|
4
|
+
RESET_AXES_RANGES,
|
|
5
|
+
SAVE_INITIAL_AXES_RANGES,
|
|
8
6
|
SET_POINTS_ZOOM_DEFAULTS,
|
|
9
7
|
TOGGLE_ANNOTATION,
|
|
8
|
+
TOGGLE_DRAG_POINTS,
|
|
9
|
+
TOGGLE_LEGEND,
|
|
10
|
+
TOGGLE_LINE,
|
|
11
|
+
TOGGLE_PAN,
|
|
12
|
+
TOGGLE_POINTS,
|
|
10
13
|
TOGGLE_TABLE,
|
|
11
|
-
|
|
14
|
+
TOGGLE_ZOOM,
|
|
12
15
|
UPDATE_AXES_RANGES,
|
|
13
|
-
RESET_AXES_RANGES,
|
|
14
16
|
} from './action-types';
|
|
15
17
|
|
|
16
18
|
export const reducer = (state, action) => {
|
|
@@ -21,6 +23,9 @@ export const reducer = (state, action) => {
|
|
|
21
23
|
if (newState.panEnabled) {
|
|
22
24
|
newState.panEnabled = false;
|
|
23
25
|
}
|
|
26
|
+
if (newState.enableDragPoints) {
|
|
27
|
+
newState.enableDragPoints = false;
|
|
28
|
+
}
|
|
24
29
|
return newState;
|
|
25
30
|
}
|
|
26
31
|
case TOGGLE_PAN: {
|
|
@@ -94,6 +99,28 @@ export const reducer = (state, action) => {
|
|
|
94
99
|
...newState,
|
|
95
100
|
showAnnotationLineIndex: updatedIndexes,
|
|
96
101
|
};
|
|
102
|
+
case TOGGLE_DRAG_POINTS: {
|
|
103
|
+
newState.enableDragPoints = !newState.enableDragPoints;
|
|
104
|
+
if (newState.panEnabled) {
|
|
105
|
+
newState.panEnabled = false;
|
|
106
|
+
}
|
|
107
|
+
if (newState.zoomEnabled) {
|
|
108
|
+
newState.zoomEnabled = false;
|
|
109
|
+
}
|
|
110
|
+
return newState;
|
|
111
|
+
}
|
|
112
|
+
case DISABLE_DRAG_OPTIONS: {
|
|
113
|
+
if (
|
|
114
|
+
newState.enableDragPoints ||
|
|
115
|
+
newState.panEnabled ||
|
|
116
|
+
newState.zoomEnabled
|
|
117
|
+
) {
|
|
118
|
+
newState.enableDragPoints = false;
|
|
119
|
+
newState.panEnabled = false;
|
|
120
|
+
newState.zoomEnabled = false;
|
|
121
|
+
}
|
|
122
|
+
return newState;
|
|
123
|
+
}
|
|
97
124
|
default: {
|
|
98
125
|
return newState;
|
|
99
126
|
}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { Plugin } from "chart.js";
|
|
2
2
|
|
|
3
|
+
export interface IChartDraggableData {
|
|
4
|
+
enableDragData: boolean;
|
|
5
|
+
showTooltip: boolean;
|
|
6
|
+
roundPoints: boolean;
|
|
7
|
+
dragX: boolean;
|
|
8
|
+
dragY: boolean;
|
|
9
|
+
onDragStart: () => any;
|
|
10
|
+
onDrag: () => any;
|
|
11
|
+
onDragEnd: () => any;
|
|
12
|
+
};
|
|
13
|
+
|
|
3
14
|
export interface IChartAnnotationsData {
|
|
4
15
|
adjustScaleRange: boolean;
|
|
5
16
|
annotationAxis: 'x' | 'y';
|
|
@@ -63,6 +74,7 @@ export interface IInitialState {
|
|
|
63
74
|
legendEnabled?: boolean;
|
|
64
75
|
axes?: {id: string, label: string | any, min?: {}, max?: {}}[];
|
|
65
76
|
showAnnotationLineIndex: [];
|
|
77
|
+
enableDragData?: boolean;
|
|
66
78
|
}
|
|
67
79
|
|
|
68
80
|
export interface IChartPlugins {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {import('./line-chart.interface').ILineChartOptions} options - line chart options object
|
|
3
|
+
*/
|
|
4
|
+
const getDraggableData = (options) => {
|
|
5
|
+
const { dragData = {} } = options;
|
|
6
|
+
const {
|
|
7
|
+
enableDragData = false,
|
|
8
|
+
showTooltip = true,
|
|
9
|
+
roundPoints = true,
|
|
10
|
+
dragX = true,
|
|
11
|
+
dragY = true,
|
|
12
|
+
onDragStart = () => {},
|
|
13
|
+
onDrag = () => {},
|
|
14
|
+
onDragEnd = () => {},
|
|
15
|
+
} = dragData;
|
|
16
|
+
|
|
17
|
+
return enableDragData
|
|
18
|
+
? {
|
|
19
|
+
dragData: {
|
|
20
|
+
dragX,
|
|
21
|
+
dragY,
|
|
22
|
+
round: roundPoints,
|
|
23
|
+
showTooltip,
|
|
24
|
+
onDragStart,
|
|
25
|
+
onDrag,
|
|
26
|
+
onDragEnd,
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
: {};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default getDraggableData;
|
package/src/style/shared.less
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
|
-
This file has shared variables that are re-used
|
|
3
|
-
- in other LESS files/modules
|
|
4
|
-
- in JavaScript, via https://www.npmjs.com/package/less-vars-to-js
|
|
5
|
-
|
|
2
|
+
This file has shared variables that are re-used in other LESS files/modules
|
|
6
3
|
Only use simple variables in this file
|
|
7
|
-
|
|
4
|
+
*/
|
|
8
5
|
|
|
9
6
|
// Brand guidelines
|
|
10
7
|
@colorPrimary: #eb6429;
|
|
@@ -12,13 +9,3 @@
|
|
|
12
9
|
@colorWarning: #e2bd27;
|
|
13
10
|
@colorSuccess: #3bbb3b;
|
|
14
11
|
@colorInfo: #29a7eb;
|
|
15
|
-
|
|
16
|
-
/*
|
|
17
|
-
Allow the parent project to optionally override the primary colour palette
|
|
18
|
-
by having an `override.less` file in its root directory
|
|
19
|
-
*/
|
|
20
|
-
@import (optional) '../../../../override.less';
|
|
21
|
-
|
|
22
|
-
/*
|
|
23
|
-
Other shared variables
|
|
24
|
-
*/
|
package/src/helpers/styles.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
This helper allows us to export simple LESS variables as JavaScript objects.
|
|
3
|
-
The intention is for keeping code DRY by allowing primary colour palettes etc
|
|
4
|
-
to be defined in one place only (LESS).
|
|
5
|
-
|
|
6
|
-
These simple variables should be defined in a files called `shared.less` that
|
|
7
|
-
can exist in one of two place:
|
|
8
|
-
|
|
9
|
-
- in `override.less` in the root of the parent project
|
|
10
|
-
(to allow overriding of the default values set in this project)
|
|
11
|
-
- in `src/style/shared.less in this project (default values)
|
|
12
|
-
|
|
13
|
-
The parent and local definitions are merged, with the parent taking
|
|
14
|
-
precedence.
|
|
15
|
-
|
|
16
|
-
The implementation uses Webpack raw-loader to load the shared LESS variables
|
|
17
|
-
file, and a 3rd party package (less-vars-to-js) to parse it, so they can be
|
|
18
|
-
exported for use in JavaScript.
|
|
19
|
-
|
|
20
|
-
When we upgrade to Webpack 5, we'll have to refactor this to use asset modules
|
|
21
|
-
instead.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import lessToJs from 'less-vars-to-js';
|
|
25
|
-
|
|
26
|
-
// eslint-disable-next-line import/no-unresolved,import/no-webpack-loader-syntax
|
|
27
|
-
import lessVariables from '../style/shared.less?raw';
|
|
28
|
-
|
|
29
|
-
/*
|
|
30
|
-
We need to import the `shared.less` file from the root of the parent project
|
|
31
|
-
conditionally (it may not exist). Would love to use ES6 imports here, but they
|
|
32
|
-
don't allow optional files without throwing an error when the file doesn't
|
|
33
|
-
exist. ES6 dynamic imports would require `async` when we use this helper
|
|
34
|
-
(prefer to avoid that). So falling back to CommonJS require here.
|
|
35
|
-
|
|
36
|
-
Hopefully this will get better once we have Webpack 5 asset modules.
|
|
37
|
-
*/
|
|
38
|
-
let lessParentVariables = '{}';
|
|
39
|
-
try {
|
|
40
|
-
const parentPath = '../../../../override.less?raw';
|
|
41
|
-
// eslint-disable-next-line import/no-unresolved,global-require,import/no-webpack-loader-syntax,import/no-dynamic-require
|
|
42
|
-
lessParentVariables = require(`${parentPath}`).default;
|
|
43
|
-
} catch (e) {
|
|
44
|
-
//do nothing (we fallback to the local definition anyway)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const load = () => {
|
|
48
|
-
/*
|
|
49
|
-
Merge the parent project shared.less with the local shared.less
|
|
50
|
-
(since less-vars-to-js doesn't handle import statements for us)
|
|
51
|
-
|
|
52
|
-
The parent definition takes precedence over the local definition
|
|
53
|
-
*/
|
|
54
|
-
const parent = lessToJs(lessParentVariables, {
|
|
55
|
-
resolveVariables: true,
|
|
56
|
-
stripPrefix: true,
|
|
57
|
-
});
|
|
58
|
-
const local = lessToJs(lessVariables, {
|
|
59
|
-
resolveVariables: true,
|
|
60
|
-
stripPrefix: true,
|
|
61
|
-
});
|
|
62
|
-
return {
|
|
63
|
-
...local,
|
|
64
|
-
...parent,
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export const styleVariables = load();
|