@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.
Files changed (118) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/g2-lite.min.js +3 -3
  3. package/dist/g2.min.js +3 -3
  4. package/esm/api/chart.d.ts +5 -16
  5. package/esm/api/extend.d.ts +5 -1
  6. package/esm/api/extend.js.map +1 -1
  7. package/esm/api/library.d.ts +5 -16
  8. package/esm/api/runtime.js +4 -1
  9. package/esm/api/runtime.js.map +1 -1
  10. package/esm/lib/builtinlib.d.ts +13 -0
  11. package/esm/lib/builtinlib.js +21 -0
  12. package/esm/lib/builtinlib.js.map +1 -0
  13. package/esm/lib/core.d.ts +1 -12
  14. package/esm/lib/core.js +4 -16
  15. package/esm/lib/core.js.map +1 -1
  16. package/esm/lib/graph.d.ts +5 -0
  17. package/esm/lib/graph.js +7 -1
  18. package/esm/lib/graph.js.map +1 -1
  19. package/esm/lib/plot.d.ts +0 -5
  20. package/esm/lib/plot.js +2 -7
  21. package/esm/lib/plot.js.map +1 -1
  22. package/esm/lib/std.d.ts +5 -16
  23. package/esm/lib/threed.d.ts +1 -0
  24. package/esm/lib/threed.js +2 -1
  25. package/esm/lib/threed.js.map +1 -1
  26. package/esm/mark/index.d.ts +1 -0
  27. package/esm/mark/index.js +1 -0
  28. package/esm/mark/index.js.map +1 -1
  29. package/esm/mark/line3D.d.ts +7 -0
  30. package/esm/mark/line3D.js +65 -0
  31. package/esm/mark/line3D.js.map +1 -0
  32. package/esm/runtime/layout.js +1 -0
  33. package/esm/runtime/layout.js.map +1 -1
  34. package/esm/runtime/library.d.ts +1 -1
  35. package/esm/runtime/library.js +3 -1
  36. package/esm/runtime/library.js.map +1 -1
  37. package/esm/runtime/render.js +1 -1
  38. package/esm/runtime/render.js.map +1 -1
  39. package/esm/shape/index.d.ts +1 -0
  40. package/esm/shape/index.js +1 -0
  41. package/esm/shape/index.js.map +1 -1
  42. package/esm/shape/line3D/line.d.ts +3 -0
  43. package/esm/shape/line3D/line.js +30 -0
  44. package/esm/shape/line3D/line.js.map +1 -0
  45. package/esm/shape/point3D/cube.js +2 -2
  46. package/esm/shape/point3D/cube.js.map +1 -1
  47. package/esm/shape/point3D/sphere.js +2 -2
  48. package/esm/shape/point3D/sphere.js.map +1 -1
  49. package/esm/theme/classic.js +2 -0
  50. package/esm/theme/classic.js.map +1 -1
  51. package/esm/theme/light.js +1 -1
  52. package/lib/api/chart.d.ts +5 -16
  53. package/lib/api/extend.d.ts +5 -1
  54. package/lib/api/extend.js.map +1 -1
  55. package/lib/api/library.d.ts +5 -16
  56. package/lib/api/runtime.js +4 -1
  57. package/lib/api/runtime.js.map +1 -1
  58. package/lib/lib/builtinlib.d.ts +13 -0
  59. package/lib/lib/builtinlib.js +25 -0
  60. package/lib/lib/builtinlib.js.map +1 -0
  61. package/lib/lib/core.d.ts +1 -12
  62. package/lib/lib/core.js +0 -12
  63. package/lib/lib/core.js.map +1 -1
  64. package/lib/lib/graph.d.ts +5 -0
  65. package/lib/lib/graph.js +6 -0
  66. package/lib/lib/graph.js.map +1 -1
  67. package/lib/lib/plot.d.ts +0 -5
  68. package/lib/lib/plot.js +0 -5
  69. package/lib/lib/plot.js.map +1 -1
  70. package/lib/lib/std.d.ts +5 -16
  71. package/lib/lib/threed.d.ts +1 -0
  72. package/lib/lib/threed.js +1 -0
  73. package/lib/lib/threed.js.map +1 -1
  74. package/lib/mark/index.d.ts +1 -0
  75. package/lib/mark/index.js +3 -1
  76. package/lib/mark/index.js.map +1 -1
  77. package/lib/mark/line3D.d.ts +7 -0
  78. package/lib/mark/line3D.js +69 -0
  79. package/lib/mark/line3D.js.map +1 -0
  80. package/lib/runtime/layout.js +1 -0
  81. package/lib/runtime/layout.js.map +1 -1
  82. package/lib/runtime/library.d.ts +1 -1
  83. package/lib/runtime/library.js +3 -1
  84. package/lib/runtime/library.js.map +1 -1
  85. package/lib/runtime/render.js +1 -1
  86. package/lib/runtime/render.js.map +1 -1
  87. package/lib/shape/index.d.ts +1 -0
  88. package/lib/shape/index.js +8 -6
  89. package/lib/shape/index.js.map +1 -1
  90. package/lib/shape/line3D/line.d.ts +3 -0
  91. package/lib/shape/line3D/line.js +34 -0
  92. package/lib/shape/line3D/line.js.map +1 -0
  93. package/lib/shape/point3D/cube.js +1 -1
  94. package/lib/shape/point3D/cube.js.map +1 -1
  95. package/lib/shape/point3D/sphere.js +1 -1
  96. package/lib/shape/point3D/sphere.js.map +1 -1
  97. package/lib/theme/classic.js +2 -0
  98. package/lib/theme/classic.js.map +1 -1
  99. package/lib/theme/light.js +1 -1
  100. package/package.json +2 -2
  101. package/src/api/extend.ts +6 -1
  102. package/src/api/runtime.ts +6 -3
  103. package/src/lib/builtinlib.ts +28 -0
  104. package/src/lib/core.ts +0 -22
  105. package/src/lib/graph.ts +7 -1
  106. package/src/lib/plot.ts +2 -7
  107. package/src/lib/threed.ts +2 -1
  108. package/src/mark/index.ts +1 -0
  109. package/src/mark/line3D.ts +81 -0
  110. package/src/runtime/layout.ts +1 -0
  111. package/src/runtime/library.ts +4 -1
  112. package/src/runtime/render.ts +1 -1
  113. package/src/shape/index.ts +1 -0
  114. package/src/shape/line3D/line.ts +29 -0
  115. package/src/shape/point3D/cube.ts +2 -2
  116. package/src/shape/point3D/sphere.ts +2 -2
  117. package/src/theme/classic.ts +2 -0
  118. package/src/theme/light.ts +1 -1
package/src/mark/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { Interval } from './interval';
2
2
  export { Rect } from './rect';
3
3
  export { Line } from './line';
4
+ export { Line3D } from './line3D';
4
5
  export { Point } from './point';
5
6
  export { Point3D } from './point3D';
6
7
  export { Text } from './text';
@@ -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
+ };
@@ -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) => {
@@ -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
- library: G2Library,
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}`;
@@ -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, theme } = options;
73
+ const { width = 640, height = 480, depth = 0 } = options;
74
74
  const keyed = inferKeys(options);
75
75
  const {
76
76
  canvas = Canvas(width, height),
@@ -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 { MeshPhongMaterial, CubeGeometry, Mesh } from '@antv/g-plugin-3d';
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 MeshPhongMaterial(device);
31
+ context.cubeMaterial = new MeshLambertMaterial(device);
32
32
  }
33
33
 
34
34
  return (points, value, defaults) => {
@@ -1,4 +1,4 @@
1
- import { MeshPhongMaterial, SphereGeometry, Mesh } from '@antv/g-plugin-3d';
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 MeshPhongMaterial(device);
31
+ context.sphereMaterial = new MeshLambertMaterial(device);
32
32
  }
33
33
 
34
34
  return (points, value, defaults) => {
@@ -238,6 +238,8 @@ export const Classic: TC<ClassicOptions> = (options) => {
238
238
  titleFontWeight: 'normal',
239
239
  titleSpacing: 12,
240
240
  titleTransformOrigin: 'center',
241
+ lineArrowOffset: 6,
242
+ lineArrowSize: 6,
241
243
  },
242
244
  axisTop: {
243
245
  gridDirection: 'positive',
@@ -6,7 +6,7 @@ const COLORS = {
6
6
  BLACK: '#1D2129',
7
7
  WHITE: '#fff',
8
8
  STROKE: '#416180',
9
- DEFAULT: '#5B8FF9',
9
+ DEFAULT: '#1783FF',
10
10
  BACKGROUND: 'transparent',
11
11
  };
12
12