/usr/share/mozart/doc/wp/node34.html is in mozart-doc 1.4.0-8ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>6.2 Example: Drawing Bar Charts</TITLE><LINK href="ozdoc.css" rel="stylesheet" type="text/css"></HEAD><BODY><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node33.html#section.canvas.widgets"><< Prev</A></TD><TD><A href="node32.html">- Up -</A></TD><TD><A href="node35.html#section.canvas.tags">Next >></A></TD></TR></TABLE><DIV id="section.canvas.barchart"><H2><A name="section.canvas.barchart">6.2 Example: Drawing Bar Charts</A></H2><P> <A name="label289"></A>As a more interesting example let us consider a program to draw bar charts. The definition of a class to display barcharts is shown in <A href="node34.html#figure.canvas.barchart">Figure 6.1</A>. Before any item is created in the canvas by the method <CODE>bars</CODE>, the canvas widget is configured such that the scrollable region is just large enough for the barchart to be drawn. </P><P> </P><DIV id="figure.canvas.barchart"><HR><P><A name="figure.canvas.barchart"></A></P><A name="label291"></A><DL class="anonymous"><DD class="code"><CODE><SPAN class="keyword">local</SPAN> <BR> O=<SPAN class="keyword">if</SPAN> Tk<SPAN class="keyword">.</SPAN>isColor <SPAN class="keyword">then</SPAN> o(fill:wheat)<BR> <SPAN class="keyword">else</SPAN> o(stipple:gray50 fill:black)<BR> <SPAN class="keyword">end</SPAN> <BR> D=10 D2=2<SPAN class="keyword">*</SPAN>D B=10<BR><SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">class</SPAN> <SPAN class="type">BarCanvas</SPAN> <SPAN class="keyword">from</SPAN><SPAN class="type"> Tk.canvas</SPAN> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">DrawBars</SPAN>(Ys H X)<BR> <SPAN class="keyword">case</SPAN> Ys <SPAN class="keyword">of</SPAN> nil <SPAN class="keyword">then</SPAN> <SPAN class="keyword">skip</SPAN> <BR> <SPAN class="keyword">[]</SPAN> Y<SPAN class="keyword">|</SPAN>Yr <SPAN class="keyword">then</SPAN> <BR> {<SPAN class="keyword">self</SPAN> tk(create rectangle X H X<SPAN class="keyword">+</SPAN>D H<SPAN class="keyword">-</SPAN>Y<SPAN class="keyword">*</SPAN>D2 O)}<BR> {<SPAN class="keyword">self</SPAN> tk(create text X H<SPAN class="keyword">+</SPAN>D text:Y anchor:w)}<BR> {<SPAN class="keyword">self</SPAN> DrawBars(Yr H X<SPAN class="keyword">+</SPAN>D2)}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">configure</SPAN>(SX SY)<BR> {<SPAN class="keyword">self</SPAN> tk(configure scrollregion:q(B <SPAN class="keyword">~</SPAN>B SX<SPAN class="keyword">+</SPAN>B SY<SPAN class="keyword">+</SPAN>B))}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">bars</SPAN>(Ys)<BR> WY=D2<SPAN class="keyword">*</SPAN>({Length Ys}<SPAN class="keyword">+</SPAN>1) HY=D2<SPAN class="keyword">*</SPAN>({FoldL Ys Max 0}<SPAN class="keyword">+</SPAN>1)<BR> <SPAN class="keyword">in</SPAN> <BR> {<SPAN class="keyword">self</SPAN> configure(WY HY)}<BR> {<SPAN class="keyword">self</SPAN> DrawBars(Ys HY D)}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR><SPAN class="keyword">end</SPAN></CODE></DD></DL><P class="caption"><STRONG>Figure 6.1:</STRONG> A canvas for displaying bar charts.</P><HR></DIV><P> </P><P> The method <CODE>DrawBars</CODE> creates for each element of the list <CODE>Ys</CODE> a rectangle item as well as a text item, which both correspond to the value of the particular item. The value of <CODE>O</CODE> is used as option for the rectangle items. This value depends on <CODE>Tk<SPAN class="keyword">.</SPAN>isColor</CODE> which is <CODE><SPAN class="keyword">true</SPAN></CODE> if the screen is a color screen, and <CODE><SPAN class="keyword">false</SPAN></CODE> otherwise. For a color screen the rectangle items are filled with the color <CODE>wheat</CODE>. For a black and white screen, the rectangle items are drawn in a stippled fashion: only those pixels are drawn with the fill color (that is <CODE>black</CODE>) where the stipple bitmap contains a pixel. </P><P> <A href="node34.html#figure.canvas.usebar">Figure 6.2</A> shows how the bar chart canvas is used in order to display data. </P><P> </P><DIV id="figure.canvas.usebar"><HR><P><A name="figure.canvas.usebar"></A></P><P> </P><DIV align="center"><IMG alt="" src="barchart.gif"></DIV><P> <A name="label293"></A> </P><DL class="anonymous"><DD class="code"><CODE>C={New BarCanvas tkInit(parent:W bg:white width:300 height:120)}<BR>H={New Tk<SPAN class="keyword">.</SPAN>scrollbar tkInit(parent:W orient:horizontal)}<BR>V={New Tk<SPAN class="keyword">.</SPAN>scrollbar tkInit(parent:W orient:vertical)}<BR>{Tk<SPAN class="keyword">.</SPAN>addXScrollbar C H} {Tk<SPAN class="keyword">.</SPAN>addYScrollbar C V}<BR>{Tk<SPAN class="keyword">.</SPAN>batch [grid(C row:0 column:0)<BR> grid(H row:1 column:0 sticky:we)<BR> grid(V row:0 column:1 sticky:ns)]}<BR>{C bars([1 3 4 5 3 4 2 1 7 2 3 4 2 4 <BR> 5 6 7 7 8 4 3 5 6 7 7 8 4 3])}</CODE></DD></DL><P> </P><P class="caption"><STRONG>Figure 6.2:</STRONG> Using a canvas for drawing barcharts.</P><HR></DIV><P> </P></DIV><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node33.html#section.canvas.widgets"><< Prev</A></TD><TD><A href="node32.html">- Up -</A></TD><TD><A href="node35.html#section.canvas.tags">Next >></A></TD></TR></TABLE><HR><ADDRESS><A href="http://www.ps.uni-sb.de/~schulte/">Christian Schulte</A><BR><SPAN class="version">Version 1.4.0 (20110908185330)</SPAN></ADDRESS></BODY></HTML>
|