Polygons3DSeries.js
2.9 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import * as echarts from 'echarts/lib/echarts';
import componentShadingMixin from '../../component/common/componentShadingMixin';
function transformPolygon(coordSys, poly) {
var ret = [];
for (var i = 0; i < poly.length; i++) {
ret.push(coordSys.dataToPoint(poly[i]));
}
return ret;
}
var Polygons3DSeries = echarts.SeriesModel.extend({
type: 'series.polygons3D',
getRegionModel: function (idx) {
return this.getData().getItemModel(idx);
},
getRegionPolygonCoords: function (idx) {
var coordSys = this.coordinateSystem;
var itemModel = this.getData().getItemModel(idx);
var coords = itemModel.option instanceof Array
? itemModel.option : itemModel.getShallow('coords');
if (!itemModel.get('multiPolygon')) {
coords = [coords];
}
// TODO Validate
var out = [];
for (var i = 0; i < coords.length; i++) {
// TODO Convert here ?
var interiors = [];
for (var k = 1; k < coords[i].length; k++) {
interiors.push(transformPolygon(coordSys, coords[i][k]));
}
out.push({
exterior: transformPolygon(coordSys, coords[i][0]),
interiors: interiors
});
}
return out;
},
getInitialData: function (option) {
var polygonsData = new echarts.List(['value'], this);
polygonsData.hasItemOption = false;
polygonsData.initData(option.data, [], function (dataItem, dimName, dataIndex, dimIndex) {
// dataItem is simply coords
if (dataItem instanceof Array) {
return NaN;
}
else {
polygonsData.hasItemOption = true;
var value = dataItem.value;
if (value != null) {
return value instanceof Array ? value[dimIndex] : value;
}
}
});
return polygonsData;
},
defaultOption: {
show: true,
data: null,
multiPolygon: false,
progressiveThreshold: 1e3,
progressive: 1e3,
zlevel: -10,
label: {
show: false,
// Distance in 3d space.
distance: 2,
textStyle: {
fontSize: 20,
color: '#000',
backgroundColor: 'rgba(255,255,255,0.7)',
padding: 3,
borderRadius: 4
}
},
itemStyle: {
color: '#fff',
borderWidth: 0,
borderColor: '#333'
},
emphasis: {
itemStyle: {
color: '#639fc0'
},
label: {
show: true
}
}
}
});
echarts.util.merge(Polygons3DSeries.prototype, componentShadingMixin);
export default Polygons3DSeries;