-
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.
feat: sphere shape used in 3d lib #5375
- Loading branch information
Showing
24 changed files
with
423 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { G2Spec } from '../../../src'; | ||
|
||
export function bodyPointScatterPlot3D(): G2Spec { | ||
return { | ||
type: 'point3D', | ||
padding: 'auto', | ||
data: { | ||
type: 'fetch', | ||
value: 'data/cars2.csv', | ||
}, | ||
encode: { | ||
x: 'Horsepower', | ||
y: 'Miles_per_Gallon', | ||
z: 'Weight_in_lbs', | ||
size: 'Origin', | ||
color: 'Cylinders', | ||
shape: 'sphere', | ||
}, | ||
scale: { | ||
x: { nice: true }, | ||
y: { nice: true }, | ||
z: { nice: true }, | ||
}, | ||
coordinate: { type: 'cartesian3D', depth: 300 }, | ||
axis: { | ||
x: { gridLineWidth: 3 }, | ||
y: { gridLineWidth: 3 }, | ||
z: { gridLineWidth: 3 }, | ||
}, | ||
// legend: false, | ||
}; | ||
} | ||
|
||
bodyPointScatterPlot3D.maxError = 100; |
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,38 @@ | ||
import { GuideComponentComponent as GCC } from '../runtime'; | ||
import { LinearAxis, AxisOptions } from './axis'; | ||
|
||
export type AxisXOptions = AxisOptions; | ||
|
||
/** | ||
* LinearAxis component bind to z scale. | ||
*/ | ||
export const AxisZ: GCC<AxisXOptions> = (options) => { | ||
return (...args) => { | ||
// empirical value for crossPadding | ||
const axis = LinearAxis( | ||
Object.assign( | ||
{}, | ||
{ | ||
crossPadding: 10, | ||
}, | ||
options, | ||
), | ||
)(...args); | ||
// const axisY = LinearAxis(Object.assign({}, { crossPadding: 10 }, options))( | ||
// ...args, | ||
// ); | ||
|
||
axis.setOrigin(0, 0, 0); | ||
// rotate around Y axis | ||
axis.rotate(0, -90, 0); | ||
|
||
return axis; | ||
}; | ||
}; | ||
|
||
AxisZ.props = { | ||
...LinearAxis.props, | ||
defaultPosition: 'bottom', | ||
}; | ||
|
||
export function axisZConfig() {} |
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,11 @@ | ||
import { Coordinate3DComponent as CC } from '../runtime'; | ||
import { Cartesian3DCoordinate } from '../spec'; | ||
|
||
export type Cartesian3DOptions = Cartesian3DCoordinate; | ||
|
||
/** | ||
* Default coordinate3D transformation for all charts. | ||
*/ | ||
export const Cartesian3D: CC<Cartesian3DCoordinate> = () => [['cartesian3D']]; | ||
|
||
Cartesian3D.props = {}; |
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,11 @@ | ||
import { Cartesian3D } from '../coordinate'; | ||
import { AxisZ } from '../component'; | ||
import { Point3D } from '../mark'; | ||
|
||
export function threedlib() { | ||
return { | ||
'coordinate.cartesian3D': Cartesian3D, | ||
'component.axisZ': AxisZ, | ||
'mark.point3D': Point3D, | ||
} as const; | ||
} |
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,84 @@ | ||
import { Coordinate3D } from '@antv/coord'; | ||
import { MarkComponent as MC, Vector2, Vector3 } from '../runtime'; | ||
import { PointMark } from '../spec'; | ||
import { MaybeZeroX, MaybeZeroY, MaybeSize } from '../transform'; | ||
import { Sphere, Cube } from '../shape'; | ||
import { | ||
baseGeometryChannels, | ||
basePostInference, | ||
basePreInference, | ||
createBandOffset, | ||
tooltip3d, | ||
} from './utils'; | ||
|
||
export type PointOptions = Omit<PointMark, 'type'>; | ||
|
||
/** | ||
* Convert value for each channel to point shapes. | ||
* Calc the bbox of each point based on x, y and r. | ||
* This is for allowing their radius can be affected by coordinate(e.g. fisheye). | ||
*/ | ||
export const Point3D: MC<PointOptions> = (options) => { | ||
return (index, scale, value, coordinate) => { | ||
const { x: X, y: Y, z: Z, x1: X1, y1: Y1, size: S, dx: DX, dy: DY } = value; | ||
const [width, height, depth] = ( | ||
coordinate as unknown as Coordinate3D | ||
).getSize(); | ||
const offset = createBandOffset(scale, value, options); | ||
const xyz: (i: number) => Vector3 = (i) => { | ||
const dx = +(DX?.[i] || 0); | ||
const dy = +(DY?.[i] || 0); | ||
const x = X1 ? (+X[i] + +X1[i]) / 2 : +X[i]; | ||
const y = Y1 ? (+Y[i] + +Y1[i]) / 2 : +Y[i]; | ||
const cx = x + dx; | ||
const cy = y + dy; | ||
return [cx, cy, (Z[i] as number) || 0]; | ||
}; | ||
const P = S | ||
? Array.from(index, (i) => { | ||
const [cx, cy, cz] = xyz(i); | ||
const r = +S[i]; | ||
const a = r / width; | ||
const b = r / height; | ||
const p1: Vector2 = [cx - a, cy - b]; | ||
const p2: Vector2 = [cx + a, cy + b]; | ||
return [ | ||
coordinate.map([...offset(p1, i), cz]), | ||
coordinate.map([...offset(p2, i), cz]), | ||
] as Vector3[]; | ||
}) | ||
: Array.from(index, (i) => { | ||
const [cx, cy, cz] = xyz(i); | ||
return [coordinate.map([...offset([cx, cy], i), cz])] as Vector3[]; | ||
}); | ||
return [index, P]; | ||
}; | ||
}; | ||
|
||
const shape = { | ||
sphere: Sphere, | ||
cube: Cube, | ||
}; | ||
|
||
Point3D.props = { | ||
defaultShape: 'sphere', | ||
defaultLabelShape: 'label', | ||
composite: false, | ||
shape, | ||
channels: [ | ||
...baseGeometryChannels({ shapes: Object.keys(shape) }), | ||
{ name: 'x', required: true }, | ||
{ name: 'y', required: true }, | ||
{ name: 'z' }, | ||
{ name: 'series', scale: 'band' }, | ||
{ name: 'size', quantitative: 'sqrt' }, | ||
{ name: 'dx', scale: 'identity' }, | ||
{ name: 'dy', scale: 'identity' }, | ||
], | ||
preInference: [ | ||
...basePreInference(), | ||
{ type: MaybeZeroX }, | ||
{ type: MaybeZeroY }, | ||
], | ||
postInference: [...basePostInference(), { type: MaybeSize }, ...tooltip3d()], | ||
}; |
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
Oops, something went wrong.