-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: surface * feat: add surface plot
- Loading branch information
Showing
13 changed files
with
640 additions
and
13 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
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,63 @@ | ||
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, corelib } from "@antv/g2"; | ||
import { threedlib } from "../../src"; | ||
import diric from "dirichlet"; | ||
|
||
const size = 100; | ||
const points: { x: number; y: number; z: number }[] = []; | ||
for (let i = 0; i < size + 1; i++) { | ||
for (let j = 0; j < size + 1; j++) { | ||
points.push({ | ||
x: i, | ||
y: j, | ||
z: 0.1 * size * diric(5, (5.0 * (i - size / 2)) / size) * diric(5, (5.0 * (j - size / 2)) / size), | ||
}); | ||
} | ||
} | ||
|
||
export function Surface(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, | ||
width: 500, | ||
height: 500, | ||
depth: 300, | ||
}); | ||
|
||
chart | ||
.surface3D() | ||
.data(points) | ||
.encode("x", "x") | ||
.encode("y", "y") | ||
.encode("z", "z") | ||
.encode("color", "z") | ||
.coordinate({ type: "cartesian3D" }) | ||
.scale("x", { nice: true }) | ||
.scale("y", { nice: true }) | ||
.scale("z", { nice: true }) | ||
.scale("color", { palette: "spectral" }) | ||
.legend(false) | ||
.axis("x", { gridLineWidth: 1 }) | ||
.axis("y", { gridLineWidth: 1, titleBillboardRotation: -Math.PI / 2 }) | ||
.axis("z", { gridLineWidth: 1 }); | ||
|
||
const finished = chart.render().then(() => { | ||
const { canvas } = chart.getContext(); | ||
const camera = canvas!.getCamera(); | ||
camera.setType(CameraType.ORBITING); | ||
camera.rotate(-20, -20, 0); | ||
}); | ||
|
||
return { finished, destroy: () => chart.destroy() }; | ||
} |
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,56 @@ | ||
import { Coordinate3D } from "@antv/coord"; | ||
import { MarkComponent as MC, BaseMark, Vector3, MaybeZeroX, MaybeZeroY, MaybeZeroZ, MaybeSize } from "@antv/g2"; | ||
import { Surface } from "../shape/surface3D/surface"; | ||
import { baseGeometryChannels, basePostInference, basePreInference, tooltip3d } from "./utils"; | ||
|
||
// @ts-ignore | ||
type Surface3DMark = BaseMark<"surface">; | ||
|
||
export type Surface3DOptions = Omit<Surface3DMark, "type">; | ||
|
||
export const Surface3D: MC<Surface3DOptions> = (options) => { | ||
return (index, _, value, coordinate) => { | ||
const { x: X, y: Y, z: Z } = value; | ||
// const [width, height, depth] = ( | ||
// coordinate as unknown as Coordinate3D | ||
// ).getSize(); | ||
const xyz: (i: number) => Vector3 = (i) => { | ||
const x = +X[i] || 0; | ||
const y = +Y[i] || 0; | ||
const z = +Z[i || 0]; | ||
return [x, y, z]; | ||
}; | ||
const P = Array.from(index, (i) => { | ||
const [cx, cy, cz] = xyz(i); | ||
return [...(coordinate as unknown as Coordinate3D).map([cx, cy, cz])] as Vector3; | ||
}); | ||
return [[0], [P]]; | ||
}; | ||
}; | ||
|
||
const shape = { | ||
surface: Surface, | ||
}; | ||
|
||
Surface3D.props = { | ||
defaultShape: "surface", | ||
defaultLabelShape: "label", | ||
composite: false, | ||
shape, | ||
channels: [ | ||
...baseGeometryChannels({ shapes: Object.keys(shape) }), | ||
{ name: "x", required: true }, | ||
{ name: "y", required: true }, | ||
{ name: "z", required: true }, | ||
// { name: 'color', scale: 'identity', required: true }, | ||
], | ||
// @ts-ignore | ||
preInference: [...basePreInference(), { type: MaybeZeroX }, { type: MaybeZeroY }, { type: MaybeZeroZ }], | ||
// @ts-ignore | ||
postInference: [...basePostInference(), { type: MaybeSize }, ...tooltip3d()], | ||
interaction: { | ||
shareTooltip: false, | ||
seriesTooltip: false, | ||
crosshairs: false, | ||
}, | ||
}; |
Oops, something went wrong.