OpenWrt packages
Sign in or create your account | Project List | Help
OpenWrt packages Git Source Tree
Root/
| 1 | --[[ $Id: x13.lua 9526 2009-02-13 22:06:13Z smekal $ |
| 2 | |
| 3 | Pie chart demo. |
| 4 | |
| 5 | Copyright (C) 2008 Werner Smekal |
| 6 | |
| 7 | This file is part of PLplot. |
| 8 | |
| 9 | PLplot is free software you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Library Public License as published |
| 11 | by the Free Software Foundation either version 2 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | PLplot is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU Library General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU Library General Public License |
| 20 | along with PLplot if not, write to the Free Software |
| 21 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 | --]] |
| 23 | |
| 24 | -- initialise Lua bindings for PLplot examples. |
| 25 | dofile("plplot_examples.lua") |
| 26 | |
| 27 | text = { "Maurice", "Geoffrey", "Alan", |
| 28 | "Rafael", "Vince" } |
| 29 | |
| 30 | -------------------------------------------------------------------------- |
| 31 | -- main |
| 32 | -- |
| 33 | -- Does a simple pie chart. |
| 34 | -------------------------------------------------------------------------- |
| 35 | |
| 36 | per = { 10, 32, 12, 30, 16 } |
| 37 | |
| 38 | -- Parse and process command line arguments |
| 39 | |
| 40 | pl.parseopts(arg, pl.PL_PARSE_FULL); |
| 41 | |
| 42 | -- Initialize plplot |
| 43 | |
| 44 | pl.init() |
| 45 | |
| 46 | pl.adv(0) |
| 47 | |
| 48 | -- Ensure window has aspect ratio of one so circle is |
| 49 | -- plotted as a circle. |
| 50 | pl.vasp(1) |
| 51 | pl.wind(0, 10, 0, 10) |
| 52 | pl.col0(2) |
| 53 | |
| 54 | -- n.b. all theta quantities scaled by 2*M_PI/500 to be integers to avoid |
| 55 | --floating point logic problems. |
| 56 | theta0 = 0 |
| 57 | dthet = 1 |
| 58 | for i = 1, 5 do |
| 59 | x = { 5 } |
| 60 | y = { 5 } |
| 61 | j = 2 |
| 62 | -- n.b. the theta quantities multiplied by 2*math.pi/500 afterward so |
| 63 | -- in fact per is interpreted as a percentage. |
| 64 | theta1 = theta0 + 5 * per[i] |
| 65 | if i == 5 then theta1 = 500 end |
| 66 | |
| 67 | for theta = theta0, theta1, dthet do |
| 68 | x[j] = 5 + 3 * math.cos(2*math.pi/500*theta) |
| 69 | y[j] = 5 + 3 * math.sin(2*math.pi/500*theta) |
| 70 | j = j + 1 |
| 71 | thetasave=theta |
| 72 | end |
| 73 | pl.col0(i) |
| 74 | pl.psty(math.mod((i + 2), 8) + 1) |
| 75 | pl.fill(x, y) |
| 76 | pl.col0(1) |
| 77 | pl.line(x, y) |
| 78 | just = 2*math.pi/500*(theta0 + theta1)/2 |
| 79 | dx = 0.25 * math.cos(just) |
| 80 | dy = 0.25 * math.sin(just) |
| 81 | if (theta0 + theta1)<250 or (theta0 + theta1)>750 then |
| 82 | just = 0 |
| 83 | else |
| 84 | just = 1 |
| 85 | end |
| 86 | |
| 87 | pl.ptex((x[(j-1)/2+1] + dx), (y[(j-1)/2+1] + dy), 1, 0, just, text[i]); |
| 88 | theta0 = thetasave |
| 89 | end |
| 90 | |
| 91 | pl.font(2) |
| 92 | pl.schr(0, 1.3) |
| 93 | pl.ptex(5, 9, 1, 0, 0.5, "Percentage of Sales") |
| 94 | |
| 95 | pl.plend() |
| 96 | |
| 97 |
