recharts
Version:
React charts
83 lines • 3.83 kB
JavaScript
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 { polarToCartesian } from '../../../util/PolarUtils';
export var combineCoordinateForDefaultIndex = (width, height, layout, offset, tooltipTicks, defaultIndex, tooltipConfigurations, polarViewBox) => {
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
};
}
case 'radial':
{
if (polarViewBox) {
var cx = polarViewBox.cx,
cy = polarViewBox.cy,
innerRadius = polarViewBox.innerRadius,
outerRadius = polarViewBox.outerRadius,
startAngle = polarViewBox.startAngle,
endAngle = polarViewBox.endAngle;
var radius = tick.coordinate;
var angle = (startAngle + endAngle) / 2;
return _objectSpread(_objectSpread({}, polarToCartesian(cx, cy, outerRadius, angle)), {}, {
cx,
cy,
radius,
angle,
startAngle,
endAngle,
innerRadius,
outerRadius,
clockWise: false
});
}
return {
x: (offset.left + width) / 2,
y: tick.coordinate
};
}
case 'centric':
{
if (polarViewBox == null) {
return undefined;
}
var _cx = polarViewBox.cx,
_cy = polarViewBox.cy,
_outerRadius = polarViewBox.outerRadius;
var _angle = tick.coordinate;
return _objectSpread(_objectSpread(_objectSpread({}, polarViewBox), polarToCartesian(_cx, _cy, _outerRadius, _angle)), {}, {
angle: _angle,
radius: _outerRadius
});
}
default:
{
return {
x: (offset.left + width) / 2,
y: tick.coordinate
};
}
}
};