@visactor/vrender-components 0.22.5 → 0.22.6-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.
package/cjs/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const version = "0.22.5";
1
+ export declare const version = "0.22.6-alpha.1";
2
2
  export * from './core/base';
3
3
  export * from './core/type';
4
4
  export * from './scrollbar';
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.22.5", __exportStar(require("./core/base"), exports),
20
+ }), exports.version = void 0, exports.version = "0.22.6-alpha.1", __exportStar(require("./core/base"), exports),
21
21
  __exportStar(require("./core/type"), exports), __exportStar(require("./scrollbar"), exports),
22
22
  __exportStar(require("./tag"), exports), __exportStar(require("./poptip"), exports),
23
23
  __exportStar(require("./crosshair"), exports), __exportStar(require("./label"), exports),
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACa,QAAA,OAAO,GAAG,QAAQ,CAAC;AAEhC,8CAA4B;AAC5B,8CAA4B;AAC5B,8CAA4B;AAC5B,wCAAsB;AACtB,2CAAyB;AACzB,8CAA4B;AAC5B,0CAAwB;AACxB,yCAAuB;AACvB,8CAA4B;AAC5B,4CAA0B;AAC1B,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB;AACxB,2CAAyB;AACzB,0CAAwB;AACxB,8CAA4B;AAC5B,2CAAyB;AACzB,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB;AACxB,4CAA0B;AAC1B,6CAA2B;AAC3B,8CAA4B;AAC5B,wCAAsB;AACtB,6CAA2B;AAC3B,0CAAwB;AACxB,8CAA4B;AAC5B,4CAA0B;AAC1B,yCAAuB;AACvB,2CAAyB;AACzB,+CAA6B","file":"index.js","sourcesContent":["// 导出版本号\nexport const version = \"0.22.5\";\n\nexport * from './core/base';\nexport * from './core/type';\nexport * from './scrollbar';\nexport * from './tag';\nexport * from './poptip';\nexport * from './crosshair';\nexport * from './label';\nexport * from './axis';\nexport * from './axis/grid';\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 './timeline';\nexport * from './interface';\nexport * from './jsx';\nexport * from './checkbox';\nexport * from './radio';\nexport * from './empty-tip';\nexport * from './weather';\nexport * from './util';\nexport * from './switch';\nexport * from './label-item';\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACa,QAAA,OAAO,GAAG,gBAAgB,CAAC;AAExC,8CAA4B;AAC5B,8CAA4B;AAC5B,8CAA4B;AAC5B,wCAAsB;AACtB,2CAAyB;AACzB,8CAA4B;AAC5B,0CAAwB;AACxB,yCAAuB;AACvB,8CAA4B;AAC5B,4CAA0B;AAC1B,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB;AACxB,2CAAyB;AACzB,0CAAwB;AACxB,8CAA4B;AAC5B,2CAAyB;AACzB,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB;AACxB,4CAA0B;AAC1B,6CAA2B;AAC3B,8CAA4B;AAC5B,wCAAsB;AACtB,6CAA2B;AAC3B,0CAAwB;AACxB,8CAA4B;AAC5B,4CAA0B;AAC1B,yCAAuB;AACvB,2CAAyB;AACzB,+CAA6B","file":"index.js","sourcesContent":["// 导出版本号\nexport const version = \"0.22.6-alpha.1\";\n\nexport * from './core/base';\nexport * from './core/type';\nexport * from './scrollbar';\nexport * from './tag';\nexport * from './poptip';\nexport * from './crosshair';\nexport * from './label';\nexport * from './axis';\nexport * from './axis/grid';\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 './timeline';\nexport * from './interface';\nexport * from './jsx';\nexport * from './checkbox';\nexport * from './radio';\nexport * from './empty-tip';\nexport * from './weather';\nexport * from './util';\nexport * from './switch';\nexport * from './label-item';\n"]}
@@ -19,9 +19,9 @@ function bitmapTool(width, height, padding = {
19
19
  }
20
20
 
21
21
  function clampRangeByBitmap($, range) {
22
- const {x1: x1, x2: x2, y1: y1, y2: y2} = range, {top: top = 0, left: left = 0, right: right = 0, bottom: bottom = 0} = $.padding, _x1 = (0,
23
- vutils_1.clamp)(x1, -left, $.width + right), _x2 = (0, vutils_1.clamp)(x2, -left, $.width + right), _y1 = (0,
24
- vutils_1.clamp)(y1, -top, $.height + bottom), _y2 = (0, vutils_1.clamp)(y2, -top, $.height + bottom);
22
+ const {x1: x1, x2: x2, y1: y1, y2: y2} = range, _x1 = (0, vutils_1.clamp)(x1, 0, $.width), _x2 = (0,
23
+ vutils_1.clamp)(x2, 0, $.width), _y1 = (0, vutils_1.clamp)(y1, 0, $.height), _y2 = (0,
24
+ vutils_1.clamp)(y2, 0, $.height);
25
25
  return {
26
26
  x1: $.x(_x1),
27
27
  x2: $.x(_x2),
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/label/overlap/scaler.ts"],"names":[],"mappings":";;;AACA,6CAAuD;AACvD,qCAAkC;AAiClC,SAAgB,UAAU,CACxB,KAAa,EACb,MAAc,EACd,UAA4E,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;IAEpH,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC;IAC7D,MAAM,K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EAAE,CAAC;KAClB,CAAC;AACJ,CAAC;AAXD,oCAWC","file":"scaler.js","sourcesContent":["import type { IBoundsLike } from '@visactor/vutils';\nimport { clamp as clampRange } from '@visactor/vutils';\nimport { bitmap } from './bitmap';\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 bitmapTool(\n width: number,\n height: number,\n padding: { top?: number; left?: number; right?: number; bottom?: number } = { top: 0, left: 0, right: 0, bottom: 0 }\n) {\n const { top = 0, left = 0, right = 0, bottom = 0 } = padding;\n const ratio = Math.max(1, Math.sqrt((width * height) / 1e6));\n const w = ~~((width + left + right + ratio) / ratio);\n const h = ~~((height + top + bottom + ratio) / ratio);\n const scale = (_: number) => ~~(_ / ratio);\n\n scale.bitmap = () => bitmap(w, h);\n scale.x = (_: number) => ~~((_ + left) / ratio);\n scale.y = (_: number) => ~~((_ + top) / ratio);\n\n scale.ratio = ratio;\n scale.padding = padding;\n scale.width = width;\n scale.height = height;\n\n return scale;\n}\n\nexport function clampRangeByBitmap($: BitmapTool, range: IBoundsLike) {\n const { x1, x2, y1, y2 } = range;\n const { top = 0, left = 0, right = 0, bottom = 0 } = $.padding;\n const _x1 = clampRange(x1, -left, $.width + right);\n const _x2 = clampRange(x2, -left, $.width + right);\n const _y1 = clampRange(y1, -top, $.height + bottom);\n const _y2 = clampRange(y2, -top, $.height + bottom);\n return {\n x1: $.x(_x1),\n x2: $.x(_x2),\n y1: $.y(_y1),\n y2: $.y(_y2)\n };\n}\n\nexport function boundToRange($: BitmapTool, bound: IBoundsLike, clamp: boolean = false) {\n if (clamp) {\n return clampRangeByBitmap($, bound);\n }\n\n return {\n x1: $.x(bound.x1),\n x2: $.x(bound.x2),\n y1: $.y(bound.y1),\n y2: $.y(bound.y2)\n };\n}\n\nexport type BitmapTool = ReturnType<typeof bitmapTool>;\n"]}
1
+ {"version":3,"sources":["../src/label/overlap/scaler.ts"],"names":[],"mappings":";;;AACA,6CAAuD;AACvD,qCAAkC;AAiClC,SAAgB,UAAU,CACxB,KAAa,EACb,MAAc,EACd,UAA4E,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;IAEpH,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,OAAO,CAA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A,cAAU,EAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;IACvC,MAAM,GAAG,GAAG,IAAA,cAAU,EAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;IACvC,MAAM,GAAG,GAAG,IAAA,cAAU,EAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,GAAG,GAAG,IAAA,cAAU,EAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;IACxC,OAAO;QACL,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACZ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACZ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACZ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;KACb,CAAC;AACJ,CAAC;AAZD,gDAYC;AAED,SAAgB,YAAY,CAAC,CAAa,EAAE,KAAkB,EAAE,QAAiB,KAAK;IACpF,IAAI,KAAK,EAAE;QACT,OAAO,kBAAkB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;KACrC;IAED,OAAO;QACL,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;KAClB,CAAC;AACJ,CAAC;AAXD,oCAWC","file":"scaler.js","sourcesContent":["import type { IBoundsLike } from '@visactor/vutils';\nimport { clamp as clampRange } from '@visactor/vutils';\nimport { bitmap } from './bitmap';\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 bitmapTool(\n width: number,\n height: number,\n padding: { top?: number; left?: number; right?: number; bottom?: number } = { top: 0, left: 0, right: 0, bottom: 0 }\n) {\n const { top = 0, left = 0, right = 0, bottom = 0 } = padding;\n const ratio = Math.max(1, Math.sqrt((width * height) / 1e6));\n const w = ~~((width + left + right + ratio) / ratio);\n const h = ~~((height + top + bottom + ratio) / ratio);\n const scale = (_: number) => ~~(_ / ratio);\n\n scale.bitmap = () => bitmap(w, h);\n scale.x = (_: number) => ~~((_ + left) / ratio);\n scale.y = (_: number) => ~~((_ + top) / ratio);\n\n scale.ratio = ratio;\n scale.padding = padding;\n scale.width = width;\n scale.height = height;\n\n return scale;\n}\n\nexport function clampRangeByBitmap($: BitmapTool, range: IBoundsLike) {\n const { x1, x2, y1, y2 } = range;\n const _x1 = clampRange(x1, 0, $.width);\n const _x2 = clampRange(x2, 0, $.width);\n const _y1 = clampRange(y1, 0, $.height);\n const _y2 = clampRange(y2, 0, $.height);\n return {\n x1: $.x(_x1),\n x2: $.x(_x2),\n y1: $.y(_y1),\n y2: $.y(_y2)\n };\n}\n\nexport function boundToRange($: BitmapTool, bound: IBoundsLike, clamp: boolean = false) {\n if (clamp) {\n return clampRangeByBitmap($, bound);\n }\n\n return {\n x1: $.x(bound.x1),\n x2: $.x(bound.x2),\n y1: $.y(bound.y1),\n y2: $.y(bound.y2)\n };\n}\n\nexport type BitmapTool = ReturnType<typeof bitmapTool>;\n"]}
package/cjs/tag/tag.js CHANGED
@@ -55,7 +55,7 @@ class Tag extends base_1.AbstractComponent {
55
55
  }), "symbol"), (0, vutils_1.isEmpty)(null == state ? void 0 : state.shape) || (symbol.states = state.shape),
56
56
  shapeVisible && (symbolPlaceWidth = maxSize + space);
57
57
  }
58
- let textShape, textWidth, textHeight;
58
+ let textShape;
59
59
  tagWidth += symbolPlaceWidth, textX += symbolPlaceWidth;
60
60
  if ((0, util_1.isRichText)({
61
61
  text: text
@@ -68,9 +68,8 @@ class Tag extends base_1.AbstractComponent {
68
68
  x: textX,
69
69
  y: 0
70
70
  });
71
- (0, vutils_1.isNil)(richTextAttrs.lineHeight) && (richTextAttrs.lineHeight = textStyle.fontSize),
72
- textShape = group.createOrUpdateChild("tag-text", richTextAttrs, "richtext"), textWidth = textShape.AABBBounds.width(),
73
- textHeight = textShape.AABBBounds.height();
71
+ textShape = group.createOrUpdateChild("tag-text", richTextAttrs, "richtext"), tagWidth += textShape.AABBBounds.width(),
72
+ tagHeight += textShape.AABBBounds.height(), tagX += textShape.AABBBounds.x1, tagY += textShape.AABBBounds.y1;
74
73
  } else {
75
74
  const textAttrs = Object.assign(Object.assign({
76
75
  text: (0, vutils_1.isObject)(text) && "type" in text && "text" === text.type ? text.text : text,
@@ -81,66 +80,63 @@ class Tag extends base_1.AbstractComponent {
81
80
  y: 0
82
81
  });
83
82
  (0, vutils_1.isNil)(textAttrs.lineHeight) && (textAttrs.lineHeight = textStyle.fontSize),
84
- textShape = group.createOrUpdateChild("tag-text", textAttrs, "text");
85
- const textBounds = (0, util_1.measureTextSize)(textAttrs.text, textStyle, null === (_b = null === (_a = this.stage) || void 0 === _a ? void 0 : _a.getTheme()) || void 0 === _b ? void 0 : _b.text);
86
- textWidth = textBounds.width, textHeight = textBounds.height;
87
- }
88
- tagWidth += textWidth;
89
- const size = null !== (_c = shape.size) && void 0 !== _c ? _c : 10, maxSize = (0,
90
- vutils_1.isNumber)(size) ? size : Math.max(size[0], size[1]);
91
- tagHeight += Math.max(textHeight, shape.visible ? maxSize : 0);
92
- const {textAlign: textAlign, textBaseline: textBaseline} = textStyle;
93
- ((0, vutils_1.isValid)(minWidth) || (0, vutils_1.isValid)(maxWidth)) && ((0, vutils_1.isValid)(minWidth) && tagWidth < minWidth && (tagWidth = minWidth),
94
- (0, vutils_1.isValid)(maxWidth) && tagWidth > maxWidth && (tagWidth = maxWidth,
95
- textShape.setAttribute("maxLineWidth", maxWidth - parsedPadding[1] - parsedPadding[2]))),
96
- tagX = 0, tagY = 0;
97
- let flag = 0;
98
- "left" === textAlign || "start" === textAlign ? flag = 1 : "right" === textAlign || "end" === textAlign ? flag = -1 : "center" === textAlign && (flag = 0),
99
- flag ? flag < 0 ? (tagX -= tagWidth, symbol && symbol.setAttribute("x", (symbol.attribute.x || 0) - textWidth),
100
- group.setAttribute("x", -parsedPadding[1] - symbolPlaceWidth)) : flag > 0 && group.setAttribute("x", parsedPadding[3]) : (tagX -= tagWidth / 2,
101
- symbol && symbol.setAttribute("x", (symbol.attribute.x || 0) - textWidth / 2), group.setAttribute("x", -symbolPlaceWidth / 2));
102
- const shouldRight = "right" === containerTextAlign || "end" === containerTextAlign, shouldLeft = "left" === containerTextAlign || "start" === containerTextAlign, updateTextAttrs = (textX, textAlign) => {
103
- "richtext" === textShape.type ? textShape.setAttributes({
104
- x: textX,
105
- textAlign: textAlign,
106
- textConfig: (0, vutils_1.array)(textShape.attribute.textConfig).map((t => Object.assign(Object.assign({}, t), {
107
- textAlign: textAlign
108
- })))
109
- }) : textShape.setAttributes({
110
- x: textX,
111
- textAlign: textAlign
112
- });
113
- };
114
- if ((containerTextAlign ? "center" === containerTextAlign : textAlwaysCenter) && flag) {
115
- const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3], tsWidth = textWidth + symbolPlaceWidth, textX = 1 === flag ? (containerWidth - tsWidth) / 2 + symbolPlaceWidth + textWidth / 2 : parsedPadding[0] + symbolPlaceWidth - (tagWidth / 2 + tsWidth / 2 - symbolPlaceWidth) + textWidth / 2;
116
- if (updateTextAttrs(textX, "center"), symbol) {
117
- const symbolX = textX - textWidth / 2 - symbolPlaceWidth + maxSize / 2;
118
- symbol.setAttributes({
119
- x: symbolX
120
- });
83
+ textShape = group.createOrUpdateChild("tag-text", textAttrs, "text"), (0, vutils_1.isEmpty)(null == state ? void 0 : state.text) || (textShape.states = state.text);
84
+ const textBounds = (0, util_1.measureTextSize)(textAttrs.text, textStyle, null === (_b = null === (_a = this.stage) || void 0 === _a ? void 0 : _a.getTheme()) || void 0 === _b ? void 0 : _b.text), textWidth = textBounds.width, textHeight = textBounds.height;
85
+ tagWidth += textWidth;
86
+ const size = null !== (_c = shape.size) && void 0 !== _c ? _c : 10, maxSize = (0,
87
+ vutils_1.isNumber)(size) ? size : Math.max(size[0], size[1]);
88
+ tagHeight += Math.max(textHeight, shape.visible ? maxSize : 0);
89
+ const {textAlign: textAlign, textBaseline: textBaseline} = textStyle;
90
+ ((0, vutils_1.isValid)(minWidth) || (0, vutils_1.isValid)(maxWidth)) && ((0, vutils_1.isValid)(minWidth) && tagWidth < minWidth && (tagWidth = minWidth),
91
+ (0, vutils_1.isValid)(maxWidth) && tagWidth > maxWidth && (tagWidth = maxWidth,
92
+ textShape.setAttribute("maxLineWidth", maxWidth - parsedPadding[1] - parsedPadding[2]))),
93
+ tagX = 0, tagY = 0;
94
+ let flag = 0;
95
+ "left" === textAlign || "start" === textAlign ? flag = 1 : "right" === textAlign || "end" === textAlign ? flag = -1 : "center" === textAlign && (flag = 0),
96
+ flag ? flag < 0 ? (tagX -= tagWidth, symbol && symbol.setAttribute("x", (symbol.attribute.x || 0) - textWidth),
97
+ group.setAttribute("x", -parsedPadding[1] - symbolPlaceWidth)) : flag > 0 && group.setAttribute("x", parsedPadding[3]) : (tagX -= tagWidth / 2,
98
+ symbol && symbol.setAttribute("x", (symbol.attribute.x || 0) - textWidth / 2), group.setAttribute("x", -symbolPlaceWidth / 2));
99
+ const shouldRight = "right" === containerTextAlign || "end" === containerTextAlign, shouldLeft = "left" === containerTextAlign || "start" === containerTextAlign;
100
+ if ((containerTextAlign ? "center" === containerTextAlign : textAlwaysCenter) && flag) {
101
+ const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3], tsWidth = textWidth + symbolPlaceWidth, textX = 1 === flag ? (containerWidth - tsWidth) / 2 + symbolPlaceWidth + textWidth / 2 : parsedPadding[0] + symbolPlaceWidth - (tagWidth / 2 + tsWidth / 2 - symbolPlaceWidth) + textWidth / 2;
102
+ if (textShape.setAttributes({
103
+ x: textX,
104
+ textAlign: "center"
105
+ }), symbol) {
106
+ const symbolX = textX - textWidth / 2 - symbolPlaceWidth + maxSize / 2;
107
+ symbol.setAttributes({
108
+ x: symbolX
109
+ });
110
+ }
121
111
  }
122
- }
123
- if (shouldLeft && 1 !== flag) {
124
- const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3], offset = 0 === flag ? -containerWidth / 2 + symbolPlaceWidth / 2 : -tagWidth + parsedPadding[3] + parsedPadding[1] + symbolPlaceWidth;
125
- if (updateTextAttrs(offset + symbolPlaceWidth, "left"), symbol) {
126
- const symbolX = offset + maxSize / 2;
127
- symbol.setAttributes({
128
- x: symbolX
129
- });
112
+ if (shouldLeft && 1 !== flag) {
113
+ const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3], offset = 0 === flag ? -containerWidth / 2 + symbolPlaceWidth / 2 : -tagWidth + parsedPadding[3] + parsedPadding[1] + symbolPlaceWidth, textX = offset + symbolPlaceWidth;
114
+ if (textShape.setAttributes({
115
+ x: textX,
116
+ textAlign: "left"
117
+ }), symbol) {
118
+ const symbolX = offset + maxSize / 2;
119
+ symbol.setAttributes({
120
+ x: symbolX
121
+ });
122
+ }
130
123
  }
131
- }
132
- if (shouldRight && -1 !== flag) {
133
- const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3], textX = 0 === flag ? containerWidth / 2 + symbolPlaceWidth / 2 : containerWidth;
134
- if (updateTextAttrs(textX, "right"), symbol) {
135
- const symbolX = textX - textWidth - symbolPlaceWidth + maxSize / 2;
136
- symbol.setAttributes({
137
- x: symbolX
138
- });
124
+ if (shouldRight && -1 !== flag) {
125
+ const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3], textX = 0 === flag ? containerWidth / 2 + symbolPlaceWidth / 2 : containerWidth;
126
+ if (textShape.setAttributes({
127
+ x: textX,
128
+ textAlign: "right"
129
+ }), symbol) {
130
+ const symbolX = textX - textWidth - symbolPlaceWidth + maxSize / 2;
131
+ symbol.setAttributes({
132
+ x: symbolX
133
+ });
134
+ }
139
135
  }
136
+ "middle" === textBaseline ? (tagY -= tagHeight / 2, symbol && symbol.setAttribute("y", 0)) : "bottom" === textBaseline ? (tagY -= tagHeight,
137
+ symbol && symbol.setAttribute("y", -textHeight / 2), group.setAttribute("y", -parsedPadding[2])) : "top" === textBaseline && (group.setAttribute("y", parsedPadding[0]),
138
+ symbol && symbol.setAttribute("y", textHeight / 2));
140
139
  }
141
- "middle" === textBaseline ? (tagY -= tagHeight / 2, symbol && symbol.setAttribute("y", 0)) : "bottom" === textBaseline ? (tagY -= tagHeight,
142
- symbol && symbol.setAttribute("y", -textHeight / 2), group.setAttribute("y", -parsedPadding[2])) : "top" === textBaseline && (group.setAttribute("y", parsedPadding[0]),
143
- symbol && symbol.setAttribute("y", textHeight / 2)), (0, vutils_1.isEmpty)(null == state ? void 0 : state.text) || (textShape.states = state.text);
144
140
  const {visible: bgVisible} = panel, backgroundStyle = __rest(panel, [ "visible" ]);
145
141
  if (visible && (0, vutils_1.isBoolean)(bgVisible)) {
146
142
  const bgRect = this.createOrUpdateChild("tag-panel", Object.assign(Object.assign({}, backgroundStyle), {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/tag/tag.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAGA,yDAWgC;AAChC,6CAU0B;AAC1B,uCAAiD;AACjD,kCAAkF;AAGlF,yCAA8C;AAG9C,IAAA,2BAAgB,GAAE,CAAC;AACnB,MAAa,GAAI,SAAQ,wBAA0C;IAWjE,SAAS;QACP,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAkBD,YAAY,UAAyB,EAAE,OAA0B;QAC/D,KAAK,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAA,cAAK,EAAC,EAAE,EAAE,GAAG,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;QAnC1F,SAAI,GAAG,KAAK,CAAC;QAKL,eAAU,GAAa,EAAE,CAAC;QAC1B,gBAAW,GAAa,EAAE,CAAC;QAC3B,kBAAa,GAAa,EAAE,CAAC;QAC7B,gBAAW,GAAa,EAAE,CAAC;IA4BnC,CAAC;IAES,MAAM;;QACd,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,MAAM,EACJ,IAAI,GAAG,EAAE,EACT,SAA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AAC,aAAa,CAAC,CAAA,CAAC;QACzE,IAAI,CAAC,WAAW,CAAC,MAAM,KAAI,MAAA,IAAI,CAAC,UAAU,0CAAE,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA,CAAC;IAC1E,CAAC;;AAtWH,kBAuWC;AApVQ,qBAAiB,GAA2B;IACjD,OAAO,EAAE,IAAI;IACb,SAAS,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,IAAI,EAAE,MAAM;QACZ,SAAS,EAAE,MAAM;QACjB,YAAY,EAAE,KAAK;KACpB;IACD,KAAK,EAAE,CAAC;IACR,OAAO,EAAE,CAAC;IAEV,KAAK,EAAE;QACL,IAAI,EAAE,MAAM;KACb;CACF,CAAC","file":"tag.js","sourcesContent":["/**\n * @description 标签组件\n */\nimport {\n type IGroup,\n type IRect,\n type ISymbol,\n type IText,\n type ITextAttribute,\n type ITextGraphicAttribute,\n type IRichTextGraphicAttribute,\n type IRichText,\n type IGraphicAttribute,\n CustomPath2D\n} from '@visactor/vrender-core';\nimport {\n array,\n isBoolean,\n isEmpty,\n isNil,\n isNumber,\n isObject,\n isValid,\n merge,\n normalizePadding\n} from '@visactor/vutils';\nimport { AbstractComponent } from '../core/base';\nimport { isRichText, measureTextSize, richTextAttributeTransform } from '../util';\nimport type { BackgroundAttributes, ComponentOptions } from '../interface';\nimport type { TagAttributes, TagShapeAttributes } from './type';\nimport { loadTagComponent } from './register';\nimport type { TextContent } from '../core/type';\n\nloadTagComponent();\nexport class Tag extends AbstractComponent<Required<TagAttributes>> {\n name = 'tag';\n\n private _bgRect!: IRect;\n private _textShape!: IText | IRichText;\n private _symbol!: ISymbol;\n private _tagStates: string[] = [];\n private _rectStates: string[] = [];\n private _symbolStates: string[] = [];\n private _textStates: string[] = [];\n\n getBgRect() {\n return this._bgRect;\n }\n\n getTextShape() {\n return this._textShape;\n }\n\n static defaultAttributes: Partial<TagAttributes> = {\n visible: true,\n textStyle: {\n fontSize: 12,\n fill: '#000',\n textAlign: 'left',\n textBaseline: 'top'\n },\n space: 4,\n padding: 4,\n // @ts-ignore\n shape: {\n fill: '#000'\n }\n };\n\n constructor(attributes: TagAttributes, options?: ComponentOptions) {\n super(options?.skipDefault ? attributes : merge({}, Tag.defaultAttributes, attributes));\n }\n\n protected render() {\n this.cacheStates();\n const {\n text = '',\n textStyle = {} as ITextGraphicAttribute | IRichTextGraphicAttribute,\n shape = {} as TagShapeAttributes,\n panel = {} as BackgroundAttributes,\n space = 4,\n minWidth,\n maxWidth,\n padding = 4,\n visible,\n state,\n type,\n textAlwaysCenter,\n containerTextAlign\n } = this.attribute as TagAttributes;\n const parsedPadding = normalizePadding(padding);\n\n const group = this.createOrUpdateChild('tag-content', { x: 0, y: 0, zIndex: 1 }, 'group') as IGroup;\n\n let symbol;\n let tagX = -parsedPadding[3];\n let tagY = -parsedPadding[0];\n let tagWidth = parsedPadding[1] + parsedPadding[3];\n let tagHeight = parsedPadding[0] + parsedPadding[2];\n let textX = 0;\n let symbolPlaceWidth = 0;\n const { visible: shapeVisible, ...shapeStyle } = shape;\n if (isBoolean(shapeVisible)) {\n const size = shapeStyle?.size || 10;\n const maxSize = (isNumber(size) ? size : Math.max(size[0], size[1])) as number;\n\n symbol = group.createOrUpdateChild(\n 'tag-shape',\n {\n symbolType: 'circle',\n size,\n strokeBoundsBuffer: 0,\n ...shapeStyle,\n visible: shapeVisible,\n x: maxSize / 2,\n y: maxSize / 2\n },\n 'symbol'\n ) as ISymbol;\n if (!isEmpty(state?.shape)) {\n symbol.states = state.shape;\n }\n\n if (shapeVisible) {\n symbolPlaceWidth = maxSize + space;\n }\n }\n\n tagWidth += symbolPlaceWidth;\n textX += symbolPlaceWidth;\n\n let textShape: IRichText | IText;\n let textWidth;\n let textHeight;\n\n const isRich = isRichText({ text } as TextContent) || type === 'rich';\n if (isRich) {\n const richTextAttrs = {\n ...richTextAttributeTransform({ type, text, ...textStyle } as any),\n ...(textStyle as IRichTextGraphicAttribute),\n visible: isValid(text) && visible !== false,\n x: textX,\n y: 0\n };\n if (isNil(richTextAttrs.lineHeight)) {\n richTextAttrs.lineHeight = (textStyle as ITextGraphicAttribute).fontSize;\n }\n textShape = group.createOrUpdateChild('tag-text', richTextAttrs, 'richtext') as IRichText;\n textWidth = textShape.AABBBounds.width();\n textHeight = textShape.AABBBounds.height();\n } else {\n const textAttrs = {\n text: isObject(text) && 'type' in text && text.type === 'text' ? text.text : text,\n visible: isValid(text) && visible !== false,\n lineHeight: (textStyle as ITextGraphicAttribute)?.fontSize,\n ...(textStyle as ITextGraphicAttribute),\n x: textX,\n y: 0\n };\n if (isNil(textAttrs.lineHeight)) {\n textAttrs.lineHeight = (textStyle as ITextGraphicAttribute).fontSize;\n }\n textShape = group.createOrUpdateChild('tag-text', textAttrs as ITextGraphicAttribute, 'text') as IText;\n\n // 因为文本可能发生旋转,所以需要使用 measureTextSize 方法\n const textBounds = measureTextSize(textAttrs.text as string, textStyle, this.stage?.getTheme()?.text);\n textWidth = textBounds.width;\n textHeight = textBounds.height;\n }\n\n tagWidth += textWidth;\n const size = shape.size ?? 10;\n const maxSize = (isNumber(size) ? size : Math.max(size[0], size[1])) as number;\n tagHeight += Math.max(textHeight, shape.visible ? maxSize : 0);\n\n const { textAlign, textBaseline } = textStyle as ITextAttribute;\n\n if (isValid(minWidth) || isValid(maxWidth)) {\n if (isValid(minWidth) && tagWidth < minWidth) {\n tagWidth = minWidth;\n }\n if (isValid(maxWidth) && tagWidth > maxWidth) {\n tagWidth = maxWidth;\n textShape.setAttribute('maxLineWidth', maxWidth - parsedPadding[1] - parsedPadding[2]);\n }\n }\n\n tagX = 0;\n tagY = 0;\n let flag = 0;\n if (textAlign === 'left' || textAlign === 'start') {\n flag = 1;\n } else if (textAlign === 'right' || textAlign === 'end') {\n flag = -1;\n } else if (textAlign === 'center') {\n flag = 0;\n }\n if (!flag) {\n tagX -= tagWidth / 2;\n if (symbol) {\n symbol.setAttribute('x', (symbol.attribute.x || 0) - textWidth / 2);\n }\n\n group.setAttribute('x', -symbolPlaceWidth / 2);\n } else if (flag < 0) {\n tagX -= tagWidth;\n if (symbol) {\n symbol.setAttribute('x', (symbol.attribute.x || 0) - textWidth);\n }\n\n group.setAttribute('x', -parsedPadding[1] - symbolPlaceWidth);\n } else if (flag > 0) {\n group.setAttribute('x', parsedPadding[3]);\n }\n\n const shouldCenter = containerTextAlign ? containerTextAlign === 'center' : textAlwaysCenter;\n const shouldRight = containerTextAlign === 'right' || containerTextAlign === 'end';\n const shouldLeft = containerTextAlign === 'left' || containerTextAlign === 'start';\n\n const updateTextAttrs = (textX: number, textAlign: 'center' | 'left' | 'right') => {\n if (textShape.type === 'richtext') {\n textShape.setAttributes({\n x: textX,\n textAlign,\n textConfig: array((textShape.attribute as IRichTextGraphicAttribute).textConfig).map(t => {\n return {\n ...t,\n textAlign\n };\n })\n });\n } else {\n textShape.setAttributes({\n x: textX,\n textAlign\n });\n }\n };\n\n if (shouldCenter && flag) {\n // 文本容器内居中\n // 剔除padding后的内宽度\n const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];\n const tsWidth = textWidth + symbolPlaceWidth;\n const textX =\n flag === 1\n ? (containerWidth - tsWidth) / 2 + symbolPlaceWidth + textWidth / 2\n : parsedPadding[0] + symbolPlaceWidth - (tagWidth / 2 + tsWidth / 2 - symbolPlaceWidth) + textWidth / 2;\n\n updateTextAttrs(textX, 'center');\n if (symbol) {\n const symbolX = textX - textWidth / 2 - symbolPlaceWidth + maxSize / 2;\n symbol.setAttributes({\n x: symbolX\n });\n }\n }\n\n if (shouldLeft && flag !== 1) {\n // 文本容器内朝左展示\n const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];\n const offset =\n flag === 0\n ? -containerWidth / 2 + symbolPlaceWidth / 2\n : -tagWidth + parsedPadding[3] + parsedPadding[1] + symbolPlaceWidth;\n const textX = offset + symbolPlaceWidth;\n\n updateTextAttrs(textX, 'left');\n\n if (symbol) {\n const symbolX = offset + maxSize / 2;\n symbol.setAttributes({\n x: symbolX\n });\n }\n }\n\n if (shouldRight && flag !== -1) {\n // 文本容器内朝右展示\n const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];\n const textX = flag === 0 ? containerWidth / 2 + symbolPlaceWidth / 2 : containerWidth;\n updateTextAttrs(textX, 'right');\n\n if (symbol) {\n const symbolX = textX - textWidth - symbolPlaceWidth + maxSize / 2;\n symbol.setAttributes({\n x: symbolX\n });\n }\n }\n\n if (textBaseline === 'middle') {\n tagY -= tagHeight / 2;\n if (symbol) {\n symbol.setAttribute('y', 0);\n }\n } else if (textBaseline === 'bottom') {\n tagY -= tagHeight;\n if (symbol) {\n symbol.setAttribute('y', -textHeight / 2);\n }\n\n group.setAttribute('y', -parsedPadding[2]);\n } else if (textBaseline === 'top') {\n group.setAttribute('y', parsedPadding[0]);\n if (symbol) {\n symbol.setAttribute('y', textHeight / 2);\n }\n }\n\n if (!isEmpty(state?.text)) {\n textShape.states = state.text;\n }\n // 绘制背景层\n const { visible: bgVisible, ...backgroundStyle } = panel;\n if (visible && isBoolean(bgVisible)) {\n const bgRect = this.createOrUpdateChild(\n 'tag-panel',\n {\n ...backgroundStyle,\n visible: bgVisible && !!text,\n width: tagWidth,\n height: tagHeight,\n x: tagX,\n y: tagY\n },\n 'rect'\n ) as IRect;\n if (!isEmpty(state?.panel)) {\n bgRect.states = state.panel;\n }\n if (backgroundStyle.customShape) {\n const customShape = backgroundStyle.customShape;\n bgRect.pathProxy = (attrs: Partial<IGraphicAttribute>) => {\n return customShape(this, attrs, new CustomPath2D());\n };\n }\n this._bgRect = bgRect;\n }\n this._textShape = textShape;\n this._symbol = symbol;\n\n this.resetStates();\n }\n\n initAttributes(params: TagAttributes, options?: ComponentOptions) {\n params = options?.skipDefault ? params : merge({}, Tag.defaultAttributes, params);\n super.initAttributes(params);\n this.render();\n }\n\n addState(stateName: string, keepCurrentStates?: boolean, hasAnimation?: boolean): void {\n super.addState(stateName, keepCurrentStates, hasAnimation);\n if (this._textShape) {\n this._textShape.addState(stateName, keepCurrentStates, hasAnimation);\n }\n if (this._bgRect) {\n this._bgRect.addState(stateName, keepCurrentStates, hasAnimation);\n }\n if (this._symbol) {\n this._symbol.addState(stateName, keepCurrentStates, hasAnimation);\n }\n }\n\n removeState(stateName: string, hasAnimation?: boolean): void {\n super.removeState(stateName, hasAnimation);\n if (this._textShape) {\n this._textShape.removeState(stateName, hasAnimation);\n }\n if (this._bgRect) {\n this._bgRect.removeState(stateName, hasAnimation);\n }\n if (this._symbol) {\n this._symbol.removeState(stateName, hasAnimation);\n }\n }\n\n cacheStates() {\n this._tagStates = this.currentStates?.slice() ?? [];\n this._rectStates = this._bgRect?.currentStates?.slice() ?? [];\n this._symbolStates = this._symbol?.currentStates?.slice() ?? [];\n this._textStates = this._textShape?.currentStates?.slice() ?? [];\n this.clearStates();\n this._bgRect?.clearStates();\n this._symbol?.clearStates();\n this._textShape?.clearStates();\n }\n resetStates() {\n this._tagStates.length && this.useStates(this._tagStates);\n this._rectStates.length && this._bgRect?.useStates(this._rectStates);\n this._symbolStates.length && this._symbol?.useStates(this._symbolStates);\n this._textStates.length && this._textShape?.useStates(this._textStates);\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/tag/tag.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAGA,yDAWgC;AAChC,6CAAmH;AACnH,uCAAiD;AACjD,kCAAkF;AAGlF,yCAA8C;AAG9C,IAAA,2BAAgB,GAAE,CAAC;AACnB,MAAa,GAAI,SAAQ,wBAA0C;IAWjE,SAAS;QACP,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAkBD,YAAY,UAAyB,EAAE,OAA0B;QAC/D,KAAK,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAA,cAAK,EAAC,EAAE,EAAE,GAAG,CAAC,iBAAiB,EAA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E,IAAI,CAAC,WAAW,CAAC,MAAM,KAAI,MAAA,IAAI,CAAC,UAAU,0CAAE,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA,CAAC;IAC1E,CAAC;;AArVH,kBAsVC;AAnUQ,qBAAiB,GAA2B;IACjD,OAAO,EAAE,IAAI;IACb,SAAS,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,IAAI,EAAE,MAAM;QACZ,SAAS,EAAE,MAAM;QACjB,YAAY,EAAE,KAAK;KACpB;IACD,KAAK,EAAE,CAAC;IACR,OAAO,EAAE,CAAC;IAEV,KAAK,EAAE;QACL,IAAI,EAAE,MAAM;KACb;CACF,CAAC","file":"tag.js","sourcesContent":["/**\n * @description 标签组件\n */\nimport {\n type IGroup,\n type IRect,\n type ISymbol,\n type IText,\n type ITextAttribute,\n type ITextGraphicAttribute,\n type IRichTextGraphicAttribute,\n type IRichText,\n type IGraphicAttribute,\n CustomPath2D\n} from '@visactor/vrender-core';\nimport { isBoolean, isEmpty, isNil, isNumber, isObject, isValid, merge, normalizePadding } from '@visactor/vutils';\nimport { AbstractComponent } from '../core/base';\nimport { isRichText, measureTextSize, richTextAttributeTransform } from '../util';\nimport type { BackgroundAttributes, ComponentOptions } from '../interface';\nimport type { TagAttributes, TagShapeAttributes } from './type';\nimport { loadTagComponent } from './register';\nimport type { TextContent } from '../core/type';\n\nloadTagComponent();\nexport class Tag extends AbstractComponent<Required<TagAttributes>> {\n name = 'tag';\n\n private _bgRect!: IRect;\n private _textShape!: IText | IRichText;\n private _symbol!: ISymbol;\n private _tagStates: string[] = [];\n private _rectStates: string[] = [];\n private _symbolStates: string[] = [];\n private _textStates: string[] = [];\n\n getBgRect() {\n return this._bgRect;\n }\n\n getTextShape() {\n return this._textShape;\n }\n\n static defaultAttributes: Partial<TagAttributes> = {\n visible: true,\n textStyle: {\n fontSize: 12,\n fill: '#000',\n textAlign: 'left',\n textBaseline: 'top'\n },\n space: 4,\n padding: 4,\n // @ts-ignore\n shape: {\n fill: '#000'\n }\n };\n\n constructor(attributes: TagAttributes, options?: ComponentOptions) {\n super(options?.skipDefault ? attributes : merge({}, Tag.defaultAttributes, attributes));\n }\n\n protected render() {\n this.cacheStates();\n const {\n text = '',\n textStyle = {} as ITextGraphicAttribute | IRichTextGraphicAttribute,\n shape = {} as TagShapeAttributes,\n panel = {} as BackgroundAttributes,\n space = 4,\n minWidth,\n maxWidth,\n padding = 4,\n visible,\n state,\n type,\n textAlwaysCenter,\n containerTextAlign\n } = this.attribute as TagAttributes;\n const parsedPadding = normalizePadding(padding);\n\n const group = this.createOrUpdateChild('tag-content', { x: 0, y: 0, zIndex: 1 }, 'group') as IGroup;\n\n let symbol;\n let tagX = -parsedPadding[3];\n let tagY = -parsedPadding[0];\n let tagWidth = parsedPadding[1] + parsedPadding[3];\n let tagHeight = parsedPadding[0] + parsedPadding[2];\n let textX = 0;\n let symbolPlaceWidth = 0;\n const { visible: shapeVisible, ...shapeStyle } = shape;\n if (isBoolean(shapeVisible)) {\n const size = shapeStyle?.size || 10;\n const maxSize = (isNumber(size) ? size : Math.max(size[0], size[1])) as number;\n\n symbol = group.createOrUpdateChild(\n 'tag-shape',\n {\n symbolType: 'circle',\n size,\n strokeBoundsBuffer: 0,\n ...shapeStyle,\n visible: shapeVisible,\n x: maxSize / 2,\n y: maxSize / 2\n },\n 'symbol'\n ) as ISymbol;\n if (!isEmpty(state?.shape)) {\n symbol.states = state.shape;\n }\n\n if (shapeVisible) {\n symbolPlaceWidth = maxSize + space;\n }\n }\n\n tagWidth += symbolPlaceWidth;\n textX += symbolPlaceWidth;\n\n let textShape: IRichText | IText;\n const isRich = isRichText({ text } as TextContent) || type === 'rich';\n if (isRich) {\n const richTextAttrs = {\n ...richTextAttributeTransform({ type, text, ...textStyle } as any),\n ...(textStyle as IRichTextGraphicAttribute),\n visible: isValid(text) && visible !== false,\n x: textX,\n y: 0\n };\n textShape = group.createOrUpdateChild('tag-text', richTextAttrs, 'richtext') as IRichText;\n tagWidth += textShape.AABBBounds.width();\n tagHeight += textShape.AABBBounds.height();\n tagX += textShape.AABBBounds.x1;\n tagY += textShape.AABBBounds.y1;\n } else {\n const textAttrs = {\n text: isObject(text) && 'type' in text && text.type === 'text' ? text.text : text,\n visible: isValid(text) && visible !== false,\n lineHeight: (textStyle as ITextGraphicAttribute)?.fontSize,\n ...(textStyle as ITextGraphicAttribute),\n x: textX,\n y: 0\n };\n if (isNil(textAttrs.lineHeight)) {\n textAttrs.lineHeight = (textStyle as ITextGraphicAttribute).fontSize;\n }\n textShape = group.createOrUpdateChild('tag-text', textAttrs as ITextGraphicAttribute, 'text') as IText;\n if (!isEmpty(state?.text)) {\n textShape.states = state.text;\n }\n\n // 因为文本可能发生旋转,所以需要使用 measureTextSize 方法\n const textBounds = measureTextSize(textAttrs.text as string, textStyle, this.stage?.getTheme()?.text);\n const textWidth = textBounds.width;\n const textHeight = textBounds.height;\n tagWidth += textWidth;\n const size = shape.size ?? 10;\n const maxSize = (isNumber(size) ? size : Math.max(size[0], size[1])) as number;\n tagHeight += Math.max(textHeight, shape.visible ? maxSize : 0);\n\n const { textAlign, textBaseline } = textStyle as ITextAttribute;\n\n if (isValid(minWidth) || isValid(maxWidth)) {\n if (isValid(minWidth) && tagWidth < minWidth) {\n tagWidth = minWidth;\n }\n if (isValid(maxWidth) && tagWidth > maxWidth) {\n tagWidth = maxWidth;\n textShape.setAttribute('maxLineWidth', maxWidth - parsedPadding[1] - parsedPadding[2]);\n }\n }\n\n tagX = 0;\n tagY = 0;\n let flag = 0;\n if (textAlign === 'left' || textAlign === 'start') {\n flag = 1;\n } else if (textAlign === 'right' || textAlign === 'end') {\n flag = -1;\n } else if (textAlign === 'center') {\n flag = 0;\n }\n if (!flag) {\n tagX -= tagWidth / 2;\n if (symbol) {\n symbol.setAttribute('x', (symbol.attribute.x || 0) - textWidth / 2);\n }\n\n group.setAttribute('x', -symbolPlaceWidth / 2);\n } else if (flag < 0) {\n tagX -= tagWidth;\n if (symbol) {\n symbol.setAttribute('x', (symbol.attribute.x || 0) - textWidth);\n }\n\n group.setAttribute('x', -parsedPadding[1] - symbolPlaceWidth);\n } else if (flag > 0) {\n group.setAttribute('x', parsedPadding[3]);\n }\n\n const shouldCenter = containerTextAlign ? containerTextAlign === 'center' : textAlwaysCenter;\n const shouldRight = containerTextAlign === 'right' || containerTextAlign === 'end';\n const shouldLeft = containerTextAlign === 'left' || containerTextAlign === 'start';\n\n if (shouldCenter && flag) {\n // 文本容器内居中\n // 剔除padding后的内宽度\n const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];\n const tsWidth = textWidth + symbolPlaceWidth;\n const textX =\n flag === 1\n ? (containerWidth - tsWidth) / 2 + symbolPlaceWidth + textWidth / 2\n : parsedPadding[0] + symbolPlaceWidth - (tagWidth / 2 + tsWidth / 2 - symbolPlaceWidth) + textWidth / 2;\n\n textShape.setAttributes({\n x: textX,\n textAlign: 'center'\n });\n if (symbol) {\n const symbolX = textX - textWidth / 2 - symbolPlaceWidth + maxSize / 2;\n symbol.setAttributes({\n x: symbolX\n });\n }\n }\n\n if (shouldLeft && flag !== 1) {\n // 文本容器内朝左展示\n const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];\n const offset =\n flag === 0\n ? -containerWidth / 2 + symbolPlaceWidth / 2\n : -tagWidth + parsedPadding[3] + parsedPadding[1] + symbolPlaceWidth;\n const textX = offset + symbolPlaceWidth;\n\n textShape.setAttributes({\n x: textX,\n textAlign: 'left'\n });\n\n if (symbol) {\n const symbolX = offset + maxSize / 2;\n symbol.setAttributes({\n x: symbolX\n });\n }\n }\n\n if (shouldRight && flag !== -1) {\n // 文本容器内朝右展示\n const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];\n const textX = flag === 0 ? containerWidth / 2 + symbolPlaceWidth / 2 : containerWidth;\n\n textShape.setAttributes({\n x: textX,\n textAlign: 'right'\n });\n if (symbol) {\n const symbolX = textX - textWidth - symbolPlaceWidth + maxSize / 2;\n symbol.setAttributes({\n x: symbolX\n });\n }\n }\n\n if (textBaseline === 'middle') {\n tagY -= tagHeight / 2;\n if (symbol) {\n symbol.setAttribute('y', 0);\n }\n } else if (textBaseline === 'bottom') {\n tagY -= tagHeight;\n if (symbol) {\n symbol.setAttribute('y', -textHeight / 2);\n }\n\n group.setAttribute('y', -parsedPadding[2]);\n } else if (textBaseline === 'top') {\n group.setAttribute('y', parsedPadding[0]);\n if (symbol) {\n symbol.setAttribute('y', textHeight / 2);\n }\n }\n }\n // 绘制背景层\n const { visible: bgVisible, ...backgroundStyle } = panel;\n if (visible && isBoolean(bgVisible)) {\n const bgRect = this.createOrUpdateChild(\n 'tag-panel',\n {\n ...backgroundStyle,\n visible: bgVisible && !!text,\n width: tagWidth,\n height: tagHeight,\n x: tagX,\n y: tagY\n },\n 'rect'\n ) as IRect;\n if (!isEmpty(state?.panel)) {\n bgRect.states = state.panel;\n }\n if (backgroundStyle.customShape) {\n const customShape = backgroundStyle.customShape;\n bgRect.pathProxy = (attrs: Partial<IGraphicAttribute>) => {\n return customShape(this, attrs, new CustomPath2D());\n };\n }\n this._bgRect = bgRect;\n }\n this._textShape = textShape;\n this._symbol = symbol;\n\n this.resetStates();\n }\n\n initAttributes(params: TagAttributes, options?: ComponentOptions) {\n params = options?.skipDefault ? params : merge({}, Tag.defaultAttributes, params);\n super.initAttributes(params);\n this.render();\n }\n\n addState(stateName: string, keepCurrentStates?: boolean, hasAnimation?: boolean): void {\n super.addState(stateName, keepCurrentStates, hasAnimation);\n if (this._textShape) {\n this._textShape.addState(stateName, keepCurrentStates, hasAnimation);\n }\n if (this._bgRect) {\n this._bgRect.addState(stateName, keepCurrentStates, hasAnimation);\n }\n if (this._symbol) {\n this._symbol.addState(stateName, keepCurrentStates, hasAnimation);\n }\n }\n\n removeState(stateName: string, hasAnimation?: boolean): void {\n super.removeState(stateName, hasAnimation);\n if (this._textShape) {\n this._textShape.removeState(stateName, hasAnimation);\n }\n if (this._bgRect) {\n this._bgRect.removeState(stateName, hasAnimation);\n }\n if (this._symbol) {\n this._symbol.removeState(stateName, hasAnimation);\n }\n }\n\n cacheStates() {\n this._tagStates = this.currentStates?.slice() ?? [];\n this._rectStates = this._bgRect?.currentStates?.slice() ?? [];\n this._symbolStates = this._symbol?.currentStates?.slice() ?? [];\n this._textStates = this._textShape?.currentStates?.slice() ?? [];\n this.clearStates();\n this._bgRect?.clearStates();\n this._symbol?.clearStates();\n this._textShape?.clearStates();\n }\n resetStates() {\n this._tagStates.length && this.useStates(this._tagStates);\n this._rectStates.length && this._bgRect?.useStates(this._rectStates);\n this._symbolStates.length && this._symbol?.useStates(this._symbolStates);\n this._textStates.length && this._textShape?.useStates(this._textStates);\n }\n}\n"]}
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { tau, halfPi as halfPi$1, AABBBounds, degreeToRadian, Point, PointService, abs, max, min, atan2, epsilon, Matrix, pi2, Logger, pi, isArray, isNumberClose, TextMeasure, EventEmitter, isBoolean, isObject, isFunction, cos, sin, isString, pointAt, isNumber, getDecimalPlaces, isNil, Color, sqrt, OBBBounds, has, normalTransform, isValidUrl, isBase64, acos, transformBoundsWithMatrix, getContextFont, rotatePoint, clampAngleByRadian, asin, arrayEqual, Bounds, getRectIntersect, isRectIntersect, isPlainObject, merge, clamp, clampRange, normalizePadding, debounce, throttle, hexToRgb, crossProduct, isValid, isEmpty, array, rectInsideAnotherRect, radianToDegree, getAngleByPoint, polarToCartesian, normalizeAngle, isValidNumber, flattenArray, isRotateAABBIntersect, isLess, isGreater, cloneDeep, get, last, mixin, isEqual, interpolateString, minInArray, maxInArray, binaryFuzzySearchInNumberRange, calculateAnchorOfBounds, computeQuadrant, polygonContainPoint } from '@visactor/vutils';
1
+ import { tau, halfPi as halfPi$1, AABBBounds, degreeToRadian, Point, PointService, abs, max, min, atan2, epsilon, Matrix, pi2, Logger, pi, isArray, isNumberClose, TextMeasure, EventEmitter, isBoolean, isObject, isFunction, cos, sin, isString, pointAt, isNumber, getDecimalPlaces, isNil, Color, sqrt, OBBBounds, has, normalTransform, isValidUrl, isBase64, acos, transformBoundsWithMatrix, getContextFont, rotatePoint, clampAngleByRadian, asin, arrayEqual, Bounds, getRectIntersect, isRectIntersect, isPlainObject, merge, clamp, clampRange, normalizePadding, debounce, throttle, hexToRgb, crossProduct, isValid, isEmpty, rectInsideAnotherRect, radianToDegree, getAngleByPoint, polarToCartesian, normalizeAngle, isValidNumber, flattenArray, array, isRotateAABBIntersect, isLess, isGreater, cloneDeep, get, last, mixin, isEqual, interpolateString, minInArray, maxInArray, binaryFuzzySearchInNumberRange, calculateAnchorOfBounds, computeQuadrant, polygonContainPoint } from '@visactor/vutils';
2
2
  import { isContinuous, isDiscrete, LinearScale } from '@visactor/vscale';
3
3
 
4
4
  class Generator {
@@ -15941,17 +15941,14 @@ class Tag extends AbstractComponent {
15941
15941
  tagWidth += symbolPlaceWidth;
15942
15942
  textX += symbolPlaceWidth;
15943
15943
  let textShape;
15944
- let textWidth;
15945
- let textHeight;
15946
15944
  const isRich = isRichText({ text }) || type === 'rich';
15947
15945
  if (isRich) {
15948
15946
  const richTextAttrs = Object.assign(Object.assign(Object.assign({}, richTextAttributeTransform(Object.assign({ type, text }, textStyle))), textStyle), { visible: isValid(text) && visible !== false, x: textX, y: 0 });
15949
- if (isNil(richTextAttrs.lineHeight)) {
15950
- richTextAttrs.lineHeight = textStyle.fontSize;
15951
- }
15952
15947
  textShape = group.createOrUpdateChild('tag-text', richTextAttrs, 'richtext');
15953
- textWidth = textShape.AABBBounds.width();
15954
- textHeight = textShape.AABBBounds.height();
15948
+ tagWidth += textShape.AABBBounds.width();
15949
+ tagHeight += textShape.AABBBounds.height();
15950
+ tagX += textShape.AABBBounds.x1;
15951
+ tagY += textShape.AABBBounds.y1;
15955
15952
  }
15956
15953
  else {
15957
15954
  const textAttrs = Object.assign(Object.assign({ text: isObject(text) && 'type' in text && text.type === 'text' ? text.text : text, visible: isValid(text) && visible !== false, lineHeight: textStyle === null || textStyle === void 0 ? void 0 : textStyle.fontSize }, textStyle), { x: textX, y: 0 });
@@ -15959,134 +15956,126 @@ class Tag extends AbstractComponent {
15959
15956
  textAttrs.lineHeight = textStyle.fontSize;
15960
15957
  }
15961
15958
  textShape = group.createOrUpdateChild('tag-text', textAttrs, 'text');
15959
+ if (!isEmpty(state === null || state === void 0 ? void 0 : state.text)) {
15960
+ textShape.states = state.text;
15961
+ }
15962
15962
  const textBounds = measureTextSize(textAttrs.text, textStyle, (_b = (_a = this.stage) === null || _a === void 0 ? void 0 : _a.getTheme()) === null || _b === void 0 ? void 0 : _b.text);
15963
- textWidth = textBounds.width;
15964
- textHeight = textBounds.height;
15965
- }
15966
- tagWidth += textWidth;
15967
- const size = (_c = shape.size) !== null && _c !== void 0 ? _c : 10;
15968
- const maxSize = (isNumber(size) ? size : Math.max(size[0], size[1]));
15969
- tagHeight += Math.max(textHeight, shape.visible ? maxSize : 0);
15970
- const { textAlign, textBaseline } = textStyle;
15971
- if (isValid(minWidth) || isValid(maxWidth)) {
15972
- if (isValid(minWidth) && tagWidth < minWidth) {
15973
- tagWidth = minWidth;
15963
+ const textWidth = textBounds.width;
15964
+ const textHeight = textBounds.height;
15965
+ tagWidth += textWidth;
15966
+ const size = (_c = shape.size) !== null && _c !== void 0 ? _c : 10;
15967
+ const maxSize = (isNumber(size) ? size : Math.max(size[0], size[1]));
15968
+ tagHeight += Math.max(textHeight, shape.visible ? maxSize : 0);
15969
+ const { textAlign, textBaseline } = textStyle;
15970
+ if (isValid(minWidth) || isValid(maxWidth)) {
15971
+ if (isValid(minWidth) && tagWidth < minWidth) {
15972
+ tagWidth = minWidth;
15973
+ }
15974
+ if (isValid(maxWidth) && tagWidth > maxWidth) {
15975
+ tagWidth = maxWidth;
15976
+ textShape.setAttribute('maxLineWidth', maxWidth - parsedPadding[1] - parsedPadding[2]);
15977
+ }
15974
15978
  }
15975
- if (isValid(maxWidth) && tagWidth > maxWidth) {
15976
- tagWidth = maxWidth;
15977
- textShape.setAttribute('maxLineWidth', maxWidth - parsedPadding[1] - parsedPadding[2]);
15979
+ tagX = 0;
15980
+ tagY = 0;
15981
+ let flag = 0;
15982
+ if (textAlign === 'left' || textAlign === 'start') {
15983
+ flag = 1;
15978
15984
  }
15979
- }
15980
- tagX = 0;
15981
- tagY = 0;
15982
- let flag = 0;
15983
- if (textAlign === 'left' || textAlign === 'start') {
15984
- flag = 1;
15985
- }
15986
- else if (textAlign === 'right' || textAlign === 'end') {
15987
- flag = -1;
15988
- }
15989
- else if (textAlign === 'center') {
15990
- flag = 0;
15991
- }
15992
- if (!flag) {
15993
- tagX -= tagWidth / 2;
15994
- if (symbol) {
15995
- symbol.setAttribute('x', (symbol.attribute.x || 0) - textWidth / 2);
15985
+ else if (textAlign === 'right' || textAlign === 'end') {
15986
+ flag = -1;
15996
15987
  }
15997
- group.setAttribute('x', -symbolPlaceWidth / 2);
15998
- }
15999
- else if (flag < 0) {
16000
- tagX -= tagWidth;
16001
- if (symbol) {
16002
- symbol.setAttribute('x', (symbol.attribute.x || 0) - textWidth);
15988
+ else if (textAlign === 'center') {
15989
+ flag = 0;
16003
15990
  }
16004
- group.setAttribute('x', -parsedPadding[1] - symbolPlaceWidth);
16005
- }
16006
- else if (flag > 0) {
16007
- group.setAttribute('x', parsedPadding[3]);
16008
- }
16009
- const shouldCenter = containerTextAlign ? containerTextAlign === 'center' : textAlwaysCenter;
16010
- const shouldRight = containerTextAlign === 'right' || containerTextAlign === 'end';
16011
- const shouldLeft = containerTextAlign === 'left' || containerTextAlign === 'start';
16012
- const updateTextAttrs = (textX, textAlign) => {
16013
- if (textShape.type === 'richtext') {
15991
+ if (!flag) {
15992
+ tagX -= tagWidth / 2;
15993
+ if (symbol) {
15994
+ symbol.setAttribute('x', (symbol.attribute.x || 0) - textWidth / 2);
15995
+ }
15996
+ group.setAttribute('x', -symbolPlaceWidth / 2);
15997
+ }
15998
+ else if (flag < 0) {
15999
+ tagX -= tagWidth;
16000
+ if (symbol) {
16001
+ symbol.setAttribute('x', (symbol.attribute.x || 0) - textWidth);
16002
+ }
16003
+ group.setAttribute('x', -parsedPadding[1] - symbolPlaceWidth);
16004
+ }
16005
+ else if (flag > 0) {
16006
+ group.setAttribute('x', parsedPadding[3]);
16007
+ }
16008
+ const shouldCenter = containerTextAlign ? containerTextAlign === 'center' : textAlwaysCenter;
16009
+ const shouldRight = containerTextAlign === 'right' || containerTextAlign === 'end';
16010
+ const shouldLeft = containerTextAlign === 'left' || containerTextAlign === 'start';
16011
+ if (shouldCenter && flag) {
16012
+ const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];
16013
+ const tsWidth = textWidth + symbolPlaceWidth;
16014
+ const textX = flag === 1
16015
+ ? (containerWidth - tsWidth) / 2 + symbolPlaceWidth + textWidth / 2
16016
+ : parsedPadding[0] + symbolPlaceWidth - (tagWidth / 2 + tsWidth / 2 - symbolPlaceWidth) + textWidth / 2;
16014
16017
  textShape.setAttributes({
16015
16018
  x: textX,
16016
- textAlign,
16017
- textConfig: array(textShape.attribute.textConfig).map(t => {
16018
- return Object.assign(Object.assign({}, t), { textAlign });
16019
- })
16019
+ textAlign: 'center'
16020
16020
  });
16021
+ if (symbol) {
16022
+ const symbolX = textX - textWidth / 2 - symbolPlaceWidth + maxSize / 2;
16023
+ symbol.setAttributes({
16024
+ x: symbolX
16025
+ });
16026
+ }
16021
16027
  }
16022
- else {
16028
+ if (shouldLeft && flag !== 1) {
16029
+ const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];
16030
+ const offset = flag === 0
16031
+ ? -containerWidth / 2 + symbolPlaceWidth / 2
16032
+ : -tagWidth + parsedPadding[3] + parsedPadding[1] + symbolPlaceWidth;
16033
+ const textX = offset + symbolPlaceWidth;
16023
16034
  textShape.setAttributes({
16024
16035
  x: textX,
16025
- textAlign
16026
- });
16027
- }
16028
- };
16029
- if (shouldCenter && flag) {
16030
- const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];
16031
- const tsWidth = textWidth + symbolPlaceWidth;
16032
- const textX = flag === 1
16033
- ? (containerWidth - tsWidth) / 2 + symbolPlaceWidth + textWidth / 2
16034
- : parsedPadding[0] + symbolPlaceWidth - (tagWidth / 2 + tsWidth / 2 - symbolPlaceWidth) + textWidth / 2;
16035
- updateTextAttrs(textX, 'center');
16036
- if (symbol) {
16037
- const symbolX = textX - textWidth / 2 - symbolPlaceWidth + maxSize / 2;
16038
- symbol.setAttributes({
16039
- x: symbolX
16040
- });
16041
- }
16042
- }
16043
- if (shouldLeft && flag !== 1) {
16044
- const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];
16045
- const offset = flag === 0
16046
- ? -containerWidth / 2 + symbolPlaceWidth / 2
16047
- : -tagWidth + parsedPadding[3] + parsedPadding[1] + symbolPlaceWidth;
16048
- const textX = offset + symbolPlaceWidth;
16049
- updateTextAttrs(textX, 'left');
16050
- if (symbol) {
16051
- const symbolX = offset + maxSize / 2;
16052
- symbol.setAttributes({
16053
- x: symbolX
16036
+ textAlign: 'left'
16054
16037
  });
16038
+ if (symbol) {
16039
+ const symbolX = offset + maxSize / 2;
16040
+ symbol.setAttributes({
16041
+ x: symbolX
16042
+ });
16043
+ }
16055
16044
  }
16056
- }
16057
- if (shouldRight && flag !== -1) {
16058
- const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];
16059
- const textX = flag === 0 ? containerWidth / 2 + symbolPlaceWidth / 2 : containerWidth;
16060
- updateTextAttrs(textX, 'right');
16061
- if (symbol) {
16062
- const symbolX = textX - textWidth - symbolPlaceWidth + maxSize / 2;
16063
- symbol.setAttributes({
16064
- x: symbolX
16045
+ if (shouldRight && flag !== -1) {
16046
+ const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];
16047
+ const textX = flag === 0 ? containerWidth / 2 + symbolPlaceWidth / 2 : containerWidth;
16048
+ textShape.setAttributes({
16049
+ x: textX,
16050
+ textAlign: 'right'
16065
16051
  });
16052
+ if (symbol) {
16053
+ const symbolX = textX - textWidth - symbolPlaceWidth + maxSize / 2;
16054
+ symbol.setAttributes({
16055
+ x: symbolX
16056
+ });
16057
+ }
16066
16058
  }
16067
- }
16068
- if (textBaseline === 'middle') {
16069
- tagY -= tagHeight / 2;
16070
- if (symbol) {
16071
- symbol.setAttribute('y', 0);
16059
+ if (textBaseline === 'middle') {
16060
+ tagY -= tagHeight / 2;
16061
+ if (symbol) {
16062
+ symbol.setAttribute('y', 0);
16063
+ }
16072
16064
  }
16073
- }
16074
- else if (textBaseline === 'bottom') {
16075
- tagY -= tagHeight;
16076
- if (symbol) {
16077
- symbol.setAttribute('y', -textHeight / 2);
16065
+ else if (textBaseline === 'bottom') {
16066
+ tagY -= tagHeight;
16067
+ if (symbol) {
16068
+ symbol.setAttribute('y', -textHeight / 2);
16069
+ }
16070
+ group.setAttribute('y', -parsedPadding[2]);
16078
16071
  }
16079
- group.setAttribute('y', -parsedPadding[2]);
16080
- }
16081
- else if (textBaseline === 'top') {
16082
- group.setAttribute('y', parsedPadding[0]);
16083
- if (symbol) {
16084
- symbol.setAttribute('y', textHeight / 2);
16072
+ else if (textBaseline === 'top') {
16073
+ group.setAttribute('y', parsedPadding[0]);
16074
+ if (symbol) {
16075
+ symbol.setAttribute('y', textHeight / 2);
16076
+ }
16085
16077
  }
16086
16078
  }
16087
- if (!isEmpty(state === null || state === void 0 ? void 0 : state.text)) {
16088
- textShape.states = state.text;
16089
- }
16090
16079
  const { visible: bgVisible } = panel, backgroundStyle = __rest(panel, ["visible"]);
16091
16080
  if (visible && isBoolean(bgVisible)) {
16092
16081
  const bgRect = this.createOrUpdateChild('tag-panel', Object.assign(Object.assign({}, backgroundStyle), { visible: bgVisible && !!text, width: tagWidth, height: tagHeight, x: tagX, y: tagY }), 'rect');
@@ -20023,11 +20012,10 @@ function bitmapTool(width, height, padding = { top: 0, left: 0, right: 0, bottom
20023
20012
  }
20024
20013
  function clampRangeByBitmap($, range) {
20025
20014
  const { x1, x2, y1, y2 } = range;
20026
- const { top = 0, left = 0, right = 0, bottom = 0 } = $.padding;
20027
- const _x1 = clamp(x1, -left, $.width + right);
20028
- const _x2 = clamp(x2, -left, $.width + right);
20029
- const _y1 = clamp(y1, -top, $.height + bottom);
20030
- const _y2 = clamp(y2, -top, $.height + bottom);
20015
+ const _x1 = clamp(x1, 0, $.width);
20016
+ const _x2 = clamp(x2, 0, $.width);
20017
+ const _y1 = clamp(y1, 0, $.height);
20018
+ const _y2 = clamp(y2, 0, $.height);
20031
20019
  return {
20032
20020
  x1: $.x(_x1),
20033
20021
  x2: $.x(_x2),
@@ -31472,6 +31460,6 @@ StoryLabelItem.defaultAttributes = {
31472
31460
  theme: 'default'
31473
31461
  };
31474
31462
 
31475
- const version = "0.22.5";
31463
+ const version = "0.22.6-alpha.1";
31476
31464
 
31477
31465
  export { AXIS_ELEMENT_NAME, AbstractComponent, ArcInfo, ArcLabel, ArcSegment, AxisStateValue, BasePlayer, Brush, CheckBox, CircleAxis, CircleAxisGrid, CircleCrosshair, ColorContinuousLegend, ContinuousPlayer, DEFAULT_ITEM_SPACE_COL, DEFAULT_ITEM_SPACE_ROW, DEFAULT_LABEL_SPACE, DEFAULT_PAGER_SPACE, DEFAULT_SHAPE_SIZE, DEFAULT_SHAPE_SPACE, DEFAULT_STATES$1 as DEFAULT_STATES, DEFAULT_TITLE_SPACE, DEFAULT_VALUE_SPACE, DataLabel, DataZoom, DataZoomActiveTag, DirectionEnum, DiscreteLegend, DiscretePlayer, EmptyTip, GroupTransition, IMarkAreaLabelPosition, IMarkCommonArcLabelPosition, IMarkLineLabelPosition, IMarkPointItemPosition, IOperateType, Indicator, LEGEND_ELEMENT_NAME, LabelBase, LegendEvent, LegendStateValue, LineAxis, LineAxisGrid, LineCrosshair, LineLabel, LinkPath, MarkArcArea, MarkArcLine, MarkArea, MarkLine, MarkPoint, Pager, PlayerEventEnum, PolygonCrosshair, PolygonSectorCrosshair, PopTip, Radio, RectCrosshair, RectLabel, SLIDER_ELEMENT_NAME, ScrollBar, SectorCrosshair, Segment, SizeContinuousLegend, Slider, StoryLabelItem, Switch, SymbolLabel, Tag, Timeline, Title, Tooltip, TopZIndex, VTag, WeatherBox, alignTextInLine, angle, angleLabelOrientAttribute, angleTo, cartesianTicks, clampRadian, computeOffsetForlimit, continuousTicks, contrastAccessibilityChecker, convertDomainToTickData, createTextGraphicByType, deltaXYToAngle, fuzzyEqualNumber, getAxisBreakSymbolAttrs, getCircleLabelPosition, getCirclePoints, getCircleVerticalVector, getElMap, getHorizontalPath, getMarksByName, getNoneGroupMarksByName, getPolarAngleLabelPosition, getPolygonPath, getSizeHandlerPath, getTextAlignAttrOfVerticalDir, getTextType, getVerticalCoord, getVerticalPath, hasOverlap, htmlAttributeTransform, initTextMeasure, isInRange, isPostiveXAxis, isRichText, isVisible, labelSmartInvert, length, limitShapeInBounds, linearDiscreteTicks, loadPoptip, loadScrollbar, measureTextSize, normalize, polarAngleAxisDiscreteTicks, polarTicks, reactAttributeTransform, registerArcDataLabel, registerLineDataLabel, registerMarkArcAreaAnimate, registerMarkArcLineAnimate, registerMarkAreaAnimate, registerMarkLineAnimate, registerMarkPointAnimate, registerRectDataLabel, registerSymbolDataLabel, removeRepeatPoint, richTextAttributeTransform, scale, scrollbarModule, setPoptipTheme, smartInvertStrategy, tan2AngleToAngle, textIntersect, ticks, traverseGroup, version };
package/es/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const version = "0.22.5";
1
+ export declare const version = "0.22.6-alpha.1";
2
2
  export * from './core/base';
3
3
  export * from './core/type';
4
4
  export * from './scrollbar';
package/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export const version = "0.22.5";
1
+ export const version = "0.22.6-alpha.1";
2
2
 
3
3
  export * from "./core/base";
4
4
 
package/es/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC;AAEhC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC","file":"index.js","sourcesContent":["// 导出版本号\nexport const version = \"0.22.5\";\n\nexport * from './core/base';\nexport * from './core/type';\nexport * from './scrollbar';\nexport * from './tag';\nexport * from './poptip';\nexport * from './crosshair';\nexport * from './label';\nexport * from './axis';\nexport * from './axis/grid';\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 './timeline';\nexport * from './interface';\nexport * from './jsx';\nexport * from './checkbox';\nexport * from './radio';\nexport * from './empty-tip';\nexport * from './weather';\nexport * from './util';\nexport * from './switch';\nexport * from './label-item';\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC;AAExC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC","file":"index.js","sourcesContent":["// 导出版本号\nexport const version = \"0.22.6-alpha.1\";\n\nexport * from './core/base';\nexport * from './core/type';\nexport * from './scrollbar';\nexport * from './tag';\nexport * from './poptip';\nexport * from './crosshair';\nexport * from './label';\nexport * from './axis';\nexport * from './axis/grid';\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 './timeline';\nexport * from './interface';\nexport * from './jsx';\nexport * from './checkbox';\nexport * from './radio';\nexport * from './empty-tip';\nexport * from './weather';\nexport * from './util';\nexport * from './switch';\nexport * from './label-item';\n"]}
@@ -15,7 +15,7 @@ export function bitmapTool(width, height, padding = {
15
15
  }
16
16
 
17
17
  export function clampRangeByBitmap($, range) {
18
- const {x1: x1, x2: x2, y1: y1, y2: y2} = range, {top: top = 0, left: left = 0, right: right = 0, bottom: bottom = 0} = $.padding, _x1 = clampRange(x1, -left, $.width + right), _x2 = clampRange(x2, -left, $.width + right), _y1 = clampRange(y1, -top, $.height + bottom), _y2 = clampRange(y2, -top, $.height + bottom);
18
+ const {x1: x1, x2: x2, y1: y1, y2: y2} = range, _x1 = clampRange(x1, 0, $.width), _x2 = clampRange(x2, 0, $.width), _y1 = clampRange(y1, 0, $.height), _y2 = clampRange(y2, 0, $.height);
19
19
  return {
20
20
  x1: $.x(_x1),
21
21
  x2: $.x(_x2),
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/label/overlap/scaler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAiClC,MAAM,UAAU,UAAU,CACxB,KAAa,EACb,MAAc,EACd,UAA4E,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;IAEpH,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC;IAC7D,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,GAAG,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IAC7D,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,GAAG,KAAK,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC;IACrD,MAAM,CAAC,GAAG,CA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AAG,KAAK,CAAC,CAAC;IACnD,MAAM,GAAG,GAAG,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,UAAU,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IACpD,OAAO;QACL,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACZ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACZ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACZ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;KACb,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,CAAa,EAAE,KAAkB,EAAE,QAAiB,KAAK;IACpF,IAAI,KAAK,EAAE;QACT,OAAO,kBAAkB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;KACrC;IAED,OAAO;QACL,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;KAClB,CAAC;AACJ,CAAC","file":"scaler.js","sourcesContent":["import type { IBoundsLike } from '@visactor/vutils';\nimport { clamp as clampRange } from '@visactor/vutils';\nimport { bitmap } from './bitmap';\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 bitmapTool(\n width: number,\n height: number,\n padding: { top?: number; left?: number; right?: number; bottom?: number } = { top: 0, left: 0, right: 0, bottom: 0 }\n) {\n const { top = 0, left = 0, right = 0, bottom = 0 } = padding;\n const ratio = Math.max(1, Math.sqrt((width * height) / 1e6));\n const w = ~~((width + left + right + ratio) / ratio);\n const h = ~~((height + top + bottom + ratio) / ratio);\n const scale = (_: number) => ~~(_ / ratio);\n\n scale.bitmap = () => bitmap(w, h);\n scale.x = (_: number) => ~~((_ + left) / ratio);\n scale.y = (_: number) => ~~((_ + top) / ratio);\n\n scale.ratio = ratio;\n scale.padding = padding;\n scale.width = width;\n scale.height = height;\n\n return scale;\n}\n\nexport function clampRangeByBitmap($: BitmapTool, range: IBoundsLike) {\n const { x1, x2, y1, y2 } = range;\n const { top = 0, left = 0, right = 0, bottom = 0 } = $.padding;\n const _x1 = clampRange(x1, -left, $.width + right);\n const _x2 = clampRange(x2, -left, $.width + right);\n const _y1 = clampRange(y1, -top, $.height + bottom);\n const _y2 = clampRange(y2, -top, $.height + bottom);\n return {\n x1: $.x(_x1),\n x2: $.x(_x2),\n y1: $.y(_y1),\n y2: $.y(_y2)\n };\n}\n\nexport function boundToRange($: BitmapTool, bound: IBoundsLike, clamp: boolean = false) {\n if (clamp) {\n return clampRangeByBitmap($, bound);\n }\n\n return {\n x1: $.x(bound.x1),\n x2: $.x(bound.x2),\n y1: $.y(bound.y1),\n y2: $.y(bound.y2)\n };\n}\n\nexport type BitmapTool = ReturnType<typeof bitmapTool>;\n"]}
1
+ {"version":3,"sources":["../src/label/overlap/scaler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAiClC,MAAM,UAAU,UAAU,CACxB,KAAa,EACb,MAAc,EACd,UAA4E,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;IAEpH,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC;IAC7D,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,GAAG,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IAC7D,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,GAAG,KAAK,GAAG,KAAK,CAAC,GAAG,KAAK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,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;IACxC,OAAO;QACL,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACZ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACZ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACZ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;KACb,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,CAAa,EAAE,KAAkB,EAAE,QAAiB,KAAK;IACpF,IAAI,KAAK,EAAE;QACT,OAAO,kBAAkB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;KACrC;IAED,OAAO;QACL,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;KAClB,CAAC;AACJ,CAAC","file":"scaler.js","sourcesContent":["import type { IBoundsLike } from '@visactor/vutils';\nimport { clamp as clampRange } from '@visactor/vutils';\nimport { bitmap } from './bitmap';\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 bitmapTool(\n width: number,\n height: number,\n padding: { top?: number; left?: number; right?: number; bottom?: number } = { top: 0, left: 0, right: 0, bottom: 0 }\n) {\n const { top = 0, left = 0, right = 0, bottom = 0 } = padding;\n const ratio = Math.max(1, Math.sqrt((width * height) / 1e6));\n const w = ~~((width + left + right + ratio) / ratio);\n const h = ~~((height + top + bottom + ratio) / ratio);\n const scale = (_: number) => ~~(_ / ratio);\n\n scale.bitmap = () => bitmap(w, h);\n scale.x = (_: number) => ~~((_ + left) / ratio);\n scale.y = (_: number) => ~~((_ + top) / ratio);\n\n scale.ratio = ratio;\n scale.padding = padding;\n scale.width = width;\n scale.height = height;\n\n return scale;\n}\n\nexport function clampRangeByBitmap($: BitmapTool, range: IBoundsLike) {\n const { x1, x2, y1, y2 } = range;\n const _x1 = clampRange(x1, 0, $.width);\n const _x2 = clampRange(x2, 0, $.width);\n const _y1 = clampRange(y1, 0, $.height);\n const _y2 = clampRange(y2, 0, $.height);\n return {\n x1: $.x(_x1),\n x2: $.x(_x2),\n y1: $.y(_y1),\n y2: $.y(_y2)\n };\n}\n\nexport function boundToRange($: BitmapTool, bound: IBoundsLike, clamp: boolean = false) {\n if (clamp) {\n return clampRangeByBitmap($, bound);\n }\n\n return {\n x1: $.x(bound.x1),\n x2: $.x(bound.x2),\n y1: $.y(bound.y1),\n y2: $.y(bound.y2)\n };\n}\n\nexport type BitmapTool = ReturnType<typeof bitmapTool>;\n"]}
package/es/tag/tag.js CHANGED
@@ -10,7 +10,7 @@ var __rest = this && this.__rest || function(s, e) {
10
10
 
11
11
  import { CustomPath2D } from "@visactor/vrender-core";
12
12
 
13
- import { array, isBoolean, isEmpty, isNil, isNumber, isObject, isValid, merge, normalizePadding } from "@visactor/vutils";
13
+ import { isBoolean, isEmpty, isNil, isNumber, isObject, isValid, merge, normalizePadding } from "@visactor/vutils";
14
14
 
15
15
  import { AbstractComponent } from "../core/base";
16
16
 
@@ -55,7 +55,7 @@ export class Tag extends AbstractComponent {
55
55
  }), "symbol"), isEmpty(null == state ? void 0 : state.shape) || (symbol.states = state.shape),
56
56
  shapeVisible && (symbolPlaceWidth = maxSize + space);
57
57
  }
58
- let textShape, textWidth, textHeight;
58
+ let textShape;
59
59
  tagWidth += symbolPlaceWidth, textX += symbolPlaceWidth;
60
60
  if (isRichText({
61
61
  text: text
@@ -68,9 +68,8 @@ export class Tag extends AbstractComponent {
68
68
  x: textX,
69
69
  y: 0
70
70
  });
71
- isNil(richTextAttrs.lineHeight) && (richTextAttrs.lineHeight = textStyle.fontSize),
72
- textShape = group.createOrUpdateChild("tag-text", richTextAttrs, "richtext"), textWidth = textShape.AABBBounds.width(),
73
- textHeight = textShape.AABBBounds.height();
71
+ textShape = group.createOrUpdateChild("tag-text", richTextAttrs, "richtext"), tagWidth += textShape.AABBBounds.width(),
72
+ tagHeight += textShape.AABBBounds.height(), tagX += textShape.AABBBounds.x1, tagY += textShape.AABBBounds.y1;
74
73
  } else {
75
74
  const textAttrs = Object.assign(Object.assign({
76
75
  text: isObject(text) && "type" in text && "text" === text.type ? text.text : text,
@@ -80,64 +79,62 @@ export class Tag extends AbstractComponent {
80
79
  x: textX,
81
80
  y: 0
82
81
  });
83
- isNil(textAttrs.lineHeight) && (textAttrs.lineHeight = textStyle.fontSize), textShape = group.createOrUpdateChild("tag-text", textAttrs, "text");
84
- const textBounds = measureTextSize(textAttrs.text, textStyle, null === (_b = null === (_a = this.stage) || void 0 === _a ? void 0 : _a.getTheme()) || void 0 === _b ? void 0 : _b.text);
85
- textWidth = textBounds.width, textHeight = textBounds.height;
86
- }
87
- tagWidth += textWidth;
88
- const size = null !== (_c = shape.size) && void 0 !== _c ? _c : 10, maxSize = isNumber(size) ? size : Math.max(size[0], size[1]);
89
- tagHeight += Math.max(textHeight, shape.visible ? maxSize : 0);
90
- const {textAlign: textAlign, textBaseline: textBaseline} = textStyle;
91
- (isValid(minWidth) || isValid(maxWidth)) && (isValid(minWidth) && tagWidth < minWidth && (tagWidth = minWidth),
92
- isValid(maxWidth) && tagWidth > maxWidth && (tagWidth = maxWidth, textShape.setAttribute("maxLineWidth", maxWidth - parsedPadding[1] - parsedPadding[2]))),
93
- tagX = 0, tagY = 0;
94
- let flag = 0;
95
- "left" === textAlign || "start" === textAlign ? flag = 1 : "right" === textAlign || "end" === textAlign ? flag = -1 : "center" === textAlign && (flag = 0),
96
- flag ? flag < 0 ? (tagX -= tagWidth, symbol && symbol.setAttribute("x", (symbol.attribute.x || 0) - textWidth),
97
- group.setAttribute("x", -parsedPadding[1] - symbolPlaceWidth)) : flag > 0 && group.setAttribute("x", parsedPadding[3]) : (tagX -= tagWidth / 2,
98
- symbol && symbol.setAttribute("x", (symbol.attribute.x || 0) - textWidth / 2), group.setAttribute("x", -symbolPlaceWidth / 2));
99
- const shouldRight = "right" === containerTextAlign || "end" === containerTextAlign, shouldLeft = "left" === containerTextAlign || "start" === containerTextAlign, updateTextAttrs = (textX, textAlign) => {
100
- "richtext" === textShape.type ? textShape.setAttributes({
101
- x: textX,
102
- textAlign: textAlign,
103
- textConfig: array(textShape.attribute.textConfig).map((t => Object.assign(Object.assign({}, t), {
104
- textAlign: textAlign
105
- })))
106
- }) : textShape.setAttributes({
107
- x: textX,
108
- textAlign: textAlign
109
- });
110
- };
111
- if ((containerTextAlign ? "center" === containerTextAlign : textAlwaysCenter) && flag) {
112
- const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3], tsWidth = textWidth + symbolPlaceWidth, textX = 1 === flag ? (containerWidth - tsWidth) / 2 + symbolPlaceWidth + textWidth / 2 : parsedPadding[0] + symbolPlaceWidth - (tagWidth / 2 + tsWidth / 2 - symbolPlaceWidth) + textWidth / 2;
113
- if (updateTextAttrs(textX, "center"), symbol) {
114
- const symbolX = textX - textWidth / 2 - symbolPlaceWidth + maxSize / 2;
115
- symbol.setAttributes({
116
- x: symbolX
117
- });
82
+ isNil(textAttrs.lineHeight) && (textAttrs.lineHeight = textStyle.fontSize), textShape = group.createOrUpdateChild("tag-text", textAttrs, "text"),
83
+ isEmpty(null == state ? void 0 : state.text) || (textShape.states = state.text);
84
+ const textBounds = measureTextSize(textAttrs.text, textStyle, null === (_b = null === (_a = this.stage) || void 0 === _a ? void 0 : _a.getTheme()) || void 0 === _b ? void 0 : _b.text), textWidth = textBounds.width, textHeight = textBounds.height;
85
+ tagWidth += textWidth;
86
+ const size = null !== (_c = shape.size) && void 0 !== _c ? _c : 10, maxSize = isNumber(size) ? size : Math.max(size[0], size[1]);
87
+ tagHeight += Math.max(textHeight, shape.visible ? maxSize : 0);
88
+ const {textAlign: textAlign, textBaseline: textBaseline} = textStyle;
89
+ (isValid(minWidth) || isValid(maxWidth)) && (isValid(minWidth) && tagWidth < minWidth && (tagWidth = minWidth),
90
+ isValid(maxWidth) && tagWidth > maxWidth && (tagWidth = maxWidth, textShape.setAttribute("maxLineWidth", maxWidth - parsedPadding[1] - parsedPadding[2]))),
91
+ tagX = 0, tagY = 0;
92
+ let flag = 0;
93
+ "left" === textAlign || "start" === textAlign ? flag = 1 : "right" === textAlign || "end" === textAlign ? flag = -1 : "center" === textAlign && (flag = 0),
94
+ flag ? flag < 0 ? (tagX -= tagWidth, symbol && symbol.setAttribute("x", (symbol.attribute.x || 0) - textWidth),
95
+ group.setAttribute("x", -parsedPadding[1] - symbolPlaceWidth)) : flag > 0 && group.setAttribute("x", parsedPadding[3]) : (tagX -= tagWidth / 2,
96
+ symbol && symbol.setAttribute("x", (symbol.attribute.x || 0) - textWidth / 2), group.setAttribute("x", -symbolPlaceWidth / 2));
97
+ const shouldRight = "right" === containerTextAlign || "end" === containerTextAlign, shouldLeft = "left" === containerTextAlign || "start" === containerTextAlign;
98
+ if ((containerTextAlign ? "center" === containerTextAlign : textAlwaysCenter) && flag) {
99
+ const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3], tsWidth = textWidth + symbolPlaceWidth, textX = 1 === flag ? (containerWidth - tsWidth) / 2 + symbolPlaceWidth + textWidth / 2 : parsedPadding[0] + symbolPlaceWidth - (tagWidth / 2 + tsWidth / 2 - symbolPlaceWidth) + textWidth / 2;
100
+ if (textShape.setAttributes({
101
+ x: textX,
102
+ textAlign: "center"
103
+ }), symbol) {
104
+ const symbolX = textX - textWidth / 2 - symbolPlaceWidth + maxSize / 2;
105
+ symbol.setAttributes({
106
+ x: symbolX
107
+ });
108
+ }
118
109
  }
119
- }
120
- if (shouldLeft && 1 !== flag) {
121
- const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3], offset = 0 === flag ? -containerWidth / 2 + symbolPlaceWidth / 2 : -tagWidth + parsedPadding[3] + parsedPadding[1] + symbolPlaceWidth;
122
- if (updateTextAttrs(offset + symbolPlaceWidth, "left"), symbol) {
123
- const symbolX = offset + maxSize / 2;
124
- symbol.setAttributes({
125
- x: symbolX
126
- });
110
+ if (shouldLeft && 1 !== flag) {
111
+ const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3], offset = 0 === flag ? -containerWidth / 2 + symbolPlaceWidth / 2 : -tagWidth + parsedPadding[3] + parsedPadding[1] + symbolPlaceWidth, textX = offset + symbolPlaceWidth;
112
+ if (textShape.setAttributes({
113
+ x: textX,
114
+ textAlign: "left"
115
+ }), symbol) {
116
+ const symbolX = offset + maxSize / 2;
117
+ symbol.setAttributes({
118
+ x: symbolX
119
+ });
120
+ }
127
121
  }
128
- }
129
- if (shouldRight && -1 !== flag) {
130
- const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3], textX = 0 === flag ? containerWidth / 2 + symbolPlaceWidth / 2 : containerWidth;
131
- if (updateTextAttrs(textX, "right"), symbol) {
132
- const symbolX = textX - textWidth - symbolPlaceWidth + maxSize / 2;
133
- symbol.setAttributes({
134
- x: symbolX
135
- });
122
+ if (shouldRight && -1 !== flag) {
123
+ const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3], textX = 0 === flag ? containerWidth / 2 + symbolPlaceWidth / 2 : containerWidth;
124
+ if (textShape.setAttributes({
125
+ x: textX,
126
+ textAlign: "right"
127
+ }), symbol) {
128
+ const symbolX = textX - textWidth - symbolPlaceWidth + maxSize / 2;
129
+ symbol.setAttributes({
130
+ x: symbolX
131
+ });
132
+ }
136
133
  }
134
+ "middle" === textBaseline ? (tagY -= tagHeight / 2, symbol && symbol.setAttribute("y", 0)) : "bottom" === textBaseline ? (tagY -= tagHeight,
135
+ symbol && symbol.setAttribute("y", -textHeight / 2), group.setAttribute("y", -parsedPadding[2])) : "top" === textBaseline && (group.setAttribute("y", parsedPadding[0]),
136
+ symbol && symbol.setAttribute("y", textHeight / 2));
137
137
  }
138
- "middle" === textBaseline ? (tagY -= tagHeight / 2, symbol && symbol.setAttribute("y", 0)) : "bottom" === textBaseline ? (tagY -= tagHeight,
139
- symbol && symbol.setAttribute("y", -textHeight / 2), group.setAttribute("y", -parsedPadding[2])) : "top" === textBaseline && (group.setAttribute("y", parsedPadding[0]),
140
- symbol && symbol.setAttribute("y", textHeight / 2)), isEmpty(null == state ? void 0 : state.text) || (textShape.states = state.text);
141
138
  const {visible: bgVisible} = panel, backgroundStyle = __rest(panel, [ "visible" ]);
142
139
  if (visible && isBoolean(bgVisible)) {
143
140
  const bgRect = this.createOrUpdateChild("tag-panel", Object.assign(Object.assign({}, backgroundStyle), {
package/es/tag/tag.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/tag/tag.ts"],"names":[],"mappings":";;;;;;;;;;;AAGA,OAAO,EAUL,YAAY,EACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,KAAK,EACL,SAAS,EACT,OAAO,EACP,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,KAAK,EACL,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAGlF,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C,gBAAgB,EAAE,CAAC;AACnB,MAAM,OAAO,GAAI,SAAQ,iBAA0C;IAWjE,SAAS;QACP,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAkBD,YAAY,UAAyB,EAAE,OAA0B;QAC/D,KAAK,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;QAnC1F,SAAI,GAAG,KAAK,CAAC;QAKL,eAAU,GAAa,EAAE,CAAC;QAC1B,gBAAW,GAAa,EAAE,CAAC;QAC3B,kBAAa,GAAa,EAAE,CAAC;QAC7B,gBAAW,GAAa,EAAE,CAAC;IA4BnC,CAAC;IAES,MAAM;;QACd,IAAI,CAAC,WAAW,EAAE,CAAC;Q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AAC,IAAI,CAAC,WAAW,CAAC,CAAA,CAAC;IAC1E,CAAC;;AAnVM,qBAAiB,GAA2B;IACjD,OAAO,EAAE,IAAI;IACb,SAAS,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,IAAI,EAAE,MAAM;QACZ,SAAS,EAAE,MAAM;QACjB,YAAY,EAAE,KAAK;KACpB;IACD,KAAK,EAAE,CAAC;IACR,OAAO,EAAE,CAAC;IAEV,KAAK,EAAE;QACL,IAAI,EAAE,MAAM;KACb;CACF,CAAC","file":"tag.js","sourcesContent":["/**\n * @description 标签组件\n */\nimport {\n type IGroup,\n type IRect,\n type ISymbol,\n type IText,\n type ITextAttribute,\n type ITextGraphicAttribute,\n type IRichTextGraphicAttribute,\n type IRichText,\n type IGraphicAttribute,\n CustomPath2D\n} from '@visactor/vrender-core';\nimport {\n array,\n isBoolean,\n isEmpty,\n isNil,\n isNumber,\n isObject,\n isValid,\n merge,\n normalizePadding\n} from '@visactor/vutils';\nimport { AbstractComponent } from '../core/base';\nimport { isRichText, measureTextSize, richTextAttributeTransform } from '../util';\nimport type { BackgroundAttributes, ComponentOptions } from '../interface';\nimport type { TagAttributes, TagShapeAttributes } from './type';\nimport { loadTagComponent } from './register';\nimport type { TextContent } from '../core/type';\n\nloadTagComponent();\nexport class Tag extends AbstractComponent<Required<TagAttributes>> {\n name = 'tag';\n\n private _bgRect!: IRect;\n private _textShape!: IText | IRichText;\n private _symbol!: ISymbol;\n private _tagStates: string[] = [];\n private _rectStates: string[] = [];\n private _symbolStates: string[] = [];\n private _textStates: string[] = [];\n\n getBgRect() {\n return this._bgRect;\n }\n\n getTextShape() {\n return this._textShape;\n }\n\n static defaultAttributes: Partial<TagAttributes> = {\n visible: true,\n textStyle: {\n fontSize: 12,\n fill: '#000',\n textAlign: 'left',\n textBaseline: 'top'\n },\n space: 4,\n padding: 4,\n // @ts-ignore\n shape: {\n fill: '#000'\n }\n };\n\n constructor(attributes: TagAttributes, options?: ComponentOptions) {\n super(options?.skipDefault ? attributes : merge({}, Tag.defaultAttributes, attributes));\n }\n\n protected render() {\n this.cacheStates();\n const {\n text = '',\n textStyle = {} as ITextGraphicAttribute | IRichTextGraphicAttribute,\n shape = {} as TagShapeAttributes,\n panel = {} as BackgroundAttributes,\n space = 4,\n minWidth,\n maxWidth,\n padding = 4,\n visible,\n state,\n type,\n textAlwaysCenter,\n containerTextAlign\n } = this.attribute as TagAttributes;\n const parsedPadding = normalizePadding(padding);\n\n const group = this.createOrUpdateChild('tag-content', { x: 0, y: 0, zIndex: 1 }, 'group') as IGroup;\n\n let symbol;\n let tagX = -parsedPadding[3];\n let tagY = -parsedPadding[0];\n let tagWidth = parsedPadding[1] + parsedPadding[3];\n let tagHeight = parsedPadding[0] + parsedPadding[2];\n let textX = 0;\n let symbolPlaceWidth = 0;\n const { visible: shapeVisible, ...shapeStyle } = shape;\n if (isBoolean(shapeVisible)) {\n const size = shapeStyle?.size || 10;\n const maxSize = (isNumber(size) ? size : Math.max(size[0], size[1])) as number;\n\n symbol = group.createOrUpdateChild(\n 'tag-shape',\n {\n symbolType: 'circle',\n size,\n strokeBoundsBuffer: 0,\n ...shapeStyle,\n visible: shapeVisible,\n x: maxSize / 2,\n y: maxSize / 2\n },\n 'symbol'\n ) as ISymbol;\n if (!isEmpty(state?.shape)) {\n symbol.states = state.shape;\n }\n\n if (shapeVisible) {\n symbolPlaceWidth = maxSize + space;\n }\n }\n\n tagWidth += symbolPlaceWidth;\n textX += symbolPlaceWidth;\n\n let textShape: IRichText | IText;\n let textWidth;\n let textHeight;\n\n const isRich = isRichText({ text } as TextContent) || type === 'rich';\n if (isRich) {\n const richTextAttrs = {\n ...richTextAttributeTransform({ type, text, ...textStyle } as any),\n ...(textStyle as IRichTextGraphicAttribute),\n visible: isValid(text) && visible !== false,\n x: textX,\n y: 0\n };\n if (isNil(richTextAttrs.lineHeight)) {\n richTextAttrs.lineHeight = (textStyle as ITextGraphicAttribute).fontSize;\n }\n textShape = group.createOrUpdateChild('tag-text', richTextAttrs, 'richtext') as IRichText;\n textWidth = textShape.AABBBounds.width();\n textHeight = textShape.AABBBounds.height();\n } else {\n const textAttrs = {\n text: isObject(text) && 'type' in text && text.type === 'text' ? text.text : text,\n visible: isValid(text) && visible !== false,\n lineHeight: (textStyle as ITextGraphicAttribute)?.fontSize,\n ...(textStyle as ITextGraphicAttribute),\n x: textX,\n y: 0\n };\n if (isNil(textAttrs.lineHeight)) {\n textAttrs.lineHeight = (textStyle as ITextGraphicAttribute).fontSize;\n }\n textShape = group.createOrUpdateChild('tag-text', textAttrs as ITextGraphicAttribute, 'text') as IText;\n\n // 因为文本可能发生旋转,所以需要使用 measureTextSize 方法\n const textBounds = measureTextSize(textAttrs.text as string, textStyle, this.stage?.getTheme()?.text);\n textWidth = textBounds.width;\n textHeight = textBounds.height;\n }\n\n tagWidth += textWidth;\n const size = shape.size ?? 10;\n const maxSize = (isNumber(size) ? size : Math.max(size[0], size[1])) as number;\n tagHeight += Math.max(textHeight, shape.visible ? maxSize : 0);\n\n const { textAlign, textBaseline } = textStyle as ITextAttribute;\n\n if (isValid(minWidth) || isValid(maxWidth)) {\n if (isValid(minWidth) && tagWidth < minWidth) {\n tagWidth = minWidth;\n }\n if (isValid(maxWidth) && tagWidth > maxWidth) {\n tagWidth = maxWidth;\n textShape.setAttribute('maxLineWidth', maxWidth - parsedPadding[1] - parsedPadding[2]);\n }\n }\n\n tagX = 0;\n tagY = 0;\n let flag = 0;\n if (textAlign === 'left' || textAlign === 'start') {\n flag = 1;\n } else if (textAlign === 'right' || textAlign === 'end') {\n flag = -1;\n } else if (textAlign === 'center') {\n flag = 0;\n }\n if (!flag) {\n tagX -= tagWidth / 2;\n if (symbol) {\n symbol.setAttribute('x', (symbol.attribute.x || 0) - textWidth / 2);\n }\n\n group.setAttribute('x', -symbolPlaceWidth / 2);\n } else if (flag < 0) {\n tagX -= tagWidth;\n if (symbol) {\n symbol.setAttribute('x', (symbol.attribute.x || 0) - textWidth);\n }\n\n group.setAttribute('x', -parsedPadding[1] - symbolPlaceWidth);\n } else if (flag > 0) {\n group.setAttribute('x', parsedPadding[3]);\n }\n\n const shouldCenter = containerTextAlign ? containerTextAlign === 'center' : textAlwaysCenter;\n const shouldRight = containerTextAlign === 'right' || containerTextAlign === 'end';\n const shouldLeft = containerTextAlign === 'left' || containerTextAlign === 'start';\n\n const updateTextAttrs = (textX: number, textAlign: 'center' | 'left' | 'right') => {\n if (textShape.type === 'richtext') {\n textShape.setAttributes({\n x: textX,\n textAlign,\n textConfig: array((textShape.attribute as IRichTextGraphicAttribute).textConfig).map(t => {\n return {\n ...t,\n textAlign\n };\n })\n });\n } else {\n textShape.setAttributes({\n x: textX,\n textAlign\n });\n }\n };\n\n if (shouldCenter && flag) {\n // 文本容器内居中\n // 剔除padding后的内宽度\n const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];\n const tsWidth = textWidth + symbolPlaceWidth;\n const textX =\n flag === 1\n ? (containerWidth - tsWidth) / 2 + symbolPlaceWidth + textWidth / 2\n : parsedPadding[0] + symbolPlaceWidth - (tagWidth / 2 + tsWidth / 2 - symbolPlaceWidth) + textWidth / 2;\n\n updateTextAttrs(textX, 'center');\n if (symbol) {\n const symbolX = textX - textWidth / 2 - symbolPlaceWidth + maxSize / 2;\n symbol.setAttributes({\n x: symbolX\n });\n }\n }\n\n if (shouldLeft && flag !== 1) {\n // 文本容器内朝左展示\n const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];\n const offset =\n flag === 0\n ? -containerWidth / 2 + symbolPlaceWidth / 2\n : -tagWidth + parsedPadding[3] + parsedPadding[1] + symbolPlaceWidth;\n const textX = offset + symbolPlaceWidth;\n\n updateTextAttrs(textX, 'left');\n\n if (symbol) {\n const symbolX = offset + maxSize / 2;\n symbol.setAttributes({\n x: symbolX\n });\n }\n }\n\n if (shouldRight && flag !== -1) {\n // 文本容器内朝右展示\n const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];\n const textX = flag === 0 ? containerWidth / 2 + symbolPlaceWidth / 2 : containerWidth;\n updateTextAttrs(textX, 'right');\n\n if (symbol) {\n const symbolX = textX - textWidth - symbolPlaceWidth + maxSize / 2;\n symbol.setAttributes({\n x: symbolX\n });\n }\n }\n\n if (textBaseline === 'middle') {\n tagY -= tagHeight / 2;\n if (symbol) {\n symbol.setAttribute('y', 0);\n }\n } else if (textBaseline === 'bottom') {\n tagY -= tagHeight;\n if (symbol) {\n symbol.setAttribute('y', -textHeight / 2);\n }\n\n group.setAttribute('y', -parsedPadding[2]);\n } else if (textBaseline === 'top') {\n group.setAttribute('y', parsedPadding[0]);\n if (symbol) {\n symbol.setAttribute('y', textHeight / 2);\n }\n }\n\n if (!isEmpty(state?.text)) {\n textShape.states = state.text;\n }\n // 绘制背景层\n const { visible: bgVisible, ...backgroundStyle } = panel;\n if (visible && isBoolean(bgVisible)) {\n const bgRect = this.createOrUpdateChild(\n 'tag-panel',\n {\n ...backgroundStyle,\n visible: bgVisible && !!text,\n width: tagWidth,\n height: tagHeight,\n x: tagX,\n y: tagY\n },\n 'rect'\n ) as IRect;\n if (!isEmpty(state?.panel)) {\n bgRect.states = state.panel;\n }\n if (backgroundStyle.customShape) {\n const customShape = backgroundStyle.customShape;\n bgRect.pathProxy = (attrs: Partial<IGraphicAttribute>) => {\n return customShape(this, attrs, new CustomPath2D());\n };\n }\n this._bgRect = bgRect;\n }\n this._textShape = textShape;\n this._symbol = symbol;\n\n this.resetStates();\n }\n\n initAttributes(params: TagAttributes, options?: ComponentOptions) {\n params = options?.skipDefault ? params : merge({}, Tag.defaultAttributes, params);\n super.initAttributes(params);\n this.render();\n }\n\n addState(stateName: string, keepCurrentStates?: boolean, hasAnimation?: boolean): void {\n super.addState(stateName, keepCurrentStates, hasAnimation);\n if (this._textShape) {\n this._textShape.addState(stateName, keepCurrentStates, hasAnimation);\n }\n if (this._bgRect) {\n this._bgRect.addState(stateName, keepCurrentStates, hasAnimation);\n }\n if (this._symbol) {\n this._symbol.addState(stateName, keepCurrentStates, hasAnimation);\n }\n }\n\n removeState(stateName: string, hasAnimation?: boolean): void {\n super.removeState(stateName, hasAnimation);\n if (this._textShape) {\n this._textShape.removeState(stateName, hasAnimation);\n }\n if (this._bgRect) {\n this._bgRect.removeState(stateName, hasAnimation);\n }\n if (this._symbol) {\n this._symbol.removeState(stateName, hasAnimation);\n }\n }\n\n cacheStates() {\n this._tagStates = this.currentStates?.slice() ?? [];\n this._rectStates = this._bgRect?.currentStates?.slice() ?? [];\n this._symbolStates = this._symbol?.currentStates?.slice() ?? [];\n this._textStates = this._textShape?.currentStates?.slice() ?? [];\n this.clearStates();\n this._bgRect?.clearStates();\n this._symbol?.clearStates();\n this._textShape?.clearStates();\n }\n resetStates() {\n this._tagStates.length && this.useStates(this._tagStates);\n this._rectStates.length && this._bgRect?.useStates(this._rectStates);\n this._symbolStates.length && this._symbol?.useStates(this._symbolStates);\n this._textStates.length && this._textShape?.useStates(this._textStates);\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/tag/tag.ts"],"names":[],"mappings":";;;;;;;;;;;AAGA,OAAO,EAUL,YAAY,EACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACnH,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAGlF,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C,gBAAgB,EAAE,CAAC;AACnB,MAAM,OAAO,GAAI,SAAQ,iBAA0C;IAWjE,SAAS;QACP,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAkBD,YAAY,UAAyB,EAAE,OAA0B;Q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,CAAA,CAAC;QACzE,IAAI,CAAC,WAAW,CAAC,MAAM,KAAI,MAAA,IAAI,CAAC,UAAU,0CAAE,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA,CAAC;IAC1E,CAAC;;AAlUM,qBAAiB,GAA2B;IACjD,OAAO,EAAE,IAAI;IACb,SAAS,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,IAAI,EAAE,MAAM;QACZ,SAAS,EAAE,MAAM;QACjB,YAAY,EAAE,KAAK;KACpB;IACD,KAAK,EAAE,CAAC;IACR,OAAO,EAAE,CAAC;IAEV,KAAK,EAAE;QACL,IAAI,EAAE,MAAM;KACb;CACF,CAAC","file":"tag.js","sourcesContent":["/**\n * @description 标签组件\n */\nimport {\n type IGroup,\n type IRect,\n type ISymbol,\n type IText,\n type ITextAttribute,\n type ITextGraphicAttribute,\n type IRichTextGraphicAttribute,\n type IRichText,\n type IGraphicAttribute,\n CustomPath2D\n} from '@visactor/vrender-core';\nimport { isBoolean, isEmpty, isNil, isNumber, isObject, isValid, merge, normalizePadding } from '@visactor/vutils';\nimport { AbstractComponent } from '../core/base';\nimport { isRichText, measureTextSize, richTextAttributeTransform } from '../util';\nimport type { BackgroundAttributes, ComponentOptions } from '../interface';\nimport type { TagAttributes, TagShapeAttributes } from './type';\nimport { loadTagComponent } from './register';\nimport type { TextContent } from '../core/type';\n\nloadTagComponent();\nexport class Tag extends AbstractComponent<Required<TagAttributes>> {\n name = 'tag';\n\n private _bgRect!: IRect;\n private _textShape!: IText | IRichText;\n private _symbol!: ISymbol;\n private _tagStates: string[] = [];\n private _rectStates: string[] = [];\n private _symbolStates: string[] = [];\n private _textStates: string[] = [];\n\n getBgRect() {\n return this._bgRect;\n }\n\n getTextShape() {\n return this._textShape;\n }\n\n static defaultAttributes: Partial<TagAttributes> = {\n visible: true,\n textStyle: {\n fontSize: 12,\n fill: '#000',\n textAlign: 'left',\n textBaseline: 'top'\n },\n space: 4,\n padding: 4,\n // @ts-ignore\n shape: {\n fill: '#000'\n }\n };\n\n constructor(attributes: TagAttributes, options?: ComponentOptions) {\n super(options?.skipDefault ? attributes : merge({}, Tag.defaultAttributes, attributes));\n }\n\n protected render() {\n this.cacheStates();\n const {\n text = '',\n textStyle = {} as ITextGraphicAttribute | IRichTextGraphicAttribute,\n shape = {} as TagShapeAttributes,\n panel = {} as BackgroundAttributes,\n space = 4,\n minWidth,\n maxWidth,\n padding = 4,\n visible,\n state,\n type,\n textAlwaysCenter,\n containerTextAlign\n } = this.attribute as TagAttributes;\n const parsedPadding = normalizePadding(padding);\n\n const group = this.createOrUpdateChild('tag-content', { x: 0, y: 0, zIndex: 1 }, 'group') as IGroup;\n\n let symbol;\n let tagX = -parsedPadding[3];\n let tagY = -parsedPadding[0];\n let tagWidth = parsedPadding[1] + parsedPadding[3];\n let tagHeight = parsedPadding[0] + parsedPadding[2];\n let textX = 0;\n let symbolPlaceWidth = 0;\n const { visible: shapeVisible, ...shapeStyle } = shape;\n if (isBoolean(shapeVisible)) {\n const size = shapeStyle?.size || 10;\n const maxSize = (isNumber(size) ? size : Math.max(size[0], size[1])) as number;\n\n symbol = group.createOrUpdateChild(\n 'tag-shape',\n {\n symbolType: 'circle',\n size,\n strokeBoundsBuffer: 0,\n ...shapeStyle,\n visible: shapeVisible,\n x: maxSize / 2,\n y: maxSize / 2\n },\n 'symbol'\n ) as ISymbol;\n if (!isEmpty(state?.shape)) {\n symbol.states = state.shape;\n }\n\n if (shapeVisible) {\n symbolPlaceWidth = maxSize + space;\n }\n }\n\n tagWidth += symbolPlaceWidth;\n textX += symbolPlaceWidth;\n\n let textShape: IRichText | IText;\n const isRich = isRichText({ text } as TextContent) || type === 'rich';\n if (isRich) {\n const richTextAttrs = {\n ...richTextAttributeTransform({ type, text, ...textStyle } as any),\n ...(textStyle as IRichTextGraphicAttribute),\n visible: isValid(text) && visible !== false,\n x: textX,\n y: 0\n };\n textShape = group.createOrUpdateChild('tag-text', richTextAttrs, 'richtext') as IRichText;\n tagWidth += textShape.AABBBounds.width();\n tagHeight += textShape.AABBBounds.height();\n tagX += textShape.AABBBounds.x1;\n tagY += textShape.AABBBounds.y1;\n } else {\n const textAttrs = {\n text: isObject(text) && 'type' in text && text.type === 'text' ? text.text : text,\n visible: isValid(text) && visible !== false,\n lineHeight: (textStyle as ITextGraphicAttribute)?.fontSize,\n ...(textStyle as ITextGraphicAttribute),\n x: textX,\n y: 0\n };\n if (isNil(textAttrs.lineHeight)) {\n textAttrs.lineHeight = (textStyle as ITextGraphicAttribute).fontSize;\n }\n textShape = group.createOrUpdateChild('tag-text', textAttrs as ITextGraphicAttribute, 'text') as IText;\n if (!isEmpty(state?.text)) {\n textShape.states = state.text;\n }\n\n // 因为文本可能发生旋转,所以需要使用 measureTextSize 方法\n const textBounds = measureTextSize(textAttrs.text as string, textStyle, this.stage?.getTheme()?.text);\n const textWidth = textBounds.width;\n const textHeight = textBounds.height;\n tagWidth += textWidth;\n const size = shape.size ?? 10;\n const maxSize = (isNumber(size) ? size : Math.max(size[0], size[1])) as number;\n tagHeight += Math.max(textHeight, shape.visible ? maxSize : 0);\n\n const { textAlign, textBaseline } = textStyle as ITextAttribute;\n\n if (isValid(minWidth) || isValid(maxWidth)) {\n if (isValid(minWidth) && tagWidth < minWidth) {\n tagWidth = minWidth;\n }\n if (isValid(maxWidth) && tagWidth > maxWidth) {\n tagWidth = maxWidth;\n textShape.setAttribute('maxLineWidth', maxWidth - parsedPadding[1] - parsedPadding[2]);\n }\n }\n\n tagX = 0;\n tagY = 0;\n let flag = 0;\n if (textAlign === 'left' || textAlign === 'start') {\n flag = 1;\n } else if (textAlign === 'right' || textAlign === 'end') {\n flag = -1;\n } else if (textAlign === 'center') {\n flag = 0;\n }\n if (!flag) {\n tagX -= tagWidth / 2;\n if (symbol) {\n symbol.setAttribute('x', (symbol.attribute.x || 0) - textWidth / 2);\n }\n\n group.setAttribute('x', -symbolPlaceWidth / 2);\n } else if (flag < 0) {\n tagX -= tagWidth;\n if (symbol) {\n symbol.setAttribute('x', (symbol.attribute.x || 0) - textWidth);\n }\n\n group.setAttribute('x', -parsedPadding[1] - symbolPlaceWidth);\n } else if (flag > 0) {\n group.setAttribute('x', parsedPadding[3]);\n }\n\n const shouldCenter = containerTextAlign ? containerTextAlign === 'center' : textAlwaysCenter;\n const shouldRight = containerTextAlign === 'right' || containerTextAlign === 'end';\n const shouldLeft = containerTextAlign === 'left' || containerTextAlign === 'start';\n\n if (shouldCenter && flag) {\n // 文本容器内居中\n // 剔除padding后的内宽度\n const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];\n const tsWidth = textWidth + symbolPlaceWidth;\n const textX =\n flag === 1\n ? (containerWidth - tsWidth) / 2 + symbolPlaceWidth + textWidth / 2\n : parsedPadding[0] + symbolPlaceWidth - (tagWidth / 2 + tsWidth / 2 - symbolPlaceWidth) + textWidth / 2;\n\n textShape.setAttributes({\n x: textX,\n textAlign: 'center'\n });\n if (symbol) {\n const symbolX = textX - textWidth / 2 - symbolPlaceWidth + maxSize / 2;\n symbol.setAttributes({\n x: symbolX\n });\n }\n }\n\n if (shouldLeft && flag !== 1) {\n // 文本容器内朝左展示\n const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];\n const offset =\n flag === 0\n ? -containerWidth / 2 + symbolPlaceWidth / 2\n : -tagWidth + parsedPadding[3] + parsedPadding[1] + symbolPlaceWidth;\n const textX = offset + symbolPlaceWidth;\n\n textShape.setAttributes({\n x: textX,\n textAlign: 'left'\n });\n\n if (symbol) {\n const symbolX = offset + maxSize / 2;\n symbol.setAttributes({\n x: symbolX\n });\n }\n }\n\n if (shouldRight && flag !== -1) {\n // 文本容器内朝右展示\n const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];\n const textX = flag === 0 ? containerWidth / 2 + symbolPlaceWidth / 2 : containerWidth;\n\n textShape.setAttributes({\n x: textX,\n textAlign: 'right'\n });\n if (symbol) {\n const symbolX = textX - textWidth - symbolPlaceWidth + maxSize / 2;\n symbol.setAttributes({\n x: symbolX\n });\n }\n }\n\n if (textBaseline === 'middle') {\n tagY -= tagHeight / 2;\n if (symbol) {\n symbol.setAttribute('y', 0);\n }\n } else if (textBaseline === 'bottom') {\n tagY -= tagHeight;\n if (symbol) {\n symbol.setAttribute('y', -textHeight / 2);\n }\n\n group.setAttribute('y', -parsedPadding[2]);\n } else if (textBaseline === 'top') {\n group.setAttribute('y', parsedPadding[0]);\n if (symbol) {\n symbol.setAttribute('y', textHeight / 2);\n }\n }\n }\n // 绘制背景层\n const { visible: bgVisible, ...backgroundStyle } = panel;\n if (visible && isBoolean(bgVisible)) {\n const bgRect = this.createOrUpdateChild(\n 'tag-panel',\n {\n ...backgroundStyle,\n visible: bgVisible && !!text,\n width: tagWidth,\n height: tagHeight,\n x: tagX,\n y: tagY\n },\n 'rect'\n ) as IRect;\n if (!isEmpty(state?.panel)) {\n bgRect.states = state.panel;\n }\n if (backgroundStyle.customShape) {\n const customShape = backgroundStyle.customShape;\n bgRect.pathProxy = (attrs: Partial<IGraphicAttribute>) => {\n return customShape(this, attrs, new CustomPath2D());\n };\n }\n this._bgRect = bgRect;\n }\n this._textShape = textShape;\n this._symbol = symbol;\n\n this.resetStates();\n }\n\n initAttributes(params: TagAttributes, options?: ComponentOptions) {\n params = options?.skipDefault ? params : merge({}, Tag.defaultAttributes, params);\n super.initAttributes(params);\n this.render();\n }\n\n addState(stateName: string, keepCurrentStates?: boolean, hasAnimation?: boolean): void {\n super.addState(stateName, keepCurrentStates, hasAnimation);\n if (this._textShape) {\n this._textShape.addState(stateName, keepCurrentStates, hasAnimation);\n }\n if (this._bgRect) {\n this._bgRect.addState(stateName, keepCurrentStates, hasAnimation);\n }\n if (this._symbol) {\n this._symbol.addState(stateName, keepCurrentStates, hasAnimation);\n }\n }\n\n removeState(stateName: string, hasAnimation?: boolean): void {\n super.removeState(stateName, hasAnimation);\n if (this._textShape) {\n this._textShape.removeState(stateName, hasAnimation);\n }\n if (this._bgRect) {\n this._bgRect.removeState(stateName, hasAnimation);\n }\n if (this._symbol) {\n this._symbol.removeState(stateName, hasAnimation);\n }\n }\n\n cacheStates() {\n this._tagStates = this.currentStates?.slice() ?? [];\n this._rectStates = this._bgRect?.currentStates?.slice() ?? [];\n this._symbolStates = this._symbol?.currentStates?.slice() ?? [];\n this._textStates = this._textShape?.currentStates?.slice() ?? [];\n this.clearStates();\n this._bgRect?.clearStates();\n this._symbol?.clearStates();\n this._textShape?.clearStates();\n }\n resetStates() {\n this._tagStates.length && this.useStates(this._tagStates);\n this._rectStates.length && this._bgRect?.useStates(this._rectStates);\n this._symbolStates.length && this._symbol?.useStates(this._symbolStates);\n this._textStates.length && this._textShape?.useStates(this._textStates);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visactor/vrender-components",
3
- "version": "0.22.5",
3
+ "version": "0.22.6-alpha.1",
4
4
  "description": "components library for dp visualization",
5
5
  "sideEffects": false,
6
6
  "main": "cjs/index.js",
@@ -14,8 +14,8 @@
14
14
  "dependencies": {
15
15
  "@visactor/vutils": "~0.19.4",
16
16
  "@visactor/vscale": "~0.19.4",
17
- "@visactor/vrender-core": "0.22.5",
18
- "@visactor/vrender-kits": "0.22.5"
17
+ "@visactor/vrender-core": "0.22.6-alpha.1",
18
+ "@visactor/vrender-kits": "0.22.6-alpha.1"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@rushstack/eslint-patch": "~1.1.4",