@antv/g2 5.1.18 → 5.1.20

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 (85) hide show
  1. package/dist/g2.lite.min.js +1 -1
  2. package/dist/g2.min.js +1 -1
  3. package/esm/animation/morphing.js +14 -12
  4. package/esm/animation/morphing.js.map +1 -1
  5. package/esm/data/utils/d3-cloud/index.js +1 -0
  6. package/esm/data/utils/d3-cloud/index.js.map +1 -1
  7. package/esm/data/wordCloud.d.ts +100 -2
  8. package/esm/data/wordCloud.js +20 -5
  9. package/esm/data/wordCloud.js.map +1 -1
  10. package/esm/index.d.ts +6 -2
  11. package/esm/interaction/brushHighlight.js +11 -8
  12. package/esm/interaction/brushHighlight.js.map +1 -1
  13. package/esm/label-transform/exceedAdjust.d.ts +7 -0
  14. package/esm/label-transform/exceedAdjust.js +45 -0
  15. package/esm/label-transform/exceedAdjust.js.map +1 -0
  16. package/esm/label-transform/index.d.ts +2 -0
  17. package/esm/label-transform/index.js +1 -0
  18. package/esm/label-transform/index.js.map +1 -1
  19. package/esm/lib/core.d.ts +3 -0
  20. package/esm/lib/core.js +6 -3
  21. package/esm/lib/core.js.map +1 -1
  22. package/esm/lib/std.d.ts +3 -1
  23. package/esm/mark/text.js +4 -3
  24. package/esm/mark/text.js.map +1 -1
  25. package/esm/mark/wordCloud.js +11 -12
  26. package/esm/mark/wordCloud.js.map +1 -1
  27. package/esm/runtime/plot.js +8 -4
  28. package/esm/runtime/plot.js.map +1 -1
  29. package/esm/runtime/types/component.d.ts +5 -2
  30. package/esm/shape/index.d.ts +2 -0
  31. package/esm/shape/index.js +1 -0
  32. package/esm/shape/index.js.map +1 -1
  33. package/esm/shape/text/tag.d.ts +7 -0
  34. package/esm/shape/text/tag.js +40 -0
  35. package/esm/shape/text/tag.js.map +1 -0
  36. package/esm/spec/labelTransform.d.ts +3 -0
  37. package/lib/animation/morphing.js +14 -12
  38. package/lib/animation/morphing.js.map +1 -1
  39. package/lib/data/utils/d3-cloud/index.js +1 -0
  40. package/lib/data/utils/d3-cloud/index.js.map +1 -1
  41. package/lib/data/wordCloud.d.ts +100 -2
  42. package/lib/data/wordCloud.js +20 -5
  43. package/lib/data/wordCloud.js.map +1 -1
  44. package/lib/index.d.ts +6 -2
  45. package/lib/interaction/brushHighlight.js +11 -8
  46. package/lib/interaction/brushHighlight.js.map +1 -1
  47. package/lib/label-transform/exceedAdjust.d.ts +7 -0
  48. package/lib/label-transform/exceedAdjust.js +49 -0
  49. package/lib/label-transform/exceedAdjust.js.map +1 -0
  50. package/lib/label-transform/index.d.ts +2 -0
  51. package/lib/label-transform/index.js +3 -1
  52. package/lib/label-transform/index.js.map +1 -1
  53. package/lib/lib/core.d.ts +3 -0
  54. package/lib/lib/core.js +3 -0
  55. package/lib/lib/core.js.map +1 -1
  56. package/lib/lib/std.d.ts +3 -1
  57. package/lib/mark/text.js +3 -2
  58. package/lib/mark/text.js.map +1 -1
  59. package/lib/mark/wordCloud.js +11 -12
  60. package/lib/mark/wordCloud.js.map +1 -1
  61. package/lib/runtime/plot.js +7 -3
  62. package/lib/runtime/plot.js.map +1 -1
  63. package/lib/runtime/types/component.d.ts +5 -2
  64. package/lib/shape/index.d.ts +2 -0
  65. package/lib/shape/index.js +4 -2
  66. package/lib/shape/index.js.map +1 -1
  67. package/lib/shape/text/tag.d.ts +7 -0
  68. package/lib/shape/text/tag.js +44 -0
  69. package/lib/shape/text/tag.js.map +1 -0
  70. package/lib/spec/labelTransform.d.ts +3 -0
  71. package/package.json +3 -2
  72. package/src/animation/morphing.ts +15 -12
  73. package/src/data/utils/d3-cloud/index.ts +1 -0
  74. package/src/data/wordCloud.ts +112 -7
  75. package/src/interaction/brushHighlight.ts +13 -8
  76. package/src/label-transform/exceedAdjust.ts +61 -0
  77. package/src/label-transform/index.ts +2 -0
  78. package/src/lib/core.ts +6 -0
  79. package/src/mark/text.ts +4 -3
  80. package/src/mark/wordCloud.ts +16 -18
  81. package/src/runtime/plot.ts +9 -3
  82. package/src/runtime/types/component.ts +10 -2
  83. package/src/shape/index.ts +2 -0
  84. package/src/shape/text/tag.ts +44 -0
  85. package/src/spec/labelTransform.ts +4 -0
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"src/","sources":["shape/index.ts"],"names":[],"mappings":";;;;AAAA,wCAAwD;AAA/C,qGAAA,IAAI,OAAiB;AAC9B,4CAA6D;AAApD,wGAAA,MAAM,OAAkB;AACjC,4CAA6D;AAApD,wGAAA,MAAM,OAAkB;AACjC,8CAAgE;AAAvD,0GAAA,OAAO,OAAmB;AACnC,wCAAoD;AAA3C,iGAAA,IAAI,OAAa;AAC1B,4CAAyD;AAAhD,oGAAA,MAAM,OAAc;AAC7B,oCAAgD;AAAvC,iGAAA,IAAI,OAAa;AAC1B,wCAAqD;AAA5C,oGAAA,MAAM,OAAc;AAC7B,gCAAyC;AAAhC,4FAAA,EAAE,OAAU;AACrB,gCAAyC;AAAhC,4FAAA,EAAE,OAAU;AACrB,kCAA4C;AAAnC,8FAAA,GAAG,OAAW;AACvB,sCAAkD;AAAzC,kGAAA,KAAK,OAAa;AAC3B,qDAAyE;AAAhE,iHAAA,YAAY,OAAqB;AAC1C,uDAA4E;AAAnE,mHAAA,aAAa,OAAsB;AAC5C,uDAA4E;AAAnE,mHAAA,aAAa,OAAsB;AAC5C,yCAA4D;AAAnD,qGAAA,WAAW,OAAe;AACnC,qDAAyE;AAAhE,iHAAA,YAAY,OAAqB;AAC1C,yDAA+E;AAAtE,qHAAA,cAAc,OAAuB;AAC9C,iEAA2F;AAAlF,6HAAA,kBAAkB,OAA2B;AACtD,qDAAyE;AAAhE,iHAAA,YAAY,OAAqB;AAC1C,yCAAuD;AAA9C,qGAAA,MAAM,OAAe;AAC9B,uCAAoD;AAA3C,mGAAA,KAAK,OAAc;AAC5B,2CAA0D;AAAjD,uGAAA,OAAO,OAAgB;AAChC,2CAA0D;AAAjD,uGAAA,OAAO,OAAgB;AAChC,yCAAuD;AA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O,OAAgB;AAChC,2CAA2D;AAAlD,uGAAA,MAAM,OAAiB;AAChC,iCAA4C;AAAnC,+FAAA,GAAG,OAAY;AACxB,uCAAmD;AAA1C,mGAAA,MAAM,OAAa;AAC5B,sCAA+C;AAAtC,8FAAA,IAAI,OAAU;AACvB,mDAAoE;AAA3D,2GAAA,SAAS,OAAkB;AACpC,uCAAoD;AAA3C,mGAAA,KAAK,OAAc;AAC5B,oCAAgD;AAAvC,iGAAA,IAAI,OAAa;AAC1B,wCAAqD;AAA5C,oGAAA,MAAM,OAAc;AAC7B,6CAA4D;AAAnD,uGAAA,OAAO,OAAgB;AAChC,6CAA4D;AAAnD,uGAAA,OAAO,OAAgB;AAChC,wCAAqD;AAA5C,kGAAA,IAAI,OAAc;AAC3B,wCAAoD;AAA3C,iGAAA,IAAI,OAAa;AAC1B,4CAAyD;AAAhD,oGAAA,MAAM,OAAc;AAC7B,uCAAoD;AAA3C,mGAAA,KAAK,OAAc;AAC5B,0CAAwD;AAA/C,qGAAA,MAAM,OAAe;AAC9B,uCAAoD;AAA3C,mGAAA,KAAK,OAAc"}
@@ -0,0 +1,7 @@
1
+ import { ShapeComponent as SC } from '../../runtime';
2
+ export type TagOptions = Record<string, any>;
3
+ /**
4
+ * @todo autoRotate when in polar coordinate
5
+ * Tag shape for Text mark, used in wordCloud plot.
6
+ */
7
+ export declare const Tag: SC<TagOptions>;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Tag = void 0;
4
+ const g_1 = require("@antv/g");
5
+ const utils_1 = require("../../shape/utils");
6
+ const selection_1 = require("../../utils/selection");
7
+ /**
8
+ * @todo autoRotate when in polar coordinate
9
+ * Tag shape for Text mark, used in wordCloud plot.
10
+ */
11
+ const Tag = (options, context) => {
12
+ const { coordinate } = context;
13
+ return (points, value, defaults) => {
14
+ const { color, text = '', fontSize, rotate = 0, transform = '' } = value;
15
+ const textStyle = {
16
+ text: String(text),
17
+ stroke: color,
18
+ fill: color,
19
+ fontSize,
20
+ textAlign: 'center',
21
+ textBaseline: 'middle',
22
+ };
23
+ const [[x0, y0]] = points;
24
+ const n = (0, selection_1.select)(new g_1.Text())
25
+ .style('x', x0)
26
+ .style('y', y0)
27
+ .call(utils_1.applyStyle, defaults)
28
+ .style('transformOrigin', 'center center')
29
+ .style('transform', `${transform}rotate(${rotate}deg)`)
30
+ .style('coordCenter', coordinate.getCenter())
31
+ .call(utils_1.applyStyle, textStyle)
32
+ .call(utils_1.applyStyle, options)
33
+ .node();
34
+ return n;
35
+ };
36
+ };
37
+ exports.Tag = Tag;
38
+ exports.Tag.props = {
39
+ defaultMarker: 'point',
40
+ defaultEnterAnimation: 'fadeIn',
41
+ defaultUpdateAnimation: 'morphing',
42
+ defaultExitAnimation: 'fadeOut',
43
+ };
44
+ //# sourceMappingURL=tag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tag.js","sourceRoot":"src/","sources":["shape/text/tag.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAE/B,6CAA+C;AAC/C,qDAA+C;AAI/C;;;GAGG;AACI,MAAM,GAAG,GAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;IACtD,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAC/B,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;QACjC,MAAM,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,EAAE,SAAS,GAAG,EAAE,EAAE,GAAG,KAAK,CAAC;QACzE,MAAM,SAAS,GAAG;YAChB,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC;YAClB,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,KAAK;YACX,QAAQ;YACR,SAAS,EAAE,QAAQ;YACnB,YAAY,EAAE,QAAQ;SACvB,CAAC;QACF,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC;QAC1B,MAAM,CAAC,GAAG,IAAA,kBAAM,EAAC,IAAI,QAAI,EAAE,CAAC;aACzB,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC;aACd,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC;aACd,IAAI,CAAC,kBAAU,EAAE,QAAQ,CAAC;aAC1B,KAAK,CAAC,iBAAiB,EAAE,eAAe,CAAC;aACzC,KAAK,CAAC,WAAW,EAAE,GAAG,SAAS,UAAU,MAAM,MAAM,CAAC;aACtD,KAAK,CAAC,aAAa,EAAE,UAAU,CAAC,SAAS,EAAE,CAAC;aAC5C,IAAI,CAAC,kBAAU,EAAE,SAAS,CAAC;aAC3B,IAAI,CAAC,kBAAU,EAAE,OAAO,CAAC;aACzB,IAAI,EAAE,CAAC;QACV,OAAO,CAAC,CAAC;IACX,CAAC,CAAC;AACJ,CAAC,CAAC;AAzBW,QAAA,GAAG,OAyBd;AAEF,WAAG,CAAC,KAAK,GAAG;IACV,aAAa,EAAE,OAAO;IACtB,qBAAqB,EAAE,QAAQ;IAC/B,sBAAsB,EAAE,UAAU;IAClC,oBAAoB,EAAE,SAAS;CAChC,CAAC"}
@@ -28,3 +28,6 @@ export type ContrastReverseLabelTransform = {
28
28
  export type OverflowHideLabelTransform = {
29
29
  type: 'overflowHide';
30
30
  };
31
+ export type ExceedAdjustLabel = {
32
+ type: 'exceedAdjust';
33
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/g2",
3
- "version": "5.1.18",
3
+ "version": "5.1.20",
4
4
  "description": "the Grammar of Graphics in Javascript",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -42,6 +42,7 @@
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",
45
46
  "prepare": "husky install",
46
47
  "upload": "node scripts/upload/snapshot.js",
47
48
  "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
@@ -153,7 +154,7 @@
153
154
  "limit-size": [
154
155
  {
155
156
  "path": "dist/g2.min.js",
156
- "limit": "280 Kb",
157
+ "limit": "285 Kb",
157
158
  "gzip": true
158
159
  },
159
160
  {
@@ -190,21 +190,24 @@ function oneToOne(
190
190
  if (fromPath !== toPath) {
191
191
  keyframes[0].d = fromPath;
192
192
  keyframes[1].d = toPath;
193
- }
194
- const animation = pathShape.animate(keyframes, timeEffect);
195
193
 
196
- animation.onfinish = () => {
197
- // Should keep the original path definition.
198
- const d = pathShape.style.d;
199
- copyAttributes(pathShape, to);
200
- pathShape.style.d = d;
194
+ const animation = pathShape.animate(keyframes, timeEffect);
195
+ animation.onfinish = () => {
196
+ // Should keep the original path definition.
197
+ const d = pathShape.style.d;
198
+ copyAttributes(pathShape, to);
199
+ pathShape.style.d = d;
200
+ pathShape.style.transform = 'none';
201
+ };
202
+
203
+ // Remove transform because it already applied in path
204
+ // converted by convertToPath.
201
205
  pathShape.style.transform = 'none';
202
- };
206
+ return animation;
207
+ }
203
208
 
204
- // Remove transform because it already applied in path
205
- // converted by convertToPath.
206
- pathShape.style.transform = 'none';
207
- return animation;
209
+ // No need to apply animation since fromPath equals toPath.
210
+ return null;
208
211
  }
209
212
 
210
213
  function oneToMultiple(
@@ -357,6 +357,7 @@ export function tagCloud() {
357
357
  const context = canvas.getContext('2d') as CanvasRenderingContext2D;
358
358
  context.fillStyle = context.strokeStyle = 'red';
359
359
  context.textAlign = 'center';
360
+ context.textBaseline = 'middle';
360
361
  return { context, ratio };
361
362
  }
362
363
 
@@ -1,15 +1,112 @@
1
1
  import { min, max } from 'd3-array';
2
2
  import { DataComponent as DC } from '../runtime';
3
- import { tagCloud } from './utils/d3-cloud';
4
3
  import { flow } from './utils/flow';
4
+ import { tagCloud } from './utils/d3-cloud';
5
5
 
6
- export type WordCloudOptions = Omit<Record<string, any>, 'type'>;
6
+ type Callable<T> = T | ((datum: any, i: number) => T);
7
+
8
+ /**
9
+ * See the document here: https://github.com/jasondavies/d3-cloud.
10
+ */
11
+ export type WordCloudOptions = {
12
+ /**
13
+ * Internally, the layout uses setInterval to avoid locking up the browser’s event loop.
14
+ * If specified, time is the maximum amount of time that can be spent during the current timestep.
15
+ * If not specified, returns the current maximum time interval, which defaults to Infinity.
16
+ */
17
+ timeInterval: number;
18
+ /**
19
+ * If specified, sets the words array. If not specified, returns the current words array, which defaults to [].
20
+ */
21
+ words: any[];
22
+ /**
23
+ * If specified, sets the rectangular [width, height] of the layout.
24
+ * If not specified, returns the current size, which defaults to [1, 1].
25
+ */
26
+ size: [number, number];
27
+ /**
28
+ * If specified, sets the font accessor function, which indicates the font face for each word.
29
+ * If not specified, returns the current font accessor function, which defaults to "serif".
30
+ * A constant may be specified instead of a function.
31
+ */
32
+ font: Callable<CSSStyleDeclaration['fontFamily']>;
33
+ /**
34
+ * TODO: Cname of font.
35
+ */
36
+ fontFamily: Callable<CSSStyleDeclaration['fontFamily']>;
37
+ /**
38
+ * If specified, sets the fontStyle accessor function, which indicates the font style for each word.
39
+ * If not specified, returns the current fontStyle accessor function, which defaults to "normal".
40
+ * A constant may be specified instead of a function.
41
+ */
42
+ fontStyle: Callable<CSSStyleDeclaration['fontFamily']>;
43
+ /**
44
+ * If specified, sets the fontWeight accessor function, which indicates the font weight for each word.
45
+ * If not specified, returns the current fontWeight accessor function, which defaults to "normal".
46
+ * A constant may be specified instead of a function.
47
+ */
48
+ fontWeight: Callable<CSSStyleDeclaration['fontFamily']>;
49
+ /**
50
+ * If specified, sets the fontSize accessor function, which indicates the numerical font size for each word.
51
+ * If not specified, returns the current fontSize accessor function, which defaults to:
52
+ *
53
+ * > function(d) { return Math.sqrt(d.value); }
54
+ *
55
+ * A constant may be specified instead of a function.
56
+ *
57
+ * If the fontSize is an array, it will be normalized to the range of [min, max] of the data value.
58
+ * If the fontSize is a function, it will be called with the data value.
59
+ * If the fontSize is a number, it will be used as the constant value.
60
+ */
61
+ fontSize: number | [number, number] | ((d: any) => number);
62
+ /**
63
+ * If specified, sets the rotate accessor function, which indicates the rotation angle (in degrees) for each word.
64
+ * If not specified, returns the current rotate accessor function, which defaults to:
65
+ *
66
+ * function() { return (~~(Math.random() * 6) - 3) * 30; }
67
+ *
68
+ * A constant may be specified instead of a function.
69
+ */
70
+ rotate: Callable<number>;
71
+ /**
72
+ * If specified, sets the text accessor function, which indicates the text for each word.
73
+ * If not specified, returns the current text accessor function, which defaults to:
74
+ *
75
+ * function(d) { return d.text; }
76
+ *
77
+ * A constant may be specified instead of a function.
78
+ */
79
+ text: Callable<string>;
80
+ /**
81
+ * If specified, sets the padding accessor function, which indicates the numerical padding for each word.
82
+ * If not specified, returns the current padding, which defaults to 1.
83
+ */
84
+ padding: Callable<number>;
85
+
86
+ /**
87
+ * If specified, sets the internal random number generator, used for selecting the initial position of each word,
88
+ * and the clockwise/counterclockwise direction of the spiral for each word.
89
+ * This should return a number in the range [0, 1).
90
+ * If not specified, returns the current random number generator, which defaults to Math.random.
91
+ */
92
+ random: () => number;
93
+ spiral: any;
94
+ };
7
95
 
8
- const DEFAULT_OPTIONS: Partial<WordCloudOptions> = {
9
- size: [500, 500],
10
- fontSize: [14, 28],
96
+ const DEFAULT_OPTIONS = {
97
+ fontSize: [20, 60],
98
+ font: 'Impact',
99
+ padding: 2,
100
+ rotate: function () {
101
+ return (~~(Math.random() * 6) - 3) * 30;
102
+ },
11
103
  };
12
104
 
105
+ /**
106
+ * Process the image mask of wordCloud.
107
+ * @param img
108
+ * @returns
109
+ */
13
110
  export function processImageMask(
14
111
  img: HTMLImageElement | string,
15
112
  ): Promise<HTMLImageElement> {
@@ -33,6 +130,12 @@ export function processImageMask(
33
130
  });
34
131
  }
35
132
 
133
+ /**
134
+ * normalize fontSize range to d3-cloud fontSize function.
135
+ * @param fontSize
136
+ * @param range
137
+ * @returns
138
+ */
36
139
  export function normalizeFontSize(fontSize: any, range?: [number, number]) {
37
140
  if (typeof fontSize === 'function') return fontSize;
38
141
 
@@ -48,7 +151,7 @@ export function normalizeFontSize(fontSize: any, range?: [number, number]) {
48
151
  return () => fontSize;
49
152
  }
50
153
 
51
- export const WordCloud: DC<WordCloudOptions> = (options) => {
154
+ export const WordCloud: DC<Partial<WordCloudOptions>> = (options) => {
52
155
  return async (data) => {
53
156
  const cloudOptions = Object.assign({}, DEFAULT_OPTIONS, options);
54
157
  const layout = tagCloud();
@@ -80,12 +183,14 @@ export const WordCloud: DC<WordCloudOptions> = (options) => {
80
183
  { x: 0, y: 0 },
81
184
  { x: cw, y: ch },
82
185
  ];
186
+
83
187
  const { _bounds: bounds = defaultBounds, _tags, hasImage } = result;
84
188
 
85
- const tags = _tags.map(({ x, y, ...rest }) => ({
189
+ const tags = _tags.map(({ x, y, font, ...rest }) => ({
86
190
  ...rest,
87
191
  x: x + cw / 2,
88
192
  y: y + ch / 2,
193
+ fontFamily: font,
89
194
  }));
90
195
 
91
196
  // Append two data to replace the corner of top-left and bottom-right, avoid calculate the actual bounds will occur some error.
@@ -613,16 +613,21 @@ export function brushHighlight(
613
613
  clonedElement.set(element, cloned);
614
614
  return cloned;
615
615
  };
616
+
617
+ // Create a clipPath shared between all children.
618
+ const clipPath = new Rect({
619
+ style: {
620
+ x: x + ordinalX,
621
+ y: y + ordinalY,
622
+ width: x1 - x,
623
+ height: y1 - y,
624
+ },
625
+ });
626
+ root.appendChild(clipPath);
627
+
616
628
  for (const element of elements) {
617
629
  const cloned = clonedElement.get(element) || clone(element);
618
- cloned.style.clipPath = new Rect({
619
- style: {
620
- x: x + ordinalX,
621
- y: y + ordinalY,
622
- width: x1 - x,
623
- height: y1 - y,
624
- },
625
- });
630
+ cloned.style.clipPath = clipPath;
626
631
  setState(element, 'inactive');
627
632
  setState(cloned, 'active');
628
633
  }
@@ -0,0 +1,61 @@
1
+ import { DisplayObject } from '@antv/g';
2
+ import { LabelTransformComponent as LLC } from '../runtime';
3
+ import { ExceedAdjustLabel } from '../spec';
4
+ import { Bounds } from '../utils/bounds';
5
+ import { show } from '../utils/style';
6
+
7
+ const adjustPosition = (target: Bounds, edge: Bounds) => {
8
+ const [[minEdgeX, minEdgeY], [maxEdgeX, maxEdgeY]] = edge;
9
+ const [[minX, minY], [maxX, maxY]] = target;
10
+
11
+ let changeX = 0,
12
+ changeY = 0;
13
+
14
+ // x-axis
15
+ if (minX < minEdgeX) {
16
+ changeX = minEdgeX - minX;
17
+ } else if (maxX > maxEdgeX) {
18
+ changeX = maxEdgeX - maxX;
19
+ }
20
+
21
+ // y-axis
22
+ if (minY < minEdgeY) {
23
+ changeY = minEdgeY - minY;
24
+ } else if (maxY > maxEdgeY) {
25
+ changeY = maxEdgeY - maxY;
26
+ }
27
+
28
+ return [changeX, changeY];
29
+ };
30
+
31
+ export type ExceedAdjustOptions = Omit<ExceedAdjustLabel, 'type'>;
32
+
33
+ /**
34
+ * adjust the label when exceed the plot
35
+ */
36
+ export const ExceedAdjust: LLC<ExceedAdjustOptions> = () => {
37
+ return (labels: DisplayObject[], { canvas }) => {
38
+ const { width, height } = canvas.getConfig();
39
+
40
+ labels.forEach((l) => {
41
+ show(l);
42
+ const { max, min } = l.getRenderBounds();
43
+ const [xMax, yMax] = max,
44
+ [xMin, yMin] = min;
45
+ const changeValue = adjustPosition(
46
+ [
47
+ [xMin, yMin],
48
+ [xMax, yMax],
49
+ ],
50
+ [
51
+ [0, 0],
52
+ [width, height],
53
+ ],
54
+ );
55
+ l.style.x += changeValue[0];
56
+ l.style.y += changeValue[1];
57
+ });
58
+
59
+ return labels;
60
+ };
61
+ };
@@ -2,8 +2,10 @@ export { OverlapHide } from './overlapHide';
2
2
  export { OverlapDodgeY } from './overlapDodgeY';
3
3
  export { ContrastReverse } from './contrastReverse';
4
4
  export { OverflowHide } from './overflowHide';
5
+ export { ExceedAdjust } from './exceedAdjust';
5
6
 
6
7
  export type { OverlapHideOptions } from './overlapHide';
7
8
  export type { OverlapDodgeYOptions } from './overlapDodgeY';
8
9
  export type { ContrastReverseOptions } from './contrastReverse';
9
10
  export type { OverflowHideOptions } from './overflowHide';
11
+ export type { ExceedAdjustOptions } from './exceedAdjust';
package/src/lib/core.ts CHANGED
@@ -32,6 +32,7 @@ import {
32
32
  Shape,
33
33
  Density,
34
34
  Heatmap,
35
+ WordCloud as WordCloudGeometry,
35
36
  } from '../mark';
36
37
  import { Category10, Category20 } from '../palette';
37
38
  import {
@@ -153,12 +154,14 @@ import {
153
154
  Sort as DataSort,
154
155
  KDE as DataKDE,
155
156
  Log as DataLog,
157
+ WordCloud,
156
158
  } from '../data';
157
159
  import {
158
160
  OverlapDodgeY,
159
161
  OverflowHide,
160
162
  ContrastReverse,
161
163
  OverlapHide,
164
+ ExceedAdjust,
162
165
  } from '../label-transform';
163
166
 
164
167
  export function corelib() {
@@ -177,6 +180,7 @@ export function corelib() {
177
180
  'data.join': DataJoin,
178
181
  'data.kde': DataKDE,
179
182
  'data.log': DataLog,
183
+ 'data.wordCloud': WordCloud,
180
184
  'transform.stackY': StackY,
181
185
  'transform.binX': BinX,
182
186
  'transform.bin': Bin,
@@ -236,6 +240,7 @@ export function corelib() {
236
240
  'mark.shape': Shape,
237
241
  'mark.density': Density,
238
242
  'mark.heatmap': Heatmap,
243
+ 'mark.wordCloud': WordCloudGeometry,
239
244
  'palette.category10': Category10,
240
245
  'palette.category20': Category20,
241
246
  'scale.linear': ScaleLinear,
@@ -313,5 +318,6 @@ export function corelib() {
313
318
  'labelTransform.overlapDodgeY': OverlapDodgeY,
314
319
  'labelTransform.overflowHide': OverflowHide,
315
320
  'labelTransform.contrastReverse': ContrastReverse,
321
+ 'labelTransform.exceedAdjust': ExceedAdjust,
316
322
  } as const;
317
323
  }
package/src/mark/text.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { MarkComponent as MC, Vector2, Mark } from '../runtime';
2
2
  import { TextMark } from '../spec';
3
- import { TextShape, TextBadge } from '../shape';
3
+ import { TextShape, TextBadge, TextTag } from '../shape';
4
4
  import { MaybeTuple, MaybeVisualPosition } from '../transform';
5
5
  import {
6
6
  baseGeometryChannels,
@@ -14,6 +14,7 @@ import {
14
14
  const shape = {
15
15
  text: TextShape,
16
16
  badge: TextBadge,
17
+ tag: TextTag,
17
18
  };
18
19
 
19
20
  export type TextOptions = Omit<TextMark, 'type'>;
@@ -42,8 +43,8 @@ Text.props = {
42
43
  { name: 'x', required: true },
43
44
  { name: 'y', required: true },
44
45
  { name: 'text', scale: 'identity' },
45
- { name: 'fontSize' },
46
- { name: 'rotate' },
46
+ { name: 'fontSize', scale: 'identity' },
47
+ { name: 'rotate', scale: 'identity' },
47
48
  ],
48
49
  preInference: [
49
50
  ...basePreInference(),
@@ -1,7 +1,6 @@
1
1
  import { deepMix } from '@antv/util';
2
2
  import { CompositeMarkComponent as CC } from '../runtime';
3
3
  import { WordCloudMark } from '../spec';
4
- import { WordCloud as WordCloudTransform } from '../data';
5
4
 
6
5
  export type WordCloudOptions = Omit<WordCloudMark, 'type'>;
7
6
 
@@ -14,11 +13,7 @@ function initializeData(data, encode) {
14
13
  }));
15
14
  }
16
15
 
17
- const GET_DEFAULT_LAYOUT_OPTIONS = (width, height) => ({
18
- size: [width, height],
19
- });
20
-
21
- const GET_DEFAULT_OPTIONS = (width, height) => ({
16
+ const GET_DEFAULT_OPTIONS = () => ({
22
17
  axis: false,
23
18
  type: 'text',
24
19
  encode: {
@@ -27,15 +22,14 @@ const GET_DEFAULT_OPTIONS = (width, height) => ({
27
22
  text: 'text',
28
23
  rotate: 'rotate',
29
24
  fontSize: 'size',
25
+ shape: 'tag',
30
26
  },
31
27
  scale: {
32
- x: { domain: [0, width], range: [0, 1] },
33
- y: { domain: [0, height], range: [0, 1] },
34
- fontSize: { type: 'identity' },
35
- rotate: { type: 'identity' },
28
+ x: { range: [0, 1] },
29
+ y: { range: [0, 1] },
36
30
  },
37
31
  style: {
38
- textAlign: 'center',
32
+ fontFamily: (d) => d.fontFamily,
39
33
  },
40
34
  });
41
35
 
@@ -53,13 +47,17 @@ export const WordCloud: CC<WordCloudOptions> = async (options, context) => {
53
47
 
54
48
  const initializedData = initializeData(data, encode);
55
49
 
56
- const transformData = await WordCloudTransform({
57
- ...GET_DEFAULT_LAYOUT_OPTIONS(width, height),
58
- ...layout,
59
- })(initializedData);
60
-
61
- return deepMix({}, GET_DEFAULT_OPTIONS(width, height), {
62
- data: transformData,
50
+ return deepMix({}, GET_DEFAULT_OPTIONS(), {
51
+ data: {
52
+ value: initializedData,
53
+ transform: [
54
+ {
55
+ type: 'wordCloud',
56
+ size: [width, height],
57
+ ...layout,
58
+ },
59
+ ],
60
+ },
63
61
  encode,
64
62
  scale,
65
63
  style,
@@ -6,6 +6,7 @@ import { format } from 'd3-format';
6
6
  import { mapObject } from '../utils/array';
7
7
  import { ChartEvent } from '../utils/event';
8
8
  import {
9
+ isStrictObject,
9
10
  appendTransform,
10
11
  compose,
11
12
  copyAttributes,
@@ -1220,15 +1221,20 @@ function plotLabel(
1220
1221
  labelDescriptor.get(d.__data__),
1221
1222
  );
1222
1223
  const { coordinate } = view;
1224
+
1225
+ const labelTransformContext = {
1226
+ canvas: context.canvas,
1227
+ coordinate,
1228
+ };
1223
1229
  for (const [label, shapes] of labelGroups) {
1224
1230
  const { transform = [] } = label;
1225
1231
  const transformFunction = compose(transform.map(useLabelTransform));
1226
- transformFunction(shapes, coordinate);
1232
+ transformFunction(shapes, labelTransformContext);
1227
1233
  }
1228
1234
 
1229
1235
  // Apply view-level transform.
1230
1236
  if (labelTransform) {
1231
- labelTransform(labelShapes, coordinate);
1237
+ labelTransform(labelShapes, labelTransformContext);
1232
1238
  }
1233
1239
  }
1234
1240
 
@@ -1378,7 +1384,7 @@ function valueOf(
1378
1384
  ) {
1379
1385
  if (typeof value === 'function') return value(datum, i, data);
1380
1386
  if (typeof value !== 'string') return value;
1381
- if (datum[value] !== undefined) return datum[value];
1387
+ if (isStrictObject(datum) && datum[value] !== undefined) return datum[value];
1382
1388
  return value;
1383
1389
  }
1384
1390
 
@@ -1,6 +1,11 @@
1
1
  import { Coordinate, Transformation } from '@antv/coord';
2
2
  import EventEmitter from '@antv/event-emitter';
3
- import { DisplayObject, IAnimation as GAnimation, IDocument } from '@antv/g';
3
+ import {
4
+ DisplayObject,
5
+ IAnimation as GAnimation,
6
+ IDocument,
7
+ Canvas,
8
+ } from '@antv/g';
4
9
  import {
5
10
  G2Theme,
6
11
  G2ViewInstance,
@@ -225,7 +230,10 @@ export type CompositionComponent<O = Record<string, unknown>> = G2BaseComponent<
225
230
 
226
231
  export type LabelTransform = (
227
232
  labels: DisplayObject[],
228
- coordinate: Coordinate,
233
+ context: {
234
+ coordinate: Coordinate;
235
+ canvas: Canvas;
236
+ },
229
237
  ) => DisplayObject[];
230
238
  export type LabelTransformComponent<O = Record<string, unknown>> =
231
239
  G2BaseComponent<LabelTransform, O>;
@@ -34,6 +34,7 @@ export { Circle as PointCircle } from './point/circle';
34
34
  export { Vector as VectorShape } from './vector/vector';
35
35
  export { Text as TextShape } from './text/text';
36
36
  export { Badge as TextBadge } from './text/badge';
37
+ export { Tag as TextTag } from './text/tag';
37
38
  export { Area as AreaShape } from './area/area';
38
39
  export { Smooth as AreaSmooth } from './area/smooth';
39
40
  export { HVH as AreaHVH } from './area/hvh';
@@ -94,6 +95,7 @@ export type { TriangleDownOptions as PointTriangleDownOptions } from './point/tr
94
95
  export type { VectorOptions as VectorShapeOptions } from './vector/vector';
95
96
  export type { TextOptions as TextShapeOptions } from './text/text';
96
97
  export type { BadgeOptions as TextBadgeOptions } from './text/badge';
98
+ export type { TagOptions as TextTagOptions } from './text/tag';
97
99
  export type { AreaOptions as AreaShapeOptions } from './area/area';
98
100
  export type { SmoothOptions as AreaSmoothOptions } from './area/smooth';
99
101
  export type { HVHOptions as AreaHVHAreaOptions } from './area/hvh';