@oliasoft-open-source/charts-library 3.3.6-beta-3 → 3.3.6-beta-5
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/index.js +14 -0
- package/package.json +1 -6
- package/release-notes.md +378 -0
- package/src/assets/circle.svg +1 -0
- package/src/assets/icons/line-and-point.svg +1 -0
- package/src/assets/icons/line-only.svg +1 -0
- package/src/assets/icons/list-hide.svg +1 -0
- package/src/assets/icons/point-only.svg +1 -0
- package/src/assets/rect.svg +1 -0
- package/src/assets/rectRot.svg +1 -0
- package/src/assets/triangle.svg +1 -0
- package/src/components/bar-chart/bar-chart-prop-types.js +209 -0
- package/src/components/bar-chart/bar-chart.interface.ts +98 -0
- package/src/components/bar-chart/bar-chart.jsx +247 -0
- package/src/components/bar-chart/bar-chart.module.less +61 -0
- package/src/components/bar-chart/get-bar-chart-data-labels.js +42 -0
- package/src/components/bar-chart/get-bar-chart-scales.js +138 -0
- package/src/components/bar-chart/get-bar-chart-tooltips.js +102 -0
- package/src/components/controls/axes-options/axes-options.jsx +271 -0
- package/src/components/line-chart/constants/default-translations.js +24 -0
- package/src/components/line-chart/constants/line-chart-consts.js +12 -0
- package/src/components/line-chart/controls/axes-options/action-types.js +5 -0
- package/src/components/line-chart/controls/axes-options/axes-options-form-state.js +97 -0
- package/src/components/line-chart/controls/controls-portal.jsx +12 -0
- package/src/components/line-chart/controls/controls.jsx +176 -0
- package/src/components/line-chart/controls/controls.module.less +12 -0
- package/src/components/line-chart/controls/drag-options.jsx +124 -0
- package/src/components/line-chart/controls/line-options.jsx +64 -0
- package/src/components/line-chart/hooks/use-chart-functions.js +261 -0
- package/src/components/line-chart/hooks/use-chart-options.js +181 -0
- package/src/components/line-chart/hooks/use-chart-plugins.js +35 -0
- package/src/components/line-chart/hooks/use-toggle-handler.js +33 -0
- package/src/components/line-chart/initialize/config.js +23 -0
- package/src/components/line-chart/initialize/initialize-line-chart.js +25 -0
- package/src/components/line-chart/legend/legend-constants.js +1 -0
- package/src/components/line-chart/legend/legend-dropzone.jsx +74 -0
- package/src/components/line-chart/legend/legend-item.jsx +105 -0
- package/src/components/line-chart/legend/legend-panel.jsx +86 -0
- package/src/components/line-chart/legend/legend.jsx +54 -0
- package/src/components/line-chart/legend/legend.module.less +192 -0
- package/src/components/line-chart/line-chart-prop-types.js +298 -0
- package/src/components/line-chart/line-chart.interface.ts +128 -0
- package/src/components/line-chart/line-chart.jsx +180 -0
- package/src/components/line-chart/line-chart.module.less +78 -0
- package/src/components/line-chart/plugins/chart-area-text-plugin.js +246 -0
- package/src/components/line-chart/plugins/line-chart.minor-gridlines-plugin.js +88 -0
- package/src/components/line-chart/plugins/plugin-constants.js +11 -0
- package/src/components/line-chart/state/action-types.js +12 -0
- package/src/components/line-chart/state/initial-state.js +89 -0
- package/src/components/line-chart/state/line-chart-reducer.js +101 -0
- package/src/components/line-chart/state/manage-state-in-local-storage.js +86 -0
- package/src/components/line-chart/state/use-chart-state.js +141 -0
- package/src/components/line-chart/utils/axis-formatting/axis-formatting.js +69 -0
- package/src/components/line-chart/utils/axis-scales/axis-scales.js +165 -0
- package/src/components/line-chart/utils/datalabels-alignment/get-alignment-condition.js +13 -0
- package/src/components/line-chart/utils/datalabels-alignment/get-alignment-data.js +20 -0
- package/src/components/line-chart/utils/datalabels-alignment/get-datalabels-position.js +25 -0
- package/src/components/line-chart/utils/generate-line-chart-datasets.js +122 -0
- package/src/components/line-chart/utils/get-axes-ranges-from-chart.js +13 -0
- package/src/components/line-chart/utils/get-line-chart-data-labels.js +21 -0
- package/src/components/line-chart/utils/get-line-chart-scales.js +117 -0
- package/src/components/line-chart/utils/get-line-chart-tooltips.js +94 -0
- package/src/components/line-chart/utils/line-chart-utils.js +62 -0
- package/src/components/line-chart/utils/translations/get-translations.js +17 -0
- package/src/components/pie-chart/pie-chart-prop-types.js +111 -0
- package/src/components/pie-chart/pie-chart-utils.js +32 -0
- package/src/components/pie-chart/pie-chart.interface.ts +61 -0
- package/src/components/pie-chart/pie-chart.jsx +458 -0
- package/src/components/pie-chart/pie-chart.module.less +61 -0
- package/src/components/scatter-chart/scatter-chart.intefrace.ts +33 -0
- package/src/components/scatter-chart/scatter-chart.jsx +21 -0
- package/src/components/scatter-chart/scatter-chart.module.less +4 -0
- package/src/helpers/chart-border-plugin.js +19 -0
- package/src/helpers/chart-consts.js +64 -0
- package/src/helpers/chart-interface.ts +94 -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 +107 -0
- package/src/helpers/get-chart-annotation.js +102 -0
- package/src/helpers/get-custom-legend-plugin-example.js +80 -0
- package/src/helpers/get-draggableData.js +32 -0
- package/src/helpers/range/estimate-data-series-have-close-values.js +54 -0
- package/src/helpers/range/range.js +100 -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 +11 -0
- package/src/style/variables.less +91 -0
- package/vite.config.mjs +49 -0
- package/vitest.config.mjs +8 -0
- package/dist/index.js +0 -39189
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,271 @@
|
|
|
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 width="300px">
|
|
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
|
+
autoLayerWidth
|
|
169
|
+
width="15%"
|
|
170
|
+
/>
|
|
171
|
+
) : null}
|
|
172
|
+
</InputGroup>
|
|
173
|
+
</Field>
|
|
174
|
+
);
|
|
175
|
+
})}
|
|
176
|
+
|
|
177
|
+
{depthType?.options?.length > 0 ? (
|
|
178
|
+
<>
|
|
179
|
+
<ButtonGroup
|
|
180
|
+
items={depthType.options.map((depth, i) => ({
|
|
181
|
+
key: i,
|
|
182
|
+
label: depth,
|
|
183
|
+
}))}
|
|
184
|
+
onSelected={(key) => {
|
|
185
|
+
setDepthTypeState(depthType.options[key]);
|
|
186
|
+
}}
|
|
187
|
+
small
|
|
188
|
+
value={depthType.options.indexOf(depthTypeState)}
|
|
189
|
+
/>
|
|
190
|
+
<Spacer />
|
|
191
|
+
</>
|
|
192
|
+
) : null}
|
|
193
|
+
|
|
194
|
+
<Flex gap="8px" alignItems="center">
|
|
195
|
+
<Button
|
|
196
|
+
type="submit"
|
|
197
|
+
small
|
|
198
|
+
colored
|
|
199
|
+
label={translations.done}
|
|
200
|
+
disabled={!valid}
|
|
201
|
+
/>
|
|
202
|
+
<Button
|
|
203
|
+
small
|
|
204
|
+
name="resetAxes"
|
|
205
|
+
label={translations.resetAxes}
|
|
206
|
+
onClick={onReset}
|
|
207
|
+
disabled={!isCustomValue}
|
|
208
|
+
/>
|
|
209
|
+
<Text small muted>
|
|
210
|
+
{translations.orDoubleClickToCanvas}
|
|
211
|
+
</Text>
|
|
212
|
+
</Flex>
|
|
213
|
+
</form>
|
|
214
|
+
);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export const AxesOptions = ({
|
|
218
|
+
initialAxesRanges,
|
|
219
|
+
axes,
|
|
220
|
+
controlsAxesLabels,
|
|
221
|
+
onUpdateAxes,
|
|
222
|
+
onResetAxes,
|
|
223
|
+
depthType,
|
|
224
|
+
translations,
|
|
225
|
+
}) => {
|
|
226
|
+
return (
|
|
227
|
+
<Popover
|
|
228
|
+
placement="bottom"
|
|
229
|
+
overflowContainer
|
|
230
|
+
content={
|
|
231
|
+
<AxesOptionsPopover
|
|
232
|
+
initialAxesRanges={initialAxesRanges}
|
|
233
|
+
axes={axes}
|
|
234
|
+
controlsAxesLabels={controlsAxesLabels}
|
|
235
|
+
onUpdateAxes={onUpdateAxes}
|
|
236
|
+
onResetAxes={onResetAxes}
|
|
237
|
+
depthType={depthType}
|
|
238
|
+
translations={translations}
|
|
239
|
+
/>
|
|
240
|
+
}
|
|
241
|
+
>
|
|
242
|
+
<Tooltip
|
|
243
|
+
text={translations.axesOptions}
|
|
244
|
+
placement="bottom"
|
|
245
|
+
display="flex"
|
|
246
|
+
>
|
|
247
|
+
<Button small basic colored="muted" round icon={<RiRuler2Line />} />
|
|
248
|
+
</Tooltip>
|
|
249
|
+
</Popover>
|
|
250
|
+
);
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
AxesOptionsPopover.defaultProps = {
|
|
254
|
+
depthType: null,
|
|
255
|
+
initialAxesRanges: [],
|
|
256
|
+
close: () => {},
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
AxesOptionsPopover.propTypes = {
|
|
260
|
+
initialAxesRanges: PropTypes.arrayOf(PropTypes.shape({})),
|
|
261
|
+
axes: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
|
|
262
|
+
controlsAxesLabels: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
|
|
263
|
+
onUpdateAxes: PropTypes.func.isRequired,
|
|
264
|
+
onResetAxes: PropTypes.func.isRequired,
|
|
265
|
+
close: PropTypes.func,
|
|
266
|
+
depthType: PropTypes.shape({
|
|
267
|
+
selectedDepthType: PropTypes.string,
|
|
268
|
+
setSelectedDepthType: PropTypes.func,
|
|
269
|
+
options: PropTypes.arrayOf(PropTypes.string),
|
|
270
|
+
}),
|
|
271
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Portal } from '@oliasoft-open-source/react-ui-library';
|
|
3
|
+
|
|
4
|
+
const ControlsPortal = ({ children, controlsPortalId }) => {
|
|
5
|
+
if (controlsPortalId && document.getElementById(controlsPortalId)) {
|
|
6
|
+
return <Portal id={controlsPortalId}>{children}</Portal>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return children;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default ControlsPortal;
|
|
@@ -0,0 +1,176 @@
|
|
|
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 styles from './controls.module.less';
|
|
12
|
+
import { useToggleHandlers } from '../hooks/use-toggle-handler';
|
|
13
|
+
import { useChartFunctions } from '../hooks/use-chart-functions';
|
|
14
|
+
import { AxesOptions } from '../../controls/axes-options/axes-options';
|
|
15
|
+
import ControlsPortal from './controls-portal';
|
|
16
|
+
|
|
17
|
+
const Controls = ({
|
|
18
|
+
props: { headerComponent, subheaderComponent, table },
|
|
19
|
+
chartRef,
|
|
20
|
+
state,
|
|
21
|
+
options,
|
|
22
|
+
dispatch,
|
|
23
|
+
generatedDatasets,
|
|
24
|
+
translations,
|
|
25
|
+
controlsPortalId,
|
|
26
|
+
}) => {
|
|
27
|
+
const {
|
|
28
|
+
enableDragPoints,
|
|
29
|
+
initialAxesRanges,
|
|
30
|
+
lineEnabled,
|
|
31
|
+
panEnabled,
|
|
32
|
+
pointsEnabled,
|
|
33
|
+
showTable,
|
|
34
|
+
zoomEnabled,
|
|
35
|
+
} = state;
|
|
36
|
+
const { dragData } = options;
|
|
37
|
+
const {
|
|
38
|
+
onToggleLine,
|
|
39
|
+
onTogglePan,
|
|
40
|
+
onTogglePoints,
|
|
41
|
+
onToggleTable,
|
|
42
|
+
onToggleZoom,
|
|
43
|
+
onToggleDragPoints,
|
|
44
|
+
onDisableDragOptions,
|
|
45
|
+
} = useToggleHandlers(dispatch);
|
|
46
|
+
const {
|
|
47
|
+
handleDownload,
|
|
48
|
+
controlsAxes,
|
|
49
|
+
controlsAxesLabels,
|
|
50
|
+
onResetAxes,
|
|
51
|
+
onUpdateAxes,
|
|
52
|
+
} = useChartFunctions({
|
|
53
|
+
chartRef,
|
|
54
|
+
state,
|
|
55
|
+
options,
|
|
56
|
+
dispatch,
|
|
57
|
+
generatedDatasets,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<>
|
|
62
|
+
<div className={styles.controls}>
|
|
63
|
+
{!!options.title && <Text bold>{options.title}</Text>}
|
|
64
|
+
{headerComponent}
|
|
65
|
+
<ControlsPortal controlsPortalId={controlsPortalId}>
|
|
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
|
+
<Tooltip
|
|
86
|
+
text={translations.downloadAsPNG}
|
|
87
|
+
placement="bottom-end"
|
|
88
|
+
>
|
|
89
|
+
<Button
|
|
90
|
+
small
|
|
91
|
+
basic
|
|
92
|
+
colored="muted"
|
|
93
|
+
round
|
|
94
|
+
icon={<RiFileDownloadLine />}
|
|
95
|
+
onClick={handleDownload}
|
|
96
|
+
/>
|
|
97
|
+
</Tooltip>
|
|
98
|
+
<DragOptions
|
|
99
|
+
panEnabled={panEnabled}
|
|
100
|
+
zoomEnabled={zoomEnabled}
|
|
101
|
+
onTogglePan={onTogglePan}
|
|
102
|
+
onToggleZoom={onToggleZoom}
|
|
103
|
+
enableDragPoints={enableDragPoints}
|
|
104
|
+
isDragDataAllowed={dragData.enableDragData}
|
|
105
|
+
onToggleDragPoints={onToggleDragPoints}
|
|
106
|
+
onDisableDragOptions={onDisableDragOptions}
|
|
107
|
+
translations={translations}
|
|
108
|
+
/>
|
|
109
|
+
</>
|
|
110
|
+
)}
|
|
111
|
+
|
|
112
|
+
{table ? (
|
|
113
|
+
<Tooltip
|
|
114
|
+
text={
|
|
115
|
+
showTable ? translations.showChart : translations.showTable
|
|
116
|
+
}
|
|
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
|
+
</ControlsPortal>
|
|
131
|
+
</div>
|
|
132
|
+
{subheaderComponent}
|
|
133
|
+
</>
|
|
134
|
+
);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
Controls.defaultProps = {
|
|
138
|
+
props: {
|
|
139
|
+
headerComponent: null,
|
|
140
|
+
subheaderComponent: null,
|
|
141
|
+
table: null,
|
|
142
|
+
controlsPortalId: null,
|
|
143
|
+
},
|
|
144
|
+
state: {
|
|
145
|
+
initialAxesRanges: [],
|
|
146
|
+
},
|
|
147
|
+
options: {},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
Controls.propTypes = {
|
|
151
|
+
props: PropTypes.shape({
|
|
152
|
+
headerComponent: PropTypes.node,
|
|
153
|
+
subheaderComponent: PropTypes.node,
|
|
154
|
+
table: PropTypes.node,
|
|
155
|
+
controlsPortalId: PropTypes.string,
|
|
156
|
+
}),
|
|
157
|
+
chartRef: PropTypes.object.isRequired,
|
|
158
|
+
state: PropTypes.shape({
|
|
159
|
+
enableDragPoints: PropTypes.bool,
|
|
160
|
+
initialAxesRanges: PropTypes.arrayOf(PropTypes.shape({})),
|
|
161
|
+
lineEnabled: PropTypes.bool,
|
|
162
|
+
panEnabled: PropTypes.bool,
|
|
163
|
+
pointsEnabled: PropTypes.bool,
|
|
164
|
+
showTable: PropTypes.bool,
|
|
165
|
+
zoomEnabled: PropTypes.bool,
|
|
166
|
+
}),
|
|
167
|
+
options: PropTypes.shape({
|
|
168
|
+
dragData: PropTypes.shape({
|
|
169
|
+
enableDragData: PropTypes.bool,
|
|
170
|
+
}),
|
|
171
|
+
}),
|
|
172
|
+
dispatch: PropTypes.func.isRequired,
|
|
173
|
+
generatedDatasets: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export default Controls;
|