@oliasoft-open-source/charts-library 2.10.2 → 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 +2 -1
- package/release-notes.md +4 -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/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,6 +36,7 @@
|
|
|
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",
|
package/release-notes.md
CHANGED
|
@@ -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;
|