source: node_modules/recharts/lib/state/touchEventsMiddleware.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 3.2 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.touchEventMiddleware = exports.touchEventAction = void 0;
7var _toolkit = require("@reduxjs/toolkit");
8var _tooltipSlice = require("./tooltipSlice");
9var _selectActivePropsFromChartPointer = require("./selectors/selectActivePropsFromChartPointer");
10var _getChartPointer = require("../util/getChartPointer");
11var _selectTooltipEventType = require("./selectors/selectTooltipEventType");
12var _Constants = require("../util/Constants");
13var _touchSelectors = require("./selectors/touchSelectors");
14var _tooltipSelectors = require("./selectors/tooltipSelectors");
15var touchEventAction = exports.touchEventAction = (0, _toolkit.createAction)('touchMove');
16var touchEventMiddleware = exports.touchEventMiddleware = (0, _toolkit.createListenerMiddleware)();
17touchEventMiddleware.startListening({
18 actionCreator: touchEventAction,
19 effect: (action, listenerApi) => {
20 var touchEvent = action.payload;
21 if (touchEvent.touches == null || touchEvent.touches.length === 0) {
22 return;
23 }
24 var state = listenerApi.getState();
25 var tooltipEventType = (0, _selectTooltipEventType.selectTooltipEventType)(state, state.tooltip.settings.shared);
26 if (tooltipEventType === 'axis') {
27 var touch = touchEvent.touches[0];
28 if (touch == null) {
29 return;
30 }
31 var activeProps = (0, _selectActivePropsFromChartPointer.selectActivePropsFromChartPointer)(state, (0, _getChartPointer.getChartPointer)({
32 clientX: touch.clientX,
33 clientY: touch.clientY,
34 currentTarget: touchEvent.currentTarget
35 }));
36 if ((activeProps === null || activeProps === void 0 ? void 0 : activeProps.activeIndex) != null) {
37 listenerApi.dispatch((0, _tooltipSlice.setMouseOverAxisIndex)({
38 activeIndex: activeProps.activeIndex,
39 activeDataKey: undefined,
40 activeCoordinate: activeProps.activeCoordinate
41 }));
42 }
43 } else if (tooltipEventType === 'item') {
44 var _target$getAttribute;
45 var _touch = touchEvent.touches[0];
46 if (document.elementFromPoint == null || _touch == null) {
47 return;
48 }
49 var target = document.elementFromPoint(_touch.clientX, _touch.clientY);
50 if (!target || !target.getAttribute) {
51 return;
52 }
53 var itemIndex = target.getAttribute(_Constants.DATA_ITEM_INDEX_ATTRIBUTE_NAME);
54 var graphicalItemId = (_target$getAttribute = target.getAttribute(_Constants.DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME)) !== null && _target$getAttribute !== void 0 ? _target$getAttribute : undefined;
55 var settings = (0, _tooltipSelectors.selectAllGraphicalItemsSettings)(state).find(item => item.id === graphicalItemId);
56 if (itemIndex == null || settings == null || graphicalItemId == null) {
57 return;
58 }
59 var {
60 dataKey
61 } = settings;
62 var coordinate = (0, _touchSelectors.selectTooltipCoordinate)(state, itemIndex, graphicalItemId);
63 listenerApi.dispatch((0, _tooltipSlice.setActiveMouseOverItemIndex)({
64 activeDataKey: dataKey,
65 activeIndex: itemIndex,
66 activeCoordinate: coordinate,
67 activeGraphicalItemId: graphicalItemId
68 }));
69 }
70 }
71});
Note: See TracBrowser for help on using the repository browser.