WordCloudView.js
1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var echarts = require('echarts/lib/echarts');
function getShallow(model, path) {
return model && model.getShallow(path);
}
echarts.extendChartView({
type: 'wordCloud',
render: function (seriesModel, ecModel, api) {
var group = this.group;
group.removeAll();
var data = seriesModel.getData();
var gridSize = seriesModel.get('gridSize');
seriesModel.layoutInstance.ondraw = function (text, size, dataIdx, drawn) {
var itemModel = data.getItemModel(dataIdx);
var textStyleModel = itemModel.getModel('textStyle.normal');
var emphasisTextStyleModel = itemModel.getModel('textStyle.emphasis');
var textEl = new echarts.graphic.Text({
style: echarts.graphic.setTextStyle({}, textStyleModel, {
x: drawn.info.fillTextOffsetX,
y: drawn.info.fillTextOffsetY + size * 0.5,
text: text,
textBaseline: 'middle',
textFill: data.getItemVisual(dataIdx, 'color'),
fontSize: size
}),
scale: [1 / drawn.info.mu, 1 / drawn.info.mu],
position: [
(drawn.gx + drawn.info.gw / 2) * gridSize,
(drawn.gy + drawn.info.gh / 2) * gridSize
],
rotation: drawn.rot
});
group.add(textEl);
data.setItemGraphicEl(dataIdx, textEl);
echarts.graphic.setHoverStyle(
textEl,
echarts.graphic.setTextStyle({}, emphasisTextStyleModel, null, {forMerge: true}, true)
);
};
this._model = seriesModel;
},
remove: function () {
this.group.removeAll();
this._model.layoutInstance.dispose();
},
dispose: function () {
this._model.layoutInstance.dispose();
}
});