1-- Pie chart demo.
2
3-- Copyright (C) 2008 Jerry Bauck
4
5-- This file is part of PLplot.
6
7-- PLplot is free software; you can redistribute it and/or modify
8-- it under the terms of the GNU Library General Public License as published
9-- by the Free Software Foundation; either version 2 of the License, or
10-- (at your option) any later version.
11
12-- PLplot is distributed in the hope that it will be useful,
13-- but WITHOUT ANY WARRANTY; without even the implied warranty of
14-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15-- GNU Library General Public License for more details.
16
17-- You should have received a copy of the GNU Library General Public License
18-- along with PLplot; if not, write to the Free Software
19-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
21with
22    Ada.Numerics,
23    Ada.Numerics.Long_Elementary_Functions,
24    PLplot_Auxiliary,
25    PLplot_Traditional;
26use
27    Ada.Numerics,
28    Ada.Numerics.Long_Elementary_Functions,
29    PLplot_Auxiliary,
30    PLplot_Traditional;
31
32------------------------------------------------------------------------------
33-- Does a simple pie chart.
34------------------------------------------------------------------------------
35
36procedure xtraditional13a is
37    j, dthet, theta0, theta1, theta : Integer;
38    just, dx, dy : Long_Float;
39    x, y : Real_Vector(0 .. 499);
40    per  : Real_Vector(0 .. 4) := (10.0, 32.0, 12.0, 30.0, 16.0);
41
42begin
43    -- Parse and process command line arguments
44    plparseopts(PL_PARSE_FULL);
45
46    -- Initialize plplot
47    plinit;
48
49    pladv(0);
50
51    -- Ensure window has aspect ratio of one so circle is plotted as a circle.
52    plvasp(1.0);
53    plwind(0.0, 10.0, 0.0, 10.0);
54    -- plenv(0.0, 10.0, 0.0, 10.0, 1, -2);
55    plcol0(2);
56
57    -- n.b. all theta quantities scaled by 2 * pi / 500 to be integers to avoid
58    -- floating point logic problems.
59    theta0 := 0;
60    dthet := 1;
61    for i in per'range loop
62        j := 0;
63        x(j) := 5.0;
64        y(j) := 5.0;
65        j := j + 1;
66
67        -- n.b. the theta quantities multiplied by 2 * pi / 500 afterward so
68        -- in fact per is interpreted as a percentage.
69        theta1 := Integer(Long_Float(theta0) + 5.0 * per(i));
70        if i = 4 then
71            theta1 := 500;
72        end if;
73
74        theta := theta0;
75        while theta <= theta1 loop
76            x(j) := 5.0 + 3.0 * cos((2.0 * pi / 500.0) * Long_Float(theta));
77            y(j) := 5.0 + 3.0 * sin((2.0 * pi / 500.0) * Long_Float(theta));
78            j := j + 1;
79            theta := theta + dthet;
80        end loop;
81
82        plcol0(i + 1);
83        plpsty((i + 3) mod 8 + 1);
84
85        declare
86            x_Temp, y_Temp : Real_Vector(0 .. j - 1);
87        begin
88            x_Temp := x(0 .. j - 1);
89            y_Temp := y(0 .. j - 1);
90            plfill(x_Temp, y_Temp);
91            plcol0(1);
92            plline(x_Temp, y_Temp);
93        end;
94
95        just := (2.0 * pi / 500.0) * Long_Float((theta0 + theta1))/2.0;
96        dx := 0.25 * cos(just);
97        dy := 0.25 * sin(just);
98        if (theta0 + theta1) < 250 or (theta0 + theta1) > 750 then
99            just := 0.0;
100        else
101            just := 1.0;
102        end if;
103
104        if i = 0 then
105            plptex(x(j / 2) + dx, y(j / 2) + dy, 1.0, 0.0, just, "Maurice");
106        elsif i = 1 then
107            plptex(x(j / 2) + dx, y(j / 2) + dy, 1.0, 0.0, just, "Geoffrey");
108        elsif i = 2 then
109            plptex(x(j / 2) + dx, y(j / 2) + dy, 1.0, 0.0, just, "Alan");
110        elsif i = 3 then
111            plptex(x(j / 2) + dx, y(j / 2) + dy, 1.0, 0.0, just, "Rafael");
112        elsif i = 4 then
113            plptex(x(j / 2) + dx, y(j / 2) + dy, 1.0, 0.0, just, "Vince");
114        end if;
115
116        theta0 := theta - dthet;
117    end loop;
118    plfont(2);
119    plschr(0.0, 1.3);
120    plptex(5.0, 9.0, 1.0, 0.0, 0.5, "Percentage of Sales");
121
122    -- Don't forget to call PLEND to finish off!
123    plend;
124end xtraditional13a;
125