@visactor/vchart 2.0.23-alpha.6 → 2.1.0-alpha.0

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 (104) hide show
  1. package/build/es5/index.js +3 -3
  2. package/build/index.es.js +21465 -16956
  3. package/build/index.js +21467 -16958
  4. package/build/index.min.js +2 -2
  5. package/build/tsconfig.tsbuildinfo +1 -1
  6. package/cjs/compile/compiler.d.ts +4 -0
  7. package/cjs/compile/compiler.js +66 -41
  8. package/cjs/compile/compiler.js.map +1 -1
  9. package/cjs/compile/interface/compiler.d.ts +2 -1
  10. package/cjs/compile/interface/compiler.js.map +1 -1
  11. package/cjs/compile/stage-app.d.ts +9 -0
  12. package/cjs/compile/stage-app.js +39 -0
  13. package/cjs/compile/stage-app.js.map +1 -0
  14. package/cjs/component/brush/brush.js +13 -12
  15. package/cjs/component/brush/brush.js.map +1 -1
  16. package/cjs/component/marker/mark-line/cartesian-mark-line.js +7 -18
  17. package/cjs/component/marker/mark-line/cartesian-mark-line.js.map +1 -1
  18. package/cjs/component/marker/mark-line/interface/spec.d.ts +2 -9
  19. package/cjs/component/marker/mark-line/interface/spec.js.map +1 -1
  20. package/cjs/component/util.js +2 -1
  21. package/cjs/constant/attribute.js +1 -2
  22. package/cjs/constant/scroll-bar.js +2 -1
  23. package/cjs/constant/waterfall.js +1 -2
  24. package/cjs/core/factory.js +1 -1
  25. package/cjs/core/index.js +1 -1
  26. package/cjs/core/instance-manager.js +1 -1
  27. package/cjs/env/env.js +1 -1
  28. package/cjs/env/index.js +1 -1
  29. package/cjs/interaction/interaction.js +11 -8
  30. package/cjs/interaction/interaction.js.map +1 -1
  31. package/cjs/interaction/triggers/element-active-by-legend.js +3 -2
  32. package/cjs/interaction/triggers/element-active-by-legend.js.map +1 -1
  33. package/cjs/interaction/triggers/element-active.js +4 -3
  34. package/cjs/interaction/triggers/element-active.js.map +1 -1
  35. package/cjs/interaction/triggers/element-highlight-by-group.js +3 -2
  36. package/cjs/interaction/triggers/element-highlight-by-group.js.map +1 -1
  37. package/cjs/interaction/triggers/element-highlight-by-legend.js +2 -2
  38. package/cjs/interaction/triggers/element-highlight-by-legend.js.map +1 -1
  39. package/cjs/interaction/triggers/element-highlight-by-name.js +2 -2
  40. package/cjs/interaction/triggers/element-highlight-by-name.js.map +1 -1
  41. package/cjs/interaction/triggers/element-highlight.js +2 -2
  42. package/cjs/interaction/triggers/element-highlight.js.map +1 -1
  43. package/cjs/interaction/triggers/element-select.js +3 -3
  44. package/cjs/interaction/triggers/element-select.js.map +1 -1
  45. package/cjs/mark/base/base-mark.d.ts +1 -0
  46. package/cjs/mark/base/base-mark.js +29 -15
  47. package/cjs/mark/base/base-mark.js.map +1 -1
  48. package/cjs/mark/utils/glyph.js +3 -2
  49. package/cjs/mark/utils/glyph.js.map +1 -1
  50. package/cjs/series/sankey/sankey.js +32 -24
  51. package/cjs/series/sankey/sankey.js.map +1 -1
  52. package/cjs/util/graphic-state.d.ts +3 -0
  53. package/cjs/util/graphic-state.js +25 -0
  54. package/cjs/util/graphic-state.js.map +1 -0
  55. package/esm/compile/compiler.d.ts +4 -0
  56. package/esm/compile/compiler.js +68 -40
  57. package/esm/compile/compiler.js.map +1 -1
  58. package/esm/compile/interface/compiler.d.ts +2 -1
  59. package/esm/compile/interface/compiler.js.map +1 -1
  60. package/esm/compile/stage-app.d.ts +9 -0
  61. package/esm/compile/stage-app.js +35 -0
  62. package/esm/compile/stage-app.js.map +1 -0
  63. package/esm/component/brush/brush.js +9 -7
  64. package/esm/component/brush/brush.js.map +1 -1
  65. package/esm/component/marker/mark-line/cartesian-mark-line.js +8 -18
  66. package/esm/component/marker/mark-line/cartesian-mark-line.js.map +1 -1
  67. package/esm/component/marker/mark-line/interface/spec.d.ts +2 -9
  68. package/esm/component/marker/mark-line/interface/spec.js.map +1 -1
  69. package/esm/component/util.js +2 -1
  70. package/esm/constant/attribute.js +1 -2
  71. package/esm/constant/scroll-bar.js +2 -1
  72. package/esm/constant/waterfall.js +1 -2
  73. package/esm/core/factory.js +1 -1
  74. package/esm/core/index.js +1 -1
  75. package/esm/core/instance-manager.js +1 -1
  76. package/esm/env/env.js +1 -1
  77. package/esm/env/index.js +1 -1
  78. package/esm/interaction/interaction.js +10 -8
  79. package/esm/interaction/interaction.js.map +1 -1
  80. package/esm/interaction/triggers/element-active-by-legend.js +3 -1
  81. package/esm/interaction/triggers/element-active-by-legend.js.map +1 -1
  82. package/esm/interaction/triggers/element-active.js +4 -2
  83. package/esm/interaction/triggers/element-active.js.map +1 -1
  84. package/esm/interaction/triggers/element-highlight-by-group.js +4 -1
  85. package/esm/interaction/triggers/element-highlight-by-group.js.map +1 -1
  86. package/esm/interaction/triggers/element-highlight-by-legend.js +3 -1
  87. package/esm/interaction/triggers/element-highlight-by-legend.js.map +1 -1
  88. package/esm/interaction/triggers/element-highlight-by-name.js +3 -1
  89. package/esm/interaction/triggers/element-highlight-by-name.js.map +1 -1
  90. package/esm/interaction/triggers/element-highlight.js +3 -1
  91. package/esm/interaction/triggers/element-highlight.js.map +1 -1
  92. package/esm/interaction/triggers/element-select.js +4 -2
  93. package/esm/interaction/triggers/element-select.js.map +1 -1
  94. package/esm/mark/base/base-mark.d.ts +1 -0
  95. package/esm/mark/base/base-mark.js +29 -14
  96. package/esm/mark/base/base-mark.js.map +1 -1
  97. package/esm/mark/utils/glyph.js +3 -1
  98. package/esm/mark/utils/glyph.js.map +1 -1
  99. package/esm/series/sankey/sankey.js +25 -21
  100. package/esm/series/sankey/sankey.js.map +1 -1
  101. package/esm/util/graphic-state.d.ts +3 -0
  102. package/esm/util/graphic-state.js +17 -0
  103. package/esm/util/graphic-state.js.map +1 -0
  104. package/package.json +8 -7
@@ -1,3 +1,5 @@
1
+ import { addGraphicState, removeGraphicState } from "../util/graphic-state";
2
+
1
3
  export class Interaction {
2
4
  constructor() {
3
5
  this._stateGraphicsByTrigger = new Map, this._disableTriggerEvent = !1, this._triggerMapByState = new Map;
@@ -32,13 +34,13 @@ export class Interaction {
32
34
  var _a;
33
35
  if (reverseState && markIdByState[reverseState] && markIdByState[reverseState].includes(g.context.markId)) {
34
36
  const m = null === (_a = g.parent) || void 0 === _a ? void 0 : _a.mark, hasAnimation = m.hasAnimationByState && m.hasAnimationByState("state");
35
- g.addState(reverseState, !0, hasAnimation);
37
+ addGraphicState(g, reverseState, !0, hasAnimation);
36
38
  }
37
39
  })), newStatedGraphics.forEach((g => {
38
40
  var _a;
39
41
  if (reverseState && markIdByState[reverseState] && markIdByState[reverseState].includes(g.context.markId)) {
40
42
  const m = null === (_a = g.parent) || void 0 === _a ? void 0 : _a.mark, hasAnimation = m.hasAnimationByState && m.hasAnimationByState("state");
41
- g.removeState(reverseState, hasAnimation);
43
+ removeGraphicState(g, reverseState, hasAnimation);
42
44
  }
43
45
  }));
44
46
  }
@@ -48,13 +50,13 @@ export class Interaction {
48
50
  var _a;
49
51
  if (state && markIdByState[state] && markIdByState[state].includes(g.context.markId)) {
50
52
  const m = null === (_a = g.parent) || void 0 === _a ? void 0 : _a.mark, hasAnimation = m.hasAnimationByState && m.hasAnimationByState("state");
51
- g.removeState(state, hasAnimation);
53
+ removeGraphicState(g, state, hasAnimation);
52
54
  }
53
55
  })), newStatedGraphics.forEach((g => {
54
56
  var _a;
55
57
  if (state && markIdByState[state] && markIdByState[state].includes(g.context.markId)) {
56
58
  const m = null === (_a = g.parent) || void 0 === _a ? void 0 : _a.mark, hasAnimation = m.hasAnimationByState && m.hasAnimationByState("state");
57
- g.addState(state, !0, hasAnimation);
59
+ addGraphicState(g, state, !0, hasAnimation);
58
60
  }
59
61
  }));
60
62
  }
@@ -66,7 +68,7 @@ export class Interaction {
66
68
  if (!hasReverse && !hasState) return;
67
69
  const hasAnimation = m.hasAnimationByState && m.hasAnimationByState("state");
68
70
  null === (_a = m.getGraphics()) || void 0 === _a || _a.forEach((g => {
69
- statedGraphics && statedGraphics.includes(g) ? hasState && g.addState(state, !0, hasAnimation) : hasReverse && g.addState(reverseState, !0, hasAnimation);
71
+ statedGraphics && statedGraphics.includes(g) ? hasState && addGraphicState(g, state, !0, hasAnimation) : hasReverse && addGraphicState(g, reverseState, !0, hasAnimation);
70
72
  }));
71
73
  }));
72
74
  }
@@ -78,7 +80,7 @@ export class Interaction {
78
80
  if (!hasState) return;
79
81
  const hasAnimation = mark.hasAnimationByState && mark.hasAnimationByState("state");
80
82
  null === (_a = mark.getGraphics()) || void 0 === _a || _a.forEach((g => {
81
- statedGraphics && statedGraphics.includes(g) && hasState && g.addState(state, !0, hasAnimation);
83
+ statedGraphics && statedGraphics.includes(g) && hasState && addGraphicState(g, state, !0, hasAnimation);
82
84
  }));
83
85
  }));
84
86
  }
@@ -91,9 +93,9 @@ export class Interaction {
91
93
  if (mark) {
92
94
  const graphics = mark.getGraphics(), hasAnimation = mark.hasAnimationByState && mark.hasAnimationByState("state");
93
95
  graphics && graphics.length && (reverseState && markIdByState[reverseState] && markIdByState[reverseState].includes(mark.id) && graphics.forEach((g => {
94
- g.removeState(reverseState, hasAnimation);
96
+ removeGraphicState(g, reverseState, hasAnimation);
95
97
  })), state && markIdByState[state] && markIdByState[state].includes(mark.id) && graphics.forEach((g => {
96
- statedGraphics.includes(g) && g.removeState(state, hasAnimation);
98
+ statedGraphics.includes(g) && removeGraphicState(g, state, hasAnimation);
97
99
  })));
98
100
  }
99
101
  }));
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/interaction/interaction.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,WAAW;IAAxB;QACU,4BAAuB,GAAkC,IAAI,GAAG,EAAE,CAAC;QAEnE,yBAAoB,GAAY,KAAK,CAAC;QAMtC,uBAAkB,GAAgC,IAAI,GAAG,EAAE,CAAC;IA0QtE,CAAC;IA9QC,sBAAsB,CAAC,OAAgB;QACrC,IAAI,CAAC,oBAAoB,GAAG,OAAO,CAAC;IACtC,CAAC;IAGD,UAAU,CAAC,OAAiB;QAC1B,IAAI,OAAO,EAAE;YACX,MAAM,UAAU,GAAG,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AC,EAAE,CAAC,CAAC;oBAC3C,CAAC,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;gBAEH,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC;gBAEzG,IAAI,CAAC,iBAAiB,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC;YAC/C,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF","file":"interaction.js","sourcesContent":["import type { StateValue } from '../compile/mark';\nimport type { IMarkGraphic } from '../mark/interface';\nimport type { IInteraction } from './interface/common';\nimport type { ITrigger } from './interface/trigger';\n\nexport class Interaction implements IInteraction {\n private _stateGraphicsByTrigger: Map<ITrigger, IMarkGraphic[]> = new Map();\n\n private _disableTriggerEvent: boolean = false;\n\n setDisableActiveEffect(disable: boolean) {\n this._disableTriggerEvent = disable;\n }\n\n private _triggerMapByState: Map<StateValue, ITrigger[]> = new Map();\n addTrigger(trigger: ITrigger) {\n if (trigger) {\n const startState = trigger.getStartState();\n const resetState = trigger.getResetState();\n\n [startState, resetState].forEach(state => {\n if (state) {\n const stateTrigger = this._triggerMapByState.get(state);\n\n if (stateTrigger) {\n !stateTrigger.includes(trigger) && stateTrigger.push(trigger);\n } else {\n this._triggerMapByState.set(state, [trigger]);\n }\n }\n });\n }\n }\n\n setStatedGraphics(trigger: ITrigger, graphics: IMarkGraphic[]) {\n this._stateGraphicsByTrigger.set(trigger, graphics);\n }\n\n getStatedGraphics(trigger: ITrigger) {\n return this._stateGraphicsByTrigger.get(trigger);\n }\n\n updateStates(\n trigger: ITrigger,\n newStatedGraphics: IMarkGraphic[],\n prevStatedGraphics?: IMarkGraphic[],\n state?: string,\n reverseState?: string\n ) {\n if (this._disableTriggerEvent) {\n return [];\n }\n\n if (!newStatedGraphics || !newStatedGraphics.length) {\n return [];\n }\n if (state && reverseState) {\n if (prevStatedGraphics && prevStatedGraphics.length) {\n // toggle\n this.toggleReverseStateOfGraphics(trigger, newStatedGraphics, prevStatedGraphics, reverseState);\n this.toggleStateOfGraphics(trigger, newStatedGraphics, prevStatedGraphics, state);\n } else {\n // update all the elements\n this.addBothStateOfGraphics(trigger, newStatedGraphics, state, reverseState);\n }\n } else if (state) {\n if (prevStatedGraphics && prevStatedGraphics.length) {\n this.toggleStateOfGraphics(trigger, newStatedGraphics, prevStatedGraphics, state);\n } else {\n this.addStateOfGraphics(trigger, newStatedGraphics, state);\n }\n }\n\n return newStatedGraphics;\n }\n\n protected toggleReverseStateOfGraphics(\n trigger: ITrigger,\n newStatedGraphics: IMarkGraphic[],\n prevStatedGraphics: IMarkGraphic[],\n reverseState: string\n ) {\n const markIdByState = trigger.getMarkIdByState();\n\n prevStatedGraphics.forEach(g => {\n const hasReverse =\n reverseState && markIdByState[reverseState] && markIdByState[reverseState].includes(g.context.markId);\n\n if (hasReverse) {\n const m = g.parent?.mark;\n const hasAnimation = (m as any).hasAnimationByState && (m as any).hasAnimationByState('state');\n g.addState(reverseState, true, hasAnimation);\n }\n });\n\n newStatedGraphics.forEach(g => {\n const hasReverse =\n reverseState && markIdByState[reverseState] && markIdByState[reverseState].includes(g.context.markId);\n\n if (hasReverse) {\n const m = g.parent?.mark;\n const hasAnimation = (m as any).hasAnimationByState && (m as any).hasAnimationByState('state');\n g.removeState(reverseState, hasAnimation);\n }\n });\n }\n\n protected toggleStateOfGraphics(\n trigger: ITrigger,\n newStatedGraphics: IMarkGraphic[],\n prevStatedGraphics: IMarkGraphic[],\n state: string\n ) {\n const markIdByState = trigger.getMarkIdByState();\n\n prevStatedGraphics.forEach(g => {\n const hasState = state && markIdByState[state] && markIdByState[state].includes(g.context.markId);\n\n if (hasState) {\n const m = g.parent?.mark;\n const hasAnimation = (m as any).hasAnimationByState && (m as any).hasAnimationByState('state');\n g.removeState(state, hasAnimation);\n }\n });\n\n newStatedGraphics.forEach(g => {\n const hasState = state && markIdByState[state] && markIdByState[state].includes(g.context.markId);\n if (hasState) {\n const m = g.parent?.mark;\n const hasAnimation = (m as any).hasAnimationByState && (m as any).hasAnimationByState('state');\n g.addState(state, true, hasAnimation);\n }\n });\n }\n\n protected addBothStateOfGraphics(\n trigger: ITrigger,\n statedGraphics: IMarkGraphic[],\n state: string,\n reverseState: string\n ) {\n const marks = trigger.getMarks();\n const markIdByState = trigger.getMarkIdByState();\n\n marks.forEach(m => {\n const hasReverse = reverseState && markIdByState[reverseState] && markIdByState[reverseState].includes(m.id);\n const hasState = state && markIdByState[state] && markIdByState[state].includes(m.id);\n\n if (!hasReverse && !hasState) {\n return;\n }\n\n const hasAnimation = (m as any).hasAnimationByState && (m as any).hasAnimationByState('state');\n m.getGraphics()?.forEach(g => {\n const isStated = statedGraphics && statedGraphics.includes(g);\n if (isStated) {\n if (hasState) {\n g.addState(state, true, hasAnimation);\n }\n } else {\n if (hasReverse) {\n g.addState(reverseState, true, hasAnimation);\n }\n }\n });\n });\n }\n\n protected addStateOfGraphics(trigger: ITrigger, statedGraphics: IMarkGraphic[], state: string) {\n const marks = trigger.getMarks();\n const markIdByState = trigger.getMarkIdByState();\n\n marks.forEach(mark => {\n const hasState = state && markIdByState[state] && markIdByState[state].includes(mark.id);\n\n if (!hasState) {\n return;\n }\n\n const hasAnimation = (mark as any).hasAnimationByState && (mark as any).hasAnimationByState('state');\n\n mark.getGraphics()?.forEach(g => {\n const isStated = statedGraphics && statedGraphics.includes(g);\n\n if (isStated) {\n if (hasState) {\n g.addState(state, true, hasAnimation);\n }\n }\n });\n });\n }\n\n clearAllStatesOfTrigger(trigger: ITrigger, state?: string, reverseState?: string) {\n if (this._disableTriggerEvent) {\n return;\n }\n\n const statedGraphics = this.getStatedGraphics(trigger);\n\n if (!statedGraphics || !statedGraphics.length) {\n return;\n }\n const marks = trigger.getMarks();\n const markIdByState = trigger.getMarkIdByState();\n\n marks.forEach(mark => {\n if (mark) {\n const graphics = mark.getGraphics();\n const hasAnimation = (mark as any).hasAnimationByState && (mark as any).hasAnimationByState('state');\n if (graphics && graphics.length) {\n if (reverseState && markIdByState[reverseState] && markIdByState[reverseState].includes(mark.id)) {\n graphics.forEach(g => {\n g.removeState(reverseState, hasAnimation);\n });\n }\n\n if (state && markIdByState[state] && markIdByState[state].includes(mark.id)) {\n graphics.forEach(g => {\n if (statedGraphics.includes(g)) {\n g.removeState(state, hasAnimation);\n }\n });\n }\n }\n }\n });\n }\n\n clearAllStates() {\n if (this._disableTriggerEvent) {\n return;\n }\n\n this._triggerMapByState.forEach((triggers, state) => {\n triggers.forEach(trigger => {\n this.clearAllStatesOfTrigger(trigger, state, trigger.getResetState());\n });\n });\n }\n\n clearByState(stateValue: string) {\n if (this._disableTriggerEvent) {\n return;\n }\n\n const triggers = this._triggerMapByState.get(stateValue);\n\n if (triggers && triggers.length) {\n triggers.forEach(t => {\n this.clearAllStatesOfTrigger(t, stateValue, t.getResetState());\n\n // 更新缓存\n this.setStatedGraphics(t, []);\n });\n }\n }\n\n updateStateOfGraphics(stateValue: string, markGraphics: IMarkGraphic[]) {\n if (this._disableTriggerEvent) {\n return;\n }\n const triggers = this._triggerMapByState.get(stateValue);\n\n if (triggers && triggers.length) {\n triggers.forEach(t => {\n const newStatedGraphics = markGraphics.filter(mg => {\n return t.getMarks().some(m => {\n const graphics = m && m.getGraphics();\n\n return graphics && graphics.includes(mg);\n });\n });\n\n this.updateStates(t, newStatedGraphics, this.getStatedGraphics(t), t.getStartState(), t.getResetState());\n\n this.setStatedGraphics(t, newStatedGraphics);\n });\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/interaction/interaction.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE5E,MAAM,OAAO,WAAW;IAAxB;QACU,4BAAuB,GAAkC,IAAI,GAAG,EAAE,CAAC;QAEnE,yBAAoB,GAAY,KAAK,CAAC;QAMtC,uBAAkB,GAA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AAC,EAAE;oBACjD,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;wBAC3B,MAAM,QAAQ,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;wBAEtC,OAAO,QAAQ,IAAI,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;oBAC3C,CAAC,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;gBAEH,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC;gBAEzG,IAAI,CAAC,iBAAiB,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC;YAC/C,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF","file":"interaction.js","sourcesContent":["import type { StateValue } from '../compile/mark';\nimport type { IMarkGraphic } from '../mark/interface';\nimport type { IInteraction } from './interface/common';\nimport type { ITrigger } from './interface/trigger';\nimport { addGraphicState, removeGraphicState } from '../util/graphic-state';\n\nexport class Interaction implements IInteraction {\n private _stateGraphicsByTrigger: Map<ITrigger, IMarkGraphic[]> = new Map();\n\n private _disableTriggerEvent: boolean = false;\n\n setDisableActiveEffect(disable: boolean) {\n this._disableTriggerEvent = disable;\n }\n\n private _triggerMapByState: Map<StateValue, ITrigger[]> = new Map();\n addTrigger(trigger: ITrigger) {\n if (trigger) {\n const startState = trigger.getStartState();\n const resetState = trigger.getResetState();\n\n [startState, resetState].forEach(state => {\n if (state) {\n const stateTrigger = this._triggerMapByState.get(state);\n\n if (stateTrigger) {\n !stateTrigger.includes(trigger) && stateTrigger.push(trigger);\n } else {\n this._triggerMapByState.set(state, [trigger]);\n }\n }\n });\n }\n }\n\n setStatedGraphics(trigger: ITrigger, graphics: IMarkGraphic[]) {\n this._stateGraphicsByTrigger.set(trigger, graphics);\n }\n\n getStatedGraphics(trigger: ITrigger) {\n return this._stateGraphicsByTrigger.get(trigger);\n }\n\n updateStates(\n trigger: ITrigger,\n newStatedGraphics: IMarkGraphic[],\n prevStatedGraphics?: IMarkGraphic[],\n state?: string,\n reverseState?: string\n ) {\n if (this._disableTriggerEvent) {\n return [];\n }\n\n if (!newStatedGraphics || !newStatedGraphics.length) {\n return [];\n }\n if (state && reverseState) {\n if (prevStatedGraphics && prevStatedGraphics.length) {\n // toggle\n this.toggleReverseStateOfGraphics(trigger, newStatedGraphics, prevStatedGraphics, reverseState);\n this.toggleStateOfGraphics(trigger, newStatedGraphics, prevStatedGraphics, state);\n } else {\n // update all the elements\n this.addBothStateOfGraphics(trigger, newStatedGraphics, state, reverseState);\n }\n } else if (state) {\n if (prevStatedGraphics && prevStatedGraphics.length) {\n this.toggleStateOfGraphics(trigger, newStatedGraphics, prevStatedGraphics, state);\n } else {\n this.addStateOfGraphics(trigger, newStatedGraphics, state);\n }\n }\n\n return newStatedGraphics;\n }\n\n protected toggleReverseStateOfGraphics(\n trigger: ITrigger,\n newStatedGraphics: IMarkGraphic[],\n prevStatedGraphics: IMarkGraphic[],\n reverseState: string\n ) {\n const markIdByState = trigger.getMarkIdByState();\n\n prevStatedGraphics.forEach(g => {\n const hasReverse =\n reverseState && markIdByState[reverseState] && markIdByState[reverseState].includes(g.context.markId);\n\n if (hasReverse) {\n const m = g.parent?.mark;\n const hasAnimation = (m as any).hasAnimationByState && (m as any).hasAnimationByState('state');\n addGraphicState(g, reverseState, true, hasAnimation);\n }\n });\n\n newStatedGraphics.forEach(g => {\n const hasReverse =\n reverseState && markIdByState[reverseState] && markIdByState[reverseState].includes(g.context.markId);\n\n if (hasReverse) {\n const m = g.parent?.mark;\n const hasAnimation = (m as any).hasAnimationByState && (m as any).hasAnimationByState('state');\n removeGraphicState(g, reverseState, hasAnimation);\n }\n });\n }\n\n protected toggleStateOfGraphics(\n trigger: ITrigger,\n newStatedGraphics: IMarkGraphic[],\n prevStatedGraphics: IMarkGraphic[],\n state: string\n ) {\n const markIdByState = trigger.getMarkIdByState();\n\n prevStatedGraphics.forEach(g => {\n const hasState = state && markIdByState[state] && markIdByState[state].includes(g.context.markId);\n\n if (hasState) {\n const m = g.parent?.mark;\n const hasAnimation = (m as any).hasAnimationByState && (m as any).hasAnimationByState('state');\n removeGraphicState(g, state, hasAnimation);\n }\n });\n\n newStatedGraphics.forEach(g => {\n const hasState = state && markIdByState[state] && markIdByState[state].includes(g.context.markId);\n if (hasState) {\n const m = g.parent?.mark;\n const hasAnimation = (m as any).hasAnimationByState && (m as any).hasAnimationByState('state');\n addGraphicState(g, state, true, hasAnimation);\n }\n });\n }\n\n protected addBothStateOfGraphics(\n trigger: ITrigger,\n statedGraphics: IMarkGraphic[],\n state: string,\n reverseState: string\n ) {\n const marks = trigger.getMarks();\n const markIdByState = trigger.getMarkIdByState();\n\n marks.forEach(m => {\n const hasReverse = reverseState && markIdByState[reverseState] && markIdByState[reverseState].includes(m.id);\n const hasState = state && markIdByState[state] && markIdByState[state].includes(m.id);\n\n if (!hasReverse && !hasState) {\n return;\n }\n\n const hasAnimation = (m as any).hasAnimationByState && (m as any).hasAnimationByState('state');\n m.getGraphics()?.forEach(g => {\n const isStated = statedGraphics && statedGraphics.includes(g);\n if (isStated) {\n if (hasState) {\n addGraphicState(g, state, true, hasAnimation);\n }\n } else {\n if (hasReverse) {\n addGraphicState(g, reverseState, true, hasAnimation);\n }\n }\n });\n });\n }\n\n protected addStateOfGraphics(trigger: ITrigger, statedGraphics: IMarkGraphic[], state: string) {\n const marks = trigger.getMarks();\n const markIdByState = trigger.getMarkIdByState();\n\n marks.forEach(mark => {\n const hasState = state && markIdByState[state] && markIdByState[state].includes(mark.id);\n\n if (!hasState) {\n return;\n }\n\n const hasAnimation = (mark as any).hasAnimationByState && (mark as any).hasAnimationByState('state');\n\n mark.getGraphics()?.forEach(g => {\n const isStated = statedGraphics && statedGraphics.includes(g);\n\n if (isStated) {\n if (hasState) {\n addGraphicState(g, state, true, hasAnimation);\n }\n }\n });\n });\n }\n\n clearAllStatesOfTrigger(trigger: ITrigger, state?: string, reverseState?: string) {\n if (this._disableTriggerEvent) {\n return;\n }\n\n const statedGraphics = this.getStatedGraphics(trigger);\n\n if (!statedGraphics || !statedGraphics.length) {\n return;\n }\n const marks = trigger.getMarks();\n const markIdByState = trigger.getMarkIdByState();\n\n marks.forEach(mark => {\n if (mark) {\n const graphics = mark.getGraphics();\n const hasAnimation = (mark as any).hasAnimationByState && (mark as any).hasAnimationByState('state');\n if (graphics && graphics.length) {\n if (reverseState && markIdByState[reverseState] && markIdByState[reverseState].includes(mark.id)) {\n graphics.forEach(g => {\n removeGraphicState(g, reverseState, hasAnimation);\n });\n }\n\n if (state && markIdByState[state] && markIdByState[state].includes(mark.id)) {\n graphics.forEach(g => {\n if (statedGraphics.includes(g)) {\n removeGraphicState(g, state, hasAnimation);\n }\n });\n }\n }\n }\n });\n }\n\n clearAllStates() {\n if (this._disableTriggerEvent) {\n return;\n }\n\n this._triggerMapByState.forEach((triggers, state) => {\n triggers.forEach(trigger => {\n this.clearAllStatesOfTrigger(trigger, state, trigger.getResetState());\n });\n });\n }\n\n clearByState(stateValue: string) {\n if (this._disableTriggerEvent) {\n return;\n }\n\n const triggers = this._triggerMapByState.get(stateValue);\n\n if (triggers && triggers.length) {\n triggers.forEach(t => {\n this.clearAllStatesOfTrigger(t, stateValue, t.getResetState());\n\n // 更新缓存\n this.setStatedGraphics(t, []);\n });\n }\n }\n\n updateStateOfGraphics(stateValue: string, markGraphics: IMarkGraphic[]) {\n if (this._disableTriggerEvent) {\n return;\n }\n const triggers = this._triggerMapByState.get(stateValue);\n\n if (triggers && triggers.length) {\n triggers.forEach(t => {\n const newStatedGraphics = markGraphics.filter(mg => {\n return t.getMarks().some(m => {\n const graphics = m && m.getGraphics();\n\n return graphics && graphics.includes(mg);\n });\n });\n\n this.updateStates(t, newStatedGraphics, this.getStatedGraphics(t), t.getStartState(), t.getResetState());\n\n this.setStatedGraphics(t, newStatedGraphics);\n });\n }\n }\n}\n"]}
@@ -10,6 +10,8 @@ import { generateFilterValue } from "./util";
10
10
 
11
11
  import { STATE_VALUE_ENUM } from "../../compile/mark/interface";
12
12
 
13
+ import { removeGraphicState } from "../../util/graphic-state";
14
+
13
15
  const type = "element-active-by-legend", defaultOptions = {
14
16
  state: STATE_VALUE_ENUM.STATE_ACTIVE,
15
17
  filterType: "groupKey"
@@ -55,7 +57,7 @@ export class ElementActiveByLegend extends BaseTrigger {
55
57
  const {state: state, interaction: interaction} = this.options;
56
58
  if (g) {
57
59
  const statedGraphics = interaction.getStatedGraphics(this);
58
- statedGraphics && statedGraphics.includes(g) && (g.removeState(state), interaction.setStatedGraphics(this, statedGraphics.filter((sg => sg !== g))));
60
+ statedGraphics && statedGraphics.includes(g) && (removeGraphicState(g, state), interaction.setStatedGraphics(this, statedGraphics.filter((sg => sg !== g))));
59
61
  } else this.resetAll();
60
62
  }
61
63
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/interaction/triggers/element-active-by-legend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAG7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,MAAM,IAAI,GAAG,0BAA0B,CAAC;AACxC,MAAM,cAAc,GAA2C;IAC7D,KAAK,EAAE,gBAAgB,CAAC,YAAY;IACpC,UAAU,EAAE,UAAU;CACvB,CAAC;AAEF,MAAM,OAAO,qBACX,SAAQ,WAA0C;IAQlD,YAAY,OAAuC;QACjD,KAAK,CAAC,OAAO,CAAC,CAAC;QALjB,SAAI,GAAW,I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AM,6BAA6B,GAAG,GAAG,EAAE;IAChD,OAAO,CAAC,0BAA0B,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;AAClE,CAAC,CAAC","file":"element-active-by-legend.js","sourcesContent":["import { Factory } from '../../core/factory';\nimport { BaseTrigger } from './base';\nimport type { IElementActiveByLegendOptions, ITrigger, ITriggerEventHandler } from '../interface/trigger';\nimport { ChartEvent } from '../../constant/event';\nimport { isNil } from '@visactor/vutils';\nimport { generateFilterValue } from './util';\nimport type { IMarkGraphic } from '../../mark/interface';\nimport type { BaseEventParams } from '../../core';\nimport { STATE_VALUE_ENUM } from '../../compile/mark/interface';\n\nconst type = 'element-active-by-legend';\nconst defaultOptions: Partial<IElementActiveByLegendOptions> = {\n state: STATE_VALUE_ENUM.STATE_ACTIVE,\n filterType: 'groupKey'\n};\n\nexport class ElementActiveByLegend\n extends BaseTrigger<IElementActiveByLegendOptions>\n implements ITrigger<IElementActiveByLegendOptions>\n{\n static type: string = type;\n type: string = type;\n\n static defaultOptions = defaultOptions;\n\n constructor(options?: IElementActiveByLegendOptions) {\n super(options);\n this.options = Object.assign({}, defaultOptions, options);\n\n this.updateMarkIdByState([this.options.state]);\n }\n protected getEvents(): Array<{ type: string | string[]; handler: ITriggerEventHandler }> {\n return [\n {\n type: ChartEvent.legendItemHover,\n handler: this.handleStart\n },\n {\n type: ChartEvent.legendItemUnHover,\n handler: this.handleReset\n }\n ];\n }\n\n getStartState(): string {\n return this.options.state;\n }\n start(itemKey: string) {\n if (isNil(itemKey)) {\n return;\n }\n const { interaction, state } = this.options;\n const filterValue = generateFilterValue(this.options);\n const statedGraphics = interaction.getStatedGraphics(this);\n const newStatedGraphics: IMarkGraphic[] = [];\n\n this.getMarks().forEach(m => {\n m.getGraphics()?.forEach(g => {\n if (filterValue(g) === itemKey) {\n newStatedGraphics.push(g);\n }\n });\n });\n\n interaction.updateStates(this, newStatedGraphics, statedGraphics, state);\n interaction.setStatedGraphics(this, newStatedGraphics);\n }\n\n resetAll() {\n const { interaction, state } = this.options;\n\n interaction.clearAllStatesOfTrigger(this, state);\n\n interaction.setStatedGraphics(this, []);\n }\n\n reset(g?: IMarkGraphic) {\n const { state, interaction } = this.options;\n\n if (g) {\n const statedGraphics = interaction.getStatedGraphics(this);\n if (statedGraphics && statedGraphics.includes(g)) {\n g.removeState(state);\n interaction.setStatedGraphics(\n this,\n statedGraphics.filter(sg => sg !== g)\n );\n }\n } else {\n this.resetAll();\n }\n }\n\n handleStart = (e: BaseEventParams) => {\n const event = e.event;\n\n if (event) {\n this.start(event.detail?.data?.id);\n }\n };\n\n handleReset = (e: BaseEventParams) => {\n this.resetAll();\n };\n}\n\nexport const registerElementActiveByLegend = () => {\n Factory.registerInteractionTrigger(type, ElementActiveByLegend);\n};\n"]}
1
+ {"version":3,"sources":["../src/interaction/triggers/element-active-by-legend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAG7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,MAAM,IAAI,GAAG,0BAA0B,CAAC;AACxC,MAAM,cAAc,GAA2C;IAC7D,KAAK,EAAE,gBAAgB,CAAC,YAAY;IACpC,UAAU,EAAE,UAAU;CACvB,CAAC;AAEF,MAAM,OAAO,qBACX,SAAQ,WAA0C;IAQlD,YAAY,OAAuC;QACjD,KAAK,CAAC,OAAO,CAAC,CAAC;QALjB,SAAI,GAAW,IAAI,CAAC;QAwEpB,gBAAW,GAAG,CAAC,CAAkB,EAAE,EAAE;;YACnC,MAAM,KAA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AE,qBAAqB,CAAC,CAAC;AAClE,CAAC,CAAC","file":"element-active-by-legend.js","sourcesContent":["import { Factory } from '../../core/factory';\nimport { BaseTrigger } from './base';\nimport type { IElementActiveByLegendOptions, ITrigger, ITriggerEventHandler } from '../interface/trigger';\nimport { ChartEvent } from '../../constant/event';\nimport { isNil } from '@visactor/vutils';\nimport { generateFilterValue } from './util';\nimport type { IMarkGraphic } from '../../mark/interface';\nimport type { BaseEventParams } from '../../core';\nimport { STATE_VALUE_ENUM } from '../../compile/mark/interface';\nimport { removeGraphicState } from '../../util/graphic-state';\n\nconst type = 'element-active-by-legend';\nconst defaultOptions: Partial<IElementActiveByLegendOptions> = {\n state: STATE_VALUE_ENUM.STATE_ACTIVE,\n filterType: 'groupKey'\n};\n\nexport class ElementActiveByLegend\n extends BaseTrigger<IElementActiveByLegendOptions>\n implements ITrigger<IElementActiveByLegendOptions>\n{\n static type: string = type;\n type: string = type;\n\n static defaultOptions = defaultOptions;\n\n constructor(options?: IElementActiveByLegendOptions) {\n super(options);\n this.options = Object.assign({}, defaultOptions, options);\n\n this.updateMarkIdByState([this.options.state]);\n }\n protected getEvents(): Array<{ type: string | string[]; handler: ITriggerEventHandler }> {\n return [\n {\n type: ChartEvent.legendItemHover,\n handler: this.handleStart\n },\n {\n type: ChartEvent.legendItemUnHover,\n handler: this.handleReset\n }\n ];\n }\n\n getStartState(): string {\n return this.options.state;\n }\n start(itemKey: string) {\n if (isNil(itemKey)) {\n return;\n }\n const { interaction, state } = this.options;\n const filterValue = generateFilterValue(this.options);\n const statedGraphics = interaction.getStatedGraphics(this);\n const newStatedGraphics: IMarkGraphic[] = [];\n\n this.getMarks().forEach(m => {\n m.getGraphics()?.forEach(g => {\n if (filterValue(g) === itemKey) {\n newStatedGraphics.push(g);\n }\n });\n });\n\n interaction.updateStates(this, newStatedGraphics, statedGraphics, state);\n interaction.setStatedGraphics(this, newStatedGraphics);\n }\n\n resetAll() {\n const { interaction, state } = this.options;\n\n interaction.clearAllStatesOfTrigger(this, state);\n\n interaction.setStatedGraphics(this, []);\n }\n\n reset(g?: IMarkGraphic) {\n const { state, interaction } = this.options;\n\n if (g) {\n const statedGraphics = interaction.getStatedGraphics(this);\n if (statedGraphics && statedGraphics.includes(g)) {\n removeGraphicState(g, state);\n interaction.setStatedGraphics(\n this,\n statedGraphics.filter(sg => sg !== g)\n );\n }\n } else {\n this.resetAll();\n }\n }\n\n handleStart = (e: BaseEventParams) => {\n const event = e.event;\n\n if (event) {\n this.start(event.detail?.data?.id);\n }\n };\n\n handleReset = (e: BaseEventParams) => {\n this.resetAll();\n };\n}\n\nexport const registerElementActiveByLegend = () => {\n Factory.registerInteractionTrigger(type, ElementActiveByLegend);\n};\n"]}
@@ -4,6 +4,8 @@ import { BaseTrigger } from "./base";
4
4
 
5
5
  import { STATE_VALUE_ENUM } from "../../compile/mark/interface";
6
6
 
7
+ import { addGraphicState, removeGraphicState } from "../../util/graphic-state";
8
+
7
9
  const defaultOptions = {
8
10
  state: STATE_VALUE_ENUM.STATE_ACTIVE,
9
11
  trigger: "pointerover",
@@ -33,12 +35,12 @@ export class ElementActive extends BaseTrigger {
33
35
  start(g) {
34
36
  if (g) {
35
37
  const {state: state, interaction: interaction} = this.options;
36
- this.isGraphicInStateMark(g, state) && (g.addState(state, !0), interaction.setStatedGraphics(this, [ g ]));
38
+ this.isGraphicInStateMark(g, state) && (addGraphicState(g, state, !0), interaction.setStatedGraphics(this, [ g ]));
37
39
  }
38
40
  }
39
41
  reset(graphic) {
40
42
  const {interaction: interaction, state: state} = this.options, statedGraphics = interaction.getStatedGraphics(this), g = null != graphic ? graphic : null == statedGraphics ? void 0 : statedGraphics[0];
41
- g && (null == statedGraphics ? void 0 : statedGraphics.includes(g)) && (g.removeState(state),
43
+ g && (null == statedGraphics ? void 0 : statedGraphics.includes(g)) && (removeGraphicState(g, state),
42
44
  interaction.setStatedGraphics(this, statedGraphics.filter((sg => sg !== g))));
43
45
  }
44
46
  }
@@ -1 +1 @@
1
- {"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AI,CAAC,EAAE;YACL,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;YAE5C,IAAI,IAAI,CAAC,oBAAoB,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE;gBACvC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;gBAExB,WAAW,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;aAC1C;SACF;IACH,CAAC;IAED,KAAK,CAAC,OAAsB;QAC1B,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAE5C,MAAM,cAAc,GAAG,WAAW,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAC3D,MAAM,CAAC,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,CAAC,CAAC,CAAC;QAEzC,IAAI,CAAC,KAAI,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,QAAQ,CAAC,CAAC,CAAC,CAAA,EAAE;YACpC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YACrB,WAAW,CAAC,iBAAiB,CAC3B,IAAI,EACJ,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,CACtC,CAAC;SACH;IACH,CAAC;;AAlDM,kBAAI,oBAA4C;AAGhD,4BAAc,GAAG,cAAc,CAAC;AA0DzC,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,EAAE;IACxC,OAAO,CAAC,0BAA0B,CAAC,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;AACxE,CAAC,CAAC","file":"element-active.js","sourcesContent":["import { Factory } from '../../core/factory';\nimport { BaseTrigger } from './base';\nimport type { IElementActiveOptions, ITrigger, ITriggerEventHandler } from '../interface/trigger';\nimport { TRIGGER_TYPE_ENUM } from './enum';\nimport { STATE_VALUE_ENUM } from '../../compile/mark/interface';\nimport type { IMarkGraphic } from '../../mark/interface';\nimport type { BaseEventParams } from '../../event/interface';\n\nconst defaultOptions: Partial<IElementActiveOptions> = {\n state: STATE_VALUE_ENUM.STATE_ACTIVE,\n trigger: 'pointerover',\n triggerOff: 'pointerout'\n};\n\nexport class ElementActive extends BaseTrigger<IElementActiveOptions> implements ITrigger<IElementActiveOptions> {\n static type: string = TRIGGER_TYPE_ENUM.ELEMENT_ACTIVE;\n type: string = TRIGGER_TYPE_ENUM.ELEMENT_ACTIVE;\n\n static defaultOptions = defaultOptions;\n\n constructor(options?: IElementActiveOptions) {\n super(options);\n this.options = Object.assign({}, defaultOptions, options);\n\n this.updateMarkIdByState([this.options.state]);\n }\n protected getEvents(): Array<{ type: string | string[]; handler: ITriggerEventHandler }> {\n return [\n {\n type: this.options.trigger,\n handler: this.handleStart\n },\n { type: this.options.triggerOff, handler: this.handleReset }\n ];\n }\n\n getStartState(): string {\n return this.options.state;\n }\n\n start(g: IMarkGraphic) {\n if (g) {\n const { state, interaction } = this.options;\n\n if (this.isGraphicInStateMark(g, state)) {\n g.addState(state, true);\n\n interaction.setStatedGraphics(this, [g]);\n }\n }\n }\n\n reset(graphic?: IMarkGraphic) {\n const { interaction, state } = this.options;\n\n const statedGraphics = interaction.getStatedGraphics(this);\n const g = graphic ?? statedGraphics?.[0];\n\n if (g && statedGraphics?.includes(g)) {\n g.removeState(state);\n interaction.setStatedGraphics(\n this,\n statedGraphics.filter(sg => sg !== g)\n );\n }\n }\n\n handleStart = (e: BaseEventParams) => {\n this.start(e.item);\n };\n\n handleReset = (e: BaseEventParams) => {\n this.reset(e.item);\n };\n}\n\nexport const registerElementActive = () => {\n Factory.registerInteractionTrigger(ElementActive.type, ElementActive);\n};\n"]}
1
+ {"version":3,"sources":["../src/interaction/triggers/element-active.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7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K,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;YAE5C,IAAI,IAAI,CAAC,oBAAoB,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE;gBACvC,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;gBAEhC,WAAW,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;aAC1C;SACF;IACH,CAAC;IAED,KAAK,CAAC,OAAsB;QAC1B,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAE5C,MAAM,cAAc,GAAG,WAAW,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAC3D,MAAM,CAAC,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,CAAC,CAAC,CAAC;QAEzC,IAAI,CAAC,KAAI,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,QAAQ,CAAC,CAAC,CAAC,CAAA,EAAE;YACpC,kBAAkB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YAC7B,WAAW,CAAC,iBAAiB,CAC3B,IAAI,EACJ,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,CACtC,CAAC;SACH;IACH,CAAC;;AAlDM,kBAAI,oBAA4C;AAGhD,4BAAc,GAAG,cAAc,CAAC;AA0DzC,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,EAAE;IACxC,OAAO,CAAC,0BAA0B,CAAC,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;AACxE,CAAC,CAAC","file":"element-active.js","sourcesContent":["import { Factory } from '../../core/factory';\nimport { BaseTrigger } from './base';\nimport type { IElementActiveOptions, ITrigger, ITriggerEventHandler } from '../interface/trigger';\nimport { TRIGGER_TYPE_ENUM } from './enum';\nimport { STATE_VALUE_ENUM } from '../../compile/mark/interface';\nimport type { IMarkGraphic } from '../../mark/interface';\nimport type { BaseEventParams } from '../../event/interface';\nimport { addGraphicState, removeGraphicState } from '../../util/graphic-state';\n\nconst defaultOptions: Partial<IElementActiveOptions> = {\n state: STATE_VALUE_ENUM.STATE_ACTIVE,\n trigger: 'pointerover',\n triggerOff: 'pointerout'\n};\n\nexport class ElementActive extends BaseTrigger<IElementActiveOptions> implements ITrigger<IElementActiveOptions> {\n static type: string = TRIGGER_TYPE_ENUM.ELEMENT_ACTIVE;\n type: string = TRIGGER_TYPE_ENUM.ELEMENT_ACTIVE;\n\n static defaultOptions = defaultOptions;\n\n constructor(options?: IElementActiveOptions) {\n super(options);\n this.options = Object.assign({}, defaultOptions, options);\n\n this.updateMarkIdByState([this.options.state]);\n }\n protected getEvents(): Array<{ type: string | string[]; handler: ITriggerEventHandler }> {\n return [\n {\n type: this.options.trigger,\n handler: this.handleStart\n },\n { type: this.options.triggerOff, handler: this.handleReset }\n ];\n }\n\n getStartState(): string {\n return this.options.state;\n }\n\n start(g: IMarkGraphic) {\n if (g) {\n const { state, interaction } = this.options;\n\n if (this.isGraphicInStateMark(g, state)) {\n addGraphicState(g, state, true);\n\n interaction.setStatedGraphics(this, [g]);\n }\n }\n }\n\n reset(graphic?: IMarkGraphic) {\n const { interaction, state } = this.options;\n\n const statedGraphics = interaction.getStatedGraphics(this);\n const g = graphic ?? statedGraphics?.[0];\n\n if (g && statedGraphics?.includes(g)) {\n removeGraphicState(g, state);\n interaction.setStatedGraphics(\n this,\n statedGraphics.filter(sg => sg !== g)\n );\n }\n }\n\n handleStart = (e: BaseEventParams) => {\n this.start(e.item);\n };\n\n handleReset = (e: BaseEventParams) => {\n this.reset(e.item);\n };\n}\n\nexport const registerElementActive = () => {\n Factory.registerInteractionTrigger(ElementActive.type, ElementActive);\n};\n"]}
@@ -6,6 +6,8 @@ import { isNil } from "@visactor/vutils";
6
6
 
7
7
  import { highlightDefaultOptions } from "./util";
8
8
 
9
+ import { removeGraphicState } from "../../util/graphic-state";
10
+
9
11
  const type = "element-highlight-by-group";
10
12
 
11
13
  export class ElementHighlightByGroup extends BaseTrigger {
@@ -58,7 +60,8 @@ export class ElementHighlightByGroup extends BaseTrigger {
58
60
  if (g) {
59
61
  if (this.isGraphicInMark(g)) {
60
62
  const {interaction: interaction} = this.options, statedGraphics = interaction.getStatedGraphics(this);
61
- g.removeState([ this.options.highlightState, this.options.blurState ]), interaction.setStatedGraphics(this, statedGraphics.filter((sg => sg !== g)));
63
+ removeGraphicState(g, [ this.options.highlightState, this.options.blurState ]),
64
+ interaction.setStatedGraphics(this, statedGraphics.filter((sg => sg !== g)));
62
65
  }
63
66
  } else this.resetAll();
64
67
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/interaction/triggers/element-highlight-by-group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAGrC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,QAAQ,CAAC;AAEjD,MAAM,IAAI,GAAG,4BAA4B,CAAC;AAE1C,MAAM,OAAO,uBACX,SAAQ,WAAqC;IAO7C,YAAY,OAAkC;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAC;QAJjB,SAAI,GAAW,IAAI,CAAC;QAmFpB,gBAAW,GAAG,CAAC,CAAkB,EAAE,EAAE;YACnC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC,CAAC;QAEF,gBAAW,GAAG,CAAC,CAAkB,EAAE,EAAE;YACnC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YACjB,MAAM,gBAAgB,GAAG,CAAC,IAAI,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YAEtD,IAAI,gBAAgB,EAAE;gBACpB,IAAI,CAAC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B;IACH,CAAC;;AAlFM,4BAAI,GAAW,IAAI,CAAC;AAGpB,sCAAc,GAAG,uBAAuB,CAAC;AA+FlD,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAAG,EAAE;IAClD,OAAO,CAAC,0BAA0B,CAAC,IAAI,EAAE,uBAAuB,CAAC,CAAC;AACpE,CAAC,CAAC","file":"element-highlight-by-group.js","sourcesContent":["import { Factory } from '../../core/factory';\nimport { BaseTrigger } from './base';\nimport type { IElementHighlightOptions, ITrigger, ITriggerEventHandler } from '../interface/trigger';\nimport type { IMarkGraphic } from '../../mark/interface';\nimport { isNil } from '@visactor/vutils';\nimport type { BaseEventParams } from '../../core';\nimport { highlightDefaultOptions } from './util';\n\nconst type = 'element-highlight-by-group';\n\nexport class ElementHighlightByGroup\n extends BaseTrigger<IElementHighlightOptions>\n implements ITrigger<IElementHighlightOptions>\n{\n static type: string = type;\n type: string = type;\n\n static defaultOptions = highlightDefaultOptions;\n constructor(options?: IElementHighlightOptions) {\n super(options);\n this.options = Object.assign({}, highlightDefaultOptions, options);\n\n this.updateMarkIdByState([this.options.highlightState, this.options.blurState]);\n }\n\n getStartState(): string {\n return this.options.highlightState;\n }\n\n getResetState(): string {\n return this.options.blurState;\n }\n\n protected getEvents(): Array<{ type: string | string[]; handler: ITriggerEventHandler }> {\n return [\n {\n type: this.options.trigger,\n handler: this.handleStart\n },\n { type: this.options.triggerOff, handler: this.handleReset }\n ];\n }\n\n resetAll() {\n const { interaction, highlightState, blurState } = this.options;\n\n interaction.clearAllStatesOfTrigger(this, highlightState, blurState);\n\n interaction.setStatedGraphics(this, []);\n }\n\n protected _getHightlightKey(g: IMarkGraphic) {\n return g.context?.groupKey;\n }\n\n start(g: IMarkGraphic) {\n if (g && this.isGraphicInMark(g)) {\n const highlightKey = this._getHightlightKey(g);\n\n if (isNil(highlightKey)) {\n return;\n }\n\n const { interaction, highlightState, blurState } = this.options;\n const statedGraphics = interaction.getStatedGraphics(this);\n const newStatedGraphics: IMarkGraphic[] = [];\n\n this.getMarks().forEach(m => {\n m.getGraphics()?.forEach(g => {\n if (this._getHightlightKey(g) === highlightKey) {\n newStatedGraphics.push(g);\n }\n });\n });\n\n interaction.updateStates(this, newStatedGraphics, statedGraphics, highlightState, blurState);\n interaction.setStatedGraphics(this, newStatedGraphics);\n }\n }\n\n reset(g?: IMarkGraphic) {\n if (g) {\n if (this.isGraphicInMark(g)) {\n const { interaction } = this.options;\n const statedGraphics = interaction.getStatedGraphics(this);\n\n g.removeState([this.options.highlightState, this.options.blurState]);\n\n interaction.setStatedGraphics(\n this,\n statedGraphics.filter(sg => sg !== g)\n );\n }\n } else {\n this.resetAll();\n }\n }\n\n handleStart = (e: BaseEventParams) => {\n this.start(e.item);\n };\n\n handleReset = (e: BaseEventParams) => {\n const g = e.item;\n const hasActiveElement = g && this.isGraphicInMark(g);\n\n if (hasActiveElement) {\n this.resetAll();\n }\n };\n}\n\nexport const registerElementHighlightByGroup = () => {\n Factory.registerInteractionTrigger(type, ElementHighlightByGroup);\n};\n"]}
1
+ {"version":3,"sources":["../src/interaction/triggers/element-highlight-by-group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAGrC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,MAAM,IAAI,GAAG,4BAA4B,CAAC;AAE1C,MAAM,OAAO,uBACX,SAAQ,WAAqC;IAO7C,YAAY,OAAkC;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAC;QAJjB,SAAI,GAAW,IAAI,CAAC;QAmFpB,gBAAW,GAAG,CAAC,CAAkB,EAAE,EAAE;YACnC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CA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c,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;gBAE7E,WAAW,CAAC,iBAAiB,CAC3B,IAAI,EACJ,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,CACtC,CAAC;aACH;SACF;aAAM;YACL,IAAI,CAAC,QAAQ,EAAE,CAAC;SACjB;IACH,CAAC;;AAlFM,4BAAI,GAAW,IAAI,CAAC;AAGpB,sCAAc,GAAG,uBAAuB,CAAC;AA+FlD,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAAG,EAAE;IAClD,OAAO,CAAC,0BAA0B,CAAC,IAAI,EAAE,uBAAuB,CAAC,CAAC;AACpE,CAAC,CAAC","file":"element-highlight-by-group.js","sourcesContent":["import { Factory } from '../../core/factory';\nimport { BaseTrigger } from './base';\nimport type { IElementHighlightOptions, ITrigger, ITriggerEventHandler } from '../interface/trigger';\nimport type { IMarkGraphic } from '../../mark/interface';\nimport { isNil } from '@visactor/vutils';\nimport type { BaseEventParams } from '../../core';\nimport { highlightDefaultOptions } from './util';\nimport { removeGraphicState } from '../../util/graphic-state';\n\nconst type = 'element-highlight-by-group';\n\nexport class ElementHighlightByGroup\n extends BaseTrigger<IElementHighlightOptions>\n implements ITrigger<IElementHighlightOptions>\n{\n static type: string = type;\n type: string = type;\n\n static defaultOptions = highlightDefaultOptions;\n constructor(options?: IElementHighlightOptions) {\n super(options);\n this.options = Object.assign({}, highlightDefaultOptions, options);\n\n this.updateMarkIdByState([this.options.highlightState, this.options.blurState]);\n }\n\n getStartState(): string {\n return this.options.highlightState;\n }\n\n getResetState(): string {\n return this.options.blurState;\n }\n\n protected getEvents(): Array<{ type: string | string[]; handler: ITriggerEventHandler }> {\n return [\n {\n type: this.options.trigger,\n handler: this.handleStart\n },\n { type: this.options.triggerOff, handler: this.handleReset }\n ];\n }\n\n resetAll() {\n const { interaction, highlightState, blurState } = this.options;\n\n interaction.clearAllStatesOfTrigger(this, highlightState, blurState);\n\n interaction.setStatedGraphics(this, []);\n }\n\n protected _getHightlightKey(g: IMarkGraphic) {\n return g.context?.groupKey;\n }\n\n start(g: IMarkGraphic) {\n if (g && this.isGraphicInMark(g)) {\n const highlightKey = this._getHightlightKey(g);\n\n if (isNil(highlightKey)) {\n return;\n }\n\n const { interaction, highlightState, blurState } = this.options;\n const statedGraphics = interaction.getStatedGraphics(this);\n const newStatedGraphics: IMarkGraphic[] = [];\n\n this.getMarks().forEach(m => {\n m.getGraphics()?.forEach(g => {\n if (this._getHightlightKey(g) === highlightKey) {\n newStatedGraphics.push(g);\n }\n });\n });\n\n interaction.updateStates(this, newStatedGraphics, statedGraphics, highlightState, blurState);\n interaction.setStatedGraphics(this, newStatedGraphics);\n }\n }\n\n reset(g?: IMarkGraphic) {\n if (g) {\n if (this.isGraphicInMark(g)) {\n const { interaction } = this.options;\n const statedGraphics = interaction.getStatedGraphics(this);\n\n removeGraphicState(g, [this.options.highlightState, this.options.blurState]);\n\n interaction.setStatedGraphics(\n this,\n statedGraphics.filter(sg => sg !== g)\n );\n }\n } else {\n this.resetAll();\n }\n }\n\n handleStart = (e: BaseEventParams) => {\n this.start(e.item);\n };\n\n handleReset = (e: BaseEventParams) => {\n const g = e.item;\n const hasActiveElement = g && this.isGraphicInMark(g);\n\n if (hasActiveElement) {\n this.resetAll();\n }\n };\n}\n\nexport const registerElementHighlightByGroup = () => {\n Factory.registerInteractionTrigger(type, ElementHighlightByGroup);\n};\n"]}
@@ -8,6 +8,8 @@ import { ChartEvent } from "../../constant/event";
8
8
 
9
9
  import { generateFilterValue } from "./util";
10
10
 
11
+ import { removeGraphicState } from "../../util/graphic-state";
12
+
11
13
  const type = "element-highlight-by-legend", defaultOptions = {
12
14
  highlightState: STATE_VALUE_ENUM.STATE_HIGHLIGHT,
13
15
  blurState: STATE_VALUE_ENUM.STATE_BLUR,
@@ -59,7 +61,7 @@ export class ElementHighlightByLegend extends BaseTrigger {
59
61
  const {highlightState: highlightState, blurState: blurState, interaction: interaction} = this.options;
60
62
  if (g) {
61
63
  const statedGraphics = interaction.getStatedGraphics(this);
62
- statedGraphics && statedGraphics.includes(g) && (g.removeState([ highlightState, blurState ]),
64
+ statedGraphics && statedGraphics.includes(g) && (removeGraphicState(g, [ highlightState, blurState ]),
63
65
  interaction.setStatedGraphics(this, statedGraphics.filter((sg => sg !== g))));
64
66
  } else this.resetAll();
65
67
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/interaction/triggers/element-highlight-by-legend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAI7C,MAAM,IAAI,GAAG,6BAA6B,CAAC;AAC3C,MAAM,cAAc,GAA8C;IAChE,cAAc,EAAE,gBAAgB,CAAC,eAAe;IAChD,SAAS,EAAE,gBAAgB,CAAC,UAAU;IACtC,UAAU,EAAE,UAAU;CACvB,CAAC;AAEF,MAAM,OAAO,wBACX,SAAQ,WAA6C;IAOrD,YAAY,OAA0C;QACpD,KAAK,CAAC,OAAO,CAAC,CAAC;QAJjB,SAAI,GAAW,IAAI,CAAC;QA4EpB,gBAAW,GAAG,CAAC,CAAkB,EAAE,EAAE;;YACnC,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;YAEtB,IAAI,KAAK,EAAE;gBACT,IAAI,CAAC,KAAK,CAAC,MAAA,MAAA,KAAK,CAAC,MAAM,0CAAE,IAAI,0CAAE,EAAE,CAAC,CAAC;aACpC;QACH,CAAC,CAAC;QAEF,gBAAW,GAAG,CAAC,CAAkB,EAAE,EAAE;YACnC,IAAI,CAAC,QAAQ,EAAE,CAAC;QAClB,CAAC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import type { IElementHighlightByLegendOptions, ITrigger, ITriggerEventHandler } from '../interface/trigger';\nimport { STATE_VALUE_ENUM } from '../../compile/mark/interface';\nimport { ChartEvent } from '../../constant/event';\nimport { generateFilterValue } from './util';\nimport type { IMarkGraphic } from '../../mark/interface/common';\nimport type { BaseEventParams } from '../../event/interface';\n\nconst type = 'element-highlight-by-legend';\nconst defaultOptions: Partial<IElementHighlightByLegendOptions> = {\n highlightState: STATE_VALUE_ENUM.STATE_HIGHLIGHT,\n blurState: STATE_VALUE_ENUM.STATE_BLUR,\n filterType: 'groupKey'\n};\n\nexport class ElementHighlightByLegend\n extends BaseTrigger<IElementHighlightByLegendOptions>\n implements ITrigger<IElementHighlightByLegendOptions>\n{\n static type: string = type;\n type: string = type;\n\n static defaultOptions = defaultOptions;\n constructor(options?: IElementHighlightByLegendOptions) {\n super(options);\n this.options = Object.assign({}, defaultOptions, options);\n this.updateMarkIdByState([this.options.highlightState, this.options.blurState]);\n }\n\n getStartState(): string {\n return this.options.highlightState;\n }\n\n getResetState(): string {\n return this.options.blurState;\n }\n\n protected getEvents(): Array<{ type: string | string[]; handler: ITriggerEventHandler }> {\n return [\n {\n type: ChartEvent.legendItemHover,\n handler: this.handleStart\n },\n {\n type: ChartEvent.legendItemUnHover,\n handler: this.handleReset\n }\n ];\n }\n\n start(itemKey: any) {\n if (itemKey) {\n const filterValue = generateFilterValue(this.options as IElementHighlightByLegendOptions);\n\n const { interaction, highlightState, blurState } = this.options;\n const statedGraphics = interaction.getStatedGraphics(this);\n const newStatedGraphics: IMarkGraphic[] = [];\n\n this.getMarks().forEach(m => {\n m.getGraphics()?.forEach(g => {\n if (filterValue(g) === itemKey) {\n newStatedGraphics.push(g);\n }\n });\n });\n\n interaction.updateStates(this, newStatedGraphics, statedGraphics, highlightState, blurState);\n interaction.setStatedGraphics(this, newStatedGraphics);\n }\n }\n\n resetAll() {\n const { interaction, highlightState, blurState } = this.options;\n\n interaction.clearAllStatesOfTrigger(this, highlightState, blurState);\n\n interaction.setStatedGraphics(this, []);\n }\n\n reset(g?: IMarkGraphic) {\n const { highlightState, blurState, interaction } = this.options;\n\n if (g) {\n const statedGraphics = interaction.getStatedGraphics(this);\n if (statedGraphics && statedGraphics.includes(g)) {\n g.removeState([highlightState, blurState]);\n interaction.setStatedGraphics(\n this,\n statedGraphics.filter(sg => sg !== g)\n );\n }\n } else {\n this.resetAll();\n }\n }\n\n handleStart = (e: BaseEventParams) => {\n const event = e.event;\n\n if (event) {\n this.start(event.detail?.data?.id);\n }\n };\n\n handleReset = (e: BaseEventParams) => {\n this.resetAll();\n };\n}\n\nexport const registerElementHighlightByLegend = () => {\n Factory.registerInteractionTrigger(type, ElementHighlightByLegend);\n};\n"]}
1
+ {"version":3,"sources":["../src/interaction/triggers/element-highlight-by-legend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAG7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,MAAM,IAAI,GAAG,6BAA6B,CAAC;AAC3C,MAAM,cAAc,GAA8C;IAChE,cAAc,EAAE,gBAAgB,CAAC,eAAe;IAChD,SAAS,EAAE,gBAAgB,CAAC,UAAU;IACtC,UAAU,EAAE,UAAU;CACvB,CAAC;AAEF,MAAM,OAAO,wBACX,SAAQ,WAA6C;IAOrD,YAAY,OAA0C;QACpD,KAAK,CAAC,OAAO,CAAC,CAAC;QAJjB,SAAI,GAAW,IAAI,CAAC;QA4EpB,gBAAW,GAAG,CAAC,CAAkB,EAAE,EAAE;;YACnC,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;YAEtB,IAA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CAAc,GAAG,cAAc,CAAC;AAuFzC,MAAM,CAAC,MAAM,gCAAgC,GAAG,GAAG,EAAE;IACnD,OAAO,CAAC,0BAA0B,CAAC,IAAI,EAAE,wBAAwB,CAAC,CAAC;AACrE,CAAC,CAAC","file":"element-highlight-by-legend.js","sourcesContent":["import { Factory } from '../../core/factory';\nimport { BaseTrigger } from './base';\nimport type { IElementHighlightByLegendOptions, ITrigger, ITriggerEventHandler } from '../interface/trigger';\nimport { STATE_VALUE_ENUM } from '../../compile/mark/interface';\nimport { ChartEvent } from '../../constant/event';\nimport { generateFilterValue } from './util';\nimport type { IMarkGraphic } from '../../mark/interface/common';\nimport type { BaseEventParams } from '../../event/interface';\nimport { removeGraphicState } from '../../util/graphic-state';\n\nconst type = 'element-highlight-by-legend';\nconst defaultOptions: Partial<IElementHighlightByLegendOptions> = {\n highlightState: STATE_VALUE_ENUM.STATE_HIGHLIGHT,\n blurState: STATE_VALUE_ENUM.STATE_BLUR,\n filterType: 'groupKey'\n};\n\nexport class ElementHighlightByLegend\n extends BaseTrigger<IElementHighlightByLegendOptions>\n implements ITrigger<IElementHighlightByLegendOptions>\n{\n static type: string = type;\n type: string = type;\n\n static defaultOptions = defaultOptions;\n constructor(options?: IElementHighlightByLegendOptions) {\n super(options);\n this.options = Object.assign({}, defaultOptions, options);\n this.updateMarkIdByState([this.options.highlightState, this.options.blurState]);\n }\n\n getStartState(): string {\n return this.options.highlightState;\n }\n\n getResetState(): string {\n return this.options.blurState;\n }\n\n protected getEvents(): Array<{ type: string | string[]; handler: ITriggerEventHandler }> {\n return [\n {\n type: ChartEvent.legendItemHover,\n handler: this.handleStart\n },\n {\n type: ChartEvent.legendItemUnHover,\n handler: this.handleReset\n }\n ];\n }\n\n start(itemKey: any) {\n if (itemKey) {\n const filterValue = generateFilterValue(this.options as IElementHighlightByLegendOptions);\n\n const { interaction, highlightState, blurState } = this.options;\n const statedGraphics = interaction.getStatedGraphics(this);\n const newStatedGraphics: IMarkGraphic[] = [];\n\n this.getMarks().forEach(m => {\n m.getGraphics()?.forEach(g => {\n if (filterValue(g) === itemKey) {\n newStatedGraphics.push(g);\n }\n });\n });\n\n interaction.updateStates(this, newStatedGraphics, statedGraphics, highlightState, blurState);\n interaction.setStatedGraphics(this, newStatedGraphics);\n }\n }\n\n resetAll() {\n const { interaction, highlightState, blurState } = this.options;\n\n interaction.clearAllStatesOfTrigger(this, highlightState, blurState);\n\n interaction.setStatedGraphics(this, []);\n }\n\n reset(g?: IMarkGraphic) {\n const { highlightState, blurState, interaction } = this.options;\n\n if (g) {\n const statedGraphics = interaction.getStatedGraphics(this);\n if (statedGraphics && statedGraphics.includes(g)) {\n removeGraphicState(g, [highlightState, blurState]);\n interaction.setStatedGraphics(\n this,\n statedGraphics.filter(sg => sg !== g)\n );\n }\n } else {\n this.resetAll();\n }\n }\n\n handleStart = (e: BaseEventParams) => {\n const event = e.event;\n\n if (event) {\n this.start(event.detail?.data?.id);\n }\n };\n\n handleReset = (e: BaseEventParams) => {\n this.resetAll();\n };\n}\n\nexport const registerElementHighlightByLegend = () => {\n Factory.registerInteractionTrigger(type, ElementHighlightByLegend);\n};\n"]}
@@ -8,6 +8,8 @@ import { array } from "@visactor/vutils";
8
8
 
9
9
  import { generateFilterValue } from "./util";
10
10
 
11
+ import { removeGraphicState } from "../../util/graphic-state";
12
+
11
13
  const type = "element-highlight-by-name", defaultOptions = {
12
14
  highlightState: STATE_VALUE_ENUM.STATE_HIGHLIGHT,
13
15
  blurState: STATE_VALUE_ENUM.STATE_BLUR,
@@ -68,7 +70,7 @@ export class ElementHighlightByName extends BaseTrigger {
68
70
  const {highlightState: highlightState, blurState: blurState, interaction: interaction} = this.options;
69
71
  if (g) {
70
72
  const statedGraphics = interaction.getStatedGraphics(this);
71
- statedGraphics && statedGraphics.includes(g) && (g.removeState([ highlightState, blurState ]),
73
+ statedGraphics && statedGraphics.includes(g) && (removeGraphicState(g, [ highlightState, blurState ]),
72
74
  interaction.setStatedGraphics(this, statedGraphics.filter((sg => sg !== g))));
73
75
  } else this.resetAll();
74
76
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/interaction/triggers/element-highlight-by-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAE7C,MAAM,IAAI,GAAG,2BAA2B,CAAC;AACzC,MAAM,cAAc,GAA4C;IAC9D,cAAc,EAAE,gBAAgB,CAAC,eAAe;IAChD,SAAS,EAAE,gBAAgB,CAAC,UAAU;IACtC,UAAU,EAAE,UAAU;CACvB,CAAC;AAEF,MAAM,OAAO,sBACX,SAAQ,WAA2C;IAOnD,YAAY,OAAwC;QAClD,KAAK,CAAC,OAAO,CAAC,CAAC;QAJjB,SAAI,GAAW,IAAI,CAAC;QAuFpB,gBAAW,GAAG,CAAC,CAAkB,EAAE,EAAE;YACnC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;YAElG,IAAI,UAAU,EAAE;gBACd,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;gBACxC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;aACrB;QACH,CAAC,CAAC;QAEF,gBAAW,GAAG,CAAC,CAAkB,EAAE,EAAE;YACnC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,C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AG,IAAI,CAAC,OAAO,CAAC;QAEhE,IAAI,CAAC,EAAE;YACL,MAAM,cAAc,GAAG,WAAW,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;YAC3D,IAAI,cAAc,IAAI,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE;gBAChD,CAAC,CAAC,WAAW,CAAC,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC,CAAC;gBAC3C,WAAW,CAAC,iBAAiB,CAC3B,IAAI,EACJ,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,CACtC,CAAC;aACH;SACF;aAAM;YACL,IAAI,CAAC,QAAQ,EAAE,CAAC;SACjB;IACH,CAAC;;AAtFM,2BAAI,GAAW,IAAI,CAAC;AAGpB,qCAAc,GAAG,cAAc,CAAC;AAuGzC,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAG,EAAE;IACjD,OAAO,CAAC,0BAA0B,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;AACnE,CAAC,CAAC","file":"element-highlight-by-name.js","sourcesContent":["import { Factory } from '../../core/factory';\nimport { BaseTrigger } from './base';\nimport type { IElementHighlightByNameOptions, ITrigger } from '../interface/trigger';\nimport { STATE_VALUE_ENUM } from '../../compile/mark/interface';\nimport type { BaseEventParams } from '../../event/interface';\nimport { array } from '@visactor/vutils';\nimport type { IMarkGraphic } from '../../mark/interface';\nimport { generateFilterValue } from './util';\n\nconst type = 'element-highlight-by-name';\nconst defaultOptions: Partial<IElementHighlightByNameOptions> = {\n highlightState: STATE_VALUE_ENUM.STATE_HIGHLIGHT,\n blurState: STATE_VALUE_ENUM.STATE_BLUR,\n filterType: 'groupKey'\n};\n\nexport class ElementHighlightByName\n extends BaseTrigger<IElementHighlightByNameOptions>\n implements ITrigger<IElementHighlightByNameOptions>\n{\n static type: string = type;\n type: string = type;\n\n static defaultOptions = defaultOptions;\n constructor(options?: IElementHighlightByNameOptions) {\n super(options);\n this.options = Object.assign({}, defaultOptions, options);\n this.updateMarkIdByState([this.options.highlightState, this.options.blurState]);\n }\n\n getStartState(): string {\n return this.options.highlightState;\n }\n\n getResetState(): string {\n return this.options.blurState;\n }\n\n protected getEvents() {\n return [\n {\n type: this.options.trigger,\n handler: this.handleStart\n },\n { type: this.options.triggerOff, handler: this.handleReset }\n ];\n }\n\n protected _filterByName(e: BaseEventParams) {\n const names = array(this.options.graphicName);\n\n return e?.node?.name && names.includes(e.node.name);\n }\n\n protected _parseTargetKey(e: BaseEventParams) {\n return this.options.parseData\n ? this.options.parseData(e)\n : e.node.type === 'text'\n ? (e.node.attribute as any).text\n : null;\n }\n\n start(itemKey: any) {\n if (itemKey) {\n const filterValue = generateFilterValue(this.options as IElementHighlightByNameOptions);\n\n const { interaction, highlightState, blurState } = this.options;\n const statedGraphics = interaction.getStatedGraphics(this);\n const newStatedGraphics: IMarkGraphic[] = [];\n\n this.getMarks().forEach(m => {\n m.getGraphics()?.forEach(g => {\n if (filterValue(g) === itemKey) {\n newStatedGraphics.push(g);\n }\n });\n });\n\n interaction.updateStates(this, newStatedGraphics, statedGraphics, highlightState, blurState);\n interaction.setStatedGraphics(this, newStatedGraphics);\n }\n }\n\n resetAll() {\n const { interaction, highlightState, blurState } = this.options;\n\n interaction.clearAllStatesOfTrigger(this, highlightState, blurState);\n\n interaction.setStatedGraphics(this, []);\n }\n\n reset(g?: IMarkGraphic) {\n const { highlightState, blurState, interaction } = this.options;\n\n if (g) {\n const statedGraphics = interaction.getStatedGraphics(this);\n if (statedGraphics && statedGraphics.includes(g)) {\n g.removeState([highlightState, blurState]);\n interaction.setStatedGraphics(\n this,\n statedGraphics.filter(sg => sg !== g)\n );\n }\n } else {\n this.resetAll();\n }\n }\n\n handleStart = (e: BaseEventParams) => {\n const shoudStart = this.options.shouldStart ? this.options.shouldStart(e) : this._filterByName(e);\n\n if (shoudStart) {\n const itemKey = this._parseTargetKey(e);\n this.start(itemKey);\n }\n };\n\n handleReset = (e: BaseEventParams) => {\n const shoudReset = this.options.shouldReset ? this.options.shouldReset(e) : this._filterByName(e);\n\n if (shoudReset) {\n this.resetAll();\n }\n };\n}\n\nexport const registerElementHighlightByName = () => {\n Factory.registerInteractionTrigger(type, ElementHighlightByName);\n};\n"]}
1
+ {"version":3,"sources":["../src/interaction/triggers/element-highlight-by-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,MAAM,IAAI,GAAG,2BAA2B,CAAC;AACzC,MAAM,cAAc,GAA4C;IAC9D,cAAc,EAAE,gBAAgB,CAAC,eAAe;IAChD,SAAS,EAAE,gBAAgB,CAAC,UAAU;IACtC,UAAU,EAAE,UAAU;CACvB,CAAC;AAEF,MAAM,OAAO,sBACX,SAAQ,WAA2C;IAOnD,YAAY,OAAwC;QAClD,KAAK,CAAC,OAAO,CAAC,CAAC;QAJjB,SAAI,GAAW,IAAI,CAAC;QAuFpB,gBAAW,GAAG,CAAC,CAAkB,EAAE,EAAE;YACnC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;YAElG,IAAI,UAAU,EAAE;gBACd,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;gBACxC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;aACrB;QACH,CA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,CAAC,CAAC;QAErE,WAAW,CAAC,iBAAiB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,CAAgB;QACpB,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAEhE,IAAI,CAAC,EAAE;YACL,MAAM,cAAc,GAAG,WAAW,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;YAC3D,IAAI,cAAc,IAAI,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE;gBAChD,kBAAkB,CAAC,CAAC,EAAE,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC,CAAC;gBACnD,WAAW,CAAC,iBAAiB,CAC3B,IAAI,EACJ,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,CACtC,CAAC;aACH;SACF;aAAM;YACL,IAAI,CAAC,QAAQ,EAAE,CAAC;SACjB;IACH,CAAC;;AAtFM,2BAAI,GAAW,IAAI,CAAC;AAGpB,qCAAc,GAAG,cAAc,CAAC;AAuGzC,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAG,EAAE;IACjD,OAAO,CAAC,0BAA0B,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;AACnE,CAAC,CAAC","file":"element-highlight-by-name.js","sourcesContent":["import { Factory } from '../../core/factory';\nimport { BaseTrigger } from './base';\nimport type { IElementHighlightByNameOptions, ITrigger } from '../interface/trigger';\nimport { STATE_VALUE_ENUM } from '../../compile/mark/interface';\nimport type { BaseEventParams } from '../../event/interface';\nimport { array } from '@visactor/vutils';\nimport type { IMarkGraphic } from '../../mark/interface';\nimport { generateFilterValue } from './util';\nimport { removeGraphicState } from '../../util/graphic-state';\n\nconst type = 'element-highlight-by-name';\nconst defaultOptions: Partial<IElementHighlightByNameOptions> = {\n highlightState: STATE_VALUE_ENUM.STATE_HIGHLIGHT,\n blurState: STATE_VALUE_ENUM.STATE_BLUR,\n filterType: 'groupKey'\n};\n\nexport class ElementHighlightByName\n extends BaseTrigger<IElementHighlightByNameOptions>\n implements ITrigger<IElementHighlightByNameOptions>\n{\n static type: string = type;\n type: string = type;\n\n static defaultOptions = defaultOptions;\n constructor(options?: IElementHighlightByNameOptions) {\n super(options);\n this.options = Object.assign({}, defaultOptions, options);\n this.updateMarkIdByState([this.options.highlightState, this.options.blurState]);\n }\n\n getStartState(): string {\n return this.options.highlightState;\n }\n\n getResetState(): string {\n return this.options.blurState;\n }\n\n protected getEvents() {\n return [\n {\n type: this.options.trigger,\n handler: this.handleStart\n },\n { type: this.options.triggerOff, handler: this.handleReset }\n ];\n }\n\n protected _filterByName(e: BaseEventParams) {\n const names = array(this.options.graphicName);\n\n return e?.node?.name && names.includes(e.node.name);\n }\n\n protected _parseTargetKey(e: BaseEventParams) {\n return this.options.parseData\n ? this.options.parseData(e)\n : e.node.type === 'text'\n ? (e.node.attribute as any).text\n : null;\n }\n\n start(itemKey: any) {\n if (itemKey) {\n const filterValue = generateFilterValue(this.options as IElementHighlightByNameOptions);\n\n const { interaction, highlightState, blurState } = this.options;\n const statedGraphics = interaction.getStatedGraphics(this);\n const newStatedGraphics: IMarkGraphic[] = [];\n\n this.getMarks().forEach(m => {\n m.getGraphics()?.forEach(g => {\n if (filterValue(g) === itemKey) {\n newStatedGraphics.push(g);\n }\n });\n });\n\n interaction.updateStates(this, newStatedGraphics, statedGraphics, highlightState, blurState);\n interaction.setStatedGraphics(this, newStatedGraphics);\n }\n }\n\n resetAll() {\n const { interaction, highlightState, blurState } = this.options;\n\n interaction.clearAllStatesOfTrigger(this, highlightState, blurState);\n\n interaction.setStatedGraphics(this, []);\n }\n\n reset(g?: IMarkGraphic) {\n const { highlightState, blurState, interaction } = this.options;\n\n if (g) {\n const statedGraphics = interaction.getStatedGraphics(this);\n if (statedGraphics && statedGraphics.includes(g)) {\n removeGraphicState(g, [highlightState, blurState]);\n interaction.setStatedGraphics(\n this,\n statedGraphics.filter(sg => sg !== g)\n );\n }\n } else {\n this.resetAll();\n }\n }\n\n handleStart = (e: BaseEventParams) => {\n const shoudStart = this.options.shouldStart ? this.options.shouldStart(e) : this._filterByName(e);\n\n if (shoudStart) {\n const itemKey = this._parseTargetKey(e);\n this.start(itemKey);\n }\n };\n\n handleReset = (e: BaseEventParams) => {\n const shoudReset = this.options.shouldReset ? this.options.shouldReset(e) : this._filterByName(e);\n\n if (shoudReset) {\n this.resetAll();\n }\n };\n}\n\nexport const registerElementHighlightByName = () => {\n Factory.registerInteractionTrigger(type, ElementHighlightByName);\n};\n"]}
@@ -6,6 +6,8 @@ import { BaseTrigger } from "./base";
6
6
 
7
7
  import { Factory } from "../../core/factory";
8
8
 
9
+ import { removeGraphicState } from "../../util/graphic-state";
10
+
9
11
  const defaultOptions = {
10
12
  highlightState: STATE_VALUE_ENUM.STATE_HIGHLIGHT,
11
13
  blurState: STATE_VALUE_ENUM.STATE_BLUR,
@@ -62,7 +64,7 @@ export class ElementHighlight extends BaseTrigger {
62
64
  } else this._lastGraphic && "view" === this._resetType && this.resetAll(e);
63
65
  }
64
66
  reset(markGraphic, e) {
65
- markGraphic ? this._markSet.getMarkInId(markGraphic.context.markId) && markGraphic.removeState([ this.options.highlightState, this.options.blurState ]) : this.resetAll(e);
67
+ markGraphic ? this._markSet.getMarkInId(markGraphic.context.markId) && removeGraphicState(markGraphic, [ this.options.highlightState, this.options.blurState ]) : this.resetAll(e);
66
68
  }
67
69
  }
68
70
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/interaction/triggers/element-highlight.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAGhE,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAK7C,MAAM,cAAc,GAAsC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W,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;aAChF;SACF;aAAM;YACL,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;SAClB;IACH,CAAC;;AAlHM,qBAAI,uBAA+C;AAGnD,+BAAc,GAAG,cAAc,CAAC;AAkHzC,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAC3C,OAAO,CAAC,0BAA0B,CAAC,gBAAgB,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;AAC9E,CAAC,CAAC","file":"element-highlight.js","sourcesContent":["import { isString } from '@visactor/vutils';\nimport { STATE_VALUE_ENUM } from '../../compile/mark/interface';\nimport type { IElementHighlightOptions, ITrigger } from '../interface/trigger';\nimport type { IMarkGraphic } from '../../mark/interface/common';\nimport { BaseTrigger } from './base';\nimport { Factory } from '../../core/factory';\nimport type { GraphicEventType } from '@visactor/vrender-core';\nimport { TRIGGER_TYPE_ENUM } from './enum';\nimport type { BaseEventParams } from '../../event/interface';\n\nconst defaultOptions: Partial<IElementHighlightOptions> = {\n highlightState: STATE_VALUE_ENUM.STATE_HIGHLIGHT,\n blurState: STATE_VALUE_ENUM.STATE_BLUR,\n trigger: 'pointerover',\n triggerOff: 'pointerout'\n};\n\nexport class ElementHighlight\n extends BaseTrigger<IElementHighlightOptions>\n implements ITrigger<IElementHighlightOptions>\n{\n static type: string = TRIGGER_TYPE_ENUM.ELEMENT_HIGHLIGHT;\n type: string = TRIGGER_TYPE_ENUM.ELEMENT_HIGHLIGHT;\n\n static defaultOptions = defaultOptions;\n\n protected _lastGraphic?: IMarkGraphic;\n\n constructor(options?: IElementHighlightOptions) {\n super(options);\n this.options = Object.assign({}, defaultOptions, options);\n\n this.updateMarkIdByState([this.options.highlightState, this.options.blurState]);\n }\n\n getStartState(): string {\n return this.options.highlightState;\n }\n\n getResetState(): string {\n return this.options.blurState;\n }\n protected _resetType?: 'view' | 'self';\n\n protected getEvents() {\n const triggerOff = this.options.triggerOff;\n const trigger = this.options.trigger;\n const events = [\n {\n type: trigger,\n handler: this.handleStart\n }\n ];\n\n let eventName = triggerOff;\n if (isString(triggerOff) && (triggerOff as string).includes('view:')) {\n eventName = (triggerOff as string).replace('view:', '') as GraphicEventType;\n this._resetType = 'view';\n } else {\n this._resetType = 'self';\n }\n\n events.push({ type: eventName as GraphicEventType, handler: this.handleReset });\n\n return events;\n }\n\n resetAll = (e?: BaseEventParams) => {\n const { highlightState, blurState, interaction } = this.options;\n\n if (this._lastGraphic) {\n interaction.clearAllStatesOfTrigger(this, highlightState, blurState);\n\n this.dispatchEvent('reset', { graphics: [this._lastGraphic], options: this.options, ...e });\n\n this._lastGraphic = null;\n\n interaction.setStatedGraphics(this, []);\n }\n };\n\n handleStart = (e: BaseEventParams) => {\n this.start(e.item, e);\n };\n\n handleReset = (e: BaseEventParams) => {\n const { interaction } = this.options;\n const statedGraphics = interaction.getStatedGraphics(this);\n\n if (!statedGraphics || !statedGraphics.length) {\n return;\n }\n const markGraphic = e.item;\n const hasActiveElement = markGraphic && this._markSet.getMarkInId(markGraphic.context.markId);\n\n if (this._resetType.includes('view') && !hasActiveElement) {\n this.resetAll(e);\n } else if (this._resetType.includes('self') && hasActiveElement) {\n this.resetAll(e);\n }\n };\n\n start(markGraphic: IMarkGraphic, e?: BaseEventParams) {\n if (markGraphic && this._markSet.getMarkInId(markGraphic.context.markId)) {\n const { highlightState, blurState, interaction } = this.options;\n\n if (this._lastGraphic === markGraphic) {\n return;\n }\n\n const newStatedGraphics = interaction.updateStates(\n this,\n [markGraphic],\n interaction.getStatedGraphics(this),\n highlightState,\n blurState\n );\n interaction.setStatedGraphics(this, newStatedGraphics);\n\n this._lastGraphic = markGraphic;\n\n this.dispatchEvent('start', { graphics: newStatedGraphics, options: this.options, ...e });\n } else if (this._lastGraphic && this._resetType === 'view') {\n this.resetAll(e);\n }\n }\n\n reset(markGraphic: IMarkGraphic, e?: BaseEventParams) {\n if (markGraphic) {\n if (this._markSet.getMarkInId(markGraphic.context.markId)) {\n markGraphic.removeState([this.options.highlightState, this.options.blurState]);\n }\n } else {\n this.resetAll(e);\n }\n }\n}\n\nexport const registerElementHighlight = () => {\n Factory.registerInteractionTrigger(ElementHighlight.type, ElementHighlight);\n};\n"]}
1
+ {"version":3,"sources":["../src/interaction/triggers/element-highlight.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAGhE,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAI7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,MAAM,cAAc,GAAsC;IACxD,cAAc,EAAE,gBAAgB,CAAC,eAAe;IAChD,SAAS,EAAE,gBAAgB,CAAC,UAAU;IACtC,OAAO,EAAE,aAAa;IACtB,UAAU,EAAE,YAAY;CACzB,CAAC;AAEF,MAAM,OAAO,gBACX,SAAQ,WAAqC;IAU7C,YAAY,OAAkC;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAC;QAPjB,SAAI,uBAA+C;QA6CnD,aAAQ,GAAG,CAAC,CAAmB,EAAE,EAAE;YACjC,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;YAEhE,IAAI,IAAI,CAAC,YAAY,EAAE;gBACrB,WAAW,CAAC,uBAAuB,CAAC,IAAI,EAAE,cAAc,EAAE,SAAS,CAAC,CAAC;gBAErE,IAAI,CAAC,aAAa,CAAC,OAAO,kBAAI,QAAQ,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,IAAK,CAAC,EAAG,CAAC;gBAE5F,IAAI,CAAC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EACd,SAAS,CACV,CAAC;YACF,WAAW,CAAC,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;YAEvD,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;YAEhC,IAAI,CAAC,aAAa,CAAC,OAAO,kBAAI,QAAQ,EAAE,iBAAiB,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,IAAK,CAAC,EAAG,CAAC;SAC3F;aAAM,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,UAAU,KAAK,MAAM,EAAE;YAC1D,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;SAClB;IACH,CAAC;IAED,KAAK,CAAC,WAAyB,EAAE,CAAmB;QAClD,IAAI,WAAW,EAAE;YACf,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;gBACzD,kBAAkB,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;aACxF;SACF;aAAM;YACL,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;SAClB;IACH,CAAC;;AAlHM,qBAAI,uBAA+C;AAGnD,+BAAc,GAAG,cAAc,CAAC;AAkHzC,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAC3C,OAAO,CAAC,0BAA0B,CAAC,gBAAgB,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;AAC9E,CAAC,CAAC","file":"element-highlight.js","sourcesContent":["import { isString } from '@visactor/vutils';\nimport { STATE_VALUE_ENUM } from '../../compile/mark/interface';\nimport type { IElementHighlightOptions, ITrigger } from '../interface/trigger';\nimport type { IMarkGraphic } from '../../mark/interface/common';\nimport { BaseTrigger } from './base';\nimport { Factory } from '../../core/factory';\nimport type { GraphicEventType } from '@visactor/vrender-core';\nimport { TRIGGER_TYPE_ENUM } from './enum';\nimport type { BaseEventParams } from '../../event/interface';\nimport { removeGraphicState } from '../../util/graphic-state';\n\nconst defaultOptions: Partial<IElementHighlightOptions> = {\n highlightState: STATE_VALUE_ENUM.STATE_HIGHLIGHT,\n blurState: STATE_VALUE_ENUM.STATE_BLUR,\n trigger: 'pointerover',\n triggerOff: 'pointerout'\n};\n\nexport class ElementHighlight\n extends BaseTrigger<IElementHighlightOptions>\n implements ITrigger<IElementHighlightOptions>\n{\n static type: string = TRIGGER_TYPE_ENUM.ELEMENT_HIGHLIGHT;\n type: string = TRIGGER_TYPE_ENUM.ELEMENT_HIGHLIGHT;\n\n static defaultOptions = defaultOptions;\n\n protected _lastGraphic?: IMarkGraphic;\n\n constructor(options?: IElementHighlightOptions) {\n super(options);\n this.options = Object.assign({}, defaultOptions, options);\n\n this.updateMarkIdByState([this.options.highlightState, this.options.blurState]);\n }\n\n getStartState(): string {\n return this.options.highlightState;\n }\n\n getResetState(): string {\n return this.options.blurState;\n }\n protected _resetType?: 'view' | 'self';\n\n protected getEvents() {\n const triggerOff = this.options.triggerOff;\n const trigger = this.options.trigger;\n const events = [\n {\n type: trigger,\n handler: this.handleStart\n }\n ];\n\n let eventName = triggerOff;\n if (isString(triggerOff) && (triggerOff as string).includes('view:')) {\n eventName = (triggerOff as string).replace('view:', '') as GraphicEventType;\n this._resetType = 'view';\n } else {\n this._resetType = 'self';\n }\n\n events.push({ type: eventName as GraphicEventType, handler: this.handleReset });\n\n return events;\n }\n\n resetAll = (e?: BaseEventParams) => {\n const { highlightState, blurState, interaction } = this.options;\n\n if (this._lastGraphic) {\n interaction.clearAllStatesOfTrigger(this, highlightState, blurState);\n\n this.dispatchEvent('reset', { graphics: [this._lastGraphic], options: this.options, ...e });\n\n this._lastGraphic = null;\n\n interaction.setStatedGraphics(this, []);\n }\n };\n\n handleStart = (e: BaseEventParams) => {\n this.start(e.item, e);\n };\n\n handleReset = (e: BaseEventParams) => {\n const { interaction } = this.options;\n const statedGraphics = interaction.getStatedGraphics(this);\n\n if (!statedGraphics || !statedGraphics.length) {\n return;\n }\n const markGraphic = e.item;\n const hasActiveElement = markGraphic && this._markSet.getMarkInId(markGraphic.context.markId);\n\n if (this._resetType.includes('view') && !hasActiveElement) {\n this.resetAll(e);\n } else if (this._resetType.includes('self') && hasActiveElement) {\n this.resetAll(e);\n }\n };\n\n start(markGraphic: IMarkGraphic, e?: BaseEventParams) {\n if (markGraphic && this._markSet.getMarkInId(markGraphic.context.markId)) {\n const { highlightState, blurState, interaction } = this.options;\n\n if (this._lastGraphic === markGraphic) {\n return;\n }\n\n const newStatedGraphics = interaction.updateStates(\n this,\n [markGraphic],\n interaction.getStatedGraphics(this),\n highlightState,\n blurState\n );\n interaction.setStatedGraphics(this, newStatedGraphics);\n\n this._lastGraphic = markGraphic;\n\n this.dispatchEvent('start', { graphics: newStatedGraphics, options: this.options, ...e });\n } else if (this._lastGraphic && this._resetType === 'view') {\n this.resetAll(e);\n }\n }\n\n reset(markGraphic: IMarkGraphic, e?: BaseEventParams) {\n if (markGraphic) {\n if (this._markSet.getMarkInId(markGraphic.context.markId)) {\n removeGraphicState(markGraphic, [this.options.highlightState, this.options.blurState]);\n }\n } else {\n this.resetAll(e);\n }\n }\n}\n\nexport const registerElementHighlight = () => {\n Factory.registerInteractionTrigger(ElementHighlight.type, ElementHighlight);\n};\n"]}
@@ -8,6 +8,8 @@ import { parseTriggerOffOfSelect } from "./util";
8
8
 
9
9
  import { Factory } from "../../core/factory";
10
10
 
11
+ import { addGraphicState, removeGraphicState } from "../../util/graphic-state";
12
+
11
13
  const defaultOptions = {
12
14
  state: STATE_VALUE_ENUM.STATE_SELECTED,
13
15
  trigger: "click"
@@ -57,7 +59,7 @@ export class ElementSelect extends BaseTrigger {
57
59
  newStatedGraphics && newStatedGraphics.length ? interaction.setStatedGraphics(this, interaction.updateStates(this, newStatedGraphics, statedGraphics, state, reverseState)) : this.resetAll(e);
58
60
  }
59
61
  } else {
60
- this._timer && clearTimeout(this._timer), markGraphic.addState(state, !0);
62
+ this._timer && clearTimeout(this._timer), addGraphicState(markGraphic, state, !0);
61
63
  const newStatedGraphics = this.options.interaction.updateStates(this, isMultiple && statedGraphics ? [ ...statedGraphics, markGraphic ] : [ markGraphic ], statedGraphics, state, reverseState);
62
64
  interaction.setStatedGraphics(this, newStatedGraphics), this.dispatchEvent("start", Object.assign({
63
65
  graphics: newStatedGraphics,
@@ -68,7 +70,7 @@ export class ElementSelect extends BaseTrigger {
68
70
  } else this._resetType.includes("view") && statedGraphics && statedGraphics.length && this.resetAll(e);
69
71
  }
70
72
  reset(markGraphic, e) {
71
- markGraphic ? this._markSet.getMarkInId(markGraphic.context.markId) && markGraphic.removeState([ this.options.state, this.options.reverseState ]) : this.resetAll(e);
73
+ markGraphic ? this._markSet.getMarkInId(markGraphic.context.markId) && removeGraphicState(markGraphic, [ this.options.state, this.options.reverseState ]) : this.resetAll(e);
72
74
  }
73
75
  }
74
76
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/interaction/triggers/element-select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAGhE,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,uBAAuB,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAI7C,MAAM,cAAc,GAAmC;IACrD,KAAK,EAAE,gBAAgB,CAAC,cAAc;IACtC,OAAO,EAAE,OAAO;CACjB,CAAC;AAEF,MAAM,OAAO,aAAc,SAAQ,WAAkC;IASnE,YAAY,OAA+B;QACzC,KAAK,CAAC,OAAO,CAAC,CAAC;QARjB,SAAI,oBAA4C;QAGtC,eAAU,GAAoC,EAAE,CAAC;QA2C3D,aAAQ,GAAG,CAAC,CAAmB,EAAE,EAAE;YACjC,MAAM,EAAE,KAAK,EAAE,YAAY,EAA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interface';\nimport type { IElementSelectOptions, ITrigger } from '../interface/trigger';\nimport type { IMarkGraphic } from '../../mark/interface/common';\nimport { BaseTrigger } from './base';\nimport { parseTriggerOffOfSelect } from './util';\nimport { Factory } from '../../core/factory';\nimport { TRIGGER_TYPE_ENUM } from './enum';\nimport type { BaseEventParams } from '../../event/interface';\n\nconst defaultOptions: Partial<IElementSelectOptions> = {\n state: STATE_VALUE_ENUM.STATE_SELECTED,\n trigger: 'click'\n};\n\nexport class ElementSelect extends BaseTrigger<IElementSelectOptions> implements ITrigger<IElementSelectOptions> {\n static type: string = TRIGGER_TYPE_ENUM.ELEMENT_SELECT;\n type: string = TRIGGER_TYPE_ENUM.ELEMENT_SELECT;\n\n static defaultOptions = defaultOptions;\n protected _resetType: ('view' | 'self' | 'timeout')[] = [];\n\n private _timer?: number;\n\n constructor(options?: IElementSelectOptions) {\n super(options);\n this.options = Object.assign({}, defaultOptions, options);\n\n this.updateMarkIdByState([this.options.state, this.options.reverseState]);\n }\n\n getStartState(): string {\n return this.options.state;\n }\n\n getResetState(): string {\n return this.options.reverseState;\n }\n\n protected getEvents() {\n const triggerOff = this.options.triggerOff;\n const trigger = this.options.trigger;\n\n const events = [\n {\n type: trigger,\n handler: this.handleStart\n }\n ];\n\n const { eventNames, resetType } = parseTriggerOffOfSelect(triggerOff);\n\n eventNames.forEach(evt => {\n if (evt && (isArray(trigger) ? !trigger.includes(evt) : evt !== trigger)) {\n events.push({ type: evt, handler: this.handleReset });\n }\n });\n\n this._resetType = resetType;\n\n return events;\n }\n\n resetAll = (e?: BaseEventParams) => {\n const { state, reverseState, interaction } = this.options;\n\n const statedGraphics = interaction.getStatedGraphics(this);\n\n if (statedGraphics && statedGraphics.length) {\n interaction.clearAllStatesOfTrigger(this, state, reverseState);\n this.dispatchEvent('reset', { graphics: statedGraphics, options: this.options, ...e });\n\n interaction.setStatedGraphics(this, []);\n }\n };\n\n handleStart = (e: BaseEventParams) => {\n this.start(e.item, e);\n };\n\n handleReset = (e: BaseEventParams) => {\n const { interaction } = this.options;\n\n const statedGraphics = interaction.getStatedGraphics(this);\n if (!statedGraphics || !statedGraphics.length) {\n return;\n }\n const markGraphic = e.item;\n const hasActiveElement = markGraphic && this._markSet.getMarkInId(markGraphic.context.markId);\n\n if (this._resetType.includes('view') && !hasActiveElement) {\n this.resetAll(e);\n } else if (this._resetType.includes('self') && hasActiveElement) {\n this.resetAll(e);\n }\n };\n\n start(markGraphic: IMarkGraphic, e?: BaseEventParams) {\n const { state, reverseState, isMultiple, interaction } = this.options;\n const statedGraphics = interaction.getStatedGraphics(this);\n\n if (markGraphic && this._markSet.getMarkInId(markGraphic.context.markId)) {\n if (markGraphic.hasState(state)) {\n if (this._resetType.includes('self')) {\n const newStatedGraphics = statedGraphics && statedGraphics.filter(g => g !== markGraphic);\n\n if (newStatedGraphics && newStatedGraphics.length) {\n interaction.setStatedGraphics(\n this,\n interaction.updateStates(this, newStatedGraphics, statedGraphics, state, reverseState)\n );\n } else {\n this.resetAll(e);\n }\n }\n } else {\n if (this._timer) {\n clearTimeout(this._timer);\n }\n markGraphic.addState(state, true);\n\n const newStatedGraphics = this.options.interaction.updateStates(\n this,\n isMultiple && statedGraphics ? [...statedGraphics, markGraphic] : [markGraphic],\n statedGraphics,\n state,\n reverseState\n );\n interaction.setStatedGraphics(this, newStatedGraphics);\n this.dispatchEvent('start', { graphics: newStatedGraphics, options: this.options, ...e });\n\n if (this._resetType.includes('timeout')) {\n this._timer = setTimeout(() => {\n this.resetAll(e);\n }, this.options.triggerOff as number) as unknown as number;\n }\n }\n } else if (this._resetType.includes('view') && statedGraphics && statedGraphics.length) {\n this.resetAll(e);\n }\n }\n\n reset(markGraphic: IMarkGraphic, e?: BaseEventParams) {\n if (markGraphic) {\n if (this._markSet.getMarkInId(markGraphic.context.markId)) {\n markGraphic.removeState([this.options.state, this.options.reverseState]);\n }\n } else {\n this.resetAll(e);\n }\n }\n}\n\nexport const registerElementSelect = () => {\n Factory.registerInteractionTrigger(ElementSel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cAAc,IAAI,cAAc,CAAC,MAAM,EAAE;YACtF,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;SAClB;IACH,CAAC;IAED,KAAK,CAAC,WAAyB,EAAE,CAAmB;QAClD,IAAI,WAAW,EAAE;YACf,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;gBACzD,kBAAkB,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;aAClF;SACF;aAAM;YACL,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;SAClB;IACH,CAAC;;AAtIM,kBAAI,oBAA4C;AAGhD,4BAAc,GAAG,cAAc,CAAC;AAsIzC,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,EAAE;IACxC,OAAO,CAAC,0BAA0B,CAAC,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;AACxE,CAAC,CAAC","file":"element-select.js","sourcesContent":["import { isArray } from '@visactor/vutils';\nimport { STATE_VALUE_ENUM } from '../../compile/mark/interface';\nimport type { IElementSelectOptions, ITrigger } from '../interface/trigger';\nimport type { IMarkGraphic } from '../../mark/interface/common';\nimport { BaseTrigger } from './base';\nimport { parseTriggerOffOfSelect } from './util';\nimport { Factory } from '../../core/factory';\nimport { TRIGGER_TYPE_ENUM } from './enum';\nimport type { BaseEventParams } from '../../event/interface';\nimport { addGraphicState, removeGraphicState } from '../../util/graphic-state';\n\nconst defaultOptions: Partial<IElementSelectOptions> = {\n state: STATE_VALUE_ENUM.STATE_SELECTED,\n trigger: 'click'\n};\n\nexport class ElementSelect extends BaseTrigger<IElementSelectOptions> implements ITrigger<IElementSelectOptions> {\n static type: string = TRIGGER_TYPE_ENUM.ELEMENT_SELECT;\n type: string = TRIGGER_TYPE_ENUM.ELEMENT_SELECT;\n\n static defaultOptions = defaultOptions;\n protected _resetType: ('view' | 'self' | 'timeout')[] = [];\n\n private _timer?: number;\n\n constructor(options?: IElementSelectOptions) {\n super(options);\n this.options = Object.assign({}, defaultOptions, options);\n\n this.updateMarkIdByState([this.options.state, this.options.reverseState]);\n }\n\n getStartState(): string {\n return this.options.state;\n }\n\n getResetState(): string {\n return this.options.reverseState;\n }\n\n protected getEvents() {\n const triggerOff = this.options.triggerOff;\n const trigger = this.options.trigger;\n\n const events = [\n {\n type: trigger,\n handler: this.handleStart\n }\n ];\n\n const { eventNames, resetType } = parseTriggerOffOfSelect(triggerOff);\n\n eventNames.forEach(evt => {\n if (evt && (isArray(trigger) ? !trigger.includes(evt) : evt !== trigger)) {\n events.push({ type: evt, handler: this.handleReset });\n }\n });\n\n this._resetType = resetType;\n\n return events;\n }\n\n resetAll = (e?: BaseEventParams) => {\n const { state, reverseState, interaction } = this.options;\n\n const statedGraphics = interaction.getStatedGraphics(this);\n\n if (statedGraphics && statedGraphics.length) {\n interaction.clearAllStatesOfTrigger(this, state, reverseState);\n this.dispatchEvent('reset', { graphics: statedGraphics, options: this.options, ...e });\n\n interaction.setStatedGraphics(this, []);\n }\n };\n\n handleStart = (e: BaseEventParams) => {\n this.start(e.item, e);\n };\n\n handleReset = (e: BaseEventParams) => {\n const { interaction } = this.options;\n\n const statedGraphics = interaction.getStatedGraphics(this);\n if (!statedGraphics || !statedGraphics.length) {\n return;\n }\n const markGraphic = e.item;\n const hasActiveElement = markGraphic && this._markSet.getMarkInId(markGraphic.context.markId);\n\n if (this._resetType.includes('view') && !hasActiveElement) {\n this.resetAll(e);\n } else if (this._resetType.includes('self') && hasActiveElement) {\n this.resetAll(e);\n }\n };\n\n start(markGraphic: IMarkGraphic, e?: BaseEventParams) {\n const { state, reverseState, isMultiple, interaction } = this.options;\n const statedGraphics = interaction.getStatedGraphics(this);\n\n if (markGraphic && this._markSet.getMarkInId(markGraphic.context.markId)) {\n if (markGraphic.hasState(state)) {\n if (this._resetType.includes('self')) {\n const newStatedGraphics = statedGraphics && statedGraphics.filter(g => g !== markGraphic);\n\n if (newStatedGraphics && newStatedGraphics.length) {\n interaction.setStatedGraphics(\n this,\n interaction.updateStates(this, newStatedGraphics, statedGraphics, state, reverseState)\n );\n } else {\n this.resetAll(e);\n }\n }\n } else {\n if (this._timer) {\n clearTimeout(this._timer);\n }\n addGraphicState(markGraphic, state, true);\n\n const newStatedGraphics = this.options.interaction.updateStates(\n this,\n isMultiple && statedGraphics ? [...statedGraphics, markGraphic] : [markGraphic],\n statedGraphics,\n state,\n reverseState\n );\n interaction.setStatedGraphics(this, newStatedGraphics);\n this.dispatchEvent('start', { graphics: newStatedGraphics, options: this.options, ...e });\n\n if (this._resetType.includes('timeout')) {\n this._timer = setTimeout(() => {\n this.resetAll(e);\n }, this.options.triggerOff as number) as unknown as number;\n }\n }\n } else if (this._resetType.includes('view') && statedGraphics && statedGraphics.length) {\n this.resetAll(e);\n }\n }\n\n reset(markGraphic: IMarkGraphic, e?: BaseEventParams) {\n if (markGraphic) {\n if (this._markSet.getMarkInId(markGraphic.context.markId)) {\n removeGraphicState(markGraphic, [this.options.state, this.options.reverseState]);\n }\n } else {\n this.resetAll(e);\n }\n }\n}\n\nexport const registerElementSelect = () => {\n Factory.registerInteractionTrigger(ElementSelect.type, ElementSelect);\n};\n"]}
@@ -155,6 +155,7 @@ export declare class BaseMark<T extends ICommonSpec> extends GrammarItem impleme
155
155
  protected _getEncoderOfStyle: (stateName: string, style: Partial<IAttrs<T>>) => Record<string, (datum: Datum) => any>;
156
156
  protected _setGraphicFromMarkConfig: (g: IMarkGraphic) => void;
157
157
  protected _setStateOfGraphic: (g: IMarkGraphic, hasAnimation?: boolean) => void;
158
+ protected _applySharedStateDefinitions(): void;
158
159
  protected _addProgressiveGraphic(parent: IGroup, g: IMarkGraphic): void;
159
160
  protected _runEncoder(graphics: IMarkGraphic[], noGroupEncode?: boolean): void;
160
161
  protected _runApplyGraphic(graphics: IMarkGraphic[]): void;