@oliasoft-open-source/charts-library 0.0.2-beta-1

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 (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/index.js +13 -0
  4. package/package.json +100 -0
  5. package/release-notes.md +178 -0
  6. package/src/assets/icons/line-and-point.svg +1 -0
  7. package/src/assets/icons/line-only.svg +1 -0
  8. package/src/assets/icons/list-hide.svg +1 -0
  9. package/src/assets/icons/point-only.svg +1 -0
  10. package/src/components/bar-chart/bar-chart-prop-types.js +188 -0
  11. package/src/components/bar-chart/bar-chart.interface.ts +84 -0
  12. package/src/components/bar-chart/bar-chart.jsx +243 -0
  13. package/src/components/bar-chart/bar-chart.module.less +61 -0
  14. package/src/components/bar-chart/get-bar-chart-data-labels.js +42 -0
  15. package/src/components/bar-chart/get-bar-chart-scales.js +123 -0
  16. package/src/components/bar-chart/get-bar-chart-tooltips.js +100 -0
  17. package/src/components/controls/axes-options/axes-options-form-state.js +95 -0
  18. package/src/components/controls/axes-options/axes-options.jsx +166 -0
  19. package/src/components/controls/controls.jsx +104 -0
  20. package/src/components/controls/controls.module.less +12 -0
  21. package/src/components/controls/drag-options.jsx +77 -0
  22. package/src/components/controls/legend-options.jsx +25 -0
  23. package/src/components/controls/line-options.jsx +54 -0
  24. package/src/components/line-chart/axis-scales/axis-scales.js +165 -0
  25. package/src/components/line-chart/datalabels-alignment/get-alignment-condition.js +13 -0
  26. package/src/components/line-chart/datalabels-alignment/get-alignment-data.js +20 -0
  27. package/src/components/line-chart/datalabels-alignment/get-datalabels-position.js +25 -0
  28. package/src/components/line-chart/get-axes-ranges-from-chart.js +10 -0
  29. package/src/components/line-chart/get-line-chart-data-labels.js +21 -0
  30. package/src/components/line-chart/get-line-chart-scales.js +120 -0
  31. package/src/components/line-chart/get-line-chart-tooltips.js +91 -0
  32. package/src/components/line-chart/line-chart-consts.js +7 -0
  33. package/src/components/line-chart/line-chart-prop-types.js +212 -0
  34. package/src/components/line-chart/line-chart-utils.js +192 -0
  35. package/src/components/line-chart/line-chart.interface.ts +107 -0
  36. package/src/components/line-chart/line-chart.jsx +531 -0
  37. package/src/components/line-chart/line-chart.minor-gridlines-plugin.js +88 -0
  38. package/src/components/line-chart/line-chart.module.less +77 -0
  39. package/src/components/line-chart/state/action-types.js +11 -0
  40. package/src/components/line-chart/state/initial-state.js +69 -0
  41. package/src/components/line-chart/state/line-chart-reducer.js +101 -0
  42. package/src/components/pie-chart/pie-chart-prop-types.js +111 -0
  43. package/src/components/pie-chart/pie-chart-utils.js +32 -0
  44. package/src/components/pie-chart/pie-chart.interface.ts +61 -0
  45. package/src/components/pie-chart/pie-chart.jsx +450 -0
  46. package/src/components/pie-chart/pie-chart.module.less +61 -0
  47. package/src/components/scatter-chart/scatter-chart.intefrace.ts +33 -0
  48. package/src/components/scatter-chart/scatter-chart.jsx +21 -0
  49. package/src/components/scatter-chart/scatter-chart.module.less +4 -0
  50. package/src/helpers/chart-border-plugin.js +19 -0
  51. package/src/helpers/chart-consts.js +62 -0
  52. package/src/helpers/chart-interface.ts +76 -0
  53. package/src/helpers/chart-utils.js +183 -0
  54. package/src/helpers/container.jsx +60 -0
  55. package/src/helpers/disabled-context.js +8 -0
  56. package/src/helpers/enums.js +87 -0
  57. package/src/helpers/get-chart-annotation.js +143 -0
  58. package/src/helpers/get-custom-legend-plugin-example.js +80 -0
  59. package/src/helpers/numbers/numbers.js +44 -0
  60. package/src/helpers/range/estimate-data-series-have-close-values.js +54 -0
  61. package/src/helpers/range/range.js +95 -0
  62. package/src/helpers/styles.js +68 -0
  63. package/src/helpers/text.js +6 -0
  64. package/src/style/external.less +4 -0
  65. package/src/style/fonts/lato/Lato-Bold.woff2 +0 -0
  66. package/src/style/fonts/lato/Lato-BoldItalic.woff2 +0 -0
  67. package/src/style/fonts/lato/Lato-Italic.woff2 +0 -0
  68. package/src/style/fonts/lato/Lato-Regular.woff2 +0 -0
  69. package/src/style/fonts.less +27 -0
  70. package/src/style/global.less +43 -0
  71. package/src/style/reset/reset.less +28 -0
  72. package/src/style/shared.less +24 -0
  73. package/src/style/variables.less +91 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Oliasoft AS and contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Chart Library
2
+
3
+ Reusable charts for use in React applications.
package/index.js ADDED
@@ -0,0 +1,13 @@
1
+ /*
2
+ Components
3
+ */
4
+
5
+ import ScatterChart from './src/components/scatter-chart/scatter-chart';
6
+
7
+ export { LineChart } from './src/components/line-chart/line-chart';
8
+
9
+ export { PieChart } from './src/components/pie-chart/pie-chart';
10
+
11
+ export { BarChart } from './src/components/bar-chart/bar-chart';
12
+
13
+ export { ScatterChart };
package/package.json ADDED
@@ -0,0 +1,100 @@
1
+ {
2
+ "name": "@oliasoft-open-source/charts-library",
3
+ "version": "0.0.2-beta-1",
4
+ "description": "React Chart Library (based on Chart.js and react-chart-js-2)",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "build": "yarn run build:storybook",
8
+ "build:storybook": "build-storybook --quiet --output-dir ./public",
9
+ "dev:storybook": "start-storybook -p 6006",
10
+ "preview:storybook": " http-server ./public -o -p 9002 -c-1",
11
+ "test": "yarn run prettier:check && yarn run lint:check && yarn run test:unit",
12
+ "test:unit": "jest",
13
+ "lint:check": "eslint \"**/*.{js,jsx}\"",
14
+ "lint:fix": "eslint --fix \"**/*.{js,jsx}\"",
15
+ "prettier:check": "prettier --check \"**/*.{js,jsx,json,css,less}\"",
16
+ "prettier:fix": "prettier --write \"**/*.{js,jsx,json,css,less}\"",
17
+ "prepare": "husky install"
18
+ },
19
+ "lint-staged": {
20
+ "*.js": "eslint --cache --fix",
21
+ "*.{js,jsx,json,css,less}": [
22
+ "prettier --write"
23
+ ]
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://gitlab.com/oliasoft-open-source/charts-library.git"
28
+ },
29
+ "author": "Oliasoft AS and contributors",
30
+ "license": "MIT",
31
+ "bugs": {
32
+ "url": "https://gitlab.com/oliasoft-open-source/charts-library/issues"
33
+ },
34
+ "homepage": "https://gitlab.com/oliasoft-open-source/charts-library",
35
+ "devDependencies": {
36
+ "@babel/core": "^7.18.13",
37
+ "@babel/eslint-parser": "^7.18.9",
38
+ "@babel/preset-env": "^7.18.10",
39
+ "@babel/preset-react": "^7.18.6",
40
+ "@storybook/addon-actions": "^6.5.10",
41
+ "@storybook/addon-docs": "^6.5.10",
42
+ "@storybook/addon-links": "^6.5.10",
43
+ "@storybook/addon-storysource": "^6.5.10",
44
+ "@storybook/addons": "^6.5.10",
45
+ "@storybook/builder-webpack5": "^6.5.10",
46
+ "@storybook/manager-webpack5": "^6.5.10",
47
+ "@storybook/react": "^6.5.10",
48
+ "@storybook/source-loader": "^6.5.10",
49
+ "@types/react": "^17.0.49",
50
+ "babel-jest": "^29.0.1",
51
+ "babel-plugin-webpack-aliases": "^1.1.3",
52
+ "css-loader": "^6.7.1",
53
+ "css-minimizer-webpack-plugin": "^4.0.0",
54
+ "eslint": "^8.23.0",
55
+ "eslint-config-airbnb": "^19.0.4",
56
+ "eslint-config-prettier": "^8.5.0",
57
+ "eslint-import-resolver-alias": "^1.1.2",
58
+ "eslint-plugin-import": "^2.26.0",
59
+ "eslint-plugin-jsx-a11y": "^6.6.1",
60
+ "eslint-plugin-react": "^7.31.1",
61
+ "eslint-plugin-react-hooks": "^4.6.0",
62
+ "html-webpack-plugin": "^5.5.0",
63
+ "http-server": "^14.1.1",
64
+ "husky": "^8.0.1",
65
+ "jest": "^29.0.1",
66
+ "jest-transform-stub": "^2.0.0",
67
+ "less": "^4.1.3",
68
+ "less-loader": "^11.0.0",
69
+ "lint-staged": "^13.0.3",
70
+ "mini-css-extract-plugin": "^2.6.1",
71
+ "prettier": "2.7.1",
72
+ "react": "^17.0.2",
73
+ "react-dom": "^17.0.2",
74
+ "storybook-dark-mode": "^1.1.0",
75
+ "terser-webpack-plugin": "^5.3.6",
76
+ "webpack": "^5.74.0",
77
+ "webpack-cli": "^4.10.0",
78
+ "webpack-dev-server": "^4.10.1",
79
+ "webpack-merge": "^5.8.0"
80
+ },
81
+ "peerDependencies": {
82
+ "react": "^17.0",
83
+ "react-dom": "^17.0"
84
+ },
85
+ "dependencies": {
86
+ "@oliasoft-open-source/react-ui-library": "^3.1",
87
+ "chart.js": "^3.9.1",
88
+ "chartjs-plugin-annotation": "^1.4.0",
89
+ "chartjs-plugin-datalabels": "^2.1.0",
90
+ "chartjs-plugin-zoom": "^1.2.1",
91
+ "classnames": "^2.3.1",
92
+ "fraction.js": "^4.2.0",
93
+ "immer": "^9.0.17",
94
+ "less-vars-to-js": "^1.3.0",
95
+ "prop-types": "^15.8.1",
96
+ "react-base64-downloader": "^2.1.7",
97
+ "react-chartjs-2": "^4.3.1",
98
+ "react-icons": "^4.4.0"
99
+ }
100
+ }
@@ -0,0 +1,178 @@
1
+ # Charts Library Release Notes
2
+
3
+ ## 2.6.1
4
+
5
+ - Added Box and Ellipse annotations ([OW-10519](https://oliasoft.atlassian.net/browse/OW-10519))
6
+
7
+ ## 2.6.0
8
+
9
+ - Add support for optional `autoAxisPadding` prop, which autoscales 5% padding around data ([OW-10398](https://oliasoft.atlassian.net/browse/OW-10398))
10
+ - Fix bug in default scales when all data points similar values ([OW-4327](https://oliasoft.atlassian.net/browse/OW-4327))
11
+
12
+ ## 2.5.27
13
+
14
+ - Add guard to useEffect in line-chart
15
+
16
+ ## 2.5.26
17
+
18
+ - Add guard to getLineChartAxis method
19
+
20
+ ## 2.5.25
21
+
22
+ - Fix axis ranges updating when new chart data and ranges is passed
23
+
24
+ ## 2.5.24
25
+
26
+ - Add performance test case
27
+
28
+ ## 2.5.23
29
+
30
+ - Patch minor regression in axis limits introduced in 2.5.22
31
+
32
+ ## 2.5.22
33
+
34
+ - Improve UX and input validation for axes range inputs ([OW-10305](https://oliasoft.atlassian.net/browse/OW-10305))
35
+
36
+ ## 2.5.21
37
+
38
+ - Revert changes from `2.5.12` / [OW-10320](https://oliasoft.atlassian.net/browse/OW-10320)
39
+ - Changing thousands separators broke decimal separators in some locales
40
+ - Resolves [OW-10320](https://oliasoft.atlassian.net/browse/OW-10320)
41
+
42
+ ## 2.5.20
43
+
44
+ - Minor refactor (code cleanup)
45
+
46
+ ## 2.5.19
47
+
48
+ - Hide irregular major axis ticks ([OW-10088](https://oliasoft.atlassian.net/browse/OW-10088))
49
+
50
+ ## 2.5.18
51
+
52
+ - Fixed minor gridlines when last major tick does not reach axis bounds ([OW-10296](https://oliasoft.atlassian.net/browse/OW-10296))
53
+
54
+ ## 2.5.17
55
+
56
+ - Added some (realistic) test case stories from our app
57
+
58
+ ## 2.5.16
59
+
60
+ - Remove test artefacts from published package
61
+
62
+ ## 2.5.15
63
+
64
+ - Changed GUI library version to `^3.1`
65
+
66
+ ## 2.5.14
67
+
68
+ - Sync axis labels in chart Controls with props
69
+
70
+ ## 2.5.13
71
+
72
+ - fixed custom range inputs reset, multi-axis range placeholder values missing
73
+
74
+ ## 2.5.12
75
+
76
+ - change thousand separators in axis label from comma to space
77
+
78
+ ## 2.5.11
79
+
80
+ - Allow headerComponent and chart title to coexist
81
+
82
+ ## 2.5.10
83
+
84
+ - Fix zoom / pan bug at < 0.1 scale on charts
85
+
86
+ ## 2.5.9
87
+
88
+ - Fix validation for two and more decimal places in charts settings
89
+
90
+ ## 2.5.8
91
+
92
+ - Disable tooltip animations in `performanceMode`
93
+
94
+ ## 2.5.7
95
+
96
+ - Allow stretchy headerComponent in controls
97
+
98
+ ## 2.5.6
99
+
100
+ - Removed resizeDelay, fixed double data labels set position
101
+
102
+ ## 2.5.5
103
+
104
+ - Removed empty label annotations
105
+
106
+ ## 2.5.4
107
+
108
+ - Fixed onPointHover event
109
+
110
+ ## 2.5.3
111
+
112
+ - Fixed datalabels position, set labels position inside chart area
113
+
114
+ ## 2.5.2
115
+
116
+ - Fix crashes when type a non number into the axis range - add validation in getLinechartAxis method
117
+
118
+ ## 2.5.1
119
+
120
+ - Added resize delay for performance
121
+
122
+ ## 2.5.0
123
+
124
+ - Separate controls for points/lines, axes options, legend, download
125
+ - Standard control for table
126
+ - Box zoom
127
+
128
+ ## 2.4.6
129
+
130
+ - Fix Multiple X Axes example in LineChart
131
+
132
+ ## 2.4.5
133
+
134
+ - Fix zooming issue from OW-9960
135
+
136
+ ## 2.4.4
137
+
138
+ - Updated GUI Library version
139
+
140
+ ## 2.4.3
141
+
142
+ - Fix crashes when type a non-number into the axis range OW-9924
143
+
144
+ ## 2.4.2
145
+
146
+ - Square aspect ratio charts can fill height/width
147
+
148
+ ## 2.4.1
149
+
150
+ - Remove dependency on http-server (moved to dev dependencies)
151
+
152
+ ## 2.4.0
153
+
154
+ - Switch package manager from NPM to Yarn
155
+
156
+ ## 2.3.4
157
+
158
+ - RollBack changes regarding OW-4327
159
+
160
+ ## 2.3.3
161
+
162
+ - restrict suggestedMin/Max by X axe OW-4327
163
+
164
+ ## 2.3.2
165
+
166
+ - added default values for axis ticks (suggestedMin/Max) OW-4327
167
+
168
+ ## 2.3.0
169
+
170
+ - Text annotations in line chart
171
+
172
+ ## 2.2.1
173
+
174
+ - Support for dark mode
175
+
176
+ ## 2.2.0
177
+
178
+ - first publish of release notes
@@ -0,0 +1 @@
1
+ <svg fill="none" height="12" viewBox="0 0 12 12" width="12" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><clipPath id="a"><path d="m0 0h12v12h-12z"/></clipPath><g clip-path="url(#a)"><path d="m7.937 6.5c-.11122.42912-.36179.80916-.71237 1.08047-.35058.2713-.78133.4185-1.22463.4185s-.87405-.1472-1.22463-.4185c-.35058-.27131-.60115-.65135-.71237-1.08047h-3.563v-1h3.563c.11122-.42912.36179-.80916.71237-1.08046s.78133-.41851 1.22463-.41851.87405.14721 1.22463.41851.60115.65134.71237 1.08046h3.563v1z" fill="currentColor"/></g></svg>
@@ -0,0 +1 @@
1
+ <svg fill="none" height="12" viewBox="0 0 12 12" width="12" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><clipPath id="a"><path d="m0 0h12v12h-12z"/></clipPath><g clip-path="url(#a)"><path d="m.5 6.5v-1h11v1c-4.16104 0-6.63549 0-11 0z" fill="currentColor"/></g></svg>
@@ -0,0 +1 @@
1
+ <svg fill="none" height="12" viewBox="0 0 12 12" width="12" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><clipPath id="a"><path d="m0 0h12v12h-12z"/></clipPath><g clip-path="url(#a)"><path clip-rule="evenodd" d="m1.85351 1.14645-.35356-.353558-.707103.707108.353553.35355.39645.39645c-.02813.07955-.0429.16401-.0429.25 0 .19891.07902.38968.21967.53033.14066.14065.33142.21967.53033.21967.08599 0 .17045-.01477.25-.04289l2.2929 2.29289h-.7929v1h1.7929l2.5 2.5h-4.2929v1h5.2929l.85355.8536.3536.3535.7071-.7071-.3536-.3536-.3535-.35351v-.79289h-.79294l-2.5-2.5h3.29294v-1h-4.29294l-3.25-3.25c-.03694-.10448-.09692-.20048-.17678-.28033-.07985-.07985-.17585-.13984-.28033-.17678zm8.64649.85355h-6.50005v1h6.50005zm-8.78038 4.53033c.14066.14065.33142.21967.53033.21967.19892 0 .38968-.07902.53033-.21967.14066-.14065.21967-.33142.21967-.53033s-.07901-.38968-.21967-.53033c-.14065-.14065-.33141-.21967-.53033-.21967-.19891 0-.38967.07902-.53033.21967-.14065.14065-.21967.33142-.21967.53033s.07902.38968.21967.53033zm0 3.45c.14066.14067.33142.21967.53033.21967.19892 0 .38968-.079.53033-.21967.14066-.14065.21967-.33142.21967-.53033s-.07901-.38968-.21967-.53033c-.14065-.14065-.33141-.21967-.53033-.21967-.19891 0-.38967.07902-.53033.21967-.14065.14065-.21967.33142-.21967.53033s.07902.38968.21967.53033z" fill="currentColor" fill-rule="evenodd"/></g></svg>
@@ -0,0 +1 @@
1
+ <svg fill="none" height="12" viewBox="0 0 12 12" width="12" xmlns="http://www.w3.org/2000/svg"><circle cx="6" cy="6" fill="currentColor" r="2"/></svg>
@@ -0,0 +1,188 @@
1
+ import PropTypes from 'prop-types';
2
+
3
+ export const BarChartPropTypes = {
4
+ chart: PropTypes.shape({
5
+ testId: PropTypes.string,
6
+ data: PropTypes.object.isRequired,
7
+ options: PropTypes.shape({
8
+ title: PropTypes.oneOfType([
9
+ PropTypes.string,
10
+ PropTypes.arrayOf(PropTypes.string),
11
+ ]),
12
+ direction: PropTypes.oneOf(['vertical', 'horizontal']),
13
+ axes: PropTypes.shape({
14
+ x: PropTypes.arrayOf(
15
+ PropTypes.shape({
16
+ label: PropTypes.string,
17
+ position: PropTypes.oneOf(['top', 'bottom']),
18
+ color: PropTypes.string,
19
+ unit: PropTypes.string,
20
+ }),
21
+ ),
22
+ y: PropTypes.arrayOf(
23
+ PropTypes.shape({
24
+ label: PropTypes.string,
25
+ position: PropTypes.oneOf(['left', 'right']),
26
+ color: PropTypes.string,
27
+ unit: PropTypes.string,
28
+ }),
29
+ ),
30
+ }),
31
+ additionalAxesOptions: PropTypes.shape({
32
+ chartScaleType: PropTypes.oneOf(['linear', 'logarithmic']),
33
+ reverse: PropTypes.bool,
34
+ beginAtZero: PropTypes.bool,
35
+ stepSize: PropTypes.number,
36
+ stacked: PropTypes.bool,
37
+ suggestedMin: PropTypes.number,
38
+ suggestedMax: PropTypes.number,
39
+ min: PropTypes.number,
40
+ max: PropTypes.number,
41
+ }),
42
+ chartStyling: PropTypes.shape({
43
+ width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
44
+ height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
45
+ maintainAspectRatio: PropTypes.bool,
46
+ staticChartHeight: PropTypes.bool,
47
+ performanceMode: PropTypes.bool,
48
+ }),
49
+ tooltip: PropTypes.shape({
50
+ tooltips: PropTypes.bool,
51
+ showLabelsInTooltips: PropTypes.bool,
52
+ }),
53
+ graph: PropTypes.shape({
54
+ showDataLabels: PropTypes.bool,
55
+ showMinorGridlines: PropTypes.bool,
56
+ }),
57
+ annotations: PropTypes.shape({
58
+ showAnnotations: PropTypes.bool,
59
+ controlAnnotation: PropTypes.bool,
60
+ annotationsData: PropTypes.arrayOf(
61
+ PropTypes.shape({
62
+ annotationAxis: PropTypes.oneOf(['x', 'y']),
63
+ label: PropTypes.string,
64
+ color: PropTypes.string,
65
+ value: PropTypes.number,
66
+ endValue: PropTypes.number,
67
+ }),
68
+ ),
69
+ }),
70
+ legend: PropTypes.shape({
71
+ display: PropTypes.bool,
72
+ position: PropTypes.oneOf(['top', 'bottom', 'right']),
73
+ align: PropTypes.oneOf(['start', 'center', 'end']),
74
+ customLegend: PropTypes.shape({
75
+ customLegendPlugin: PropTypes.object,
76
+ customLegendContainerID: PropTypes.string,
77
+ }),
78
+ }),
79
+ chartOptions: PropTypes.shape({
80
+ enableZoom: PropTypes.bool,
81
+ enablePan: PropTypes.bool,
82
+ }),
83
+ interactions: PropTypes.shape({
84
+ onLegendClick: PropTypes.func,
85
+ onBarHover: PropTypes.func,
86
+ onBarUnhover: PropTypes.func,
87
+ }),
88
+ }),
89
+ }).isRequired,
90
+ };
91
+
92
+ export const getDefaultProps = (props) => {
93
+ // Add missing nested objects
94
+ props.chart.options = props.chart.options || {};
95
+ props.chart.options.axes = props.chart.options.axes || {};
96
+ props.chart.options.additionalAxesOptions =
97
+ props.chart.options.additionalAxesOptions || {};
98
+ props.chart.options.chartStyling = props.chart.options.chartStyling || {};
99
+ props.chart.options.tooltip = props.chart.options.tooltip || {};
100
+ props.chart.options.graph = props.chart.options.graph || {};
101
+ props.chart.options.annotations = props.chart.options.annotations || {};
102
+ props.chart.options.legend = props.chart.options.legend || {};
103
+ props.chart.options.legend.customLegend = props.chart.options.legend
104
+ .customLegend || { customLegendPlugin: null, customLegendContainerID: '' };
105
+ props.chart.options.chartOptions = props.chart.options.chartOptions || {};
106
+ props.chart.options.interactions = props.chart.options.interactions || {};
107
+ // Set defaults for missing properties
108
+ const chart = {
109
+ testId: props.chart.testId ?? null,
110
+ data: props.chart.data,
111
+ options: {
112
+ title: props.chart.options.title || '',
113
+ direction: props.chart.options.direction || 'vertical',
114
+ axes: {
115
+ x: props.chart.options.axes.x || [{}],
116
+ y: props.chart.options.axes.y || [{}],
117
+ },
118
+ additionalAxesOptions: {
119
+ chartScaleType:
120
+ props.chart.options.additionalAxesOptions.chartScaleType || 'linear',
121
+ reverse: props.chart.options.additionalAxesOptions.reverse || false,
122
+ stacked: props.chart.options.additionalAxesOptions.stacked || false,
123
+ beginAtZero:
124
+ props.chart.options.additionalAxesOptions.beginAtZero != null
125
+ ? props.chart.options.additionalAxesOptions.beginAtZero
126
+ : true,
127
+ stepSize: props.chart.options.additionalAxesOptions.stepSize,
128
+ suggestedMin: props.chart.options.additionalAxesOptions.suggestedMin,
129
+ suggestedMax: props.chart.options.additionalAxesOptions.suggestedMax,
130
+ min: props.chart.options.additionalAxesOptions.min,
131
+ max: props.chart.options.additionalAxesOptions.max,
132
+ },
133
+ chartStyling: {
134
+ width: props.chart.options.chartStyling.width,
135
+ height: props.chart.options.chartStyling.height,
136
+ maintainAspectRatio:
137
+ props.chart.options.chartStyling.maintainAspectRatio || false,
138
+ staticChartHeight:
139
+ props.chart.options.chartStyling.staticChartHeight || false,
140
+ performanceMode:
141
+ props.chart.options.chartStyling.performanceMode != null
142
+ ? props.chart.options.chartStyling.performanceMode
143
+ : true,
144
+ },
145
+ tooltip: {
146
+ tooltips:
147
+ props.chart.options.tooltip.tooltips != null
148
+ ? props.chart.options.tooltip.tooltips
149
+ : true,
150
+ showLabelsInTooltips:
151
+ props.chart.options.tooltip.showLabelsInTooltips || false,
152
+ },
153
+ graph: {
154
+ showDataLabels: props.chart.options.graph.showDataLabels || false,
155
+ showMinorGridlines:
156
+ props.chart.options.graph.showMinorGridlines || false,
157
+ },
158
+ annotations: {
159
+ showAnnotations:
160
+ props.chart.options.annotations.showAnnotations != null
161
+ ? props.chart.options.annotations.showAnnotations
162
+ : true,
163
+ controlAnnotation:
164
+ props.chart.options.annotations.controlAnnotation || false,
165
+ annotationsData: props.chart.options.annotations.annotationsData || [],
166
+ },
167
+ legend: {
168
+ display:
169
+ props.chart.options.legend.display != null
170
+ ? props.chart.options.legend.display
171
+ : true,
172
+ position: props.chart.options.legend.position || 'bottom',
173
+ align: props.chart.options.legend.align || 'center',
174
+ customLegend: props.chart.options.legend.customLegend,
175
+ },
176
+ chartOptions: {
177
+ enableZoom: props.chart.options.chartOptions.enableZoom || false,
178
+ enablePan: props.chart.options.chartOptions.enablePan || false,
179
+ },
180
+ interactions: {
181
+ onLegendClick: props.chart.options.interactions.onLegendClick,
182
+ onBarHover: props.chart.options.interactions.onBarHover,
183
+ onBarUnhover: props.chart.options.interactions.onBarUnhover,
184
+ },
185
+ },
186
+ };
187
+ return chart;
188
+ };
@@ -0,0 +1,84 @@
1
+ import {IChartAnnotations, IChartInteractions, IChartLegend, IChartStyling} from "../../helpers/chart-interface";
2
+
3
+ export interface IChartOptions {
4
+ enableZoom: boolean;
5
+ enablePan: boolean;
6
+ }
7
+
8
+ export interface IBarChartGraph {
9
+ showDataLabels: boolean;
10
+ showMinorGridlines: boolean;
11
+ }
12
+
13
+ export interface IBarChartTooltip {
14
+ tooltips: boolean;
15
+ showLabelsInTooltips: boolean;
16
+ }
17
+
18
+ export interface IBarChartAdditionalAxesOptions {
19
+ chartScaleType: 'linear' | 'logarithmic';
20
+ reverse: boolean;
21
+ beginAtZero: boolean;
22
+ stepSize: number;
23
+ stacked: boolean;
24
+ suggestedMin: number;
25
+ suggestedMax:number;
26
+ min: number;
27
+ max: number;
28
+ }
29
+
30
+ export interface IBarChartAxes<PositionType> {
31
+ label: string;
32
+ position: PositionType;
33
+ color: string;
34
+ unit: string;
35
+ }
36
+
37
+ export interface IBarChartOptions {
38
+ title: string | string[];
39
+ direction: 'vertical' | 'horizontal';
40
+ axes: {
41
+ x: IBarChartAxes<'top' | 'bottom'>[];
42
+ y: IBarChartAxes<'left' | 'right'>[];
43
+ };
44
+ additionalAxesOptions: IBarChartAdditionalAxesOptions;
45
+ chartStyling: IChartStyling;
46
+ tooltip: IBarChartTooltip;
47
+ graph: IBarChartGraph;
48
+ annotations: IChartAnnotations;
49
+ legend: IChartLegend;
50
+ chartOptions: IChartOptions;
51
+ interactions: IChartInteractions;
52
+ }
53
+
54
+ export interface IBarDataPoint {
55
+ x: number;
56
+ y: number;
57
+ label?: string;
58
+ }
59
+
60
+ export interface IBarChartDataset {
61
+ label?: string;
62
+ data: number[] | number[][] | IBarDataPoint[];
63
+ borderSkipped?: string;
64
+ backgroundColor?: string[];
65
+ borderColor?: string[];
66
+ borderRadius?: number;
67
+ borderWidth?: number;
68
+ yAxisID?: string;
69
+ stack?: number;
70
+ }
71
+
72
+ export interface IBarChartData {
73
+ //TODO: revisit data interface definition after project is more stable
74
+ testId: string | null;
75
+ data: {
76
+ labels?: string[],
77
+ datasets: IBarChartDataset[]
78
+ } | any;
79
+ options: IBarChartOptions;
80
+ }
81
+
82
+ export interface IBarChartProps {
83
+ chart: IBarChartData;
84
+ }