-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: sphere shape used in 3d lib #5375 * fix: remove lighting initialization from geometry * fix: add grid on x-z & y-z planes * fix: support perspective * chore: add 3d charts example in site * chore: add 3d chart manual * fix: depth should work in chart api * chore: update usage of threelib * chore: fix test case for stdlib
- Loading branch information
Showing
64 changed files
with
1,613 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
__tests__/plots/api/chart-render-3d-scatter-plot-perspective.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { CameraType } from '@antv/g'; | ||
import { Renderer as WebGLRenderer } from '@antv/g-webgl'; | ||
import { Plugin as ThreeDPlugin, DirectionalLight } 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 chartRender3dScatterPlotPerspective(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, | ||
theme: 'classic', | ||
renderer, | ||
depth: 400, | ||
}); | ||
|
||
chart | ||
.point3D() | ||
.data({ | ||
type: 'fetch', | ||
value: 'data/cars2.csv', | ||
}) | ||
.encode('x', 'Horsepower') | ||
.encode('y', 'Miles_per_Gallon') | ||
.encode('z', 'Weight_in_lbs') | ||
.encode('size', 'Origin') | ||
.encode('color', 'Cylinders') | ||
.encode('shape', 'cube') | ||
.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); | ||
|
||
// Add a directional light into scene. | ||
const light = new DirectionalLight({ | ||
style: { | ||
intensity: 3, | ||
fill: 'white', | ||
direction: [-1, 0, 1], | ||
}, | ||
}); | ||
canvas!.appendChild(light); | ||
}); | ||
|
||
return { finished }; | ||
} | ||
|
||
chartRender3dScatterPlotPerspective.skip = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { CameraType } from '@antv/g'; | ||
import { Renderer as WebGLRenderer } from '@antv/g-webgl'; | ||
import { Plugin as ThreeDPlugin, DirectionalLight } 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 chartRender3dScatterPlot(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, | ||
theme: 'classic', | ||
renderer, | ||
depth: 400, | ||
}); | ||
|
||
chart | ||
.point3D() | ||
.data({ | ||
type: 'fetch', | ||
value: 'data/cars2.csv', | ||
}) | ||
.encode('x', 'Horsepower') | ||
.encode('y', 'Miles_per_Gallon') | ||
.encode('z', 'Weight_in_lbs') | ||
.encode('size', 'Origin') | ||
.encode('color', 'Cylinders') | ||
.encode('shape', 'cube') | ||
.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.setType(CameraType.ORBITING); | ||
camera.rotate(-20, -20, 0); | ||
|
||
// Add a directional light into scene. | ||
const light = new DirectionalLight({ | ||
style: { | ||
intensity: 2.5, | ||
fill: 'white', | ||
direction: [-1, 0, 1], | ||
}, | ||
}); | ||
canvas!.appendChild(light); | ||
}); | ||
|
||
return { finished }; | ||
} | ||
|
||
chartRender3dScatterPlot.skip = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { threedlib } from '../../../src/lib'; | ||
import { Cartesian3D } from '../../../src/coordinate'; | ||
import { AxisZ } from '../../../src/component'; | ||
import { Point3D } from '../../../src/mark'; | ||
|
||
describe('threedlib', () => { | ||
it('threedlib() should returns expected threed components.', () => { | ||
expect(threedlib()).toEqual({ | ||
'coordinate.cartesian3D': Cartesian3D, | ||
'component.axisZ': AxisZ, | ||
'mark.point3D': Point3D, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
title: Use 3D Charts | ||
order: 11 | ||
--- | ||
|
||
<embed src="@/docs/manual/extra-topics/3d-charts.zh.md"></embed> |
Oops, something went wrong.