@visactor/vrender-components 0.16.14-alpha.7 → 0.16.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/axis/base.js +11 -22
- package/cjs/axis/base.js.map +1 -1
- package/cjs/axis/line.js +1 -1
- package/cjs/axis/line.js.map +1 -1
- package/cjs/axis/type.d.ts +3 -6
- package/cjs/axis/type.js.map +1 -1
- package/cjs/brush/index.js +2 -1
- package/cjs/checkbox/index.js +1 -2
- package/cjs/data-zoom/config.d.ts +0 -6
- package/cjs/data-zoom/config.js +1 -7
- package/cjs/data-zoom/config.js.map +1 -1
- package/cjs/data-zoom/data-zoom.d.ts +3 -2
- package/cjs/data-zoom/data-zoom.js +19 -15
- package/cjs/data-zoom/data-zoom.js.map +1 -1
- package/cjs/data-zoom/type.d.ts +6 -0
- package/cjs/data-zoom/type.js +6 -1
- package/cjs/data-zoom/type.js.map +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/indicator/indicator.js +6 -50
- package/cjs/indicator/indicator.js.map +1 -1
- package/cjs/indicator/type.d.ts +2 -5
- package/cjs/indicator/type.js.map +1 -1
- package/cjs/label/animate/animate.d.ts +8 -2
- package/cjs/label/animate/animate.js +37 -3
- package/cjs/label/animate/animate.js.map +1 -1
- package/cjs/label/arc.d.ts +3 -4
- package/cjs/label/arc.js.map +1 -1
- package/cjs/label/area.d.ts +15 -0
- package/cjs/label/area.js +41 -0
- package/cjs/label/area.js.map +1 -0
- package/cjs/label/base.d.ts +17 -14
- package/cjs/label/base.js +38 -61
- package/cjs/label/base.js.map +1 -1
- package/cjs/label/dataLabel.js +8 -5
- package/cjs/label/dataLabel.js.map +1 -1
- package/cjs/label/line.d.ts +1 -1
- package/cjs/label/line.js +2 -9
- package/cjs/label/line.js.map +1 -1
- package/cjs/label/type.d.ts +26 -10
- package/cjs/label/type.js +1 -2
- package/cjs/label/type.js.map +1 -1
- package/cjs/label/util.d.ts +4 -0
- package/cjs/label/util.js +14 -2
- package/cjs/label/util.js.map +1 -1
- package/cjs/link-path/type.js +1 -1
- package/cjs/marker/point.d.ts +1 -1
- package/cjs/marker/type.js.map +1 -1
- package/cjs/scrollbar/scrollbar.js.map +1 -1
- package/cjs/tag/tag.js +40 -90
- package/cjs/tag/tag.js.map +1 -1
- package/cjs/tag/type.d.ts +3 -4
- package/cjs/tag/type.js.map +1 -1
- package/cjs/title/title.js +47 -111
- package/cjs/title/title.js.map +1 -1
- package/cjs/title/type.d.ts +5 -10
- package/cjs/title/type.js.map +1 -1
- package/cjs/tooltip/tooltip.js +1 -26
- package/cjs/tooltip/tooltip.js.map +1 -1
- package/cjs/tooltip/type.d.ts +1 -3
- package/cjs/tooltip/type.js.map +1 -1
- package/dist/index.js +290 -311
- package/dist/index.min.js +1 -1
- package/es/axis/base.js +11 -23
- package/es/axis/base.js.map +1 -1
- package/es/axis/line.js +1 -1
- package/es/axis/line.js.map +1 -1
- package/es/axis/type.d.ts +3 -6
- package/es/axis/type.js.map +1 -1
- package/es/brush/index.js +2 -1
- package/es/checkbox/index.js +1 -2
- package/es/data-zoom/config.d.ts +0 -6
- package/es/data-zoom/config.js +0 -7
- package/es/data-zoom/config.js.map +1 -1
- package/es/data-zoom/data-zoom.d.ts +3 -2
- package/es/data-zoom/data-zoom.js +10 -4
- package/es/data-zoom/data-zoom.js.map +1 -1
- package/es/data-zoom/type.d.ts +6 -0
- package/es/data-zoom/type.js +6 -1
- package/es/data-zoom/type.js.map +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/indicator/indicator.js +6 -50
- package/es/indicator/indicator.js.map +1 -1
- package/es/indicator/type.d.ts +2 -5
- package/es/indicator/type.js.map +1 -1
- package/es/label/animate/animate.d.ts +8 -2
- package/es/label/animate/animate.js +35 -0
- package/es/label/animate/animate.js.map +1 -1
- package/es/label/arc.d.ts +3 -4
- package/es/label/arc.js.map +1 -1
- package/es/label/area.d.ts +15 -0
- package/es/label/area.js +39 -0
- package/es/label/area.js.map +1 -0
- package/es/label/base.d.ts +17 -14
- package/es/label/base.js +40 -63
- package/es/label/base.js.map +1 -1
- package/es/label/dataLabel.js +11 -4
- package/es/label/dataLabel.js.map +1 -1
- package/es/label/line.d.ts +1 -1
- package/es/label/line.js +3 -8
- package/es/label/line.js.map +1 -1
- package/es/label/type.d.ts +26 -10
- package/es/label/type.js +1 -2
- package/es/label/type.js.map +1 -1
- package/es/label/util.d.ts +4 -0
- package/es/label/util.js +13 -1
- package/es/label/util.js.map +1 -1
- package/es/link-path/type.js +1 -1
- package/es/marker/point.d.ts +1 -1
- package/es/marker/type.js.map +1 -1
- package/es/scrollbar/scrollbar.js.map +1 -1
- package/es/tag/tag.js +38 -88
- package/es/tag/tag.js.map +1 -1
- package/es/tag/type.d.ts +3 -4
- package/es/tag/type.js.map +1 -1
- package/es/title/title.js +45 -111
- package/es/title/title.js.map +1 -1
- package/es/title/type.d.ts +5 -10
- package/es/title/type.js.map +1 -1
- package/es/tooltip/tooltip.js +1 -26
- package/es/tooltip/tooltip.js.map +1 -1
- package/es/tooltip/type.d.ts +1 -3
- package/es/tooltip/type.js.map +1 -1
- package/package.json +6 -6
package/cjs/label/type.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EasingType, IGraphic, IGroupGraphicAttribute, ITextGraphicAttribute,
|
|
1
|
+
import type { EasingType, IGraphic, IGroupGraphicAttribute, ITextGraphicAttribute, Text, TextAlignType, TextBaselineType, ILineGraphicAttribute } from '@visactor/vrender-core';
|
|
2
2
|
import type { IPointLike } from '@visactor/vutils';
|
|
3
3
|
export type LabelItemStateStyle<T> = {
|
|
4
4
|
hover?: T;
|
|
@@ -11,11 +11,7 @@ export type LabelItem = {
|
|
|
11
11
|
id?: string;
|
|
12
12
|
data?: any;
|
|
13
13
|
[key: string]: any;
|
|
14
|
-
|
|
15
|
-
text?: string | string[] | number | number[] | IRichTextCharacter[];
|
|
16
|
-
textAlign?: 'left' | 'right' | 'center' | 'start' | 'end';
|
|
17
|
-
textBaseline?: 'top' | 'middle' | 'bottom' | 'alphabetic';
|
|
18
|
-
} & Omit<Partial<ITextGraphicAttribute>, 'textAlign' | 'textBaseline'> & Omit<Partial<IRichTextGraphicAttribute>, 'textAlign' | 'textBaseline'>;
|
|
14
|
+
} & ITextGraphicAttribute;
|
|
19
15
|
export interface BaseLabelAttrs extends IGroupGraphicAttribute {
|
|
20
16
|
type: string;
|
|
21
17
|
baseMarkGroupName: string;
|
|
@@ -32,10 +28,14 @@ export interface BaseLabelAttrs extends IGroupGraphicAttribute {
|
|
|
32
28
|
overlap?: OverlapAttrs | false;
|
|
33
29
|
smartInvert?: SmartInvertAttrs | false;
|
|
34
30
|
animation?: ILabelAnimation | false;
|
|
31
|
+
animationEnter?: ILabelUpdateAnimation;
|
|
32
|
+
animationUpdate?: ILabelUpdateAnimation | ILabelUpdateChannelAnimation[];
|
|
33
|
+
animationExit?: ILabelExitAnimation;
|
|
35
34
|
dataFilter?: (data: LabelItem[]) => LabelItem[];
|
|
36
|
-
customLayoutFunc?: (data: LabelItem[], getRelatedGraphic: (data: LabelItem) => IGraphic, getRelatedPoint?: (data: LabelItem) => IPointLike) =>
|
|
37
|
-
customOverlapFunc?: (label:
|
|
35
|
+
customLayoutFunc?: (data: LabelItem[], getRelatedGraphic: (data: LabelItem) => IGraphic, getRelatedPoint?: (data: LabelItem) => IPointLike) => Text[];
|
|
36
|
+
customOverlapFunc?: (label: Text[], getRelatedGraphic: (data: LabelItem) => IGraphic, getRelatedPoint?: (data: LabelItem) => IPointLike) => Text[];
|
|
38
37
|
disableTriggerEvent?: boolean;
|
|
38
|
+
id?: string;
|
|
39
39
|
}
|
|
40
40
|
export interface OverlapAttrs {
|
|
41
41
|
size?: {
|
|
@@ -89,6 +89,10 @@ export interface LineLabelAttrs extends BaseLabelAttrs {
|
|
|
89
89
|
type: 'line';
|
|
90
90
|
position?: Functional<'start' | 'end'>;
|
|
91
91
|
}
|
|
92
|
+
export interface AreaLabelAttrs extends BaseLabelAttrs {
|
|
93
|
+
type: 'area';
|
|
94
|
+
position?: Functional<'start' | 'end'>;
|
|
95
|
+
}
|
|
92
96
|
export interface LineDataLabelAttrs extends BaseLabelAttrs {
|
|
93
97
|
type: 'line-data';
|
|
94
98
|
position?: Functional<'top' | 'bottom' | 'left' | 'right' | 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'center'>;
|
|
@@ -140,13 +144,25 @@ export interface DataLabelAttrs extends IGroupGraphicAttribute {
|
|
|
140
144
|
};
|
|
141
145
|
}
|
|
142
146
|
export type Functional<T> = T | ((data: any) => T);
|
|
143
|
-
export interface
|
|
144
|
-
mode?: 'same-time' | 'after' | 'after-all';
|
|
147
|
+
export interface ILabelExitAnimation {
|
|
145
148
|
duration?: number;
|
|
146
149
|
delay?: number;
|
|
147
150
|
easing?: EasingType;
|
|
151
|
+
}
|
|
152
|
+
export interface ILabelEnterAnimation extends ILabelExitAnimation {
|
|
153
|
+
mode?: 'same-time' | 'after' | 'after-all';
|
|
154
|
+
}
|
|
155
|
+
export interface ILabelUpdateAnimation extends ILabelExitAnimation {
|
|
148
156
|
increaseEffect?: boolean;
|
|
149
157
|
}
|
|
158
|
+
export interface ILabelUpdateChannelAnimation extends ILabelUpdateAnimation {
|
|
159
|
+
channel?: string[];
|
|
160
|
+
options?: {
|
|
161
|
+
excludeChannels?: string[];
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
export interface ILabelAnimation extends ILabelEnterAnimation, ILabelExitAnimation, ILabelUpdateAnimation {
|
|
165
|
+
}
|
|
150
166
|
export interface IPoint {
|
|
151
167
|
x: number;
|
|
152
168
|
y: number;
|
package/cjs/label/type.js
CHANGED
package/cjs/label/type.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/label/type.ts"],"names":[],"mappings":"","file":"type.js","sourcesContent":["import type {\n EasingType,\n IGraphic,\n IGroupGraphicAttribute,\n ITextGraphicAttribute,\n
|
|
1
|
+
{"version":3,"sources":["../src/label/type.ts"],"names":[],"mappings":"","file":"type.js","sourcesContent":["import type {\n EasingType,\n IGraphic,\n IGroupGraphicAttribute,\n ITextGraphicAttribute,\n Text,\n TextAlignType,\n TextBaselineType,\n ILineGraphicAttribute\n} from '@visactor/vrender-core';\nimport type { IPointLike } from '@visactor/vutils';\n\nexport type LabelItemStateStyle<T> = {\n hover?: T;\n hover_reverse?: T;\n selected?: T;\n selected_reverse?: T;\n [key: string]: T;\n};\n\nexport type LabelItem = {\n // 用于动画\n id?: string;\n // 原始数据\n data?: any;\n [key: string]: any;\n} & ITextGraphicAttribute;\n\nexport interface BaseLabelAttrs extends IGroupGraphicAttribute {\n type: string;\n /**\n * 图元 group 名称\n */\n baseMarkGroupName: string;\n /**\n * @hack not recommend to use\n * @returns\n */\n getBaseMarks?: () => IGraphic[];\n /**\n * 是否开启选中交互\n * @default false\n */\n select?: boolean;\n /**\n * 是否开启 hover 交互\n * @default false\n */\n hover?: boolean;\n /**\n * 标签数据\n */\n data: LabelItem[];\n\n /** 文本样式,优先级低于 data */\n textStyle?: Partial<ITextGraphicAttribute>;\n\n /** 文本交互样式 */\n state?: LabelItemStateStyle<ITextGraphicAttribute>;\n\n /** 连线的交互样式 */\n labelLineState?: LabelItemStateStyle<ILineGraphicAttribute>;\n\n syncState?: boolean;\n\n /** 标签默认位置 */\n position?: Functional<string>;\n\n /** 偏移量 */\n offset?: number;\n\n /** 是否开启防重叠\n * @default true\n */\n overlap?: OverlapAttrs | false;\n\n /** 智能反色 */\n smartInvert?: SmartInvertAttrs | false;\n\n /** 动画配置 */\n animation?: ILabelAnimation | false;\n animationEnter?: ILabelUpdateAnimation;\n animationUpdate?: ILabelUpdateAnimation | ILabelUpdateChannelAnimation[];\n animationExit?: ILabelExitAnimation;\n\n // 排序 or 删减\n dataFilter?: (data: LabelItem[]) => LabelItem[];\n\n /** 自定义布局函数\n * @description 当配置了 customLayoutFunc 后,默认布局逻辑将不再生效。(position/offset不生效)\n */\n customLayoutFunc?: (\n data: LabelItem[],\n getRelatedGraphic: (data: LabelItem) => IGraphic,\n getRelatedPoint?: (data: LabelItem) => IPointLike\n ) => Text[];\n\n /** 自定义标签躲避函数\n * @description 当配置了 customOverlapFunc 后,会根据 position 和 offset 进行初始布局。配置的防重叠逻辑(overlap)不生效。\n */\n customOverlapFunc?: (\n label: Text[],\n getRelatedGraphic: (data: LabelItem) => IGraphic,\n getRelatedPoint?: (data: LabelItem) => IPointLike\n ) => Text[];\n /**\n * 关闭交互效果\n * @default false\n */\n disableTriggerEvent?: boolean;\n /** 唯一标志符 */\n id?: string;\n}\n\nexport interface OverlapAttrs {\n /**\n * 防重叠的区域大小\n */\n size?: { width: number; height: number };\n\n /**\n * 发生重叠后,是否隐藏标签\n * @default true\n */\n hideOnHit?: boolean;\n\n /**\n * 是否约束标签在指定 size 的范围内。开启后若标签被区域裁剪,会向内收缩。\n * @default true\n */\n clampForce?: boolean;\n\n /**\n * 是否躲避基础图元\n * @default false\n */\n avoidBaseMark?: boolean;\n\n /**\n * 躲避指定图元\n * @default []\n */\n avoidMarks?: string[] | IGraphic[];\n\n /**\n * 发生重叠后的躲避策略\n */\n strategy?: Strategy[];\n\n /**\n * 文字在防重叠计算中预留的边距。\n * @default 0\n */\n overlapPadding?: number;\n}\n\nexport interface SmartInvertAttrs {\n /**\n * 文本类型\n * 包含普通文本和大文本,对应不同的对比度标准,label默认为普通文本\n * 'normalText' | 'largeText'\n * @default 'normalText'\n */\n textType?: string;\n /**\n * 自定义对比度阈值\n */\n contrastRatiosThreshold?: number;\n /**\n * 自定义备选label颜色\n */\n alternativeColors?: string | string[];\n /**\n * fillStrategy四种策略:\n * - base(baseMark色),\n * - invertBase(执行智能反色),\n * - similarBase(智能反色的补色),\n * - null(不执行智能反色,保持fill设置的颜色)\n * @default 'invertBase'\n */\n fillStrategy?: 'base' | 'invertBase' | 'similarBase' | 'null';\n /**\n * strokeStrategy的四种策略:\n * - base(baseMark色),\n * - invertBase(执行智能反色),\n * - similarBase(智能反色的补色),\n * - null(不执行智能反色,保持stroke设置的颜色)\n * @default 'base'\n */\n strokeStrategy?: 'base' | 'invertBase' | 'similarBase' | 'null';\n /**\n * 前景色与亮色具有对比度时,similarSeries使用该色\n * @default '#ffffff'\n */\n brightColor?: string;\n /**\n * 前景色与暗色具有对比度时,similarSeries使用该色\n * @default '#000000'\n */\n darkColor?: string;\n /**\n * label超出mark范围,也以mark作为背景色进行反色\n */\n outsideEnable?: boolean;\n}\n\nexport type PositionStrategy = {\n /**\n * 可选位置策略。\n * 若默认位置没有足够的空间放置标签,则考虑 position 内的备选位置。\n */\n type: 'position';\n position?: Functional<LabelPosition[]>;\n};\n\nexport type BoundStrategy = {\n /**\n * 标签配置在图形内部时使用。\n * 当图形大小不足以放下标签,则考虑 position 内的备选位置。\n */\n type: 'bound';\n position?: Functional<LabelPosition[]>;\n};\n\nexport type MoveYStrategy = {\n /**\n * 可选位置策略。\n * 若默认位置没有足够的空间放置标签,则根据 offset 在Y方向上寻找位置。\n */\n type: 'moveY';\n /**\n * Y方向上的尝试的位置偏移量\n */\n offset: Functional<number[]>;\n};\n\nexport type MoveXStrategy = {\n /**\n * 可选位置策略。\n * 若默认位置没有足够的空间放置标签,则根据 offset 在X方向上寻找位置。\n */\n type: 'moveX';\n /**\n * X方向上的尝试的位置偏移量\n */\n offset: Functional<number[]>;\n};\n\nexport type Strategy = PositionStrategy | BoundStrategy | MoveYStrategy | MoveXStrategy;\n\nexport type LabelPosition = SymbolLabelAttrs['position'] | RectLabelAttrs['position'];\n\nexport interface SymbolLabelAttrs extends BaseLabelAttrs {\n type: 'symbol';\n\n /**\n * 标签位置\n * @default 'top'\n */\n position?: Functional<\n 'top' | 'bottom' | 'left' | 'right' | 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'center'\n >;\n}\n\nexport interface RectLabelAttrs extends BaseLabelAttrs {\n type: 'rect';\n /**\n * 标签位置\n * @default 'top'\n */\n position?: Functional<\n | 'top'\n | 'bottom'\n | 'left'\n | 'right'\n | 'inside'\n | 'inside-top'\n | 'inside-bottom'\n | 'inside-right'\n | 'inside-left'\n | 'top-right'\n | 'top-left'\n | 'bottom-right'\n | 'bottom-left'\n >;\n}\n\nexport interface LineLabelAttrs extends BaseLabelAttrs {\n type: 'line';\n /**\n * 标签位置\n * @default 'end'\n */\n position?: Functional<'start' | 'end'>;\n}\n\nexport interface AreaLabelAttrs extends BaseLabelAttrs {\n type: 'area';\n /**\n * 标签位置\n * @default 'end'\n */\n position?: Functional<'start' | 'end'>;\n}\n\nexport interface LineDataLabelAttrs extends BaseLabelAttrs {\n type: 'line-data';\n\n /**\n * 标签位置\n * @default 'top'\n */\n position?: Functional<\n 'top' | 'bottom' | 'left' | 'right' | 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'center'\n >;\n}\n\nexport interface PolygonLabelAttrs extends BaseLabelAttrs {\n type: 'polygon';\n /**\n * 标签位置\n * @default 'center'\n */\n position?: Functional<'center'>;\n}\n\nexport interface ArcLabelAttrs extends BaseLabelAttrs {\n type: 'arc';\n\n /**\n * 图元 group 名称\n */\n baseMarkGroupName: string;\n\n /**\n * 标签位置\n * @default 'outside'\n */\n position?: Functional<'inside' | 'outside' | 'inside-inner' | 'inside-outer'>;\n\n // 画布宽度\n width?: number;\n // 画布高度\n height?: number;\n\n /**\n * 是否允许标签重叠\n * @default false\n */\n coverEnable?: boolean;\n /**\n * 是否允许标签旋转\n * @default true\n */\n rotate?: boolean;\n\n /**\n * 文字与引导线间隔宽度\n * @default 5\n */\n spaceWidth?: number;\n /**\n * 标签旋转角度\n */\n angle?: number;\n /**\n * 标签旋转角度的偏移角度\n */\n offsetAngle?: number;\n /**\n * 标签相对于 `outerRadius` 的径向偏移,目前仅作用于 inside 标签\n */\n offsetRadius?: number;\n /**\n * 标签横向点对齐\n */\n textAlign?: TextAlignType;\n /**\n * 标签纵向点对齐\n */\n textBaseline?: TextBaselineType;\n /**\n * 扇区间标签的间隔\n * @default 6\n */\n layoutArcGap?: number;\n /** 标签引导线样式 */\n line?: IArcLabelLineSpec;\n /** 标签布局配置 */\n layout?: IArcLabelLayoutSpec;\n /** 标签引导线点集 */\n points?: IPoint[];\n /** 饼图扇区中心偏移 */\n centerOffset?: number;\n}\n\nexport interface IArcLabelLineSpec {\n /**\n * 是否显示引导线\n * @default true\n */\n visible?: boolean;\n /**\n * 引导线 line1 部分最小长度\n * @default 20\n */\n line1MinLength?: number;\n /**\n * 引导线 line2 部分最小长度\n * @default 10\n */\n line2MinLength?: number;\n /**\n * 引导线是否光滑\n * @default false\n */\n smooth?: boolean;\n /**\n * 引导线样式\n */\n style?: Partial<ILineGraphicAttribute>;\n}\n\nexport type ArcLabelAlignType = 'arc' | 'labelLine' | 'edge';\n\nexport type ArcLabelStrategyType = 'priority' | 'vertical' | 'none';\n\nexport interface IArcLabelLayoutSpec {\n /**\n * 标签对齐方式\n * @default 'arc'\n */\n textAlign?: ArcLabelAlignType;\n /** @deprecate 建议统一使用textAlign,后续将废除 */\n align?: ArcLabelAlignType;\n /**\n * 标签布局策略\n * @default 'priority'\n */\n strategy?: ArcLabelStrategyType;\n /**\n * 是否启用切线约束\n * @default true\n */\n tangentConstraint?: boolean;\n}\n\nexport interface DataLabelAttrs extends IGroupGraphicAttribute {\n dataLabels: (RectLabelAttrs | SymbolLabelAttrs | ArcLabelAttrs | LineDataLabelAttrs)[];\n /**\n * 防重叠的区域大小\n */\n size: { width: number; height: number };\n}\n\nexport type Functional<T> = T | ((data: any) => T);\n\nexport interface ILabelExitAnimation {\n duration?: number;\n delay?: number;\n easing?: EasingType;\n}\n\nexport interface ILabelEnterAnimation extends ILabelExitAnimation {\n mode?: 'same-time' | 'after' | 'after-all';\n}\n\nexport interface ILabelUpdateAnimation extends ILabelExitAnimation {\n /** 是否开启 increaseCount 动画\n * @default true\n */\n increaseEffect?: boolean;\n}\n\nexport interface ILabelUpdateChannelAnimation extends ILabelUpdateAnimation {\n channel?: string[];\n options?: { excludeChannels?: string[] };\n}\n\nexport interface ILabelAnimation extends ILabelEnterAnimation, ILabelExitAnimation, ILabelUpdateAnimation {}\n\nexport interface IPoint {\n x: number;\n y: number;\n}\n\nexport interface IPolarPoint {\n radius: number;\n angle: number;\n}\n\nexport type Quadrant = 1 | 2 | 3 | 4;\n\nexport type TextAlign = 'left' | 'right' | 'center';\n"]}
|
package/cjs/label/util.d.ts
CHANGED
|
@@ -16,3 +16,7 @@ export declare const labelingPoint: (textBounds: IBoundsLike, graphicBounds: IBo
|
|
|
16
16
|
y: number;
|
|
17
17
|
};
|
|
18
18
|
export declare const getPointsOfLineArea: (graphic: ILine | IArea) => IPointLike[];
|
|
19
|
+
export declare function labelingLineOrArea(textBounds: IBoundsLike, graphicBounds: IBoundsLike, position?: string, offset?: number): {
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
};
|
package/cjs/label/util.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: !0
|
|
5
|
-
}), exports.getPointsOfLineArea = exports.labelingPoint = exports.degrees = exports.checkBoundsOverlap = exports.connectLineRadian = exports.lineCirclePoints = exports.isQuadrantRight = exports.isQuadrantLeft = exports.normalizeAngle = exports.computeQuadrant = exports.circlePoint = exports.polarToCartesian = void 0;
|
|
5
|
+
}), exports.labelingLineOrArea = exports.getPointsOfLineArea = exports.labelingPoint = exports.degrees = exports.checkBoundsOverlap = exports.connectLineRadian = exports.lineCirclePoints = exports.isQuadrantRight = exports.isQuadrantLeft = exports.normalizeAngle = exports.computeQuadrant = exports.circlePoint = exports.polarToCartesian = void 0;
|
|
6
6
|
|
|
7
7
|
const vutils_1 = require("@visactor/vutils");
|
|
8
8
|
|
|
@@ -171,4 +171,16 @@ const getPointsOfLineArea = graphic => {
|
|
|
171
171
|
return points;
|
|
172
172
|
};
|
|
173
173
|
|
|
174
|
-
|
|
174
|
+
function labelingLineOrArea(textBounds, graphicBounds, position = "end", offset = 0) {
|
|
175
|
+
if (!textBounds || !graphicBounds) return;
|
|
176
|
+
const {x1: x1, x2: x2} = textBounds, width = Math.abs(x2 - x1), anchorX = graphicBounds.x1;
|
|
177
|
+
let x = anchorX;
|
|
178
|
+
return "end" === position ? x = anchorX + width / 2 + offset : "start" === position && (x = anchorX - width / 2 - offset),
|
|
179
|
+
{
|
|
180
|
+
x: x,
|
|
181
|
+
y: graphicBounds.y1
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
exports.getPointsOfLineArea = getPointsOfLineArea, exports.labelingLineOrArea = labelingLineOrArea;
|
|
186
|
+
//# sourceMappingURL=util.js.map
|
package/cjs/label/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/label/util.ts"],"names":[],"mappings":";;;AAGA,6CAAiE;AAOjE,SAAgB,gBAAgB,CAAC,KAAkB;IACjD,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;QACjB,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;KACvB;IACD,OAAO;QACL,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM;QACvC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM;KACxC,CAAC;AACJ,CAAC;AARD,4CAQC;AASD,SAAgB,WAAW,CAAC,EAAU,EAAE,EAAU,EAAE,MAAc,EAAE,MAAc;IAChF,MAAM,MAAM,GAAG,gBAAgB,CAAC;QAC9B,MAAM;QACN,KAAK,EAAE,MAAM;KACd,CAAC,CAAC;IACH,OAAO;QACL,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC,CAAC;QAChB,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC,C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AAgB,EAAE;IAC1E,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;QAClC,OAAO,EAAE,CAAC;KACX;IAED,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC;IAE/C,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,EAAE;QAC/B,MAAM,GAAG,GAAiB,EAAE,CAAC;QAE7B,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACrB,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC;YAE7B,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBACxB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,CAAC;KACZ;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAtBW,QAAA,mBAAmB,uBAsB9B","file":"util.js","sourcesContent":["import type { IArea, IAreaSegment, ILine, ISegment } from '@visactor/vrender-core';\nimport type { IPolarPoint, IPoint, Quadrant } from './type';\nimport type { IBoundsLike, IPointLike } from '@visactor/vutils';\nimport { radianToDegree, isValidNumber } from '@visactor/vutils';\n\n/**\n * 极坐标系 -> 直角坐标系\n * @param point\n * @returns\n */\nexport function polarToCartesian(point: IPolarPoint): IPoint {\n if (!point.radius) {\n return { x: 0, y: 0 };\n }\n return {\n x: Math.cos(point.angle) * point.radius,\n y: Math.sin(point.angle) * point.radius\n };\n}\n\n/**\n * 计算圆弧上的点坐标\n * @param x0 圆心 x 坐标\n * @param y0 圆心 y 坐标\n * @param radius 圆弧半径\n * @param radian 点所在弧度\n */\nexport function circlePoint(x0: number, y0: number, radius: number, radian: number): IPoint {\n const offset = polarToCartesian({\n radius,\n angle: radian\n });\n return {\n x: x0 + offset.x,\n y: y0 + offset.y\n };\n}\n\n/**\n * 根据角度计算象限\n * 计算角度所在象限\n * @param angle\n * @returns\n */\nexport function computeQuadrant(angle: number): Quadrant {\n angle = normalizeAngle(angle);\n if (angle > 0 && angle <= Math.PI / 2) {\n return 2;\n } else if (angle > Math.PI / 2 && angle <= Math.PI) {\n return 3;\n } else if (angle > Math.PI && angle <= (3 * Math.PI) / 2) {\n return 4;\n }\n return 1;\n}\n\n/**\n * 角度标准化处理\n * @param angle 弧度角\n */\nexport function normalizeAngle(angle: number): number {\n while (angle < 0) {\n angle += Math.PI * 2;\n }\n while (angle >= Math.PI * 2) {\n angle -= Math.PI * 2;\n }\n return angle;\n}\n\nexport function isQuadrantLeft(quadrant: Quadrant): boolean {\n return quadrant === 3 || quadrant === 4;\n}\n\nexport function isQuadrantRight(quadrant: Quadrant): boolean {\n return quadrant === 1 || quadrant === 2;\n}\n\n/**\n * 计算直线与圆交点\n * 直线方程:ax + by + c = 0\n * 圆方程:(x - x0)^2 + (y - y0)^2 = r^2\n */\nexport function lineCirclePoints(a: number, b: number, c: number, x0: number, y0: number, r: number): IPoint[] {\n if ((a === 0 && b === 0) || r <= 0) {\n return [];\n }\n if (a === 0) {\n const y1 = -c / b;\n const fy = (y1 - y0) ** 2;\n const fd = r ** 2 - fy;\n if (fd < 0) {\n return [];\n } else if (fd === 0) {\n return [{ x: x0, y: y1 }];\n }\n const x1 = Math.sqrt(fd) + x0;\n const x2 = -Math.sqrt(fd) + x0;\n return [\n { x: x1, y: y1 },\n { x: x2, y: y1 }\n ];\n } else if (b === 0) {\n const x1 = -c / a;\n const fx = (x1 - x0) ** 2;\n const fd = r ** 2 - fx;\n if (fd < 0) {\n return [];\n } else if (fd === 0) {\n return [{ x: x1, y: y0 }];\n }\n const y1 = Math.sqrt(fd) + y0;\n const y2 = -Math.sqrt(fd) + y0;\n return [\n { x: x1, y: y1 },\n { x: x1, y: y2 }\n ];\n }\n const fa = (b / a) ** 2 + 1;\n const fb = 2 * ((c / a + x0) * (b / a) - y0);\n const fc = (c / a + x0) ** 2 + y0 ** 2 - r ** 2;\n const fd = fb ** 2 - 4 * fa * fc;\n if (fd < 0) {\n return [];\n }\n const y1 = (-fb + Math.sqrt(fd)) / (2 * fa);\n const y2 = (-fb - Math.sqrt(fd)) / (2 * fa);\n const x1 = -(b * y1 + c) / a;\n const x2 = -(b * y2 + c) / a;\n if (fd === 0) {\n return [{ x: x1, y: y1 }];\n }\n return [\n { x: x1, y: y1 },\n { x: x2, y: y2 }\n ];\n}\n\n/**\n * 根据圆弧两点连接线长度计算弧度\n * @param radius 圆弧半径\n * @param length 连接线长度\n */\nexport function connectLineRadian(radius: number, length: number) {\n if (length > radius * 2) {\n return NaN;\n }\n return Math.asin(length / 2 / radius) * 2;\n}\n\nexport function checkBoundsOverlap(boundsA: IBoundsLike, boundsB: IBoundsLike): boolean {\n const { x1: ax1, y1: ay1, x2: ax2, y2: ay2 } = boundsA;\n const { x1: bx1, y1: by1, x2: bx2, y2: by2 } = boundsB;\n return !(\n (ax1 <= bx1 && ax2 <= bx1) ||\n (ax1 >= bx2 && ax2 >= bx2) ||\n (ay1 <= by1 && ay2 <= by1) ||\n (ay1 >= by2 && ay2 >= by2)\n );\n}\n\nexport const degrees = (angle?: number) => {\n if (!isValidNumber(angle)) {\n return null;\n }\n return radianToDegree(angle);\n};\n\nexport const labelingPoint = (textBounds: IBoundsLike, graphicBounds: IBoundsLike, position = 'top', offset = 0) => {\n if (!textBounds) {\n return;\n }\n\n const { x1, y1, x2, y2 } = textBounds;\n const width = Math.abs(x2 - x1);\n const height = Math.abs(y2 - y1);\n\n const anchorX = (graphicBounds.x1 + graphicBounds.x2) / 2;\n const anchorY = (graphicBounds.y1 + graphicBounds.y2) / 2;\n\n let sx = 0;\n let sy = 0;\n let offsetX = 0;\n let offsetY = 0;\n if (graphicBounds) {\n offsetX = Math.abs(graphicBounds.x1 - graphicBounds.x2) / 2;\n offsetY = Math.abs(graphicBounds.y1 - graphicBounds.y2) / 2;\n }\n\n const angle = {\n 'top-right': -235,\n 'top-left': 235,\n 'bottom-right': 45,\n 'bottom-left': -45\n };\n\n switch (position) {\n case 'top':\n sy = -1;\n break;\n case 'bottom':\n sy = 1;\n break;\n case 'left':\n sx = -1;\n break;\n case 'right':\n sx = 1;\n break;\n case 'bottom-left':\n case 'bottom-right':\n case 'top-left':\n case 'top-right':\n sx = Math.sin(angle[position] * (Math.PI / 180));\n sy = Math.cos(angle[position] * (Math.PI / 180));\n break;\n case 'center':\n sx = 0;\n sy = 0;\n break;\n }\n\n const x = anchorX + sx * (offset + offsetX) + Math.sign(sx) * (width / 2);\n const y = anchorY + sy * (offset + offsetY) + Math.sign(sy) * (height / 2);\n\n return { x, y };\n};\n\nexport const getPointsOfLineArea = (graphic: ILine | IArea): IPointLike[] => {\n if (!graphic || !graphic.attribute) {\n return [];\n }\n\n const { points, segments } = graphic.attribute;\n\n if (segments && segments.length) {\n const res: IPointLike[] = [];\n\n segments.forEach(seg => {\n const segPoints = seg.points;\n\n segPoints.forEach(point => {\n res.push(point);\n });\n });\n\n return res;\n }\n\n return points;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/label/util.ts"],"names":[],"mappings":";;;AAGA,6CAAiE;AAOjE,SAAgB,gBAAgB,CAAC,KAAkB;IACjD,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;QACjB,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;KACvB;IACD,OAAO;QACL,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM;QACvC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM;KACxC,CAAC;AACJ,CAAC;AARD,4CAQC;AASD,SAAgB,WAAW,CAAC,EAAU,EAAE,EAAU,EAAE,MAAc,EAAE,MAAc;IAChF,MAAM,MAAM,GAAG,gBAAgB,CAAC;QAC9B,MAAM;QACN,KAAK,EAAE,MAAM;KACd,CAAC,CAAC;IAC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OAAO,GAAG,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC;KAClC;SAAM,IAAI,QAAQ,KAAK,OAAO,EAAE;QAC/B,CAAC,GAAG,OAAO,GAAG,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC;KAClC;IAED,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAClB,CAAC;AA1BD,gDA0BC","file":"util.js","sourcesContent":["import type { IArea, ILine } from '@visactor/vrender-core';\nimport type { IPolarPoint, IPoint, Quadrant } from './type';\nimport type { IBoundsLike, IPointLike } from '@visactor/vutils';\nimport { radianToDegree, isValidNumber } from '@visactor/vutils';\n\n/**\n * 极坐标系 -> 直角坐标系\n * @param point\n * @returns\n */\nexport function polarToCartesian(point: IPolarPoint): IPoint {\n if (!point.radius) {\n return { x: 0, y: 0 };\n }\n return {\n x: Math.cos(point.angle) * point.radius,\n y: Math.sin(point.angle) * point.radius\n };\n}\n\n/**\n * 计算圆弧上的点坐标\n * @param x0 圆心 x 坐标\n * @param y0 圆心 y 坐标\n * @param radius 圆弧半径\n * @param radian 点所在弧度\n */\nexport function circlePoint(x0: number, y0: number, radius: number, radian: number): IPoint {\n const offset = polarToCartesian({\n radius,\n angle: radian\n });\n return {\n x: x0 + offset.x,\n y: y0 + offset.y\n };\n}\n\n/**\n * 根据角度计算象限\n * 计算角度所在象限\n * @param angle\n * @returns\n */\nexport function computeQuadrant(angle: number): Quadrant {\n angle = normalizeAngle(angle);\n if (angle > 0 && angle <= Math.PI / 2) {\n return 2;\n } else if (angle > Math.PI / 2 && angle <= Math.PI) {\n return 3;\n } else if (angle > Math.PI && angle <= (3 * Math.PI) / 2) {\n return 4;\n }\n return 1;\n}\n\n/**\n * 角度标准化处理\n * @param angle 弧度角\n */\nexport function normalizeAngle(angle: number): number {\n while (angle < 0) {\n angle += Math.PI * 2;\n }\n while (angle >= Math.PI * 2) {\n angle -= Math.PI * 2;\n }\n return angle;\n}\n\nexport function isQuadrantLeft(quadrant: Quadrant): boolean {\n return quadrant === 3 || quadrant === 4;\n}\n\nexport function isQuadrantRight(quadrant: Quadrant): boolean {\n return quadrant === 1 || quadrant === 2;\n}\n\n/**\n * 计算直线与圆交点\n * 直线方程:ax + by + c = 0\n * 圆方程:(x - x0)^2 + (y - y0)^2 = r^2\n */\nexport function lineCirclePoints(a: number, b: number, c: number, x0: number, y0: number, r: number): IPoint[] {\n if ((a === 0 && b === 0) || r <= 0) {\n return [];\n }\n if (a === 0) {\n const y1 = -c / b;\n const fy = (y1 - y0) ** 2;\n const fd = r ** 2 - fy;\n if (fd < 0) {\n return [];\n } else if (fd === 0) {\n return [{ x: x0, y: y1 }];\n }\n const x1 = Math.sqrt(fd) + x0;\n const x2 = -Math.sqrt(fd) + x0;\n return [\n { x: x1, y: y1 },\n { x: x2, y: y1 }\n ];\n } else if (b === 0) {\n const x1 = -c / a;\n const fx = (x1 - x0) ** 2;\n const fd = r ** 2 - fx;\n if (fd < 0) {\n return [];\n } else if (fd === 0) {\n return [{ x: x1, y: y0 }];\n }\n const y1 = Math.sqrt(fd) + y0;\n const y2 = -Math.sqrt(fd) + y0;\n return [\n { x: x1, y: y1 },\n { x: x1, y: y2 }\n ];\n }\n const fa = (b / a) ** 2 + 1;\n const fb = 2 * ((c / a + x0) * (b / a) - y0);\n const fc = (c / a + x0) ** 2 + y0 ** 2 - r ** 2;\n const fd = fb ** 2 - 4 * fa * fc;\n if (fd < 0) {\n return [];\n }\n const y1 = (-fb + Math.sqrt(fd)) / (2 * fa);\n const y2 = (-fb - Math.sqrt(fd)) / (2 * fa);\n const x1 = -(b * y1 + c) / a;\n const x2 = -(b * y2 + c) / a;\n if (fd === 0) {\n return [{ x: x1, y: y1 }];\n }\n return [\n { x: x1, y: y1 },\n { x: x2, y: y2 }\n ];\n}\n\n/**\n * 根据圆弧两点连接线长度计算弧度\n * @param radius 圆弧半径\n * @param length 连接线长度\n */\nexport function connectLineRadian(radius: number, length: number) {\n if (length > radius * 2) {\n return NaN;\n }\n return Math.asin(length / 2 / radius) * 2;\n}\n\nexport function checkBoundsOverlap(boundsA: IBoundsLike, boundsB: IBoundsLike): boolean {\n const { x1: ax1, y1: ay1, x2: ax2, y2: ay2 } = boundsA;\n const { x1: bx1, y1: by1, x2: bx2, y2: by2 } = boundsB;\n return !(\n (ax1 <= bx1 && ax2 <= bx1) ||\n (ax1 >= bx2 && ax2 >= bx2) ||\n (ay1 <= by1 && ay2 <= by1) ||\n (ay1 >= by2 && ay2 >= by2)\n );\n}\n\nexport const degrees = (angle?: number) => {\n if (!isValidNumber(angle)) {\n return null;\n }\n return radianToDegree(angle);\n};\n\nexport const labelingPoint = (textBounds: IBoundsLike, graphicBounds: IBoundsLike, position = 'top', offset = 0) => {\n if (!textBounds) {\n return;\n }\n\n const { x1, y1, x2, y2 } = textBounds;\n const width = Math.abs(x2 - x1);\n const height = Math.abs(y2 - y1);\n\n const anchorX = (graphicBounds.x1 + graphicBounds.x2) / 2;\n const anchorY = (graphicBounds.y1 + graphicBounds.y2) / 2;\n\n let sx = 0;\n let sy = 0;\n let offsetX = 0;\n let offsetY = 0;\n if (graphicBounds) {\n offsetX = Math.abs(graphicBounds.x1 - graphicBounds.x2) / 2;\n offsetY = Math.abs(graphicBounds.y1 - graphicBounds.y2) / 2;\n }\n\n const angle = {\n 'top-right': -235,\n 'top-left': 235,\n 'bottom-right': 45,\n 'bottom-left': -45\n };\n\n switch (position) {\n case 'top':\n sy = -1;\n break;\n case 'bottom':\n sy = 1;\n break;\n case 'left':\n sx = -1;\n break;\n case 'right':\n sx = 1;\n break;\n case 'bottom-left':\n case 'bottom-right':\n case 'top-left':\n case 'top-right':\n sx = Math.sin(angle[position] * (Math.PI / 180));\n sy = Math.cos(angle[position] * (Math.PI / 180));\n break;\n case 'center':\n sx = 0;\n sy = 0;\n break;\n }\n\n const x = anchorX + sx * (offset + offsetX) + Math.sign(sx) * (width / 2);\n const y = anchorY + sy * (offset + offsetY) + Math.sign(sy) * (height / 2);\n\n return { x, y };\n};\n\nexport const getPointsOfLineArea = (graphic: ILine | IArea): IPointLike[] => {\n if (!graphic || !graphic.attribute) {\n return [];\n }\n\n const { points, segments } = graphic.attribute;\n\n if (segments && segments.length) {\n const res: IPointLike[] = [];\n\n segments.forEach(seg => {\n const segPoints = seg.points;\n\n segPoints.forEach(point => {\n res.push(point);\n });\n });\n\n return res;\n }\n\n return points;\n};\n\nexport function labelingLineOrArea(\n textBounds: IBoundsLike,\n graphicBounds: IBoundsLike,\n position: string = 'end',\n offset = 0\n) {\n if (!textBounds || !graphicBounds) {\n return;\n }\n\n const { x1, x2 } = textBounds;\n const width = Math.abs(x2 - x1);\n\n const anchorX = graphicBounds.x1;\n const anchorY = graphicBounds.y1;\n\n let x = anchorX;\n const y = anchorY;\n\n if (position === 'end') {\n x = anchorX + width / 2 + offset;\n } else if (position === 'start') {\n x = anchorX - width / 2 - offset;\n }\n\n return { x, y };\n}\n"]}
|
package/cjs/link-path/type.js
CHANGED
package/cjs/marker/point.d.ts
CHANGED
|
@@ -70,7 +70,7 @@ export declare class MarkPoint extends Marker<MarkPointAttrs> {
|
|
|
70
70
|
protected setItemAttributes(item: ISymbol | Tag | IImage | IRichText, itemContent: IItemContent, itemPosition: Point, itemType: 'symbol' | 'text' | 'image' | 'richText' | 'custom'): void;
|
|
71
71
|
protected getItemDx(item: ISymbol | Tag | IImage | IRichText, position: keyof typeof IMarkPointItemPosition, style?: IImageGraphicAttribute | IRichTextGraphicAttribute): number;
|
|
72
72
|
protected getItemDy(item: ISymbol | Tag | IImage | IRichText, position: keyof typeof IMarkPointItemPosition, style?: IImageGraphicAttribute | IRichTextGraphicAttribute): number;
|
|
73
|
-
protected initItem(itemContent: IItemContent, itemPosition: Point): IGroup | Tag | ISymbol |
|
|
73
|
+
protected initItem(itemContent: IItemContent, itemPosition: Point): IGroup | Tag | ISymbol | IImage | IRichText;
|
|
74
74
|
protected getItemLineAttr(itemLine: IItemLine, position: Point, itemPosition: Point): Point[];
|
|
75
75
|
protected setItemLineAttr(itemLine: IItemLine, position: Point, itemPosition: Point, visible: boolean): void;
|
|
76
76
|
protected getDecorativeLineAttr(itemLine: IItemLine, itemPosition: Point): {
|
package/cjs/marker/type.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/marker/type.ts"],"names":[],"mappings":";;;AAYA,IAAY,sBAUX;AAVD,WAAY,sBAAsB;IAChC,yCAAe,CAAA;IACf,2CAAiB,CAAA;IACjB,qCAAW,CAAA;IACX,2DAAiC,CAAA;IACjC,iEAAuC,CAAA;IACvC,6DAAmC,CAAA;IACnC,mEAAyC,CAAA;IACzC,uDAA6B,CAAA;IAC7B,6DAAmC,CAAA;AACrC,CAAC,EAVW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAUjC;AAED,IAAY,sBAUX;AAVD,WAAY,sBAAsB;IAChC,uCAAa,CAAA;IACb,yCAAe,CAAA;IACf,qCAAW,CAAA;IACX,2CAAiB,CAAA;IACjB,2CAAiB,CAAA;IACjB,mDAAyB,CAAA;IACzB,qDAA2B,CAAA;IAC3B,iDAAuB,CAAA;IACvB,uDAA6B,CAAA;AAC/B,CAAC,EAVW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAUjC;AAED,IAAY,sBAOX;AAPD,WAAY,sBAAsB;IAChC,qCAAW,CAAA;IACX,2CAAiB,CAAA;IACjB,2CAAiB,CAAA;IACjB,iDAAuB,CAAA;IACvB,uDAA6B,CAAA;IAC7B,uDAA6B,CAAA;AAC/B,CAAC,EAPW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAOjC","file":"type.js","sourcesContent":["import type {\n IGroup,\n IGroupGraphicAttribute,\n IImageGraphicAttribute,\n IPolygonAttribute,\n IRichTextGraphicAttribute,\n ISymbolGraphicAttribute\n} from '@visactor/vrender-core';\nimport type { SegmentAttributes, SymbolAttributes } from '../segment';\nimport type { TagAttributes } from '../tag';\nimport type { Point } from '../core/type';\n\nexport enum IMarkLineLabelPosition {\n start = 'start',\n middle = 'middle',\n end = 'end',\n insideStartTop = 'insideStartTop',\n insideStartBottom = 'insideStartBottom',\n insideMiddleTop = 'insideMiddleTop',\n insideMiddleBottom = 'insideMiddleBottom',\n insideEndTop = 'insideEndTop',\n insideEndBottom = 'insideEndBottom'\n}\n\nexport enum IMarkAreaLabelPosition {\n left = 'left',\n right = 'right',\n top = 'top',\n bottom = 'bottom',\n middle = 'middle',\n insideLeft = 'insideLeft',\n insideRight = 'insideRight',\n insideTop = 'insideTop',\n insideBottom = 'insideBottom'\n}\n\nexport enum IMarkPointItemPosition {\n top = 'top',\n bottom = 'bottom',\n middle = 'middle',\n insideTop = 'insideTop',\n insideBottom = 'insideBottom',\n insideMiddle = 'insideMiddle'\n}\n\nexport type IMarkBackgroundAttributes = {\n /**\n * 是否绘制背景层\n */\n visible: boolean;\n /**\n * TODO: 根据文字宽度进行背景 panel size自适应\n */\n autoHeight?: boolean;\n /**\n * TODO: 根据文高度度进行背景 panel size自适应\n */\n autoWidth?: boolean;\n} & Partial<SymbolAttributes>;\n\nexport interface IMarkLabel extends Omit<TagAttributes, 'x' | 'y' | 'panel'> {\n /**\n * 标签的背景面板配置\n */\n panel?: IMarkBackgroundAttributes;\n}\n\nexport interface IMarkRef {\n /**\n * 自动旋转,沿着线的方向,默认 true\n */\n autoRotate?: boolean;\n /**\n * label 相对line平行方向上的偏移\n */\n refX?: number;\n /**\n * label 相对line正交方向上的偏移\n */\n refY?: number;\n /**\n * label 相对默认角度的偏移 (label跟随line的角度做自动旋转时,默认按照line的平行向量作为初始角度)\n */\n refAngle?: number;\n}\n\nexport interface MarkerAttrs extends IGroupGraphicAttribute {\n type?: 'line' | 'area' | 'point';\n /**\n * 是否支持交互\n * @default false\n */\n interactive?: boolean;\n /**\n * 是否显示marker组件\n * @default true\n */\n visible?: boolean;\n /**\n * 是否将组件在绘制区域内进行剪切\n * @default true\n */\n clipInRange?: boolean;\n /**\n * 组件绘制范围配置\n */\n limitRect?: {\n x: number;\n y: number;\n width: number;\n height: number;\n };\n}\n\nexport interface MarkLineAttrs extends MarkerAttrs, SegmentAttributes {\n type?: 'line';\n /**\n * 构成line的点: 如果是两个点,则为直线;多个点则为曲线\n */\n points: Point[] | Point[][];\n\n /**\n * 标签\n */\n label?: {\n /**\n * label 相对line的位置\n */\n position?: keyof typeof IMarkLineLabelPosition;\n /**\n * 当 mark 配置了 clip 之后,label 是否自动调整位置\n */\n confine?: boolean;\n } & IMarkRef &\n IMarkLabel;\n}\n\nexport interface MarkAreaAttrs extends MarkerAttrs {\n type?: 'area';\n /**\n * 构成area的点\n */\n points: Point[];\n /**\n * 标签\n */\n label?: {\n position?: keyof typeof IMarkAreaLabelPosition;\n /**\n * 当 mark 配置了 clip 之后,label 是否自动调整位置\n */\n confine?: boolean;\n } & IMarkLabel;\n /**\n * area的样式\n */\n areaStyle?: IPolygonAttribute;\n}\n\nexport interface IItemContent extends IMarkRef {\n /**\n * 标注类型\n
|
|
1
|
+
{"version":3,"sources":["../src/marker/type.ts"],"names":[],"mappings":";;;AAYA,IAAY,sBAUX;AAVD,WAAY,sBAAsB;IAChC,yCAAe,CAAA;IACf,2CAAiB,CAAA;IACjB,qCAAW,CAAA;IACX,2DAAiC,CAAA;IACjC,iEAAuC,CAAA;IACvC,6DAAmC,CAAA;IACnC,mEAAyC,CAAA;IACzC,uDAA6B,CAAA;IAC7B,6DAAmC,CAAA;AACrC,CAAC,EAVW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAUjC;AAED,IAAY,sBAUX;AAVD,WAAY,sBAAsB;IAChC,uCAAa,CAAA;IACb,yCAAe,CAAA;IACf,qCAAW,CAAA;IACX,2CAAiB,CAAA;IACjB,2CAAiB,CAAA;IACjB,mDAAyB,CAAA;IACzB,qDAA2B,CAAA;IAC3B,iDAAuB,CAAA;IACvB,uDAA6B,CAAA;AAC/B,CAAC,EAVW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAUjC;AAED,IAAY,sBAOX;AAPD,WAAY,sBAAsB;IAChC,qCAAW,CAAA;IACX,2CAAiB,CAAA;IACjB,2CAAiB,CAAA;IACjB,iDAAuB,CAAA;IACvB,uDAA6B,CAAA;IAC7B,uDAA6B,CAAA;AAC/B,CAAC,EAPW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAOjC","file":"type.js","sourcesContent":["import type {\n IGroup,\n IGroupGraphicAttribute,\n IImageGraphicAttribute,\n IPolygonAttribute,\n IRichTextGraphicAttribute,\n ISymbolGraphicAttribute\n} from '@visactor/vrender-core';\nimport type { SegmentAttributes, SymbolAttributes } from '../segment';\nimport type { TagAttributes } from '../tag';\nimport type { Point } from '../core/type';\n\nexport enum IMarkLineLabelPosition {\n start = 'start',\n middle = 'middle',\n end = 'end',\n insideStartTop = 'insideStartTop',\n insideStartBottom = 'insideStartBottom',\n insideMiddleTop = 'insideMiddleTop',\n insideMiddleBottom = 'insideMiddleBottom',\n insideEndTop = 'insideEndTop',\n insideEndBottom = 'insideEndBottom'\n}\n\nexport enum IMarkAreaLabelPosition {\n left = 'left',\n right = 'right',\n top = 'top',\n bottom = 'bottom',\n middle = 'middle',\n insideLeft = 'insideLeft',\n insideRight = 'insideRight',\n insideTop = 'insideTop',\n insideBottom = 'insideBottom'\n}\n\nexport enum IMarkPointItemPosition {\n top = 'top',\n bottom = 'bottom',\n middle = 'middle',\n insideTop = 'insideTop',\n insideBottom = 'insideBottom',\n insideMiddle = 'insideMiddle'\n}\n\nexport type IMarkBackgroundAttributes = {\n /**\n * 是否绘制背景层\n */\n visible: boolean;\n /**\n * TODO: 根据文字宽度进行背景 panel size自适应\n */\n autoHeight?: boolean;\n /**\n * TODO: 根据文高度度进行背景 panel size自适应\n */\n autoWidth?: boolean;\n} & Partial<SymbolAttributes>;\n\nexport interface IMarkLabel extends Omit<TagAttributes, 'x' | 'y' | 'panel'> {\n /**\n * 标签的背景面板配置\n */\n panel?: IMarkBackgroundAttributes;\n}\n\nexport interface IMarkRef {\n /**\n * 自动旋转,沿着线的方向,默认 true\n */\n autoRotate?: boolean;\n /**\n * label 相对line平行方向上的偏移\n */\n refX?: number;\n /**\n * label 相对line正交方向上的偏移\n */\n refY?: number;\n /**\n * label 相对默认角度的偏移 (label跟随line的角度做自动旋转时,默认按照line的平行向量作为初始角度)\n */\n refAngle?: number;\n}\n\nexport interface MarkerAttrs extends IGroupGraphicAttribute {\n type?: 'line' | 'area' | 'point';\n /**\n * 是否支持交互\n * @default false\n */\n interactive?: boolean;\n /**\n * 是否显示marker组件\n * @default true\n */\n visible?: boolean;\n /**\n * 是否将组件在绘制区域内进行剪切\n * @default true\n */\n clipInRange?: boolean;\n /**\n * 组件绘制范围配置\n */\n limitRect?: {\n x: number;\n y: number;\n width: number;\n height: number;\n };\n}\n\nexport interface MarkLineAttrs extends MarkerAttrs, SegmentAttributes {\n type?: 'line';\n /**\n * 构成line的点: 如果是两个点,则为直线;多个点则为曲线\n */\n points: Point[] | Point[][];\n\n /**\n * 标签\n */\n label?: {\n /**\n * label 相对line的位置\n */\n position?: keyof typeof IMarkLineLabelPosition;\n /**\n * 当 mark 配置了 clip 之后,label 是否自动调整位置\n */\n confine?: boolean;\n } & IMarkRef &\n IMarkLabel;\n}\n\nexport interface MarkAreaAttrs extends MarkerAttrs {\n type?: 'area';\n /**\n * 构成area的点\n */\n points: Point[];\n /**\n * 标签\n */\n label?: {\n position?: keyof typeof IMarkAreaLabelPosition;\n /**\n * 当 mark 配置了 clip 之后,label 是否自动调整位置\n */\n confine?: boolean;\n } & IMarkLabel;\n /**\n * area的样式\n */\n areaStyle?: IPolygonAttribute;\n}\n\nexport interface IItemContent extends IMarkRef {\n /**\n * 标注类型\n */\n type?: 'symbol' | 'text' | 'image' | 'richText' | 'custom';\n position?: keyof typeof IMarkPointItemPosition;\n /**\n * x 方向偏移量\n */\n offsetX?: number;\n /**\n * y 方向偏移量\n */\n offsetY?: number;\n /**\n * type为symbol时, symbol的样式\n */\n symbolStyle?: ISymbolGraphicAttribute;\n /**\n * type为image时, image的样式\n */\n imageStyle?: IImageGraphicAttribute;\n /**\n * type为text时, text的配置\n */\n textStyle?: IMarkLabel;\n /**\n * type为rich text时, rich text的样式\n */\n richTextStyle?: IRichTextGraphicAttribute;\n /**\n * type为custom时,允许以callback的方式传入需要render的item\n */\n renderCustomCallback?: () => IGroup;\n // /**\n // * 当 mark 配置了 clip 之后,label 是否自动调整位置\n // */\n // confine?: boolean;\n}\n\nexport type IItemLine = {\n /** TODO:'type-opo' */\n type?: 'type-s' | 'type-do' | 'type-po' | 'type-op';\n visible?: boolean;\n /**\n * 垂直于引导线的装饰线,参考案例: https://observablehq.com/@mikelotis/edmonton-population-history-line-chart\n */\n decorativeLine?: {\n visible?: boolean;\n length?: number;\n };\n} & Omit<SegmentAttributes, 'points'>;\n\nexport interface MarkPointAttrs extends Omit<MarkerAttrs, 'labelStyle'> {\n /**\n * markPoint的位置(也是path的起点)\n */\n position: Point;\n /**\n * 标注引导线\n */\n itemLine?: IItemLine;\n\n /**\n * 标注内容\n */\n itemContent?: IItemContent;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/scrollbar/scrollbar.ts"],"names":[],"mappings":";;;AAIA,yDAA8D;AAC9D,6CAAkG;AAClG,uCAAiD;AAajD,MAAM,QAAQ,GAAG;IACf,QAAQ,EAAE,iBAAQ;IAClB,QAAQ,EAAE,iBAAQ;CACnB,CAAC;AAEF,MAAa,SAAU,SAAQ,wBAAgD;IAmC7E,YAAY,UAA+B;QACzC,KAAK,CAAC,IAAA,cAAK,EAAC,EAAE,EAAE,SAAS,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;QAnC5D,SAAI,GAAG,WAAW,CAAC;QAuOX,uBAAkB,GAAG,CAAC,CAAwB,EAAE,EAAE;;YAGxD,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;YAC3B,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,KA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ACD,OAAO,EAAE,CAAC;IACV,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IACnB,SAAS,EAAE,UAAU;IACrB,SAAS,EAAE,CAAC;IACZ,QAAQ,EAAE,IAAI;CACf,CAAC","file":"scrollbar.js","sourcesContent":["/**\n * @description 滚动条组件\n */\nimport type { IRectGraphicAttribute, FederatedPointerEvent, IGroup, IRect } from '@visactor/vrender-core';\nimport { CustomEvent, vglobal } from '@visactor/vrender-core';\nimport { merge, normalizePadding, clamp, clampRange, debounce, throttle } from '@visactor/vutils';\nimport { AbstractComponent } from '../core/base';\n\nimport type { ScrollBarAttributes } from './type';\n\ntype ComponentBounds = {\n x1: number;\n y1: number;\n x2: number;\n y2: number;\n width: number;\n height: number;\n};\n\nconst delayMap = {\n debounce: debounce,\n throttle: throttle\n};\n\nexport class ScrollBar extends AbstractComponent<Required<ScrollBarAttributes>> {\n name = 'scrollbar';\n\n static defaultAttributes = {\n direction: 'horizontal',\n round: true,\n sliderSize: 20,\n sliderStyle: {\n fill: 'rgba(0, 0, 0, .5)'\n },\n railStyle: {\n fill: 'rgba(0, 0, 0, .0)'\n },\n padding: 2,\n scrollRange: [0, 1],\n delayType: 'throttle',\n delayTime: 0,\n realTime: true\n };\n\n private _container!: IGroup;\n // 滚动条滑块\n private _slider!: IRect;\n // 滚动条滑轨\n private _rail!: IRect;\n // 滑块可渲染的区域包围盒\n private _sliderRenderBounds!: ComponentBounds | null;\n // 滑块滑动的范围\n private _sliderLimitRange!: [number, number] | null;\n // 保留滑块上一次的位置\n private _prePos!: number;\n // TODO: 临时方案\n private _viewPosition!: { x: number; y: number };\n private _sliderSize!: number;\n\n constructor(attributes: ScrollBarAttributes) {\n super(merge({}, ScrollBar.defaultAttributes, attributes));\n }\n\n setScrollRange(range: [number, number], render = true) {\n const {\n direction = 'horizontal',\n limitRange = [0, 1],\n range: preRange,\n realTime = true\n } = this.attribute as ScrollBarAttributes;\n\n const currScrollRange = clampRange(range, limitRange[0], limitRange[1]);\n if (render) {\n // 更新图形\n const sliderPos = this._getSliderPos(currScrollRange);\n if (this._slider) {\n if (direction === 'horizontal') {\n this._slider.setAttribute('x', sliderPos[0], true);\n } else {\n this._slider.setAttribute('y', sliderPos[0], true);\n }\n\n if (!this.stage?.autoRender) {\n this.stage?.renderNextFrame();\n }\n }\n }\n (this.attribute as ScrollBarAttributes).range = currScrollRange;\n // 发射 change 事件\n if (realTime) {\n this._onChange({\n pre: preRange,\n value: currScrollRange\n });\n }\n }\n\n getScrollRange(): [number, number] {\n return (this.attribute as ScrollBarAttributes).range;\n }\n\n // public setLocation(point: PointLocationCfg) {\n // this.translateTo(point.x, point.y);\n // }\n\n // 绑定事件\n protected bindEvents(): void {\n if (this.attribute.disableTriggerEvent) {\n return;\n }\n const { delayType = 'throttle', delayTime = 0 } = this.attribute as ScrollBarAttributes;\n // TODO: wheel 事件支持\n if (this._rail) {\n this._rail.addEventListener(\n 'pointerdown',\n delayMap[delayType](this._onRailPointerDown, delayTime) as EventListener\n );\n }\n if (this._slider) {\n this._slider.addEventListener('pointerdown', this._onSliderPointerDown as EventListener);\n }\n }\n\n protected render() {\n this._reset();\n const {\n direction = 'horizontal',\n width,\n height,\n range,\n limitRange = [0, 1],\n // sliderSize = 20,\n // scrollValue = 0,\n // scrollRange = [0, 1],\n railStyle,\n sliderStyle,\n padding = 2\n } = this.attribute as ScrollBarAttributes;\n\n const group = this.createOrUpdateChild('scrollbar-container', {}, 'group') as IGroup;\n // 绘制轨道\n\n const rail = group.createOrUpdateChild(\n 'scrollbar-rail',\n {\n x: 0,\n y: 0,\n width,\n height,\n ...railStyle\n },\n 'rect'\n ) as IRect;\n this._rail = rail;\n\n // 滑块\n const sliderRenderBounds = this._getSliderRenderBounds();\n const sliderPos = this._getSliderPos(clampRange(range, limitRange[0], limitRange[1]));\n const sliderSize = sliderPos[1] - sliderPos[0];\n this._sliderSize = sliderSize;\n // const sliderRangePos = this._getScrollRange();\n\n let sliderAttribute: IRectGraphicAttribute;\n if (direction === 'horizontal') {\n sliderAttribute = {\n x: sliderPos[0],\n y: sliderRenderBounds.y1,\n width: sliderSize,\n height: sliderRenderBounds.height\n };\n } else {\n sliderAttribute = {\n x: sliderRenderBounds.x1,\n y: sliderPos[0],\n width: sliderRenderBounds.width,\n height: sliderSize\n };\n }\n\n const slider = group.createOrUpdateChild(\n 'slider',\n {\n ...sliderAttribute,\n cornerRadius: this._getDefaultSliderCornerRadius(),\n ...sliderStyle,\n boundsPadding: normalizePadding(padding),\n pickMode: 'imprecise'\n },\n 'rect'\n ) as IRect;\n this._slider = slider;\n this._container = group;\n\n const containerAABBBounds = this._container.AABBBounds;\n this._viewPosition = {\n x: containerAABBBounds.x1,\n y: containerAABBBounds.y1\n };\n }\n\n // 获取滑块渲染的包围盒区域\n private _getSliderRenderBounds() {\n if (this._sliderRenderBounds) {\n return this._sliderRenderBounds;\n }\n const { width, height, padding = 2 } = this.attribute as ScrollBarAttributes;\n const [top, right, bottom, left] = normalizePadding(padding);\n const renderBounds = {\n x1: left,\n y1: top,\n x2: width - right,\n y2: height - bottom,\n width: width - (left + right),\n height: height - (top + bottom)\n };\n this._sliderRenderBounds = renderBounds;\n return renderBounds;\n }\n\n // 获取默认的滑块圆角\n private _getDefaultSliderCornerRadius() {\n const { direction, round } = this.attribute as ScrollBarAttributes;\n\n if (round) {\n const { width, height } = this._getSliderRenderBounds();\n return direction === 'horizontal' ? height : width;\n }\n\n return 0;\n }\n\n // 计算滑块在轨道的位置\n private _getSliderPos(range: [number, number]) {\n const { direction } = this.attribute as ScrollBarAttributes;\n const { width, height, x1, y1 } = this._getSliderRenderBounds();\n\n if (direction === 'horizontal') {\n return [width * range[0] + x1, width * range[1] + x1];\n }\n return [height * range[0] + y1, height * range[1] + y1];\n }\n\n private _getScrollRange() {\n if (this._sliderLimitRange) {\n return this._sliderLimitRange;\n }\n const { limitRange = [0, 1], direction } = this.attribute as ScrollBarAttributes;\n const [min, max] = clampRange(limitRange, 0, 1);\n const { width, height, x1, y1 } = this._getSliderRenderBounds();\n const sliderSize = this._sliderSize;\n\n return direction === 'horizontal'\n ? clampRange([x1 + min * width, x1 + max * width], x1, width - sliderSize)\n : clampRange([y1 + min * height, y1 + max * height], y1, height - sliderSize);\n }\n\n private _onRailPointerDown = (e: FederatedPointerEvent) => {\n // 将事件坐标转换为实际的滑块位置\n // TODO: 这里有问题,应该拿 viewX viewY,同时 graphic 要提供接口获取它的 相对 view 的坐标\n const { viewX, viewY } = e;\n const { direction, width, height, range } = this.attribute as ScrollBarAttributes;\n const sliderSize = this._sliderSize;\n const [min, max] = this._getScrollRange();\n let currentScrollValue;\n if (direction === 'vertical') {\n const relativeY = viewY - this._viewPosition.y;\n const currentYPos = clamp(relativeY - sliderSize / 2, min, max);\n currentScrollValue = relativeY / height;\n this._slider.setAttribute('y', currentYPos, true);\n } else {\n const relativeX = viewX - this._viewPosition.x;\n const currentXPos = clamp(relativeX - sliderSize / 2, min, max);\n currentScrollValue = relativeX / width;\n this._slider.setAttribute('x', currentXPos, true);\n }\n\n this.setScrollRange(\n [currentScrollValue - (range[1] - range[0]) / 2, currentScrollValue + (range[1] - range[0]) / 2],\n false\n );\n\n if (!this.stage?.autoRender) {\n this.stage?.renderNextFrame();\n }\n };\n\n private _onSliderPointerDown = (e: FederatedPointerEvent) => {\n e.stopPropagation();\n const { direction } = this.attribute as ScrollBarAttributes;\n this._prePos = direction === 'horizontal' ? e.clientX : e.clientY;\n if (vglobal.env === 'browser') {\n vglobal.addEventListener('pointermove', this._onSliderPointerMove, { capture: true });\n vglobal.addEventListener('pointerup', this._onSliderPointerUp);\n } else {\n this.stage.addEventListener('pointermove', this._onSliderPointerMove, { capture: true });\n this.stage.addEventListener('pointerup', this._onSliderPointerUp);\n this.stage.addEventListener('pointerupoutside', this._onSliderPointerUp);\n }\n };\n\n private _computeScrollValue = (e: any) => {\n const { direction } = this.attribute as ScrollBarAttributes;\n let currentScrollValue;\n let currentPos;\n let delta = 0;\n\n const { width, height } = this._getSliderRenderBounds();\n if (direction === 'vertical') {\n currentPos = e.clientY;\n delta = currentPos - this._prePos;\n currentScrollValue = delta / height;\n } else {\n currentPos = e.clientX;\n delta = currentPos - this._prePos;\n currentScrollValue = delta / width;\n }\n return [currentPos, currentScrollValue];\n };\n\n private _onSliderPointerMove = delayMap[this.attribute.delayType]((e: any) => {\n e.stopPropagation();\n const preScrollRange = this.getScrollRange();\n const [currentPos, currentScrollValue] = this._computeScrollValue(e);\n this.setScrollRange([preScrollRange[0] + currentScrollValue, preScrollRange[1] + currentScrollValue], true);\n this._prePos = currentPos;\n }, this.attribute.delayTime);\n\n private _onSliderPointerUp = (e: any) => {\n e.preventDefault();\n const { realTime = true, range: preRange, limitRange = [0, 1] } = this.attribute as ScrollBarAttributes;\n // 发射 change 事件\n const preScrollRange = this.getScrollRange();\n const [currentPos, currentScrollValue] = this._computeScrollValue(e);\n const range: [number, number] = [preScrollRange[0] + currentScrollValue, preScrollRange[1] + currentScrollValue];\n if (!realTime) {\n this._onChange({\n pre: preRange,\n value: clampRange(range, limitRange[0], limitRange[1])\n });\n }\n if (vglobal.env === 'browser') {\n vglobal.removeEventListener('pointermove', this._onSliderPointerMove, { capture: true });\n vglobal.removeEventListener('pointerup', this._onSliderPointerUp);\n } else {\n this.stage.removeEventListener('pointermove', this._onSliderPointerMove, { capture: true });\n this.stage.removeEventListener('pointerup', this._onSliderPointerUp);\n this.stage.removeEventListener('pointerupoutside', this._onSliderPointerUp);\n }\n };\n\n private _onChange(detail: any) {\n const changeEvent = new CustomEvent('scroll', detail);\n // FIXME: 需要在 vrender 的事件系统支持\n // @ts-ignore\n changeEvent.manager = this.stage?.eventSystem.manager;\n this.dispatchEvent(changeEvent);\n }\n\n private _reset() {\n this._sliderRenderBounds = null;\n this._sliderLimitRange = null;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/scrollbar/scrollbar.ts"],"names":[],"mappings":";;;AAKA,yDAA8D;AAC9D,6CAAkG;AAClG,uCAAiD;AAajD,MAA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A,IAAI,CAAC,KAAK,0CAAE,WAAW,CAAC,OAAO,CAAC;QACtD,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;IAClC,CAAC;IAEO,MAAM;QACZ,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;QAChC,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAChC,CAAC;;AAjVH,8BAkVC;AA/UQ,2BAAiB,GAAG;IACzB,SAAS,EAAE,YAAY;IACvB,KAAK,EAAE,IAAI;IACX,UAAU,EAAE,EAAE;IACd,WAAW,EAAE;QACX,IAAI,EAAE,mBAAmB;KAC1B;IACD,SAAS,EAAE;QACT,IAAI,EAAE,mBAAmB;KAC1B;IACD,OAAO,EAAE,CAAC;IACV,WAAW,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IACnB,SAAS,EAAE,UAAU;IACrB,SAAS,EAAE,CAAC;IACZ,QAAQ,EAAE,IAAI;CACf,CAAC","file":"scrollbar.js","sourcesContent":["/**\n * @description 滚动条组件\n */\nimport type { IRectGraphicAttribute, FederatedPointerEvent, IGroup, IRect } from '@visactor/vrender-core';\n// eslint-disable-next-line no-duplicate-imports\nimport { CustomEvent, vglobal } from '@visactor/vrender-core';\nimport { merge, normalizePadding, clamp, clampRange, debounce, throttle } from '@visactor/vutils';\nimport { AbstractComponent } from '../core/base';\n\nimport type { ScrollBarAttributes } from './type';\n\ntype ComponentBounds = {\n x1: number;\n y1: number;\n x2: number;\n y2: number;\n width: number;\n height: number;\n};\n\nconst delayMap = {\n debounce: debounce,\n throttle: throttle\n};\n\nexport class ScrollBar extends AbstractComponent<Required<ScrollBarAttributes>> {\n name = 'scrollbar';\n\n static defaultAttributes = {\n direction: 'horizontal',\n round: true,\n sliderSize: 20,\n sliderStyle: {\n fill: 'rgba(0, 0, 0, .5)'\n },\n railStyle: {\n fill: 'rgba(0, 0, 0, .0)'\n },\n padding: 2,\n scrollRange: [0, 1],\n delayType: 'throttle',\n delayTime: 0,\n realTime: true\n };\n\n private _container!: IGroup;\n // 滚动条滑块\n private _slider!: IRect;\n // 滚动条滑轨\n private _rail!: IRect;\n // 滑块可渲染的区域包围盒\n private _sliderRenderBounds!: ComponentBounds | null;\n // 滑块滑动的范围\n private _sliderLimitRange!: [number, number] | null;\n // 保留滑块上一次的位置\n private _prePos!: number;\n // TODO: 临时方案\n private _viewPosition!: { x: number; y: number };\n private _sliderSize!: number;\n\n constructor(attributes: ScrollBarAttributes) {\n super(merge({}, ScrollBar.defaultAttributes, attributes));\n }\n\n setScrollRange(range: [number, number], render = true) {\n const {\n direction = 'horizontal',\n limitRange = [0, 1],\n range: preRange,\n realTime = true\n } = this.attribute as ScrollBarAttributes;\n\n const currScrollRange = clampRange(range, limitRange[0], limitRange[1]);\n if (render) {\n // 更新图形\n const sliderPos = this._getSliderPos(currScrollRange);\n if (this._slider) {\n if (direction === 'horizontal') {\n this._slider.setAttribute('x', sliderPos[0], true);\n } else {\n this._slider.setAttribute('y', sliderPos[0], true);\n }\n\n if (!this.stage?.autoRender) {\n this.stage?.renderNextFrame();\n }\n }\n }\n (this.attribute as ScrollBarAttributes).range = currScrollRange;\n // 发射 change 事件\n if (realTime) {\n this._onChange({\n pre: preRange,\n value: currScrollRange\n });\n }\n }\n\n getScrollRange(): [number, number] {\n return (this.attribute as ScrollBarAttributes).range;\n }\n\n // public setLocation(point: PointLocationCfg) {\n // this.translateTo(point.x, point.y);\n // }\n\n // 绑定事件\n protected bindEvents(): void {\n if (this.attribute.disableTriggerEvent) {\n return;\n }\n const { delayType = 'throttle', delayTime = 0 } = this.attribute as ScrollBarAttributes;\n // TODO: wheel 事件支持\n if (this._rail) {\n this._rail.addEventListener(\n 'pointerdown',\n delayMap[delayType](this._onRailPointerDown, delayTime) as EventListener\n );\n }\n if (this._slider) {\n this._slider.addEventListener('pointerdown', this._onSliderPointerDown as EventListener);\n }\n }\n\n protected render() {\n this._reset();\n const {\n direction = 'horizontal',\n width,\n height,\n range,\n limitRange = [0, 1],\n // sliderSize = 20,\n // scrollValue = 0,\n // scrollRange = [0, 1],\n railStyle,\n sliderStyle,\n padding = 2\n } = this.attribute as ScrollBarAttributes;\n\n const group = this.createOrUpdateChild('scrollbar-container', {}, 'group') as IGroup;\n // 绘制轨道\n\n const rail = group.createOrUpdateChild(\n 'scrollbar-rail',\n {\n x: 0,\n y: 0,\n width,\n height,\n ...railStyle\n },\n 'rect'\n ) as IRect;\n this._rail = rail;\n\n // 滑块\n const sliderRenderBounds = this._getSliderRenderBounds();\n const sliderPos = this._getSliderPos(clampRange(range, limitRange[0], limitRange[1]));\n const sliderSize = sliderPos[1] - sliderPos[0];\n this._sliderSize = sliderSize;\n // const sliderRangePos = this._getScrollRange();\n\n let sliderAttribute: IRectGraphicAttribute;\n if (direction === 'horizontal') {\n sliderAttribute = {\n x: sliderPos[0],\n y: sliderRenderBounds.y1,\n width: sliderSize,\n height: sliderRenderBounds.height\n };\n } else {\n sliderAttribute = {\n x: sliderRenderBounds.x1,\n y: sliderPos[0],\n width: sliderRenderBounds.width,\n height: sliderSize\n };\n }\n\n const slider = group.createOrUpdateChild(\n 'slider',\n {\n ...sliderAttribute,\n cornerRadius: this._getDefaultSliderCornerRadius(),\n ...sliderStyle,\n boundsPadding: normalizePadding(padding),\n pickMode: 'imprecise'\n },\n 'rect'\n ) as IRect;\n this._slider = slider;\n this._container = group;\n\n const containerAABBBounds = this._container.AABBBounds;\n this._viewPosition = {\n x: containerAABBBounds.x1,\n y: containerAABBBounds.y1\n };\n }\n\n // 获取滑块渲染的包围盒区域\n private _getSliderRenderBounds() {\n if (this._sliderRenderBounds) {\n return this._sliderRenderBounds;\n }\n const { width, height, padding = 2 } = this.attribute as ScrollBarAttributes;\n const [top, right, bottom, left] = normalizePadding(padding);\n const renderBounds = {\n x1: left,\n y1: top,\n x2: width - right,\n y2: height - bottom,\n width: width - (left + right),\n height: height - (top + bottom)\n };\n this._sliderRenderBounds = renderBounds;\n return renderBounds;\n }\n\n // 获取默认的滑块圆角\n private _getDefaultSliderCornerRadius() {\n const { direction, round } = this.attribute as ScrollBarAttributes;\n\n if (round) {\n const { width, height } = this._getSliderRenderBounds();\n return direction === 'horizontal' ? height : width;\n }\n\n return 0;\n }\n\n // 计算滑块在轨道的位置\n private _getSliderPos(range: [number, number]) {\n const { direction } = this.attribute as ScrollBarAttributes;\n const { width, height, x1, y1 } = this._getSliderRenderBounds();\n\n if (direction === 'horizontal') {\n return [width * range[0] + x1, width * range[1] + x1];\n }\n return [height * range[0] + y1, height * range[1] + y1];\n }\n\n private _getScrollRange() {\n if (this._sliderLimitRange) {\n return this._sliderLimitRange;\n }\n const { limitRange = [0, 1], direction } = this.attribute as ScrollBarAttributes;\n const [min, max] = clampRange(limitRange, 0, 1);\n const { width, height, x1, y1 } = this._getSliderRenderBounds();\n const sliderSize = this._sliderSize;\n\n return direction === 'horizontal'\n ? clampRange([x1 + min * width, x1 + max * width], x1, width - sliderSize)\n : clampRange([y1 + min * height, y1 + max * height], y1, height - sliderSize);\n }\n\n private _onRailPointerDown = (e: FederatedPointerEvent) => {\n // 将事件坐标转换为实际的滑块位置\n // TODO: 这里有问题,应该拿 viewX viewY,同时 graphic 要提供接口获取它的 相对 view 的坐标\n const { viewX, viewY } = e;\n const { direction, width, height, range } = this.attribute as ScrollBarAttributes;\n const sliderSize = this._sliderSize;\n const [min, max] = this._getScrollRange();\n let currentScrollValue;\n if (direction === 'vertical') {\n const relativeY = viewY - this._viewPosition.y;\n const currentYPos = clamp(relativeY - sliderSize / 2, min, max);\n currentScrollValue = relativeY / height;\n this._slider.setAttribute('y', currentYPos, true);\n } else {\n const relativeX = viewX - this._viewPosition.x;\n const currentXPos = clamp(relativeX - sliderSize / 2, min, max);\n currentScrollValue = relativeX / width;\n this._slider.setAttribute('x', currentXPos, true);\n }\n\n this.setScrollRange(\n [currentScrollValue - (range[1] - range[0]) / 2, currentScrollValue + (range[1] - range[0]) / 2],\n false\n );\n\n if (!this.stage?.autoRender) {\n this.stage?.renderNextFrame();\n }\n };\n\n private _onSliderPointerDown = (e: FederatedPointerEvent) => {\n e.stopPropagation();\n const { direction } = this.attribute as ScrollBarAttributes;\n this._prePos = direction === 'horizontal' ? e.clientX : e.clientY;\n if (vglobal.env === 'browser') {\n vglobal.addEventListener('pointermove', this._onSliderPointerMove, { capture: true });\n vglobal.addEventListener('pointerup', this._onSliderPointerUp);\n } else {\n this.stage.addEventListener('pointermove', this._onSliderPointerMove, { capture: true });\n this.stage.addEventListener('pointerup', this._onSliderPointerUp);\n this.stage.addEventListener('pointerupoutside', this._onSliderPointerUp);\n }\n };\n\n private _computeScrollValue = (e: any) => {\n const { direction } = this.attribute as ScrollBarAttributes;\n let currentScrollValue;\n let currentPos;\n let delta = 0;\n\n const { width, height } = this._getSliderRenderBounds();\n if (direction === 'vertical') {\n currentPos = e.clientY;\n delta = currentPos - this._prePos;\n currentScrollValue = delta / height;\n } else {\n currentPos = e.clientX;\n delta = currentPos - this._prePos;\n currentScrollValue = delta / width;\n }\n return [currentPos, currentScrollValue];\n };\n\n private _onSliderPointerMove = delayMap[this.attribute.delayType]((e: any) => {\n e.stopPropagation();\n const preScrollRange = this.getScrollRange();\n const [currentPos, currentScrollValue] = this._computeScrollValue(e);\n this.setScrollRange([preScrollRange[0] + currentScrollValue, preScrollRange[1] + currentScrollValue], true);\n this._prePos = currentPos;\n }, this.attribute.delayTime);\n\n private _onSliderPointerUp = (e: any) => {\n e.preventDefault();\n const { realTime = true, range: preRange, limitRange = [0, 1] } = this.attribute as ScrollBarAttributes;\n // 发射 change 事件\n const preScrollRange = this.getScrollRange();\n const [currentPos, currentScrollValue] = this._computeScrollValue(e);\n const range: [number, number] = [preScrollRange[0] + currentScrollValue, preScrollRange[1] + currentScrollValue];\n if (!realTime) {\n this._onChange({\n pre: preRange,\n value: clampRange(range, limitRange[0], limitRange[1])\n });\n }\n if (vglobal.env === 'browser') {\n vglobal.removeEventListener('pointermove', this._onSliderPointerMove, { capture: true });\n vglobal.removeEventListener('pointerup', this._onSliderPointerUp);\n } else {\n this.stage.removeEventListener('pointermove', this._onSliderPointerMove, { capture: true });\n this.stage.removeEventListener('pointerup', this._onSliderPointerUp);\n this.stage.removeEventListener('pointerupoutside', this._onSliderPointerUp);\n }\n };\n\n private _onChange(detail: any) {\n const changeEvent = new CustomEvent('scroll', detail);\n // FIXME: 需要在 vrender 的事件系统支持\n // @ts-ignore\n changeEvent.manager = this.stage?.eventSystem.manager;\n this.dispatchEvent(changeEvent);\n }\n\n private _reset() {\n this._sliderRenderBounds = null;\n this._sliderLimitRange = null;\n }\n}\n"]}
|
package/cjs/tag/tag.js
CHANGED
|
@@ -21,8 +21,8 @@ class Tag extends base_1.AbstractComponent {
|
|
|
21
21
|
super((0, vutils_1.merge)({}, Tag.defaultAttributes, attributes)), this.name = "tag";
|
|
22
22
|
}
|
|
23
23
|
render() {
|
|
24
|
-
var _a
|
|
25
|
-
const {text: text = "", textStyle: textStyle = {}, shape: shape = {}, panel: panel = {}, space: space = 4, minWidth: minWidth, maxWidth: maxWidth, padding: padding = 4, visible: visible, state: state
|
|
24
|
+
var _a;
|
|
25
|
+
const {text: text = "", textStyle: textStyle = {}, shape: shape = {}, panel: panel = {}, space: space = 4, minWidth: minWidth, maxWidth: maxWidth, padding: padding = 4, visible: visible, state: state} = this.attribute, parsedPadding = (0,
|
|
26
26
|
vutils_1.normalizePadding)(padding), group = this.createOrUpdateChild("tag-content", {
|
|
27
27
|
x: 0,
|
|
28
28
|
y: 0,
|
|
@@ -44,94 +44,44 @@ class Tag extends base_1.AbstractComponent {
|
|
|
44
44
|
}), "symbol"), (0, vutils_1.isEmpty)(null == state ? void 0 : state.shape) || (symbol.states = state.shape),
|
|
45
45
|
shapeVisible && (symbolPlaceWidth = maxSize + space);
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
textShape = group.createOrUpdateChild("tag-text", richTextAttrs, "richtext");
|
|
86
|
-
const {visible: bgVisible} = panel, backgroundStyle = __rest(panel, [ "visible" ]);
|
|
87
|
-
if (visible && (0, vutils_1.isBoolean)(bgVisible)) {
|
|
88
|
-
const bgRect = this.createOrUpdateChild("tag-panel", Object.assign(Object.assign({}, backgroundStyle), {
|
|
89
|
-
visible: bgVisible && !!text,
|
|
90
|
-
x: textShape.AABBBounds.x1,
|
|
91
|
-
y: textShape.AABBBounds.y1,
|
|
92
|
-
width: textShape.AABBBounds.width(),
|
|
93
|
-
height: textShape.AABBBounds.height()
|
|
94
|
-
}), "rect");
|
|
95
|
-
(0, vutils_1.isEmpty)(null == state ? void 0 : state.panel) || (bgRect.states = state.panel);
|
|
96
|
-
}
|
|
97
|
-
} else {
|
|
98
|
-
const textAttrs = Object.assign(Object.assign({
|
|
99
|
-
text: text,
|
|
100
|
-
visible: (0, vutils_1.isValid)(text) && !1 !== visible,
|
|
101
|
-
lineHeight: null == textStyle ? void 0 : textStyle.fontSize
|
|
102
|
-
}, textStyle), {
|
|
103
|
-
x: textX,
|
|
104
|
-
y: 0
|
|
105
|
-
});
|
|
106
|
-
(0, vutils_1.isNil)(textAttrs.lineHeight) && (textAttrs.lineHeight = textStyle.fontSize),
|
|
107
|
-
textShape = group.createOrUpdateChild("tag-text", textAttrs, "text"), (0, vutils_1.isEmpty)(null == state ? void 0 : state.text) || (textShape.states = state.text);
|
|
108
|
-
const textBounds = (0, util_1.measureTextSize)(textAttrs.text, textStyle), textWidth = textBounds.width, textHeight = textBounds.height;
|
|
109
|
-
tagWidth += textWidth;
|
|
110
|
-
const size = null !== (_c = shape.size) && void 0 !== _c ? _c : 10, maxSize = (0,
|
|
111
|
-
vutils_1.isNumber)(size) ? size : Math.max(size[0], size[1]);
|
|
112
|
-
tagHeight += Math.max(textHeight, (null == shape ? void 0 : shape.visible) ? maxSize : 0);
|
|
113
|
-
const {textAlign: textAlign, textBaseline: textBaseline} = textStyle;
|
|
114
|
-
((0, vutils_1.isValid)(minWidth) || (0, vutils_1.isValid)(maxWidth)) && ((0, vutils_1.isValid)(minWidth) && tagWidth < minWidth && (tagWidth = minWidth),
|
|
115
|
-
(0, vutils_1.isValid)(maxWidth) && tagWidth > maxWidth && (tagWidth = maxWidth,
|
|
116
|
-
textShape.setAttribute("maxLineWidth", maxWidth - parsedPadding[1] - parsedPadding[2])));
|
|
117
|
-
let x = 0, y = 0;
|
|
118
|
-
"center" === textAlign ? (x -= tagWidth / 2, symbol && symbol.setAttribute("x", (symbol.attribute.x || 0) - textWidth / 2),
|
|
119
|
-
group.setAttribute("x", -symbolPlaceWidth / 2)) : "right" === textAlign || "end" === textAlign ? (x -= tagWidth,
|
|
120
|
-
symbol && symbol.setAttribute("x", (symbol.attribute.x || 0) - textWidth), group.setAttribute("x", -parsedPadding[1] - symbolPlaceWidth)) : "left" !== textAlign && "start" !== textAlign || group.setAttribute("x", parsedPadding[3]),
|
|
121
|
-
"middle" === textBaseline ? (y -= tagHeight / 2, symbol && symbol.setAttribute("y", 0)) : "bottom" === textBaseline ? (y -= tagHeight,
|
|
122
|
-
symbol && symbol.setAttribute("y", -textHeight / 2), group.setAttribute("y", -parsedPadding[2])) : "top" === textBaseline && (group.setAttribute("y", parsedPadding[0]),
|
|
123
|
-
symbol && symbol.setAttribute("y", textHeight / 2));
|
|
124
|
-
const {visible: bgVisible} = panel, backgroundStyle = __rest(panel, [ "visible" ]);
|
|
125
|
-
if (visible && (0, vutils_1.isBoolean)(bgVisible)) {
|
|
126
|
-
const bgRect = this.createOrUpdateChild("tag-panel", Object.assign(Object.assign({}, backgroundStyle), {
|
|
127
|
-
visible: bgVisible && !!text,
|
|
128
|
-
x: x,
|
|
129
|
-
y: y,
|
|
130
|
-
width: tagWidth,
|
|
131
|
-
height: tagHeight
|
|
132
|
-
}), "rect");
|
|
133
|
-
(0, vutils_1.isEmpty)(null == state ? void 0 : state.panel) || (bgRect.states = state.panel);
|
|
134
|
-
}
|
|
47
|
+
tagWidth += symbolPlaceWidth, textX += symbolPlaceWidth;
|
|
48
|
+
const textAttrs = Object.assign(Object.assign({
|
|
49
|
+
text: text,
|
|
50
|
+
visible: (0, vutils_1.isValid)(text) && !1 !== visible,
|
|
51
|
+
lineHeight: null == textStyle ? void 0 : textStyle.fontSize
|
|
52
|
+
}, textStyle), {
|
|
53
|
+
x: textX,
|
|
54
|
+
y: 0
|
|
55
|
+
});
|
|
56
|
+
(0, vutils_1.isNil)(textAttrs.lineHeight) && (textAttrs.lineHeight = textAttrs.fontSize);
|
|
57
|
+
const textShape = group.createOrUpdateChild("tag-text", textAttrs, "text");
|
|
58
|
+
(0, vutils_1.isEmpty)(null == state ? void 0 : state.text) || (textShape.states = state.text);
|
|
59
|
+
const textBounds = (0, util_1.measureTextSize)(textAttrs.text, textStyle), textWidth = textBounds.width, textHeight = textBounds.height;
|
|
60
|
+
tagWidth += textWidth;
|
|
61
|
+
const size = null !== (_a = shape.size) && void 0 !== _a ? _a : 10, maxSize = (0,
|
|
62
|
+
vutils_1.isNumber)(size) ? size : Math.max(size[0], size[1]);
|
|
63
|
+
tagHeight += Math.max(textHeight, (null == shape ? void 0 : shape.visible) ? maxSize : 0);
|
|
64
|
+
const {textAlign: textAlign, textBaseline: textBaseline} = textStyle;
|
|
65
|
+
((0, vutils_1.isValid)(minWidth) || (0, vutils_1.isValid)(maxWidth)) && ((0, vutils_1.isValid)(minWidth) && tagWidth < minWidth && (tagWidth = minWidth),
|
|
66
|
+
(0, vutils_1.isValid)(maxWidth) && tagWidth > maxWidth && (tagWidth = maxWidth,
|
|
67
|
+
textShape.setAttribute("maxLineWidth", maxWidth - parsedPadding[1] - parsedPadding[2])));
|
|
68
|
+
let x = 0, y = 0;
|
|
69
|
+
"center" === textAlign ? (x -= tagWidth / 2, symbol && symbol.setAttribute("x", (symbol.attribute.x || 0) - textWidth / 2),
|
|
70
|
+
group.setAttribute("x", -symbolPlaceWidth / 2)) : "right" === textAlign || "end" === textAlign ? (x -= tagWidth,
|
|
71
|
+
symbol && symbol.setAttribute("x", (symbol.attribute.x || 0) - textWidth), group.setAttribute("x", -parsedPadding[1] - symbolPlaceWidth)) : "left" !== textAlign && "start" !== textAlign || group.setAttribute("x", parsedPadding[3]),
|
|
72
|
+
"middle" === textBaseline ? (y -= tagHeight / 2, symbol && symbol.setAttribute("y", 0)) : "bottom" === textBaseline ? (y -= tagHeight,
|
|
73
|
+
symbol && symbol.setAttribute("y", -textHeight / 2), group.setAttribute("y", -parsedPadding[2])) : "top" === textBaseline && (group.setAttribute("y", parsedPadding[0]),
|
|
74
|
+
symbol && symbol.setAttribute("y", textHeight / 2));
|
|
75
|
+
const {visible: bgVisible} = panel, backgroundStyle = __rest(panel, [ "visible" ]);
|
|
76
|
+
if (visible && (0, vutils_1.isBoolean)(bgVisible)) {
|
|
77
|
+
const bgRect = this.createOrUpdateChild("tag-panel", Object.assign(Object.assign({}, backgroundStyle), {
|
|
78
|
+
visible: bgVisible && !!text,
|
|
79
|
+
x: x,
|
|
80
|
+
y: y,
|
|
81
|
+
width: tagWidth,
|
|
82
|
+
height: tagHeight
|
|
83
|
+
}), "rect");
|
|
84
|
+
(0, vutils_1.isEmpty)(null == state ? void 0 : state.panel) || (bgRect.states = state.panel);
|
|
135
85
|
}
|
|
136
86
|
}
|
|
137
87
|
}
|