source: node_modules/recharts/es6/context/ErrorBarContext.js@ a762898

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

Added visualizations

  • Property mode set to 100644
File size: 2.4 KB
Line 
1var _excluded = ["children"];
2function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
3function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
4import * as React from 'react';
5import { createContext, useContext, useEffect, useRef } from 'react';
6import { addErrorBar, removeErrorBar, replaceErrorBar } from '../state/errorBarSlice';
7import { useAppDispatch } from '../state/hooks';
8import { useGraphicalItemId } from './RegisterGraphicalItemId';
9var initialContextState = {
10 data: [],
11 xAxisId: 'xAxis-0',
12 yAxisId: 'yAxis-0',
13 dataPointFormatter: () => ({
14 x: 0,
15 y: 0,
16 value: 0
17 }),
18 errorBarOffset: 0
19};
20var ErrorBarContext = /*#__PURE__*/createContext(initialContextState);
21export function SetErrorBarContext(props) {
22 var {
23 children
24 } = props,
25 rest = _objectWithoutProperties(props, _excluded);
26 return /*#__PURE__*/React.createElement(ErrorBarContext.Provider, {
27 value: rest
28 }, children);
29}
30export var useErrorBarContext = () => useContext(ErrorBarContext);
31export function ReportErrorBarSettings(props) {
32 var dispatch = useAppDispatch();
33 var graphicalItemId = useGraphicalItemId();
34 var prevPropsRef = useRef(null);
35 useEffect(() => {
36 if (graphicalItemId == null) {
37 // ErrorBar outside a graphical item context does not do anything.
38 return;
39 }
40 if (prevPropsRef.current === null) {
41 dispatch(addErrorBar({
42 itemId: graphicalItemId,
43 errorBar: props
44 }));
45 } else if (prevPropsRef.current !== props) {
46 dispatch(replaceErrorBar({
47 itemId: graphicalItemId,
48 prev: prevPropsRef.current,
49 next: props
50 }));
51 }
52 prevPropsRef.current = props;
53 }, [dispatch, graphicalItemId, props]);
54 useEffect(() => {
55 return () => {
56 if (prevPropsRef.current != null && graphicalItemId != null) {
57 dispatch(removeErrorBar({
58 itemId: graphicalItemId,
59 errorBar: prevPropsRef.current
60 }));
61 prevPropsRef.current = null;
62 }
63 };
64 }, [dispatch, graphicalItemId]);
65 return null;
66}
Note: See TracBrowser for help on using the repository browser.