|
|
import { useEffect } from 'react'; |
|
|
import { ChartData, setChartData, setComputedData } from '../state/chartDataSlice'; |
|
|
import { useAppDispatch, useAppSelector } from '../state/hooks'; |
|
|
import { RechartsRootState } from '../state/store'; |
|
|
import { BrushStartEndIndex } from './brushUpdateContext'; |
|
|
import { useIsPanorama } from './PanoramaContext'; |
|
|
|
|
|
export const ChartDataContextProvider = (props: { chartData: ChartData | undefined }): null => { |
|
|
const { chartData } = props; |
|
|
const dispatch = useAppDispatch(); |
|
|
const isPanorama = useIsPanorama(); |
|
|
useEffect(() => { |
|
|
if (isPanorama) { |
|
|
|
|
|
return () => { |
|
|
|
|
|
}; |
|
|
} |
|
|
dispatch(setChartData(chartData)); |
|
|
return () => { |
|
|
dispatch(setChartData(undefined)); |
|
|
}; |
|
|
}, [chartData, dispatch, isPanorama]); |
|
|
return null; |
|
|
}; |
|
|
|
|
|
export const SetComputedData = (props: { computedData: any }): null => { |
|
|
const { computedData } = props; |
|
|
const dispatch = useAppDispatch(); |
|
|
useEffect(() => { |
|
|
dispatch(setComputedData(computedData)); |
|
|
return () => { |
|
|
dispatch(setChartData(undefined)); |
|
|
}; |
|
|
}, [computedData, dispatch]); |
|
|
return null; |
|
|
}; |
|
|
|
|
|
const selectChartData = (state: RechartsRootState): ChartData | undefined => state.chartData.chartData; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const useChartData = (): ChartData | undefined => useAppSelector(selectChartData); |
|
|
|
|
|
const selectDataIndex = (state: RechartsRootState): BrushStartEndIndex => { |
|
|
const { dataStartIndex, dataEndIndex } = state.chartData; |
|
|
return { startIndex: dataStartIndex, endIndex: dataEndIndex }; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const useDataIndex = () => { |
|
|
return useAppSelector(selectDataIndex); |
|
|
}; |
|
|
|