| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.SetLegendPayload = SetLegendPayload;
|
|---|
| 7 | exports.SetPolarLegendPayload = SetPolarLegendPayload;
|
|---|
| 8 | var _react = require("react");
|
|---|
| 9 | var _PanoramaContext = require("../context/PanoramaContext");
|
|---|
| 10 | var _chartLayoutContext = require("../context/chartLayoutContext");
|
|---|
| 11 | var _hooks = require("./hooks");
|
|---|
| 12 | var _legendSlice = require("./legendSlice");
|
|---|
| 13 | function 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 | }
|
|---|
| 44 | function 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 | } |
|---|