-
Notifications
You must be signed in to change notification settings - Fork 0
/
chart-render-3d-line-plot-perspective.ts
66 lines (57 loc) · 1.79 KB
/
chart-render-3d-line-plot-perspective.ts
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
import { CameraType } from '@antv/g';
import { Renderer as WebGLRenderer } from '@antv/g-webgl';
import { Plugin as ThreeDPlugin } from '@antv/g-plugin-3d';
import { Plugin as ControlPlugin } from '@antv/g-plugin-control';
import { Runtime, extend } from '../../../src/api';
import { corelib, threedlib } from '../../../src/lib';
export function chartRender3dLinePlotPerspective(context) {
const { container } = context;
// Create a WebGL renderer.
const renderer = new WebGLRenderer();
renderer.registerPlugin(new ThreeDPlugin());
renderer.registerPlugin(new ControlPlugin());
const Chart = extend(Runtime, { ...corelib(), ...threedlib() });
const chart = new Chart({
container,
renderer,
depth: 400,
});
/**
* 3D Spiral
* @see https://plotly.com/javascript/3d-line-plots/
*/
const pointCount = 500;
let r: number;
const data: { x: number; y: number; z: number }[] = [];
for (let i = 0; i < pointCount; i++) {
r = i * (pointCount - i);
data.push({
x: r * Math.cos(i / 30),
y: r * Math.sin(i / 30),
z: i,
});
}
chart
.line3D()
.data(data)
.encode('x', 'x')
.encode('y', 'y')
.encode('z', 'z')
.encode('size', 4)
.coordinate({ type: 'cartesian3D' })
.scale('x', { nice: true })
.scale('y', { nice: true })
.scale('z', { nice: true })
.legend(false)
.axis('x', { gridLineWidth: 2 })
.axis('y', { gridLineWidth: 2, titleBillboardRotation: -Math.PI / 2 })
.axis('z', { gridLineWidth: 2 });
const finished = chart.render().then(() => {
const { canvas } = chart.getContext();
const camera = canvas!.getCamera();
camera.setPerspective(0.1, 5000, 45, 500 / 500);
camera.setType(CameraType.ORBITING);
});
return { finished };
}
chartRender3dLinePlotPerspective.skip = true;