@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.
Files changed (86) hide show
  1. package/dist/index.js +40398 -0
  2. package/dist/style.css +177 -0
  3. package/package.json +26 -34
  4. package/index.js +0 -14
  5. package/release-notes.md +0 -310
  6. package/src/assets/icons/line-and-point.svg +0 -1
  7. package/src/assets/icons/line-only.svg +0 -1
  8. package/src/assets/icons/list-hide.svg +0 -1
  9. package/src/assets/icons/point-only.svg +0 -1
  10. package/src/components/bar-chart/bar-chart-prop-types.js +0 -209
  11. package/src/components/bar-chart/bar-chart.interface.ts +0 -91
  12. package/src/components/bar-chart/bar-chart.jsx +0 -247
  13. package/src/components/bar-chart/bar-chart.module.less +0 -61
  14. package/src/components/bar-chart/get-bar-chart-data-labels.js +0 -42
  15. package/src/components/bar-chart/get-bar-chart-scales.js +0 -123
  16. package/src/components/bar-chart/get-bar-chart-tooltips.js +0 -102
  17. package/src/components/controls/axes-options/axes-options.jsx +0 -270
  18. package/src/components/line-chart/constants/default-translations.js +0 -24
  19. package/src/components/line-chart/constants/line-chart-consts.js +0 -12
  20. package/src/components/line-chart/controls/axes-options/action-types.js +0 -5
  21. package/src/components/line-chart/controls/axes-options/axes-options-form-state.js +0 -97
  22. package/src/components/line-chart/controls/controls.jsx +0 -174
  23. package/src/components/line-chart/controls/controls.module.less +0 -12
  24. package/src/components/line-chart/controls/drag-options.jsx +0 -112
  25. package/src/components/line-chart/controls/legend-options.jsx +0 -36
  26. package/src/components/line-chart/controls/line-options.jsx +0 -64
  27. package/src/components/line-chart/hooks/use-chart-functions.js +0 -257
  28. package/src/components/line-chart/hooks/use-chart-options.js +0 -181
  29. package/src/components/line-chart/hooks/use-chart-plugins.js +0 -35
  30. package/src/components/line-chart/hooks/use-toggle-handler.js +0 -33
  31. package/src/components/line-chart/initialize/config.js +0 -23
  32. package/src/components/line-chart/initialize/initialize-line-chart.js +0 -25
  33. package/src/components/line-chart/line-chart-prop-types.js +0 -292
  34. package/src/components/line-chart/line-chart.interface.ts +0 -121
  35. package/src/components/line-chart/line-chart.jsx +0 -161
  36. package/src/components/line-chart/line-chart.module.less +0 -77
  37. package/src/components/line-chart/plugins/chart-area-text-plugin.js +0 -246
  38. package/src/components/line-chart/plugins/line-chart.minor-gridlines-plugin.js +0 -88
  39. package/src/components/line-chart/plugins/plugin-constants.js +0 -11
  40. package/src/components/line-chart/state/action-types.js +0 -12
  41. package/src/components/line-chart/state/initial-state.js +0 -89
  42. package/src/components/line-chart/state/line-chart-reducer.js +0 -100
  43. package/src/components/line-chart/state/manage-state-in-local-storage.js +0 -86
  44. package/src/components/line-chart/state/use-chart-state.js +0 -141
  45. package/src/components/line-chart/utils/axis-scales/axis-scales.js +0 -165
  46. package/src/components/line-chart/utils/datalabels-alignment/get-alignment-condition.js +0 -13
  47. package/src/components/line-chart/utils/datalabels-alignment/get-alignment-data.js +0 -20
  48. package/src/components/line-chart/utils/datalabels-alignment/get-datalabels-position.js +0 -25
  49. package/src/components/line-chart/utils/generate-line-chart-datasets.js +0 -114
  50. package/src/components/line-chart/utils/get-axes-ranges-from-chart.js +0 -13
  51. package/src/components/line-chart/utils/get-line-chart-data-labels.js +0 -21
  52. package/src/components/line-chart/utils/get-line-chart-scales.js +0 -120
  53. package/src/components/line-chart/utils/get-line-chart-tooltips.js +0 -94
  54. package/src/components/line-chart/utils/line-chart-utils.js +0 -77
  55. package/src/components/line-chart/utils/translations/get-translations.js +0 -17
  56. package/src/components/pie-chart/pie-chart-prop-types.js +0 -111
  57. package/src/components/pie-chart/pie-chart-utils.js +0 -32
  58. package/src/components/pie-chart/pie-chart.interface.ts +0 -61
  59. package/src/components/pie-chart/pie-chart.jsx +0 -450
  60. package/src/components/pie-chart/pie-chart.module.less +0 -61
  61. package/src/components/scatter-chart/scatter-chart.intefrace.ts +0 -33
  62. package/src/components/scatter-chart/scatter-chart.jsx +0 -21
  63. package/src/components/scatter-chart/scatter-chart.module.less +0 -4
  64. package/src/helpers/chart-border-plugin.js +0 -19
  65. package/src/helpers/chart-consts.js +0 -64
  66. package/src/helpers/chart-interface.ts +0 -94
  67. package/src/helpers/chart-utils.js +0 -182
  68. package/src/helpers/container.jsx +0 -60
  69. package/src/helpers/disabled-context.js +0 -8
  70. package/src/helpers/enums.js +0 -96
  71. package/src/helpers/get-chart-annotation.js +0 -106
  72. package/src/helpers/get-custom-legend-plugin-example.js +0 -80
  73. package/src/helpers/get-draggableData.js +0 -32
  74. package/src/helpers/range/estimate-data-series-have-close-values.js +0 -54
  75. package/src/helpers/range/range.js +0 -100
  76. package/src/helpers/text.js +0 -6
  77. package/src/style/external.less +0 -4
  78. package/src/style/fonts/lato/Lato-Bold.woff2 +0 -0
  79. package/src/style/fonts/lato/Lato-BoldItalic.woff2 +0 -0
  80. package/src/style/fonts/lato/Lato-Italic.woff2 +0 -0
  81. package/src/style/fonts/lato/Lato-Regular.woff2 +0 -0
  82. package/src/style/fonts.less +0 -27
  83. package/src/style/global.less +0 -43
  84. package/src/style/reset/reset.less +0 -28
  85. package/src/style/shared.less +0 -11
  86. package/src/style/variables.less +0 -91
@@ -1,114 +0,0 @@
1
- import { COLORS } from '../../../helpers/chart-consts';
2
- import {
3
- BORDER_JOIN_STYLE,
4
- DEFAULT_BACKGROUND_COLOR,
5
- DEFAULT_BORDER_WIDTH,
6
- DEFAULT_HOVER_RADIUS,
7
- DEFAULT_LINE_POINT_RADIUS,
8
- DEFAULT_POINT_RADIUS,
9
- } from '../constants/line-chart-consts';
10
- import { generateRandomColor } from '../../../helpers/chart-utils';
11
-
12
- /**
13
- * Generates line chart datasets based on the provided datasets, state, and options.
14
- *
15
- * @param {Array} datasets - The initial datasets for the line chart.
16
- * @param {Object} state - The state object containing chart settings (e.g., lineEnabled, pointsEnabled, axes).
17
- * @param {Object} options - The options object containing additional settings (e.g., annotations, graph).
18
- * @param {Object} translations - The getTranslations object with the label property
19
- * @returns {Array} - The generated line chart datasets with applied settings and configurations.
20
- */
21
- export const generateLineChartDatasets = (
22
- datasets,
23
- state,
24
- options,
25
- { label },
26
- ) => {
27
- const copyDataset = [...datasets];
28
- const { annotations, graph } = options;
29
- const {
30
- controlAnnotation,
31
- showAnnotations,
32
- annotationsData = [],
33
- } = annotations;
34
- // Add annotations to dataset to have them appear in legend.
35
- if (controlAnnotation && showAnnotations) {
36
- const annotationDatasets = annotationsData.map((annotation, index) => {
37
- const color = annotation.color ?? COLORS[index];
38
-
39
- // Create an annotation dataset
40
- return {
41
- isAnnotation: true,
42
- label: annotation.label,
43
- annotationIndex: index,
44
- backgroundColor: color,
45
- pointBackgroundColor: color,
46
- borderColor: color,
47
- data: [{}],
48
- };
49
- });
50
-
51
- // Add annotation datasets to the copyDataset array
52
- copyDataset.push(...annotationDatasets);
53
- }
54
-
55
- // Map over the copyDataset array and generate line chart datasets with applied settings and configurations
56
- return copyDataset.map((line, i) => {
57
- // Destructure properties from the line, state, and graph objects
58
- const {
59
- formation,
60
- data = [],
61
- pointRadius,
62
- pointHoverRadius,
63
- borderWidth,
64
- borderColor,
65
- backgroundColor,
66
- pointBackgroundColor,
67
- borderDash,
68
- } = line ?? {};
69
- const { lineEnabled, pointsEnabled, axes = [] } = state ?? {};
70
- const { lineTension, spanGaps } = graph ?? {};
71
-
72
- // Adjust the start and end points of the line if it has a formation flag
73
- if (formation) {
74
- const axesMin = axes[0]?.min;
75
- const axesMax = axes[0]?.max;
76
- const [startPoint, midPointWithLabel, endPoint] = data;
77
-
78
- if (axesMin && startPoint?.x) {
79
- data[0].x = Math.max(axesMin, startPoint.x);
80
- }
81
-
82
- if (axesMax && endPoint?.x) {
83
- data[2].x = Math.min(axesMax, endPoint.x);
84
- }
85
- }
86
-
87
- // Remove invalid falsy data points (OW-9855)
88
- const filteredData = data.filter(Boolean) || [];
89
-
90
- const linePointRadius = parseFloat(pointRadius) || DEFAULT_POINT_RADIUS;
91
- const hoverRadius = parseFloat(pointHoverRadius) || DEFAULT_HOVER_RADIUS;
92
- const indexedColor = COLORS[i];
93
-
94
- // Return the dataset with applied settings and configurations
95
- return {
96
- ...line,
97
- label: line.label || `${label} ${i + 1}`,
98
- data: filteredData,
99
- showLine: lineEnabled,
100
- lineTension,
101
- spanGaps,
102
- borderWidth: parseFloat(borderWidth) || DEFAULT_BORDER_WIDTH,
103
- borderDash: borderDash || [],
104
- borderJoinStyle: BORDER_JOIN_STYLE,
105
- borderColor: borderColor ?? indexedColor ?? generateRandomColor(COLORS),
106
- backgroundColor: backgroundColor ?? DEFAULT_BACKGROUND_COLOR,
107
- pointBackgroundColor:
108
- pointBackgroundColor ?? indexedColor ?? generateRandomColor(COLORS),
109
- pointRadius: pointsEnabled ? linePointRadius : DEFAULT_LINE_POINT_RADIUS,
110
- pointHoverRadius: hoverRadius,
111
- pointHitRadius: line.pointHitRadius ?? hoverRadius,
112
- };
113
- });
114
- };
@@ -1,13 +0,0 @@
1
- export const getAxesRangesFromChart = (chartRef, axes) => {
2
- const { scales = {} } = chartRef.current || {};
3
- return Object.entries(scales).map(([key, { min, max }], i) => {
4
- const axesArray = axes.x.concat(axes.y);
5
- const unit = axesArray?.[i]?.unit;
6
- return {
7
- id: key,
8
- min,
9
- max,
10
- ...(unit ? { unit } : {}),
11
- };
12
- });
13
- };
@@ -1,21 +0,0 @@
1
- import { AUTO } from '../../../helpers/chart-consts';
2
- import { getPosition } from './datalabels-alignment/get-datalabels-position';
3
-
4
- /**
5
- * adjusts the position of the label depends on chart area
6
- *
7
- * @param {import('../line-chart.interface').ILineChartOptions} options - line chart options object
8
- * @return {object} - returning position, if label exist in datasets item
9
- */
10
- const getLineChartDataLabels = (options) => {
11
- return options.graph.showDataLabels
12
- ? {
13
- display: AUTO,
14
- align: getPosition(),
15
- formatter: (value, context) =>
16
- context.dataset.data[context.dataIndex].label || '',
17
- }
18
- : { display: false };
19
- };
20
-
21
- export default getLineChartDataLabels;
@@ -1,120 +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, truncateDecimals } from './line-chart-utils';
7
- import { AxisType, ScaleType } from '../../../helpers/enums';
8
-
9
- /**
10
- * @param {import('../line-chart.interface').ILineChartOptions} options - line chart options object
11
- * @param {'x'|'y'} axisType
12
- * @param {import('../../../helpers/chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
13
- * @param {import('../line-chart.interface').ILineChartAxis[]} [currentScales]
14
- * @param {number} [i]
15
- */
16
- const getLineChartAxis = (options, axisType, state, currentScales, i = 0) => {
17
- const axisData = currentScales || options.axes[axisType][0];
18
- const stateAxis = state.axes.filter((axis) => axis.id.startsWith(axisType))[
19
- i
20
- ];
21
-
22
- const { additionalAxesOptions } = options;
23
-
24
- const getTicks = () => {
25
- const truncateAxisNumbersToDigitsCallback = Number.isInteger(
26
- additionalAxesOptions.truncateAxisNumbersToDigitsCallback,
27
- )
28
- ? {
29
- callback: (tick) =>
30
- truncateDecimals(
31
- tick,
32
- additionalAxesOptions.truncateAxisNumbersToDigitsCallback,
33
- ),
34
- }
35
- : {};
36
-
37
- const ticks =
38
- additionalAxesOptions.chartScaleType === ScaleType.Logarithmic
39
- ? {
40
- callback: (tick) => {
41
- return LOGARITHMIC_STEPS.includes(tick)
42
- ? tick.toLocaleString()
43
- : '';
44
- },
45
- }
46
- : {
47
- stepSize:
48
- axisData.stepSize ||
49
- (axisType === AxisType.Y ? additionalAxesOptions.stepSize : null),
50
- ...truncateAxisNumbersToDigitsCallback,
51
- };
52
- return {
53
- ...ticks,
54
- includeBounds: false, //OW-10088 disable irregular axis ticks
55
- };
56
- };
57
-
58
- return {
59
- type: additionalAxesOptions.chartScaleType,
60
- position: axisData.position,
61
- beginAtZero: additionalAxesOptions.beginAtZero,
62
- reverse: axisType === AxisType.Y ? additionalAxesOptions.reverse : false,
63
- suggestedMax: additionalAxesOptions.suggestedMax,
64
- suggestedMin: additionalAxesOptions.suggestedMin,
65
- min: stateAxis?.min ?? additionalAxesOptions?.range?.[axisType]?.min,
66
- max: stateAxis?.max ?? additionalAxesOptions?.range?.[axisType]?.max,
67
- title: {
68
- display: axisData.label?.length,
69
- text: axisData.label,
70
- padding: 0,
71
- },
72
- ticks: getTicks(),
73
- grid: {
74
- ...axisData.gridLines,
75
- },
76
- };
77
- };
78
-
79
- /**
80
- * @param {import('../line-chart.interface').ILineChartOptions} options - line chart options object
81
- * @param {'x'|'y'} axisType
82
- * @param {import('../../../helpers/chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
83
- */
84
- const getLineChartAxes = (options, axisType, state) => {
85
- const axesData = options.axes[axisType];
86
- const axes = axesData.reduce((acc, curr, i) => {
87
- const axisData = curr;
88
- axisData.color = curr.color || COLORS[i] || generateRandomColor(COLORS);
89
- axisData.position = curr.position || getAxisPosition(axisType, i);
90
-
91
- const axis = getLineChartAxis(options, axisType, state, axisData, i);
92
- const axisId = generateAxisId(axisType, i, true);
93
- return { ...acc, [axisId]: axis };
94
- }, {});
95
- return axes;
96
- };
97
-
98
- /**
99
- *
100
- * @param {import('../line-chart.interface').ILineChartOptions} options - line chart options object
101
- * @param {import('../../../helpers/chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
102
- */
103
- const getLineChartScales = (options, state) => {
104
- const hasMultipleXAxes = options.axes.x?.length > 1;
105
- const hasMultipleYAxes = options.axes.y?.length > 1;
106
-
107
- const xAxes = hasMultipleXAxes
108
- ? getLineChartAxes(options, AxisType.X, state)
109
- : { x: getLineChartAxis(options, AxisType.X, state) };
110
- const yAxes = hasMultipleYAxes
111
- ? getLineChartAxes(options, AxisType.Y, state)
112
- : { y: getLineChartAxis(options, AxisType.Y, state) };
113
-
114
- return {
115
- ...xAxes,
116
- ...yAxes,
117
- };
118
- };
119
-
120
- 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,77 +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
- * Truncates a number to the specified decimal digits.
22
- * Truncate refers to shaving digits off a number without rounding it.
23
- * @param {Number} number
24
- * @param {Number} digits
25
- * @returns {Number}
26
- */
27
- export const truncateDecimals = (number, digits) => {
28
- const multiplier = 10 ** digits;
29
- const adjustedNum = number * multiplier;
30
- const truncatedNum = Math[adjustedNum < 0 ? 'ceil' : 'floor'](adjustedNum);
31
-
32
- return truncatedNum / multiplier;
33
- };
34
-
35
- /**
36
- *
37
- * @param {'x'|'y'} axisType
38
- * @param {number} [index] - axis index; optional, 0 by default
39
- * @param {boolean} [hasMultiAxes] - optional, false by default
40
- * @return {string} - e.g. x if chart has singular axes; x1, x2 - in case of multiple axes
41
- */
42
- export const generateAxisId = (axisType, index = 0, hasMultiAxes = false) => {
43
- const i = hasMultiAxes ? index + 1 : '';
44
- return `${axisType}${i}`;
45
- };
46
-
47
- /**
48
- Get axis type from a key string.
49
- @param {string} string - The key string to extract from.
50
- @returns {string} e.g. x1 => x
51
- */
52
- export const getAxisTypeFromKey = (string) => {
53
- return string.match(/[^0-9/]+/gi)[0];
54
- };
55
-
56
- /**
57
- * Generates a key based on an array of values. The key changes
58
- * if any of the values in the array change.
59
- *
60
- * @param {Array} values - The array of values to base the key on.
61
- * @returns {String} The key.
62
- */
63
- export const generateKey = (values) => {
64
- const key = values.join('');
65
- return key;
66
- };
67
-
68
- /**
69
- * Checks if a value is a primitive value (which includes strings, numbers, booleans, and null).
70
- * @param {*} value - The value to check.
71
- * @returns {boolean} - Returns true if the value is a primitive value, otherwise false.
72
- */
73
- export const isPrimitiveValue = (value) =>
74
- typeof value === 'string' ||
75
- typeof value === 'number' ||
76
- typeof value === 'boolean' ||
77
- 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
- }