| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.Fisheye = void 0;
- const util_1 = require("@antv/util");
- const utils_1 = require("./utils");
- function maybeCoordinate(options) {
- const { coordinate = {} } = options;
- const { transform = [] } = coordinate;
- const fisheye = transform.find((d) => d.type === 'fisheye');
- if (fisheye)
- return fisheye;
- const newFisheye = { type: 'fisheye' };
- transform.push(newFisheye);
- coordinate.transform = transform;
- options.coordinate = coordinate;
- return newFisheye;
- }
- /**
- * @todo Bind abstract data or data index.
- */
- function Fisheye({ wait = 30, leading, trailing = false, }) {
- return (context) => {
- const { options, update, container } = context;
- const plotArea = (0, utils_1.selectPlotArea)(container);
- // Clone options and mutate it.
- // Disable animation.
- const clonedOptions = (0, util_1.deepMix)({}, options);
- for (const mark of clonedOptions.marks)
- mark.animate = false;
- const updateFocus = (0, util_1.throttle)((event) => {
- const focus = (0, utils_1.mousePosition)(plotArea, event);
- if (!focus) {
- update(options);
- return;
- }
- const [x, y] = focus;
- const fisheye = maybeCoordinate(clonedOptions);
- fisheye.focusX = x;
- fisheye.focusY = y;
- fisheye.visual = true;
- update(clonedOptions);
- }, wait, { leading, trailing });
- // Bind events.
- plotArea.addEventListener('pointerenter', updateFocus);
- plotArea.addEventListener('pointermove', updateFocus);
- plotArea.addEventListener('pointerleave', updateFocus);
- return () => {
- plotArea.removeEventListener('pointerenter', updateFocus);
- plotArea.removeEventListener('pointermove', updateFocus);
- plotArea.removeEventListener('pointerleave', updateFocus);
- };
- };
- }
- exports.Fisheye = Fisheye;
- //# sourceMappingURL=fisheye.js.map
|