@visactor/vrender-components 0.22.3 → 0.22.5-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.
@@ -203,5 +203,4 @@ class Brush extends base_1.AbstractComponent {
203
203
  }
204
204
  }
205
205
 
206
- exports.Brush = Brush, Brush.defaultAttributes = config_1.DEFAULT_BRUSH_ATTRIBUTES;
207
- //# sourceMappingURL=brush.js.map
206
+ exports.Brush = Brush, Brush.defaultAttributes = config_1.DEFAULT_BRUSH_ATTRIBUTES;
package/cjs/brush/type.js CHANGED
@@ -8,4 +8,5 @@ Object.defineProperty(exports, "__esModule", {
8
8
  IOperateType.drawStart = "drawStart", IOperateType.drawEnd = "drawEnd", IOperateType.drawing = "drawing",
9
9
  IOperateType.moving = "moving", IOperateType.moveStart = "moveStart", IOperateType.moveEnd = "moveEnd",
10
10
  IOperateType.brushClear = "brushClear";
11
- }(IOperateType = exports.IOperateType || (exports.IOperateType = {}));
11
+ }(IOperateType = exports.IOperateType || (exports.IOperateType = {}));
12
+ //# sourceMappingURL=type.js.map
package/cjs/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const version = "0.22.3";
1
+ export declare const version = "0.22.5-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.3", __exportStar(require("./core/base"), exports),
20
+ }), exports.version = void 0, exports.version = "0.22.5-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.3\";\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.5-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"]}
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;
58
+ let textShape, textWidth, textHeight;
59
59
  tagWidth += symbolPlaceWidth, textX += symbolPlaceWidth;
60
60
  if ((0, util_1.isRichText)({
61
61
  text: text
@@ -68,8 +68,9 @@ class Tag extends base_1.AbstractComponent {
68
68
  x: textX,
69
69
  y: 0
70
70
  });
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;
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();
73
74
  } else {
74
75
  const textAttrs = Object.assign(Object.assign({
75
76
  text: (0, vutils_1.isObject)(text) && "type" in text && "text" === text.type ? text.text : text,
@@ -80,63 +81,66 @@ class Tag extends base_1.AbstractComponent {
80
81
  y: 0
81
82
  });
82
83
  (0, vutils_1.isNil)(textAttrs.lineHeight) && (textAttrs.lineHeight = textStyle.fontSize),
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
- }
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
+ });
111
121
  }
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
- }
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
+ });
123
130
  }
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
- }
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
+ });
135
139
  }
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));
139
140
  }
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);
140
144
  const {visible: bgVisible} = panel, backgroundStyle = __rest(panel, [ "visible" ]);
141
145
  if (visible && (0, vutils_1.isBoolean)(bgVisible)) {
142
146
  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,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,EAAE,UAAU,CAAC,CAAC,CAAC;QAnC1F,SAAI,GAAG,KAAK,CAAC;QAKL,eAAU,GAAa,EAA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,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"]}
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,SAAS,GAAG,EAAuD,EACnE,KAAK,GAAG,EAAwB,EAChC,KAAK,GAAG,EAA0B,EAClC,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AAA,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"]}
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, 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';
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';
2
2
  import { isContinuous, isDiscrete, LinearScale } from '@visactor/vscale';
3
3
 
4
4
  class Generator {
@@ -10319,6 +10319,7 @@ class DefaultBaseTextureRenderContribution {
10319
10319
  texture && this.drawTexture(texture, graphic, context, x, y, graphicAttribute, textureColor, textureSize, texturePadding);
10320
10320
  }
10321
10321
  drawTexture(texture, graphic, context, x, y, graphicAttribute, textureColor, textureSize, texturePadding) {
10322
+ var _a;
10322
10323
  const {
10323
10324
  textureRatio = graphicAttribute.textureRatio,
10324
10325
  textureOptions = null
@@ -10350,12 +10351,32 @@ class DefaultBaseTextureRenderContribution {
10350
10351
  pattern = this.createGridPattern(textureSize, texturePadding, textureColor, context);
10351
10352
  }
10352
10353
  if (textureOptions && textureOptions.dynamicTexture) {
10353
- context.save(), context.setCommonStyle(graphic, graphic.attribute, x, y, graphicAttribute), context.clip();
10354
10354
  const {
10355
- gridConfig = {}
10355
+ gridConfig = {},
10356
+ useNewCanvas: useNewCanvas
10356
10357
  } = textureOptions,
10357
- b = graphic.AABBBounds,
10358
- width = b.width(),
10358
+ b = graphic.AABBBounds;
10359
+ x = b.x1, y = b.y1;
10360
+ const originalContext = context;
10361
+ let newCanvas;
10362
+ if (useNewCanvas) {
10363
+ newCanvas = canvasAllocate.allocate({
10364
+ width: b.width(),
10365
+ height: b.height(),
10366
+ dpr: context.dpr
10367
+ });
10368
+ const ctx = newCanvas.getContext("2d");
10369
+ ctx.clearRect(0, 0, b.width(), b.height()), x = 0, y = 0, context = ctx;
10370
+ }
10371
+ if (originalContext.save(), graphic.parent && !graphic.transMatrix.onlyTranslate()) {
10372
+ const {
10373
+ scrollX = 0,
10374
+ scrollY = 0
10375
+ } = graphic.parent.attribute;
10376
+ originalContext.setTransformFromMatrix(graphic.parent.globalTransMatrix), originalContext.translate(scrollX, scrollY, !0);
10377
+ }
10378
+ originalContext.setCommonStyle(graphic, graphic.attribute, x, y, graphicAttribute), originalContext.clip();
10379
+ const width = b.width(),
10359
10380
  height = b.height(),
10360
10381
  padding = texturePadding,
10361
10382
  cellSize = textureSize,
@@ -10374,9 +10395,9 @@ class DefaultBaseTextureRenderContribution {
10374
10395
  for (let i = 0; i < gridRows; i++) for (let j = 0; j < gridColumns; j++) {
10375
10396
  const _x = x + cellSize / 2 + j * cellSize,
10376
10397
  _y = y + cellSize / 2 + i * cellSize;
10377
- context.beginPath(), !1 === parsedPath.draw(context, Math.min(sizeW - gutterColumn, sizeH - gutterRow), _x, _y, 0) && context.closePath(), context.fillStyle = textureColor, textureOptions.dynamicTexture(context, i, j, gridRows, gridColumns, textureRatio, graphic);
10398
+ null === (_a = textureOptions.beforeDynamicTexture) || void 0 === _a || _a.call(textureOptions, context, i, j, gridRows, gridColumns, textureRatio, graphic, b.width(), b.height()), context.beginPath(), !1 === parsedPath.draw(context, Math.min(sizeW - gutterColumn, sizeH - gutterRow), _x, _y, 0) && context.closePath(), context.fillStyle = textureColor, textureOptions.dynamicTexture(context, i, j, gridRows, gridColumns, textureRatio, graphic, b.width(), b.height());
10378
10399
  }
10379
- context.restore();
10400
+ useNewCanvas && (originalContext.globalAlpha = 1, originalContext.drawImage(newCanvas.nativeCanvas, 0, 0, newCanvas.nativeCanvas.width, newCanvas.nativeCanvas.height, b.x1, b.y1, b.width() * originalContext.dpr, b.height() * originalContext.dpr)), originalContext.restore();
10380
10401
  } else if (pattern) context.highPerformanceSave(), context.setCommonStyle(graphic, graphic.attribute, x, y, graphicAttribute), context.fillStyle = pattern, context.fill(), context.highPerformanceRestore();else if ("wave" === texture) {
10381
10402
  context.save(), context.setCommonStyle(graphic, graphic.attribute, x, y, graphicAttribute), context.clip();
10382
10403
  const b = graphic.AABBBounds;
@@ -15920,14 +15941,17 @@ class Tag extends AbstractComponent {
15920
15941
  tagWidth += symbolPlaceWidth;
15921
15942
  textX += symbolPlaceWidth;
15922
15943
  let textShape;
15944
+ let textWidth;
15945
+ let textHeight;
15923
15946
  const isRich = isRichText({ text }) || type === 'rich';
15924
15947
  if (isRich) {
15925
15948
  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
+ }
15926
15952
  textShape = group.createOrUpdateChild('tag-text', richTextAttrs, 'richtext');
15927
- tagWidth += textShape.AABBBounds.width();
15928
- tagHeight += textShape.AABBBounds.height();
15929
- tagX += textShape.AABBBounds.x1;
15930
- tagY += textShape.AABBBounds.y1;
15953
+ textWidth = textShape.AABBBounds.width();
15954
+ textHeight = textShape.AABBBounds.height();
15931
15955
  }
15932
15956
  else {
15933
15957
  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 });
@@ -15935,125 +15959,133 @@ class Tag extends AbstractComponent {
15935
15959
  textAttrs.lineHeight = textStyle.fontSize;
15936
15960
  }
15937
15961
  textShape = group.createOrUpdateChild('tag-text', textAttrs, 'text');
15938
- if (!isEmpty(state === null || state === void 0 ? void 0 : state.text)) {
15939
- textShape.states = state.text;
15940
- }
15941
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);
15942
- const textWidth = textBounds.width;
15943
- const textHeight = textBounds.height;
15944
- tagWidth += textWidth;
15945
- const size = (_c = shape.size) !== null && _c !== void 0 ? _c : 10;
15946
- const maxSize = (isNumber(size) ? size : Math.max(size[0], size[1]));
15947
- tagHeight += Math.max(textHeight, shape.visible ? maxSize : 0);
15948
- const { textAlign, textBaseline } = textStyle;
15949
- if (isValid(minWidth) || isValid(maxWidth)) {
15950
- if (isValid(minWidth) && tagWidth < minWidth) {
15951
- tagWidth = minWidth;
15952
- }
15953
- if (isValid(maxWidth) && tagWidth > maxWidth) {
15954
- tagWidth = maxWidth;
15955
- textShape.setAttribute('maxLineWidth', maxWidth - parsedPadding[1] - parsedPadding[2]);
15956
- }
15957
- }
15958
- tagX = 0;
15959
- tagY = 0;
15960
- let flag = 0;
15961
- if (textAlign === 'left' || textAlign === 'start') {
15962
- flag = 1;
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
15974
  }
15964
- else if (textAlign === 'right' || textAlign === 'end') {
15965
- flag = -1;
15975
+ if (isValid(maxWidth) && tagWidth > maxWidth) {
15976
+ tagWidth = maxWidth;
15977
+ textShape.setAttribute('maxLineWidth', maxWidth - parsedPadding[1] - parsedPadding[2]);
15966
15978
  }
15967
- else if (textAlign === 'center') {
15968
- flag = 0;
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);
15969
15996
  }
15970
- if (!flag) {
15971
- tagX -= tagWidth / 2;
15972
- if (symbol) {
15973
- symbol.setAttribute('x', (symbol.attribute.x || 0) - textWidth / 2);
15974
- }
15975
- group.setAttribute('x', -symbolPlaceWidth / 2);
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);
15976
16003
  }
15977
- else if (flag < 0) {
15978
- tagX -= tagWidth;
15979
- if (symbol) {
15980
- symbol.setAttribute('x', (symbol.attribute.x || 0) - textWidth);
15981
- }
15982
- group.setAttribute('x', -parsedPadding[1] - symbolPlaceWidth);
15983
- }
15984
- else if (flag > 0) {
15985
- group.setAttribute('x', parsedPadding[3]);
15986
- }
15987
- const shouldCenter = containerTextAlign ? containerTextAlign === 'center' : textAlwaysCenter;
15988
- const shouldRight = containerTextAlign === 'right' || containerTextAlign === 'end';
15989
- const shouldLeft = containerTextAlign === 'left' || containerTextAlign === 'start';
15990
- if (shouldCenter && flag) {
15991
- const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];
15992
- const tsWidth = textWidth + symbolPlaceWidth;
15993
- const textX = flag === 1
15994
- ? (containerWidth - tsWidth) / 2 + symbolPlaceWidth + textWidth / 2
15995
- : parsedPadding[0] + symbolPlaceWidth - (tagWidth / 2 + tsWidth / 2 - symbolPlaceWidth) + textWidth / 2;
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') {
15996
16014
  textShape.setAttributes({
15997
16015
  x: textX,
15998
- textAlign: 'center'
16016
+ textAlign,
16017
+ textConfig: array(textShape.attribute.textConfig).map(t => {
16018
+ return Object.assign(Object.assign({}, t), { textAlign });
16019
+ })
15999
16020
  });
16000
- if (symbol) {
16001
- const symbolX = textX - textWidth / 2 - symbolPlaceWidth + maxSize / 2;
16002
- symbol.setAttributes({
16003
- x: symbolX
16004
- });
16005
- }
16006
16021
  }
16007
- if (shouldLeft && flag !== 1) {
16008
- const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];
16009
- const offset = flag === 0
16010
- ? -containerWidth / 2 + symbolPlaceWidth / 2
16011
- : -tagWidth + parsedPadding[3] + parsedPadding[1] + symbolPlaceWidth;
16012
- const textX = offset + symbolPlaceWidth;
16022
+ else {
16013
16023
  textShape.setAttributes({
16014
16024
  x: textX,
16015
- textAlign: 'left'
16025
+ textAlign
16016
16026
  });
16017
- if (symbol) {
16018
- const symbolX = offset + maxSize / 2;
16019
- symbol.setAttributes({
16020
- x: symbolX
16021
- });
16022
- }
16023
16027
  }
16024
- if (shouldRight && flag !== -1) {
16025
- const containerWidth = tagWidth - parsedPadding[1] - parsedPadding[3];
16026
- const textX = flag === 0 ? containerWidth / 2 + symbolPlaceWidth / 2 : containerWidth;
16027
- textShape.setAttributes({
16028
- x: textX,
16029
- textAlign: 'right'
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
16030
16040
  });
16031
- if (symbol) {
16032
- const symbolX = textX - textWidth - symbolPlaceWidth + maxSize / 2;
16033
- symbol.setAttributes({
16034
- x: symbolX
16035
- });
16036
- }
16037
16041
  }
16038
- if (textBaseline === 'middle') {
16039
- tagY -= tagHeight / 2;
16040
- if (symbol) {
16041
- symbol.setAttribute('y', 0);
16042
- }
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
16054
+ });
16043
16055
  }
16044
- else if (textBaseline === 'bottom') {
16045
- tagY -= tagHeight;
16046
- if (symbol) {
16047
- symbol.setAttribute('y', -textHeight / 2);
16048
- }
16049
- group.setAttribute('y', -parsedPadding[2]);
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
16065
+ });
16050
16066
  }
16051
- else if (textBaseline === 'top') {
16052
- group.setAttribute('y', parsedPadding[0]);
16053
- if (symbol) {
16054
- symbol.setAttribute('y', textHeight / 2);
16055
- }
16067
+ }
16068
+ if (textBaseline === 'middle') {
16069
+ tagY -= tagHeight / 2;
16070
+ if (symbol) {
16071
+ symbol.setAttribute('y', 0);
16072
+ }
16073
+ }
16074
+ else if (textBaseline === 'bottom') {
16075
+ tagY -= tagHeight;
16076
+ if (symbol) {
16077
+ symbol.setAttribute('y', -textHeight / 2);
16056
16078
  }
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);
16085
+ }
16086
+ }
16087
+ if (!isEmpty(state === null || state === void 0 ? void 0 : state.text)) {
16088
+ textShape.states = state.text;
16057
16089
  }
16058
16090
  const { visible: bgVisible } = panel, backgroundStyle = __rest(panel, ["visible"]);
16059
16091
  if (visible && isBoolean(bgVisible)) {
@@ -31439,6 +31471,6 @@ StoryLabelItem.defaultAttributes = {
31439
31471
  theme: 'default'
31440
31472
  };
31441
31473
 
31442
- const version = "0.22.3";
31474
+ const version = "0.22.5-alpha.1";
31443
31475
 
31444
31476
  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/brush/brush.js CHANGED
@@ -209,5 +209,4 @@ export class Brush extends AbstractComponent {
209
209
  }
210
210
  }
211
211
 
212
- Brush.defaultAttributes = DEFAULT_BRUSH_ATTRIBUTES;
213
- //# sourceMappingURL=brush.js.map
212
+ Brush.defaultAttributes = DEFAULT_BRUSH_ATTRIBUTES;
package/es/brush/type.js CHANGED
@@ -4,4 +4,5 @@ export var IOperateType;
4
4
  IOperateType.drawStart = "drawStart", IOperateType.drawEnd = "drawEnd", IOperateType.drawing = "drawing",
5
5
  IOperateType.moving = "moving", IOperateType.moveStart = "moveStart", IOperateType.moveEnd = "moveEnd",
6
6
  IOperateType.brushClear = "brushClear";
7
- }(IOperateType || (IOperateType = {}));
7
+ }(IOperateType || (IOperateType = {}));
8
+ //# sourceMappingURL=type.js.map
package/es/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const version = "0.22.3";
1
+ export declare const version = "0.22.5-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.3";
1
+ export const version = "0.22.5-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.3\";\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.5-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"]}
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 { isBoolean, isEmpty, isNil, isNumber, isObject, isValid, merge, normalizePadding } from "@visactor/vutils";
13
+ import { array, 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;
58
+ let textShape, textWidth, textHeight;
59
59
  tagWidth += symbolPlaceWidth, textX += symbolPlaceWidth;
60
60
  if (isRichText({
61
61
  text: text
@@ -68,8 +68,9 @@ export class Tag extends AbstractComponent {
68
68
  x: textX,
69
69
  y: 0
70
70
  });
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;
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();
73
74
  } else {
74
75
  const textAttrs = Object.assign(Object.assign({
75
76
  text: isObject(text) && "type" in text && "text" === text.type ? text.text : text,
@@ -79,62 +80,64 @@ export class Tag extends AbstractComponent {
79
80
  x: textX,
80
81
  y: 0
81
82
  });
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
- }
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
+ });
109
118
  }
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
- }
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
+ });
121
127
  }
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
- }
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
+ });
133
136
  }
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);
138
141
  const {visible: bgVisible} = panel, backgroundStyle = __rest(panel, [ "visible" ]);
139
142
  if (visible && isBoolean(bgVisible)) {
140
143
  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,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,M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,EAAE,CAAC;IACjC,CAAC;IACD,WAAW;;QACT,IAAI,CAAC,UAAU,CAAC,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC1D,IAAI,CAAC,WAAW,CAAC,MAAM,KAAI,MAAA,IAAI,CAAC,OAAO,0CAAE,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA,CAAC;QACrE,IAAI,CAAC,aAAa,CAAC,MAAM,KAAI,MAAA,IAAI,CAAC,OAAO,0CAAE,SAAS,CAAC,IAAI,CAAC,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;;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"]}
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,gBAAg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;QACnB,MAAA,IAAI,CAAC,OAAO,0CAAE,WAAW,EAAE,CAAC;QAC5B,MAAA,IAAI,CAAC,OAAO,0CAAE,WAAW,EAAE,CAAC;QAC5B,MAAA,IAAI,CAAC,UAAU,0CAAE,WAAW,EAAE,CAAC;IACjC,CAAC;IACD,WAAW;;QACT,IAAI,CAAC,UAAU,CAAC,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC1D,IAAI,CAAC,WAAW,CAAC,MAAM,KAAI,MAAA,IAAI,CAAC,OAAO,0CAAE,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA,CAAC;QACrE,IAAI,CAAC,aAAa,CAAC,MAAM,KAAI,MAAA,IAAI,CAAC,OAAO,0CAAE,SAAS,CAAC,IAAI,CAAC,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;;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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visactor/vrender-components",
3
- "version": "0.22.3",
3
+ "version": "0.22.5-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.3",
18
- "@visactor/vrender-kits": "0.22.3"
17
+ "@visactor/vrender-core": "0.22.5-alpha.1",
18
+ "@visactor/vrender-kits": "0.22.5-alpha.1"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@rushstack/eslint-patch": "~1.1.4",
@@ -29,9 +29,9 @@
29
29
  "vite": "3.2.6",
30
30
  "typescript": "4.9.5",
31
31
  "cross-env": "^7.0.3",
32
- "@internal/bundler": "0.0.1",
33
32
  "@internal/eslint-config": "0.0.1",
34
- "@internal/ts-config": "0.0.1"
33
+ "@internal/ts-config": "0.0.1",
34
+ "@internal/bundler": "0.0.1"
35
35
  },
36
36
  "keywords": [
37
37
  "VisActor",