@antv/g2 5.2.7 → 5.2.8

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.
@@ -1,7 +1,7 @@
1
1
  import { Coordinate, Transformation } from '@antv/coord';
2
2
  import EventEmitter from '@antv/event-emitter';
3
3
  import { DisplayObject, IAnimation as GAnimation, IDocument, Canvas } from '@antv/g';
4
- import { G2Theme, G2ViewInstance, GuideComponentOrientation, GuideComponentPosition, IndexedValue, Vector2, G2MarkState, GuideComponentPlane } from './common';
4
+ import { G2Theme, G2ViewInstance, GuideComponentOrientation, GuideComponentPosition, IndexedValue, Vector2, G2MarkState, GuideComponentPlane, Layout } from './common';
5
5
  import { DataComponent } from './data';
6
6
  import { Encode, EncodeComponent } from './encode';
7
7
  import { Mark, MarkComponent } from './mark';
@@ -98,5 +98,6 @@ export type CompositionComponent<O = Record<string, unknown>> = G2BaseComponent<
98
98
  export type LabelTransform = (labels: DisplayObject[], context: {
99
99
  coordinate: Coordinate;
100
100
  canvas: Canvas;
101
+ layout: Layout;
101
102
  }) => DisplayObject[];
102
103
  export type LabelTransformComponent<O = Record<string, unknown>> = G2BaseComponent<LabelTransform, O>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/g2",
3
- "version": "5.2.7",
3
+ "version": "5.2.8",
4
4
  "description": "the Grammar of Graphics in Javascript",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -42,7 +42,6 @@
42
42
  "build": "run-p build:*",
43
43
  "bundle-vis": "cross-env BUNDLE_VIS=1 run-p build:umd",
44
44
  "ci": "run-s lint test build",
45
- "prepublishOnly": "npm run ci",
46
45
  "prepare": "husky install",
47
46
  "upload": "node scripts/upload/snapshot.js",
48
47
  "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
@@ -34,9 +34,7 @@ export type ExceedAdjustOptions = Omit<ExceedAdjustLabel, 'type'>;
34
34
  * adjust the label when exceed the plot
35
35
  */
36
36
  export const ExceedAdjust: LLC<ExceedAdjustOptions> = () => {
37
- return (labels: DisplayObject[], { canvas }) => {
38
- const { width, height } = canvas.getConfig();
39
-
37
+ return (labels: DisplayObject[], { canvas, layout }) => {
40
38
  labels.forEach((l) => {
41
39
  show(l);
42
40
  const { max, min } = l.getRenderBounds();
@@ -47,9 +45,10 @@ export const ExceedAdjust: LLC<ExceedAdjustOptions> = () => {
47
45
  [xMin, yMin],
48
46
  [xMax, yMax],
49
47
  ],
48
+ // Prevent label overlap in multiple charts by calculating layouts separately to avoid collisions.
50
49
  [
51
- [0, 0],
52
- [width, height],
50
+ [layout.x, layout.y],
51
+ [layout.x + layout.width, layout.y + layout.height],
53
52
  ],
54
53
  );
55
54
  // For label with connectorPoints
@@ -1229,11 +1229,12 @@ function plotLabel(
1229
1229
  const labelGroups = group(labelShapes, (d) =>
1230
1230
  labelDescriptor.get(d.__data__),
1231
1231
  );
1232
- const { coordinate } = view;
1232
+ const { coordinate, layout } = view;
1233
1233
 
1234
1234
  const labelTransformContext = {
1235
1235
  canvas: context.canvas,
1236
1236
  coordinate,
1237
+ layout,
1237
1238
  };
1238
1239
  for (const [label, shapes] of labelGroups) {
1239
1240
  const { transform = [] } = label;
@@ -15,6 +15,7 @@ import {
15
15
  Vector2,
16
16
  G2MarkState,
17
17
  GuideComponentPlane,
18
+ Layout,
18
19
  } from './common';
19
20
  import { DataComponent } from './data';
20
21
  import { Encode, EncodeComponent } from './encode';
@@ -233,6 +234,7 @@ export type LabelTransform = (
233
234
  context: {
234
235
  coordinate: Coordinate;
235
236
  canvas: Canvas;
237
+ layout: Layout;
236
238
  },
237
239
  ) => DisplayObject[];
238
240
  export type LabelTransformComponent<O = Record<string, unknown>> =