@oliasoft-open-source/charts-library 2.0.1 → 2.1.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 (31) hide show
  1. package/.gitlab-ci.yml +6 -3
  2. package/.storybook/main.js +18 -22
  3. package/.storybook/preview.js +37 -0
  4. package/.storybook/storybook.less +8 -0
  5. package/package.json +3 -2
  6. package/scripts/send-mattermost-message.sh +21 -0
  7. package/src/components/bar-chart/bar-chart-prop-types.js +7 -0
  8. package/src/components/bar-chart/bar-chart.jsx +7 -2
  9. package/src/components/bar-chart/{basic.stories.jsx → bar-chart.stories.jsx} +108 -371
  10. package/src/components/line-chart/Controls/Controls.jsx +2 -0
  11. package/src/components/line-chart/Controls/Layer.jsx +52 -49
  12. package/src/components/line-chart/line-chart-prop-types.js +10 -0
  13. package/src/components/line-chart/line-chart.jsx +91 -10
  14. package/src/components/line-chart/line-chart.module.less +5 -0
  15. package/src/components/line-chart/line-chart.stories.jsx +393 -0
  16. package/src/components/line-chart/state/line-chart-reducer.js +26 -15
  17. package/src/components/pie-chart/pie-chart.stories.jsx +234 -0
  18. package/src/components/scatter-chart/{scatter.stories.jsx → scatter-chart.stories.jsx} +25 -79
  19. package/src/helpers/chart-consts.js +2 -0
  20. package/src/helpers/chart-interface.ts +9 -0
  21. package/src/helpers/chart-utils.js +24 -4
  22. package/src/helpers/get-custom-legend-plugin-example.js +81 -0
  23. package/src/components/bar-chart/charts.stories.jsx +0 -119
  24. package/src/components/line-chart/basic.stories.jsx +0 -735
  25. package/src/components/line-chart/charts.stories.jsx +0 -264
  26. package/src/components/line-chart/stories/shapes/cubes.stories.jsx +0 -326
  27. package/src/components/line-chart/stories/shapes/pyramid.stories.jsx +0 -189
  28. package/src/components/line-chart/stories/shapes/round.stories.jsx +0 -339
  29. package/src/components/line-chart/stories/shapes/triangle.stories.jsx +0 -166
  30. package/src/components/pie-chart/basic.stories.jsx +0 -390
  31. package/src/components/pie-chart/charts.stories.jsx +0 -66
package/.gitlab-ci.yml CHANGED
@@ -46,6 +46,9 @@ publish:
46
46
  script:
47
47
  # Get the version from package.json
48
48
  - VERSION=$(node -p "require('./package.json').version")
49
+ # Prepare MatterMost message
50
+ - MESSAGE="🤖 Charts Library version $VERSION released"
51
+ - chmod +x ./scripts/send-mattermost-message.sh
49
52
  # Prepare .npmrc
50
53
  - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
51
54
  # Configure git
@@ -66,12 +69,12 @@ publish:
66
69
  echo "Version $VERSION already exists"
67
70
  exit 1
68
71
  else
69
- # Tag a release in gitlab
70
72
  echo "Tagging release in git"
71
73
  git tag $VERSION -m "🤖 Tagged by Gitlab CI/CD Pipeline" -m "For further reference see $CI_PIPELINE_URL" -m "[skip ci]"
72
74
  echo "Pushing tag to remote repository"
73
75
  git push origin $VERSION --no-verify
74
- # Publish the NPM package to the public NPM registry
75
76
  echo "Publishing package to NPM registry"
76
77
  npm publish
77
- fi
78
+ echo "Notifying MatterMost"
79
+ ./scripts/send-mattermost-message.sh "$MATTERMOST_BOT_KEY" "$MESSAGE"
80
+ fi
@@ -1,3 +1,4 @@
1
+ const { merge } = require('webpack-merge');
1
2
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
2
3
  const getRules = require('../webpack/webpack.common.rules.js');
3
4
  const resolve = require('../webpack/webpack.resolve.js').resolve;
@@ -5,36 +6,31 @@ const resolve = require('../webpack/webpack.resolve.js').resolve;
5
6
  module.exports = {
6
7
  stories: ['../src/components/**/*.stories.@(js|jsx|mdx)'],
7
8
  addons: [
8
- '@storybook/addon-actions/register',
9
- '@storybook/addon-links/register',
10
- '@storybook/addon-storysource',
11
- '@storybook/addon-docs',
9
+ '@storybook/addon-actions',
10
+ {
11
+ name: '@storybook/addon-docs',
12
+ options: {
13
+ sourceLoaderOptions: {
14
+ injectStoryParameters: false,
15
+ },
16
+ },
17
+ },
18
+ 'storybook-dark-mode',
12
19
  ],
20
+ features: {
21
+ modernInlineRender: true,
22
+ },
13
23
  core: {
14
24
  builder: 'webpack5',
15
25
  },
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
- },
26
+ webpackFinal: (config) =>
27
+ merge(config, {
28
+ module: { rules: getRules('development') },
31
29
  plugins: [
32
- ...config.plugins,
33
30
  new MiniCssExtractPlugin({
34
31
  filename: '[name].css',
35
32
  }),
36
33
  ],
37
34
  resolve,
38
- };
39
- },
35
+ }),
40
36
  };
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import { useDarkMode } from 'storybook-dark-mode';
3
+ import { themes } from '@storybook/theming';
4
+ import { DocsContainer } from '@storybook/addon-docs';
5
+ import '@oliasoft-open-source/react-ui-library/src/style/global.less';
6
+ import './storybook.less';
7
+
8
+ /**
9
+ * Dark mode for GUI Library components (i.e. Controls)
10
+ */
11
+ export const decorators = [
12
+ (Story) => {
13
+ document.documentElement.setAttribute(
14
+ 'data-theme',
15
+ useDarkMode() ? 'dark' : 'default',
16
+ );
17
+ return <Story />;
18
+ },
19
+ ];
20
+
21
+ export const parameters = {
22
+ /**
23
+ * Fix for dark mode docs from https://github.com/hipstersmoothie/storybook-dark-mode/issues/180
24
+ */
25
+ docs: {
26
+ container: (props) => {
27
+ const isDark = useDarkMode();
28
+ const { id: storyId, storyById } = props.context;
29
+ const {
30
+ parameters: { docs = {} },
31
+ } = storyById(storyId);
32
+ docs.theme = isDark ? themes.dark : themes.light;
33
+
34
+ return React.createElement(DocsContainer, props);
35
+ },
36
+ },
37
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Fix for Firefox story height bug
3
+ */
4
+ @-moz-document url-prefix() {
5
+ .docs-story > div > div {
6
+ height: 100% !important;
7
+ }
8
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/charts-library",
3
- "version": "2.0.1",
3
+ "version": "2.1.1",
4
4
  "description": "React Chart Library (based on Chart.js and react-chart-js-2)",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "build": "npm run build:storybook",
8
- "build:storybook": "build-storybook --quiet --output-dir ./public/storybook",
8
+ "build:storybook": "build-storybook --quiet --output-dir ./public",
9
9
  "dev:storybook": "start-storybook -p 6006",
10
10
  "test": "npm run prettier:check && npm run lint:check && npm run test:unit",
11
11
  "test:unit": "jest",
@@ -69,6 +69,7 @@
69
69
  "prettier": "2.7.1",
70
70
  "react": "^17.0.2",
71
71
  "react-dom": "^17.0.2",
72
+ "storybook-dark-mode": "^1.1.0",
72
73
  "terser-webpack-plugin": "^5.3.6",
73
74
  "webpack": "^5.74.0",
74
75
  "webpack-cli": "^4.10.0",
@@ -0,0 +1,21 @@
1
+ #!/bin/bash
2
+ set -eEuo pipefail
3
+
4
+ # This script requires the following things to be installed:
5
+ # - bash
6
+ # - curl
7
+
8
+ # Required inputs:
9
+ MATTERMOST_BOT_KEY=$1
10
+ MSG=$2
11
+
12
+ # Optional inputs:
13
+ CHANNEL=${3:-'#releases'}
14
+ USERNAME=${4:-'Gitlab CI/CD'}
15
+ ICON_URL=${5:-'https://oliasoftstaticwebsite.blob.core.windows.net/helpguideimages/robot-icon.png'}
16
+ MATTERMOST_URL=${6:-'https://mm.oliasoft.com/hooks/'}
17
+
18
+ curl -X POST \
19
+ --data-urlencode \
20
+ "payload={\"channel\": \"$CHANNEL\", \"username\": \"$USERNAME\", \"icon_url\": \"$ICON_URL\", \"text\": \"$MSG\"}" \
21
+ $MATTERMOST_URL$MATTERMOST_BOT_KEY
@@ -71,6 +71,10 @@ export const BarChartPropTypes = {
71
71
  display: PropTypes.bool,
72
72
  position: PropTypes.oneOf(['top', 'bottom', 'right']),
73
73
  align: PropTypes.oneOf(['start', 'center', 'end']),
74
+ customLegend: PropTypes.shape({
75
+ customLegendPlugin: PropTypes.object,
76
+ customLegendContainerID: PropTypes.string,
77
+ }),
74
78
  }),
75
79
  chartOptions: PropTypes.shape({
76
80
  enableZoom: PropTypes.bool,
@@ -96,6 +100,8 @@ export const getDefaultProps = (props) => {
96
100
  props.chart.options.graph = props.chart.options.graph || {};
97
101
  props.chart.options.annotations = props.chart.options.annotations || {};
98
102
  props.chart.options.legend = props.chart.options.legend || {};
103
+ props.chart.options.legend.customLegend = props.chart.options.legend
104
+ .customLegend || { customLegendPlugin: null, customLegendContainerID: '' };
99
105
  props.chart.options.chartOptions = props.chart.options.chartOptions || {};
100
106
  props.chart.options.interactions = props.chart.options.interactions || {};
101
107
  // Set defaults for missing properties
@@ -165,6 +171,7 @@ export const getDefaultProps = (props) => {
165
171
  : true,
166
172
  position: props.chart.options.legend.position || 'bottom',
167
173
  align: props.chart.options.legend.align || 'center',
174
+ customLegend: props.chart.options.legend.customLegend,
168
175
  },
169
176
  chartOptions: {
170
177
  enableZoom: props.chart.options.chartOptions.enableZoom || false,
@@ -1,4 +1,4 @@
1
- import React, { useRef, useState } from 'react';
1
+ import React, { useEffect, useRef, useState } from 'react';
2
2
  import {
3
3
  BarElement,
4
4
  CategoryScale,
@@ -36,6 +36,7 @@ import {
36
36
  ANIMATION_DURATION,
37
37
  AUTO,
38
38
  COLORS,
39
+ CUSTOM_LEGEND_PLUGIN_NAME,
39
40
  DARK_MODE_COLORS,
40
41
  DEFAULT_COLOR,
41
42
  DEFAULT_DARK_MODE_BORDER_COLOR,
@@ -234,9 +235,13 @@ const BarChart = (props) => {
234
235
  }),
235
236
  tooltip: getBarChartToolTips(options),
236
237
  legend: getLegend(options, legendClick),
238
+ [CUSTOM_LEGEND_PLUGIN_NAME]: options.legend.customLegend
239
+ .customLegendPlugin && {
240
+ containerID: options.legend.customLegend.customLegendContainerID,
241
+ },
237
242
  },
238
243
  }}
239
- plugins={getPlugins(graph)}
244
+ plugins={getPlugins(graph, options.legend)}
240
245
  />
241
246
  </div>
242
247
  );