|
|
@@ -31,6 +31,7 @@ class TagCloud extends Component {
|
|
|
}
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
+ this.isUnmount = true;
|
|
|
window.removeEventListener('resize', this.resize);
|
|
|
}
|
|
|
|
|
|
@@ -87,18 +88,14 @@ class TagCloud extends Component {
|
|
|
const h = height * 4;
|
|
|
const w = this.root.offsetWidth * 4;
|
|
|
|
|
|
- const imageMask = new Image();
|
|
|
- imageMask.crossOrigin = '';
|
|
|
- imageMask.src = imgUrl;
|
|
|
-
|
|
|
- imageMask.onload = () => {
|
|
|
+ const onload = () => {
|
|
|
const dv = new DataSet.View().source(data);
|
|
|
const range = dv.range('value');
|
|
|
const [min, max] = range;
|
|
|
dv.transform({
|
|
|
type: 'tag-cloud',
|
|
|
fields: ['name', 'value'],
|
|
|
- imageMask,
|
|
|
+ imageMask: this.imageMask,
|
|
|
font: 'Verdana',
|
|
|
size: [w, h], // 宽高设置最好根据 imageMask 做调整
|
|
|
padding: 5,
|
|
|
@@ -112,12 +109,26 @@ class TagCloud extends Component {
|
|
|
},
|
|
|
});
|
|
|
|
|
|
+ if (this.isUnmount) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
this.setState({
|
|
|
dv,
|
|
|
w,
|
|
|
h,
|
|
|
});
|
|
|
};
|
|
|
+
|
|
|
+ if (!this.imageMask) {
|
|
|
+ this.imageMask = new Image();
|
|
|
+ this.imageMask.crossOrigin = '';
|
|
|
+ this.imageMask.src = imgUrl;
|
|
|
+
|
|
|
+ this.imageMask.onload = onload;
|
|
|
+ } else {
|
|
|
+ onload();
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
render() {
|