Skip to content

Fix HeatMap legend gradient asymmetry (issue #585) + cleanup#966

Merged
timmolter merged 1 commit into
developfrom
timmolter/fix-heatmap-legend-asymmetry-585
Jun 9, 2026
Merged

Fix HeatMap legend gradient asymmetry (issue #585) + cleanup#966
timmolter merged 1 commit into
developfrom
timmolter/fix-heatmap-legend-asymmetry-585

Conversation

@timmolter

Copy link
Copy Markdown
Member

Root cause

The HeatMap gradient legend bar was visually asymmetric even when the colormap and data range were perfectly symmetric. The LinearGradientPaint start point (fraction=0, min colour) was placed at starty + gradientColumnHeight, but the rectangle it filled extended fontSize pixels further down to starty + fontSize + gradientColumnHeight. That extra strip at the bottom was always clamped to rangeColors[0], making the min-colour band appear disproportionately wide.

Fixes

Legend_HeatMap - align the gradient start point to the actual bottom of the rectangle:

starty + legendFont.getSize() + gradientColorColumnHeight

HeatMapSeries - calculateMinMax() initialised max = Double.MIN_VALUE (~4.9E-324, not the minimum double). Changed to -Double.MAX_VALUE so datasets with all-negative values compute the correct max.

HeatMapStyler - setRangeColors() was missing an else, so the single-colour workaround array was immediately overwritten by the original 1-element array.

Styler / all subclass stylers - setTheme(Theme) was @Deprecated in each of the 10 concrete stylers, yet every chart's (width, height, Theme) constructor called it internally, producing deprecation warnings on every build. Fixed by promoting a single non-deprecated setTheme(Theme) to Styler, removing the redundant overrides from 9 subclasses, and converting BoxStyler's override to a proper @Override (it has extra boxplotCalCulationMethod reset logic). Build is now warning-free.

Styler - fixed a broken Javadoc {@link XChartPanel#setToolTipsEnabled(boolean)} reference (class is in a different package; added fully-qualified name).

Demo

TestForIssue585 in xchart-demo/.../standalone/issues/ opens two windows (vertical and horizontal legend) with a symmetric blue colormap over a -5 to +5 range, making the pre-fix asymmetry immediately obvious.

Closes #585

- Legend_HeatMap: align LinearGradientPaint start point to the actual
  bottom of the gradient rectangle (was fontSize pixels short, causing
  the min-color band to appear wider than the max-color band)
- HeatMapSeries: fix calculateMinMax() initialising max = Double.MIN_VALUE
  (~0) instead of -Double.MAX_VALUE, which broke all-negative datasets
- HeatMapStyler: add missing else in setRangeColors() so the single-color
  workaround array is not immediately overwritten by the original array
- Styler: promote setTheme(Theme) to a non-deprecated base-class method;
  remove redundant @deprecated overrides from all 9 subclass stylers;
  keep BoxStyler override (@OverRide) because it resets boxplotCalCulationMethod
- Styler: fix broken Javadoc @link to XChartPanel#setToolTipsEnabled
- Demo: add TestForIssue585 reproducing the asymmetric gradient legend

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@timmolter timmolter merged commit 0e731bc into develop Jun 9, 2026
1 check passed
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.

HeatMap: Presumably symmetric colormap definition leads to unsymmetric legend

1 participant