@visactor/vgrammar-core 0.10.0-alpha.0 → 0.10.0-alpha.2

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 (79) hide show
  1. package/cjs/component/label.js +15 -10
  2. package/cjs/component/label.js.map +1 -1
  3. package/cjs/env.d.ts +3 -1
  4. package/cjs/env.js +22 -16
  5. package/cjs/env.js.map +1 -1
  6. package/cjs/graph/animation/animator.js +3 -1
  7. package/cjs/graph/animation/animator.js.map +1 -1
  8. package/cjs/graph/attributes/helpers.js +4 -4
  9. package/cjs/graph/attributes/helpers.js.map +1 -1
  10. package/cjs/graph/attributes/transform.js +1 -19
  11. package/cjs/graph/attributes/transform.js.map +1 -1
  12. package/cjs/graph/canvas-renderer.js +2 -1
  13. package/cjs/graph/canvas-renderer.js.map +1 -1
  14. package/cjs/graph/element.d.ts +2 -0
  15. package/cjs/graph/element.js +21 -18
  16. package/cjs/graph/element.js.map +1 -1
  17. package/cjs/graph/glyph-element.js +2 -3
  18. package/cjs/graph/glyph-element.js.map +1 -1
  19. package/cjs/index.d.ts +1 -1
  20. package/cjs/index.js +1 -1
  21. package/cjs/index.js.map +1 -1
  22. package/cjs/theme/common/component.d.ts +2 -1
  23. package/cjs/theme/common/component.js +20 -6
  24. package/cjs/theme/common/component.js.map +1 -1
  25. package/cjs/types/element.d.ts +2 -0
  26. package/cjs/types/element.js.map +1 -1
  27. package/cjs/types/grammar.d.ts +2 -1
  28. package/cjs/types/grammar.js.map +1 -1
  29. package/cjs/types/mark.d.ts +1 -0
  30. package/cjs/types/mark.js.map +1 -1
  31. package/cjs/types/theme.d.ts +2 -1
  32. package/cjs/types/theme.js.map +1 -1
  33. package/cjs/view/View.js +3 -1
  34. package/cjs/view/View.js.map +1 -1
  35. package/cjs/view/dataflow.js +7 -7
  36. package/cjs/view/dataflow.js.map +1 -1
  37. package/cjs/view/mark.d.ts +3 -1
  38. package/cjs/view/mark.js +9 -3
  39. package/cjs/view/mark.js.map +1 -1
  40. package/es/component/label.js +15 -10
  41. package/es/component/label.js.map +1 -1
  42. package/es/env.d.ts +3 -1
  43. package/es/env.js +9 -1
  44. package/es/env.js.map +1 -1
  45. package/es/graph/animation/animator.js +3 -1
  46. package/es/graph/animation/animator.js.map +1 -1
  47. package/es/graph/attributes/helpers.js +4 -4
  48. package/es/graph/attributes/helpers.js.map +1 -1
  49. package/es/graph/attributes/transform.js +1 -15
  50. package/es/graph/attributes/transform.js.map +1 -1
  51. package/es/graph/canvas-renderer.js +2 -1
  52. package/es/graph/canvas-renderer.js.map +1 -1
  53. package/es/graph/element.d.ts +2 -0
  54. package/es/graph/element.js +21 -17
  55. package/es/graph/element.js.map +1 -1
  56. package/es/graph/glyph-element.js +2 -3
  57. package/es/graph/glyph-element.js.map +1 -1
  58. package/es/index.d.ts +1 -1
  59. package/es/index.js +1 -1
  60. package/es/index.js.map +1 -1
  61. package/es/theme/common/component.d.ts +2 -1
  62. package/es/theme/common/component.js +21 -5
  63. package/es/theme/common/component.js.map +1 -1
  64. package/es/types/element.d.ts +2 -0
  65. package/es/types/element.js.map +1 -1
  66. package/es/types/grammar.d.ts +2 -1
  67. package/es/types/grammar.js.map +1 -1
  68. package/es/types/mark.d.ts +1 -0
  69. package/es/types/mark.js.map +1 -1
  70. package/es/types/theme.d.ts +2 -1
  71. package/es/types/theme.js.map +1 -1
  72. package/es/view/View.js +3 -1
  73. package/es/view/View.js.map +1 -1
  74. package/es/view/dataflow.js +9 -8
  75. package/es/view/dataflow.js.map +1 -1
  76. package/es/view/mark.d.ts +3 -1
  77. package/es/view/mark.js +9 -3
  78. package/es/view/mark.js.map +1 -1
  79. package/package.json +12 -12
@@ -7,40 +7,45 @@ Object.defineProperty(exports, "__esModule", {
7
7
  const vutils_1 = require("@visactor/vutils"), vrender_components_1 = require("@visactor/vrender-components"), enums_1 = require("../graph/enums"), component_1 = require("../view/component"), encode_1 = require("../graph/mark/encode"), util_1 = require("../parse/util"), factory_1 = require("../core/factory"), generateLabelAttributes = (marks, groupSize, encoder, labelStyle, parameters, theme) => {
8
8
  var _a;
9
9
  const labelTheme = null === (_a = null == theme ? void 0 : theme.components) || void 0 === _a ? void 0 : _a.dataLabel, dataLabels = marks.map(((mark, index) => {
10
- var _a, _b, _c, _d, _e, _f, _g, _h;
10
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
11
11
  const labelParameters = Object.assign(Object.assign({}, parameters), {
12
12
  labelIndex: index
13
- });
13
+ }), addition = (0, util_1.invokeFunctionType)(labelStyle, labelParameters, mark);
14
14
  let currentTheme = {};
15
15
  switch (mark.markType) {
16
16
  case enums_1.GrammarMarkType.line:
17
17
  case enums_1.GrammarMarkType.area:
18
- currentTheme = null === (_a = null == theme ? void 0 : theme.components) || void 0 === _a ? void 0 : _a.lineDataLabel;
18
+ currentTheme = "line" === (null == addition ? void 0 : addition.type) ? null === (_a = null == theme ? void 0 : theme.components) || void 0 === _a ? void 0 : _a.lineLabel : "area" === (null == addition ? void 0 : addition.type) ? null === (_b = null == theme ? void 0 : theme.components) || void 0 === _b ? void 0 : _b.areaLabel : null === (_c = null == theme ? void 0 : theme.components) || void 0 === _c ? void 0 : _c.lineDataLabel;
19
19
  break;
20
20
 
21
21
  case enums_1.GrammarMarkType.rect:
22
22
  case enums_1.GrammarMarkType.interval:
23
- currentTheme = null === (_b = null == theme ? void 0 : theme.components) || void 0 === _b ? void 0 : _b.rectLabel;
23
+ currentTheme = null === (_d = null == theme ? void 0 : theme.components) || void 0 === _d ? void 0 : _d.rectLabel;
24
24
  break;
25
25
 
26
26
  case enums_1.GrammarMarkType.symbol:
27
27
  case enums_1.GrammarMarkType.circle:
28
28
  case enums_1.GrammarMarkType.cell:
29
- currentTheme = null === (_c = null == theme ? void 0 : theme.components) || void 0 === _c ? void 0 : _c.symbolLabel;
29
+ currentTheme = null === (_e = null == theme ? void 0 : theme.components) || void 0 === _e ? void 0 : _e.symbolLabel;
30
30
  break;
31
31
 
32
32
  case enums_1.GrammarMarkType.arc:
33
33
  case enums_1.GrammarMarkType.arc3d:
34
- currentTheme = null === (_d = null == theme ? void 0 : theme.components) || void 0 === _d ? void 0 : _d.arcLabel;
34
+ currentTheme = null === (_f = null == theme ? void 0 : theme.components) || void 0 === _f ? void 0 : _f.arcLabel;
35
35
  break;
36
36
 
37
37
  case enums_1.GrammarMarkType.polygon:
38
38
  case enums_1.GrammarMarkType.path:
39
39
  default:
40
- currentTheme = null === (_e = null == theme ? void 0 : theme.components) || void 0 === _e ? void 0 : _e.pointLabel;
40
+ currentTheme = null === (_g = null == theme ? void 0 : theme.components) || void 0 === _g ? void 0 : _g.pointLabel;
41
41
  }
42
- const data = [], themeDatum = null !== (_g = null === (_f = null == currentTheme ? void 0 : currentTheme.data) || void 0 === _f ? void 0 : _f[0]) && void 0 !== _g ? _g : {};
43
- mark.elements.forEach((element => {
42
+ const data = null !== (_h = null == addition ? void 0 : addition.data) && void 0 !== _h ? _h : [], themeDatum = null !== (_k = null === (_j = null == currentTheme ? void 0 : currentTheme.data) || void 0 === _j ? void 0 : _j[0]) && void 0 !== _k ? _k : {};
43
+ data && data.length > 0 ? data.forEach(((d, index) => {
44
+ if (mark.elements[index]) {
45
+ const attributes = (0, encode_1.invokeEncoder)(encoder, d, mark.elements[index], labelParameters);
46
+ (0, vutils_1.merge)(d, themeDatum, attributes);
47
+ }
48
+ })) : mark.elements.forEach((element => {
44
49
  if ("willRelease" !== element.getGraphicItem().releaseStatus) if (mark.isCollectionMark()) {
45
50
  element.getDatum().forEach((entry => {
46
51
  const attributes = (0, encode_1.invokeEncoder)(encoder, entry, element, labelParameters);
@@ -52,7 +57,7 @@ const vutils_1 = require("@visactor/vutils"), vrender_components_1 = require("@v
52
57
  data.push(datum);
53
58
  }
54
59
  }));
55
- const addition = (0, util_1.invokeFunctionType)(labelStyle, labelParameters, mark), graphicItemName = null === (_h = mark.graphicItem) || void 0 === _h ? void 0 : _h.name;
60
+ const graphicItemName = null === (_l = mark.graphicItem) || void 0 === _l ? void 0 : _l.name;
56
61
  return (0, vutils_1.merge)({}, currentTheme, {
57
62
  data: data,
58
63
  baseMarkGroupName: graphicItemName,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/component/label.ts"],"names":[],"mappings":";;;AAAA,6CAAiE;AAIjE,qEAAyD;AAYzD,0CAAgE;AAEhE,iDAA8C;AAC9C,iDAAqD;AACrD,wCAAmD;AACnD,6CAA0C;AAEnC,MAAM,uBAAuB,GAAG,CACrC,KAAc,EACd,SAA4C,EAC5C,OAA6B,EAC7B,UAAqD,EACrD,UAAe,EACf,KAAc,EACE,EAAE;;IAClB,MAAM,UAAU,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,0CAAE,SAAS,CAAC;IAChD,MAAM,UAAU,GAAG,KAAK;SACrB,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;;QACnB,MAAM,eAAe,mCAAQ,UAAU,KAAE,UAAU,EAAE,KAAK,GAAE,CAAC;QAC7D,IAAI,YAAY,GAAQ,EAAE,CAAC;QAC3B,QAAQ,IAAI,CAAC,QAAQ,EAAE;YACrB,KAAK,uBAAe,CAAC,IAAI,CAAC;YAC1B,KAAK,uBAAe,CAAC,IAAI;gBACvB,YAAY,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,0CAAE,aAAa,CAAC;gBAChD,MAAM;YACR,KAAK,uBAAe,CAAC,IAAI,CAAC;YAC1B,KAAK,uBAAe,CAAC,QAAQ;gBAC3B,YAAY,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,0CAAE,SAAS,CAAC;gBAC5C,MAAM;YACR,KAAK,uBAAe,CAAC,MAAM,CAAC;YAC5B,KAAK,uBAAe,CAAC,MAAM,CAAC;YAC5B,KAAK,uBAAe,CAAC,IAAI;gBACvB,YAAY,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,0CAAE,WA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C;wBAED,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;wBAEvE,OAAO,IAAA,+BAAuB,EAC5B,KAAK,EACL,IAAI,EACJ,OAA+B,EAC/B,IAAI,CAAC,IAAI,CAAC,UAAU,EACpB,UAAU,EACV,KAAK,CACN,CAAC;oBACJ,CAAC;iBACF,CAAC;aACH;YACD,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,IAAI,CAAC,SAAS,GAAG,iBAAiB,CAAC;IACrC,CAAC;;AA1EH,sBA2EC;AA1EiB,mBAAa,GAAW,qBAAa,CAAC,KAAK,CAAC;AA4EvD,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,iBAAO,CAAC,wBAAwB,CAC9B,qBAAa,CAAC,KAAK,EACnB,CAAC,KAAqB,EAAE,EAAE,CAAC,IAAI,8BAAS,CAAC,KAAK,CAAwB,CACvE,CAAC;IAEF,iBAAO,CAAC,iBAAiB,CAAC,qBAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACxD,CAAC,CAAC;AAPW,QAAA,aAAa,iBAOxB","file":"label.js","sourcesContent":["import { array, isNil, isString, merge } from '@visactor/vutils';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { BaseLabelAttrs, DataLabelAttrs } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { DataLabel } from '@visactor/vrender-components';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n IMark,\n ITheme,\n IView,\n MarkFunctionType,\n Nil,\n StateEncodeSpec\n} from '../types';\nimport { ComponentEnum, GrammarMarkType } from '../graph/enums';\nimport type { ILabel, LabelSpec } from '../types/component';\nimport { Component } from '../view/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport { Factory } from '../core/factory';\n\nexport const generateLabelAttributes = (\n marks: IMark[],\n groupSize: { width: number; height: number },\n encoder: BaseSignleEncodeSpec,\n labelStyle: MarkFunctionType<Partial<BaseLabelAttrs>>,\n parameters: any,\n theme?: ITheme\n): DataLabelAttrs => {\n const labelTheme = theme?.components?.dataLabel;\n const dataLabels = marks\n .map((mark, index) => {\n const labelParameters = { ...parameters, labelIndex: index };\n let currentTheme: any = {};\n switch (mark.markType) {\n case GrammarMarkType.line:\n case GrammarMarkType.area:\n currentTheme = theme?.components?.lineDataLabel;\n break;\n case GrammarMarkType.rect:\n case GrammarMarkType.interval:\n currentTheme = theme?.components?.rectLabel;\n break;\n case GrammarMarkType.symbol:\n case GrammarMarkType.circle:\n case GrammarMarkType.cell:\n currentTheme = theme?.components?.symbolLabel;\n break;\n case GrammarMarkType.arc:\n case GrammarMarkType.arc3d:\n currentTheme = theme?.components?.arcLabel;\n break;\n case GrammarMarkType.polygon:\n case GrammarMarkType.path:\n default:\n currentTheme = theme?.components?.pointLabel;\n break;\n }\n const data: any[] = [];\n const themeDatum = currentTheme?.data?.[0] ?? {};\n // process by order of elements\n mark.elements.forEach(element => {\n const graphicItem = element.getGraphicItem();\n if ((graphicItem as any).releaseStatus !== 'willRelease') {\n if (mark.isCollectionMark()) {\n const datum = element.getDatum();\n\n datum.forEach((entry: any) => {\n const attributes = invokeEncoder(encoder, entry, element, labelParameters);\n data.push(merge({}, themeDatum, attributes));\n });\n } else {\n const attributes = invokeEncoder(encoder, element.getDatum(), element, labelParameters);\n const datum = merge({}, themeDatum, attributes);\n data.push(datum);\n }\n }\n });\n const addition = invokeFunctionType(labelStyle, labelParameters, mark);\n const graphicItemName = mark.graphicItem?.name;\n return merge(\n {},\n currentTheme,\n {\n data,\n baseMarkGroupName: graphicItemName,\n // FIXME: hack\n // 标签是对数据顺序有强要求的场景,因为顺序会影响标签躲避结果;而目前没有机制保证 vrender 图元顺序与数据顺序一致。\n // 这里目前只能通过自定义方法来 hack\n getBaseMarks: () => mark.elements.map(element => element.getGraphicItem())\n },\n addition ?? {}\n );\n })\n .filter(label => !isNil(label));\n\n return merge({}, labelTheme, { size: groupSize, dataLabels });\n};\n\nexport class Label extends Component implements ILabel {\n static readonly componentType: string = ComponentEnum.label;\n protected declare spec: LabelSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.label, group);\n this.spec.componentType = ComponentEnum.label;\n }\n\n protected parseAddition(spec: LabelSpec) {\n super.parseAddition(spec);\n this.labelStyle(spec.labelStyle);\n this.size(spec.size);\n this.target(spec.target);\n return this;\n }\n\n labelStyle(style: MarkFunctionType<Partial<BaseLabelAttrs>>) {\n return this.setFunctionSpec(style, 'labelStyle');\n }\n\n size(size: LabelSpec['size']) {\n return this.setFunctionSpec(size, 'size');\n }\n\n target(mark: IMark | IMark[] | string | string[] | Nil): this {\n if (this.spec.target) {\n const prevMarks = array(this.spec.target).map(m => (isString(m) ? this.view.getMarkById(m) : m));\n this.detach(prevMarks);\n }\n this.spec.target = mark;\n if (mark) {\n const nextMarks = array(mark).map(m => (isString(m) ? this.view.getMarkById(m) : m));\n this.attach(nextMarks);\n }\n this.commit();\n return this;\n }\n\n protected _updateComponentEncoders() {\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const marks = array(this.spec.target).map(m => (isString(m) ? this.view.getMarkById(m) : m));\n const groupGraphicItem = this.group?.getGroupGraphicItem?.();\n let size = invokeFunctionType(this.spec.size, parameters);\n if (!size) {\n size = groupGraphicItem\n ? {\n width: groupGraphicItem.attribute.width ?? groupGraphicItem.AABBBounds.width(),\n height: groupGraphicItem.attribute.height ?? groupGraphicItem.AABBBounds.height()\n }\n : { width: Infinity, height: Infinity };\n }\n\n const theme = this.spec.skipTheme ? null : this.view.getCurrentTheme();\n\n return generateLabelAttributes(\n marks,\n size,\n encoder as BaseSignleEncodeSpec,\n this.spec.labelStyle,\n parameters,\n theme\n );\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n}\n\nexport const registerLabel = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.label,\n (attrs: DataLabelAttrs) => new DataLabel(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.label, Label);\n};\n"]}
1
+ {"version":3,"sources":["../src/component/label.ts"],"names":[],"mappings":";;;AACA,6CAAuE;AAIvE,qEAAyD;AAYzD,0CAAgE;AAEhE,iDAA8C;AAC9C,iDAAqD;AACrD,wCAAmD;AACnD,6CAA0C;AAEnC,MAAM,uBAAuB,GAAG,CACrC,KAAc,EACd,SAA4C,EAC5C,OAA6B,EAC7B,UAAqD,EACrD,UAAe,EACf,KAAc,EACE,EAAE;;IAClB,MAAM,UAAU,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,0CAAE,SAAS,CAAC;IAChD,MAAM,UAAU,GAAG,KAAK;SACrB,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;;QACnB,MAAM,eAAe,mCAAQ,UAAU,KAAE,UAAU,EAAE,KAAK,GAAE,CAAC;QAC7D,MAAM,QAAQ,GAAG,IAAA,yBAAkB,EAAC,UAAU,EAAE,eAAe,EAAE,IAAI,CAAC,CAAC;QACvE,IAAI,YAAY,GAAQ,EAAE,CAAC;QAE3B,QAAQ,IAAI,CAAC,QAAQ,EAAE;YACrB,KAAK,uBAAe,CAAC,IAAI,CAAC;YAC1B,KAAK,uBAAe,CAAC,IAAI;gBACvB,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,MAAK,MAAM,EAAE;oBAC7B,YAAY,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,0CAAE,SAAS,CAAC;iBAC7C;qBAAM,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ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IAAI,CAAC,UAAU,EACpB,UAAU,EACV,KAAK,CACN,CAAC;oBACJ,CAAC;iBACF,CAAC;aACH;YACD,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,IAAI,CAAC,SAAS,GAAG,iBAAiB,CAAC;IACrC,CAAC;;AA1EH,sBA2EC;AA1EiB,mBAAa,GAAW,qBAAa,CAAC,KAAK,CAAC;AA4EvD,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,iBAAO,CAAC,wBAAwB,CAC9B,qBAAa,CAAC,KAAK,EACnB,CAAC,KAAqB,EAAE,EAAE,CAAC,IAAI,8BAAS,CAAC,KAAK,CAAwB,CACvE,CAAC;IAEF,iBAAO,CAAC,iBAAiB,CAAC,qBAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACxD,CAAC,CAAC;AAPW,QAAA,aAAa,iBAOxB","file":"label.js","sourcesContent":["import { load } from './../util/data';\nimport { array, isNil, isString, merge, last } from '@visactor/vutils';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { BaseLabelAttrs, DataLabelAttrs } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { DataLabel } from '@visactor/vrender-components';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n IMark,\n ITheme,\n IView,\n MarkFunctionType,\n Nil,\n StateEncodeSpec\n} from '../types';\nimport { ComponentEnum, GrammarMarkType } from '../graph/enums';\nimport type { ILabel, LabelSpec } from '../types/component';\nimport { Component } from '../view/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport { Factory } from '../core/factory';\n\nexport const generateLabelAttributes = (\n marks: IMark[],\n groupSize: { width: number; height: number },\n encoder: BaseSignleEncodeSpec,\n labelStyle: MarkFunctionType<Partial<BaseLabelAttrs>>,\n parameters: any,\n theme?: ITheme\n): DataLabelAttrs => {\n const labelTheme = theme?.components?.dataLabel;\n const dataLabels = marks\n .map((mark, index) => {\n const labelParameters = { ...parameters, labelIndex: index };\n const addition = invokeFunctionType(labelStyle, labelParameters, mark);\n let currentTheme: any = {};\n\n switch (mark.markType) {\n case GrammarMarkType.line:\n case GrammarMarkType.area:\n if (addition?.type === 'line') {\n currentTheme = theme?.components?.lineLabel;\n } else if (addition?.type === 'area') {\n currentTheme = theme?.components?.areaLabel;\n } else {\n currentTheme = theme?.components?.lineDataLabel;\n }\n break;\n case GrammarMarkType.rect:\n case GrammarMarkType.interval:\n currentTheme = theme?.components?.rectLabel;\n break;\n case GrammarMarkType.symbol:\n case GrammarMarkType.circle:\n case GrammarMarkType.cell:\n currentTheme = theme?.components?.symbolLabel;\n break;\n case GrammarMarkType.arc:\n case GrammarMarkType.arc3d:\n currentTheme = theme?.components?.arcLabel;\n break;\n case GrammarMarkType.polygon:\n case GrammarMarkType.path:\n default:\n currentTheme = theme?.components?.pointLabel;\n break;\n }\n\n const data: any[] = addition?.data ?? [];\n const themeDatum = currentTheme?.data?.[0] ?? {};\n\n if (data && data.length > 0) {\n data.forEach((d, index) => {\n if (mark.elements[index]) {\n const attributes = invokeEncoder(encoder, d, mark.elements[index], labelParameters);\n merge(d, themeDatum, attributes);\n }\n });\n } else {\n // process by order of elements\n mark.elements.forEach(element => {\n const graphicItem = element.getGraphicItem();\n if ((graphicItem as any).releaseStatus !== 'willRelease') {\n if (mark.isCollectionMark()) {\n const datum = element.getDatum();\n\n datum.forEach((entry: any) => {\n const attributes = invokeEncoder(encoder, entry, element, labelParameters);\n data.push(merge({}, themeDatum, attributes));\n });\n } else {\n const attributes = invokeEncoder(encoder, element.getDatum(), element, labelParameters);\n const datum = merge({}, themeDatum, attributes);\n data.push(datum);\n }\n }\n });\n }\n\n const graphicItemName = mark.graphicItem?.name;\n return merge(\n {},\n currentTheme,\n {\n data,\n baseMarkGroupName: graphicItemName,\n // FIXME: hack\n // 标签是对数据顺序有强要求的场景,因为顺序会影响标签躲避结果;而目前没有机制保证 vrender 图元顺序与数据顺序一致。\n // 这里目前只能通过自定义方法来 hack\n getBaseMarks: () => mark.elements.map(element => element.getGraphicItem())\n },\n addition ?? {}\n );\n })\n .filter(label => !isNil(label));\n\n return merge({}, labelTheme, { size: groupSize, dataLabels });\n};\n\nexport class Label extends Component implements ILabel {\n static readonly componentType: string = ComponentEnum.label;\n protected declare spec: LabelSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.label, group);\n this.spec.componentType = ComponentEnum.label;\n }\n\n protected parseAddition(spec: LabelSpec) {\n super.parseAddition(spec);\n this.labelStyle(spec.labelStyle);\n this.size(spec.size);\n this.target(spec.target);\n return this;\n }\n\n labelStyle(style: MarkFunctionType<Partial<BaseLabelAttrs>>) {\n return this.setFunctionSpec(style, 'labelStyle');\n }\n\n size(size: LabelSpec['size']) {\n return this.setFunctionSpec(size, 'size');\n }\n\n target(mark: IMark | IMark[] | string | string[] | Nil): this {\n if (this.spec.target) {\n const prevMarks = array(this.spec.target).map(m => (isString(m) ? this.view.getMarkById(m) : m));\n this.detach(prevMarks);\n }\n this.spec.target = mark;\n if (mark) {\n const nextMarks = array(mark).map(m => (isString(m) ? this.view.getMarkById(m) : m));\n this.attach(nextMarks);\n }\n this.commit();\n return this;\n }\n\n protected _updateComponentEncoders() {\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const marks = array(this.spec.target).map(m => (isString(m) ? this.view.getMarkById(m) : m));\n const groupGraphicItem = this.group?.getGroupGraphicItem?.();\n let size = invokeFunctionType(this.spec.size, parameters);\n if (!size) {\n size = groupGraphicItem\n ? {\n width: groupGraphicItem.attribute.width ?? groupGraphicItem.AABBBounds.width(),\n height: groupGraphicItem.attribute.height ?? groupGraphicItem.AABBBounds.height()\n }\n : { width: Infinity, height: Infinity };\n }\n\n const theme = this.spec.skipTheme ? null : this.view.getCurrentTheme();\n\n return generateLabelAttributes(\n marks,\n size,\n encoder as BaseSignleEncodeSpec,\n this.spec.labelStyle,\n parameters,\n theme\n );\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n}\n\nexport const registerLabel = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.label,\n (attrs: DataLabelAttrs) => new DataLabel(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.label, Label);\n};\n"]}
package/cjs/env.d.ts CHANGED
@@ -1 +1,3 @@
1
- export * from '@visactor/vrender-kits';
1
+ import { initBrowserEnv, initNodeEnv } from '@visactor/vrender-kits';
2
+ export declare const initAutoEnv: () => void;
3
+ export { initBrowserEnv, initNodeEnv };
package/cjs/env.js CHANGED
@@ -1,20 +1,26 @@
1
1
  "use strict";
2
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
3
  Object.defineProperty(exports, "__esModule", {
19
4
  value: !0
20
- }), __exportStar(require("@visactor/vrender-kits"), exports);
5
+ }), exports.initNodeEnv = exports.initBrowserEnv = exports.initAutoEnv = void 0;
6
+
7
+ const vrender_kits_1 = require("@visactor/vrender-kits");
8
+
9
+ Object.defineProperty(exports, "initBrowserEnv", {
10
+ enumerable: !0,
11
+ get: function() {
12
+ return vrender_kits_1.initBrowserEnv;
13
+ }
14
+ }), Object.defineProperty(exports, "initNodeEnv", {
15
+ enumerable: !0,
16
+ get: function() {
17
+ return vrender_kits_1.initNodeEnv;
18
+ }
19
+ });
20
+
21
+ const vrender_core_1 = require("@visactor/vrender-core"), initAutoEnv = () => {
22
+ (0, vrender_core_1.isBrowserEnv)() ? (0, vrender_kits_1.initBrowserEnv)() : (0,
23
+ vrender_core_1.isNodeEnv)() && (0, vrender_kits_1.initNodeEnv)();
24
+ };
25
+
26
+ exports.initAutoEnv = initAutoEnv;
package/cjs/env.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/env.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC","file":"env.js","sourcesContent":["export * from '@visactor/vrender-kits';\n"]}
1
+ {"version":3,"sources":["../src/env.ts"],"names":[],"mappings":";;;AAAA,yDAAqE;AAW5D,+FAXA,6BAAc,OAWA;AAAE,4FAXA,0BAAW,OAWA;AAVpC,yDAAiE;AAE1D,MAAM,WAAW,GAAG,GAAG,EAAE;IAC9B,IAAI,IAAA,2BAAY,GAAE,EAAE;QAClB,IAAA,6BAAc,GAAE,CAAC;KAClB;SAAM,IAAI,IAAA,wBAAS,GAAE,EAAE;QACtB,IAAA,0BAAW,GAAE,CAAC;KACf;AACH,CAAC,CAAC;AANW,QAAA,WAAW,eAMtB","file":"env.js","sourcesContent":["import { initBrowserEnv, initNodeEnv } from '@visactor/vrender-kits';\nimport { isBrowserEnv, isNodeEnv } from '@visactor/vrender-core';\n\nexport const initAutoEnv = () => {\n if (isBrowserEnv()) {\n initBrowserEnv();\n } else if (isNodeEnv()) {\n initNodeEnv();\n }\n};\n\nexport { initBrowserEnv, initNodeEnv };\n"]}
@@ -53,7 +53,9 @@ class Animator {
53
53
  this.isAnimating = !1, this.runnings = null, invokeCallback && (null === (_a = this.callbackFunction) || void 0 === _a || _a.call(null));
54
54
  }
55
55
  animateElement(animationParameters, parameters) {
56
- const graphicAnimate = this.element.getGraphicItem().animate();
56
+ const graphicItem = this.element.getGraphicItem();
57
+ if (!graphicItem) return;
58
+ const graphicAnimate = graphicItem.animate();
57
59
  this.runnings.push(graphicAnimate), graphicAnimate.startAt(this.unit.initialDelay),
58
60
  graphicAnimate.wait(this.unit.loopDelay), this.unit.timeSlices.forEach((timeSlice => {
59
61
  this.animateTimeSlice(graphicAnimate, timeSlice, animationParameters, parameters);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graph/animation/animator.ts"],"names":[],"mappings":";;;AAAA,6CAAwD;AAGxD,yDAA4F;AAa5F,2CAAwH;AAExH,sBAAO,CAAC,IAAI,IAAI,0BAAW,CAAC,oBAAoB,CAAC;AAEjD,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAEzB,MAAM,mBAAmB,GAAG,CAAC,MAAoE,EAAE,EAAE;IACnG,OAAO,CAAC,IAAA,cAAK,EAAC,MAAM,CAAC,IAAI,MAAM,CAAC,SAAS,YAAY,6BAAc,CAAC;AACtE,CAAC,CAAC;AAEF,MAAa,QAAQ;IAUnB,YACE,OAAiB,EACjB,IAAoB,EACpB,gBAIC;QAhBH,OAAE,GAAW,gBAAgB,EAAE,CAAC;QAGhC,gBAAW,GAAY,KAAK,CAAC;QAGrB,aAAQ,GAAsB,EAAE,CAAC;QAYvC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,QAAQ,CAAC,gBAA0C;QACjD,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CAAC,mBAAyC,EAAE,UAAe;QAChE,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAExB,IAAI,CAAC,cAAc,CAAC,mBAAmB,EAAE,UAAU,CAAC,CAAC;QAGrD,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;YAC9B,IAAI,CAAC,YAAY,EAAE,CAAC;SACrB;QACD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,MAAM,CAAC,MAAM,CAAC,CAAC;iBACtF;YACH,CAAC,CAAC;iBACD,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAA,cAAK,EAAC,OAAO,CAAC,CAAC,CAAC;YAEtC,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE;gBAC/B,cAAc,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;aACxC;iBAAM;gBACL,cAAc,CAAC,IAAI,CAAC,IAAI,2BAAY,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC;aACjE;SACF;IACH,CAAC;CACF;AAvLD,4BAuLC","file":"animator.js","sourcesContent":["import { isNil, isValidNumber } from '@visactor/vutils';\nimport type { IAnimate as IGraphicAnimate } from '@visactor/vrender-core';\n// eslint-disable-next-line no-duplicate-imports\nimport { ACustomAnimate, Animate, AnimateGroup, AnimateMode } from '@visactor/vrender-core';\nimport type {\n IAnimationChannelInterpolator,\n IAnimationCustomConstructor,\n IAnimationTimeline,\n IAnimator,\n IAnimatorOptions,\n IAnimationUnit,\n IAnimationParameters,\n IAnimationTimeSlice,\n IElement,\n IAnimationEffect\n} from '../../types';\nimport { AttributeAnimate, channelAnimationAttributes, CustomInterpolator, typeAnimationAttributes } from './attribute';\n\nAnimate.mode |= AnimateMode.SET_ATTR_IMMEDIATELY;\n\nlet GlobalAnimatorId = 0;\n\nconst isCustomAnimateCtor = (custom?: IAnimationChannelInterpolator | IAnimationCustomConstructor) => {\n return !isNil(custom) && custom.prototype instanceof ACustomAnimate;\n};\n\nexport class Animator implements IAnimator {\n id: number = GlobalAnimatorId++;\n element: IElement;\n animationOptions: IAnimatorOptions;\n isAnimating: boolean = false;\n\n private unit: IAnimationUnit;\n private runnings: IGraphicAnimate[] = [];\n private callbackFunction: (...args: any[]) => any;\n\n constructor(\n element: IElement,\n unit: IAnimationUnit,\n animationOptions: {\n state: string;\n timeline: IAnimationTimeline;\n id: string;\n }\n ) {\n this.element = element;\n this.animationOptions = animationOptions;\n this.unit = unit;\n }\n\n callback(callbackFunction: (...args: any[]) => void): this {\n this.callbackFunction = callbackFunction;\n return this;\n }\n\n animate(animationParameters: IAnimationParameters, parameters: any): this {\n this.isAnimating = true;\n\n this.animateElement(animationParameters, parameters);\n\n // if no valid running, end animating immediately\n if (this.runnings.length === 0) {\n this.animationEnd();\n }\n return this;\n }\n\n stop(stopState: 'start' | 'end' = 'end', invokeCallback: boolean = true): this {\n // FIXME: wait for VRender to fix 'end' parameter\n this.runnings.forEach(running => running.stop(stopState));\n this.animationEnd(invokeCallback);\n return this;\n }\n\n pause(): this {\n this.runnings.forEach(running => running.pause());\n return this;\n }\n\n resume(): this {\n this.runnings.forEach(running => running.resume());\n return this;\n }\n\n startAt(startTime: number): this {\n this.runnings.forEach(running => {\n const initialDelay = this.unit.initialDelay;\n running.startAt(initialDelay + startTime);\n });\n return this;\n }\n\n getTotalAnimationTime() {\n const timeLineDuration = this.unit.initialDelay + this.unit.loopDuration * this.unit.loopCount;\n return this.unit.totalTime ?? timeLineDuration;\n }\n\n getEndAttributes() {\n return this.runnings.reduce((attributes, running) => {\n return Object.assign(attributes, running.getEndProps());\n }, {} as Record<string, any>);\n }\n\n private animationEnd(invokeCallback: boolean = true) {\n this.isAnimating = false;\n this.runnings = null;\n if (invokeCallback) {\n this.callbackFunction?.call(null);\n }\n }\n\n private animateElement(animationParameters: IAnimationParameters, parameters: any) {\n const graphicAnimate: IGraphicAnimate = this.element.getGraphicItem().animate();\n this.runnings.push(graphicAnimate);\n // initialDelay is only used at first loop\n graphicAnimate.startAt(this.unit.initialDelay);\n // execute loop animation\n graphicAnimate.wait(this.unit.loopDelay);\n this.unit.timeSlices.forEach(timeSlice => {\n this.animateTimeSlice(graphicAnimate, timeSlice, animationParameters, parameters);\n });\n graphicAnimate.wait(this.unit.loopDelayAfter);\n\n graphicAnimate.loop(this.unit.loopCount - 1);\n\n if (isValidNumber(this.unit.totalTime)) {\n // FIXME: use VRender api instead after VRender refactor is finished\n setTimeout(() => {\n if (graphicAnimate) {\n graphicAnimate.stop('end');\n }\n }, this.unit.totalTime);\n }\n\n graphicAnimate.onEnd(() => {\n this.runnings = this.runnings.filter(running => running !== graphicAnimate);\n if (this.runnings.length === 0) {\n this.animationEnd();\n }\n });\n }\n\n private animateTimeSlice(\n graphicAnimate: IGraphicAnimate,\n timeSlice: IAnimationTimeSlice,\n animationParameters: IAnimationParameters,\n parameters: any\n ) {\n const delay = timeSlice.delay as number;\n const duration = timeSlice.duration as number;\n const effects = timeSlice.effects as IAnimationEffect[];\n\n // wait in loop animation before animation starts\n if (delay > 0) {\n graphicAnimate.wait(delay);\n }\n\n if (effects.length < 0) {\n graphicAnimate.wait(duration);\n } else {\n const customAnimates = effects\n .map((effect, index) => {\n const attributes =\n (effect.type\n ? typeAnimationAttributes(this.element, effect, animationParameters, parameters)\n : channelAnimationAttributes(this.element, effect, animationParameters, parameters)) ?? {};\n const customOption = attributes?.custom || effect?.custom;\n const customParametersOption = attributes?.customParameters || effect?.customParameters;\n\n if (\n attributes.from &&\n Object.keys(attributes.from).length &&\n this.unit &&\n this.animationOptions.timeline.controlOptions.immediatelyApply &&\n this.element.mark.markType !== 'component'\n ) {\n this.element.getGraphicItem().setAttributes(attributes.from);\n }\n\n const isCustomAnimate = isCustomAnimateCtor(customOption);\n const isCustomInterpolator = !isNil(customOption) && !isCustomAnimateCtor(customOption);\n\n if (isCustomInterpolator) {\n return new CustomInterpolator(attributes.from, attributes.to, duration, effect.easing, {\n interpolator: customOption as IAnimationChannelInterpolator,\n element: this.element,\n parameters: customParametersOption\n });\n } else if (isCustomAnimate) {\n return new (customOption as IAnimationCustomConstructor)(\n attributes.from,\n attributes.to,\n duration,\n effect.easing,\n customParametersOption\n );\n } else if (attributes.to) {\n return new AttributeAnimate(attributes.from, attributes.to, duration, effect.easing);\n }\n })\n .filter(animate => !isNil(animate));\n\n if (customAnimates.length === 1) {\n graphicAnimate.play(customAnimates[0]);\n } else {\n graphicAnim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,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAA,cAAK,EAAC,OAAO,CAAC,CAAC,CAAC;YAEtC,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE;gBAC/B,cAAc,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;aACxC;iBAAM;gBACL,cAAc,CAAC,IAAI,CAAC,IAAI,2BAAY,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC;aACjE;SACF;IACH,CAAC;CACF;AA7LD,4BA6LC","file":"animator.js","sourcesContent":["import { isNil, isValidNumber } from '@visactor/vutils';\nimport type { IAnimate as IGraphicAnimate } from '@visactor/vrender-core';\n// eslint-disable-next-line no-duplicate-imports\nimport { ACustomAnimate, Animate, AnimateGroup, AnimateMode } from '@visactor/vrender-core';\nimport type {\n IAnimationChannelInterpolator,\n IAnimationCustomConstructor,\n IAnimationTimeline,\n IAnimator,\n IAnimatorOptions,\n IAnimationUnit,\n IAnimationParameters,\n IAnimationTimeSlice,\n IElement,\n IAnimationEffect\n} from '../../types';\nimport { AttributeAnimate, channelAnimationAttributes, CustomInterpolator, typeAnimationAttributes } from './attribute';\n\nAnimate.mode |= AnimateMode.SET_ATTR_IMMEDIATELY;\n\nlet GlobalAnimatorId = 0;\n\nconst isCustomAnimateCtor = (custom?: IAnimationChannelInterpolator | IAnimationCustomConstructor) => {\n return !isNil(custom) && custom.prototype instanceof ACustomAnimate;\n};\n\nexport class Animator implements IAnimator {\n id: number = GlobalAnimatorId++;\n element: IElement;\n animationOptions: IAnimatorOptions;\n isAnimating: boolean = false;\n\n private unit: IAnimationUnit;\n private runnings: IGraphicAnimate[] = [];\n private callbackFunction: (...args: any[]) => any;\n\n constructor(\n element: IElement,\n unit: IAnimationUnit,\n animationOptions: {\n state: string;\n timeline: IAnimationTimeline;\n id: string;\n }\n ) {\n this.element = element;\n this.animationOptions = animationOptions;\n this.unit = unit;\n }\n\n callback(callbackFunction: (...args: any[]) => void): this {\n this.callbackFunction = callbackFunction;\n return this;\n }\n\n animate(animationParameters: IAnimationParameters, parameters: any): this {\n this.isAnimating = true;\n\n this.animateElement(animationParameters, parameters);\n\n // if no valid running, end animating immediately\n if (this.runnings.length === 0) {\n this.animationEnd();\n }\n return this;\n }\n\n stop(stopState: 'start' | 'end' = 'end', invokeCallback: boolean = true): this {\n // FIXME: wait for VRender to fix 'end' parameter\n this.runnings.forEach(running => running.stop(stopState));\n this.animationEnd(invokeCallback);\n return this;\n }\n\n pause(): this {\n this.runnings.forEach(running => running.pause());\n return this;\n }\n\n resume(): this {\n this.runnings.forEach(running => running.resume());\n return this;\n }\n\n startAt(startTime: number): this {\n this.runnings.forEach(running => {\n const initialDelay = this.unit.initialDelay;\n running.startAt(initialDelay + startTime);\n });\n return this;\n }\n\n getTotalAnimationTime() {\n const timeLineDuration = this.unit.initialDelay + this.unit.loopDuration * this.unit.loopCount;\n return this.unit.totalTime ?? timeLineDuration;\n }\n\n getEndAttributes() {\n return this.runnings.reduce((attributes, running) => {\n return Object.assign(attributes, running.getEndProps());\n }, {} as Record<string, any>);\n }\n\n private animationEnd(invokeCallback: boolean = true) {\n this.isAnimating = false;\n this.runnings = null;\n if (invokeCallback) {\n this.callbackFunction?.call(null);\n }\n }\n\n private animateElement(animationParameters: IAnimationParameters, parameters: any) {\n const graphicItem = this.element.getGraphicItem();\n\n if (!graphicItem) {\n return;\n }\n\n const graphicAnimate: IGraphicAnimate = graphicItem.animate();\n this.runnings.push(graphicAnimate);\n // initialDelay is only used at first loop\n graphicAnimate.startAt(this.unit.initialDelay);\n // execute loop animation\n graphicAnimate.wait(this.unit.loopDelay);\n this.unit.timeSlices.forEach(timeSlice => {\n this.animateTimeSlice(graphicAnimate, timeSlice, animationParameters, parameters);\n });\n graphicAnimate.wait(this.unit.loopDelayAfter);\n\n graphicAnimate.loop(this.unit.loopCount - 1);\n\n if (isValidNumber(this.unit.totalTime)) {\n // FIXME: use VRender api instead after VRender refactor is finished\n setTimeout(() => {\n if (graphicAnimate) {\n graphicAnimate.stop('end');\n }\n }, this.unit.totalTime);\n }\n\n graphicAnimate.onEnd(() => {\n this.runnings = this.runnings.filter(running => running !== graphicAnimate);\n if (this.runnings.length === 0) {\n this.animationEnd();\n }\n });\n }\n\n private animateTimeSlice(\n graphicAnimate: IGraphicAnimate,\n timeSlice: IAnimationTimeSlice,\n animationParameters: IAnimationParameters,\n parameters: any\n ) {\n const delay = timeSlice.delay as number;\n const duration = timeSlice.duration as number;\n const effects = timeSlice.effects as IAnimationEffect[];\n\n // wait in loop animation before animation starts\n if (delay > 0) {\n graphicAnimate.wait(delay);\n }\n\n if (effects.length < 0) {\n graphicAnimate.wait(duration);\n } else {\n const customAnimates = effects\n .map((effect, index) => {\n const attributes =\n (effect.type\n ? typeAnimationAttributes(this.element, effect, animationParameters, parameters)\n : channelAnimationAttributes(this.element, effect, animationParameters, parameters)) ?? {};\n const customOption = attributes?.custom || effect?.custom;\n const customParametersOption = attributes?.customParameters || effect?.customParameters;\n\n if (\n attributes.from &&\n Object.keys(attributes.from).length &&\n this.unit &&\n this.animationOptions.timeline.controlOptions.immediatelyApply &&\n this.element.mark.markType !== 'component'\n ) {\n this.element.getGraphicItem().setAttributes(attributes.from);\n }\n\n const isCustomAnimate = isCustomAnimateCtor(customOption);\n const isCustomInterpolator = !isNil(customOption) && !isCustomAnimateCtor(customOption);\n\n if (isCustomInterpolator) {\n return new CustomInterpolator(attributes.from, attributes.to, duration, effect.easing, {\n interpolator: customOption as IAnimationChannelInterpolator,\n element: this.element,\n parameters: customParametersOption\n });\n } else if (isCustomAnimate) {\n return new (customOption as IAnimationCustomConstructor)(\n attributes.from,\n attributes.to,\n duration,\n effect.easing,\n customParametersOption\n );\n } else if (attributes.to) {\n return new AttributeAnimate(attributes.from, attributes.to, duration, effect.easing);\n }\n })\n .filter(animate => !isNil(animate));\n\n if (customAnimates.length === 1) {\n graphicAnimate.play(customAnimates[0]);\n } else {\n graphicAnimate.play(new AnimateGroup(duration, customAnimates));\n }\n }\n }\n}\n"]}
@@ -38,13 +38,13 @@ function getRulePoints(nextAttrs) {
38
38
  function getLinePoints(items, includeOnePoint, lastPoints, isArea) {
39
39
  if (!items || !items.length || 1 === items.length && includeOnePoint) return [];
40
40
  return items.some((item => isValidPointsChannel(Object.keys(item.nextAttrs), "line"))) ? items.map(((item, index) => {
41
- var _a, _b, _c, _d, _e, _f;
41
+ var _a, _b, _c, _d, _e;
42
42
  const attrs = item.nextAttrs;
43
43
  return (0, vutils_1.isNil)(attrs.x) && (attrs.x = null === (_a = null == lastPoints ? void 0 : lastPoints[index]) || void 0 === _a ? void 0 : _a.x),
44
44
  (0, vutils_1.isNil)(attrs.y) && (attrs.y = null === (_b = null == lastPoints ? void 0 : lastPoints[index]) || void 0 === _b ? void 0 : _b.y),
45
- (0, vutils_1.isNil)(attrs.defined) && !1 === (null === (_c = null == lastPoints ? void 0 : lastPoints[index]) || void 0 === _c ? void 0 : _c.defined) && (attrs.defined = null === (_d = null == lastPoints ? void 0 : lastPoints[index]) || void 0 === _d ? void 0 : _d.defined),
46
- attrs.context = item.key, isArea && ((0, vutils_1.isNil)(attrs.x1) && (attrs.x1 = null === (_e = null == lastPoints ? void 0 : lastPoints[index]) || void 0 === _e ? void 0 : _e.x1),
47
- (0, vutils_1.isNil)(attrs.y1) && (attrs.y1 = null === (_f = null == lastPoints ? void 0 : lastPoints[index]) || void 0 === _f ? void 0 : _f.y1)),
45
+ (0, vutils_1.isNil)(attrs.defined) && !1 === (null === (_c = null == lastPoints ? void 0 : lastPoints[index]) || void 0 === _c ? void 0 : _c.defined) && (attrs.defined = !1),
46
+ attrs.context = item.key, isArea && ((0, vutils_1.isNil)(attrs.x1) && (attrs.x1 = null === (_d = null == lastPoints ? void 0 : lastPoints[index]) || void 0 === _d ? void 0 : _d.x1),
47
+ (0, vutils_1.isNil)(attrs.y1) && (attrs.y1 = null === (_e = null == lastPoints ? void 0 : lastPoints[index]) || void 0 === _e ? void 0 : _e.y1)),
48
48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AAE,IAAI,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACnD,KAAK,uBAAe,CAAC,IAAI;YACvB,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACxC,KAAK,uBAAe,CAAC,MAAM;YACzB,OAAO,OAAO,KAAK,MAAM,CAAC;QAC5B,KAAK,uBAAe,CAAC,OAAO;YAC1B,OAAO,OAAO,KAAK,QAAQ,CAAC;QAC9B,KAAK,uBAAe,CAAC,IAAI;YACvB,OAAO,OAAO,KAAK,MAAM,CAAC;KAC7B;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AA9BD,0DA8BC;AAED,SAAgB,gBAAgB,CAAC,QAAkB;IACjD,OACE,CAAC,uBAAe,CAAC,IAAI,EAAE,uBAAe,CAAC,IAAI,EAAE,uBAAe,CAAC,UAAU,EAAE,uBAAe,CAAC,YAAY,CACtG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACvB,CAAC;AAJD,4CAIC","file":"helpers.js","sourcesContent":["import type { IPointLike } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { isNil, isValidNumber } from '@visactor/vutils';\nimport type { MarkElementItem, MarkType } from '../../types';\nimport { GrammarMarkType } from '../enums';\n\nexport function isValidPointsChannel(channels: string[], markType: MarkType): boolean {\n switch (markType) {\n case 'line':\n return channels.some(channel => ['x', 'y', 'defined'].includes(channel));\n case 'area':\n return channels.some(channel => ['x', 'y', 'x1', 'y1', 'defined'].includes(channel));\n case 'largeRects':\n return channels.some(channel => ['x', 'y', 'width', 'y1'].includes(channel));\n case 'largeSymbols':\n return channels.some(channel => ['x', 'y'].includes(channel));\n }\n return false;\n}\n\n/**\n * 获取rule的points\n * 相对位置\n * @param {*} item\n * @returns\n */\nexport function getRulePoints(nextAttrs: { x: number; y: number; x1: number; y1: number }) {\n const { x, y, x1, y1 } = nextAttrs;\n\n if (!isValidNumber(x) || !isValidNumber(y) || !isValidNumber(x1) || !isValidNumber(y1)) {\n return [];\n }\n return [\n { x, y },\n { x: x1, y: y1 }\n ];\n}\n/**\n * 生成用于渲染的点数组\n * @param {*} item\n * @returns {IPointLike[]}\n */\nexport function getLinePoints(\n items?: MarkElementItem[],\n includeOnePoint?: boolean,\n lastPoints?: IPointLike[],\n isArea?: boolean\n) {\n if (!items || !items.length || (items.length === 1 && includeOnePoint)) {\n return [];\n }\n const hasValidChannel = items.some(item => {\n return isValidPointsChannel(Object.keys(item.nextAttrs), 'line');\n });\n if (!hasValidChannel) {\n return lastPoints ?? [];\n }\n return items.map((item, index) => {\n const attrs = item.nextAttrs;\n\n if (isNil(attrs.x)) {\n attrs.x = lastPoints?.[index]?.x;\n }\n if (isNil(attrs.y)) {\n attrs.y = lastPoints?.[index]?.y;\n }\n\n if (isNil(attrs.defined) && lastPoints?.[index]?.defined === false) {\n attrs.defined = lastPoints?.[index]?.defined;\n }\n\n attrs.context = item.key;\n\n if (isArea) {\n if (isNil(attrs.x1)) {\n attrs.x1 = lastPoints?.[index]?.x1;\n }\n if (isNil(attrs.y1)) {\n attrs.y1 = lastPoints?.[index]?.y1;\n }\n }\n\n return attrs;\n });\n}\n\nexport function getLargeRectsPoints(\n items?: MarkElementItem[],\n includeOnePoint?: boolean,\n lastPoints?: Float32Array | number[]\n): Float32Array | number[] {\n if (!items || !items.length || (items.length === 1 && includeOnePoint)) {\n return [];\n }\n const arr: Float32Array = new Float32Array(items.length * 4);\n\n items.forEach((item, index) => {\n const attrs = item.nextAttrs;\n const x = attrs.x ?? lastPoints?.[index * 4];\n const y = attrs.y ?? lastPoints?.[index * 4 + 1];\n const width = attrs.width ?? lastPoints?.[index * 4 + 2];\n const y1 = attrs.y1 ?? lastPoints?.[index * 4 + 3];\n arr[index * 4] = x;\n arr[index * 4 + 1] = y;\n arr[index * 4 + 2] = width;\n arr[index * 4 + 3] = y1 - y;\n });\n\n return arr;\n}\n\nexport function getLargeSymbolsPoints(\n items?: MarkElementItem[],\n includeOnePoint?: boolean,\n lastPoints?: Float32Array | number[]\n): Float32Array | number[] {\n if (!items || !items.length || (items.length === 1 && includeOnePoint)) {\n return [];\n }\n const arr: Float32Array = new Float32Array(items.length * 2);\n\n items.forEach((item, index) => {\n const attrs = item.nextAttrs;\n const x = attrs.x ?? lastPoints?.[index * 2];\n const y = attrs.y ?? lastPoints?.[index * 2 + 1];\n arr[index * 2] = x;\n arr[index * 2 + 1] = y;\n });\n\n return arr;\n}\n\nexport function isPositionOrSizeChannel(type: string, channel: string) {\n if (['x', 'y', 'dx', 'dy'].includes(channel)) {\n return true;\n }\n\n switch (type) {\n case GrammarMarkType.arc:\n return ['innerRadius', 'outerRadius', 'startAngle', 'endAngle'].includes(channel);\n case GrammarMarkType.group:\n case GrammarMarkType.rect:\n case GrammarMarkType.image:\n return ['width', 'height', 'y1'].includes(channel);\n case GrammarMarkType.path:\n case GrammarMarkType.shape:\n return ['path', 'customPath'].includes(channel);\n case GrammarMarkType.line:\n return channel === 'defined';\n case GrammarMarkType.area:\n return ['x1', 'y1', 'defined'].includes(channel);\n case GrammarMarkType.rule:\n return ['x1', 'y1'].includes(channel);\n case GrammarMarkType.symbol:\n return channel === 'size';\n case GrammarMarkType.polygon:\n return channel === 'points';\n case GrammarMarkType.text:\n return channel === 'text';\n }\n\n return false;\n}\n\nexport function isPointsMarkType(markType: MarkType): boolean {\n return (\n [GrammarMarkType.line, GrammarMarkType.area, GrammarMarkType.largeRects, GrammarMarkType.largeSymbols] as MarkType[]\n ).includes(markType);\n}\n"]}
1
+ {"version":3,"sources":["../src/graph/attributes/helpers.ts"],"names":[],"mappings":";;;AAEA,6CAAwD;AAExD,oCAA2C;AAE3C,SAAgB,oBAAoB,CAAC,QAAkB,EAAE,QAAkB;IACzE,QAAQ,QAAQ,EAAE;QAChB,KAAK,MAAM;YACT,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,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ED,OAAO,KAAK,CAAC;AACf,CAAC;AA9BD,0DA8BC;AAED,SAAgB,gBAAgB,CAAC,QAAkB;IACjD,OACE,CAAC,uBAAe,CAAC,IAAI,EAAE,uBAAe,CAAC,IAAI,EAAE,uBAAe,CAAC,UAAU,EAAE,uBAAe,CAAC,YAAY,CACtG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACvB,CAAC;AAJD,4CAIC","file":"helpers.js","sourcesContent":["import type { IPointLike } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { isNil, isValidNumber } from '@visactor/vutils';\nimport type { MarkElementItem, MarkType } from '../../types';\nimport { GrammarMarkType } from '../enums';\n\nexport function isValidPointsChannel(channels: string[], markType: MarkType): boolean {\n switch (markType) {\n case 'line':\n return channels.some(channel => ['x', 'y', 'defined'].includes(channel));\n case 'area':\n return channels.some(channel => ['x', 'y', 'x1', 'y1', 'defined'].includes(channel));\n case 'largeRects':\n return channels.some(channel => ['x', 'y', 'width', 'y1'].includes(channel));\n case 'largeSymbols':\n return channels.some(channel => ['x', 'y'].includes(channel));\n }\n return false;\n}\n\n/**\n * 获取rule的points\n * 相对位置\n * @param {*} item\n * @returns\n */\nexport function getRulePoints(nextAttrs: { x: number; y: number; x1: number; y1: number }) {\n const { x, y, x1, y1 } = nextAttrs;\n\n if (!isValidNumber(x) || !isValidNumber(y) || !isValidNumber(x1) || !isValidNumber(y1)) {\n return [];\n }\n return [\n { x, y },\n { x: x1, y: y1 }\n ];\n}\n/**\n * 生成用于渲染的点数组\n * @param {*} item\n * @returns {IPointLike[]}\n */\nexport function getLinePoints(\n items?: MarkElementItem[],\n includeOnePoint?: boolean,\n lastPoints?: IPointLike[],\n isArea?: boolean\n) {\n if (!items || !items.length || (items.length === 1 && includeOnePoint)) {\n return [];\n }\n const hasValidChannel = items.some(item => {\n return isValidPointsChannel(Object.keys(item.nextAttrs), 'line');\n });\n if (!hasValidChannel) {\n return lastPoints ?? [];\n }\n return items.map((item, index) => {\n const attrs = item.nextAttrs;\n\n if (isNil(attrs.x)) {\n attrs.x = lastPoints?.[index]?.x;\n }\n if (isNil(attrs.y)) {\n attrs.y = lastPoints?.[index]?.y;\n }\n\n if (isNil(attrs.defined) && lastPoints?.[index]?.defined === false) {\n attrs.defined = false;\n }\n\n attrs.context = item.key;\n\n if (isArea) {\n if (isNil(attrs.x1)) {\n attrs.x1 = lastPoints?.[index]?.x1;\n }\n if (isNil(attrs.y1)) {\n attrs.y1 = lastPoints?.[index]?.y1;\n }\n }\n\n return attrs;\n });\n}\n\nexport function getLargeRectsPoints(\n items?: MarkElementItem[],\n includeOnePoint?: boolean,\n lastPoints?: Float32Array | number[]\n): Float32Array | number[] {\n if (!items || !items.length || (items.length === 1 && includeOnePoint)) {\n return [];\n }\n const arr: Float32Array = new Float32Array(items.length * 4);\n\n items.forEach((item, index) => {\n const attrs = item.nextAttrs;\n const x = attrs.x ?? lastPoints?.[index * 4];\n const y = attrs.y ?? lastPoints?.[index * 4 + 1];\n const width = attrs.width ?? lastPoints?.[index * 4 + 2];\n const y1 = attrs.y1 ?? lastPoints?.[index * 4 + 3];\n arr[index * 4] = x;\n arr[index * 4 + 1] = y;\n arr[index * 4 + 2] = width;\n arr[index * 4 + 3] = y1 - y;\n });\n\n return arr;\n}\n\nexport function getLargeSymbolsPoints(\n items?: MarkElementItem[],\n includeOnePoint?: boolean,\n lastPoints?: Float32Array | number[]\n): Float32Array | number[] {\n if (!items || !items.length || (items.length === 1 && includeOnePoint)) {\n return [];\n }\n const arr: Float32Array = new Float32Array(items.length * 2);\n\n items.forEach((item, index) => {\n const attrs = item.nextAttrs;\n const x = attrs.x ?? lastPoints?.[index * 2];\n const y = attrs.y ?? lastPoints?.[index * 2 + 1];\n arr[index * 2] = x;\n arr[index * 2 + 1] = y;\n });\n\n return arr;\n}\n\nexport function isPositionOrSizeChannel(type: string, channel: string) {\n if (['x', 'y', 'dx', 'dy'].includes(channel)) {\n return true;\n }\n\n switch (type) {\n case GrammarMarkType.arc:\n return ['innerRadius', 'outerRadius', 'startAngle', 'endAngle'].includes(channel);\n case GrammarMarkType.group:\n case GrammarMarkType.rect:\n case GrammarMarkType.image:\n return ['width', 'height', 'y1'].includes(channel);\n case GrammarMarkType.path:\n case GrammarMarkType.shape:\n return ['path', 'customPath'].includes(channel);\n case GrammarMarkType.line:\n return channel === 'defined';\n case GrammarMarkType.area:\n return ['x1', 'y1', 'defined'].includes(channel);\n case GrammarMarkType.rule:\n return ['x1', 'y1'].includes(channel);\n case GrammarMarkType.symbol:\n return channel === 'size';\n case GrammarMarkType.polygon:\n return channel === 'points';\n case GrammarMarkType.text:\n return channel === 'text';\n }\n\n return false;\n}\n\nexport function isPointsMarkType(markType: MarkType): boolean {\n return (\n [GrammarMarkType.line, GrammarMarkType.area, GrammarMarkType.largeRects, GrammarMarkType.largeSymbols] as MarkType[]\n ).includes(markType);\n}\n"]}
@@ -42,29 +42,11 @@ exports.transformsByType = {
42
42
  }
43
43
  } ],
44
44
  [enums_1.GrammarMarkType.line]: [ {
45
- channels: [ "x", "y", "defined", "enableSegments" ],
45
+ channels: [ "x", "y", "defined" ],
46
46
  transform: (graphicAttributes, nextAttrs, storedAttrs) => {
47
47
  graphicAttributes.x = 0, graphicAttributes.y = 0;
48
48
  }
49
49
  } ],
50
- [enums_1.GrammarMarkType.rect]: [ {
51
- channels: [ "x", "y", "x1", "y1", "width", "height" ],
52
- transform: (graphicAttributes, nextAttrs, storedAttrs) => {
53
- var _a, _b, _c, _d, _e, _f, _g, _h;
54
- (0, vutils_1.isValidNumber)(nextAttrs.width) || !(0, vutils_1.isValidNumber)(nextAttrs.x1) && (0,
55
- vutils_1.isValidNumber)(storedAttrs.width) ? (graphicAttributes.x = Math.min(null !== (_a = storedAttrs.x) && void 0 !== _a ? _a : 0, null !== (_b = storedAttrs.x1) && void 0 !== _b ? _b : 1 / 0),
56
- graphicAttributes.width = storedAttrs.width) : (0, vutils_1.isValidNumber)(nextAttrs.x1) || !(0,
57
- vutils_1.isValidNumber)(nextAttrs.width) && (0, vutils_1.isValidNumber)(storedAttrs.x1) ? (graphicAttributes.x = Math.min(storedAttrs.x, storedAttrs.x1),
58
- graphicAttributes.width = Math.abs(storedAttrs.x1 - storedAttrs.x)) : (graphicAttributes.x = Math.min(null !== (_c = storedAttrs.x) && void 0 !== _c ? _c : 0, null !== (_d = storedAttrs.x1) && void 0 !== _d ? _d : 1 / 0),
59
- graphicAttributes.width = storedAttrs.width), (0, vutils_1.isValidNumber)(nextAttrs.height) || !(0,
60
- vutils_1.isValidNumber)(nextAttrs.y1) && (0, vutils_1.isValidNumber)(storedAttrs.height) ? (graphicAttributes.y = Math.min(null !== (_e = storedAttrs.y) && void 0 !== _e ? _e : 0, null !== (_f = storedAttrs.y1) && void 0 !== _f ? _f : 1 / 0),
61
- graphicAttributes.height = storedAttrs.height) : (0, vutils_1.isValidNumber)(nextAttrs.y1) || !(0,
62
- vutils_1.isValidNumber)(nextAttrs.height) && (0, vutils_1.isValidNumber)(storedAttrs.y1) ? (graphicAttributes.y = Math.min(storedAttrs.y, storedAttrs.y1),
63
- graphicAttributes.height = Math.abs(storedAttrs.y1 - storedAttrs.y)) : (graphicAttributes.y = Math.min(null !== (_g = storedAttrs.y) && void 0 !== _g ? _g : 0, null !== (_h = storedAttrs.y1) && void 0 !== _h ? _h : 1 / 0),
64
- graphicAttributes.height = storedAttrs.height);
65
- },
66
- storedAttrs: "sizeAttrs"
67
- } ],
68
50
  rect3d: [ {
69
51
  channels: [ "x", "y", "z", "x1", "y1", "width", "height", "length" ],
70
52
  transform: (graphicAttributes, nextAttrs, storedAttrs) => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graph/attributes/transform.ts"],"names":[],"mappings":";;;AAAA,6CAAsF;AAGtF,oCAA2C;AAC3C,uCAA0C;AAC1C,qCAAsE;AAEtE,SAAS,qBAAqB,CAC5B,IAAY,EACZ,QAAkB,EAClB,iBAAsB,EACtB,SAAc,EACd,OAAiB,EACjB,QAAgB;;IAE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BAClC,IAAA,iCAAwB,EAAC,iBAAiB,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;aAC7D;iBAAM;gBACL,iBAAiB,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;aACzC;QACH,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AA5DW,QAAA,mBAAmB,uBA4D9B","file":"transform.js","sourcesContent":["import { has, isNil, isPlainObject, isString, isValidNumber } from '@visactor/vutils';\nimport type { IElement, IGlyphElement } from '../../types/element';\nimport type { AttributeTransform, MarkType } from '../../types/mark';\nimport { GrammarMarkType } from '../enums';\nimport { getRulePoints } from './helpers';\nimport { commonAttributes, transformCommonAttribute } from './common';\n\nfunction storeOriginAttributes(\n name: string,\n channels: string[],\n graphicAttributes: any,\n nextAttrs: any,\n element: IElement,\n markName: string\n): Record<string, any> {\n const prevStoredAttrs = (element as IGlyphElement).getGraphicAttribute(name, false, markName) ?? {};\n const storedAttrs = {};\n channels.forEach(channel => {\n storedAttrs[channel] = nextAttrs[channel] ?? prevStoredAttrs[channel];\n });\n graphicAttributes[name] = storedAttrs;\n return storedAttrs;\n}\n\nexport const transformsByType: Record<string, AttributeTransform[]> = {\n [GrammarMarkType.largeRects]: [\n {\n channels: ['x', 'y', 'y1', 'x1', 'width', 'height'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n graphicAttributes.x = 0;\n graphicAttributes.y = 0;\n }\n }\n ],\n [GrammarMarkType.largeSymbols]: [\n {\n channels: ['x', 'y', 'size'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n graphicAttributes.x = 0;\n graphicAttributes.y = 0;\n }\n }\n ],\n [GrammarMarkType.area]: [\n {\n channels: ['x', 'y', 'x1', 'y1'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n graphicAttributes.x = 0;\n graphicAttributes.y = 0;\n graphicAttributes.x1 = 0;\n graphicAttributes.y1 = 0;\n }\n }\n ],\n [GrammarMarkType.line]: [\n {\n channels: ['x', 'y', 'defined', 'enableSegments'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n graphicAttributes.x = 0;\n graphicAttributes.y = 0;\n }\n }\n ],\n [GrammarMarkType.rect]: [\n {\n channels: ['x', 'y', 'x1', 'y1', 'width', 'height'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n // width\n if (isValidNumber(nextAttrs.width) || (!isValidNumber(nextAttrs.x1) && isValidNumber(storedAttrs.width))) {\n graphicAttributes.x = Math.min(storedAttrs.x ?? 0, storedAttrs.x1 ?? Infinity);\n graphicAttributes.width = storedAttrs.width;\n } else if (isValidNumber(nextAttrs.x1) || (!isValidNumber(nextAttrs.width) && isValidNumber(storedAttrs.x1))) {\n graphicAttributes.x = Math.min(storedAttrs.x, storedAttrs.x1);\n graphicAttributes.width = Math.abs(storedAttrs.x1 - storedAttrs.x);\n } else {\n graphicAttributes.x = Math.min(storedAttrs.x ?? 0, storedAttrs.x1 ?? Infinity);\n graphicAttributes.width = storedAttrs.width;\n }\n\n // height\n if (isValidNumber(nextAttrs.height) || (!isValidNumber(nextAttrs.y1) && isValidNumber(storedAttrs.height))) {\n graphicAttributes.y = Math.min(storedAttrs.y ?? 0, storedAttrs.y1 ?? Infinity);\n graphicAttributes.height = storedAttrs.height;\n } else if (isValidNumber(nextAttrs.y1) || (!isValidNumber(nextAttrs.height) && isValidNumber(storedAttrs.y1))) {\n graphicAttributes.y = Math.min(storedAttrs.y, storedAttrs.y1);\n graphicAttributes.height = Math.abs(storedAttrs.y1 - storedAttrs.y);\n } else {\n graphicAttributes.y = Math.min(storedAttrs.y ?? 0, storedAttrs.y1 ?? Infinity);\n graphicAttributes.height = storedAttrs.height;\n }\n },\n storedAttrs: 'sizeAttrs'\n }\n ],\n rect3d: [\n {\n channels: ['x', 'y', 'z', 'x1', 'y1', 'width', 'height', 'length'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n // width\n if (isValidNumber(nextAttrs.width) || (!isValidNumber(nextAttrs.x1) && isValidNumber(storedAttrs.width))) {\n graphicAttributes.x = Math.min(storedAttrs.x ?? 0, storedAttrs.x1 ?? Infinity);\n graphicAttributes.width = storedAttrs.width;\n } else if (isValidNumber(nextAttrs.x1) || (!isValidNumber(nextAttrs.width) && isValidNumber(storedAttrs.x1))) {\n graphicAttributes.x = Math.min(storedAttrs.x, storedAttrs.x1);\n graphicAttributes.width = Math.abs(storedAttrs.x1 - storedAttrs.x);\n } else {\n graphicAttributes.x = Math.min(storedAttrs.x ?? 0, storedAttrs.x1 ?? Infinity);\n graphicAttributes.width = storedAttrs.width;\n }\n\n // height\n if (isValidNumber(nextAttrs.height) || (!isValidNumber(nextAttrs.y1) && isValidNumber(storedAttrs.height))) {\n graphicAttributes.y = Math.min(storedAttrs.y ?? 0, storedAttrs.y1 ?? Infinity);\n graphicAttributes.height = storedAttrs.height;\n } else if (isValidNumber(nextAttrs.y1) || (!isValidNumber(nextAttrs.height) && isValidNumber(storedAttrs.y1))) {\n graphicAttributes.y = Math.min(storedAttrs.y, storedAttrs.y1);\n graphicAttributes.height = Math.abs(storedAttrs.y1 - storedAttrs.y);\n } else {\n graphicAttributes.y = Math.min(storedAttrs.y ?? 0, storedAttrs.y1 ?? Infinity);\n graphicAttributes.height = storedAttrs.height;\n }\n\n // length\n if (isValidNumber(nextAttrs.length) || (!isValidNumber(nextAttrs.z1) && isValidNumber(storedAttrs.length))) {\n graphicAttributes.z = Math.min(storedAttrs.z ?? 0, storedAttrs.z1 ?? Infinity);\n graphicAttributes.length = storedAttrs.length;\n } else if (isValidNumber(nextAttrs.z1) || (!isValidNumber(nextAttrs.length) && isValidNumber(storedAttrs.z1))) {\n graphicAttributes.z = Math.min(storedAttrs.z, storedAttrs.z1);\n graphicAttributes.length = Math.abs(storedAttrs.z1 - storedAttrs.z);\n } else {\n graphicAttributes.z = Math.min(storedAttrs.z ?? 0, storedAttrs.z1 ?? Infinity);\n graphicAttributes.length = storedAttrs.length;\n }\n },\n storedAttrs: 'sizeAttrs'\n }\n ],\n [GrammarMarkType.text]: [\n {\n channels: ['text', 'limit', 'autoLimit', 'maxLineWidth'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n const limit = storedAttrs.limit ?? Infinity;\n const autoLimit = storedAttrs.autoLimit ?? Infinity;\n const maxWidth = Math.min(limit, autoLimit);\n const isTextConfig = isPlainObject(storedAttrs.text) && !isNil(storedAttrs.text.text);\n const text = isTextConfig ? storedAttrs.text.text : storedAttrs.text;\n\n if (Array.isArray(text)) {\n graphicAttributes.maxLineWidth = maxWidth === Infinity ? storedAttrs.maxLineWidth : maxWidth;\n } else {\n graphicAttributes.maxLineWidth = maxWidth === Infinity ? storedAttrs.maxLineWidth : maxWidth;\n }\n\n if (isTextConfig) {\n if (storedAttrs.text.type === 'html') {\n graphicAttributes.html = {\n dom: text,\n width: nextAttrs.width ?? maxWidth,\n height: nextAttrs.height ?? nextAttrs.fontSize,\n anchorType: 'position'\n };\n graphicAttributes.text = '';\n } else if (storedAttrs.text.type === 'rich') {\n graphicAttributes.textConfig = text;\n } else {\n graphicAttributes.text = text;\n }\n } else {\n graphicAttributes.text = text;\n }\n },\n storedAttrs: 'limitAttrs'\n }\n ],\n [GrammarMarkType.rule]: [\n {\n channels: ['x', 'y', 'x1', 'y1'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n const points = getRulePoints(storedAttrs);\n graphicAttributes.points = points;\n graphicAttributes.x = 0;\n graphicAttributes.y = 0;\n },\n storedAttrs: 'pointAttrs'\n }\n ],\n [GrammarMarkType.symbol]: [\n {\n channels: ['shape', 'symbolType'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n graphicAttributes.symbolType = nextAttrs.shape ?? nextAttrs.symbolType;\n }\n },\n {\n channels: ['image', 'fill', 'background'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n if (nextAttrs.image) {\n graphicAttributes.background = nextAttrs.image;\n graphicAttributes.fill = false;\n } else if (storedAttrs.image) {\n graphicAttributes.background = storedAttrs.image;\n graphicAttributes.fill = false;\n } else {\n graphicAttributes.fill = storedAttrs.fill;\n graphicAttributes.background = storedAttrs.background;\n }\n },\n storedAttrs: 'imageAttrs'\n }\n ],\n [GrammarMarkType.richtext]: [\n {\n channels: ['text', 'textConfig'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n graphicAttributes.text = null;\n\n if (nextAttrs.text?.type === 'rich') {\n graphicAttributes.textConfig = nextAttrs.text.text;\n } else if (nextAttrs.textConfig?.type === 'html') {\n graphicAttributes.html = {\n dom: nextAttrs.textConfig.text,\n width: nextAttrs.width,\n height: nextAttrs.height ?? nextAttrs.fontSize,\n anchorType: 'position'\n };\n graphicAttributes.text = '';\n } else if (nextAttrs.textConfig?.type === 'rich') {\n graphicAttributes.textConfig = nextAttrs.textConfig.text;\n } else {\n graphicAttributes.textConfig = nextAttrs.textConfig;\n }\n }\n }\n ]\n};\n\nexport function cloneTransformAttributes(markType: MarkType, attributes: any) {\n const transforms = transformsByType[markType] ?? [];\n return transforms.reduce((clonedAttributes, transform) => {\n transform.channels.forEach(channel => {\n if (has(attributes, channel)) {\n clonedAttributes[channel] = attributes[channel];\n }\n });\n return clonedAttributes;\n }, {} as any);\n}\n\nexport const transformAttributes = (\n markType: MarkType | AttributeTransform[],\n nextAttrs: any,\n element: IElement,\n markName?: string\n) => {\n const graphicAttributes = {};\n const changedKeys = nextAttrs ? Object.keys(nextAttrs) : [];\n const transforms: AttributeTransform[] = isString(markType)\n ? transformsByType[markType]\n : (markType as AttributeTransform[]);\n\n if (transforms?.length) {\n const tags: boolean[] = [];\n\n changedKeys.forEach(key => {\n let isTransformed = false;\n\n transforms.forEach((transform, index) => {\n if (transform.channels.includes(key)) {\n if (!tags[index]) {\n if (transform.storedAttrs) {\n const storedAttrs = storeOriginAttributes(\n transform.storedAttrs,\n transform.channels,\n graphicAttributes,\n nextAttrs,\n element,\n markName\n );\n transform.transform(graphicAttributes, nextAttrs, storedAttrs);\n } else {\n transform.transform(graphicAttributes, nextAttrs, null);\n }\n }\n // 记录一下,不重复处理\n tags[index] = true;\n isTransformed = true;\n }\n });\n\n if (!isTransformed) {\n if (commonAttributes.includes(key)) {\n transformCommonAttribute(graphicAttributes, key, nextAttrs);\n } else {\n graphicAttributes[key] = nextAttrs[key];\n }\n }\n });\n } else {\n changedKeys.forEach(key => {\n if (commonAttributes.includes(key)) {\n transformCommonAttribute(graphicAttributes, key, nextAttrs);\n } else {\n graphicAttributes[key] = nextAttrs[key];\n }\n });\n }\n\n return graphicAttributes;\n};\n"]}
1
+ {"version":3,"sources":["../src/graph/attributes/transform.ts"],"names":[],"mappings":";;;AAAA,6CAAsF;AAGtF,oCAA2C;AAC3C,uCAA0C;AAC1C,qCAAsE;AAEtE,SAAS,qBAAqB,CAC5B,IAAY,EACZ,QAAkB,EAClB,iBAAsB,EACtB,SAAc,EACd,OAAiB,EACjB,QAAgB;;IAEhB,MAAM,eAAe,GAAG,MAAC,OAAyB,CAAC,mBAAmB,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,mCAAI,EAAE,CAAC;IACpG,MAAM,WAAW,GAAG,EAAE,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;;QACzB,WAAW,CAAC,OAAO,CAAC,GAAG,MAAA,SAAS,CAAC,OAAO,CAAC,mCAAI,eAAe,CAAC,OAAO,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;IACH,iBAAiB,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC;IACtC,OAAO,WAAW,CAAC;AACrB,CAAC;AAEY,QAAA,gBAAgB,GAAyC;IACpE,CAAC,uBAAe,CAAC,UAAU,CAAC,EAAE;QAC5B;YACE,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,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AC,WAAW,EACrB,SAAS,CAAC,QAAQ,EAClB,iBAAiB,EACjB,SAAS,EACT,OAAO,EACP,QAAQ,CACT,CAAC;4BACF,SAAS,CAAC,SAAS,CAAC,iBAAiB,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;yBAChE;6BAAM;4BACL,SAAS,CAAC,SAAS,CAAC,iBAAiB,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;yBACzD;qBACF;oBAED,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;oBACnB,aAAa,GAAG,IAAI,CAAC;iBACtB;YACH,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,aAAa,EAAE;gBAClB,IAAI,yBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;oBAClC,IAAA,iCAAwB,EAAC,iBAAiB,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;iBAC7D;qBAAM;oBACL,iBAAiB,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;iBACzC;aACF;QACH,CAAC,CAAC,CAAC;KACJ;SAAM;QACL,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACxB,IAAI,yBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;gBAClC,IAAA,iCAAwB,EAAC,iBAAiB,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;aAC7D;iBAAM;gBACL,iBAAiB,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;aACzC;QACH,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AA5DW,QAAA,mBAAmB,uBA4D9B","file":"transform.js","sourcesContent":["import { has, isNil, isPlainObject, isString, isValidNumber } from '@visactor/vutils';\nimport type { IElement, IGlyphElement } from '../../types/element';\nimport type { AttributeTransform, MarkType } from '../../types/mark';\nimport { GrammarMarkType } from '../enums';\nimport { getRulePoints } from './helpers';\nimport { commonAttributes, transformCommonAttribute } from './common';\n\nfunction storeOriginAttributes(\n name: string,\n channels: string[],\n graphicAttributes: any,\n nextAttrs: any,\n element: IElement,\n markName: string\n): Record<string, any> {\n const prevStoredAttrs = (element as IGlyphElement).getGraphicAttribute(name, false, markName) ?? {};\n const storedAttrs = {};\n channels.forEach(channel => {\n storedAttrs[channel] = nextAttrs[channel] ?? prevStoredAttrs[channel];\n });\n graphicAttributes[name] = storedAttrs;\n return storedAttrs;\n}\n\nexport const transformsByType: Record<string, AttributeTransform[]> = {\n [GrammarMarkType.largeRects]: [\n {\n channels: ['x', 'y', 'y1', 'x1', 'width', 'height'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n graphicAttributes.x = 0;\n graphicAttributes.y = 0;\n }\n }\n ],\n [GrammarMarkType.largeSymbols]: [\n {\n channels: ['x', 'y', 'size'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n graphicAttributes.x = 0;\n graphicAttributes.y = 0;\n }\n }\n ],\n [GrammarMarkType.area]: [\n {\n channels: ['x', 'y', 'x1', 'y1'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n graphicAttributes.x = 0;\n graphicAttributes.y = 0;\n graphicAttributes.x1 = 0;\n graphicAttributes.y1 = 0;\n }\n }\n ],\n [GrammarMarkType.line]: [\n {\n channels: ['x', 'y', 'defined'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n graphicAttributes.x = 0;\n graphicAttributes.y = 0;\n }\n }\n ],\n rect3d: [\n {\n channels: ['x', 'y', 'z', 'x1', 'y1', 'width', 'height', 'length'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n // width\n if (isValidNumber(nextAttrs.width) || (!isValidNumber(nextAttrs.x1) && isValidNumber(storedAttrs.width))) {\n graphicAttributes.x = Math.min(storedAttrs.x ?? 0, storedAttrs.x1 ?? Infinity);\n graphicAttributes.width = storedAttrs.width;\n } else if (isValidNumber(nextAttrs.x1) || (!isValidNumber(nextAttrs.width) && isValidNumber(storedAttrs.x1))) {\n graphicAttributes.x = Math.min(storedAttrs.x, storedAttrs.x1);\n graphicAttributes.width = Math.abs(storedAttrs.x1 - storedAttrs.x);\n } else {\n graphicAttributes.x = Math.min(storedAttrs.x ?? 0, storedAttrs.x1 ?? Infinity);\n graphicAttributes.width = storedAttrs.width;\n }\n\n // height\n if (isValidNumber(nextAttrs.height) || (!isValidNumber(nextAttrs.y1) && isValidNumber(storedAttrs.height))) {\n graphicAttributes.y = Math.min(storedAttrs.y ?? 0, storedAttrs.y1 ?? Infinity);\n graphicAttributes.height = storedAttrs.height;\n } else if (isValidNumber(nextAttrs.y1) || (!isValidNumber(nextAttrs.height) && isValidNumber(storedAttrs.y1))) {\n graphicAttributes.y = Math.min(storedAttrs.y, storedAttrs.y1);\n graphicAttributes.height = Math.abs(storedAttrs.y1 - storedAttrs.y);\n } else {\n graphicAttributes.y = Math.min(storedAttrs.y ?? 0, storedAttrs.y1 ?? Infinity);\n graphicAttributes.height = storedAttrs.height;\n }\n\n // length\n if (isValidNumber(nextAttrs.length) || (!isValidNumber(nextAttrs.z1) && isValidNumber(storedAttrs.length))) {\n graphicAttributes.z = Math.min(storedAttrs.z ?? 0, storedAttrs.z1 ?? Infinity);\n graphicAttributes.length = storedAttrs.length;\n } else if (isValidNumber(nextAttrs.z1) || (!isValidNumber(nextAttrs.length) && isValidNumber(storedAttrs.z1))) {\n graphicAttributes.z = Math.min(storedAttrs.z, storedAttrs.z1);\n graphicAttributes.length = Math.abs(storedAttrs.z1 - storedAttrs.z);\n } else {\n graphicAttributes.z = Math.min(storedAttrs.z ?? 0, storedAttrs.z1 ?? Infinity);\n graphicAttributes.length = storedAttrs.length;\n }\n },\n storedAttrs: 'sizeAttrs'\n }\n ],\n [GrammarMarkType.text]: [\n {\n channels: ['text', 'limit', 'autoLimit', 'maxLineWidth'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n const limit = storedAttrs.limit ?? Infinity;\n const autoLimit = storedAttrs.autoLimit ?? Infinity;\n const maxWidth = Math.min(limit, autoLimit);\n const isTextConfig = isPlainObject(storedAttrs.text) && !isNil(storedAttrs.text.text);\n const text = isTextConfig ? storedAttrs.text.text : storedAttrs.text;\n\n if (Array.isArray(text)) {\n graphicAttributes.maxLineWidth = maxWidth === Infinity ? storedAttrs.maxLineWidth : maxWidth;\n } else {\n graphicAttributes.maxLineWidth = maxWidth === Infinity ? storedAttrs.maxLineWidth : maxWidth;\n }\n\n if (isTextConfig) {\n if (storedAttrs.text.type === 'html') {\n graphicAttributes.html = {\n dom: text,\n width: nextAttrs.width ?? maxWidth,\n height: nextAttrs.height ?? nextAttrs.fontSize,\n anchorType: 'position'\n };\n graphicAttributes.text = '';\n } else if (storedAttrs.text.type === 'rich') {\n graphicAttributes.textConfig = text;\n } else {\n graphicAttributes.text = text;\n }\n } else {\n graphicAttributes.text = text;\n }\n },\n storedAttrs: 'limitAttrs'\n }\n ],\n [GrammarMarkType.rule]: [\n {\n channels: ['x', 'y', 'x1', 'y1'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n const points = getRulePoints(storedAttrs);\n graphicAttributes.points = points;\n graphicAttributes.x = 0;\n graphicAttributes.y = 0;\n },\n storedAttrs: 'pointAttrs'\n }\n ],\n [GrammarMarkType.symbol]: [\n {\n channels: ['shape', 'symbolType'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n graphicAttributes.symbolType = nextAttrs.shape ?? nextAttrs.symbolType;\n }\n },\n {\n channels: ['image', 'fill', 'background'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n if (nextAttrs.image) {\n graphicAttributes.background = nextAttrs.image;\n graphicAttributes.fill = false;\n } else if (storedAttrs.image) {\n graphicAttributes.background = storedAttrs.image;\n graphicAttributes.fill = false;\n } else {\n graphicAttributes.fill = storedAttrs.fill;\n graphicAttributes.background = storedAttrs.background;\n }\n },\n storedAttrs: 'imageAttrs'\n }\n ],\n [GrammarMarkType.richtext]: [\n {\n channels: ['text', 'textConfig'],\n transform: (graphicAttributes: any, nextAttrs: any, storedAttrs: any) => {\n graphicAttributes.text = null;\n\n if (nextAttrs.text?.type === 'rich') {\n graphicAttributes.textConfig = nextAttrs.text.text;\n } else if (nextAttrs.textConfig?.type === 'html') {\n graphicAttributes.html = {\n dom: nextAttrs.textConfig.text,\n width: nextAttrs.width,\n height: nextAttrs.height ?? nextAttrs.fontSize,\n anchorType: 'position'\n };\n graphicAttributes.text = '';\n } else if (nextAttrs.textConfig?.type === 'rich') {\n graphicAttributes.textConfig = nextAttrs.textConfig.text;\n } else {\n graphicAttributes.textConfig = nextAttrs.textConfig;\n }\n }\n }\n ]\n};\n\nexport function cloneTransformAttributes(markType: MarkType, attributes: any) {\n const transforms = transformsByType[markType] ?? [];\n return transforms.reduce((clonedAttributes, transform) => {\n transform.channels.forEach(channel => {\n if (has(attributes, channel)) {\n clonedAttributes[channel] = attributes[channel];\n }\n });\n return clonedAttributes;\n }, {} as any);\n}\n\nexport const transformAttributes = (\n markType: MarkType | AttributeTransform[],\n nextAttrs: any,\n element: IElement,\n markName?: string\n) => {\n const graphicAttributes = {};\n const changedKeys = nextAttrs ? Object.keys(nextAttrs) : [];\n const transforms: AttributeTransform[] = isString(markType)\n ? transformsByType[markType]\n : (markType as AttributeTransform[]);\n\n if (transforms?.length) {\n const tags: boolean[] = [];\n\n changedKeys.forEach(key => {\n let isTransformed = false;\n\n transforms.forEach((transform, index) => {\n if (transform.channels.includes(key)) {\n if (!tags[index]) {\n if (transform.storedAttrs) {\n const storedAttrs = storeOriginAttributes(\n transform.storedAttrs,\n transform.channels,\n graphicAttributes,\n nextAttrs,\n element,\n markName\n );\n transform.transform(graphicAttributes, nextAttrs, storedAttrs);\n } else {\n transform.transform(graphicAttributes, nextAttrs, null);\n }\n }\n // 记录一下,不重复处理\n tags[index] = true;\n isTransformed = true;\n }\n });\n\n if (!isTransformed) {\n if (commonAttributes.includes(key)) {\n transformCommonAttribute(graphicAttributes, key, nextAttrs);\n } else {\n graphicAttributes[key] = nextAttrs[key];\n }\n }\n });\n } else {\n changedKeys.forEach(key => {\n if (commonAttributes.includes(key)) {\n transformCommonAttribute(graphicAttributes, key, nextAttrs);\n } else {\n graphicAttributes[key] = nextAttrs[key];\n }\n });\n }\n\n return graphicAttributes;\n};\n"]}
@@ -95,7 +95,8 @@ class CanvasRenderer {
95
95
  disableDirtyBounds: !0,
96
96
  autoRender: !0,
97
97
  pluginList: viewOptions.pluginList,
98
- enableHtmlAttribute: viewOptions.enableHtmlAttribute
98
+ enableHtmlAttribute: viewOptions.enableHtmlAttribute,
99
+ optimize: viewOptions.optimize
99
100
  });
100
101
  (null === (_b = viewOptions.options3d) || void 0 === _b ? void 0 : _b.enable) && stage.set3dOptions(viewOptions.options3d),
101
102
  stage.enableIncrementalAutoRender(), this._viewBox = viewOptions.viewBox, this._view.emit(enums_1.HOOK_EVENT.AFTER_CREATE_VRENDER_STAGE),
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graph/canvas-renderer.ts"],"names":[],"mappings":";;AAEA,6CAA4C;AAG5C,yDAA0E;AAC1E,yDAA4D;AAG5D,mCAAqC;AAErC,MAAqB,cAAc;IAajC,YAAY,IAAW;QAyOf,0BAAqB,GAAG,GAAG,EAAE;YACnC,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE;gBACxD,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;aACjC;YAED,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAU,CAAC,kBAAkB,CAAC,CAAC;YAC/C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAU,CAAC,yBAAyB,CAAC,CAAC;QACxD,CAAC,CAAC;QA/OA,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,UAAU,CAAC,KAAa,EAAE,MAAc,EAAE,OAAqB,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YAEpB,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;YAC3C,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;SAC7B;IACH,CAAC;CAUF;AA9PD,iCA8PC","file":"canvas-renderer.js","sourcesContent":["import type { IBoundsLike } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { isObject } from '@visactor/vutils';\nimport type { IEventTarget, IColor, ILayer, Stage } from '@visactor/vrender-core';\n// eslint-disable-next-line no-duplicate-imports\nimport { createStage, waitForAllSubLayers } from '@visactor/vrender-core';\nimport { DragNDrop, Gesture } from '@visactor/vrender-kits';\nimport type { IViewOptions, IView, IMark, IViewEventConfig } from '../types';\nimport type { IRenderer } from '../types/renderer';\nimport { HOOK_EVENT } from './enums';\n\nexport default class CanvasRenderer implements IRenderer {\n private _width: number;\n private _height: number;\n\n private _view: IView;\n private _viewOptions: IViewOptions;\n private _eventConfig: IViewEventConfig;\n private _stage: Stage;\n private _layer: ILayer;\n private _dragController: DragNDrop;\n private _gestureController: Gesture;\n private _viewBox: IBoundsLike;\n\n constructor(view: IView) {\n this._view = view;\n }\n\n initialize(width: number, height: number, options: IViewOptions, eventConfig: IViewEventConfig) {\n this._width = width;\n this._height = height;\n this._viewOptions = options;\n this._eventConfig = eventConfig;\n\n this.initStage();\n\n // this method will invoke resize to size the canvas appropriately\n return this;\n }\n\n stage() {\n return this._stage ?? null;\n }\n\n canvas() {\n if (this._stage) {\n return this._stage.window.getNativeHandler().nativeCanvas;\n }\n return null;\n }\n\n context() {\n if (this._stage) {\n return this._stage.window.getContext().nativeContext;\n }\n return null;\n }\n\n combineIncrementalLayers() {\n if (this._stage) {\n waitForAllSubLayers(this._stage as any).then(() => {\n // stage might be null in current tick\n if (this._stage) {\n this._stage.defaultLayer.combineSubLayer();\n }\n });\n }\n return this;\n }\n\n background(color: IColor) {\n if (this._stage) {\n this._stage.background = color;\n return this;\n }\n }\n\n setDpr(resolution: number, redraw: boolean) {\n this._stage?.setDpr?.(resolution);\n if (redraw) {\n this.renderNextFrame();\n }\n return this;\n }\n\n shouldResize(width: number, height: number) {\n return width !== this._width || height !== this._height;\n }\n\n resize(width: number, height: number) {\n this._view.emit(HOOK_EVENT.BEFORE_STAGE_RESIZE);\n if (this.shouldResize(width, height)) {\n this._width = width;\n this._height = height;\n this._stage && this._stage.resize(width, height);\n }\n\n this._view.emit(HOOK_EVENT.AFTER_STAGE_RESIZE);\n\n return this;\n }\n\n setViewBox(viewBox: IBoundsLike, rerender: boolean = true) {\n if (!this._stage) {\n return this;\n }\n if (\n viewBox &&\n (!this._viewBox ||\n viewBox.x1 !== this._viewBox.x1 ||\n viewBox.x2 !== this._viewBox.x2 ||\n viewBox.y1 !== this._viewBox.y1 ||\n viewBox.y2 !== this._viewBox.y2)\n ) {\n this._viewBox = viewBox;\n\n // FIXME: vRender\n this._stage.setViewBox(viewBox.x1, viewBox.y1, viewBox.x2 - viewBox.x1, viewBox.y2 - viewBox.y1, rerender);\n }\n return this;\n }\n\n render(immediately: boolean = false) {\n this._view.emit(HOOK_EVENT.BEFORE_VRENDER_DRAW);\n\n this.initStage();\n\n // disable dirty bounds when render is called\n this._stage.disableDirtyBounds();\n this._stage.afterNextRender(this.handleAfterNextRender);\n\n // render immediately and skip render in next frame\n if (immediately) {\n this._stage.render();\n\n this._view.emit(HOOK_EVENT.AFTER_VRENDER_DRAW);\n }\n return this;\n }\n\n renderNextFrame() {\n this.initStage();\n\n this._stage.renderNextFrame();\n\n return this;\n }\n\n toCanvas() {\n if (this._stage) {\n return this._stage.toCanvas();\n }\n return null;\n }\n\n preventRender(tag: boolean) {\n if (this._stage) {\n this._stage.preventRender(tag);\n }\n }\n\n // toImageData() {\n // if (this._stage) {\n // return this._stage.toImageData();\n // }\n // return null;\n // }\n\n release() {\n this._view.traverseMarkTree((mark: IMark) => {\n mark.release();\n });\n\n if (this._dragController) {\n this._dragController.release();\n }\n if (this._gestureController) {\n this._gestureController.release();\n }\n\n if (this._stage !== (this._viewOptions?.stage as unknown as Stage)) {\n // don't release the stage created by outside\n this._stage.release();\n }\n\n this._stage = null;\n this._layer = null;\n this._dragController = null;\n this._gestureController = null;\n }\n\n private createStage() {\n this._view.emit(HOOK_EVENT.BEFORE_CREATE_VRENDER_STAGE);\n\n const viewOptions = this._viewOptions;\n\n const stage =\n (viewOptions.stage as unknown as Stage) ??\n createStage({\n width: this._width,\n height: this._height,\n renderStyle: viewOptions.renderStyle,\n viewBox: viewOptions.viewBox,\n dpr: viewOptions.dpr,\n canvas: viewOptions.renderCanvas,\n canvasControled: viewOptions.canvasControled,\n container: viewOptions.container,\n title: viewOptions.rendererTitle,\n beforeRender: viewOptions.beforeRender,\n afterRender: viewOptions.afterRender,\n disableDirtyBounds: true,\n autoRender: true,\n pluginList: viewOptions.pluginList,\n enableHtmlAttribute: viewOptions.enableHtmlAttribute\n });\n\n if (viewOptions.options3d?.enable) {\n stage.set3dOptions(viewOptions.options3d);\n }\n\n stage.enableIncrementalAutoRender();\n\n this._viewBox = viewOptions.viewBox;\n this._view.emit(HOOK_EVENT.AFTER_CREATE_VRENDER_STAGE);\n\n this._view.emit(HOOK_EVENT.BEFORE_CREATE_VRENDER_LAYER);\n const layer = viewOptions.layer ?? (stage.defaultLayer as ILayer);\n this._view.emit(HOOK_EVENT.AFTER_CREATE_VRENDER_LAYER);\n\n if (this._eventConfig?.drag) {\n // 允许 drag 事件\n this._dragController = new DragNDrop(stage as unknown as IEventTarget);\n }\n if (this._eventConfig?.gesture) {\n const gestureConfig = isObject(this._eventConfig.gesture) ? this._eventConfig.gesture : {};\n // 允许手势\n this._gestureController = new Gesture(stage as unknown as IEventTarget, gestureConfig);\n }\n\n return {\n stage,\n layer\n };\n }\n\n private initStage() {\n if (!this._stage) {\n const { stage, layer } = this.createStage();\n\n this._stage = stage;\n this._layer = layer;\n\n const background = this._view.background();\n this.background(background);\n }\n }\n\n private handleAfterNextRender = () => {\n if (this._stage && !this._viewOptions.disableDirtyBounds) {\n this._stage.enableDirtyBounds();\n }\n\n this._view.emit(HOOK_EVENT.AFTER_VRENDER_DRAW);\n this._view.emit(HOOK_EVENT.AFTER_VRENDER_NEXT_RENDER);\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/graph/canvas-renderer.ts"],"names":[],"mappings":";;AAEA,6CAA4C;AAG5C,yDAA0E;AAC1E,yDAA4D;AAG5D,mCAAqC;AAErC,MAAqB,cAAc;IAajC,YAAY,IAAW;QA0Of,0BAAqB,GAAG,GAAG,EAAE;YACnC,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE;gBACxD,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;aACjC;YAED,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAU,CAAC,kBAAkB,CAAC,CAAC;YAC/C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAU,CAAC,yBAAyB,CAAC,CAAC;QACxD,CAAC,CAAC;QAhPA,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,UAAU,CAAC,KAAa,EAAE,MAAc,EAAE,OAAqB,EAAE,WAA6B;QAC5F,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC;QAC5B,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAEhC,IAAI,CAAC,SAAS,EAAE,CAAC;QAGjB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;;QACH,OAAO,MAAA,IAAI,CAAC,MAAM,mCAAI,IAAI,CAAC;IAC7B,CAAC;IAED,MAAM;QACJ,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC,YAAY,CAAC;SAC3D;QACD,OAAO,IAAI,CAAC;IACd,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,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAU,CAAC,0BAA0B,CAAC,CAAC;QAEvD,IAAI,MAAA,IAAI,CAAC,YAAY,0CAAE,IAAI,EAAE;YAE3B,IAAI,CAAC,eAAe,GAAG,IAAI,wBAAS,CAAC,KAAgC,CAAC,CAAC;SACxE;QACD,IAAI,MAAA,IAAI,CAAC,YAAY,0CAAE,OAAO,EAAE;YAC9B,MAAM,aAAa,GAAG,IAAA,iBAAQ,EAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YAE3F,IAAI,CAAC,kBAAkB,GAAG,IAAI,sBAAO,CAAC,KAAgC,EAAE,aAAa,CAAC,CAAC;SACxF;QAED,OAAO;YACL,KAAK;YACL,KAAK;SACN,CAAC;IACJ,CAAC;IAEO,SAAS;QACf,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAChB,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;YAE5C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;YACpB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;YAEpB,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;YAC3C,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;SAC7B;IACH,CAAC;CAUF;AA/PD,iCA+PC","file":"canvas-renderer.js","sourcesContent":["import type { IBoundsLike } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { isObject } from '@visactor/vutils';\nimport type { IEventTarget, IColor, ILayer, Stage } from '@visactor/vrender-core';\n// eslint-disable-next-line no-duplicate-imports\nimport { createStage, waitForAllSubLayers } from '@visactor/vrender-core';\nimport { DragNDrop, Gesture } from '@visactor/vrender-kits';\nimport type { IViewOptions, IView, IMark, IViewEventConfig } from '../types';\nimport type { IRenderer } from '../types/renderer';\nimport { HOOK_EVENT } from './enums';\n\nexport default class CanvasRenderer implements IRenderer {\n private _width: number;\n private _height: number;\n\n private _view: IView;\n private _viewOptions: IViewOptions;\n private _eventConfig: IViewEventConfig;\n private _stage: Stage;\n private _layer: ILayer;\n private _dragController: DragNDrop;\n private _gestureController: Gesture;\n private _viewBox: IBoundsLike;\n\n constructor(view: IView) {\n this._view = view;\n }\n\n initialize(width: number, height: number, options: IViewOptions, eventConfig: IViewEventConfig) {\n this._width = width;\n this._height = height;\n this._viewOptions = options;\n this._eventConfig = eventConfig;\n\n this.initStage();\n\n // this method will invoke resize to size the canvas appropriately\n return this;\n }\n\n stage() {\n return this._stage ?? null;\n }\n\n canvas() {\n if (this._stage) {\n return this._stage.window.getNativeHandler().nativeCanvas;\n }\n return null;\n }\n\n context() {\n if (this._stage) {\n return this._stage.window.getContext().nativeContext;\n }\n return null;\n }\n\n combineIncrementalLayers() {\n if (this._stage) {\n waitForAllSubLayers(this._stage as any).then(() => {\n // stage might be null in current tick\n if (this._stage) {\n this._stage.defaultLayer.combineSubLayer();\n }\n });\n }\n return this;\n }\n\n background(color: IColor) {\n if (this._stage) {\n this._stage.background = color;\n return this;\n }\n }\n\n setDpr(resolution: number, redraw: boolean) {\n this._stage?.setDpr?.(resolution);\n if (redraw) {\n this.renderNextFrame();\n }\n return this;\n }\n\n shouldResize(width: number, height: number) {\n return width !== this._width || height !== this._height;\n }\n\n resize(width: number, height: number) {\n this._view.emit(HOOK_EVENT.BEFORE_STAGE_RESIZE);\n if (this.shouldResize(width, height)) {\n this._width = width;\n this._height = height;\n this._stage && this._stage.resize(width, height);\n }\n\n this._view.emit(HOOK_EVENT.AFTER_STAGE_RESIZE);\n\n return this;\n }\n\n setViewBox(viewBox: IBoundsLike, rerender: boolean = true) {\n if (!this._stage) {\n return this;\n }\n if (\n viewBox &&\n (!this._viewBox ||\n viewBox.x1 !== this._viewBox.x1 ||\n viewBox.x2 !== this._viewBox.x2 ||\n viewBox.y1 !== this._viewBox.y1 ||\n viewBox.y2 !== this._viewBox.y2)\n ) {\n this._viewBox = viewBox;\n\n // FIXME: vRender\n this._stage.setViewBox(viewBox.x1, viewBox.y1, viewBox.x2 - viewBox.x1, viewBox.y2 - viewBox.y1, rerender);\n }\n return this;\n }\n\n render(immediately: boolean = false) {\n this._view.emit(HOOK_EVENT.BEFORE_VRENDER_DRAW);\n\n this.initStage();\n\n // disable dirty bounds when render is called\n this._stage.disableDirtyBounds();\n this._stage.afterNextRender(this.handleAfterNextRender);\n\n // render immediately and skip render in next frame\n if (immediately) {\n this._stage.render();\n\n this._view.emit(HOOK_EVENT.AFTER_VRENDER_DRAW);\n }\n return this;\n }\n\n renderNextFrame() {\n this.initStage();\n\n this._stage.renderNextFrame();\n\n return this;\n }\n\n toCanvas() {\n if (this._stage) {\n return this._stage.toCanvas();\n }\n return null;\n }\n\n preventRender(tag: boolean) {\n if (this._stage) {\n this._stage.preventRender(tag);\n }\n }\n\n // toImageData() {\n // if (this._stage) {\n // return this._stage.toImageData();\n // }\n // return null;\n // }\n\n release() {\n this._view.traverseMarkTree((mark: IMark) => {\n mark.release();\n });\n\n if (this._dragController) {\n this._dragController.release();\n }\n if (this._gestureController) {\n this._gestureController.release();\n }\n\n if (this._stage !== (this._viewOptions?.stage as unknown as Stage)) {\n // don't release the stage created by outside\n this._stage.release();\n }\n\n this._stage = null;\n this._layer = null;\n this._dragController = null;\n this._gestureController = null;\n }\n\n private createStage() {\n this._view.emit(HOOK_EVENT.BEFORE_CREATE_VRENDER_STAGE);\n\n const viewOptions = this._viewOptions;\n\n const stage =\n (viewOptions.stage as unknown as Stage) ??\n createStage({\n width: this._width,\n height: this._height,\n renderStyle: viewOptions.renderStyle,\n viewBox: viewOptions.viewBox,\n dpr: viewOptions.dpr,\n canvas: viewOptions.renderCanvas,\n canvasControled: viewOptions.canvasControled,\n container: viewOptions.container,\n title: viewOptions.rendererTitle,\n beforeRender: viewOptions.beforeRender,\n afterRender: viewOptions.afterRender,\n disableDirtyBounds: true,\n autoRender: true,\n pluginList: viewOptions.pluginList,\n enableHtmlAttribute: viewOptions.enableHtmlAttribute,\n optimize: viewOptions.optimize\n });\n\n if (viewOptions.options3d?.enable) {\n stage.set3dOptions(viewOptions.options3d);\n }\n\n stage.enableIncrementalAutoRender();\n\n this._viewBox = viewOptions.viewBox;\n this._view.emit(HOOK_EVENT.AFTER_CREATE_VRENDER_STAGE);\n\n this._view.emit(HOOK_EVENT.BEFORE_CREATE_VRENDER_LAYER);\n const layer = viewOptions.layer ?? (stage.defaultLayer as ILayer);\n this._view.emit(HOOK_EVENT.AFTER_CREATE_VRENDER_LAYER);\n\n if (this._eventConfig?.drag) {\n // 允许 drag 事件\n this._dragController = new DragNDrop(stage as unknown as IEventTarget);\n }\n if (this._eventConfig?.gesture) {\n const gestureConfig = isObject(this._eventConfig.gesture) ? this._eventConfig.gesture : {};\n // 允许手势\n this._gestureController = new Gesture(stage as unknown as IEventTarget, gestureConfig);\n }\n\n return {\n stage,\n layer\n };\n }\n\n private initStage() {\n if (!this._stage) {\n const { stage, layer } = this.createStage();\n\n this._stage = stage;\n this._layer = layer;\n\n const background = this._view.background();\n this.background(background);\n }\n }\n\n private handleAfterNextRender = () => {\n if (this._stage && !this._viewOptions.disableDirtyBounds) {\n this._stage.enableDirtyBounds();\n }\n\n this._view.emit(HOOK_EVENT.AFTER_VRENDER_DRAW);\n this._view.emit(HOOK_EVENT.AFTER_VRENDER_NEXT_RENDER);\n };\n}\n"]}
@@ -16,6 +16,8 @@ export declare class Element implements IElement {
16
16
  initGraphicItem(attributes?: any): void;
17
17
  updateGraphicItem(config: IMarkConfig): void;
18
18
  getGraphicItem(): IGraphic<Partial<IGraphicAttribute>>;
19
+ removeGraphicItem(): void;
20
+ resetGraphicItem(): void;
19
21
  getBounds(): import("@visactor/vutils").IBounds;
20
22
  getStates(): string[];
21
23
  updateData(groupKey: string | null, data: any[], key: MarkKeySpec): MarkElementItem[];