@mui/x-charts
Version:
The community edition of MUI X Charts components.
106 lines (104 loc) • 2.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _coordinateTransformation = require("../../internals/plugins/featurePlugins/useChartPolarAxis/coordinateTransformation");
var _useChartPolarAxis = require("../../internals/plugins/featurePlugins/useChartPolarAxis");
const tooltipItemPositionGetter = params => {
const {
series,
identifier,
axesConfig,
drawingArea,
placement
} = params;
if (!identifier) {
return null;
}
const itemSeries = series.radar?.series[identifier.seriesId];
if (itemSeries == null) {
return null;
}
const {
radiusAxes,
rotationAxes
} = axesConfig;
if (radiusAxes === undefined || rotationAxes === undefined) {
return null;
}
// Only one rotation axis is supported for radar charts
const rotationAxis = rotationAxes.axis[rotationAxes.axisIds[0]];
const metrics = rotationAxis.scale.domain() ?? [];
const angles = metrics.map(key => rotationAxis.scale(key));
const {
cx,
cy
} = (0, _useChartPolarAxis.getDrawingAreaCenter)(drawingArea);
const polar2svg = (0, _coordinateTransformation.generatePolar2svg)({
cx,
cy
});
const points = itemSeries.data.map((value, dataIndex) => {
const rId = radiusAxes.axisIds[dataIndex];
const r = radiusAxes.axis[rId].scale(value);
const angle = angles[dataIndex];
return polar2svg(r, angle);
});
if (points.length === 0) {
return null;
}
if (identifier.dataIndex != null) {
const point = points[identifier.dataIndex];
switch (placement) {
case 'right':
return {
x: point[0] + 4,
y: point[1]
};
case 'bottom':
return {
x: point[0],
y: point[1] + 4
};
case 'left':
return {
x: point[0] - 4,
y: point[1]
};
case 'top':
default:
return {
x: point[0],
y: point[1] - 4
};
}
}
const [top, right, bottom, left] = points.reduce((acc, [x, y]) => {
return [Math.min(y, acc[0]), Math.max(x, acc[1]), Math.max(y, acc[2]), Math.min(x, acc[3])];
}, [Infinity, -Infinity, -Infinity, Infinity]);
switch (placement) {
case 'right':
return {
x: right,
y: (top + bottom) / 2
};
case 'bottom':
return {
x: (left + right) / 2,
y: bottom
};
case 'left':
return {
x: left,
y: (top + bottom) / 2
};
case 'top':
default:
return {
x: (left + right) / 2,
y: top
};
}
};
var _default = exports.default = tooltipItemPositionGetter;