@@ -26,6 +26,7 @@ WebGPU is a modern graphics API for the web that provides:
2626
2727### Guix WebGPU Features
2828
29+ #### 3D Graphics
2930- ✅ ** Declarative 3D API** : Scene graph with meshes, cameras, and lights
3031- ✅ ** PBR Materials** : Physically-based rendering with metalness/roughness
3132- ✅ ** Built-in Geometries** : Box, sphere, plane primitives
@@ -39,6 +40,18 @@ WebGPU is a modern graphics API for the web that provides:
3940- 🚧 ** Textures** : Image and procedural textures (in progress)
4041- 🚧 ** Post-processing** : Effects and filters (planned)
4142
43+ #### 2D Charts
44+ - ✅ ** Candlestick Charts** : OHLCV (Open-High-Low-Close-Volume) visualization
45+ - ✅ ** Declarative API** : Component-based chart definition
46+ - ✅ ** Axis System** : Time-based and numeric scales with automatic formatting
47+ - ✅ ** Grid Lines** : Configurable grid lines for both axes
48+ - ✅ ** GPU Acceleration** : All rendering happens on GPU for high performance
49+ - ✅ ** Responsive Design** : Adapts to different canvas sizes
50+ - 🚧 ** Line Charts** : Continuous data visualization (in progress)
51+ - 🚧 ** Bar Charts** : Categorical data visualization (planned)
52+ - 🚧 ** Area Charts** : Filled line charts (planned)
53+ - 🚧 ** Multiple Series** : Overlay multiple data series (planned)
54+
4255## Architecture
4356
4457### Runtime Structure
@@ -443,10 +456,14 @@ renderer.Cleanup()
443456
444457## Examples
445458
446- ### Rotating Cube
459+ ### Rotating Cube (3D)
447460
448461See [ ` examples/webgpu-cube/ ` ] ( ../examples/webgpu-cube/ ) for a complete rotating cube example with controls.
449462
463+ ### Candlestick Chart (2D)
464+
465+ See [ ` examples/webgpu-chart/ ` ] ( ../examples/webgpu-chart/ ) for a complete 2D charting example with Bitcoin price data.
466+
450467### Custom Animation
451468
452469``` go
@@ -484,6 +501,254 @@ for x := -2; x <= 2; x++ {
484501}
485502```
486503
504+ ## 2D Charts
505+
506+ Guix provides GPU-accelerated 2D charting capabilities for high-performance data visualization.
507+
508+ ### Chart Types
509+
510+ #### Candlestick Charts
511+
512+ Candlestick charts visualize OHLCV (Open-High-Low-Close-Volume) data, commonly used for financial markets:
513+
514+ ``` go
515+ // Define OHLCV data
516+ chartData := []chart.OHLCV {
517+ {
518+ Timestamp: 1701388800000 , // Unix timestamp in milliseconds
519+ Open: 37500 ,
520+ High: 38200 ,
521+ Low: 37100 ,
522+ Close: 37800 ,
523+ Volume: 28500000000 ,
524+ },
525+ // ... more data points
526+ }
527+
528+ // Create chart with declarative syntax
529+ Chart (ChartBackground (0.08 , 0.09 , 0.12 , 1.0 )) {
530+ // X-Axis with time scale
531+ XAxis (
532+ AxisPosition (" bottom" ),
533+ TimeScale (true ), // Format timestamps as dates
534+ GridLines (true ), // Show vertical grid lines
535+ )
536+
537+ // Y-Axis with automatic formatting
538+ YAxis (
539+ AxisPosition (" right" ),
540+ GridLines (true ), // Show horizontal grid lines
541+ )
542+
543+ // Candlestick series
544+ CandlestickSeries (
545+ ChartData (chartData),
546+ UpColor (0.18 , 0.80 , 0.44 , 1.0 ), // Green for bullish (close > open)
547+ DownColor (0.91 , 0.27 , 0.38 , 1.0 ), // Red for bearish (close < open)
548+ WickColor (0.6 , 0.6 , 0.65 , 1.0 ), // Gray for wicks (high/low lines)
549+ BarWidth (0.8 ), // Width of candle body (0.0-1.0)
550+ )
551+ }
552+ ```
553+
554+ ### Chart Components
555+
556+ Charts are built from declarative components:
557+
558+ #### Chart Container
559+
560+ The root ` Chart ` component defines the overall chart configuration:
561+
562+ ``` go
563+ Chart (
564+ ChartBackground (r, g, b, a), // Background color (RGBA)
565+ ) {
566+ // Child components (axes, series)
567+ }
568+ ```
569+
570+ #### Axes
571+
572+ Define X and Y axes with position, scale type, and grid lines:
573+
574+ ``` go
575+ // X-Axis (horizontal)
576+ XAxis (
577+ AxisPosition (" bottom" ), // "bottom" or "top"
578+ TimeScale (true ), // Time-based scale (converts timestamps)
579+ GridLines (true ), // Show grid lines
580+ )
581+
582+ // Y-Axis (vertical)
583+ YAxis (
584+ AxisPosition (" right" ), // "left" or "right"
585+ GridLines (true ), // Show grid lines
586+ )
587+ ```
588+
589+ #### Series
590+
591+ Series components render the actual data:
592+
593+ ``` go
594+ // Candlestick series for OHLCV data
595+ CandlestickSeries (
596+ ChartData (data), // []chart.OHLCV data
597+ UpColor (r, g, b, a), // Color for bullish candles
598+ DownColor (r, g, b, a), // Color for bearish candles
599+ WickColor (r, g, b, a), // Color for wick lines
600+ BarWidth (width), // Width of candle bodies (0.0-1.0)
601+ )
602+ ```
603+
604+ ### Using Charts in Components
605+
606+ Integrate charts into Guix components:
607+
608+ ``` go
609+ func App () (Component ) {
610+ chartData := GetBitcoinData ()
611+
612+ Div (ID (" app" )) {
613+ H1 { " Bitcoin Price Chart" }
614+
615+ // Canvas element for chart rendering
616+ Canvas (
617+ ID (" chart-canvas" ),
618+ Width (1200 ),
619+ Height (700 ),
620+ ) {
621+ // Embed chart using GPUChart
622+ GPUChart (NewBitcoinChart (chartData))
623+ }
624+ }
625+ }
626+
627+ // Define chart in separate component
628+ func BitcoinChart (data *ChartData ) (Chart ) {
629+ Chart (ChartBackground (0.08 , 0.09 , 0.12 , 1.0 )) {
630+ XAxis (AxisPosition (" bottom" ), TimeScale (true ), GridLines (true ))
631+ YAxis (AxisPosition (" right" ), GridLines (true ))
632+
633+ CandlestickSeries (
634+ ChartData (data.Bitcoin ),
635+ UpColor (0.18 , 0.80 , 0.44 , 1.0 ),
636+ DownColor (0.91 , 0.27 , 0.38 , 1.0 ),
637+ WickColor (0.6 , 0.6 , 0.65 , 1.0 ),
638+ BarWidth (0.8 ),
639+ )
640+ }
641+ }
642+ ```
643+
644+ ### Chart Data Format
645+
646+ #### OHLCV Structure
647+
648+ ``` go
649+ type OHLCV struct {
650+ Timestamp int64 // Unix timestamp in milliseconds
651+ Open float64 // Opening price
652+ High float64 // Highest price in period
653+ Low float64 // Lowest price in period
654+ Close float64 // Closing price
655+ Volume float64 // Trading volume
656+ }
657+ ```
658+
659+ #### Example Data
660+
661+ ``` go
662+ data := []chart.OHLCV {
663+ {
664+ Timestamp: 1701388800000 , // Dec 1, 2024 00:00:00 UTC
665+ Open: 37500 ,
666+ High: 38200 ,
667+ Low: 37100 ,
668+ Close: 37800 ,
669+ Volume: 28500000000 ,
670+ },
671+ {
672+ Timestamp: 1701475200000 , // Dec 2, 2024 00:00:00 UTC
673+ Open: 37800 ,
674+ High: 39100 ,
675+ Low: 37600 ,
676+ Close: 38900 ,
677+ Volume: 32100000000 ,
678+ },
679+ }
680+ ```
681+
682+ ### Chart Configuration
683+
684+ #### Colors
685+
686+ Colors are specified as RGBA floats (0.0-1.0):
687+
688+ ``` go
689+ // Predefined colors
690+ Green := Color (0.18 , 0.80 , 0.44 , 1.0 ) // Bullish
691+ Red := Color (0.91 , 0.27 , 0.38 , 1.0 ) // Bearish
692+ Gray := Color (0.60 , 0.60 , 0.65 , 1.0 ) // Neutral
693+ Dark := Color (0.08 , 0.09 , 0.12 , 1.0 ) // Background
694+ ```
695+
696+ #### Bar Width
697+
698+ Control the width of candlestick bodies:
699+
700+ ``` go
701+ BarWidth (0.8 ) // 80% of available space (default)
702+ BarWidth (0.5 ) // 50% - thinner candles with more spacing
703+ BarWidth (1.0 ) // 100% - candles touch each other
704+ ```
705+
706+ ### Chart Rendering
707+
708+ Charts are automatically rendered by the WebGPU runtime:
709+
710+ 1 . ** Data Processing** : Convert OHLCV data to GPU buffers
711+ 2 . ** Axis Calculation** : Determine scales, ranges, and tick positions
712+ 3 . ** GPU Upload** : Transfer vertex data to GPU memory
713+ 4 . ** Shader Execution** : Execute WGSL shaders for rendering
714+ 5 . ** Presentation** : Display result on canvas
715+
716+ ### Chart Performance
717+
718+ GPU-accelerated charts provide excellent performance:
719+
720+ - ** High Data Volume** : Handle thousands of candles smoothly
721+ - ** Real-time Updates** : Update data without performance degradation
722+ - ** Smooth Rendering** : 60 FPS rendering with requestAnimationFrame
723+ - ** Memory Efficient** : Data stored in GPU buffers
724+
725+ ### Future Chart Types
726+
727+ Upcoming chart types:
728+
729+ ``` go
730+ // Line chart (in progress)
731+ LineSeries (
732+ ChartData (data),
733+ LineColor (r, g, b, a),
734+ LineWidth (width),
735+ )
736+
737+ // Bar chart (planned)
738+ BarSeries (
739+ ChartData (data),
740+ BarColor (r, g, b, a),
741+ BarWidth (width),
742+ )
743+
744+ // Area chart (planned)
745+ AreaSeries (
746+ ChartData (data),
747+ FillColor (r, g, b, a),
748+ LineColor (r, g, b, a),
749+ )
750+ ```
751+
487752## Performance Tips
488753
489754### 1. Minimize Buffer Updates
0 commit comments