source: node_modules/recharts/es6/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: 2.9 KB
RevLine 
[a762898]1import { createAction, createListenerMiddleware } from '@reduxjs/toolkit';
2import { setActiveMouseOverItemIndex, setMouseOverAxisIndex } from './tooltipSlice';
3import { selectActivePropsFromChartPointer } from './selectors/selectActivePropsFromChartPointer';
4import { getChartPointer } from '../util/getChartPointer';
5import { selectTooltipEventType } from './selectors/selectTooltipEventType';
6import { DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME, DATA_ITEM_INDEX_ATTRIBUTE_NAME } from '../util/Constants';
7import { selectTooltipCoordinate } from './selectors/touchSelectors';
8import { selectAllGraphicalItemsSettings } from './selectors/tooltipSelectors';
9export var touchEventAction = createAction('touchMove');
10export var touchEventMiddleware = createListenerMiddleware();
11touchEventMiddleware.startListening({
12 actionCreator: touchEventAction,
13 effect: (action, listenerApi) => {
14 var touchEvent = action.payload;
15 if (touchEvent.touches == null || touchEvent.touches.length === 0) {
16 return;
17 }
18 var state = listenerApi.getState();
19 var tooltipEventType = selectTooltipEventType(state, state.tooltip.settings.shared);
20 if (tooltipEventType === 'axis') {
21 var touch = touchEvent.touches[0];
22 if (touch == null) {
23 return;
24 }
25 var activeProps = selectActivePropsFromChartPointer(state, getChartPointer({
26 clientX: touch.clientX,
27 clientY: touch.clientY,
28 currentTarget: touchEvent.currentTarget
29 }));
30 if ((activeProps === null || activeProps === void 0 ? void 0 : activeProps.activeIndex) != null) {
31 listenerApi.dispatch(setMouseOverAxisIndex({
32 activeIndex: activeProps.activeIndex,
33 activeDataKey: undefined,
34 activeCoordinate: activeProps.activeCoordinate
35 }));
36 }
37 } else if (tooltipEventType === 'item') {
38 var _target$getAttribute;
39 var _touch = touchEvent.touches[0];
40 if (document.elementFromPoint == null || _touch == null) {
41 return;
42 }
43 var target = document.elementFromPoint(_touch.clientX, _touch.clientY);
44 if (!target || !target.getAttribute) {
45 return;
46 }
47 var itemIndex = target.getAttribute(DATA_ITEM_INDEX_ATTRIBUTE_NAME);
48 var graphicalItemId = (_target$getAttribute = target.getAttribute(DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME)) !== null && _target$getAttribute !== void 0 ? _target$getAttribute : undefined;
49 var settings = selectAllGraphicalItemsSettings(state).find(item => item.id === graphicalItemId);
50 if (itemIndex == null || settings == null || graphicalItemId == null) {
51 return;
52 }
53 var {
54 dataKey
55 } = settings;
56 var coordinate = selectTooltipCoordinate(state, itemIndex, graphicalItemId);
57 listenerApi.dispatch(setActiveMouseOverItemIndex({
58 activeDataKey: dataKey,
59 activeIndex: itemIndex,
60 activeCoordinate: coordinate,
61 activeGraphicalItemId: graphicalItemId
62 }));
63 }
64 }
65});
Note: See TracBrowser for help on using the repository browser.