TAChart: Extract TAMultiSeries unit.

git-svn-id: trunk@27114 -
This commit is contained in:
ask 2010-08-17 07:47:09 +00:00
parent ed2ad62dbf
commit dc77b7c0f3
6 changed files with 158 additions and 116 deletions

1
.gitattributes vendored
View File

@ -2216,6 +2216,7 @@ components/tachart/tadrawutils.pas svneol=native#text/pascal
components/tachart/tagraph.lrs svneol=native#text/pascal
components/tachart/tagraph.pas svneol=native#text/plain
components/tachart/talegend.pas svneol=native#text/plain
components/tachart/tamultiseries.pas svneol=native#text/pascal
components/tachart/taseries.pas svneol=native#text/plain
components/tachart/taserieseditor.pas svneol=native#text/plain
components/tachart/tasources.pas svneol=native#text/pascal

View File

@ -6,7 +6,7 @@ interface
uses
Classes, ComCtrls, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
TAGraph, TASeries, TASources;
TAGraph, TAMultiSeries, TASeries, TASources;
type

View File

@ -25,7 +25,7 @@
for details about the copyright.
"/>
<Version Major="1"/>
<Files Count="13">
<Files Count="14">
<Item1>
<Filename Value="tachartaxis.pas"/>
<UnitName Value="TAChartAxis"/>
@ -84,6 +84,10 @@
<Filename Value="tadrawutils.pas"/>
<UnitName Value="TADrawUtils"/>
</Item13>
<Item14>
<Filename Value="tamultiseries.pas"/>
<UnitName Value="TAMultiSeries"/>
</Item14>
</Files>
<LazDoc Paths="$(LazarusDir)\components\tachart\fpdoc\"/>
<Type Value="RunAndDesignTime"/>

View File

@ -9,7 +9,7 @@ interface
uses
TAChartAxis, TAChartUtils, TACustomSeries, TADbSource, TAGraph, TASeries,
TASeriesEditor, TASources, TASubcomponentsEditor, TATools,
TATransformations, TATypes, TADrawUtils, LazarusPackageIntf;
TATransformations, TATypes, TADrawUtils, TAMultiSeries, LazarusPackageIntf;
implementation

View File

@ -0,0 +1,147 @@
{
*****************************************************************************
* *
* See the file COPYING.modifiedLGPL.txt, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
Authors: Alexander Klenin
}
unit TAMultiSeries;
{$mode objfpc}{$H+}
interface
uses
Classes, Graphics,
TAChartUtils, TACustomSeries, TALegend;
type
TBubbleRadiusTransform = (brtNone, brtX, brtY);
{ TBubbleSeries }
TBubbleSeries = class(TBasicPointSeries)
private
FBubbleBrush: TBrush;
FBubblePen: TPen;
procedure SetBubbleBrush(const AValue: TBrush);
procedure SetBubblePen(AValue: TPen);
protected
procedure GetLegendItems(AItems: TChartLegendItems); override;
function GetSeriesColor: TColor; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Draw(ACanvas: TCanvas); override;
function Extent: TDoubleRect; override;
published
property AxisIndexX;
property AxisIndexY;
property BubbleBrush: TBrush read FBubbleBrush write SetBubbleBrush;
property BubblePen: TPen read FBubblePen write SetBubblePen;
property Source;
end;
implementation
uses
Math, SysUtils, TAGraph;
{ TBubbleSeries }
constructor TBubbleSeries.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FBubblePen := TPen.Create;
FBubblePen.OnChange := @StyleChanged;
FBubbleBrush := TBrush.Create;
FBubbleBrush.OnChange := @StyleChanged;
end;
destructor TBubbleSeries.Destroy;
begin
FreeAndNil(FBubbleBrush);
FreeAndNil(FBubblePen);
inherited Destroy;
end;
procedure TBubbleSeries.Draw(ACanvas: TCanvas);
var
i: Integer;
pt, d: TPoint;
r: Double;
begin
if Source.YCount < 2 then exit;
r := 0;
for i := 0 to Count - 1 do
r := Max(Source[i]^.YList[0], r);
with ParentChart.CurrentExtent do
PrepareGraphPoints(DoubleRect(a.X - r, a.Y - r, b.X + r, b.Y + r), true);
ACanvas.Pen.Assign(BubblePen);
ACanvas.Brush.Assign(BubbleBrush);
for i := 0 to High(FGraphPoints) do begin
pt := ParentChart.GraphToImage(FGraphPoints[i]);
r := Source[i + FLoBound]^.YList[0];
d.X := ParentChart.XGraphToImage(r) - ParentChart.XGraphToImage(0);
d.Y := ParentChart.YGraphToImage(r) - ParentChart.YGraphToImage(0);
ACanvas.EllipseC(pt.X, pt.Y, d.X, d.Y);
end;
DrawLabels(ACanvas);
end;
function TBubbleSeries.Extent: TDoubleRect;
var
i: Integer;
r: Double;
begin
Result := EmptyExtent;
if Source.YCount < 2 then exit;
for i := 0 to Count - 1 do
with Source[i]^ do begin
r := YList[0];
Result.a.X := Min(Result.a.X, X - r);
Result.b.X := Max(Result.b.X, X + r);
Result.a.Y := Min(Result.a.Y, Y - r);
Result.b.Y := Max(Result.b.Y, Y + r);
end;
end;
procedure TBubbleSeries.GetLegendItems(AItems: TChartLegendItems);
begin
AItems.Add(TLegendItemBrushRect.Create(BubbleBrush, Title));
end;
function TBubbleSeries.GetSeriesColor: TColor;
begin
Result := FBubbleBrush.Color;
end;
procedure TBubbleSeries.SetBubbleBrush(const AValue: TBrush);
begin
if FBubbleBrush = AValue then exit;
FBubbleBrush := AValue;
UpdateParentChart;
end;
procedure TBubbleSeries.SetBubblePen(AValue: TPen);
begin
if FBubblePen = AValue then exit;
FBubblePen := AValue;
UpdateParentChart;
end;
initialization
RegisterSeriesClass(TBubbleSeries, 'Bubble series');
end.

View File

@ -30,7 +30,7 @@ interface
uses
Classes, Graphics,
TAChartUtils, TADrawUtils, TACustomSeries, TAGraph, TALegend, TATypes;
TAChartUtils, TADrawUtils, TACustomSeries, TALegend, TATypes;
const
DEF_BAR_WIDTH_PERCENT = 70;
@ -207,33 +207,6 @@ type
// Use TLineSeries instead.
TSerie = TLineSeries deprecated;
TBubbleRadiusTransform = (brtNone, brtX, brtY);
{ TBubbleSeries }
TBubbleSeries = class(TBasicPointSeries)
private
FBubbleBrush: TBrush;
FBubblePen: TPen;
procedure SetBubbleBrush(const AValue: TBrush);
procedure SetBubblePen(AValue: TPen);
protected
procedure GetLegendItems(AItems: TChartLegendItems); override;
function GetSeriesColor: TColor; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Draw(ACanvas: TCanvas); override;
function Extent: TDoubleRect; override;
published
property AxisIndexX;
property AxisIndexY;
property BubbleBrush: TBrush read FBubbleBrush write SetBubbleBrush;
property BubblePen: TPen read FBubblePen write SetBubblePen;
property Source;
end;
TLineStyle = (lsVertical, lsHorizontal);
{ TConstantLine }
@ -355,7 +328,8 @@ type
implementation
uses
GraphMath, LResources, Math, PropEdits, SysUtils, Types;
GraphMath, LResources, Math, PropEdits, SysUtils, Types,
TAGraph;
{ TLineSeries }
@ -555,89 +529,6 @@ begin
UpdateParentChart;
end;
{ TBubbleSeries }
constructor TBubbleSeries.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FBubblePen := TPen.Create;
FBubblePen.OnChange := @StyleChanged;
FBubbleBrush := TBrush.Create;
FBubbleBrush.OnChange := @StyleChanged;
end;
destructor TBubbleSeries.Destroy;
begin
FreeAndNil(FBubbleBrush);
FreeAndNil(FBubblePen);
inherited Destroy;
end;
procedure TBubbleSeries.Draw(ACanvas: TCanvas);
var
i: Integer;
pt, d: TPoint;
r: Double;
begin
if Source.YCount < 2 then exit;
r := 0;
for i := 0 to Count - 1 do
r := Max(Source[i]^.YList[0], r);
with ParentChart.CurrentExtent do
PrepareGraphPoints(DoubleRect(a.X - r, a.Y - r, b.X + r, b.Y + r), true);
ACanvas.Pen.Assign(BubblePen);
ACanvas.Brush.Assign(BubbleBrush);
for i := 0 to High(FGraphPoints) do begin
pt := ParentChart.GraphToImage(FGraphPoints[i]);
r := Source[i + FLoBound]^.YList[0];
d.X := ParentChart.XGraphToImage(r) - ParentChart.XGraphToImage(0);
d.Y := ParentChart.YGraphToImage(r) - ParentChart.YGraphToImage(0);
ACanvas.EllipseC(pt.X, pt.Y, d.X, d.Y);
end;
DrawLabels(ACanvas);
end;
function TBubbleSeries.Extent: TDoubleRect;
var
i: Integer;
r: Double;
begin
Result := EmptyExtent;
if Source.YCount < 2 then exit;
for i := 0 to Count - 1 do
with Source[i]^ do begin
r := YList[0];
Result.a.X := Min(Result.a.X, X - r);
Result.b.X := Max(Result.b.X, X + r);
Result.a.Y := Min(Result.a.Y, Y - r);
Result.b.Y := Max(Result.b.Y, Y + r);
end;
end;
procedure TBubbleSeries.GetLegendItems(AItems: TChartLegendItems);
begin
AItems.Add(TLegendItemBrushRect.Create(BubbleBrush, Title));
end;
function TBubbleSeries.GetSeriesColor: TColor;
begin
Result := FBubbleBrush.Color;
end;
procedure TBubbleSeries.SetBubbleBrush(const AValue: TBrush);
begin
if FBubbleBrush = AValue then exit;
FBubbleBrush := AValue;
UpdateParentChart;
end;
procedure TBubbleSeries.SetBubblePen(AValue: TPen);
begin
if FBubblePen = AValue then exit;
FBubblePen := AValue;
UpdateParentChart;
end;
{ TConstantLine }
constructor TConstantLine.Create(AOwner: TComponent);
@ -1419,7 +1310,6 @@ initialization
RegisterSeriesClass(TAreaSeries, 'Area series');
RegisterSeriesClass(TBarSeries, 'Bar series');
RegisterSeriesClass(TPieSeries, 'Pie series');
RegisterSeriesClass(TBubbleSeries, 'Bubble series');
RegisterSeriesClass(TFuncSeries, 'Function series');
RegisterSeriesClass(TUserDrawnSeries, 'User-drawn series');
RegisterSeriesClass(TConstantLine, 'Constant line');