70 CHAPTER5. OBJECTSANDGRAPHICS
objects.WhencreatingText, wespecifytheanchorpoint(thepointthetextis centeredon)andthestringto
useasthelabel.
Thelabelstringsareeasy. Ourlongestlabelis five characters,andthelabelsshouldalllineuponthe
rightsideofa column,sotheshorterstringswillbepaddedontheleftwithspaces.Theplacementofthe
labelsis chosenwitha bitofcalculationandsometrialanderror. Playingwithsomeinteractive examples,
it seemsthata stringoflengthfive looksnicelypositionedinthehorizontaldirectionplacingthecenter 20
pixelsinfromtheleftedge.Thisleavesjusta bitofwhitespaceat themargin.
Intheverticaldirection,wehave justover 200 pixelstoworkwith.Asimplescalingwouldbetohave
100 pixelsrepresent$5,000.Thatmeansourfive labelsshouldbespaced 50 pixelsapart.Using 200 pixels
fortherange0–10,000leaves 240 200 40 pixelstosplitbetweenthetopandbottommargins.We might
wanttoleave a littlemoremarginatthetoptoaccommodatevaluesthatgrowbeyond$10,000. Alittle
experimentationsuggeststhatputtingthe“ 0.0K”label 10 pixelsfromthebottom(position230)seemsto
looknice.
Elaboratingouralgorithmtoincludethesedetails,thesinglestep
Draw scale labels on leftside of window
becomesa sequenceofsteps
Draw label " 0.0K"at (20, 230)
Draw label " 2.5K"at (20, 180)
Draw label " 5.0K"at (20, 130)
Draw label " 7.5K"at (20, 80)
Draw label "10.0K"at (20, 30)
Thenextstepintheoriginaldesigncallsfordrawingthebarthatcorrespondstotheinitialamountofthe
principal.It is easytoseewherethelowerleftcornerofthisbarshouldbe.Thevalueof$0.0is located
verticallyat pixel 230,andthelabelsarecentered 20 pixelsinfromtheleftedge.Addinganother 20 pixels
getsusto therightedgeofthelabels.Thusthelowerleftcornerofthe0thbarshouldbeat location
40 230 .
Nowwejustneedtofigureoutwheretheopposite(upperright)cornerofthebarshouldbesothatwe
candraw anappropriaterectangle.Intheverticaldirection,theheightofthebaris determinedbythevalue
ofprincipal. Indrawingthescale,wedeterminedthat 100 pixelsis equalto$5,000.Thismeansthat
wehave 100
5000 0 02 pixelstothedollar. Thistellsus,forexample,thata principalof$2,000should
producea barofheight 2000