Skip to content

Modernize chart rendering: theme layer, HiDPI zoom, downsampling - #21

Open
velteyn wants to merge 11 commits into
masterfrom
feature/modernize-chart-rendering
Open

Modernize chart rendering: theme layer, HiDPI zoom, downsampling#21
velteyn wants to merge 11 commits into
masterfrom
feature/modernize-chart-rendering

Conversation

@velteyn

@velteyn velteyn commented Aug 10, 2026

Copy link
Copy Markdown
Owner

Summary

Implements the modernize-chart-rendering change — three groups of improvements to the EclipseTrader chart subsystem.

1. Theme layer

  • ChartTheme (immutable value object) + ChartThemes.getDefault() with Material palette (blue line 33,150,243, teal positive 38,166,154, red negative 239,83,80, outline 64,64,64)
  • All six chart classes (CandleStickChart, BarChart, OHLCLineChart, HistogramBarChart, HistogramAreaChart, LineChart) replace inline new RGB(...) with ChartThemes.getDefault() lookups
  • MainPropertiesPage color-selector defaults now source from theme

2. HiDPI rendering (SWT 4.31)

  • ChartUtils.createBackingImage(Canvas, Rectangle) creates logical-size offscreen images; SWT 4.31 auto-scales to device pixels
  • ChartUtils.getZoom(Canvas) uses Monitor.getZoom() (4.31) with getDPI() fallback
  • ChartCanvas (main + vertical scale) and DateScaleCanvas now recreate images on zoom change (previously only on resize; getBounds() is logical so resize check never fired on zoom)
  • Graphics constructor enables setAntialias(SWT.ON) + setTextAntialias(SWT.ON) for shape/text smoothing

3. Downsampling and geometry caching

  • OHLCDownsampler: min/max binning per pixel column (preserves high/low, first-open/last-close); returns pooled IOHLC[]
  • ScalarDownsampler: max-deviation-from-mean per column (preserves spikes) for line/area/histogram; returns NumberValue[]
  • Wired into all six setDataBounds: when visible points exceed clientArea.width, aggregate before geometry build
  • Geometry cache keyed by (firstDate, lastDate, width) per chart object; invalidate() clears it

4. Tests

  • Pure-function JUnit 5 tests for OHLCDownsampler and ScalarDownsampler (boundary, extreme preservation, one-per-column) in org.eclipsetrader.core.modern.tests

No local Java/Maven — CI build verification with mvn package (Tycho 4.0.8, JDK 21) is needed.

- Add ChartTheme/ChartThemes with Material palette defaults
- Replace inline RGB literals in six chart classes with theme lookups
- Apply theme defaults to MainPropertiesPage color selectors
- Add ChartUtils.createBackingImage/getZoom helpers for SWT 4.31 zoom awareness
- Migrate ChartCanvas/DateScaleCanvas offscreen images to recreate on zoom change
- Enable GC anti-aliasing (shape + text) in Graphics constructor
- Add OHLCDownsampler (min/max binning) and ScalarDownsampler (max-deviation)
- Wire downsampling and range-based caching into all six chart setDataBounds
- Cache keyed by (firstDate,lastDate,width); cleared on invalidate()
- Add pure-function unit tests for both downsamplers in core.modern.tests
- Update OpenSpec tasks.md checkboxes
OHLCDownsampler and ScalarDownsampler depend only on core types (IOHLC,
OHLC, NumberValue, IAdaptable) -- zero SWT dependencies. Moving them
to core.charts lets core.modern.tests run their unit tests without
pulling in the full SWT/UI stack, fixing the Windows test-runtime
failure (error 13 / native library resolution).
- Default chart type: candlestick (was bars in basic-template.xml)
- Chart type switcher toolbar: Candlestick / OHLC Bars / Line / Area
- Period/timeframe actions added to toolbar for quick time switching
- Enhanced context menu with Chart Type and Period submenus
- TraderPerspective: added orders/tickers placeholders, chart toolbars,
  show-view shortcuts for Watchlist/Level2/Orders/Tickers
- ChartsPerspective: added markets/orders/level2/tickers/portfolio
  placeholders, more show-view shortcuts
- Fixed paste action ID bug (was "copy")

These changes make the chart interface functional out-of-the-box for
a professional trading workflow, with chart type switching, period
selection, and populated perspective defaults.
- MainChartFactory.setParameters fallback: Candles not Bars
  (this was the root cause of line charts on fresh open)
- ChartsPerspective: markets view auto-opens in bottom panel
- TraderPerspective: chart tool/zoom action sets added

These were uncommitted edits from the previous toolbar commit.
- Register PreferenceInitializer in core bundle
- Set DEFAULT_CONNECTOR_ID to org.eclipsetrader.jessx.connector
- Level2View reads this preference when no saved connector exists
  (no more manual "Select Data Source" on each Level2 open)
- Level2View: when no saved connector in memento (first run), use
  default connector from CoreActivator (JessX streaming via
  PreferenceInitializer). Previously the fallback was unreachable
  because the entire block was skipped when id was null.

- createPeriodActions: hardcoded fallback default period list
  (2Y,1Y,6M,3M,1M,5D,1D) when preference unmarshalling fails,
  so period menu is never empty.

Verified: mvn clean install all 248 tests pass, product builds.
@velteyn
velteyn force-pushed the feature/modernize-chart-rendering branch from 7a2861c to c99ff17 Compare August 10, 2026 17:23
- Add missing preferenceCustomization property to product extension
  in org.eclipsetrader.platform/plugin.xml. Without this, the
  plugin_customization.ini was never loaded by the workbench on
  first launch, meaning:
  - Initial perspective (traderPerspective) was not set
  - Default connector was not applied
  - All other customization defaults were ignored

- Change default connector from Yahoo to JessX streaming
  (org.eclipsetrader.jessx.connector) for both live feed and
  backfill. Combined with Level2View fallback fix, Level2 now
  auto-connects to JessX on first open.

Verified: mvn clean install all 248 tests pass, product assembles.
- CandleStickChart.Candle.paint(): min body width 2px,
  min body height 1px (doji candles now visible)
- BarChart.Bar.paint(): min tick width 3px

Without this, downsampled candles at high zoom-out (800 candles
in 800px) had body width of 0-1px, appearing as invisible or
flattened lines. The wick line was visible but the body was not.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant