@@ -26,7 +26,9 @@ vdom.H("recharts:ResponsiveContainer", map[string]any{
2626## Key Concepts
2727
2828### Namespace Usage
29+
2930All recharts components use the ` recharts: ` prefix and have the same names as their React counterparts:
31+
3032- ` recharts:ResponsiveContainer ` - Container that responds to parent size changes
3133- ` recharts:LineChart ` , ` recharts:AreaChart ` , ` recharts:BarChart ` - Chart types
3234- ` recharts:XAxis ` , ` recharts:YAxis ` - Axis components
@@ -36,6 +38,7 @@ All recharts components use the `recharts:` prefix and have the same names as th
3638Every Recharts component from the React library is available with the ` recharts: ` prefix.
3739
3840### Data Structure
41+
3942Charts expect Go structs or slices that can be serialized to JSON. Use json tags to control field names:
4043
4144``` go
@@ -53,6 +56,7 @@ data := []DataPoint{
5356```
5457
5558### Props and Configuration
59+
5660Recharts components accept the same props as the React version, passed as Go map[ string] any:
5761
5862``` go
@@ -188,13 +192,13 @@ Charts automatically re-render when their data changes through Tsunami's reactiv
188192var App = app.DefineComponent (" App" ,
189193 func (ctx context.Context , _ struct {}) any {
190194 // State management
191- chartData , setChartData , setChartDataFn := vdom .UseData [[]MetricsData ](ctx, " metrics" )
192-
195+ chartData , setChartData , setChartDataFn := app .UseData [[]MetricsData ](" metrics" )
196+
193197 // Timer for live updates
194- vdom .UseEffect (ctx, func () func () {
198+ app .UseEffect (func () func () {
195199 ticker := time.NewTicker (1 * time.Second )
196200 done := make (chan bool )
197-
201+
198202 go func () {
199203 for {
200204 select {
@@ -215,13 +219,13 @@ var App = app.DefineComponent("App",
215219 }
216220 }
217221 }()
218-
222+
219223 return func () {
220224 ticker.Stop ()
221225 close (done)
222226 }
223227 }, []any{})
224-
228+
225229 return renderLineChart (chartData)
226230 },
227231)
@@ -230,6 +234,7 @@ var App = app.DefineComponent("App",
230234## Responsive Design
231235
232236### Container Sizing
237+
233238Always use ` ResponsiveContainer ` for charts that should adapt to their container:
234239
235240``` go
@@ -247,6 +252,7 @@ vdom.H("recharts:ResponsiveContainer", map[string]any{
247252```
248253
249254### Mobile-Friendly Charts
255+
250256Use Tailwind classes to create responsive chart layouts:
251257
252258``` go
@@ -265,6 +271,7 @@ vdom.H("div", map[string]any{
265271## Advanced Features
266272
267273### Custom Styling
274+
268275You can customize chart appearance through props:
269276
270277``` go
@@ -280,6 +287,7 @@ vdom.H("recharts:Tooltip", map[string]any{
280287```
281288
282289### Event Handling
290+
283291Charts support interaction events:
284292
285293``` go
@@ -295,24 +303,28 @@ vdom.H("recharts:LineChart", map[string]any{
295303## Best Practices
296304
297305### Data Management
298- - Use global atoms (` UseData ` ) for chart data that updates frequently
306+
307+ - Use global atoms (app.UseData) for chart data that updates frequently
299308- Implement data windowing for large datasets to maintain performance
300309- Structure data with appropriate json tags for clean field names
301310
302311### Performance
312+
303313- Limit data points for real-time charts (typically 20-100 points)
304- - Use ` UseEffect ` cleanup functions to prevent memory leaks with timers
314+ - Use app. UseEffect cleanup functions to prevent memory leaks with timers
305315- Consider data aggregation for historical views
306316
307317### Styling
318+
308319- Use consistent color schemes across charts
309320- Leverage Tailwind classes for chart containers and surrounding UI
310321- Consider dark/light theme support in color choices
311322
312323### State Updates
324+
313325- Use functional setters (` setDataFn ` ) for complex data transformations
314- - Call ` app.SendAsyncInitiation() ` after async state updates
315- - Implement proper cleanup in ` UseEffect ` for timers and goroutines
326+ - Call app.SendAsyncInitiation() after async state updates
327+ - Implement proper cleanup in app. UseEffect for timers and goroutines
316328
317329## Differences from React Recharts
318330
@@ -322,4 +334,4 @@ vdom.H("recharts:LineChart", map[string]any{
3223344 . ** Events** : Event handlers receive Go types, not JavaScript events
3233355 . ** Styling** : Combine Recharts styling with Tailwind classes for layout
324336
325- The core Recharts API remains the same - consult the official Recharts documentation for detailed prop references and advanced features. The Tsunami integration simply adapts the React patterns to Go's type system while maintaining the familiar development experience.
337+ The core Recharts API remains the same - consult the official Recharts documentation for detailed prop references and advanced features. The Tsunami integration simply adapts the React patterns to Go's type system while maintaining the familiar development experience.
0 commit comments