@oliasoft-open-source/charts-library 2.14.1 → 2.15.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 +1 -1
- package/release-notes.md +3 -0
- package/src/components/controls/axes-options/axes-options.jsx +19 -6
- package/src/components/line-chart/constants/default-translations.js +24 -0
- package/src/components/line-chart/controls/axes-options/axes-options-form-state.js +4 -4
- package/src/components/line-chart/controls/controls.jsx +7 -2
- package/src/components/line-chart/controls/drag-options.jsx +14 -6
- package/src/components/line-chart/controls/legend-options.jsx +6 -2
- package/src/components/line-chart/controls/line-options.jsx +4 -3
- package/src/components/line-chart/line-chart.jsx +6 -2
- package/src/components/line-chart/utils/generate-line-chart-datasets.js +8 -2
- package/src/components/line-chart/utils/get-translations/get-translations.js +17 -0
package/package.json
CHANGED
package/release-notes.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Charts Library Release Notes
|
|
2
2
|
|
|
3
|
+
## 2.15.0
|
|
4
|
+
- Added translation, by provider handled([OW-11237](https://oliasoft.atlassian.net/browse/OW-11237))
|
|
5
|
+
|
|
3
6
|
## 2.14.1
|
|
4
7
|
- Fix save initAxesRange when dataset changed by parent component([OW-11332](https://oliasoft.atlassian.net/browse/OW-11332))
|
|
5
8
|
|
|
@@ -31,6 +31,7 @@ const AxesOptionsPopover = ({
|
|
|
31
31
|
onResetAxes,
|
|
32
32
|
close,
|
|
33
33
|
depthType,
|
|
34
|
+
translations,
|
|
34
35
|
}) => {
|
|
35
36
|
const [depthTypeState, setDepthTypeState] = useState(
|
|
36
37
|
depthType?.selectedDepthType,
|
|
@@ -124,7 +125,7 @@ const AxesOptionsPopover = ({
|
|
|
124
125
|
<Input
|
|
125
126
|
name="min"
|
|
126
127
|
value={min}
|
|
127
|
-
error={minError}
|
|
128
|
+
error={translations[minError]}
|
|
128
129
|
size={5}
|
|
129
130
|
width="100%"
|
|
130
131
|
onChange={(evt) =>
|
|
@@ -140,7 +141,7 @@ const AxesOptionsPopover = ({
|
|
|
140
141
|
<Input
|
|
141
142
|
name="max"
|
|
142
143
|
value={max}
|
|
143
|
-
error={maxError}
|
|
144
|
+
error={translations[maxError]}
|
|
144
145
|
size={5}
|
|
145
146
|
width="100%"
|
|
146
147
|
onChange={(evt) =>
|
|
@@ -190,16 +191,22 @@ const AxesOptionsPopover = ({
|
|
|
190
191
|
) : null}
|
|
191
192
|
|
|
192
193
|
<Flex gap="8px" alignItems="center">
|
|
193
|
-
<Button
|
|
194
|
+
<Button
|
|
195
|
+
type="submit"
|
|
196
|
+
small
|
|
197
|
+
colored
|
|
198
|
+
label={translations.done}
|
|
199
|
+
disabled={!valid}
|
|
200
|
+
/>
|
|
194
201
|
<Button
|
|
195
202
|
small
|
|
196
203
|
name="resetAxes"
|
|
197
|
-
label=
|
|
204
|
+
label={translations.resetAxes}
|
|
198
205
|
onClick={onReset}
|
|
199
206
|
disabled={!isCustomValue}
|
|
200
207
|
/>
|
|
201
208
|
<Text small muted>
|
|
202
|
-
|
|
209
|
+
{translations.orDoubleClickToCanvas}
|
|
203
210
|
</Text>
|
|
204
211
|
</Flex>
|
|
205
212
|
</form>
|
|
@@ -213,6 +220,7 @@ export const AxesOptions = ({
|
|
|
213
220
|
onUpdateAxes,
|
|
214
221
|
onResetAxes,
|
|
215
222
|
depthType,
|
|
223
|
+
translations,
|
|
216
224
|
}) => {
|
|
217
225
|
return (
|
|
218
226
|
<Popover
|
|
@@ -226,10 +234,15 @@ export const AxesOptions = ({
|
|
|
226
234
|
onUpdateAxes={onUpdateAxes}
|
|
227
235
|
onResetAxes={onResetAxes}
|
|
228
236
|
depthType={depthType}
|
|
237
|
+
translations={translations}
|
|
229
238
|
/>
|
|
230
239
|
}
|
|
231
240
|
>
|
|
232
|
-
<Tooltip
|
|
241
|
+
<Tooltip
|
|
242
|
+
text={translations.axesOptions}
|
|
243
|
+
placement="bottom"
|
|
244
|
+
display="flex"
|
|
245
|
+
>
|
|
233
246
|
<Button small basic colored="muted" round icon={<RiRuler2Line />} />
|
|
234
247
|
</Tooltip>
|
|
235
248
|
</Popover>
|
|
@@ -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
|
+
});
|
|
@@ -36,13 +36,13 @@ const isEmptyString = (value) => value === '';
|
|
|
36
36
|
|
|
37
37
|
const createErrorMessages = (value, compareTo, type) => {
|
|
38
38
|
const errors = [];
|
|
39
|
-
if (isEmptyString(value)) errors.push('
|
|
40
|
-
if (!validNumber(value)) errors.push('
|
|
39
|
+
if (isEmptyString(value)) errors.push('mustHaveAValue');
|
|
40
|
+
if (!validNumber(value)) errors.push('mustBeANumber');
|
|
41
41
|
|
|
42
42
|
if (type === 'min' && !isLessThanMax(value, compareTo)) {
|
|
43
|
-
errors.push('
|
|
43
|
+
errors.push('mustBeLessThanMax');
|
|
44
44
|
} else if (type === 'max' && !isGreaterThanMin(value, compareTo)) {
|
|
45
|
-
errors.push('
|
|
45
|
+
errors.push('mustBeGreaterThanMin');
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
return errors;
|
|
@@ -21,6 +21,7 @@ const Controls = ({
|
|
|
21
21
|
options,
|
|
22
22
|
dispatch,
|
|
23
23
|
generatedDatasets,
|
|
24
|
+
translations,
|
|
24
25
|
}) => {
|
|
25
26
|
const {
|
|
26
27
|
enableDragPoints,
|
|
@@ -72,18 +73,21 @@ const Controls = ({
|
|
|
72
73
|
onUpdateAxes={onUpdateAxes}
|
|
73
74
|
onResetAxes={onResetAxes}
|
|
74
75
|
depthType={options.depthType}
|
|
76
|
+
translations={translations}
|
|
75
77
|
/>
|
|
76
78
|
<LineOptions
|
|
77
79
|
lineEnabled={lineEnabled}
|
|
78
80
|
pointsEnabled={pointsEnabled}
|
|
79
81
|
onToggleLine={onToggleLine}
|
|
80
82
|
onTogglePoints={onTogglePoints}
|
|
83
|
+
translations={translations}
|
|
81
84
|
/>
|
|
82
85
|
<LegendOptions
|
|
83
86
|
legendEnabled={legendEnabled}
|
|
84
87
|
onToggleLegend={onToggleLegend}
|
|
88
|
+
translations={translations}
|
|
85
89
|
/>
|
|
86
|
-
<Tooltip text=
|
|
90
|
+
<Tooltip text={translations.downloadAsPNG} placement="bottom-end">
|
|
87
91
|
<Button
|
|
88
92
|
small
|
|
89
93
|
basic
|
|
@@ -102,13 +106,14 @@ const Controls = ({
|
|
|
102
106
|
isDragDataAllowed={dragData.enableDragData}
|
|
103
107
|
onToggleDragPoints={onToggleDragPoints}
|
|
104
108
|
onDisableDragOptions={onDisableDragOptions}
|
|
109
|
+
translations={translations}
|
|
105
110
|
/>
|
|
106
111
|
</>
|
|
107
112
|
)}
|
|
108
113
|
|
|
109
114
|
{table ? (
|
|
110
115
|
<Tooltip
|
|
111
|
-
text={showTable ?
|
|
116
|
+
text={showTable ? translations.showChart : translations.showTable}
|
|
112
117
|
placement="bottom-end"
|
|
113
118
|
>
|
|
114
119
|
<Button
|
|
@@ -13,16 +13,24 @@ export const DragOptions = ({
|
|
|
13
13
|
isDragDataAllowed,
|
|
14
14
|
onToggleDragPoints,
|
|
15
15
|
onDisableDragOptions,
|
|
16
|
+
translations: {
|
|
17
|
+
dragToZoom,
|
|
18
|
+
doubleClickToReset,
|
|
19
|
+
dragToPan,
|
|
20
|
+
orDoubleClickToCanvas,
|
|
21
|
+
dragToMovePoints,
|
|
22
|
+
dragDisabled,
|
|
23
|
+
},
|
|
16
24
|
}) => {
|
|
17
25
|
const options = useMemo(
|
|
18
26
|
() => [
|
|
19
27
|
{
|
|
20
|
-
buttonLabel:
|
|
28
|
+
buttonLabel: dragToZoom,
|
|
21
29
|
label: (
|
|
22
30
|
<Flex direction="column">
|
|
23
31
|
<Text>Drag to zoom</Text>
|
|
24
32
|
<Text small muted>
|
|
25
|
-
|
|
33
|
+
{doubleClickToReset}
|
|
26
34
|
</Text>
|
|
27
35
|
</Flex>
|
|
28
36
|
),
|
|
@@ -31,12 +39,12 @@ export const DragOptions = ({
|
|
|
31
39
|
onClick: onToggleZoom,
|
|
32
40
|
},
|
|
33
41
|
{
|
|
34
|
-
buttonLabel:
|
|
42
|
+
buttonLabel: dragToPan,
|
|
35
43
|
label: (
|
|
36
44
|
<Flex direction="column">
|
|
37
45
|
<Text>Drag to pan</Text>
|
|
38
46
|
<Text small muted>
|
|
39
|
-
|
|
47
|
+
{orDoubleClickToCanvas}
|
|
40
48
|
</Text>
|
|
41
49
|
</Flex>
|
|
42
50
|
),
|
|
@@ -47,7 +55,7 @@ export const DragOptions = ({
|
|
|
47
55
|
...(isDragDataAllowed
|
|
48
56
|
? [
|
|
49
57
|
{
|
|
50
|
-
label:
|
|
58
|
+
label: dragToMovePoints,
|
|
51
59
|
icon: <TbHandStop />,
|
|
52
60
|
selected: enableDragPoints,
|
|
53
61
|
type: 'Option',
|
|
@@ -56,7 +64,7 @@ export const DragOptions = ({
|
|
|
56
64
|
]
|
|
57
65
|
: []),
|
|
58
66
|
{
|
|
59
|
-
label:
|
|
67
|
+
label: dragDisabled,
|
|
60
68
|
icon: <RiForbidLine />,
|
|
61
69
|
selected: !zoomEnabled && !panEnabled && !enableDragPoints,
|
|
62
70
|
onClick: onDisableDragOptions,
|
|
@@ -4,8 +4,12 @@ import { Button, Icon, Tooltip } from '@oliasoft-open-source/react-ui-library';
|
|
|
4
4
|
import { RiListUnordered } from 'react-icons/ri';
|
|
5
5
|
import listHideIcon from '../../../assets/icons/list-hide.svg';
|
|
6
6
|
|
|
7
|
-
export const LegendOptions = ({
|
|
8
|
-
|
|
7
|
+
export const LegendOptions = ({
|
|
8
|
+
legendEnabled,
|
|
9
|
+
onToggleLegend,
|
|
10
|
+
translations: { hideLegend, showLegend },
|
|
11
|
+
}) => {
|
|
12
|
+
const tooltipText = legendEnabled ? hideLegend : showLegend;
|
|
9
13
|
const icon = legendEnabled ? (
|
|
10
14
|
<RiListUnordered />
|
|
11
15
|
) : (
|
|
@@ -10,10 +10,11 @@ export const LineOptions = ({
|
|
|
10
10
|
onToggleLine,
|
|
11
11
|
onTogglePoints,
|
|
12
12
|
pointsEnabled,
|
|
13
|
+
translations,
|
|
13
14
|
}) => {
|
|
14
15
|
const options = [
|
|
15
16
|
{
|
|
16
|
-
label:
|
|
17
|
+
label: translations.pointsLines,
|
|
17
18
|
icon: <Icon icon={lineAndPointIcon} />,
|
|
18
19
|
selected: pointsEnabled && lineEnabled,
|
|
19
20
|
onClick: () => {
|
|
@@ -21,7 +22,7 @@ export const LineOptions = ({
|
|
|
21
22
|
},
|
|
22
23
|
},
|
|
23
24
|
{
|
|
24
|
-
label:
|
|
25
|
+
label: translations.linesOnly,
|
|
25
26
|
icon: <Icon icon={lineOnlyIcon} />,
|
|
26
27
|
selected: !pointsEnabled && lineEnabled,
|
|
27
28
|
onClick: () => {
|
|
@@ -30,7 +31,7 @@ export const LineOptions = ({
|
|
|
30
31
|
},
|
|
31
32
|
},
|
|
32
33
|
{
|
|
33
|
-
label:
|
|
34
|
+
label: translations.pointsOnly,
|
|
34
35
|
icon: <Icon icon={pointOnlyIcon} />,
|
|
35
36
|
selected: pointsEnabled && !lineEnabled,
|
|
36
37
|
onClick: () => {
|
|
@@ -29,6 +29,8 @@ import { useChartOptions } from './hooks/use-chart-options';
|
|
|
29
29
|
import { useChartPlugins } from './hooks/use-chart-plugins';
|
|
30
30
|
import { generateKey } from './utils/line-chart-utils';
|
|
31
31
|
import { useChartState } from './state/use-chart-state';
|
|
32
|
+
import { defaultTranslations } from './constants/default-translations';
|
|
33
|
+
import { getTranslations } from './utils/get-translations/get-translations';
|
|
32
34
|
|
|
33
35
|
ChartJS.register(
|
|
34
36
|
LinearScale,
|
|
@@ -53,7 +55,8 @@ ChartJS.register(
|
|
|
53
55
|
const LineChart = (props) => {
|
|
54
56
|
setDefaultTheme();
|
|
55
57
|
const chartRef = useRef(null);
|
|
56
|
-
const { table } = props;
|
|
58
|
+
const { table, translations: translationsRaw } = props;
|
|
59
|
+
const translations = getTranslations(translationsRaw);
|
|
57
60
|
const chart = getDefaultProps(props);
|
|
58
61
|
const {
|
|
59
62
|
data: { datasets },
|
|
@@ -76,7 +79,7 @@ const LineChart = (props) => {
|
|
|
76
79
|
);
|
|
77
80
|
|
|
78
81
|
const generatedDatasets = useMemo(() => {
|
|
79
|
-
return generateLineChartDatasets(datasets, state, options);
|
|
82
|
+
return generateLineChartDatasets(datasets, state, options, translations);
|
|
80
83
|
}, [state.lineEnabled, state.pointsEnabled, axes, annotations, graph]);
|
|
81
84
|
|
|
82
85
|
// Call the custom hooks.
|
|
@@ -132,6 +135,7 @@ const LineChart = (props) => {
|
|
|
132
135
|
options={options}
|
|
133
136
|
dispatch={dispatch}
|
|
134
137
|
generatedDatasets={generatedDatasets}
|
|
138
|
+
translations={translations}
|
|
135
139
|
/>
|
|
136
140
|
{table && state.showTable ? (
|
|
137
141
|
<div className={styles.table}>{table}</div>
|
|
@@ -15,9 +15,15 @@ import { generateRandomColor } from '../../../helpers/chart-utils';
|
|
|
15
15
|
* @param {Array} datasets - The initial datasets for the line chart.
|
|
16
16
|
* @param {Object} state - The state object containing chart settings (e.g., lineEnabled, pointsEnabled, axes).
|
|
17
17
|
* @param {Object} options - The options object containing additional settings (e.g., annotations, graph).
|
|
18
|
+
* @param {Object} translations - The translations object with the label property
|
|
18
19
|
* @returns {Array} - The generated line chart datasets with applied settings and configurations.
|
|
19
20
|
*/
|
|
20
|
-
export const generateLineChartDatasets = (
|
|
21
|
+
export const generateLineChartDatasets = (
|
|
22
|
+
datasets,
|
|
23
|
+
state,
|
|
24
|
+
options,
|
|
25
|
+
{ label },
|
|
26
|
+
) => {
|
|
21
27
|
const copyDataset = [...datasets];
|
|
22
28
|
const { annotations, graph } = options;
|
|
23
29
|
const {
|
|
@@ -88,7 +94,7 @@ export const generateLineChartDatasets = (datasets, state, options) => {
|
|
|
88
94
|
// Return the dataset with applied settings and configurations
|
|
89
95
|
return {
|
|
90
96
|
...line,
|
|
91
|
-
label: line.label ||
|
|
97
|
+
label: line.label || `${label} ${i + 1}`,
|
|
92
98
|
data: filteredData,
|
|
93
99
|
showLine: lineEnabled,
|
|
94
100
|
lineTension,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defaultTranslations } from '../../constants/default-translations';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Merges custom translations with the default translations.
|
|
5
|
+
* If a custom translation is provided for a key, it will override the default one.
|
|
6
|
+
* @param {object} translations - Custom translations.
|
|
7
|
+
* @returns {object} - The resulting translations object, containing both default and custom translations.
|
|
8
|
+
*/
|
|
9
|
+
export const getTranslations = (translations = {}) => {
|
|
10
|
+
return Object.keys(defaultTranslations).reduce(
|
|
11
|
+
(acc, key) => ({
|
|
12
|
+
...acc,
|
|
13
|
+
[key]: translations[key] || defaultTranslations[key],
|
|
14
|
+
}),
|
|
15
|
+
{},
|
|
16
|
+
);
|
|
17
|
+
};
|