| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.ReportErrorBarSettings = ReportErrorBarSettings;
|
|---|
| 7 | exports.SetErrorBarContext = SetErrorBarContext;
|
|---|
| 8 | exports.useErrorBarContext = void 0;
|
|---|
| 9 | var _react = _interopRequireWildcard(require("react"));
|
|---|
| 10 | var React = _react;
|
|---|
| 11 | var _errorBarSlice = require("../state/errorBarSlice");
|
|---|
| 12 | var _hooks = require("../state/hooks");
|
|---|
| 13 | var _RegisterGraphicalItemId = require("./RegisterGraphicalItemId");
|
|---|
| 14 | var _excluded = ["children"];
|
|---|
| 15 | function _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); }
|
|---|
| 16 | function _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; }
|
|---|
| 17 | function _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; }
|
|---|
| 18 | var 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 | };
|
|---|
| 29 | var ErrorBarContext = /*#__PURE__*/(0, _react.createContext)(initialContextState);
|
|---|
| 30 | function 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 | }
|
|---|
| 39 | var useErrorBarContext = () => (0, _react.useContext)(ErrorBarContext);
|
|---|
| 40 | exports.useErrorBarContext = useErrorBarContext;
|
|---|
| 41 | function 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 | } |
|---|