metal-surface.html
13.1 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<!--
此示例下载自 https://echarts.apache.org/examples/zh/editor.html?c=metal-surface&gl=1&theme=dark&code=PTAEnxXQEI0cSNCN9QQt0E9mgjdMEPKgHU0J2mhoL0DD_gKV0Di5UAZwFMAnASzJIFoSBXCgMwEMBjMgOgAc2KbALZkALtQ4BRAI6M2oqgHsAdgFgAUC0bKOClaADmYgAoDhYiTLl7lAChKiBogErylAGlBllAE1d7PKhIAZTIAGzJdMh9AkgAJRQA3SmjPAGtPAAsASlAAbw1QItAQUEBC6MB070LijhUHUCEqPzdFUABeUHtHChcW0ABqL19_JVywACYAbmqi2uV6hydXHyo2ZXbSbt69UAAqUABZeUzuYwBJPdApmdA5-u9mlbWNh5HW_aPRE_PL6_Vi251UQNJrLVbrDqNZo7D7HU4XfZ_AGlQBBmoAc80AV8qASHNAABygCo5OC4QCYSoBYOUAedqABudAJAJgFo5QASpmjA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AeSo5yiCqKDCqgDiAsoawxREGOCQFpKPbwFc4844GY74G0qc6KCiBcFCDkpU7YGhJkDZiiB1ocHcTi7k5Djy7SSR4GEx5x6C42p0G9hcE8FUB8ER5LL2TqGUAHhMKjwkC5BtD9T8EAhdT0oXrnoABy5gw66SQgigV6ESjABht6SKQobcPhT4t6ERIgURaSHuBaVBx0qynOLAnOGwjWMa0ktgzB6R4WIR1RnycK2YrmXWoorQdApqx0VRRmtR56ZwDRTRY2jgUWKUVSew7R3EVOvIYxoA2Q3AXBAAYlQNmNELYOMLtoHJLGUeqgCMipit0RkeYNqAlJzhQMAL1Liv0FMdsQlCQPwIdiWm0AAERHy8AB5fQvhhC5J0Cc7z5pCTD2QUAGAvh0DUAp57jkS8DZiTCqEUBZIUDAngGqpU4QmTAco-BfB7hImQmZAQKgmYlQmcBpAGAUCxG-B0AmG7FpHi55wPG9QJTAA3FrBnEDCXHFA7F5BFGc7agwHIpTFrFtTiG9hI5payjVA3DZj17ZhBAMJGEgjCQWzM4xT2RBQKmCmuRFgSlSkdwymWTym0pKnh6qk3BawakkDSn5F2QvhZx6kOQI5q43BElNBmn8GCHCEDYqGKDZjJ7QJp5t5gCACQcoAC9-gA2N6ACGyoACg6gACuqADgFoAN8-GYgZgAXOqAD2ZjSPAAgi9jQGygAMIqDiAZoykAiiJsDvYE4tJB5SGgDA4162SCJrBcAHiIHj4gCwaAAuphfDfPfM_LgIAN4-gAPPKtlazcFCAtLEnKqKreDPgKCJCM60Fr6gCAB90bMu2LyIAAemgAqzZ_wtKDmKDuoTmYJUDTnK6zmlCLnLnrmACU_uBC0rcaEPMPuYefDk2WAKeauWuYAM56tYLSbACRigzgahe0TKLKc5gAV4GAAVSpuXYXab2OegeOeipHnEAA
⚠ 请注意,该图表不是 Apache ECharts 官方示例,而是由用户代码生成的。请注意鉴别其内容。
-->
<!DOCTYPE html>
<html style="height: 100%;width: 100%;">
<head>
<meta charset="utf-8">
</head>
<body style="height: 100%;width: 100%; margin: 0;font-size:1rem;line-height:150%;overflow-y: hidden;overflow-x:hidden;">
<div id="container" style="height: 100%;width: 100%;"></div>
<script type="text/javascript" src="jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="echarts-gl.min.js"></script>
<script type="text/javascript" src="echarts-gl.js"></script>
<script type="text/javascript" src="ajax.js"></script>
<script type="text/javascript">
var dom = document.getElementById('container');
var myChart = echarts.init(dom, 'dark', {
renderer: 'canvas',
useDirtyRect: false
});
var app = {};
var option;
// 生成扇形的曲面参数方程,用于 series-surface.parametricEquation
function getParametricEquation(startRatio, endRatio, isSelected, isHovered, k, h) {
// 计算
const midRatio = (startRatio + endRatio) / 2;
const startRadian = startRatio * Math.PI * 2;
const endRadian = endRatio * Math.PI * 2;
const midRadian = midRatio * Math.PI * 2;
// 如果只有一个扇形,则不实现选中效果。
if (startRatio === 0 && endRatio === 1) {
isSelected = false;
}
// 通过扇形内径/外径的值,换算出辅助参数 k(默认值 1/3)
k = 1;
// 计算选中效果分别在 x 轴、y 轴方向上的位移(未选中,则位移均为 0)
const offsetX = isSelected ? Math.cos(midRadian) * 0.1 : 0;
const offsetY = isSelected ? Math.sin(midRadian) * 0.1 : 0;
// 计算高亮效果的放大比例(未高亮,则比例为 1)
const hoverRate = isHovered ? 1.05 : 1;
// 返回曲面参数方程
return {
u: {
min: -Math.PI,
max: Math.PI * 3,
step: Math.PI / 32,
},
v: {
min: 0,
max: Math.PI * 2,
step: Math.PI / 20,
},
x: function (u, v) {
if (u < startRadian) {
return offsetX + Math.cos(startRadian) * (1 + Math.cos(v) * k) * hoverRate;
}
if (u > endRadian) {
return offsetX + Math.cos(endRadian) * (1 + Math.cos(v) * k) * hoverRate;
}
return offsetX + Math.cos(u) * (1 + Math.cos(v) * k) * hoverRate;
},
y: function (u, v) {
if (u < startRadian) {
return offsetY + Math.sin(startRadian) * (1 + Math.cos(v) * k) * hoverRate;
}
if (u > endRadian) {
return offsetY + Math.sin(endRadian) * (1 + Math.cos(v) * k) * hoverRate;
}
return offsetY + Math.sin(u) * (1 + Math.cos(v) * k) * hoverRate;
},
z: function (u, v) {
if (u < -Math.PI * 0.5) {
return Math.sin(u);
}
if (u > Math.PI * 2.5) {
return Math.sin(u) * h * 0.1;
}
return Math.sin(v) > 0 ? 1 * h * 0.1 : -1;
},
};
}
/**
* 绘制3d图
* @param pieData 总数据
* @param internalDiameterRatio:透明的空心占比
* @param distance 视角到主体的距离
* @param alpha 旋转角度
* @param pieHeight 立体的高度
* @param opacity 饼或者环的透明度
*/
function getPie3D(pieData, internalDiameterRatio, distance, alpha, pieHeight, opacity = 1) {
const series = [];
let sumValue = 0;
let startValue = 0;
let endValue = 0;
const legendData = [];
const k =
typeof internalDiameterRatio !== 'undefined'
? (1 - internalDiameterRatio) / (1 + internalDiameterRatio)
: 1 / 3;
// 为每一个饼图数据,生成一个 series-surface 配置
for (let i = 0; i < pieData.length; i += 1) {
sumValue += pieData[i].value;
const seriesItem = {
name: typeof pieData[i].name === 'undefined' ? `series${i}` : pieData[i].name,
type: 'surface',
parametric: true,
wireframe: {
show: false,
},
pieData: pieData[i],
pieStatus: {
selected: false,
hovered: false,
k: k,
},
};
if (typeof pieData[i].itemStyle !== 'undefined') {
const itemStyle = {};
if (typeof pieData[i].itemStyle.color !== 'undefined') {
itemStyle.color = pieData[i].itemStyle.color;
}
if (typeof pieData[i].itemStyle.opacity !== 'undefined') {
itemStyle.opacity = pieData[i].itemStyle.opacity;
}
seriesItem.itemStyle = itemStyle;
}
series.push(seriesItem);
}
// 使用上一次遍历时,计算出的数据和 sumValue,调用 getParametricEquation 函数,
// 向每个 series-surface 传入不同的参数方程 series-surface.parametricEquation,也就是实现每一个扇形。
for (let i = 0; i < series.length; i += 1) {
endValue = startValue + series[i].pieData.value;
series[i].pieData.startRatio = startValue / sumValue;
series[i].pieData.endRatio = endValue / sumValue;
console.log(series[i].pieData.startRatio,
series[i].pieData.endRatio,
false,
false,
k,
series[i].pieData.value)
series[i].parametricEquation = getParametricEquation(
series[i].pieData.startRatio,
series[i].pieData.endRatio,
false,
false,
k,
series[i].pieData.value
);
startValue = endValue;
legendData.push(series[i].name);
}
return series;
}
const optionsData = [
{
name: 'aa',
value: 20,
itemStyle: {
color: '#41adf8',
// opacity: 1,
},
},
{
name: 'cc',
value: 25,
itemStyle: {
color: '#ffa100',
// opacity: 1,
},
},
{
name: 'bb',
value: 22,
itemStyle: {
color: '#2acf81',
// opacity: 1,
},
},
];
const series = getPie3D(optionsData, 0.8, 20, 24, 26, 0.5);
series.push({
name: 'pie2d',
type: 'pie',
label: {
opacity: 1,
fontSize: 13,
lineHeight: 20,
},
labelLine: {
length: 30,
length2: 30,
},
startAngle: -30, //起始角度,支持范围[0, 360]。
clockwise: false, //饼图的扇区是否是顺时针排布。上述这两项配置主要是为了对齐3d的样式
radius: ['20%', '50%'],
center: ['50%', '50%'],
data: optionsData,
itemStyle: {
opacity: 0,
},
});
option = {
legend: {
tooltip: {
show: true,
},
data: ['aa', 'bb', 'cc'],
bottom: '10%',
textStyle: {
color: '#fff',
fontSize: 12,
},
},
tooltip: {
formatter: (params) => {
if (params.seriesName !== 'mouseoutSeries' && params.seriesName !== 'pie2d') {
let bfb = (
(option.series[params.seriesIndex].pieData.endRatio -
option.series[params.seriesIndex].pieData.startRatio) *
100
).toFixed(2);
return (
`${params.seriesName}<br/>` +
`<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:${params.color};"></span>` +
`${bfb}%`
);
}
},
},
xAxis3D: {
min: -1,
max: 1,
},
yAxis3D: {
min: -1,
max: 1,
},
zAxis3D: {
min: -1,
max: 1,
},
grid3D: {
show: false,
boxHeight: 20, // 三维笛卡尔坐标系在三维场景中的高度
viewControl: {
alpha: 25,
beta: 40,
distance: 500, //调整视角到主体的距离,类似调整zoom
rotateSensitivity: 0, // 设置为0无法旋转
zoomSensitivity: 0, // 设置为0无法缩放
panSensitivity: 0, // 设置为0无法平移
autoRotate: true, // 自动旋转
},
},
series: series,
};
if (option && typeof option === 'object') {
myChart.setOption(option);
}
</script>
</body>
</html>