UNPKG

@antv/g2

Version:

the Grammar of Graphics in Javascript

70 lines 2.58 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { MeshLambertMaterial, CubeGeometry, Mesh } from '@antv/g-plugin-3d'; import { applyStyle, getOrigin, toOpacityKey } from '../utils'; import { select } from '../../utils/selection'; const GEOMETRY_SIZE = 5; /** * @see https://g.antv.antgroup.com/api/3d/geometry#cubegeometry */ export const Cube = (options, context) => { // Render border only when colorAttribute is stroke. const style = __rest(options, []); // @ts-ignore if (!context.cubeGeometry) { const renderer = context.canvas.getConfig().renderer; const plugin = renderer.getPlugin('device-renderer'); const device = plugin.getDevice(); // create a sphere geometry // @ts-ignore context.cubeGeometry = new CubeGeometry(device, { width: GEOMETRY_SIZE * 2, height: GEOMETRY_SIZE * 2, depth: GEOMETRY_SIZE * 2, }); // create a material with Phong lighting model // @ts-ignore context.cubeMaterial = new MeshLambertMaterial(device); } return (points, value, defaults) => { const { color: defaultColor } = defaults; const { color = defaultColor, transform, opacity } = value; const [cx, cy, cz] = getOrigin(points); const r = value.size; const finalRadius = r || style.r || defaults.r; const cube = new Mesh({ style: { x: cx, y: cy, z: cz, // @ts-ignore geometry: context.cubeGeometry, // @ts-ignore material: context.cubeMaterial, }, }); cube.setOrigin(0, 0, 0); const scaling = finalRadius / GEOMETRY_SIZE; cube.scale(scaling); return select(cube) .call(applyStyle, defaults) .style('fill', color) .style('transform', transform) .style(toOpacityKey(options), opacity) .call(applyStyle, style) .node(); }; }; Cube.props = { defaultMarker: 'cube', }; //# sourceMappingURL=cube.js.map