UNPKG

react-plot

Version:

Library of React components to render SVG 2D plots.

83 lines 3.94 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { Annotation, Annotations } from './Annotations/index.js'; import { Axis } from './Axis/Axis.js'; import { ParallelAxis } from './Axis/ParallelAxis.js'; import { Legend } from './Legend.js'; import { Plot } from './Plot.js'; import { LineSeries } from './Series/LineSeries.js'; import { ScatterSeries } from './Series/ScatterSeries.js'; export function PlotObject({ plot: { dimensions, svg = {}, seriesViewportStyle, axes, content, legend, colorScheme, }, children, }) { const { className: svgClassName, id: svgId, style: svgStyle, ...svgProps } = svg; return (_jsxs(Plot, { colorScheme: colorScheme, seriesViewportStyle: seriesViewportStyle, ...dimensions, svgClassName: svgClassName, svgId: svgId, svgStyle: svgStyle, ...svgProps, children: [axes.map((axisProps) => { switch (axisProps.type) { case 'main': { const { type, ...props } = axisProps; return _jsx(Axis, { ...props }, axisProps.position); } case 'secondary': { const { type, ...props } = axisProps; return _jsx(ParallelAxis, { ...props }, `secondary-${props.id}`); } default: { return null; } } }), legend !== undefined ? _jsx(Legend, { ...legend }) : null, content.map((contentProps, i) => { switch (contentProps.type) { case 'line': { const { type, ...props } = contentProps; return _jsx(LineSeries, { ...props }, `${type}-${i}`); } case 'scatter': { const { type, ...props } = contentProps; return _jsx(ScatterSeries, { ...props }, `${type}-${i}`); } case 'annotation': { return (_jsx(Annotations, { children: contentProps.children.map(annotationMap) }, `${contentProps.type}-${i}`)); } default: { return null; } } }), children && _jsx(Annotations, { children: children })] })); } function annotationMap(annotationProps, index) { switch (annotationProps.type) { case 'arrow': { const { type, ...props } = annotationProps; return _jsx(Annotation.Arrow, { ...props }, `${type}-${index}`); } case 'circle': { const { type, ...props } = annotationProps; return _jsx(Annotation.Circle, { ...props }, `${type}-${index}`); } case 'ellipse': { const { type, ...props } = annotationProps; return _jsx(Annotation.Ellipse, { ...props }, `${type}-${index}`); } case 'line': { const { type, ...props } = annotationProps; return _jsx(Annotation.Line, { ...props }, `${type}-${index}`); } case 'rectangle': { const { type, ...props } = annotationProps; return _jsx(Annotation.Rectangle, { ...props }, `${type}-${index}`); } case 'shape': { const { type, ...props } = annotationProps; return _jsx(Annotation.Shape, { ...props }, `${type}-${index}`); } case 'text': { const { type, ...props } = annotationProps; return _jsx(Annotation.Text, { ...props }, `${type}-${index}`); } case 'group': { const { type, children, ...props } = annotationProps; return (_jsx(Annotation.Group, { ...props, children: children.map(annotationMap) }, `${type}-${index}`)); } default: { return null; } } } //# sourceMappingURL=PlotObject.js.map