@@ -16,34 +16,66 @@ import uPlot from "uplot";
1616import type { PluginFactory , SolidUplotPluginBus , VoidStruct } from "./createPluginBus" ;
1717import { getSeriesData , type SeriesDatum } from "./utils/getSeriesData" ;
1818
19+ /** Placement options for children components relative to the chart */
1920type ChildrenPlacement = "top" | "bottom" ;
2021
22+ /**
23+ * A SolidJS-compatible uPlot plugin that can be either a standard uPlot plugin
24+ * or a factory function that creates a plugin with access to the plugin bus
25+ *
26+ * @template T - The type of the plugin bus data structure
27+ */
2128export type SolidUplotPlugin < T extends VoidStruct = VoidStruct > = uPlot . Plugin | PluginFactory < T > ;
2229
30+ /**
31+ * Configuration options for the SolidUplot component, extending uPlot.Options
32+ * with SolidJS-specific enhancements
33+ *
34+ * @template T - The type of the plugin bus data structure
35+ */
2336export type SolidUplotOptions < T extends VoidStruct = VoidStruct > = Omit <
2437 uPlot . Options ,
2538 "plugins" | "width" | "height"
2639> & {
40+ /** Chart width in pixels */
2741 readonly width ?: number ;
42+ /** Chart height in pixels */
2843 readonly height ?: number ;
44+ /** Plugin communication bus for coordinating between plugins */
2945 readonly pluginBus ?: SolidUplotPluginBus < T > ;
46+ /** Array of plugins to apply to the chart */
3047 readonly plugins ?: SolidUplotPlugin < T > [ ] ;
3148} ;
3249
50+ /**
51+ * Metadata provided to the onCreate callback when the chart is initialized
52+ */
3353type OnCreateMeta = {
54+ /** Array of series data extracted from the chart configuration */
3455 readonly seriesData : SeriesDatum [ ] ;
3556} ;
3657
58+ /**
59+ * Props for the SolidUplot component
60+ *
61+ * @template T - The type of the plugin bus data structure
62+ */
3763type SolidUplotProps < T extends VoidStruct = VoidStruct > = SolidUplotOptions < T > & {
38- /** The ref of the uPlot instance */
64+ /** Ref callback to access the chart container element */
3965 readonly ref ?: ( el : HTMLDivElement ) => void ;
40- /** Callback when uPlot instance is created */
66+ /** Callback fired when the uPlot instance is created */
4167 readonly onCreate ?: ( u : uPlot , meta : OnCreateMeta ) => void ;
42- /** Apply scale reset on redraw triggered by updated plot data (default: `true`) */
68+ /**
69+ * Whether to reset scales when chart data is updated
70+ * @default true
71+ */
4372 readonly resetScales ?: boolean ;
44- /** The style of the uPlot instance container */
73+ /** CSS styles for the chart container (position is managed internally) */
4574 readonly style ?: Omit < JSX . CSSProperties , "position" > ;
46- /** The placement of the children container. Defaults to "top" */
75+ /**
76+ * Where to place children components relative to the chart
77+ * @default "top"
78+ */
4779 readonly childrenPlacement ?: ChildrenPlacement ;
4880 /**
4981 * Enable automatic resizing to fit container.
@@ -58,6 +90,35 @@ type SolidUplotProps<T extends VoidStruct = VoidStruct> = SolidUplotOptions<T> &
5890 readonly autoResize ?: boolean ;
5991} ;
6092
93+ /**
94+ * A SolidJS wrapper component for uPlot charts with enhanced features
95+ *
96+ * This component provides:
97+ * - Reactive data updates
98+ * - Plugin system with communication bus
99+ * - Automatic resizing capabilities
100+ * - Flexible children placement
101+ * - TypeScript support with generics
102+ *
103+ * @template T - The type of the plugin bus data structure for type-safe plugin communication
104+ *
105+ * @param props - Component props extending uPlot options with SolidJS enhancements
106+ * @returns JSX element containing the chart and any children components
107+ *
108+ * @example
109+ * ```tsx
110+ * <SolidUplot
111+ * data={chartData}
112+ * height={400}
113+ * autoResize
114+ * series={[
115+ * {},
116+ * { label: "Series 1", stroke: "red" }
117+ * ]}
118+ * onCreate={(chart) => console.log("Chart created:", chart)}
119+ * />
120+ * ```
121+ */
61122export const SolidUplot = < T extends VoidStruct = VoidStruct > (
62123 props : ParentProps < SolidUplotProps < T > > ,
63124) : JSX . Element => {
0 commit comments