source: node_modules/recharts/lib/context/ErrorBarContext.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.4 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.ReportErrorBarSettings = ReportErrorBarSettings;
7exports.SetErrorBarContext = SetErrorBarContext;
8exports.useErrorBarContext = void 0;
9var _react = _interopRequireWildcard(require("react"));
10var React = _react;
11var _errorBarSlice = require("../state/errorBarSlice");
12var _hooks = require("../state/hooks");
13var _RegisterGraphicalItemId = require("./RegisterGraphicalItemId");
14var _excluded = ["children"];
15function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
16function _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; }
17function _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; }
18var initialContextState = {
19 data: [],
20 xAxisId: 'xAxis-0',
21 yAxisId: 'yAxis-0',
22 dataPointFormatter: () => ({
23 x: 0,
24 y: 0,
25 value: 0
26 }),
27 errorBarOffset: 0
28};
29var ErrorBarContext = /*#__PURE__*/(0, _react.createContext)(initialContextState);
30function SetErrorBarContext(props) {
31 var {
32 children
33 } = props,
34 rest = _objectWithoutProperties(props, _excluded);
35 return /*#__PURE__*/React.createElement(ErrorBarContext.Provider, {
36 value: rest
37 }, children);
38}
39var useErrorBarContext = () => (0, _react.useContext)(ErrorBarContext);
40exports.useErrorBarContext = useErrorBarContext;
41function ReportErrorBarSettings(props) {
42 var dispatch = (0, _hooks.useAppDispatch)();
43 var graphicalItemId = (0, _RegisterGraphicalItemId.useGraphicalItemId)();
44 var prevPropsRef = (0, _react.useRef)(null);
45 (0, _react.useEffect)(() => {
46 if (graphicalItemId == null) {
47 // ErrorBar outside a graphical item context does not do anything.
48 return;
49 }
50 if (prevPropsRef.current === null) {
51 dispatch((0, _errorBarSlice.addErrorBar)({
52 itemId: graphicalItemId,
53 errorBar: props
54 }));
55 } else if (prevPropsRef.current !== props) {
56 dispatch((0, _errorBarSlice.replaceErrorBar)({
57 itemId: graphicalItemId,
58 prev: prevPropsRef.current,
59 next: props
60 }));
61 }
62 prevPropsRef.current = props;
63 }, [dispatch, graphicalItemId, props]);
64 (0, _react.useEffect)(() => {
65 return () => {
66 if (prevPropsRef.current != null && graphicalItemId != null) {
67 dispatch((0, _errorBarSlice.removeErrorBar)({
68 itemId: graphicalItemId,
69 errorBar: prevPropsRef.current
70 }));
71 prevPropsRef.current = null;
72 }
73 };
74 }, [dispatch, graphicalItemId]);
75 return null;
76}
Note: See TracBrowser for help on using the repository browser.