hoverNodeActived.js 908 B

1234567891011121314151617181920212223242526272829
  1. import { Marker } from '@antv/g-canvas/lib/shape';
  2. export default function(G6){
  3. G6.registerBehavior('hoverNodeActived', {
  4. getEvents() {
  5. return {
  6. 'node:mouseenter': 'onNodeEnter',
  7. 'node:mouseleave': 'onNodeLeave',
  8. 'anchor:mouseleave': 'onAnchorLeave',
  9. }
  10. },
  11. onAnchorLeave(e){
  12. let node = e.item.getContainer().getParent();
  13. if(node && !this.graph.get('edgeDragging')) {
  14. this.graph.setItemState(node.get('item'), 'show-anchor', false);
  15. }
  16. },
  17. onNodeEnter(e){
  18. const clazz = e.item.getModel().clazz;
  19. if(clazz !== 'endEvent' && !this.graph.get('edgeDragging')){
  20. this.graph.setItemState(e.item, 'show-anchor', true);
  21. }
  22. },
  23. onNodeLeave(e){
  24. if(!(e.target instanceof Marker) && !this.graph.get('edgeDragging')) {
  25. this.graph.setItemState(e.item, 'show-anchor', false);
  26. }
  27. },
  28. });
  29. }