@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.
Files changed (99) hide show
  1. package/dist/index.js +39230 -0
  2. package/dist/index.js.map +1 -0
  3. package/package.json +6 -1
  4. package/index.js +0 -14
  5. package/release-notes.md +0 -378
  6. package/src/assets/circle.svg +0 -1
  7. package/src/assets/icons/line-and-point.svg +0 -1
  8. package/src/assets/icons/line-only.svg +0 -1
  9. package/src/assets/icons/list-hide.svg +0 -1
  10. package/src/assets/icons/point-only.svg +0 -1
  11. package/src/assets/rect.svg +0 -1
  12. package/src/assets/rectRot.svg +0 -1
  13. package/src/assets/triangle.svg +0 -1
  14. package/src/components/bar-chart/bar-chart-prop-types.js +0 -209
  15. package/src/components/bar-chart/bar-chart.interface.ts +0 -98
  16. package/src/components/bar-chart/bar-chart.jsx +0 -247
  17. package/src/components/bar-chart/bar-chart.module.less +0 -61
  18. package/src/components/bar-chart/get-bar-chart-data-labels.js +0 -42
  19. package/src/components/bar-chart/get-bar-chart-scales.js +0 -138
  20. package/src/components/bar-chart/get-bar-chart-tooltips.js +0 -102
  21. package/src/components/controls/axes-options/axes-options.jsx +0 -271
  22. package/src/components/line-chart/constants/default-translations.js +0 -24
  23. package/src/components/line-chart/constants/line-chart-consts.js +0 -12
  24. package/src/components/line-chart/controls/axes-options/action-types.js +0 -5
  25. package/src/components/line-chart/controls/axes-options/axes-options-form-state.js +0 -97
  26. package/src/components/line-chart/controls/controls-portal.jsx +0 -12
  27. package/src/components/line-chart/controls/controls.jsx +0 -176
  28. package/src/components/line-chart/controls/controls.module.less +0 -12
  29. package/src/components/line-chart/controls/drag-options.jsx +0 -124
  30. package/src/components/line-chart/controls/line-options.jsx +0 -64
  31. package/src/components/line-chart/hooks/use-chart-functions.js +0 -261
  32. package/src/components/line-chart/hooks/use-chart-options.js +0 -181
  33. package/src/components/line-chart/hooks/use-chart-plugins.js +0 -35
  34. package/src/components/line-chart/hooks/use-toggle-handler.js +0 -33
  35. package/src/components/line-chart/initialize/config.js +0 -23
  36. package/src/components/line-chart/initialize/initialize-line-chart.js +0 -25
  37. package/src/components/line-chart/legend/legend-constants.js +0 -1
  38. package/src/components/line-chart/legend/legend-dropzone.jsx +0 -74
  39. package/src/components/line-chart/legend/legend-item.jsx +0 -105
  40. package/src/components/line-chart/legend/legend-panel.jsx +0 -86
  41. package/src/components/line-chart/legend/legend.jsx +0 -54
  42. package/src/components/line-chart/legend/legend.module.less +0 -192
  43. package/src/components/line-chart/line-chart-prop-types.js +0 -298
  44. package/src/components/line-chart/line-chart.interface.ts +0 -128
  45. package/src/components/line-chart/line-chart.jsx +0 -180
  46. package/src/components/line-chart/line-chart.module.less +0 -78
  47. package/src/components/line-chart/plugins/chart-area-text-plugin.js +0 -246
  48. package/src/components/line-chart/plugins/line-chart.minor-gridlines-plugin.js +0 -88
  49. package/src/components/line-chart/plugins/plugin-constants.js +0 -11
  50. package/src/components/line-chart/state/action-types.js +0 -12
  51. package/src/components/line-chart/state/initial-state.js +0 -89
  52. package/src/components/line-chart/state/line-chart-reducer.js +0 -101
  53. package/src/components/line-chart/state/manage-state-in-local-storage.js +0 -86
  54. package/src/components/line-chart/state/use-chart-state.js +0 -141
  55. package/src/components/line-chart/utils/axis-formatting/axis-formatting.js +0 -69
  56. package/src/components/line-chart/utils/axis-scales/axis-scales.js +0 -165
  57. package/src/components/line-chart/utils/datalabels-alignment/get-alignment-condition.js +0 -13
  58. package/src/components/line-chart/utils/datalabels-alignment/get-alignment-data.js +0 -20
  59. package/src/components/line-chart/utils/datalabels-alignment/get-datalabels-position.js +0 -25
  60. package/src/components/line-chart/utils/generate-line-chart-datasets.js +0 -122
  61. package/src/components/line-chart/utils/get-axes-ranges-from-chart.js +0 -13
  62. package/src/components/line-chart/utils/get-line-chart-data-labels.js +0 -21
  63. package/src/components/line-chart/utils/get-line-chart-scales.js +0 -117
  64. package/src/components/line-chart/utils/get-line-chart-tooltips.js +0 -94
  65. package/src/components/line-chart/utils/line-chart-utils.js +0 -62
  66. package/src/components/line-chart/utils/translations/get-translations.js +0 -17
  67. package/src/components/pie-chart/pie-chart-prop-types.js +0 -111
  68. package/src/components/pie-chart/pie-chart-utils.js +0 -32
  69. package/src/components/pie-chart/pie-chart.interface.ts +0 -61
  70. package/src/components/pie-chart/pie-chart.jsx +0 -458
  71. package/src/components/pie-chart/pie-chart.module.less +0 -61
  72. package/src/components/scatter-chart/scatter-chart.intefrace.ts +0 -33
  73. package/src/components/scatter-chart/scatter-chart.jsx +0 -21
  74. package/src/components/scatter-chart/scatter-chart.module.less +0 -4
  75. package/src/helpers/chart-border-plugin.js +0 -19
  76. package/src/helpers/chart-consts.js +0 -64
  77. package/src/helpers/chart-interface.ts +0 -94
  78. package/src/helpers/chart-utils.js +0 -178
  79. package/src/helpers/container.jsx +0 -60
  80. package/src/helpers/disabled-context.js +0 -8
  81. package/src/helpers/enums.js +0 -107
  82. package/src/helpers/get-chart-annotation.js +0 -102
  83. package/src/helpers/get-custom-legend-plugin-example.js +0 -80
  84. package/src/helpers/get-draggableData.js +0 -32
  85. package/src/helpers/range/estimate-data-series-have-close-values.js +0 -54
  86. package/src/helpers/range/range.js +0 -100
  87. package/src/helpers/text.js +0 -6
  88. package/src/style/external.less +0 -4
  89. package/src/style/fonts/lato/Lato-Bold.woff2 +0 -0
  90. package/src/style/fonts/lato/Lato-BoldItalic.woff2 +0 -0
  91. package/src/style/fonts/lato/Lato-Italic.woff2 +0 -0
  92. package/src/style/fonts/lato/Lato-Regular.woff2 +0 -0
  93. package/src/style/fonts.less +0 -27
  94. package/src/style/global.less +0 -43
  95. package/src/style/reset/reset.less +0 -28
  96. package/src/style/shared.less +0 -11
  97. package/src/style/variables.less +0 -91
  98. package/vite.config.mjs +0 -49
  99. package/vitest.config.mjs +0 -8
@@ -1,94 +0,0 @@
1
- import { Plugin } from "chart.js";
2
-
3
- export interface IChartDraggableData {
4
- enableDragData: boolean;
5
- showTooltip: boolean;
6
- roundPoints: boolean;
7
- dragX: boolean;
8
- dragY: boolean;
9
- onDragStart: () => any;
10
- onDrag: () => any;
11
- onDragEnd: () => any;
12
- };
13
-
14
- export interface IChartAnnotationsData {
15
- adjustScaleRange: boolean;
16
- annotationAxis: 'x' | 'y';
17
- color: string;
18
- endValue: number;
19
- label: string;
20
- type: string;
21
- value: number;
22
- xMin: number,
23
- xMax: number,
24
- yMin: number,
25
- yMax: number,
26
- };
27
-
28
- export interface ILabelAnnotation {
29
- showLabel: boolean;
30
- text: string | string[];
31
- position?: string
32
- fontSize?: number;
33
- xOffset?: number
34
- yOffset?: number
35
- maxWidth?: number
36
- lineHeight?: number
37
- }
38
-
39
-
40
- export interface IChartAnnotations {
41
- showAnnotations: boolean;
42
- controlAnnotation: boolean;
43
- annotationsData: IChartAnnotationsData[];
44
- labelAnnotation: ILabelAnnotation
45
- }
46
-
47
- export interface IChartStyling {
48
- width: number | string;
49
- height: number | string;
50
- maintainAspectRatio: boolean;
51
- squareAspectRatio?: boolean;
52
- staticChartHeight: boolean;
53
- performanceMode: boolean;
54
- }
55
-
56
- export interface ICustomLegend {
57
- customLegendPlugin: Plugin;
58
- customLegendContainerID: string,
59
- }
60
-
61
- export interface IChartLegend {
62
- display: boolean;
63
- position: 'top' | 'bottom' | 'right';
64
- align: 'start' | 'center' | 'end';
65
- customLegend?: ICustomLegend;
66
- usePointStyle: boolean;
67
- }
68
-
69
- export interface IChartInteractions {
70
- onLegendClick: () => any;
71
- onPointHover: () => any;
72
- onPointUnhover: () => any;
73
- }
74
-
75
- export interface IInitialState {
76
- zoomEnabled?: boolean;
77
- panEnabled?: boolean;
78
- pointsEnabled?: boolean;
79
- lineEnabled?: boolean;
80
- legendEnabled?: boolean;
81
- axes?: {id: string, label: string | any, min?: {}, max?: {}}[];
82
- showAnnotationLineIndex: [];
83
- enableDragData?: boolean;
84
- }
85
-
86
- export interface IChartPlugins {
87
- legend: {
88
- position: 'top' | 'right' | 'bottom' | 'left';
89
- }
90
- title: {
91
- display: boolean;
92
- text: string;
93
- }
94
- }
@@ -1,178 +0,0 @@
1
- import { round } from '@oliasoft-open-source/units';
2
- import { defaults } from 'chart.js';
3
- import cx from 'classnames';
4
- import { chartMinorGridlinesPlugin } from '../components/line-chart/plugins/line-chart.minor-gridlines-plugin';
5
- import {
6
- BORDER_COLOR,
7
- CUSTOM_LEGEND_PLUGIN_NAME,
8
- DEFAULT_CHART_NAME,
9
- DEFAULT_COLOR,
10
- DEFAULT_FONT_FAMILY,
11
- DEFAULT_FONT_SIZE,
12
- LEGEND_LABEL_BOX_SIZE,
13
- WHITE_COLOR_AS_DECIMAL,
14
- } from './chart-consts';
15
- import { AxisType, ChartDirection, Position } from './enums';
16
- import { chartAreaBorderPlugin } from './chart-border-plugin';
17
-
18
- /**
19
- * @param {import('../components/bar-chart/bar-chart.interface').IBarChartGraph |
20
- * import('../components/line-chart/line-chart.interface').ILineChartGraph } graph - graph data from chart options
21
- * @param {import('../helpers/chart-interface').IChartLegend} legend
22
- * @return {[]}
23
- */
24
- export const getPlugins = (graph, legend) => {
25
- let plugins = [];
26
- if (graph.showMinorGridlines) {
27
- plugins.push(chartMinorGridlinesPlugin);
28
- }
29
- const customLegend = legend?.customLegend;
30
- if (
31
- customLegend?.customLegendPlugin &&
32
- customLegend?.customLegendContainerID
33
- ) {
34
- plugins.push({
35
- id: CUSTOM_LEGEND_PLUGIN_NAME,
36
- ...legend.customLegend.customLegendPlugin,
37
- });
38
- }
39
- plugins.push(chartAreaBorderPlugin);
40
- return plugins;
41
- };
42
-
43
- /**
44
- * @param {string[]} colors - color schema
45
- * @return {string} - random color
46
- */
47
- export const generateRandomColor = (colors) => {
48
- const color = `#${Math.floor(Math.random() * WHITE_COLOR_AS_DECIMAL).toString(
49
- 16,
50
- )}`;
51
- if (colors.includes(color)) {
52
- return generateRandomColor(colors);
53
- } else {
54
- colors.push(color);
55
- return color;
56
- }
57
- };
58
-
59
- /**
60
- * @param {import('./chart-interface').IChartAnnotationsData[]} annotationsData
61
- * @return {number[]|*[]}
62
- */
63
- export const setAnnotations = (annotationsData) => {
64
- return annotationsData?.length ? annotationsData.map((v, i) => i) : [];
65
- };
66
-
67
- /**
68
- * @param {import('../components/bar-chart/bar-chart.interface').IBarChartOptions |
69
- * import('../components/line-chart/line-chart.interface').ILineChartOptions} options - chart options object
70
- * @return {{color: (string|undefined), display: boolean, text}|{}}
71
- */
72
- export const getTitle = (options) => {
73
- return options.title !== ''
74
- ? {
75
- display: true,
76
- text: options.title,
77
- }
78
- : {};
79
- };
80
-
81
- /**
82
- * @function isVertical
83
- * @param {'vertical'|'horizontal'|string} direction
84
- * @return {boolean} returns true if chart direction is vertical
85
- */
86
- export const isVertical = (direction) => {
87
- return direction === ChartDirection.Vertical;
88
- };
89
-
90
- /**
91
- * @param {'x'|'y'} axisType
92
- * @param {number} i - index
93
- * @return {'top'|'bottom'|'left'|'right'|*}
94
- */
95
- export const getAxisPosition = (axisType, i) => {
96
- const [positionA, positionB] =
97
- axisType === AxisType.Y
98
- ? [Position.Left, Position.Right]
99
- : [Position.Top, Position.Bottom];
100
- return i % 2 === 0 ? positionA : positionB;
101
- };
102
-
103
- /**
104
- * @param {import('../helpers/chart-interface').IChartStyling} chartStyling
105
- * @param {Object} styles - styles imported form .less file
106
- * @return {string} - class name
107
- */
108
- export const getClassName = (chartStyling, styles) => {
109
- const { width, height, staticChartHeight, squareAspectRatio } = chartStyling;
110
- const squareAspectRatioStyle = squareAspectRatio
111
- ? styles.squareAspectRatio
112
- : '';
113
- let heightStyles = '';
114
- if (width || height) {
115
- heightStyles = '';
116
- } else {
117
- heightStyles = staticChartHeight
118
- ? styles?.fixedHeight
119
- : styles?.stretchHeight;
120
- }
121
- return cx(styles.chart, heightStyles, squareAspectRatioStyle);
122
- };
123
-
124
- /**
125
- *
126
- * @param {import('../components/bar-chart/bar-chart.interface').IBarChartOptions |
127
- * import('../components/line-chart/line-chart.interface').ILineChartOptions} options - chart options object
128
- * @param {function} clickHandler - on click callback
129
- * @param {import('./chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
130
- * @returns {*}
131
- */
132
- export const getLegend = (options, clickHandler, state = null) => {
133
- const { legend } = options;
134
- return {
135
- position: legend.position || Position.Top,
136
- display: legend.display,
137
- align: legend.align,
138
- labels: {
139
- boxHeight: LEGEND_LABEL_BOX_SIZE,
140
- boxWidth: legend.usePointStyle ? LEGEND_LABEL_BOX_SIZE : undefined,
141
- usePointStyle: legend.usePointStyle,
142
- },
143
- onClick: clickHandler,
144
- };
145
- };
146
-
147
- export const afterLabelCallback = (tooltipItem) => {
148
- const { error } = tooltipItem.dataset.data[tooltipItem?.dataIndex];
149
- return error ? `Error: ${round(error, 4)}` : '';
150
- };
151
-
152
- export const getTooltipLabel = (tooltipItem, showLabelsInTooltips) => {
153
- const datasetDataLabel =
154
- tooltipItem.dataset.data[tooltipItem.dataIndex]?.label;
155
- const dataLabel = Array.isArray(datasetDataLabel)
156
- ? datasetDataLabel.join(' , ')
157
- : datasetDataLabel;
158
- return showLabelsInTooltips && dataLabel?.length ? ` (${dataLabel})` : '';
159
- };
160
-
161
- //TODO: consider returning chart name instead of axis names
162
- export const getChartFileName = (axes) => {
163
- if (!axes) {
164
- return DEFAULT_CHART_NAME;
165
- }
166
- const axesLabels = axes.reduce((acc, cur, index) => {
167
- const labelWithNoSpace = cur.label?.replace(/\s/g, '_') || index;
168
- return [...acc, labelWithNoSpace];
169
- }, []);
170
- return axesLabels.join('_');
171
- };
172
-
173
- export const setDefaultTheme = () => {
174
- defaults.font.size = DEFAULT_FONT_SIZE;
175
- defaults.font.family = DEFAULT_FONT_FAMILY;
176
- defaults.color = DEFAULT_COLOR;
177
- defaults.borderColor = BORDER_COLOR;
178
- };
@@ -1,60 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
-
4
- import '../style/reset/reset.less';
5
- import '../style/global.less';
6
-
7
- const outerContainerStyle = {
8
- margin: '50px',
9
- };
10
-
11
- export const Container = ({
12
- style,
13
- children,
14
- margin,
15
- deprecatedMessage,
16
- warningMessage,
17
- }) => {
18
- return (
19
- <div style={margin ? outerContainerStyle : {}}>
20
- {deprecatedMessage ? (
21
- <div
22
- style={{
23
- border: '1px solid red',
24
- color: 'red',
25
- padding: '10px',
26
- marginBottom: '20px',
27
- }}
28
- >
29
- {deprecatedMessage}
30
- </div>
31
- ) : null}
32
- {warningMessage ? (
33
- <div
34
- style={{
35
- border: '1px solid orange',
36
- color: 'orange',
37
- padding: '10px',
38
- marginBottom: '20px',
39
- }}
40
- >
41
- {warningMessage}
42
- </div>
43
- ) : null}
44
- <div style={style}>{children}</div>
45
- </div>
46
- );
47
- };
48
-
49
- Container.defaultProps = {
50
- style: {},
51
- margin: true,
52
- deprecatedMessage: null,
53
- };
54
-
55
- Container.propTypes = {
56
- style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
57
- children: PropTypes.node.isRequired,
58
- margin: PropTypes.bool,
59
- deprecatedMessage: PropTypes.string,
60
- };
@@ -1,8 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
-
4
- export const DisabledContext = React.createContext(false);
5
-
6
- DisabledContext.Provider.propTypes = {
7
- value: PropTypes.bool,
8
- };
@@ -1,107 +0,0 @@
1
- /**
2
- * @enum {string}
3
- */
4
- export const AxisType = Object.freeze({
5
- X: 'x',
6
- Y: 'y',
7
- });
8
-
9
- /**
10
- * @enum {string}
11
- */
12
- export const Position = Object.freeze({
13
- Bottom: 'bottom',
14
- Top: 'top',
15
- Left: 'left',
16
- Right: 'right',
17
- TopRight: 'top-right',
18
- TopLeft: 'top-left',
19
- BottomLeft: 'bottom-left',
20
- BottomRight: 'bottom-right',
21
- });
22
-
23
- /**
24
- * @enum {string}
25
- */
26
- export const ChartType = Object.freeze({
27
- Line: 'line',
28
- Bar: 'bar',
29
- });
30
-
31
- /**
32
- * @enum {string}
33
- */
34
- export const CursorStyle = Object.freeze({
35
- Pointer: 'pointer',
36
- Initial: 'initial',
37
- });
38
-
39
- /**
40
- * @enum {string}
41
- */
42
- export const ScaleType = Object.freeze({
43
- Category: 'category', //TODO: verify
44
- Linear: 'linear',
45
- Logarithmic: 'logarithmic',
46
- });
47
-
48
- /**
49
- * @enum {string}
50
- */
51
- export const ChartDirection = Object.freeze({
52
- Vertical: 'vertical',
53
- });
54
-
55
- /**
56
- * @enum {string}
57
- */
58
- export const TooltipLabel = Object.freeze({
59
- Y: 'yLabel',
60
- X: 'xLabel',
61
- });
62
-
63
- export const AlignOptions = Object.freeze({
64
- End: 'end',
65
- Start: 'start',
66
- Center: 'center',
67
- Right: 'right',
68
- Left: 'left',
69
- });
70
-
71
- export const PointType = Object.freeze({
72
- Casing: 'casing',
73
- });
74
-
75
- export const AnnotationType = Object.freeze({
76
- Box: 'box',
77
- Ellipse: 'ellipse',
78
- Line: 'line',
79
- Text: 'text',
80
- });
81
-
82
- export const PointStyle = Object.freeze({
83
- Circle: 'circle',
84
- });
85
-
86
- export const ChartHoverMode = Object.freeze({
87
- Nearest: 'nearest',
88
- });
89
-
90
- export const PanZoomMode = Object.freeze({
91
- X: 'x',
92
- Y: 'y',
93
- XY: 'xy',
94
- });
95
-
96
- export const Key = Object.freeze({
97
- Shift: 'Shift',
98
- });
99
-
100
- export const Events = Object.freeze([
101
- 'mousemove',
102
- 'mouseout',
103
- 'click',
104
- 'touchstart',
105
- 'touchmove',
106
- 'dblclick',
107
- ]);
@@ -1,102 +0,0 @@
1
- import { AxisType, ChartType, CursorStyle, Position } from './enums';
2
- import { ANNOTATION_DASH, BORDER_WIDTH, COLORS } from './chart-consts';
3
-
4
- const annotationEnter = ({ element }, { chart }) => {
5
- if (element.options.scaleID?.includes(AxisType.X)) {
6
- element.options.label.xAdjust = chart.chartArea.left;
7
- }
8
- element.options.borderWidth = BORDER_WIDTH.HOVERED;
9
- if (element.options.label) element.options.label.enabled = true;
10
- chart.draw();
11
- chart.canvas.style.cursor = CursorStyle.Pointer;
12
- };
13
-
14
- const annotationLeave = ({ element }, { chart }) => {
15
- element.options.borderWidth = BORDER_WIDTH.INITIAL;
16
- if (element.options.label) element.options.label.enabled = false;
17
- chart.draw();
18
- chart.canvas.style.cursor = CursorStyle.Initial;
19
- };
20
-
21
- /**
22
- * @param {import('../components/bar-chart/bar-chart.interface').IBarChartOptions |
23
- * import('../components/line-chart/line-chart.interface').ILineChartOptions} options - chart options object
24
- * @param {import('./chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
25
- */
26
- const generateAnnotations = (options, state) => {
27
- const { annotationsData } = options.annotations;
28
-
29
- const annotations = annotationsData?.reduce((acc, curr, i) => {
30
- if (!state?.showAnnotationLineIndex?.includes(i)) {
31
- return { ...acc };
32
- }
33
-
34
- const scaleID = curr?.annotationAxis ?? undefined;
35
- const color = curr?.color || COLORS[i];
36
- const type = curr?.type || 'line';
37
- const adjustScaleRange = curr?.adjustScaleRange;
38
- const borderColor = type === 'line' ? color : 'transparent';
39
- const borderWidth = type === 'line' ? BORDER_WIDTH.INITIAL : 0;
40
- const borderDash = ANNOTATION_DASH;
41
-
42
- const label =
43
- type === 'line'
44
- ? {
45
- backgroundColor: color,
46
- content: curr?.label,
47
- enabled: false,
48
- position: Position.Top,
49
- }
50
- : {
51
- content: curr?.label,
52
- enabled: true,
53
- font: { weight: 'normal' },
54
- };
55
-
56
- const enter = (context, event) => {
57
- if (type !== 'line') return;
58
- annotationEnter(context, event);
59
- };
60
-
61
- const leave = (context, event) => {
62
- if (type !== 'line') return;
63
- annotationLeave(context, event);
64
- };
65
-
66
- const annotation = {
67
- ...curr,
68
- id: `${curr?.label}-${curr?.value}-${i}`,
69
- scaleID,
70
- label,
71
- backgroundColor: color,
72
- borderColor,
73
- borderWidth,
74
- borderDash,
75
- type,
76
- adjustScaleRange,
77
- enter,
78
- leave,
79
- };
80
- return { ...acc, [`annotation${i + 1}`]: annotation };
81
- }, {});
82
- return annotations;
83
- };
84
-
85
- /**
86
- * @param {import('../components/bar-chart/bar-chart.interface').IBarChartOptions |
87
- * import('../components/line-chart/line-chart.interface').ILineChartOptions} options - chart options object
88
- * @param {import('./chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
89
- * @return {{annotations: []}}
90
- */
91
- const getAnnotation = (options, state) => {
92
- const { showAnnotations, annotationsData } = options.annotations || {};
93
- const shouldGenerateAnnotations = showAnnotations && annotationsData?.length;
94
-
95
- const annotations = shouldGenerateAnnotations
96
- ? generateAnnotations(options, state)
97
- : null;
98
-
99
- return { annotations };
100
- };
101
-
102
- export default getAnnotation;
@@ -1,80 +0,0 @@
1
- const getOrCreateLegendList = (chart, id) => {
2
- const legendContainer = document.getElementById(id);
3
- let listContainer = legendContainer.querySelector('ul');
4
-
5
- if (!listContainer) {
6
- listContainer = document.createElement('ul');
7
- listContainer.style.display = 'flex';
8
- listContainer.style.flexDirection = 'row';
9
- listContainer.style.margin = 0;
10
- listContainer.style.padding = 0;
11
-
12
- legendContainer.appendChild(listContainer);
13
- }
14
-
15
- return listContainer;
16
- };
17
-
18
- /**
19
- * Gets an example custom legend plugin for use in storybook.
20
- * @param {string} customLegendContainerID - the id of the div container to put the generated legend in
21
- */
22
- export const getCustomLegendPlugin = (customLegendContainerID) => ({
23
- afterUpdate(chart, _args, _options) {
24
- const ul = getOrCreateLegendList(chart, customLegendContainerID);
25
-
26
- // Remove old legend items
27
- while (ul.firstChild) {
28
- ul.firstChild.remove();
29
- }
30
-
31
- // Reuse the built-in legendItems generator
32
- const items = chart.options.plugins.legend.labels.generateLabels(chart);
33
-
34
- items.forEach((item) => {
35
- const li = document.createElement('li');
36
- li.style.alignItems = 'center';
37
- li.style.cursor = 'pointer';
38
- li.style.display = 'flex';
39
- li.style.flexDirection = 'row';
40
- li.style.marginLeft = '10px';
41
-
42
- li.onclick = () => {
43
- const { type } = chart.config;
44
- if (type === 'pie' || type === 'doughnut') {
45
- // Pie and doughnut charts only have a single dataset and visibility is per item
46
- chart.toggleDataVisibility(item.index);
47
- } else {
48
- chart.setDatasetVisibility(
49
- item.datasetIndex,
50
- !chart.isDatasetVisible(item.datasetIndex),
51
- );
52
- }
53
- chart.update();
54
- };
55
-
56
- // Color box
57
- const boxSpan = document.createElement('span');
58
- boxSpan.style.background = item.fillStyle;
59
- boxSpan.style.borderColor = item.strokeStyle;
60
- boxSpan.style.borderWidth = item.lineWidth + 'px';
61
- boxSpan.style.display = 'inline-block';
62
- boxSpan.style.height = '20px';
63
- boxSpan.style.marginRight = '10px';
64
- boxSpan.style.width = '20px';
65
-
66
- // Text
67
- const textContainer = document.createElement('p');
68
- textContainer.style.margin = 0;
69
- textContainer.style.padding = 0;
70
- textContainer.style.textDecoration = item.hidden ? 'line-through' : '';
71
-
72
- const text = document.createTextNode(item.text);
73
- textContainer.appendChild(text);
74
-
75
- li.appendChild(boxSpan);
76
- li.appendChild(textContainer);
77
- ul.appendChild(li);
78
- });
79
- },
80
- });
@@ -1,32 +0,0 @@
1
- /**
2
- * @param {import('./line-chart.interface').ILineChartOptions} options - line chart options object
3
- */
4
- const getDraggableData = (options) => {
5
- const { dragData = {} } = options;
6
- const {
7
- enableDragData = false,
8
- showTooltip = true,
9
- roundPoints = true,
10
- dragX = true,
11
- dragY = true,
12
- onDragStart = () => {},
13
- onDrag = () => {},
14
- onDragEnd = () => {},
15
- } = dragData;
16
-
17
- return enableDragData
18
- ? {
19
- dragData: {
20
- dragX,
21
- dragY,
22
- round: roundPoints,
23
- showTooltip,
24
- onDragStart,
25
- onDrag,
26
- onDragEnd,
27
- },
28
- }
29
- : {};
30
- };
31
-
32
- export default getDraggableData;