UNPKG

@antv/g2

Version:

the Grammar of Graphics in Javascript

74 lines 2.78 kB
"use strict"; 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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Sphere = void 0; const g_plugin_3d_1 = require("@antv/g-plugin-3d"); const utils_1 = require("../utils"); const selection_1 = require("../../utils/selection"); const GEOMETRY_SIZE = 5; /** * @see https://g.antv.antgroup.com/api/3d/geometry#spheregeometry */ const Sphere = (options, context) => { // Render border only when colorAttribute is stroke. const style = __rest(options, []); // @ts-ignore if (!context.sphereGeometry) { const renderer = context.canvas.getConfig().renderer; const plugin = renderer.getPlugin('device-renderer'); const device = plugin.getDevice(); // create a sphere geometry // @ts-ignore context.sphereGeometry = new g_plugin_3d_1.SphereGeometry(device, { radius: GEOMETRY_SIZE, latitudeBands: 32, longitudeBands: 32, }); // create a material with Phong lighting model // @ts-ignore context.sphereMaterial = new g_plugin_3d_1.MeshLambertMaterial(device); } return (points, value, defaults) => { const { color: defaultColor } = defaults; const { color = defaultColor, transform, opacity } = value; const [cx, cy, cz] = (0, utils_1.getOrigin)(points); const r = value.size; const finalRadius = r || style.r || defaults.r; const sphere = new g_plugin_3d_1.Mesh({ style: { x: cx, y: cy, z: cz, // @ts-ignore geometry: context.sphereGeometry, // @ts-ignore material: context.sphereMaterial, }, }); sphere.setOrigin(0, 0, 0); const scaling = finalRadius / GEOMETRY_SIZE; sphere.scale(scaling); return (0, selection_1.select)(sphere) .call(utils_1.applyStyle, defaults) .style('fill', color) .style('transform', transform) .style((0, utils_1.toOpacityKey)(options), opacity) .call(utils_1.applyStyle, style) .node(); }; }; exports.Sphere = Sphere; exports.Sphere.props = { defaultMarker: 'sphere', }; //# sourceMappingURL=sphere.js.map