From f89078bfddfd6ab85b39cd3130cba5b34db53021 Mon Sep 17 00:00:00 2001 From: means88 Date: Tue, 28 Mar 2017 16:24:09 +0800 Subject: [PATCH 1/2] fix render problem of empty data --- src/index.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index ae3357a..7affbe9 100644 --- a/src/index.js +++ b/src/index.js @@ -23,6 +23,12 @@ export default function createG2(__operation) { const { data: newData, width: newWidth, height: newHeight, plotCfg: newPlotCfg } = newProps; const { data: oldData, width: oldWidth, height: oldHeight, plotCfg: oldPlotCfg } = this.props; + if (oldData.length === 0 && newData.length > 0) { + this.destroyChart(); + this.initChart(newProps); + return; + } + if (newPlotCfg !== oldPlotCfg) { console.warn('plotCfg 不支持修改'); } @@ -40,9 +46,7 @@ export default function createG2(__operation) { } componentWillUnmount() { - this.chart.destroy(); - this.chart = null; - this.chartId = null; + this.destroyChart(); } initChart(props) { @@ -58,6 +62,14 @@ export default function createG2(__operation) { this.chart = chart; } + destroyChart() { + if (this.chart) { + this.chart.destroy(); + } + this.chart = null; + this.chartId = null; + } + render() { return (
); } From 0863aa3dcc782a247f5f264aa508b99453942eb8 Mon Sep 17 00:00:00 2001 From: means88 Date: Tue, 28 Mar 2017 16:36:56 +0800 Subject: [PATCH 2/2] remove chartId before unmount --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 7affbe9..e1e51b1 100644 --- a/src/index.js +++ b/src/index.js @@ -47,6 +47,7 @@ export default function createG2(__operation) { componentWillUnmount() { this.destroyChart(); + this.chartId = null; } initChart(props) { @@ -67,7 +68,6 @@ export default function createG2(__operation) { this.chart.destroy(); } this.chart = null; - this.chartId = null; } render() {