mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 10:39:09 +02:00
TAChart: Add new property AutoscaleColors to TCustomColorMapSeries
git-svn-id: trunk@56368 -
This commit is contained in:
parent
8f98861cb6
commit
098ed06162
@ -584,8 +584,8 @@ end;
|
|||||||
|
|
||||||
procedure TExpressionSeries.SetExpression(const AValue: String);
|
procedure TExpressionSeries.SetExpression(const AValue: String);
|
||||||
begin
|
begin
|
||||||
if FParser.Expression = AValue then
|
// if FParser.Expression = AValue then
|
||||||
exit;
|
// exit;
|
||||||
FExpression := AValue;
|
FExpression := AValue;
|
||||||
RequestParserUpdate;
|
RequestParserUpdate;
|
||||||
UpdateParentChart;
|
UpdateParentChart;
|
||||||
|
@ -357,6 +357,9 @@ type
|
|||||||
FStepX: TFuncSeriesStep;
|
FStepX: TFuncSeriesStep;
|
||||||
FStepY: TFuncSeriesStep;
|
FStepY: TFuncSeriesStep;
|
||||||
FUseImage: TUseImage;
|
FUseImage: TUseImage;
|
||||||
|
FAutoScaleColors: Boolean;
|
||||||
|
FColorExtentMin, FColorExtentMax: Double;
|
||||||
|
procedure SetAutoscaleColors(AValue: Boolean);
|
||||||
procedure SetBrush(AValue: TBrush);
|
procedure SetBrush(AValue: TBrush);
|
||||||
procedure SetColorSource(AValue: TCustomChartSource);
|
procedure SetColorSource(AValue: TCustomChartSource);
|
||||||
procedure SetInterpolate(AValue: Boolean);
|
procedure SetInterpolate(AValue: Boolean);
|
||||||
@ -364,7 +367,9 @@ type
|
|||||||
procedure SetStepY(AValue: TFuncSeriesStep);
|
procedure SetStepY(AValue: TFuncSeriesStep);
|
||||||
procedure SetUseImage(AValue: TUseImage);
|
procedure SetUseImage(AValue: TUseImage);
|
||||||
protected
|
protected
|
||||||
|
FMinZ, FMaxZ: Double;
|
||||||
procedure GetLegendItems(AItems: TChartLegendItems); override;
|
procedure GetLegendItems(AItems: TChartLegendItems); override;
|
||||||
|
procedure GetZRange(ARect: TRect; dx, dy: Integer);
|
||||||
|
|
||||||
public
|
public
|
||||||
procedure Assign(ASource: TPersistent); override;
|
procedure Assign(ASource: TPersistent); override;
|
||||||
@ -377,6 +382,8 @@ type
|
|||||||
procedure Draw(ADrawer: IChartDrawer); override;
|
procedure Draw(ADrawer: IChartDrawer); override;
|
||||||
function IsEmpty: Boolean; override;
|
function IsEmpty: Boolean; override;
|
||||||
published
|
published
|
||||||
|
property AutoScaleColors: Boolean
|
||||||
|
read FAutoScaleColors write SetAutoScaleColors default false;
|
||||||
property AxisIndexX;
|
property AxisIndexX;
|
||||||
property AxisIndexY;
|
property AxisIndexY;
|
||||||
property Brush: TBrush read FBrush write SetBrush;
|
property Brush: TBrush read FBrush write SetBrush;
|
||||||
@ -1808,8 +1815,19 @@ var
|
|||||||
lb, ub: Integer;
|
lb, ub: Integer;
|
||||||
c1, c2: TColor;
|
c1, c2: TColor;
|
||||||
v1, v2: Double;
|
v1, v2: Double;
|
||||||
|
f: Double;
|
||||||
begin
|
begin
|
||||||
if (ColorSource = nil) or (ColorSource.Count = 0) then exit(clTAColor);
|
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);
|
ColorSource.FindBounds(AValue, SafeInfinity, lb, ub);
|
||||||
if Interpolate and InRange(lb, 1, ColorSource.Count - 1) then begin
|
if Interpolate and InRange(lb, 1, ColorSource.Count - 1) then begin
|
||||||
with ColorSource[lb - 1]^ do begin
|
with ColorSource[lb - 1]^ do begin
|
||||||
@ -1861,6 +1879,7 @@ var
|
|||||||
cellColor: TChartColor;
|
cellColor: TChartColor;
|
||||||
scaled_stepX: Integer;
|
scaled_stepX: Integer;
|
||||||
scaled_stepY: Integer;
|
scaled_stepY: Integer;
|
||||||
|
zmin, zmax: Double;
|
||||||
begin
|
begin
|
||||||
if not (csDesigning in ComponentState) and IsEmpty then exit;
|
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_stepX := IfThen(StepX > 1, Max(1, ADrawer.Scale(StepX)), 1);
|
||||||
scaled_stepY := IfThen(StepY > 1, Max(1, ADrawer.Scale(StepY)), 1);
|
scaled_stepY := IfThen(StepY > 1, Max(1, ADrawer.Scale(StepY)), 1);
|
||||||
|
|
||||||
|
GetZRange(r, scaled_stepX, scaled_stepY);
|
||||||
|
|
||||||
try
|
try
|
||||||
pt.Y := (r.Top div scaled_stepY - 1) * scaled_stepY + offset.Y mod scaled_stepY;
|
pt.Y := (r.Top div scaled_stepY - 1) * scaled_stepY + offset.Y mod scaled_stepY;
|
||||||
while pt.Y <= r.Bottom do begin
|
while pt.Y <= r.Bottom do begin
|
||||||
@ -2015,11 +2036,46 @@ begin
|
|||||||
end;
|
end;
|
||||||
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;
|
function TCustomColorMapSeries.IsEmpty: Boolean;
|
||||||
begin
|
begin
|
||||||
Result := true;
|
Result := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomColorMapSeries.SetAutoscaleColors(AValue: Boolean);
|
||||||
|
begin
|
||||||
|
if FAutoscaleColors = AValue then exit;
|
||||||
|
FAutoscaleColors := AValue;
|
||||||
|
UpdateParentChart;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomColorMapSeries.SetBrush(AValue: TBrush);
|
procedure TCustomColorMapSeries.SetBrush(AValue: TBrush);
|
||||||
begin
|
begin
|
||||||
if FBrush = AValue then exit;
|
if FBrush = AValue then exit;
|
||||||
@ -2028,13 +2084,19 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomColorMapSeries.SetColorSource(AValue: TCustomChartSource);
|
procedure TCustomColorMapSeries.SetColorSource(AValue: TCustomChartSource);
|
||||||
|
var
|
||||||
|
ex: TDoubleRect;
|
||||||
begin
|
begin
|
||||||
if FColorSource = AValue then exit;
|
if FColorSource = AValue then exit;
|
||||||
if FColorSourceListener.IsListening then
|
if FColorSourceListener.IsListening then
|
||||||
ColorSource.Broadcaster.Unsubscribe(FColorSourceListener);
|
ColorSource.Broadcaster.Unsubscribe(FColorSourceListener);
|
||||||
FColorSource := AValue;
|
FColorSource := AValue;
|
||||||
if ColorSource <> nil then
|
if ColorSource <> nil then begin
|
||||||
ColorSource.Broadcaster.Subscribe(FColorSourceListener);
|
ColorSource.Broadcaster.Subscribe(FColorSourceListener);
|
||||||
|
ex := ColorSource.Extent;
|
||||||
|
FColorExtentMin := ex.a.x;
|
||||||
|
FColorExtentMax := ex.b.x;
|
||||||
|
end;
|
||||||
UpdateParentChart;
|
UpdateParentChart;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -1343,7 +1343,7 @@ begin
|
|||||||
SetBounds(FConnectorData);
|
SetBounds(FConnectorData);
|
||||||
Draw(Drawer, FConnectorData.FDrawerBounds);
|
Draw(Drawer, FConnectorData.FDrawerBounds);
|
||||||
EffectiveGUIConnector.Display(FConnectorData);
|
EffectiveGUIConnector.Display(FConnectorData);
|
||||||
end;
|
end;
|
||||||
if Assigned(OnAfterPaint) then
|
if Assigned(OnAfterPaint) then
|
||||||
OnAfterPaint(Self);
|
OnAfterPaint(Self);
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user