@antv/g2 5.1.7 → 5.1.8-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/g2.full.min.js +1 -1
- package/dist/g2.lite.min.js +1 -1
- package/dist/g2.min.js +1 -1
- package/esm/component/axis.js +1 -5
- package/esm/component/axis.js.map +1 -1
- package/esm/component/index.d.ts +0 -1
- package/esm/component/index.js +0 -1
- package/esm/component/index.js.map +1 -1
- package/esm/component/legendContinuous.js +1 -1
- package/esm/component/legendContinuous.js.map +1 -1
- package/esm/coordinate/index.d.ts +0 -2
- package/esm/coordinate/index.js +0 -1
- package/esm/coordinate/index.js.map +1 -1
- package/esm/exports.d.ts +5 -1
- package/esm/exports.js +3 -0
- package/esm/exports.js.map +1 -1
- package/esm/index.d.ts +114 -114
- package/esm/index.js +2 -2
- package/esm/index.js.map +1 -1
- package/esm/lib/builtinlib.d.ts +7 -7
- package/esm/lib/core.d.ts +32 -32
- package/esm/lib/index.d.ts +0 -1
- package/esm/lib/index.js +0 -1
- package/esm/lib/index.js.map +1 -1
- package/esm/lib/lite.d.ts +18 -18
- package/esm/lib/std.d.ts +56 -56
- package/esm/mark/index.d.ts +0 -3
- package/esm/mark/index.js +0 -3
- package/esm/mark/index.js.map +1 -1
- package/esm/mark/liquid.js +2 -1
- package/esm/mark/liquid.js.map +1 -1
- package/esm/runtime/component.js +1 -3
- package/esm/runtime/component.js.map +1 -1
- package/esm/runtime/types/component.d.ts +1 -6
- package/esm/shape/index.d.ts +0 -4
- package/esm/shape/index.js +0 -4
- package/esm/shape/index.js.map +1 -1
- package/esm/spec/coordinate.d.ts +1 -4
- package/esm/spec/mark.d.ts +1 -3
- package/esm/transform/filter.js +3 -1
- package/esm/transform/filter.js.map +1 -1
- package/esm/transform/maybeTitle.js +6 -1
- package/esm/transform/maybeTitle.js.map +1 -1
- package/esm/utils/dateFormat.d.ts +1 -0
- package/esm/utils/dateFormat.js +18 -0
- package/esm/utils/dateFormat.js.map +1 -0
- package/esm/utils/number.d.ts +4 -0
- package/esm/utils/number.js +8 -0
- package/esm/utils/number.js.map +1 -1
- package/lib/component/axis.js +3 -7
- package/lib/component/axis.js.map +1 -1
- package/lib/component/index.d.ts +0 -1
- package/lib/component/index.js +1 -3
- package/lib/component/index.js.map +1 -1
- package/lib/component/legendContinuous.js +1 -1
- package/lib/component/legendContinuous.js.map +1 -1
- package/lib/coordinate/index.d.ts +0 -2
- package/lib/coordinate/index.js +1 -3
- package/lib/coordinate/index.js.map +1 -1
- package/lib/exports.d.ts +5 -1
- package/lib/exports.js +7 -1
- package/lib/exports.js.map +1 -1
- package/lib/index.d.ts +114 -114
- package/lib/index.js +1 -2
- package/lib/index.js.map +1 -1
- package/lib/lib/builtinlib.d.ts +7 -7
- package/lib/lib/core.d.ts +32 -32
- package/lib/lib/index.d.ts +0 -1
- package/lib/lib/index.js +1 -3
- package/lib/lib/index.js.map +1 -1
- package/lib/lib/lite.d.ts +18 -18
- package/lib/lib/std.d.ts +56 -56
- package/lib/mark/index.d.ts +0 -3
- package/lib/mark/index.js +1 -7
- package/lib/mark/index.js.map +1 -1
- package/lib/mark/liquid.js +2 -1
- package/lib/mark/liquid.js.map +1 -1
- package/lib/runtime/component.js +2 -4
- package/lib/runtime/component.js.map +1 -1
- package/lib/runtime/types/component.d.ts +1 -6
- package/lib/shape/index.d.ts +0 -4
- package/lib/shape/index.js +6 -14
- package/lib/shape/index.js.map +1 -1
- package/lib/spec/coordinate.d.ts +1 -4
- package/lib/spec/mark.d.ts +1 -3
- package/lib/transform/filter.js +3 -1
- package/lib/transform/filter.js.map +1 -1
- package/lib/transform/maybeTitle.js +6 -1
- package/lib/transform/maybeTitle.js.map +1 -1
- package/lib/utils/dateFormat.d.ts +1 -0
- package/lib/utils/dateFormat.js +22 -0
- package/lib/utils/dateFormat.js.map +1 -0
- package/lib/utils/number.d.ts +4 -0
- package/lib/utils/number.js +10 -1
- package/lib/utils/number.js.map +1 -1
- package/package.json +9 -16
- package/src/component/axis.ts +1 -5
- package/src/component/index.ts +0 -1
- package/src/component/legendContinuous.ts +1 -1
- package/src/coordinate/index.ts +0 -2
- package/src/exports.ts +16 -2
- package/src/index.ts +2 -2
- package/src/lib/index.ts +0 -1
- package/src/mark/index.ts +0 -3
- package/src/mark/liquid.ts +2 -1
- package/src/runtime/component.ts +1 -4
- package/src/runtime/types/component.ts +2 -9
- package/src/shape/index.ts +0 -4
- package/src/spec/coordinate.ts +0 -5
- package/src/spec/mark.ts +0 -3
- package/src/transform/filter.ts +3 -1
- package/src/transform/maybeTitle.ts +8 -1
- package/src/utils/dateFormat.ts +22 -0
- package/src/utils/number.ts +8 -0
- package/CHANGELOG.md +0 -429
- package/esm/component/axisZ.d.ts +0 -8
- package/esm/component/axisZ.js +0 -14
- package/esm/component/axisZ.js.map +0 -1
- package/esm/coordinate/cartesian3D.d.ts +0 -7
- package/esm/coordinate/cartesian3D.js +0 -6
- package/esm/coordinate/cartesian3D.js.map +0 -1
- package/esm/lib/threed.d.ts +0 -7
- package/esm/lib/threed.js +0 -13
- package/esm/lib/threed.js.map +0 -1
- package/esm/mark/interval3D.d.ts +0 -8
- package/esm/mark/interval3D.js +0 -65
- package/esm/mark/interval3D.js.map +0 -1
- package/esm/mark/line3D.d.ts +0 -7
- package/esm/mark/line3D.js +0 -65
- package/esm/mark/line3D.js.map +0 -1
- package/esm/mark/point3D.d.ts +0 -9
- package/esm/mark/point3D.js +0 -76
- package/esm/mark/point3D.js.map +0 -1
- package/esm/shape/interval3D/cube.d.ts +0 -6
- package/esm/shape/interval3D/cube.js +0 -71
- package/esm/shape/interval3D/cube.js.map +0 -1
- package/esm/shape/line3D/line.d.ts +0 -3
- package/esm/shape/line3D/line.js +0 -30
- package/esm/shape/line3D/line.js.map +0 -1
- package/esm/shape/point3D/cube.d.ts +0 -6
- package/esm/shape/point3D/cube.js +0 -70
- package/esm/shape/point3D/cube.js.map +0 -1
- package/esm/shape/point3D/sphere.d.ts +0 -6
- package/esm/shape/point3D/sphere.js +0 -70
- package/esm/shape/point3D/sphere.js.map +0 -1
- package/lib/component/axisZ.d.ts +0 -8
- package/lib/component/axisZ.js +0 -19
- package/lib/component/axisZ.js.map +0 -1
- package/lib/coordinate/cartesian3D.d.ts +0 -7
- package/lib/coordinate/cartesian3D.js +0 -10
- package/lib/coordinate/cartesian3D.js.map +0 -1
- package/lib/lib/threed.d.ts +0 -7
- package/lib/lib/threed.js +0 -17
- package/lib/lib/threed.js.map +0 -1
- package/lib/mark/interval3D.d.ts +0 -8
- package/lib/mark/interval3D.js +0 -69
- package/lib/mark/interval3D.js.map +0 -1
- package/lib/mark/line3D.d.ts +0 -7
- package/lib/mark/line3D.js +0 -69
- package/lib/mark/line3D.js.map +0 -1
- package/lib/mark/point3D.d.ts +0 -9
- package/lib/mark/point3D.js +0 -80
- package/lib/mark/point3D.js.map +0 -1
- package/lib/shape/interval3D/cube.d.ts +0 -6
- package/lib/shape/interval3D/cube.js +0 -75
- package/lib/shape/interval3D/cube.js.map +0 -1
- package/lib/shape/line3D/line.d.ts +0 -3
- package/lib/shape/line3D/line.js +0 -34
- package/lib/shape/line3D/line.js.map +0 -1
- package/lib/shape/point3D/cube.d.ts +0 -6
- package/lib/shape/point3D/cube.js +0 -74
- package/lib/shape/point3D/cube.js.map +0 -1
- package/lib/shape/point3D/sphere.d.ts +0 -6
- package/lib/shape/point3D/sphere.js +0 -74
- package/lib/shape/point3D/sphere.js.map +0 -1
- package/src/component/axisZ.ts +0 -25
- package/src/coordinate/cartesian3D.ts +0 -11
- package/src/lib/threed.ts +0 -13
- package/src/mark/interval3D.ts +0 -100
- package/src/mark/line3D.ts +0 -81
- package/src/mark/point3D.ts +0 -90
- package/src/shape/interval3D/cube.ts +0 -69
- package/src/shape/line3D/line.ts +0 -29
- package/src/shape/point3D/cube.ts +0 -68
- package/src/shape/point3D/sphere.ts +0 -68
package/src/mark/line3D.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { group } from 'd3-array';
|
|
2
|
-
import { Mark, MarkComponent as MC, SingleMark, Vector3 } from '../runtime';
|
|
3
|
-
import { LineMark } from '../spec';
|
|
4
|
-
import { Line3DShape } from '../shape';
|
|
5
|
-
import { MaybeSeries } from '../transform';
|
|
6
|
-
import {
|
|
7
|
-
baseGeometryChannels,
|
|
8
|
-
basePostInference,
|
|
9
|
-
basePreInference,
|
|
10
|
-
tooltip3d,
|
|
11
|
-
} from './utils';
|
|
12
|
-
|
|
13
|
-
const shape = {
|
|
14
|
-
line: Line3DShape,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type LineOptions = Omit<LineMark, 'type'>;
|
|
18
|
-
|
|
19
|
-
const line: Mark = (index, scale, value, coordinate) => {
|
|
20
|
-
const { series: S, x: X, y: Y, z: Z } = value;
|
|
21
|
-
const { x, y, z } = scale;
|
|
22
|
-
|
|
23
|
-
// Because x and y channel is not strictly required in Line.props,
|
|
24
|
-
// it should throw error with empty x, y or z channels.
|
|
25
|
-
if (X === undefined || Y === undefined || Z === undefined) {
|
|
26
|
-
throw new Error('Missing encode for x, y or z channel.');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Group data into series.
|
|
30
|
-
// There is only one series without specified series encode.
|
|
31
|
-
const series = S ? Array.from(group(index, (i) => S[i]).values()) : [index];
|
|
32
|
-
const I = series.map((group) => group[0]).filter((i) => i !== undefined);
|
|
33
|
-
|
|
34
|
-
// A group of data corresponds to one line.
|
|
35
|
-
const xoffset = (x?.getBandWidth?.() || 0) / 2;
|
|
36
|
-
const yoffset = (y?.getBandWidth?.() || 0) / 2;
|
|
37
|
-
const zoffset = (z?.getBandWidth?.() || 0) / 2;
|
|
38
|
-
const P = Array.from(series, (I) => {
|
|
39
|
-
return I.map((i) =>
|
|
40
|
-
coordinate.map([
|
|
41
|
-
(+X[i] || 0) + xoffset,
|
|
42
|
-
(+Y[i] || 0) + yoffset,
|
|
43
|
-
(+Z[i] || 0) + zoffset,
|
|
44
|
-
]),
|
|
45
|
-
) as Vector3[];
|
|
46
|
-
});
|
|
47
|
-
return [I, P, series];
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Convert value for each channel to line shapes.
|
|
52
|
-
*/
|
|
53
|
-
export const Line3D: MC<LineOptions> = () => {
|
|
54
|
-
return (index, scale, value, coordinate) => {
|
|
55
|
-
const mark = line;
|
|
56
|
-
return (mark as SingleMark)(index, scale, value, coordinate);
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
Line3D.props = {
|
|
61
|
-
defaultShape: 'line',
|
|
62
|
-
defaultLabelShape: 'label',
|
|
63
|
-
composite: false,
|
|
64
|
-
shape,
|
|
65
|
-
channels: [
|
|
66
|
-
...baseGeometryChannels({ shapes: Object.keys(shape) }),
|
|
67
|
-
{ name: 'x' },
|
|
68
|
-
{ name: 'y' },
|
|
69
|
-
{ name: 'z' },
|
|
70
|
-
{ name: 'position', independent: true },
|
|
71
|
-
{ name: 'size' },
|
|
72
|
-
{ name: 'series', scale: 'identity' },
|
|
73
|
-
],
|
|
74
|
-
preInference: [...basePreInference(), { type: MaybeSeries }],
|
|
75
|
-
postInference: [...basePostInference(), ...tooltip3d()],
|
|
76
|
-
interaction: {
|
|
77
|
-
shareTooltip: false,
|
|
78
|
-
seriesTooltip: false,
|
|
79
|
-
crosshairs: false,
|
|
80
|
-
},
|
|
81
|
-
};
|
package/src/mark/point3D.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { Coordinate3D } from '@antv/coord';
|
|
2
|
-
import { MarkComponent as MC, Vector3 } from '../runtime';
|
|
3
|
-
import { PointMark } from '../spec';
|
|
4
|
-
import { MaybeZeroX, MaybeZeroY, MaybeZeroZ, MaybeSize } from '../transform';
|
|
5
|
-
import { Sphere, Cube } from '../shape';
|
|
6
|
-
import {
|
|
7
|
-
baseGeometryChannels,
|
|
8
|
-
basePostInference,
|
|
9
|
-
basePreInference,
|
|
10
|
-
tooltip3d,
|
|
11
|
-
} from './utils';
|
|
12
|
-
|
|
13
|
-
export type PointOptions = Omit<PointMark, 'type'>;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Convert value for each channel to point shapes.
|
|
17
|
-
* Calc the bbox of each point based on x, y and r.
|
|
18
|
-
* This is for allowing their radius can be affected by coordinate(e.g. fisheye).
|
|
19
|
-
*/
|
|
20
|
-
export const Point3D: MC<PointOptions> = (options) => {
|
|
21
|
-
return (index, _, value, coordinate) => {
|
|
22
|
-
const { x: X, y: Y, z: Z, size: S, dx: DX, dy: DY, dz: DZ } = value;
|
|
23
|
-
const [width, height, depth] = (
|
|
24
|
-
coordinate as unknown as Coordinate3D
|
|
25
|
-
).getSize();
|
|
26
|
-
const xyz: (i: number) => Vector3 = (i) => {
|
|
27
|
-
const dx = +(DX?.[i] || 0);
|
|
28
|
-
const dy = +(DY?.[i] || 0);
|
|
29
|
-
const dz = +(DZ?.[i] || 0);
|
|
30
|
-
const x = +X[i];
|
|
31
|
-
const y = +Y[i];
|
|
32
|
-
const z = +Z[i];
|
|
33
|
-
const cx = x + dx;
|
|
34
|
-
const cy = y + dy;
|
|
35
|
-
const cz = z + dz;
|
|
36
|
-
return [cx, cy, cz];
|
|
37
|
-
};
|
|
38
|
-
const P = S
|
|
39
|
-
? Array.from(index, (i) => {
|
|
40
|
-
const [cx, cy, cz] = xyz(i);
|
|
41
|
-
const r = +S[i];
|
|
42
|
-
const a = r / width;
|
|
43
|
-
const b = r / height;
|
|
44
|
-
const c = r / depth;
|
|
45
|
-
const p1: Vector3 = [cx - a, cy - b, cz - c];
|
|
46
|
-
const p2: Vector3 = [cx + a, cy + b, cz + c];
|
|
47
|
-
return [
|
|
48
|
-
(coordinate as unknown as Coordinate3D).map([...p1, cz]),
|
|
49
|
-
(coordinate as unknown as Coordinate3D).map([...p2, cz]),
|
|
50
|
-
] as Vector3[];
|
|
51
|
-
})
|
|
52
|
-
: Array.from(index, (i) => {
|
|
53
|
-
const [cx, cy, cz] = xyz(i);
|
|
54
|
-
return [
|
|
55
|
-
(coordinate as unknown as Coordinate3D).map([cx, cy, cz]),
|
|
56
|
-
] as Vector3[];
|
|
57
|
-
});
|
|
58
|
-
return [index, P];
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const shape = {
|
|
63
|
-
sphere: Sphere,
|
|
64
|
-
cube: Cube,
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
Point3D.props = {
|
|
68
|
-
defaultShape: 'cube',
|
|
69
|
-
defaultLabelShape: 'label',
|
|
70
|
-
composite: false,
|
|
71
|
-
shape,
|
|
72
|
-
channels: [
|
|
73
|
-
...baseGeometryChannels({ shapes: Object.keys(shape) }),
|
|
74
|
-
{ name: 'x', required: true },
|
|
75
|
-
{ name: 'y', required: true },
|
|
76
|
-
{ name: 'z', required: true },
|
|
77
|
-
{ name: 'series', scale: 'band' },
|
|
78
|
-
{ name: 'size', quantitative: 'sqrt' },
|
|
79
|
-
{ name: 'dx', scale: 'identity' },
|
|
80
|
-
{ name: 'dy', scale: 'identity' },
|
|
81
|
-
{ name: 'dz', scale: 'identity' },
|
|
82
|
-
],
|
|
83
|
-
preInference: [
|
|
84
|
-
...basePreInference(),
|
|
85
|
-
{ type: MaybeZeroX },
|
|
86
|
-
{ type: MaybeZeroY },
|
|
87
|
-
{ type: MaybeZeroZ },
|
|
88
|
-
],
|
|
89
|
-
postInference: [...basePostInference(), { type: MaybeSize }, ...tooltip3d()],
|
|
90
|
-
};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { MeshLambertMaterial, CubeGeometry, Mesh } from '@antv/g-plugin-3d';
|
|
2
|
-
import { applyStyle, getOrigin, toOpacityKey } from '../utils';
|
|
3
|
-
import { ShapeComponent as SC, Vector3 } from '../../runtime';
|
|
4
|
-
import { select } from '../../utils/selection';
|
|
5
|
-
|
|
6
|
-
export type CubeOptions = Record<string, any>;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @see https://g.antv.antgroup.com/api/3d/geometry#cubegeometry
|
|
10
|
-
*/
|
|
11
|
-
export const Cube: SC<CubeOptions> = (options, context) => {
|
|
12
|
-
// Render border only when colorAttribute is stroke.
|
|
13
|
-
const { ...style } = options;
|
|
14
|
-
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
if (!context.cubeGeometry) {
|
|
17
|
-
const renderer = context.canvas.getConfig().renderer;
|
|
18
|
-
const plugin = renderer.getPlugin('device-renderer');
|
|
19
|
-
const device = plugin.getDevice();
|
|
20
|
-
// create a cube geometry
|
|
21
|
-
// @ts-ignore
|
|
22
|
-
context.cubeGeometry = new CubeGeometry(device, {
|
|
23
|
-
width: 1,
|
|
24
|
-
height: 1,
|
|
25
|
-
depth: 1,
|
|
26
|
-
});
|
|
27
|
-
// create a material with Lambert lighting model
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
context.cubeMaterial = new MeshLambertMaterial(device);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return (_points, value, defaults) => {
|
|
33
|
-
const points = _points as unknown as Vector3[];
|
|
34
|
-
const { color: defaultColor } = defaults;
|
|
35
|
-
const { color = defaultColor, transform, opacity } = value;
|
|
36
|
-
const [cx, cy, cz] = getOrigin(points);
|
|
37
|
-
|
|
38
|
-
const width = Math.abs(points[1][0] - points[0][0]);
|
|
39
|
-
const height = Math.abs(points[1][1] - points[0][1]);
|
|
40
|
-
const depth = Math.abs(points[1][2] - points[0][2]);
|
|
41
|
-
|
|
42
|
-
const cube = new Mesh({
|
|
43
|
-
style: {
|
|
44
|
-
x: cx,
|
|
45
|
-
y: cy,
|
|
46
|
-
z: cz,
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
geometry: context.cubeGeometry,
|
|
49
|
-
// @ts-ignore
|
|
50
|
-
material: context.cubeMaterial,
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
cube.setOrigin(0, 0, 0);
|
|
54
|
-
cube.scale([width, height, depth]);
|
|
55
|
-
|
|
56
|
-
const selection = select(cube)
|
|
57
|
-
.call(applyStyle, defaults)
|
|
58
|
-
.style('fill', color)
|
|
59
|
-
.style('transform', transform)
|
|
60
|
-
.style(toOpacityKey(options), opacity)
|
|
61
|
-
.call(applyStyle, style)
|
|
62
|
-
.node();
|
|
63
|
-
return selection;
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
Cube.props = {
|
|
68
|
-
defaultMarker: 'cube',
|
|
69
|
-
};
|
package/src/shape/line3D/line.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Polyline } from '@antv/g';
|
|
2
|
-
import { applyStyle } from '../utils';
|
|
3
|
-
import { ShapeComponent as SC } from '../../runtime';
|
|
4
|
-
import { select } from '../../utils/selection';
|
|
5
|
-
|
|
6
|
-
export type LineOptions = Record<string, any>;
|
|
7
|
-
|
|
8
|
-
export const Line: SC<LineOptions> = (options, context) => {
|
|
9
|
-
return (P, value, defaults) => {
|
|
10
|
-
const { color: defaultColor, lineWidth: defaultSize, ...rest } = defaults;
|
|
11
|
-
const { color = defaultColor, size = defaultSize } = value;
|
|
12
|
-
const stroke = color;
|
|
13
|
-
const finalStyle = {
|
|
14
|
-
isBillboard: true,
|
|
15
|
-
...rest,
|
|
16
|
-
...(stroke && { stroke }),
|
|
17
|
-
...(size && { lineWidth: size }),
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
return select(new Polyline())
|
|
21
|
-
.style('points', P)
|
|
22
|
-
.call(applyStyle, finalStyle)
|
|
23
|
-
.node();
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
Line.props = {
|
|
28
|
-
defaultMarker: 'line',
|
|
29
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { MeshLambertMaterial, CubeGeometry, Mesh } from '@antv/g-plugin-3d';
|
|
2
|
-
import { applyStyle, getOrigin, toOpacityKey } from '../utils';
|
|
3
|
-
import { ShapeComponent as SC } from '../../runtime';
|
|
4
|
-
import { select } from '../../utils/selection';
|
|
5
|
-
|
|
6
|
-
const GEOMETRY_SIZE = 5;
|
|
7
|
-
|
|
8
|
-
export type CubeOptions = Record<string, any>;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @see https://g.antv.antgroup.com/api/3d/geometry#cubegeometry
|
|
12
|
-
*/
|
|
13
|
-
export const Cube: SC<CubeOptions> = (options, context) => {
|
|
14
|
-
// Render border only when colorAttribute is stroke.
|
|
15
|
-
const { ...style } = options;
|
|
16
|
-
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
if (!context.cubeGeometry) {
|
|
19
|
-
const renderer = context.canvas.getConfig().renderer;
|
|
20
|
-
const plugin = renderer.getPlugin('device-renderer');
|
|
21
|
-
const device = plugin.getDevice();
|
|
22
|
-
// create a sphere geometry
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
context.cubeGeometry = new CubeGeometry(device, {
|
|
25
|
-
width: GEOMETRY_SIZE * 2,
|
|
26
|
-
height: GEOMETRY_SIZE * 2,
|
|
27
|
-
depth: GEOMETRY_SIZE * 2,
|
|
28
|
-
});
|
|
29
|
-
// create a material with Phong lighting model
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
context.cubeMaterial = new MeshLambertMaterial(device);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return (points, value, defaults) => {
|
|
35
|
-
const { color: defaultColor } = defaults;
|
|
36
|
-
const { color = defaultColor, transform, opacity } = value;
|
|
37
|
-
const [cx, cy, cz] = getOrigin(points);
|
|
38
|
-
const r = value.size;
|
|
39
|
-
const finalRadius = r || style.r || defaults.r;
|
|
40
|
-
|
|
41
|
-
const cube = new Mesh({
|
|
42
|
-
style: {
|
|
43
|
-
x: cx,
|
|
44
|
-
y: cy,
|
|
45
|
-
z: cz,
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
geometry: context.cubeGeometry,
|
|
48
|
-
// @ts-ignore
|
|
49
|
-
material: context.cubeMaterial,
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
cube.setOrigin(0, 0, 0);
|
|
53
|
-
const scaling = finalRadius / GEOMETRY_SIZE;
|
|
54
|
-
cube.scale(scaling);
|
|
55
|
-
|
|
56
|
-
return select(cube)
|
|
57
|
-
.call(applyStyle, defaults)
|
|
58
|
-
.style('fill', color)
|
|
59
|
-
.style('transform', transform)
|
|
60
|
-
.style(toOpacityKey(options), opacity)
|
|
61
|
-
.call(applyStyle, style)
|
|
62
|
-
.node();
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
Cube.props = {
|
|
67
|
-
defaultMarker: 'cube',
|
|
68
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { MeshLambertMaterial, SphereGeometry, Mesh } from '@antv/g-plugin-3d';
|
|
2
|
-
import { applyStyle, getOrigin, toOpacityKey } from '../utils';
|
|
3
|
-
import { ShapeComponent as SC } from '../../runtime';
|
|
4
|
-
import { select } from '../../utils/selection';
|
|
5
|
-
|
|
6
|
-
export type SphereOptions = Record<string, any>;
|
|
7
|
-
|
|
8
|
-
const GEOMETRY_SIZE = 5;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @see https://g.antv.antgroup.com/api/3d/geometry#spheregeometry
|
|
12
|
-
*/
|
|
13
|
-
export const Sphere: SC<SphereOptions> = (options, context) => {
|
|
14
|
-
// Render border only when colorAttribute is stroke.
|
|
15
|
-
const { ...style } = options;
|
|
16
|
-
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
if (!context.sphereGeometry) {
|
|
19
|
-
const renderer = context.canvas.getConfig().renderer;
|
|
20
|
-
const plugin = renderer.getPlugin('device-renderer');
|
|
21
|
-
const device = plugin.getDevice();
|
|
22
|
-
// create a sphere geometry
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
context.sphereGeometry = new SphereGeometry(device, {
|
|
25
|
-
radius: GEOMETRY_SIZE,
|
|
26
|
-
latitudeBands: 32,
|
|
27
|
-
longitudeBands: 32,
|
|
28
|
-
});
|
|
29
|
-
// create a material with Phong lighting model
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
context.sphereMaterial = new MeshLambertMaterial(device);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return (points, value, defaults) => {
|
|
35
|
-
const { color: defaultColor } = defaults;
|
|
36
|
-
const { color = defaultColor, transform, opacity } = value;
|
|
37
|
-
const [cx, cy, cz] = getOrigin(points);
|
|
38
|
-
const r = value.size;
|
|
39
|
-
const finalRadius = r || style.r || defaults.r;
|
|
40
|
-
|
|
41
|
-
const sphere = new Mesh({
|
|
42
|
-
style: {
|
|
43
|
-
x: cx,
|
|
44
|
-
y: cy,
|
|
45
|
-
z: cz,
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
geometry: context.sphereGeometry,
|
|
48
|
-
// @ts-ignore
|
|
49
|
-
material: context.sphereMaterial,
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
sphere.setOrigin(0, 0, 0);
|
|
53
|
-
const scaling = finalRadius / GEOMETRY_SIZE;
|
|
54
|
-
sphere.scale(scaling);
|
|
55
|
-
|
|
56
|
-
return select(sphere)
|
|
57
|
-
.call(applyStyle, defaults)
|
|
58
|
-
.style('fill', color)
|
|
59
|
-
.style('transform', transform)
|
|
60
|
-
.style(toOpacityKey(options), opacity)
|
|
61
|
-
.call(applyStyle, style)
|
|
62
|
-
.node();
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
Sphere.props = {
|
|
67
|
-
defaultMarker: 'sphere',
|
|
68
|
-
};
|