macro barchart (sheet,block())
rem --- draws a bar chart from !BudgScratch.e3><b5 ---
rem --- sheet and block passed in by macro bartrigger ---
rem
rem --- declare variables ---
local rep,wind,i,leftflag,bottomflag,rightflag,topflag,xorigflag,yorigflag
local leftval,bottomval,rightval,topval,xorigval,yorigval
local yellow,red,green,black,colr(2)
rem
rem --- init variables ---
leftflag=0:bottomflag=1:rightflag=2:topflag=3:xorigflag=4:yorigflag=5
yellow=0x00ffff00:red=0x0000ff00:green=0x00ff0000:black=0x00
colr(0)=yellow:colr(1)=red:colr(2)=green
rep=graphcolours(0,yellow):rep=graphcolours(1,red):rep=graphcolours(2,green)
rem
rem --- draw chart, top level call ---
rep=selectsheet(sheet)
wind=graph(1,0,block,0,1,0,0,1,1,50,50,.4,1)
rem
rem --- annotate chart using level 3 calls ---
rightval=graphenquire(wind,rightflag)
topval=graphenquire(wind,topflag)-20
leftval=graphenquire(wind,leftflag)
bottomval=graphenquire(wind,bottomflag)
rep=font(wind,"System",18,32)
rep=text(wind,leftval,topval+80,"Income and Expenditure",black)
rep=text(wind,rightval+40,topval-20,"Key",black)
rep=text(wind,leftval-100,topval-200,"",black)
for i= 1 to 3
  rep=box(wind,rightval+40,topval-20-i*80,40,40,colr(i-1))
  rep=text(wind,rightval+120,topval-20-i*80,a3(i-1,0),black)
next i
rep=text(wind,20,bottomval-140,"Note:",black)
rep=text(wind,20,bottomval-200,"Click chart's full size icon, top right of window.",black)
rep=text(wind,20,bottomval-260,"Click chart's Quit icon when ready to go on.",black)
=wind
endmacro
$
macro bartrigger
local rep
rep=barchart("BudgScratch",b3><e5)
=rep
endmacro
$
macro boot_Budget
local rep
rep=selectsheet("Budget")
rep=contmacro("bartrigger",0)
rep=contmacro("pietrigger",1)
rep=addtomenu("piechart","piechart")
=rep
endmacro
$
macro fontcache (minsize)
rem --- checks current size of font cache, in K ---
rem --- if < minsize, returns True else returns False ---
local in(0),out(3),rep
in(0)=0:out(0)=0:out(1)=0:out(2)=0:out(3)=0
rep=sys("Font_CacheAddr",in,out)/1024
if out(2)/1024 < minsize then = 1 else = 0
endmacro
$
macro piechart (sheet,block())
rem --- pie chart from selected block (10.06.91) ---
rem
rem charts any column vector, but labels currently drawn from !Budget,
rem so results not sensible - edit references to labels as required
rem
rem --- declare variables ---
local window,rep,x(first(block)-1),rows,sysfont,lastseg
local pietotal,sf,radius,top,rt,startangle,endangle,pieangle,label,i
local yellow,red,green,lblue,black,colr(7)
local fawn,dkgreen,orange,midgrey,dkblue,white,bloggs
local xorigin,yorigin,solid,thin
rem
rem --- init variables ---
yellow=0x00ffff00:red=0x0000ff00:green=0x00ff0000:lblue=0xffbb0000:black=0x00
fawn=0xbbeeee00:dkgreen=0x00885500:orange=0x00bbff00:midgrey=0xbbbbbb00
dkblue=0x99440000:white=0xffffff00
colr(0)=yellow:colr(1)=red:colr(2)=green:colr(3)=lblue:colr(4)=fawn
colr(5)=dkgreen:colr(6)=orange:colr(7)=dkblue
solid=1:thin=2
rem
rem --- error check data block to chart, read into local array x() ---
if second(block)>1 then rep=reporterror("Error","Pie cannot chart more than one column",0x11):=rep
rows=first(block)
if rows=1 then rep=reporterror("Error","Please select at least two cells in a column - a pie of one cell simply shows that a number is 100% of itself!",0x11):=rep
for i=0 to rows-1
  x(i)=block(i,0)
next i
rep=min(x)
if rep<0 then rep=reporterror("Error","Pie cannot chart values less than zero",0x11):=rep
rep=max(x)
if rep=0 then rep=reporterror("Error","Pie cannot chart all zero values",0x11):=rep
rem
rem --- open graph window ---
window=gopen(0,0,0,1000,1000,0,0)
rep=lineattributes(window,solid,thin,white,0)
rep=box(window,0,0,1000,1000,white)
rem
rem --- calculate data-to-angle scale factor ---
rep=angle(0)
pietotal=sum(x):sf=360/pietotal
rem
rem --- plot pie ---
rep=lineattributes(window,solid,thin,black,0)
xorigin=350:yorigin=500:radius=200:startangle=0:endangle=0
top=yorigin+radius+50:rt=xorigin+radius+100
for i=0 to rows-1
  startangle=endangle
  pieangle=x(i)*sf:endangle=startangle+pieangle
  if abs(360-endangle)<0.5 then
    lastseg=i:i=rows-1
  else
    if pieangle>0 then
      rep=arc(window,xorigin,yorigin,startangle,endangle,radius,colr(i mod 8))
    endif
  endif
next i
rep=arc(window,xorigin,yorigin,startangle,360,radius,midgrey)
rem
rem --- label pie ---
sysfont=fontcache(16)
if sysfont then
  rep=font(window,"System",18,32)
  bloggs=15
else
  rep=font(window,"Trinity.Medium",40,60)
  bloggs=15
endif
rep=selectsheet(sheet)
label=a234
rep=text(window,xorigin-len(label)*bloggs,top,label,black): rem title
if sysfont then
  rep=font(window,"System",18,32)
else
  rep=font(window,"Trinity.Medium",32,48)
endif
rep=text(window,rt,top,"Key",black)
if lastseg>0 then
  for i= 0 to lastseg-1
    if x(i)>0 then
      rep=box(window,rt,top-100-i*80,40,40,colr(i mod 8))
      rep=text(window,rt+120,top-100-i*80,a235(i,0),black)
    endif
  next i
endif
rep=box(window,rt,top-100-i*80,40,40,midgrey)
rep=text(window,rt+120,top-100-i*80,a235(lastseg,0),black)
rep=font(window,"System",18,32)
rep=text(window,100,120,"Note:",black)
rep=text(window,100,80,"Click on chart's quit icon",black)
rep=text(window,100,40,"when ready to move on.",black)
=window
endmacro
$
macro pietrigger
local rep
rep=piechart("Budget",!Budget.f235><f238)
if iserror(rep) then rep=reporterror("Pie chart","Problem with pie chart: " cat rep,0x11)
=rep
endmacro
$$
