@oliasoft-open-source/charts-library 2.0.0

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 (79) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.js +129 -0
  3. package/.gitlab-ci.yml +77 -0
  4. package/.husky/pre-commit +4 -0
  5. package/.prettierignore +3 -0
  6. package/.prettierrc +4 -0
  7. package/.storybook/main.js +40 -0
  8. package/LICENSE +21 -0
  9. package/README.md +5 -0
  10. package/babel.config.js +29 -0
  11. package/index.js +9 -0
  12. package/jest.config.js +9 -0
  13. package/package.json +96 -0
  14. package/src/components/bar-chart/bar-chart-prop-types.js +181 -0
  15. package/src/components/bar-chart/bar-chart.interface.ts +83 -0
  16. package/src/components/bar-chart/bar-chart.jsx +247 -0
  17. package/src/components/bar-chart/bar-chart.module.less +56 -0
  18. package/src/components/bar-chart/basic.stories.jsx +752 -0
  19. package/src/components/bar-chart/charts.stories.jsx +119 -0
  20. package/src/components/bar-chart/get-bar-chart-data-labels.js +45 -0
  21. package/src/components/bar-chart/get-bar-chart-scales.js +147 -0
  22. package/src/components/bar-chart/get-bar-chart-tooltips.js +100 -0
  23. package/src/components/line-chart/Controls/Controls.jsx +59 -0
  24. package/src/components/line-chart/Controls/Controls.module.less +21 -0
  25. package/src/components/line-chart/Controls/Layer.jsx +169 -0
  26. package/src/components/line-chart/basic.stories.jsx +735 -0
  27. package/src/components/line-chart/charts.stories.jsx +264 -0
  28. package/src/components/line-chart/get-line-chart-data-labels.js +24 -0
  29. package/src/components/line-chart/get-line-chart-scales.js +131 -0
  30. package/src/components/line-chart/get-line-chart-tooltips.js +91 -0
  31. package/src/components/line-chart/line-chart-consts.js +6 -0
  32. package/src/components/line-chart/line-chart-prop-types.js +187 -0
  33. package/src/components/line-chart/line-chart-utils.js +163 -0
  34. package/src/components/line-chart/line-chart.interface.ts +103 -0
  35. package/src/components/line-chart/line-chart.jsx +423 -0
  36. package/src/components/line-chart/line-chart.minor-gridlines-plugin.js +78 -0
  37. package/src/components/line-chart/line-chart.minor-gridlines-plugin.test.js +34 -0
  38. package/src/components/line-chart/line-chart.module.less +56 -0
  39. package/src/components/line-chart/state/action-types.js +9 -0
  40. package/src/components/line-chart/state/initial-state.js +51 -0
  41. package/src/components/line-chart/state/line-chart-reducer.js +115 -0
  42. package/src/components/line-chart/stories/shapes/cubes.stories.jsx +326 -0
  43. package/src/components/line-chart/stories/shapes/pyramid.stories.jsx +189 -0
  44. package/src/components/line-chart/stories/shapes/round.stories.jsx +339 -0
  45. package/src/components/line-chart/stories/shapes/triangle.stories.jsx +166 -0
  46. package/src/components/pie-chart/basic.stories.jsx +390 -0
  47. package/src/components/pie-chart/charts.stories.jsx +66 -0
  48. package/src/components/pie-chart/pie-chart-prop-types.js +111 -0
  49. package/src/components/pie-chart/pie-chart-utils.js +55 -0
  50. package/src/components/pie-chart/pie-chart.interface.ts +61 -0
  51. package/src/components/pie-chart/pie-chart.jsx +477 -0
  52. package/src/components/pie-chart/pie-chart.module.less +56 -0
  53. package/src/components/scatter-chart/scatter-chart.intefrace.ts +32 -0
  54. package/src/components/scatter-chart/scatter-chart.jsx +13 -0
  55. package/src/components/scatter-chart/scatter.stories.jsx +196 -0
  56. package/src/helpers/chart-consts.js +82 -0
  57. package/src/helpers/chart-interface.ts +54 -0
  58. package/src/helpers/chart-utils.js +178 -0
  59. package/src/helpers/container.jsx +60 -0
  60. package/src/helpers/disabled-context.js +8 -0
  61. package/src/helpers/enums.js +84 -0
  62. package/src/helpers/get-chart-annotation.js +91 -0
  63. package/src/helpers/styles.js +68 -0
  64. package/src/helpers/text.js +6 -0
  65. package/src/style/external.less +4 -0
  66. package/src/style/fonts/lato/Lato-Bold.woff2 +0 -0
  67. package/src/style/fonts/lato/Lato-BoldItalic.woff2 +0 -0
  68. package/src/style/fonts/lato/Lato-Italic.woff2 +0 -0
  69. package/src/style/fonts/lato/Lato-Regular.woff2 +0 -0
  70. package/src/style/fonts.less +27 -0
  71. package/src/style/global.less +43 -0
  72. package/src/style/reset/reset.less +28 -0
  73. package/src/style/shared.less +24 -0
  74. package/src/style/variables.less +91 -0
  75. package/webpack/webpack.common.js +39 -0
  76. package/webpack/webpack.common.rules.js +107 -0
  77. package/webpack/webpack.dev.js +22 -0
  78. package/webpack/webpack.prod.js +23 -0
  79. package/webpack/webpack.resolve.js +22 -0
package/.eslintignore ADDED
@@ -0,0 +1,2 @@
1
+ node_modules
2
+ public
package/.eslintrc.js ADDED
@@ -0,0 +1,129 @@
1
+ module.exports = {
2
+ env: {
3
+ browser: true,
4
+ es2021: true,
5
+ node: true,
6
+ jest: true,
7
+ },
8
+ extends: ['plugin:react/recommended', 'airbnb', 'prettier'],
9
+ parser: '@babel/eslint-parser',
10
+ parserOptions: {
11
+ ecmaFeatures: {
12
+ jsx: true,
13
+ },
14
+ ecmaVersion: 12,
15
+ sourceType: 'module',
16
+ },
17
+ plugins: ['react'],
18
+ settings: {
19
+ 'import/resolver': {
20
+ alias: {
21
+ map: [
22
+ ['~components', './src/components'],
23
+ ['~docs', './src/docs'],
24
+ ['~helpers', './src/helpers'],
25
+ ['~style', './src/style'],
26
+ ['~vendor', './src/vendor'],
27
+ ],
28
+ extensions: ['.js', '.jsx'],
29
+ },
30
+ },
31
+ },
32
+ rules: {
33
+ 'arrow-parens': 0,
34
+ 'array-callback-return': 0,
35
+ camelcase: 0,
36
+ 'comma-dangle': 0,
37
+ 'consistent-return': 0,
38
+ curly: 0,
39
+ 'class-methods-use-this': 0,
40
+ 'default-case': 0,
41
+ eqeqeq: 0,
42
+ 'eol-last': 0,
43
+ 'function-paren-newline': 0,
44
+ 'max-len': 0,
45
+ 'import/extensions': 0,
46
+ 'import/prefer-default-export': 0,
47
+ 'object-curly-newline': 0,
48
+ 'object-curly-spacing': 0,
49
+ 'one-var-declaration-per-line': 0,
50
+ 'one-var': 0,
51
+ radix: 0,
52
+ 'prefer-template': 0,
53
+ 'prefer-const': 0,
54
+ 'prefer-destructuring': [
55
+ 'error',
56
+ {
57
+ VariableDeclarator: {
58
+ array: false,
59
+ object: true,
60
+ },
61
+ AssignmentExpression: {
62
+ array: false,
63
+ object: false,
64
+ },
65
+ },
66
+ {
67
+ enforceForRenamedProperties: false,
68
+ },
69
+ ],
70
+ 'spaced-comment': 0,
71
+ 'no-multi-spaces': 0,
72
+ 'arrow-body-style': 0,
73
+ 'no-shadow': 0,
74
+ 'no-else-return': 0,
75
+ 'no-param-reassign': 0,
76
+ 'no-plusplus': 0,
77
+ 'no-restricted-globals': 0,
78
+ 'no-unused-vars': 0,
79
+ 'no-unused-state': 0,
80
+ 'no-case-declarations': 0,
81
+ 'no-return-assign': 0,
82
+ 'no-prototype-builtins': 0,
83
+ 'no-restricted-syntax': 0,
84
+ 'no-cond-assign': [2, 'except-parens'],
85
+ 'no-console': 0,
86
+ 'no-constant-condition': 0,
87
+ 'no-underscore-dangle': 0,
88
+ 'no-restricted-properties': 0,
89
+ 'no-nested-ternary': 0,
90
+ 'no-mixed-operators': 0,
91
+ 'no-confusing-arrow': 0,
92
+ 'no-lonely-if': 0,
93
+ 'nonblock-statement-body-position': 0,
94
+ 'react/jsx-tag-spacing': 0,
95
+ 'react/jsx-one-expression-per-line': 0,
96
+ 'react/no-array-index-key': 0,
97
+ 'react/forbid-prop-types': 0,
98
+ 'react/destructuring-assignment': 0,
99
+ 'react/no-unused-state': 0,
100
+ 'react/no-access-state-in-setstate': 0,
101
+ 'react/no-did-update-set-state': 0,
102
+ 'react/prop-types': 0,
103
+ 'react/self-closing-comp': [
104
+ 'error',
105
+ {
106
+ component: true,
107
+ html: false,
108
+ },
109
+ ],
110
+ 'jsx-a11y/no-static-element-interactions': 0,
111
+ 'jsx-a11y/click-events-have-key-events': 0,
112
+ 'jsx-a11y/tabindex-no-positive': 0,
113
+ 'jsx-a11y/label-has-associated-control': 0,
114
+ 'jsx-a11y/label-has-for': 0,
115
+ 'react/function-component-definition': [
116
+ 2,
117
+ { namedComponents: 'arrow-function' },
118
+ ],
119
+ 'import/no-extraneous-dependencies': [
120
+ 'error',
121
+ {
122
+ devDependencies: [
123
+ 'src/components/**/*.stories.{js,jsx}',
124
+ 'webpack/**/*.js',
125
+ ],
126
+ },
127
+ ],
128
+ },
129
+ };
package/.gitlab-ci.yml ADDED
@@ -0,0 +1,77 @@
1
+ image: node:18
2
+
3
+ stages:
4
+ - test
5
+ - release
6
+
7
+ default:
8
+ tags:
9
+ - oliasoft
10
+ - kubernetes
11
+
12
+ test:
13
+ stage: test
14
+ only:
15
+ - merge_requests
16
+ script:
17
+ - npm install --progress=false --no-save
18
+ - npm run build
19
+ - npm run test
20
+
21
+ cache:
22
+ paths:
23
+ - node_modules/
24
+ - public/
25
+
26
+ # Publish the Storybook to Gitlab pages upon merge to master
27
+ pages:
28
+ stage: release
29
+ only:
30
+ - master
31
+ script:
32
+ - npm install --progress=false --no-save
33
+ - npm run build
34
+ artifacts:
35
+ paths:
36
+ - public
37
+
38
+ # Push a tag and publish the release to the public NPM registry upon merge to master
39
+ # Loosely inspired by:
40
+ # - https://markswanderingthoughts.nl/tagging-in-gitlab-ci-pipeline-using-deploy-keys/
41
+ # - https://www.garybell.co.uk/creating-a-release-with-gitlab-ci-and-composer/
42
+ publish:
43
+ stage: release
44
+ only:
45
+ - master
46
+ script:
47
+ # Get the version from package.json
48
+ - VERSION=$(node -p "require('./package.json').version")
49
+ # Prepare .npmrc
50
+ - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
51
+ # Configure git
52
+ - mkdir -p ~/.ssh
53
+ - echo "$SSH_PRIVATE_KEY_TOOLKIT" > ~/.ssh/id_rsa; chmod 0600 ~/.ssh/id_rsa
54
+ - echo "StrictHostKeyChecking no " > /root/.ssh/config
55
+ - git config --global http.sslVerify false
56
+ - git config --global user.email "$GITLAB_USER_EMAIL"
57
+ - git config --global user.name "🤖 GitLab CI/CD"
58
+ - echo "setting origin remote to 'git@$CI_SERVER_HOST:$CI_PROJECT_PATH.git'"
59
+ - git remote rm origin
60
+ - git remote add origin git@$CI_SERVER_HOST:$CI_PROJECT_PATH.git
61
+ - git fetch --quiet
62
+ - git checkout "$CI_BUILD_REF_NAME"
63
+ # Only complete pipeline if version does not already exist
64
+ - >
65
+ if [ $(git tag -l "$VERSION") ]; then
66
+ echo "Version $VERSION already exists"
67
+ exit 1
68
+ else
69
+ # Tag a release in gitlab
70
+ echo "Tagging release in git"
71
+ git tag $VERSION -m "🤖 Tagged by Gitlab CI/CD Pipeline" -m "For further reference see $CI_PIPELINE_URL" -m "[skip ci]"
72
+ echo "Pushing tag to remote repository"
73
+ git push origin $VERSION --no-verify
74
+ # Publish the NPM package to the public NPM registry
75
+ echo "Publishing package to NPM registry"
76
+ npm publish
77
+ fi
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npx lint-staged
@@ -0,0 +1,3 @@
1
+ node_modules
2
+ public
3
+ dist
package/.prettierrc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all"
4
+ }
@@ -0,0 +1,40 @@
1
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
2
+ const getRules = require('../webpack/webpack.common.rules.js');
3
+ const resolve = require('../webpack/webpack.resolve.js').resolve;
4
+
5
+ module.exports = {
6
+ stories: ['../src/components/**/*.stories.@(js|jsx|mdx)'],
7
+ addons: [
8
+ '@storybook/addon-actions/register',
9
+ '@storybook/addon-links/register',
10
+ '@storybook/addon-storysource',
11
+ '@storybook/addon-docs',
12
+ ],
13
+ core: {
14
+ builder: 'webpack5',
15
+ },
16
+ webpackFinal: (config) => {
17
+ const rules = getRules('development');
18
+
19
+ config.module.rules = []; //delete default storybook rules because they conflict (postcss causes a conflict)
20
+
21
+ rules.forEach((r) => {
22
+ config.module.rules.push(r);
23
+ });
24
+
25
+ return {
26
+ ...config,
27
+ module: {
28
+ ...config.module,
29
+ rules: [...rules], //attach our own rules from the application webpack config
30
+ },
31
+ plugins: [
32
+ ...config.plugins,
33
+ new MiniCssExtractPlugin({
34
+ filename: '[name].css',
35
+ }),
36
+ ],
37
+ resolve,
38
+ };
39
+ },
40
+ };
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,5 @@
1
+ # React UI Library
2
+
3
+ React UI Library is a collection of reusable UI components for use in React applications.
4
+
5
+ For usage instructions and technical documentation, see the [Wiki](https://gitlab.com/oliasoft-open-source/react-ui-library/wikis/home).
@@ -0,0 +1,29 @@
1
+ module.exports = (api) => {
2
+ api.cache(true);
3
+
4
+ const presets = [
5
+ [
6
+ '@babel/preset-env',
7
+ {
8
+ targets: {
9
+ browsers: ['defaults'],
10
+ },
11
+ useBuiltIns: 'usage',
12
+ corejs: 3,
13
+ },
14
+ ],
15
+ '@babel/preset-react',
16
+ ];
17
+
18
+ const plugins = [
19
+ [
20
+ 'babel-plugin-webpack-aliases',
21
+ { config: './webpack/webpack.resolve.js' },
22
+ ],
23
+ ];
24
+
25
+ return {
26
+ presets,
27
+ plugins,
28
+ };
29
+ };
package/index.js ADDED
@@ -0,0 +1,9 @@
1
+ /*
2
+ Components
3
+ */
4
+
5
+ export { LineChart } from './src/components/line-chart/line-chart';
6
+
7
+ export { PieChart } from './src/components/pie-chart/pie-chart';
8
+
9
+ export { BarChart } from './src/components/bar-chart/bar-chart';
package/jest.config.js ADDED
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ transform: {
3
+ '^.+\\.jsx?$': 'babel-jest',
4
+ '.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$':
5
+ 'jest-transform-stub',
6
+ },
7
+ moduleFileExtensions: ['js', 'jsx'],
8
+ moduleDirectories: ['node_modules'],
9
+ };
package/package.json ADDED
@@ -0,0 +1,96 @@
1
+ {
2
+ "name": "@oliasoft-open-source/charts-library",
3
+ "version": "2.0.0",
4
+ "description": "React Chart Library (based on Chart.js and react-chart-js-2)",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "build": "npm run build:storybook",
8
+ "build:storybook": "build-storybook --quiet --output-dir ./public/storybook",
9
+ "dev:storybook": "start-storybook -p 6006",
10
+ "test": "npm run prettier:check && npm run lint:check && npm run test:unit",
11
+ "test:unit": "jest",
12
+ "lint:check": "eslint \"**/*.{js,jsx}\"",
13
+ "lint:fix": "eslint --fix \"**/*.{js,jsx}\"",
14
+ "prettier:check": "prettier --check \"**/*.{js,jsx,json,css,less}\"",
15
+ "prettier:fix": "prettier --write \"**/*.{js,jsx,json,css,less}\"",
16
+ "prepare": "husky install"
17
+ },
18
+ "lint-staged": {
19
+ "*.js": "eslint --cache --fix",
20
+ "*.{js,jsx,json,css,less}": [
21
+ "prettier --write"
22
+ ]
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://gitlab.com/oliasoft-open-source/charts-library.git"
27
+ },
28
+ "author": "Oliasoft AS and contributors",
29
+ "license": "MIT",
30
+ "bugs": {
31
+ "url": "https://gitlab.com/oliasoft-open-source/charts-library/issues"
32
+ },
33
+ "homepage": "https://gitlab.com/oliasoft-open-source/charts-library",
34
+ "devDependencies": {
35
+ "@babel/core": "^7.18.13",
36
+ "@babel/eslint-parser": "^7.18.9",
37
+ "@babel/preset-env": "^7.18.10",
38
+ "@babel/preset-react": "^7.18.6",
39
+ "@storybook/addon-actions": "^6.5.10",
40
+ "@storybook/addon-docs": "^6.5.10",
41
+ "@storybook/addon-links": "^6.5.10",
42
+ "@storybook/addon-storysource": "^6.5.10",
43
+ "@storybook/addons": "^6.5.10",
44
+ "@storybook/builder-webpack5": "^6.5.10",
45
+ "@storybook/manager-webpack5": "^6.5.10",
46
+ "@storybook/react": "^6.5.10",
47
+ "@storybook/source-loader": "^6.5.10",
48
+ "@types/react": "^17.0.49",
49
+ "babel-jest": "^29.0.1",
50
+ "babel-plugin-webpack-aliases": "^1.1.3",
51
+ "css-loader": "^6.7.1",
52
+ "css-minimizer-webpack-plugin": "^4.0.0",
53
+ "eslint": "^8.23.0",
54
+ "eslint-config-airbnb": "^19.0.4",
55
+ "eslint-config-prettier": "^8.5.0",
56
+ "eslint-import-resolver-alias": "^1.1.2",
57
+ "eslint-plugin-import": "^2.26.0",
58
+ "eslint-plugin-jsx-a11y": "^6.6.1",
59
+ "eslint-plugin-react": "^7.31.1",
60
+ "eslint-plugin-react-hooks": "^4.6.0",
61
+ "html-webpack-plugin": "^5.5.0",
62
+ "husky": "^8.0.1",
63
+ "jest": "^29.0.1",
64
+ "jest-transform-stub": "^2.0.0",
65
+ "less": "^4.1.3",
66
+ "less-loader": "^11.0.0",
67
+ "lint-staged": "^13.0.3",
68
+ "mini-css-extract-plugin": "^2.6.1",
69
+ "prettier": "2.7.1",
70
+ "react": "^17.0.2",
71
+ "react-dom": "^17.0.2",
72
+ "terser-webpack-plugin": "^5.3.6",
73
+ "webpack": "^5.74.0",
74
+ "webpack-cli": "^4.10.0",
75
+ "webpack-dev-server": "^4.10.1",
76
+ "webpack-merge": "^5.8.0"
77
+ },
78
+ "peerDependencies": {
79
+ "react": "^17.0",
80
+ "react-dom": "^17.0"
81
+ },
82
+ "dependencies": {
83
+ "@oliasoft-open-source/react-ui-library": "^2.2.2",
84
+ "chart.js": "^3.9.1",
85
+ "chartjs-plugin-annotation": "^1.4.0",
86
+ "chartjs-plugin-datalabels": "^2.1.0",
87
+ "chartjs-plugin-zoom": "^1.2.1",
88
+ "classnames": "^2.3.1",
89
+ "fraction.js": "^4.2.0",
90
+ "less-vars-to-js": "^1.3.0",
91
+ "prop-types": "^15.8.1",
92
+ "react-base64-downloader": "^2.1.7",
93
+ "react-chartjs-2": "^4.3.1",
94
+ "react-icons": "^4.4.0"
95
+ }
96
+ }
@@ -0,0 +1,181 @@
1
+ import PropTypes from 'prop-types';
2
+
3
+ export const BarChartPropTypes = {
4
+ chart: PropTypes.shape({
5
+ data: PropTypes.object.isRequired,
6
+ options: PropTypes.shape({
7
+ title: PropTypes.oneOfType([
8
+ PropTypes.string,
9
+ PropTypes.arrayOf(PropTypes.string),
10
+ ]),
11
+ direction: PropTypes.oneOf(['vertical', 'horizontal']),
12
+ axes: PropTypes.shape({
13
+ x: PropTypes.arrayOf(
14
+ PropTypes.shape({
15
+ label: PropTypes.string,
16
+ position: PropTypes.oneOf(['top', 'bottom']),
17
+ color: PropTypes.string,
18
+ unit: PropTypes.string,
19
+ }),
20
+ ),
21
+ y: PropTypes.arrayOf(
22
+ PropTypes.shape({
23
+ label: PropTypes.string,
24
+ position: PropTypes.oneOf(['left', 'right']),
25
+ color: PropTypes.string,
26
+ unit: PropTypes.string,
27
+ }),
28
+ ),
29
+ }),
30
+ additionalAxesOptions: PropTypes.shape({
31
+ chartScaleType: PropTypes.oneOf(['linear', 'logarithmic']),
32
+ reverse: PropTypes.bool,
33
+ beginAtZero: PropTypes.bool,
34
+ stepSize: PropTypes.number,
35
+ stacked: PropTypes.bool,
36
+ suggestedMin: PropTypes.number,
37
+ suggestedMax: PropTypes.number,
38
+ min: PropTypes.number,
39
+ max: PropTypes.number,
40
+ }),
41
+ chartStyling: PropTypes.shape({
42
+ width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
43
+ height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
44
+ maintainAspectRatio: PropTypes.bool,
45
+ staticChartHeight: PropTypes.bool,
46
+ performanceMode: PropTypes.bool,
47
+ darkMode: 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
+ }),
75
+ chartOptions: PropTypes.shape({
76
+ enableZoom: PropTypes.bool,
77
+ enablePan: PropTypes.bool,
78
+ }),
79
+ interactions: PropTypes.shape({
80
+ onLegendClick: PropTypes.func,
81
+ onBarHover: PropTypes.func,
82
+ onBarUnhover: PropTypes.func,
83
+ }),
84
+ }),
85
+ }).isRequired,
86
+ };
87
+
88
+ export const getDefaultProps = (props) => {
89
+ // Add missing nested objects
90
+ props.chart.options = props.chart.options || {};
91
+ props.chart.options.axes = props.chart.options.axes || {};
92
+ props.chart.options.additionalAxesOptions =
93
+ props.chart.options.additionalAxesOptions || {};
94
+ props.chart.options.chartStyling = props.chart.options.chartStyling || {};
95
+ props.chart.options.tooltip = props.chart.options.tooltip || {};
96
+ props.chart.options.graph = props.chart.options.graph || {};
97
+ props.chart.options.annotations = props.chart.options.annotations || {};
98
+ props.chart.options.legend = props.chart.options.legend || {};
99
+ props.chart.options.chartOptions = props.chart.options.chartOptions || {};
100
+ props.chart.options.interactions = props.chart.options.interactions || {};
101
+ // Set defaults for missing properties
102
+ const chart = {
103
+ data: props.chart.data,
104
+ options: {
105
+ title: props.chart.options.title || '',
106
+ direction: props.chart.options.direction || 'vertical',
107
+ axes: {
108
+ x: props.chart.options.axes.x || [{}],
109
+ y: props.chart.options.axes.y || [{}],
110
+ },
111
+ additionalAxesOptions: {
112
+ chartScaleType:
113
+ props.chart.options.additionalAxesOptions.chartScaleType || 'linear',
114
+ reverse: props.chart.options.additionalAxesOptions.reverse || false,
115
+ stacked: props.chart.options.additionalAxesOptions.stacked || false,
116
+ beginAtZero:
117
+ props.chart.options.additionalAxesOptions.beginAtZero != null
118
+ ? props.chart.options.additionalAxesOptions.beginAtZero
119
+ : true,
120
+ stepSize: props.chart.options.additionalAxesOptions.stepSize,
121
+ suggestedMin: props.chart.options.additionalAxesOptions.suggestedMin,
122
+ suggestedMax: props.chart.options.additionalAxesOptions.suggestedMax,
123
+ min: props.chart.options.additionalAxesOptions.min,
124
+ max: props.chart.options.additionalAxesOptions.max,
125
+ },
126
+ chartStyling: {
127
+ width: props.chart.options.chartStyling.width,
128
+ height: props.chart.options.chartStyling.height,
129
+ maintainAspectRatio:
130
+ props.chart.options.chartStyling.maintainAspectRatio || false,
131
+ staticChartHeight:
132
+ props.chart.options.chartStyling.staticChartHeight || false,
133
+ performanceMode:
134
+ props.chart.options.chartStyling.performanceMode != null
135
+ ? props.chart.options.chartStyling.performanceMode
136
+ : true,
137
+ darkMode: props.chart.options.chartStyling.darkMode || false,
138
+ },
139
+ tooltip: {
140
+ tooltips:
141
+ props.chart.options.tooltip.tooltips != null
142
+ ? props.chart.options.tooltip.tooltips
143
+ : true,
144
+ showLabelsInTooltips:
145
+ props.chart.options.tooltip.showLabelsInTooltips || false,
146
+ },
147
+ graph: {
148
+ showDataLabels: props.chart.options.graph.showDataLabels || false,
149
+ showMinorGridlines:
150
+ props.chart.options.graph.showMinorGridlines || false,
151
+ },
152
+ annotations: {
153
+ showAnnotations:
154
+ props.chart.options.annotations.showAnnotations != null
155
+ ? props.chart.options.annotations.showAnnotations
156
+ : true,
157
+ controlAnnotation:
158
+ props.chart.options.annotations.controlAnnotation || false,
159
+ annotationsData: props.chart.options.annotations.annotationsData || [],
160
+ },
161
+ legend: {
162
+ display:
163
+ props.chart.options.legend.display != null
164
+ ? props.chart.options.legend.display
165
+ : true,
166
+ position: props.chart.options.legend.position || 'bottom',
167
+ align: props.chart.options.legend.align || 'center',
168
+ },
169
+ chartOptions: {
170
+ enableZoom: props.chart.options.chartOptions.enableZoom || false,
171
+ enablePan: props.chart.options.chartOptions.enablePan || false,
172
+ },
173
+ interactions: {
174
+ onLegendClick: props.chart.options.interactions.onLegendClick,
175
+ onBarHover: props.chart.options.interactions.onBarHover,
176
+ onBarUnhover: props.chart.options.interactions.onBarUnhover,
177
+ },
178
+ },
179
+ };
180
+ return chart;
181
+ };