UNPKG

@antv/g2

Version:

the Grammar of Graphics in Javascript

76 lines 2.73 kB
import { MaybeZeroX, MaybeZeroY, MaybeZeroZ, MaybeSize } from '../transform'; import { Sphere, Cube } from '../shape'; import { baseGeometryChannels, basePostInference, basePreInference, tooltip3d, } from './utils'; /** * 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 = (options) => { return (index, _, value, coordinate) => { const { x: X, y: Y, z: Z, size: S, dx: DX, dy: DY, dz: DZ } = value; const [width, height, depth] = coordinate.getSize(); const xyz = (i) => { const dx = +((DX === null || DX === void 0 ? void 0 : DX[i]) || 0); const dy = +((DY === null || DY === void 0 ? void 0 : DY[i]) || 0); const dz = +((DZ === null || DZ === void 0 ? void 0 : DZ[i]) || 0); const x = +X[i]; const y = +Y[i]; const z = +Z[i]; const cx = x + dx; const cy = y + dy; const cz = z + dz; return [cx, cy, cz]; }; 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 c = r / depth; const p1 = [cx - a, cy - b, cz - c]; const p2 = [cx + a, cy + b, cz + c]; return [ coordinate.map([...p1, cz]), coordinate.map([...p2, cz]), ]; }) : Array.from(index, (i) => { const [cx, cy, cz] = xyz(i); return [ coordinate.map([cx, cy, cz]), ]; }); return [index, P]; }; }; const shape = { sphere: Sphere, cube: Cube, }; Point3D.props = { defaultShape: 'cube', defaultLabelShape: 'label', composite: false, shape, channels: [ ...baseGeometryChannels({ shapes: Object.keys(shape) }), { name: 'x', required: true }, { name: 'y', required: true }, { name: 'z', required: true }, { name: 'series', scale: 'band' }, { name: 'size', quantitative: 'sqrt' }, { name: 'dx', scale: 'identity' }, { name: 'dy', scale: 'identity' }, { name: 'dz', scale: 'identity' }, ], preInference: [ ...basePreInference(), { type: MaybeZeroX }, { type: MaybeZeroY }, { type: MaybeZeroZ }, ], postInference: [...basePostInference(), { type: MaybeSize }, ...tooltip3d()], }; //# sourceMappingURL=point3D.js.map