@antv/g2 5.2.1 → 5.2.3

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 (93) hide show
  1. package/README.md +1 -1
  2. package/README.zh-CN.md +1 -1
  3. package/dist/g2.lite.min.js +1 -1
  4. package/dist/g2.min.js +1 -1
  5. package/esm/api/library.d.ts +2 -1
  6. package/esm/api/library.js +5 -1
  7. package/esm/api/library.js.map +1 -1
  8. package/esm/composition/facetRect.js +4 -6
  9. package/esm/composition/facetRect.js.map +1 -1
  10. package/esm/composition/utils.d.ts +2 -0
  11. package/esm/composition/utils.js +10 -2
  12. package/esm/composition/utils.js.map +1 -1
  13. package/esm/index.d.ts +2 -0
  14. package/esm/index.js.map +1 -1
  15. package/esm/interaction/legendFilter.js +0 -2
  16. package/esm/interaction/legendFilter.js.map +1 -1
  17. package/esm/interaction/sliderFilter.js +0 -2
  18. package/esm/interaction/sliderFilter.js.map +1 -1
  19. package/esm/interaction/tooltip.js +1 -0
  20. package/esm/interaction/tooltip.js.map +1 -1
  21. package/esm/label-transform/exceedAdjust.js +5 -0
  22. package/esm/label-transform/exceedAdjust.js.map +1 -1
  23. package/esm/runtime/plot.js +15 -7
  24. package/esm/runtime/plot.js.map +1 -1
  25. package/esm/runtime/scale.d.ts +1 -0
  26. package/esm/runtime/scale.js +13 -2
  27. package/esm/runtime/scale.js.map +1 -1
  28. package/esm/shape/label/label.js +4 -4
  29. package/esm/shape/label/label.js.map +1 -1
  30. package/esm/shape/label/position/spider.d.ts +3 -2
  31. package/esm/shape/label/position/spider.js +22 -6
  32. package/esm/shape/label/position/spider.js.map +1 -1
  33. package/esm/shape/label/position/utils.d.ts +2 -0
  34. package/esm/shape/label/position/utils.js +68 -0
  35. package/esm/shape/label/position/utils.js.map +1 -0
  36. package/esm/shape/text/advance.js +65 -32
  37. package/esm/shape/text/advance.js.map +1 -1
  38. package/esm/spec/scale.d.ts +4 -1
  39. package/esm/transform/filter.js +25 -3
  40. package/esm/transform/filter.js.map +1 -1
  41. package/lib/api/library.d.ts +2 -1
  42. package/lib/api/library.js +5 -1
  43. package/lib/api/library.js.map +1 -1
  44. package/lib/composition/facetRect.js +4 -6
  45. package/lib/composition/facetRect.js.map +1 -1
  46. package/lib/composition/utils.d.ts +2 -0
  47. package/lib/composition/utils.js +12 -3
  48. package/lib/composition/utils.js.map +1 -1
  49. package/lib/index.d.ts +2 -0
  50. package/lib/index.js.map +1 -1
  51. package/lib/interaction/legendFilter.js +0 -2
  52. package/lib/interaction/legendFilter.js.map +1 -1
  53. package/lib/interaction/sliderFilter.js +0 -2
  54. package/lib/interaction/sliderFilter.js.map +1 -1
  55. package/lib/interaction/tooltip.js +1 -0
  56. package/lib/interaction/tooltip.js.map +1 -1
  57. package/lib/label-transform/exceedAdjust.js +5 -0
  58. package/lib/label-transform/exceedAdjust.js.map +1 -1
  59. package/lib/runtime/plot.js +14 -6
  60. package/lib/runtime/plot.js.map +1 -1
  61. package/lib/runtime/scale.d.ts +1 -0
  62. package/lib/runtime/scale.js +14 -2
  63. package/lib/runtime/scale.js.map +1 -1
  64. package/lib/shape/label/label.js +4 -4
  65. package/lib/shape/label/label.js.map +1 -1
  66. package/lib/shape/label/position/spider.d.ts +3 -2
  67. package/lib/shape/label/position/spider.js +22 -6
  68. package/lib/shape/label/position/spider.js.map +1 -1
  69. package/lib/shape/label/position/utils.d.ts +2 -0
  70. package/lib/shape/label/position/utils.js +73 -0
  71. package/lib/shape/label/position/utils.js.map +1 -0
  72. package/lib/shape/text/advance.js +65 -32
  73. package/lib/shape/text/advance.js.map +1 -1
  74. package/lib/spec/scale.d.ts +4 -1
  75. package/lib/transform/filter.js +25 -3
  76. package/lib/transform/filter.js.map +1 -1
  77. package/package.json +2 -4
  78. package/src/api/library.ts +6 -3
  79. package/src/composition/facetRect.ts +7 -4
  80. package/src/composition/utils.ts +10 -2
  81. package/src/index.ts +2 -1
  82. package/src/interaction/legendFilter.ts +0 -1
  83. package/src/interaction/sliderFilter.ts +0 -3
  84. package/src/interaction/tooltip.ts +1 -0
  85. package/src/label-transform/exceedAdjust.ts +5 -0
  86. package/src/runtime/plot.ts +18 -6
  87. package/src/runtime/scale.ts +28 -2
  88. package/src/shape/label/label.ts +4 -3
  89. package/src/shape/label/position/spider.ts +29 -10
  90. package/src/shape/label/position/utils.ts +77 -0
  91. package/src/shape/text/advance.ts +76 -38
  92. package/src/spec/scale.ts +8 -0
  93. package/src/transform/filter.ts +55 -5
@@ -16,12 +16,20 @@ export function useOverrideAdaptor<T>(adaptor: Adapter<T>): Adapter<T> {
16
16
  return (options?, ...rest) => deepMix({}, options, adaptor(options, ...rest));
17
17
  }
18
18
 
19
+ export function isObject(d) {
20
+ if (d instanceof Date) return false;
21
+ return typeof d === 'object';
22
+ }
23
+
19
24
  export function mergeData(
20
25
  dataDescriptor: any[] | { value: any; [key: string]: any },
21
26
  dataValue: any[],
22
27
  ) {
23
28
  if (!dataDescriptor) return dataValue;
24
29
  if (Array.isArray(dataDescriptor)) return dataDescriptor;
25
- const { value = dataValue, ...rest } = dataDescriptor;
26
- return { ...rest, value };
30
+ if (isObject(dataDescriptor)) {
31
+ const { value = dataValue, ...rest } = dataDescriptor;
32
+ return { ...rest, value };
33
+ }
34
+ return dataDescriptor;
27
35
  }
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ import { corelib, plotlib, graphlib, geolib, stdlib } from './lib';
2
2
  import { extend, Runtime } from './api';
3
3
  import { API, CompositionAPI } from './api/extend';
4
4
  import { G2Spec } from './spec';
5
+ import type { SymbolFactor } from './utils/marker';
5
6
 
6
7
  export { corelib, plotlib, graphlib, geolib, stdlib };
7
8
 
@@ -11,7 +12,7 @@ export * from './exports';
11
12
  * G2 standard library initial all the libs except 3D and auto.
12
13
  */
13
14
  const library = { ...stdlib() };
14
-
15
+ export type { SymbolFactor };
15
16
  export const Chart = extend(Runtime, library);
16
17
  export interface Chart extends API<G2Spec, typeof library> {}
17
18
  export interface CompositionNode extends CompositionAPI<typeof library> {}
@@ -126,7 +126,6 @@ function legendFilterOrdinal(
126
126
  const index = selectedValues.indexOf(value);
127
127
  if (index === -1) selectedValues.push(value);
128
128
  else selectedValues.splice(index, 1);
129
- if (selectedValues.length === 0) selectedValues.push(...items.map(datum));
130
129
  await filter(selectedValues);
131
130
  updateLegendState();
132
131
 
@@ -227,9 +227,6 @@ export function SliderFilter({
227
227
  }
228
228
  }
229
229
 
230
- // Update to async state such as scale.
231
- update();
232
-
233
230
  return () => {
234
231
  for (const [slider, handler] of sliderHandler) {
235
232
  slider.removeEventListener('valuechange', handler);
@@ -499,6 +499,7 @@ function updateMarker(root, { data, style, theme }) {
499
499
  const fill = type === 'hollow' ? 'transparent' : originColor;
500
500
  const stroke = type === 'hollow' ? originColor : '#fff';
501
501
  const shape = new Circle({
502
+ className: 'g2-tooltip-marker',
502
503
  style: {
503
504
  cx: point[0],
504
505
  cy: point[1],
@@ -52,6 +52,11 @@ export const ExceedAdjust: LLC<ExceedAdjustOptions> = () => {
52
52
  [width, height],
53
53
  ],
54
54
  );
55
+ // For label with connectorPoints
56
+ if (l.style.connector && l.style.connectorPoints) {
57
+ l.style.connectorPoints[0][0] -= changeValue[0];
58
+ l.style.connectorPoints[0][1] -= changeValue[1];
59
+ }
55
60
  l.style.x += changeValue[0];
56
61
  l.style.y += changeValue[1];
57
62
  });
@@ -49,6 +49,7 @@ import {
49
49
  inferScale,
50
50
  syncFacetsScales,
51
51
  useRelationScale,
52
+ groupTransform,
52
53
  } from './scale';
53
54
  import { applyDataTransform } from './transform';
54
55
  import {
@@ -671,6 +672,7 @@ async function initializeMarks(
671
672
  const values = channels.flatMap(({ values }) => values.map((d) => d.value));
672
673
  const scale = {
673
674
  ...inferScale(name, values, options, coordinates, theme, library),
675
+ uid: Symbol('scale'),
674
676
  key: scaleKey,
675
677
  };
676
678
  channels.forEach((channel) => (channel.scale = scale));
@@ -745,6 +747,19 @@ function initializeState(
745
747
  // AxisZ need a copy of axisX and axisY to show grids in X-Z & Y-Z planes.
746
748
  processAxisZ(components);
747
749
 
750
+ // Index scale instance by uid.
751
+ const uidScale = new Map(
752
+ Array.from(markState.values()).flatMap((state) => {
753
+ const { channels } = state;
754
+ return channels.map(({ scale }) => [
755
+ scale.uid,
756
+ useRelationScale(scale, library),
757
+ ]);
758
+ }),
759
+ );
760
+
761
+ groupTransform(markState, uidScale);
762
+
748
763
  // Scale from marks and components.
749
764
  const scaleInstance: Record<string, Scale> = {};
750
765
 
@@ -753,8 +768,8 @@ function initializeState(
753
768
  const { scales: scaleDescriptors = [] } = component;
754
769
  const scales = [];
755
770
  for (const descriptor of scaleDescriptors) {
756
- const { name } = descriptor;
757
- const scale = useRelationScale(descriptor, library);
771
+ const { name, uid } = descriptor;
772
+ const scale = uidScale.get(uid) ?? useRelationScale(descriptor, library);
758
773
  scales.push(scale);
759
774
  // Delivery the scale of axisX to the AxisY,
760
775
  // in order to calculate the angle of axisY component when rendering radar chart.
@@ -766,7 +781,6 @@ function initializeState(
766
781
  }
767
782
  assignScale(scaleInstance, { [name]: scale });
768
783
  }
769
-
770
784
  component.scaleInstances = scales;
771
785
  }
772
786
 
@@ -791,9 +805,7 @@ function initializeState(
791
805
  channels.map(({ name, scale }) => [name, scale]),
792
806
  );
793
807
  // Transform abstract value to visual value by scales.
794
- const markScaleInstance = mapObject(scale, (options) => {
795
- return useRelationScale(options, library);
796
- });
808
+ const markScaleInstance = mapObject(scale, ({ uid }) => uidScale.get(uid));
797
809
  assignScale(scaleInstance, markScaleInstance);
798
810
  const value = applyScale(channels, markScaleInstance);
799
811
 
@@ -1,5 +1,5 @@
1
1
  import { Linear, createInterpolateValue } from '@antv/scale';
2
- import { extent, max } from 'd3-array';
2
+ import { extent, max, rollups } from 'd3-array';
3
3
  import * as d3ScaleChromatic from 'd3-scale-chromatic';
4
4
  import { deepMix, omit, upperFirst } from '@antv/util';
5
5
  import { firstOf, lastOf, unique } from '../utils/array';
@@ -72,6 +72,32 @@ export function applyScale(
72
72
  return scaledValue;
73
73
  }
74
74
 
75
+ export function groupTransform(
76
+ markState: Map<G2Mark, G2MarkState>,
77
+ uidScale: Map<symbol, Scale>,
78
+ ) {
79
+ const channels = Array.from(markState.values()).flatMap((d) => d.channels);
80
+
81
+ const scaleGroups = rollups(
82
+ channels,
83
+ (channels) => channels.map((d) => uidScale.get(d.scale.uid)),
84
+ (d) => d.name,
85
+ )
86
+ .filter(
87
+ ([, scales]) =>
88
+ scales.some(
89
+ (d) => typeof d.getOptions().groupTransform === 'function',
90
+ ) && // only sync scales with groupTransform options
91
+ scales.every((d) => d.getTicks), // only sync quantitative scales
92
+ )
93
+ .map((d) => d[1]);
94
+
95
+ scaleGroups.forEach((group) => {
96
+ const groupTransform = group.map((d) => d.getOptions().groupTransform)[0];
97
+ groupTransform(group);
98
+ });
99
+ }
100
+
75
101
  export function collectScales(states: G2MarkState[], options: G2View) {
76
102
  const { components = [] } = options;
77
103
 
@@ -416,7 +442,7 @@ function categoricalColors(
416
442
  library,
417
443
  );
418
444
  const { category10: c10, category20: c20 } = theme;
419
- const defaultPalette = unique(values.flat()).length <= c10.length ? c10 : c20;
445
+ const defaultPalette = unique(domain).length <= c10.length ? c10 : c20;
420
446
  const { palette = defaultPalette, offset } = options;
421
447
  if (Array.isArray(palette)) return palette;
422
448
  // Built-in palettes have higher priority.
@@ -29,6 +29,7 @@ function getDefaultStyle(
29
29
  coordinate: Coordinate,
30
30
  theme: G2Theme,
31
31
  options: LabelOptions,
32
+ labels: Vector2[][],
32
33
  ): Record<string, any> {
33
34
  // For non-series mark, calc position for label based on
34
35
  // position and the bounds of shape.
@@ -48,7 +49,7 @@ function getDefaultStyle(
48
49
  }
49
50
  return {
50
51
  ...t,
51
- ...processor(p, points, v, coordinate, options),
52
+ ...processor(p, points, v, coordinate, options, labels),
52
53
  };
53
54
  }
54
55
 
@@ -59,7 +60,7 @@ function getDefaultStyle(
59
60
  export const Label: SC<LabelOptions> = (options, context) => {
60
61
  const { coordinate, theme } = context;
61
62
  const { render } = options;
62
- return (points, value) => {
63
+ return (points, value, style, labels) => {
63
64
  const {
64
65
  text,
65
66
  x,
@@ -73,7 +74,7 @@ export const Label: SC<LabelOptions> = (options, context) => {
73
74
  rotate = 0,
74
75
  transform = '',
75
76
  ...defaultStyle
76
- } = getDefaultStyle(points, value, coordinate, theme, options);
77
+ } = getDefaultStyle(points, value, coordinate, theme, options, labels);
77
78
 
78
79
  return select(new Advance())
79
80
  .call(applyStyle, defaultStyle)
@@ -3,19 +3,16 @@ import { Vector2 } from '../../../runtime';
3
3
  import { isCircular } from '../../../utils/coordinate';
4
4
  import { LabelPosition } from './default';
5
5
  import { inferOutsideCircularStyle, radiusOf, angleOf } from './outside';
6
+ import { hideAndDodgeY } from './utils';
6
7
 
7
- /**
8
- * Spider label transform only suitable for the labels in polar coordinate, labels should distinguish coordinate type.
9
- */
10
- export function spider(
11
- position: LabelPosition,
8
+ const styleByPoints = new WeakMap();
9
+
10
+ function compute(
12
11
  points: Vector2[],
13
12
  value: Record<string, any>,
14
13
  coordinate: Coordinate,
15
14
  ) {
16
- if (!isCircular(coordinate)) return {};
17
15
  const { connectorLength, connectorLength2, connectorDistance } = value;
18
-
19
16
  const { ...style }: any = inferOutsideCircularStyle(
20
17
  'outside',
21
18
  points,
@@ -27,13 +24,35 @@ export function spider(
27
24
  const angle = angleOf(points, value, coordinate);
28
25
  const radius1 = radius + connectorLength + connectorLength2;
29
26
  const sign = Math.sin(angle) > 0 ? 1 : -1;
30
-
31
27
  const newX = center[0] + (radius1 + +connectorDistance) * sign;
32
-
33
28
  const { x: originX } = style;
34
29
  const dx = newX - originX;
35
30
  style.x += dx;
36
31
  style.connectorPoints[0][0] -= dx;
37
-
38
32
  return style;
39
33
  }
34
+
35
+ /**
36
+ * Spider label transform only suitable for the labels in polar coordinate,
37
+ * labels should distinguish coordinate type.
38
+ */
39
+ export function spider(
40
+ position: LabelPosition,
41
+ points: Vector2[],
42
+ value: Record<string, any>,
43
+ coordinate: Coordinate,
44
+ options: Record<string, any>,
45
+ labels: Vector2[][],
46
+ ) {
47
+ if (!isCircular(coordinate)) return {};
48
+ if (styleByPoints.has(points)) return styleByPoints.get(points);
49
+ const computed = labels.map((points) => compute(points, value, coordinate));
50
+ const { width, height } = coordinate.getOptions();
51
+ const left = computed.filter((d) => d.x < width / 2);
52
+ const right = computed.filter((d) => d.x >= width / 2);
53
+ const extendedOptions = { ...options, height };
54
+ hideAndDodgeY(left, extendedOptions);
55
+ hideAndDodgeY(right, extendedOptions);
56
+ computed.forEach((style, i) => styleByPoints.set(labels[i], style));
57
+ return styleByPoints.get(points);
58
+ }
@@ -0,0 +1,77 @@
1
+ import { sort } from 'd3-array';
2
+
3
+ // Optimize antiCollision from: https://github.com/antvis/G2/blob/master/src/geometry/label/layout/pie/util.ts
4
+ export function dodgeY(
5
+ labels: Record<string, any>[],
6
+ options: Record<string, any> = {},
7
+ ) {
8
+ const { labelHeight = 14, height } = options;
9
+
10
+ // Sort labels by y and init boxes (one box for each label)
11
+ const sortedLabels = sort(labels, (d) => d.y);
12
+ const n = sortedLabels.length;
13
+ const boxes = new Array(n);
14
+ for (let i = 0; i < n; i++) {
15
+ const label = sortedLabels[i];
16
+ const { y } = label;
17
+ boxes[i] = { y, y1: y + labelHeight, labels: [y] };
18
+ }
19
+
20
+ // Merge boxes until no overlapping boxes or only one box left.
21
+ // All the boxes should start higher than 0, but maybe higher than height.
22
+ let overlap = true;
23
+ while (overlap) {
24
+ overlap = false;
25
+ // Scan backward because boxes maybe deleted.
26
+ for (let i = boxes.length - 1; i > 0; i--) {
27
+ const box = boxes[i];
28
+ const preBox = boxes[i - 1];
29
+ if (preBox.y1 > box.y) {
30
+ overlap = true;
31
+ preBox.labels.push(...box.labels);
32
+ boxes.splice(i, 1);
33
+
34
+ // Compute new y1 to contain the current box.
35
+ preBox.y1 += box.y1 - box.y;
36
+
37
+ // Make sure the new box is in the range of [0, height].
38
+ const newHeight = preBox.y1 - preBox.y;
39
+ preBox.y1 = Math.max(Math.min(preBox.y1, height), newHeight);
40
+ preBox.y = preBox.y1 - newHeight;
41
+ }
42
+ }
43
+ }
44
+
45
+ let i = 0;
46
+ for (const box of boxes) {
47
+ const { y, labels } = box;
48
+ let prevY = y - labelHeight;
49
+ for (const curY of labels) {
50
+ const label = sortedLabels[i++];
51
+ const expectedY = prevY + labelHeight;
52
+ const dy = expectedY - curY;
53
+ label.connectorPoints[0][1] -= dy;
54
+ label.y = prevY + labelHeight;
55
+ prevY += labelHeight;
56
+ }
57
+ }
58
+ }
59
+
60
+ export function hideAndDodgeY(
61
+ unsorted: Record<string, any>[],
62
+ options: Record<string, any>,
63
+ ) {
64
+ const labels = sort(unsorted, (d) => d.y);
65
+ const { height, labelHeight = 14 } = options;
66
+ const maxCount = Math.ceil(height / labelHeight);
67
+ if (labels.length <= maxCount) return dodgeY(labels, options);
68
+ const filtered = [];
69
+ for (let i = 0; i < labels.length; i++) {
70
+ // Hide labels out of range.
71
+ if (i < labels.length - maxCount) {
72
+ labels[i].opacity = 0;
73
+ labels[i].connector = false;
74
+ } else filtered.push(labels[i]);
75
+ }
76
+ dodgeY(filtered, options);
77
+ }
@@ -50,7 +50,7 @@ type TextShapeStyleProps = Omit<TextStyleProps, 'text'> &
50
50
  text?: string;
51
51
  };
52
52
 
53
- function getConnectorPoint(shape: GText | Rect) {
53
+ function getConnectorPoint(shape: GText | Rect): [number, number] {
54
54
  const {
55
55
  min: [x0, y0],
56
56
  max: [x1, y1],
@@ -61,7 +61,6 @@ function getConnectorPoint(shape: GText | Rect) {
61
61
  if (x1 < 0) x = x1;
62
62
  if (y0 > 0) y = y0;
63
63
  if (y1 < 0) y = y1;
64
-
65
64
  return [x, y];
66
65
  }
67
66
 
@@ -91,41 +90,76 @@ const cos = (p0: Vector2, p1: Vector2, p2: Vector2) => {
91
90
  return (a ** 2 + b ** 2 - c ** 2) / (2 * a * b);
92
91
  };
93
92
 
93
+ // A path from element to label.
94
+ // Adapted drawLabelLine from https://github.com/antvis/G2/blob/master/src/geometry/label/layout/pie/spider.ts
94
95
  function inferConnectorPath(
95
96
  shape: DisplayObject,
96
- points: Vector2[],
97
- controlPoints: Vector2[],
98
- coordCenter,
97
+ end: Vector2,
98
+ control: Vector2[],
99
+ coordCenter: Vector2,
100
+ left = true,
101
+ top = true,
99
102
  ) {
100
- const [[x0, y0], [x1, y1]] = points;
101
- const [x, y] = getConnectorPoint(shape);
102
- // Straight connector line.
103
- if (x0 === x1 && y0 === y1) {
104
- return line()([
105
- [0, 0],
106
- [x, y],
107
- ]);
108
- }
103
+ const path = (points) => line()(points);
109
104
 
110
- const P: any = [[x0 - x1, y0 - y1]].concat(
111
- controlPoints.length ? controlPoints : [[0, 0]],
112
- );
105
+ if (!end[0] && !end[1]) return path([getConnectorPoint(shape), end]);
106
+ if (!control.length) return path([[0, 0], end]);
107
+
108
+ const [inflection, start] = control;
109
+ const p1 = [...start];
110
+ const p2 = [...inflection];
111
+
112
+ // Label has been adjusted, so add offset to the label.
113
+ if (start[0] !== inflection[0]) {
114
+ const offset = left ? -4 : 4;
115
+ p1[1] = start[1];
113
116
 
114
- const p0 = [coordCenter[0] - x1, coordCenter[1] - y1] as Vector2;
115
- const [p1, p2] = P;
116
- // If angle is smaller than 90, which will cause connector overlap with element.
117
- if (cos(p0, p1, p2) > 0) {
118
- const x2 = (() => {
119
- const { min, max } = shape.getLocalBounds();
120
- // A(x1,y2) perpendicular to B(x2,y2) => x1*x2 + y1*y2 = 0
121
- const vx = p1[0] + ((p1[1] - p0[1]) * (p1[1] - 0)) / (p1[0] - p0[0]);
122
- if (max[0] < p0[0]) return Math.min(max[0], vx);
123
- return Math.max(min[0], vx);
124
- })();
125
- P.splice(1, 1, [x2, 0]);
117
+ // For the label in the first quadrant.
118
+ if (top && !left) {
119
+ p1[0] = Math.max(inflection[0], start[0] - offset);
120
+ if (start[1] < inflection[1]) {
121
+ p2[1] = p1[1];
122
+ } else {
123
+ p2[1] = inflection[1];
124
+ p2[0] = Math.max(p2[0], p1[0] - offset);
125
+ }
126
+ }
127
+
128
+ // For the label in the second quadrant.
129
+ if (!top && !left) {
130
+ p1[0] = Math.max(inflection[0], start[0] - offset);
131
+ if (start[1] > inflection[1]) {
132
+ p2[1] = p1[1];
133
+ } else {
134
+ p2[1] = inflection[1];
135
+ p2[0] = Math.max(p2[0], p1[0] - offset);
136
+ }
137
+ }
138
+
139
+ // For the label in the third quadrant.
140
+ if (!top && left) {
141
+ p1[0] = Math.min(inflection[0], start[0] - offset);
142
+ if (start[1] > inflection[1]) {
143
+ p2[1] = p1[1];
144
+ } else {
145
+ p2[1] = inflection[1];
146
+ p2[0] = Math.min(p2[0], p1[0] - offset);
147
+ }
148
+ }
149
+
150
+ // For the label in the fourth quadrant.
151
+ if (top && left) {
152
+ p1[0] = Math.min(inflection[0], start[0] - offset);
153
+ if (start[1] < inflection[1]) {
154
+ p2[1] = p1[1];
155
+ } else {
156
+ p2[1] = inflection[1];
157
+ p2[0] = Math.min(p2[0], p1[0] - offset);
158
+ }
159
+ }
126
160
  }
127
161
 
128
- return line()(P);
162
+ return path([start, p1, p2, inflection, end]);
129
163
  }
130
164
 
131
165
  export const Advance = createElement((g) => {
@@ -161,14 +195,12 @@ export const Advance = createElement((g) => {
161
195
  }
162
196
 
163
197
  const { padding, ...backgroundStyle } = subObject(rest, 'background');
164
- const { points = [], ...connectorStyle } = subObject(rest, 'connector');
165
- const endPoints: Vector2[] = [
166
- [+x0, +y0],
167
- [+x, +y],
168
- ];
198
+ const { points: controlPoints = [], ...connectorStyle } = subObject(
199
+ rest,
200
+ 'connector',
201
+ );
169
202
 
170
203
  let textShape;
171
- // Use html to customize advance text.
172
204
  if (innerHTML) {
173
205
  textShape = select(g)
174
206
  .maybeAppend('html', 'html', className)
@@ -201,12 +233,18 @@ export const Advance = createElement((g) => {
201
233
  .call(applyStyle, background ? backgroundStyle : {})
202
234
  .node();
203
235
 
236
+ const left = +x0 < coordCenter[0];
237
+ const top = +y0 < coordCenter[1];
238
+ const end: [number, number] = [+x0 - +x, +y0 - +y];
204
239
  const connectorPath = inferConnectorPath(
205
240
  rect,
206
- endPoints,
207
- points,
241
+ end,
242
+ controlPoints,
208
243
  coordCenter,
244
+ left,
245
+ top,
209
246
  );
247
+
210
248
  const markerStart =
211
249
  startMarker &&
212
250
  new Marker({
package/src/spec/scale.ts CHANGED
@@ -13,6 +13,11 @@ import {
13
13
  SqrtOptions,
14
14
  SequentialOptions,
15
15
  ConstantOptions,
16
+ Linear,
17
+ Log,
18
+ Pow,
19
+ Sqrt,
20
+ Time,
16
21
  } from '@antv/scale';
17
22
  import { ScaleComponent } from '../runtime';
18
23
  import { Palette } from './palette';
@@ -51,6 +56,8 @@ export type ScaleTypes =
51
56
  | 'constant'
52
57
  | ScaleComponent;
53
58
 
59
+ type QuantitativeScale = Linear | Log | Pow | Sqrt | Time;
60
+
54
61
  export type BaseScale<T extends ScaleTypes, O> = {
55
62
  type?: T;
56
63
  palette?: Palette['type'] | string;
@@ -64,6 +71,7 @@ export type BaseScale<T extends ScaleTypes, O> = {
64
71
  zero?: boolean;
65
72
  offset?: (t: number) => number;
66
73
  relations?: [any, any][];
74
+ groupTransform?: (scales: QuantitativeScale[]) => void;
67
75
  } & O;
68
76
 
69
77
  export type LinearScale = BaseScale<'linear', LinearOptions>;
@@ -1,5 +1,5 @@
1
1
  import { deepMix } from '@antv/util';
2
- import { TransformComponent as TC } from '../runtime';
2
+ import { G2Mark, TransformComponent as TC } from '../runtime';
3
3
  import { FilterTransform } from '../spec';
4
4
  import { defined } from '../utils/helper';
5
5
  import { columnOf } from './utils/helper';
@@ -11,6 +11,54 @@ function normalizeValue(value) {
11
11
  else return [value, true];
12
12
  }
13
13
 
14
+ function filterWhenNoElements(mark: G2Mark) {
15
+ const { encode } = mark;
16
+
17
+ // keep y-axis
18
+ const noElementMark = {
19
+ ...mark,
20
+ encode: {
21
+ ...mark.encode,
22
+ y: {
23
+ ...mark.encode.y,
24
+ value: [],
25
+ },
26
+ },
27
+ };
28
+
29
+ const targetField = encode?.color?.field;
30
+ if (!encode || !targetField) {
31
+ return noElementMark;
32
+ }
33
+
34
+ // 获取color的筛选源
35
+ let filterObject;
36
+
37
+ for (const [key, v] of Object.entries(encode)) {
38
+ if ((key === 'x' || key === 'y') && v.field === targetField) {
39
+ filterObject = {
40
+ ...filterObject,
41
+ [key]: {
42
+ ...v,
43
+ value: [],
44
+ },
45
+ };
46
+ }
47
+ }
48
+
49
+ if (!filterObject) {
50
+ return noElementMark;
51
+ }
52
+
53
+ return {
54
+ ...mark,
55
+ encode: {
56
+ ...mark.encode,
57
+ ...filterObject,
58
+ },
59
+ };
60
+ }
61
+
14
62
  /**
15
63
  * The Filter transform filter channels.
16
64
  */
@@ -35,14 +83,16 @@ export const Filter: TC<FilterOptions> = (options = {}) => {
35
83
  }
36
84
  })
37
85
  .filter(defined);
38
-
39
- // Skip empty filters.
40
- if (filters.length === 0) return [I, mark];
41
-
42
86
  // Filter index and channels.
43
87
  const totalFilter = (i) => filters.every((f) => f(i));
44
88
  const FI = I.filter(totalFilter);
45
89
  const newIndex = FI.map((_, i) => i);
90
+
91
+ if (filters.length === 0) {
92
+ const targetMark = filterWhenNoElements(mark);
93
+ return [I, targetMark];
94
+ }
95
+
46
96
  const newEncodes = Object.entries(encode).map(([key, encode]) => {
47
97
  return [
48
98
  key,