plotpanel: Add properties for linewidth control (issue #32648) and background color control.

git-svn-id: trunk@56326 -
This commit is contained in:
wp 2017-11-06 20:14:34 +00:00
parent cee38e2b1b
commit 8a2289c220
3 changed files with 162 additions and 18 deletions

View File

@ -72,12 +72,16 @@ Type
Published
Property Expression : String Read GetExpression Write SetExpression;
Property Identifiers : TFPExprIdentifierDefs Read GetIdentifiers Write SetIdentifiers;
Property Anchors;
Property Active;
Property Align;
Property Anchors;
Property BackgroundColor;
Property BorderSpacing;
Property Color;
Property PlotColor;
property PlotLinewidth;
Property XAxis;
Property YAxis;
Property Active;
Property PlotColor;
end;
implementation

View File

@ -54,6 +54,7 @@ Const
DefGridInterval = 1;
DefGridColor = clSilver;
DefPlotColor = clRed;
DefLineWidth = 1;
Type
TPlotFloat = Double;
@ -88,6 +89,7 @@ Type
private
FDrawZero: Boolean;
FGridColor: TColor;
FGridLinewidth: Integer;
FGridInterval: Integer;
FInterval: TPlotFloat;
FCaption: TPlotCaption;
@ -96,20 +98,27 @@ Type
FOrigin: TPlotFloat;
FPlotter : TCanvasPlotter;
FColor: TColor;
FLinewidth: Integer;
FTickColor: TColor;
FTickFont: TFont;
FTickMode: TTickMode;
FTicks: Integer;
FTickSize: integer;
FTickLinewidth: Integer;
procedure SetAxisColor(const AValue: TColor);
procedure SetLinewidth(const AValue: Integer);
procedure SetDrawZero(const AValue: Boolean);
procedure SetInterval(const AValue: TPlotFloat);
procedure SetCaption(const AValue: TPlotCaption);
procedure SetGridColor(const AValue: TColor);
procedure SetGridInterval(const AValue: Integer);
procedure SetGridLinewidth(const AValue: Integer);
procedure SetLegendInterval(const AValue: Integer);
procedure SetLegendFormat(const AValue: String);
procedure SetOrigin(const AValue: TPlotFloat);
procedure SetTickColor(const AValue: TColor);
procedure SetTickFont(const AValue: TFont);
procedure SetTickLinewidth(const AValue: Integer);
procedure SetTickMode(const AValue: TTickMode);
procedure SetTicks(const AValue: Integer);
procedure SetTickSize(const AValue: integer);
@ -126,6 +135,8 @@ Type
Constructor Create;virtual;
Destructor Destroy; override;
Published
// Linewidth of axis line
Property LineWidth: Integer read FLineWidth write SetLineWidth default DefLineWidth;
// Graph color
Property Color : TColor Read FColor Write SetAxisColor default defAxisColor;
// Color of ticks on axis
@ -134,6 +145,8 @@ Type
Property Ticks : Integer Read FTicks Write SetTicks;
// Length of ticks on axis
Property TickSize : integer Read FTickSize Write SetTickSize;
// Linewidth of ticks on axis
Property TickLinewidth: Integer read FTickLinewidth write SetTickLinewidth default DefLinewidth;
// Ticks is number of ticks or distance (in pixels) between ticks ?
Property TickMode : TTickMode Read FTickMode Write SetTickMode;
// Font for tick legend
@ -151,9 +164,11 @@ Type
// Format for legend (formatfloat);
Property LegendFormat : String Read FLegendFormat write SetLegendFormat;
// Interval (in ticks) of grid. 0 means no grid.
Property GridInterval : Integer Read FGridInterval Write FGridInterval default DefGridInterval;
Property GridInterval : Integer Read FGridInterval Write SetGridInterval default DefGridInterval;
// Grid color.
Property GridColor : TColor Read FGridColor Write FGridColor default DefGridColor;
Property GridColor : TColor Read FGridColor Write SetGridColor default DefGridColor;
// Grid linewidth
Property GridLinewidth: Integer Read FGridLinewidth Write SetGridLinewidth default DefLineWidth;
end;
{ TPlotXAxis }
@ -208,7 +223,9 @@ Type
FBackGroundColor: TColor;
FBoundsRect: TRect;
FCaption: TPlotCaption;
FColor: TColor;
FPlotColor: TColor;
FPlotLineWidth: Integer;
FXaxis: TPlotXAxis;
FYaxis: TPlotYAxis;
FCanvas: TCanvas;
@ -221,7 +238,9 @@ Type
procedure SetBoundsRect(const AValue: TRect);
procedure SetCanvas(const AValue: TCanvas);
procedure SetCaption(const AValue: TPlotCaption);
procedure SetColor(const AValue: TColor);
procedure SetPlotColor(const AValue: TColor);
procedure SetPlotLineWidth(const AValue: Integer);
procedure SetXAxis(const AValue: TPlotXAxis);
procedure SetYAxis(const AValue: TPlotYAxis);
Protected
@ -243,7 +262,9 @@ Type
Property XAxis : TPlotXAxis Read FXaxis Write SetXAxis;
Property YAxis : TPlotYAxis Read FYaxis Write SetYAxis;
Property BackgroundColor : TColor Read FBackGroundColor Write SetBackGroundColor;
Property Color: TColor Read FColor write SetColor;
Property PlotColor : TColor Read FPlotColor Write SetPlotColor;
Property PlotLinewidth: Integer read FPlotLineWidth Write SetPlotLineWidth;
Property Active : Boolean Read FActive Write SetActive;
Property Caption : TPlotCaption Read FCaption Write SetCaption;
end;
@ -277,13 +298,18 @@ Type
private
FPlotter: TCanvasPlotter;
function GetActive: Boolean;
function GetBackgroundColor: TColor;
function GetCaption: TPlotCaption;
function GetColor: TColor;
function GetPlotColor: TColor;
function GetPlotLineWidth: Integer;
function GetXaxis: TPlotXAxis;
function GetYaxis: TPlotYAxis;
procedure SetActive(const AValue: Boolean);
procedure SetBackgroundColor(const AValue: TColor);
procedure SetCaption(const AValue: TPlotCaption);
procedure SetPlotColor(const AValue: TColor);
procedure SetPlotLineWidth(const AValue: Integer);
procedure SetXAxis(const AValue: TPlotXAxis);
procedure SetYAxis(const AValue: TPlotYAxis);
Protected
@ -294,13 +320,15 @@ Type
Public
Constructor Create(AOwner : TComponent); override;
Destructor Destroy; override;
Property Anchors;
Property Align;
Property Active : Boolean Read GetActive Write SetActive;
Property BackgroundColor: TColor read GetBackgroundColor write SetBackgroundColor default clDefault;
Property Caption : TPlotCaption Read GetCaption Write SetCaption;
Property Color: TColor read GetColor write SetColor default clDefault;
Property PlotColor : TColor Read GetPlotColor Write SetPlotColor;
Property PlotLineWidth: Integer read GetPlotLinewidth Write SetPlotLinewidth default DefLinewidth;
Property XAxis : TPlotXAxis Read GetXaxis Write SetXAxis;
Property YAxis : TPlotYAxis Read GetYaxis Write SetYAxis;
Property Active : Boolean Read GetActive Write SetActive;
Property PlotColor : TColor Read GetPlotColor Write SetPlotColor;
Property Caption : TPlotCaption Read GetCaption Write SetCaption;
end;
{ TPlotFunctionPanel }
@ -313,12 +341,16 @@ Type
Function CreatePlotter : TCanvasPlotter; override;
Published
Property OnCalcPlot : TOnCalcPlotEvent Read GetOnCalcPlot Write SetOnCalcPlot;
Property Anchors;
Property Align;
Property Anchors;
Property Active;
Property BackgroundColor;
Property BorderSpacing;
Property Color;
Property PlotColor;
property PlotLinewidth;
Property XAxis;
Property YAxis;
Property Active;
Property PlotColor;
end;
EPlotPanel = Class(Exception);
@ -351,16 +383,31 @@ begin
Result:=FPlotter.Active;
end;
function TCustomPlotFunctionPanel.GetBackgroundColor: TColor;
begin
Result := FPlotter.BackgroundColor;
end;
function TCustomPlotFunctionPanel.GetCaption: TPlotCaption;
begin
Result:=FPlotter.Caption;
end;
function TCustomPlotFunctionPanel.GetColor: TColor;
begin
Result := FPlotter.Color;
end;
function TCustomPlotFunctionPanel.GetPlotColor: TColor;
begin
Result:=FPlotter.PlotColor;
end;
function TCustomPlotFunctionPanel.GetPlotLinewidth: Integer;
begin
Result := FPlotter.PlotLinewidth;
end;
function TCustomPlotFunctionPanel.GetXaxis: TPlotXAxis;
begin
Result:=FPlotter.XAxis;
@ -376,6 +423,11 @@ begin
FPlotter.Active:=AValue;
end;
procedure TCustomPlotFunctionPanel.SetBackgroundColor(const AValue: TColor);
begin
FPlotter.BackgroundColor := AValue;
end;
procedure TCustomPlotFunctionPanel.SetCaption(const AValue: TPlotCaption);
begin
FPlotter.Caption.Assign(AValue);
@ -386,6 +438,11 @@ begin
FPlotter.PlotColor:=AValue;
end;
procedure TCustomPlotFunctionPanel.SetPlotLineWidth(const AValue: Integer);
begin
FPlotter.PlotLinewidth := AValue;
end;
procedure TCustomPlotFunctionPanel.SetYAxis(const AValue: TPlotYAxis);
begin
FPlotter.Yaxis.Assign(AValue);
@ -402,7 +459,7 @@ procedure TCustomPlotFunctionPanel.SetColor(Value: TColor);
begin
inherited SetColor(Value);
If Assigned(FPlotter) then
FPLotter.BackgroundColor:=Value;
FPLotter.Color:=Value;
end;
@ -434,6 +491,12 @@ begin
Changed;
end;
procedure TPlotAxis.SetLinewidth(const AValue: Integer);
begin
if FLinewidth = AValue then exit;
FLinewidth := AValue;
Changed;
end;
procedure TPlotAxis.SetDrawZero(const AValue: Boolean);
begin
@ -458,6 +521,27 @@ begin
Changed;
end;
procedure TPlotAxis.SetGridColor(const AValue: TColor);
begin
if FGridColor=AValue then exit;
FGridColor := AValue;
Changed;
end;
procedure TPlotAxis.SetGridInterval(const AValue: Integer);
begin
if FGridInterval = AValue then exit;
FGridInterval := AValue;
Changed;
end;
procedure TPlotAxis.SetGridLinewidth(const AValue: Integer);
begin
if FGridLinewidth = AValue then exit;
FGridLinewidth := AValue;
Changed;
end;
procedure TPlotAxis.SetLegendInterval(const AValue: Integer);
begin
if FLegendInterval=AValue then exit;
@ -495,6 +579,13 @@ begin
Changed;
end;
procedure TPlotAxis.SetTickLinewidth(const AValue: Integer);
begin
if FTickLinewidth = AValue then exit;
FTickLinewidth := AValue;
Changed;
end;
procedure TPlotAxis.SetTickMode(const AValue: TTickMode);
begin
if FTickMode=AValue then exit;
@ -558,12 +649,15 @@ begin
FCaption.FOnChange:=@DoCaptionChange;
FCaption.Font.OnChange:= @DoCaptionChange;
FColor:=DefAxisColor;
FLineWidth:= DefLineWidth;
FTickFont:=TFont.Create;
FTickFont.OnChange := @DoCaptionChange;
FTickLinewidth := DefLinewidth;
FLegendInterval:=DefLegendInterval;
FInterval:=DefInterval;
FTickColor:=DefTickColor;
FGridColor:=DefGridColor;
FGridLinewidth:=DefLineWidth;
FGridInterval:=DefGridInterval;
end;
@ -696,6 +790,13 @@ begin
Changed;
end;
procedure TCanvasPlotter.SetColor(const AValue: TColor);
begin
if FColor = AValue then exit;
FColor := AValue;
Changed;
end;
procedure TCanvasPlotter.SetPlotColor(const AValue: TColor);
begin
If (FPlotColor=AValue) then Exit;
@ -703,6 +804,13 @@ begin
Changed;
end;
procedure TCanvasPlotter.SetPlotLineWidth(const AValue: Integer);
begin
if (FPlotLinewidth=AValue) then exit;
FPlotLineWidth := AValue;
Changed;
end;
procedure TCanvasPlotter.SetXAxis(const AValue: TPlotXAxis);
begin
if FXaxis=AValue then exit;
@ -737,7 +845,10 @@ begin
FYAxis:=TPlotYAxis.Create;
FYAxis.FPlotter:=Self;
FPlotColor:=DefPlotColor;
FPlotLinewidth:=DefLinewidth;
FCaption:=TPlotCaption.Create;
FBackgroundColor := clDefault;
FColor := clDefault;
end;
destructor TCanvasPlotter.Destroy;
@ -782,11 +893,20 @@ end;
procedure TCanvasPlotter.DrawBackground(ACanvas: TCanvas);
begin
// self.ClientRect
ACanvas.Brush.Color:=BackgroundColor;
// Color paints the entire diagram background
ACanvas.Brush.Color:=Color;
ACanvas.Brush.Style:=bsSolid;
ACanvas.FillRect(BoundsRect);
// ACanvas.FillRect(0,0,ACanvas.Width,ACanvas.Height);
// Background color paints the background spanned by the axes
ACanvas.Brush.Color := BackgroundColor;
ACanvas.FillRect(
FXAxis.LeftMargin,
FYAxis.TopMargin,
BoundsRect.Width-FXAxis.RightMargin,
BoundsRect.Height-FYAxis.BottomMargin
);
DrawHAxis(ACanvas,FXAxis,FYAxis);
DrawVAxis(ACanvas,FYAxis,FXAxis);
end;
@ -808,7 +928,9 @@ begin
EY:=FBoundsRect.Top+AVAxis.Margin2;
// Writeln(Format('(%d,%d) -> (%d,%d) (%d,%d) (%d,%d)',[width,height,ox,oy,ox,ey,ex,oy]));
// X axis
ACanvas.Brush.Style := bsClear;
ACanvas.Pen.Color:=AHAxis.Color;
ACanvas.Pen.Width:=AHAxis.LineWidth;
ACanvas.Line(OX,OY,EX,OY);
Canvas.Font:=AHAxis.TickFont;
TickDelta:=AHAxis.TickDelta;
@ -821,11 +943,13 @@ begin
L:='#0.#';
Repeat
ACanvas.Pen.Color:=AHAxis.TickColor;
ACanvas.Pen.Width := AHAxis.TickLinewidth;
X:=OX+Round(I*TickDelta);
ACanvas.Line(X,OY,X,TE);
If (AHAxis.GridInterval<>0) and ((I mod AHAxis.GridInterval)=0) then
begin
ACanvas.Pen.Color:=AHAxis.GridColor;
ACanvas.Pen.Width := AHAxis.GridLinewidth;
ACanvas.Line(X,OY,X,EY);
end;
If (AHAxis.LegendInterval<>0) and ((I mod AHAxis.LegendInterval)=0) then
@ -841,6 +965,7 @@ begin
begin
X:=OX+Round((EX-OX)*Abs(AHAxis.Origin)/AHAxis.Interval);
ACanvas.Pen.Color:=AHAxis.TickColor;
ACanvas.Pen.Width := AHAxis.TickLinewidth;
ACanvas.Line(X,OY,X,EY);
end;
Canvas.Font:=AHAxis.Caption.Font;
@ -877,7 +1002,9 @@ begin
EX:=FBoundsRect.Right-AHAxis.Margin2;
OY:=FBoundsRect.Bottom-AVAxis.Margin1;
EY:=FBoundsRect.Top+AVAxis.Margin2;
ACanvas.Brush.Style := bsClear;
ACanvas.Pen.Color:=AVAxis.Color;
ACanvas.Pen.Width:=AVAxis.Linewidth;
ACanvas.Line(OX,OY,OX,EY);
TickDelta:=AVAxis.TickDelta;
VD:=AVAxis.ValueDelta;
@ -892,10 +1019,12 @@ begin
Repeat
Y:=OY-Round(I*TickDelta);
ACanvas.Pen.Color:=AVAxis.TickColor;
ACanvas.Pen.Width := AVAxis.TickLinewidth;
ACanvas.Line(TE,Y,OX,Y);
If (Y<>OY) and (AVAxis.GridInterval<>0) and ((I mod AVAxis.GridInterval)=0) then
begin
ACanvas.Pen.Color:=AVAxis.GridColor;
ACanvas.Pen.Width := AVAxis.GridLinewidth;
ACanvas.Line(OX,Y,EX,Y);
end;
If (AVAxis.LegendInterval<>0) and ((I mod AVAxis.LegendInterval)=0) then
@ -911,6 +1040,7 @@ begin
begin
Y:=OY-Round((OY-EY)*Abs(AVAxis.Origin)/AVAxis.Interval);
ACanvas.Pen.Color:=AVAxis.TickColor;
ACanvas.Pen.Width := AVAxis.TickLinewidth;
ACanvas.Line(OX,Y,EX,Y);
end;
L:=AVAxis.Caption.Title;
@ -1051,6 +1181,7 @@ begin
// Start value
X:=FXAxis.Origin;
ACanvas.Pen.Color:=PlotColor;
ACanvas.Pen.Width := FPlotLineWidth;
PLX:=POX;
PLY:=POY;
For PX:=0 to PXW do
@ -1108,13 +1239,15 @@ begin
If AOwner is TCOntrol then
begin
FControl:=AOwner as TControl;
FBackGroundColor:=FControl.Color;
if FColor = clDefault then
FColor := FControl.Color;
if FBackgroundColor = clDefault then
FBackGroundColor:=FControl.Color;
end;
end;
{ TEventControlPlotter }
procedure TEventControlPlotter.SetOnCalcPlot(const AValue: TOnCalcPlotEvent);
begin
FOnCalcPlot:=AValue;

View File

@ -18,16 +18,22 @@ Active : If set to false, only the grid is drawn.
PlotColor : Color of the plotted line
BackgroundColor : Background color of the area spanned by the axes
Color : Background color of the entire control.
Caption : Caption of the graph
XAxis, YAxis: These control the appearance of the X and Y axis.
They have both the following properties:
Color : Axis color
Linewidth : Width of the axis line
TickColor : Color of the tick marks on the axis.
Ticks : Number of tick marks or distance between tick marks on the
axis.
TickSize : Length of the tick mark.
TickLinewidth : Linewidth for the tick marks
TickMode : Ticks is number of ticks or distance (in pixels) between ticks.
TickFont : Font for the tick labels
Caption : Caption of the axis.
@ -42,4 +48,5 @@ XAxis, YAxis: These control the appearance of the X and Y axis.
This should be a valid float formatting specifier (used in FormatFloat);
GridInterval : The number of ticks at which a grid line must be drawn.
GridColor : Color of the grid line.
GridLinewidth : Width for the grid line