@oliasoft-open-source/charts-library 2.17.6 → 2.18.0-beta-2
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/dist/index.js +40398 -0
- package/dist/style.css +177 -0
- package/package.json +26 -34
- package/index.js +0 -14
- package/release-notes.md +0 -310
- package/src/assets/icons/line-and-point.svg +0 -1
- package/src/assets/icons/line-only.svg +0 -1
- package/src/assets/icons/list-hide.svg +0 -1
- package/src/assets/icons/point-only.svg +0 -1
- package/src/components/bar-chart/bar-chart-prop-types.js +0 -209
- package/src/components/bar-chart/bar-chart.interface.ts +0 -91
- package/src/components/bar-chart/bar-chart.jsx +0 -247
- package/src/components/bar-chart/bar-chart.module.less +0 -61
- package/src/components/bar-chart/get-bar-chart-data-labels.js +0 -42
- package/src/components/bar-chart/get-bar-chart-scales.js +0 -123
- package/src/components/bar-chart/get-bar-chart-tooltips.js +0 -102
- package/src/components/controls/axes-options/axes-options.jsx +0 -270
- package/src/components/line-chart/constants/default-translations.js +0 -24
- package/src/components/line-chart/constants/line-chart-consts.js +0 -12
- package/src/components/line-chart/controls/axes-options/action-types.js +0 -5
- package/src/components/line-chart/controls/axes-options/axes-options-form-state.js +0 -97
- package/src/components/line-chart/controls/controls.jsx +0 -174
- package/src/components/line-chart/controls/controls.module.less +0 -12
- package/src/components/line-chart/controls/drag-options.jsx +0 -112
- package/src/components/line-chart/controls/legend-options.jsx +0 -36
- package/src/components/line-chart/controls/line-options.jsx +0 -64
- package/src/components/line-chart/hooks/use-chart-functions.js +0 -257
- package/src/components/line-chart/hooks/use-chart-options.js +0 -181
- package/src/components/line-chart/hooks/use-chart-plugins.js +0 -35
- package/src/components/line-chart/hooks/use-toggle-handler.js +0 -33
- package/src/components/line-chart/initialize/config.js +0 -23
- package/src/components/line-chart/initialize/initialize-line-chart.js +0 -25
- package/src/components/line-chart/line-chart-prop-types.js +0 -292
- package/src/components/line-chart/line-chart.interface.ts +0 -121
- package/src/components/line-chart/line-chart.jsx +0 -161
- package/src/components/line-chart/line-chart.module.less +0 -77
- package/src/components/line-chart/plugins/chart-area-text-plugin.js +0 -246
- package/src/components/line-chart/plugins/line-chart.minor-gridlines-plugin.js +0 -88
- package/src/components/line-chart/plugins/plugin-constants.js +0 -11
- package/src/components/line-chart/state/action-types.js +0 -12
- package/src/components/line-chart/state/initial-state.js +0 -89
- package/src/components/line-chart/state/line-chart-reducer.js +0 -100
- package/src/components/line-chart/state/manage-state-in-local-storage.js +0 -86
- package/src/components/line-chart/state/use-chart-state.js +0 -141
- package/src/components/line-chart/utils/axis-scales/axis-scales.js +0 -165
- package/src/components/line-chart/utils/datalabels-alignment/get-alignment-condition.js +0 -13
- package/src/components/line-chart/utils/datalabels-alignment/get-alignment-data.js +0 -20
- package/src/components/line-chart/utils/datalabels-alignment/get-datalabels-position.js +0 -25
- package/src/components/line-chart/utils/generate-line-chart-datasets.js +0 -114
- package/src/components/line-chart/utils/get-axes-ranges-from-chart.js +0 -13
- package/src/components/line-chart/utils/get-line-chart-data-labels.js +0 -21
- package/src/components/line-chart/utils/get-line-chart-scales.js +0 -120
- package/src/components/line-chart/utils/get-line-chart-tooltips.js +0 -94
- package/src/components/line-chart/utils/line-chart-utils.js +0 -77
- package/src/components/line-chart/utils/translations/get-translations.js +0 -17
- package/src/components/pie-chart/pie-chart-prop-types.js +0 -111
- package/src/components/pie-chart/pie-chart-utils.js +0 -32
- package/src/components/pie-chart/pie-chart.interface.ts +0 -61
- package/src/components/pie-chart/pie-chart.jsx +0 -450
- package/src/components/pie-chart/pie-chart.module.less +0 -61
- package/src/components/scatter-chart/scatter-chart.intefrace.ts +0 -33
- package/src/components/scatter-chart/scatter-chart.jsx +0 -21
- package/src/components/scatter-chart/scatter-chart.module.less +0 -4
- package/src/helpers/chart-border-plugin.js +0 -19
- package/src/helpers/chart-consts.js +0 -64
- package/src/helpers/chart-interface.ts +0 -94
- package/src/helpers/chart-utils.js +0 -182
- package/src/helpers/container.jsx +0 -60
- package/src/helpers/disabled-context.js +0 -8
- package/src/helpers/enums.js +0 -96
- package/src/helpers/get-chart-annotation.js +0 -106
- package/src/helpers/get-custom-legend-plugin-example.js +0 -80
- package/src/helpers/get-draggableData.js +0 -32
- package/src/helpers/range/estimate-data-series-have-close-values.js +0 -54
- package/src/helpers/range/range.js +0 -100
- package/src/helpers/text.js +0 -6
- package/src/style/external.less +0 -4
- 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 +0 -27
- package/src/style/global.less +0 -43
- package/src/style/reset/reset.less +0 -28
- package/src/style/shared.less +0 -11
- package/src/style/variables.less +0 -91
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { AxisType, ScaleType } from '../../helpers/enums';
|
|
2
|
-
import {
|
|
3
|
-
getAxisPosition,
|
|
4
|
-
isVertical,
|
|
5
|
-
generateRandomColor,
|
|
6
|
-
} from '../../helpers/chart-utils';
|
|
7
|
-
import { COLORS, LOGARITHMIC_STEPS } from '../../helpers/chart-consts';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @param {import('./bar-chart.interface').IBarChartData} chart - chart data
|
|
11
|
-
* @param {'x'|'y'} axisType
|
|
12
|
-
* @param {import('./bar-chart.interface').IBarChartAxes} [currentScales]
|
|
13
|
-
*/
|
|
14
|
-
const getBarChartAxis = (chart, axisType, currentScales) => {
|
|
15
|
-
const isDirectionVertical = isVertical(chart.options.direction);
|
|
16
|
-
|
|
17
|
-
const axisData = currentScales || chart.options.axes[axisType][0];
|
|
18
|
-
const isDirectionCompatibleWithAxisType =
|
|
19
|
-
(isDirectionVertical && axisType === AxisType.Y) ||
|
|
20
|
-
(!isDirectionVertical && axisType === AxisType.X);
|
|
21
|
-
|
|
22
|
-
const grid = axisData?.gridLines || {};
|
|
23
|
-
|
|
24
|
-
const getScaleType = () => {
|
|
25
|
-
const scaleType = chart.data.labels ? ScaleType.Category : ScaleType.Linear;
|
|
26
|
-
const axisWithScale = isDirectionVertical ? AxisType.X : AxisType.Y;
|
|
27
|
-
return axisType === axisWithScale
|
|
28
|
-
? scaleType
|
|
29
|
-
: chart.options.additionalAxesOptions.chartScaleType;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const getReverse = () => {
|
|
33
|
-
const axisWithReverse = isDirectionVertical ? AxisType.Y : AxisType.X;
|
|
34
|
-
return axisType === axisWithReverse
|
|
35
|
-
? chart.options.additionalAxesOptions.reverse
|
|
36
|
-
: false;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const getTicks = () => {
|
|
40
|
-
const areLogarithmicTicks =
|
|
41
|
-
isDirectionCompatibleWithAxisType &&
|
|
42
|
-
chart.options.additionalAxesOptions.chartScaleType ===
|
|
43
|
-
ScaleType.Logarithmic;
|
|
44
|
-
|
|
45
|
-
if (areLogarithmicTicks) {
|
|
46
|
-
return {
|
|
47
|
-
callback: (tick) => {
|
|
48
|
-
return LOGARITHMIC_STEPS.includes(tick) ? tick.toLocaleString() : '';
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
} else {
|
|
52
|
-
return {
|
|
53
|
-
stepSize:
|
|
54
|
-
axisData.stepSize || chart.options.additionalAxesOptions.stepSize,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
type: getScaleType(),
|
|
61
|
-
position: axisData.position,
|
|
62
|
-
beginAtZero: chart.options.additionalAxesOptions.beginAtZero,
|
|
63
|
-
reverse: getReverse(),
|
|
64
|
-
suggestedMax: chart.options?.additionalAxesOptions?.suggestedMax,
|
|
65
|
-
suggestedMin: chart.options?.additionalAxesOptions?.suggestedMin,
|
|
66
|
-
min: isDirectionCompatibleWithAxisType
|
|
67
|
-
? chart.options?.additionalAxesOptions?.min
|
|
68
|
-
: undefined,
|
|
69
|
-
max: isDirectionCompatibleWithAxisType
|
|
70
|
-
? chart.options?.additionalAxesOptions?.max
|
|
71
|
-
: undefined,
|
|
72
|
-
title: {
|
|
73
|
-
display: axisData.label?.length || axisData.unit?.length,
|
|
74
|
-
text: axisData.label || axisData.unit,
|
|
75
|
-
padding: 0,
|
|
76
|
-
},
|
|
77
|
-
ticks: getTicks(),
|
|
78
|
-
grid: {
|
|
79
|
-
...grid,
|
|
80
|
-
},
|
|
81
|
-
stacked: chart.options.additionalAxesOptions.stacked,
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* @param {import('./bar-chart.interface').IBarChartData} chart - chart data
|
|
87
|
-
* @param {'x'|'y'} axisType
|
|
88
|
-
*/
|
|
89
|
-
const getBarChartAxes = (chart, axisType) => {
|
|
90
|
-
const axesData = chart.options.axes[axisType];
|
|
91
|
-
const axes = axesData.reduce((acc, curr, i) => {
|
|
92
|
-
const axisData = curr;
|
|
93
|
-
const color = curr.color || COLORS[i] || generateRandomColor(COLORS);
|
|
94
|
-
axisData.color = color;
|
|
95
|
-
axisData.position = curr.position || getAxisPosition(axisType, i);
|
|
96
|
-
|
|
97
|
-
const axis = getBarChartAxis(chart, axisType, axisData);
|
|
98
|
-
return { ...acc, [axisType + (i + 1)]: axis };
|
|
99
|
-
}, {});
|
|
100
|
-
return axes;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* @param {import('./bar-chart.interface').IBarChartData} chart - chart data
|
|
105
|
-
*/
|
|
106
|
-
const getBarChartScales = (chart) => {
|
|
107
|
-
const hasMultipleXAxes = chart.options.axes.x?.length > 1;
|
|
108
|
-
const hasMultipleYAxes = chart.options.axes.y?.length > 1;
|
|
109
|
-
|
|
110
|
-
const xAxesScales = hasMultipleXAxes
|
|
111
|
-
? getBarChartAxes(chart, AxisType.X)
|
|
112
|
-
: { x: getBarChartAxis(chart, AxisType.X) };
|
|
113
|
-
const yAxesScales = hasMultipleYAxes
|
|
114
|
-
? getBarChartAxes(chart, AxisType.Y)
|
|
115
|
-
: { y: getBarChartAxis(chart, AxisType.Y) };
|
|
116
|
-
|
|
117
|
-
return {
|
|
118
|
-
...xAxesScales,
|
|
119
|
-
...yAxesScales,
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
export default getBarChartScales;
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { toNum } from '@oliasoft-open-source/units';
|
|
2
|
-
import {
|
|
3
|
-
afterLabelCallback,
|
|
4
|
-
getTooltipLabel,
|
|
5
|
-
isVertical,
|
|
6
|
-
} from '../../helpers/chart-utils';
|
|
7
|
-
import { ChartHoverMode, TooltipLabel } from '../../helpers/enums';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @param {import('./bar-chart.interface').IBarChartOptions} options - bar chart options object
|
|
11
|
-
*/
|
|
12
|
-
const getBarChartToolTips = (options) => {
|
|
13
|
-
const getTooltipLabels = (dataset) => {
|
|
14
|
-
const isDirectionVertical = isVertical(options.direction);
|
|
15
|
-
const { x, y } = options.axes;
|
|
16
|
-
|
|
17
|
-
const xIndex = dataset.xAxisID?.length > 1 ? dataset.xAxisID[1] - 1 : 0;
|
|
18
|
-
const yIndex = dataset.yAxisID?.length > 1 ? dataset.yAxisID[1] - 1 : 0;
|
|
19
|
-
const xAxis = isDirectionVertical ? x[xIndex] : y[yIndex];
|
|
20
|
-
const yAxis = isDirectionVertical ? y[yIndex] : x[xIndex];
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
titleAxisLabel: xAxis?.label || '',
|
|
24
|
-
valueAxisLabel: yAxis?.label || '',
|
|
25
|
-
titleLabel: TooltipLabel.X,
|
|
26
|
-
valueLabel: TooltipLabel.Y,
|
|
27
|
-
titleUnit: xAxis?.unit || '',
|
|
28
|
-
valueUnit: yAxis?.unit || '',
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const titleCallback = (tooltipItem, data) => {
|
|
33
|
-
const barLabel = tooltipItem[0]?.label || '';
|
|
34
|
-
const labels = getTooltipLabels(tooltipItem[0].dataset);
|
|
35
|
-
const { titleAxisLabel, titleUnit } = labels;
|
|
36
|
-
const axisLabel =
|
|
37
|
-
!titleAxisLabel && !titleUnit ? '' : `${titleAxisLabel || titleUnit}: `;
|
|
38
|
-
return axisLabel + barLabel;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const labelCallback = (tooltipItem) => {
|
|
42
|
-
const { showLabelsInTooltips } = options.tooltip;
|
|
43
|
-
let label = tooltipItem.dataset?.label || '';
|
|
44
|
-
|
|
45
|
-
const labels = getTooltipLabels(tooltipItem.dataset);
|
|
46
|
-
const { valueUnit, valueAxisLabel } = labels;
|
|
47
|
-
|
|
48
|
-
const getTooltipItemValue = () => {
|
|
49
|
-
const { formattedValue } = tooltipItem;
|
|
50
|
-
const formattedValueWithDotSeparator = formattedValue.replace(',', '.');
|
|
51
|
-
const labelNumber = toNum(formattedValueWithDotSeparator);
|
|
52
|
-
|
|
53
|
-
let labelNumberFormatted;
|
|
54
|
-
if (Math.abs(labelNumber) < 1) {
|
|
55
|
-
labelNumberFormatted = labelNumber.toPrecision(3);
|
|
56
|
-
} else {
|
|
57
|
-
labelNumberFormatted = Number.isInteger(labelNumber)
|
|
58
|
-
? labelNumber
|
|
59
|
-
: labelNumber.toFixed(3);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
let tooltipItemValue = '';
|
|
63
|
-
if (typeof tooltipItem.raw === 'number') {
|
|
64
|
-
tooltipItemValue = labelNumberFormatted;
|
|
65
|
-
}
|
|
66
|
-
if (Array.isArray(tooltipItem.raw)) {
|
|
67
|
-
tooltipItemValue = tooltipItem.raw.reduce((acc, curr, i) => {
|
|
68
|
-
return i === 0 ? `${acc} ${curr}` : `${acc}, ${curr}`;
|
|
69
|
-
}, '');
|
|
70
|
-
}
|
|
71
|
-
if (typeof tooltipItem.raw === 'object') {
|
|
72
|
-
tooltipItemValue = formattedValue;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return tooltipItemValue;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const hideValueAxisLabel =
|
|
79
|
-
label === valueAxisLabel || valueAxisLabel.includes(label);
|
|
80
|
-
|
|
81
|
-
const tooltipItemValue = getTooltipItemValue();
|
|
82
|
-
const unit = valueUnit ? `[${valueUnit}] ` : '';
|
|
83
|
-
const valAxisLabel = hideValueAxisLabel ? '' : valueAxisLabel;
|
|
84
|
-
const tooltipLabel = getTooltipLabel(tooltipItem, showLabelsInTooltips);
|
|
85
|
-
|
|
86
|
-
return `${label}: ${tooltipItemValue} ${unit}${valAxisLabel}${tooltipLabel}`;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
enabled: options.tooltip.tooltips,
|
|
91
|
-
mode: ChartHoverMode.Nearest,
|
|
92
|
-
intersect: true,
|
|
93
|
-
padding: 8,
|
|
94
|
-
callbacks: {
|
|
95
|
-
title: titleCallback,
|
|
96
|
-
label: labelCallback,
|
|
97
|
-
afterLabel: afterLabelCallback,
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export default getBarChartToolTips;
|
|
@@ -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,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
|
-
};
|