From 098ed0616234b417016bf4ef30916b7aceaa38c8 Mon Sep 17 00:00:00 2001 From: wp Date: Sat, 11 Nov 2017 23:07:56 +0000 Subject: [PATCH] TAChart: Add new property AutoscaleColors to TCustomColorMapSeries git-svn-id: trunk@56368 - --- components/tachart/taexpressionseries.pas | 4 +- components/tachart/tafuncseries.pas | 64 ++++++++++++++++++++++- components/tachart/tagraph.pas | 2 +- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/components/tachart/taexpressionseries.pas b/components/tachart/taexpressionseries.pas index b840213a14..ddae7193a0 100644 --- a/components/tachart/taexpressionseries.pas +++ b/components/tachart/taexpressionseries.pas @@ -584,8 +584,8 @@ end; procedure TExpressionSeries.SetExpression(const AValue: String); begin - if FParser.Expression = AValue then - exit; +// if FParser.Expression = AValue then +// exit; FExpression := AValue; RequestParserUpdate; UpdateParentChart; diff --git a/components/tachart/tafuncseries.pas b/components/tachart/tafuncseries.pas index 915a5a548a..7a25ee9677 100644 --- a/components/tachart/tafuncseries.pas +++ b/components/tachart/tafuncseries.pas @@ -357,6 +357,9 @@ type FStepX: TFuncSeriesStep; FStepY: TFuncSeriesStep; FUseImage: TUseImage; + FAutoScaleColors: Boolean; + FColorExtentMin, FColorExtentMax: Double; + procedure SetAutoscaleColors(AValue: Boolean); procedure SetBrush(AValue: TBrush); procedure SetColorSource(AValue: TCustomChartSource); procedure SetInterpolate(AValue: Boolean); @@ -364,7 +367,9 @@ type procedure SetStepY(AValue: TFuncSeriesStep); procedure SetUseImage(AValue: TUseImage); protected + FMinZ, FMaxZ: Double; procedure GetLegendItems(AItems: TChartLegendItems); override; + procedure GetZRange(ARect: TRect; dx, dy: Integer); public procedure Assign(ASource: TPersistent); override; @@ -377,6 +382,8 @@ type procedure Draw(ADrawer: IChartDrawer); override; function IsEmpty: Boolean; override; published + property AutoScaleColors: Boolean + read FAutoScaleColors write SetAutoScaleColors default false; property AxisIndexX; property AxisIndexY; property Brush: TBrush read FBrush write SetBrush; @@ -1808,8 +1815,19 @@ var lb, ub: Integer; c1, c2: TColor; v1, v2: Double; + f: Double; begin if (ColorSource = nil) or (ColorSource.Count = 0) then exit(clTAColor); + + if FAutoscaleColors then begin + // Transform data value to the values assigned to the colorsource + if FMinZ <> FMaxZ then begin + AValue := (AValue - FMinZ) / (FMaxZ - FMinZ); + AValue := AValue * (FColorExtentMax - FColorExtentMin) + FColorExtentMin; + end else + AValue := FColorExtentMin; + end; + ColorSource.FindBounds(AValue, SafeInfinity, lb, ub); if Interpolate and InRange(lb, 1, ColorSource.Count - 1) then begin with ColorSource[lb - 1]^ do begin @@ -1861,6 +1879,7 @@ var cellColor: TChartColor; scaled_stepX: Integer; scaled_stepY: Integer; + zmin, zmax: Double; begin if not (csDesigning in ComponentState) and IsEmpty then exit; @@ -1891,6 +1910,8 @@ begin scaled_stepX := IfThen(StepX > 1, Max(1, ADrawer.Scale(StepX)), 1); scaled_stepY := IfThen(StepY > 1, Max(1, ADrawer.Scale(StepY)), 1); + GetZRange(r, scaled_stepX, scaled_stepY); + try pt.Y := (r.Top div scaled_stepY - 1) * scaled_stepY + offset.Y mod scaled_stepY; while pt.Y <= r.Bottom do begin @@ -2015,11 +2036,46 @@ begin end; end; +procedure TCustomColorMapSeries.GetZRange(ARect: TRect; dx, dy: Integer); +var + gp: TDoublePoint; + ix, iy: Integer; + z: Double; +begin + if IsEmpty then begin + FMinZ := 0.0; + FMaxZ := 0.0; + exit; + end; + + FMinZ := 1E308; + FMaxZ := -FMinZ; + iy := ARect.Top; + while (iy <= ARect.Bottom) do begin + ix := ARect.Left; + while ix <= ARect.Right do begin + gp := ParentChart.ImageToGraph(Point(ix, iy)); + z := FunctionValue(gp.X, gp.Y); + FMinZ := Min(FMinZ, z); + FMaxZ := Max(FMaxZ, z); + inc(ix, dx); + end; + inc(iy, dy); + end; +end; + function TCustomColorMapSeries.IsEmpty: Boolean; begin Result := true; end; +procedure TCustomColorMapSeries.SetAutoscaleColors(AValue: Boolean); +begin + if FAutoscaleColors = AValue then exit; + FAutoscaleColors := AValue; + UpdateParentChart; +end; + procedure TCustomColorMapSeries.SetBrush(AValue: TBrush); begin if FBrush = AValue then exit; @@ -2028,13 +2084,19 @@ begin end; procedure TCustomColorMapSeries.SetColorSource(AValue: TCustomChartSource); +var + ex: TDoubleRect; begin if FColorSource = AValue then exit; if FColorSourceListener.IsListening then ColorSource.Broadcaster.Unsubscribe(FColorSourceListener); FColorSource := AValue; - if ColorSource <> nil then + if ColorSource <> nil then begin ColorSource.Broadcaster.Subscribe(FColorSourceListener); + ex := ColorSource.Extent; + FColorExtentMin := ex.a.x; + FColorExtentMax := ex.b.x; + end; UpdateParentChart; end; diff --git a/components/tachart/tagraph.pas b/components/tachart/tagraph.pas index 4aecdcc3ea..faebf016c6 100644 --- a/components/tachart/tagraph.pas +++ b/components/tachart/tagraph.pas @@ -1343,7 +1343,7 @@ begin SetBounds(FConnectorData); Draw(Drawer, FConnectorData.FDrawerBounds); EffectiveGUIConnector.Display(FConnectorData); - end; + end; if Assigned(OnAfterPaint) then OnAfterPaint(Self); end;