PieChart := proc(Lp::{Array, array, list}) option `Maple Advisor Database 1.01 for Maple 6`, `Copyright (c) 2000 by Robert B. Israel. All rights reserved`; local i, o, t, r, rh, rl, res, base, L, opts, cols, labs, expl; L := evalf(convert(Lp, list)); if not type(L, list(positive)) then error "list member not a positive number: ", op(1, remove(type, L, positive)) end if; opts := NULL; cols := NULL; labs := []; expl := []; for o in args[2 .. nargs] do if type(o, `=`) then if op(1, o) = 'labels' then if type(op(2, o), list) then labs := op(2, o); if nops(labs) < nops(L) then error cat("too few labels: ",nops(labs)," for ",nops(L), " items") fi; else error "labels option must be a list" end if elif member(op(1, o), {'colour', 'color', 'colours', 'colors'}) then if type(op(2, o), list) then cols := op(2, o); if nops(cols) < nops(L) then error cat("too few colours: ",nops(cols)," for ",nops(L), " items") fi; else error op(1, o), "option must be a list" end if elif op(1, o) = 'explode' then if type(op(2, o), integer) then expl := [op(2, o)] elif type(op(2, o), list) then expl := op(2, o) else error "explode option needs an integer or list" end if else opts := opts, o end if else opts := opts, o end if end do; opts := `plot/options2d`(opts, scaling = constrained, axes = NONE); if cols = NULL then cols := [seq(COLOUR(HUE, (i-1/2)/nops(L)), i = 1 .. nops(L))] end if; if expl = [] then rl := 1.2 else rl := 1.4 end if; t := evalf(2*Pi/convert(L, `+`)); r := evalf(1/2*Pi); res := NULL; for i to nops(L) do rh := r - 1/2*t*L[i]; if member(i, expl) then base := evalf(.2*[cos(rh), sin(rh)]) else base := [0, 0] end if; res := res, plottools[pieslice](base, 1, r - t*L[i] .. r, colour = cols[i]); if i <= nops(labs) then res := res, op( plots[textplot]([rl*cos(rh), rl*sin(rh), labs[i]])) end if; r := r - t*L[i] end do; PLOT(res, opts) end proc;