@visactor/vchart 1.13.23-alpha.0 → 1.13.23

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.
@@ -56,37 +56,41 @@ class Title extends base_component_1.BaseComponent {
56
56
  };
57
57
  }
58
58
  _getTitleAttrs() {
59
- var _a, _b, _c, _d, _e, _f, _g, _h;
59
+ var _a, _b, _c, _d, _e, _f;
60
60
  if (!1 === this._spec.visible) return {
61
61
  visible: !1
62
62
  };
63
63
  const layoutRect = this.getLayoutRect(), titleWidth = (0, space_1.calcLayoutNumber)(this._spec.width, layoutRect.width, null, layoutRect.width), titleMaxWidth = (0,
64
- space_1.calcLayoutNumber)(this._spec.maxWidth, layoutRect.width, null, layoutRect.width), maxWidth = Math.max(Math.min(titleWidth, titleMaxWidth, layoutRect.width), 0), attrs = Object.assign(Object.assign({}, (0,
64
+ space_1.calcLayoutNumber)(this._spec.maxWidth, layoutRect.width, null, layoutRect.width), maxWidth = Math.max(Math.min(titleWidth, titleMaxWidth, layoutRect.width), 0), hasText = (0,
65
+ vutils_1.isValid)(this._spec.text) && "" !== this._spec.text, hasSubtext = (0, vutils_1.isValid)(this._spec.subtext) && "" !== this._spec.subtext, attrs = Object.assign(Object.assign({}, (0,
65
66
  vutils_1.pickWithout)(this._spec, [ "padding" ])), {
66
67
  textType: null !== (_a = this._spec.textType) && void 0 !== _a ? _a : "text",
67
- text: null !== (_b = this._spec.text) && void 0 !== _b ? _b : "",
68
- subtextType: null !== (_c = this._spec.subtextType) && void 0 !== _c ? _c : "text",
69
- subtext: null !== (_d = this._spec.subtext) && void 0 !== _d ? _d : "",
70
- x: null !== (_e = this._spec.x) && void 0 !== _e ? _e : 0,
71
- y: null !== (_f = this._spec.y) && void 0 !== _f ? _f : 0,
68
+ text: hasText ? this._spec.text : void 0,
69
+ subtextType: null !== (_b = this._spec.subtextType) && void 0 !== _b ? _b : "text",
70
+ subtext: hasSubtext ? this._spec.subtext : void 0,
71
+ x: null !== (_c = this._spec.x) && void 0 !== _c ? _c : 0,
72
+ y: null !== (_d = this._spec.y) && void 0 !== _d ? _d : 0,
72
73
  height: this._spec.height,
73
74
  minWidth: this._spec.minWidth,
74
75
  maxWidth: maxWidth,
75
76
  minHeight: this._spec.minHeight,
76
77
  maxHeight: this._spec.maxHeight,
77
78
  padding: this._spec.innerPadding,
78
- align: null !== (_g = this._spec.align) && void 0 !== _g ? _g : "left",
79
- verticalAlign: null !== (_h = this._spec.verticalAlign) && void 0 !== _h ? _h : "top",
79
+ align: null !== (_e = this._spec.align) && void 0 !== _e ? _e : "left",
80
+ verticalAlign: null !== (_f = this._spec.verticalAlign) && void 0 !== _f ? _f : "top",
80
81
  textStyle: Object.assign({
81
- width: maxWidth,
82
82
  maxLineWidth: maxWidth
83
83
  }, this._spec.textStyle),
84
84
  subtextStyle: Object.assign({
85
85
  maxLineWidth: maxWidth
86
86
  }, this._spec.subtextStyle)
87
87
  });
88
- return (0, vutils_1.isValid)(this._spec.width) && (attrs.textStyle.width = Math.max(titleWidth, layoutRect.width),
89
- attrs.subtextStyle.width = attrs.textStyle.width), attrs;
88
+ if (hasText && (attrs.textStyle.width = maxWidth), hasSubtext && (attrs.subtextStyle.width = maxWidth),
89
+ (0, vutils_1.isValid)(this._spec.width)) {
90
+ const clampedWidth = Math.max(Math.min(titleWidth, layoutRect.width), 0);
91
+ hasText ? attrs.textStyle.width = clampedWidth : delete attrs.textStyle.width, hasSubtext && (attrs.subtextStyle.width = clampedWidth);
92
+ }
93
+ return attrs;
90
94
  }
91
95
  _createOrUpdateTitleComponent(attrs) {
92
96
  if (this._titleComponent) (0, vutils_1.isEqual)(attrs, this._cacheAttrs) || this._titleComponent.setAttributes(attrs); else {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/component/title/title.ts"],"names":[],"mappings":";;;AAAA,kDAAkE;AAClE,gDAA6C;AAI7C,4CAAmE;AACnE,2DAAuD;AAGvD,4CAAsD;AAEtD,qEAAwE;AAMxE,6CAAgF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AAlLQ,UAAI,GAAG,wBAAiB,CAAC,KAAK,CAAC;AAE/B,aAAO,GAAG,wBAAiB,CAAC,KAAK,CAAC;AAkLpC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,iBAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC/C,CAAC,CAAC;AAFW,QAAA,aAAa,iBAExB","file":"title.js","sourcesContent":["import { LayoutLevel, LayoutZIndex } from '../../constant/layout';\nimport { Factory } from '../../core/factory';\nimport type { IModelSpecInfo } from '../../model/interface';\nimport type { IRegion } from '../../region/interface';\nimport type { IPoint, IOrientType, ILayoutType, ILayoutRect } from '../../typings';\nimport { calcLayoutNumber, isValidOrient } from '../../util/space';\nimport { BaseComponent } from '../base/base-component';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IComponentOption } from '../interface';\nimport { ComponentTypeEnum } from '../interface/type';\nimport type { ITitle, ITitleSpec } from './interface';\nimport { Title as TitleComponents } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport type { TitleAttrs } from '@visactor/vrender-components';\nimport type { IGraphic, IGroup, INode } from '@visactor/vrender-core';\nimport type { Maybe } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { isEqual, isValidNumber, pickWithout, isValid } from '@visactor/vutils';\nimport { getSpecInfo } from '../util';\n\nexport class Title<T extends ITitleSpec = ITitleSpec> extends BaseComponent<T> implements ITitle {\n static type = ComponentTypeEnum.title;\n type = ComponentTypeEnum.title;\n static specKey = ComponentTypeEnum.title;\n specKey: string = ComponentTypeEnum.title;\n\n layoutType: ILayoutType = 'normal';\n layoutZIndex: number = LayoutZIndex.Title;\n layoutLevel: number = LayoutLevel.Title;\n\n protected _orient: IOrientType = 'top';\n\n private _titleComponent: TitleComponents;\n private _cacheAttrs: TitleAttrs;\n\n get orient() {\n return this._orient;\n }\n\n constructor(spec: T, options: IComponentOption) {\n super(spec, options);\n this._orient = isValidOrient(spec.orient) ? spec.orient : 'top';\n }\n\n initLayout(): void {\n super.initLayout();\n this._layout && (this._layout.layoutOrient = this._orient);\n }\n\n static getSpecInfo(chartSpec: any): Maybe<IModelSpecInfo[]> {\n return getSpecInfo<ITitleSpec>(chartSpec, this.specKey, ComponentTypeEnum.title, (s: ITitleSpec) => {\n return s.visible !== false;\n });\n }\n\n onRender(ctx: any): void {\n // do nothing\n }\n\n /**\n * updateSpec\n */\n _compareSpec(spec: T, prevSpec: T) {\n const result = super._compareSpec(spec, prevSpec);\n\n if (prevSpec?.orient !== spec?.orient || (prevSpec as any)?.visible !== (spec as any).visible) {\n // title 组件切换visible会影响布局,所以需要重新remake\n result.reMake = true;\n }\n\n result.change = true;\n result.reRender = true;\n return result;\n }\n\n // region\n changeRegions(regions: IRegion[]): void {\n // do nothing\n }\n\n update(ctx: IComponentOption) {\n // TODO\n }\n\n resize(ctx: IComponentOption) {\n // TODO\n }\n\n afterSetLayoutStartPoint(pos: IPoint): void {\n if (isValidNumber(pos.x)) {\n this._titleComponent && this._titleComponent.setAttribute('x', pos.x);\n }\n if (isValidNumber(pos.y)) {\n this._titleComponent && this._titleComponent.setAttribute('y', pos.y);\n }\n super.afterSetLayoutStartPoint(pos);\n }\n\n getBoundsInRect(rect: ILayoutRect) {\n let result: Partial<ILayoutRect> = {};\n this.setLayoutRect(rect);\n\n const attrs = this._getTitleAttrs();\n this._createOrUpdateTitleComponent(attrs);\n\n result = this._getTitleLayoutRect();\n const { x, y } = this.getLayoutStartPoint();\n return {\n x1: x,\n y1: y,\n x2: x + result.width,\n y2: y + result.height\n };\n }\n\n private _getTitleLayoutRect() {\n const titleBounds = this._titleComponent.AABBBounds;\n const width = this._spec.width ? this._spec.width : isValidNumber(titleBounds.width()) ? titleBounds.width() : 0;\n const height = this._spec.height\n ? this._spec.height\n : isValidNumber(titleBounds.height())\n ? titleBounds.height()\n : 0;\n return {\n width,\n height\n };\n }\n\n private _getTitleAttrs() {\n // 当 width 小于 0 时,设置为 0,负数场景容易引起不可预知的问题\n if (this._spec.visible === false) {\n return { visible: false };\n }\n const layoutRect = this.getLayoutRect();\n const titleWidth = calcLayoutNumber(this._spec.width, layoutRect.width, null, layoutRect.width);\n const titleMaxWidth = calcLayoutNumber(this._spec.maxWidth, layoutRect.width, null, layoutRect.width);\n const maxWidth = Math.max(Math.min(titleWidth, titleMaxWidth, layoutRect.width), 0);\n\n const attrs = {\n ...(pickWithout(this._spec, ['padding']) as any),\n textType: this._spec.textType ?? 'text',\n text: this._spec.text ?? '',\n subtextType: this._spec.subtextType ?? 'text',\n subtext: this._spec.subtext ?? '',\n x: this._spec.x ?? 0,\n y: this._spec.y ?? 0,\n height: this._spec.height,\n minWidth: this._spec.minWidth,\n maxWidth,\n minHeight: this._spec.minHeight,\n maxHeight: this._spec.maxHeight,\n padding: this._spec.innerPadding,\n align: this._spec.align ?? 'left',\n verticalAlign: this._spec.verticalAlign ?? 'top',\n textStyle: {\n width: maxWidth,\n maxLineWidth: maxWidth,\n ...this._spec.textStyle\n },\n subtextStyle: {\n maxLineWidth: maxWidth,\n ...this._spec.subtextStyle\n }\n } as TitleAttrs;\n\n if (isValid(this._spec.width)) {\n attrs.textStyle.width = Math.max(titleWidth, layoutRect.width);\n attrs.subtextStyle.width = attrs.textStyle.width;\n }\n return attrs;\n }\n\n private _createOrUpdateTitleComponent(attrs: TitleAttrs): TitleComponents {\n if (this._titleComponent) {\n if (!isEqual(attrs, this._cacheAttrs)) {\n this._titleComponent.setAttributes(attrs);\n }\n } else {\n const container = this.getContainer();\n const title = new TitleComponents(attrs);\n title.name = 'title';\n container.add(title as unknown as INode);\n this._titleComponent = title;\n // 代理 title 组件上的事件\n title.on('*', (event: any, type: string) => this._delegateEvent(title as unknown as IGraphic, event, type));\n }\n this._cacheAttrs = attrs;\n return this._titleComponent;\n }\n\n protected _getNeedClearVRenderComponents(): IGraphic[] {\n return [this._titleComponent] as unknown as IGroup[];\n }\n\n clear(): void {\n super.clear();\n this._cacheAttrs = null;\n }\n}\n\nexport const registerTitle = () => {\n Factory.registerComponent(Title.type, Title);\n};\n"]}
1
+ {"version":3,"sources":["../src/component/title/title.ts"],"names":[],"mappings":";;;AAAA,kDAAkE;AAClE,gDAA6C;AAI7C,4CAAmE;AACnE,2DAAuD;AAGvD,4CAAsD;AAEtD,qEAAwE;AAMxE,6CAAgF;AAChF,kCAAsC;AAEtC,MAAa,KAAyC,SAAQ,8BAAgB;IAe5E,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,YAAY,IAAO,EAAE,OAAyB;QAC5C,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAlBvB,SAAI,GAAG,wBAAiB,CAAC,KAAK,CAAC;QAE/B,YAAO,GAAW,wBAAiB,CAAC,KAAK,CAAC;QAE1C,eAAU,GAAgB,QAAQ,CAAC;QACnC,iBAAY,GAAW,qBAAY,CAAC,KAAK,CAAC;QAC1C,gBAAW,GAAW,oBAAW,CAAC,KAAK,CAAC;QAE9B,YAAO,GAAgB,KAAK,CAAC;QAWrC,IAAI,CAAC,OAAO,GAAG,IAAA,qBAAa,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;IAClE,CAAC;IAED,UAAU;QACR,KAAK,CAAC,UAAU,EAAE,CAAC;QACnB,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;IAC7D,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,SAAc;QAC/B,OAAO,IAAA,kBAAW,EAAa,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE,wBAAiB,CAAC,KAAK,EAAE,CAAC,CAAa,EAAE,EAAE;YACjG,OAAO,CAAC,CAAC,OAAO,KAAK,KAAK,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC;IAED,QAAQ,CAAC,GAAQ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EAAE;YACxB,IAAI,CAAC,IAAA,gBAAO,EAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,EAAE;gBACrC,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;aAC3C;SACF;aAAM;YACL,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YACtC,MAAM,KAAK,GAAG,IAAI,0BAAe,CAAC,KAAK,CAAC,CAAC;YACzC,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC;YACrB,SAAS,CAAC,GAAG,CAAC,KAAyB,CAAC,CAAC;YACzC,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;YAE7B,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,KAAU,EAAE,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,KAA4B,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;SAC7G;QACD,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAES,8BAA8B;QACtC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAwB,CAAC;IACvD,CAAC;IAED,KAAK;QACH,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;;AAtMH,sBAuMC;AAtMQ,UAAI,GAAG,wBAAiB,CAAC,KAAK,CAAC;AAE/B,aAAO,GAAG,wBAAiB,CAAC,KAAK,CAAC;AAsMpC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,iBAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC/C,CAAC,CAAC;AAFW,QAAA,aAAa,iBAExB","file":"title.js","sourcesContent":["import { LayoutLevel, LayoutZIndex } from '../../constant/layout';\nimport { Factory } from '../../core/factory';\nimport type { IModelSpecInfo } from '../../model/interface';\nimport type { IRegion } from '../../region/interface';\nimport type { IPoint, IOrientType, ILayoutType, ILayoutRect } from '../../typings';\nimport { calcLayoutNumber, isValidOrient } from '../../util/space';\nimport { BaseComponent } from '../base/base-component';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IComponentOption } from '../interface';\nimport { ComponentTypeEnum } from '../interface/type';\nimport type { ITitle, ITitleSpec } from './interface';\nimport { Title as TitleComponents } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport type { TitleAttrs } from '@visactor/vrender-components';\nimport type { IGraphic, IGroup, INode } from '@visactor/vrender-core';\nimport type { Maybe } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { isEqual, isValidNumber, pickWithout, isValid } from '@visactor/vutils';\nimport { getSpecInfo } from '../util';\n\nexport class Title<T extends ITitleSpec = ITitleSpec> extends BaseComponent<T> implements ITitle {\n static type = ComponentTypeEnum.title;\n type = ComponentTypeEnum.title;\n static specKey = ComponentTypeEnum.title;\n specKey: string = ComponentTypeEnum.title;\n\n layoutType: ILayoutType = 'normal';\n layoutZIndex: number = LayoutZIndex.Title;\n layoutLevel: number = LayoutLevel.Title;\n\n protected _orient: IOrientType = 'top';\n\n private _titleComponent: TitleComponents;\n private _cacheAttrs: TitleAttrs;\n\n get orient() {\n return this._orient;\n }\n\n constructor(spec: T, options: IComponentOption) {\n super(spec, options);\n this._orient = isValidOrient(spec.orient) ? spec.orient : 'top';\n }\n\n initLayout(): void {\n super.initLayout();\n this._layout && (this._layout.layoutOrient = this._orient);\n }\n\n static getSpecInfo(chartSpec: any): Maybe<IModelSpecInfo[]> {\n return getSpecInfo<ITitleSpec>(chartSpec, this.specKey, ComponentTypeEnum.title, (s: ITitleSpec) => {\n return s.visible !== false;\n });\n }\n\n onRender(ctx: any): void {\n // do nothing\n }\n\n /**\n * updateSpec\n */\n _compareSpec(spec: T, prevSpec: T) {\n const result = super._compareSpec(spec, prevSpec);\n\n if (prevSpec?.orient !== spec?.orient || (prevSpec as any)?.visible !== (spec as any).visible) {\n // title 组件切换visible会影响布局,所以需要重新remake\n result.reMake = true;\n }\n\n result.change = true;\n result.reRender = true;\n return result;\n }\n\n // region\n changeRegions(regions: IRegion[]): void {\n // do nothing\n }\n\n update(ctx: IComponentOption) {\n // TODO\n }\n\n resize(ctx: IComponentOption) {\n // TODO\n }\n\n afterSetLayoutStartPoint(pos: IPoint): void {\n if (isValidNumber(pos.x)) {\n this._titleComponent && this._titleComponent.setAttribute('x', pos.x);\n }\n if (isValidNumber(pos.y)) {\n this._titleComponent && this._titleComponent.setAttribute('y', pos.y);\n }\n super.afterSetLayoutStartPoint(pos);\n }\n\n getBoundsInRect(rect: ILayoutRect) {\n let result: Partial<ILayoutRect> = {};\n this.setLayoutRect(rect);\n\n const attrs = this._getTitleAttrs();\n this._createOrUpdateTitleComponent(attrs);\n\n result = this._getTitleLayoutRect();\n const { x, y } = this.getLayoutStartPoint();\n return {\n x1: x,\n y1: y,\n x2: x + result.width,\n y2: y + result.height\n };\n }\n\n private _getTitleLayoutRect() {\n const titleBounds = this._titleComponent.AABBBounds;\n const width = this._spec.width ? this._spec.width : isValidNumber(titleBounds.width()) ? titleBounds.width() : 0;\n const height = this._spec.height\n ? this._spec.height\n : isValidNumber(titleBounds.height())\n ? titleBounds.height()\n : 0;\n return {\n width,\n height\n };\n }\n\n private _getTitleAttrs() {\n /**\n * 生成标题组件的渲染属性,统一计算宽高与对齐参数,\n * 并在仅副标题场景下避免主标题宽度影响副标题布局。\n */\n if (this._spec.visible === false) {\n return { visible: false };\n }\n const layoutRect = this.getLayoutRect();\n const titleWidth = calcLayoutNumber(this._spec.width, layoutRect.width, null, layoutRect.width);\n const titleMaxWidth = calcLayoutNumber(this._spec.maxWidth, layoutRect.width, null, layoutRect.width);\n const maxWidth = Math.max(Math.min(titleWidth, titleMaxWidth, layoutRect.width), 0);\n const hasText = isValid(this._spec.text) && this._spec.text !== '';\n const hasSubtext = isValid(this._spec.subtext) && this._spec.subtext !== '';\n\n const attrs = {\n ...(pickWithout(this._spec, ['padding']) as any),\n textType: this._spec.textType ?? 'text',\n text: hasText ? this._spec.text : undefined,\n subtextType: this._spec.subtextType ?? 'text',\n subtext: hasSubtext ? this._spec.subtext : undefined,\n x: this._spec.x ?? 0,\n y: this._spec.y ?? 0,\n height: this._spec.height,\n minWidth: this._spec.minWidth,\n maxWidth,\n minHeight: this._spec.minHeight,\n maxHeight: this._spec.maxHeight,\n padding: this._spec.innerPadding,\n align: this._spec.align ?? 'left',\n verticalAlign: this._spec.verticalAlign ?? 'top',\n textStyle: {\n maxLineWidth: maxWidth,\n ...this._spec.textStyle\n },\n subtextStyle: {\n maxLineWidth: maxWidth,\n ...this._spec.subtextStyle\n }\n } as TitleAttrs;\n\n // 仅在对应文本存在时设置 width,避免空主标题影响副标题的对齐与宽度计算\n if (hasText) {\n (attrs.textStyle as any).width = maxWidth;\n }\n if (hasSubtext) {\n (attrs.subtextStyle as any).width = maxWidth;\n }\n\n if (isValid(this._spec.width)) {\n const clampedWidth = Math.max(Math.min(titleWidth, layoutRect.width), 0);\n if (hasText) {\n (attrs.textStyle as any).width = clampedWidth;\n } else {\n // 主标题不存在时,不设置其 width\n delete (attrs.textStyle as any).width;\n }\n if (hasSubtext) {\n (attrs.subtextStyle as any).width = clampedWidth;\n }\n }\n return attrs;\n }\n\n private _createOrUpdateTitleComponent(attrs: TitleAttrs): TitleComponents {\n if (this._titleComponent) {\n if (!isEqual(attrs, this._cacheAttrs)) {\n this._titleComponent.setAttributes(attrs);\n }\n } else {\n const container = this.getContainer();\n const title = new TitleComponents(attrs);\n title.name = 'title';\n container.add(title as unknown as INode);\n this._titleComponent = title;\n // 代理 title 组件上的事件\n title.on('*', (event: any, type: string) => this._delegateEvent(title as unknown as IGraphic, event, type));\n }\n this._cacheAttrs = attrs;\n return this._titleComponent;\n }\n\n protected _getNeedClearVRenderComponents(): IGraphic[] {\n return [this._titleComponent] as unknown as IGroup[];\n }\n\n clear(): void {\n super.clear();\n this._cacheAttrs = null;\n }\n}\n\nexport const registerTitle = () => {\n Factory.registerComponent(Title.type, Title);\n};\n"]}
package/cjs/core/index.js CHANGED
@@ -99,4 +99,5 @@ Object.defineProperty(exports, "vglobal", {
99
99
  get: function() {
100
100
  return vrender_core_1.StreamLight;
101
101
  }
102
- });
102
+ });
103
+ //# sourceMappingURL=index.js.map
@@ -2,5 +2,4 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
- });
6
- //# sourceMappingURL=interface.js.map
5
+ });
@@ -51,4 +51,4 @@ class Bubble {
51
51
  }
52
52
 
53
53
  exports.Bubble = Bubble;
54
- //# sourceMappingURL=bubble.js.map
54
+ //# sourceMappingURL=bubble.js.map
@@ -31,4 +31,4 @@ function getDefaultInteractionConfigByMode(mode) {
31
31
  }
32
32
 
33
33
  exports.getDefaultInteractionConfigByMode = getDefaultInteractionConfigByMode;
34
- //# sourceMappingURL=config.js.map
34
+ //# sourceMappingURL=config.js.map
@@ -64,35 +64,38 @@ export class Title extends BaseComponent {
64
64
  };
65
65
  }
66
66
  _getTitleAttrs() {
67
- var _a, _b, _c, _d, _e, _f, _g, _h;
67
+ var _a, _b, _c, _d, _e, _f;
68
68
  if (!1 === this._spec.visible) return {
69
69
  visible: !1
70
70
  };
71
- const layoutRect = this.getLayoutRect(), titleWidth = calcLayoutNumber(this._spec.width, layoutRect.width, null, layoutRect.width), titleMaxWidth = calcLayoutNumber(this._spec.maxWidth, layoutRect.width, null, layoutRect.width), maxWidth = Math.max(Math.min(titleWidth, titleMaxWidth, layoutRect.width), 0), attrs = Object.assign(Object.assign({}, pickWithout(this._spec, [ "padding" ])), {
71
+ const layoutRect = this.getLayoutRect(), titleWidth = calcLayoutNumber(this._spec.width, layoutRect.width, null, layoutRect.width), titleMaxWidth = calcLayoutNumber(this._spec.maxWidth, layoutRect.width, null, layoutRect.width), maxWidth = Math.max(Math.min(titleWidth, titleMaxWidth, layoutRect.width), 0), hasText = isValid(this._spec.text) && "" !== this._spec.text, hasSubtext = isValid(this._spec.subtext) && "" !== this._spec.subtext, attrs = Object.assign(Object.assign({}, pickWithout(this._spec, [ "padding" ])), {
72
72
  textType: null !== (_a = this._spec.textType) && void 0 !== _a ? _a : "text",
73
- text: null !== (_b = this._spec.text) && void 0 !== _b ? _b : "",
74
- subtextType: null !== (_c = this._spec.subtextType) && void 0 !== _c ? _c : "text",
75
- subtext: null !== (_d = this._spec.subtext) && void 0 !== _d ? _d : "",
76
- x: null !== (_e = this._spec.x) && void 0 !== _e ? _e : 0,
77
- y: null !== (_f = this._spec.y) && void 0 !== _f ? _f : 0,
73
+ text: hasText ? this._spec.text : void 0,
74
+ subtextType: null !== (_b = this._spec.subtextType) && void 0 !== _b ? _b : "text",
75
+ subtext: hasSubtext ? this._spec.subtext : void 0,
76
+ x: null !== (_c = this._spec.x) && void 0 !== _c ? _c : 0,
77
+ y: null !== (_d = this._spec.y) && void 0 !== _d ? _d : 0,
78
78
  height: this._spec.height,
79
79
  minWidth: this._spec.minWidth,
80
80
  maxWidth: maxWidth,
81
81
  minHeight: this._spec.minHeight,
82
82
  maxHeight: this._spec.maxHeight,
83
83
  padding: this._spec.innerPadding,
84
- align: null !== (_g = this._spec.align) && void 0 !== _g ? _g : "left",
85
- verticalAlign: null !== (_h = this._spec.verticalAlign) && void 0 !== _h ? _h : "top",
84
+ align: null !== (_e = this._spec.align) && void 0 !== _e ? _e : "left",
85
+ verticalAlign: null !== (_f = this._spec.verticalAlign) && void 0 !== _f ? _f : "top",
86
86
  textStyle: Object.assign({
87
- width: maxWidth,
88
87
  maxLineWidth: maxWidth
89
88
  }, this._spec.textStyle),
90
89
  subtextStyle: Object.assign({
91
90
  maxLineWidth: maxWidth
92
91
  }, this._spec.subtextStyle)
93
92
  });
94
- return isValid(this._spec.width) && (attrs.textStyle.width = Math.max(titleWidth, layoutRect.width),
95
- attrs.subtextStyle.width = attrs.textStyle.width), attrs;
93
+ if (hasText && (attrs.textStyle.width = maxWidth), hasSubtext && (attrs.subtextStyle.width = maxWidth),
94
+ isValid(this._spec.width)) {
95
+ const clampedWidth = Math.max(Math.min(titleWidth, layoutRect.width), 0);
96
+ hasText ? attrs.textStyle.width = clampedWidth : delete attrs.textStyle.width, hasSubtext && (attrs.subtextStyle.width = clampedWidth);
97
+ }
98
+ return attrs;
96
99
  }
97
100
  _createOrUpdateTitleComponent(attrs) {
98
101
  if (this._titleComponent) isEqual(attrs, this._cacheAttrs) || this._titleComponent.setAttributes(attrs); else {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/component/title/title.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAI7C,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAGvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,KAAK,IAAI,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAMxE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,OAAO,KAAyC,SAAQ,aAAgB;IAe5E,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,YAAY,IAAO,EAAE,OAAyB;QAC5C,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAlBvB,SAAI,GAAG,iBAAiB,CAAC,KAAK,CAAC;QAE/B,YAAO,GAAW,iBAAiB,CAAC,KAAK,CAAC;QAE1C,eAAU,GAAgB,QAAQ,CAAC;QACnC,iBAAY,GAAW,YAAY,CAAC,KAAK,CAAC;QAC1C,gBAAW,GAAW,WAAW,CAAC,KAAK,CAAC;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Aa,CAAC,KAAK,CAAC,CAAC;aAC3C;SACF;aAAM;YACL,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YACtC,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;YACzC,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC;YACrB,SAAS,CAAC,GAAG,CAAC,KAAyB,CAAC,CAAC;YACzC,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;YAE7B,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,KAAU,EAAE,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,KAA4B,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;SAC7G;QACD,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAES,8BAA8B;QACtC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAwB,CAAC;IACvD,CAAC;IAED,KAAK;QACH,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;;AAjLM,UAAI,GAAG,iBAAiB,CAAC,KAAK,CAAC;AAE/B,aAAO,GAAG,iBAAiB,CAAC,KAAK,CAAC;AAkL3C,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC/C,CAAC,CAAC","file":"title.js","sourcesContent":["import { LayoutLevel, LayoutZIndex } from '../../constant/layout';\nimport { Factory } from '../../core/factory';\nimport type { IModelSpecInfo } from '../../model/interface';\nimport type { IRegion } from '../../region/interface';\nimport type { IPoint, IOrientType, ILayoutType, ILayoutRect } from '../../typings';\nimport { calcLayoutNumber, isValidOrient } from '../../util/space';\nimport { BaseComponent } from '../base/base-component';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IComponentOption } from '../interface';\nimport { ComponentTypeEnum } from '../interface/type';\nimport type { ITitle, ITitleSpec } from './interface';\nimport { Title as TitleComponents } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport type { TitleAttrs } from '@visactor/vrender-components';\nimport type { IGraphic, IGroup, INode } from '@visactor/vrender-core';\nimport type { Maybe } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { isEqual, isValidNumber, pickWithout, isValid } from '@visactor/vutils';\nimport { getSpecInfo } from '../util';\n\nexport class Title<T extends ITitleSpec = ITitleSpec> extends BaseComponent<T> implements ITitle {\n static type = ComponentTypeEnum.title;\n type = ComponentTypeEnum.title;\n static specKey = ComponentTypeEnum.title;\n specKey: string = ComponentTypeEnum.title;\n\n layoutType: ILayoutType = 'normal';\n layoutZIndex: number = LayoutZIndex.Title;\n layoutLevel: number = LayoutLevel.Title;\n\n protected _orient: IOrientType = 'top';\n\n private _titleComponent: TitleComponents;\n private _cacheAttrs: TitleAttrs;\n\n get orient() {\n return this._orient;\n }\n\n constructor(spec: T, options: IComponentOption) {\n super(spec, options);\n this._orient = isValidOrient(spec.orient) ? spec.orient : 'top';\n }\n\n initLayout(): void {\n super.initLayout();\n this._layout && (this._layout.layoutOrient = this._orient);\n }\n\n static getSpecInfo(chartSpec: any): Maybe<IModelSpecInfo[]> {\n return getSpecInfo<ITitleSpec>(chartSpec, this.specKey, ComponentTypeEnum.title, (s: ITitleSpec) => {\n return s.visible !== false;\n });\n }\n\n onRender(ctx: any): void {\n // do nothing\n }\n\n /**\n * updateSpec\n */\n _compareSpec(spec: T, prevSpec: T) {\n const result = super._compareSpec(spec, prevSpec);\n\n if (prevSpec?.orient !== spec?.orient || (prevSpec as any)?.visible !== (spec as any).visible) {\n // title 组件切换visible会影响布局,所以需要重新remake\n result.reMake = true;\n }\n\n result.change = true;\n result.reRender = true;\n return result;\n }\n\n // region\n changeRegions(regions: IRegion[]): void {\n // do nothing\n }\n\n update(ctx: IComponentOption) {\n // TODO\n }\n\n resize(ctx: IComponentOption) {\n // TODO\n }\n\n afterSetLayoutStartPoint(pos: IPoint): void {\n if (isValidNumber(pos.x)) {\n this._titleComponent && this._titleComponent.setAttribute('x', pos.x);\n }\n if (isValidNumber(pos.y)) {\n this._titleComponent && this._titleComponent.setAttribute('y', pos.y);\n }\n super.afterSetLayoutStartPoint(pos);\n }\n\n getBoundsInRect(rect: ILayoutRect) {\n let result: Partial<ILayoutRect> = {};\n this.setLayoutRect(rect);\n\n const attrs = this._getTitleAttrs();\n this._createOrUpdateTitleComponent(attrs);\n\n result = this._getTitleLayoutRect();\n const { x, y } = this.getLayoutStartPoint();\n return {\n x1: x,\n y1: y,\n x2: x + result.width,\n y2: y + result.height\n };\n }\n\n private _getTitleLayoutRect() {\n const titleBounds = this._titleComponent.AABBBounds;\n const width = this._spec.width ? this._spec.width : isValidNumber(titleBounds.width()) ? titleBounds.width() : 0;\n const height = this._spec.height\n ? this._spec.height\n : isValidNumber(titleBounds.height())\n ? titleBounds.height()\n : 0;\n return {\n width,\n height\n };\n }\n\n private _getTitleAttrs() {\n // 当 width 小于 0 时,设置为 0,负数场景容易引起不可预知的问题\n if (this._spec.visible === false) {\n return { visible: false };\n }\n const layoutRect = this.getLayoutRect();\n const titleWidth = calcLayoutNumber(this._spec.width, layoutRect.width, null, layoutRect.width);\n const titleMaxWidth = calcLayoutNumber(this._spec.maxWidth, layoutRect.width, null, layoutRect.width);\n const maxWidth = Math.max(Math.min(titleWidth, titleMaxWidth, layoutRect.width), 0);\n\n const attrs = {\n ...(pickWithout(this._spec, ['padding']) as any),\n textType: this._spec.textType ?? 'text',\n text: this._spec.text ?? '',\n subtextType: this._spec.subtextType ?? 'text',\n subtext: this._spec.subtext ?? '',\n x: this._spec.x ?? 0,\n y: this._spec.y ?? 0,\n height: this._spec.height,\n minWidth: this._spec.minWidth,\n maxWidth,\n minHeight: this._spec.minHeight,\n maxHeight: this._spec.maxHeight,\n padding: this._spec.innerPadding,\n align: this._spec.align ?? 'left',\n verticalAlign: this._spec.verticalAlign ?? 'top',\n textStyle: {\n width: maxWidth,\n maxLineWidth: maxWidth,\n ...this._spec.textStyle\n },\n subtextStyle: {\n maxLineWidth: maxWidth,\n ...this._spec.subtextStyle\n }\n } as TitleAttrs;\n\n if (isValid(this._spec.width)) {\n attrs.textStyle.width = Math.max(titleWidth, layoutRect.width);\n attrs.subtextStyle.width = attrs.textStyle.width;\n }\n return attrs;\n }\n\n private _createOrUpdateTitleComponent(attrs: TitleAttrs): TitleComponents {\n if (this._titleComponent) {\n if (!isEqual(attrs, this._cacheAttrs)) {\n this._titleComponent.setAttributes(attrs);\n }\n } else {\n const container = this.getContainer();\n const title = new TitleComponents(attrs);\n title.name = 'title';\n container.add(title as unknown as INode);\n this._titleComponent = title;\n // 代理 title 组件上的事件\n title.on('*', (event: any, type: string) => this._delegateEvent(title as unknown as IGraphic, event, type));\n }\n this._cacheAttrs = attrs;\n return this._titleComponent;\n }\n\n protected _getNeedClearVRenderComponents(): IGraphic[] {\n return [this._titleComponent] as unknown as IGroup[];\n }\n\n clear(): void {\n super.clear();\n this._cacheAttrs = null;\n }\n}\n\nexport const registerTitle = () => {\n Factory.registerComponent(Title.type, Title);\n};\n"]}
1
+ {"version":3,"sources":["../src/component/title/title.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAI7C,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAGvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,KAAK,IAAI,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAMxE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,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e,CAAC,KAAK,CAAC,CAAC;YACzC,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC;YACrB,SAAS,CAAC,GAAG,CAAC,KAAyB,CAAC,CAAC;YACzC,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;YAE7B,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,KAAU,EAAE,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,KAA4B,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;SAC7G;QACD,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAES,8BAA8B;QACtC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAwB,CAAC;IACvD,CAAC;IAED,KAAK;QACH,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;;AArMM,UAAI,GAAG,iBAAiB,CAAC,KAAK,CAAC;AAE/B,aAAO,GAAG,iBAAiB,CAAC,KAAK,CAAC;AAsM3C,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC/C,CAAC,CAAC","file":"title.js","sourcesContent":["import { LayoutLevel, LayoutZIndex } from '../../constant/layout';\nimport { Factory } from '../../core/factory';\nimport type { IModelSpecInfo } from '../../model/interface';\nimport type { IRegion } from '../../region/interface';\nimport type { IPoint, IOrientType, ILayoutType, ILayoutRect } from '../../typings';\nimport { calcLayoutNumber, isValidOrient } from '../../util/space';\nimport { BaseComponent } from '../base/base-component';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IComponentOption } from '../interface';\nimport { ComponentTypeEnum } from '../interface/type';\nimport type { ITitle, ITitleSpec } from './interface';\nimport { Title as TitleComponents } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport type { TitleAttrs } from '@visactor/vrender-components';\nimport type { IGraphic, IGroup, INode } from '@visactor/vrender-core';\nimport type { Maybe } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { isEqual, isValidNumber, pickWithout, isValid } from '@visactor/vutils';\nimport { getSpecInfo } from '../util';\n\nexport class Title<T extends ITitleSpec = ITitleSpec> extends BaseComponent<T> implements ITitle {\n static type = ComponentTypeEnum.title;\n type = ComponentTypeEnum.title;\n static specKey = ComponentTypeEnum.title;\n specKey: string = ComponentTypeEnum.title;\n\n layoutType: ILayoutType = 'normal';\n layoutZIndex: number = LayoutZIndex.Title;\n layoutLevel: number = LayoutLevel.Title;\n\n protected _orient: IOrientType = 'top';\n\n private _titleComponent: TitleComponents;\n private _cacheAttrs: TitleAttrs;\n\n get orient() {\n return this._orient;\n }\n\n constructor(spec: T, options: IComponentOption) {\n super(spec, options);\n this._orient = isValidOrient(spec.orient) ? spec.orient : 'top';\n }\n\n initLayout(): void {\n super.initLayout();\n this._layout && (this._layout.layoutOrient = this._orient);\n }\n\n static getSpecInfo(chartSpec: any): Maybe<IModelSpecInfo[]> {\n return getSpecInfo<ITitleSpec>(chartSpec, this.specKey, ComponentTypeEnum.title, (s: ITitleSpec) => {\n return s.visible !== false;\n });\n }\n\n onRender(ctx: any): void {\n // do nothing\n }\n\n /**\n * updateSpec\n */\n _compareSpec(spec: T, prevSpec: T) {\n const result = super._compareSpec(spec, prevSpec);\n\n if (prevSpec?.orient !== spec?.orient || (prevSpec as any)?.visible !== (spec as any).visible) {\n // title 组件切换visible会影响布局,所以需要重新remake\n result.reMake = true;\n }\n\n result.change = true;\n result.reRender = true;\n return result;\n }\n\n // region\n changeRegions(regions: IRegion[]): void {\n // do nothing\n }\n\n update(ctx: IComponentOption) {\n // TODO\n }\n\n resize(ctx: IComponentOption) {\n // TODO\n }\n\n afterSetLayoutStartPoint(pos: IPoint): void {\n if (isValidNumber(pos.x)) {\n this._titleComponent && this._titleComponent.setAttribute('x', pos.x);\n }\n if (isValidNumber(pos.y)) {\n this._titleComponent && this._titleComponent.setAttribute('y', pos.y);\n }\n super.afterSetLayoutStartPoint(pos);\n }\n\n getBoundsInRect(rect: ILayoutRect) {\n let result: Partial<ILayoutRect> = {};\n this.setLayoutRect(rect);\n\n const attrs = this._getTitleAttrs();\n this._createOrUpdateTitleComponent(attrs);\n\n result = this._getTitleLayoutRect();\n const { x, y } = this.getLayoutStartPoint();\n return {\n x1: x,\n y1: y,\n x2: x + result.width,\n y2: y + result.height\n };\n }\n\n private _getTitleLayoutRect() {\n const titleBounds = this._titleComponent.AABBBounds;\n const width = this._spec.width ? this._spec.width : isValidNumber(titleBounds.width()) ? titleBounds.width() : 0;\n const height = this._spec.height\n ? this._spec.height\n : isValidNumber(titleBounds.height())\n ? titleBounds.height()\n : 0;\n return {\n width,\n height\n };\n }\n\n private _getTitleAttrs() {\n /**\n * 生成标题组件的渲染属性,统一计算宽高与对齐参数,\n * 并在仅副标题场景下避免主标题宽度影响副标题布局。\n */\n if (this._spec.visible === false) {\n return { visible: false };\n }\n const layoutRect = this.getLayoutRect();\n const titleWidth = calcLayoutNumber(this._spec.width, layoutRect.width, null, layoutRect.width);\n const titleMaxWidth = calcLayoutNumber(this._spec.maxWidth, layoutRect.width, null, layoutRect.width);\n const maxWidth = Math.max(Math.min(titleWidth, titleMaxWidth, layoutRect.width), 0);\n const hasText = isValid(this._spec.text) && this._spec.text !== '';\n const hasSubtext = isValid(this._spec.subtext) && this._spec.subtext !== '';\n\n const attrs = {\n ...(pickWithout(this._spec, ['padding']) as any),\n textType: this._spec.textType ?? 'text',\n text: hasText ? this._spec.text : undefined,\n subtextType: this._spec.subtextType ?? 'text',\n subtext: hasSubtext ? this._spec.subtext : undefined,\n x: this._spec.x ?? 0,\n y: this._spec.y ?? 0,\n height: this._spec.height,\n minWidth: this._spec.minWidth,\n maxWidth,\n minHeight: this._spec.minHeight,\n maxHeight: this._spec.maxHeight,\n padding: this._spec.innerPadding,\n align: this._spec.align ?? 'left',\n verticalAlign: this._spec.verticalAlign ?? 'top',\n textStyle: {\n maxLineWidth: maxWidth,\n ...this._spec.textStyle\n },\n subtextStyle: {\n maxLineWidth: maxWidth,\n ...this._spec.subtextStyle\n }\n } as TitleAttrs;\n\n // 仅在对应文本存在时设置 width,避免空主标题影响副标题的对齐与宽度计算\n if (hasText) {\n (attrs.textStyle as any).width = maxWidth;\n }\n if (hasSubtext) {\n (attrs.subtextStyle as any).width = maxWidth;\n }\n\n if (isValid(this._spec.width)) {\n const clampedWidth = Math.max(Math.min(titleWidth, layoutRect.width), 0);\n if (hasText) {\n (attrs.textStyle as any).width = clampedWidth;\n } else {\n // 主标题不存在时,不设置其 width\n delete (attrs.textStyle as any).width;\n }\n if (hasSubtext) {\n (attrs.subtextStyle as any).width = clampedWidth;\n }\n }\n return attrs;\n }\n\n private _createOrUpdateTitleComponent(attrs: TitleAttrs): TitleComponents {\n if (this._titleComponent) {\n if (!isEqual(attrs, this._cacheAttrs)) {\n this._titleComponent.setAttributes(attrs);\n }\n } else {\n const container = this.getContainer();\n const title = new TitleComponents(attrs);\n title.name = 'title';\n container.add(title as unknown as INode);\n this._titleComponent = title;\n // 代理 title 组件上的事件\n title.on('*', (event: any, type: string) => this._delegateEvent(title as unknown as IGraphic, event, type));\n }\n this._cacheAttrs = attrs;\n return this._titleComponent;\n }\n\n protected _getNeedClearVRenderComponents(): IGraphic[] {\n return [this._titleComponent] as unknown as IGroup[];\n }\n\n clear(): void {\n super.clear();\n this._cacheAttrs = null;\n }\n}\n\nexport const registerTitle = () => {\n Factory.registerComponent(Title.type, Title);\n};\n"]}
package/esm/core/index.js CHANGED
@@ -26,4 +26,5 @@ export * from "../typings/tooltip";
26
26
 
27
27
  export * from "../theme/index";
28
28
 
29
- export { vglobal, createGroup, createRichText, createText, createArc, createArea, createRect, createLine, createSymbol, ManualTicker, StreamLight } from "@visactor/vrender-core";
29
+ export { vglobal, createGroup, createRichText, createText, createArc, createArea, createRect, createLine, createSymbol, ManualTicker, StreamLight } from "@visactor/vrender-core";
30
+ //# sourceMappingURL=index.js.map
@@ -1,2 +1 @@
1
- export { };
2
- //# sourceMappingURL=interface.js.map
1
+ export { };
@@ -43,4 +43,4 @@ export class Bubble {
43
43
  this._map.clear(), this._levelNodes.clear();
44
44
  }
45
45
  }
46
- //# sourceMappingURL=bubble.js.map
46
+ //# sourceMappingURL=bubble.js.map
@@ -25,4 +25,4 @@ export function getDefaultInteractionConfigByMode(mode) {
25
25
  }
26
26
  } : null;
27
27
  }
28
- //# sourceMappingURL=config.js.map
28
+ //# sourceMappingURL=config.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visactor/vchart",
3
- "version": "1.13.23-alpha.0",
3
+ "version": "1.13.23",
4
4
  "description": "charts lib based @visactor/VGrammar",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -81,10 +81,10 @@
81
81
  "@size-limit/file": "9.0.0",
82
82
  "rimraf": "3.0.2",
83
83
  "cross-env": "^7.0.3",
84
- "@internal/eslint-config": "0.0.1",
84
+ "@internal/typescript-json-schema": "0.0.1",
85
85
  "@internal/bundler": "0.0.1",
86
- "@internal/ts-config": "0.0.1",
87
- "@internal/typescript-json-schema": "0.0.1"
86
+ "@internal/eslint-config": "0.0.1",
87
+ "@internal/ts-config": "0.0.1"
88
88
  },
89
89
  "dependencies": {
90
90
  "@visactor/vutils": "~0.19.7",
@@ -101,7 +101,7 @@
101
101
  "@visactor/vgrammar-sankey": "0.16.16",
102
102
  "@visactor/vgrammar-venn": "0.16.16",
103
103
  "@visactor/vgrammar-util": "0.16.16",
104
- "@visactor/vutils-extension": "1.13.23-alpha.0"
104
+ "@visactor/vutils-extension": "1.13.23"
105
105
  },
106
106
  "publishConfig": {
107
107
  "access": "public",