@visactor/vrender-components 0.20.0-alpha.1 → 0.20.0-alpha.3
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/brush/brush.js +2 -1
- package/cjs/brush/type.js +1 -2
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +5 -4
- package/cjs/index.js.map +1 -1
- package/cjs/indicator/indicator.d.ts +3 -1
- package/cjs/indicator/indicator.js +19 -41
- package/cjs/indicator/indicator.js.map +1 -1
- package/cjs/indicator/type.d.ts +1 -0
- package/cjs/indicator/type.js.map +1 -1
- package/cjs/interface.d.ts +2 -1
- package/cjs/interface.js.map +1 -1
- package/cjs/label/arc.js +13 -6
- package/cjs/label/arc.js.map +1 -1
- package/cjs/label/base.js +4 -0
- package/cjs/label/base.js.map +1 -1
- package/cjs/label/type.d.ts +2 -1
- package/cjs/label/type.js.map +1 -1
- package/cjs/label/util.d.ts +1 -5
- package/cjs/label/util.js +1 -34
- package/cjs/label/util.js.map +1 -1
- package/cjs/marker/point.js +4 -3
- package/cjs/marker/point.js.map +1 -1
- package/cjs/tag/tag.d.ts +1 -1
- package/cjs/tag/tag.js +11 -3
- package/cjs/tag/tag.js.map +1 -1
- package/cjs/timeline/index.d.ts +2 -0
- package/cjs/timeline/index.js +21 -0
- package/cjs/timeline/index.js.map +1 -0
- package/cjs/timeline/register.d.ts +1 -0
- package/cjs/timeline/register.js +15 -0
- package/cjs/timeline/register.js.map +1 -0
- package/cjs/timeline/timeline.d.ts +30 -0
- package/cjs/timeline/timeline.js +178 -0
- package/cjs/timeline/timeline.js.map +1 -0
- package/cjs/timeline/type.d.ts +18 -0
- package/cjs/timeline/type.js +6 -0
- package/cjs/timeline/type.js.map +1 -0
- package/cjs/util/index.d.ts +1 -0
- package/cjs/util/index.js +1 -1
- package/cjs/util/index.js.map +1 -1
- package/dist/index.es.js +2870 -2724
- package/es/brush/brush.js +2 -1
- package/es/brush/type.js +1 -2
- package/es/index.d.ts +2 -1
- package/es/index.js +3 -1
- package/es/index.js.map +1 -1
- package/es/indicator/indicator.d.ts +3 -1
- package/es/indicator/indicator.js +19 -40
- package/es/indicator/indicator.js.map +1 -1
- package/es/indicator/type.d.ts +1 -0
- package/es/indicator/type.js.map +1 -1
- package/es/interface.d.ts +2 -1
- package/es/interface.js.map +1 -1
- package/es/label/arc.js +14 -7
- package/es/label/arc.js.map +1 -1
- package/es/label/base.js +5 -1
- package/es/label/base.js.map +1 -1
- package/es/label/type.d.ts +2 -1
- package/es/label/type.js.map +1 -1
- package/es/label/util.d.ts +1 -5
- package/es/label/util.js +0 -31
- package/es/label/util.js.map +1 -1
- package/es/marker/point.js +4 -3
- package/es/marker/point.js.map +1 -1
- package/es/tag/tag.d.ts +1 -1
- package/es/tag/tag.js +12 -2
- package/es/tag/tag.js.map +1 -1
- package/es/timeline/index.d.ts +2 -0
- package/es/timeline/index.js +4 -0
- package/es/timeline/index.js.map +1 -0
- package/es/timeline/register.d.ts +1 -0
- package/es/timeline/register.js +6 -0
- package/es/timeline/register.js.map +1 -0
- package/es/timeline/timeline.d.ts +30 -0
- package/es/timeline/timeline.js +175 -0
- package/es/timeline/timeline.js.map +1 -0
- package/es/timeline/type.d.ts +18 -0
- package/es/timeline/type.js +2 -0
- package/es/timeline/type.js.map +1 -0
- package/es/util/index.d.ts +1 -0
- package/es/util/index.js +2 -0
- package/es/util/index.js.map +1 -1
- package/package.json +4 -4
package/es/brush/brush.js
CHANGED
package/es/brush/type.js
CHANGED
|
@@ -4,5 +4,4 @@ export var IOperateType;
|
|
|
4
4
|
IOperateType.drawStart = "drawStart", IOperateType.drawEnd = "drawEnd", IOperateType.drawing = "drawing",
|
|
5
5
|
IOperateType.moving = "moving", IOperateType.moveStart = "moveStart", IOperateType.moveEnd = "moveEnd",
|
|
6
6
|
IOperateType.brushClear = "brushClear";
|
|
7
|
-
}(IOperateType || (IOperateType = {}));
|
|
8
|
-
//# sourceMappingURL=type.js.map
|
|
7
|
+
}(IOperateType || (IOperateType = {}));
|
package/es/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const version = "0.20.0-alpha.
|
|
1
|
+
export declare const version = "0.20.0-alpha.3";
|
|
2
2
|
export * from './core/base';
|
|
3
3
|
export * from './core/type';
|
|
4
4
|
export * from './scrollbar';
|
|
@@ -20,6 +20,7 @@ export * from './link-path';
|
|
|
20
20
|
export * from './player';
|
|
21
21
|
export * from './brush';
|
|
22
22
|
export * from './tooltip';
|
|
23
|
+
export * from './timeline';
|
|
23
24
|
export * from './interface';
|
|
24
25
|
export * from './jsx';
|
|
25
26
|
export * from './checkbox';
|
package/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const version = "0.20.0-alpha.
|
|
1
|
+
export const version = "0.20.0-alpha.3";
|
|
2
2
|
|
|
3
3
|
export * from "./core/base";
|
|
4
4
|
|
|
@@ -42,6 +42,8 @@ export * from "./brush";
|
|
|
42
42
|
|
|
43
43
|
export * from "./tooltip";
|
|
44
44
|
|
|
45
|
+
export * from "./timeline";
|
|
46
|
+
|
|
45
47
|
export * from "./interface";
|
|
46
48
|
|
|
47
49
|
export * from "./jsx";
|
package/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC;AAExC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC","file":"index.js","sourcesContent":["// 导出版本号\nexport const version = \"0.20.0-alpha.
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC;AAExC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC","file":"index.js","sourcesContent":["// 导出版本号\nexport const version = \"0.20.0-alpha.3\";\n\nexport * from './core/base';\nexport * from './core/type';\nexport * from './scrollbar';\nexport * from './tag';\nexport * from './poptip';\nexport * from './crosshair';\nexport * from './label';\nexport * from './axis';\nexport * from './axis/grid';\nexport * from './segment';\nexport * from './data-zoom';\nexport * from './marker';\nexport * from './pager';\nexport * from './legend';\nexport * from './title';\nexport * from './indicator';\nexport * from './slider';\nexport * from './link-path';\nexport * from './player';\nexport * from './brush';\nexport * from './tooltip';\nexport * from './timeline';\nexport * from './interface';\nexport * from './jsx';\nexport * from './checkbox';\nexport * from './radio';\nexport * from './empty-tip';\nexport * from './util';\n"]}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import type { IGroup, IRichText, IText } from '@visactor/vrender-core';
|
|
1
2
|
import { AbstractComponent } from '../core/base';
|
|
2
|
-
import type { IndicatorAttributes } from './type';
|
|
3
|
+
import type { IndicatorAttributes, IndicatorItemSpec } from './type';
|
|
3
4
|
export declare class Indicator extends AbstractComponent<Required<IndicatorAttributes>> {
|
|
4
5
|
name: string;
|
|
5
6
|
private _title?;
|
|
6
7
|
private _content?;
|
|
8
|
+
protected _renderText(group: IGroup, title: IndicatorItemSpec, limit: number, limitRatio: number, themePath: string, graphicName: string): IRichText | IText;
|
|
7
9
|
protected render(): void;
|
|
8
10
|
private _setLocalAutoFit;
|
|
9
11
|
private _setGlobalAutoFit;
|
|
@@ -2,7 +2,7 @@ import { merge, isValid, array, isValidNumber, get } from "@visactor/vutils";
|
|
|
2
2
|
|
|
3
3
|
import { AbstractComponent } from "../core/base";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { createTextGraphicByType, measureTextSize } from "../util";
|
|
6
6
|
|
|
7
7
|
import { DEFAULT_INDICATOR_THEME } from "./config";
|
|
8
8
|
|
|
@@ -14,53 +14,32 @@ export class Indicator extends AbstractComponent {
|
|
|
14
14
|
constructor() {
|
|
15
15
|
super(...arguments), this.name = "indicator";
|
|
16
16
|
}
|
|
17
|
+
_renderText(group, title, limit, limitRatio, themePath, graphicName) {
|
|
18
|
+
if (!1 !== title.visible) {
|
|
19
|
+
const titleStyle = merge({}, get(DEFAULT_INDICATOR_THEME, themePath), title.style, {
|
|
20
|
+
visible: title.visible
|
|
21
|
+
});
|
|
22
|
+
titleStyle.lineHeight = isValid(titleStyle.lineHeight) ? titleStyle.lineHeight : titleStyle.fontSize,
|
|
23
|
+
title.formatMethod && (titleStyle._originText = titleStyle.text, titleStyle.text = title.formatMethod(titleStyle.text, titleStyle));
|
|
24
|
+
const textGraphic = createTextGraphicByType(titleStyle);
|
|
25
|
+
return textGraphic.name = graphicName, group.appendChild(textGraphic), title.autoFit && isValidNumber(limit) && this._setLocalAutoFit(limit, textGraphic, title),
|
|
26
|
+
title.autoLimit && isValidNumber(limitRatio) && textGraphic.setAttribute("maxLineWidth", limit),
|
|
27
|
+
textGraphic;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
17
30
|
render() {
|
|
18
31
|
var _a;
|
|
19
|
-
|
|
32
|
+
if (this.removeAllChild(!0), !0 !== this.attribute.visible) return;
|
|
33
|
+
const {title: title = {}, content: content, size: size, limitRatio: limitRatio = 1 / 0} = this.attribute, limit = Math.min(size.width, size.height) * limitRatio, group = this.createOrUpdateChild("indicator-container", {
|
|
20
34
|
x: 0,
|
|
21
35
|
y: 0,
|
|
22
36
|
zIndex: 1
|
|
23
37
|
}, "group");
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
const titleStyle = merge({}, get(DEFAULT_INDICATOR_THEME, "title.style"), title.style);
|
|
27
|
-
isRichText(titleStyle) ? this._title = group.createOrUpdateChild("indicator-title", Object.assign(Object.assign({}, richTextAttributeTransform(titleStyle)), {
|
|
28
|
-
visible: title.visible,
|
|
29
|
-
x: 0,
|
|
30
|
-
y: 0
|
|
31
|
-
}), "richtext") : this._title = group.createOrUpdateChild("indicator-title", Object.assign(Object.assign({}, titleStyle), {
|
|
32
|
-
lineHeight: isValid(titleStyle.lineHeight) ? titleStyle.lineHeight : titleStyle.fontSize,
|
|
33
|
-
visible: title.visible,
|
|
34
|
-
x: 0,
|
|
35
|
-
y: 0
|
|
36
|
-
}), "text"), title.autoFit && isValidNumber(limit) && this._setLocalAutoFit(limit, this._title, title),
|
|
37
|
-
title.autoLimit && isValidNumber(limitRatio) && this._title.setAttribute("maxLineWidth", limit);
|
|
38
|
-
} else {
|
|
39
|
-
const titleNode = group.find((node => "indicator-title" === node.name), !1);
|
|
40
|
-
titleNode && group.removeChild(titleNode), this._title = void 0;
|
|
41
|
-
}
|
|
42
|
-
if (isValid(content)) {
|
|
38
|
+
if (isValid(title) && (this._title = this._renderText(group, title, limit, limitRatio, "title.style", "indicator-title")),
|
|
39
|
+
isValid(content)) {
|
|
43
40
|
const contents = array(content), contentComponents = [];
|
|
44
41
|
contents.forEach(((contentItem, i) => {
|
|
45
|
-
|
|
46
|
-
const contentStyle = merge({}, get(DEFAULT_INDICATOR_THEME, "content.style"), contentItem.style);
|
|
47
|
-
let contentComponent;
|
|
48
|
-
contentComponent = isRichText(contentStyle) ? group.createOrUpdateChild("indicator-content-" + i, Object.assign(Object.assign({}, richTextAttributeTransform(contentStyle)), {
|
|
49
|
-
visible: title.visible,
|
|
50
|
-
x: 0,
|
|
51
|
-
y: 0
|
|
52
|
-
}), "richtext") : group.createOrUpdateChild("indicator-content-" + i, Object.assign(Object.assign({}, contentStyle), {
|
|
53
|
-
lineHeight: isValid(contentStyle.lineHeight) ? contentStyle.lineHeight : contentStyle.fontSize,
|
|
54
|
-
visible: contentItem.visible,
|
|
55
|
-
x: 0,
|
|
56
|
-
y: 0
|
|
57
|
-
}), "text"), contentItem.autoFit && isValidNumber(limit) && this._setLocalAutoFit(limit, contentComponent, contentItem),
|
|
58
|
-
contentItem.autoLimit && isValidNumber(limitRatio) && contentComponent.setAttribute("maxLineWidth", limit),
|
|
59
|
-
contentComponents.push(contentComponent);
|
|
60
|
-
} else {
|
|
61
|
-
const contentItemNode = group.find((node => node.name === "indicator-content-" + i), !1);
|
|
62
|
-
contentItemNode && group.removeChild(contentItemNode);
|
|
63
|
-
}
|
|
42
|
+
!1 !== contentItem.visible && contentComponents.push(this._renderText(group, contentItem, limit, limitRatio, "content.style", "indicator-content-" + i));
|
|
64
43
|
})), this._content = contentComponents;
|
|
65
44
|
}
|
|
66
45
|
this._setGlobalAutoFit(limit), this._setYPosition();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/indicator/indicator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAElF,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEpD,sBAAsB,EAAE,CAAC;AACzB,MAAM,OAAO,SAAU,SAAQ,iBAAgD;IAA/E;;QACE,SAAI,GAAG,WAAW,CAAC;IA4OrB,CAAC;IAvOW,MAAM;;QACd,MAAM,EAAE,OAAO,EAAE,KAAK,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,GAAG,QAAQ,EAAE,GAAG,IAAI,CAAC,SAAgC,CAAC;QAE5G,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC;QAE7D,MAAM,KAAK,GAAG,IAAI,CAAC,mBAAmB,CAAC,qBAAqB,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,OAAO,CAAW,CAAC;QAG5G,IAAI,OAAO,KAAK,IAAI,EAAE;YACpB,KAAK,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;YACzB,OA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AC;IAEO,aAAa;;QACnB,IAAI,iBAAiB,GAAG,CAAC,CAAC;QAE1B,MAAM,WAAW,GAAG,MAAA,MAAA,MAAA,MAAA,IAAI,CAAC,MAAM,0CAAE,UAAU,0CAAE,MAAM,kDAAI,mCAAI,CAAC,CAAC;QAC7D,MAAM,UAAU,GAAG,MAAA,MAAA,IAAI,CAAC,SAAS,CAAC,KAAK,0CAAE,KAAK,mCAAI,CAAC,CAAC;QACpD,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;aAC1B,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,WAAW,CAAC,OAAO,KAAK,KAAK,CAAC;aACpD,OAAO,CAAC,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE;;YAC9B,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACzC,WAAW,CAAC,YAAY,CAAC,GAAG,EAAE,WAAW,GAAG,UAAU,GAAG,iBAAiB,CAAC,CAAC;YAC5E,MAAM,YAAY,GAAG,MAAA,WAAW,CAAC,KAAK,mCAAI,CAAC,CAAC;YAC5C,iBAAiB,IAAI,WAAW,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC;QACtE,CAAC,CAAC,CAAC;IACP,CAAC;CACF","file":"indicator.js","sourcesContent":["/**\n * @description 指标卡组件\n */\nimport type { IGroup, INode, IText, ITextGraphicAttribute } from '@visactor/vrender-core';\nimport { merge, isValid, array, isValidNumber, get } from '@visactor/vutils';\nimport { AbstractComponent } from '../core/base';\nimport { isRichText, measureTextSize, richTextAttributeTransform } from '../util';\nimport type { IndicatorAttributes, IndicatorItemSpec } from './type';\nimport { DEFAULT_INDICATOR_THEME } from './config';\nimport { loadIndicatorComponent } from './register';\n\nloadIndicatorComponent();\nexport class Indicator extends AbstractComponent<Required<IndicatorAttributes>> {\n name = 'indicator';\n\n private _title?: IText;\n private _content?: IText | IText[];\n\n protected render() {\n const { visible, title = {}, content, size, limitRatio = Infinity } = this.attribute as IndicatorAttributes;\n\n const limit = Math.min(size.width, size.height) * limitRatio;\n\n const group = this.createOrUpdateChild('indicator-container', { x: 0, y: 0, zIndex: 1 }, 'group') as IGroup;\n\n // 指标卡全部隐藏\n if (visible !== true) {\n group && group.hideAll();\n return;\n }\n\n if (isValid(title)) {\n if (title.visible !== false) {\n const titleStyle = merge({}, get(DEFAULT_INDICATOR_THEME, 'title.style'), title.style);\n if (isRichText(titleStyle)) {\n this._title = group.createOrUpdateChild(\n 'indicator-title',\n {\n ...richTextAttributeTransform(titleStyle),\n visible: title.visible,\n x: 0,\n y: 0\n },\n 'richtext'\n ) as IText;\n } else {\n this._title = group.createOrUpdateChild(\n 'indicator-title',\n {\n ...titleStyle,\n /**\n * 加入以下逻辑:如果没有声明lineHeight,默认 lineHeight 等于 fontSize\n * 因为如果不声明 vrender 底层会默认给文本加上 2px 的高度,会影响布局计算\n * 注意:在autoFit改变fontsize时,lineHeight也要同步修改\n */\n lineHeight: isValid(titleStyle.lineHeight) ? titleStyle.lineHeight : titleStyle.fontSize,\n visible: title.visible,\n x: 0,\n y: 0\n },\n 'text'\n ) as IText;\n }\n\n // auto-fit\n if (title.autoFit && isValidNumber(limit)) {\n this._setLocalAutoFit(limit, this._title, title);\n }\n\n //auto-limit\n if (title.autoLimit && isValidNumber(limitRatio)) {\n this._title.setAttribute('maxLineWidth', limit);\n }\n } else {\n /**\n * indicator部分隐藏\n * 例如title隐藏了,content还保留。直接设置visible:false 计算group.AABBounts是错的,影响上下居中。\n * 这里把隐藏的nodes删除后,group.AABBounts计算才正确。\n */\n const titleNode = group.find(node => node.name === 'indicator-title', false);\n titleNode && group.removeChild(titleNode as INode);\n this._title = undefined;\n }\n }\n\n if (isValid(content)) {\n const contents: IndicatorItemSpec[] = array(content);\n const contentComponents: IText[] = [];\n contents.forEach((contentItem, i) => {\n if (contentItem.visible !== false) {\n const contentStyle = merge({}, get(DEFAULT_INDICATOR_THEME, 'content.style'), contentItem.style);\n let contentComponent;\n if (isRichText(contentStyle)) {\n contentComponent = group.createOrUpdateChild(\n 'indicator-content-' + i,\n {\n ...richTextAttributeTransform(contentStyle),\n visible: title.visible,\n x: 0,\n y: 0\n },\n 'richtext'\n ) as IText;\n } else {\n contentComponent = group.createOrUpdateChild(\n 'indicator-content-' + i,\n {\n ...contentStyle,\n lineHeight: isValid(contentStyle.lineHeight) ? contentStyle.lineHeight : contentStyle.fontSize,\n visible: contentItem.visible,\n x: 0,\n y: 0\n },\n 'text'\n ) as IText;\n }\n\n // auto-fit\n if (contentItem.autoFit && isValidNumber(limit)) {\n this._setLocalAutoFit(limit, contentComponent, contentItem);\n }\n\n //auto-limit\n if (contentItem.autoLimit && isValidNumber(limitRatio)) {\n contentComponent.setAttribute('maxLineWidth', limit);\n }\n\n contentComponents.push(contentComponent);\n } else {\n /**\n * indicator部分隐藏\n */\n const contentItemNode = group.find(node => node.name === 'indicator-content-' + i, false);\n contentItemNode && group.removeChild(contentItemNode as INode);\n }\n });\n this._content = contentComponents;\n }\n\n this._setGlobalAutoFit(limit);\n this._setYPosition();\n\n const totalHeight = group?.AABBBounds.height() ?? 0;\n group.setAttribute('y', size.height / 2 - totalHeight / 2);\n group.setAttribute('x', size.width / 2);\n }\n\n private _setLocalAutoFit(limit: number, indicatorItem: IText, indicatorItemSpec: IndicatorItemSpec) {\n // only apply local auto fit for default auto fit text\n if ((indicatorItemSpec.fitStrategy ?? 'default') !== 'default') {\n return;\n }\n const originWidth = measureTextSize(\n (indicatorItemSpec.style?.text ?? '') as string | number | number[] | string[],\n (indicatorItemSpec.style ?? {}) as Partial<ITextGraphicAttribute>,\n this.stage?.getTheme()?.text\n ).width;\n if (originWidth > 0) {\n const ratio = (limit * (indicatorItemSpec.fitPercent ?? 0.5)) / originWidth;\n const fontSize = Math.floor((indicatorItemSpec.style?.fontSize ?? 20) * ratio);\n indicatorItem.setAttribute('fontSize', fontSize);\n indicatorItem.setAttribute(\n 'lineHeight',\n isValid(indicatorItemSpec.style.lineHeight) ? indicatorItemSpec.style.lineHeight : fontSize\n );\n }\n }\n\n private _setGlobalAutoFit(limit: number) {\n // compute the inscribed rect width & height for all texts\n // the font size will be determined by the longest text\n // 1. hx^2 + hy^2 = r^2\n // 2. hy = ra * hx + h\n // -> (ra^2 + 1) * x^2 + (2 * h * ra) * x + (h^2 - r^2) = 0\n\n const r = limit / 2;\n\n // unify the initial font size for auto fit texts\n const singleHeight = 12;\n const autoFitTexts: { text: IText; spec: IndicatorItemSpec }[] = [];\n // other text height\n let otherHeight = 0;\n // non auto fit title height\n const titleSpec = this.attribute.title ?? {};\n if (titleSpec.autoFit && titleSpec.fitStrategy === 'inscribed') {\n this._title.setAttribute('fontSize', singleHeight);\n autoFitTexts.push({ text: this._title, spec: this.attribute.title ?? {} });\n } else {\n otherHeight += this._title?.AABBBounds?.height?.() ?? 0;\n }\n const titleSpace = titleSpec.space ?? 0;\n otherHeight += titleSpace;\n // non auto fit content height\n array(this.attribute.content)\n .filter(contentSpec => contentSpec.visible !== false)\n .forEach((contentSpec, index) => {\n const contentText = this._content[index];\n if (contentSpec.autoFit && contentSpec.fitStrategy === 'inscribed') {\n contentText.setAttribute('fontSize', singleHeight);\n autoFitTexts.push({ text: contentText, spec: contentSpec });\n } else {\n otherHeight += contentText?.AABBBounds?.height?.() ?? 0;\n }\n const contentSpace = contentSpec.space ?? 0;\n otherHeight += contentSpace;\n });\n if (autoFitTexts.length <= 0) {\n return;\n }\n\n // max width for all auto fit texts\n const maxWidth = autoFitTexts.reduce((width, textItem) => {\n return Math.max(width, textItem.text.AABBBounds.width());\n }, 0);\n\n // y = x * (singleHeight / maxWidth * textCount) + otherHeight\n // hy = hx * (singleHeight / maxWidth * textCount) + otherHeight / 2\n const ra = (singleHeight / maxWidth) * autoFitTexts.length;\n const h = otherHeight / 2;\n const a = ra ** 2 + 1;\n const b = 2 * h * ra;\n const c = h ** 2 - r ** 2;\n const hx = (-b + Math.sqrt(b ** 2 - 4 * a * c)) / (2 * a);\n const hy = ra * hx + h;\n const y = 2 * hy;\n const lineHeight = (y - otherHeight) / autoFitTexts.length;\n if (isValidNumber(y)) {\n autoFitTexts.forEach(textItem => {\n const specLineHeight = textItem.spec.style?.lineHeight;\n textItem.text.setAttribute('fontSize', lineHeight);\n textItem.text.setAttribute('lineHeight', isValid(specLineHeight) ? specLineHeight : lineHeight);\n });\n }\n }\n\n private _setYPosition() {\n let lastContentHeight = 0;\n\n const titleHeight = this._title?.AABBBounds?.height?.() ?? 0;\n const titleSpace = this.attribute.title?.space ?? 0;\n array(this.attribute.content)\n .filter(contentSpec => contentSpec.visible !== false)\n .forEach((contentSpec, index) => {\n const contentText = this._content[index];\n contentText.setAttribute('y', titleHeight + titleSpace + lastContentHeight);\n const contentSpace = contentSpec.space ?? 0;\n lastContentHeight += contentText.AABBBounds.height() + contentSpace;\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/indicator/indicator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAEnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEpD,sBAAsB,EAAE,CAAC;AACzB,MAAM,OAAO,SAAU,SAAQ,iBAAgD;IAA/E;;QACE,SAAI,GAAG,WAAW,CAAC;IAuLrB,CAAC;IAlLW,WAAW,CACnB,KAAa,EACb,KAAwB,EACxB,KAAa,EACb,UAAkB,EAClB,SAAiB,EACjB,WAAmB;QAEnB,IAAI,KAAK,CAAC,OAAO,KAAK,KAAK,EAAE;YAC3B,MAAM,UAAU,GAAG,KAAK,CAAC,EAAE,EAAE,GAAG,CAAC,uBAAuB,E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Text, ITextGraphicAttribute } from '@visactor/vrender-core';\nimport { merge, isValid, array, isValidNumber, get } from '@visactor/vutils';\nimport { AbstractComponent } from '../core/base';\nimport { createTextGraphicByType, measureTextSize } from '../util';\nimport type { IndicatorAttributes, IndicatorItemSpec } from './type';\nimport { DEFAULT_INDICATOR_THEME } from './config';\nimport { loadIndicatorComponent } from './register';\n\nloadIndicatorComponent();\nexport class Indicator extends AbstractComponent<Required<IndicatorAttributes>> {\n name = 'indicator';\n\n private _title?: IText | IRichText;\n private _content?: (IText | IRichText)[];\n\n protected _renderText(\n group: IGroup,\n title: IndicatorItemSpec,\n limit: number,\n limitRatio: number,\n themePath: string,\n graphicName: string\n ) {\n if (title.visible !== false) {\n const titleStyle = merge({}, get(DEFAULT_INDICATOR_THEME, themePath), title.style, {\n visible: title.visible\n });\n titleStyle.lineHeight = isValid(titleStyle.lineHeight) ? titleStyle.lineHeight : titleStyle.fontSize;\n\n if (title.formatMethod) {\n titleStyle._originText = titleStyle.text;\n titleStyle.text = title.formatMethod(titleStyle.text, titleStyle);\n }\n const textGraphic = createTextGraphicByType(titleStyle);\n textGraphic.name = graphicName;\n group.appendChild(textGraphic);\n\n // auto-fit\n if (title.autoFit && isValidNumber(limit)) {\n this._setLocalAutoFit(limit, textGraphic as IText, title);\n }\n\n //auto-limit\n if (title.autoLimit && isValidNumber(limitRatio)) {\n textGraphic.setAttribute('maxLineWidth', limit);\n }\n\n return textGraphic;\n }\n\n return undefined;\n }\n\n protected render() {\n this.removeAllChild(true);\n\n if (this.attribute.visible !== true) {\n return;\n }\n const { title = {}, content, size, limitRatio = Infinity } = this.attribute as IndicatorAttributes;\n\n const limit = Math.min(size.width, size.height) * limitRatio;\n\n const group = this.createOrUpdateChild('indicator-container', { x: 0, y: 0, zIndex: 1 }, 'group') as IGroup;\n\n if (isValid(title)) {\n this._title = this._renderText(group, title, limit, limitRatio, 'title.style', 'indicator-title');\n }\n\n if (isValid(content)) {\n const contents: IndicatorItemSpec[] = array(content);\n const contentComponents: (IText | IRichText)[] = [];\n contents.forEach((contentItem, i) => {\n if (contentItem.visible !== false) {\n contentComponents.push(\n this._renderText(group, contentItem, limit, limitRatio, 'content.style', 'indicator-content-' + i)\n );\n } else {\n }\n });\n this._content = contentComponents;\n }\n\n this._setGlobalAutoFit(limit);\n this._setYPosition();\n\n const totalHeight = group?.AABBBounds.height() ?? 0;\n group.setAttribute('y', size.height / 2 - totalHeight / 2);\n group.setAttribute('x', size.width / 2);\n }\n\n private _setLocalAutoFit(limit: number, indicatorItem: IText, indicatorItemSpec: IndicatorItemSpec) {\n // only apply local auto fit for default auto fit text\n if ((indicatorItemSpec.fitStrategy ?? 'default') !== 'default') {\n return;\n }\n const originWidth = measureTextSize(\n (indicatorItemSpec.style?.text ?? '') as string | number | number[] | string[],\n (indicatorItemSpec.style ?? {}) as Partial<ITextGraphicAttribute>,\n this.stage?.getTheme()?.text\n ).width;\n if (originWidth > 0) {\n const ratio = (limit * (indicatorItemSpec.fitPercent ?? 0.5)) / originWidth;\n const fontSize = Math.floor((indicatorItemSpec.style?.fontSize ?? 20) * ratio);\n indicatorItem.setAttribute('fontSize', fontSize);\n indicatorItem.setAttribute(\n 'lineHeight',\n isValid(indicatorItemSpec.style.lineHeight) ? indicatorItemSpec.style.lineHeight : fontSize\n );\n }\n }\n\n private _setGlobalAutoFit(limit: number) {\n // compute the inscribed rect width & height for all texts\n // the font size will be determined by the longest text\n // 1. hx^2 + hy^2 = r^2\n // 2. hy = ra * hx + h\n // -> (ra^2 + 1) * x^2 + (2 * h * ra) * x + (h^2 - r^2) = 0\n\n const r = limit / 2;\n\n // unify the initial font size for auto fit texts\n const singleHeight = 12;\n const autoFitTexts: { text: IText; spec: IndicatorItemSpec }[] = [];\n // other text height\n let otherHeight = 0;\n // non auto fit title height\n const titleSpec = this.attribute.title ?? {};\n if (titleSpec.autoFit && titleSpec.fitStrategy === 'inscribed') {\n this._title.setAttribute('fontSize', singleHeight);\n autoFitTexts.push({ text: this._title as IText, spec: this.attribute.title ?? {} });\n } else {\n otherHeight += this._title?.AABBBounds?.height?.() ?? 0;\n }\n const titleSpace = titleSpec.space ?? 0;\n otherHeight += titleSpace;\n // non auto fit content height\n array(this.attribute.content)\n .filter(contentSpec => contentSpec.visible !== false)\n .forEach((contentSpec, index) => {\n const contentText = this._content[index];\n if (contentSpec.autoFit && contentSpec.fitStrategy === 'inscribed') {\n contentText.setAttribute('fontSize', singleHeight);\n autoFitTexts.push({ text: contentText as IText, spec: contentSpec });\n } else {\n otherHeight += contentText?.AABBBounds?.height?.() ?? 0;\n }\n const contentSpace = contentSpec.space ?? 0;\n otherHeight += contentSpace;\n });\n if (autoFitTexts.length <= 0) {\n return;\n }\n\n // max width for all auto fit texts\n const maxWidth = autoFitTexts.reduce((width, textItem) => {\n return Math.max(width, textItem.text.AABBBounds.width());\n }, 0);\n\n // y = x * (singleHeight / maxWidth * textCount) + otherHeight\n // hy = hx * (singleHeight / maxWidth * textCount) + otherHeight / 2\n const ra = (singleHeight / maxWidth) * autoFitTexts.length;\n const h = otherHeight / 2;\n const a = ra ** 2 + 1;\n const b = 2 * h * ra;\n const c = h ** 2 - r ** 2;\n const hx = (-b + Math.sqrt(b ** 2 - 4 * a * c)) / (2 * a);\n const hy = ra * hx + h;\n const y = 2 * hy;\n const lineHeight = (y - otherHeight) / autoFitTexts.length;\n if (isValidNumber(y)) {\n autoFitTexts.forEach(textItem => {\n const specLineHeight = textItem.spec.style?.lineHeight;\n textItem.text.setAttribute('fontSize', lineHeight);\n textItem.text.setAttribute('lineHeight', isValid(specLineHeight) ? specLineHeight : lineHeight);\n });\n }\n }\n\n private _setYPosition() {\n let lastContentHeight = 0;\n\n const titleHeight = this._title?.AABBBounds?.height?.() ?? 0;\n const titleSpace = this.attribute.title?.space ?? 0;\n array(this.attribute.content)\n .filter(contentSpec => contentSpec.visible !== false)\n .forEach((contentSpec, index) => {\n const contentText = this._content[index];\n contentText.setAttribute('y', titleHeight + titleSpace + lastContentHeight);\n const contentSpace = contentSpec.space ?? 0;\n lastContentHeight += contentText.AABBBounds.height() + contentSpace;\n });\n }\n}\n"]}
|
package/es/indicator/type.d.ts
CHANGED
|
@@ -19,5 +19,6 @@ export interface IndicatorItemSpec {
|
|
|
19
19
|
autoFit?: boolean;
|
|
20
20
|
fitPercent?: number;
|
|
21
21
|
fitStrategy?: 'default' | 'inscribed';
|
|
22
|
+
formatMethod?: (text: string | number, textStyle: ITextGraphicAttribute) => TextContent;
|
|
22
23
|
style?: Omit<ITextGraphicAttribute, 'text'> & TextContent;
|
|
23
24
|
}
|
package/es/indicator/type.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/indicator/type.ts"],"names":[],"mappings":"","file":"type.js","sourcesContent":["import type { IGroupGraphicAttribute, ITextGraphicAttribute, IRichTextCharacter } from '@visactor/vrender-core';\nimport type { TextContent } from '../core/type';\n\nexport interface IndicatorAttributes extends IGroupGraphicAttribute {\n /**\n * 是否显示指标卡组件\n * @default true\n */\n visible?: boolean;\n /**\n * 内容尺寸\n */\n size: { width: number; height: number };\n /**\n * 指标卡 x 方向偏移\n * @default 0\n */\n dx?: number;\n /**\n * 指标卡 y 方向偏移\n * @default 0\n */\n dy?: number;\n /**\n * 指标卡宽度占内容区域的最大比值(从0到1)\n */\n limitRatio?: number;\n /**\n * 指标卡标题文字配置\n */\n title?: IndicatorItemSpec;\n /**\n * 指标卡内容文字配置\n */\n content?: IndicatorItemSpec[] | IndicatorItemSpec;\n}\n\nexport interface IndicatorItemSpec {\n /**\n * 是否显示当前项\n * @default true\n */\n visible?: boolean;\n /**\n * title.space: title 和 content 之间的间距\n * contentItem.space: content 之间的间距\n */\n space?: number;\n /**\n * 是否自适应文字空间进行缩略\n * 按照原字体大小,根据空间大小缩略文字\n * @default false\n */\n autoLimit?: boolean;\n /**\n * 是否自适应文字空间缩放文字大小\n * 不缩略文字,改变字体大小以适应空间\n * @default false\n */\n autoFit?: boolean;\n /**\n * 自适应文字宽度与可用空间的比例\n * @default 0.5\n */\n fitPercent?: number;\n /**\n * 自适应文字策略\n * @default 'local'\n */\n fitStrategy?: 'default' | 'inscribed';\n /**\n * 文字样式\n */\n style?: Omit<ITextGraphicAttribute, 'text'> & TextContent;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/indicator/type.ts"],"names":[],"mappings":"","file":"type.js","sourcesContent":["import type { IGroupGraphicAttribute, ITextGraphicAttribute, IRichTextCharacter } from '@visactor/vrender-core';\nimport type { TextContent } from '../core/type';\n\nexport interface IndicatorAttributes extends IGroupGraphicAttribute {\n /**\n * 是否显示指标卡组件\n * @default true\n */\n visible?: boolean;\n /**\n * 内容尺寸\n */\n size: { width: number; height: number };\n /**\n * 指标卡 x 方向偏移\n * @default 0\n */\n dx?: number;\n /**\n * 指标卡 y 方向偏移\n * @default 0\n */\n dy?: number;\n /**\n * 指标卡宽度占内容区域的最大比值(从0到1)\n */\n limitRatio?: number;\n /**\n * 指标卡标题文字配置\n */\n title?: IndicatorItemSpec;\n /**\n * 指标卡内容文字配置\n */\n content?: IndicatorItemSpec[] | IndicatorItemSpec;\n}\n\nexport interface IndicatorItemSpec {\n /**\n * 是否显示当前项\n * @default true\n */\n visible?: boolean;\n /**\n * title.space: title 和 content 之间的间距\n * contentItem.space: content 之间的间距\n */\n space?: number;\n /**\n * 是否自适应文字空间进行缩略\n * 按照原字体大小,根据空间大小缩略文字\n * @default false\n */\n autoLimit?: boolean;\n /**\n * 是否自适应文字空间缩放文字大小\n * 不缩略文字,改变字体大小以适应空间\n * @default false\n */\n autoFit?: boolean;\n /**\n * 自适应文字宽度与可用空间的比例\n * @default 0.5\n */\n fitPercent?: number;\n /**\n * 自适应文字策略\n * @default 'local'\n */\n fitStrategy?: 'default' | 'inscribed';\n /**\n * 格式化方法\n * @since 0.20.0\n * @param text 文本\n * @returns\n */\n formatMethod?: (text: string | number, textStyle: ITextGraphicAttribute) => TextContent;\n /**\n * 文字样式\n */\n style?: Omit<ITextGraphicAttribute, 'text'> & TextContent;\n}\n"]}
|
package/es/interface.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { IRectGraphicAttribute } from '@visactor/vrender-core';
|
|
1
|
+
import type { ICustomPath2D, IGraphicAttribute, IRectGraphicAttribute, IRichTextAttribute, ITextGraphicAttribute } from '@visactor/vrender-core';
|
|
2
2
|
export type Direction = 'horizontal' | 'vertical';
|
|
3
3
|
export type OrientType = 'top' | 'right' | 'bottom' | 'left';
|
|
4
4
|
export type BackgroundAttributes = {
|
|
5
5
|
visible: boolean;
|
|
6
|
+
customShape?: (text: ITextGraphicAttribute | IRichTextAttribute, attrs: Partial<IGraphicAttribute>, path: ICustomPath2D) => ICustomPath2D;
|
|
6
7
|
} & Partial<IRectGraphicAttribute>;
|
|
7
8
|
export type IDelayType = 'debounce' | 'throttle';
|
|
8
9
|
export interface ComponentOptions {
|
package/es/interface.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface.ts"],"names":[],"mappings":"","file":"interface.js","sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/interface.ts"],"names":[],"mappings":"","file":"interface.js","sourcesContent":["import type {\n ICustomPath2D,\n IGraphicAttribute,\n IRectGraphicAttribute,\n IRichTextAttribute,\n ITextGraphicAttribute\n} from '@visactor/vrender-core';\nimport type { TextContent } from './core/type';\n\nexport type Direction = 'horizontal' | 'vertical';\n\nexport type OrientType = 'top' | 'right' | 'bottom' | 'left';\n\nexport type BackgroundAttributes = {\n /**\n * 是否绘制背景层\n */\n visible: boolean;\n /**\n * 自定义路径\n * @since 0.19.19\n */\n customShape?: (\n text: ITextGraphicAttribute | IRichTextAttribute,\n attrs: Partial<IGraphicAttribute>,\n path: ICustomPath2D\n ) => ICustomPath2D;\n} & Partial<IRectGraphicAttribute>;\n\nexport type IDelayType = 'debounce' | 'throttle';\n\nexport interface ComponentOptions {\n /** skip default attributes of component */\n skipDefault?: boolean;\n /** the mode of component, only axis support 3d mode now */\n mode?: '2d' | '3d';\n}\n"]}
|
package/es/label/arc.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { merge, isValidNumber, isNil, isLess, isGreater, isNumberClose as isClose } from "@visactor/vutils";
|
|
1
|
+
import { merge, isValidNumber, isNil, isLess, isGreater, isNumberClose as isClose, polarToCartesian, computeQuadrant } from "@visactor/vutils";
|
|
2
2
|
|
|
3
3
|
import { LabelBase } from "./base";
|
|
4
4
|
|
|
5
|
-
import { graphicCreator } from "@visactor/vrender-core";
|
|
5
|
+
import { graphicCreator, CustomPath2D } from "@visactor/vrender-core";
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { isQuadrantRight, isQuadrantLeft, lineCirclePoints, connectLineRadian, checkBoundsOverlap } from "./util";
|
|
8
8
|
|
|
9
9
|
import { registerLabelComponent } from "./data-label-register";
|
|
10
10
|
|
|
@@ -92,8 +92,8 @@ export class ArcLabel extends LabelBase {
|
|
|
92
92
|
x2: 0,
|
|
93
93
|
y1: 0,
|
|
94
94
|
y2: 0
|
|
95
|
-
}, arcMiddleAngle = (graphicAttribute.startAngle + graphicAttribute.endAngle) / 2, intervalAngle = graphicAttribute.endAngle - graphicAttribute.startAngle, arcQuadrant = computeQuadrant(graphicAttribute.endAngle - intervalAngle / 2), arcMiddle =
|
|
96
|
-
arc.pointA =
|
|
95
|
+
}, arcMiddleAngle = (graphicAttribute.startAngle + graphicAttribute.endAngle) / 2, intervalAngle = graphicAttribute.endAngle - graphicAttribute.startAngle, arcQuadrant = computeQuadrant(graphicAttribute.endAngle - intervalAngle / 2), arcMiddle = polarToCartesian(center, graphicAttribute.outerRadius, arcMiddleAngle), outerArcMiddle = polarToCartesian(center, maxRadius + attribute.line.line1MinLength, arcMiddleAngle), arc = new ArcInfo(item, arcMiddle, outerArcMiddle, arcQuadrant, intervalAngle, arcMiddleAngle, graphicAttribute.innerRadius, graphicAttribute.outerRadius, center);
|
|
96
|
+
arc.pointA = polarToCartesian(center, this.computeDatumRadius(2 * center.x, 2 * center.y, graphicAttribute.outerRadius), arc.middleAngle),
|
|
97
97
|
arc.labelSize = {
|
|
98
98
|
width: textBounds.x2 - textBounds.x1,
|
|
99
99
|
height: textBounds.y2 - textBounds.y1
|
|
@@ -132,7 +132,7 @@ export class ArcLabel extends LabelBase {
|
|
|
132
132
|
let labelRadius, alignOffset = 0;
|
|
133
133
|
if ("inside" === position && (alignOffset = "left" === align ? labelWidth : "right" === align ? 0 : labelWidth / 2),
|
|
134
134
|
labelRadius = "inside-inner" === position ? innerRadius - offsetRadius + alignOffset : outerRadius + offsetRadius - alignOffset,
|
|
135
|
-
arc.labelPosition =
|
|
135
|
+
arc.labelPosition = polarToCartesian(arc.circleCenter, labelRadius, arc.middleAngle),
|
|
136
136
|
arc.labelLimit = labelWidth, isGreater(labelWidth, 0) || (arc.labelVisible = !1),
|
|
137
137
|
!1 !== labelConfig.rotate) {
|
|
138
138
|
arc.angle = null !== (_b = null === (_a = attribute.textStyle) || void 0 === _a ? void 0 : _a.angle) && void 0 !== _b ? _b : arc.middleAngle;
|
|
@@ -429,7 +429,14 @@ export class ArcLabel extends LabelBase {
|
|
|
429
429
|
points: points,
|
|
430
430
|
curveType: line.smooth ? "basis" : null
|
|
431
431
|
}) : void 0;
|
|
432
|
-
|
|
432
|
+
if (labelLine) {
|
|
433
|
+
if (null == line ? void 0 : line.customShape) {
|
|
434
|
+
const customShape = line.customShape;
|
|
435
|
+
labelLine.pathProxy = attrs => customShape(text.attribute, attrs, new CustomPath2D);
|
|
436
|
+
}
|
|
437
|
+
this._setStatesOfLabelLine(labelLine);
|
|
438
|
+
}
|
|
439
|
+
return labelLine;
|
|
433
440
|
}
|
|
434
441
|
computeRadius(r, width, height, k) {
|
|
435
442
|
return this.computeLayoutRadius(width || 0, height || 0) * r * (isNil(k) ? 1 : k);
|