@oliasoft-open-source/charts-library 2.17.6 → 2.18.0-beta-1

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.
Files changed (84) hide show
  1. package/package.json +26 -34
  2. package/index.js +0 -14
  3. package/release-notes.md +0 -310
  4. package/src/assets/icons/line-and-point.svg +0 -1
  5. package/src/assets/icons/line-only.svg +0 -1
  6. package/src/assets/icons/list-hide.svg +0 -1
  7. package/src/assets/icons/point-only.svg +0 -1
  8. package/src/components/bar-chart/bar-chart-prop-types.js +0 -209
  9. package/src/components/bar-chart/bar-chart.interface.ts +0 -91
  10. package/src/components/bar-chart/bar-chart.jsx +0 -247
  11. package/src/components/bar-chart/bar-chart.module.less +0 -61
  12. package/src/components/bar-chart/get-bar-chart-data-labels.js +0 -42
  13. package/src/components/bar-chart/get-bar-chart-scales.js +0 -123
  14. package/src/components/bar-chart/get-bar-chart-tooltips.js +0 -102
  15. package/src/components/controls/axes-options/axes-options.jsx +0 -270
  16. package/src/components/line-chart/constants/default-translations.js +0 -24
  17. package/src/components/line-chart/constants/line-chart-consts.js +0 -12
  18. package/src/components/line-chart/controls/axes-options/action-types.js +0 -5
  19. package/src/components/line-chart/controls/axes-options/axes-options-form-state.js +0 -97
  20. package/src/components/line-chart/controls/controls.jsx +0 -174
  21. package/src/components/line-chart/controls/controls.module.less +0 -12
  22. package/src/components/line-chart/controls/drag-options.jsx +0 -112
  23. package/src/components/line-chart/controls/legend-options.jsx +0 -36
  24. package/src/components/line-chart/controls/line-options.jsx +0 -64
  25. package/src/components/line-chart/hooks/use-chart-functions.js +0 -257
  26. package/src/components/line-chart/hooks/use-chart-options.js +0 -181
  27. package/src/components/line-chart/hooks/use-chart-plugins.js +0 -35
  28. package/src/components/line-chart/hooks/use-toggle-handler.js +0 -33
  29. package/src/components/line-chart/initialize/config.js +0 -23
  30. package/src/components/line-chart/initialize/initialize-line-chart.js +0 -25
  31. package/src/components/line-chart/line-chart-prop-types.js +0 -292
  32. package/src/components/line-chart/line-chart.interface.ts +0 -121
  33. package/src/components/line-chart/line-chart.jsx +0 -161
  34. package/src/components/line-chart/line-chart.module.less +0 -77
  35. package/src/components/line-chart/plugins/chart-area-text-plugin.js +0 -246
  36. package/src/components/line-chart/plugins/line-chart.minor-gridlines-plugin.js +0 -88
  37. package/src/components/line-chart/plugins/plugin-constants.js +0 -11
  38. package/src/components/line-chart/state/action-types.js +0 -12
  39. package/src/components/line-chart/state/initial-state.js +0 -89
  40. package/src/components/line-chart/state/line-chart-reducer.js +0 -100
  41. package/src/components/line-chart/state/manage-state-in-local-storage.js +0 -86
  42. package/src/components/line-chart/state/use-chart-state.js +0 -141
  43. package/src/components/line-chart/utils/axis-scales/axis-scales.js +0 -165
  44. package/src/components/line-chart/utils/datalabels-alignment/get-alignment-condition.js +0 -13
  45. package/src/components/line-chart/utils/datalabels-alignment/get-alignment-data.js +0 -20
  46. package/src/components/line-chart/utils/datalabels-alignment/get-datalabels-position.js +0 -25
  47. package/src/components/line-chart/utils/generate-line-chart-datasets.js +0 -114
  48. package/src/components/line-chart/utils/get-axes-ranges-from-chart.js +0 -13
  49. package/src/components/line-chart/utils/get-line-chart-data-labels.js +0 -21
  50. package/src/components/line-chart/utils/get-line-chart-scales.js +0 -120
  51. package/src/components/line-chart/utils/get-line-chart-tooltips.js +0 -94
  52. package/src/components/line-chart/utils/line-chart-utils.js +0 -77
  53. package/src/components/line-chart/utils/translations/get-translations.js +0 -17
  54. package/src/components/pie-chart/pie-chart-prop-types.js +0 -111
  55. package/src/components/pie-chart/pie-chart-utils.js +0 -32
  56. package/src/components/pie-chart/pie-chart.interface.ts +0 -61
  57. package/src/components/pie-chart/pie-chart.jsx +0 -450
  58. package/src/components/pie-chart/pie-chart.module.less +0 -61
  59. package/src/components/scatter-chart/scatter-chart.intefrace.ts +0 -33
  60. package/src/components/scatter-chart/scatter-chart.jsx +0 -21
  61. package/src/components/scatter-chart/scatter-chart.module.less +0 -4
  62. package/src/helpers/chart-border-plugin.js +0 -19
  63. package/src/helpers/chart-consts.js +0 -64
  64. package/src/helpers/chart-interface.ts +0 -94
  65. package/src/helpers/chart-utils.js +0 -182
  66. package/src/helpers/container.jsx +0 -60
  67. package/src/helpers/disabled-context.js +0 -8
  68. package/src/helpers/enums.js +0 -96
  69. package/src/helpers/get-chart-annotation.js +0 -106
  70. package/src/helpers/get-custom-legend-plugin-example.js +0 -80
  71. package/src/helpers/get-draggableData.js +0 -32
  72. package/src/helpers/range/estimate-data-series-have-close-values.js +0 -54
  73. package/src/helpers/range/range.js +0 -100
  74. package/src/helpers/text.js +0 -6
  75. package/src/style/external.less +0 -4
  76. package/src/style/fonts/lato/Lato-Bold.woff2 +0 -0
  77. package/src/style/fonts/lato/Lato-BoldItalic.woff2 +0 -0
  78. package/src/style/fonts/lato/Lato-Italic.woff2 +0 -0
  79. package/src/style/fonts/lato/Lato-Regular.woff2 +0 -0
  80. package/src/style/fonts.less +0 -27
  81. package/src/style/global.less +0 -43
  82. package/src/style/reset/reset.less +0 -28
  83. package/src/style/shared.less +0 -11
  84. package/src/style/variables.less +0 -91
@@ -1,270 +0,0 @@
1
- import React, { useReducer, useState } from 'react';
2
- import {
3
- Button,
4
- ButtonGroup,
5
- Field,
6
- Flex,
7
- NumberInput,
8
- InputGroup,
9
- InputGroupAddon,
10
- Popover,
11
- Select,
12
- Spacer,
13
- Text,
14
- Tooltip,
15
- } from '@oliasoft-open-source/react-ui-library';
16
- import { RiRuler2Line } from 'react-icons/ri';
17
- import PropTypes from 'prop-types';
18
- import { toNum } from '@oliasoft-open-source/units';
19
- import {
20
- initializeFormState,
21
- reducer,
22
- validateAxes,
23
- } from '../../line-chart/controls/axes-options/axes-options-form-state';
24
- import { actionTypes } from '../../line-chart/controls/axes-options/action-types';
25
-
26
- const AxesOptionsPopover = ({
27
- initialAxesRanges,
28
- axes,
29
- controlsAxesLabels,
30
- onUpdateAxes,
31
- onResetAxes,
32
- close,
33
- depthType,
34
- translations,
35
- }) => {
36
- const [depthTypeState, setDepthTypeState] = useState(
37
- depthType?.selectedDepthType,
38
- );
39
- const [formState, dispatch] = useReducer(
40
- reducer,
41
- {
42
- axes,
43
- initialAxesRanges,
44
- },
45
- initializeFormState,
46
- );
47
-
48
- const { errors, valid } = validateAxes(formState);
49
-
50
- const onEditValue = ({ name, value, id }) => {
51
- dispatch({
52
- type: actionTypes.valueUpdated,
53
- payload: { name, value, id },
54
- });
55
- };
56
-
57
- const onEditUnit = ({ name, value, id }) => {
58
- dispatch({
59
- type: actionTypes.unitUpdated,
60
- payload: { name, value, id },
61
- });
62
- };
63
-
64
- const onDone = (e) => {
65
- e.preventDefault();
66
- if (valid) {
67
- const sanitizedFormState = formState.map((axis) => ({
68
- ...axis,
69
- min: toNum(axis.min),
70
- max: toNum(axis.max),
71
- }));
72
- onUpdateAxes({
73
- axes: sanitizedFormState,
74
- });
75
-
76
- //update units
77
- sanitizedFormState.map((el, i) => {
78
- if (el.unit?.selectedUnit) {
79
- axes[i].unit.setSelectedUnit(el.unit.selectedUnit);
80
- }
81
- });
82
- //update depthType
83
- if (depthType) {
84
- depthType.setSelectedDepthType(depthTypeState);
85
- }
86
- }
87
- close();
88
- };
89
-
90
- const onReset = () => {
91
- //reset local form
92
- dispatch({
93
- type: actionTypes.reset,
94
- payload: { axes, initialAxesRanges },
95
- });
96
- //update units
97
- initialAxesRanges.map((el, i) => {
98
- if (el?.unit?.selectedUnit) {
99
- axes[i].unit.setSelectedUnit(el.unit.selectedUnit);
100
- }
101
- });
102
-
103
- //reset parent state
104
- onResetAxes();
105
- close();
106
- };
107
-
108
- const isCustomValue = axes.filter((axis) => axis.max || axis.min).length > 0;
109
- const handleInputFocus = (e) => e.target.select();
110
- return (
111
- <form onSubmit={onDone}>
112
- {axes.map((axis, i) => {
113
- const axisLabel = controlsAxesLabels.find(
114
- (el) => el.id === axis.id,
115
- )?.label;
116
-
117
- const min = formState.find((a) => a.id === axis.id)?.min;
118
- const max = formState.find((a) => a.id === axis.id)?.max;
119
- const minError = errors?.find((a) => a.id === axis.id)?.min?.[0];
120
- const maxError = errors?.find((a) => a.id === axis.id)?.max?.[0];
121
- const unit = formState.find((a) => a.id === axis.id)?.unit;
122
- return (
123
- <Field key={i} label={axisLabel || axis.id || ''}>
124
- <InputGroup small>
125
- <NumberInput
126
- name="min"
127
- value={min}
128
- error={translations[minError]}
129
- size={5}
130
- width="100%"
131
- onChange={(evt) =>
132
- onEditValue({
133
- name: evt.target.name,
134
- value: evt.target.value,
135
- id: axis.id,
136
- })
137
- }
138
- onFocus={handleInputFocus}
139
- />
140
- <InputGroupAddon>to</InputGroupAddon>
141
- <NumberInput
142
- name="max"
143
- value={max}
144
- error={translations[maxError]}
145
- size={5}
146
- width="100%"
147
- onChange={(evt) =>
148
- onEditValue({
149
- name: evt.target.name,
150
- value: evt.target.value,
151
- id: axis.id,
152
- })
153
- }
154
- onFocus={handleInputFocus}
155
- />
156
- {axis.unit ? (
157
- <Select
158
- name="selectedUnit"
159
- options={axis?.unit?.options}
160
- value={unit?.selectedUnit}
161
- onChange={(e) => {
162
- onEditUnit({
163
- name: e.target.name,
164
- value: e.target.value,
165
- id: axis.id,
166
- });
167
- }}
168
- width="auto"
169
- />
170
- ) : null}
171
- </InputGroup>
172
- </Field>
173
- );
174
- })}
175
-
176
- {depthType?.options?.length > 0 ? (
177
- <>
178
- <ButtonGroup
179
- items={depthType.options.map((depth, i) => ({
180
- key: i,
181
- label: depth,
182
- }))}
183
- onSelected={(key) => {
184
- setDepthTypeState(depthType.options[key]);
185
- }}
186
- small
187
- value={depthType.options.indexOf(depthTypeState)}
188
- />
189
- <Spacer />
190
- </>
191
- ) : null}
192
-
193
- <Flex gap="8px" alignItems="center">
194
- <Button
195
- type="submit"
196
- small
197
- colored
198
- label={translations.done}
199
- disabled={!valid}
200
- />
201
- <Button
202
- small
203
- name="resetAxes"
204
- label={translations.resetAxes}
205
- onClick={onReset}
206
- disabled={!isCustomValue}
207
- />
208
- <Text small muted>
209
- {translations.orDoubleClickToCanvas}
210
- </Text>
211
- </Flex>
212
- </form>
213
- );
214
- };
215
-
216
- export const AxesOptions = ({
217
- initialAxesRanges,
218
- axes,
219
- controlsAxesLabels,
220
- onUpdateAxes,
221
- onResetAxes,
222
- depthType,
223
- translations,
224
- }) => {
225
- return (
226
- <Popover
227
- placement="bottom"
228
- overflowContainer
229
- content={
230
- <AxesOptionsPopover
231
- initialAxesRanges={initialAxesRanges}
232
- axes={axes}
233
- controlsAxesLabels={controlsAxesLabels}
234
- onUpdateAxes={onUpdateAxes}
235
- onResetAxes={onResetAxes}
236
- depthType={depthType}
237
- translations={translations}
238
- />
239
- }
240
- >
241
- <Tooltip
242
- text={translations.axesOptions}
243
- placement="bottom"
244
- display="flex"
245
- >
246
- <Button small basic colored="muted" round icon={<RiRuler2Line />} />
247
- </Tooltip>
248
- </Popover>
249
- );
250
- };
251
-
252
- AxesOptionsPopover.defaultProps = {
253
- depthType: null,
254
- initialAxesRanges: [],
255
- close: () => {},
256
- };
257
-
258
- AxesOptionsPopover.propTypes = {
259
- initialAxesRanges: PropTypes.arrayOf(PropTypes.shape({})),
260
- axes: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
261
- controlsAxesLabels: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
262
- onUpdateAxes: PropTypes.func.isRequired,
263
- onResetAxes: PropTypes.func.isRequired,
264
- close: PropTypes.func,
265
- depthType: PropTypes.shape({
266
- selectedDepthType: PropTypes.string,
267
- setSelectedDepthType: PropTypes.func,
268
- options: PropTypes.arrayOf(PropTypes.string),
269
- }),
270
- };
@@ -1,24 +0,0 @@
1
- export const defaultTranslations = Object.freeze({
2
- label: 'Label',
3
- pointsLines: 'Points & lines',
4
- linesOnly: 'Lines only',
5
- pointsOnly: 'Points only',
6
- axesOptions: 'Axes options',
7
- resetAxes: 'Reset Axes',
8
- done: 'Done',
9
- downloadAsPNG: 'Download as PNG',
10
- showChart: 'Show chart',
11
- showTable: 'Show table',
12
- dragToZoom: 'Drag to zoom',
13
- dragToPan: 'Drag to pan',
14
- dragToMovePoints: 'Drag to move points',
15
- dragDisabled: 'Drag disabled',
16
- hideLegend: 'Hide Legend',
17
- showLegend: 'Show Legend',
18
- mustHaveAValue: 'Must have a value',
19
- mustBeANumber: 'Must be a number',
20
- mustBeLessThanMax: 'Must be less than max',
21
- mustBeGreaterThanMin: 'Must be greater than min',
22
- doubleClickToReset: 'Double click on canvas to reset',
23
- orDoubleClickToCanvas: 'or double click on canvas',
24
- });
@@ -1,12 +0,0 @@
1
- export const DEFAULT_POINT_RADIUS = 2;
2
- export const DEFAULT_HOVER_RADIUS = 5;
3
- export const DEFAULT_BORDER_WIDTH = 1;
4
- export const BORDER_JOIN_STYLE = 'round';
5
- export const DEFAULT_LINE_POINT_RADIUS = 0;
6
- export const DEFAULT_BACKGROUND_COLOR = 'transparent';
7
- export const ZOOM_BOX_BACKGROUND_COLOR = 'rgba(0, 0, 0, 0.1)';
8
- export const DOUBLE_CLICK = 'dblclick';
9
- export const INIT_KEYS = {
10
- TRANSLATIONS: 'translations',
11
- LANGUAGE_KEY: 'languageKey',
12
- };
@@ -1,5 +0,0 @@
1
- export const actionTypes = Object.freeze({
2
- reset: 'reset',
3
- valueUpdated: 'valueUpdated',
4
- unitUpdated: 'unitUpdated',
5
- });
@@ -1,97 +0,0 @@
1
- import { produce } from 'immer';
2
- import { isGreaterThanMin, isLessThanMax } from '../../utils/line-chart-utils';
3
- import { actionTypes } from './action-types';
4
-
5
- /**
6
- * Initialize local component form state for a custom loads density table
7
- *
8
- * @param {Object} args
9
- * @param {Object} args.initialAxesRanges
10
- * @param {Array} [args.axes]
11
- * @returns {Object} formState
12
- */
13
- export const initializeFormState = ({ initialAxesRanges, axes = [] }) => {
14
- return initialAxesRanges.map((initialAxisRange) => {
15
- const currentAxisRange = axes.find((a) => a.id === initialAxisRange.id);
16
- return {
17
- id: initialAxisRange.id,
18
- min: currentAxisRange?.min ?? initialAxisRange?.min,
19
- max: currentAxisRange?.max ?? initialAxisRange?.max,
20
- unit: currentAxisRange?.unit,
21
- };
22
- });
23
- };
24
-
25
- /**
26
- * @typedef {Object} Action
27
- * @property {String} type Action type
28
- * @property {Object} [payload] Action payload (optional)
29
- */
30
-
31
- const isEmptyString = (value) => value === '';
32
-
33
- const createErrorMessages = (value, compareTo, type) => {
34
- const errors = [];
35
- if (isEmptyString(value)) errors.push('mustHaveAValue');
36
-
37
- if (type === 'min' && !isLessThanMax(value, compareTo)) {
38
- errors.push('mustBeLessThanMax');
39
- } else if (type === 'max' && !isGreaterThanMin(value, compareTo)) {
40
- errors.push('mustBeGreaterThanMin');
41
- }
42
-
43
- return errors;
44
- };
45
-
46
- export const validateAxes = (formState) => {
47
- return formState.reduce(
48
- (acc, { id, min, max }) => {
49
- return produce(acc, (draft) => {
50
- const errors = {
51
- min: createErrorMessages(min, max, 'min'),
52
- max: createErrorMessages(max, min, 'max'),
53
- };
54
- draft.errors.push({
55
- id,
56
- ...errors,
57
- });
58
- draft.valid = !(
59
- !acc.valid ||
60
- !!errors.min.length ||
61
- !!errors.max.length
62
- );
63
- });
64
- },
65
- { errors: [], valid: true },
66
- );
67
- };
68
-
69
- /**
70
- * Local component form state reducer for a axes options form
71
- *
72
- * @param {Object} state Local component form state
73
- * @param {Action} action Action with type and payload
74
- * @returns {Object} FormState
75
- */
76
- export const reducer = (state, action) => {
77
- switch (action.type) {
78
- case actionTypes.reset: {
79
- const { initialAxesRanges, axes } = action.payload;
80
- return initializeFormState({ initialAxesRanges, axes });
81
- }
82
- case actionTypes.valueUpdated:
83
- return produce(state, (draft) => {
84
- const { name, value, id } = action.payload;
85
- const axis = draft.find((a) => a.id === id);
86
- axis[name] = value;
87
- });
88
- case actionTypes.unitUpdated:
89
- return produce(state, (draft) => {
90
- const { name, value, id } = action.payload;
91
- const axis = draft.find((a) => a.id === id);
92
- axis.unit[name] = value;
93
- });
94
- default:
95
- return state;
96
- }
97
- };
@@ -1,174 +0,0 @@
1
- import React from 'react';
2
- import { Button, Text, Tooltip } from '@oliasoft-open-source/react-ui-library';
3
- import {
4
- RiFileDownloadLine,
5
- RiLineChartLine,
6
- RiTableLine,
7
- } from 'react-icons/ri';
8
- import PropTypes from 'prop-types';
9
- import { LineOptions } from './line-options';
10
- import { DragOptions } from './drag-options';
11
- import { LegendOptions } from './legend-options';
12
- import styles from './controls.module.less';
13
- import { useToggleHandlers } from '../hooks/use-toggle-handler';
14
- import { useChartFunctions } from '../hooks/use-chart-functions';
15
- import { AxesOptions } from '../../controls/axes-options/axes-options';
16
-
17
- const Controls = ({
18
- props: { headerComponent, subheaderComponent, table },
19
- chartRef,
20
- state,
21
- options,
22
- dispatch,
23
- generatedDatasets,
24
- translations,
25
- }) => {
26
- const {
27
- enableDragPoints,
28
- initialAxesRanges,
29
- legendEnabled,
30
- lineEnabled,
31
- panEnabled,
32
- pointsEnabled,
33
- showTable,
34
- zoomEnabled,
35
- } = state;
36
- const { dragData } = options;
37
- const {
38
- onToggleLegend,
39
- onToggleLine,
40
- onTogglePan,
41
- onTogglePoints,
42
- onToggleTable,
43
- onToggleZoom,
44
- onToggleDragPoints,
45
- onDisableDragOptions,
46
- } = useToggleHandlers(dispatch);
47
- const {
48
- handleDownload,
49
- controlsAxes,
50
- controlsAxesLabels,
51
- onResetAxes,
52
- onUpdateAxes,
53
- } = useChartFunctions({
54
- chartRef,
55
- state,
56
- options,
57
- dispatch,
58
- generatedDatasets,
59
- });
60
-
61
- return (
62
- <>
63
- <div className={styles.controls}>
64
- {!!options.title && <Text bold>{options.title}</Text>}
65
- {headerComponent}
66
- <div className={styles.buttons}>
67
- {!showTable && (
68
- <>
69
- <AxesOptions
70
- initialAxesRanges={initialAxesRanges}
71
- axes={controlsAxes}
72
- controlsAxesLabels={controlsAxesLabels}
73
- onUpdateAxes={onUpdateAxes}
74
- onResetAxes={onResetAxes}
75
- depthType={options.depthType}
76
- translations={translations}
77
- />
78
- <LineOptions
79
- lineEnabled={lineEnabled}
80
- pointsEnabled={pointsEnabled}
81
- onToggleLine={onToggleLine}
82
- onTogglePoints={onTogglePoints}
83
- translations={translations}
84
- />
85
- <LegendOptions
86
- legendEnabled={legendEnabled}
87
- onToggleLegend={onToggleLegend}
88
- translations={translations}
89
- />
90
- <Tooltip text={translations.downloadAsPNG} placement="bottom-end">
91
- <Button
92
- small
93
- basic
94
- colored="muted"
95
- round
96
- icon={<RiFileDownloadLine />}
97
- onClick={handleDownload}
98
- />
99
- </Tooltip>
100
- <DragOptions
101
- panEnabled={panEnabled}
102
- zoomEnabled={zoomEnabled}
103
- onTogglePan={onTogglePan}
104
- onToggleZoom={onToggleZoom}
105
- enableDragPoints={enableDragPoints}
106
- isDragDataAllowed={dragData.enableDragData}
107
- onToggleDragPoints={onToggleDragPoints}
108
- onDisableDragOptions={onDisableDragOptions}
109
- translations={translations}
110
- />
111
- </>
112
- )}
113
-
114
- {table ? (
115
- <Tooltip
116
- text={showTable ? translations.showChart : translations.showTable}
117
- placement="bottom-end"
118
- >
119
- <Button
120
- small
121
- basic
122
- colored="muted"
123
- round
124
- icon={showTable ? <RiLineChartLine /> : <RiTableLine />}
125
- onClick={onToggleTable}
126
- />
127
- </Tooltip>
128
- ) : null}
129
- </div>
130
- </div>
131
- {subheaderComponent}
132
- </>
133
- );
134
- };
135
-
136
- Controls.defaultProps = {
137
- props: {
138
- headerComponent: null,
139
- subheaderComponent: null,
140
- table: null,
141
- },
142
- state: {
143
- initialAxesRanges: [],
144
- },
145
- options: {},
146
- };
147
-
148
- Controls.propTypes = {
149
- props: PropTypes.shape({
150
- headerComponent: PropTypes.node,
151
- subheaderComponent: PropTypes.node,
152
- table: PropTypes.node,
153
- }),
154
- chartRef: PropTypes.object.isRequired,
155
- state: PropTypes.shape({
156
- enableDragPoints: PropTypes.bool,
157
- initialAxesRanges: PropTypes.arrayOf(PropTypes.shape({})),
158
- legendEnabled: PropTypes.bool,
159
- lineEnabled: PropTypes.bool,
160
- panEnabled: PropTypes.bool,
161
- pointsEnabled: PropTypes.bool,
162
- showTable: PropTypes.bool,
163
- zoomEnabled: PropTypes.bool,
164
- }),
165
- options: PropTypes.shape({
166
- dragData: PropTypes.shape({
167
- enableDragData: PropTypes.bool,
168
- }),
169
- }),
170
- dispatch: PropTypes.func.isRequired,
171
- generatedDatasets: PropTypes.arrayOf(PropTypes.object).isRequired,
172
- };
173
-
174
- export default Controls;
@@ -1,12 +0,0 @@
1
- .controls {
2
- display: flex;
3
- align-items: center;
4
- flex-wrap: wrap;
5
- gap: 8px;
6
- }
7
-
8
- .buttons {
9
- display: flex;
10
- margin-left: auto;
11
- gap: 4px;
12
- }
@@ -1,112 +0,0 @@
1
- import React, { useMemo } from 'react';
2
- import PropTypes from 'prop-types';
3
- import { Flex, Menu, Text } from '@oliasoft-open-source/react-ui-library';
4
- import { RiDragMove2Line, RiForbidLine, RiZoomInLine } from 'react-icons/ri';
5
- import { TbHandStop } from 'react-icons/tb';
6
-
7
- export const DragOptions = ({
8
- onTogglePan,
9
- onToggleZoom,
10
- panEnabled,
11
- zoomEnabled,
12
- enableDragPoints,
13
- isDragDataAllowed,
14
- onToggleDragPoints,
15
- onDisableDragOptions,
16
- translations: {
17
- dragToZoom,
18
- doubleClickToReset,
19
- dragToPan,
20
- orDoubleClickToCanvas,
21
- dragToMovePoints,
22
- dragDisabled,
23
- },
24
- }) => {
25
- const options = useMemo(
26
- () => [
27
- {
28
- buttonLabel: dragToZoom,
29
- label: (
30
- <Flex direction="column">
31
- <Text>Drag to zoom</Text>
32
- <Text small muted>
33
- {doubleClickToReset}
34
- </Text>
35
- </Flex>
36
- ),
37
- icon: <RiZoomInLine />,
38
- selected: zoomEnabled,
39
- onClick: onToggleZoom,
40
- },
41
- {
42
- buttonLabel: dragToPan,
43
- label: (
44
- <Flex direction="column">
45
- <Text>Drag to pan</Text>
46
- <Text small muted>
47
- {orDoubleClickToCanvas}
48
- </Text>
49
- </Flex>
50
- ),
51
- icon: <RiDragMove2Line />,
52
- selected: panEnabled,
53
- onClick: onTogglePan,
54
- },
55
- ...(isDragDataAllowed
56
- ? [
57
- {
58
- label: dragToMovePoints,
59
- icon: <TbHandStop />,
60
- selected: enableDragPoints,
61
- type: 'Option',
62
- onClick: onToggleDragPoints,
63
- },
64
- ]
65
- : []),
66
- {
67
- label: dragDisabled,
68
- icon: <RiForbidLine />,
69
- selected: !zoomEnabled && !panEnabled && !enableDragPoints,
70
- onClick: onDisableDragOptions,
71
- },
72
- ],
73
- [zoomEnabled, panEnabled, enableDragPoints, isDragDataAllowed],
74
- );
75
-
76
- const selectedOption = options.find((option) => option.selected);
77
- const optionsWithDragPoints = options.map(
78
- ({ icon, label, onClick, selected }) => ({
79
- icon,
80
- label,
81
- type: 'Option',
82
- onClick,
83
- disabled: selected,
84
- }),
85
- );
86
-
87
- return (
88
- <Menu
89
- menu={{
90
- label: selectedOption.buttonLabel || selectedOption.label,
91
- sections: optionsWithDragPoints,
92
- trigger: 'DropDownButton',
93
- small: true,
94
- }}
95
- />
96
- );
97
- };
98
-
99
- DragOptions.defaultProps = {
100
- enableDragPoints: false,
101
- };
102
-
103
- DragOptions.propTypes = {
104
- onTogglePan: PropTypes.func.isRequired,
105
- onToggleZoom: PropTypes.func.isRequired,
106
- panEnabled: PropTypes.bool.isRequired,
107
- zoomEnabled: PropTypes.bool.isRequired,
108
- enableDragPoints: PropTypes.bool,
109
- isDragDataAllowed: PropTypes.bool.isRequired,
110
- onToggleDragPoints: PropTypes.func.isRequired,
111
- onDisableDragOptions: PropTypes.func.isRequired,
112
- };