@@ -42,7 +42,11 @@ Core components and plugin system:
4242
4343``` tsx
4444import { SolidUplot , createPluginBus } from " @dschz/solid-uplot" ;
45- import type { PluginFactory , SolidUplotPluginBus } from " @dschz/solid-uplot" ;
45+ import type {
46+ SolidUplotPluginBus ,
47+ UplotPluginFactory ,
48+ UplotPluginFactoryContext ,
49+ } from " @dschz/solid-uplot" ;
4650```
4751
4852### ` @dschz/solid-uplot/plugins `
@@ -376,7 +380,7 @@ const MyChart = () => {
376380The plugin system is open to extension. When authoring plugins for public consumption, follow this pattern:
377381
378382``` tsx
379- import type { PluginFactory } from " @dschz/solid-uplot" ;
383+ import type { UplotPluginFactory } from " @dschz/solid-uplot" ;
380384import type { CursorPluginMessageBus } from " @dschz/solid-uplot/plugins" ;
381385
382386// 1. Define your plugin's message type
@@ -393,7 +397,7 @@ export type MyPluginMessageBus = {
393397// 3. Export your plugin factory
394398export const myPlugin = (
395399 options = {},
396- ): PluginFactory <CursorPluginMessageBus & MyPluginMessageBus > => {
400+ ): UplotPluginFactory <CursorPluginMessageBus & MyPluginMessageBus > => {
397401 return ({ bus }) => {
398402 if (! bus ) {
399403 console .warn (" [my-plugin]: A plugin bus is required" );
@@ -457,73 +461,67 @@ const MyDashboard = () => {
457461### SolidUplot Component
458462
459463``` tsx
460- type SolidUplotProps <T extends VoidStruct = VoidStruct > = {
461- // Chart data (required)
462- data: uPlot .AlignedData ;
464+ // Main component props (extends all uPlot.Options except plugins, width, height)
465+ type SolidUplotProps <T extends VoidStruct = VoidStruct > = SolidUplotOptions <T > & {
466+ // Ref callback to access the chart container element
467+ ref? : (el : HTMLDivElement ) => void ;
468+
469+ // Callback fired when the uPlot instance is created
470+ onCreate? : (u : uPlot , meta : { seriesData: SeriesDatum [] }) => void ;
471+
472+ // Whether to reset scales when chart data is updated (default: true)
473+ resetScales? : boolean ;
463474
475+ // CSS styles for the chart container (position is managed internally)
476+ style? : Omit <JSX .CSSProperties , " position" >;
477+
478+ // Where to place children components relative to the chart (default: "top")
479+ childrenPlacement? : " top" | " bottom" ;
480+
481+ // Enable automatic resizing to fit container (default: false)
482+ autoResize? : boolean ;
483+ };
484+
485+ // Configuration options extending uPlot.Options with SolidJS enhancements
486+ type SolidUplotOptions <T extends VoidStruct = VoidStruct > = Omit <
487+ uPlot .Options ,
488+ " plugins" | " width" | " height"
489+ > & {
464490 // Chart dimensions
465491 width? : number ; // default: 600
466492 height? : number ; // default: 300
467493
468- // Responsive sizing
469- autoResize? : boolean ; // default: false
470-
471494 // Plugin configuration
472495 plugins? : SolidUplotPlugin <T >[];
473496 pluginBus? : SolidUplotPluginBus <T >;
474-
475- // Chart options (all uPlot.Options except plugins, width, height)
476- series? : uPlot .Series [];
477- scales? : uPlot .Scales ;
478- axes? : uPlot .Axis [];
479- // ... other uPlot options
480-
481- // Chart behavior
482- resetScales? : boolean ; // default: true
483-
484- // Callbacks
485- onCreate? : (u : uPlot , meta : { seriesData: SeriesDatum [] }) => void ;
486-
487- // Container styling
488- style? : JSX .CSSProperties ;
489- class? : string ;
490- id? : string ;
491- ref? : (el : HTMLDivElement ) => void ;
492-
493- // Children placement
494- childrenPlacement? : " top" | " bottom" ; // default: "top"
495497};
498+
499+ // Plugin type (can be standard uPlot plugin or factory function)
500+ type SolidUplotPlugin <T extends VoidStruct = VoidStruct > = uPlot .Plugin | UplotPluginFactory <T >;
496501```
497502
498503### Plugin Bus
499504
500505``` tsx
501- type SolidUplotPluginBus <T extends VoidStruct = VoidStruct > = {
502- data: T ;
503- setData: <K extends keyof T >(key : K , value : T [K ]) => void ;
504- setData: <K extends keyof T , P extends keyof T [K ]>(
505- key : K ,
506- path : P ,
507- value : T [K ][P ]
508- ) => void ;
509- };
506+ // Plugin bus type (derived from createPluginBus return type)
507+ type SolidUplotPluginBus <T extends VoidStruct = VoidStruct > = ReturnType <typeof createPluginBus <T >>;
510508
511509// Create a plugin bus
512- const createPluginBus = <T extends VoidStruct = VoidStruct >(
513- initialData ? : Partial < T >
514- ): SolidUplotPluginBus <T >;
510+ const createPluginBus: <T extends VoidStruct = VoidStruct >(
511+ initialData ? : T ,
512+ ) => SolidUplotPluginBus <T >;
515513```
516514
517515### Built-in Plugin Options
518516
519517``` tsx
520518// Cursor Plugin
521- const cursor = (): PluginFactory <CursorPluginMessageBus >;
519+ const cursor = (): UplotPluginFactory <CursorPluginMessageBus >;
522520
523521// Focus Series Plugin
524522const focusSeries = (options ?: {
525523 pxThreshold?: number ; // default: 15
526- }): PluginFactory < CursorPluginMessageBus & FocusSeriesPluginMessageBus > ;
524+ }): UplotPluginFactory < CursorPluginMessageBus & FocusSeriesPluginMessageBus > ;
527525
528526// Tooltip Plugin
529527const tooltip = (
@@ -535,7 +533,7 @@ const tooltip = (
535533 style? : JSX .CSSProperties ;
536534 zIndex? : number ; // default: 20
537535 }
538- ): PluginFactory < CursorPluginMessageBus & FocusSeriesPluginMessageBus > ;
536+ ): UplotPluginFactory < CursorPluginMessageBus & FocusSeriesPluginMessageBus > ;
539537
540538// Legend Plugin
541539const legend = (
@@ -548,7 +546,7 @@ const legend = (
548546 style? : JSX .CSSProperties ;
549547 zIndex? : number ; // default: 10
550548 }
551- ): PluginFactory < CursorPluginMessageBus & FocusSeriesPluginMessageBus > ;
549+ ): UplotPluginFactory < CursorPluginMessageBus & FocusSeriesPluginMessageBus > ;
552550```
553551
554552## 📚 Examples
0 commit comments