apex-react-charts
Advanced tools
Comparing version 1.0.2 to 1.0.3
39
index.js
@@ -9,10 +9,12 @@ var React = require('react'); | ||
super(props); | ||
this.genId = new window.Date().getTime(); | ||
this.options = props.options ? props.options : {}; | ||
this.options = props.options || {}; | ||
this.series = this.options.series = props.series || {}; | ||
this.style = props.style || {width: "100%", height: "100%", position: "relative"}; | ||
this.chartContainerId = "apexchart-container-" + this.genId; | ||
this.chartRef = null; | ||
this.chart = null; | ||
this.setRef = (el => this.chartRef = el).bind(this); | ||
} | ||
componentDidMount() { | ||
//Create Chart and Render | ||
this.chart = new Apex(document.querySelector('#' + this.chartContainerId), this.options); | ||
this.chart = new Apex(this.chartRef, this.options); | ||
this.chart.render(); | ||
@@ -23,10 +25,17 @@ | ||
} | ||
shouldComponentUpdate(props, state){ | ||
//Check if Chart-options has changed and determine if component has to be updated | ||
return !(props.options === this.options); | ||
} | ||
componentDidUpdate() { | ||
//Update Chart Options & Render | ||
this.options = this.props.options; | ||
this.chart.updateOptions(this.options); | ||
componentDidUpdate(prevProps) { | ||
if (!this.chart) return null | ||
const currentOptions = JSON.stringify(this.props.options); | ||
const currentSeries = JSON.stringify(this.props.series); | ||
const prevOptions = JSON.stringify(prevProps.options); | ||
const prevSeries = JSON.stringify(prevProps.series); | ||
if(prevOptions !== currentOptions){ | ||
this.chart.updateOptions(currentOptions); | ||
} | ||
else if(currentSeries !== prevSeries){ | ||
this.chart.updateSeries(currentSeries); | ||
} | ||
} | ||
@@ -40,3 +49,7 @@ componentWillUnmount() { | ||
render() { | ||
return React.createElement('div', { id: this.chartContainerId, style: this.style }); | ||
return React.createElement('div', { | ||
ref: this.setRef, | ||
style: this.style, | ||
...this.props | ||
}); | ||
@@ -43,0 +56,0 @@ } |
{ | ||
"name": "apex-react-charts", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "A React Component Wrapper for ApexCharts", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
473520
2375