react-apexcharts 1.4.0 → 1.4.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.
@@ -0,0 +1,20 @@
1
+ name: Mark stale issues and pull requests
2
+ on:
3
+ schedule:
4
+ - cron: '21 14 * * *'
5
+ jobs:
6
+ stale:
7
+ runs-on: ubuntu-latest
8
+ permissions:
9
+ issues: write
10
+ pull-requests: write
11
+ steps:
12
+ - uses: actions/stale@v9
13
+ with:
14
+ repo-token: ${{ secrets.GITHUB_TOKEN }}
15
+ stale-issue-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.'
16
+ stale-pr-message: 'This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.'
17
+ stale-issue-label: 'no-issue-activity'
18
+ stale-pr-label: 'no-pr-activity'
19
+ exempt-issue-labels: 'bug,high-priority'
20
+ operations-per-run: 100
package/README.md CHANGED
@@ -96,11 +96,11 @@ this.setState({
96
96
 
97
97
  | Prop | Type | Description |
98
98
  | ------------- |-------------| -----|
99
- | **series** | Array | The series is an array which accepts object in the following format. To know more about the format of dataSeries, checkout [Series](https://apexcharts.com/docs/series/) docs on the website. |
100
- | **type** | String | `line`, `area`, `bar`, `pie`, `donut`, `scatter`, `bubble`, `heatmap`, `radialBar` |
101
- | **width** | Number/String | Possible values for width can be `100%` or `400px` or 400 |
102
- | **height** | Number/String | Possible values for width can be `100%` or `300px` or 300 |
103
- | **options** | Object | The configuration object, see options on [API (Reference)](https://apexcharts.com/docs/options/chart/type/) |
99
+ | **series** | `Array` | The series is a set of data. To know more about the format of the data, checkout [Series docs](https://apexcharts.com/docs/series/) on the website. |
100
+ | **type** | `String` | `line`, `area`, `bar`, `pie`, `donut`, `scatter`, `bubble`, `heatmap`, `radialBar` |
101
+ | **width** | `Number or String` | Possible values for width can be `100%`, `400px` or `400` (by default is `100%`) |
102
+ | **height** | `Number or String` | Possible values for height can be `100%`, `300px` or `300` (by default is `auto`) |
103
+ | **options** | `Object` | The configuration object, see options on [API (Reference)](https://apexcharts.com/docs/options/chart/type/) |
104
104
 
105
105
  ## How to call methods of ApexCharts programmatically?
106
106
  Sometimes, you may want to call other methods of the core ApexCharts library, and you can do so on `ApexCharts` global variable directly
@@ -1,32 +1,33 @@
1
1
  /// <reference types="react"/>
2
- import { ApexOptions } from 'apexcharts';
3
- import React from 'react';
2
+ import { ApexOptions } from "apexcharts";
3
+ import React from "react";
4
4
  /**
5
5
  * Basic type definitions from https://apexcharts.com/docs/react-charts/#props
6
6
  */
7
7
  declare module "react-apexcharts" {
8
8
  export interface Props {
9
- type?: "line"
10
- | "area"
11
- | "bar"
12
- | "histogram"
13
- | "pie"
14
- | "donut"
15
- | "radialBar"
16
- | "scatter"
17
- | "bubble"
18
- | "heatmap"
19
- | "treemap"
20
- | "boxPlot"
21
- | "candlestick"
22
- | "radar"
23
- | "polarArea"
24
- | "rangeBar",
25
- series?: ApexOptions['series'],
26
- width?: string | number,
27
- height?: string | number,
28
- options?: ApexOptions,
29
- [key: string]: any,
9
+ type?:
10
+ | "line"
11
+ | "area"
12
+ | "bar"
13
+ | "pie"
14
+ | "donut"
15
+ | "radialBar"
16
+ | "scatter"
17
+ | "bubble"
18
+ | "heatmap"
19
+ | "candlestick"
20
+ | "boxPlot"
21
+ | "radar"
22
+ | "polarArea"
23
+ | "rangeBar"
24
+ | "rangeArea"
25
+ | "treemap";
26
+ series?: ApexOptions["series"];
27
+ width?: string | number;
28
+ height?: string | number;
29
+ options?: ApexOptions;
30
+ [key: string]: any;
30
31
  }
31
- export default class ReactApexChart extends React.Component<Props> {}
32
+ export default class ReactApexChart extends React.Component<Props> {}
32
33
  }
@@ -1 +1 @@
1
- var ReactApexChart=function(t,e,r){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var i="default"in e?e.default:e;r=r&&r.hasOwnProperty("default")?r.default:r;var s=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t};window.ApexCharts=t;class n extends e.Component{constructor(t){super(t),i.createRef?this.chartRef=i.createRef():this.setRef=(t=>this.chartRef=t),this.chart=null}render(){const t=function(t,e){var r={};for(var i in t)e.indexOf(i)>=0||Object.prototype.hasOwnProperty.call(t,i)&&(r[i]=t[i]);return r}(this.props,["type","height","width","series","options"]);return i.createElement("div",s({ref:i.createRef?this.chartRef:this.setRef},t))}componentDidMount(){const e=i.createRef?this.chartRef.current:this.chartRef;this.chart=new t(e,this.getConfig()),this.chart.render()}getConfig(){const{type:t,height:e,width:r,series:i,options:s}=this.props,n={chart:{type:t,height:e,width:r},series:i};return this.extend(s,n)}isObject(t){return t&&"object"==typeof t&&!Array.isArray(t)&&null!=t}extend(t,e){"function"!=typeof Object.assign&&(Object.assign=function(t){if(void 0===t||null===t)throw new TypeError("Cannot convert undefined or null to object");let e=Object(t);for(let t=1;t<arguments.length;t++){let r=arguments[t];if(void 0!==r&&null!==r)for(let t in r)r.hasOwnProperty(t)&&(e[t]=r[t])}return e});let r=Object.assign({},t);return this.isObject(t)&&this.isObject(e)&&Object.keys(e).forEach(i=>{this.isObject(e[i])&&i in t?r[i]=this.extend(t[i],e[i]):Object.assign(r,{[i]:e[i]})}),r}componentDidUpdate(t){if(!this.chart)return null;const{options:e,series:r,height:i,width:s}=this.props,n=JSON.stringify(t.options),h=JSON.stringify(t.series),o=JSON.stringify(e),a=JSON.stringify(r);n===o&&h===a&&i===t.height&&s===t.width||(h===a?this.chart.updateOptions(this.getConfig()):n===o&&i===t.height&&s===t.width?this.chart.updateSeries(r):this.chart.updateOptions(this.getConfig()))}componentWillUnmount(){this.chart&&"function"==typeof this.chart.destroy&&this.chart.destroy()}}return n.propTypes={type:r.string.isRequired,width:r.any,height:r.any,series:r.array.isRequired,options:r.object.isRequired},n.defaultProps={type:"line",width:"100%",height:"auto"},n}(ApexCharts,React,PropTypes);
1
+ var ReactApexChart=function(e,r,t){"use strict";function n(e,r,t){return(r=function(e){var r=function(e,r){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:r+""}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function i(){return i=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)({}).hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},i.apply(null,arguments)}function o(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function u(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?o(Object(t),!0).forEach((function(r){n(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}var f=["type","width","height","series","options"];function s(t){var o=t.type,a=void 0===o?"line":o,p=t.width,y=void 0===p?"100%":p,l=t.height,b=void 0===l?"auto":l,O=t.series,v=t.options,g=function(e,r){if(null==e)return{};var t,n,i=function(e,r){if(null==e)return{};var t={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(r.includes(n))continue;t[n]=e[n]}return t}(e,r);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n<o.length;n++)t=o[n],r.includes(t)||{}.propertyIsEnumerable.call(e,t)&&(i[t]=e[t])}return i}(t,f),h=e.useRef(null),d=e.useRef(null);e.useEffect((function(){var e=h.current;return d.current=new r(e,P()),d.current.render(),function(){d.current&&"function"==typeof d.current.destroy&&d.current.destroy()}}),[]),e.useEffect((function(){var e=JSON.stringify(d.current.options),r=JSON.stringify(d.current.series),t=JSON.stringify(v),n=JSON.stringify(O);e===t&&r===n&&b===d.current.height&&y===d.current.width||(r===n?d.current.updateOptions(P()):d.current.updateSeries(O))}),[v,O,b,y]);var m,j,w,P=function(){return E(v,{chart:{type:a,height:b,width:y},series:O})},S=function(e){return e&&"object"===c(e)&&!Array.isArray(e)},E=function(e,r){var t=u({},e);return S(e)&&S(r)&&Object.keys(r).forEach((function(i){S(r[i])&&i in e?t[i]=E(e[i],r[i]):Object.assign(t,n({},i,r[i]))})),t},R=(m=g,j=Object.keys(s.propTypes),w=u({},m),j.forEach((function(e){delete w[e]})),w);return React.createElement("div",i({ref:h},R))}return s.propTypes={type:t.string.isRequired,series:t.array.isRequired,options:t.object.isRequired,width:t.oneOfType([t.string,t.number]),height:t.oneOfType([t.string,t.number])},s}(React,ApexCharts,PropTypes);
@@ -1,139 +1,107 @@
1
- import ApexCharts from 'apexcharts/dist/apexcharts.common'
2
- import React, { Component } from 'react'
3
- import PropTypes from 'prop-types'
1
+ "use strict";
4
2
 
5
- window.ApexCharts = ApexCharts
6
-
7
- export default class Charts extends Component {
8
- constructor (props) {
9
- super(props)
10
- if (React.createRef) {
11
- this.chartRef = React.createRef()
12
- } else {
13
- this.setRef = el => this.chartRef = el
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = Charts;
7
+ var _apexcharts = _interopRequireDefault(require("apexcharts"));
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _propTypes = _interopRequireDefault(require("prop-types"));
10
+ var _excluded = ["type", "width", "height", "series", "options"];
11
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
12
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
14
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
15
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
16
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
17
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
18
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
19
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
20
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
21
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
22
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
+ function omit(obj, keysToRemove) {
24
+ var newObj = _objectSpread({}, obj);
25
+ keysToRemove.forEach(function (key) {
26
+ delete newObj[key];
27
+ });
28
+ return newObj;
29
+ }
30
+ function Charts(_ref) {
31
+ var _ref$type = _ref.type,
32
+ type = _ref$type === void 0 ? "line" : _ref$type,
33
+ _ref$width = _ref.width,
34
+ width = _ref$width === void 0 ? "100%" : _ref$width,
35
+ _ref$height = _ref.height,
36
+ height = _ref$height === void 0 ? "auto" : _ref$height,
37
+ series = _ref.series,
38
+ options = _ref.options,
39
+ restProps = _objectWithoutProperties(_ref, _excluded);
40
+ var chartRef = (0, _react.useRef)(null);
41
+ var chart = (0, _react.useRef)(null);
42
+ (0, _react.useEffect)(function () {
43
+ var current = chartRef.current;
44
+ chart.current = new _apexcharts["default"](current, getConfig());
45
+ chart.current.render();
46
+ return function () {
47
+ if (chart.current && typeof chart.current.destroy === "function") {
48
+ chart.current.destroy();
49
+ }
50
+ };
51
+ }, []);
52
+ (0, _react.useEffect)(function () {
53
+ var prevOptions = JSON.stringify(chart.current.options);
54
+ var prevSeries = JSON.stringify(chart.current.series);
55
+ var currentOptions = JSON.stringify(options);
56
+ var currentSeries = JSON.stringify(series);
57
+ if (prevOptions !== currentOptions || prevSeries !== currentSeries || height !== chart.current.height || width !== chart.current.width) {
58
+ if (prevSeries === currentSeries) {
59
+ chart.current.updateOptions(getConfig());
60
+ } else {
61
+ chart.current.updateSeries(series);
62
+ }
14
63
  }
15
- this.chart = null
16
- }
17
-
18
- render () {
19
- const { ...props } = this.props
20
- return React.createElement('div', {
21
- ref: React.createRef
22
- ? this.chartRef
23
- : this.setRef,
24
- ...props
25
- })
26
- }
27
-
28
- componentDidMount () {
29
- const current = React.createRef ? this.chartRef.current : this.chartRef
30
- this.chart = new ApexCharts(current, this.getConfig())
31
- this.chart.render()
32
- }
33
-
34
- getConfig () {
35
- const { type, height, width, series, options } = this.props
36
- const newOptions = {
64
+ }, [options, series, height, width]);
65
+ var getConfig = function getConfig() {
66
+ var newOptions = {
37
67
  chart: {
38
- type,
39
- height,
40
- width
68
+ type: type,
69
+ height: height,
70
+ width: width
41
71
  },
42
- series
43
- }
44
-
45
- return this.extend(options, newOptions)
46
- }
47
-
48
- isObject(item) {
49
- return (
50
- item && typeof item === 'object' && !Array.isArray(item) && item != null
51
- )
52
- }
53
-
54
- extend (target, source) {
55
- if (typeof Object.assign !== 'function') {
56
- (function () {
57
- Object.assign = function (target) {
58
- // We must check against these specific cases.
59
- if (target === undefined || target === null) {
60
- throw new TypeError('Cannot convert undefined or null to object')
61
- }
62
-
63
- let output = Object(target)
64
- for (let index = 1; index < arguments.length; index++) {
65
- let source = arguments[index]
66
- if (source !== undefined && source !== null) {
67
- for (let nextKey in source) {
68
- if (source.hasOwnProperty(nextKey)) {
69
- output[nextKey] = source[nextKey]
70
- }
71
- }
72
- }
73
- }
74
- return output
75
- }
76
- })()
77
- }
78
-
79
- let output = Object.assign({}, target)
80
- if (this.isObject(target) && this.isObject(source)) {
81
- Object.keys(source).forEach((key) => {
82
- if (this.isObject(source[key])) {
72
+ series: series
73
+ };
74
+ return _extend(options, newOptions);
75
+ };
76
+ var isObject = function isObject(item) {
77
+ return item && _typeof(item) === "object" && !Array.isArray(item);
78
+ };
79
+ var _extend = function extend(target, source) {
80
+ var output = _objectSpread({}, target);
81
+ if (isObject(target) && isObject(source)) {
82
+ Object.keys(source).forEach(function (key) {
83
+ if (isObject(source[key])) {
83
84
  if (!(key in target)) {
84
- Object.assign(output, {
85
- [key]: source[key]
86
- })
85
+ Object.assign(output, _defineProperty({}, key, source[key]));
87
86
  } else {
88
- output[key] = this.extend(target[key], source[key])
87
+ output[key] = _extend(target[key], source[key]);
89
88
  }
90
89
  } else {
91
- Object.assign(output, {
92
- [key]: source[key]
93
- })
90
+ Object.assign(output, _defineProperty({}, key, source[key]));
94
91
  }
95
- })
92
+ });
96
93
  }
97
- return output
98
- }
99
-
100
- componentDidUpdate (prevProps) {
101
- if (!this.chart) return null
102
- const { options, series } = this.props
103
- const prevOptions = JSON.stringify(prevProps.options)
104
- const prevSeries = JSON.stringify(prevProps.series)
105
- const currentOptions = JSON.stringify(options)
106
- const currentSeries = JSON.stringify(series)
107
-
108
- if (prevOptions !== currentOptions || prevSeries !== currentSeries) {
109
- if (prevSeries === currentSeries) {
110
- // series is not changed,but options are changed
111
- this.chart.updateOptions(this.getConfig())
112
- } else if (prevOptions === currentOptions) {
113
- // options are not changed, just the series is changed
114
- this.chart.updateSeries(series)
115
- } else {
116
- // both might be changed
117
- this.chart.updateOptions(this.getConfig())
118
- }
119
- }
120
- }
121
-
122
- componentWillUnmount () {
123
- if (this.chart && typeof this.chart.destroy === 'function') this.chart.destroy()
124
- }
94
+ return output;
95
+ };
96
+ var rest = omit(restProps, Object.keys(Charts.propTypes));
97
+ return /*#__PURE__*/_react["default"].createElement("div", _extends({
98
+ ref: chartRef
99
+ }, rest));
125
100
  }
126
-
127
101
  Charts.propTypes = {
128
- type: PropTypes.string.isRequired,
129
- width: PropTypes.any,
130
- height: PropTypes.any,
131
- series: PropTypes.array.isRequired,
132
- options: PropTypes.object.isRequired
133
- }
134
-
135
- Charts.defaultProps = {
136
- type: 'line',
137
- width: '100%',
138
- height: 'auto'
139
- }
102
+ type: _propTypes["default"].string.isRequired,
103
+ series: _propTypes["default"].array.isRequired,
104
+ options: _propTypes["default"].object.isRequired,
105
+ width: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
106
+ height: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number])
107
+ };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},_createClass=function(){function n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}}(),_apexcharts=require("apexcharts/dist/apexcharts.common"),_apexcharts2=_interopRequireDefault(_apexcharts),_react=require("react"),_react2=_interopRequireDefault(_react),_propTypes=require("prop-types"),_propTypes2=_interopRequireDefault(_propTypes);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _objectWithoutProperties(e,t){var r={};for(var n in e)0<=t.indexOf(n)||Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n]);return r}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}window.ApexCharts=_apexcharts2.default;var Charts=function(){function r(e){_classCallCheck(this,r);var t=_possibleConstructorReturn(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,e));return _react2.default.createRef?t.chartRef=_react2.default.createRef():t.setRef=function(e){return t.chartRef=e},t.chart=null,t}return _inherits(r,_react.Component),_createClass(r,[{key:"render",value:function(){var e=this.props,t=(e.type,e.height,e.width,e.series,e.options,_objectWithoutProperties(e,["type","height","width","series","options"]));return _react2.default.createElement("div",_extends({ref:_react2.default.createRef?this.chartRef:this.setRef},t))}},{key:"componentDidMount",value:function(){var e=_react2.default.createRef?this.chartRef.current:this.chartRef;this.chart=new _apexcharts2.default(e,this.getConfig()),this.chart.render()}},{key:"getConfig",value:function(){var e=this.props,t=e.type,r=e.height,n=e.width,o=e.series,i=e.options,a={chart:{type:t,height:r,width:n},series:o};return this.extend(i,a)}},{key:"isObject",value:function(e){return e&&"object"===(void 0===e?"undefined":_typeof(e))&&!Array.isArray(e)&&null!=e}},{key:"extend",value:function(t,r){var n=this;"function"!=typeof Object.assign&&(Object.assign=function(e){if(null==e)throw new TypeError("Cannot convert undefined or null to object");for(var t=Object(e),r=1;r<arguments.length;r++){var n=arguments[r];if(null!=n)for(var o in n)n.hasOwnProperty(o)&&(t[o]=n[o])}return t});var o=Object.assign({},t);return this.isObject(t)&&this.isObject(r)&&Object.keys(r).forEach(function(e){n.isObject(r[e])&&e in t?o[e]=n.extend(t[e],r[e]):Object.assign(o,_defineProperty({},e,r[e]))}),o}},{key:"componentDidUpdate",value:function(e){if(!this.chart)return null;var t=this.props,r=t.options,n=t.series,o=t.height,i=t.width,a=JSON.stringify(e.options),s=JSON.stringify(e.series),c=JSON.stringify(r),u=JSON.stringify(n);a===c&&s===u&&o===e.height&&i===e.width||(s===u?this.chart.updateOptions(this.getConfig()):a===c&&o===e.height&&i===e.width?this.chart.updateSeries(n):this.chart.updateOptions(this.getConfig()))}},{key:"componentWillUnmount",value:function(){this.chart&&"function"==typeof this.chart.destroy&&this.chart.destroy()}}]),r}();(exports.default=Charts).propTypes={type:_propTypes2.default.string.isRequired,width:_propTypes2.default.any,height:_propTypes2.default.any,series:_propTypes2.default.array.isRequired,options:_propTypes2.default.object.isRequired},Charts.defaultProps={type:"line",width:"100%",height:"auto"};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=Charts;var _react=require("react"),_apexcharts=_interopRequireDefault(require("apexcharts")),_propTypes=_interopRequireDefault(require("prop-types")),_excluded=["type","width","height","series","options"];function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _extends(){return(_extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r,n=arguments[t];for(r in n)!{}.hasOwnProperty.call(n,r)||(e[r]=n[r])}return e}).apply(null,arguments)}function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _objectWithoutProperties(e,t){if(null==e)return{};var r,n=_objectWithoutPropertiesLoose(e,t);if(Object.getOwnPropertySymbols)for(var o=Object.getOwnPropertySymbols(e),i=0;i<o.length;i++)r=o[i],t.includes(r)||{}.propertyIsEnumerable.call(e,r)&&(n[r]=e[r]);return n}function _objectWithoutPropertiesLoose(e,t){if(null==e)return{};var r,n={};for(r in e)if({}.hasOwnProperty.call(e,r)){if(t.includes(r))continue;n[r]=e[r]}return n}function ownKeys(t,e){var r,n=Object.keys(t);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(t),e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)),n}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(r),!0).forEach(function(e){_defineProperty(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function _defineProperty(e,t,r){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _toPropertyKey(e){e=_toPrimitive(e,"string");return"symbol"==_typeof(e)?e:e+""}function _toPrimitive(e,t){if("object"!=_typeof(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0===r)return("string"===t?String:Number)(e);r=r.call(e,t||"default");if("object"!=_typeof(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}function omit(e,t){var r=_objectSpread({},e);return t.forEach(function(e){delete r[e]}),r}function Charts(e){function o(e){return e&&"object"===_typeof(e)&&!Array.isArray(e)}var t=e.type,r=void 0===t?"line":t,t=e.width,i=void 0===t?"100%":t,t=e.height,u=void 0===t?"auto":t,p=e.series,c=e.options,t=_objectWithoutProperties(e,_excluded),n=(0,_react.useRef)(null),s=(0,_react.useRef)(null),f=((0,_react.useEffect)(function(){var e=n.current;return s.current=new _apexcharts.default(e,f()),s.current.render(),function(){s.current&&"function"==typeof s.current.destroy&&s.current.destroy()}},[]),(0,_react.useEffect)(function(){var e=JSON.stringify(s.current.options),t=JSON.stringify(s.current.series),r=JSON.stringify(c),n=JSON.stringify(p);e===r&&t===n&&u===s.current.height&&i===s.current.width||(t===n?s.current.updateOptions(f()):s.current.updateSeries(p))},[c,p,u,i]),function(){return a(c,{chart:{type:r,height:u,width:i},series:p})}),a=function(t,r){var n=_objectSpread({},t);return o(t)&&o(r)&&Object.keys(r).forEach(function(e){o(r[e])&&e in t?n[e]=a(t[e],r[e]):Object.assign(n,_defineProperty({},e,r[e]))}),n},e=omit(t,Object.keys(Charts.propTypes));return React.createElement("div",_extends({ref:n},e))}Charts.propTypes={type:_propTypes.default.string.isRequired,series:_propTypes.default.array.isRequired,options:_propTypes.default.object.isRequired,width:_propTypes.default.oneOfType([_propTypes.default.string,_propTypes.default.number]),height:_propTypes.default.oneOfType([_propTypes.default.string,_propTypes.default.number])};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-apexcharts",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "React.js wrapper for ApexCharts",
5
5
  "main": "dist/react-apexcharts.min.js",
6
6
  "types": "types/react-apexcharts.d.ts",
@@ -26,36 +26,35 @@
26
26
  },
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
- "prop-types": "^15.5.7"
29
+ "prop-types": "^15.8.1"
30
30
  },
31
31
  "peerDependencies": {
32
- "apexcharts": "^3.18.0",
32
+ "apexcharts": "^3.41.0",
33
33
  "react": ">=0.13"
34
34
  },
35
35
  "devDependencies": {
36
- "@types/react": "^16.8.8",
37
- "babel-core": "^6.26.3",
38
- "babel-plugin-transform-object-rest-spread": "^6.26.0",
39
- "babel-preset-env": "^1.7.0",
40
- "babel-preset-es2015": "^6.24.1",
41
- "babel-preset-react": "^6.24.1",
42
- "babel-preset-stage-3": "^6.24.1",
43
- "concurrently": "^4.1.0",
44
- "eslint": "^5.14.1",
45
- "eslint-plugin-react": "^7.12.4",
46
- "gulp": "^4.0.2",
47
- "gulp-babel": "^6.1.2",
36
+ "@babel/core": "^7.25.8",
37
+ "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
38
+ "@babel/preset-env": "^7.25.8",
39
+ "@babel/preset-react": "^7.25.7",
40
+ "@rollup/plugin-babel": "^6.0.4",
41
+ "@rollup/plugin-node-resolve": "^15.3.0",
42
+ "@rollup/plugin-terser": "^0.4.4",
43
+ "@types/react": "^18.3.11",
44
+ "concurrently": "^9.0.1",
45
+ "eslint": "^9.12.0",
46
+ "eslint-plugin-react": "^7.37.1",
47
+ "gulp": "^5.0.0",
48
+ "gulp-babel": "^8.0.0",
48
49
  "gulp-concat": "^2.6.1",
49
- "gulp-react": "^3.1.0",
50
- "gulp-uglify": "^3.0.0",
51
- "jest": "^25.1.0",
52
- "react": "^16.6.3",
53
- "react-dom": "^16.6.3",
54
- "react-test-renderer": "^16.6.3",
55
- "rollup": "1.27.14",
56
- "rollup-plugin-babel": "^3.0.4",
57
- "rollup-plugin-node-resolve": "^3.4.0",
58
- "rollup-plugin-postcss": "^2.0.6",
59
- "rollup-plugin-uglify": "^3.0.0"
50
+ "gulp-react": "^4.0.0",
51
+ "gulp-uglify": "^3.0.2",
52
+ "jest": "^29.7.0",
53
+ "jest-environment-jsdom": "^29.7.0",
54
+ "react": "^18.3.1",
55
+ "react-dom": "^18.3.1",
56
+ "react-test-renderer": "^18.3.1",
57
+ "rollup": "4.24.0",
58
+ "rollup-plugin-postcss": "^4.0.2"
60
59
  }
61
60
  }
@@ -1,32 +1,33 @@
1
1
  /// <reference types="react"/>
2
- import { ApexOptions } from 'apexcharts';
3
- import React from 'react';
2
+ import { ApexOptions } from "apexcharts";
3
+ import React from "react";
4
4
  /**
5
5
  * Basic type definitions from https://apexcharts.com/docs/react-charts/#props
6
6
  */
7
7
  declare module "react-apexcharts" {
8
8
  export interface Props {
9
- type?: "line"
10
- | "area"
11
- | "bar"
12
- | "histogram"
13
- | "pie"
14
- | "donut"
15
- | "radialBar"
16
- | "scatter"
17
- | "bubble"
18
- | "heatmap"
19
- | "treemap"
20
- | "boxPlot"
21
- | "candlestick"
22
- | "radar"
23
- | "polarArea"
24
- | "rangeBar",
25
- series?: ApexOptions['series'],
26
- width?: string | number,
27
- height?: string | number,
28
- options?: ApexOptions,
29
- [key: string]: any,
9
+ type?:
10
+ | "line"
11
+ | "area"
12
+ | "bar"
13
+ | "pie"
14
+ | "donut"
15
+ | "radialBar"
16
+ | "scatter"
17
+ | "bubble"
18
+ | "heatmap"
19
+ | "candlestick"
20
+ | "boxPlot"
21
+ | "radar"
22
+ | "polarArea"
23
+ | "rangeBar"
24
+ | "rangeArea"
25
+ | "treemap";
26
+ series?: ApexOptions["series"];
27
+ width?: string | number;
28
+ height?: string | number;
29
+ options?: ApexOptions;
30
+ [key: string]: any;
30
31
  }
31
- export default class ReactApexChart extends React.Component<Props> {}
32
+ export default class ReactApexChart extends React.Component<Props> {}
32
33
  }
package/.babelrc DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "presets":[
3
- "react",
4
- "stage-3"
5
- ]
6
- }
package/.eslintignore DELETED
File without changes
package/.eslintrc.js DELETED
@@ -1,24 +0,0 @@
1
- module.exports = {
2
- root: true,
3
- parserOptions: {
4
- ecmaVersion: 2018,
5
- parser: 'babel-eslint',
6
- sourceType: 'module'
7
- },
8
- env: {
9
- browser: true,
10
- es6: true,
11
- node: true
12
- },
13
- extends: [
14
- "eslint:recommended",
15
- "plugin:react/recommended"
16
- ],
17
- globals: {
18
- "ApexCharts": true
19
- },
20
- rules: {
21
- // Remove this when prettier 2.0 is out
22
- 'space-before-function-paren': 0 // Do not clash with Prettier
23
- }
24
- };
package/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - "stable"
4
- cache:
5
- directories:
6
- - node_modules
7
- script:
8
- - npm run build
@@ -1,4 +0,0 @@
1
- {
2
- // Temporary until prettier and eslint are correctly setup
3
- "editor.formatOnSave": false
4
- }
package/gulpfile.js DELETED
@@ -1,46 +0,0 @@
1
- const { src, dest, parallel } = require('gulp');
2
- const react = require('gulp-react');
3
- const concat = require('gulp-concat');
4
- const uglify = require('gulp-uglify');
5
- const babel = require('gulp-babel');
6
-
7
- function dev() {
8
- return (
9
- src(['./src/react-apexcharts.jsx'])
10
- .pipe(react({
11
- es6module: true
12
- }))
13
- .pipe(concat('react-apexcharts.js'))
14
- .pipe(dest('./dist/'))
15
- );
16
- }
17
-
18
- function prod() {
19
- return (
20
- src(['./src/react-apexcharts.jsx'])
21
- .pipe(react({
22
- es6module: true
23
- }))
24
- .pipe(babel({
25
- presets: ['es2015', 'react'],
26
- plugins: ['transform-object-rest-spread']
27
- }))
28
- .pipe(concat('react-apexcharts.min.js'))
29
- .pipe(uglify())
30
- .pipe(dest('./dist/'))
31
- );
32
- }
33
-
34
- function types() {
35
- return (
36
- src(['./types/react-apexcharts.d.ts'])
37
- .pipe(dest('./dist/'))
38
- );
39
- }
40
-
41
- const prodBuild = parallel(prod, types);
42
- const devBuild = parallel(dev, types);
43
-
44
- exports.build = prodBuild;
45
- exports.devBuild = devBuild;
46
- exports.default = prodBuild;
package/jest.config.js DELETED
@@ -1,11 +0,0 @@
1
- // For a detailed explanation regarding each configuration property, visit:
2
- // https://jestjs.io/docs/en/configuration.html
3
-
4
- module.exports = {
5
- clearMocks: true,
6
- testEnvironment: "jest-environment-jsdom",
7
- testPathIgnorePatterns: [
8
- "/node_modules/",
9
- "/example/"
10
- ],
11
- };
package/rollup.config.js DELETED
@@ -1,29 +0,0 @@
1
- import babel from 'rollup-plugin-babel';
2
- import resolve from 'rollup-plugin-node-resolve';
3
- import uglify from 'rollup-plugin-uglify'
4
-
5
- let pluginOptions = [
6
- resolve({
7
- browser: true
8
- }),
9
- babel({
10
- exclude: 'node_modules/**'
11
- }),
12
- uglify()
13
- ];
14
-
15
- module.exports = {
16
- input: './src/react-apexcharts.jsx',
17
- output: [{
18
- name: 'ReactApexChart',
19
- file: 'dist/react-apexcharts.iife.min.js',
20
- format: 'iife',
21
- globals: {
22
- react: "React",
23
- apexcharts: "ApexCharts",
24
- 'prop-types': "PropTypes"
25
- }
26
- }],
27
- external: ['react', 'apexcharts', 'prop-types'],
28
- plugins: pluginOptions
29
- }
@@ -1,148 +0,0 @@
1
- import ApexCharts from 'apexcharts/dist/apexcharts.common'
2
- import React, { Component } from 'react'
3
- import PropTypes from 'prop-types'
4
-
5
- window.ApexCharts = ApexCharts
6
-
7
- export default class Charts extends Component {
8
- constructor (props) {
9
- super(props)
10
- if (React.createRef) {
11
- this.chartRef = React.createRef()
12
- } else {
13
- this.setRef = el => this.chartRef = el
14
- }
15
- this.chart = null
16
- }
17
-
18
- render () {
19
- const { type, height, width, series, options, ...props } = this.props
20
- return React.createElement('div', {
21
- ref: React.createRef
22
- ? this.chartRef
23
- : this.setRef,
24
- ...props
25
- })
26
- }
27
-
28
- componentDidMount () {
29
- const current = React.createRef ? this.chartRef.current : this.chartRef
30
- this.chart = new ApexCharts(current, this.getConfig())
31
- this.chart.render()
32
- }
33
-
34
- getConfig () {
35
- const { type, height, width, series, options } = this.props
36
- const newOptions = {
37
- chart: {
38
- type,
39
- height,
40
- width
41
- },
42
- series
43
- }
44
-
45
- return this.extend(options, newOptions)
46
- }
47
-
48
- isObject(item) {
49
- return (
50
- item && typeof item === 'object' && !Array.isArray(item) && item != null
51
- )
52
- }
53
-
54
- extend (target, source) {
55
- if (typeof Object.assign !== 'function') {
56
- (function () {
57
- Object.assign = function (target) {
58
- // We must check against these specific cases.
59
- if (target === undefined || target === null) {
60
- throw new TypeError('Cannot convert undefined or null to object')
61
- }
62
-
63
- let output = Object(target)
64
- for (let index = 1; index < arguments.length; index++) {
65
- let source = arguments[index]
66
- if (source !== undefined && source !== null) {
67
- for (let nextKey in source) {
68
- if (source.hasOwnProperty(nextKey)) {
69
- output[nextKey] = source[nextKey]
70
- }
71
- }
72
- }
73
- }
74
- return output
75
- }
76
- })()
77
- }
78
-
79
- let output = Object.assign({}, target)
80
- if (this.isObject(target) && this.isObject(source)) {
81
- Object.keys(source).forEach((key) => {
82
- if (this.isObject(source[key])) {
83
- if (!(key in target)) {
84
- Object.assign(output, {
85
- [key]: source[key]
86
- })
87
- } else {
88
- output[key] = this.extend(target[key], source[key])
89
- }
90
- } else {
91
- Object.assign(output, {
92
- [key]: source[key]
93
- })
94
- }
95
- })
96
- }
97
- return output
98
- }
99
-
100
- componentDidUpdate (prevProps) {
101
- if (!this.chart) return null
102
- const { options, series, height, width } = this.props
103
- const prevOptions = JSON.stringify(prevProps.options)
104
- const prevSeries = JSON.stringify(prevProps.series)
105
- const currentOptions = JSON.stringify(options)
106
- const currentSeries = JSON.stringify(series)
107
-
108
- if (
109
- prevOptions !== currentOptions ||
110
- prevSeries !== currentSeries ||
111
- height !== prevProps.height ||
112
- width !== prevProps.width
113
- ) {
114
- if (prevSeries === currentSeries) {
115
- // series has not changed, but options or size have changed
116
- this.chart.updateOptions(this.getConfig())
117
- } else if (
118
- prevOptions === currentOptions &&
119
- height === prevProps.height &&
120
- width === prevProps.width
121
- ) {
122
- // options or size have not changed, just the series has changed
123
- this.chart.updateSeries(series)
124
- } else {
125
- // both might be changed
126
- this.chart.updateOptions(this.getConfig())
127
- }
128
- }
129
- }
130
-
131
- componentWillUnmount () {
132
- if (this.chart && typeof this.chart.destroy === 'function') this.chart.destroy()
133
- }
134
- }
135
-
136
- Charts.propTypes = {
137
- type: PropTypes.string.isRequired,
138
- width: PropTypes.any,
139
- height: PropTypes.any,
140
- series: PropTypes.array.isRequired,
141
- options: PropTypes.object.isRequired
142
- }
143
-
144
- Charts.defaultProps = {
145
- type: 'line',
146
- width: '100%',
147
- height: 'auto'
148
- }
@@ -1,20 +0,0 @@
1
- import React from 'react'
2
- import ReactDOM from 'react-dom'
3
- import Chart from './react-apexcharts.jsx'
4
-
5
- const props = {
6
- options: {
7
- xaxis: {
8
- categories: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
9
- }
10
- },
11
- series: [{
12
- data: [30, 40, 25, 50, 49, 21, 70, 51]
13
- }],
14
- }
15
-
16
- it('renders without crashing', () => {
17
- const div = document.createElement('div')
18
- ReactDOM.render(<Chart {...props}/>, div)
19
- ReactDOM.unmountComponentAtNode(div);
20
- })