Add settings page for managing forecasting API key and URL via UI

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-20 14:37:36 +00:00
parent cae411eae7
commit 1c411e402e
19809 changed files with 1962608 additions and 97 deletions

View file

@ -0,0 +1,92 @@
import { createSelector } from 'reselect';
import { computeArea } from '../../cartesian/Area';
import { selectAxisWithScale, selectStackGroups, selectTicksOfGraphicalItem, selectUnfilteredCartesianItems } from './axisSelectors';
import { selectChartLayout } from '../../context/chartLayoutContext';
import { selectChartDataWithIndexesIfNotInPanoramaPosition3 } from './dataSelectors';
import { getBandSizeOfAxis, isCategoricalAxis } from '../../util/ChartUtils';
import { getStackSeriesIdentifier } from '../../util/stacks/getStackSeriesIdentifier';
import { selectChartBaseValue } from './rootPropsSelectors';
import { selectXAxisIdFromGraphicalItemId, selectYAxisIdFromGraphicalItemId } from './graphicalItemSelectors';
var selectXAxisWithScale = (state, graphicalItemId, isPanorama) => selectAxisWithScale(state, 'xAxis', selectXAxisIdFromGraphicalItemId(state, graphicalItemId), isPanorama);
var selectXAxisTicks = (state, graphicalItemId, isPanorama) => selectTicksOfGraphicalItem(state, 'xAxis', selectXAxisIdFromGraphicalItemId(state, graphicalItemId), isPanorama);
var selectYAxisWithScale = (state, graphicalItemId, isPanorama) => selectAxisWithScale(state, 'yAxis', selectYAxisIdFromGraphicalItemId(state, graphicalItemId), isPanorama);
var selectYAxisTicks = (state, graphicalItemId, isPanorama) => selectTicksOfGraphicalItem(state, 'yAxis', selectYAxisIdFromGraphicalItemId(state, graphicalItemId), isPanorama);
var selectBandSize = createSelector([selectChartLayout, selectXAxisWithScale, selectYAxisWithScale, selectXAxisTicks, selectYAxisTicks], (layout, xAxis, yAxis, xAxisTicks, yAxisTicks) => {
if (isCategoricalAxis(layout, 'xAxis')) {
return getBandSizeOfAxis(xAxis, xAxisTicks, false);
}
return getBandSizeOfAxis(yAxis, yAxisTicks, false);
});
var pickAreaId = (_state, id) => id;
/*
* There is a race condition problem because we read some data from props and some from the state.
* The state is updated through a dispatch and is one render behind,
* and so we have this weird one tick render where the displayedData in one selector have the old dataKey
* but the new dataKey in another selector.
*
* A proper fix is to either move everything into the state, or read the dataKey always from props
* - but this is a smaller change.
*/
var selectSynchronisedAreaSettings = createSelector([selectUnfilteredCartesianItems, pickAreaId], (graphicalItems, id) => graphicalItems.filter(item => item.type === 'area').find(item => item.id === id));
var selectNumericalAxisType = state => {
var layout = selectChartLayout(state);
var isXAxisCategorical = isCategoricalAxis(layout, 'xAxis');
return isXAxisCategorical ? 'yAxis' : 'xAxis';
};
var selectNumericalAxisIdFromGraphicalItemId = (state, graphicalItemId) => {
var axisType = selectNumericalAxisType(state);
if (axisType === 'yAxis') {
return selectYAxisIdFromGraphicalItemId(state, graphicalItemId);
}
return selectXAxisIdFromGraphicalItemId(state, graphicalItemId);
};
var selectNumericalAxisStackGroups = (state, graphicalItemId, isPanorama) => selectStackGroups(state, selectNumericalAxisType(state), selectNumericalAxisIdFromGraphicalItemId(state, graphicalItemId), isPanorama);
export var selectGraphicalItemStackedData = createSelector([selectSynchronisedAreaSettings, selectNumericalAxisStackGroups], (areaSettings, stackGroups) => {
var _stackGroups$stackId;
if (areaSettings == null || stackGroups == null) {
return undefined;
}
var stackId = areaSettings.stackId;
var stackSeriesIdentifier = getStackSeriesIdentifier(areaSettings);
if (stackId == null || stackSeriesIdentifier == null) {
return undefined;
}
var groups = (_stackGroups$stackId = stackGroups[stackId]) === null || _stackGroups$stackId === void 0 ? void 0 : _stackGroups$stackId.stackedData;
var found = groups === null || groups === void 0 ? void 0 : groups.find(v => v.key === stackSeriesIdentifier);
if (found == null) {
return undefined;
}
return found.map(item => [item[0], item[1]]);
});
export var selectArea = createSelector([selectChartLayout, selectXAxisWithScale, selectYAxisWithScale, selectXAxisTicks, selectYAxisTicks, selectGraphicalItemStackedData, selectChartDataWithIndexesIfNotInPanoramaPosition3, selectBandSize, selectSynchronisedAreaSettings, selectChartBaseValue], (layout, xAxis, yAxis, xAxisTicks, yAxisTicks, stackedData, _ref, bandSize, areaSettings, chartBaseValue) => {
var chartData = _ref.chartData,
dataStartIndex = _ref.dataStartIndex,
dataEndIndex = _ref.dataEndIndex;
if (areaSettings == null || layout !== 'horizontal' && layout !== 'vertical' || xAxis == null || yAxis == null || xAxisTicks == null || yAxisTicks == null || xAxisTicks.length === 0 || yAxisTicks.length === 0 || bandSize == null) {
return undefined;
}
var data = areaSettings.data;
var displayedData;
if (data && data.length > 0) {
displayedData = data;
} else {
displayedData = chartData === null || chartData === void 0 ? void 0 : chartData.slice(dataStartIndex, dataEndIndex + 1);
}
if (displayedData == null) {
return undefined;
}
return computeArea({
layout,
xAxis,
yAxis,
xAxisTicks,
yAxisTicks,
dataStartIndex,
areaSettings,
stackedData,
displayedData,
chartBaseValue,
bandSize
});
});

View file

@ -0,0 +1,30 @@
/**
* Checks if two arrays are equal, treating empty arrays as equal regardless of reference.
* If both arrays are non-empty, it checks for reference equality.
* @param a
* @param b
*/
export function emptyArraysAreEqualCheck(a, b) {
if (Array.isArray(a) && Array.isArray(b) && a.length === 0 && b.length === 0) {
// empty arrays are always equal, regardless of reference
return true;
}
return a === b;
}
/**
* Checks if two arrays have the same contents in the same order.
* @param a
* @param b
*/
export function arrayContentsAreEqualCheck(a, b) {
if (a.length === b.length) {
for (var i = 0; i < a.length; i++) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
}
return false;
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,157 @@
import { createSelector } from 'reselect';
import { selectAxisWithScale, selectCartesianAxisSize, selectStackGroups, selectTicksOfGraphicalItem, selectUnfilteredCartesianItems } from './axisSelectors';
import { isNullish } from '../../util/DataUtils';
import { getBandSizeOfAxis } from '../../util/ChartUtils';
import { computeBarRectangles } from '../../cartesian/Bar';
import { selectChartLayout } from '../../context/chartLayoutContext';
import { selectChartDataWithIndexesIfNotInPanoramaPosition3 } from './dataSelectors';
import { selectAxisViewBox, selectChartOffsetInternal } from './selectChartOffsetInternal';
import { selectBarCategoryGap, selectBarGap, selectRootBarSize, selectRootMaxBarSize } from './rootPropsSelectors';
import { combineBarSizeList } from './combiners/combineBarSizeList';
import { combineAllBarPositions } from './combiners/combineAllBarPositions';
import { combineStackedData } from './combiners/combineStackedData';
import { selectXAxisIdFromGraphicalItemId, selectYAxisIdFromGraphicalItemId } from './graphicalItemSelectors';
import { combineBarPosition } from './combiners/combineBarPosition';
var pickIsPanorama = (_state, _id, isPanorama) => isPanorama;
var pickBarId = (_state, id) => id;
var selectSynchronisedBarSettings = createSelector([selectUnfilteredCartesianItems, pickBarId], (graphicalItems, id) => graphicalItems.filter(item => item.type === 'bar').find(item => item.id === id));
export var selectMaxBarSize = createSelector([selectSynchronisedBarSettings], barSettings => barSettings === null || barSettings === void 0 ? void 0 : barSettings.maxBarSize);
var pickCells = (_state, _id, _isPanorama, cells) => cells;
export var selectAllVisibleBars = createSelector([selectChartLayout, selectUnfilteredCartesianItems, selectXAxisIdFromGraphicalItemId, selectYAxisIdFromGraphicalItemId, pickIsPanorama], (layout, allItems, xAxisId, yAxisId, isPanorama) => allItems.filter(i => {
if (layout === 'horizontal') {
return i.xAxisId === xAxisId;
}
return i.yAxisId === yAxisId;
}).filter(i => i.isPanorama === isPanorama).filter(i => i.hide === false).filter(i => i.type === 'bar'));
var selectBarStackGroups = (state, id, isPanorama) => {
var layout = selectChartLayout(state);
var xAxisId = selectXAxisIdFromGraphicalItemId(state, id);
var yAxisId = selectYAxisIdFromGraphicalItemId(state, id);
if (xAxisId == null || yAxisId == null) {
return undefined;
}
if (layout === 'horizontal') {
return selectStackGroups(state, 'yAxis', yAxisId, isPanorama);
}
return selectStackGroups(state, 'xAxis', xAxisId, isPanorama);
};
export var selectBarCartesianAxisSize = (state, id) => {
var layout = selectChartLayout(state);
var xAxisId = selectXAxisIdFromGraphicalItemId(state, id);
var yAxisId = selectYAxisIdFromGraphicalItemId(state, id);
if (xAxisId == null || yAxisId == null) {
return undefined;
}
if (layout === 'horizontal') {
return selectCartesianAxisSize(state, 'xAxis', xAxisId);
}
return selectCartesianAxisSize(state, 'yAxis', yAxisId);
};
export var selectBarSizeList = createSelector([selectAllVisibleBars, selectRootBarSize, selectBarCartesianAxisSize], combineBarSizeList);
export var selectBarBandSize = (state, id, isPanorama) => {
var _ref, _getBandSizeOfAxis;
var barSettings = selectSynchronisedBarSettings(state, id);
if (barSettings == null) {
return 0;
}
var xAxisId = selectXAxisIdFromGraphicalItemId(state, id);
var yAxisId = selectYAxisIdFromGraphicalItemId(state, id);
if (xAxisId == null || yAxisId == null) {
return 0;
}
var layout = selectChartLayout(state);
var globalMaxBarSize = selectRootMaxBarSize(state);
var childMaxBarSize = barSettings.maxBarSize;
var maxBarSize = isNullish(childMaxBarSize) ? globalMaxBarSize : childMaxBarSize;
var axis, ticks;
if (layout === 'horizontal') {
axis = selectAxisWithScale(state, 'xAxis', xAxisId, isPanorama);
ticks = selectTicksOfGraphicalItem(state, 'xAxis', xAxisId, isPanorama);
} else {
axis = selectAxisWithScale(state, 'yAxis', yAxisId, isPanorama);
ticks = selectTicksOfGraphicalItem(state, 'yAxis', yAxisId, isPanorama);
}
return (_ref = (_getBandSizeOfAxis = getBandSizeOfAxis(axis, ticks, true)) !== null && _getBandSizeOfAxis !== void 0 ? _getBandSizeOfAxis : maxBarSize) !== null && _ref !== void 0 ? _ref : 0;
};
export var selectAxisBandSize = (state, id, isPanorama) => {
var layout = selectChartLayout(state);
var xAxisId = selectXAxisIdFromGraphicalItemId(state, id);
var yAxisId = selectYAxisIdFromGraphicalItemId(state, id);
if (xAxisId == null || yAxisId == null) {
return undefined;
}
var axis, ticks;
if (layout === 'horizontal') {
axis = selectAxisWithScale(state, 'xAxis', xAxisId, isPanorama);
ticks = selectTicksOfGraphicalItem(state, 'xAxis', xAxisId, isPanorama);
} else {
axis = selectAxisWithScale(state, 'yAxis', yAxisId, isPanorama);
ticks = selectTicksOfGraphicalItem(state, 'yAxis', yAxisId, isPanorama);
}
return getBandSizeOfAxis(axis, ticks);
};
export var selectAllBarPositions = createSelector([selectBarSizeList, selectRootMaxBarSize, selectBarGap, selectBarCategoryGap, selectBarBandSize, selectAxisBandSize, selectMaxBarSize], combineAllBarPositions);
var selectXAxisWithScale = (state, id, isPanorama) => {
var xAxisId = selectXAxisIdFromGraphicalItemId(state, id);
if (xAxisId == null) {
return undefined;
}
return selectAxisWithScale(state, 'xAxis', xAxisId, isPanorama);
};
var selectYAxisWithScale = (state, id, isPanorama) => {
var yAxisId = selectYAxisIdFromGraphicalItemId(state, id);
if (yAxisId == null) {
return undefined;
}
return selectAxisWithScale(state, 'yAxis', yAxisId, isPanorama);
};
var selectXAxisTicks = (state, id, isPanorama) => {
var xAxisId = selectXAxisIdFromGraphicalItemId(state, id);
if (xAxisId == null) {
return undefined;
}
return selectTicksOfGraphicalItem(state, 'xAxis', xAxisId, isPanorama);
};
var selectYAxisTicks = (state, id, isPanorama) => {
var yAxisId = selectYAxisIdFromGraphicalItemId(state, id);
if (yAxisId == null) {
return undefined;
}
return selectTicksOfGraphicalItem(state, 'yAxis', yAxisId, isPanorama);
};
export var selectBarPosition = createSelector([selectAllBarPositions, selectSynchronisedBarSettings], combineBarPosition);
export var selectStackedDataOfItem = createSelector([selectBarStackGroups, selectSynchronisedBarSettings], combineStackedData);
export var selectBarRectangles = createSelector([selectChartOffsetInternal, selectAxisViewBox, selectXAxisWithScale, selectYAxisWithScale, selectXAxisTicks, selectYAxisTicks, selectBarPosition, selectChartLayout, selectChartDataWithIndexesIfNotInPanoramaPosition3, selectAxisBandSize, selectStackedDataOfItem, selectSynchronisedBarSettings, pickCells], (offset, axisViewBox, xAxis, yAxis, xAxisTicks, yAxisTicks, pos, layout, _ref2, bandSize, stackedData, barSettings, cells) => {
var chartData = _ref2.chartData,
dataStartIndex = _ref2.dataStartIndex,
dataEndIndex = _ref2.dataEndIndex;
if (barSettings == null || pos == null || axisViewBox == null || layout !== 'horizontal' && layout !== 'vertical' || xAxis == null || yAxis == null || xAxisTicks == null || yAxisTicks == null || bandSize == null) {
return undefined;
}
var data = barSettings.data;
var displayedData;
if (data != null && data.length > 0) {
displayedData = data;
} else {
displayedData = chartData === null || chartData === void 0 ? void 0 : chartData.slice(dataStartIndex, dataEndIndex + 1);
}
if (displayedData == null) {
return undefined;
}
return computeBarRectangles({
layout,
barSettings,
pos,
parentViewBox: axisViewBox,
bandSize,
xAxis,
yAxis,
xAxisTicks,
yAxisTicks,
stackedData,
displayedData,
offset,
cells,
dataStartIndex
});
});

View file

@ -0,0 +1,51 @@
import { createSelector } from 'reselect';
import { selectUnfilteredCartesianItems } from './axisSelectors';
import { selectBarRectangles } from './barSelectors';
var pickStackId = (state, stackId) => stackId;
var pickIsPanorama = (state, stackId, isPanorama) => isPanorama;
export var selectAllBarsInStack = createSelector([pickStackId, selectUnfilteredCartesianItems, pickIsPanorama], (stackId, allItems, isPanorama) => {
return allItems.filter(i => i.type === 'bar').filter(i => i.stackId === stackId).filter(i => i.isPanorama === isPanorama).filter(i => !i.hide);
});
var selectAllBarIdsInStack = createSelector([selectAllBarsInStack], allBars => {
return allBars.map(bar => bar.id);
});
/**
* Takes two rectangles and returns a new rectangle that encompasses both.
* It takes the minimum x and y, and the maximum width and height.
* It handles overlapping rectangles, and rectangles with a gap between them.
* @param rect1
* @param rect2
*/
export var expandRectangle = (rect1, rect2) => {
if (!rect1) {
return rect2;
}
if (!rect2) {
return rect1;
}
var x = Math.min(rect1.x, rect1.x + rect1.width, rect2.x, rect2.x + rect2.width);
var y = Math.min(rect1.y, rect1.y + rect1.height, rect2.y, rect2.y + rect2.height);
var maxX = Math.max(rect1.x, rect1.x + rect1.width, rect2.x, rect2.x + rect2.width);
var maxY = Math.max(rect1.y, rect1.y + rect1.height, rect2.y, rect2.y + rect2.height);
var width = maxX - x;
var height = maxY - y;
return {
x,
y,
width,
height
};
};
var combineStackRects = (state, stackId, isPanorama) => {
var allBarIds = selectAllBarIdsInStack(state, stackId, isPanorama);
var stackRects = [];
allBarIds.forEach(barId => {
var rectangles = selectBarRectangles(state, barId, isPanorama, undefined);
rectangles === null || rectangles === void 0 || rectangles.forEach(rect => {
var rectIndex = rect.originalDataIndex;
stackRects[rectIndex] = expandRectangle(stackRects[rectIndex], rect);
});
});
return stackRects;
};
export var selectStackRects = createSelector([state => state, pickStackId, pickIsPanorama], combineStackRects);

View file

@ -0,0 +1,11 @@
import { createSelector } from 'reselect';
import { selectChartOffsetInternal } from './selectChartOffsetInternal';
import { selectMargin } from './containerSelectors';
import { isNumber } from '../../util/DataUtils';
export var selectBrushSettings = state => state.brush;
export var selectBrushDimensions = createSelector([selectBrushSettings, selectChartOffsetInternal, selectMargin], (brushSettings, offset, margin) => ({
height: brushSettings.height,
x: isNumber(brushSettings.x) ? brushSettings.x : offset.left,
y: isNumber(brushSettings.y) ? brushSettings.y : offset.top + offset.height + offset.brushBottom - ((margin === null || margin === void 0 ? void 0 : margin.bottom) || 0),
width: isNumber(brushSettings.width) ? brushSettings.width : offset.width
}));

View file

@ -0,0 +1,9 @@
import { isNan } from '../../../util/DataUtils';
export var combineActiveLabel = (tooltipTicks, activeIndex) => {
var _tooltipTicks$n;
var n = Number(activeIndex);
if (isNan(n) || activeIndex == null) {
return undefined;
}
return n >= 0 ? tooltipTicks === null || tooltipTicks === void 0 || (_tooltipTicks$n = tooltipTicks[n]) === null || _tooltipTicks$n === void 0 ? void 0 : _tooltipTicks$n.value : undefined;
};

View file

@ -0,0 +1,70 @@
import { isWellBehavedNumber } from '../../../util/isWellBehavedNumber';
import { getValueByDataKey } from '../../../util/ChartUtils';
import { isWellFormedNumberDomain } from '../../../util/isDomainSpecifiedByUser';
function toFiniteNumber(value) {
if (typeof value === 'number') {
return Number.isFinite(value) ? value : undefined;
}
if (value instanceof Date) {
var numericValue = value.valueOf();
return Number.isFinite(numericValue) ? numericValue : undefined;
}
var parsed = Number(value);
return Number.isFinite(parsed) ? parsed : undefined;
}
function isValueWithinNumberDomain(value, domain) {
var numericValue = toFiniteNumber(value);
var lowerBound = domain[0];
var upperBound = domain[1];
if (numericValue === undefined) {
return false;
}
var min = Math.min(lowerBound, upperBound);
var max = Math.max(lowerBound, upperBound);
return numericValue >= min && numericValue <= max;
}
function isValueWithinDomain(entry, axisDataKey, domain) {
if (domain == null || axisDataKey == null) {
return true;
}
var value = getValueByDataKey(entry, axisDataKey);
if (value == null) {
return true;
}
if (!isWellFormedNumberDomain(domain)) {
return true;
}
return isValueWithinNumberDomain(value, domain);
}
export var combineActiveTooltipIndex = (tooltipInteraction, chartData, axisDataKey, domain) => {
var desiredIndex = tooltipInteraction === null || tooltipInteraction === void 0 ? void 0 : tooltipInteraction.index;
if (desiredIndex == null) {
return null;
}
var indexAsNumber = Number(desiredIndex);
if (!isWellBehavedNumber(indexAsNumber)) {
// this is for charts like Sankey and Treemap that do not support numerical indexes. We need a proper solution for this before we can start supporting keyboard events on these charts.
return desiredIndex;
}
/*
* Zero is a trivial limit for single-dimensional charts like Line and Area,
* but this also needs a support for multidimensional charts like Sankey and Treemap! TODO
*/
var lowerLimit = 0;
var upperLimit = +Infinity;
if (chartData.length > 0) {
upperLimit = chartData.length - 1;
}
// now let's clamp the desiredIndex between the limits
var clampedIndex = Math.max(lowerLimit, Math.min(indexAsNumber, upperLimit));
var entry = chartData[clampedIndex];
if (entry == null) {
return String(clampedIndex);
}
if (!isValueWithinDomain(entry, axisDataKey, domain)) {
return null;
}
return String(clampedIndex);
};

View file

@ -0,0 +1,85 @@
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); }
import { getPercentValue, isNullish } from '../../../util/DataUtils';
import { isWellBehavedNumber } from '../../../util/isWellBehavedNumber';
function getBarPositions(barGap, barCategoryGap, bandSize, sizeList, maxBarSize) {
var _sizeList$;
var len = sizeList.length;
if (len < 1) {
return undefined;
}
var realBarGap = getPercentValue(barGap, bandSize, 0, true);
var result;
var initialValue = [];
// whether is barSize set by user
// Okay but why does it check only for the first element? What if the first element is set but others are not?
if (isWellBehavedNumber((_sizeList$ = sizeList[0]) === null || _sizeList$ === void 0 ? void 0 : _sizeList$.barSize)) {
var useFull = false;
var fullBarSize = bandSize / len;
var sum = sizeList.reduce((res, entry) => res + (entry.barSize || 0), 0);
sum += (len - 1) * realBarGap;
if (sum >= bandSize) {
sum -= (len - 1) * realBarGap;
realBarGap = 0;
}
if (sum >= bandSize && fullBarSize > 0) {
useFull = true;
fullBarSize *= 0.9;
sum = len * fullBarSize;
}
var offset = Math.round((bandSize - sum) / 2);
var prev = {
offset: offset - realBarGap,
size: 0
};
result = sizeList.reduce((res, entry) => {
var _entry$barSize;
var newPosition = {
stackId: entry.stackId,
dataKeys: entry.dataKeys,
position: {
offset: prev.offset + prev.size + realBarGap,
size: useFull ? fullBarSize : (_entry$barSize = entry.barSize) !== null && _entry$barSize !== void 0 ? _entry$barSize : 0
}
};
var newRes = [...res, newPosition];
prev = newPosition.position;
return newRes;
}, initialValue);
} else {
var _offset = getPercentValue(barCategoryGap, bandSize, 0, true);
if (bandSize - 2 * _offset - (len - 1) * realBarGap <= 0) {
realBarGap = 0;
}
var originalSize = (bandSize - 2 * _offset - (len - 1) * realBarGap) / len;
if (originalSize > 1) {
originalSize = Math.round(originalSize);
}
var size = isWellBehavedNumber(maxBarSize) ? Math.min(originalSize, maxBarSize) : originalSize;
result = sizeList.reduce((res, entry, i) => [...res, {
stackId: entry.stackId,
dataKeys: entry.dataKeys,
position: {
offset: _offset + (originalSize + realBarGap) * i + (originalSize - size) / 2,
size
}
}], initialValue);
}
return result;
}
export var combineAllBarPositions = (sizeList, globalMaxBarSize, barGap, barCategoryGap, barBandSize, bandSize, childMaxBarSize) => {
var maxBarSize = isNullish(childMaxBarSize) ? globalMaxBarSize : childMaxBarSize;
var allBarPositions = getBarPositions(barGap, barCategoryGap, barBandSize !== bandSize ? barBandSize : bandSize, sizeList, maxBarSize);
if (barBandSize !== bandSize && allBarPositions != null) {
allBarPositions = allBarPositions.map(pos => _objectSpread(_objectSpread({}, pos), {}, {
position: _objectSpread(_objectSpread({}, pos.position), {}, {
offset: pos.position.offset - barBandSize / 2
})
}));
}
return allBarPositions;
};

View file

@ -0,0 +1,9 @@
export var combineAxisRangeWithReverse = (axisSettings, axisRange) => {
if (!axisSettings || !axisRange) {
return undefined;
}
if (axisSettings !== null && axisSettings !== void 0 && axisSettings.reversed) {
return [axisRange[1], axisRange[0]];
}
return axisRange;
};

View file

@ -0,0 +1,10 @@
export var combineBarPosition = (allBarPositions, barSettings) => {
if (allBarPositions == null || barSettings == null) {
return undefined;
}
var position = allBarPositions.find(p => p.stackId === barSettings.stackId && barSettings.dataKey != null && p.dataKeys.includes(barSettings.dataKey));
if (position == null) {
return undefined;
}
return position.position;
};

View file

@ -0,0 +1,52 @@
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
import { isStacked } from '../../types/StackedGraphicalItem';
import { getPercentValue, isNullish } from '../../../util/DataUtils';
var getBarSize = (globalSize, totalSize, selfSize) => {
var barSize = selfSize !== null && selfSize !== void 0 ? selfSize : globalSize;
if (isNullish(barSize)) {
return undefined;
}
return getPercentValue(barSize, totalSize, 0);
};
export var combineBarSizeList = (allBars, globalSize, totalSize) => {
var initialValue = {};
var stackedBars = allBars.filter(isStacked);
var unstackedBars = allBars.filter(b => b.stackId == null);
var groupByStack = stackedBars.reduce((acc, bar) => {
var s = acc[bar.stackId];
if (s == null) {
s = [];
}
s.push(bar);
acc[bar.stackId] = s;
return acc;
}, initialValue);
var stackedSizeList = Object.entries(groupByStack).map(_ref => {
var _bars$;
var _ref2 = _slicedToArray(_ref, 2),
stackId = _ref2[0],
bars = _ref2[1];
var dataKeys = bars.map(b => b.dataKey);
var barSize = getBarSize(globalSize, totalSize, (_bars$ = bars[0]) === null || _bars$ === void 0 ? void 0 : _bars$.barSize);
return {
stackId,
dataKeys,
barSize
};
});
var unstackedSizeList = unstackedBars.map(b => {
var dataKeys = [b.dataKey].filter(dk => dk != null);
var barSize = getBarSize(globalSize, totalSize, b.barSize);
return {
stackId: undefined,
dataKeys,
barSize
};
});
return [...stackedSizeList, ...unstackedSizeList];
};

View file

@ -0,0 +1,43 @@
import { isWellFormedNumberDomain } from '../../../util/isDomainSpecifiedByUser';
import { isWellBehavedNumber } from '../../../util/isWellBehavedNumber';
/**
* This function validates and transforms the axis domain so that it is safe to use in the provided scale.
*/
export var combineCheckedDomain = (realScaleType, axisDomain) => {
if (axisDomain == null) {
return undefined;
}
switch (realScaleType) {
case 'linear':
{
/*
* linear scale only reads the first two numbers in the domain, and ignores everything else.
* So if it happens that someone somehow gave us a bigger domain,
* let's pick the min and max from it.
*/
if (!isWellFormedNumberDomain(axisDomain)) {
var min, max;
for (var i = 0; i < axisDomain.length; i++) {
var value = axisDomain[i];
if (!isWellBehavedNumber(value)) {
continue;
}
if (min === undefined || value < min) {
min = value;
}
if (max === undefined || value > max) {
max = value;
}
}
if (min !== undefined && max !== undefined) {
return [min, max];
}
return undefined;
}
return axisDomain;
}
default:
return axisDomain;
}
};

View file

@ -0,0 +1,44 @@
import * as d3Scales from 'victory-vendor/d3-scale';
import { upperFirst } from '../../../util/DataUtils';
function getD3ScaleFromType(realScaleType) {
var scales = d3Scales;
if (realScaleType in scales && typeof scales[realScaleType] === 'function') {
return scales[realScaleType]();
}
var name = "scale".concat(upperFirst(realScaleType));
if (name in scales && typeof scales[name] === 'function') {
return scales[name]();
}
return undefined;
}
/**
* Converts external scale definition into internal RechartsScale definition.
* @param scale custom function scale - if you have the `string` from outside, use `combineRealScaleType` first which will validate it and return RechartsScaleType or undefined
* @param axisDomain
* @param axisRange
*/
export function combineConfiguredScaleInternal(scale, axisDomain, axisRange) {
if (typeof scale === 'function') {
return scale.copy().domain(axisDomain).range(axisRange);
}
if (scale == null) {
return undefined;
}
var d3ScaleFunction = getD3ScaleFromType(scale);
if (d3ScaleFunction == null) {
return undefined;
}
d3ScaleFunction.domain(axisDomain).range(axisRange);
return d3ScaleFunction;
}
export function combineConfiguredScale(axis, realScaleType, axisDomain, axisRange) {
if (axisDomain == null || axisRange == null) {
return undefined;
}
if (typeof axis.scale === 'function') {
return combineConfiguredScaleInternal(axis.scale, axisDomain, axisRange);
}
return combineConfiguredScaleInternal(realScaleType, axisDomain, axisRange);
}

View file

@ -0,0 +1,36 @@
export var combineCoordinateForDefaultIndex = (width, height, layout, offset, tooltipTicks, defaultIndex, tooltipConfigurations) => {
if (defaultIndex == null) {
return undefined;
}
/*
* With defaultIndex alone, we don't have enough information to decide _which_ of the multiple tooltips to display.
* Maybe one day we could add new prop `activeGraphicalItemId` to the chart to help with that.
* Until then, we choose the first one.
*/
var firstConfiguration = tooltipConfigurations[0];
var maybePosition = firstConfiguration === null || firstConfiguration === void 0 ? void 0 : firstConfiguration.getPosition(defaultIndex);
if (maybePosition != null) {
return maybePosition;
}
var tick = tooltipTicks === null || tooltipTicks === void 0 ? void 0 : tooltipTicks[Number(defaultIndex)];
if (!tick) {
return undefined;
}
switch (layout) {
case 'horizontal':
{
return {
x: tick.coordinate,
y: (offset.top + height) / 2
};
}
default:
{
// This logic is not super sound - it conflates vertical, radial, centric layouts into just one. TODO improve!
return {
x: (offset.left + width) / 2,
y: tick.coordinate
};
}
}
};

View file

@ -0,0 +1,48 @@
import { getStackSeriesIdentifier } from '../../../util/stacks/getStackSeriesIdentifier';
import { getValueByDataKey } from '../../../util/ChartUtils';
/**
* In a stacked chart, each graphical item has its own data. That data could be either:
* - defined on the chart root, in which case the item gets a unique dataKey
* - or defined on the item itself, in which case multiple items can share the same dataKey
*
* That means we cannot use the dataKey as a unique identifier for the item.
*
* This type represents a single data point in a stacked chart, where each key is a series identifier
* and the value is the numeric value for that series using the numerical axis dataKey.
*/
export function combineDisplayedStackedData(stackedGraphicalItems, _ref, tooltipAxisSettings) {
var _ref$chartData = _ref.chartData,
chartData = _ref$chartData === void 0 ? [] : _ref$chartData;
var allowDuplicatedCategory = tooltipAxisSettings.allowDuplicatedCategory,
tooltipDataKey = tooltipAxisSettings.dataKey;
// A map of tooltip data keys to the stacked data points
var knownItemsByDataKey = new Map();
stackedGraphicalItems.forEach(item => {
var _item$data;
// If there is no data on the individual item then we use the root chart data
var resolvedData = (_item$data = item.data) !== null && _item$data !== void 0 ? _item$data : chartData;
if (resolvedData == null || resolvedData.length === 0) {
// if that doesn't work then we skip this item
return;
}
var stackIdentifier = getStackSeriesIdentifier(item);
resolvedData.forEach((entry, index) => {
var tooltipValue = tooltipDataKey == null || allowDuplicatedCategory ? index : String(getValueByDataKey(entry, tooltipDataKey, null));
var numericValue = getValueByDataKey(entry, item.dataKey, 0);
var curr;
if (knownItemsByDataKey.has(tooltipValue)) {
curr = knownItemsByDataKey.get(tooltipValue);
} else {
curr = {};
}
Object.assign(curr, {
[stackIdentifier]: numericValue
});
knownItemsByDataKey.set(tooltipValue, curr);
});
});
return Array.from(knownItemsByDataKey.values());
}

View file

@ -0,0 +1,10 @@
import { createCategoricalInverse } from '../../../util/scale/createCategoricalInverse';
export function combineInverseScaleFunction(configuredScale) {
if (configuredScale == null) {
return undefined;
}
if ('invert' in configuredScale && typeof configuredScale.invert === 'function') {
return configuredScale.invert.bind(configuredScale);
}
return createCategoricalInverse(configuredScale, undefined);
}

View file

@ -0,0 +1,28 @@
import * as d3Scales from 'victory-vendor/d3-scale';
import { upperFirst } from '../../../util/DataUtils';
function getD3ScaleName(name) {
return "scale".concat(upperFirst(name));
}
function isSupportedScaleName(name) {
return getD3ScaleName(name) in d3Scales;
}
export var combineRealScaleType = (axisConfig, hasBar, chartType) => {
if (axisConfig == null) {
return undefined;
}
var scale = axisConfig.scale,
type = axisConfig.type;
if (scale === 'auto') {
if (type === 'category' && chartType && (chartType.indexOf('LineChart') >= 0 || chartType.indexOf('AreaChart') >= 0 || chartType.indexOf('ComposedChart') >= 0 && !hasBar)) {
return 'point';
}
if (type === 'category') {
return 'band';
}
return 'linear';
}
if (typeof scale === 'string') {
return isSupportedScaleName(scale) ? scale : 'point';
}
return undefined;
};

View file

@ -0,0 +1,20 @@
import { getStackSeriesIdentifier } from '../../../util/stacks/getStackSeriesIdentifier';
export var combineStackedData = (stackGroups, barSettings) => {
var stackSeriesIdentifier = getStackSeriesIdentifier(barSettings);
if (!stackGroups || stackSeriesIdentifier == null || barSettings == null) {
return undefined;
}
var stackId = barSettings.stackId;
if (stackId == null) {
return undefined;
}
var stackGroup = stackGroups[stackId];
if (!stackGroup) {
return undefined;
}
var stackedData = stackGroup.stackedData;
if (!stackedData) {
return undefined;
}
return stackedData.find(sd => sd.key === stackSeriesIdentifier);
};

View file

@ -0,0 +1,58 @@
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); }
import { noInteraction } from '../../tooltipSlice';
function chooseAppropriateMouseInteraction(tooltipState, tooltipEventType, trigger) {
if (tooltipEventType === 'axis') {
if (trigger === 'click') {
return tooltipState.axisInteraction.click;
}
return tooltipState.axisInteraction.hover;
}
if (trigger === 'click') {
return tooltipState.itemInteraction.click;
}
return tooltipState.itemInteraction.hover;
}
function hasBeenActivePreviously(tooltipInteractionState) {
return tooltipInteractionState.index != null;
}
export var combineTooltipInteractionState = (tooltipState, tooltipEventType, trigger, defaultIndex) => {
if (tooltipEventType == null) {
return noInteraction;
}
var appropriateMouseInteraction = chooseAppropriateMouseInteraction(tooltipState, tooltipEventType, trigger);
if (appropriateMouseInteraction == null) {
return noInteraction;
}
if (appropriateMouseInteraction.active) {
return appropriateMouseInteraction;
}
if (tooltipState.keyboardInteraction.active) {
return tooltipState.keyboardInteraction;
}
if (tooltipState.syncInteraction.active && tooltipState.syncInteraction.index != null) {
return tooltipState.syncInteraction;
}
var activeFromProps = tooltipState.settings.active === true;
if (hasBeenActivePreviously(appropriateMouseInteraction)) {
if (activeFromProps) {
return _objectSpread(_objectSpread({}, appropriateMouseInteraction), {}, {
active: true
});
}
} else if (defaultIndex != null) {
return {
active: true,
coordinate: undefined,
dataKey: undefined,
index: defaultIndex,
graphicalItemId: undefined
};
}
return _objectSpread(_objectSpread({}, noInteraction), {}, {
coordinate: appropriateMouseInteraction.coordinate
});
};

View file

@ -0,0 +1,155 @@
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); }
import { findEntryInArray } from '../../../util/DataUtils';
import { getTooltipEntry, getValueByDataKey } from '../../../util/ChartUtils';
import { getSliced } from '../../../util/getSliced';
function parseName(value) {
if (typeof value === 'string' || typeof value === 'number') {
return value;
}
return undefined;
}
function parseUnit(value) {
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
return value;
}
return undefined;
}
function parseDataKey(value) {
if (typeof value === 'string' || typeof value === 'number') {
return value;
}
if (typeof value === 'function') {
return obj => value(obj);
}
return undefined;
}
function parseColor(value) {
if (typeof value === 'string') {
return value;
}
return undefined;
}
function parseTooltipPayloadItem(item) {
if (item == null || typeof item !== 'object') {
return undefined;
}
var name = 'name' in item ? parseName(item.name) : undefined;
var unit = 'unit' in item ? parseUnit(item.unit) : undefined;
var dataKey = 'dataKey' in item ? parseDataKey(item.dataKey) : undefined;
var payload = 'payload' in item ? item.payload : undefined;
var color = 'color' in item ? parseColor(item.color) : undefined;
var fill = 'fill' in item ? parseColor(item.fill) : undefined;
return {
name,
unit,
dataKey,
payload,
color,
fill
};
}
function selectFinalData(dataDefinedOnItem, dataDefinedOnChart) {
/*
* If a payload has data specified directly from the graphical item, prefer that.
* Otherwise, fill in data from the chart level, using the same index.
*/
if (dataDefinedOnItem != null) {
return dataDefinedOnItem;
}
return dataDefinedOnChart;
}
export var combineTooltipPayload = (tooltipPayloadConfigurations, activeIndex, chartDataState, tooltipAxisDataKey, activeLabel, tooltipPayloadSearcher, tooltipEventType) => {
if (activeIndex == null || tooltipPayloadSearcher == null) {
return undefined;
}
var chartData = chartDataState.chartData,
computedData = chartDataState.computedData,
dataStartIndex = chartDataState.dataStartIndex,
dataEndIndex = chartDataState.dataEndIndex;
var init = [];
return tooltipPayloadConfigurations.reduce((agg, _ref) => {
var _settings$dataKey;
var dataDefinedOnItem = _ref.dataDefinedOnItem,
settings = _ref.settings;
var finalData = selectFinalData(dataDefinedOnItem, chartData);
var sliced = Array.isArray(finalData) ? getSliced(finalData, dataStartIndex, dataEndIndex) : finalData;
var finalDataKey = (_settings$dataKey = settings === null || settings === void 0 ? void 0 : settings.dataKey) !== null && _settings$dataKey !== void 0 ? _settings$dataKey : tooltipAxisDataKey;
// BaseAxisProps does not support nameKey but it could!
var finalNameKey = settings === null || settings === void 0 ? void 0 : settings.nameKey; // ?? tooltipAxis?.nameKey;
var tooltipPayload;
if (tooltipAxisDataKey && Array.isArray(sliced) &&
/*
* findEntryInArray won't work for Scatter because Scatter provides an array of arrays
* as tooltip payloads and findEntryInArray is not prepared to handle that.
* Sad but also ScatterChart only allows 'item' tooltipEventType
* and also this is only a problem if there are multiple Scatters and each has its own data array
* so let's fix that some other time.
*/
!Array.isArray(sliced[0]) &&
/*
* If the tooltipEventType is 'axis', we should search for the dataKey in the sliced data
* because thanks to allowDuplicatedCategory=false, the order of elements in the array
* no longer matches the order of elements in the original data
* and so we need to search by the active dataKey + label rather than by index.
*
* The same happens if multiple graphical items are present in the chart
* and each of them has its own data array. Those arrays get concatenated
* and again the tooltip index no longer matches the original data.
*
* On the other hand the tooltipEventType 'item' should always search by index
* because we get the index from interacting over the individual elements
* which is always accurate, irrespective of the allowDuplicatedCategory setting.
*/
tooltipEventType === 'axis') {
tooltipPayload = findEntryInArray(sliced, tooltipAxisDataKey, activeLabel);
} else {
/*
* This is a problem because it assumes that the index is pointing to the displayed data
* which it isn't because the index is pointing to the tooltip ticks array.
* The above approach (with findEntryInArray) is the correct one, but it only works
* if the axis dataKey is defined explicitly, and if the data is an array of objects.
*/
tooltipPayload = tooltipPayloadSearcher(sliced, activeIndex, computedData, finalNameKey);
}
if (Array.isArray(tooltipPayload)) {
tooltipPayload.forEach(item => {
var _parsedItem$color, _parsedItem$fill;
var parsedItem = parseTooltipPayloadItem(item);
var itemName = parsedItem === null || parsedItem === void 0 ? void 0 : parsedItem.name;
var itemDataKey = parsedItem === null || parsedItem === void 0 ? void 0 : parsedItem.dataKey;
var itemPayload = parsedItem === null || parsedItem === void 0 ? void 0 : parsedItem.payload;
var newSettings = _objectSpread(_objectSpread({}, settings), {}, {
name: itemName,
unit: parsedItem === null || parsedItem === void 0 ? void 0 : parsedItem.unit,
// Preserve item-level color/fill from graphical items.
color: (_parsedItem$color = parsedItem === null || parsedItem === void 0 ? void 0 : parsedItem.color) !== null && _parsedItem$color !== void 0 ? _parsedItem$color : settings === null || settings === void 0 ? void 0 : settings.color,
fill: (_parsedItem$fill = parsedItem === null || parsedItem === void 0 ? void 0 : parsedItem.fill) !== null && _parsedItem$fill !== void 0 ? _parsedItem$fill : settings === null || settings === void 0 ? void 0 : settings.fill
});
agg.push(getTooltipEntry({
tooltipEntrySettings: newSettings,
dataKey: itemDataKey,
payload: itemPayload,
value: getValueByDataKey(itemPayload, itemDataKey),
name: itemName == null ? undefined : String(itemName)
}));
});
} else {
var _getValueByDataKey;
// I am not quite sure why these two branches (Array vs Array of Arrays) have to behave differently - I imagine we should unify these. 3.x breaking change?
agg.push(getTooltipEntry({
tooltipEntrySettings: settings,
dataKey: finalDataKey,
payload: tooltipPayload,
// getValueByDataKey does not validate the output type
value: getValueByDataKey(tooltipPayload, finalDataKey),
// getValueByDataKey does not validate the output type
name: (_getValueByDataKey = getValueByDataKey(tooltipPayload, finalNameKey)) !== null && _getValueByDataKey !== void 0 ? _getValueByDataKey : settings === null || settings === void 0 ? void 0 : settings.name
}));
}
return agg;
}, init);
};

View file

@ -0,0 +1,45 @@
export var combineTooltipPayloadConfigurations = (tooltipState, tooltipEventType, trigger, defaultIndex) => {
// if tooltip reacts to axis interaction, then we display all items at the same time.
if (tooltipEventType === 'axis') {
return tooltipState.tooltipItemPayloads;
}
/*
* By now we already know that tooltipEventType is 'item', so we can only search in itemInteractions.
* item means that only the hovered or clicked item will be present in the tooltip.
*/
if (tooltipState.tooltipItemPayloads.length === 0) {
// No point filtering if the payload is empty
return [];
}
var filterByGraphicalItemId;
if (trigger === 'hover') {
filterByGraphicalItemId = tooltipState.itemInteraction.hover.graphicalItemId;
} else {
filterByGraphicalItemId = tooltipState.itemInteraction.click.graphicalItemId;
}
if (tooltipState.syncInteraction.active && filterByGraphicalItemId == null) {
/*
* When a tooltip is synchronised from another chart, the local itemInteraction
* has no graphicalItemId because the user hasn't hovered over this chart.
* In that case we show all tooltip items so the receiving chart can display
* its own data at the synced index matching the behaviour of axis-type tooltips.
*/
return tooltipState.tooltipItemPayloads;
}
if (filterByGraphicalItemId == null && (defaultIndex != null || tooltipState.keyboardInteraction.active)) {
/*
* So when we use `defaultIndex` - we don't have a dataKey to filter by because user did not hover over anything yet.
* In that case let's display the first item in the tooltip; after all, this is `item` interaction case,
* so we should display only one item at a time instead of all.
*/
var firstItemPayload = tooltipState.tooltipItemPayloads[0];
if (firstItemPayload != null) {
return [firstItemPayload];
}
return [];
}
return tooltipState.tooltipItemPayloads.filter(tpc => {
var _tpc$settings;
return ((_tpc$settings = tpc.settings) === null || _tpc$settings === void 0 ? void 0 : _tpc$settings.graphicalItemId) === filterByGraphicalItemId;
});
};

View file

@ -0,0 +1,4 @@
export var selectChartWidth = state => state.layout.width;
export var selectChartHeight = state => state.layout.height;
export var selectContainerScale = state => state.layout.scale;
export var selectMargin = state => state.layout.margin;

View file

@ -0,0 +1,78 @@
import { createSelector } from 'reselect';
/**
* This selector always returns the data with the indexes set by a Brush.
* Trouble is, that might or might not be what you want.
*
* In charts with Brush, you will sometimes want to select the full range of data, and sometimes the one decided by the Brush
* - even if the Brush is active, the panorama inside the Brush should show the full range of data.
*
* So instead of this selector, consider using either selectChartDataAndAlwaysIgnoreIndexes or selectChartDataWithIndexesIfNotInPanorama
*
* @param state RechartsRootState
* @returns data defined on the chart root element, such as BarChart or ScatterChart
*/
export var selectChartDataWithIndexes = state => state.chartData;
/**
* This selector will always return the full range of data, ignoring the indexes set by a Brush.
* Useful for when you want to render the full range of data, even if a Brush is active.
* For example: in the Brush panorama, in Legend, in Tooltip.
*/
export var selectChartDataAndAlwaysIgnoreIndexes = createSelector([selectChartDataWithIndexes], dataState => {
var dataEndIndex = dataState.chartData != null ? dataState.chartData.length - 1 : 0;
return {
chartData: dataState.chartData,
computedData: dataState.computedData,
dataEndIndex,
dataStartIndex: 0
};
});
export var selectChartDataWithIndexesIfNotInPanoramaPosition4 = (state, _unused1, _unused2, isPanorama) => {
if (isPanorama) {
return selectChartDataAndAlwaysIgnoreIndexes(state);
}
return selectChartDataWithIndexes(state);
};
export var selectChartDataWithIndexesIfNotInPanoramaPosition3 = (state, _unused1, isPanorama) => {
if (isPanorama) {
return selectChartDataAndAlwaysIgnoreIndexes(state);
}
return selectChartDataWithIndexes(state);
};
/**
* Returns the chart-level data slice (respecting Brush indexes), memoized by content so that
* spurious Immer reference changes (e.g. dispatching `setChartData(undefined)` when data is
* already `undefined`) do not propagate to downstream selectors.
*
* Used when a selector needs chart-level data but must avoid extra recomputes when the
* data content has not actually changed.
*/
export var selectChartDataSliceIfNotInPanorama = createSelector([selectChartDataWithIndexesIfNotInPanoramaPosition4], _ref => {
var chartData = _ref.chartData,
dataStartIndex = _ref.dataStartIndex,
dataEndIndex = _ref.dataEndIndex;
return chartData != null ? chartData.slice(dataStartIndex, dataEndIndex + 1) : [];
});
/**
* Returns the chart-level data slice (ignoring Brush indexes), memoized by content.
* Used in tooltip and polar selectors that always need the full data range.
*/
export var selectChartDataSliceIgnoringIndexes = createSelector([selectChartDataAndAlwaysIgnoreIndexes], _ref2 => {
var chartData = _ref2.chartData,
dataStartIndex = _ref2.dataStartIndex,
dataEndIndex = _ref2.dataEndIndex;
return chartData != null ? chartData.slice(dataStartIndex, dataEndIndex + 1) : [];
});
/**
* Returns the chart-level data slice (with Brush indexes applied), memoized by content.
* Used in tooltip selectors.
*/
export var selectChartDataSliceWithIndexes = createSelector([selectChartDataWithIndexes], _ref3 => {
var chartData = _ref3.chartData,
dataStartIndex = _ref3.dataStartIndex,
dataEndIndex = _ref3.dataEndIndex;
return chartData != null ? chartData.slice(dataStartIndex, dataEndIndex + 1) : [];
});

View file

@ -0,0 +1,49 @@
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); }
import { createSelector } from 'reselect';
import { computeFunnelTrapezoids } from '../../cartesian/Funnel';
import { selectChartOffsetInternal } from './selectChartOffsetInternal';
import { selectChartDataAndAlwaysIgnoreIndexes } from './dataSelectors';
var pickFunnelSettings = (_state, funnelSettings) => funnelSettings;
export var selectFunnelTrapezoids = createSelector([selectChartOffsetInternal, pickFunnelSettings, selectChartDataAndAlwaysIgnoreIndexes], (offset, _ref, _ref2) => {
var data = _ref.data,
dataKey = _ref.dataKey,
nameKey = _ref.nameKey,
tooltipType = _ref.tooltipType,
lastShapeType = _ref.lastShapeType,
reversed = _ref.reversed,
customWidth = _ref.customWidth,
cells = _ref.cells,
presentationProps = _ref.presentationProps,
graphicalItemId = _ref.id;
var chartData = _ref2.chartData;
var displayedData;
if (data != null && data.length > 0) {
displayedData = data;
} else if (chartData != null && chartData.length > 0) {
displayedData = chartData;
}
if (displayedData && displayedData.length) {
displayedData = displayedData.map((entry, index) => _objectSpread(_objectSpread(_objectSpread({
payload: entry
}, presentationProps), entry), cells && cells[index] && cells[index].props));
} else if (cells && cells.length) {
displayedData = cells.map(cell => _objectSpread(_objectSpread({}, presentationProps), cell.props));
} else {
return [];
}
return computeFunnelTrapezoids({
dataKey,
nameKey,
displayedData,
tooltipType,
lastShapeType,
reversed,
offset,
customWidth,
graphicalItemId
});
});

View file

@ -0,0 +1,9 @@
import { defaultAxisId } from '../cartesianAxisSlice';
export function selectXAxisIdFromGraphicalItemId(state, id) {
var _state$graphicalItems, _state$graphicalItems2;
return (_state$graphicalItems = (_state$graphicalItems2 = state.graphicalItems.cartesianItems.find(item => item.id === id)) === null || _state$graphicalItems2 === void 0 ? void 0 : _state$graphicalItems2.xAxisId) !== null && _state$graphicalItems !== void 0 ? _state$graphicalItems : defaultAxisId;
}
export function selectYAxisIdFromGraphicalItemId(state, id) {
var _state$graphicalItems3, _state$graphicalItems4;
return (_state$graphicalItems3 = (_state$graphicalItems4 = state.graphicalItems.cartesianItems.find(item => item.id === id)) === null || _state$graphicalItems4 === void 0 ? void 0 : _state$graphicalItems4.yAxisId) !== null && _state$graphicalItems3 !== void 0 ? _state$graphicalItems3 : defaultAxisId;
}

View file

@ -0,0 +1,10 @@
import { createSelector } from 'reselect';
import sortBy from 'es-toolkit/compat/sortBy';
export var selectLegendSettings = state => state.legend.settings;
export var selectLegendSize = state => state.legend.size;
var selectAllLegendPayload2DArray = state => state.legend.payload;
export var selectLegendPayload = createSelector([selectAllLegendPayload2DArray, selectLegendSettings], (payloads, _ref) => {
var itemSorter = _ref.itemSorter;
var flat = payloads.flat(1);
return itemSorter ? sortBy(flat, itemSorter) : flat;
});

View file

@ -0,0 +1,59 @@
import { createSelector } from 'reselect';
import { computeLinePoints } from '../../cartesian/Line';
import { selectChartDataWithIndexesIfNotInPanoramaPosition4 } from './dataSelectors';
import { selectChartLayout } from '../../context/chartLayoutContext';
import { selectAxisWithScale, selectTicksOfGraphicalItem, selectUnfilteredCartesianItems } from './axisSelectors';
import { getBandSizeOfAxis, isCategoricalAxis } from '../../util/ChartUtils';
var selectXAxisWithScale = (state, xAxisId, _yAxisId, isPanorama) => selectAxisWithScale(state, 'xAxis', xAxisId, isPanorama);
var selectXAxisTicks = (state, xAxisId, _yAxisId, isPanorama) => selectTicksOfGraphicalItem(state, 'xAxis', xAxisId, isPanorama);
var selectYAxisWithScale = (state, _xAxisId, yAxisId, isPanorama) => selectAxisWithScale(state, 'yAxis', yAxisId, isPanorama);
var selectYAxisTicks = (state, _xAxisId, yAxisId, isPanorama) => selectTicksOfGraphicalItem(state, 'yAxis', yAxisId, isPanorama);
var selectBandSize = createSelector([selectChartLayout, selectXAxisWithScale, selectYAxisWithScale, selectXAxisTicks, selectYAxisTicks], (layout, xAxis, yAxis, xAxisTicks, yAxisTicks) => {
if (isCategoricalAxis(layout, 'xAxis')) {
return getBandSizeOfAxis(xAxis, xAxisTicks, false);
}
return getBandSizeOfAxis(yAxis, yAxisTicks, false);
});
var pickLineId = (_state, _xAxisId, _yAxisId, _isPanorama, id) => id;
function isLineSettings(item) {
return item.type === 'line';
}
/*
* There is a race condition problem because we read some data from props and some from the state.
* The state is updated through a dispatch and is one render behind,
* and so we have this weird one tick render where the displayedData in one selector have the old dataKey
* but the new dataKey in another selector.
*
* So here instead of reading the dataKey from the props, we always read it from the state.
*/
var selectSynchronisedLineSettings = createSelector([selectUnfilteredCartesianItems, pickLineId], (graphicalItems, id) => graphicalItems.filter(isLineSettings).find(x => x.id === id));
export var selectLinePoints = createSelector([selectChartLayout, selectXAxisWithScale, selectYAxisWithScale, selectXAxisTicks, selectYAxisTicks, selectSynchronisedLineSettings, selectBandSize, selectChartDataWithIndexesIfNotInPanoramaPosition4], (layout, xAxis, yAxis, xAxisTicks, yAxisTicks, lineSettings, bandSize, _ref) => {
var chartData = _ref.chartData,
dataStartIndex = _ref.dataStartIndex,
dataEndIndex = _ref.dataEndIndex;
if (lineSettings == null || xAxis == null || yAxis == null || xAxisTicks == null || yAxisTicks == null || xAxisTicks.length === 0 || yAxisTicks.length === 0 || bandSize == null || layout !== 'horizontal' && layout !== 'vertical') {
return undefined;
}
var dataKey = lineSettings.dataKey,
data = lineSettings.data;
var displayedData;
if (data != null && data.length > 0) {
displayedData = data;
} else {
displayedData = chartData === null || chartData === void 0 ? void 0 : chartData.slice(dataStartIndex, dataEndIndex + 1);
}
if (displayedData == null) {
return undefined;
}
return computeLinePoints({
layout,
xAxis,
yAxis,
xAxisTicks,
yAxisTicks,
dataKey,
bandSize,
displayedData
});
});

View file

@ -0,0 +1,9 @@
export var numberDomainEqualityCheck = (a, b) => {
if (a === b) {
return true;
}
if (a == null || b == null) {
return false;
}
return a[0] === b[0] && a[1] === b[1];
};

View file

@ -0,0 +1 @@
export var pickAxisId = (_state, _axisType, axisId) => axisId;

View file

@ -0,0 +1 @@
export var pickAxisType = (_state, axisType) => axisType;

View file

@ -0,0 +1,77 @@
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); }
import { createSelector } from 'reselect';
import { computePieSectors } from '../../polar/Pie';
import { selectChartDataAndAlwaysIgnoreIndexes } from './dataSelectors';
import { selectChartOffsetInternal } from './selectChartOffsetInternal';
import { getTooltipNameProp, getValueByDataKey } from '../../util/ChartUtils';
import { selectUnfilteredPolarItems } from './polarSelectors';
var pickId = (_state, id) => id;
var selectSynchronisedPieSettings = createSelector([selectUnfilteredPolarItems, pickId], (graphicalItems, id) => graphicalItems.filter(item => item.type === 'pie').find(item => item.id === id));
// Keep stable reference to an empty array to prevent re-renders
var emptyArray = [];
var pickCells = (_state, _id, cells) => {
if ((cells === null || cells === void 0 ? void 0 : cells.length) === 0) {
return emptyArray;
}
return cells;
};
export var selectDisplayedData = createSelector([selectChartDataAndAlwaysIgnoreIndexes, selectSynchronisedPieSettings, pickCells], (_ref, pieSettings, cells) => {
var chartData = _ref.chartData;
if (pieSettings == null) {
return undefined;
}
var displayedData;
if ((pieSettings === null || pieSettings === void 0 ? void 0 : pieSettings.data) != null && pieSettings.data.length > 0) {
displayedData = pieSettings.data;
} else {
displayedData = chartData;
}
if ((!displayedData || !displayedData.length) && cells != null) {
displayedData = cells.map(cell => _objectSpread(_objectSpread({}, pieSettings.presentationProps), cell.props));
}
if (displayedData == null) {
return undefined;
}
return displayedData;
});
export var selectPieLegend = createSelector([selectDisplayedData, selectSynchronisedPieSettings, pickCells], (displayedData, pieSettings, cells) => {
if (displayedData == null || pieSettings == null) {
return undefined;
}
return displayedData.map((entry, i) => {
var _cells$i;
var name = getValueByDataKey(entry, pieSettings.nameKey, pieSettings.name);
var color;
if (cells !== null && cells !== void 0 && (_cells$i = cells[i]) !== null && _cells$i !== void 0 && (_cells$i = _cells$i.props) !== null && _cells$i !== void 0 && _cells$i.fill) {
color = cells[i].props.fill;
} else if (typeof entry === 'object' && entry != null && 'fill' in entry) {
color = entry.fill;
} else {
color = pieSettings.fill;
}
return {
value: getTooltipNameProp(name, pieSettings.dataKey),
dataKey: pieSettings.dataKey,
color,
// @ts-expect-error Legend payload.payload says it wants objects but our data can be unknown
payload: entry,
type: pieSettings.legendType
};
});
});
export var selectPieSectors = createSelector([selectDisplayedData, selectSynchronisedPieSettings, pickCells, selectChartOffsetInternal], (displayedData, pieSettings, cells, offset) => {
if (pieSettings == null || displayedData == null) {
return undefined;
}
return computePieSectors({
offset,
pieSettings,
displayedData,
cells
});
});

View file

@ -0,0 +1,130 @@
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); }
import { createSelector } from 'reselect';
import { selectChartHeight, selectChartWidth } from './containerSelectors';
import { selectChartOffsetInternal } from './selectChartOffsetInternal';
import { getMaxRadius } from '../../util/PolarUtils';
import { getPercentValue } from '../../util/DataUtils';
import { defaultPolarAngleAxisProps } from '../../polar/defaultPolarAngleAxisProps';
import { defaultPolarRadiusAxisProps } from '../../polar/defaultPolarRadiusAxisProps';
import { combineAxisRangeWithReverse } from './combiners/combineAxisRangeWithReverse';
import { selectChartLayout, selectPolarChartLayout } from '../../context/chartLayoutContext';
import { getAxisTypeBasedOnLayout } from '../../util/getAxisTypeBasedOnLayout';
export var implicitAngleAxis = {
allowDataOverflow: defaultPolarAngleAxisProps.allowDataOverflow,
allowDecimals: defaultPolarAngleAxisProps.allowDecimals,
allowDuplicatedCategory: false,
// defaultPolarAngleAxisProps.allowDuplicatedCategory has it set to true but the actual axis rendering ignores the prop because reasons,
dataKey: undefined,
domain: undefined,
id: defaultPolarAngleAxisProps.angleAxisId,
includeHidden: false,
name: undefined,
reversed: defaultPolarAngleAxisProps.reversed,
scale: defaultPolarAngleAxisProps.scale,
tick: defaultPolarAngleAxisProps.tick,
tickCount: undefined,
ticks: undefined,
type: defaultPolarAngleAxisProps.type,
unit: undefined,
niceTicks: 'auto'
};
export var implicitRadiusAxis = {
allowDataOverflow: defaultPolarRadiusAxisProps.allowDataOverflow,
allowDecimals: defaultPolarRadiusAxisProps.allowDecimals,
allowDuplicatedCategory: defaultPolarRadiusAxisProps.allowDuplicatedCategory,
dataKey: undefined,
domain: undefined,
id: defaultPolarRadiusAxisProps.radiusAxisId,
includeHidden: defaultPolarRadiusAxisProps.includeHidden,
name: undefined,
reversed: defaultPolarRadiusAxisProps.reversed,
scale: defaultPolarRadiusAxisProps.scale,
tick: defaultPolarRadiusAxisProps.tick,
tickCount: defaultPolarRadiusAxisProps.tickCount,
ticks: undefined,
type: defaultPolarRadiusAxisProps.type,
unit: undefined,
niceTicks: 'auto'
};
var selectAngleAxisNoDefaults = (state, angleAxisId) => {
if (angleAxisId == null) {
return undefined;
}
return state.polarAxis.angleAxis[angleAxisId];
};
export var selectAngleAxis = createSelector([selectAngleAxisNoDefaults, selectPolarChartLayout], (angleAxisSettings, layout) => {
var _getAxisTypeBasedOnLa;
if (angleAxisSettings != null) {
return angleAxisSettings;
}
var evaluatedType = (_getAxisTypeBasedOnLa = getAxisTypeBasedOnLayout(layout, 'angleAxis', implicitAngleAxis.type)) !== null && _getAxisTypeBasedOnLa !== void 0 ? _getAxisTypeBasedOnLa : 'category';
return _objectSpread(_objectSpread({}, implicitAngleAxis), {}, {
type: evaluatedType
});
});
var selectRadiusAxisNoDefaults = (state, radiusAxisId) => {
return state.polarAxis.radiusAxis[radiusAxisId];
};
export var selectRadiusAxis = createSelector([selectRadiusAxisNoDefaults, selectPolarChartLayout], (radiusAxisSettings, layout) => {
var _getAxisTypeBasedOnLa2;
if (radiusAxisSettings != null) {
return radiusAxisSettings;
}
var evaluatedType = (_getAxisTypeBasedOnLa2 = getAxisTypeBasedOnLayout(layout, 'radiusAxis', implicitRadiusAxis.type)) !== null && _getAxisTypeBasedOnLa2 !== void 0 ? _getAxisTypeBasedOnLa2 : 'category';
return _objectSpread(_objectSpread({}, implicitRadiusAxis), {}, {
type: evaluatedType
});
});
export var selectPolarOptions = state => state.polarOptions;
export var selectMaxRadius = createSelector([selectChartWidth, selectChartHeight, selectChartOffsetInternal], getMaxRadius);
var selectInnerRadius = createSelector([selectPolarOptions, selectMaxRadius], (polarChartOptions, maxRadius) => {
if (polarChartOptions == null) {
return undefined;
}
return getPercentValue(polarChartOptions.innerRadius, maxRadius, 0);
});
export var selectOuterRadius = createSelector([selectPolarOptions, selectMaxRadius], (polarChartOptions, maxRadius) => {
if (polarChartOptions == null) {
return undefined;
}
return getPercentValue(polarChartOptions.outerRadius, maxRadius, maxRadius * 0.8);
});
var combineAngleAxisRange = polarOptions => {
if (polarOptions == null) {
return [0, 0];
}
var startAngle = polarOptions.startAngle,
endAngle = polarOptions.endAngle;
return [startAngle, endAngle];
};
export var selectAngleAxisRange = createSelector([selectPolarOptions], combineAngleAxisRange);
export var selectAngleAxisRangeWithReversed = createSelector([selectAngleAxis, selectAngleAxisRange], combineAxisRangeWithReverse);
export var selectRadiusAxisRange = createSelector([selectMaxRadius, selectInnerRadius, selectOuterRadius], (maxRadius, innerRadius, outerRadius) => {
if (maxRadius == null || innerRadius == null || outerRadius == null) {
return undefined;
}
return [innerRadius, outerRadius];
});
export var selectRadiusAxisRangeWithReversed = createSelector([selectRadiusAxis, selectRadiusAxisRange], combineAxisRangeWithReverse);
export var selectPolarViewBox = createSelector([selectChartLayout, selectPolarOptions, selectInnerRadius, selectOuterRadius, selectChartWidth, selectChartHeight], (layout, polarOptions, innerRadius, outerRadius, width, height) => {
if (layout !== 'centric' && layout !== 'radial' || polarOptions == null || innerRadius == null || outerRadius == null) {
return undefined;
}
var cx = polarOptions.cx,
cy = polarOptions.cy,
startAngle = polarOptions.startAngle,
endAngle = polarOptions.endAngle;
return {
cx: getPercentValue(cx, width, width / 2),
cy: getPercentValue(cy, height, height / 2),
innerRadius,
outerRadius,
startAngle,
endAngle,
clockWise: false // this property look useful, why not use it?
};
});

View file

@ -0,0 +1,16 @@
import { createSelector } from 'reselect';
import { selectPolarAxisTicks } from './polarScaleSelectors';
var selectAngleAxisTicks = (state, anglexisId) => selectPolarAxisTicks(state, 'angleAxis', anglexisId, false);
export var selectPolarGridAngles = createSelector([selectAngleAxisTicks], ticks => {
if (!ticks) {
return undefined;
}
return ticks.map(tick => tick.coordinate);
});
var selectRadiusAxisTicks = (state, radiusAxisId) => selectPolarAxisTicks(state, 'radiusAxis', radiusAxisId, false);
export var selectPolarGridRadii = createSelector([selectRadiusAxisTicks], ticks => {
if (!ticks) {
return undefined;
}
return ticks.map(tick => tick.coordinate);
});

View file

@ -0,0 +1,62 @@
import { createSelector } from 'reselect';
import { combineAxisTicks, combineCategoricalDomain, combineGraphicalItemTicks, selectDuplicateDomain, selectRealScaleType, selectRenderableAxisSettings } from './axisSelectors';
import { selectAngleAxis, selectAngleAxisRangeWithReversed, selectRadiusAxis, selectRadiusAxisRangeWithReversed } from './polarAxisSelectors';
import { selectChartLayout } from '../../context/chartLayoutContext';
import { selectPolarAppliedValues, selectPolarAxisCheckedDomain, selectPolarNiceTicks } from './polarSelectors';
import { pickAxisType } from './pickAxisType';
import { rechartsScaleFactory } from '../../util/scale/RechartsScale';
import { combineConfiguredScale } from './combiners/combineConfiguredScale';
export var selectPolarAxis = (state, axisType, axisId) => {
switch (axisType) {
case 'angleAxis':
{
return selectAngleAxis(state, axisId);
}
case 'radiusAxis':
{
return selectRadiusAxis(state, axisId);
}
default:
{
throw new Error("Unexpected axis type: ".concat(axisType));
}
}
};
var selectPolarAxisRangeWithReversed = (state, axisType, axisId) => {
switch (axisType) {
case 'angleAxis':
{
return selectAngleAxisRangeWithReversed(state, axisId);
}
case 'radiusAxis':
{
return selectRadiusAxisRangeWithReversed(state, axisId);
}
default:
{
throw new Error("Unexpected axis type: ".concat(axisType));
}
}
};
var selectPolarConfiguredScale = createSelector([selectPolarAxis, selectRealScaleType, selectPolarAxisCheckedDomain, selectPolarAxisRangeWithReversed], combineConfiguredScale);
export var selectPolarAxisScale = createSelector([selectPolarConfiguredScale], rechartsScaleFactory);
export var selectPolarCategoricalDomain = createSelector([selectChartLayout, selectPolarAppliedValues, selectRenderableAxisSettings, pickAxisType], combineCategoricalDomain);
export var selectPolarAxisTicks = createSelector([selectChartLayout, selectPolarAxis, selectRealScaleType, selectPolarAxisScale, selectPolarNiceTicks, selectPolarAxisRangeWithReversed, selectDuplicateDomain, selectPolarCategoricalDomain, pickAxisType], combineAxisTicks);
export var selectPolarAngleAxisTicks = createSelector([selectPolarAxisTicks], ticks => {
/*
* Angle axis is circular; so here we need to look for ticks that overlap (i.e., 0 and 360 degrees)
* and remove the duplicate tick to avoid rendering issues.
*/
if (!ticks) {
return undefined;
}
var uniqueTicksMap = new Map();
ticks.forEach(tick => {
var normalizedCoordinate = (tick.coordinate + 360) % 360;
if (!uniqueTicksMap.has(normalizedCoordinate)) {
uniqueTicksMap.set(normalizedCoordinate, tick);
}
});
return Array.from(uniqueTicksMap.values());
});
export var selectPolarGraphicalItemAxisTicks = createSelector([selectChartLayout, selectPolarAxis, selectPolarAxisScale, selectPolarAxisRangeWithReversed, selectDuplicateDomain, selectPolarCategoricalDomain, pickAxisType], combineGraphicalItemTicks);

View file

@ -0,0 +1,46 @@
import { createSelector } from 'reselect';
import { selectChartDataAndAlwaysIgnoreIndexes, selectChartDataSliceIgnoringIndexes } from './dataSelectors';
import { combineAppliedValues, combineAxisDomain, combineAxisDomainWithNiceTicks, combineDisplayedData, combineDomainOfAllAppliedNumericalValuesIncludingErrorValues, combineGraphicalItemsData, combineGraphicalItemsSettings, combineNiceTicks, combineNumericalDomain, itemAxisPredicate, selectAllErrorBarSettings, selectBaseAxis, selectDomainDefinition, selectDomainFromUserPreference, selectRealScaleType, selectRenderableAxisSettings } from './axisSelectors';
import { selectChartLayout } from '../../context/chartLayoutContext';
import { getValueByDataKey } from '../../util/ChartUtils';
import { pickAxisType } from './pickAxisType';
import { pickAxisId } from './pickAxisId';
import { selectStackOffsetType } from './rootPropsSelectors';
import { combineCheckedDomain } from './combiners/combineCheckedDomain';
export var selectUnfilteredPolarItems = state => state.graphicalItems.polarItems;
var selectAxisPredicate = createSelector([pickAxisType, pickAxisId], itemAxisPredicate);
export var selectPolarItemsSettings = createSelector([selectUnfilteredPolarItems, selectBaseAxis, selectAxisPredicate], combineGraphicalItemsSettings);
var selectPolarGraphicalItemsData = createSelector([selectPolarItemsSettings], combineGraphicalItemsData);
export var selectPolarDisplayedData = createSelector([selectPolarGraphicalItemsData, selectChartDataAndAlwaysIgnoreIndexes], combineDisplayedData);
export var selectPolarAppliedValues = createSelector([selectPolarDisplayedData, selectBaseAxis, selectPolarItemsSettings], combineAppliedValues);
export var selectAllPolarAppliedNumericalValues = createSelector([selectPolarDisplayedData, selectBaseAxis, selectPolarItemsSettings], (data, axisSettings, items) => {
if (items.length > 0) {
return data.flatMap(entry => {
return items.flatMap(item => {
var _axisSettings$dataKey;
var valueByDataKey = getValueByDataKey(entry, (_axisSettings$dataKey = axisSettings.dataKey) !== null && _axisSettings$dataKey !== void 0 ? _axisSettings$dataKey : item.dataKey);
return {
value: valueByDataKey,
errorDomain: [] // polar charts do not have error bars
};
});
}).filter(Boolean);
}
if ((axisSettings === null || axisSettings === void 0 ? void 0 : axisSettings.dataKey) != null) {
return data.map(item => ({
value: getValueByDataKey(item, axisSettings.dataKey),
errorDomain: []
}));
}
return data.map(entry => ({
value: entry,
errorDomain: []
}));
});
var unsupportedInPolarChart = () => undefined;
var selectDomainOfAllPolarAppliedNumericalValues = createSelector([selectPolarDisplayedData, selectBaseAxis, selectPolarItemsSettings, selectAllErrorBarSettings, pickAxisType, selectChartDataSliceIgnoringIndexes], combineDomainOfAllAppliedNumericalValuesIncludingErrorValues);
var selectPolarNumericalDomain = createSelector([selectBaseAxis, selectDomainDefinition, selectDomainFromUserPreference, unsupportedInPolarChart, selectDomainOfAllPolarAppliedNumericalValues, unsupportedInPolarChart, selectChartLayout, pickAxisType], combineNumericalDomain);
export var selectPolarAxisDomain = createSelector([selectBaseAxis, selectChartLayout, selectPolarDisplayedData, selectPolarAppliedValues, selectStackOffsetType, pickAxisType, selectPolarNumericalDomain], combineAxisDomain);
export var selectPolarNiceTicks = createSelector([selectPolarAxisDomain, selectRenderableAxisSettings, selectRealScaleType], combineNiceTicks);
export var selectPolarAxisDomainIncludingNiceTicks = createSelector([selectBaseAxis, selectPolarAxisDomain, selectPolarNiceTicks, pickAxisType], combineAxisDomainWithNiceTicks);
export var selectPolarAxisCheckedDomain = createSelector([selectRealScaleType, selectPolarAxisDomainIncludingNiceTicks], combineCheckedDomain);

View file

@ -0,0 +1,90 @@
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); }
import { createSelector } from 'reselect';
import { computeRadarPoints } from '../../polar/Radar';
import { selectPolarAxisScale, selectPolarAxisTicks } from './polarScaleSelectors';
import { selectAngleAxis, selectPolarViewBox, selectRadiusAxis } from './polarAxisSelectors';
import { selectChartDataAndAlwaysIgnoreIndexes } from './dataSelectors';
import { selectChartLayout } from '../../context/chartLayoutContext';
import { getBandSizeOfAxis, isCategoricalAxis } from '../../util/ChartUtils';
import { selectUnfilteredPolarItems } from './polarSelectors';
var selectRadiusAxisScale = (state, radiusAxisId) => selectPolarAxisScale(state, 'radiusAxis', radiusAxisId);
var selectRadiusAxisForRadar = createSelector([selectRadiusAxisScale], scale => {
if (scale == null) {
return undefined;
}
return {
scale
};
});
export var selectRadiusAxisForBandSize = createSelector([selectRadiusAxis, selectRadiusAxisScale], (axisSettings, scale) => {
if (axisSettings == null || scale == null) {
return undefined;
}
return _objectSpread(_objectSpread({}, axisSettings), {}, {
scale
});
});
var selectRadiusAxisTicks = (state, radiusAxisId, _angleAxisId, isPanorama) => {
return selectPolarAxisTicks(state, 'radiusAxis', radiusAxisId, isPanorama);
};
var selectAngleAxisForRadar = (state, _radiusAxisId, angleAxisId) => selectAngleAxis(state, angleAxisId);
var selectPolarAxisScaleForRadar = (state, _radiusAxisId, angleAxisId) => selectPolarAxisScale(state, 'angleAxis', angleAxisId);
export var selectAngleAxisForBandSize = createSelector([selectAngleAxisForRadar, selectPolarAxisScaleForRadar], (axisSettings, scale) => {
if (axisSettings == null || scale == null) {
return undefined;
}
return _objectSpread(_objectSpread({}, axisSettings), {}, {
scale
});
});
var selectAngleAxisTicks = (state, _radiusAxisId, angleAxisId, isPanorama) => {
return selectPolarAxisTicks(state, 'angleAxis', angleAxisId, isPanorama);
};
export var selectAngleAxisWithScaleAndViewport = createSelector([selectAngleAxisForRadar, selectPolarAxisScaleForRadar, selectPolarViewBox], (axisOptions, scale, polarViewBox) => {
if (polarViewBox == null || scale == null) {
return undefined;
}
return {
scale,
type: axisOptions.type,
dataKey: axisOptions.dataKey,
cx: polarViewBox.cx,
cy: polarViewBox.cy
};
});
var pickId = (_state, _radiusAxisId, _angleAxisId, _isPanorama, radarId) => radarId;
var selectBandSizeOfAxis = createSelector([selectChartLayout, selectRadiusAxisForBandSize, selectRadiusAxisTicks, selectAngleAxisForBandSize, selectAngleAxisTicks], (layout, radiusAxis, radiusAxisTicks, angleAxis, angleAxisTicks) => {
if (isCategoricalAxis(layout, 'radiusAxis')) {
return getBandSizeOfAxis(radiusAxis, radiusAxisTicks, false);
}
return getBandSizeOfAxis(angleAxis, angleAxisTicks, false);
});
var selectSynchronisedRadarDataKey = createSelector([selectUnfilteredPolarItems, pickId], (graphicalItems, radarId) => {
if (graphicalItems == null) {
return undefined;
}
// Find the radar item with the given radarId
var pgis = graphicalItems.find(item => item.type === 'radar' && radarId === item.id);
// If found, return its dataKey
return pgis === null || pgis === void 0 ? void 0 : pgis.dataKey;
});
export var selectRadarPoints = createSelector([selectRadiusAxisForRadar, selectAngleAxisWithScaleAndViewport, selectChartDataAndAlwaysIgnoreIndexes, selectSynchronisedRadarDataKey, selectBandSizeOfAxis], (radiusAxis, angleAxis, _ref, dataKey, bandSize) => {
var chartData = _ref.chartData,
dataStartIndex = _ref.dataStartIndex,
dataEndIndex = _ref.dataEndIndex;
if (radiusAxis == null || angleAxis == null || chartData == null || bandSize == null || dataKey == null) {
return undefined;
}
var displayedData = chartData.slice(dataStartIndex, dataEndIndex + 1);
return computeRadarPoints({
radiusAxis,
angleAxis,
displayedData,
dataKey,
bandSize
});
});

View file

@ -0,0 +1,175 @@
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); }
import { createSelector } from 'reselect';
import { computeRadialBarDataItems } from '../../polar/RadialBar';
import { selectChartDataAndAlwaysIgnoreIndexes, selectChartDataWithIndexes } from './dataSelectors';
import { selectPolarAxisScale, selectPolarAxisTicks, selectPolarGraphicalItemAxisTicks } from './polarScaleSelectors';
import { combineStackGroups, selectTooltipAxis } from './axisSelectors';
import { selectAngleAxis, selectPolarViewBox, selectRadiusAxis } from './polarAxisSelectors';
import { selectChartLayout } from '../../context/chartLayoutContext';
import { getBandSizeOfAxis, getBaseValueOfBar, isCategoricalAxis } from '../../util/ChartUtils';
import { selectBarCategoryGap, selectBarGap, selectReverseStackOrder, selectRootBarSize, selectRootMaxBarSize, selectStackOffsetType } from './rootPropsSelectors';
import { selectPolarItemsSettings, selectUnfilteredPolarItems } from './polarSelectors';
import { isNullish } from '../../util/DataUtils';
import { combineDisplayedStackedData } from './combiners/combineDisplayedStackedData';
import { isStacked } from '../types/StackedGraphicalItem';
import { combineBarSizeList } from './combiners/combineBarSizeList';
import { combineAllBarPositions } from './combiners/combineAllBarPositions';
import { combineStackedData } from './combiners/combineStackedData';
import { combineBarPosition } from './combiners/combineBarPosition';
var selectRadiusAxisForRadialBar = (state, radiusAxisId) => selectRadiusAxis(state, radiusAxisId);
var selectRadiusAxisScaleForRadar = (state, radiusAxisId) => selectPolarAxisScale(state, 'radiusAxis', radiusAxisId);
export var selectRadiusAxisWithScale = createSelector([selectRadiusAxisForRadialBar, selectRadiusAxisScaleForRadar], (axis, scale) => {
if (axis == null || scale == null) {
return undefined;
}
return _objectSpread(_objectSpread({}, axis), {}, {
scale
});
});
export var selectRadiusAxisTicks = (state, radiusAxisId) => {
return selectPolarGraphicalItemAxisTicks(state, 'radiusAxis', radiusAxisId, false);
};
var selectAngleAxisForRadialBar = (state, _radiusAxisId, angleAxisId) => selectAngleAxis(state, angleAxisId);
var selectAngleAxisScaleForRadialBar = (state, _radiusAxisId, angleAxisId) => selectPolarAxisScale(state, 'angleAxis', angleAxisId);
export var selectAngleAxisWithScale = createSelector([selectAngleAxisForRadialBar, selectAngleAxisScaleForRadialBar], (axis, scale) => {
if (axis == null || scale == null) {
return undefined;
}
return _objectSpread(_objectSpread({}, axis), {}, {
scale
});
});
var selectAngleAxisTicks = (state, _radiusAxisId, angleAxisId) => {
// here we can hardcode isPanorama to false because radialBar does not support panorama mode
return selectPolarAxisTicks(state, 'angleAxis', angleAxisId, false);
};
var pickRadialBarSettings = (_state, _radiusAxisId, _angleAxisId, radialBarSettings) => radialBarSettings;
var selectSynchronisedRadialBarSettings = createSelector([selectUnfilteredPolarItems, pickRadialBarSettings], (graphicalItems, radialBarSettingsFromProps) => {
if (graphicalItems.some(pgis => pgis.type === 'radialBar' && radialBarSettingsFromProps.dataKey === pgis.dataKey && radialBarSettingsFromProps.stackId === pgis.stackId)) {
return radialBarSettingsFromProps;
}
return undefined;
});
export var selectBandSizeOfPolarAxis = createSelector([selectChartLayout, selectRadiusAxisWithScale, selectRadiusAxisTicks, selectAngleAxisWithScale, selectAngleAxisTicks], (layout, radiusAxis, radiusAxisTicks, angleAxis, angleAxisTicks) => {
if (isCategoricalAxis(layout, 'radiusAxis')) {
return getBandSizeOfAxis(radiusAxis, radiusAxisTicks, false);
}
return getBandSizeOfAxis(angleAxis, angleAxisTicks, false);
});
export var selectBaseValue = createSelector([selectAngleAxisWithScale, selectRadiusAxisWithScale, selectChartLayout], (angleAxis, radiusAxis, layout) => {
var numericAxis = layout === 'radial' ? angleAxis : radiusAxis;
if (numericAxis == null || numericAxis.scale == null) {
return undefined;
}
return getBaseValueOfBar({
numericAxis
});
});
var pickCells = (_state, _radiusAxisId, _angleAxisId, _radialBarSettings, cells) => cells;
var pickAngleAxisId = (_state, _radiusAxisId, angleAxisId, _radialBarSettings, _cells) => angleAxisId;
var pickRadiusAxisId = (_state, radiusAxisId, _angleAxisId, _radialBarSettings, _cells) => radiusAxisId;
export var pickMaxBarSize = (_state, _radiusAxisId, _angleAxisId, radialBarSettings, _cells) => radialBarSettings.maxBarSize;
var isRadialBar = item => item.type === 'radialBar';
var selectAllVisibleRadialBars = createSelector([selectChartLayout, selectUnfilteredPolarItems, pickAngleAxisId, pickRadiusAxisId], (layout, allItems, angleAxisId, radiusAxisId) => {
return allItems.filter(i => {
if (layout === 'centric') {
return i.angleAxisId === angleAxisId;
}
return i.radiusAxisId === radiusAxisId;
}).filter(i => i.hide === false).filter(isRadialBar);
});
/**
* The generator never returned the totalSize which means that barSize in polar chart can not support percent values.
* We can add that if we want to I suppose.
* @returns undefined - but it should be a total size of numerical axis in polar chart
*/
var selectPolarBarAxisSize = () => undefined;
export var selectPolarBarSizeList = createSelector([selectAllVisibleRadialBars, selectRootBarSize, selectPolarBarAxisSize], combineBarSizeList);
export var selectPolarBarBandSize = createSelector([selectChartLayout, selectRootMaxBarSize, selectAngleAxisWithScale, selectAngleAxisTicks, selectRadiusAxisWithScale, selectRadiusAxisTicks, pickMaxBarSize], (layout, globalMaxBarSize, angleAxis, angleAxisTicks, radiusAxis, radiusAxisTicks, childMaxBarSize) => {
var _ref2, _getBandSizeOfAxis2;
var maxBarSize = isNullish(childMaxBarSize) ? globalMaxBarSize : childMaxBarSize;
if (layout === 'centric') {
var _ref, _getBandSizeOfAxis;
return (_ref = (_getBandSizeOfAxis = getBandSizeOfAxis(angleAxis, angleAxisTicks, true)) !== null && _getBandSizeOfAxis !== void 0 ? _getBandSizeOfAxis : maxBarSize) !== null && _ref !== void 0 ? _ref : 0;
}
return (_ref2 = (_getBandSizeOfAxis2 = getBandSizeOfAxis(radiusAxis, radiusAxisTicks, true)) !== null && _getBandSizeOfAxis2 !== void 0 ? _getBandSizeOfAxis2 : maxBarSize) !== null && _ref2 !== void 0 ? _ref2 : 0;
});
export var selectAllPolarBarPositions = createSelector([selectPolarBarSizeList, selectRootMaxBarSize, selectBarGap, selectBarCategoryGap, selectPolarBarBandSize, selectBandSizeOfPolarAxis, pickMaxBarSize], combineAllBarPositions);
export var selectPolarBarPosition = createSelector([selectAllPolarBarPositions, selectSynchronisedRadialBarSettings], combineBarPosition);
var selectStackedRadialBars = createSelector([selectPolarItemsSettings], allPolarItems => allPolarItems.filter(isRadialBar).filter(isStacked));
var selectPolarCombinedStackedData = createSelector([selectStackedRadialBars, selectChartDataAndAlwaysIgnoreIndexes, selectTooltipAxis], combineDisplayedStackedData);
var selectStackGroups = createSelector([selectPolarCombinedStackedData, selectStackedRadialBars, selectStackOffsetType, selectReverseStackOrder], combineStackGroups);
var selectRadialBarStackGroups = (state, radiusAxisId, angleAxisId) => {
var layout = selectChartLayout(state);
if (layout === 'centric') {
return selectStackGroups(state, 'radiusAxis', radiusAxisId);
}
return selectStackGroups(state, 'angleAxis', angleAxisId);
};
var selectPolarStackedData = createSelector([selectRadialBarStackGroups, selectSynchronisedRadialBarSettings], combineStackedData);
export var selectRadialBarSectors = createSelector([selectAngleAxisWithScale, selectAngleAxisTicks, selectRadiusAxisWithScale, selectRadiusAxisTicks, selectChartDataWithIndexes, selectSynchronisedRadialBarSettings, selectBandSizeOfPolarAxis, selectChartLayout, selectBaseValue, selectPolarViewBox, pickCells, selectPolarBarPosition, selectPolarStackedData], (angleAxis, angleAxisTicks, radiusAxis, radiusAxisTicks, _ref3, radialBarSettings, bandSize, layout, baseValue, polarViewBox, cells, pos, stackedData) => {
var chartData = _ref3.chartData,
dataStartIndex = _ref3.dataStartIndex,
dataEndIndex = _ref3.dataEndIndex;
if (radialBarSettings == null || radiusAxis == null || angleAxis == null || chartData == null || bandSize == null || pos == null || layout !== 'centric' && layout !== 'radial' || radiusAxisTicks == null || polarViewBox == null) {
return [];
}
var dataKey = radialBarSettings.dataKey,
minPointSize = radialBarSettings.minPointSize;
var cx = polarViewBox.cx,
cy = polarViewBox.cy,
startAngle = polarViewBox.startAngle,
endAngle = polarViewBox.endAngle;
var displayedData = chartData.slice(dataStartIndex, dataEndIndex + 1);
var numericAxis = layout === 'centric' ? radiusAxis : angleAxis;
var stackedDomain = stackedData ? numericAxis.scale.domain() : null;
return computeRadialBarDataItems({
angleAxis,
angleAxisTicks,
bandSize,
baseValue,
cells,
cx,
cy,
dataKey,
dataStartIndex,
displayedData,
endAngle,
layout,
minPointSize,
pos,
radiusAxis,
radiusAxisTicks,
stackedData,
stackedDomain,
startAngle
});
});
export var selectRadialBarLegendPayload = createSelector([selectChartDataAndAlwaysIgnoreIndexes, (_s, l) => l], (_ref4, legendType) => {
var chartData = _ref4.chartData,
dataStartIndex = _ref4.dataStartIndex,
dataEndIndex = _ref4.dataEndIndex;
if (chartData == null) {
return [];
}
var displayedData = chartData.slice(dataStartIndex, dataEndIndex + 1);
if (displayedData.length === 0) {
return [];
}
return displayedData.map(entry => {
return {
type: legendType,
// @ts-expect-error we need a better typing for our data inputs
value: entry.name,
// @ts-expect-error we need a better typing for our data inputs
color: entry.fill,
// @ts-expect-error Legend payload.payload says it wants objects but our data can be unknown
payload: entry
};
});
});

View file

@ -0,0 +1,11 @@
export var selectRootMaxBarSize = state => state.rootProps.maxBarSize;
export var selectBarGap = state => state.rootProps.barGap;
export var selectBarCategoryGap = state => state.rootProps.barCategoryGap;
export var selectRootBarSize = state => state.rootProps.barSize;
export var selectStackOffsetType = state => state.rootProps.stackOffset;
export var selectReverseStackOrder = state => state.rootProps.reverseStackOrder;
export var selectChartName = state => state.options.chartName;
export var selectSyncId = state => state.rootProps.syncId;
export var selectSyncMethod = state => state.rootProps.syncMethod;
export var selectEventEmitter = state => state.options.eventEmitter;
export var selectChartBaseValue = state => state.rootProps.baseValue;

View file

@ -0,0 +1,42 @@
import { createSelector } from 'reselect';
import { computeScatterPoints } from '../../cartesian/Scatter';
import { selectChartDataWithIndexesIfNotInPanoramaPosition4 } from './dataSelectors';
import { selectAxisWithScale, selectTicksOfGraphicalItem, selectUnfilteredCartesianItems, selectZAxisWithScale } from './axisSelectors';
var selectXAxisWithScale = (state, xAxisId, _yAxisId, _zAxisId, _id, _cells, isPanorama) => selectAxisWithScale(state, 'xAxis', xAxisId, isPanorama);
var selectXAxisTicks = (state, xAxisId, _yAxisId, _zAxisId, _id, _cells, isPanorama) => selectTicksOfGraphicalItem(state, 'xAxis', xAxisId, isPanorama);
var selectYAxisWithScale = (state, _xAxisId, yAxisId, _zAxisId, _id, _cells, isPanorama) => selectAxisWithScale(state, 'yAxis', yAxisId, isPanorama);
var selectYAxisTicks = (state, _xAxisId, yAxisId, _zAxisId, _id, _cells, isPanorama) => selectTicksOfGraphicalItem(state, 'yAxis', yAxisId, isPanorama);
var selectZAxis = (state, _xAxisId, _yAxisId, zAxisId) => selectZAxisWithScale(state, 'zAxis', zAxisId, false);
var pickScatterId = (_state, _xAxisId, _yAxisId, _zAxisId, id) => id;
var pickCells = (_state, _xAxisId, _yAxisId, _zAxisId, _id, cells) => cells;
var scatterChartDataSelector = (state, _xAxisId, _yAxisId, _zAxisId, _id, _cells, isPanorama) => selectChartDataWithIndexesIfNotInPanoramaPosition4(state, undefined, undefined, isPanorama);
var selectSynchronisedScatterSettings = createSelector([selectUnfilteredCartesianItems, pickScatterId], (graphicalItems, id) => {
return graphicalItems.filter(item => item.type === 'scatter').find(item => item.id === id);
});
export var selectScatterPoints = createSelector([scatterChartDataSelector, selectXAxisWithScale, selectXAxisTicks, selectYAxisWithScale, selectYAxisTicks, selectZAxis, selectSynchronisedScatterSettings, pickCells], (_ref, xAxis, xAxisTicks, yAxis, yAxisTicks, zAxis, scatterSettings, cells) => {
var chartData = _ref.chartData,
dataStartIndex = _ref.dataStartIndex,
dataEndIndex = _ref.dataEndIndex;
if (scatterSettings == null) {
return undefined;
}
var displayedData;
if ((scatterSettings === null || scatterSettings === void 0 ? void 0 : scatterSettings.data) != null && scatterSettings.data.length > 0) {
displayedData = scatterSettings.data;
} else {
displayedData = chartData === null || chartData === void 0 ? void 0 : chartData.slice(dataStartIndex, dataEndIndex + 1);
}
if (displayedData == null || xAxis == null || yAxis == null || xAxisTicks == null || yAxisTicks == null || (xAxisTicks === null || xAxisTicks === void 0 ? void 0 : xAxisTicks.length) === 0 || (yAxisTicks === null || yAxisTicks === void 0 ? void 0 : yAxisTicks.length) === 0) {
return undefined;
}
return computeScatterPoints({
displayedData,
xAxis,
yAxis,
zAxis,
scatterSettings,
xAxisTicks,
yAxisTicks,
cells
});
});

View file

@ -0,0 +1,9 @@
import { createSelector } from 'reselect';
import { selectChartLayout } from '../../context/chartLayoutContext';
import { selectTooltipAxisRangeWithReverse, selectTooltipAxisTicks } from './tooltipSelectors';
import { selectChartOffsetInternal } from './selectChartOffsetInternal';
import { combineActiveProps, selectOrderedTooltipTicks } from './selectors';
import { selectPolarViewBox } from './polarAxisSelectors';
import { selectTooltipAxisType } from './selectTooltipAxisType';
var pickChartPointer = (_state, chartPointer) => chartPointer;
export var selectActivePropsFromChartPointer = createSelector([pickChartPointer, selectChartLayout, selectPolarViewBox, selectTooltipAxisType, selectTooltipAxisRangeWithReverse, selectTooltipAxisTicks, selectOrderedTooltipTicks, selectChartOffsetInternal], combineActiveProps);

View file

@ -0,0 +1,7 @@
import { createSelector } from 'reselect';
export var selectAllXAxes = createSelector(state => state.cartesianAxis.xAxis, xAxisMap => {
return Object.values(xAxisMap);
});
export var selectAllYAxes = createSelector(state => state.cartesianAxis.yAxis, yAxisMap => {
return Object.values(yAxisMap);
});

View file

@ -0,0 +1,10 @@
import { createSelector } from 'reselect';
import { selectChartOffsetInternal } from './selectChartOffsetInternal';
export var selectChartOffset = createSelector([selectChartOffsetInternal], offsetInternal => {
return {
top: offsetInternal.top,
bottom: offsetInternal.bottom,
left: offsetInternal.left,
right: offsetInternal.right
};
});

View file

@ -0,0 +1,92 @@
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); }
import { createSelector } from 'reselect';
import { selectLegendSettings, selectLegendSize } from './legendSelectors';
import { appendOffsetOfLegend } from '../../util/ChartUtils';
import { selectChartHeight, selectChartWidth, selectMargin } from './containerSelectors';
import { selectAllXAxes, selectAllYAxes } from './selectAllAxes';
import { DEFAULT_Y_AXIS_WIDTH } from '../../util/Constants';
export var selectBrushHeight = state => state.brush.height;
function selectLeftAxesOffset(state) {
var yAxes = selectAllYAxes(state);
return yAxes.reduce((result, entry) => {
if (entry.orientation === 'left' && !entry.mirror && !entry.hide) {
var width = typeof entry.width === 'number' ? entry.width : DEFAULT_Y_AXIS_WIDTH;
return result + width;
}
return result;
}, 0);
}
function selectRightAxesOffset(state) {
var yAxes = selectAllYAxes(state);
return yAxes.reduce((result, entry) => {
if (entry.orientation === 'right' && !entry.mirror && !entry.hide) {
var width = typeof entry.width === 'number' ? entry.width : DEFAULT_Y_AXIS_WIDTH;
return result + width;
}
return result;
}, 0);
}
function selectTopAxesOffset(state) {
var xAxes = selectAllXAxes(state);
return xAxes.reduce((result, entry) => {
if (entry.orientation === 'top' && !entry.mirror && !entry.hide) {
return result + entry.height;
}
return result;
}, 0);
}
function selectBottomAxesOffset(state) {
var xAxes = selectAllXAxes(state);
return xAxes.reduce((result, entry) => {
if (entry.orientation === 'bottom' && !entry.mirror && !entry.hide) {
return result + entry.height;
}
return result;
}, 0);
}
/**
* For internal use only.
*
* @param root state
* @return ChartOffsetInternal
*/
export var selectChartOffsetInternal = createSelector([selectChartWidth, selectChartHeight, selectMargin, selectBrushHeight, selectLeftAxesOffset, selectRightAxesOffset, selectTopAxesOffset, selectBottomAxesOffset, selectLegendSettings, selectLegendSize], (chartWidth, chartHeight, margin, brushHeight, leftAxesOffset, rightAxesOffset, topAxesOffset, bottomAxesOffset, legendSettings, legendSize) => {
var offsetH = {
left: (margin.left || 0) + leftAxesOffset,
right: (margin.right || 0) + rightAxesOffset
};
var offsetV = {
top: (margin.top || 0) + topAxesOffset,
bottom: (margin.bottom || 0) + bottomAxesOffset
};
var offset = _objectSpread(_objectSpread({}, offsetV), offsetH);
var brushBottom = offset.bottom;
offset.bottom += brushHeight;
offset = appendOffsetOfLegend(offset, legendSettings, legendSize);
var offsetWidth = chartWidth - offset.left - offset.right;
var offsetHeight = chartHeight - offset.top - offset.bottom;
return _objectSpread(_objectSpread({
brushBottom
}, offset), {}, {
// never return negative values for height and width
width: Math.max(offsetWidth, 0),
height: Math.max(offsetHeight, 0)
});
});
export var selectChartViewBox = createSelector(selectChartOffsetInternal, offset => ({
x: offset.left,
y: offset.top,
width: offset.width,
height: offset.height
}));
export var selectAxisViewBox = createSelector(selectChartWidth, selectChartHeight, (width, height) => ({
x: 0,
y: 0,
width,
height
}));

View file

@ -0,0 +1,14 @@
import { createSelector } from 'reselect';
import { selectChartOffset } from './selectChartOffset';
import { selectChartHeight, selectChartWidth } from './containerSelectors';
export var selectPlotArea = createSelector([selectChartOffset, selectChartWidth, selectChartHeight], (offset, chartWidth, chartHeight) => {
if (!offset || chartWidth == null || chartHeight == null) {
return undefined;
}
return {
x: offset.left,
y: offset.top,
width: Math.max(0, chartWidth - offset.left - offset.right),
height: Math.max(0, chartHeight - offset.top - offset.bottom)
};
});

View file

@ -0,0 +1 @@
export var selectTooltipAxisId = state => state.tooltip.settings.axisId;

View file

@ -0,0 +1,23 @@
import { selectChartLayout } from '../../context/chartLayoutContext';
/**
* angle, radius, X, Y, and Z axes all have domain and range and scale and associated settings
*/
/**
* Z axis is never displayed and so it lacks ticks and tick settings.
*/
export var selectTooltipAxisType = state => {
var layout = selectChartLayout(state);
if (layout === 'horizontal') {
return 'xAxis';
}
if (layout === 'vertical') {
return 'yAxis';
}
if (layout === 'centric') {
return 'angleAxis';
}
return 'radiusAxis';
};

View file

@ -0,0 +1,21 @@
import { useAppSelector } from '../hooks';
export var selectDefaultTooltipEventType = state => state.options.defaultTooltipEventType;
export var selectValidateTooltipEventTypes = state => state.options.validateTooltipEventTypes;
export function combineTooltipEventType(shared, defaultTooltipEventType, validateTooltipEventTypes) {
if (shared == null) {
return defaultTooltipEventType;
}
var eventType = shared ? 'axis' : 'item';
if (validateTooltipEventTypes == null) {
return defaultTooltipEventType;
}
return validateTooltipEventTypes.includes(eventType) ? eventType : defaultTooltipEventType;
}
export function selectTooltipEventType(state, shared) {
var defaultTooltipEventType = selectDefaultTooltipEventType(state);
var validateTooltipEventTypes = selectValidateTooltipEventTypes(state);
return combineTooltipEventType(shared, defaultTooltipEventType, validateTooltipEventTypes);
}
export function useTooltipEventType(shared) {
return useAppSelector(state => selectTooltipEventType(state, shared));
}

View file

@ -0,0 +1 @@
export var selectTooltipPayloadSearcher = state => state.options.tooltipPayloadSearcher;

View file

@ -0,0 +1 @@
export var selectTooltipSettings = state => state.tooltip.settings;

View file

@ -0,0 +1 @@
export var selectTooltipState = state => state.tooltip;

View file

@ -0,0 +1,100 @@
import { createSelector } from 'reselect';
import sortBy from 'es-toolkit/compat/sortBy';
import { useAppSelector } from '../hooks';
import { calculateCartesianTooltipPos, calculatePolarTooltipPos } from '../../util/ChartUtils';
import { selectChartDataWithIndexes } from './dataSelectors';
import { selectTooltipAxisDomain, selectTooltipAxisTicks, selectTooltipDisplayedData } from './tooltipSelectors';
import { selectTooltipAxisDataKey } from './axisSelectors';
import { selectChartName } from './rootPropsSelectors';
import { selectChartLayout } from '../../context/chartLayoutContext';
import { selectChartOffsetInternal } from './selectChartOffsetInternal';
import { selectChartHeight, selectChartWidth } from './containerSelectors';
import { combineActiveLabel } from './combiners/combineActiveLabel';
import { combineTooltipInteractionState } from './combiners/combineTooltipInteractionState';
import { combineActiveTooltipIndex } from './combiners/combineActiveTooltipIndex';
import { combineCoordinateForDefaultIndex } from './combiners/combineCoordinateForDefaultIndex';
import { combineTooltipPayloadConfigurations } from './combiners/combineTooltipPayloadConfigurations';
import { selectTooltipPayloadSearcher } from './selectTooltipPayloadSearcher';
import { selectTooltipState } from './selectTooltipState';
import { combineTooltipPayload } from './combiners/combineTooltipPayload';
import { calculateActiveTickIndex, getActiveCartesianCoordinate, getActivePolarCoordinate, isInCartesianRange } from '../../util/getActiveCoordinate';
import { inRangeOfSector } from '../../util/PolarUtils';
export var useChartName = () => {
return useAppSelector(selectChartName);
};
var pickTooltipEventType = (_state, tooltipEventType) => tooltipEventType;
var pickTrigger = (_state, _tooltipEventType, trigger) => trigger;
var pickDefaultIndex = (_state, _tooltipEventType, _trigger, defaultIndex) => defaultIndex;
export var selectOrderedTooltipTicks = createSelector(selectTooltipAxisTicks, ticks => sortBy(ticks, o => o.coordinate));
export var selectTooltipInteractionState = createSelector([selectTooltipState, pickTooltipEventType, pickTrigger, pickDefaultIndex], combineTooltipInteractionState);
export var selectActiveIndex = createSelector([selectTooltipInteractionState, selectTooltipDisplayedData, selectTooltipAxisDataKey, selectTooltipAxisDomain], combineActiveTooltipIndex);
export var selectTooltipDataKey = (state, tooltipEventType, trigger) => {
if (tooltipEventType == null) {
return undefined;
}
var tooltipState = selectTooltipState(state);
if (tooltipEventType === 'axis') {
if (trigger === 'hover') {
return tooltipState.axisInteraction.hover.dataKey;
}
return tooltipState.axisInteraction.click.dataKey;
}
if (trigger === 'hover') {
return tooltipState.itemInteraction.hover.dataKey;
}
return tooltipState.itemInteraction.click.dataKey;
};
export var selectTooltipPayloadConfigurations = createSelector([selectTooltipState, pickTooltipEventType, pickTrigger, pickDefaultIndex], combineTooltipPayloadConfigurations);
export var selectCoordinateForDefaultIndex = createSelector([selectChartWidth, selectChartHeight, selectChartLayout, selectChartOffsetInternal, selectTooltipAxisTicks, pickDefaultIndex, selectTooltipPayloadConfigurations], combineCoordinateForDefaultIndex);
export var selectActiveCoordinate = createSelector([selectTooltipInteractionState, selectCoordinateForDefaultIndex], (tooltipInteractionState, defaultIndexCoordinate) => {
var _tooltipInteractionSt;
return (_tooltipInteractionSt = tooltipInteractionState.coordinate) !== null && _tooltipInteractionSt !== void 0 ? _tooltipInteractionSt : defaultIndexCoordinate;
});
export var selectActiveLabel = createSelector([selectTooltipAxisTicks, selectActiveIndex], combineActiveLabel);
export var selectTooltipPayload = createSelector([selectTooltipPayloadConfigurations, selectActiveIndex, selectChartDataWithIndexes, selectTooltipAxisDataKey, selectActiveLabel, selectTooltipPayloadSearcher, pickTooltipEventType], combineTooltipPayload);
export var selectIsTooltipActive = createSelector([selectTooltipInteractionState, selectActiveIndex], (tooltipInteractionState, activeIndex) => {
return {
isActive: tooltipInteractionState.active && activeIndex != null,
activeIndex
};
});
var combineActiveCartesianProps = (chartEvent, layout, tooltipAxisType, tooltipAxisRange, tooltipTicks, orderedTooltipTicks, offset) => {
if (!chartEvent || !tooltipAxisType || !tooltipAxisRange || !tooltipTicks) {
return undefined;
}
if (!isInCartesianRange(chartEvent, offset)) {
return undefined;
}
var pos = calculateCartesianTooltipPos(chartEvent, layout);
var activeIndex = calculateActiveTickIndex(pos, orderedTooltipTicks, tooltipTicks, tooltipAxisType, tooltipAxisRange);
var activeCoordinate = getActiveCartesianCoordinate(layout, tooltipTicks, activeIndex, chartEvent);
return {
activeIndex: String(activeIndex),
activeCoordinate
};
};
var combineActivePolarProps = (chartEvent, layout, polarViewBox, tooltipAxisType, tooltipAxisRange, tooltipTicks, orderedTooltipTicks) => {
if (!chartEvent || !tooltipAxisType || !tooltipAxisRange || !tooltipTicks || !polarViewBox) {
return undefined;
}
var rangeObj = inRangeOfSector(chartEvent, polarViewBox);
if (!rangeObj) {
return undefined;
}
var pos = calculatePolarTooltipPos(rangeObj, layout);
var activeIndex = calculateActiveTickIndex(pos, orderedTooltipTicks, tooltipTicks, tooltipAxisType, tooltipAxisRange);
var activeCoordinate = getActivePolarCoordinate(layout, tooltipTicks, activeIndex, rangeObj);
return {
activeIndex: String(activeIndex),
activeCoordinate
};
};
export var combineActiveProps = (chartEvent, layout, polarViewBox, tooltipAxisType, tooltipAxisRange, tooltipTicks, orderedTooltipTicks, offset) => {
if (!chartEvent || !layout || !tooltipAxisType || !tooltipAxisRange || !tooltipTicks) {
return undefined;
}
if (layout === 'horizontal' || layout === 'vertical') {
return combineActiveCartesianProps(chartEvent, layout, tooltipAxisType, tooltipAxisRange, tooltipTicks, orderedTooltipTicks, offset);
}
return combineActivePolarProps(chartEvent, layout, polarViewBox, tooltipAxisType, tooltipAxisRange, tooltipTicks, orderedTooltipTicks);
};

View file

@ -0,0 +1,182 @@
import { createSelector } from 'reselect';
import { combineAllAppliedValues, combineAreasDomain, combineAxisDomain, combineAxisDomainWithNiceTicks, combineCategoricalDomain, combineDisplayedData, combineDomainOfAllAppliedNumericalValuesIncludingErrorValues, combineDomainOfStackGroups, combineDotsDomain, combineDuplicateDomain, combineGraphicalItemsData, combineGraphicalItemsSettings, combineLinesDomain, combineNiceTicks, combineNumericalDomain, combineStackGroups, filterGraphicalNotStackedItems, filterReferenceElements, getDomainDefinition, itemAxisPredicate, mergeDomains, selectAllErrorBarSettings, selectAxisRange, selectHasBar, selectReferenceAreas, selectReferenceDots, selectReferenceLines, selectTooltipAxis, selectTooltipAxisDataKey } from './axisSelectors';
import { selectChartLayout } from '../../context/chartLayoutContext';
import { isCategoricalAxis } from '../../util/ChartUtils';
import { selectChartDataWithIndexes, selectChartDataSliceWithIndexes } from './dataSelectors';
import { selectChartName, selectReverseStackOrder, selectStackOffsetType } from './rootPropsSelectors';
import { isNotNil, mathSign } from '../../util/DataUtils';
import { combineAxisRangeWithReverse } from './combiners/combineAxisRangeWithReverse';
import { combineTooltipEventType, selectDefaultTooltipEventType, selectValidateTooltipEventTypes } from './selectTooltipEventType';
import { combineActiveLabel } from './combiners/combineActiveLabel';
import { selectTooltipSettings } from './selectTooltipSettings';
import { combineTooltipInteractionState } from './combiners/combineTooltipInteractionState';
import { combineActiveTooltipIndex } from './combiners/combineActiveTooltipIndex';
import { combineCoordinateForDefaultIndex } from './combiners/combineCoordinateForDefaultIndex';
import { selectChartHeight, selectChartWidth } from './containerSelectors';
import { selectChartOffsetInternal } from './selectChartOffsetInternal';
import { combineTooltipPayloadConfigurations } from './combiners/combineTooltipPayloadConfigurations';
import { selectTooltipPayloadSearcher } from './selectTooltipPayloadSearcher';
import { selectTooltipState } from './selectTooltipState';
import { combineTooltipPayload } from './combiners/combineTooltipPayload';
import { selectTooltipAxisId } from './selectTooltipAxisId';
import { selectTooltipAxisType } from './selectTooltipAxisType';
import { combineDisplayedStackedData } from './combiners/combineDisplayedStackedData';
import { isStacked } from '../types/StackedGraphicalItem';
import { numericalDomainSpecifiedWithoutRequiringData } from '../../util/isDomainSpecifiedByUser';
import { numberDomainEqualityCheck } from './numberDomainEqualityCheck';
import { emptyArraysAreEqualCheck } from './arrayEqualityCheck';
import { rechartsScaleFactory } from '../../util/scale/RechartsScale';
import { isWellBehavedNumber } from '../../util/isWellBehavedNumber';
import { combineRealScaleType } from './combiners/combineRealScaleType';
import { combineConfiguredScale } from './combiners/combineConfiguredScale';
export var selectTooltipAxisRealScaleType = createSelector([selectTooltipAxis, selectHasBar, selectChartName], combineRealScaleType);
export var selectAllUnfilteredGraphicalItems = createSelector([state => state.graphicalItems.cartesianItems, state => state.graphicalItems.polarItems], (cartesianItems, polarItems) => [...cartesianItems, ...polarItems]);
var selectTooltipAxisPredicate = createSelector([selectTooltipAxisType, selectTooltipAxisId], itemAxisPredicate);
export var selectAllGraphicalItemsSettings = createSelector([selectAllUnfilteredGraphicalItems, selectTooltipAxis, selectTooltipAxisPredicate], combineGraphicalItemsSettings, {
memoizeOptions: {
resultEqualityCheck: emptyArraysAreEqualCheck
}
});
var selectAllStackedGraphicalItemsSettings = createSelector([selectAllGraphicalItemsSettings], graphicalItems => graphicalItems.filter(isStacked));
export var selectTooltipGraphicalItemsData = createSelector([selectAllGraphicalItemsSettings], combineGraphicalItemsData, {
memoizeOptions: {
resultEqualityCheck: emptyArraysAreEqualCheck
}
});
var selectAnyTooltipItemUsesChartData = createSelector([selectAllGraphicalItemsSettings], items => items.some(item => !item.data));
/**
* Data for tooltip always use the data with indexes set by a Brush,
* and never accept the isPanorama flag:
* because Tooltip never displays inside the panorama anyway
* so we don't need to worry what would happen there.
*/
export var selectTooltipDisplayedData = createSelector([selectTooltipGraphicalItemsData, selectChartDataWithIndexes], combineDisplayedData);
var selectTooltipStackedData = createSelector([selectAllStackedGraphicalItemsSettings, selectChartDataWithIndexes, selectTooltipAxis], combineDisplayedStackedData);
var selectAllTooltipAppliedValues = createSelector([selectTooltipDisplayedData, selectTooltipAxis, selectAllGraphicalItemsSettings, selectChartDataWithIndexes, selectAnyTooltipItemUsesChartData, selectTooltipGraphicalItemsData], combineAllAppliedValues);
var selectTooltipAxisDomainDefinition = createSelector([selectTooltipAxis], getDomainDefinition);
var selectTooltipDataOverflow = createSelector([selectTooltipAxis], axisSettings => axisSettings.allowDataOverflow);
var selectTooltipDomainFromUserPreferences = createSelector([selectTooltipAxisDomainDefinition, selectTooltipDataOverflow], numericalDomainSpecifiedWithoutRequiringData);
var selectAllStackedGraphicalItems = createSelector([selectAllGraphicalItemsSettings], graphicalItems => graphicalItems.filter(isStacked));
var selectTooltipStackGroups = createSelector([selectTooltipStackedData, selectAllStackedGraphicalItems, selectStackOffsetType, selectReverseStackOrder], combineStackGroups);
var selectTooltipDomainOfStackGroups = createSelector([selectTooltipStackGroups, selectChartDataWithIndexes, selectTooltipAxisType, selectTooltipDomainFromUserPreferences], combineDomainOfStackGroups);
var selectTooltipItemsSettingsExceptStacked = createSelector([selectAllGraphicalItemsSettings], filterGraphicalNotStackedItems);
var selectDomainOfAllAppliedNumericalValuesIncludingErrorValues = createSelector([selectTooltipDisplayedData, selectTooltipAxis, selectTooltipItemsSettingsExceptStacked, selectAllErrorBarSettings, selectTooltipAxisType, selectChartDataSliceWithIndexes], combineDomainOfAllAppliedNumericalValuesIncludingErrorValues, {
memoizeOptions: {
resultEqualityCheck: numberDomainEqualityCheck
}
});
var selectReferenceDotsByTooltipAxis = createSelector([selectReferenceDots, selectTooltipAxisType, selectTooltipAxisId], filterReferenceElements);
var selectTooltipReferenceDotsDomain = createSelector([selectReferenceDotsByTooltipAxis, selectTooltipAxisType], combineDotsDomain);
var selectReferenceAreasByTooltipAxis = createSelector([selectReferenceAreas, selectTooltipAxisType, selectTooltipAxisId], filterReferenceElements);
var selectTooltipReferenceAreasDomain = createSelector([selectReferenceAreasByTooltipAxis, selectTooltipAxisType], combineAreasDomain);
var selectReferenceLinesByTooltipAxis = createSelector([selectReferenceLines, selectTooltipAxisType, selectTooltipAxisId], filterReferenceElements);
var selectTooltipReferenceLinesDomain = createSelector([selectReferenceLinesByTooltipAxis, selectTooltipAxisType], combineLinesDomain);
var selectTooltipReferenceElementsDomain = createSelector([selectTooltipReferenceDotsDomain, selectTooltipReferenceLinesDomain, selectTooltipReferenceAreasDomain], mergeDomains);
var selectTooltipNumericalDomain = createSelector([selectTooltipAxis, selectTooltipAxisDomainDefinition, selectTooltipDomainFromUserPreferences, selectTooltipDomainOfStackGroups, selectDomainOfAllAppliedNumericalValuesIncludingErrorValues, selectTooltipReferenceElementsDomain, selectChartLayout, selectTooltipAxisType], combineNumericalDomain);
export var selectTooltipAxisDomain = createSelector([selectTooltipAxis, selectChartLayout, selectTooltipDisplayedData, selectAllTooltipAppliedValues, selectStackOffsetType, selectTooltipAxisType, selectTooltipNumericalDomain], combineAxisDomain);
var selectTooltipNiceTicks = createSelector([selectTooltipAxisDomain, selectTooltipAxis, selectTooltipAxisRealScaleType], combineNiceTicks);
export var selectTooltipAxisDomainIncludingNiceTicks = createSelector([selectTooltipAxis, selectTooltipAxisDomain, selectTooltipNiceTicks, selectTooltipAxisType], combineAxisDomainWithNiceTicks);
var selectTooltipAxisRange = state => {
var axisType = selectTooltipAxisType(state);
var axisId = selectTooltipAxisId(state);
var isPanorama = false; // Tooltip never displays in panorama so this is safe to assume
return selectAxisRange(state, axisType, axisId, isPanorama);
};
export var selectTooltipAxisRangeWithReverse = createSelector([selectTooltipAxis, selectTooltipAxisRange], combineAxisRangeWithReverse);
var selectTooltipConfiguredScale = createSelector([selectTooltipAxis, selectTooltipAxisRealScaleType, selectTooltipAxisDomainIncludingNiceTicks, selectTooltipAxisRangeWithReverse], combineConfiguredScale);
export var selectTooltipAxisScale = createSelector([selectTooltipConfiguredScale], rechartsScaleFactory);
var selectTooltipDuplicateDomain = createSelector([selectChartLayout, selectAllTooltipAppliedValues, selectTooltipAxis, selectTooltipAxisType], combineDuplicateDomain);
export var selectTooltipCategoricalDomain = createSelector([selectChartLayout, selectAllTooltipAppliedValues, selectTooltipAxis, selectTooltipAxisType], combineCategoricalDomain);
var combineTicksOfTooltipAxis = (layout, axis, realScaleType, scale, range, duplicateDomain, categoricalDomain, axisType) => {
if (!axis) {
return undefined;
}
var type = axis.type;
var isCategorical = isCategoricalAxis(layout, axisType);
if (!scale) {
return undefined;
}
var offsetForBand = realScaleType === 'scaleBand' && scale.bandwidth ? scale.bandwidth() / 2 : 2;
var offset = type === 'category' && scale.bandwidth ? scale.bandwidth() / offsetForBand : 0;
offset = axisType === 'angleAxis' && range != null && (range === null || range === void 0 ? void 0 : range.length) >= 2 ? mathSign(range[0] - range[1]) * 2 * offset : offset;
// When axis is a categorical axis, but the type of axis is number or the scale of axis is not "auto"
if (isCategorical && categoricalDomain) {
return categoricalDomain.map((entry, index) => {
var scaled = scale.map(entry);
if (!isWellBehavedNumber(scaled)) {
return null;
}
return {
coordinate: scaled + offset,
value: entry,
index,
offset
};
}).filter(isNotNil);
}
// When axis has duplicated text, serial numbers are used to generate scale
return scale.domain().map((entry, index) => {
var scaled = scale.map(entry);
if (!isWellBehavedNumber(scaled)) {
return null;
}
return {
coordinate: scaled + offset,
// @ts-expect-error can't use Date as an index
value: duplicateDomain ? duplicateDomain[entry] : entry,
index,
offset
};
}).filter(isNotNil);
};
/**
* Of on four almost identical implementations of tick generation.
* The four horsemen of tick generation are:
* - {@link selectTooltipAxisTicks}
* - {@link combineAxisTicks}
* - {@link getTicksOfAxis}.
* - {@link combineGraphicalItemTicks}
*/
export var selectTooltipAxisTicks = createSelector([selectChartLayout, selectTooltipAxis, selectTooltipAxisRealScaleType, selectTooltipAxisScale, selectTooltipAxisRange, selectTooltipDuplicateDomain, selectTooltipCategoricalDomain, selectTooltipAxisType], combineTicksOfTooltipAxis);
var selectTooltipEventType = createSelector([selectDefaultTooltipEventType, selectValidateTooltipEventTypes, selectTooltipSettings], (defaultTooltipEventType, validateTooltipEventType, settings) => combineTooltipEventType(settings.shared, defaultTooltipEventType, validateTooltipEventType));
var selectTooltipTrigger = state => state.tooltip.settings.trigger;
var selectDefaultIndex = state => state.tooltip.settings.defaultIndex;
var selectTooltipInteractionState = createSelector([selectTooltipState, selectTooltipEventType, selectTooltipTrigger, selectDefaultIndex], combineTooltipInteractionState);
export var selectActiveTooltipIndex = createSelector([selectTooltipInteractionState, selectTooltipDisplayedData, selectTooltipAxisDataKey, selectTooltipAxisDomain], combineActiveTooltipIndex);
export var selectActiveLabel = createSelector([selectTooltipAxisTicks, selectActiveTooltipIndex], combineActiveLabel);
export var selectActiveTooltipDataKey = createSelector([selectTooltipInteractionState], tooltipInteraction => {
if (!tooltipInteraction) {
return undefined;
}
return tooltipInteraction.dataKey;
});
export var selectActiveTooltipGraphicalItemId = createSelector([selectTooltipInteractionState], tooltipInteraction => {
if (!tooltipInteraction) {
return undefined;
}
return tooltipInteraction.graphicalItemId;
});
var selectTooltipPayloadConfigurations = createSelector([selectTooltipState, selectTooltipEventType, selectTooltipTrigger, selectDefaultIndex], combineTooltipPayloadConfigurations);
var selectTooltipCoordinateForDefaultIndex = createSelector([selectChartWidth, selectChartHeight, selectChartLayout, selectChartOffsetInternal, selectTooltipAxisTicks, selectDefaultIndex, selectTooltipPayloadConfigurations], combineCoordinateForDefaultIndex);
export var selectActiveTooltipCoordinate = createSelector([selectTooltipInteractionState, selectTooltipCoordinateForDefaultIndex], (tooltipInteractionState, defaultIndexCoordinate) => {
if (tooltipInteractionState !== null && tooltipInteractionState !== void 0 && tooltipInteractionState.coordinate) {
return tooltipInteractionState.coordinate;
}
return defaultIndexCoordinate;
});
export var selectIsTooltipActive = createSelector([selectTooltipInteractionState], tooltipInteractionState => {
var _tooltipInteractionSt;
return (_tooltipInteractionSt = tooltipInteractionState === null || tooltipInteractionState === void 0 ? void 0 : tooltipInteractionState.active) !== null && _tooltipInteractionSt !== void 0 ? _tooltipInteractionSt : false;
});
export var selectActiveTooltipPayload = createSelector([selectTooltipPayloadConfigurations, selectActiveTooltipIndex, selectChartDataWithIndexes, selectTooltipAxisDataKey, selectActiveLabel, selectTooltipPayloadSearcher, selectTooltipEventType], combineTooltipPayload);
export var selectActiveTooltipDataPoints = createSelector([selectActiveTooltipPayload], payload => {
if (payload == null) {
return undefined;
}
var dataPoints = payload.map(p => p.payload).filter(p => p != null);
return Array.from(new Set(dataPoints));
});

View file

@ -0,0 +1,19 @@
import { createSelector } from 'reselect';
import { selectTooltipState } from './selectTooltipState';
var selectAllTooltipPayloadConfiguration = createSelector([selectTooltipState], tooltipState => tooltipState.tooltipItemPayloads);
export var selectTooltipCoordinate = createSelector([selectAllTooltipPayloadConfiguration, (_state, tooltipIndex) => tooltipIndex, (_state, _tooltipIndex, graphicalItemId) => graphicalItemId], (allTooltipConfigurations, tooltipIndex, graphicalItemId) => {
if (tooltipIndex == null) {
return undefined;
}
var mostRelevantTooltipConfiguration = allTooltipConfigurations.find(tooltipConfiguration => {
return tooltipConfiguration.settings.graphicalItemId === graphicalItemId;
});
if (mostRelevantTooltipConfiguration == null) {
return undefined;
}
var getPosition = mostRelevantTooltipConfiguration.getPosition;
if (getPosition == null) {
return undefined;
}
return getPosition(tooltipIndex);
});