Locate Previous Next Contents

Calling a Server

This topic is only really relevant if you have your web-server in APL, and don’t want to make all those detailed pages in advance. In this case, you need to be told which function to call to generate the required data on the fly, and of course you must pass the function the row/column index of the data which the user just clicked.

Here is the previous example again, but notice how much simpler the ch.Href call can be:

 dailytot„+š22 7 3½demand
 ch.Name 'mybar'
 ch.Set 'head' 'Total Demand for the Three Bread Products'
 ch.Set 'key' 'White' 'Brown' 'Organic'
 ch.Set 'xlab' 'Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday'
 ch.Href 'http://127.0.0.1/Barinfo'
 ch.Bar dailytot
 PG„ch.Close

If you are using the Dyadic web server, you might want to call #.Barinfo to generate the required page and return it via TCP/IP. Substitute the host name of your server for ‘127.0.0.1’ in the line above, or generate it dynamically:

 ‘home„2 ŒNQ'.' 'TCPGetHostID'
 cbk„'http://',‘home,'/Barinfo'
 ch.Href cbk

Of course this is useless without the row/column info, so this is precisely what Rain puts into the imagemap for you:

      png„0.6 PostScrp.MakePNG PG                    
      2œpng                            
<MAP name="mybar">
<area shape="rect" coords="28,88,33,163" href="http://127.0.0.1/Barinfo?row=1&col=1">
<area shape="rect" coords="60,97,65,163" href="http://127.0.0.1/Barinfo?row=2&col=1">
<area shape="rect" coords="91,99,97,163" href="http://127.0.0.1/Barinfo?row=3&col=1">
     ...
<area shape="rect" coords="172,139,178,163" href="http://127.0.0.1/Barinfo?row=5&col=3">
<area shape="rect" coords="204,138,209,163" href="http://127.0.0.1/Barinfo?row=6&col=3">
<area shape="rect" coords="236,158,241,163" href="http://127.0.0.1/Barinfo?row=7&col=3">
</MAP>

Now what you get passed as the right argument to #.Barinfo is a 2-column matrix:

   row  2
   col  3

... which makes it very easy to select the right data, format it and return a suitable result. There are several examples on the Dyadic DWS web site which use exactly this mechanism to generate pages on the fly, rather than making a complete ‘canned’ set in advance. Just for now, we can demonstrate a trivial function which just echos the numbers back in very basic HTML format.

htm„{sock} Barinfo tokens;row;col
(row col)„–¨tokens[;2]
htm„sws.Frame 'Demand was ',•dailytot[row;col]

Hopefully, you would do a little more error checking in a real-world system!

Targeting a Separate Frame
As you have probably noticed, this rapidly becomes a very irritating application to use, as the numbers completely replace the chart and you keep having to hit the “Back” button to check another data point. To have the result target a separate frame in the browser, you can simply add the frame name as part of the argument to ch.Href, separating it from the URL with ‘;’ ...

 ch.Href 'http://127.0.0.1/Barinfo;info'

This generates a very similar set of areas, but adding the frame target to the attributes:

<MAP name="mybar">
<area shape="rect" coords="28,88,33,163" href="http://127.0.0.1/Barinfo?row=1&col=1" target="info">

... so that the additional data can appear in a separate frame and the original chart remains visible to be clicked again. There is a nice example of this on the Causeway web site, where a 3-frame layout is used to explore the last 10 years rainfall and temperature data at Gilling.

These charts were all generated in advance, but you can easily see how the principle can be adapted to display information generated on the fly by your server.



Continue to: For the Future ... Let’s Do It in VML!
© Copyright Alan Sykes and Adrian Smith 1999