@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,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,182 +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?.customLegend?.customLegendPlugin
137
- ? state
138
- ? state.legendEnabled
139
- : legend.display
140
- : false,
141
- align: legend.align,
142
- labels: {
143
- boxHeight: LEGEND_LABEL_BOX_SIZE,
144
- boxWidth: legend.usePointStyle ? LEGEND_LABEL_BOX_SIZE : undefined,
145
- usePointStyle: legend.usePointStyle,
146
- },
147
- onClick: clickHandler,
148
- };
149
- };
150
-
151
- export const afterLabelCallback = (tooltipItem) => {
152
- const { error } = tooltipItem.dataset.data[tooltipItem?.dataIndex];
153
- return error ? `Error: ${round(error, 4)}` : '';
154
- };
155
-
156
- export const getTooltipLabel = (tooltipItem, showLabelsInTooltips) => {
157
- const datasetDataLabel =
158
- tooltipItem.dataset.data[tooltipItem.dataIndex]?.label;
159
- const dataLabel = Array.isArray(datasetDataLabel)
160
- ? datasetDataLabel.join(' , ')
161
- : datasetDataLabel;
162
- return showLabelsInTooltips && dataLabel?.length ? ` (${dataLabel})` : '';
163
- };
164
-
165
- //TODO: consider returning chart name instead of axis names
166
- export const getChartFileName = (axes) => {
167
- if (!axes) {
168
- return DEFAULT_CHART_NAME;
169
- }
170
- const axesLabels = axes.reduce((acc, cur, index) => {
171
- const labelWithNoSpace = cur.label?.replace(/\s/g, '_') || index;
172
- return [...acc, labelWithNoSpace];
173
- }, []);
174
- return axesLabels.join('_');
175
- };
176
-
177
- export const setDefaultTheme = () => {
178
- defaults.font.size = DEFAULT_FONT_SIZE;
179
- defaults.font.family = DEFAULT_FONT_FAMILY;
180
- defaults.color = DEFAULT_COLOR;
181
- defaults.borderColor = BORDER_COLOR;
182
- };
@@ -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,96 +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
- });
18
-
19
- /**
20
- * @enum {string}
21
- */
22
- export const ChartType = Object.freeze({
23
- Line: 'line',
24
- Bar: 'bar',
25
- });
26
-
27
- /**
28
- * @enum {string}
29
- */
30
- export const CursorStyle = Object.freeze({
31
- Pointer: 'pointer',
32
- Initial: 'initial',
33
- });
34
-
35
- /**
36
- * @enum {string}
37
- */
38
- export const ScaleType = Object.freeze({
39
- Category: 'category', //TODO: verify
40
- Linear: 'linear',
41
- Logarithmic: 'logarithmic',
42
- });
43
-
44
- /**
45
- * @enum {string}
46
- */
47
- export const ChartDirection = Object.freeze({
48
- Vertical: 'vertical',
49
- });
50
-
51
- /**
52
- * @enum {string}
53
- */
54
- export const TooltipLabel = Object.freeze({
55
- Y: 'yLabel',
56
- X: 'xLabel',
57
- });
58
-
59
- export const AlignOptions = Object.freeze({
60
- End: 'end',
61
- Start: 'start',
62
- Center: 'center',
63
- Right: 'right',
64
- Left: 'left',
65
- });
66
-
67
- export const PointType = Object.freeze({
68
- Casing: 'casing',
69
- });
70
-
71
- export const PointStyle = Object.freeze({
72
- Circle: 'circle',
73
- });
74
-
75
- export const ChartHoverMode = Object.freeze({
76
- Nearest: 'nearest',
77
- });
78
-
79
- export const PanZoomMode = Object.freeze({
80
- X: 'x',
81
- Y: 'y',
82
- XY: 'xy',
83
- });
84
-
85
- export const Key = Object.freeze({
86
- Shift: 'Shift',
87
- });
88
-
89
- export const Events = Object.freeze([
90
- 'mousemove',
91
- 'mouseout',
92
- 'click',
93
- 'touchstart',
94
- 'touchmove',
95
- 'dblclick',
96
- ]);
@@ -1,106 +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 getScaleId = () => {
35
- const axisType = curr.annotationAxis;
36
- return options.axes[axisType]?.length > 1 ? `${axisType}1` : axisType;
37
- };
38
-
39
- const color = curr?.color || COLORS[i];
40
- const type = curr?.type || 'line';
41
- const adjustScaleRange = curr?.adjustScaleRange;
42
- const borderColor = type === 'line' ? color : 'transparent';
43
- const borderWidth = type === 'line' ? BORDER_WIDTH.INITIAL : 0;
44
- const borderDash = ANNOTATION_DASH;
45
-
46
- const label =
47
- type === 'line'
48
- ? {
49
- backgroundColor: color,
50
- content: curr?.label,
51
- enabled: false,
52
- position: Position.Top,
53
- }
54
- : {
55
- content: curr?.label,
56
- enabled: true,
57
- font: { weight: 'normal' },
58
- };
59
-
60
- const enter = (context, event) => {
61
- if (type !== 'line') return;
62
- annotationEnter(context, event);
63
- };
64
-
65
- const leave = (context, event) => {
66
- if (type !== 'line') return;
67
- annotationLeave(context, event);
68
- };
69
-
70
- const annotation = {
71
- ...curr,
72
- id: `${curr?.label}-${curr?.value}-${i}`,
73
- scaleID: getScaleId(),
74
- label,
75
- backgroundColor: color,
76
- borderColor,
77
- borderWidth,
78
- borderDash,
79
- type,
80
- adjustScaleRange,
81
- enter,
82
- leave,
83
- };
84
- return { ...acc, [`annotation${i + 1}`]: annotation };
85
- }, {});
86
- return annotations;
87
- };
88
-
89
- /**
90
- * @param {import('../components/bar-chart/bar-chart.interface').IBarChartOptions |
91
- * import('../components/line-chart/line-chart.interface').ILineChartOptions} options - chart options object
92
- * @param {import('./chart-interface').IInitialState} state - chart state object controlled by useReducer or similar
93
- * @return {{annotations: []}}
94
- */
95
- const getAnnotation = (options, state) => {
96
- const { showAnnotations, annotationsData } = options.annotations || {};
97
- const shouldGenerateAnnotations = showAnnotations && annotationsData?.length;
98
-
99
- const annotations = shouldGenerateAnnotations
100
- ? generateAnnotations(options, state)
101
- : null;
102
-
103
- return { annotations };
104
- };
105
-
106
- 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;