Overview
VibeTrader’s charting system is built on a hierarchical component architecture, with each layer responsible for specific rendering and interaction concerns.Component Hierarchy
Layer 1: Container
KlineViewContainer
The top-level container that orchestrates all chart views and manages global state. Location:src/lib/charting/view/KlineViewContainer.tsx
Responsibilities:
- Manages
ChartXControlshared across all views - Handles data fetching and series initialization
- Controls layout (stacked indicators, overlays)
- Manages user interactions (pan, zoom, drawing)
- Coordinates updates across all child views
- Handles indicator execution via PineTS
Layer 2: Views
Views are responsible for rendering a specific aspect of the chart (price, volume, or indicator).ChartView (Abstract Base)
Location:src/lib/charting/view/ChartView.tsx
The abstract base class for all chart views.
Interface:
KlineView
Location:src/lib/charting/view/KlineView.tsx
Renders the main price chart with candlesticks and overlays.
Implementation:
VolumeView
Location:src/lib/charting/view/VolumeView.tsx
Renders the volume histogram below the price chart.
IndicatorView
Location:src/lib/charting/view/IndicatorView.tsx
Renders stacked indicator panels (RSI, MACD, etc.).
Indicator Definition:
Layer 3: Plots
Plot components are responsible for rendering specific visual elements. Location:src/lib/charting/plot/
PlotKline
Renders OHLCV candlesticks or bars. Props:PlotLine
Renders continuous lines for indicators.PlotStepLine
Renders step lines (horizontal segments with vertical steps).PlotHistogram
Renders histogram bars (used for volume, MACD histogram).PlotCrossCircles
Renders cross or circle markers at data points.PlotShape
Renders custom shapes (arrows, flags, triangles) for signals.PlotHline
Renders horizontal reference lines.PlotFill
Fills the area between two plot lines.PlotBgcolor
Applies background color to chart regions.PlotDrawingLine
Renders user-drawn trend lines and shapes.Plot Type Selection
The view selects the appropriate plot component based onoptions.style:
Layer 4: Panes
Pane components render UI elements around the chart. Location:src/lib/charting/pane/
AxisX
Location:src/lib/charting/pane/AxisX.tsx
Renders the time axis at the bottom of the chart.
Features:
- Intelligent tick spacing based on timeframe
- Multi-level labeling (year, month, day, hour, minute)
- Timezone-aware formatting
AxisY
Location:src/lib/charting/pane/AxisY.tsx
Renders the value axis on the right side of each view.
Features:
- Auto-scaled tick values
- Normalization display (x 10^n)
- Grid line coordination
Title
Location:src/lib/charting/pane/Title.tsx
Displays chart title and indicator values at cursor position.
Spacing
Location:src/lib/charting/pane/Spacing.tsx
Provides spacing between chart elements.
Help
Location:src/lib/charting/pane/Help.tsx
Displays keyboard shortcuts and help information.
Screenshot
Location:src/lib/charting/pane/Screenshot.tsx
Handles chart screenshot generation using html2canvas.
Layer 5: Drawings
Drawing components enable interactive chart annotations. Location:src/lib/charting/drawing/
Drawing (Base)
Location:src/lib/charting/drawing/Drawing.tsx
Available Drawings
- LineDrawing: Trend lines
- ParallelDrawing: Parallel channels
- FibonacciRetraceDrawing: Fibonacci retracement levels
- FibonacciTimeZoneDrawing: Fibonacci time zones
- GannAnglesDrawing: Gann fan lines
- PloylineDrawing: Multi-segment lines
Controls
ChartXControl
Location:src/lib/charting/view/ChartXControl.ts
Manages X-axis (time) coordinate transformations.
Key Properties:
ChartYControl
Location:src/lib/charting/view/ChartYControl.ts
Manages Y-axis (value) coordinate transformations.
Key Properties:
Update Flow
When user interacts with the chart:- Event Capture: Mouse/keyboard events captured by view
- Control Update:
ChartXControlorChartYControlstate changes - Event Propagation:
UpdateEventsent to all views - Geometry Recomputation: Views call
computeGeometry() - Plot Regeneration:
plot()creates new JSX elements - State Update:
setState()triggers React re-render - SVG Rendering: React reconciles and updates DOM
Best Practices
Creating Custom Views
- Extend
ChartView<ViewProps, ViewState> - Implement required abstract methods
- Initialize
ycin constructor - Call
computeGeometry()before plotting - Return plot elements from
plot()
Creating Custom Plots
- Use SVG primitives (
<path>,<rect>,<circle>, etc.) - Iterate only over visible bars (
xc.nBars) - Use
xcmethods for time-to-x conversion - Use
yc.yv()for value-to-y conversion - Apply proper z-ordering with
depthprop
Performance Tips
- Limit rendering to visible range using
xc.nBars - Memoize expensive calculations
- Use
React.Fragmentto avoid extra DOM nodes - Batch state updates when possible
- Avoid creating new objects in render methods
Next Steps
- Learn about the Time Series System
- Review the Architecture Overview
- Explore the source code in
src/lib/charting/