source: node_modules/recharts/lib/context/chartDataContext.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.0 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.useDataIndex = exports.useChartData = exports.SetComputedData = exports.ChartDataContextProvider = void 0;
7var _react = require("react");
8var _chartDataSlice = require("../state/chartDataSlice");
9var _hooks = require("../state/hooks");
10var _PanoramaContext = require("./PanoramaContext");
11var ChartDataContextProvider = props => {
12 var {
13 chartData
14 } = props;
15 var dispatch = (0, _hooks.useAppDispatch)();
16 var isPanorama = (0, _PanoramaContext.useIsPanorama)();
17 (0, _react.useEffect)(() => {
18 if (isPanorama) {
19 // Panorama mode reuses data from the main chart, so we must not overwrite it here.
20 return () => {
21 // there is nothing to clean up
22 };
23 }
24 dispatch((0, _chartDataSlice.setChartData)(chartData));
25 return () => {
26 dispatch((0, _chartDataSlice.setChartData)(undefined));
27 };
28 }, [chartData, dispatch, isPanorama]);
29 return null;
30};
31exports.ChartDataContextProvider = ChartDataContextProvider;
32var SetComputedData = props => {
33 var {
34 computedData
35 } = props;
36 var dispatch = (0, _hooks.useAppDispatch)();
37 (0, _react.useEffect)(() => {
38 dispatch((0, _chartDataSlice.setComputedData)(computedData));
39 return () => {
40 dispatch((0, _chartDataSlice.setChartData)(undefined));
41 };
42 }, [computedData, dispatch]);
43 return null;
44};
45exports.SetComputedData = SetComputedData;
46var selectChartData = state => state.chartData.chartData;
47
48/**
49 * "data" is the data of the chart - it has no type because this part of recharts is very flexible.
50 * Basically it's an array of "something" and then there's the dataKey property in various places
51 * that's meant to pull other things away from the data.
52 *
53 * Some charts have `data` defined on the chart root, and they will return the array through this hook.
54 * For example: <ComposedChart data={data} />.
55 *
56 * Other charts, such as Pie, have data defined on individual graphical elements.
57 * These charts will return `undefined` through this hook, and you need to read the data from children.
58 * For example: <PieChart><Pie data={data} />
59 *
60 * Some charts also allow setting both - data on the parent, and data on the children at the same time!
61 * However, this particular selector will only return the ones defined on the parent.
62 *
63 * @deprecated use one of the other selectors instead - which one, depends on how do you identify the applicable graphical items.
64 *
65 * @return data array for some charts and undefined for other
66 */
67var useChartData = () => (0, _hooks.useAppSelector)(selectChartData);
68exports.useChartData = useChartData;
69var selectDataIndex = state => {
70 var {
71 dataStartIndex,
72 dataEndIndex
73 } = state.chartData;
74 return {
75 startIndex: dataStartIndex,
76 endIndex: dataEndIndex
77 };
78};
79
80/**
81 * startIndex and endIndex are data boundaries, set through Brush.
82 *
83 * @return object with startIndex and endIndex
84 */
85var useDataIndex = () => {
86 return (0, _hooks.useAppSelector)(selectDataIndex);
87};
88exports.useDataIndex = useDataIndex;
Note: See TracBrowser for help on using the repository browser.