| 1 | import * as React from 'react';
|
|---|
| 2 | import { useLayoutEffect, useRef } from 'react';
|
|---|
| 3 | import { addZAxis, removeZAxis, replaceZAxis } from '../state/cartesianAxisSlice';
|
|---|
| 4 | import { useAppDispatch } from '../state/hooks';
|
|---|
| 5 | import { implicitZAxis } from '../state/selectors/axisSelectors';
|
|---|
| 6 | import { resolveDefaultProps } from '../util/resolveDefaultProps';
|
|---|
| 7 | function SetZAxisSettings(settings) {
|
|---|
| 8 | var dispatch = useAppDispatch();
|
|---|
| 9 | var prevSettingsRef = useRef(null);
|
|---|
| 10 | useLayoutEffect(() => {
|
|---|
| 11 | if (prevSettingsRef.current === null) {
|
|---|
| 12 | dispatch(addZAxis(settings));
|
|---|
| 13 | } else if (prevSettingsRef.current !== settings) {
|
|---|
| 14 | dispatch(replaceZAxis({
|
|---|
| 15 | prev: prevSettingsRef.current,
|
|---|
| 16 | next: settings
|
|---|
| 17 | }));
|
|---|
| 18 | }
|
|---|
| 19 | prevSettingsRef.current = settings;
|
|---|
| 20 | }, [settings, dispatch]);
|
|---|
| 21 | useLayoutEffect(() => {
|
|---|
| 22 | return () => {
|
|---|
| 23 | if (prevSettingsRef.current) {
|
|---|
| 24 | dispatch(removeZAxis(prevSettingsRef.current));
|
|---|
| 25 | prevSettingsRef.current = null;
|
|---|
| 26 | }
|
|---|
| 27 | };
|
|---|
| 28 | }, [dispatch]);
|
|---|
| 29 | return null;
|
|---|
| 30 | }
|
|---|
| 31 | export var zAxisDefaultProps = {
|
|---|
| 32 | zAxisId: 0,
|
|---|
| 33 | range: implicitZAxis.range,
|
|---|
| 34 | scale: implicitZAxis.scale,
|
|---|
| 35 | type: implicitZAxis.type
|
|---|
| 36 | };
|
|---|
| 37 |
|
|---|
| 38 | /**
|
|---|
| 39 | * Virtual axis, does not render anything itself. Has no ticks, grid lines, or labels.
|
|---|
| 40 | * Useful for dynamically setting Scatter point size, based on data.
|
|---|
| 41 | *
|
|---|
| 42 | * @consumes CartesianViewBoxContext
|
|---|
| 43 | */
|
|---|
| 44 | export function ZAxis(outsideProps) {
|
|---|
| 45 | var props = resolveDefaultProps(outsideProps, zAxisDefaultProps);
|
|---|
| 46 | return /*#__PURE__*/React.createElement(SetZAxisSettings, {
|
|---|
| 47 | domain: props.domain,
|
|---|
| 48 | id: props.zAxisId,
|
|---|
| 49 | dataKey: props.dataKey,
|
|---|
| 50 | name: props.name,
|
|---|
| 51 | unit: props.unit,
|
|---|
| 52 | range: props.range,
|
|---|
| 53 | scale: props.scale,
|
|---|
| 54 | type: props.type,
|
|---|
| 55 | allowDuplicatedCategory: implicitZAxis.allowDuplicatedCategory,
|
|---|
| 56 | allowDataOverflow: implicitZAxis.allowDataOverflow,
|
|---|
| 57 | reversed: implicitZAxis.reversed,
|
|---|
| 58 | includeHidden: implicitZAxis.includeHidden
|
|---|
| 59 | });
|
|---|
| 60 | }
|
|---|
| 61 | ZAxis.displayName = 'ZAxis'; |
|---|