TAChart: Add new axis property LabelSize and corresponding demo (axisalign).

git-svn-id: trunk@47194 -
This commit is contained in:
wp 2014-12-13 23:08:29 +00:00
parent b333a79083
commit 0b179b19ec
7 changed files with 638 additions and 4 deletions

4
.gitattributes vendored
View File

@ -3562,6 +3562,10 @@ components/tachart/demo/axis/axisdemo.lpi svneol=native#text/plain
components/tachart/demo/axis/axisdemo.lpr svneol=native#text/pascal
components/tachart/demo/axis/main.lfm svneol=native#text/plain
components/tachart/demo/axis/main.pas svneol=native#text/pascal
components/tachart/demo/axisalign/axisalign.lpi svneol=native#text/plain
components/tachart/demo/axisalign/axisalign.lpr svneol=native#text/plain
components/tachart/demo/axisalign/main.lfm svneol=native#text/plain
components/tachart/demo/axisalign/main.pas svneol=native#text/plain
components/tachart/demo/axistransf/axistransfdemo.lpi svneol=native#text/plain
components/tachart/demo/axistransf/axistransfdemo.lpr svneol=native#text/pascal
components/tachart/demo/axistransf/main.lfm svneol=native#text/plain

View File

@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
<PathDelim Value="\"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="axisalign"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
</General>
<i18n>
<EnableI18N LFM="False"/>
</i18n>
<VersionInfo>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="2">
<Item1 Name="Debug" Default="True"/>
<Item2 Name="Release">
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
</SearchPaths>
<CodeGeneration>
<SmartLinkUnit Value="True"/>
</CodeGeneration>
<Linking>
<Debugging>
<StripSymbols Value="True"/>
</Debugging>
<LinkSmart Value="True"/>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
</Item2>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
</RunParams>
<RequiredPackages Count="2">
<Item1>
<PackageName Value="TAChartLazarusPkg"/>
</Item1>
<Item2>
<PackageName Value="LCL"/>
</Item2>
</RequiredPackages>
<Units Count="2">
<Unit0>
<Filename Value="axisalign.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="axisalign"/>
</Unit0>
<Unit1>
<Filename Value="main.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="main"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
</SearchPaths>
<CodeGeneration>
<SmartLinkUnit Value="True"/>
</CodeGeneration>
<Linking>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,21 @@
program axisalign;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, main, tachartlazaruspkg
{ you can add units after this };
{$R *.res}
begin
RequireDerivedFormResource := True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

View File

@ -0,0 +1,367 @@
object Form1: TForm1
Left = 583
Height = 500
Top = 262
Width = 674
Caption = 'Form1'
ClientHeight = 500
ClientWidth = 674
OnCreate = FormCreate
LCLVersion = '1.3'
object PageControl1: TPageControl
Left = 0
Height = 472
Top = 0
Width = 674
ActivePage = TabSheet1
Align = alClient
TabIndex = 0
TabOrder = 0
OnChange = PageControl1Change
object TabSheet1: TTabSheet
Caption = 'stacked'
ClientHeight = 444
ClientWidth = 666
object Panel1: TPanel
Left = 0
Height = 64
Top = 0
Width = 666
Align = alTop
BevelOuter = bvNone
ClientHeight = 64
ClientWidth = 666
TabOrder = 0
object EdLabelSizeLeft: TSpinEdit
Left = 96
Height = 23
Top = 8
Width = 74
OnChange = EdLabelSizeLeftChange
TabOrder = 0
end
object Label1: TLabel
Left = 19
Height = 15
Top = 14
Width = 51
Caption = 'LabelSize:'
ParentColor = False
end
object EdLabelSizeRight: TSpinEdit
Left = 536
Height = 23
Top = 8
Width = 66
OnChange = EdLabelSizeRightChange
TabOrder = 1
end
object Label2: TLabel
Left = 19
Height = 15
Top = 38
Width = 46
Caption = 'Position:'
ParentColor = False
end
object EdPositionLeft: TSpinEdit
Left = 96
Height = 23
Top = 32
Width = 74
OnChange = EdPositionLeftChange
TabOrder = 2
end
object Label6: TLabel
Left = 464
Height = 15
Top = 14
Width = 51
Caption = 'LabelSize:'
ParentColor = False
end
object Bevel2: TBevel
Left = 0
Height = 3
Top = 61
Width = 666
Align = alBottom
Shape = bsBottomLine
end
end
object ChartBottom: TChart
Left = 0
Height = 176
Top = 268
Width = 666
AxisList = <
item
Grid.Color = clSilver
AxisPen.Visible = True
Minors = <>
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'Y axis title'
end
item
Grid.Color = clSilver
Alignment = calBottom
Minors = <>
end
item
Alignment = calRight
Marks.Visible = False
Minors = <>
end>
BackColor = clWhite
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
MarginsExternal.Left = 10
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alBottom
Color = clWhite
ParentColor = False
object ChartBottomLineSeries1: TLineSeries
Source = RandomChartSource2
end
end
object ChartTop: TChart
Left = 0
Height = 204
Top = 64
Width = 666
AntialiasingMode = amOn
AxisList = <
item
Grid.Color = clSilver
AxisPen.Visible = True
Minors = <>
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'Y axis title'
end
item
Grid.Color = clSilver
Alignment = calBottom
Minors = <>
Title.Visible = True
Title.Caption = 'x'
end
item
Alignment = calRight
Marks.Visible = False
Minors = <>
end>
BackColor = clWhite
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
MarginsExternal.Left = 10
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alClient
Color = clWhite
ParentColor = False
object ChartTopLineSeries1: TLineSeries
Source = RandomChartSource1
end
end
end
object TabSheet2: TTabSheet
Caption = 'side-by-side'
ClientHeight = 422
ClientWidth = 666
object Panel2: TPanel
Left = 0
Height = 422
Top = 0
Width = 104
Align = alLeft
BevelOuter = bvNone
ClientHeight = 422
ClientWidth = 104
TabOrder = 0
object EdLabelSizeBottom: TSpinEdit
Left = 16
Height = 23
Top = 392
Width = 74
OnChange = EdLabelSizeBottomChange
TabOrder = 0
end
object Label3: TLabel
Left = 16
Height = 15
Top = 368
Width = 51
Caption = 'LabelSize:'
ParentColor = False
end
object EdLabelSizeTop: TSpinEdit
Left = 16
Height = 23
Top = 32
Width = 66
OnChange = EdLabelSizeTopChange
TabOrder = 1
end
object Label4: TLabel
Left = 16
Height = 15
Top = 304
Width = 46
Caption = 'Position:'
ParentColor = False
end
object EdPositionBottom: TSpinEdit
Left = 16
Height = 23
Top = 328
Width = 74
OnChange = EdPositionBottomChange
TabOrder = 2
end
object Label5: TLabel
Left = 16
Height = 15
Top = 8
Width = 51
Caption = 'LabelSize:'
ParentColor = False
end
object Bevel1: TBevel
Left = 96
Height = 422
Top = 0
Width = 8
Align = alRight
Shape = bsRightLine
end
end
object ChartRight: TChart
Left = 384
Height = 422
Top = 0
Width = 282
AxisList = <
item
Grid.Color = clSilver
AxisPen.Visible = True
Minors = <>
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'Y axis'
end
item
Grid.Color = clSilver
Alignment = calBottom
AxisPen.Visible = True
Marks.LabelFont.Orientation = 900
Minors = <>
Title.Visible = True
Title.Caption = 'X axis'
end
item
Alignment = calTop
Marks.Visible = False
Minors = <>
end>
BackColor = clWhite
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
MarginsExternal.Left = 10
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alRight
Color = clWhite
ParentColor = False
object Chart2LineSeries2: TLineSeries
Source = RandomChartSource2
end
end
object ChartLeft: TChart
Left = 104
Height = 422
Top = 0
Width = 280
AntialiasingMode = amOn
AxisList = <
item
Grid.Color = clSilver
AxisPen.Visible = True
Minors = <>
Title.LabelFont.Orientation = 900
Title.Visible = True
Title.Caption = 'Y axis'
end
item
Grid.Color = clSilver
Alignment = calBottom
AxisPen.Visible = True
Marks.LabelFont.Orientation = 900
Minors = <>
Title.Visible = True
Title.Caption = 'X axis'
end
item
Alignment = calTop
Marks.Visible = False
Minors = <>
end>
BackColor = clWhite
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
MarginsExternal.Left = 10
Title.Brush.Color = clBtnFace
Title.Font.Color = clBlue
Title.Text.Strings = (
'TAChart'
)
Align = alClient
Color = clWhite
ParentColor = False
object Chart1LineSeries2: TLineSeries
Source = RandomChartSource1
end
end
end
end
object Panel3: TPanel
Left = 0
Height = 28
Top = 472
Width = 674
Align = alBottom
Caption = 'Panel3'
TabOrder = 1
end
object RandomChartSource1: TRandomChartSource
PointsNumber = 10
RandSeed = 1952997387
XMax = 1
XMin = 0
YMax = 1
YMin = 0
left = 264
top = 272
end
object RandomChartSource2: TRandomChartSource
PointsNumber = 20
RandSeed = 1953042499
XMax = 1000
XMin = -1000
YMax = 1000000
YMin = 0
left = 392
top = 272
end
end

View File

@ -0,0 +1,122 @@
unit main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, TAGraph, TASources, TASeries, Forms, Controls,
Graphics, Dialogs, Spin, StdCtrls, ExtCtrls, ComCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Bevel1: TBevel;
Bevel2: TBevel;
ChartTop: TChart;
ChartTopLineSeries1: TLineSeries;
Chart1LineSeries2: TLineSeries;
ChartBottom: TChart;
ChartBottomLineSeries1: TLineSeries;
Chart2LineSeries2: TLineSeries;
ChartRight: TChart;
ChartLeft: TChart;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
PageControl1: TPageControl;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
RandomChartSource1: TRandomChartSource;
RandomChartSource2: TRandomChartSource;
EdLabelSizeLeft: TSpinEdit;
EdLabelSizeRight: TSpinEdit;
EdPositionLeft: TSpinEdit;
EdLabelSizeBottom: TSpinEdit;
EdLabelSizeTop: TSpinEdit;
EdPositionBottom: TSpinEdit;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
procedure EdLabelSizeTopChange(Sender: TObject);
procedure EdPositionBottomChange(Sender: TObject);
procedure EdLabelSizeLeftChange(Sender: TObject);
procedure EdLabelSizeRightChange(Sender: TObject);
procedure EdPositionLeftChange(Sender: TObject);
procedure EdLabelSizeBottomChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure PageControl1Change(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
PageControl1Change(nil);
end;
procedure TForm1.PageControl1Change(Sender: TObject);
const
AXIS_NAMES: array[0..1] of String = ('left and right', 'top and bottom');
begin
Panel3.Caption := Format('The %s axis lines are at different ' +
'positions. Increase "LabelSize" to align them.', [AXIS_NAMES[PageControl1.PageIndex]]);
end;
{ Charts on page "stacked" }
procedure TForm1.EdLabelSizeLeftChange(Sender: TObject);
begin
ChartTop.LeftAxis.LabelSize := EdLabelSizeLeft.Value;
ChartBottom.LeftAxis.LabelSize := EdLabelSizeLeft.Value;
end;
procedure TForm1.EdLabelSizeRightChange(Sender: TObject);
begin
ChartTop.AxisList[2].LabelSize := EdLabelSizeRight.Value;
ChartBottom.AxisList[2].LabelSize := EdLabelSizeRight.Value;
end;
procedure TForm1.EdPositionLeftChange(Sender: TObject);
begin
ChartTop.LeftAxis.Position := EdPositionLeft.Value;
ChartBottom.LeftAxis.Position := EdPositionLeft.Value;
end;
{ Charts on page "side-by-side" }
procedure TForm1.EdLabelSizeBottomChange(Sender: TObject);
begin
ChartLeft.BottomAxis.LabelSize := EdLabelSizeBottom.Value;
ChartRight.BottomAxis.LabelSize := EdLabelSizeBottom.Value;
end;
procedure TForm1.EdLabelSizeTopChange(Sender: TObject);
begin
ChartLeft.AxisList[2].LabelSize := EdLabelSizeTop.Value;
ChartRight.AxisList[2].LabelSize := EdLabelSizeTop.Value;
end;
procedure TForm1.EdPositionBottomChange(Sender: TObject);
begin
ChartLeft.BottomAxis.Position := EdPositionBottom.Value;
ChartRight.BottomAxis.Position := EdPositionBottom.Value;
end;
end.

View File

@ -86,7 +86,6 @@ type
FListener: TListener;
FMarkValues: TChartValueTextArray;
FTitlePos: Integer;
procedure GetMarkValues;
procedure VisitSource(ASource: TCustomChartSource; var AData);
private
@ -100,6 +99,7 @@ type
FGroup: Integer;
FHelper: TAxisDrawHelper;
FInverted: Boolean;
FLabelSize: Integer;
FMargin: TChartDistance;
FMarginsForMarks: Boolean;
FMinors: TChartMinorAxisList;
@ -118,6 +118,7 @@ type
procedure SetAxisPen(AValue: TChartAxisPen);
procedure SetGroup(AValue: Integer);
procedure SetInverted(AValue: Boolean);
procedure SetLabelSize(AValue: Integer);
procedure SetMargin(AValue: TChartDistance);
procedure SetMarginsForMarks(AValue: Boolean);
procedure SetMarks(AValue: TChartAxisMarks);
@ -166,6 +167,7 @@ type
property Group: Integer read FGroup write SetGroup default 0;
// Inverts the axis scale from increasing to decreasing.
property Inverted: boolean read FInverted write SetInverted default false;
property LabelSize: Integer read FLabelSize write SetLabelSize default 0;
property Margin: TChartDistance read FMargin write SetMargin default 0;
property MarginsForMarks: Boolean
read FMarginsForMarks write SetMarginsForMarks default true;
@ -691,13 +693,18 @@ begin
FHelper.FValueMin := TDoublePointBoolArr(AExtent.a)[v];
FHelper.FValueMax := TDoublePointBoolArr(AExtent.b)[v];
GetMarkValues;
sz := Marks.Measure(d, not v, TickLength, FMarkValues);
if FLabelSize = 0 then
// Default distance (= length of marks)
sz := Marks.Measure(d, not v, TickLength, FMarkValues)
else
// User-defined distance
sz := d.Scale(FLabelSize);
FHelper.GetClipRange(rmin, rmax);
minc := MaxInt;
maxc := -MaxInt;
for i := 0 to High(FMarkValues) do begin
cv := FMarkValues[i].FValue;
if not IsNan(pv) then begin
if (FLabelSize = 0) and (not IsNan(pv)) then begin
for j := 0 to Minors.Count - 1 do
with Minors[j] do begin
minorValues := GetMarkValues(pv, cv);
@ -817,6 +824,13 @@ begin
StyleChanged(Self);
end;
procedure TChartAxis.SetLabelSize(AValue: Integer);
begin
if FLabelSize = AValue then exit;
FLabelSize := Max(AValue, 0);
StyleChanged(Self);
end;
procedure TChartAxis.SetMargin(AValue: TChartDistance);
begin
if FMargin = AValue then exit;

View File

@ -828,7 +828,6 @@ begin
PrepareAxis(ADrawer);
if (FPrevLogicalExtent <> FLogicalExtent) and Assigned(OnExtentChanging) then
OnExtentChanging(Self);
ADrawer.DrawingBegin(ARect);
ADrawer.SetAntialiasingMode(AntialiasingMode);
Clear(ADrawer, ARect);