agpl_1.0.0_b5da3320/src/agpl-graph.ads

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
 

--  Type for generating a simple graph
--  Data values are floats, vertical scale is automatic, horizontal is fixed,
--  multiple series are allowed. Values in multiple series should be normali-
--  zed against a common scale.

with Agpl.Bmp;
with Agpl.Constants;
with Agpl.Containers.Naked_Vectors;
with Agpl.Types;

with Ada.Containers.Doubly_Linked_Lists;

package Agpl.Graph is

   --  pragma Elaborate_Body;

   ------------------------------------------------------------------------
   -- Object                                                             --
   ------------------------------------------------------------------------
   type Object (Series : Positive; Samples : Positive) is tagged limited private;

   ------------------------------------------------------------------------
   -- Add_sample                                                         --
   ------------------------------------------------------------------------
   procedure Add_sample (
      This : in out Object; Serie : in Natural; Sample : in Float);

   ------------------------------------------------------------------------
   -- Get_bmp                                                            --
   ------------------------------------------------------------------------
   function Get_bmp (This : in Object; Height : in Positive)
      return Bmp.Object;

   ------------------------------------------------------------------------
   -- Reset                                                              --
   ------------------------------------------------------------------------
   --  Removes all samples
   procedure Reset (This : in out Object);

   ------------------------------------------------------------------------
   -- Set_colors                                                         --
   ------------------------------------------------------------------------
   procedure Set_colors (
      This    : in out Object;
      Bgcolor : in     Types.Rgb_triplet;
      Fgcolor : in     Types.Rgb_array); -- Must have Series elements.

   ------------------------------------------------------------------------
   -- Set_scale                                                          --
   ------------------------------------------------------------------------
   procedure Set_scale_min (This : in out Object; Min : in Float);
   procedure Set_scale_max (This : in out Object; Max : in Float);
   procedure Set_scale_auto (This : in out Object);

   ------------------------------------------------------------------------
   -- Set_YAxis                                                          --
   ------------------------------------------------------------------------
   --  Repeat indicates if the axis will repeat x2, x3, etc.
   procedure Set_YAxis (
      This   : in out Object;
      Height : in     Float;
      Color  : in     Types.Rgb_triplet;
      Repeat : in     Boolean := False);

private

   package Lists is new Ada.Containers.Doubly_Linked_Lists (
      Float, "=");

   type List_array is array (Positive range <>) of Lists.List;

   type Orientations is (Horizontal, Vertical);

   type Axis_type (Orientation : Orientations := Horizontal) is record
      Color  : Types.Rgb_triplet;
      Repeat : Boolean;
      case Orientation is
         when Horizontal =>
            Height : Float;
         when Vertical =>
            Width : Positive;
      end case;
   end record;

   package Axis_vector is new Agpl.Containers.Naked_Vectors (Axis_type);

   type Object (Series : Positive; Samples : Positive) is tagged limited record
      Data    : List_array (1 .. Series);
      Bgcolor : Types.Rgb_triplet := Constants.Black;
      Fgcolor : Types.Rgb_array (1 .. Series) := (others => Constants.White);

      Scale_min_forced : Boolean := False;
      Scale_max_forced : Boolean := False;
      Scale_min        : Float;
      Scale_max        : Float;

      Axis    : Axis_vector.Object (First => 1);
   end record;

   -----------------
   -- Get_max_min --
   -----------------
   --  Says max and min values in a graph
   --  Uses forced extremes if present
   procedure Get_max_min (This : in Object; Max, Min : out Float);

   ---------------
   -- Draw_axis --
   ---------------
   procedure Draw_axis (
      This     : in     Object;
      Max, Min : in     Float;
      Height   : in     Positive;
      Canvas   : in out Bmp.Object);

end Agpl.Graph;