@visactor/vrender-components 0.19.21 → 0.19.22

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.
Files changed (42) hide show
  1. package/cjs/index.d.ts +2 -1
  2. package/cjs/index.js +5 -4
  3. package/cjs/index.js.map +1 -1
  4. package/cjs/indicator/indicator.d.ts +3 -1
  5. package/cjs/indicator/indicator.js +19 -41
  6. package/cjs/indicator/indicator.js.map +1 -1
  7. package/cjs/indicator/type.d.ts +1 -0
  8. package/cjs/indicator/type.js.map +1 -1
  9. package/cjs/timeline/index.d.ts +2 -0
  10. package/cjs/timeline/index.js +21 -0
  11. package/cjs/timeline/index.js.map +1 -0
  12. package/cjs/timeline/register.d.ts +1 -0
  13. package/cjs/timeline/register.js +15 -0
  14. package/cjs/timeline/register.js.map +1 -0
  15. package/cjs/timeline/timeline.d.ts +30 -0
  16. package/cjs/timeline/timeline.js +178 -0
  17. package/cjs/timeline/timeline.js.map +1 -0
  18. package/cjs/timeline/type.d.ts +18 -0
  19. package/cjs/timeline/type.js +6 -0
  20. package/cjs/timeline/type.js.map +1 -0
  21. package/dist/index.es.js +381 -172
  22. package/es/index.d.ts +2 -1
  23. package/es/index.js +3 -1
  24. package/es/index.js.map +1 -1
  25. package/es/indicator/indicator.d.ts +3 -1
  26. package/es/indicator/indicator.js +19 -40
  27. package/es/indicator/indicator.js.map +1 -1
  28. package/es/indicator/type.d.ts +1 -0
  29. package/es/indicator/type.js.map +1 -1
  30. package/es/timeline/index.d.ts +2 -0
  31. package/es/timeline/index.js +4 -0
  32. package/es/timeline/index.js.map +1 -0
  33. package/es/timeline/register.d.ts +1 -0
  34. package/es/timeline/register.js +6 -0
  35. package/es/timeline/register.js.map +1 -0
  36. package/es/timeline/timeline.d.ts +30 -0
  37. package/es/timeline/timeline.js +175 -0
  38. package/es/timeline/timeline.js.map +1 -0
  39. package/es/timeline/type.d.ts +18 -0
  40. package/es/timeline/type.js +2 -0
  41. package/es/timeline/type.js.map +1 -0
  42. package/package.json +3 -3
package/cjs/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const version = "0.19.21";
1
+ export declare const version = "0.19.22";
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/cjs/index.js CHANGED
@@ -17,7 +17,7 @@ var __createBinding = this && this.__createBinding || (Object.create ? function(
17
17
 
18
18
  Object.defineProperty(exports, "__esModule", {
19
19
  value: !0
20
- }), exports.version = void 0, exports.version = "0.19.21", __exportStar(require("./core/base"), exports),
20
+ }), exports.version = void 0, exports.version = "0.19.22", __exportStar(require("./core/base"), exports),
21
21
  __exportStar(require("./core/type"), exports), __exportStar(require("./scrollbar"), exports),
22
22
  __exportStar(require("./tag"), exports), __exportStar(require("./poptip"), exports),
23
23
  __exportStar(require("./crosshair"), exports), __exportStar(require("./label"), exports),
@@ -28,7 +28,8 @@ __exportStar(require("./legend"), exports), __exportStar(require("./title"), exp
28
28
  __exportStar(require("./indicator"), exports), __exportStar(require("./slider"), exports),
29
29
  __exportStar(require("./link-path"), exports), __exportStar(require("./player"), exports),
30
30
  __exportStar(require("./brush"), exports), __exportStar(require("./tooltip"), exports),
31
- __exportStar(require("./interface"), exports), __exportStar(require("./jsx"), exports),
32
- __exportStar(require("./checkbox"), exports), __exportStar(require("./radio"), exports),
33
- __exportStar(require("./empty-tip"), exports), __exportStar(require("./util"), exports);
31
+ __exportStar(require("./timeline"), exports), __exportStar(require("./interface"), exports),
32
+ __exportStar(require("./jsx"), exports), __exportStar(require("./checkbox"), exports),
33
+ __exportStar(require("./radio"), exports), __exportStar(require("./empty-tip"), exports),
34
+ __exportStar(require("./util"), exports);
34
35
  //# sourceMappingURL=index.js.map
package/cjs/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACa,QAAA,OAAO,GAAG,SAAS,CAAC;AAEjC,8CAA4B;AAC5B,8CAA4B;AAC5B,8CAA4B;AAC5B,wCAAsB;AACtB,2CAAyB;AACzB,8CAA4B;AAC5B,0CAAwB;AACxB,yCAAuB;AACvB,8CAA4B;AAC5B,4CAA0B;AAC1B,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB;AACxB,2CAAyB;AACzB,0CAAwB;AACxB,8CAA4B;AAC5B,2CAAyB;AACzB,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB;AACxB,4CAA0B;AAC1B,8CAA4B;AAC5B,wCAAsB;AACtB,6CAA2B;AAC3B,0CAAwB;AACxB,8CAA4B;AAC5B,yCAAuB","file":"index.js","sourcesContent":["// 导出版本号\nexport const version = \"0.19.21\";\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 './interface';\nexport * from './jsx';\nexport * from './checkbox';\nexport * from './radio';\nexport * from './empty-tip';\nexport * from './util';\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACa,QAAA,OAAO,GAAG,SAAS,CAAC;AAEjC,8CAA4B;AAC5B,8CAA4B;AAC5B,8CAA4B;AAC5B,wCAAsB;AACtB,2CAAyB;AACzB,8CAA4B;AAC5B,0CAAwB;AACxB,yCAAuB;AACvB,8CAA4B;AAC5B,4CAA0B;AAC1B,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB;AACxB,2CAAyB;AACzB,0CAAwB;AACxB,8CAA4B;AAC5B,2CAAyB;AACzB,8CAA4B;AAC5B,2CAAyB;AACzB,0CAAwB;AACxB,4CAA0B;AAC1B,6CAA2B;AAC3B,8CAA4B;AAC5B,wCAAsB;AACtB,6CAA2B;AAC3B,0CAAwB;AACxB,8CAA4B;AAC5B,yCAAuB","file":"index.js","sourcesContent":["// 导出版本号\nexport const version = \"0.19.22\";\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;
@@ -12,55 +12,33 @@ class Indicator extends base_1.AbstractComponent {
12
12
  constructor() {
13
13
  super(...arguments), this.name = "indicator";
14
14
  }
15
+ _renderText(group, title, limit, limitRatio, themePath, graphicName) {
16
+ if (!1 !== title.visible) {
17
+ const titleStyle = (0, vutils_1.merge)({}, (0, vutils_1.get)(config_1.DEFAULT_INDICATOR_THEME, themePath), title.style, {
18
+ visible: title.visible
19
+ });
20
+ titleStyle.lineHeight = (0, vutils_1.isValid)(titleStyle.lineHeight) ? titleStyle.lineHeight : titleStyle.fontSize,
21
+ title.formatMethod && (titleStyle._originText = titleStyle.text, titleStyle.text = title.formatMethod(titleStyle.text, titleStyle));
22
+ const textGraphic = (0, util_1.createTextGraphicByType)(titleStyle);
23
+ return textGraphic.name = graphicName, group.appendChild(textGraphic), title.autoFit && (0,
24
+ vutils_1.isValidNumber)(limit) && this._setLocalAutoFit(limit, textGraphic, title),
25
+ title.autoLimit && (0, vutils_1.isValidNumber)(limitRatio) && textGraphic.setAttribute("maxLineWidth", limit),
26
+ textGraphic;
27
+ }
28
+ }
15
29
  render() {
16
30
  var _a;
17
- const {visible: visible, 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", {
31
+ if (this.removeAllChild(!0), !0 !== this.attribute.visible) return;
32
+ 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", {
18
33
  x: 0,
19
34
  y: 0,
20
35
  zIndex: 1
21
36
  }, "group");
22
- if (!0 !== visible) return void (group && group.hideAll());
23
- if ((0, vutils_1.isValid)(title)) if (!1 !== title.visible) {
24
- const titleStyle = (0, vutils_1.merge)({}, (0, vutils_1.get)(config_1.DEFAULT_INDICATOR_THEME, "title.style"), title.style);
25
- (0, util_1.isRichText)(titleStyle) ? this._title = group.createOrUpdateChild("indicator-title", Object.assign(Object.assign({}, (0,
26
- util_1.richTextAttributeTransform)(titleStyle)), {
27
- visible: title.visible,
28
- x: 0,
29
- y: 0
30
- }), "richtext") : this._title = group.createOrUpdateChild("indicator-title", Object.assign(Object.assign({}, titleStyle), {
31
- lineHeight: (0, vutils_1.isValid)(titleStyle.lineHeight) ? titleStyle.lineHeight : titleStyle.fontSize,
32
- visible: title.visible,
33
- x: 0,
34
- y: 0
35
- }), "text"), title.autoFit && (0, vutils_1.isValidNumber)(limit) && this._setLocalAutoFit(limit, this._title, title),
36
- title.autoLimit && (0, vutils_1.isValidNumber)(limitRatio) && this._title.setAttribute("maxLineWidth", limit);
37
- } else {
38
- const titleNode = group.find((node => "indicator-title" === node.name), !1);
39
- titleNode && group.removeChild(titleNode), this._title = void 0;
40
- }
41
- if ((0, vutils_1.isValid)(content)) {
37
+ if ((0, vutils_1.isValid)(title) && (this._title = this._renderText(group, title, limit, limitRatio, "title.style", "indicator-title")),
38
+ (0, vutils_1.isValid)(content)) {
42
39
  const contents = (0, vutils_1.array)(content), contentComponents = [];
43
40
  contents.forEach(((contentItem, i) => {
44
- if (!1 !== contentItem.visible) {
45
- const contentStyle = (0, vutils_1.merge)({}, (0, vutils_1.get)(config_1.DEFAULT_INDICATOR_THEME, "content.style"), contentItem.style);
46
- let contentComponent;
47
- contentComponent = (0, util_1.isRichText)(contentStyle) ? group.createOrUpdateChild("indicator-content-" + i, Object.assign(Object.assign({}, (0,
48
- util_1.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: (0, vutils_1.isValid)(contentStyle.lineHeight) ? contentStyle.lineHeight : contentStyle.fontSize,
54
- visible: contentItem.visible,
55
- x: 0,
56
- y: 0
57
- }), "text"), contentItem.autoFit && (0, vutils_1.isValidNumber)(limit) && this._setLocalAutoFit(limit, contentComponent, contentItem),
58
- contentItem.autoLimit && (0, vutils_1.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
- }
41
+ !1 !== contentItem.visible && contentComponents.push(this._renderText(group, contentItem, limit, limitRatio, "content.style", "indicator-content-" + i));
64
42
  })), this._content = contentComponents;
65
43
  }
66
44
  this._setGlobalAutoFit(limit), this._setYPosition();
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/indicator/indicator.ts"],"names":[],"mappings":";;;AAIA,6CAA6E;AAC7E,uCAAiD;AACjD,kCAAkF;AAElF,qCAAmD;AACnD,yCAAoD;AAEpD,IAAA,iCAAsB,GAAE,CAAC;AACzB,MAAa,SAAU,SAAQ,wBAAgD;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,OAAO;SACR;QAED,IAAI,IAAA,gBAAO,EAAC,KAAK,CAAC,EAAE;YAClB,IAAI,KAAK,CAAC,OAAO,KAAK,KAAK,EAAE;gBAC3B,MAAM,UAAU,GAAG,IAAA,cAAK,EAAC,EAAE,EAAE,IAAA,YAAG,EAAC,gCAAuB,EAAE,aAAa,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;gBACvF,IAAI,IAAA,iBAAU,EAAC,UAAU,CAAC,EAAE;oBAC1B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,mBAAmB,CACrC,iBAAiB,kCAEZ,IAAA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,SAAS,CAAC,KAAK,0CAAE,KAAK,mCAAI,CAAC,CAAC;QACpD,IAAA,cAAK,EAAC,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;AA7OD,8BA6OC","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,6CAA6E;AAC7E,uCAAiD;AACjD,kCAAmE;AAEnE,qCAAmD;AACnD,yCAAoD;AAEpD,IAAA,iCAAsB,GAAE,CAAC;AACzB,MAAa,SAAU,SAAQ,wBAAgD;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,IAAA,cAAK,EAAC,EAAE,EAAE,IAAA,YAAG,EAAC,gCAAuB,EAAE,SAAS,CAAC,EAAE,KAAK,CAAC,KAAK,EAAE;gBACjF,OAAO,EAAE,KAAK,CAAC,OAAO;aACvB,CAAC,CAAC;YACH,UAAU,CAAC,UAAU,GAAG,IAAA,gBAAO,EAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC;YAErG,IAAI,KAAK,CAAC,YAAY,EAAE;gBACtB,UAAU,CAAC,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC;gBACzC,UAAU,CAAC,IAAI,GAAG,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC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;SACJ;IACH,CAAC;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,IAAA,cAAK,EAAC,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;AAxLD,8BAwLC","file":"indicator.js","sourcesContent":["/**\n * @description 指标卡组件\n */\nimport type { IGroup, IRichText, IText, 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"]}
@@ -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
  }
@@ -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"]}
@@ -0,0 +1,2 @@
1
+ export * from './timeline';
2
+ export * from './type';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
4
+ void 0 === k2 && (k2 = k);
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ desc && !("get" in desc ? !m.__esModule : desc.writable || desc.configurable) || (desc = {
7
+ enumerable: !0,
8
+ get: function() {
9
+ return m[k];
10
+ }
11
+ }), Object.defineProperty(o, k2, desc);
12
+ } : function(o, m, k, k2) {
13
+ void 0 === k2 && (k2 = k), o[k2] = m[k];
14
+ }), __exportStar = this && this.__exportStar || function(m, exports) {
15
+ for (var p in m) "default" === p || Object.prototype.hasOwnProperty.call(exports, p) || __createBinding(exports, m, p);
16
+ };
17
+
18
+ Object.defineProperty(exports, "__esModule", {
19
+ value: !0
20
+ }), __exportStar(require("./timeline"), exports), __exportStar(require("./type"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/timeline/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,yCAAuB","file":"index.js","sourcesContent":["export * from './timeline';\nexport * from './type';\n"]}
@@ -0,0 +1 @@
1
+ export declare function loadTimelineComponent(): void;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.loadTimelineComponent = void 0;
6
+
7
+ const vrender_kits_1 = require("@visactor/vrender-kits");
8
+
9
+ function loadTimelineComponent() {
10
+ (0, vrender_kits_1.registerGroup)(), (0, vrender_kits_1.registerText)(), (0, vrender_kits_1.registerSymbol)(),
11
+ (0, vrender_kits_1.registerLine)();
12
+ }
13
+
14
+ exports.loadTimelineComponent = loadTimelineComponent;
15
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/timeline/register.ts"],"names":[],"mappings":";;;AAAA,yDAAmG;AAEnG,SAAgB,qBAAqB;IACnC,IAAA,4BAAa,GAAE,CAAC;IAChB,IAAA,2BAAY,GAAE,CAAC;IACf,IAAA,6BAAc,GAAE,CAAC;IACjB,IAAA,2BAAY,GAAE,CAAC;AACjB,CAAC;AALD,sDAKC","file":"register.js","sourcesContent":["import { registerGroup, registerSymbol, registerLine, registerText } from '@visactor/vrender-kits';\n\nexport function loadTimelineComponent() {\n registerGroup();\n registerText();\n registerSymbol();\n registerLine();\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import { AbstractComponent } from '../core/base';
2
+ import type { TimelineAttrs } from './type';
3
+ import type { ComponentOptions } from '../interface';
4
+ export declare class Timeline extends AbstractComponent<Required<TimelineAttrs>> {
5
+ name: string;
6
+ private _line?;
7
+ private _activeLine?;
8
+ private _symbolGroup?;
9
+ private _labelGroup?;
10
+ private _timesPercent?;
11
+ static defaultAttributes: Partial<TimelineAttrs>;
12
+ constructor(attributes: TimelineAttrs, options?: ComponentOptions);
13
+ protected render(): void;
14
+ appearAnimate(animateConfig: {
15
+ duration?: number;
16
+ easing?: string;
17
+ }): void;
18
+ goto(flag: 1 | -1, animateConfig: {
19
+ duration?: number;
20
+ easing?: string;
21
+ }): void;
22
+ forward(animateConfig: {
23
+ duration?: number;
24
+ easing?: string;
25
+ }): void;
26
+ backward(animateConfig: {
27
+ duration?: number;
28
+ easing?: string;
29
+ }): void;
30
+ }
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.Timeline = void 0;
6
+
7
+ const vutils_1 = require("@visactor/vutils"), base_1 = require("../core/base"), register_1 = require("./register");
8
+
9
+ (0, register_1.loadTimelineComponent)();
10
+
11
+ class Timeline extends base_1.AbstractComponent {
12
+ constructor(attributes, options) {
13
+ super((null == options ? void 0 : options.skipDefault) ? attributes : (0, vutils_1.merge)({}, Timeline.defaultAttributes, attributes)),
14
+ this.name = "timeline";
15
+ }
16
+ render() {
17
+ const {width: width, lineStyle: lineStyle, activeLineStyle: activeLineStyle, symbolStyle: symbolStyle, activeSymbolStyle: activeSymbolStyle, labelStyle: labelStyle, activeLabelStyle: activeLabelStyle, times: times, pointLayoutMode: pointLayoutMode, labelSpace: labelSpace, clipRange: clipRange, animation: animation} = this.attribute;
18
+ if (!times || !times.length) return;
19
+ const symbolHeight = ((0, vutils_1.isArray)(symbolStyle.size) ? symbolStyle.size[1] : symbolStyle.size) || 0, activeSymbolHeight = ((0,
20
+ vutils_1.isArray)(activeSymbolStyle.size) ? activeSymbolStyle.size[1] : activeSymbolStyle.size) || 0, lineSymbolHeight = Math.max(lineStyle.lineWidth || 0, activeLineStyle.lineWidth || 0, symbolHeight, activeSymbolHeight), lineY = lineSymbolHeight / 2, lineAttr = {
21
+ y: lineY,
22
+ points: [ {
23
+ x: 0,
24
+ y: 0
25
+ }, {
26
+ x: width,
27
+ y: 0
28
+ } ]
29
+ };
30
+ this._line = this.createOrUpdateChild("line-axes", Object.assign(Object.assign({}, lineStyle), lineAttr), "line"),
31
+ this._activeLine = this.createOrUpdateChild("active-line-axes", Object.assign(Object.assign(Object.assign({}, activeLineStyle), lineAttr), {
32
+ clipRange: clipRange
33
+ }), "line");
34
+ const activeWidth = width * clipRange, symbolGroup = this.createOrUpdateChild("symbol-group", {
35
+ y: lineY
36
+ }, "group"), symbolSpace = 1 === times.length ? width : "space-between" === pointLayoutMode ? width / (times.length - 1) : width / times.length, symbolStartX = "space-between" === pointLayoutMode ? 0 : symbolSpace / 2;
37
+ this._timesPercent = times.map(((_, i) => (symbolStartX + symbolSpace * i) / width)),
38
+ times.forEach(((item, i) => {
39
+ const x = this._timesPercent[i] * width;
40
+ symbolGroup.createOrUpdateChild(item.label, Object.assign(Object.assign({}, symbolStyle), {
41
+ x: x
42
+ }), "symbol");
43
+ })), this._symbolGroup = symbolGroup;
44
+ const labelY = lineSymbolHeight + labelSpace, labelGroup = this.createOrUpdateChild("label-group", {
45
+ y: labelY
46
+ }, "group");
47
+ times.forEach(((item, i) => {
48
+ const x = this._timesPercent[i] * width;
49
+ labelGroup.createOrUpdateChild(item.label, Object.assign(Object.assign({}, labelStyle), {
50
+ x: x,
51
+ text: item.label
52
+ }), "text");
53
+ })), this._labelGroup = labelGroup;
54
+ const setActive = (group, activeStyle) => {
55
+ group.forEachChildren((label => {
56
+ if (label.currentStates) {
57
+ const currentStates = label.currentStates;
58
+ label.clearStates(), label.useStates(currentStates, !1);
59
+ }
60
+ label.states = {
61
+ active: activeStyle
62
+ }, label.attribute.x <= activeWidth && label.useStates([ "active" ], animation);
63
+ }));
64
+ };
65
+ setActive(labelGroup, activeLabelStyle), setActive(symbolGroup, activeSymbolStyle);
66
+ }
67
+ appearAnimate(animateConfig) {
68
+ const {duration: duration = 1e3, easing: easing = "quadOut"} = animateConfig, {activeLabelStyle: activeLabelStyle, activeSymbolStyle: activeSymbolStyle} = this.attribute, percent = duration / 1e3, lineDuration = 500 * percent, activeLineDuration = 200 * percent, perSymbolDuration = 100 * percent, perSymbolNormalDuration = 90 * percent, symbolDelay = 100 * percent, symbolNormalDelay = 600 * percent;
69
+ if (this._line && (this._line.setAttributes({
70
+ clipRange: 0
71
+ }), this._line.animate().to({
72
+ clipRange: 1
73
+ }, lineDuration, easing)), this._activeLine && (this._activeLine.setAttributes({
74
+ opacity: 0
75
+ }), this._activeLine.animate().wait(500).to({
76
+ opacity: 1
77
+ }, activeLineDuration, easing)), this._symbolGroup) {
78
+ const size = this._symbolGroup.count - 1, delay = percent * (1 === size ? 0 : 400 / (size - 1)), delayNormal = percent * (1 === size ? 0 : 240 / (size - 1));
79
+ this._symbolGroup.forEachChildren(((symbol, i) => {
80
+ const originAttrs = Object.assign({}, symbol.attribute);
81
+ symbol.setAttributes({
82
+ opacity: 0
83
+ }), symbol.animate().wait(symbolDelay + delay * i).to({
84
+ opacity: 1
85
+ }, perSymbolDuration, easing), symbol.animate().wait(symbolNormalDelay + delayNormal * i).to(Object.assign({
86
+ scaleX: 1.8,
87
+ scaleY: 1.8
88
+ }, activeSymbolStyle), perSymbolNormalDuration, easing).to(Object.assign({
89
+ scaleX: 1,
90
+ scaleY: 1
91
+ }, originAttrs), perSymbolNormalDuration, easing);
92
+ }));
93
+ }
94
+ if (this._labelGroup) {
95
+ const size = this._labelGroup.count - 1, delay = percent * (1 === size ? 0 : 400 / (size - 1)), delayNormal = percent * (1 === size ? 0 : 240 / (size - 1));
96
+ this._labelGroup.forEachChildren(((label, i) => {
97
+ const originAttrs = Object.assign({}, label.attribute);
98
+ label.setAttributes({
99
+ opacity: 0
100
+ }), label.animate().wait(symbolDelay + delay * i).to({
101
+ opacity: 1
102
+ }, perSymbolDuration, easing), label.animate().wait(symbolNormalDelay + delayNormal * i).to(Object.assign({
103
+ dy: 10
104
+ }, activeLabelStyle), perSymbolNormalDuration, easing).to(Object.assign({
105
+ dy: 0
106
+ }, originAttrs), perSymbolNormalDuration, easing);
107
+ }));
108
+ }
109
+ }
110
+ goto(flag, animateConfig) {
111
+ var _a;
112
+ let {clipRange: clipRange} = this.attribute;
113
+ const {animation: animation} = this.attribute;
114
+ if (flag > 0) {
115
+ if (clipRange >= 1) return;
116
+ clipRange < 0 && (clipRange = 0);
117
+ } else {
118
+ if (clipRange <= 0) return;
119
+ clipRange > 1 && (clipRange = 1);
120
+ }
121
+ clipRange !== this.attribute.clipRange && this.setAttributes({
122
+ clipRange: clipRange
123
+ });
124
+ let i = 0;
125
+ for (;i < this._timesPercent.length && !(clipRange < this._timesPercent[i]); i++) ;
126
+ const nextClipRange = flag > 0 ? this._timesPercent[i] : this._timesPercent[i - 1] || 0;
127
+ if (animation) {
128
+ const {duration: duration = 1e3, easing: easing = "quadOut"} = animateConfig, actDuration = Math.abs(nextClipRange - clipRange) / (this._timesPercent[i] - (null !== (_a = this._timesPercent[i - 1]) && void 0 !== _a ? _a : 0)) * duration;
129
+ this.animate().to({
130
+ clipRange: nextClipRange
131
+ }, actDuration, easing);
132
+ } else this.setAttributes({
133
+ clipRange: nextClipRange
134
+ });
135
+ }
136
+ forward(animateConfig) {
137
+ this.goto(1, animateConfig);
138
+ }
139
+ backward(animateConfig) {
140
+ this.goto(-1, animateConfig);
141
+ }
142
+ }
143
+
144
+ exports.Timeline = Timeline, Timeline.defaultAttributes = {
145
+ labelSpace: 10,
146
+ pointLayoutMode: "space-around",
147
+ animation: !0,
148
+ symbolStyle: {
149
+ fill: "black",
150
+ size: 12,
151
+ symbolType: "circle"
152
+ },
153
+ activeSymbolStyle: {
154
+ fill: "orange"
155
+ },
156
+ lineStyle: {
157
+ lineDash: [ 2, 2 ],
158
+ lineCap: "butt",
159
+ stroke: "black",
160
+ lineWidth: 2
161
+ },
162
+ activeLineStyle: {
163
+ stroke: "orange",
164
+ lineWidth: 4
165
+ },
166
+ labelStyle: {
167
+ fontSize: 12,
168
+ fill: "black",
169
+ textAlign: "center",
170
+ textBaseline: "top"
171
+ },
172
+ activeLabelStyle: {
173
+ fontSize: 14,
174
+ fill: "orange"
175
+ },
176
+ clipRange: 0
177
+ };
178
+ //# sourceMappingURL=timeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/timeline/timeline.ts"],"names":[],"mappings":";;;AAAA,6CAAkD;AAClD,uCAAiD;AACjD,yCAAmD;AAMnD,IAAA,gCAAqB,GAAE,CAAC;AAExB,MAAa,QAAS,SAAQ,wBAA0C;IA4CtE,YAAY,UAAyB,EAAE,OAA0B;QAC/D,KAAK,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAA,cAAK,EAAC,EAAE,EAAE,QAAQ,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC,CAAC;QA5C/F,SAAI,GAAG,UAAU,CAAC;IA6ClB,CAAC;IAES,MAAM;QACd,MAAM,EACJ,KAAK,EACL,SAAS,EACT,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,gBAAgB,EAChB,KAAK,EACL,eAAe,EACf,UAAU,EACV,SAAS,EACT,SAAS,EACV,GAAG,IAAI,CAAC,SAAS,CAAC;QAEnB,IAAI,CAAC,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE;YAC5B,OAAO;SACR;QAGD,MAAM,YAAY,GAAG,CAAC,IAAA,gBAAO,EAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/F,MAAM,kBAAkB,GACtB,CAAC,IAAA,gBAAO,EAAC,iBAAiB,CAAC,IAAI,CAAC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AI,EAAE,OAAO;QACb,SAAS,EAAE,QAAQ;QACnB,YAAY,EAAE,KAAK;KACpB;IACD,gBAAgB,EAAE;QAChB,QAAQ,EAAE,EAAE;QACZ,IAAI,EAAE,QAAQ;KACf;IACD,SAAS,EAAE,CAAC;CACb,CAAC","file":"timeline.js","sourcesContent":["import { isArray, merge } from '@visactor/vutils';\nimport { AbstractComponent } from '../core/base';\nimport { loadTimelineComponent } from './register';\nimport type { TimelineAttrs } from './type';\nimport type { ComponentOptions } from '../interface';\nimport type { IGraphicAttribute, IGroup, ILine, IText } from '@visactor/vrender-core';\nimport type { ISymbol } from '@visactor/vrender-core';\n\nloadTimelineComponent();\n\nexport class Timeline extends AbstractComponent<Required<TimelineAttrs>> {\n name = 'timeline';\n\n private _line?: ILine;\n private _activeLine?: ILine;\n private _symbolGroup?: IGroup;\n private _labelGroup?: IGroup;\n private _timesPercent?: number[];\n\n static defaultAttributes: Partial<TimelineAttrs> = {\n labelSpace: 10,\n pointLayoutMode: 'space-around',\n animation: true,\n symbolStyle: {\n fill: 'black',\n size: 12,\n symbolType: 'circle'\n },\n activeSymbolStyle: {\n fill: 'orange'\n },\n lineStyle: {\n lineDash: [2, 2],\n lineCap: 'butt',\n stroke: 'black',\n lineWidth: 2\n },\n activeLineStyle: {\n stroke: 'orange',\n lineWidth: 4\n },\n labelStyle: {\n fontSize: 12,\n fill: 'black',\n textAlign: 'center',\n textBaseline: 'top'\n },\n activeLabelStyle: {\n fontSize: 14,\n fill: 'orange'\n },\n clipRange: 0\n };\n\n constructor(attributes: TimelineAttrs, options?: ComponentOptions) {\n super(options?.skipDefault ? attributes : merge({}, Timeline.defaultAttributes, attributes));\n }\n\n protected render(): void {\n const {\n width,\n lineStyle,\n activeLineStyle,\n symbolStyle,\n activeSymbolStyle,\n labelStyle,\n activeLabelStyle,\n times,\n pointLayoutMode,\n labelSpace,\n clipRange,\n animation\n } = this.attribute;\n\n if (!(times && times.length)) {\n return;\n }\n\n // 计算线段中心的y位置,考虑线宽和symbol宽度\n const symbolHeight = (isArray(symbolStyle.size) ? symbolStyle.size[1] : symbolStyle.size) || 0;\n const activeSymbolHeight =\n (isArray(activeSymbolStyle.size) ? activeSymbolStyle.size[1] : activeSymbolStyle.size) || 0;\n const lineSymbolHeight = Math.max(\n lineStyle.lineWidth || 0,\n activeLineStyle.lineWidth || 0,\n symbolHeight,\n activeSymbolHeight\n );\n const lineY = lineSymbolHeight / 2;\n const lineAttr = {\n y: lineY,\n points: [\n { x: 0, y: 0 },\n { x: width, y: 0 }\n ]\n };\n this._line = this.createOrUpdateChild(\n 'line-axes',\n {\n ...lineStyle,\n ...lineAttr\n },\n 'line'\n ) as ILine;\n this._activeLine = this.createOrUpdateChild(\n 'active-line-axes',\n {\n ...activeLineStyle,\n ...lineAttr,\n clipRange\n },\n 'line'\n ) as ILine;\n\n const activeWidth = width * clipRange;\n\n const symbolGroup = this.createOrUpdateChild(\n 'symbol-group',\n {\n y: lineY\n },\n 'group'\n ) as IGroup;\n const symbolSpace =\n times.length === 1\n ? width\n : pointLayoutMode === 'space-between'\n ? width / (times.length - 1)\n : width / times.length;\n const symbolStartX = pointLayoutMode === 'space-between' ? 0 : symbolSpace / 2;\n this._timesPercent = times.map((_, i) => (symbolStartX + symbolSpace * i) / width);\n\n times.forEach((item, i) => {\n const x = this._timesPercent[i] * width;\n symbolGroup.createOrUpdateChild(\n item.label,\n {\n ...symbolStyle,\n x\n },\n 'symbol'\n );\n });\n this._symbolGroup = symbolGroup;\n\n const labelY = lineSymbolHeight + labelSpace;\n const labelGroup = this.createOrUpdateChild(\n 'label-group',\n {\n y: labelY\n },\n 'group'\n ) as IGroup;\n\n times.forEach((item, i) => {\n const x = this._timesPercent[i] * width;\n labelGroup.createOrUpdateChild(\n item.label,\n {\n ...labelStyle,\n x,\n text: item.label\n },\n 'text'\n );\n });\n this._labelGroup = labelGroup;\n\n const setActive = (group: IGroup, activeStyle: Partial<IGraphicAttribute>) => {\n group.forEachChildren((label: IText) => {\n if (label.currentStates) {\n const currentStates = label.currentStates;\n label.clearStates();\n label.useStates(currentStates, false);\n }\n label.states = {\n active: activeStyle\n };\n if (label.attribute.x <= activeWidth) {\n label.useStates(['active'], animation);\n }\n });\n };\n\n setActive(labelGroup, activeLabelStyle);\n setActive(symbolGroup, activeSymbolStyle);\n }\n\n appearAnimate(animateConfig: { duration?: number; easing?: string }) {\n // 基准时间,line[0, 500], point[100, 600] 100 onebyone, pointNormal[600, 1000] 90+90 onebyone, activeLine[500, 700]\n // line和activeLine的clipRange\n const { duration = 1000, easing = 'quadOut' } = animateConfig;\n const { activeLabelStyle, activeSymbolStyle } = this.attribute;\n const percent = duration / 1000;\n const lineDuration = percent * 500;\n const activeLineDuration = percent * 200;\n const perSymbolDuration = percent * 100;\n const perSymbolNormalDuration = percent * 90;\n const symbolDelay = percent * 100;\n const symbolNormalDelay = percent * 600;\n if (this._line) {\n this._line.setAttributes({ clipRange: 0 });\n this._line.animate().to({ clipRange: 1 }, lineDuration, easing as any);\n }\n if (this._activeLine) {\n this._activeLine.setAttributes({ opacity: 0 });\n this._activeLine\n .animate()\n .wait(500)\n .to({ opacity: 1 }, activeLineDuration, easing as any);\n }\n if (this._symbolGroup) {\n const size = this._symbolGroup.count - 1;\n const delay = percent * (size === 1 ? 0 : (500 - 100) / (size - 1));\n const delayNormal = percent * (size === 1 ? 0 : (400 - 160) / (size - 1));\n this._symbolGroup.forEachChildren((symbol: ISymbol, i) => {\n const originAttrs = { ...symbol.attribute };\n symbol.setAttributes({ opacity: 0 });\n symbol\n .animate()\n .wait(symbolDelay + delay * i)\n .to({ opacity: 1 }, perSymbolDuration, easing as any);\n symbol\n .animate()\n .wait(symbolNormalDelay + delayNormal * i)\n .to({ scaleX: 1.8, scaleY: 1.8, ...activeSymbolStyle }, perSymbolNormalDuration, easing as any)\n .to({ scaleX: 1, scaleY: 1, ...originAttrs }, perSymbolNormalDuration, easing as any);\n });\n }\n if (this._labelGroup) {\n const size = this._labelGroup.count - 1;\n const delay = percent * (size === 1 ? 0 : (500 - 100) / (size - 1));\n const delayNormal = percent * (size === 1 ? 0 : (400 - 160) / (size - 1));\n this._labelGroup.forEachChildren((label: IText, i) => {\n const originAttrs = { ...label.attribute };\n label.setAttributes({ opacity: 0 });\n label\n .animate()\n .wait(symbolDelay + delay * i)\n .to({ opacity: 1 }, perSymbolDuration, easing as any);\n label\n .animate()\n .wait(symbolNormalDelay + delayNormal * i)\n .to({ dy: 10, ...activeLabelStyle }, perSymbolNormalDuration, easing as any)\n .to({ dy: 0, ...originAttrs }, perSymbolNormalDuration, easing as any);\n });\n }\n }\n\n goto(flag: 1 | -1, animateConfig: { duration?: number; easing?: string }) {\n let { clipRange } = this.attribute;\n const { animation } = this.attribute;\n\n // 合法性判断\n if (flag > 0) {\n if (clipRange >= 1) {\n return;\n } else if (clipRange < 0) {\n clipRange = 0;\n }\n } else {\n if (clipRange <= 0) {\n return;\n } else if (clipRange > 1) {\n clipRange = 1;\n }\n }\n\n if (clipRange !== this.attribute.clipRange) {\n this.setAttributes({ clipRange });\n }\n\n // 判断区间\n let i = 0;\n for (; i < this._timesPercent.length; i++) {\n if (clipRange < this._timesPercent[i]) {\n break;\n }\n }\n\n const nextClipRange = flag > 0 ? this._timesPercent[i] : this._timesPercent[i - 1] || 0;\n if (animation) {\n const { duration = 1000, easing = 'quadOut' } = animateConfig;\n const actDuration =\n (Math.abs(nextClipRange - clipRange) / (this._timesPercent[i] - (this._timesPercent[i - 1] ?? 0))) * duration;\n this.animate().to({ clipRange: nextClipRange }, actDuration, easing as any);\n } else {\n this.setAttributes({ clipRange: nextClipRange });\n }\n }\n\n forward(animateConfig: { duration?: number; easing?: string }) {\n this.goto(1, animateConfig);\n }\n\n backward(animateConfig: { duration?: number; easing?: string }) {\n this.goto(-1, animateConfig);\n }\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import type { IGroupGraphicAttribute, ILineGraphicAttribute, ISymbolGraphicAttribute, ITextGraphicAttribute } from '@visactor/vrender-core';
2
+ export interface TimelineAttrs extends IGroupGraphicAttribute {
3
+ width: number;
4
+ times: {
5
+ label: string;
6
+ desc?: string;
7
+ }[];
8
+ labelSpace?: number;
9
+ symbolStyle?: Partial<ISymbolGraphicAttribute>;
10
+ activeSymbolStyle?: Partial<ISymbolGraphicAttribute>;
11
+ lineStyle?: Partial<ILineGraphicAttribute>;
12
+ activeLineStyle?: Partial<ILineGraphicAttribute>;
13
+ labelStyle?: Partial<ITextGraphicAttribute>;
14
+ activeLabelStyle?: Partial<ITextGraphicAttribute>;
15
+ pointLayoutMode?: 'space-around' | 'space-between';
16
+ clipRange?: number;
17
+ animation?: boolean;
18
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ });
6
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/timeline/type.ts"],"names":[],"mappings":"","file":"type.js","sourcesContent":["import type {\n IGroupGraphicAttribute,\n ILineGraphicAttribute,\n ISymbolGraphicAttribute,\n ITextGraphicAttribute\n} from '@visactor/vrender-core';\nimport { ILineAttribute, ISymbolAttribute } from '@visactor/vrender-core';\n\nexport interface TimelineAttrs extends IGroupGraphicAttribute {\n width: number;\n // height?: number;\n times: { label: string; desc?: string }[];\n labelSpace?: number;\n symbolStyle?: Partial<ISymbolGraphicAttribute>;\n activeSymbolStyle?: Partial<ISymbolGraphicAttribute>;\n lineStyle?: Partial<ILineGraphicAttribute>;\n activeLineStyle?: Partial<ILineGraphicAttribute>;\n labelStyle?: Partial<ITextGraphicAttribute>;\n activeLabelStyle?: Partial<ITextGraphicAttribute>;\n pointLayoutMode?: 'space-around' | 'space-between';\n // 当前进度\n clipRange?: number;\n animation?: boolean;\n}\n"]}