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