drill-down.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.isParentNode = void 0;
  4. var g2_1 = require("@antv/g2");
  5. var util_1 = require("@antv/util");
  6. var drill_down_1 = require("./actions/drill-down");
  7. /**
  8. * 判断是否为父节点
  9. */
  10. function isParentNode(context) {
  11. var data = (0, util_1.get)(context, ['event', 'data', 'data'], {});
  12. return (0, util_1.isArray)(data.children) && data.children.length > 0;
  13. }
  14. exports.isParentNode = isParentNode;
  15. /**
  16. * 判断是否在中心
  17. */
  18. function inCenter(context) {
  19. var coordinate = context.view.getCoordinate();
  20. var innerRadius = coordinate.innerRadius;
  21. if (innerRadius) {
  22. var _a = context.event, x = _a.x, y = _a.y;
  23. var _b = coordinate.center, centerX = _b.x, centerY = _b.y;
  24. var r = coordinate.getRadius() * innerRadius;
  25. var distance = Math.sqrt(Math.pow((centerX - x), 2) + Math.pow((centerY - y), 2));
  26. return distance < r;
  27. }
  28. return false;
  29. }
  30. (0, g2_1.registerAction)('drill-down-action', drill_down_1.DrillDownAction);
  31. (0, g2_1.registerInteraction)('drill-down', {
  32. showEnable: [
  33. { trigger: 'element:mouseenter', action: 'cursor:pointer', isEnable: isParentNode },
  34. { trigger: 'element:mouseleave', action: 'cursor:default' },
  35. // 中心处,肯定会触发 element:mouseleave 操作
  36. { trigger: 'element:mouseleave', action: 'cursor:pointer', isEnable: inCenter },
  37. ],
  38. start: [
  39. {
  40. trigger: 'element:click',
  41. isEnable: isParentNode,
  42. action: ['drill-down-action:click'],
  43. },
  44. {
  45. trigger: 'afterchangesize',
  46. action: ['drill-down-action:resetPosition'],
  47. },
  48. {
  49. // 点击中心,返回上一层
  50. trigger: 'click',
  51. isEnable: inCenter,
  52. action: ['drill-down-action:back'],
  53. },
  54. ],
  55. });
  56. //# sourceMappingURL=drill-down.js.map