Project Init

This commit is contained in:
Muluhabt
2026-05-29 15:23:46 +03:00
commit 2fbc557aac
67387 changed files with 6063341 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.combineActiveLabel = void 0;
var _DataUtils = require("../../../util/DataUtils");
var combineActiveLabel = (tooltipTicks, activeIndex) => {
var _tooltipTicks$n;
var n = Number(activeIndex);
if ((0, _DataUtils.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;
};
exports.combineActiveLabel = combineActiveLabel;

View File

@@ -0,0 +1,77 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.combineActiveTooltipIndex = void 0;
var _isWellBehavedNumber = require("../../../util/isWellBehavedNumber");
var _ChartUtils = require("../../../util/ChartUtils");
var _isDomainSpecifiedByUser = require("../../../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 = (0, _ChartUtils.getValueByDataKey)(entry, axisDataKey);
if (value == null) {
return true;
}
if (!(0, _isDomainSpecifiedByUser.isWellFormedNumberDomain)(domain)) {
return true;
}
return isValueWithinNumberDomain(value, domain);
}
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 (!(0, _isWellBehavedNumber.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);
};
exports.combineActiveTooltipIndex = combineActiveTooltipIndex;

View File

@@ -0,0 +1,92 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.combineAllBarPositions = void 0;
var _DataUtils = require("../../../util/DataUtils");
var _isWellBehavedNumber = require("../../../util/isWellBehavedNumber");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function getBarPositions(barGap, barCategoryGap, bandSize, sizeList, maxBarSize) {
var _sizeList$;
var len = sizeList.length;
if (len < 1) {
return undefined;
}
var realBarGap = (0, _DataUtils.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 ((0, _isWellBehavedNumber.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 = (bandSize - sum) / 2 >> 0;
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 = (0, _DataUtils.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 >>= 0;
}
var size = (0, _isWellBehavedNumber.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;
}
var combineAllBarPositions = (sizeList, globalMaxBarSize, barGap, barCategoryGap, barBandSize, bandSize, childMaxBarSize) => {
var maxBarSize = (0, _DataUtils.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;
};
exports.combineAllBarPositions = combineAllBarPositions;

View File

@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.combineAxisRangeWithReverse = void 0;
var combineAxisRangeWithReverse = (axisSettings, axisRange) => {
if (!axisSettings || !axisRange) {
return undefined;
}
if (axisSettings !== null && axisSettings !== void 0 && axisSettings.reversed) {
return [axisRange[1], axisRange[0]];
}
return axisRange;
};
exports.combineAxisRangeWithReverse = combineAxisRangeWithReverse;

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.combineBarPosition = void 0;
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;
};
exports.combineBarPosition = combineBarPosition;

View File

@@ -0,0 +1,51 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.combineBarSizeList = void 0;
var _StackedGraphicalItem = require("../../types/StackedGraphicalItem");
var _DataUtils = require("../../../util/DataUtils");
var getBarSize = (globalSize, totalSize, selfSize) => {
var barSize = selfSize !== null && selfSize !== void 0 ? selfSize : globalSize;
if ((0, _DataUtils.isNullish)(barSize)) {
return undefined;
}
return (0, _DataUtils.getPercentValue)(barSize, totalSize, 0);
};
var combineBarSizeList = (allBars, globalSize, totalSize) => {
var initialValue = {};
var stackedBars = allBars.filter(_StackedGraphicalItem.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 [stackId, bars] = _ref;
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];
};
exports.combineBarSizeList = combineBarSizeList;

View File

@@ -0,0 +1,49 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.combineCheckedDomain = void 0;
var _isDomainSpecifiedByUser = require("../../../util/isDomainSpecifiedByUser");
var _isWellBehavedNumber = require("../../../util/isWellBehavedNumber");
/**
* This function validates and transforms the axis domain so that it is safe to use in the provided scale.
*/
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 (!(0, _isDomainSpecifiedByUser.isWellFormedNumberDomain)(axisDomain)) {
var min, max;
for (var i = 0; i < axisDomain.length; i++) {
var value = axisDomain[i];
if (!(0, _isWellBehavedNumber.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;
}
};
exports.combineCheckedDomain = combineCheckedDomain;

View File

@@ -0,0 +1,52 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.combineConfiguredScale = combineConfiguredScale;
exports.combineConfiguredScaleInternal = combineConfiguredScaleInternal;
var d3Scales = _interopRequireWildcard(require("victory-vendor/d3-scale"));
var _DataUtils = require("../../../util/DataUtils");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function getD3ScaleFromType(realScaleType) {
var scales = d3Scales;
if (realScaleType in scales && typeof scales[realScaleType] === 'function') {
return scales[realScaleType]();
}
var name = "scale".concat((0, _DataUtils.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
*/
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;
}
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,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.combineCoordinateForDefaultIndex = void 0;
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
};
}
}
};
exports.combineCoordinateForDefaultIndex = combineCoordinateForDefaultIndex;

View File

@@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.combineDisplayedStackedData = combineDisplayedStackedData;
var _getStackSeriesIdentifier = require("../../../util/stacks/getStackSeriesIdentifier");
var _ChartUtils = require("../../../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.
*/
function combineDisplayedStackedData(stackedGraphicalItems, _ref, tooltipAxisSettings) {
var {
chartData = []
} = _ref;
var {
allowDuplicatedCategory,
dataKey: tooltipDataKey
} = tooltipAxisSettings;
// 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 = (0, _getStackSeriesIdentifier.getStackSeriesIdentifier)(item);
resolvedData.forEach((entry, index) => {
var tooltipValue = tooltipDataKey == null || allowDuplicatedCategory ? index : String((0, _ChartUtils.getValueByDataKey)(entry, tooltipDataKey, null));
var numericValue = (0, _ChartUtils.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,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.combineInverseScaleFunction = combineInverseScaleFunction;
var _createCategoricalInverse = require("../../../util/scale/createCategoricalInverse");
function combineInverseScaleFunction(configuredScale) {
if (configuredScale == null) {
return undefined;
}
if ('invert' in configuredScale && typeof configuredScale.invert === 'function') {
return configuredScale.invert.bind(configuredScale);
}
return (0, _createCategoricalInverse.createCategoricalInverse)(configuredScale, undefined);
}

View File

@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.combineRealScaleType = void 0;
var d3Scales = _interopRequireWildcard(require("victory-vendor/d3-scale"));
var _DataUtils = require("../../../util/DataUtils");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function getD3ScaleName(name) {
return "scale".concat((0, _DataUtils.upperFirst)(name));
}
function isSupportedScaleName(name) {
return getD3ScaleName(name) in d3Scales;
}
var combineRealScaleType = (axisConfig, hasBar, chartType) => {
if (axisConfig == null) {
return undefined;
}
var {
scale,
type
} = axisConfig;
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;
};
exports.combineRealScaleType = combineRealScaleType;

View File

@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.combineStackedData = void 0;
var _getStackSeriesIdentifier = require("../../../util/stacks/getStackSeriesIdentifier");
var combineStackedData = (stackGroups, barSettings) => {
var stackSeriesIdentifier = (0, _getStackSeriesIdentifier.getStackSeriesIdentifier)(barSettings);
if (!stackGroups || stackSeriesIdentifier == null || barSettings == null) {
return undefined;
}
var {
stackId
} = barSettings;
if (stackId == null) {
return undefined;
}
var stackGroup = stackGroups[stackId];
if (!stackGroup) {
return undefined;
}
var {
stackedData
} = stackGroup;
if (!stackedData) {
return undefined;
}
return stackedData.find(sd => sd.key === stackSeriesIdentifier);
};
exports.combineStackedData = combineStackedData;

View File

@@ -0,0 +1,65 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.combineTooltipInteractionState = void 0;
var _tooltipSlice = require("../../tooltipSlice");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function 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;
}
var combineTooltipInteractionState = (tooltipState, tooltipEventType, trigger, defaultIndex) => {
if (tooltipEventType == null) {
return _tooltipSlice.noInteraction;
}
var appropriateMouseInteraction = chooseAppropriateMouseInteraction(tooltipState, tooltipEventType, trigger);
if (appropriateMouseInteraction == null) {
return _tooltipSlice.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({}, _tooltipSlice.noInteraction), {}, {
coordinate: appropriateMouseInteraction.coordinate
});
};
exports.combineTooltipInteractionState = combineTooltipInteractionState;

View File

@@ -0,0 +1,166 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.combineTooltipPayload = void 0;
var _DataUtils = require("../../../util/DataUtils");
var _ChartUtils = require("../../../util/ChartUtils");
var _getSliced = require("../../../util/getSliced");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function 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;
}
var combineTooltipPayload = (tooltipPayloadConfigurations, activeIndex, chartDataState, tooltipAxisDataKey, activeLabel, tooltipPayloadSearcher, tooltipEventType) => {
if (activeIndex == null || tooltipPayloadSearcher == null) {
return undefined;
}
var {
chartData,
computedData,
dataStartIndex,
dataEndIndex
} = chartDataState;
var init = [];
return tooltipPayloadConfigurations.reduce((agg, _ref) => {
var _settings$dataKey;
var {
dataDefinedOnItem,
settings
} = _ref;
var finalData = selectFinalData(dataDefinedOnItem, chartData);
var sliced = Array.isArray(finalData) ? (0, _getSliced.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 = (0, _DataUtils.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((0, _ChartUtils.getTooltipEntry)({
tooltipEntrySettings: newSettings,
dataKey: itemDataKey,
payload: itemPayload,
value: (0, _ChartUtils.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((0, _ChartUtils.getTooltipEntry)({
tooltipEntrySettings: settings,
dataKey: finalDataKey,
payload: tooltipPayload,
// getValueByDataKey does not validate the output type
value: (0, _ChartUtils.getValueByDataKey)(tooltipPayload, finalDataKey),
// getValueByDataKey does not validate the output type
name: (_getValueByDataKey = (0, _ChartUtils.getValueByDataKey)(tooltipPayload, finalNameKey)) !== null && _getValueByDataKey !== void 0 ? _getValueByDataKey : settings === null || settings === void 0 ? void 0 : settings.name
}));
}
return agg;
}, init);
};
exports.combineTooltipPayload = combineTooltipPayload;

View File

@@ -0,0 +1,52 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.combineTooltipPayloadConfigurations = void 0;
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;
});
};
exports.combineTooltipPayloadConfigurations = combineTooltipPayloadConfigurations;