|
|
@ -16,12 +16,18 @@ class WaterWave extends PureComponent { |
|
|
this.renderChart(); |
|
|
this.renderChart(); |
|
|
this.resize(); |
|
|
this.resize(); |
|
|
|
|
|
|
|
|
window.addEventListener('resize', () => { |
|
|
window.addEventListener('resize', this.resize); |
|
|
this.resize(); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
resize() { |
|
|
componentWillUnmount() { |
|
|
|
|
|
cancelAnimationFrame(this.timer); |
|
|
|
|
|
if (this.node) { |
|
|
|
|
|
this.node.innerHTML = ''; |
|
|
|
|
|
} |
|
|
|
|
|
window.removeEventListener('resize', this.resize); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
resize = () => { |
|
|
const { height } = this.props; |
|
|
const { height } = this.props; |
|
|
const realWidth = this.root.parentNode.offsetWidth; |
|
|
const realWidth = this.root.parentNode.offsetWidth; |
|
|
if (realWidth < this.props.height) { |
|
|
if (realWidth < this.props.height) { |
|
|
@ -39,6 +45,7 @@ class WaterWave extends PureComponent { |
|
|
renderChart() { |
|
|
renderChart() { |
|
|
const { percent, color = '#19AFFA' } = this.props; |
|
|
const { percent, color = '#19AFFA' } = this.props; |
|
|
const data = percent / 100; |
|
|
const data = percent / 100; |
|
|
|
|
|
const self = this; |
|
|
|
|
|
|
|
|
if (!this.node || !data) { |
|
|
if (!this.node || !data) { |
|
|
return; |
|
|
return; |
|
|
@ -163,7 +170,7 @@ class WaterWave extends PureComponent { |
|
|
sp += 0.07; |
|
|
sp += 0.07; |
|
|
drawSin(); |
|
|
drawSin(); |
|
|
} |
|
|
} |
|
|
requestAnimationFrame(render); |
|
|
self.timer = requestAnimationFrame(render); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
render(); |
|
|
render(); |
|
|
|