source: node_modules/recharts/lib/state/SetLegendPayload.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.4 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.SetLegendPayload = SetLegendPayload;
7exports.SetPolarLegendPayload = SetPolarLegendPayload;
8var _react = require("react");
9var _PanoramaContext = require("../context/PanoramaContext");
10var _chartLayoutContext = require("../context/chartLayoutContext");
11var _hooks = require("./hooks");
12var _legendSlice = require("./legendSlice");
13function SetLegendPayload(_ref) {
14 var {
15 legendPayload
16 } = _ref;
17 var dispatch = (0, _hooks.useAppDispatch)();
18 var isPanorama = (0, _PanoramaContext.useIsPanorama)();
19 var prevPayloadRef = (0, _react.useRef)(null);
20 (0, _react.useLayoutEffect)(() => {
21 if (isPanorama) {
22 return;
23 }
24 if (prevPayloadRef.current === null) {
25 dispatch((0, _legendSlice.addLegendPayload)(legendPayload));
26 } else if (prevPayloadRef.current !== legendPayload) {
27 dispatch((0, _legendSlice.replaceLegendPayload)({
28 prev: prevPayloadRef.current,
29 next: legendPayload
30 }));
31 }
32 prevPayloadRef.current = legendPayload;
33 }, [dispatch, isPanorama, legendPayload]);
34 (0, _react.useLayoutEffect)(() => {
35 return () => {
36 if (prevPayloadRef.current) {
37 dispatch((0, _legendSlice.removeLegendPayload)(prevPayloadRef.current));
38 prevPayloadRef.current = null;
39 }
40 };
41 }, [dispatch]);
42 return null;
43}
44function SetPolarLegendPayload(_ref2) {
45 var {
46 legendPayload
47 } = _ref2;
48 var dispatch = (0, _hooks.useAppDispatch)();
49 var layout = (0, _hooks.useAppSelector)(_chartLayoutContext.selectChartLayout);
50 var prevPayloadRef = (0, _react.useRef)(null);
51 (0, _react.useLayoutEffect)(() => {
52 if (layout !== 'centric' && layout !== 'radial') {
53 return;
54 }
55 if (prevPayloadRef.current === null) {
56 dispatch((0, _legendSlice.addLegendPayload)(legendPayload));
57 } else if (prevPayloadRef.current !== legendPayload) {
58 dispatch((0, _legendSlice.replaceLegendPayload)({
59 prev: prevPayloadRef.current,
60 next: legendPayload
61 }));
62 }
63 prevPayloadRef.current = legendPayload;
64 }, [dispatch, layout, legendPayload]);
65 (0, _react.useLayoutEffect)(() => {
66 return () => {
67 if (prevPayloadRef.current) {
68 dispatch((0, _legendSlice.removeLegendPayload)(prevPayloadRef.current));
69 prevPayloadRef.current = null;
70 }
71 };
72 }, [dispatch]);
73 return null;
74}
Note: See TracBrowser for help on using the repository browser.