TAChart: added lacking protection for TCustomColorMapSeries color source
Original Reporter info from Mantis: Marcin Wiazowski
-
Reporter name:
Original Reporter info from Mantis: Marcin Wiazowski
- Reporter name:
Description:
Recently, some protection was added for series' built-in sources: XCount / YCount can't be set below the required minimum values.
There is still one series family, that hasn't this protection implemented: TCustomColorMapSeries. This is because:
- it has other inheritance path, than all the other series having source,
- the source is unusual in that sense, that it provides colors, and is assigned by ColorSource property (not just Source).
Since ColorSource uses extent calculation for internal color transformation, it's important to avoid decreasing its XCount to 0 - because XCount = 0 case has now some special extent calculation algorithm, which is not valid for color source.
The attached patch adds the lacking protection, mainly by copying lacking functions from TChartSeries:
- TChartSeries.CheckSource() -> TCustomColorMapSeries.CheckColorSource()
- TChartSeries.SourceChanged() -> TCustomColorMapSeries.ColorSourceChanged()
- TChartSeries.GetXYCountNeeded() -> TCustomColorMapSeries.GetXYCountNeeded()
Other changes are:
-
built-in color source (i.e. FBuiltinColorSource) is now declared as TListChartSource - typecasting in TCustomColorMapSeries.BuildPalette() is no longer needed (sorry for not providing a separate patch for this trivial change)
-
In TCustomColorMapSeries.BuildPalette(), all the code is located between BeginUpdate() and EndUpdate() again: I moved some of the code below the EndUpdate() call some time ago and this was a mistake - this is because:
for i:=0 to Count-1 do
Item[i]^.X := (Item[i]^.X - ex.a.x) * factor + cmin;
also modifies the source.
-
In TCustomColorMapSeries.BuildPalette(), UpdateColorExtent() is no longer called - all source changes are now handled by TCustomColorMapSeries.ColorSourceChanged() handler (where the UpdateColorExtent() call is made).
-
In TCustomColorMapSeries.Create():
- listener for color source changes uses now a dedicated TCustomColorMapSeries.ColorSourceChanged() method
- built-in color source is now created as TBuiltinListChartSource
- built-in color source has now XCount and YCount manually assigned, which decreases YCount to 0 (thus making extent calculation faster)
-
In TCustomColorMapSeries.Destroy(), listener is freed before the built-in color source, to avoid SIGSEV
-
As already mentioned, all color source changes are now handled by TCustomColorMapSeries.ColorSourceChanged() - so UpdateParentChart() calls are no longer needed after BuildPalette() calls in TCustomColorMapSeries.SetBuiltinPalette() / SetPaletteMax() / SetPaletteMin()
-
TCustomColorMapSeries.SetColorSource() was adjusted a bit, to follow current TChartSeries.SetSource() implementation:
- removed UpdateColorExtent() is now called in TCustomColorMapSeries.ColorSourceChanged()
- removed UpdateParentChart() is now replaced with StyleChanged() call in TCustomColorMapSeries.ColorSourceChanged()
By it's nature, the attached patch fixes also some other problem: TCustomColorMapSeries.ColorSourceChanged() handler calls now UpdateColorExtent() - thanks to this, changes in the external color source are no longer able to make the color extent out-of-sync with the source itself.
Mantis conversion info:
- Mantis ID: 35705
- Build: 61359
- Version: 2.1 (SVN)
- Fixed in revision: 61409 (#900910e4)
- Target version: 2.2