root / UEchelle.pas @ 3
Historique | Voir | Annoter | Télécharger (2,228 ko)
1 | 3 | avalancogn | unit UEchelle;
|
---|---|---|---|
2 | |||
3 | interface
|
||
4 | |||
5 | uses
|
||
6 | Chart; |
||
7 | |||
8 | function AjustPas(Max: double): double;
|
||
9 | function AjustMax(Max: double; Pas: double): double;
|
||
10 | function AjustMin(Min: double; Pas: double): double;
|
||
11 | function AjustFormat(Pas: double): string; |
||
12 | procedure AjustEchelle(Graph: TChart);
|
||
13 | |||
14 | implementation
|
||
15 | |||
16 | uses
|
||
17 | UVariables; |
||
18 | |||
19 | function AjustPas(Max: double): double;
|
||
20 | begin
|
||
21 | if (Max < 5) and (Max > PICO) // si Max = 0 alors Pas = 1 |
||
22 | then
|
||
23 | result := AjustPas (Max * 10) / 10 |
||
24 | else
|
||
25 | if Max > 50 |
||
26 | then
|
||
27 | result := AjustPas (Max / 10) * 10 |
||
28 | else
|
||
29 | if Max > 25 |
||
30 | then
|
||
31 | result := 5
|
||
32 | else
|
||
33 | if Max > 10 |
||
34 | then
|
||
35 | result := 2.5
|
||
36 | else
|
||
37 | result := 1 ;
|
||
38 | end;
|
||
39 | |||
40 | function AjustMax(Max: double; Pas: double): double;
|
||
41 | begin
|
||
42 | if Max = 100 |
||
43 | then
|
||
44 | result := 100
|
||
45 | else
|
||
46 | result := Round (Max / Pas) * Pas + Pas ; |
||
47 | end;
|
||
48 | |||
49 | function AjustMin(Min: double; Pas: double): double;
|
||
50 | begin
|
||
51 | if (Min >= 0) and (Round (Min / Pas) * Pas < Pas) |
||
52 | then
|
||
53 | result := 0
|
||
54 | else
|
||
55 | result := Round (Min / Pas) * Pas - Pas ; |
||
56 | end;
|
||
57 | |||
58 | function AjustFormat(Pas: double): string; |
||
59 | var
|
||
60 | s: string;
|
||
61 | begin
|
||
62 | // s := '#' + ThousandSeparator + '##0' + DecimalSeparator ;
|
||
63 | s := '# ##0.' ;
|
||
64 | while (Int (Pas) < Pas) do |
||
65 | begin
|
||
66 | s := s + '0' ;
|
||
67 | Pas := Pas * 10 ;
|
||
68 | end ;
|
||
69 | result := s ; |
||
70 | end;
|
||
71 | |||
72 | procedure AjustEchelle(Graph: TChart);
|
||
73 | begin
|
||
74 | with Graph do |
||
75 | begin
|
||
76 | // Axe de gauche
|
||
77 | LeftAxis.Minimum := 0 ;
|
||
78 | LeftAxis.Increment := AjustPas (MaxYValue (LeftAxis) - MinYValue (LeftAxis)) ; |
||
79 | LeftAxis.MinorTickCount := 4 ;
|
||
80 | LeftAxis.Maximum := AjustMax (MaxYValue (LeftAxis), LeftAxis.Increment) ; |
||
81 | LeftAxis.Minimum := AjustMin (MinYValue (LeftAxis), LeftAxis.Increment) ; |
||
82 | LeftAxis.AxisValuesFormat := AjustFormat (LeftAxis.Increment) ; |
||
83 | // Axe de droite
|
||
84 | RightAxis.Minimum := 0 ;
|
||
85 | RightAxis.Increment := AjustPas (MaxYValue (RightAxis) - MinYValue (RightAxis)) ; |
||
86 | RightAxis.MinorTickCount := 4 ;
|
||
87 | RightAxis.Maximum := AjustMax (MaxYValue (RightAxis), RightAxis.Increment) ; |
||
88 | RightAxis.Minimum := AjustMin (MinYValue (RightAxis), RightAxis.Increment) ; |
||
89 | RightAxis.AxisValuesFormat := AjustFormat (RightAxis.Increment) ; |
||
90 | end;
|
||
91 | end;
|
||
92 | |||
93 | end. |