From ac133a1f33443ad41ee8f0c6760b15859bc36ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Thu, 6 Sep 2018 09:33:20 +0800 Subject: [PATCH] fix #2173 Wrong rendering logic --- src/components/Charts/WaterWave/index.js | 14 +++++++------- src/pages/Dashboard/Monitor.js | 3 ++- src/pages/Dashboard/Workplace.js | 3 ++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/components/Charts/WaterWave/index.js b/src/components/Charts/WaterWave/index.js index 450b31ff..055f7c73 100644 --- a/src/components/Charts/WaterWave/index.js +++ b/src/components/Charts/WaterWave/index.js @@ -27,7 +27,8 @@ class WaterWave extends PureComponent { componentDidUpdate(props) { const { percent } = this.props; if (props.percent !== percent) { - this.renderChart(); + // 不加这个会造成绘制缓慢 + this.renderChart('update'); } } @@ -49,10 +50,11 @@ class WaterWave extends PureComponent { } }; - renderChart() { + renderChart(type) { const { percent, color = '#1890FF' } = this.props; const data = percent / 100; const self = this; + cancelAnimationFrame(this.timer); if (!this.node || (data !== 0 && !data)) { return; @@ -60,7 +62,6 @@ class WaterWave extends PureComponent { const canvas = this.node; const ctx = canvas.getContext('2d'); - const canvasWidth = canvas.width; const canvasHeight = canvas.height; const radius = canvasWidth / 2; @@ -115,7 +116,7 @@ class WaterWave extends PureComponent { const gradient = ctx.createLinearGradient(0, 0, 0, canvasHeight); gradient.addColorStop(0, '#ffffff'); - gradient.addColorStop(1, '#1890FF'); + gradient.addColorStop(1, color); ctx.fillStyle = gradient; ctx.fill(); ctx.restore(); @@ -123,7 +124,7 @@ class WaterWave extends PureComponent { function render() { ctx.clearRect(0, 0, canvasWidth, canvasHeight); - if (circleLock) { + if (circleLock && type !== 'update') { if (arcStack.length) { const temp = arcStack.shift(); ctx.lineTo(temp[0], temp[1]); @@ -145,7 +146,7 @@ class WaterWave extends PureComponent { ctx.restore(); ctx.clip(); - ctx.fillStyle = '#1890FF'; + ctx.fillStyle = color; } } else { if (data >= 0.85) { @@ -180,7 +181,6 @@ class WaterWave extends PureComponent { } self.timer = requestAnimationFrame(render); } - render(); } diff --git a/src/pages/Dashboard/Monitor.js b/src/pages/Dashboard/Monitor.js index 5ec0a260..0c475db3 100644 --- a/src/pages/Dashboard/Monitor.js +++ b/src/pages/Dashboard/Monitor.js @@ -21,7 +21,6 @@ const havePermissionAsync = new Promise(resolve => { setTimeout(() => resolve(), 300); }); -export default @Secured(havePermissionAsync) @connect(({ monitor, loading }) => ({ monitor, @@ -153,3 +152,5 @@ class Monitor extends PureComponent { ); } } + +export default Monitor; diff --git a/src/pages/Dashboard/Workplace.js b/src/pages/Dashboard/Workplace.js index c53ef469..e9e44d45 100644 --- a/src/pages/Dashboard/Workplace.js +++ b/src/pages/Dashboard/Workplace.js @@ -37,7 +37,6 @@ const links = [ }, ]; -export default @connect(({ user, project, activities, chart, loading }) => ({ currentUser: user.currentUser, project, @@ -253,3 +252,5 @@ class Workplace extends PureComponent { ); } } + +export default Workplace; -- GitLab