react-plot
Version:
Library of React components to render SVG 2D plots.
31 lines • 1.31 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { usePosition } from '../../hooks.js';
import { Circle as CircleMarker, Diamond as DiamondMarker, Square as SquareMarker, Triangle as TriangleMarker, } from '../Markers.js';
const shapes = {
triangle: Triangle,
circle: Circle,
diamond: Diamond,
square: Square,
};
function Triangle(props) {
return _jsx(TriangleMarker, { size: props.size, style: props.style });
}
function Circle(props) {
return _jsx(CircleMarker, { size: props.size, style: props.style });
}
function Diamond(props) {
return _jsx(DiamondMarker, { size: props.size, style: props.style });
}
function Square(props) {
return _jsx(SquareMarker, { size: props.size, style: props.style });
}
export function Shape(props) {
const { shape, x: xOld, y: yOld, onMouseEnter, onMouseLeave, color, size, style, xAxis = 'x', yAxis = 'y', } = props;
const Figure = shapes[shape];
if (!Figure) {
throw new Error(`Invalid shape: "${shape}"`);
}
const { x, y } = usePosition({ x: xOld, y: yOld, xAxis, yAxis });
return (_jsx("g", { onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, transform: `translate(${x}, ${y})`, children: _jsx(Figure, { size: size, style: { fill: color, ...style } }) }));
}
//# sourceMappingURL=Shape.js.map