@octanejs/recharts 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +53 -0
- package/src/animation/AnimatedItems.tsrx +82 -0
- package/src/animation/AnimationControllerImpl.js +33 -0
- package/src/animation/AnimationHandle.js +291 -0
- package/src/animation/JavascriptAnimate.tsrx +81 -0
- package/src/animation/easing.js +193 -0
- package/src/animation/matchBy.js +279 -0
- package/src/animation/timeoutController.js +49 -0
- package/src/animation/useAnimationController.ts +22 -0
- package/src/animation/useAnimationStartSnapshot.ts +43 -0
- package/src/animation/util.js +11 -0
- package/src/cartesian/Bar.ts +4 -0
- package/src/cartesian/Bar.tsrx +716 -0
- package/src/cartesian/Bar.tsrx.d.ts +4 -0
- package/src/cartesian/BarStack.tsrx +97 -0
- package/src/cartesian/BarStack.tsrx.d.ts +6 -0
- package/src/cartesian/CartesianAxis.tsrx +413 -0
- package/src/cartesian/CartesianAxis.tsrx.d.ts +3 -0
- package/src/cartesian/GraphicalItemClipPath.tsrx +44 -0
- package/src/cartesian/Line.ts +4 -0
- package/src/cartesian/Line.tsrx +544 -0
- package/src/cartesian/Line.tsrx.d.ts +4 -0
- package/src/cartesian/LineDrawShape.tsrx +106 -0
- package/src/cartesian/LineDrawShape.tsrx.d.ts +2 -0
- package/src/cartesian/XAxis.tsrx +156 -0
- package/src/cartesian/XAxis.tsrx.d.ts +3 -0
- package/src/cartesian/YAxis.tsrx +183 -0
- package/src/cartesian/YAxis.tsrx.d.ts +3 -0
- package/src/cartesian/getCartesianPosition.js +277 -0
- package/src/cartesian/getEquidistantTicks.js +133 -0
- package/src/cartesian/getTicks.js +280 -0
- package/src/cartesian/useAnimatedLineLength.ts +33 -0
- package/src/chart/BarChart.tsrx +22 -0
- package/src/chart/BarChart.tsrx.d.ts +2 -0
- package/src/chart/CartesianChart.tsrx +76 -0
- package/src/chart/CartesianChart.tsrx.d.ts +10 -0
- package/src/chart/CategoricalChart.tsrx +54 -0
- package/src/chart/LineChart.tsrx +22 -0
- package/src/chart/LineChart.tsrx.d.ts +2 -0
- package/src/chart/RechartsWrapper.tsrx +294 -0
- package/src/component/ActivePoints.tsrx +76 -0
- package/src/component/Cell.ts +37 -0
- package/src/component/Dots.tsrx +74 -0
- package/src/component/Label.tsrx +309 -0
- package/src/component/Label.tsrx.d.ts +12 -0
- package/src/component/LabelList.tsrx +83 -0
- package/src/component/LabelList.tsrx.d.ts +8 -0
- package/src/component/ResponsiveContainer.ts +22 -0
- package/src/component/Text.tsrx +281 -0
- package/src/component/Text.tsrx.d.ts +9 -0
- package/src/component/responsiveContainerUtils.js +111 -0
- package/src/container/ClipPathProvider.tsrx +29 -0
- package/src/container/Layer.tsrx +9 -0
- package/src/container/Layer.tsrx.d.ts +6 -0
- package/src/container/RootSurface.tsrx +76 -0
- package/src/container/Surface.tsrx +23 -0
- package/src/container/Surface.tsrx.d.ts +12 -0
- package/src/context/CellsContext.ts +80 -0
- package/src/context/ErrorBarContext.tsrx +53 -0
- package/src/context/PanoramaContext.ts +10 -0
- package/src/context/RegisterGraphicalItemId.tsrx +19 -0
- package/src/context/accessibilityContext.js +10 -0
- package/src/context/chartDataContext.ts +57 -0
- package/src/context/chartLayoutContext.ts +171 -0
- package/src/context/legendPortalContext.ts +5 -0
- package/src/context/tooltipContext.js +55 -0
- package/src/context/tooltipPortalContext.ts +5 -0
- package/src/hooks.js +509 -0
- package/src/index.ts +64 -0
- package/src/internal.ts +37 -0
- package/src/polar/defaultPolarAngleAxisProps.js +27 -0
- package/src/polar/defaultPolarRadiusAxisProps.js +24 -0
- package/src/shape/Cross.tsrx +25 -0
- package/src/shape/Cross.tsrx.d.ts +12 -0
- package/src/shape/Curve.tsrx +132 -0
- package/src/shape/Curve.tsrx.d.ts +42 -0
- package/src/shape/Dot.tsrx +21 -0
- package/src/shape/Dot.tsrx.d.ts +9 -0
- package/src/shape/Polygon.tsrx +95 -0
- package/src/shape/Polygon.tsrx.d.ts +13 -0
- package/src/shape/Rectangle.tsrx +162 -0
- package/src/shape/Rectangle.tsrx.d.ts +31 -0
- package/src/shape/Sector.tsrx +219 -0
- package/src/shape/Sector.tsrx.d.ts +29 -0
- package/src/shape/Symbols.tsrx +95 -0
- package/src/shape/Symbols.tsrx.d.ts +15 -0
- package/src/shape/Trapezoid.tsrx +56 -0
- package/src/shape/Trapezoid.tsrx.d.ts +29 -0
- package/src/state/RechartsReduxContext.ts +7 -0
- package/src/state/RechartsStoreProvider.tsrx +24 -0
- package/src/state/ReportChartProps.ts +13 -0
- package/src/state/ReportEventSettings.ts +15 -0
- package/src/state/ReportMainChartProps.ts +22 -0
- package/src/state/SetGraphicalItem.ts +61 -0
- package/src/state/SetLegendPayload.ts +61 -0
- package/src/state/SetTooltipEntrySettings.ts +40 -0
- package/src/state/brushSlice.js +36 -0
- package/src/state/cartesianAxisSlice.js +256 -0
- package/src/state/chartDataSlice.js +67 -0
- package/src/state/errorBarSlice.js +53 -0
- package/src/state/eventSettingsSlice.js +25 -0
- package/src/state/externalEventsMiddleware.js +127 -0
- package/src/state/graphicalItemsSlice.js +91 -0
- package/src/state/hooks.ts +46 -0
- package/src/state/keyboardEventsMiddleware.js +226 -0
- package/src/state/layoutSlice.js +57 -0
- package/src/state/legendSlice.js +83 -0
- package/src/state/mouseEventsMiddleware.js +130 -0
- package/src/state/optionsSlice.js +45 -0
- package/src/state/polarAxisSlice.js +33 -0
- package/src/state/polarOptionsSlice.js +26 -0
- package/src/state/reduxDevtoolsJsonStringifyReplacer.js +14 -0
- package/src/state/referenceElementsSlice.js +51 -0
- package/src/state/renderedTicksSlice.js +41 -0
- package/src/state/rootPropsSlice.js +48 -0
- package/src/state/selectors/arrayEqualityCheck.js +32 -0
- package/src/state/selectors/axisSelectors.js +2113 -0
- package/src/state/selectors/barSelectors.js +263 -0
- package/src/state/selectors/barStackSelectors.js +65 -0
- package/src/state/selectors/brushSelectors.js +21 -0
- package/src/state/selectors/combiners/combineActiveLabel.js +18 -0
- package/src/state/selectors/combiners/combineActiveTooltipIndex.js +75 -0
- package/src/state/selectors/combiners/combineAllBarPositions.js +169 -0
- package/src/state/selectors/combiners/combineAxisRangeWithReverse.js +11 -0
- package/src/state/selectors/combiners/combineBarPosition.js +17 -0
- package/src/state/selectors/combiners/combineBarSizeList.js +115 -0
- package/src/state/selectors/combiners/combineCheckedDomain.js +44 -0
- package/src/state/selectors/combiners/combineConfiguredScale.js +46 -0
- package/src/state/selectors/combiners/combineCoordinateForDefaultIndex.js +48 -0
- package/src/state/selectors/combiners/combineDisplayedStackedData.js +54 -0
- package/src/state/selectors/combiners/combineInverseScaleFunction.js +12 -0
- package/src/state/selectors/combiners/combineRealScaleType.js +36 -0
- package/src/state/selectors/combiners/combineStackedData.js +22 -0
- package/src/state/selectors/combiners/combineTooltipInteractionState.js +121 -0
- package/src/state/selectors/combiners/combineTooltipPayload.js +248 -0
- package/src/state/selectors/combiners/combineTooltipPayloadConfigurations.js +59 -0
- package/src/state/selectors/containerSelectors.js +6 -0
- package/src/state/selectors/dataSelectors.js +97 -0
- package/src/state/selectors/graphicalItemSelectors.js +25 -0
- package/src/state/selectors/legendSelectors.js +18 -0
- package/src/state/selectors/lineSelectors.js +106 -0
- package/src/state/selectors/numberDomainEqualityCheck.js +11 -0
- package/src/state/selectors/pickAxisId.js +3 -0
- package/src/state/selectors/pickAxisType.js +3 -0
- package/src/state/selectors/polarAxisSelectors.js +237 -0
- package/src/state/selectors/rootPropsSelectors.js +13 -0
- package/src/state/selectors/selectActivePropsFromChartPointer.js +23 -0
- package/src/state/selectors/selectAllAxes.js +15 -0
- package/src/state/selectors/selectChartOffset.js +12 -0
- package/src/state/selectors/selectChartOffsetInternal.js +174 -0
- package/src/state/selectors/selectPlotArea.js +19 -0
- package/src/state/selectors/selectTooltipAxisId.js +3 -0
- package/src/state/selectors/selectTooltipAxisType.js +25 -0
- package/src/state/selectors/selectTooltipEventType.js +27 -0
- package/src/state/selectors/selectTooltipPayloadSearcher.js +3 -0
- package/src/state/selectors/selectTooltipSettings.js +3 -0
- package/src/state/selectors/selectTooltipState.js +3 -0
- package/src/state/selectors/selectors.js +222 -0
- package/src/state/selectors/tooltipSelectors.js +471 -0
- package/src/state/selectors/touchSelectors.js +31 -0
- package/src/state/store.js +101 -0
- package/src/state/tooltipSlice.js +237 -0
- package/src/state/touchEventsMiddleware.js +140 -0
- package/src/state/types/StackedGraphicalItem.js +18 -0
- package/src/state/zIndexSlice.js +167 -0
- package/src/synchronisation/syncSelectors.js +5 -0
- package/src/synchronisation/useChartSynchronisation.tsrx +285 -0
- package/src/util/ActiveShapeUtils.tsrx +62 -0
- package/src/util/BarUtils.tsrx +35 -0
- package/src/util/CartesianUtils.js +66 -0
- package/src/util/ChartUtils.js +630 -0
- package/src/util/Constants.js +42 -0
- package/src/util/DOMUtils.js +180 -0
- package/src/util/DataUtils.js +199 -0
- package/src/util/Events.js +7 -0
- package/src/util/Global.js +13 -0
- package/src/util/LRUCache.js +58 -0
- package/src/util/LogUtils.js +29 -0
- package/src/util/PolarUtils.js +190 -0
- package/src/util/ReactUtils.ts +94 -0
- package/src/util/ReduceCSSCalc.js +260 -0
- package/src/util/TickUtils.js +43 -0
- package/src/util/YAxisUtils.js +43 -0
- package/src/util/axisPropsAreEqual.js +63 -0
- package/src/util/createEventProxy.js +18 -0
- package/src/util/excludeEventProps.js +172 -0
- package/src/util/getActiveCoordinate.js +253 -0
- package/src/util/getAxisTypeBasedOnLayout.js +17 -0
- package/src/util/getClassNameFromUnknown.js +8 -0
- package/src/util/getEveryNth.js +29 -0
- package/src/util/getRadiusAndStrokeWidthFromDot.js +28 -0
- package/src/util/getRelativeCoordinate.js +96 -0
- package/src/util/getSliced.js +11 -0
- package/src/util/isDomainSpecifiedByUser.js +255 -0
- package/src/util/isWellBehavedNumber.js +8 -0
- package/src/util/propsAreEqual.js +96 -0
- package/src/util/resolveDefaultProps.js +131 -0
- package/src/util/round.js +39 -0
- package/src/util/scale/RechartsScale.js +68 -0
- package/src/util/scale/createCategoricalInverse.js +77 -0
- package/src/util/scale/getNiceTickValues.js +354 -0
- package/src/util/scale/index.js +3 -0
- package/src/util/scale/util/arithmetic.js +51 -0
- package/src/util/stacks/getStackSeriesIdentifier.js +10 -0
- package/src/util/svgPropertiesAndEvents.ts +29 -0
- package/src/util/svgPropertiesNoEvents.js +383 -0
- package/src/util/types.ts +59 -0
- package/src/util/useAnimationId.ts +14 -0
- package/src/util/useId.ts +13 -0
- package/src/util/usePrefersReducedMotion.ts +30 -0
- package/src/util/useReportScale.ts +26 -0
- package/src/util/useUniqueId.js +34 -0
- package/src/zIndex/DefaultZIndexes.js +75 -0
- package/src/zIndex/ZIndexLayer.tsrx +80 -0
- package/src/zIndex/ZIndexLayer.tsrx.d.ts +2 -0
- package/src/zIndex/ZIndexPortal.tsrx +43 -0
- package/src/zIndex/getZIndexFromUnknown.js +15 -0
- package/src/zIndex/zIndexSelectors.js +45 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Port of context/ErrorBarContext.tsx — the per-graphical-item settings an
|
|
2
|
+
// <ErrorBar> child reads, plus the reporter that registers error-bar presence
|
|
3
|
+
// in the store.
|
|
4
|
+
import { createContext, useContext, useEffect, useRef } from 'octane';
|
|
5
|
+
import { addErrorBar, removeErrorBar, replaceErrorBar } from '../state/errorBarSlice';
|
|
6
|
+
import { useAppDispatch } from '../state/hooks';
|
|
7
|
+
import { useGraphicalItemId } from './RegisterGraphicalItemId.tsrx';
|
|
8
|
+
|
|
9
|
+
const initialContextState = {
|
|
10
|
+
data: [],
|
|
11
|
+
xAxisId: 'xAxis-0',
|
|
12
|
+
yAxisId: 'yAxis-0',
|
|
13
|
+
dataPointFormatter: () => ({ x: 0, y: 0, value: 0 }),
|
|
14
|
+
errorBarOffset: 0,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const ErrorBarContext = createContext(initialContextState);
|
|
18
|
+
|
|
19
|
+
export function SetErrorBarContext(props) {
|
|
20
|
+
const { children, ...rest } = props;
|
|
21
|
+
return <ErrorBarContext.Provider value={rest}>{children}</ErrorBarContext.Provider>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const useErrorBarContext = () => useContext(ErrorBarContext);
|
|
25
|
+
|
|
26
|
+
export function ReportErrorBarSettings(props) {
|
|
27
|
+
const dispatch = useAppDispatch();
|
|
28
|
+
const graphicalItemId = useGraphicalItemId();
|
|
29
|
+
const prevPropsRef = useRef(null);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (graphicalItemId == null) {
|
|
32
|
+
// ErrorBar outside a graphical item context does not do anything.
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (prevPropsRef.current === null) {
|
|
36
|
+
dispatch(addErrorBar({ itemId: graphicalItemId, errorBar: props }));
|
|
37
|
+
} else if (prevPropsRef.current !== props) {
|
|
38
|
+
dispatch(
|
|
39
|
+
replaceErrorBar({ itemId: graphicalItemId, prev: prevPropsRef.current, next: props }),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
prevPropsRef.current = props;
|
|
43
|
+
}, [dispatch, graphicalItemId, props]);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
return () => {
|
|
46
|
+
if (prevPropsRef.current != null && graphicalItemId != null) {
|
|
47
|
+
dispatch(removeErrorBar({ itemId: graphicalItemId, errorBar: prevPropsRef.current }));
|
|
48
|
+
prevPropsRef.current = null;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}, [dispatch, graphicalItemId]);
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Port of context/PanoramaContext.ts. A "panorama" chart is the mini-chart
|
|
2
|
+
// preview inside <Brush> — it renders WITHOUT its own store provider and
|
|
3
|
+
// inherits the parent chart's store.
|
|
4
|
+
import { createContext, useContext } from 'octane';
|
|
5
|
+
|
|
6
|
+
export const PanoramaContext = createContext<boolean | null>(null);
|
|
7
|
+
|
|
8
|
+
export function useIsPanorama(): boolean {
|
|
9
|
+
return useContext(PanoramaContext) != null;
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Port of context/RegisterGraphicalItemId.tsx — mints a stable per-item id
|
|
2
|
+
// (user override wins) and provides it to descendants via context. `children`
|
|
3
|
+
// is a RENDER PROP receiving the resolved id.
|
|
4
|
+
import { createContext, useContext } from 'octane';
|
|
5
|
+
import { useUniqueId } from '../util/useUniqueId';
|
|
6
|
+
|
|
7
|
+
const GraphicalItemIdContext = createContext(undefined);
|
|
8
|
+
|
|
9
|
+
export function RegisterGraphicalItemId(props) {
|
|
10
|
+
const { id, type, children } = props;
|
|
11
|
+
const resolvedId = useUniqueId('recharts-' + type, id);
|
|
12
|
+
return <GraphicalItemIdContext.Provider value={resolvedId}>{children(
|
|
13
|
+
resolvedId,
|
|
14
|
+
)}</GraphicalItemIdContext.Provider>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function useGraphicalItemId() {
|
|
18
|
+
return useContext(GraphicalItemIdContext);
|
|
19
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Vendored verbatim from recharts@3.9.2 es6/context/accessibilityContext.js (framework-agnostic).
|
|
2
|
+
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
+
import { useAppSelector } from '../state/hooks';
|
|
4
|
+
export var useAccessibilityLayer = () => {
|
|
5
|
+
var _useAppSelector;
|
|
6
|
+
return (_useAppSelector = useAppSelector((state) => state.rootProps.accessibilityLayer)) !==
|
|
7
|
+
null && _useAppSelector !== void 0
|
|
8
|
+
? _useAppSelector
|
|
9
|
+
: true;
|
|
10
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Port of context/chartDataContext.tsx — reporter components that publish the
|
|
2
|
+
// chart's `data` prop into the store, plus the read hooks.
|
|
3
|
+
import { useEffect } from 'octane';
|
|
4
|
+
import { setChartData, setComputedData } from '../state/chartDataSlice';
|
|
5
|
+
import { useAppDispatch, useAppSelector } from '../state/hooks';
|
|
6
|
+
import { useIsPanorama } from './PanoramaContext';
|
|
7
|
+
import { splitSlot, subSlot } from '../internal';
|
|
8
|
+
|
|
9
|
+
export const ChartDataContextProvider = (props: { chartData: unknown }): null => {
|
|
10
|
+
const { chartData } = props;
|
|
11
|
+
const dispatch = useAppDispatch();
|
|
12
|
+
const isPanorama = useIsPanorama();
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (isPanorama) {
|
|
15
|
+
// Panorama mode reuses data from the main chart, so we must not overwrite it here.
|
|
16
|
+
return () => {
|
|
17
|
+
// there is nothing to clean up
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
dispatch(setChartData(chartData));
|
|
21
|
+
return () => {
|
|
22
|
+
dispatch(setChartData(undefined));
|
|
23
|
+
};
|
|
24
|
+
}, [chartData, dispatch, isPanorama]);
|
|
25
|
+
return null;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const SetComputedData = (props: { computedData: unknown }): null => {
|
|
29
|
+
const { computedData } = props;
|
|
30
|
+
const dispatch = useAppDispatch();
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
dispatch(setComputedData(computedData));
|
|
33
|
+
return () => {
|
|
34
|
+
dispatch(setChartData(undefined));
|
|
35
|
+
};
|
|
36
|
+
}, [computedData, dispatch]);
|
|
37
|
+
return null;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const selectChartData = (state: any) => state.chartData.chartData;
|
|
41
|
+
|
|
42
|
+
/** @deprecated use one of the other selectors instead. */
|
|
43
|
+
export const useChartData = (...rest: any[]) => {
|
|
44
|
+
const [, slot] = splitSlot(rest);
|
|
45
|
+
return useAppSelector(selectChartData, subSlot(slot, 'cdc:data'));
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const selectDataIndex = (state: any) => {
|
|
49
|
+
const { dataStartIndex, dataEndIndex } = state.chartData;
|
|
50
|
+
return { startIndex: dataStartIndex, endIndex: dataEndIndex };
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** startIndex and endIndex are data boundaries, set through Brush. */
|
|
54
|
+
export const useDataIndex = (...rest: any[]) => {
|
|
55
|
+
const [, slot] = splitSlot(rest);
|
|
56
|
+
return useAppSelector(selectDataIndex, subSlot(slot, 'cdc:index'));
|
|
57
|
+
};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// Port of context/chartLayoutContext.ts — layout/size/margin/viewBox selector
|
|
2
|
+
// hooks plus the reporter components that publish chart dimensions into the
|
|
3
|
+
// layout slice. Hooks that read the store MULTIPLE times thread explicit
|
|
4
|
+
// sub-slots (binding convention — see ../internal).
|
|
5
|
+
import { useEffect } from 'octane';
|
|
6
|
+
import { useAppDispatch, useAppSelector } from '../state/hooks';
|
|
7
|
+
import { setChartSize, setMargin } from '../state/layoutSlice';
|
|
8
|
+
import {
|
|
9
|
+
selectChartOffsetInternal,
|
|
10
|
+
selectChartViewBox,
|
|
11
|
+
} from '../state/selectors/selectChartOffsetInternal';
|
|
12
|
+
import { selectChartHeight, selectChartWidth } from '../state/selectors/containerSelectors';
|
|
13
|
+
import { useIsPanorama } from './PanoramaContext';
|
|
14
|
+
import { selectBrushDimensions, selectBrushSettings } from '../state/selectors/brushSelectors';
|
|
15
|
+
import { useResponsiveContainerContext } from '../component/ResponsiveContainer';
|
|
16
|
+
import { isPositiveNumber } from '../util/isWellBehavedNumber';
|
|
17
|
+
import { splitSlot, subSlot } from '../internal';
|
|
18
|
+
|
|
19
|
+
export function cartesianViewBoxToTrapezoid(box: any) {
|
|
20
|
+
if (!box) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
x: box.x,
|
|
25
|
+
y: box.y,
|
|
26
|
+
upperWidth: 'upperWidth' in box ? box.upperWidth : box.width,
|
|
27
|
+
lowerWidth: 'lowerWidth' in box ? box.lowerWidth : box.width,
|
|
28
|
+
width: box.width,
|
|
29
|
+
height: box.height,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const useViewBox = (...rest: any[]) => {
|
|
34
|
+
const [, slot] = splitSlot(rest);
|
|
35
|
+
const panorama = useIsPanorama();
|
|
36
|
+
const rootViewBox = useAppSelector(selectChartViewBox, subSlot(slot, 'clc:viewBox'));
|
|
37
|
+
const brushDimensions = useAppSelector(selectBrushDimensions, subSlot(slot, 'clc:brushDim'));
|
|
38
|
+
const brushPadding = useAppSelector(selectBrushSettings, subSlot(slot, 'clc:brushSet'))?.padding;
|
|
39
|
+
if (!panorama || !brushDimensions || !brushPadding) {
|
|
40
|
+
return rootViewBox;
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
width: brushDimensions.width - brushPadding.left - brushPadding.right,
|
|
44
|
+
height: brushDimensions.height - brushPadding.top - brushPadding.bottom,
|
|
45
|
+
x: brushPadding.left,
|
|
46
|
+
y: brushPadding.top,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const manyComponentsThrowErrorsIfOffsetIsUndefined = {
|
|
51
|
+
top: 0,
|
|
52
|
+
bottom: 0,
|
|
53
|
+
left: 0,
|
|
54
|
+
right: 0,
|
|
55
|
+
width: 0,
|
|
56
|
+
height: 0,
|
|
57
|
+
brushBottom: 0,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* For internal use only. If you want this information, `import { useOffset }
|
|
62
|
+
* from 'recharts'` instead. Returns the offset of the chart in pixels.
|
|
63
|
+
*/
|
|
64
|
+
export const useOffsetInternal = (...rest: any[]) => {
|
|
65
|
+
const [, slot] = splitSlot(rest);
|
|
66
|
+
return (
|
|
67
|
+
useAppSelector(selectChartOffsetInternal, subSlot(slot, 'clc:offset')) ??
|
|
68
|
+
manyComponentsThrowErrorsIfOffsetIsUndefined
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/** The width of the chart in pixels, or `undefined` outside a chart context. */
|
|
73
|
+
export const useChartWidth = (...rest: any[]) => {
|
|
74
|
+
const [, slot] = splitSlot(rest);
|
|
75
|
+
return useAppSelector(selectChartWidth, subSlot(slot, 'clc:width'));
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** The height of the chart in pixels, or `undefined` outside a chart context. */
|
|
79
|
+
export const useChartHeight = (...rest: any[]) => {
|
|
80
|
+
const [, slot] = splitSlot(rest);
|
|
81
|
+
return useAppSelector(selectChartHeight, subSlot(slot, 'clc:height'));
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const selectMargin = (state: any) => state.layout.margin;
|
|
85
|
+
|
|
86
|
+
/** The chart's margin (empty space around the plot), or `undefined` outside a chart. */
|
|
87
|
+
export const useMargin = (...rest: any[]) => {
|
|
88
|
+
const [, slot] = splitSlot(rest);
|
|
89
|
+
return useAppSelector(selectMargin, subSlot(slot, 'clc:margin'));
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const selectChartLayout = (state: any) => state.layout.layoutType;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The chart layout as configured by the chart (`horizontal`/`vertical` for
|
|
96
|
+
* cartesian, `centric`/`radial` for polar), or `undefined` outside a chart.
|
|
97
|
+
* @deprecated prefer useCartesianChartLayout / usePolarChartLayout.
|
|
98
|
+
*/
|
|
99
|
+
export const useChartLayout = (...rest: any[]) => {
|
|
100
|
+
const [, slot] = splitSlot(rest);
|
|
101
|
+
return useAppSelector(selectChartLayout, subSlot(slot, 'clc:layout'));
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** The layout only when cartesian (`horizontal` / `vertical`), else undefined. */
|
|
105
|
+
export const useCartesianChartLayout = (...rest: any[]) => {
|
|
106
|
+
const [, slot] = splitSlot(rest);
|
|
107
|
+
const layout = useAppSelector(selectChartLayout, subSlot(slot, 'clc:layout'));
|
|
108
|
+
if (layout === 'horizontal' || layout === 'vertical') {
|
|
109
|
+
return layout;
|
|
110
|
+
}
|
|
111
|
+
return undefined;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const selectPolarChartLayout = (state: any) => {
|
|
115
|
+
const layout = state.layout.layoutType;
|
|
116
|
+
if (layout === 'centric' || layout === 'radial') {
|
|
117
|
+
return layout;
|
|
118
|
+
}
|
|
119
|
+
return undefined;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/** The layout only when polar (`centric` / `radial`), else undefined. */
|
|
123
|
+
export const usePolarChartLayout = (...rest: any[]) => {
|
|
124
|
+
const [, slot] = splitSlot(rest);
|
|
125
|
+
return useAppSelector(selectPolarChartLayout, subSlot(slot, 'clc:polarLayout'));
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/** True when rendered inside a chart context (all charts provide a layout). */
|
|
129
|
+
export const useIsInChartContext = (...rest: any[]) => {
|
|
130
|
+
const [, slot] = splitSlot(rest);
|
|
131
|
+
const layout = useAppSelector(selectChartLayout, subSlot(slot, 'clc:layout'));
|
|
132
|
+
return layout !== undefined;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export const ReportChartSize = (props: { width: number; height: number }): null => {
|
|
136
|
+
const dispatch = useAppDispatch();
|
|
137
|
+
// Skip dispatching in a panorama chart: the ROOT chart decides these, and
|
|
138
|
+
// Brush reads them from the store (stability avoids a re-render cycle).
|
|
139
|
+
const isPanorama = useIsPanorama();
|
|
140
|
+
const { width: widthFromProps, height: heightFromProps } = props;
|
|
141
|
+
const responsiveContainerCalculations = useResponsiveContainerContext();
|
|
142
|
+
let width = widthFromProps;
|
|
143
|
+
let height = heightFromProps;
|
|
144
|
+
if (responsiveContainerCalculations) {
|
|
145
|
+
// ResponsiveContainer-provided dimensions win over explicit props (3.x
|
|
146
|
+
// behavior, kept for backwards compatibility).
|
|
147
|
+
width =
|
|
148
|
+
responsiveContainerCalculations.width > 0
|
|
149
|
+
? responsiveContainerCalculations.width
|
|
150
|
+
: widthFromProps;
|
|
151
|
+
height =
|
|
152
|
+
responsiveContainerCalculations.height > 0
|
|
153
|
+
? responsiveContainerCalculations.height
|
|
154
|
+
: heightFromProps;
|
|
155
|
+
}
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
if (!isPanorama && isPositiveNumber(width) && isPositiveNumber(height)) {
|
|
158
|
+
dispatch(setChartSize({ width, height }));
|
|
159
|
+
}
|
|
160
|
+
}, [dispatch, isPanorama, width, height]);
|
|
161
|
+
return null;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export const ReportChartMargin = (props: { margin: unknown }): null => {
|
|
165
|
+
const { margin } = props;
|
|
166
|
+
const dispatch = useAppDispatch();
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
dispatch(setMargin(margin));
|
|
169
|
+
}, [dispatch, margin]);
|
|
170
|
+
return null;
|
|
171
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Vendored verbatim from recharts@3.9.2 es6/context/tooltipContext.js (framework-agnostic).
|
|
2
|
+
// Do not edit — update by re-vendoring when the recharts devDependency moves.
|
|
3
|
+
import { useAppDispatch } from '../state/hooks';
|
|
4
|
+
import {
|
|
5
|
+
mouseLeaveItem,
|
|
6
|
+
setActiveClickItemIndex,
|
|
7
|
+
setActiveMouseOverItemIndex,
|
|
8
|
+
} from '../state/tooltipSlice';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Some graphical items choose to provide more information to the tooltip
|
|
12
|
+
* and some do not.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export var useMouseEnterItemDispatch = (onMouseEnterFromProps, dataKey, graphicalItemId) => {
|
|
16
|
+
var dispatch = useAppDispatch();
|
|
17
|
+
return (data, index) => (event) => {
|
|
18
|
+
onMouseEnterFromProps === null ||
|
|
19
|
+
onMouseEnterFromProps === void 0 ||
|
|
20
|
+
onMouseEnterFromProps(data, index, event);
|
|
21
|
+
dispatch(
|
|
22
|
+
setActiveMouseOverItemIndex({
|
|
23
|
+
activeIndex: String(index),
|
|
24
|
+
activeDataKey: dataKey,
|
|
25
|
+
activeCoordinate: data.tooltipPosition,
|
|
26
|
+
activeGraphicalItemId: graphicalItemId,
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export var useMouseLeaveItemDispatch = (onMouseLeaveFromProps) => {
|
|
32
|
+
var dispatch = useAppDispatch();
|
|
33
|
+
return (data, index) => (event) => {
|
|
34
|
+
onMouseLeaveFromProps === null ||
|
|
35
|
+
onMouseLeaveFromProps === void 0 ||
|
|
36
|
+
onMouseLeaveFromProps(data, index, event);
|
|
37
|
+
dispatch(mouseLeaveItem());
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export var useMouseClickItemDispatch = (onMouseClickFromProps, dataKey, graphicalItemId) => {
|
|
41
|
+
var dispatch = useAppDispatch();
|
|
42
|
+
return (data, index) => (event) => {
|
|
43
|
+
onMouseClickFromProps === null ||
|
|
44
|
+
onMouseClickFromProps === void 0 ||
|
|
45
|
+
onMouseClickFromProps(data, index, event);
|
|
46
|
+
dispatch(
|
|
47
|
+
setActiveClickItemIndex({
|
|
48
|
+
activeIndex: String(index),
|
|
49
|
+
activeDataKey: dataKey,
|
|
50
|
+
activeCoordinate: data.tooltipPosition,
|
|
51
|
+
activeGraphicalItemId: graphicalItemId,
|
|
52
|
+
}),
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
};
|