@oliasoft-open-source/charts-library 3.3.6-beta-5 → 3.3.6
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 +39230 -0
- package/dist/index.js.map +1 -0
- package/package.json +6 -1
- package/index.js +0 -14
- package/release-notes.md +0 -378
- package/src/assets/circle.svg +0 -1
- 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/assets/rect.svg +0 -1
- package/src/assets/rectRot.svg +0 -1
- package/src/assets/triangle.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 -98
- 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 -138
- package/src/components/bar-chart/get-bar-chart-tooltips.js +0 -102
- package/src/components/controls/axes-options/axes-options.jsx +0 -271
- 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-portal.jsx +0 -12
- package/src/components/line-chart/controls/controls.jsx +0 -176
- package/src/components/line-chart/controls/controls.module.less +0 -12
- package/src/components/line-chart/controls/drag-options.jsx +0 -124
- package/src/components/line-chart/controls/line-options.jsx +0 -64
- package/src/components/line-chart/hooks/use-chart-functions.js +0 -261
- 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/legend/legend-constants.js +0 -1
- package/src/components/line-chart/legend/legend-dropzone.jsx +0 -74
- package/src/components/line-chart/legend/legend-item.jsx +0 -105
- package/src/components/line-chart/legend/legend-panel.jsx +0 -86
- package/src/components/line-chart/legend/legend.jsx +0 -54
- package/src/components/line-chart/legend/legend.module.less +0 -192
- package/src/components/line-chart/line-chart-prop-types.js +0 -298
- package/src/components/line-chart/line-chart.interface.ts +0 -128
- package/src/components/line-chart/line-chart.jsx +0 -180
- package/src/components/line-chart/line-chart.module.less +0 -78
- 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 -101
- 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-formatting/axis-formatting.js +0 -69
- 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 -122
- 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 -117
- package/src/components/line-chart/utils/get-line-chart-tooltips.js +0 -94
- package/src/components/line-chart/utils/line-chart-utils.js +0 -62
- 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 -458
- 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 -178
- package/src/helpers/container.jsx +0 -60
- package/src/helpers/disabled-context.js +0 -8
- package/src/helpers/enums.js +0 -107
- package/src/helpers/get-chart-annotation.js +0 -102
- 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
- package/vite.config.mjs +0 -49
- package/vitest.config.mjs +0 -8
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
generateRandomColor,
|
|
3
|
-
getAxisPosition,
|
|
4
|
-
} from '../../../helpers/chart-utils';
|
|
5
|
-
import { COLORS, LOGARITHMIC_STEPS } from '../../../helpers/chart-consts';
|
|
6
|
-
import { generateAxisId } from './line-chart-utils';
|
|
7
|
-
import { AxisType, ScaleType } from '../../../helpers/enums';
|
|
8
|
-
import { formatAxisLabelNumbers } from './axis-formatting/axis-formatting';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @param {import('../line-chart.interface').ILineChartOptions} options - line chart options object
|
|
12
|
-
* @param {'x'|'y'} axisType
|
|
13
|
-
* @param {import('../../../helpers/chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
|
|
14
|
-
* @param {import('../line-chart.interface').ILineChartAxis[]} [currentScales]
|
|
15
|
-
* @param {number} [i]
|
|
16
|
-
*/
|
|
17
|
-
const getLineChartAxis = (options, axisType, state, currentScales, i = 0) => {
|
|
18
|
-
const axisData = currentScales || options.axes[axisType][0];
|
|
19
|
-
const stateAxis = state.axes.filter((axis) => axis.id.startsWith(axisType))[
|
|
20
|
-
i
|
|
21
|
-
];
|
|
22
|
-
const ticksConfigFromProps =
|
|
23
|
-
options?.scales?.[`${i === 0 ? axisType : axisType + i}`]?.ticks;
|
|
24
|
-
const { additionalAxesOptions } = options;
|
|
25
|
-
|
|
26
|
-
const getTicks = () => {
|
|
27
|
-
const isLogarithmic =
|
|
28
|
-
additionalAxesOptions?.chartScaleType === ScaleType.Logarithmic;
|
|
29
|
-
const ticksFormattingCallback = (tick, _index, ticks) => {
|
|
30
|
-
return isLogarithmic
|
|
31
|
-
? LOGARITHMIC_STEPS.includes(tick)
|
|
32
|
-
? formatAxisLabelNumbers(tick, ticks)
|
|
33
|
-
: ''
|
|
34
|
-
: formatAxisLabelNumbers(tick, ticks);
|
|
35
|
-
};
|
|
36
|
-
const stepSize = !isLogarithmic
|
|
37
|
-
? {
|
|
38
|
-
stepSize:
|
|
39
|
-
axisData.stepSize ??
|
|
40
|
-
(axisType === AxisType.Y ? additionalAxesOptions.stepSize : null),
|
|
41
|
-
}
|
|
42
|
-
: {};
|
|
43
|
-
const ticks = {
|
|
44
|
-
...stepSize,
|
|
45
|
-
callback: ticksFormattingCallback,
|
|
46
|
-
includeBounds: false, //OW-10088 disable irregular axis ticks
|
|
47
|
-
...ticksConfigFromProps,
|
|
48
|
-
font: {
|
|
49
|
-
size: 14,
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
return ticks;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
type: additionalAxesOptions.chartScaleType,
|
|
57
|
-
position: axisData.position,
|
|
58
|
-
beginAtZero: additionalAxesOptions.beginAtZero,
|
|
59
|
-
reverse: axisType === AxisType.Y ? additionalAxesOptions.reverse : false,
|
|
60
|
-
suggestedMax: additionalAxesOptions.suggestedMax,
|
|
61
|
-
suggestedMin: additionalAxesOptions.suggestedMin,
|
|
62
|
-
min: stateAxis?.min ?? additionalAxesOptions?.range?.[axisType]?.min,
|
|
63
|
-
max: stateAxis?.max ?? additionalAxesOptions?.range?.[axisType]?.max,
|
|
64
|
-
title: {
|
|
65
|
-
display: axisData.label?.length,
|
|
66
|
-
text: axisData.label,
|
|
67
|
-
padding: 0,
|
|
68
|
-
},
|
|
69
|
-
ticks: getTicks(),
|
|
70
|
-
grid: {
|
|
71
|
-
...axisData.gridLines,
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @param {import('../line-chart.interface').ILineChartOptions} options - line chart options object
|
|
78
|
-
* @param {'x'|'y'} axisType
|
|
79
|
-
* @param {import('../../../helpers/chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
|
|
80
|
-
*/
|
|
81
|
-
const getLineChartAxes = (options, axisType, state) => {
|
|
82
|
-
const axesData = options.axes[axisType];
|
|
83
|
-
const axes = axesData.reduce((acc, curr, i) => {
|
|
84
|
-
const axisData = curr;
|
|
85
|
-
axisData.color = curr.color || COLORS[i] || generateRandomColor(COLORS);
|
|
86
|
-
axisData.position = curr.position || getAxisPosition(axisType, i);
|
|
87
|
-
|
|
88
|
-
const axis = getLineChartAxis(options, axisType, state, axisData, i);
|
|
89
|
-
const axisId = generateAxisId(axisType, i, true);
|
|
90
|
-
return { ...acc, [axisId]: axis };
|
|
91
|
-
}, {});
|
|
92
|
-
return axes;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
*
|
|
97
|
-
* @param {import('../line-chart.interface').ILineChartOptions} options - line chart options object
|
|
98
|
-
* @param {import('../../../helpers/chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
|
|
99
|
-
*/
|
|
100
|
-
const getLineChartScales = (options, state) => {
|
|
101
|
-
const hasMultipleXAxes = options.axes.x?.length > 1;
|
|
102
|
-
const hasMultipleYAxes = options.axes.y?.length > 1;
|
|
103
|
-
|
|
104
|
-
const xAxes = hasMultipleXAxes
|
|
105
|
-
? getLineChartAxes(options, AxisType.X, state)
|
|
106
|
-
: { x: getLineChartAxis(options, AxisType.X, state) };
|
|
107
|
-
const yAxes = hasMultipleYAxes
|
|
108
|
-
? getLineChartAxes(options, AxisType.Y, state)
|
|
109
|
-
: { y: getLineChartAxis(options, AxisType.Y, state) };
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
...xAxes,
|
|
113
|
-
...yAxes,
|
|
114
|
-
};
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export default getLineChartScales;
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { ChartHoverMode, Position, TooltipLabel } from '../../../helpers/enums';
|
|
2
|
-
import {
|
|
3
|
-
afterLabelCallback,
|
|
4
|
-
getTooltipLabel,
|
|
5
|
-
} from '../../../helpers/chart-utils';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @param {import('../line-chart.interface').ILineChartOptions} options - line chart options object
|
|
9
|
-
*/
|
|
10
|
-
const getLineChartToolTips = (options) => {
|
|
11
|
-
const getTooltipLabels = (dataset) => {
|
|
12
|
-
const xIndex = dataset.xAxisID?.length > 1 ? dataset.xAxisID[1] - 1 : 0;
|
|
13
|
-
const yIndex = dataset.yAxisID?.length > 1 ? dataset.yAxisID[1] - 1 : 0;
|
|
14
|
-
const xAxis = options.axes.x[xIndex];
|
|
15
|
-
const yAxis = options.axes.y[yIndex];
|
|
16
|
-
|
|
17
|
-
if (options.axes.x[0].position === Position.Top) {
|
|
18
|
-
return {
|
|
19
|
-
titleAxisLabel: yAxis?.label || '',
|
|
20
|
-
valueAxisLabel: xAxis?.label || '',
|
|
21
|
-
titleLabel: TooltipLabel.Y,
|
|
22
|
-
valueLabel: TooltipLabel.X,
|
|
23
|
-
};
|
|
24
|
-
} else {
|
|
25
|
-
return {
|
|
26
|
-
titleAxisLabel: xAxis?.label || '',
|
|
27
|
-
valueAxisLabel: yAxis?.label || '',
|
|
28
|
-
titleLabel: TooltipLabel.X,
|
|
29
|
-
valueLabel: TooltipLabel.Y,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const titleCallback = (tooltipItem, data) => {
|
|
35
|
-
const labels = getTooltipLabels(tooltipItem[0].dataset);
|
|
36
|
-
const { titleLabel, titleAxisLabel } = labels;
|
|
37
|
-
|
|
38
|
-
const formattedValue =
|
|
39
|
-
titleLabel === TooltipLabel.Y
|
|
40
|
-
? tooltipItem[0].parsed.y
|
|
41
|
-
: tooltipItem[0].parsed.x;
|
|
42
|
-
const roundedValue =
|
|
43
|
-
Math.abs(formattedValue) < 1
|
|
44
|
-
? formattedValue.toPrecision(3)
|
|
45
|
-
: formattedValue.toFixed(2);
|
|
46
|
-
|
|
47
|
-
return `${roundedValue} ${titleAxisLabel}`;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const labelCallback = (tooltipItem) => {
|
|
51
|
-
const { showLabelsInTooltips, hideSimulationName } = options.tooltip;
|
|
52
|
-
let label = tooltipItem.dataset.label || '';
|
|
53
|
-
const labels = getTooltipLabels(tooltipItem.dataset);
|
|
54
|
-
const { valueLabel, valueAxisLabel } = labels;
|
|
55
|
-
|
|
56
|
-
const getTooltipItemValue = () => {
|
|
57
|
-
const labelNumber =
|
|
58
|
-
valueLabel === TooltipLabel.X
|
|
59
|
-
? tooltipItem.parsed.x
|
|
60
|
-
: tooltipItem.parsed.y;
|
|
61
|
-
return Math.abs(labelNumber) < 1
|
|
62
|
-
? labelNumber.toPrecision(3)
|
|
63
|
-
: labelNumber.toFixed(3);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const splitValueAxisLabel = valueAxisLabel.split(' ');
|
|
67
|
-
const newValueAxisLabel = hideSimulationName
|
|
68
|
-
? splitValueAxisLabel[splitValueAxisLabel.length - 1]
|
|
69
|
-
: valueAxisLabel;
|
|
70
|
-
|
|
71
|
-
const tooltipItemValue = getTooltipItemValue();
|
|
72
|
-
const valAxisLabel =
|
|
73
|
-
label === valueAxisLabel || valueAxisLabel.includes(label)
|
|
74
|
-
? ''
|
|
75
|
-
: newValueAxisLabel;
|
|
76
|
-
const tooltipLabel = getTooltipLabel(tooltipItem, showLabelsInTooltips);
|
|
77
|
-
|
|
78
|
-
return `${label}: ${tooltipItemValue} ${valAxisLabel}${tooltipLabel}`;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
enabled: options.tooltip.tooltips,
|
|
83
|
-
mode: ChartHoverMode.Nearest,
|
|
84
|
-
intersect: true,
|
|
85
|
-
padding: 8,
|
|
86
|
-
callbacks: {
|
|
87
|
-
title: titleCallback,
|
|
88
|
-
label: labelCallback,
|
|
89
|
-
afterLabel: afterLabelCallback,
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export default getLineChartToolTips;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { toNum as toNumber } from '@oliasoft-open-source/units';
|
|
2
|
-
|
|
3
|
-
export const toNum = (value) => {
|
|
4
|
-
const asNumber = toNumber(value);
|
|
5
|
-
return value === '' || isNaN(asNumber) ? '' : asNumber;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const isLessThanMax = (value, max) => {
|
|
9
|
-
return (
|
|
10
|
-
value === undefined || max === undefined || Number(value) < Number(max)
|
|
11
|
-
);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const isGreaterThanMin = (value, min) => {
|
|
15
|
-
return (
|
|
16
|
-
value === undefined || min === undefined || Number(value) > Number(min)
|
|
17
|
-
);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
* @param {'x'|'y'} axisType
|
|
23
|
-
* @param {number} [index] - axis index; optional, 0 by default
|
|
24
|
-
* @param {boolean} [hasMultiAxes] - optional, false by default
|
|
25
|
-
* @return {string} - e.g. x if chart has singular axes; x, x2 - in case of multiple axes
|
|
26
|
-
*/
|
|
27
|
-
export const generateAxisId = (axisType, index = 0, hasMultiAxes = false) => {
|
|
28
|
-
const i = hasMultiAxes && index !== 0 ? index + 1 : '';
|
|
29
|
-
return `${axisType}${i}`;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
Get axis type from a key string.
|
|
34
|
-
@param {string} string - The key string to extract from.
|
|
35
|
-
@returns {string} e.g. x1 => x
|
|
36
|
-
*/
|
|
37
|
-
export const getAxisTypeFromKey = (string) => {
|
|
38
|
-
return string.match(/[^0-9/]+/gi)[0];
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Generates a key based on an array of values. The key changes
|
|
43
|
-
* if any of the values in the array change.
|
|
44
|
-
*
|
|
45
|
-
* @param {Array} values - The array of values to base the key on.
|
|
46
|
-
* @returns {String} The key.
|
|
47
|
-
*/
|
|
48
|
-
export const generateKey = (values) => {
|
|
49
|
-
const key = values.join('');
|
|
50
|
-
return key;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Checks if a value is a primitive value (which includes strings, numbers, booleans, and null).
|
|
55
|
-
* @param {*} value - The value to check.
|
|
56
|
-
* @returns {boolean} - Returns true if the value is a primitive value, otherwise false.
|
|
57
|
-
*/
|
|
58
|
-
export const isPrimitiveValue = (value) =>
|
|
59
|
-
typeof value === 'string' ||
|
|
60
|
-
typeof value === 'number' ||
|
|
61
|
-
typeof value === 'boolean' ||
|
|
62
|
-
value === null;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { defaultTranslations } from '../../constants/default-translations';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Merges custom getTranslations with the default getTranslations.
|
|
5
|
-
* If a custom translation is provided for a key, it will override the default one.
|
|
6
|
-
* @param {object} translations - Custom getTranslations.
|
|
7
|
-
* @returns {object} - The resulting getTranslations object, containing both default and custom getTranslations.
|
|
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
|
-
};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import PropTypes from 'prop-types';
|
|
2
|
-
|
|
3
|
-
export const PieChartPropTypes = {
|
|
4
|
-
chart: PropTypes.shape({
|
|
5
|
-
testId: PropTypes.string,
|
|
6
|
-
data: PropTypes.shape({
|
|
7
|
-
labels: PropTypes.arrayOf(PropTypes.string),
|
|
8
|
-
datasets: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
9
|
-
}).isRequired,
|
|
10
|
-
options: PropTypes.shape({
|
|
11
|
-
title: PropTypes.oneOfType([
|
|
12
|
-
PropTypes.string,
|
|
13
|
-
PropTypes.arrayOf(PropTypes.string),
|
|
14
|
-
]),
|
|
15
|
-
chartStyling: PropTypes.shape({
|
|
16
|
-
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
17
|
-
height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
18
|
-
maintainAspectRatio: PropTypes.bool,
|
|
19
|
-
staticChartHeight: PropTypes.bool,
|
|
20
|
-
performanceMode: PropTypes.bool,
|
|
21
|
-
}),
|
|
22
|
-
tooltip: PropTypes.shape({
|
|
23
|
-
tooltips: PropTypes.bool,
|
|
24
|
-
showLabelsInTooltips: PropTypes.bool,
|
|
25
|
-
}),
|
|
26
|
-
graph: PropTypes.shape({
|
|
27
|
-
showDataLabels: PropTypes.bool,
|
|
28
|
-
stacked: PropTypes.bool,
|
|
29
|
-
cutout: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
30
|
-
}),
|
|
31
|
-
legend: PropTypes.shape({
|
|
32
|
-
display: PropTypes.bool,
|
|
33
|
-
position: PropTypes.oneOf(['top', 'bottom', 'right']),
|
|
34
|
-
align: PropTypes.oneOf(['start', 'center', 'end']),
|
|
35
|
-
useDataset: PropTypes.bool,
|
|
36
|
-
}),
|
|
37
|
-
chartOptions: PropTypes.shape({
|
|
38
|
-
enableZoom: PropTypes.bool,
|
|
39
|
-
enablePan: PropTypes.bool,
|
|
40
|
-
}),
|
|
41
|
-
interactions: PropTypes.shape({
|
|
42
|
-
onLegendClick: PropTypes.func,
|
|
43
|
-
onPieHover: PropTypes.func,
|
|
44
|
-
onPieUnhover: PropTypes.func,
|
|
45
|
-
}),
|
|
46
|
-
}),
|
|
47
|
-
}).isRequired,
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export const getDefaultProps = (props) => {
|
|
51
|
-
// Add missing nested objects
|
|
52
|
-
props.chart.options = props.chart.options || {};
|
|
53
|
-
props.chart.options.chartStyling = props.chart.options.chartStyling || {};
|
|
54
|
-
props.chart.options.tooltip = props.chart.options.tooltip || {};
|
|
55
|
-
props.chart.options.graph = props.chart.options.graph || {};
|
|
56
|
-
props.chart.options.legend = props.chart.options.legend || {};
|
|
57
|
-
props.chart.options.chartOptions = props.chart.options.chartOptions || {};
|
|
58
|
-
props.chart.options.interactions = props.chart.options.interactions || {};
|
|
59
|
-
// Set defaults for missing properties
|
|
60
|
-
const chart = {
|
|
61
|
-
testId: props.chart.testId ?? null,
|
|
62
|
-
data: props.chart.data,
|
|
63
|
-
options: {
|
|
64
|
-
title: props.chart.options.title || '',
|
|
65
|
-
chartStyling: {
|
|
66
|
-
width: props.chart.options.chartStyling.width,
|
|
67
|
-
height: props.chart.options.chartStyling.height,
|
|
68
|
-
maintainAspectRatio:
|
|
69
|
-
props.chart.options.chartStyling.maintainAspectRatio || false,
|
|
70
|
-
staticChartHeight:
|
|
71
|
-
props.chart.options.chartStyling.staticChartHeight || false,
|
|
72
|
-
performanceMode:
|
|
73
|
-
props.chart.options.chartStyling.performanceMode != null
|
|
74
|
-
? props.chart.options.chartStyling.performanceMode
|
|
75
|
-
: true,
|
|
76
|
-
},
|
|
77
|
-
tooltip: {
|
|
78
|
-
tooltips:
|
|
79
|
-
props.chart.options.tooltip.tooltips != null
|
|
80
|
-
? props.chart.options.tooltip.tooltips
|
|
81
|
-
: true,
|
|
82
|
-
showLabelsInTooltips:
|
|
83
|
-
props.chart.options.tooltip.showLabelsInTooltips || false,
|
|
84
|
-
},
|
|
85
|
-
graph: {
|
|
86
|
-
showDataLabels: props.chart.options.graph.showDataLabels || false,
|
|
87
|
-
stacked: props.chart.options.graph.stacked || false,
|
|
88
|
-
cutout: props.chart.options.graph.cutout || 0,
|
|
89
|
-
},
|
|
90
|
-
legend: {
|
|
91
|
-
display:
|
|
92
|
-
props.chart.options.legend.display != null
|
|
93
|
-
? props.chart.options.legend.display
|
|
94
|
-
: true,
|
|
95
|
-
useDataset: props.chart.options.legend.useDataset || false,
|
|
96
|
-
position: props.chart.options.legend.position || 'bottom',
|
|
97
|
-
align: props.chart.options.legend.align || 'center',
|
|
98
|
-
},
|
|
99
|
-
chartOptions: {
|
|
100
|
-
enableZoom: props.chart.options.chartOptions.enableZoom || false,
|
|
101
|
-
enablePan: props.chart.options.chartOptions.enablePan || false,
|
|
102
|
-
},
|
|
103
|
-
interactions: {
|
|
104
|
-
onLegendClick: props.chart.options.interactions.onLegendClick,
|
|
105
|
-
onPieHover: props.chart.options.interactions.onPieHover,
|
|
106
|
-
onPieUnhover: props.chart.options.interactions.onPieUnhover,
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
return chart;
|
|
111
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export const colors = [
|
|
2
|
-
'#3366cc',
|
|
3
|
-
'#dc3912',
|
|
4
|
-
'#ff9900',
|
|
5
|
-
'#109618',
|
|
6
|
-
'#990099',
|
|
7
|
-
'#0099c6',
|
|
8
|
-
'#dd4477',
|
|
9
|
-
'#66aa00',
|
|
10
|
-
'#b82e2e',
|
|
11
|
-
'#316395',
|
|
12
|
-
'#994499',
|
|
13
|
-
'#22aa99',
|
|
14
|
-
'#aaaa11',
|
|
15
|
-
'#6633cc',
|
|
16
|
-
'#e67300',
|
|
17
|
-
'#8b0707',
|
|
18
|
-
'#651067',
|
|
19
|
-
'#329262',
|
|
20
|
-
'#5574a6',
|
|
21
|
-
'#3b3eac',
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
export const generateRandomColor = () => {
|
|
25
|
-
const color = `#${Math.floor(Math.random() * 16777215).toString(16)}`;
|
|
26
|
-
if (colors.includes(color)) {
|
|
27
|
-
return generateRandomColor();
|
|
28
|
-
} else {
|
|
29
|
-
colors.push(color);
|
|
30
|
-
return color;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
export interface IChartInteractions {
|
|
2
|
-
onLegendClick: () => any;
|
|
3
|
-
onPointHover: () => any;
|
|
4
|
-
onPointUnhover: () => any;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface IChartOptions {
|
|
8
|
-
enableZoom: boolean;
|
|
9
|
-
enablePan: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface IChartLegend {
|
|
13
|
-
display: boolean;
|
|
14
|
-
position: 'top' | 'bottom' | 'right';
|
|
15
|
-
align: 'start' | 'center' | 'end';
|
|
16
|
-
useDataset: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface IChartGraph {
|
|
20
|
-
showDataLabels: boolean;
|
|
21
|
-
stacked: boolean;
|
|
22
|
-
cutout: number | string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface IChartTooltip {
|
|
26
|
-
tooltips: boolean;
|
|
27
|
-
showLabelsInTooltips: boolean;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface IChartStyling {
|
|
31
|
-
width: number | string;
|
|
32
|
-
height: number | string;
|
|
33
|
-
maintainAspectRatio: boolean;
|
|
34
|
-
staticChartHeight: boolean;
|
|
35
|
-
performanceMode: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface IOptions {
|
|
39
|
-
title: string | string[];
|
|
40
|
-
chartStyling: IChartStyling;
|
|
41
|
-
tooltip: IChartTooltip;
|
|
42
|
-
graph: IChartGraph;
|
|
43
|
-
legend: IChartLegend;
|
|
44
|
-
chartOptions: IChartOptions;
|
|
45
|
-
interactions: IChartInteractions;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface IChartData {
|
|
49
|
-
labels: string;
|
|
50
|
-
datasets: any[];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface IChartData {
|
|
54
|
-
testId: string | null;
|
|
55
|
-
data: IChartData;
|
|
56
|
-
options: IOptions;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface IPieChartProps {
|
|
60
|
-
chart: IChartData;
|
|
61
|
-
}
|