@antv/g2 5.0.23 → 5.0.24
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/CHANGELOG.md +17 -0
- package/dist/g2-lite.min.js +3 -3
- package/dist/g2.min.js +3 -3
- package/esm/api/chart.d.ts +5 -16
- package/esm/api/extend.d.ts +5 -1
- package/esm/api/extend.js.map +1 -1
- package/esm/api/library.d.ts +5 -16
- package/esm/api/runtime.js +4 -1
- package/esm/api/runtime.js.map +1 -1
- package/esm/lib/builtinlib.d.ts +13 -0
- package/esm/lib/builtinlib.js +21 -0
- package/esm/lib/builtinlib.js.map +1 -0
- package/esm/lib/core.d.ts +1 -12
- package/esm/lib/core.js +4 -16
- package/esm/lib/core.js.map +1 -1
- package/esm/lib/graph.d.ts +5 -0
- package/esm/lib/graph.js +7 -1
- package/esm/lib/graph.js.map +1 -1
- package/esm/lib/plot.d.ts +0 -5
- package/esm/lib/plot.js +2 -7
- package/esm/lib/plot.js.map +1 -1
- package/esm/lib/std.d.ts +5 -16
- package/esm/lib/threed.d.ts +1 -0
- package/esm/lib/threed.js +2 -1
- package/esm/lib/threed.js.map +1 -1
- package/esm/mark/index.d.ts +1 -0
- package/esm/mark/index.js +1 -0
- package/esm/mark/index.js.map +1 -1
- package/esm/mark/line3D.d.ts +7 -0
- package/esm/mark/line3D.js +65 -0
- package/esm/mark/line3D.js.map +1 -0
- package/esm/runtime/layout.js +1 -0
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/library.d.ts +1 -1
- package/esm/runtime/library.js +3 -1
- package/esm/runtime/library.js.map +1 -1
- package/esm/runtime/render.js +1 -1
- package/esm/runtime/render.js.map +1 -1
- package/esm/shape/index.d.ts +1 -0
- package/esm/shape/index.js +1 -0
- package/esm/shape/index.js.map +1 -1
- package/esm/shape/line3D/line.d.ts +3 -0
- package/esm/shape/line3D/line.js +30 -0
- package/esm/shape/line3D/line.js.map +1 -0
- package/esm/shape/point3D/cube.js +2 -2
- package/esm/shape/point3D/cube.js.map +1 -1
- package/esm/shape/point3D/sphere.js +2 -2
- package/esm/shape/point3D/sphere.js.map +1 -1
- package/esm/theme/classic.js +2 -0
- package/esm/theme/classic.js.map +1 -1
- package/esm/theme/light.js +1 -1
- package/lib/api/chart.d.ts +5 -16
- package/lib/api/extend.d.ts +5 -1
- package/lib/api/extend.js.map +1 -1
- package/lib/api/library.d.ts +5 -16
- package/lib/api/runtime.js +4 -1
- package/lib/api/runtime.js.map +1 -1
- package/lib/lib/builtinlib.d.ts +13 -0
- package/lib/lib/builtinlib.js +25 -0
- package/lib/lib/builtinlib.js.map +1 -0
- package/lib/lib/core.d.ts +1 -12
- package/lib/lib/core.js +0 -12
- package/lib/lib/core.js.map +1 -1
- package/lib/lib/graph.d.ts +5 -0
- package/lib/lib/graph.js +6 -0
- package/lib/lib/graph.js.map +1 -1
- package/lib/lib/plot.d.ts +0 -5
- package/lib/lib/plot.js +0 -5
- package/lib/lib/plot.js.map +1 -1
- package/lib/lib/std.d.ts +5 -16
- package/lib/lib/threed.d.ts +1 -0
- package/lib/lib/threed.js +1 -0
- package/lib/lib/threed.js.map +1 -1
- package/lib/mark/index.d.ts +1 -0
- package/lib/mark/index.js +3 -1
- package/lib/mark/index.js.map +1 -1
- package/lib/mark/line3D.d.ts +7 -0
- package/lib/mark/line3D.js +69 -0
- package/lib/mark/line3D.js.map +1 -0
- package/lib/runtime/layout.js +1 -0
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/library.d.ts +1 -1
- package/lib/runtime/library.js +3 -1
- package/lib/runtime/library.js.map +1 -1
- package/lib/runtime/render.js +1 -1
- package/lib/runtime/render.js.map +1 -1
- package/lib/shape/index.d.ts +1 -0
- package/lib/shape/index.js +8 -6
- package/lib/shape/index.js.map +1 -1
- package/lib/shape/line3D/line.d.ts +3 -0
- package/lib/shape/line3D/line.js +34 -0
- package/lib/shape/line3D/line.js.map +1 -0
- package/lib/shape/point3D/cube.js +1 -1
- package/lib/shape/point3D/cube.js.map +1 -1
- package/lib/shape/point3D/sphere.js +1 -1
- package/lib/shape/point3D/sphere.js.map +1 -1
- package/lib/theme/classic.js +2 -0
- package/lib/theme/classic.js.map +1 -1
- package/lib/theme/light.js +1 -1
- package/package.json +2 -2
- package/src/api/extend.ts +6 -1
- package/src/api/runtime.ts +6 -3
- package/src/lib/builtinlib.ts +28 -0
- package/src/lib/core.ts +0 -22
- package/src/lib/graph.ts +7 -1
- package/src/lib/plot.ts +2 -7
- package/src/lib/threed.ts +2 -1
- package/src/mark/index.ts +1 -0
- package/src/mark/line3D.ts +81 -0
- package/src/runtime/layout.ts +1 -0
- package/src/runtime/library.ts +4 -1
- package/src/runtime/render.ts +1 -1
- package/src/shape/index.ts +1 -0
- package/src/shape/line3D/line.ts +29 -0
- package/src/shape/point3D/cube.ts +2 -2
- package/src/shape/point3D/sphere.ts +2 -2
- package/src/theme/classic.ts +2 -0
- package/src/theme/light.ts +1 -1
package/src/mark/index.ts
CHANGED
|
@@ -0,0 +1,81 @@
|
|
|
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/runtime/layout.ts
CHANGED
|
@@ -311,6 +311,7 @@ function computePadding(
|
|
|
311
311
|
|
|
312
312
|
for (const position of positions) {
|
|
313
313
|
const key = `padding${capitalizeFirst(camelCase(position))}`;
|
|
314
|
+
const insetKey = `inset${capitalizeFirst(camelCase(position))}`;
|
|
314
315
|
const components = positionComponents.get(position) || [];
|
|
315
316
|
const value = layout[key];
|
|
316
317
|
const defaultSizeOf = (d) => {
|
package/src/runtime/library.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IDocument } from '@antv/g';
|
|
2
2
|
import { error } from '../utils/helper';
|
|
3
|
+
import { builtinlib } from '../lib/builtinlib';
|
|
3
4
|
import { G2ComponentOptions, G2Context, G2Library } from './types/options';
|
|
4
5
|
import {
|
|
5
6
|
G2Component,
|
|
@@ -13,8 +14,10 @@ export function useLibrary<
|
|
|
13
14
|
V extends G2ComponentValue,
|
|
14
15
|
>(
|
|
15
16
|
namespace: G2ComponentNamespaces,
|
|
16
|
-
|
|
17
|
+
publicLibrary: G2Library,
|
|
17
18
|
): [(options: O, context?) => V, (type: O['type']) => C] {
|
|
19
|
+
const library = { ...builtinlib(), ...publicLibrary };
|
|
20
|
+
|
|
18
21
|
const create = (type: O['type']) => {
|
|
19
22
|
if (typeof type !== 'string') return type;
|
|
20
23
|
const key = `${namespace}.${type}`;
|
package/src/runtime/render.ts
CHANGED
|
@@ -70,7 +70,7 @@ export function render<T extends G2ViewTree = G2ViewTree>(
|
|
|
70
70
|
},
|
|
71
71
|
): HTMLElement {
|
|
72
72
|
// Initialize the context if it is not provided.
|
|
73
|
-
const { width = 640, height = 480, depth = 0
|
|
73
|
+
const { width = 640, height = 480, depth = 0 } = options;
|
|
74
74
|
const keyed = inferKeys(options);
|
|
75
75
|
const {
|
|
76
76
|
canvas = Canvas(width, height),
|
package/src/shape/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { HV as LineHV } from './line/hv';
|
|
|
10
10
|
export { VH as LineVH } from './line/vh';
|
|
11
11
|
export { HVH as LineHVH } from './line/hvh';
|
|
12
12
|
export { Trail as LineTrail } from './line/trail';
|
|
13
|
+
export { Line as Line3DShape } from './line3D/line';
|
|
13
14
|
export { HollowBowtie as PointHollowBowtie } from './point/hollowBowtie';
|
|
14
15
|
export { HollowDiamond as PointHollowDiamond } from './point/hollowDiamond';
|
|
15
16
|
export { HollowHexagon as PointHollowHexagon } from './point/hollowHexagon';
|
|
@@ -0,0 +1,29 @@
|
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MeshLambertMaterial, CubeGeometry, Mesh } from '@antv/g-plugin-3d';
|
|
2
2
|
import { applyStyle, getOrigin, toOpacityKey } from '../utils';
|
|
3
3
|
import { ShapeComponent as SC } from '../../runtime';
|
|
4
4
|
import { select } from '../../utils/selection';
|
|
@@ -28,7 +28,7 @@ export const Cube: SC<CubeOptions> = (options, context) => {
|
|
|
28
28
|
});
|
|
29
29
|
// create a material with Phong lighting model
|
|
30
30
|
// @ts-ignore
|
|
31
|
-
context.cubeMaterial = new
|
|
31
|
+
context.cubeMaterial = new MeshLambertMaterial(device);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
return (points, value, defaults) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MeshLambertMaterial, SphereGeometry, Mesh } from '@antv/g-plugin-3d';
|
|
2
2
|
import { applyStyle, getOrigin, toOpacityKey } from '../utils';
|
|
3
3
|
import { ShapeComponent as SC } from '../../runtime';
|
|
4
4
|
import { select } from '../../utils/selection';
|
|
@@ -28,7 +28,7 @@ export const Sphere: SC<SphereOptions> = (options, context) => {
|
|
|
28
28
|
});
|
|
29
29
|
// create a material with Phong lighting model
|
|
30
30
|
// @ts-ignore
|
|
31
|
-
context.sphereMaterial = new
|
|
31
|
+
context.sphereMaterial = new MeshLambertMaterial(device);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
return (points, value, defaults) => {
|
package/src/theme/classic.ts
CHANGED