~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to components/tachart/tatransformations.pas

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
  { TAxisTransform }
34
34
 
35
35
  TAxisTransform = class(TIndexedComponent)
36
 
  private
 
36
  strict private
37
37
    FEnabled: Boolean;
38
38
    FTransformations: TChartAxisTransformations;
39
39
    procedure SetEnabled(AValue: Boolean);
55
55
    constructor Create(AOwner: TComponent); override;
56
56
    destructor Destroy; override;
57
57
  public
58
 
    procedure Assign(Source: TPersistent); override;
 
58
    procedure Assign(ASource: TPersistent); override;
59
59
    function GetParentComponent: TComponent; override;
60
60
    function HasParent: Boolean; override;
61
61
  public
70
70
 
71
71
  TAxisTransformClass = class of TAxisTransform;
72
72
 
73
 
  TAxisTransformList = class(TFPList)
 
73
  {$IFNDEF fpdoc} // Workaround for issue #18549.
 
74
  TAxisTransformEnumerator = specialize TTypedFPListEnumerator<TAxisTransform>;
 
75
  {$ENDIF}
 
76
 
 
77
  TAxisTransformList = class(TIndexedComponentList)
 
78
  public
 
79
    function GetEnumerator: TAxisTransformEnumerator;
74
80
  end;
75
81
 
76
82
  { TChartAxisTransformations }
77
83
 
78
 
  TChartAxisTransformations = class (TComponent)
79
 
  private
 
84
  TChartAxisTransformations = class(TComponent)
 
85
  strict private
80
86
    FBroadcaster: TBroadcaster;
81
87
    FList: TAxisTransformList;
 
88
  protected
 
89
    procedure SetName(const AValue: TComponentName); override;
82
90
  public
83
91
    constructor Create(AOwner: TComponent); override;
84
92
    destructor Destroy; override;
100
108
  { TLinearAxisTransform }
101
109
 
102
110
  TLinearAxisTransform = class(TAxisTransform)
103
 
  private
 
111
  strict private
104
112
    FOffset: Double;
105
113
    FScale: Double;
106
114
    function OffsetIsStored: Boolean;
110
118
  public
111
119
    constructor Create(AOwner: TComponent); override;
112
120
  public
113
 
    procedure Assign(Source: TPersistent); override;
 
121
    procedure Assign(ASource: TPersistent); override;
114
122
 
115
123
    function AxisToGraph(AX: Double): Double; override;
116
124
    function GraphToAxis(AX: Double): Double; override;
122
130
  { TAutoScaleAxisTransform }
123
131
 
124
132
  TAutoScaleAxisTransform = class(TAxisTransform)
125
 
  private
 
133
  strict private
126
134
    FMaxValue: Double;
127
135
    FMinValue: Double;
128
 
    function MaxValueIsStored: boolean;
129
 
    function MinValueIsStored: boolean;
130
 
    procedure SetMaxValue(const AValue: Double);
131
 
    procedure SetMinValue(const AValue: Double);
 
136
    function MaxValueIsStored: Boolean;
 
137
    function MinValueIsStored: Boolean;
 
138
    procedure SetMaxValue(AValue: Double);
 
139
    procedure SetMinValue(AValue: Double);
132
140
  protected
133
141
    procedure ClearBounds; override;
134
142
    function GetDrawDataClass: TDrawDataItemClass; override;
136
144
  public
137
145
    constructor Create(AOwner: TComponent); override;
138
146
  public
139
 
    procedure Assign(Source: TPersistent); override;
 
147
    procedure Assign(ASource: TPersistent); override;
140
148
 
141
149
    function AxisToGraph(AX: Double): Double; override;
142
150
    function GraphToAxis(AX: Double): Double; override;
150
158
  { TLogarithmAxisTransform }
151
159
 
152
160
  TLogarithmAxisTransform = class(TAxisTransform)
153
 
  private
 
161
  strict private
154
162
    FBase: Double;
155
163
    procedure SetBase(AValue: Double);
156
164
  public
164
172
    property Base: Double read FBase write SetBase;
165
173
  end;
166
174
 
 
175
  TCumulNormDistrAxisTransform = class(TAxisTransform)
 
176
  public
 
177
    function AxisToGraph(AX: Double): Double; override;
 
178
    function GraphToAxis(AX: Double): Double; override;
 
179
  end;
 
180
 
 
181
  TTransformEvent = procedure (AX: Double; out AT: Double) of object;
 
182
 
 
183
  { TUserDefinedAxisTransform }
 
184
 
 
185
  TUserDefinedAxisTransform = class(TAxisTransform)
 
186
  private
 
187
    FOnAxisToGraph: TTransformEvent;
 
188
    FOnGraphToAxis: TTransformEvent;
 
189
    procedure SetOnAxisToGraph(AValue: TTransformEvent);
 
190
    procedure SetOnGraphToAxis(AValue: TTransformEvent);
 
191
  public
 
192
    procedure Assign(ASource: TPersistent); override;
 
193
 
 
194
    function AxisToGraph(AX: Double): Double; override;
 
195
    function GraphToAxis(AX: Double): Double; override;
 
196
  published
 
197
    property OnAxisToGraph: TTransformEvent read FOnAxisToGraph write SetOnAxisToGraph;
 
198
    property OnGraphToAxis: TTransformEvent read FOnGraphToAxis write SetOnGraphToAxis;
 
199
  end;
 
200
 
167
201
  procedure Register;
168
202
 
169
203
resourcestring
173
207
 
174
208
uses
175
209
  ComponentEditors, Forms, Math, PropEdits,
176
 
  TASubcomponentsEditor;
 
210
  TAMath, TASubcomponentsEditor;
177
211
 
178
212
type
179
213
  { TAxisTransformsComponentEditor }
236
270
  AxisTransformsClassRegistry.AddObject(ACaption, TObject(AAxisTransformClass));
237
271
end;
238
272
 
 
273
{ TAxisTransformList }
 
274
 
 
275
function TAxisTransformList.GetEnumerator: TAxisTransformEnumerator;
 
276
begin
 
277
  Result := TAxisTransformEnumerator.Create(Self);
 
278
end;
 
279
 
239
280
{ TAxisTransformsComponentEditor }
240
281
 
241
282
function TAxisTransformsComponentEditor.GetVerb(Index: Integer): string;
305
346
 
306
347
{ TAxisTransform }
307
348
 
308
 
procedure TAxisTransform.Assign(Source: TPersistent);
 
349
procedure TAxisTransform.Assign(ASource: TPersistent);
309
350
begin
310
 
  if Source is TAxisTransform then
311
 
    with TAxisTransform(Source) do
 
351
  if ASource is TAxisTransform then
 
352
    with TAxisTransform(ASource) do
312
353
      Self.FEnabled := Enabled
313
354
  else
314
 
    inherited Assign(Source);
 
355
    inherited Assign(ASource);
315
356
end;
316
357
 
317
358
function TAxisTransform.AxisToGraph(AX: Double): Double;
428
469
 
429
470
function TChartAxisTransformations.AxisToGraph(AX: Double): Double;
430
471
var
431
 
  i: Integer;
 
472
  t: TAxisTransform;
432
473
begin
433
474
  Result := AX;
434
 
  for i := 0 to List.Count - 1 do
435
 
    with TAxisTransform(List[i]) do
436
 
      if Enabled then
437
 
        Result := AxisToGraph(Result);
 
475
  if IsNan(Result) then exit;
 
476
  for t in List do
 
477
    if t.Enabled then
 
478
      Result := t.AxisToGraph(Result);
438
479
end;
439
480
 
440
481
procedure TChartAxisTransformations.ClearBounds;
441
482
var
442
 
  i: Integer;
 
483
  t: TAxisTransform;
443
484
begin
444
 
  for i := List.Count - 1 downto 0 do
445
 
    with TAxisTransform(List[i]) do
446
 
      if Enabled then
447
 
        ClearBounds;
 
485
  for t in List do
 
486
    if t.Enabled then
 
487
      t.ClearBounds;
448
488
end;
449
489
 
450
490
constructor TChartAxisTransformations.Create(AOwner: TComponent);
466
506
procedure TChartAxisTransformations.GetChildren(
467
507
  Proc: TGetChildProc; Root: TComponent);
468
508
var
469
 
  i: Integer;
 
509
  t: TAxisTransform;
470
510
begin
471
 
  for i := 0 to List.Count - 1 do
472
 
    if TAxisTransform(List[i]).Owner = Root then
473
 
      Proc(TAxisTransform(List[i]));
 
511
  for t in List do
 
512
    if t.Owner = Root then
 
513
      Proc(t);
474
514
end;
475
515
 
476
516
function TChartAxisTransformations.GraphToAxis(AX: Double): Double;
486
526
 
487
527
procedure TChartAxisTransformations.SetChart(AChart: TObject);
488
528
var
489
 
  i: Integer;
 
529
  t: TAxisTransform;
490
530
begin
491
 
  for i := 0 to List.Count - 1 do
492
 
    with TAxisTransform(List[i]) do
493
 
      if Enabled then
494
 
        TAxisTransform(List[i]).SetChart(AChart);
 
531
  for t in List do
 
532
    if t.Enabled then
 
533
      t.SetChart(AChart);
495
534
end;
496
535
 
497
536
procedure TChartAxisTransformations.SetChildOrder(
504
543
    List.Move(i, Order);
505
544
end;
506
545
 
 
546
procedure TChartAxisTransformations.SetName(const AValue: TComponentName);
 
547
var
 
548
  oldName: String;
 
549
begin
 
550
  if Name = AValue then exit;
 
551
  oldName := Name;
 
552
  inherited SetName(AValue);
 
553
  if csDesigning in ComponentState then
 
554
    List.ChangeNamePrefix(oldName, AValue);
 
555
end;
 
556
 
507
557
procedure TChartAxisTransformations.UpdateBounds(var AMin, AMax: Double);
508
558
var
509
 
  i: Integer;
 
559
  t: TAxisTransform;
510
560
begin
511
 
  for i := 0 to List.Count - 1 do
512
 
    with TAxisTransform(List[i]) do
513
 
      if Enabled then
514
 
        UpdateBounds(AMin, AMax);
 
561
  for t in List do
 
562
    if t.Enabled then
 
563
      t.UpdateBounds(AMin, AMax);
515
564
end;
516
565
 
517
566
{ TLinearAxisTransform }
518
567
 
519
 
procedure TLinearAxisTransform.Assign(Source: TPersistent);
 
568
procedure TLinearAxisTransform.Assign(ASource: TPersistent);
520
569
begin
521
 
  if Source is TLinearAxisTransform then
522
 
    with Source as TLinearAxisTransform do begin
 
570
  if ASource is TLinearAxisTransform then
 
571
    with ASource as TLinearAxisTransform do begin
523
572
      Self.FOffset := Offset;
524
573
      Self.FScale := Scale;
525
574
    end;
526
 
  inherited Assign(Source);
 
575
  inherited Assign(ASource);
527
576
end;
528
577
 
529
578
function TLinearAxisTransform.AxisToGraph(AX: Double): Double;
606
655
 
607
656
{ TAutoScaleAxisTransform }
608
657
 
609
 
procedure TAutoScaleAxisTransform.Assign(Source: TPersistent);
 
658
procedure TAutoScaleAxisTransform.Assign(ASource: TPersistent);
610
659
begin
611
 
  if Source is TAutoScaleAxisTransform then
612
 
    with TAutoScaleAxisTransform(Source) do begin
 
660
  if ASource is TAutoScaleAxisTransform then
 
661
    with TAutoScaleAxisTransform(ASource) do begin
613
662
      Self.FMinValue := FMinValue;
614
663
      Self.FMaxValue := FMaxValue;
615
664
    end;
616
 
  inherited Assign(Source);
 
665
  inherited Assign(ASource);
617
666
end;
618
667
 
619
668
function TAutoScaleAxisTransform.AxisToGraph(AX: Double): Double;
650
699
    Result := (AX - FOffset) / FScale;
651
700
end;
652
701
 
653
 
function TAutoScaleAxisTransform.MaxValueIsStored: boolean;
 
702
function TAutoScaleAxisTransform.MaxValueIsStored: Boolean;
654
703
begin
655
704
  Result := MaxValue <> 1.0;
656
705
end;
657
706
 
658
 
function TAutoScaleAxisTransform.MinValueIsStored: boolean;
 
707
function TAutoScaleAxisTransform.MinValueIsStored: Boolean;
659
708
begin
660
709
  Result := MinValue <> 0.0;
661
710
end;
662
711
 
663
 
procedure TAutoScaleAxisTransform.SetMaxValue(const AValue: Double);
 
712
procedure TAutoScaleAxisTransform.SetMaxValue(AValue: Double);
664
713
begin
665
714
  if FMaxValue = AValue then exit;
666
715
  FMaxValue := AValue;
667
716
  Changed;
668
717
end;
669
718
 
670
 
procedure TAutoScaleAxisTransform.SetMinValue(const AValue: Double);
 
719
procedure TAutoScaleAxisTransform.SetMinValue(AValue: Double);
671
720
begin
672
721
  if FMinValue = AValue then exit;
673
722
  FMinValue := AValue;
691
740
  AMax := MaxValue;
692
741
end;
693
742
 
 
743
{ TCumulNormDistrAxisTransform }
 
744
 
 
745
function TCumulNormDistrAxisTransform.AxisToGraph(AX: Double): Double;
 
746
begin
 
747
  Result := InvCumulNormDistr(AX);
 
748
end;
 
749
 
 
750
function TCumulNormDistrAxisTransform.GraphToAxis(AX: Double): Double;
 
751
begin
 
752
  Result := CumulNormDistr(AX);
 
753
end;
 
754
 
 
755
{ TUserDefinedAxisTransform }
 
756
 
 
757
procedure TUserDefinedAxisTransform.Assign(ASource: TPersistent);
 
758
begin
 
759
  if ASource is TUserDefinedAxisTransform then
 
760
    with TUserDefinedAxisTransform(ASource) do begin
 
761
      Self.FOnAxisToGraph := FOnAxisToGraph;
 
762
      Self.FOnGraphToAxis := FOnGraphToAxis;
 
763
    end;
 
764
  inherited Assign(ASource);
 
765
end;
 
766
 
 
767
function TUserDefinedAxisTransform.AxisToGraph(AX: Double): Double;
 
768
begin
 
769
  if Assigned(OnAxisToGraph) then
 
770
    OnAxisToGraph(AX, Result)
 
771
  else
 
772
    Result := AX;
 
773
end;
 
774
 
 
775
function TUserDefinedAxisTransform.GraphToAxis(AX: Double): Double;
 
776
begin
 
777
  if Assigned(OnGraphToAxis) then
 
778
    OnGraphToAxis(AX, Result)
 
779
  else
 
780
    Result := AX;
 
781
end;
 
782
 
 
783
procedure TUserDefinedAxisTransform.SetOnAxisToGraph(AValue: TTransformEvent);
 
784
begin
 
785
  if TMethod(FOnAxisToGraph) = TMethod(AValue) then exit;
 
786
  FOnAxisToGraph := AValue;
 
787
  Changed;
 
788
end;
 
789
 
 
790
procedure TUserDefinedAxisTransform.SetOnGraphToAxis(AValue: TTransformEvent);
 
791
begin
 
792
  if TMethod(FOnGraphToAxis) = TMethod(AValue) then exit;
 
793
  FOnGraphToAxis := AValue;
 
794
  Changed;
 
795
end;
 
796
 
694
797
initialization
695
798
 
696
799
  AxisTransformsClassRegistry := TStringList.Create;
697
800
  RegisterAxisTransformClass(TAutoScaleAxisTransform, 'Auto scale');
 
801
  RegisterAxisTransformClass(
 
802
    TCumulNormDistrAxisTransform, 'Cumulative normal distribution');
698
803
  RegisterAxisTransformClass(TLinearAxisTransform, 'Linear');
699
804
  RegisterAxisTransformClass(TLogarithmAxisTransform, 'Logarithmic');
 
805
  RegisterAxisTransformClass(TUserDefinedAxisTransform, 'User defined');
700
806
 
701
807
finalization
702
808