fisheye.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Fisheye = void 0;
  4. const util_1 = require("@antv/util");
  5. const utils_1 = require("./utils");
  6. function maybeCoordinate(options) {
  7. const { coordinate = {} } = options;
  8. const { transform = [] } = coordinate;
  9. const fisheye = transform.find((d) => d.type === 'fisheye');
  10. if (fisheye)
  11. return fisheye;
  12. const newFisheye = { type: 'fisheye' };
  13. transform.push(newFisheye);
  14. coordinate.transform = transform;
  15. options.coordinate = coordinate;
  16. return newFisheye;
  17. }
  18. /**
  19. * @todo Bind abstract data or data index.
  20. */
  21. function Fisheye({ wait = 30, leading, trailing = false, }) {
  22. return (context) => {
  23. const { options, update, container } = context;
  24. const plotArea = (0, utils_1.selectPlotArea)(container);
  25. // Clone options and mutate it.
  26. // Disable animation.
  27. const clonedOptions = (0, util_1.deepMix)({}, options);
  28. for (const mark of clonedOptions.marks)
  29. mark.animate = false;
  30. const updateFocus = (0, util_1.throttle)((event) => {
  31. const focus = (0, utils_1.mousePosition)(plotArea, event);
  32. if (!focus) {
  33. update(options);
  34. return;
  35. }
  36. const [x, y] = focus;
  37. const fisheye = maybeCoordinate(clonedOptions);
  38. fisheye.focusX = x;
  39. fisheye.focusY = y;
  40. fisheye.visual = true;
  41. update(clonedOptions);
  42. }, wait, { leading, trailing });
  43. // Bind events.
  44. plotArea.addEventListener('pointerenter', updateFocus);
  45. plotArea.addEventListener('pointermove', updateFocus);
  46. plotArea.addEventListener('pointerleave', updateFocus);
  47. return () => {
  48. plotArea.removeEventListener('pointerenter', updateFocus);
  49. plotArea.removeEventListener('pointermove', updateFocus);
  50. plotArea.removeEventListener('pointerleave', updateFocus);
  51. };
  52. };
  53. }
  54. exports.Fisheye = Fisheye;
  55. //# sourceMappingURL=fisheye.js.map