mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 02:19:32 +02:00
TAChart: Introduce intermediate class TCustomcolorMapSeries without OnCalculate event.
git-svn-id: trunk@56355 -
This commit is contained in:
parent
978fbdcdd1
commit
d37550ded9
@ -345,7 +345,7 @@ type
|
|||||||
TFuncCalculate3DEvent =
|
TFuncCalculate3DEvent =
|
||||||
procedure (const AX, AY: Double; out AZ: Double) of object;
|
procedure (const AX, AY: Double; out AZ: Double) of object;
|
||||||
|
|
||||||
TColorMapSeries = class(TBasicFuncSeries)
|
TCustomColorMapSeries = class(TBasicFuncSeries)
|
||||||
public
|
public
|
||||||
type
|
type
|
||||||
TUseImage = (cmuiAuto, cmuiAlways, cmuiNever);
|
TUseImage = (cmuiAuto, cmuiAlways, cmuiNever);
|
||||||
@ -354,14 +354,12 @@ type
|
|||||||
FColorSource: TCustomChartSource;
|
FColorSource: TCustomChartSource;
|
||||||
FColorSourceListener: TListener;
|
FColorSourceListener: TListener;
|
||||||
FInterpolate: Boolean;
|
FInterpolate: Boolean;
|
||||||
FOnCalculate: TFuncCalculate3DEvent;
|
|
||||||
FStepX: TFuncSeriesStep;
|
FStepX: TFuncSeriesStep;
|
||||||
FStepY: TFuncSeriesStep;
|
FStepY: TFuncSeriesStep;
|
||||||
FUseImage: TUseImage;
|
FUseImage: TUseImage;
|
||||||
procedure SetBrush(AValue: TBrush);
|
procedure SetBrush(AValue: TBrush);
|
||||||
procedure SetColorSource(AValue: TCustomChartSource);
|
procedure SetColorSource(AValue: TCustomChartSource);
|
||||||
procedure SetInterpolate(AValue: Boolean);
|
procedure SetInterpolate(AValue: Boolean);
|
||||||
procedure SetOnCalculate(AValue: TFuncCalculate3DEvent);
|
|
||||||
procedure SetStepX(AValue: TFuncSeriesStep);
|
procedure SetStepX(AValue: TFuncSeriesStep);
|
||||||
procedure SetStepY(AValue: TFuncSeriesStep);
|
procedure SetStepY(AValue: TFuncSeriesStep);
|
||||||
procedure SetUseImage(AValue: TUseImage);
|
procedure SetUseImage(AValue: TUseImage);
|
||||||
@ -375,6 +373,7 @@ type
|
|||||||
|
|
||||||
public
|
public
|
||||||
function ColorByValue(AValue: Double): TColor;
|
function ColorByValue(AValue: Double): TColor;
|
||||||
|
function FunctionValue(AX, AY: Double): Double; virtual;
|
||||||
procedure Draw(ADrawer: IChartDrawer); override;
|
procedure Draw(ADrawer: IChartDrawer); override;
|
||||||
function IsEmpty: Boolean; override;
|
function IsEmpty: Boolean; override;
|
||||||
published
|
published
|
||||||
@ -385,8 +384,6 @@ type
|
|||||||
read FColorSource write SetColorSource;
|
read FColorSource write SetColorSource;
|
||||||
property Interpolate: Boolean
|
property Interpolate: Boolean
|
||||||
read FInterpolate write SetInterpolate default false;
|
read FInterpolate write SetInterpolate default false;
|
||||||
property OnCalculate: TFuncCalculate3DEvent
|
|
||||||
read FOnCalculate write SetOnCalculate;
|
|
||||||
property StepX: TFuncSeriesStep
|
property StepX: TFuncSeriesStep
|
||||||
read FStepX write SetStepX default DEF_COLORMAP_STEP;
|
read FStepX write SetStepX default DEF_COLORMAP_STEP;
|
||||||
property StepY: TFuncSeriesStep
|
property StepY: TFuncSeriesStep
|
||||||
@ -395,6 +392,20 @@ type
|
|||||||
read FUseImage write SetUseImage default cmuiAuto;
|
read FUseImage write SetUseImage default cmuiAuto;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TColorMapSeries = class(TCustomColorMapSeries)
|
||||||
|
private
|
||||||
|
FOnCalculate: TFuncCalculate3DEvent;
|
||||||
|
procedure SetOnCalculate(AValue: TFuncCalculate3DEvent);
|
||||||
|
public
|
||||||
|
procedure Assign(ASource: TPersistent); override;
|
||||||
|
function FunctionValue(AX, AY: Double): Double; override;
|
||||||
|
function IsEmpty: Boolean; override;
|
||||||
|
published
|
||||||
|
property OnCalculate: TFuncCalculate3DEvent
|
||||||
|
read FOnCalculate write SetOnCalculate;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
// Builds an equation string based on the parameters and the type of equation.
|
// Builds an equation string based on the parameters and the type of equation.
|
||||||
// AXText and AYText are placeholders for the x and y variables, respectively.
|
// AXText and AYText are placeholders for the x and y variables, respectively.
|
||||||
// Parameters are formatted by passing ANumFormat to the "Format" function.
|
// Parameters are formatted by passing ANumFormat to the "Format" function.
|
||||||
@ -1776,23 +1787,23 @@ begin
|
|||||||
ANewY := AY;
|
ANewY := AY;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TColorMapSeries }
|
|
||||||
|
|
||||||
procedure TColorMapSeries.Assign(ASource: TPersistent);
|
{ TCustomColorMapSeries }
|
||||||
|
|
||||||
|
procedure TCustomColorMapSeries.Assign(ASource: TPersistent);
|
||||||
begin
|
begin
|
||||||
if ASource is TColorMapSeries then
|
if ASource is TCustomColorMapSeries then
|
||||||
with TColorMapSeries(ASource) do begin
|
with TCustomColorMapSeries(ASource) do begin
|
||||||
Self.Brush := FBrush;
|
Self.Brush := FBrush;
|
||||||
Self.ColorSource := FColorSource;
|
Self.ColorSource := FColorSource;
|
||||||
Self.FInterpolate := FInterpolate;
|
Self.FInterpolate := FInterpolate;
|
||||||
Self.FOnCalculate := FOnCalculate;
|
|
||||||
Self.FStepX := FStepX;
|
Self.FStepX := FStepX;
|
||||||
Self.FStepY := FStepY;
|
Self.FStepY := FStepY;
|
||||||
end;
|
end;
|
||||||
inherited Assign(ASource);
|
inherited Assign(ASource);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TColorMapSeries.ColorByValue(AValue: Double): TColor;
|
function TCustomColorMapSeries.ColorByValue(AValue: Double): TColor;
|
||||||
var
|
var
|
||||||
lb, ub: Integer;
|
lb, ub: Integer;
|
||||||
c1, c2: TColor;
|
c1, c2: TColor;
|
||||||
@ -1818,7 +1829,7 @@ begin
|
|||||||
Result := ColorSource[EnsureRange(lb, 0, ColorSource.Count - 1)]^.Color;
|
Result := ColorSource[EnsureRange(lb, 0, ColorSource.Count - 1)]^.Color;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TColorMapSeries.Create(AOwner: TComponent);
|
constructor TCustomColorMapSeries.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
FColorSourceListener := TListener.Create(@FColorSource, @StyleChanged);
|
FColorSourceListener := TListener.Create(@FColorSource, @StyleChanged);
|
||||||
@ -1828,14 +1839,14 @@ begin
|
|||||||
FStepY := DEF_COLORMAP_STEP;
|
FStepY := DEF_COLORMAP_STEP;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TColorMapSeries.Destroy;
|
destructor TCustomColorMapSeries.Destroy;
|
||||||
begin
|
begin
|
||||||
FreeAndNil(FColorSourceListener);
|
FreeAndNil(FColorSourceListener);
|
||||||
FreeAndNil(FBrush);
|
FreeAndNil(FBrush);
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TColorMapSeries.Draw(ADrawer: IChartDrawer);
|
procedure TCustomColorMapSeries.Draw(ADrawer: IChartDrawer);
|
||||||
var
|
var
|
||||||
ext: TDoubleRect;
|
ext: TDoubleRect;
|
||||||
bounds: TDoubleRect;
|
bounds: TDoubleRect;
|
||||||
@ -1897,7 +1908,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
gp := GraphToAxis(ParentChart.ImageToGraph((pt + next) div 2));
|
gp := GraphToAxis(ParentChart.ImageToGraph((pt + next) div 2));
|
||||||
if not (csDesigning in ComponentState) then
|
if not (csDesigning in ComponentState) then
|
||||||
OnCalculate(gp.X, gp.Y, v);
|
v := FunctionValue(gp.X, gp.Y);
|
||||||
cell := Rect(
|
cell := Rect(
|
||||||
Max(pt.X, r.Left), Max(pt.Y, r.Top),
|
Max(pt.X, r.Left), Max(pt.Y, r.Top),
|
||||||
Min(next.X, r.Right) + 1, Min(next.Y, r.Bottom) + 1);
|
Min(next.X, r.Right) + 1, Min(next.Y, r.Bottom) + 1);
|
||||||
@ -1926,7 +1937,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TColorMapSeries.GetLegendItems(AItems: TChartLegendItems);
|
function TCustomColorMapSeries.FunctionValue(AX, AY: Double): Double;
|
||||||
|
begin
|
||||||
|
Result := 0.0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomColorMapSeries.GetLegendItems(AItems: TChartLegendItems);
|
||||||
|
|
||||||
function PrepareFormats: TStrings;
|
function PrepareFormats: TStrings;
|
||||||
const
|
const
|
||||||
@ -1999,19 +2015,19 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TColorMapSeries.IsEmpty: Boolean;
|
function TCustomColorMapSeries.IsEmpty: Boolean;
|
||||||
begin
|
begin
|
||||||
Result := not Assigned(OnCalculate);
|
Result := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TColorMapSeries.SetBrush(AValue: TBrush);
|
procedure TCustomColorMapSeries.SetBrush(AValue: TBrush);
|
||||||
begin
|
begin
|
||||||
if FBrush = AValue then exit;
|
if FBrush = AValue then exit;
|
||||||
FBrush := AValue;
|
FBrush := AValue;
|
||||||
UpdateParentChart;
|
UpdateParentChart;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TColorMapSeries.SetColorSource(AValue: TCustomChartSource);
|
procedure TCustomColorMapSeries.SetColorSource(AValue: TCustomChartSource);
|
||||||
begin
|
begin
|
||||||
if FColorSource = AValue then exit;
|
if FColorSource = AValue then exit;
|
||||||
if FColorSourceListener.IsListening then
|
if FColorSourceListener.IsListening then
|
||||||
@ -2022,13 +2038,56 @@ begin
|
|||||||
UpdateParentChart;
|
UpdateParentChart;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TColorMapSeries.SetInterpolate(AValue: Boolean);
|
procedure TCustomColorMapSeries.SetInterpolate(AValue: Boolean);
|
||||||
begin
|
begin
|
||||||
if FInterpolate = AValue then exit;
|
if FInterpolate = AValue then exit;
|
||||||
FInterpolate := AValue;
|
FInterpolate := AValue;
|
||||||
UpdateParentChart;
|
UpdateParentChart;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomColorMapSeries.SetStepX(AValue: TFuncSeriesStep);
|
||||||
|
begin
|
||||||
|
if FStepX = AValue then exit;
|
||||||
|
FStepX := AValue;
|
||||||
|
UpdateParentChart;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomColorMapSeries.SetStepY(AValue: TFuncSeriesStep);
|
||||||
|
begin
|
||||||
|
if FStepY = AValue then exit;
|
||||||
|
FStepY := AValue;
|
||||||
|
UpdateParentChart;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomColorMapSeries.SetUseImage(AValue: TUseImage);
|
||||||
|
begin
|
||||||
|
if FUseImage = AValue then exit;
|
||||||
|
FUseImage := AValue;
|
||||||
|
UpdateParentChart;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ TColorMapSeries }
|
||||||
|
|
||||||
|
procedure TColorMapSeries.Assign(ASource: TPersistent);
|
||||||
|
begin
|
||||||
|
if ASource is TColorMapSeries then
|
||||||
|
with TCustomColorMapSeries(ASource) do begin
|
||||||
|
Self.FOnCalculate := FOnCalculate;
|
||||||
|
end;
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TColorMapSeries.FunctionValue(AX, AY: Double): Double;
|
||||||
|
begin
|
||||||
|
OnCalculate(AX, AY, Result);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TColorMapSeries.IsEmpty: Boolean;
|
||||||
|
begin
|
||||||
|
Result := not Assigned(OnCalculate);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TColorMapSeries.SetOnCalculate(AValue: TFuncCalculate3DEvent);
|
procedure TColorMapSeries.SetOnCalculate(AValue: TFuncCalculate3DEvent);
|
||||||
begin
|
begin
|
||||||
if TMethod(FOnCalculate) = TMethod(AValue) then exit;
|
if TMethod(FOnCalculate) = TMethod(AValue) then exit;
|
||||||
@ -2036,26 +2095,6 @@ begin
|
|||||||
UpdateParentChart;
|
UpdateParentChart;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TColorMapSeries.SetStepX(AValue: TFuncSeriesStep);
|
|
||||||
begin
|
|
||||||
if FStepX = AValue then exit;
|
|
||||||
FStepX := AValue;
|
|
||||||
UpdateParentChart;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TColorMapSeries.SetStepY(AValue: TFuncSeriesStep);
|
|
||||||
begin
|
|
||||||
if FStepY = AValue then exit;
|
|
||||||
FStepY := AValue;
|
|
||||||
UpdateParentChart;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TColorMapSeries.SetUseImage(AValue: TUseImage);
|
|
||||||
begin
|
|
||||||
if FUseImage = AValue then exit;
|
|
||||||
FUseImage := AValue;
|
|
||||||
UpdateParentChart;
|
|
||||||
end;
|
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
RegisterSeriesClass(TFuncSeries, @rsFunctionSeries);
|
RegisterSeriesClass(TFuncSeries, @rsFunctionSeries);
|
||||||
|
Loading…
Reference in New Issue
Block a user