@visactor/vrender-components 0.13.7 → 0.13.8-alpha.1

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 (53) hide show
  1. package/cjs/index.d.ts +1 -1
  2. package/cjs/index.js +1 -1
  3. package/cjs/index.js.map +1 -1
  4. package/cjs/label/base.d.ts +12 -10
  5. package/cjs/label/base.js +76 -55
  6. package/cjs/label/base.js.map +1 -1
  7. package/cjs/label/overlap/place.d.ts +8 -4
  8. package/cjs/label/overlap/place.js +14 -2
  9. package/cjs/label/overlap/place.js.map +1 -1
  10. package/cjs/label/rect.d.ts +5 -3
  11. package/cjs/label/rect.js.map +1 -1
  12. package/cjs/label/symbol.d.ts +5 -3
  13. package/cjs/label/symbol.js.map +1 -1
  14. package/cjs/label/type.d.ts +11 -7
  15. package/cjs/label/type.js.map +1 -1
  16. package/cjs/marker/type.d.ts +0 -1
  17. package/cjs/marker/type.js.map +1 -1
  18. package/cjs/segment/segment.js +4 -1
  19. package/cjs/segment/segment.js.map +1 -1
  20. package/cjs/segment/type.d.ts +1 -0
  21. package/cjs/segment/type.js.map +1 -1
  22. package/cjs/tag/tag.js +2 -2
  23. package/cjs/tag/tag.js.map +1 -1
  24. package/cjs/tag/type.d.ts +0 -1
  25. package/cjs/tag/type.js.map +1 -1
  26. package/dist/index.js +138 -79
  27. package/dist/index.min.js +1 -1
  28. package/es/index.d.ts +1 -1
  29. package/es/index.js +1 -1
  30. package/es/index.js.map +1 -1
  31. package/es/label/base.d.ts +12 -10
  32. package/es/label/base.js +77 -57
  33. package/es/label/base.js.map +1 -1
  34. package/es/label/overlap/place.d.ts +8 -4
  35. package/es/label/overlap/place.js +11 -0
  36. package/es/label/overlap/place.js.map +1 -1
  37. package/es/label/rect.d.ts +5 -3
  38. package/es/label/rect.js.map +1 -1
  39. package/es/label/symbol.d.ts +5 -3
  40. package/es/label/symbol.js.map +1 -1
  41. package/es/label/type.d.ts +11 -7
  42. package/es/label/type.js.map +1 -1
  43. package/es/marker/type.d.ts +0 -1
  44. package/es/marker/type.js.map +1 -1
  45. package/es/segment/segment.js +4 -1
  46. package/es/segment/segment.js.map +1 -1
  47. package/es/segment/type.d.ts +1 -0
  48. package/es/segment/type.js.map +1 -1
  49. package/es/tag/tag.js +2 -2
  50. package/es/tag/tag.js.map +1 -1
  51. package/es/tag/type.d.ts +0 -1
  52. package/es/tag/type.js.map +1 -1
  53. package/package.json +2 -2
package/cjs/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const version = "0.13.7";
1
+ export declare const version = "0.13.8-alpha.1";
2
2
  export * from './core/base';
3
3
  export * from './scrollbar';
4
4
  export * from './tag';
package/cjs/index.js CHANGED
@@ -17,7 +17,7 @@ var __createBinding = this && this.__createBinding || (Object.create ? function(
17
17
 
18
18
  Object.defineProperty(exports, "__esModule", {
19
19
  value: !0
20
- }), exports.version = void 0, exports.version = "0.13.7", __exportStar(require("./core/base"), exports),
20
+ }), exports.version = void 0, exports.version = "0.13.8-alpha.1", __exportStar(require("./core/base"), exports),
21
21
  __exportStar(require("./scrollbar"), exports), __exportStar(require("./tag"), exports),
22
22
  __exportStar(require("./poptip"), exports), __exportStar(require("./crosshair"), exports),
23
23
  __exportStar(require("./label"), exports), __exportStar(require("./axis"), exports),
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACa,QAAA,OAAO,GAAG,QAAQ,CAAC;AAEhC,8CAA4B;AAC5B,8CAA4B;AAC5B,wCAAsB;AACtB,2CAAyB;AACzB,8CAA4B;AAC5B,0CAAwB;AACxB,yCAAuB;AACvB,4CAA0B;AAC1B,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB;AACxB,2CAAyB;AACzB,0CAAwB;AACxB,8CAA4B;AAC5B,2CAAyB;AACzB,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB;AACxB,4CAA0B;AAC1B,8CAA4B","file":"index.js","sourcesContent":["// 导出版本号\nexport const version = \"0.13.7\";\n\nexport * from './core/base';\nexport * from './scrollbar';\nexport * from './tag';\nexport * from './poptip';\nexport * from './crosshair';\nexport * from './label';\nexport * from './axis';\nexport * from './segment';\nexport * from './data-zoom';\nexport * from './marker';\nexport * from './pager';\nexport * from './legend';\nexport * from './title';\nexport * from './indicator';\nexport * from './slider';\nexport * from './link-path';\nexport * from './player';\nexport * from './brush';\nexport * from './tooltip';\nexport * from './interface';\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACa,QAAA,OAAO,GAAG,gBAAgB,CAAC;AAExC,8CAA4B;AAC5B,8CAA4B;AAC5B,wCAAsB;AACtB,2CAAyB;AACzB,8CAA4B;AAC5B,0CAAwB;AACxB,yCAAuB;AACvB,4CAA0B;AAC1B,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB;AACxB,2CAAyB;AACzB,0CAAwB;AACxB,8CAA4B;AAC5B,2CAAyB;AACzB,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB;AACxB,4CAA0B;AAC1B,8CAA4B","file":"index.js","sourcesContent":["// 导出版本号\nexport const version = \"0.13.8-alpha.1\";\n\nexport * from './core/base';\nexport * from './scrollbar';\nexport * from './tag';\nexport * from './poptip';\nexport * from './crosshair';\nexport * from './label';\nexport * from './axis';\nexport * from './segment';\nexport * from './data-zoom';\nexport * from './marker';\nexport * from './pager';\nexport * from './legend';\nexport * from './title';\nexport * from './indicator';\nexport * from './slider';\nexport * from './link-path';\nexport * from './player';\nexport * from './brush';\nexport * from './tooltip';\nexport * from './interface';\n"]}
@@ -4,7 +4,7 @@ import { AbstractComponent } from '../core/base';
4
4
  import type { PointLocationCfg } from '../core/type';
5
5
  import type { Bitmap } from './overlap';
6
6
  import { bitmapTool } from './overlap';
7
- import type { BaseLabelAttrs, OverlapAttrs, ILabelGraphicAttribute, ILabelAnimation } from './type';
7
+ import type { BaseLabelAttrs, ILabelAnimation, LabelItem } from './type';
8
8
  export declare abstract class LabelBase<T extends BaseLabelAttrs> extends AbstractComponent<T> {
9
9
  name: string;
10
10
  protected _baseMarks?: IGraphic[];
@@ -12,14 +12,16 @@ export declare abstract class LabelBase<T extends BaseLabelAttrs> extends Abstra
12
12
  setBitmap(bitmap: Bitmap): void;
13
13
  protected _bmpTool?: ReturnType<typeof bitmapTool>;
14
14
  setBitmapTool(bmpTool: ReturnType<typeof bitmapTool>): void;
15
- protected _relationMap: Map<number, IGraphic>;
16
- protected _prevRelationMap: Map<number, IGraphic>;
17
- protected _textMap: Map<IGraphic, IText>;
15
+ protected _graphicToText: Map<IGraphic, IText>;
16
+ protected _idToGraphic: Map<string, IGraphic>;
18
17
  onAfterLabelOverlap?: (bitmap: Bitmap) => void;
19
18
  private _lastHover;
20
19
  private _lastSelect;
21
20
  private _enableAnimation;
22
- protected abstract labeling(textBounds: IBoundsLike, graphicBounds: IBoundsLike, position?: BaseLabelAttrs['position'], offset?: number): Partial<ILabelGraphicAttribute> | undefined;
21
+ protected abstract labeling(textBounds: IBoundsLike, graphicBounds: IBoundsLike, position?: BaseLabelAttrs['position'], offset?: number): {
22
+ x: number;
23
+ y: number;
24
+ } | undefined;
23
25
  protected render(): void;
24
26
  private _bindEvent;
25
27
  private _setStates;
@@ -27,17 +29,17 @@ export declare abstract class LabelBase<T extends BaseLabelAttrs> extends Abstra
27
29
  private _onUnHover;
28
30
  private _onClick;
29
31
  private _createLabelText;
30
- private _checkMarks;
31
- protected layout(currentMarks?: IGraphic[]): ILabelGraphicAttribute[];
32
- protected overlapping(labels: ILabelGraphicAttribute[], option?: OverlapAttrs): ILabelGraphicAttribute[];
32
+ private _prepare;
33
+ protected layout(data?: LabelItem[]): IText[];
34
+ protected _overlapping(labels: IText[]): IText[];
33
35
  protected getBaseMarks(): IGraphic<Partial<import("@visactor/vrender").IGraphicAttribute>>[];
34
36
  protected getBaseMarkGroup(): IGroup;
35
37
  protected getGraphicBounds(graphic?: IGraphic, point?: Partial<PointLocationCfg>): IBoundsLike;
36
- protected _renderLabels(labels: ILabelGraphicAttribute[]): void;
38
+ protected _renderLabels(labels: IText[]): void;
37
39
  protected _afterRelatedGraphicAttributeUpdate(text: IText, texts: IText[], index: number, relatedGraphic: IGraphic, { mode, duration, easing, to, delay }: ILabelAnimation & {
38
40
  to: any;
39
41
  }): (event: any) => {};
40
- protected _smartInvert(labels: ILabelGraphicAttribute[]): void;
42
+ protected _smartInvert(labels: IText[]): void;
41
43
  setLocation(point: PointLocationCfg): void;
42
44
  disableAnimation(): void;
43
45
  enableAnimation(): void;
package/cjs/label/base.js CHANGED
@@ -39,8 +39,12 @@ class LabelBase extends base_1.AbstractComponent {
39
39
  this._bmpTool = bmpTool;
40
40
  }
41
41
  render() {
42
- const currentBaseMarks = this._checkMarks(), labels = this.layout(currentBaseMarks);
43
- this._smartInvert(labels), this._renderLabels(labels);
42
+ this._prepare();
43
+ const {overlap: overlap, smartInvert: smartInvert, dataFilter: dataFilter, customLayoutFunc: customLayoutFunc, customOverlapFunc: customOverlapFunc} = this.attribute;
44
+ let labels, data = this.attribute.data;
45
+ (0, vutils_1.isFunction)(dataFilter) && (data = dataFilter(data)), (0, vutils_1.isFunction)(customLayoutFunc) ? labels = customLayoutFunc(data, (d => this._idToGraphic.get(d.id))) : (labels = this.layout(data),
46
+ (0, vutils_1.isFunction)(customOverlapFunc) ? labels = customOverlapFunc(labels, (d => this._idToGraphic.get(d.id))) : !1 !== overlap && (labels = this._overlapping(labels))),
47
+ !1 !== smartInvert && this._smartInvert(labels), this._renderLabels(labels);
44
48
  }
45
49
  _bindEvent(target) {
46
50
  if (!target) return;
@@ -57,43 +61,39 @@ class LabelBase extends base_1.AbstractComponent {
57
61
  const text = (0, vrender_1.createText)(attributes);
58
62
  return this._bindEvent(text), this._setStates(text), text;
59
63
  }
60
- _checkMarks() {
64
+ _prepare() {
61
65
  var _a;
62
66
  const baseMarks = this.getBaseMarks(), currentBaseMarks = [];
63
- return baseMarks.forEach((mark => {
67
+ if (baseMarks.forEach((mark => {
64
68
  "willRelease" !== mark.releaseStatus && currentBaseMarks.push(mark);
65
- })), this._prevRelationMap = new Map(this._relationMap), null === (_a = this._relationMap) || void 0 === _a || _a.clear(),
66
- currentBaseMarks;
67
- }
68
- layout(currentMarks) {
69
- const {textStyle: textStyle, position: position, offset: offset} = this.attribute;
70
- let {data: data} = this.attribute;
71
- if ((0, vutils_1.isFunction)(data) && (data = data({})), !data || 0 === data.length) return [];
72
- let labels = [];
73
- (0, vutils_1.isFunction)(this.attribute.sort) && currentMarks && currentMarks.length && (currentMarks = currentMarks.sort(this.attribute.sort)),
74
- this._relationMap || (this._relationMap = new Map);
75
- for (let i = 0; i < data.length; i++) {
76
- const textData = data[i], baseMark = null == currentMarks ? void 0 : currentMarks[i], labelAttribute = Object.assign(Object.assign(Object.assign({}, textStyle), textData), {
77
- _relatedIndex: i
78
- });
79
- if (this._relationMap.set(i, baseMark), textData) {
80
- const text = (0, vrender_1.createText)(labelAttribute);
81
- text.update();
82
- const textBounds = this.getGraphicBounds(text), graphicBounds = this.getGraphicBounds(baseMark, {
83
- x: textData.x,
84
- y: textData.y
85
- }), textAttributes = this.labeling(textBounds, graphicBounds, (0, vutils_1.isFunction)(position) ? position(textData) : position, offset);
86
- if (!textAttributes) continue;
87
- labelAttribute.x = textAttributes.x, labelAttribute.y = textAttributes.y, labels.push(labelAttribute);
69
+ })), null === (_a = this._idToGraphic) || void 0 === _a || _a.clear(), this._baseMarks = currentBaseMarks,
70
+ !currentBaseMarks || 0 === currentBaseMarks.length) return;
71
+ const {data: data} = this.attribute;
72
+ if (data && 0 !== data.length) {
73
+ this._idToGraphic || (this._idToGraphic = new Map);
74
+ for (let i = 0; i < currentBaseMarks.length; i++) {
75
+ const textData = data[i], baseMark = currentBaseMarks[i];
76
+ textData && baseMark && ((0, vutils_1.isValid)(textData.id) || (textData.id = `vrender-component-${this.name}-${i}`),
77
+ this._idToGraphic.set(textData.id, baseMark));
88
78
  }
89
79
  }
90
- return this._baseMarks = currentMarks, !1 !== this.attribute.overlap && (labels = this.overlapping(labels, this.attribute.overlap)),
91
- labels;
92
80
  }
93
- overlapping(labels, option = {}) {
94
- var _a, _b, _c, _d, _e;
81
+ layout(data = []) {
82
+ const {textStyle: textStyle = {}, position: position, offset: offset} = this.attribute, labels = [];
83
+ for (let i = 0; i < data.length; i++) {
84
+ const textData = data[i], baseMark = this._idToGraphic.get(textData.id), labelAttribute = Object.assign(Object.assign({}, textStyle), textData), text = this._createLabelText(labelAttribute), textBounds = this.getGraphicBounds(text), graphicBounds = this.getGraphicBounds(baseMark, {
85
+ x: textData.x,
86
+ y: textData.y
87
+ }), textLocation = this.labeling(textBounds, graphicBounds, (0, vutils_1.isFunction)(position) ? position(textData) : position, offset);
88
+ textLocation && (labelAttribute.x = textLocation.x, labelAttribute.y = textLocation.y,
89
+ text.setAttributes(textLocation), labels.push(text));
90
+ }
91
+ return labels;
92
+ }
93
+ _overlapping(labels) {
94
+ var _a, _b, _c, _d;
95
95
  if (0 === labels.length) return [];
96
- const result = [], baseMarkGroup = this.getBaseMarkGroup(), size = null !== (_a = option.size) && void 0 !== _a ? _a : {
96
+ const option = this.attribute.overlap, result = [], baseMarkGroup = this.getBaseMarkGroup(), size = null !== (_a = option.size) && void 0 !== _a ? _a : {
97
97
  width: null !== (_b = null == baseMarkGroup ? void 0 : baseMarkGroup.AABBBounds.width()) && void 0 !== _b ? _b : 0,
98
98
  height: null !== (_c = null == baseMarkGroup ? void 0 : baseMarkGroup.AABBBounds.height()) && void 0 !== _c ? _c : 0
99
99
  };
@@ -105,27 +105,43 @@ class LabelBase extends base_1.AbstractComponent {
105
105
  })));
106
106
  for (let i = 0; i < labels.length; i++) {
107
107
  if (!1 === labels[i].visible) continue;
108
- const text = (0, vrender_1.createText)(labels[i]), baseMark = null === (_e = this._baseMarks) || void 0 === _e ? void 0 : _e[i];
108
+ const text = labels[i], baseMark = this._idToGraphic.get(text.attribute.id);
109
109
  if (text.update(), (0, overlap_1.canPlace)(bmpTool, bitmap, text.AABBBounds, clampForce)) {
110
110
  if (!checkBounds) {
111
- bitmap.setRange((0, overlap_1.boundToRange)(bmpTool, text.AABBBounds, !0)), result.push(Object.assign({}, text.attribute));
111
+ bitmap.setRange((0, overlap_1.boundToRange)(bmpTool, text.AABBBounds, !0)), result.push(text);
112
112
  continue;
113
113
  }
114
114
  if (checkBounds && (null == baseMark ? void 0 : baseMark.AABBBounds) && (0, overlap_1.canPlaceInside)(text.AABBBounds, null == baseMark ? void 0 : baseMark.AABBBounds)) {
115
- bitmap.setRange((0, overlap_1.boundToRange)(bmpTool, text.AABBBounds, !0)), result.push(Object.assign({}, text.attribute));
115
+ bitmap.setRange((0, overlap_1.boundToRange)(bmpTool, text.AABBBounds, !0)), result.push(text);
116
116
  continue;
117
117
  }
118
118
  }
119
119
  let hasPlace = !1;
120
120
  for (let j = 0; j < strategy.length; j++) if (hasPlace = (0, overlap_1.place)(bmpTool, bitmap, strategy[j], this.attribute, text, this.getGraphicBounds(baseMark, labels[i]), this.labeling),
121
121
  !1 !== hasPlace) {
122
- result.push(Object.assign(Object.assign({}, text.attribute), {
122
+ text.setAttributes({
123
123
  x: hasPlace.x,
124
124
  y: hasPlace.y
125
- }));
125
+ }), result.push(text);
126
126
  break;
127
127
  }
128
- !hasPlace && !hideOnHit && result.push(Object.assign({}, text.attribute));
128
+ if (clampForce) {
129
+ const {dx: dx = 0, dy: dy = 0} = (0, overlap_1.clampText)(text, bmpTool.width, bmpTool.height);
130
+ if ((0 !== dx || 0 !== dy) && (0, overlap_1.canPlace)(bmpTool, bitmap, {
131
+ x1: text.AABBBounds.x1 + dx,
132
+ x2: text.AABBBounds.x2 + dx,
133
+ y1: text.AABBBounds.y1 + dy,
134
+ y2: text.AABBBounds.y2 + dy
135
+ })) {
136
+ text.setAttributes({
137
+ x: text.attribute.x + dx,
138
+ y: text.attribute.y + dy
139
+ }), bitmap.setRange((0, overlap_1.boundToRange)(bmpTool, text.AABBBounds, !0)),
140
+ result.push(text);
141
+ continue;
142
+ }
143
+ }
144
+ !hasPlace && !hideOnHit && result.push(text);
129
145
  }
130
146
  return (0, vutils_1.isFunction)(this.onAfterLabelOverlap) && this.onAfterLabelOverlap(bitmap),
131
147
  result;
@@ -148,12 +164,12 @@ class LabelBase extends base_1.AbstractComponent {
148
164
  }
149
165
  _renderLabels(labels) {
150
166
  var _a, _b, _c, _d, _e;
151
- const animationConfig = null !== (_a = this.attribute.animation) && void 0 !== _a ? _a : {}, disableAnimation = !1 === this._enableAnimation || !1 === animationConfig, mode = null !== (_b = animationConfig.mode) && void 0 !== _b ? _b : animate_1.DefaultLabelAnimation.mode, duration = null !== (_c = animationConfig.duration) && void 0 !== _c ? _c : animate_1.DefaultLabelAnimation.duration, easing = null !== (_d = animationConfig.easing) && void 0 !== _d ? _d : animate_1.DefaultLabelAnimation.easing, delay = null !== (_e = animationConfig.delay) && void 0 !== _e ? _e : 0, currentTextMap = new Map, prevTextMap = this._textMap || new Map, texts = [];
152
- labels.forEach(((label, index) => {
153
- const text = this._createLabelText(label), relatedGraphic = this._relationMap.get(label._relatedIndex), state = (null == prevTextMap ? void 0 : prevTextMap.get(relatedGraphic)) ? "update" : "enter";
167
+ const animationConfig = null !== (_a = this.attribute.animation) && void 0 !== _a ? _a : {}, disableAnimation = !1 === this._enableAnimation || !1 === animationConfig, mode = null !== (_b = animationConfig.mode) && void 0 !== _b ? _b : animate_1.DefaultLabelAnimation.mode, duration = null !== (_c = animationConfig.duration) && void 0 !== _c ? _c : animate_1.DefaultLabelAnimation.duration, easing = null !== (_d = animationConfig.easing) && void 0 !== _d ? _d : animate_1.DefaultLabelAnimation.easing, delay = null !== (_e = animationConfig.delay) && void 0 !== _e ? _e : 0, currentTextMap = new Map, prevTextMap = this._graphicToText || new Map, texts = [];
168
+ labels.forEach(((text, index) => {
169
+ const relatedGraphic = this._idToGraphic.get(text.attribute.id), state = (null == prevTextMap ? void 0 : prevTextMap.get(relatedGraphic)) ? "update" : "enter";
154
170
  if ("enter" === state) if (texts.push(text), currentTextMap.set(relatedGraphic, text),
155
171
  !disableAnimation && relatedGraphic) {
156
- const {from: from, to: to} = (0, animate_1.getAnimationAttributes)(label, "fadeIn");
172
+ const {from: from, to: to} = (0, animate_1.getAnimationAttributes)(text.attribute, "fadeIn");
157
173
  this.add(text), relatedGraphic.onAnimateBind = () => {
158
174
  text.setAttributes(from);
159
175
  const listener = this._afterRelatedGraphicAttributeUpdate(text, texts, index, relatedGraphic, {
@@ -182,7 +198,7 @@ class LabelBase extends base_1.AbstractComponent {
182
198
  animate_1.getAnimationAttributes)(label.attribute, "fadeOut").to, duration, easing).onEnd((() => {
183
199
  this.removeChild(label);
184
200
  }));
185
- })), this._textMap = currentTextMap;
201
+ })), this._graphicToText = currentTextMap;
186
202
  }
187
203
  _afterRelatedGraphicAttributeUpdate(text, texts, index, relatedGraphic, {mode: mode, duration: duration, easing: easing, to: to, delay: delay}) {
188
204
  const listener = event => {
@@ -218,19 +234,24 @@ class LabelBase extends base_1.AbstractComponent {
218
234
  return listener;
219
235
  }
220
236
  _smartInvert(labels) {
221
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
222
- if (!1 !== this.attribute.smartInvert) for (let i = 0; i < labels.length; i++) {
223
- const label = null == labels ? void 0 : labels[i];
237
+ const option = this.attribute.smartInvert || {}, {textType: textType, contrastRatiosThreshold: contrastRatiosThreshold, alternativeColors: alternativeColors} = option;
238
+ for (let i = 0; i < labels.length; i++) {
239
+ const label = labels[i];
224
240
  if (!label) continue;
225
- const isInside = (0, overlap_1.canPlaceInside)((0, vrender_1.createText)(label).AABBBounds, null === (_a = this._relationMap.get(label._relatedIndex)) || void 0 === _a ? void 0 : _a.AABBBounds);
226
- if (label.stroke && label.lineWidth > 0) label.fill = (0, labelSmartInvert_1.labelSmartInvert)(label.fill, label.stroke, null === (_b = this.attribute.smartInvert) || void 0 === _b ? void 0 : _b.textType, null === (_c = this.attribute.smartInvert) || void 0 === _c ? void 0 : _c.contrastRatiosThreshold, null === (_d = this.attribute.smartInvert) || void 0 === _d ? void 0 : _d.alternativeColors); else if (isInside) {
227
- const backgroundColor = this._relationMap.get(label._relatedIndex).attribute.fill, foregroundColor = label.fill;
228
- label.fill = (0, labelSmartInvert_1.labelSmartInvert)(foregroundColor, backgroundColor, null === (_e = this.attribute.smartInvert) || void 0 === _e ? void 0 : _e.textType, null === (_f = this.attribute.smartInvert) || void 0 === _f ? void 0 : _f.contrastRatiosThreshold, null === (_g = this.attribute.smartInvert) || void 0 === _g ? void 0 : _g.alternativeColors);
229
- } else if (label.lineWidth > 0) {
230
- const baseMark = this._relationMap.get(label._relatedIndex);
231
- label.stroke = baseMark.attribute.fill;
232
- const backgroundColor = label.stroke, foregroundColor = label.fill;
233
- label.fill = (0, labelSmartInvert_1.labelSmartInvert)(foregroundColor, backgroundColor, null === (_h = this.attribute.smartInvert) || void 0 === _h ? void 0 : _h.textType, null === (_j = this.attribute.smartInvert) || void 0 === _j ? void 0 : _j.contrastRatiosThreshold, null === (_k = this.attribute.smartInvert) || void 0 === _k ? void 0 : _k.alternativeColors);
241
+ const baseMark = this._idToGraphic.get(label.attribute.id), isInside = (0, overlap_1.canPlaceInside)(label.AABBBounds, null == baseMark ? void 0 : baseMark.AABBBounds);
242
+ if (label.attribute.stroke && label.attribute.lineWidth > 0) label.setAttributes({
243
+ fill: (0, labelSmartInvert_1.labelSmartInvert)(label.attribute.fill, label.attribute.stroke, textType, contrastRatiosThreshold, alternativeColors)
244
+ }); else if (isInside) {
245
+ const backgroundColor = baseMark.attribute.fill, foregroundColor = label.attribute.fill;
246
+ label.setAttributes({
247
+ fill: (0, labelSmartInvert_1.labelSmartInvert)(foregroundColor, backgroundColor, textType, contrastRatiosThreshold, alternativeColors)
248
+ });
249
+ } else if (label.attribute.lineWidth > 0) {
250
+ const backgroundColor = label.attribute.stroke, foregroundColor = label.attribute.fill;
251
+ label.setAttributes({
252
+ stroke: baseMark.attribute.fill,
253
+ fill: (0, labelSmartInvert_1.labelSmartInvert)(foregroundColor, backgroundColor, textType, contrastRatiosThreshold, alternativeColors)
254
+ });
234
255
  }
235
256
  }
236
257
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["label/base.ts"],"names":[],"mappings":";;;AAIA,+CAAmF;AAEnF,6CAAsE;AACtE,uCAAiD;AAEjD,+DAA4D;AAC5D,kCAAwC;AACxC,0CAAyC;AAEzC,uCAAsF;AAEtF,+CAAkF;AAElF,MAAsB,SAAoC,SAAQ,wBAAoB;IAAtF;;QACE,SAAI,GAAG,OAAO,CAAC;QA0EP,aAAQ,GAAG,CAAC,CAAwB,EAAE,EAAE;YAC9C,MAAM,MAAM,GAAG,CAAC,CAAC,MAA6B,CAAC;YAC/C,IAAI,MAAM,KAAK,IAAI,CAAC,UAAU,IAAI,CAAC,IAAA,gBAAO,EAAC,MAAM,CAAC,MAAM,CAAC,EAAE;gBACzD,MAAM,CAAC,QAAQ,CAAC,qBAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;gBACxC,IAAA,oBAAa,EAAC,IAA2B,EAAE,CAAC,IAAc,EAAE,EAAE;oBAC5D,IAAI,IAAI,KAAK,MAAM,IAAI,CAAC,IAAA,gBAAO,EAAC,IAAI,CAAC,MAAM,CAAC,EAAE;wBAC5C,IAAI,CAAC,QAAQ,CAAC,qBAAU,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;qBAC9C;gBACH,CAAC,CAAC,CAAC;gBACH,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC;aAC1B;QACH,CAAC,CAAC;QAEM,eAAU,GAAG,CAAC,CAAwB,EAAE,EAAE;YAChD,IAAI,IAAI,CAAC,UAAU,EAAE;gBACnB,IAAA,oBAAa,EAAC,IAA2B,EAAE,CAAC,IAAc,EAAE,EAAE;oBAC5D,IAAI,CAAC,IAAA,gBAAO,EAAC,IAAI,CAAC,MAAM,CAAC,EAAE;wBACzB,IAAI,CAAC,WAAW,CAAC,qBAAU,CAAC,YAAY,CAAC,CAA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D,MAAA,IAAI,CAAC,SAAS,CAAC,WAAW,0CAAE,iBAAiB,CAC9C,CAAC;aACH;SACF;IACH,CAAC;IAED,WAAW,CAAC,KAAuB;QACjC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,gBAAgB;QACd,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC;IAChC,CAAC;IAED,eAAe;QACb,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAC/B,CAAC;CACF;AAziBD,8BAyiBC","file":"base.js","sourcesContent":["/**\n * @description Label 基类\n */\nimport type { IGroup, Text, IGraphic, IText, FederatedPointerEvent, IColor } from '@visactor/vrender';\nimport { createText, IncreaseCount, AttributeUpdateType } from '@visactor/vrender';\nimport type { IBoundsLike } from '@visactor/vutils';\nimport { isFunction, isValidNumber, isEmpty } from '@visactor/vutils';\nimport { AbstractComponent } from '../core/base';\nimport type { PointLocationCfg } from '../core/type';\nimport { labelSmartInvert } from '../util/labelSmartInvert';\nimport { traverseGroup } from '../util';\nimport { StateValue } from '../constant';\nimport type { Bitmap } from './overlap';\nimport { bitmapTool, boundToRange, canPlace, canPlaceInside, place } from './overlap';\nimport type { BaseLabelAttrs, OverlapAttrs, ILabelGraphicAttribute, ILabelAnimation } from './type';\nimport { DefaultLabelAnimation, getAnimationAttributes } from './animate/animate';\n\nexport abstract class LabelBase<T extends BaseLabelAttrs> extends AbstractComponent<T> {\n name = 'label';\n\n protected _baseMarks?: IGraphic[];\n\n protected _bitmap?: Bitmap;\n\n setBitmap(bitmap: Bitmap) {\n this._bitmap = bitmap;\n }\n\n protected _bmpTool?: ReturnType<typeof bitmapTool>;\n setBitmapTool(bmpTool: ReturnType<typeof bitmapTool>) {\n this._bmpTool = bmpTool;\n }\n\n protected _relationMap: Map<number, IGraphic>;\n\n protected _prevRelationMap: Map<number, IGraphic>;\n\n protected _textMap: Map<IGraphic, IText>;\n\n onAfterLabelOverlap?: (bitmap: Bitmap) => void;\n\n private _lastHover: IGraphic;\n private _lastSelect: IGraphic;\n\n private _enableAnimation: boolean;\n\n protected abstract labeling(\n textBounds: IBoundsLike,\n graphicBounds: IBoundsLike,\n position?: BaseLabelAttrs['position'],\n offset?: number\n ): Partial<ILabelGraphicAttribute> | undefined;\n\n protected render() {\n const currentBaseMarks = this._checkMarks();\n const labels = this.layout(currentBaseMarks);\n\n this._smartInvert(labels);\n\n this._renderLabels(labels);\n }\n\n private _bindEvent(target: IGraphic) {\n if (!target) {\n return;\n }\n\n const { hover, select } = this.attribute;\n\n if (hover) {\n target.addEventListener('pointermove', this._onHover as EventListenerOrEventListenerObject);\n target.addEventListener('pointerout', this._onUnHover as EventListenerOrEventListenerObject);\n }\n\n if (select) {\n target.addEventListener('pointerdown', this._onClick as EventListenerOrEventListenerObject);\n }\n }\n\n private _setStates(target: IGraphic) {\n if (!target) {\n return;\n }\n const state = this.attribute.state;\n\n if (!state || isEmpty(state)) {\n return;\n }\n\n target.states = state;\n }\n\n private _onHover = (e: FederatedPointerEvent) => {\n const target = e.target as unknown as IGraphic;\n if (target !== this._lastHover && !isEmpty(target.states)) {\n target.addState(StateValue.hover, true);\n traverseGroup(this as unknown as IGraphic, (node: IGraphic) => {\n if (node !== target && !isEmpty(node.states)) {\n node.addState(StateValue.hoverReverse, true);\n }\n });\n this._lastHover = target;\n }\n };\n\n private _onUnHover = (e: FederatedPointerEvent) => {\n if (this._lastHover) {\n traverseGroup(this as unknown as IGraphic, (node: IGraphic) => {\n if (!isEmpty(node.states)) {\n node.removeState(StateValue.hoverReverse);\n node.removeState(StateValue.hover);\n }\n });\n this._lastHover = null;\n }\n };\n\n private _onClick = (e: FederatedPointerEvent) => {\n const target = e.target as unknown as IGraphic;\n if (this._lastSelect === target && target.hasState('selected')) {\n // 取消选中\n this._lastSelect = null;\n traverseGroup(this as unknown as IGraphic, (node: IGraphic) => {\n if (!isEmpty(node.states)) {\n node.removeState(StateValue.selectedReverse);\n node.removeState(StateValue.selected);\n }\n });\n return;\n }\n\n if (!isEmpty(target.states)) {\n target.addState(StateValue.selected, true);\n traverseGroup(this as unknown as IGraphic, (node: IGraphic) => {\n if (node !== target && !isEmpty(node.states)) {\n node.addState(StateValue.selectedReverse, true);\n }\n });\n this._lastSelect = target;\n }\n };\n\n private _createLabelText(attributes: ILabelGraphicAttribute) {\n const text = createText(attributes);\n this._bindEvent(text);\n this._setStates(text);\n return text;\n }\n\n private _checkMarks() {\n const baseMarks = this.getBaseMarks();\n const currentBaseMarks: IGraphic[] = [];\n baseMarks.forEach(mark => {\n if ((mark as any).releaseStatus !== 'willRelease') {\n currentBaseMarks.push(mark);\n }\n });\n this._prevRelationMap = new Map(this._relationMap);\n this._relationMap?.clear();\n return currentBaseMarks;\n }\n\n protected layout(currentMarks?: IGraphic[]): ILabelGraphicAttribute[] {\n const { textStyle, position, offset } = this.attribute as BaseLabelAttrs;\n let { data } = this.attribute as BaseLabelAttrs;\n if (isFunction(data)) {\n data = data({});\n }\n if (!data || data.length === 0) {\n return [];\n }\n\n let labels: ILabelGraphicAttribute[] = [];\n\n if (isFunction(this.attribute.sort) && currentMarks && currentMarks.length) {\n currentMarks = currentMarks.sort(this.attribute.sort);\n }\n\n if (!this._relationMap) {\n this._relationMap = new Map();\n }\n\n // 默认根据 index 顺序排序\n for (let i = 0; i < data.length; i++) {\n const textData = data[i];\n const baseMark = currentMarks?.[i] as IGraphic;\n const labelAttribute = {\n ...textStyle,\n ...textData,\n _relatedIndex: i\n };\n this._relationMap.set(i, baseMark);\n\n if (textData) {\n const text = createText(labelAttribute);\n text.update();\n const textBounds = this.getGraphicBounds(text);\n const graphicBounds = this.getGraphicBounds(baseMark, { x: textData.x as number, y: textData.y as number });\n\n const textAttributes = this.labeling(\n textBounds,\n graphicBounds,\n isFunction(position) ? position(textData) : position,\n offset\n );\n\n if (!textAttributes) {\n continue;\n }\n\n labelAttribute.x = textAttributes.x;\n labelAttribute.y = textAttributes.y;\n\n labels.push(labelAttribute);\n }\n }\n\n this._baseMarks = currentMarks as IGraphic[];\n if (this.attribute.overlap !== false) {\n labels = this.overlapping(labels, this.attribute.overlap as OverlapAttrs);\n }\n\n return labels;\n }\n\n protected overlapping(labels: ILabelGraphicAttribute[], option: OverlapAttrs = {}) {\n if (labels.length === 0) {\n return [];\n }\n const result: ILabelGraphicAttribute[] = [];\n const baseMarkGroup = this.getBaseMarkGroup();\n const size = option.size ?? {\n width: baseMarkGroup?.AABBBounds.width() ?? 0,\n height: baseMarkGroup?.AABBBounds.height() ?? 0\n };\n\n if (size.width === 0 || size.height === 0) {\n return labels;\n }\n\n const { avoidBaseMark, strategy = [], hideOnHit = true, clampForce = true } = option;\n const bmpTool = this._bmpTool || bitmapTool(size.width, size.height);\n const bitmap = this._bitmap || bmpTool.bitmap();\n const checkBounds = strategy.some(s => s.type === 'bound');\n\n if (avoidBaseMark) {\n this._baseMarks?.forEach(mark => {\n mark.AABBBounds && bitmap.setRange(boundToRange(bmpTool, mark.AABBBounds, true));\n });\n }\n\n for (let i = 0; i < labels.length; i++) {\n if (labels[i].visible === false) {\n continue;\n }\n const text = createText(labels[i]) as Text;\n const baseMark = this._baseMarks?.[i];\n text.update();\n\n // 默认位置可以放置\n if (canPlace(bmpTool, bitmap, text.AABBBounds, clampForce)) {\n // 如果配置了限制在图形内部,需要提前判断;\n if (!checkBounds) {\n bitmap.setRange(boundToRange(bmpTool, text.AABBBounds, true));\n result.push({ ...text.attribute });\n continue;\n }\n\n if (checkBounds && baseMark?.AABBBounds && canPlaceInside(text.AABBBounds, baseMark?.AABBBounds)) {\n bitmap.setRange(boundToRange(bmpTool, text.AABBBounds, true));\n result.push({ ...text.attribute });\n continue;\n }\n }\n\n let hasPlace: ReturnType<typeof place> = false;\n // 发生碰撞,根据策略寻找可放置的位置\n for (let j = 0; j < strategy.length; j++) {\n hasPlace = place(\n bmpTool,\n bitmap,\n strategy[j],\n <BaseLabelAttrs>this.attribute,\n text,\n this.getGraphicBounds(baseMark, labels[i]),\n this.labeling\n );\n if (hasPlace !== false) {\n result.push({\n ...text.attribute,\n x: hasPlace.x,\n y: hasPlace.y\n });\n break;\n }\n }\n\n !hasPlace && !hideOnHit && result.push({ ...text.attribute });\n }\n\n if (isFunction(this.onAfterLabelOverlap)) {\n this.onAfterLabelOverlap(bitmap);\n }\n\n return result;\n }\n\n protected getBaseMarks() {\n const baseMarkGroup = this.getBaseMarkGroup() as IGroup;\n if (!baseMarkGroup) {\n return;\n }\n return baseMarkGroup.getChildren() as IGraphic[];\n }\n\n protected getBaseMarkGroup() {\n const { baseMarkGroupName } = this.attribute as BaseLabelAttrs;\n if (!baseMarkGroupName) {\n return;\n }\n return (this.getRootNode() as IGroup).find(node => node.name === baseMarkGroupName, true) as IGroup;\n }\n\n protected getGraphicBounds(graphic?: IGraphic, point: Partial<PointLocationCfg> = {}): IBoundsLike {\n // if (graphic && !isEmpty((graphic as any).finalAttrs)) {\n // const g = graphic.clone();\n // g.onBeforeAttributeUpdate = graphic.onBeforeAttributeUpdate;\n // g.setAttributes((graphic as any).finalAttrs);\n // g.update();\n // return g.AABBBounds;\n // }\n return (\n graphic?.AABBBounds ||\n ({\n x1: point.x,\n x2: point.x,\n y1: point.y,\n y2: point.y\n } as IBoundsLike)\n );\n }\n\n protected _renderLabels(labels: ILabelGraphicAttribute[]) {\n const animationConfig = (this.attribute.animation ?? {}) as ILabelAnimation;\n const disableAnimation = this._enableAnimation === false || (animationConfig as unknown as boolean) === false;\n const mode = animationConfig.mode ?? DefaultLabelAnimation.mode;\n const duration = animationConfig.duration ?? DefaultLabelAnimation.duration;\n const easing = animationConfig.easing ?? DefaultLabelAnimation.easing;\n const delay = animationConfig.delay ?? 0;\n\n const currentTextMap = new Map();\n const prevTextMap = this._textMap || new Map();\n const texts = [] as IText[];\n\n labels.forEach((label, index) => {\n const text = this._createLabelText(label);\n const relatedGraphic = this._relationMap.get(label._relatedIndex);\n const state = prevTextMap?.get(relatedGraphic) ? 'update' : 'enter';\n\n if (state === 'enter') {\n texts.push(text);\n currentTextMap.set(relatedGraphic, text);\n if (!disableAnimation && relatedGraphic) {\n const { from, to } = getAnimationAttributes(label, 'fadeIn');\n this.add(text);\n relatedGraphic.onAnimateBind = () => {\n text.setAttributes(from);\n const listener = this._afterRelatedGraphicAttributeUpdate(text, texts, index, relatedGraphic, {\n mode,\n duration,\n easing,\n to,\n delay\n });\n relatedGraphic.on('afterAttributeUpdate', listener);\n };\n } else {\n this.add(text);\n }\n }\n\n if (state === 'update') {\n const prevText = prevTextMap.get(relatedGraphic);\n prevTextMap.delete(relatedGraphic);\n currentTextMap.set(relatedGraphic, prevText);\n if (!disableAnimation) {\n prevText.animate().to(text.attribute, duration, easing);\n if (\n animationConfig.increaseEffect !== false &&\n prevText.attribute.text !== text.attribute.text &&\n isValidNumber(Number(prevText.attribute.text) * Number(text.attribute.text))\n ) {\n prevText\n .animate()\n .play(\n new IncreaseCount(\n { text: prevText.attribute.text as string },\n { text: text.attribute.text as string },\n duration,\n easing\n )\n );\n }\n } else {\n prevText.setAttributes(text.attribute);\n }\n }\n });\n prevTextMap.forEach(label => {\n if (disableAnimation) {\n this.removeChild(label);\n } else {\n label\n ?.animate()\n .to(getAnimationAttributes(label.attribute, 'fadeOut').to, duration, easing)\n .onEnd(() => {\n this.removeChild(label);\n });\n }\n });\n\n this._textMap = currentTextMap;\n }\n\n protected _afterRelatedGraphicAttributeUpdate(\n text: IText,\n texts: IText[],\n index: number,\n relatedGraphic: IGraphic,\n { mode, duration, easing, to, delay }: ILabelAnimation & { to: any }\n ) {\n const listener = (event: any) => {\n const { detail } = event;\n if (!detail) {\n return {};\n }\n\n const isValidAnimateState =\n detail &&\n detail.type === AttributeUpdateType.ANIMATE_UPDATE &&\n detail.animationState &&\n detail.animationState.step?.type !== 'wait';\n\n if (!isValidAnimateState) {\n return {};\n }\n\n if (detail.type === AttributeUpdateType.ANIMATE_END) {\n text.setAttributes(to);\n return;\n }\n\n const onEnd = () => {\n if (relatedGraphic) {\n relatedGraphic.onAnimateBind = undefined;\n relatedGraphic.removeEventListener('afterAttributeUpdate', listener);\n }\n };\n\n switch (mode) {\n case 'after':\n // 3. 当前关联图元的动画播放结束后\n if (detail.animationState.end) {\n text.animate({ onEnd }).wait(delay).to(to, duration, easing);\n }\n break;\n case 'after-all':\n // 2. 所有完成后才开始;\n if (index === texts.length - 1) {\n if (detail.animationState.end) {\n texts.forEach(t => {\n t.animate({ onEnd }).wait(delay).to(to, duration, easing);\n });\n }\n }\n break;\n case 'same-time':\n default:\n // 1. 与当前关联图元的动画播放同时进行\n if (detail.animationState.isFirstFrameOfStep) {\n text.animate({ onEnd }).wait(delay).to(to, duration, easing);\n }\n break;\n }\n };\n return listener;\n }\n\n protected _smartInvert(labels: ILabelGraphicAttribute[]) {\n if (this.attribute.smartInvert === false) {\n return;\n }\n for (let i = 0; i < labels.length; i++) {\n const label = labels?.[i] as ILabelGraphicAttribute;\n if (!label) {\n continue;\n }\n\n const isInside = canPlaceInside(\n createText(label).AABBBounds,\n this._relationMap.get(label._relatedIndex)?.AABBBounds\n );\n /**\n * stroke 的处理逻辑\n * 1. 当文本在图元内部时,有两种情况:\n * - a. 未设置stroke:labelFill为前景色,baseMark填充色为背景色\n * - b. 设置了stroke:labelFill为前景色,labelStroke填充色为背景色\n * 2. 当文本在图元外部时,有两种情况:\n * - a. 未设置stroke:此时设置strokeColor为backgroundColor。labelFill为前景色,labelStroke填充色为背景色。避免文字一半在图元内部,一半在图元外部时,在图元外部文字不可见。\n * - b. 设置了stroke:保持strokeColor。labelFill为前景色,labelStroke填充色为背景色。\n */\n if (label.stroke && label.lineWidth > 0) {\n /**\n * 1-b, 2-b\n * 若label存在stroke,label填充色为前景色,label描边色为背景色\n * WCAG 2 字母周围的文本发光/光晕可用作背景颜色\n */\n label.fill = labelSmartInvert(\n label.fill as IColor,\n label.stroke as IColor,\n this.attribute.smartInvert?.textType,\n this.attribute.smartInvert?.contrastRatiosThreshold,\n this.attribute.smartInvert?.alternativeColors\n );\n } else if (isInside) {\n /**\n * 1-a\n * label在图元内部时,label填充色为前景色,baseMark填充色为背景色\n */\n const baseMark = this._relationMap.get(label._relatedIndex);\n const backgroundColor = baseMark.attribute.fill as IColor;\n const foregroundColor = label.fill as IColor;\n label.fill = labelSmartInvert(\n foregroundColor,\n backgroundColor,\n this.attribute.smartInvert?.textType,\n this.attribute.smartInvert?.contrastRatiosThreshold,\n this.attribute.smartInvert?.alternativeColors\n );\n } else if (label.lineWidth > 0) {\n /**\n * 2-a\n * 当文本在图元外部时,设置strokeColor为backgroundColor。labelFill为前景色,labelStroke填充色为背景色。\n */\n const baseMark = this._relationMap.get(label._relatedIndex);\n label.stroke = baseMark.attribute.fill;\n const backgroundColor = label.stroke as IColor;\n const foregroundColor = label.fill as IColor;\n label.fill = labelSmartInvert(\n foregroundColor,\n backgroundColor,\n this.attribute.smartInvert?.textType,\n this.attribute.smartInvert?.contrastRatiosThreshold,\n this.attribute.smartInvert?.alternativeColors\n );\n }\n }\n }\n\n setLocation(point: PointLocationCfg) {\n this.translateTo(point.x, point.y);\n }\n\n disableAnimation() {\n this._enableAnimation = false;\n }\n\n enableAnimation() {\n this._enableAnimation = true;\n }\n}\n"]}
1
+ {"version":3,"sources":["label/base.ts"],"names":[],"mappings":";;;AAIA,+CAAmF;AAEnF,6CAA+E;AAC/E,uCAAiD;AAEjD,+DAA4D;AAC5D,kCAAwC;AACxC,0CAAyC;AAEzC,uCAAiG;AAEjG,+CAAkF;AAElF,MAAsB,SAAoC,SAAQ,wBAAoB;IAAtF;;QACE,SAAI,GAAG,OAAO,CAAC;QAkGP,aAAQ,GAAG,CAAC,CAAwB,EAAE,EAAE;YAC9C,MAAM,MAAM,GAAG,CAAC,CAAC,MAA6B,CAAC;YAC/C,IAAI,MAAM,KAAK,IAAI,CAAC,UAAU,IAAI,CAAC,IAAA,gBAAO,EAAC,MAAM,CAAC,MAAM,CAAC,EAAE;gBACzD,MAAM,CAAC,QAAQ,CAAC,qBAAU,CAAC,K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Text, FederatedPointerEvent, IColor } from '@visactor/vrender';\nimport { createText, IncreaseCount, AttributeUpdateType } from '@visactor/vrender';\nimport type { IBoundsLike } from '@visactor/vutils';\nimport { isFunction, isValidNumber, isEmpty, isValid } from '@visactor/vutils';\nimport { AbstractComponent } from '../core/base';\nimport type { PointLocationCfg } from '../core/type';\nimport { labelSmartInvert } from '../util/labelSmartInvert';\nimport { traverseGroup } from '../util';\nimport { StateValue } from '../constant';\nimport type { Bitmap } from './overlap';\nimport { bitmapTool, boundToRange, canPlace, canPlaceInside, clampText, place } from './overlap';\nimport type { BaseLabelAttrs, OverlapAttrs, ILabelAnimation, LabelItem, SmartInvertAttrs } from './type';\nimport { DefaultLabelAnimation, getAnimationAttributes } from './animate/animate';\n\nexport abstract class LabelBase<T extends BaseLabelAttrs> extends AbstractComponent<T> {\n name = 'label';\n\n protected _baseMarks?: IGraphic[];\n\n protected _bitmap?: Bitmap;\n\n setBitmap(bitmap: Bitmap) {\n this._bitmap = bitmap;\n }\n\n protected _bmpTool?: ReturnType<typeof bitmapTool>;\n setBitmapTool(bmpTool: ReturnType<typeof bitmapTool>) {\n this._bmpTool = bmpTool;\n }\n\n protected _graphicToText: Map<IGraphic, IText>;\n\n protected _idToGraphic: Map<string, IGraphic>;\n\n onAfterLabelOverlap?: (bitmap: Bitmap) => void;\n\n private _lastHover: IGraphic;\n private _lastSelect: IGraphic;\n\n private _enableAnimation: boolean;\n\n protected abstract labeling(\n textBounds: IBoundsLike,\n graphicBounds: IBoundsLike,\n position?: BaseLabelAttrs['position'],\n offset?: number\n ): { x: number; y: number } | undefined;\n\n protected render() {\n this._prepare();\n\n const { overlap, smartInvert, dataFilter, customLayoutFunc, customOverlapFunc } = this.attribute;\n let data = this.attribute.data;\n\n if (isFunction(dataFilter)) {\n data = dataFilter(data);\n }\n\n let labels: IText[];\n\n if (isFunction(customLayoutFunc)) {\n labels = customLayoutFunc(data, (d: LabelItem) => this._idToGraphic.get(d.id));\n } else {\n // 根据关联图元和配置的position计算标签坐标\n labels = this.layout(data);\n\n if (isFunction(customOverlapFunc)) {\n labels = customOverlapFunc(labels as Text[], (d: LabelItem) => this._idToGraphic.get(d.id));\n } else {\n // 防重叠逻辑\n if (overlap !== false) {\n labels = this._overlapping(labels);\n }\n }\n }\n\n if (smartInvert !== false) {\n this._smartInvert(labels);\n }\n\n this._renderLabels(labels);\n }\n\n private _bindEvent(target: IGraphic) {\n if (!target) {\n return;\n }\n\n const { hover, select } = this.attribute;\n\n if (hover) {\n target.addEventListener('pointermove', this._onHover as EventListenerOrEventListenerObject);\n target.addEventListener('pointerout', this._onUnHover as EventListenerOrEventListenerObject);\n }\n\n if (select) {\n target.addEventListener('pointerdown', this._onClick as EventListenerOrEventListenerObject);\n }\n }\n\n private _setStates(target: IGraphic) {\n if (!target) {\n return;\n }\n const state = this.attribute.state;\n\n if (!state || isEmpty(state)) {\n return;\n }\n\n target.states = state;\n }\n\n private _onHover = (e: FederatedPointerEvent) => {\n const target = e.target as unknown as IGraphic;\n if (target !== this._lastHover && !isEmpty(target.states)) {\n target.addState(StateValue.hover, true);\n traverseGroup(this as unknown as IGraphic, (node: IGraphic) => {\n if (node !== target && !isEmpty(node.states)) {\n node.addState(StateValue.hoverReverse, true);\n }\n });\n this._lastHover = target;\n }\n };\n\n private _onUnHover = (e: FederatedPointerEvent) => {\n if (this._lastHover) {\n traverseGroup(this as unknown as IGraphic, (node: IGraphic) => {\n if (!isEmpty(node.states)) {\n node.removeState(StateValue.hoverReverse);\n node.removeState(StateValue.hover);\n }\n });\n this._lastHover = null;\n }\n };\n\n private _onClick = (e: FederatedPointerEvent) => {\n const target = e.target as unknown as IGraphic;\n if (this._lastSelect === target && target.hasState('selected')) {\n // 取消选中\n this._lastSelect = null;\n traverseGroup(this as unknown as IGraphic, (node: IGraphic) => {\n if (!isEmpty(node.states)) {\n node.removeState(StateValue.selectedReverse);\n node.removeState(StateValue.selected);\n }\n });\n return;\n }\n\n if (!isEmpty(target.states)) {\n target.addState(StateValue.selected, true);\n traverseGroup(this as unknown as IGraphic, (node: IGraphic) => {\n if (node !== target && !isEmpty(node.states)) {\n node.addState(StateValue.selectedReverse, true);\n }\n });\n this._lastSelect = target;\n }\n };\n\n private _createLabelText(attributes: LabelItem) {\n const text = createText(attributes);\n this._bindEvent(text);\n this._setStates(text);\n return text;\n }\n\n private _prepare() {\n const baseMarks = this.getBaseMarks();\n const currentBaseMarks: IGraphic[] = [];\n baseMarks.forEach(mark => {\n if ((mark as any).releaseStatus !== 'willRelease') {\n currentBaseMarks.push(mark);\n }\n });\n\n this._idToGraphic?.clear();\n this._baseMarks = currentBaseMarks;\n\n if (!currentBaseMarks || currentBaseMarks.length === 0) {\n return;\n }\n\n const { data } = this.attribute;\n\n if (!data || data.length === 0) {\n return;\n }\n\n if (!this._idToGraphic) {\n this._idToGraphic = new Map();\n }\n // generate id mapping before data filter\n for (let i = 0; i < currentBaseMarks.length; i++) {\n const textData = data[i];\n const baseMark = currentBaseMarks[i] as IGraphic;\n if (textData && baseMark) {\n if (!isValid(textData.id)) {\n textData.id = `vrender-component-${this.name}-${i}`;\n }\n this._idToGraphic.set(textData.id, baseMark);\n }\n }\n }\n\n protected layout(data: LabelItem[] = []): IText[] {\n const { textStyle = {}, position, offset } = this.attribute;\n const labels = [];\n\n for (let i = 0; i < data.length; i++) {\n const textData = data[i];\n const baseMark = this._idToGraphic.get(textData.id);\n\n const labelAttribute = {\n ...textStyle,\n ...textData\n };\n const text = this._createLabelText(labelAttribute);\n const textBounds = this.getGraphicBounds(text);\n const graphicBounds = this.getGraphicBounds(baseMark, { x: textData.x as number, y: textData.y as number });\n const textLocation = this.labeling(\n textBounds,\n graphicBounds,\n isFunction(position) ? position(textData) : position,\n offset\n );\n if (!textLocation) {\n continue;\n }\n labelAttribute.x = textLocation.x;\n labelAttribute.y = textLocation.y;\n\n text.setAttributes(textLocation);\n labels.push(text);\n }\n\n return labels;\n }\n\n protected _overlapping(labels: IText[]) {\n if (labels.length === 0) {\n return [];\n }\n const option = this.attribute.overlap as OverlapAttrs;\n\n const result: IText[] = [];\n const baseMarkGroup = this.getBaseMarkGroup();\n\n const size = option.size ?? {\n width: baseMarkGroup?.AABBBounds.width() ?? 0,\n height: baseMarkGroup?.AABBBounds.height() ?? 0\n };\n\n if (size.width === 0 || size.height === 0) {\n return labels;\n }\n\n const { avoidBaseMark, strategy = [], hideOnHit = true, clampForce = true } = option;\n const bmpTool = this._bmpTool || bitmapTool(size.width, size.height);\n const bitmap = this._bitmap || bmpTool.bitmap();\n const checkBounds = strategy.some(s => s.type === 'bound');\n\n if (avoidBaseMark) {\n this._baseMarks?.forEach(mark => {\n mark.AABBBounds && bitmap.setRange(boundToRange(bmpTool, mark.AABBBounds, true));\n });\n }\n\n for (let i = 0; i < labels.length; i++) {\n if (labels[i].visible === false) {\n continue;\n }\n const text = labels[i] as IText;\n const baseMark = this._idToGraphic.get((text.attribute as LabelItem).id);\n text.update();\n\n // 默认位置可以放置\n if (canPlace(bmpTool, bitmap, text.AABBBounds, clampForce)) {\n // 如果配置了限制在图形内部,需要提前判断;\n if (!checkBounds) {\n bitmap.setRange(boundToRange(bmpTool, text.AABBBounds, true));\n result.push(text);\n continue;\n }\n\n if (checkBounds && baseMark?.AABBBounds && canPlaceInside(text.AABBBounds, baseMark?.AABBBounds)) {\n bitmap.setRange(boundToRange(bmpTool, text.AABBBounds, true));\n result.push(text);\n continue;\n }\n }\n\n let hasPlace: ReturnType<typeof place> = false;\n // 发生碰撞,根据策略寻找可放置的位置\n for (let j = 0; j < strategy.length; j++) {\n hasPlace = place(\n bmpTool,\n bitmap,\n strategy[j],\n <BaseLabelAttrs>this.attribute,\n text as Text,\n this.getGraphicBounds(baseMark, labels[i]),\n this.labeling\n );\n if (hasPlace !== false) {\n text.setAttributes({ x: hasPlace.x, y: hasPlace.y });\n result.push(text);\n break;\n }\n }\n\n // 尝试向内挤压\n if (clampForce) {\n const { dx = 0, dy = 0 } = clampText(text, bmpTool.width, bmpTool.height);\n if (\n !(dx === 0 && dy === 0) &&\n canPlace(bmpTool, bitmap, {\n x1: text.AABBBounds.x1 + dx,\n x2: text.AABBBounds.x2 + dx,\n y1: text.AABBBounds.y1 + dy,\n y2: text.AABBBounds.y2 + dy\n })\n ) {\n text.setAttributes({ x: text.attribute.x + dx, y: text.attribute.y + dy });\n bitmap.setRange(boundToRange(bmpTool, text.AABBBounds, true));\n result.push(text);\n continue;\n }\n }\n\n !hasPlace && !hideOnHit && result.push(text);\n }\n\n if (isFunction(this.onAfterLabelOverlap)) {\n this.onAfterLabelOverlap(bitmap);\n }\n\n return result;\n }\n\n protected getBaseMarks() {\n const baseMarkGroup = this.getBaseMarkGroup() as IGroup;\n if (!baseMarkGroup) {\n return;\n }\n return baseMarkGroup.getChildren() as IGraphic[];\n }\n\n protected getBaseMarkGroup() {\n const { baseMarkGroupName } = this.attribute as BaseLabelAttrs;\n if (!baseMarkGroupName) {\n return;\n }\n return (this.getRootNode() as IGroup).find(node => node.name === baseMarkGroupName, true) as IGroup;\n }\n\n protected getGraphicBounds(graphic?: IGraphic, point: Partial<PointLocationCfg> = {}): IBoundsLike {\n // if (graphic && !isEmpty((graphic as any).finalAttrs)) {\n // const g = graphic.clone();\n // g.onBeforeAttributeUpdate = graphic.onBeforeAttributeUpdate;\n // g.setAttributes((graphic as any).finalAttrs);\n // g.update();\n // return g.AABBBounds;\n // }\n return (\n graphic?.AABBBounds ||\n ({\n x1: point.x,\n x2: point.x,\n y1: point.y,\n y2: point.y\n } as IBoundsLike)\n );\n }\n\n protected _renderLabels(labels: IText[]) {\n const animationConfig = (this.attribute.animation ?? {}) as ILabelAnimation;\n const disableAnimation = this._enableAnimation === false || (animationConfig as unknown as boolean) === false;\n const mode = animationConfig.mode ?? DefaultLabelAnimation.mode;\n const duration = animationConfig.duration ?? DefaultLabelAnimation.duration;\n const easing = animationConfig.easing ?? DefaultLabelAnimation.easing;\n const delay = animationConfig.delay ?? 0;\n\n const currentTextMap = new Map();\n const prevTextMap = this._graphicToText || new Map();\n const texts = [] as IText[];\n labels.forEach((text, index) => {\n const relatedGraphic = this._idToGraphic.get((text.attribute as LabelItem).id);\n const state = prevTextMap?.get(relatedGraphic) ? 'update' : 'enter';\n if (state === 'enter') {\n texts.push(text);\n currentTextMap.set(relatedGraphic, text);\n if (!disableAnimation && relatedGraphic) {\n const { from, to } = getAnimationAttributes(text.attribute, 'fadeIn');\n this.add(text);\n relatedGraphic.onAnimateBind = () => {\n text.setAttributes(from);\n const listener = this._afterRelatedGraphicAttributeUpdate(text, texts, index, relatedGraphic, {\n mode,\n duration,\n easing,\n to,\n delay\n });\n relatedGraphic.on('afterAttributeUpdate', listener);\n };\n } else {\n this.add(text);\n }\n }\n\n if (state === 'update') {\n const prevText = prevTextMap.get(relatedGraphic);\n prevTextMap.delete(relatedGraphic);\n currentTextMap.set(relatedGraphic, prevText);\n if (!disableAnimation) {\n prevText.animate().to(text.attribute, duration, easing);\n if (\n animationConfig.increaseEffect !== false &&\n prevText.attribute.text !== text.attribute.text &&\n isValidNumber(Number(prevText.attribute.text) * Number(text.attribute.text))\n ) {\n prevText\n .animate()\n .play(\n new IncreaseCount(\n { text: prevText.attribute.text as string },\n { text: text.attribute.text as string },\n duration,\n easing\n )\n );\n }\n } else {\n prevText.setAttributes(text.attribute);\n }\n }\n });\n prevTextMap.forEach(label => {\n if (disableAnimation) {\n this.removeChild(label);\n } else {\n label\n ?.animate()\n .to(getAnimationAttributes(label.attribute, 'fadeOut').to, duration, easing)\n .onEnd(() => {\n this.removeChild(label);\n });\n }\n });\n\n this._graphicToText = currentTextMap;\n }\n\n protected _afterRelatedGraphicAttributeUpdate(\n text: IText,\n texts: IText[],\n index: number,\n relatedGraphic: IGraphic,\n { mode, duration, easing, to, delay }: ILabelAnimation & { to: any }\n ) {\n const listener = (event: any) => {\n const { detail } = event;\n if (!detail) {\n return {};\n }\n\n const isValidAnimateState =\n detail &&\n detail.type === AttributeUpdateType.ANIMATE_UPDATE &&\n detail.animationState &&\n detail.animationState.step?.type !== 'wait';\n\n if (!isValidAnimateState) {\n return {};\n }\n\n if (detail.type === AttributeUpdateType.ANIMATE_END) {\n text.setAttributes(to);\n return;\n }\n\n const onEnd = () => {\n if (relatedGraphic) {\n relatedGraphic.onAnimateBind = undefined;\n relatedGraphic.removeEventListener('afterAttributeUpdate', listener);\n }\n };\n\n switch (mode) {\n case 'after':\n // 3. 当前关联图元的动画播放结束后\n if (detail.animationState.end) {\n text.animate({ onEnd }).wait(delay).to(to, duration, easing);\n }\n break;\n case 'after-all':\n // 2. 所有完成后才开始;\n if (index === texts.length - 1) {\n if (detail.animationState.end) {\n texts.forEach(t => {\n t.animate({ onEnd }).wait(delay).to(to, duration, easing);\n });\n }\n }\n break;\n case 'same-time':\n default:\n // 1. 与当前关联图元的动画播放同时进行\n if (detail.animationState.isFirstFrameOfStep) {\n text.animate({ onEnd }).wait(delay).to(to, duration, easing);\n }\n break;\n }\n };\n return listener;\n }\n\n protected _smartInvert(labels: IText[]) {\n const option = (this.attribute.smartInvert || {}) as SmartInvertAttrs;\n const { textType, contrastRatiosThreshold, alternativeColors } = option;\n\n for (let i = 0; i < labels.length; i++) {\n const label = labels[i];\n if (!label) {\n continue;\n }\n const baseMark = this._idToGraphic.get((label.attribute as LabelItem).id);\n const isInside = canPlaceInside(label.AABBBounds, baseMark?.AABBBounds);\n /**\n * stroke 的处理逻辑\n * 1. 当文本在图元内部时,有两种情况:\n * - a. 未设置stroke:labelFill为前景色,baseMark填充色为背景色\n * - b. 设置了stroke:labelFill为前景色,labelStroke填充色为背景色\n * 2. 当文本在图元外部时,有两种情况:\n * - a. 未设置stroke:此时设置strokeColor为backgroundColor。labelFill为前景色,labelStroke填充色为背景色。避免文字一半在图元内部,一半在图元外部时,在图元外部文字不可见。\n * - b. 设置了stroke:保持strokeColor。labelFill为前景色,labelStroke填充色为背景色。\n */\n if (label.attribute.stroke && label.attribute.lineWidth > 0) {\n /**\n * 1-b, 2-b\n * 若label存在stroke,label填充色为前景色,label描边色为背景色\n * WCAG 2 字母周围的文本发光/光晕可用作背景颜色\n */\n label.setAttributes({\n fill: labelSmartInvert(\n label.attribute.fill as IColor,\n label.attribute.stroke as IColor,\n textType,\n contrastRatiosThreshold,\n alternativeColors\n )\n });\n } else if (isInside) {\n /**\n * 1-a\n * label在图元内部时,label填充色为前景色,baseMark填充色为背景色\n */\n const backgroundColor = baseMark.attribute.fill as IColor;\n const foregroundColor = label.attribute.fill as IColor;\n label.setAttributes({\n fill: labelSmartInvert(foregroundColor, backgroundColor, textType, contrastRatiosThreshold, alternativeColors)\n });\n } else if (label.attribute.lineWidth > 0) {\n /**\n * 2-a\n * 当文本在图元外部时,设置strokeColor为backgroundColor。labelFill为前景色,labelStroke填充色为背景色。\n */\n const backgroundColor = label.attribute.stroke as IColor;\n const foregroundColor = label.attribute.fill as IColor;\n label.setAttributes({\n stroke: baseMark.attribute.fill,\n fill: labelSmartInvert(foregroundColor, backgroundColor, textType, contrastRatiosThreshold, alternativeColors)\n });\n }\n }\n }\n\n setLocation(point: PointLocationCfg) {\n this.translateTo(point.x, point.y);\n }\n\n disableAnimation() {\n this._enableAnimation = false;\n }\n\n enableAnimation() {\n this._enableAnimation = true;\n }\n}\n"]}
@@ -1,10 +1,10 @@
1
- import { Text } from '@visactor/vrender';
2
- import { IAABBBounds, IBoundsLike } from '@visactor/vutils';
3
- import { PointLocationCfg } from '../../core/type';
1
+ import type { IText, Text } from '@visactor/vrender';
2
+ import type { IAABBBounds, IBoundsLike } from '@visactor/vutils';
3
+ import type { PointLocationCfg } from '../../core/type';
4
4
  import type { LabelBase } from '../base';
5
5
  import type { BaseLabelAttrs, Strategy } from '../type';
6
6
  import type { Bitmap } from './bitmap';
7
- import { BitmapTool } from './scaler';
7
+ import type { BitmapTool } from './scaler';
8
8
  export declare function canPlace($: BitmapTool, bitmap: Bitmap, bound: IBoundsLike, checkBound?: boolean): boolean;
9
9
  export declare function canPlaceInside(textBound: IBoundsLike, shapeBound: IAABBBounds): boolean;
10
10
  export declare function placeToCandidates($: BitmapTool, bitmap: Bitmap, text: Text, candidates?: PointLocationCfg[], clampForce?: boolean): PointLocationCfg | false;
@@ -12,3 +12,7 @@ export declare function place<T extends BaseLabelAttrs>($: BitmapTool, bitmap: B
12
12
  export declare const DefaultPositions: string[];
13
13
  export declare const DefaultRectPositions: string[];
14
14
  export declare function defaultLabelPosition(type?: string): string[];
15
+ export declare function clampText(text: IText, width: number, height: number): {
16
+ dx: number;
17
+ dy: number;
18
+ };
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
- }), exports.defaultLabelPosition = exports.DefaultRectPositions = exports.DefaultPositions = exports.place = exports.placeToCandidates = exports.canPlaceInside = exports.canPlace = void 0;
5
+ }), exports.clampText = exports.defaultLabelPosition = exports.DefaultRectPositions = exports.DefaultPositions = exports.place = exports.placeToCandidates = exports.canPlaceInside = exports.canPlace = void 0;
6
6
 
7
7
  const vutils_1 = require("@visactor/vutils"), scaler_1 = require("./scaler");
8
8
 
@@ -55,7 +55,19 @@ function defaultLabelPosition(type) {
55
55
  return "rect" === type ? exports.DefaultRectPositions : exports.DefaultPositions;
56
56
  }
57
57
 
58
+ function clampText(text, width, height) {
59
+ const {x1: x1, x2: x2, y1: y1, y2: y2} = text.AABBBounds, minX = Math.min(x1, x2), maxX = Math.max(x1, x2), minY = Math.min(y1, y2), maxY = Math.max(y1, y2);
60
+ let dx = 0, dy = 0;
61
+ return minX < 0 && maxX - minX <= width ? dx = -minX : maxX > width && minX - (maxX - width) >= 0 && (dx = width - maxX),
62
+ minY < 0 && maxY - minY <= height ? dy = -minY : maxY > height && minY - (maxY - height) >= 0 && (dy = height - maxY),
63
+ {
64
+ dx: dx,
65
+ dy: dy
66
+ };
67
+ }
68
+
58
69
  exports.canPlace = canPlace, exports.canPlaceInside = canPlaceInside, exports.placeToCandidates = placeToCandidates,
59
70
  exports.place = place, exports.DefaultPositions = [ "top", "bottom", "right", "left", "top-right", "bottom-right", "top-left", "bottom-left" ],
60
- exports.DefaultRectPositions = [ "top", "inside-top", "inside" ], exports.defaultLabelPosition = defaultLabelPosition;
71
+ exports.DefaultRectPositions = [ "top", "inside-top", "inside" ], exports.defaultLabelPosition = defaultLabelPosition,
72
+ exports.clampText = clampText;
61
73
  //# sourceMappingURL=place.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["label/overlap/place.ts"],"names":[],"mappings":";;;AACA,6CAAwE;AAKxE,qCAAoD;AAiCpD,SAAgB,QAAQ,CAAC,CAAa,EAAE,MAAc,EAAE,KAAkB,EAAE,UAAU,GAAG,IAAI;IAC3F,MAAM,KAAK,GAAG,IAAA,qBAAY,EAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACrC,MAAM,WAAW,GAAG,UAAU,IAAI,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAE5D,IAAI,WAAW,EAAE;QACf,OAAO,KAAK,CAAC;KACd;IAED,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACjC,CAAC;AATD,4BASC;AAQD,SAAgB,cAAc,CAAC,SAAsB,EAAE,UAAuB;IAC5E,IAAI,CAAC,SAAS,IAAI,CAAC,UAAU,EAAE;QAC7B,OAAO,KAAK,CAAC;KACd;IACD,OAAO,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACxC,CAAC;AALD,wCAKC;AAED,SAAgB,iBAAiB,CAC/B,CAAa,EACb,MAAc,EACd,IAAU,EACV,aAAiC,EAAE,EACnC,UAAU,GAAG,IAAI;IAEjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC1C,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QAC9B,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QACtC,QAAQ,CAAC,MAAM,EAAE,CAAC;QAElB,IAAI,QA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ACpG;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AApCD,sBAoCC;AAEY,QAAA,gBAAgB,GAAG;IAC9B,KAAK;IACL,QAAQ;IACR,OAAO;IACP,MAAM;IACN,WAAW;IACX,cAAc;IACd,UAAU;IACV,aAAa;CACd,CAAC;AACW,QAAA,oBAAoB,GAAG,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAC;AAEpE,SAAgB,oBAAoB,CAAC,IAAa;IAChD,QAAQ,IAAI,EAAE;QACZ,KAAK,MAAM;YACT,OAAO,4BAAoB,CAAC;QAC9B;YACE,OAAO,wBAAgB,CAAC;KAC3B;AACH,CAAC;AAPD,oDAOC","file":"place.js","sourcesContent":["import { Text } from '@visactor/vrender';\nimport { IAABBBounds, IBoundsLike, isFunction } from '@visactor/vutils';\nimport { PointLocationCfg } from '../../core/type';\nimport type { LabelBase } from '../base';\nimport type { BaseLabelAttrs, OverlapAttrs, Strategy } from '../type';\nimport type { Bitmap } from './bitmap';\nimport { BitmapTool, boundToRange } from './scaler';\n\n/**\n * 防重叠逻辑参考 https://github.com/vega/vega/\n * Copyright (c) 2015-2023, University of Washington Interactive Data Lab\n All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation\n and/or other materials provided with the distribution.\n\n 3. Neither the name of the copyright holder nor the names of its contributors\n may be used to endorse or promote products derived from this software\n without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE\n FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\nexport function canPlace($: BitmapTool, bitmap: Bitmap, bound: IBoundsLike, checkBound = true) {\n const range = boundToRange($, bound);\n const outOfBounds = checkBound && bitmap.outOfBounds(range);\n\n if (outOfBounds) {\n return false;\n }\n\n return !bitmap.getRange(range);\n}\n\n/**\n * 是否在图形内部\n * @param textBound\n * @param shapeBound\n * @returns\n */\nexport function canPlaceInside(textBound: IBoundsLike, shapeBound: IAABBBounds) {\n if (!textBound || !shapeBound) {\n return false;\n }\n return shapeBound.encloses(textBound);\n}\n\nexport function placeToCandidates(\n $: BitmapTool,\n bitmap: Bitmap,\n text: Text,\n candidates: PointLocationCfg[] = [],\n clampForce = true\n): PointLocationCfg | false {\n for (let i = 0; i < candidates.length; i++) {\n const tempText = text.clone();\n tempText.setAttributes(candidates[i]);\n tempText.update();\n\n if (canPlace($, bitmap, boundToRange($, tempText.AABBBounds), clampForce)) {\n bitmap.setRange(boundToRange($, tempText.AABBBounds, true));\n return candidates[i];\n }\n }\n return false;\n}\n\nexport function place<T extends BaseLabelAttrs>(\n $: BitmapTool,\n bitmap: Bitmap,\n s: Strategy,\n attrs: T,\n text: Text,\n bounds: IBoundsLike,\n labeling?: LabelBase<T>['labeling']\n): PointLocationCfg | false {\n if (s.type === 'bound' || s.type === 'position') {\n if (isFunction(labeling)) {\n // TODO:这里可以 filter 掉初始位置,提升一部分性能\n const userPosition = isFunction(s.position) ? s.position(text.attribute) : s.position;\n const positions = (userPosition || defaultLabelPosition(attrs.type)) as string[];\n const candidates = positions.map(p => labeling(text.AABBBounds, bounds, p, attrs.offset) as PointLocationCfg);\n return placeToCandidates($, bitmap, text, candidates, (attrs.overlap as OverlapAttrs)?.clampForce);\n }\n return false;\n }\n\n if (s.type === 'moveY') {\n const offset = s.offset ? (isFunction(s.offset) ? s.offset(text.attribute) : s.offset) : [];\n const candidates = offset.map(dy => {\n return { x: text.attribute.x as number, y: (text.attribute.y as number) + dy };\n });\n return placeToCandidates($, bitmap, text, candidates, (attrs.overlap as OverlapAttrs)?.clampForce);\n }\n\n if (s.type === 'moveX') {\n const offset = s.offset ? (isFunction(s.offset) ? s.offset(text.attribute) : s.offset) : [];\n const candidates = offset.map(dx => {\n return { x: (text.attribute.x as number) + dx, y: text.attribute.y as number };\n });\n return placeToCandidates($, bitmap, text, candidates, (attrs.overlap as OverlapAttrs)?.clampForce);\n }\n return false;\n}\n\nexport const DefaultPositions = [\n 'top',\n 'bottom',\n 'right',\n 'left',\n 'top-right',\n 'bottom-right',\n 'top-left',\n 'bottom-left'\n];\nexport const DefaultRectPositions = ['top', 'inside-top', 'inside'];\n\nexport function defaultLabelPosition(type?: string) {\n switch (type) {\n case 'rect':\n return DefaultRectPositions;\n default:\n return DefaultPositions;\n }\n}\n"]}
1
+ {"version":3,"sources":["label/overlap/place.ts"],"names":[],"mappings":";;;AAEA,6CAA8C;AAM9C,qCAAwC;AAiCxC,SAAgB,QAAQ,CAAC,CAAa,EAAE,MAAc,EAAE,KAAkB,EAAE,UAAU,GAAG,IAAI;IAC3F,MAAM,KAAK,GAAG,IAAA,qBAAY,EAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACrC,MAAM,WAAW,GAAG,UAAU,IAAI,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAE5D,IAAI,WAAW,EAAE;QACf,OAAO,KAAK,CAAC;KAC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;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAE9B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAE9B,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,IAAI,EAAE,GAAG,CAAC,CAAC;IAGX,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK,EAAE;QACpC,EAAE,GAAG,CAAC,IAAI,CAAC;KACZ;SAAM,IAAI,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE;QACrD,EAAE,GAAG,KAAK,GAAG,IAAI,CAAC;KACnB;IAGD,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,IAAI,IAAI,MAAM,EAAE;QACrC,EAAE,GAAG,CAAC,IAAI,CAAC;KACZ;SAAM,IAAI,IAAI,GAAG,MAAM,IAAI,IAAI,GAAG,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE;QACvD,EAAE,GAAG,MAAM,GAAG,IAAI,CAAC;KACpB;IAED,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;AACpB,CAAC;AA1BD,8BA0BC","file":"place.js","sourcesContent":["import type { IText, Text } from '@visactor/vrender';\nimport type { IAABBBounds, IBoundsLike } from '@visactor/vutils';\nimport { isFunction } from '@visactor/vutils';\nimport type { PointLocationCfg } from '../../core/type';\nimport type { LabelBase } from '../base';\nimport type { BaseLabelAttrs, OverlapAttrs, Strategy } from '../type';\nimport type { Bitmap } from './bitmap';\nimport type { BitmapTool } from './scaler';\nimport { boundToRange } from './scaler';\n\n/**\n * 防重叠逻辑参考 https://github.com/vega/vega/\n * Copyright (c) 2015-2023, University of Washington Interactive Data Lab\n All rights reserved.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions are met:\n\n 1. Redistributions of source code must retain the above copyright notice, this\n list of conditions and the following disclaimer.\n\n 2. Redistributions in binary form must reproduce the above copyright notice,\n this list of conditions and the following disclaimer in the documentation\n and/or other materials provided with the distribution.\n\n 3. Neither the name of the copyright holder nor the names of its contributors\n may be used to endorse or promote products derived from this software\n without specific prior written permission.\n\n THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE\n FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\nexport function canPlace($: BitmapTool, bitmap: Bitmap, bound: IBoundsLike, checkBound = true) {\n const range = boundToRange($, bound);\n const outOfBounds = checkBound && bitmap.outOfBounds(range);\n\n if (outOfBounds) {\n return false;\n }\n\n return !bitmap.getRange(range);\n}\n\n/**\n * 是否在图形内部\n * @param textBound\n * @param shapeBound\n * @returns\n */\nexport function canPlaceInside(textBound: IBoundsLike, shapeBound: IAABBBounds) {\n if (!textBound || !shapeBound) {\n return false;\n }\n return shapeBound.encloses(textBound);\n}\n\nexport function placeToCandidates(\n $: BitmapTool,\n bitmap: Bitmap,\n text: Text,\n candidates: PointLocationCfg[] = [],\n clampForce = true\n): PointLocationCfg | false {\n for (let i = 0; i < candidates.length; i++) {\n const tempText = text.clone();\n tempText.setAttributes(candidates[i]);\n tempText.update();\n\n if (canPlace($, bitmap, boundToRange($, tempText.AABBBounds), clampForce)) {\n bitmap.setRange(boundToRange($, tempText.AABBBounds, true));\n return candidates[i];\n }\n }\n return false;\n}\n\nexport function place<T extends BaseLabelAttrs>(\n $: BitmapTool,\n bitmap: Bitmap,\n s: Strategy,\n attrs: T,\n text: Text,\n bounds: IBoundsLike,\n labeling?: LabelBase<T>['labeling']\n): PointLocationCfg | false {\n if (s.type === 'bound' || s.type === 'position') {\n if (isFunction(labeling)) {\n // TODO:这里可以 filter 掉初始位置,提升一部分性能\n const userPosition = isFunction(s.position) ? s.position(text.attribute) : s.position;\n const positions = (userPosition || defaultLabelPosition(attrs.type)) as string[];\n const candidates = positions.map(p => labeling(text.AABBBounds, bounds, p, attrs.offset) as PointLocationCfg);\n return placeToCandidates($, bitmap, text, candidates, (attrs.overlap as OverlapAttrs)?.clampForce);\n }\n return false;\n }\n\n if (s.type === 'moveY') {\n const offset = s.offset ? (isFunction(s.offset) ? s.offset(text.attribute) : s.offset) : [];\n const candidates = offset.map(dy => {\n return { x: text.attribute.x as number, y: (text.attribute.y as number) + dy };\n });\n return placeToCandidates($, bitmap, text, candidates, (attrs.overlap as OverlapAttrs)?.clampForce);\n }\n\n if (s.type === 'moveX') {\n const offset = s.offset ? (isFunction(s.offset) ? s.offset(text.attribute) : s.offset) : [];\n const candidates = offset.map(dx => {\n return { x: (text.attribute.x as number) + dx, y: text.attribute.y as number };\n });\n return placeToCandidates($, bitmap, text, candidates, (attrs.overlap as OverlapAttrs)?.clampForce);\n }\n return false;\n}\n\nexport const DefaultPositions = [\n 'top',\n 'bottom',\n 'right',\n 'left',\n 'top-right',\n 'bottom-right',\n 'top-left',\n 'bottom-left'\n];\nexport const DefaultRectPositions = ['top', 'inside-top', 'inside'];\n\nexport function defaultLabelPosition(type?: string) {\n switch (type) {\n case 'rect':\n return DefaultRectPositions;\n default:\n return DefaultPositions;\n }\n}\n\nexport function clampText(text: IText, width: number, height: number) {\n const { x1, x2, y1, y2 } = text.AABBBounds;\n const minX = Math.min(x1, x2);\n const maxX = Math.max(x1, x2);\n\n const minY = Math.min(y1, y2);\n const maxY = Math.max(y1, y2);\n\n let dx = 0;\n let dy = 0;\n\n // x 方向\n if (minX < 0 && maxX - minX <= width) {\n dx = -minX;\n } else if (maxX > width && minX - (maxX - width) >= 0) {\n dx = width - maxX;\n }\n\n // y 方向\n if (minY < 0 && maxY - minY <= height) {\n dy = -minY;\n } else if (maxY > height && minY - (maxY - height) >= 0) {\n dy = height - maxY;\n }\n\n return { dx, dy };\n}\n"]}
@@ -1,10 +1,12 @@
1
- import { IBoundsLike } from '@visactor/vutils';
2
- import type { ITextGraphicAttribute } from '@visactor/vrender';
1
+ import type { IBoundsLike } from '@visactor/vutils';
3
2
  import type { RectLabelAttrs } from './type';
4
3
  import { LabelBase } from './base';
5
4
  export declare class RectLabel extends LabelBase<RectLabelAttrs> {
6
5
  static tag: string;
7
6
  static defaultAttributes: Partial<RectLabelAttrs>;
8
7
  constructor(attributes: RectLabelAttrs);
9
- protected labeling(textBounds: IBoundsLike, graphicBounds: IBoundsLike, position?: string, offset?: number): Partial<ITextGraphicAttribute> | undefined;
8
+ protected labeling(textBounds: IBoundsLike, graphicBounds: IBoundsLike, position?: string, offset?: number): {
9
+ x: number;
10
+ y: number;
11
+ };
10
12
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["label/rect.ts"],"names":[],"mappings":";;;AAAA,6CAAsD;AAGtD,iCAAmC;AAEnC,MAAa,SAAU,SAAQ,gBAAyB;IAgBtD,YAAY,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FH,8BAoFC;AAnFQ,aAAG,GAAG,YAAY,CAAC;AAEnB,2BAAiB,GAA4B;IAClD,SAAS,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,IAAI,EAAE,MAAM;QACZ,SAAS,EAAE,QAAQ;QACnB,YAAY,EAAE,QAAQ;QACtB,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;KAC9B;IACD,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,CAAC;IACT,QAAQ,EAAE,KAAK;CAChB,CAAC","file":"rect.js","sourcesContent":["import { merge, IBoundsLike } from '@visactor/vutils';\nimport type { ITextGraphicAttribute } from '@visactor/vrender';\nimport type { RectLabelAttrs } from './type';\nimport { LabelBase } from './base';\n\nexport class RectLabel extends LabelBase<RectLabelAttrs> {\n static tag = 'rect-label';\n\n static defaultAttributes: Partial<RectLabelAttrs> = {\n textStyle: {\n fontSize: 12,\n fill: '#000',\n textAlign: 'center',\n textBaseline: 'middle',\n boundsPadding: [-1, 0, -1, 0] // to ignore the textBound buf\n },\n position: 'top',\n offset: 5,\n pickable: false\n };\n\n constructor(attributes: RectLabelAttrs) {\n super(merge({}, RectLabel.defaultAttributes, attributes));\n }\n\n protected labeling(\n textBounds: IBoundsLike,\n graphicBounds: IBoundsLike,\n position = 'top',\n offset = 0\n ): Partial<ITextGraphicAttribute> | undefined {\n if (!textBounds || !graphicBounds) {\n return;\n }\n\n const { x1, y1, x2, y2 } = textBounds;\n const width = Math.abs(x2 - x1);\n const height = Math.abs(y2 - y1);\n\n const rectWidth = Math.abs(graphicBounds.x2 - graphicBounds.x1);\n const rectHeight = Math.abs(graphicBounds.y2 - graphicBounds.y1);\n let anchorX = (graphicBounds.x1 + graphicBounds.x2) / 2;\n let anchorY = (graphicBounds.y1 + graphicBounds.y2) / 2;\n\n let sx = 0;\n let sy = 0;\n\n switch (position) {\n case 'top':\n case 'inside-top':\n sy = -0.5;\n break;\n case 'bottom':\n case 'inside-bottom':\n sy = 0.5;\n break;\n case 'left':\n case 'inside-left':\n sx = -0.5;\n break;\n case 'right':\n case 'inside-right':\n sx = 0.5;\n break;\n }\n\n anchorX += sx * rectWidth;\n anchorY += sy * rectHeight;\n\n let vx = 0;\n let vy = 0;\n\n const isInside = position.includes('inside');\n\n if (position.includes('top')) {\n vy = isInside ? 1 : -1;\n } else if (position.includes('bottom')) {\n vy = isInside ? -1 : 1;\n } else if (position.includes('left')) {\n vx = isInside ? 1 : -1;\n } else if (position.includes('right')) {\n vx = isInside ? -1 : 1;\n }\n\n const x = anchorX + vx * offset + (vx * width) / 2;\n const y = anchorY + vy * offset + (vy * height) / 2;\n\n return { x, y };\n }\n}\n"]}
1
+ {"version":3,"sources":["label/rect.ts"],"names":[],"mappings":";;;AACA,6CAAyC;AAGzC,iCAAmC;AAEnC,MAAa,SAAU,SAAQ,gBAAyB;IAgBtD,YAAY,UAA0B;QACpC,KAAK,CAAC,IAAA,cAAK,EAAC,EAAE,EAAE,SAAS,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;IAC5D,CAAC;IAES,QAAQ,CAAC,UAAuB,EAAE,aAA0B,EAAE,QAAQ,GAAG,KAAK,EAAE,MAAM,GAAG,CAAC;QAClG,IAAI,CAAC,UAAU,IAAI,CAAC,aAAa,EAAE;YACjC,OAAO;SACR;QAED,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,UAAU,CAAC;QACtC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QAEjC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;QAChE,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,aA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QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YACpC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACxB;aAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YACrC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACxB;QAED,MAAM,CAAC,GAAG,OAAO,GAAG,EAAE,GAAG,MAAM,GAAG,CAAC,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QACnD,MAAM,CAAC,GAAG,OAAO,GAAG,EAAE,GAAG,MAAM,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAEpD,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IAClB,CAAC;;AA9EH,8BA+EC;AA9EQ,aAAG,GAAG,YAAY,CAAC;AAEnB,2BAAiB,GAA4B;IAClD,SAAS,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,IAAI,EAAE,MAAM;QACZ,SAAS,EAAE,QAAQ;QACnB,YAAY,EAAE,QAAQ;QACtB,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;KAC9B;IACD,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,CAAC;IACT,QAAQ,EAAE,KAAK;CAChB,CAAC","file":"rect.js","sourcesContent":["import type { IBoundsLike } from '@visactor/vutils';\nimport { merge } from '@visactor/vutils';\nimport type { ITextGraphicAttribute } from '@visactor/vrender';\nimport type { RectLabelAttrs } from './type';\nimport { LabelBase } from './base';\n\nexport class RectLabel extends LabelBase<RectLabelAttrs> {\n static tag = 'rect-label';\n\n static defaultAttributes: Partial<RectLabelAttrs> = {\n textStyle: {\n fontSize: 12,\n fill: '#000',\n textAlign: 'center',\n textBaseline: 'middle',\n boundsPadding: [-1, 0, -1, 0] // to ignore the textBound buf\n },\n position: 'top',\n offset: 5,\n pickable: false\n };\n\n constructor(attributes: RectLabelAttrs) {\n super(merge({}, RectLabel.defaultAttributes, attributes));\n }\n\n protected labeling(textBounds: IBoundsLike, graphicBounds: IBoundsLike, position = 'top', offset = 0) {\n if (!textBounds || !graphicBounds) {\n return;\n }\n\n const { x1, y1, x2, y2 } = textBounds;\n const width = Math.abs(x2 - x1);\n const height = Math.abs(y2 - y1);\n\n const rectWidth = Math.abs(graphicBounds.x2 - graphicBounds.x1);\n const rectHeight = Math.abs(graphicBounds.y2 - graphicBounds.y1);\n let anchorX = (graphicBounds.x1 + graphicBounds.x2) / 2;\n let anchorY = (graphicBounds.y1 + graphicBounds.y2) / 2;\n\n let sx = 0;\n let sy = 0;\n\n switch (position) {\n case 'top':\n case 'inside-top':\n sy = -0.5;\n break;\n case 'bottom':\n case 'inside-bottom':\n sy = 0.5;\n break;\n case 'left':\n case 'inside-left':\n sx = -0.5;\n break;\n case 'right':\n case 'inside-right':\n sx = 0.5;\n break;\n }\n\n anchorX += sx * rectWidth;\n anchorY += sy * rectHeight;\n\n let vx = 0;\n let vy = 0;\n\n const isInside = position.includes('inside');\n\n if (position.includes('top')) {\n vy = isInside ? 1 : -1;\n } else if (position.includes('bottom')) {\n vy = isInside ? -1 : 1;\n } else if (position.includes('left')) {\n vx = isInside ? 1 : -1;\n } else if (position.includes('right')) {\n vx = isInside ? -1 : 1;\n }\n\n const x = anchorX + vx * offset + (vx * width) / 2;\n const y = anchorY + vy * offset + (vy * height) / 2;\n\n return { x, y };\n }\n}\n"]}