react-chartjs-2
Advanced tools
Comparing version 2.7.5 to 2.7.6
@@ -60,3 +60,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
if (this.props.redraw) { | ||
this.chartInstance.destroy(); | ||
this.destroyChart(); | ||
this.renderChart(); | ||
@@ -110,3 +110,3 @@ return; | ||
ChartComponent.prototype.componentWillUnmount = function componentWillUnmount() { | ||
this.chartInstance.destroy(); | ||
this.destroyChart(); | ||
}; | ||
@@ -144,2 +144,4 @@ | ||
this.saveCurrentDatasets(); // to remove the dataset metadata from this chart when the chart is destroyed | ||
return data; | ||
@@ -167,5 +169,19 @@ }; | ||
ChartComponent.prototype.updateChart = function updateChart() { | ||
ChartComponent.prototype.getCurrentDatasets = function getCurrentDatasets() { | ||
return this.chartInstance && this.chartInstance.config.data && this.chartInstance.config.data.datasets || []; | ||
}; | ||
ChartComponent.prototype.saveCurrentDatasets = function saveCurrentDatasets() { | ||
var _this2 = this; | ||
this.datasets = this.datasets || {}; | ||
var currentDatasets = this.getCurrentDatasets(); | ||
currentDatasets.forEach(function (d) { | ||
_this2.datasets[_this2.props.datasetKeyProvider(d)] = d; | ||
}); | ||
}; | ||
ChartComponent.prototype.updateChart = function updateChart() { | ||
var _this3 = this; | ||
var options = this.props.options; | ||
@@ -184,3 +200,3 @@ | ||
// seamless transitions | ||
var currentDatasets = this.chartInstance.config.data && this.chartInstance.config.data.datasets || []; | ||
var currentDatasets = this.getCurrentDatasets(); | ||
var nextDatasets = data.datasets || []; | ||
@@ -194,3 +210,3 @@ this.checkDatasets(currentDatasets); | ||
this.chartInstance.config.data.datasets = nextDatasets.map(function (next) { | ||
var current = currentDatasetsIndexed[_this2.props.datasetKeyProvider(next)]; | ||
var current = currentDatasetsIndexed[_this3.props.datasetKeyProvider(next)]; | ||
@@ -247,2 +263,15 @@ if (current && current.type === next.type) { | ||
ChartComponent.prototype.destroyChart = function destroyChart() { | ||
// Put all of the datasets that have existed in the chart back on the chart | ||
// so that the metadata associated with this chart get destroyed. | ||
// This allows the datasets to be used in another chart. This can happen, | ||
// for example, in a tabbed UI where the chart gets created each time the | ||
// tab gets switched to the chart and uses the same data). | ||
this.saveCurrentDatasets(); | ||
var datasets = Object.values(this.datasets); | ||
this.chartInstance.config.data.datasets = datasets; | ||
this.chartInstance.destroy(); | ||
}; | ||
ChartComponent.prototype.render = function render() { | ||
@@ -316,7 +345,7 @@ var _props3 = this.props, | ||
Doughnut.prototype.render = function render() { | ||
var _this4 = this; | ||
var _this5 = this; | ||
return React.createElement(ChartComponent, _extends({}, this.props, { | ||
ref: function ref(_ref) { | ||
return _this4.chartInstance = _ref && _ref.chartInstance; | ||
return _this5.chartInstance = _ref && _ref.chartInstance; | ||
}, | ||
@@ -340,7 +369,7 @@ type: 'doughnut' | ||
Pie.prototype.render = function render() { | ||
var _this6 = this; | ||
var _this7 = this; | ||
return React.createElement(ChartComponent, _extends({}, this.props, { | ||
ref: function ref(_ref2) { | ||
return _this6.chartInstance = _ref2 && _ref2.chartInstance; | ||
return _this7.chartInstance = _ref2 && _ref2.chartInstance; | ||
}, | ||
@@ -364,7 +393,7 @@ type: 'pie' | ||
Line.prototype.render = function render() { | ||
var _this8 = this; | ||
var _this9 = this; | ||
return React.createElement(ChartComponent, _extends({}, this.props, { | ||
ref: function ref(_ref3) { | ||
return _this8.chartInstance = _ref3 && _ref3.chartInstance; | ||
return _this9.chartInstance = _ref3 && _ref3.chartInstance; | ||
}, | ||
@@ -388,7 +417,7 @@ type: 'line' | ||
Bar.prototype.render = function render() { | ||
var _this10 = this; | ||
var _this11 = this; | ||
return React.createElement(ChartComponent, _extends({}, this.props, { | ||
ref: function ref(_ref4) { | ||
return _this10.chartInstance = _ref4 && _ref4.chartInstance; | ||
return _this11.chartInstance = _ref4 && _ref4.chartInstance; | ||
}, | ||
@@ -412,7 +441,7 @@ type: 'bar' | ||
HorizontalBar.prototype.render = function render() { | ||
var _this12 = this; | ||
var _this13 = this; | ||
return React.createElement(ChartComponent, _extends({}, this.props, { | ||
ref: function ref(_ref5) { | ||
return _this12.chartInstance = _ref5 && _ref5.chartInstance; | ||
return _this13.chartInstance = _ref5 && _ref5.chartInstance; | ||
}, | ||
@@ -436,7 +465,7 @@ type: 'horizontalBar' | ||
Radar.prototype.render = function render() { | ||
var _this14 = this; | ||
var _this15 = this; | ||
return React.createElement(ChartComponent, _extends({}, this.props, { | ||
ref: function ref(_ref6) { | ||
return _this14.chartInstance = _ref6 && _ref6.chartInstance; | ||
return _this15.chartInstance = _ref6 && _ref6.chartInstance; | ||
}, | ||
@@ -460,7 +489,7 @@ type: 'radar' | ||
Polar.prototype.render = function render() { | ||
var _this16 = this; | ||
var _this17 = this; | ||
return React.createElement(ChartComponent, _extends({}, this.props, { | ||
ref: function ref(_ref7) { | ||
return _this16.chartInstance = _ref7 && _ref7.chartInstance; | ||
return _this17.chartInstance = _ref7 && _ref7.chartInstance; | ||
}, | ||
@@ -484,7 +513,7 @@ type: 'polarArea' | ||
Bubble.prototype.render = function render() { | ||
var _this18 = this; | ||
var _this19 = this; | ||
return React.createElement(ChartComponent, _extends({}, this.props, { | ||
ref: function ref(_ref8) { | ||
return _this18.chartInstance = _ref8 && _ref8.chartInstance; | ||
return _this19.chartInstance = _ref8 && _ref8.chartInstance; | ||
}, | ||
@@ -508,7 +537,7 @@ type: 'bubble' | ||
Scatter.prototype.render = function render() { | ||
var _this20 = this; | ||
var _this21 = this; | ||
return React.createElement(ChartComponent, _extends({}, this.props, { | ||
ref: function ref(_ref9) { | ||
return _this20.chartInstance = _ref9 && _ref9.chartInstance; | ||
return _this21.chartInstance = _ref9 && _ref9.chartInstance; | ||
}, | ||
@@ -515,0 +544,0 @@ type: 'scatter' |
@@ -81,3 +81,3 @@ 'use strict'; | ||
if (this.props.redraw) { | ||
this.chartInstance.destroy(); | ||
this.destroyChart(); | ||
this.renderChart(); | ||
@@ -131,3 +131,3 @@ return; | ||
ChartComponent.prototype.componentWillUnmount = function componentWillUnmount() { | ||
this.chartInstance.destroy(); | ||
this.destroyChart(); | ||
}; | ||
@@ -165,2 +165,4 @@ | ||
this.saveCurrentDatasets(); // to remove the dataset metadata from this chart when the chart is destroyed | ||
return data; | ||
@@ -188,5 +190,19 @@ }; | ||
ChartComponent.prototype.updateChart = function updateChart() { | ||
ChartComponent.prototype.getCurrentDatasets = function getCurrentDatasets() { | ||
return this.chartInstance && this.chartInstance.config.data && this.chartInstance.config.data.datasets || []; | ||
}; | ||
ChartComponent.prototype.saveCurrentDatasets = function saveCurrentDatasets() { | ||
var _this2 = this; | ||
this.datasets = this.datasets || {}; | ||
var currentDatasets = this.getCurrentDatasets(); | ||
currentDatasets.forEach(function (d) { | ||
_this2.datasets[_this2.props.datasetKeyProvider(d)] = d; | ||
}); | ||
}; | ||
ChartComponent.prototype.updateChart = function updateChart() { | ||
var _this3 = this; | ||
var options = this.props.options; | ||
@@ -205,3 +221,3 @@ | ||
// seamless transitions | ||
var currentDatasets = this.chartInstance.config.data && this.chartInstance.config.data.datasets || []; | ||
var currentDatasets = this.getCurrentDatasets(); | ||
var nextDatasets = data.datasets || []; | ||
@@ -215,3 +231,3 @@ this.checkDatasets(currentDatasets); | ||
this.chartInstance.config.data.datasets = nextDatasets.map(function (next) { | ||
var current = currentDatasetsIndexed[_this2.props.datasetKeyProvider(next)]; | ||
var current = currentDatasetsIndexed[_this3.props.datasetKeyProvider(next)]; | ||
@@ -268,2 +284,15 @@ if (current && current.type === next.type) { | ||
ChartComponent.prototype.destroyChart = function destroyChart() { | ||
// Put all of the datasets that have existed in the chart back on the chart | ||
// so that the metadata associated with this chart get destroyed. | ||
// This allows the datasets to be used in another chart. This can happen, | ||
// for example, in a tabbed UI where the chart gets created each time the | ||
// tab gets switched to the chart and uses the same data). | ||
this.saveCurrentDatasets(); | ||
var datasets = Object.values(this.datasets); | ||
this.chartInstance.config.data.datasets = datasets; | ||
this.chartInstance.destroy(); | ||
}; | ||
ChartComponent.prototype.render = function render() { | ||
@@ -335,7 +364,7 @@ var _props3 = this.props, | ||
Doughnut.prototype.render = function render() { | ||
var _this4 = this; | ||
var _this5 = this; | ||
return _react2.default.createElement(ChartComponent, _extends({}, this.props, { | ||
ref: function ref(_ref) { | ||
return _this4.chartInstance = _ref && _ref.chartInstance; | ||
return _this5.chartInstance = _ref && _ref.chartInstance; | ||
}, | ||
@@ -359,7 +388,7 @@ type: 'doughnut' | ||
Pie.prototype.render = function render() { | ||
var _this6 = this; | ||
var _this7 = this; | ||
return _react2.default.createElement(ChartComponent, _extends({}, this.props, { | ||
ref: function ref(_ref2) { | ||
return _this6.chartInstance = _ref2 && _ref2.chartInstance; | ||
return _this7.chartInstance = _ref2 && _ref2.chartInstance; | ||
}, | ||
@@ -383,7 +412,7 @@ type: 'pie' | ||
Line.prototype.render = function render() { | ||
var _this8 = this; | ||
var _this9 = this; | ||
return _react2.default.createElement(ChartComponent, _extends({}, this.props, { | ||
ref: function ref(_ref3) { | ||
return _this8.chartInstance = _ref3 && _ref3.chartInstance; | ||
return _this9.chartInstance = _ref3 && _ref3.chartInstance; | ||
}, | ||
@@ -407,7 +436,7 @@ type: 'line' | ||
Bar.prototype.render = function render() { | ||
var _this10 = this; | ||
var _this11 = this; | ||
return _react2.default.createElement(ChartComponent, _extends({}, this.props, { | ||
ref: function ref(_ref4) { | ||
return _this10.chartInstance = _ref4 && _ref4.chartInstance; | ||
return _this11.chartInstance = _ref4 && _ref4.chartInstance; | ||
}, | ||
@@ -431,7 +460,7 @@ type: 'bar' | ||
HorizontalBar.prototype.render = function render() { | ||
var _this12 = this; | ||
var _this13 = this; | ||
return _react2.default.createElement(ChartComponent, _extends({}, this.props, { | ||
ref: function ref(_ref5) { | ||
return _this12.chartInstance = _ref5 && _ref5.chartInstance; | ||
return _this13.chartInstance = _ref5 && _ref5.chartInstance; | ||
}, | ||
@@ -455,7 +484,7 @@ type: 'horizontalBar' | ||
Radar.prototype.render = function render() { | ||
var _this14 = this; | ||
var _this15 = this; | ||
return _react2.default.createElement(ChartComponent, _extends({}, this.props, { | ||
ref: function ref(_ref6) { | ||
return _this14.chartInstance = _ref6 && _ref6.chartInstance; | ||
return _this15.chartInstance = _ref6 && _ref6.chartInstance; | ||
}, | ||
@@ -479,7 +508,7 @@ type: 'radar' | ||
Polar.prototype.render = function render() { | ||
var _this16 = this; | ||
var _this17 = this; | ||
return _react2.default.createElement(ChartComponent, _extends({}, this.props, { | ||
ref: function ref(_ref7) { | ||
return _this16.chartInstance = _ref7 && _ref7.chartInstance; | ||
return _this17.chartInstance = _ref7 && _ref7.chartInstance; | ||
}, | ||
@@ -503,7 +532,7 @@ type: 'polarArea' | ||
Bubble.prototype.render = function render() { | ||
var _this18 = this; | ||
var _this19 = this; | ||
return _react2.default.createElement(ChartComponent, _extends({}, this.props, { | ||
ref: function ref(_ref8) { | ||
return _this18.chartInstance = _ref8 && _ref8.chartInstance; | ||
return _this19.chartInstance = _ref8 && _ref8.chartInstance; | ||
}, | ||
@@ -527,7 +556,7 @@ type: 'bubble' | ||
Scatter.prototype.render = function render() { | ||
var _this20 = this; | ||
var _this21 = this; | ||
return _react2.default.createElement(ChartComponent, _extends({}, this.props, { | ||
ref: function ref(_ref9) { | ||
return _this20.chartInstance = _ref9 && _ref9.chartInstance; | ||
return _this21.chartInstance = _ref9 && _ref9.chartInstance; | ||
}, | ||
@@ -534,0 +563,0 @@ type: 'scatter' |
{ | ||
"name": "react-chartjs-2", | ||
"version": "2.7.5", | ||
"version": "2.7.6", | ||
"description": "react-chartjs-2", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
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
501491
17
5568
2
80
1
16
3