recharts
Version:
React charts
639 lines (630 loc) • 31.8 kB
JavaScript
var _excluded = ["shape", "activeShape", "cornerRadius", "id", "unthemedColors", "themedActiveStyles", "fillObject"],
_excluded2 = ["onMouseEnter", "onClick", "onMouseLeave"],
_excluded3 = ["value", "background"];
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
import * as React from 'react';
import omit from 'es-toolkit/compat/omit';
import { PureComponent, useRef } from 'react';
import { defaultRadialBarShape, parseCornerRadius, RadialBarSector } from '../util/RadialBarUtils';
import { Layer } from '../container/Layer';
import { clsx } from '../util/clsx';
import { findAllByType } from '../util/ReactUtils';
import { LabelListFromLabelProp, PolarLabelListContextProvider } from '../component/LabelList';
import { Cell } from '../component/Cell';
import { interpolate, mathSign, noop } from '../util/DataUtils';
import { getCateCoordinateOfBar, getNormalizedStackId, getTooltipNameProp, getValueByDataKey, truncateByDomain } from '../util/ChartUtils';
import { adaptEventsOfChild } from '../util/types';
import { useMouseClickItemDispatch, useMouseEnterItemDispatch, useMouseLeaveItemDispatch } from '../context/tooltipContext';
import { SetTooltipEntrySettings } from '../state/SetTooltipEntrySettings';
import { selectRadialBarLegendPayload, selectRadialBarSectors } from '../state/selectors/radialBarSelectors';
import { useAppSelector } from '../state/hooks';
import { selectActiveTooltipIndex } from '../state/selectors/tooltipSelectors';
import { SetPolarLegendPayload } from '../state/SetLegendPayload';
import { AnimatedItems, useAnimationCallbacks } from '../animation/AnimatedItems';
import { matchAppend } from '../animation/matchBy';
import { RegisterGraphicalItemId } from '../context/RegisterGraphicalItemId';
import { SetPolarGraphicalItem } from '../state/SetGraphicalItem';
import { svgPropertiesNoEvents, svgPropertiesNoEventsFromUnknown } from '../util/svgPropertiesNoEvents';
import { resolveDefaultProps } from '../util/resolveDefaultProps';
import { ZIndexLayer } from '../zIndex/ZIndexLayer';
import { DefaultZIndexes } from '../zIndex/DefaultZIndexes';
import { getZIndexFromUnknown } from '../zIndex/getZIndexFromUnknown';
import { usePolarChartLayout } from '../context/chartLayoutContext';
import { EntryFillDefinitions, FillObjectDefinition, getEntryFillId, getEntryFillObject, getFillUrl, getSeriesFillId, hasEntryFillObjects, readEntryFill, splitFill, withEntryFillColor } from '../fill/fillDefinitions';
import { useBackwardsCompatibleTheme } from '../theme/useBackwardsCompatibleTheme';
import { useGraphicalItemIdentity, useGraphicalItemThemeFill } from '../theme/useGraphicalItemIdentity';
import { useEffectiveDataKey } from '../util/useEffectiveDataKey';
import { getEntryColor as _getEntryColor, getEntryShapeColors, getEntryStyleOverrides, omitEntrySvgProps, useUnthemedColors } from '../theme/dataEntryStyles';
import { getActiveStyleOverrides, useThemedActiveStyles } from '../theme/activeStyles';
import { DataLabelColorsContextProvider, DataLabelThemeContextProvider, useSeriesLabelThemeResolver } from '../theme/labelTheme';
var STABLE_EMPTY_ARRAY = [];
var noLegendPayload = [];
/**
* @public
*/
function RadialBarLabelListProvider(_ref) {
var showLabels = _ref.showLabels,
sectors = _ref.sectors,
fill = _ref.fill,
stroke = _ref.stroke,
unthemedColors = _ref.unthemedColors,
children = _ref.children;
// The same color as in Tooltip and Legend.
var labelColors = React.useMemo(() => ({
hasFilledShapes: true,
getShapeColors: index => getEntryShapeColors(sectors[index], fill, stroke, unthemedColors)
}), [sectors, fill, stroke, unthemedColors]);
var labelListEntries = sectors.map(sector => ({
value: sector.value,
payload: sector.payload,
parentViewBox: undefined,
clockWise: false,
viewBox: {
cx: sector.cx,
cy: sector.cy,
innerRadius: sector.innerRadius,
outerRadius: sector.outerRadius,
startAngle: sector.startAngle,
endAngle: sector.endAngle,
clockWise: false
},
fill: sector.fill
}));
return /*#__PURE__*/React.createElement(PolarLabelListContextProvider, {
value: showLabels ? labelListEntries : undefined
}, /*#__PURE__*/React.createElement(DataLabelColorsContextProvider, {
value: labelColors
}, children));
}
function RadialBarSectors(_ref2) {
var sectors = _ref2.sectors,
allOtherRadialBarProps = _ref2.allOtherRadialBarProps,
showLabels = _ref2.showLabels,
animationElapsedTime = _ref2.animationElapsedTime,
isAnimating = _ref2.isAnimating,
isEntrance = _ref2.isEntrance;
var shape = allOtherRadialBarProps.shape,
activeShape = allOtherRadialBarProps.activeShape,
cornerRadius = allOtherRadialBarProps.cornerRadius,
id = allOtherRadialBarProps.id,
unthemedColors = allOtherRadialBarProps.unthemedColors,
themedActiveStyles = allOtherRadialBarProps.themedActiveStyles,
fillObject = allOtherRadialBarProps.fillObject,
others = _objectWithoutProperties(allOtherRadialBarProps, _excluded);
var svgProps = svgPropertiesNoEvents(others);
// `fill` stays the base color for labels; the shapes paint with the definition
var baseProps = fillObject == null ? svgProps : _objectSpread(_objectSpread({}, svgProps), {}, {
fill: getFillUrl(getSeriesFillId(id))
});
var activeIndex = useAppSelector(selectActiveTooltipIndex);
var onMouseEnterFromProps = allOtherRadialBarProps.onMouseEnter,
onItemClickFromProps = allOtherRadialBarProps.onClick,
onMouseLeaveFromProps = allOtherRadialBarProps.onMouseLeave,
restOfAllOtherProps = _objectWithoutProperties(allOtherRadialBarProps, _excluded2);
var onMouseEnterFromContext = useMouseEnterItemDispatch(onMouseEnterFromProps, allOtherRadialBarProps.dataKey, id);
var onMouseLeaveFromContext = useMouseLeaveItemDispatch(onMouseLeaveFromProps);
var onClickFromContext = useMouseClickItemDispatch(onItemClickFromProps, allOtherRadialBarProps.dataKey, id);
if (sectors == null) {
return null;
}
return /*#__PURE__*/React.createElement(RadialBarLabelListProvider, {
showLabels: showLabels,
sectors: sectors,
fill: others.fill,
stroke: others.stroke,
unthemedColors: unthemedColors
}, sectors.map((entry, i) => {
var isActive = Boolean(activeShape && activeIndex === String(i));
var onMouseEnter = onMouseEnterFromContext(entry, i);
var onMouseLeave = onMouseLeaveFromContext(entry, i);
var onClick = onClickFromContext(entry, i);
var radialBarSectorProps = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, baseProps), {}, {
cornerRadius: parseCornerRadius(cornerRadius)
}, getEntryStyleOverrides(entry, unthemedColors)), entry), readEntryFill(entry.payload).fillObject == null ? undefined : {
fill: getFillUrl(getEntryFillId(id, i))
}), isActive ? getActiveStyleOverrides(activeShape, themedActiveStyles, entry) : undefined), adaptEventsOfChild(restOfAllOtherProps, entry, i)), {}, {
onMouseEnter,
onMouseLeave,
onClick,
className: clsx('recharts-radial-bar-sector', entry.className),
forceCornerRadius: others.forceCornerRadius,
cornerIsExternal: others.cornerIsExternal,
animationElapsedTime,
isAnimating,
isEntrance,
isActive,
option: isActive && activeShape != null ? activeShape : shape,
index: i
});
if (isActive) {
return /*#__PURE__*/React.createElement(ZIndexLayer, {
zIndex: DefaultZIndexes.activeBar,
key: "sector-".concat(i)
}, /*#__PURE__*/React.createElement(RadialBarSector, radialBarSectorProps));
}
return /*#__PURE__*/React.createElement(RadialBarSector, _extends({
key: "sector-".concat(i)
}, radialBarSectorProps));
}), /*#__PURE__*/React.createElement(LabelListFromLabelProp, {
label: allOtherRadialBarProps.label
}), allOtherRadialBarProps.children);
}
var defaultRadialBarAnimateItems = (items, animationElapsedTime) => {
if (items == null) return [];
if (animationElapsedTime === 1) {
return items.flatMap(item => item.status === 'removed' ? [] : [item.next]);
}
return items.flatMap(item => {
if (item.status === 'removed') return [];
if (item.status === 'matched') {
return [_objectSpread(_objectSpread({}, item.next), {}, {
startAngle: interpolate(item.prev.startAngle, item.next.startAngle, animationElapsedTime),
endAngle: interpolate(item.prev.endAngle, item.next.endAngle, animationElapsedTime)
})];
}
// added
return [_objectSpread(_objectSpread({}, item.next), {}, {
endAngle: interpolate(item.next.startAngle, item.next.endAngle, animationElapsedTime)
})];
});
};
function SectorsWithAnimation(_ref3) {
var props = _ref3.props,
previousSectorsRef = _ref3.previousSectorsRef;
var sectors = props.sectors,
isAnimationActive = props.isAnimationActive,
animationBegin = props.animationBegin,
animationDuration = props.animationDuration,
animationEasing = props.animationEasing,
onAnimationStart = props.onAnimationStart,
onAnimationEnd = props.onAnimationEnd;
var _useAnimationCallback = useAnimationCallbacks(onAnimationStart, onAnimationEnd),
isAnimating = _useAnimationCallback.isAnimating,
handleAnimationStart = _useAnimationCallback.handleAnimationStart,
handleAnimationEnd = _useAnimationCallback.handleAnimationEnd;
var layout = usePolarChartLayout();
if (layout == null) return null;
return /*#__PURE__*/React.createElement(AnimatedItems, {
animationInput: props,
animationIdPrefix: "recharts-radialbar-",
items: sectors,
previousItemsRef: previousSectorsRef,
isAnimationActive: isAnimationActive,
animationBegin: animationBegin,
animationDuration: animationDuration,
animationEasing: animationEasing,
onAnimationStart: handleAnimationStart,
onAnimationEnd: handleAnimationEnd,
animationInterpolateFn: props.animationInterpolateFn,
animationMatchBy: props.animationMatchBy,
layout: layout
}, (stepData, animationElapsedTime, isEntrance) => /*#__PURE__*/React.createElement(RadialBarSectors, {
sectors: stepData,
allOtherRadialBarProps: props,
showLabels: !isAnimating,
animationElapsedTime: animationElapsedTime,
isAnimating: isAnimating || animationElapsedTime < 1,
isEntrance: isEntrance
}));
}
function RenderSectors(props) {
var previousSectorsRef = useRef(null);
return /*#__PURE__*/React.createElement(SectorsWithAnimation, {
props: props,
previousSectorsRef: previousSectorsRef
});
}
/**
* The type is exported only so that TypeScript can name it in the declaration files of projects
* that wrap Recharts components. It is not part of the public API and may change in any release.
*
* @internal
*/
/**
* @public
*/
/**
* Props after the fill object is split off: `fill` is the base color.
*/
/**
* RadialBar has one legend item per data entry, so each item shows the color its own sector renders with.
*/
function SetRadialBarPayloadLegend(_ref4) {
var legendType = _ref4.legendType,
fill = _ref4.fill,
stroke = _ref4.stroke,
unthemedColors = _ref4.unthemedColors,
fillObject = _ref4.fillObject,
children = _ref4.children;
var cells = React.useMemo(() => findAllByType(children, Cell), [children]);
var legendPayload = useAppSelector(state => selectRadialBarLegendPayload(state, legendType));
var coloredLegendPayload = React.useMemo(() => {
var _legendPayload$map;
return (_legendPayload$map = legendPayload === null || legendPayload === void 0 ? void 0 : legendPayload.map((entry, index) => {
var _cells$index;
var payload = _objectSpread(_objectSpread({}, entry.payload), (_cells$index = cells[index]) === null || _cells$index === void 0 ? void 0 : _cells$index.props);
return _objectSpread(_objectSpread({}, entry), {}, {
color: _getEntryColor(payload, fill, stroke, unthemedColors),
fill: getEntryFillObject(payload, fillObject)
});
})) !== null && _legendPayload$map !== void 0 ? _legendPayload$map : noLegendPayload;
}, [legendPayload, cells, fill, stroke, unthemedColors, fillObject]);
return /*#__PURE__*/React.createElement(SetPolarLegendPayload, {
legendPayload: coloredLegendPayload
});
}
var SetRadialBarTooltipEntrySettings = /*#__PURE__*/React.memo(_ref5 => {
var dataKey = _ref5.dataKey,
sectors = _ref5.sectors,
stroke = _ref5.stroke,
strokeWidth = _ref5.strokeWidth,
name = _ref5.name,
hide = _ref5.hide,
fill = _ref5.fill,
tooltipType = _ref5.tooltipType,
formatter = _ref5.formatter,
id = _ref5.id,
unthemedColors = _ref5.unthemedColors;
var tooltipEntrySettings = {
dataDefinedOnItem: sectors,
getPosition: noop,
// The tooltip data are the sectors, so the entry here already includes the props of its Cell.
getEntryColor: sector => _getEntryColor(sector, fill, stroke, unthemedColors),
settings: {
graphicalItemId: id,
stroke,
strokeWidth,
fill,
nameKey: undefined,
// RadialBar does not have nameKey, why?
dataKey,
name: getTooltipNameProp(name, dataKey),
hide,
type: tooltipType,
color: fill,
unit: '',
// Why does RadialBar not support unit?
formatter
}
};
return /*#__PURE__*/React.createElement(SetTooltipEntrySettings, {
tooltipEntrySettings: tooltipEntrySettings
});
});
var defaultLegacyBarBackgroundProps = {
fill: '#eee'
};
function RadialBarBackgroundSectors(_ref6) {
var sectors = _ref6.sectors,
allOtherRadialBarProps = _ref6.allOtherRadialBarProps;
var cornerRadius = allOtherRadialBarProps.cornerRadius,
backgroundFromProps = allOtherRadialBarProps.background;
var backgroundProps = svgPropertiesNoEventsFromUnknown(backgroundFromProps);
var backgroundThemeProps = useBackwardsCompatibleTheme(theme => theme.barBackground, backgroundProps !== null && backgroundProps !== void 0 ? backgroundProps : {}, defaultLegacyBarBackgroundProps);
if (sectors == null) {
return null;
}
return /*#__PURE__*/React.createElement(ZIndexLayer, {
zIndex: getZIndexFromUnknown(backgroundFromProps, DefaultZIndexes.barBackground)
}, sectors.map((entry, i) => {
var value = entry.value,
background = entry.background,
rest = _objectWithoutProperties(entry, _excluded3);
if (!background) {
return null;
}
// @ts-expect-error backgroundProps is contributing unknown props
var props = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
cornerRadius: parseCornerRadius(cornerRadius)
}, omitEntrySvgProps(rest)), backgroundThemeProps), background), backgroundProps), adaptEventsOfChild(allOtherRadialBarProps, entry, i)), {}, {
index: i,
className: clsx('recharts-radial-bar-background-sector', (backgroundProps === null || backgroundProps === void 0 ? void 0 : backgroundProps.className) == null ? undefined : String(backgroundProps.className)),
// A custom element or function draws the background; `true` and objects draw the default sector
option: /*#__PURE__*/React.isValidElement(backgroundFromProps) || typeof backgroundFromProps === 'function' ? backgroundFromProps : background,
isActive: false
});
return /*#__PURE__*/React.createElement(RadialBarSector, _extends({
key: "background-".concat(rest.cx, "-").concat(rest.cy, "-").concat(rest.innerRadius, "-").concat(rest.outerRadius, "-").concat(rest.startAngle, "-").concat(rest.endAngle, "-").concat(i)
}, props));
}));
}
class RadialBarWithState extends PureComponent {
renderBackground(sectors) {
return /*#__PURE__*/React.createElement(RadialBarBackgroundSectors, {
sectors: sectors,
allOtherRadialBarProps: this.props
});
}
render() {
var _this$props = this.props,
hide = _this$props.hide,
sectors = _this$props.sectors,
className = _this$props.className,
background = _this$props.background,
fillObject = _this$props.fillObject,
id = _this$props.id,
fill = _this$props.fill,
stroke = _this$props.stroke,
unthemedColors = _this$props.unthemedColors;
if (hide) {
return null;
}
var layerClass = clsx('recharts-area', className);
var hasEntryFills = hasEntryFillObjects(sectors.map(sector => sector.payload));
return /*#__PURE__*/React.createElement(ZIndexLayer, {
zIndex: this.props.zIndex
}, /*#__PURE__*/React.createElement(Layer, {
className: layerClass
}, (fillObject != null || hasEntryFills) && /*#__PURE__*/React.createElement("defs", null, fillObject != null && /*#__PURE__*/React.createElement(FillObjectDefinition, {
id: getSeriesFillId(id),
fillObject: fillObject,
color: fill
}), hasEntryFills && /*#__PURE__*/React.createElement(EntryFillDefinitions, {
id: id,
entries: sectors.map((sector, index) => ({
index,
payload: sector.payload,
color: getEntryShapeColors(sector.payload, fill, stroke, unthemedColors).fill
}))
})), background && /*#__PURE__*/React.createElement(Layer, {
className: "recharts-radial-bar-background"
}, this.renderBackground(sectors)), /*#__PURE__*/React.createElement(Layer, {
className: "recharts-radial-bar-sectors"
}, /*#__PURE__*/React.createElement(RenderSectors, this.props))));
}
}
function RadialBarImpl(props) {
var _useAppSelector;
var cells = React.useMemo(() => findAllByType(props.children, Cell), [props.children]);
var radialBarSettings = React.useMemo(() => ({
data: undefined,
hide: false,
id: props.id,
dataKey: props.dataKey,
minAngle: props.minAngle,
minPointSize: props.minPointSize,
stackId: getNormalizedStackId(props.stackId),
maxBarSize: props.maxBarSize,
barSize: props.barSize,
type: 'radialBar',
angleAxisId: props.angleAxisId,
radiusAxisId: props.radiusAxisId
}), [props.id, props.dataKey, props.minAngle, props.minPointSize, props.stackId, props.maxBarSize, props.barSize, props.angleAxisId, props.radiusAxisId]);
var sectors = (_useAppSelector = useAppSelector(state => selectRadialBarSectors(state, props.radiusAxisId, props.angleAxisId, radialBarSettings, cells))) !== null && _useAppSelector !== void 0 ? _useAppSelector : STABLE_EMPTY_ARRAY;
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SetRadialBarTooltipEntrySettings, {
dataKey: props.dataKey,
sectors: sectors,
stroke: props.stroke,
strokeWidth: props.strokeWidth,
name: props.name,
hide: props.hide,
fill: props.fill,
tooltipType: props.tooltipType,
formatter: props.formatter,
id: props.id,
unthemedColors: props.unthemedColors
}), /*#__PURE__*/React.createElement(RadialBarWithState, _extends({}, props, {
sectors: sectors
})));
}
export var defaultRadialBarProps = {
angleAxisId: 0,
animationBegin: 0,
animationDuration: 1500,
animationEasing: 'ease',
animationMatchBy: matchAppend,
animationInterpolateFn: defaultRadialBarAnimateItems,
background: false,
cornerIsExternal: false,
cornerRadius: 0,
forceCornerRadius: false,
hide: false,
isAnimationActive: 'auto',
label: false,
legendType: 'rect',
minAngle: 0,
minPointSize: 0,
radiusAxisId: 0,
shape: defaultRadialBarShape,
zIndex: DefaultZIndexes.bar
};
export function computeRadialBarDataItems(_ref7) {
var displayedData = _ref7.displayedData,
stackedData = _ref7.stackedData,
dataStartIndex = _ref7.dataStartIndex,
stackedDomain = _ref7.stackedDomain,
dataKey = _ref7.dataKey,
baseValue = _ref7.baseValue,
layout = _ref7.layout,
radiusAxis = _ref7.radiusAxis,
radiusAxisTicks = _ref7.radiusAxisTicks,
bandSize = _ref7.bandSize,
pos = _ref7.pos,
angleAxis = _ref7.angleAxis,
minAngle = _ref7.minAngle,
minPointSize = _ref7.minPointSize,
cx = _ref7.cx,
cy = _ref7.cy,
angleAxisTicks = _ref7.angleAxisTicks,
cells = _ref7.cells,
rootStartAngle = _ref7.startAngle,
rootEndAngle = _ref7.endAngle;
if (angleAxisTicks == null || radiusAxisTicks == null) {
return STABLE_EMPTY_ARRAY;
}
return (displayedData !== null && displayedData !== void 0 ? displayedData : []).map((entry, index) => {
/*
* `id` from a data entry is never spread on rendered elements to avoid duplicate DOM ids.
* The raw entry, id included, stays available through `payload`.
*/
var entryWithoutId = entry != null && typeof entry === 'object' ? omit(entry, ['id']) : entry;
var value, innerRadius, outerRadius, startAngle, endAngle, backgroundSector;
if (stackedData) {
// @ts-expect-error truncateByDomain expects only numerical domain, but it can received categorical domain too
value = truncateByDomain(stackedData[dataStartIndex + index], stackedDomain);
} else {
value = getValueByDataKey(entry, dataKey);
if (!Array.isArray(value)) {
value = [baseValue, value];
}
}
if (layout === 'radial') {
var _angleAxis$scale$map;
startAngle = (_angleAxis$scale$map = angleAxis.scale.map(value[0])) !== null && _angleAxis$scale$map !== void 0 ? _angleAxis$scale$map : rootStartAngle;
var valueAngle = angleAxis.scale.map(value[1]);
endAngle = valueAngle !== null && valueAngle !== void 0 ? valueAngle : startAngle;
innerRadius = getCateCoordinateOfBar({
axis: radiusAxis,
ticks: radiusAxisTicks,
bandSize,
offset: pos.offset,
entry,
index
});
if (innerRadius != null && endAngle != null && startAngle != null) {
outerRadius = innerRadius + pos.size;
var deltaAngle = endAngle - startAngle;
if (valueAngle != null && Math.abs(minPointSize) > 0 && Math.abs(deltaAngle) < Math.abs(minPointSize)) {
var delta = mathSign(deltaAngle || minPointSize) * (Math.abs(minPointSize) - Math.abs(deltaAngle));
endAngle += delta;
deltaAngle = endAngle - startAngle;
}
// Zero-value bars are excluded so a truly empty bar never gets an artificial sliver.
// Negative minAngle is normalized the same way Pie normalizes pieSettings.minAngle.
// Note: like minPointSize above, this expands each bar independently, so a stacked
// bar's expansion can overlap into its neighbor's range. That is an existing
// limitation shared with minPointSize, not something new to minAngle.
if (Math.abs(minAngle) > 0 && deltaAngle !== 0 && Math.abs(deltaAngle) < Math.abs(minAngle)) {
var _delta = mathSign(deltaAngle) * (Math.abs(minAngle) - Math.abs(deltaAngle));
endAngle += _delta;
}
backgroundSector = {
background: {
cx,
cy,
innerRadius,
outerRadius,
startAngle: rootStartAngle,
endAngle: rootEndAngle
}
};
}
} else {
innerRadius = radiusAxis.scale.map(value[0]);
outerRadius = radiusAxis.scale.map(value[1]);
startAngle = getCateCoordinateOfBar({
axis: angleAxis,
ticks: angleAxisTicks,
bandSize,
offset: pos.offset,
entry,
index
});
if (innerRadius != null && outerRadius != null && startAngle != null) {
endAngle = startAngle + pos.size;
var deltaRadius = outerRadius - innerRadius;
if (Math.abs(minPointSize) > 0 && Math.abs(deltaRadius) < Math.abs(minPointSize)) {
var _delta2 = mathSign(deltaRadius || minPointSize) * (Math.abs(minPointSize) - Math.abs(deltaRadius));
outerRadius += _delta2;
}
}
}
return withEntryFillColor(_objectSpread(_objectSpread(_objectSpread({}, entryWithoutId), backgroundSector), {}, {
payload: entry,
value: stackedData ? value : value[1],
cx,
cy,
innerRadius,
outerRadius,
startAngle,
// @ts-expect-error endAngle is used before assigned (?)
endAngle
}, cells && cells[index] && cells[index].props), entry);
});
}
/**
* @consumes PolarChartContext
* @provides LabelListContext
* @provides CellReader
* @public
*/
export function RadialBar(propsWithFillObject) {
var _outsideProps$angleAx, _outsideProps$radiusA, _outsideProps$fill, _outsideProps$stroke, _outsideProps$strokeW, _outsideProps$strokeO, _outsideProps$strokeD, _outsideProps$fillOpa;
var _splitFill = splitFill(propsWithFillObject.fill),
fillColor = _splitFill.color,
fillObject = _splitFill.fillObject;
// From here on, `fill` is the base color
var outsideProps = _objectSpread(_objectSpread({}, propsWithFillObject), {}, {
fill: fillColor
});
var dataKey = useEffectiveDataKey({
dataKey: outsideProps.dataKey,
angleAxisId: (_outsideProps$angleAx = outsideProps.angleAxisId) !== null && _outsideProps$angleAx !== void 0 ? _outsideProps$angleAx : defaultRadialBarProps.angleAxisId,
radiusAxisId: (_outsideProps$radiusA = outsideProps.radiusAxisId) !== null && _outsideProps$radiusA !== void 0 ? _outsideProps$radiusA : defaultRadialBarProps.radiusAxisId
});
var graphicalItemThemeSelector = useGraphicalItemIdentity(dataKey, outsideProps);
var themeFillObject = useGraphicalItemThemeFill(dataKey, outsideProps);
var effectiveFillObject = fillObject !== null && fillObject !== void 0 ? fillObject : themeFillObject;
var resolveLabelTheme = useSeriesLabelThemeResolver(graphicalItemThemeSelector);
var unthemedColors = useUnthemedColors(outsideProps);
var themedActiveStyles = useThemedActiveStyles(graphicalItemThemeSelector, outsideProps);
var graphicalItemStyle = useBackwardsCompatibleTheme(graphicalItemThemeSelector, outsideProps, undefined);
var props = resolveDefaultProps(_objectSpread(_objectSpread({}, outsideProps), {}, {
dataKey
}), defaultRadialBarProps);
var themeFill = (_outsideProps$fill = outsideProps.fill) !== null && _outsideProps$fill !== void 0 ? _outsideProps$fill : graphicalItemStyle === null || graphicalItemStyle === void 0 ? void 0 : graphicalItemStyle.fill;
var themeStroke = (_outsideProps$stroke = outsideProps.stroke) !== null && _outsideProps$stroke !== void 0 ? _outsideProps$stroke : graphicalItemStyle === null || graphicalItemStyle === void 0 ? void 0 : graphicalItemStyle.stroke;
var themeStrokeWidth = (_outsideProps$strokeW = outsideProps.strokeWidth) !== null && _outsideProps$strokeW !== void 0 ? _outsideProps$strokeW : graphicalItemStyle === null || graphicalItemStyle === void 0 ? void 0 : graphicalItemStyle.strokeWidth;
var themeStrokeOpacity = (_outsideProps$strokeO = outsideProps.strokeOpacity) !== null && _outsideProps$strokeO !== void 0 ? _outsideProps$strokeO : graphicalItemStyle === null || graphicalItemStyle === void 0 ? void 0 : graphicalItemStyle.strokeOpacity;
var themeStrokeDasharray = (_outsideProps$strokeD = outsideProps.strokeDasharray) !== null && _outsideProps$strokeD !== void 0 ? _outsideProps$strokeD : graphicalItemStyle === null || graphicalItemStyle === void 0 ? void 0 : graphicalItemStyle.strokeDasharray;
var themeFillOpacity = (_outsideProps$fillOpa = outsideProps.fillOpacity) !== null && _outsideProps$fillOpa !== void 0 ? _outsideProps$fillOpa : graphicalItemStyle === null || graphicalItemStyle === void 0 ? void 0 : graphicalItemStyle.fillOpacity;
var themedProps = {};
if (themeFill !== undefined) themedProps.fill = themeFill;
if (themeStroke !== undefined) themedProps.stroke = themeStroke;
if (themeStrokeWidth !== undefined) themedProps.strokeWidth = themeStrokeWidth;
if (themeStrokeOpacity !== undefined) themedProps.strokeOpacity = themeStrokeOpacity;
if (themeStrokeDasharray !== undefined) themedProps.strokeDasharray = themeStrokeDasharray;
if (themeFillOpacity !== undefined) themedProps.fillOpacity = themeFillOpacity;
return /*#__PURE__*/React.createElement(RegisterGraphicalItemId, {
id: props.id,
type: "radialBar"
}, id => {
var _props$hide, _props$angleAxisId, _props$radiusAxisId;
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SetPolarGraphicalItem, {
type: "radialBar",
id: id,
data: undefined // why does RadialBar not allow data defined on the item?
,
dataKey: props.dataKey,
hide: (_props$hide = props.hide) !== null && _props$hide !== void 0 ? _props$hide : defaultRadialBarProps.hide,
angleAxisId: (_props$angleAxisId = props.angleAxisId) !== null && _props$angleAxisId !== void 0 ? _props$angleAxisId : defaultRadialBarProps.angleAxisId,
radiusAxisId: (_props$radiusAxisId = props.radiusAxisId) !== null && _props$radiusAxisId !== void 0 ? _props$radiusAxisId : defaultRadialBarProps.radiusAxisId,
stackId: getNormalizedStackId(props.stackId),
barSize: props.barSize,
minAngle: props.minAngle,
minPointSize: props.minPointSize,
maxBarSize: props.maxBarSize
}), /*#__PURE__*/React.createElement(SetRadialBarPayloadLegend, {
legendType: props.legendType,
fill: themedProps.fill,
stroke: themedProps.stroke,
unthemedColors: unthemedColors,
fillObject: effectiveFillObject
}, props.children), /*#__PURE__*/React.createElement(DataLabelThemeContextProvider, {
value: resolveLabelTheme
}, /*#__PURE__*/React.createElement(RadialBarImpl, _extends({}, props, themedProps, {
id: id,
fillObject: effectiveFillObject,
unthemedColors: unthemedColors,
themedActiveStyles: themedActiveStyles
}))));
});
}
RadialBar.displayName = 'RadialBar';