Next Previous Up Contents
Next: RESTful API
Up: Plot Service
Previous: Plot Service

#### 11.1.1 Usage

The best way to see how the plot service can be used is to run the service (most simply by executing `stilts server`), and look at the running plot examples, along with their HTML source code, served from the server endpoint.

However this section gives a brief independent overview of how the service can be used. The PlotServlet itself exposes a RESTful API as described in Section 11.1.2. This offers the services required for client HTML/JavaScript code running in a browser to set up a plot based on server-side (or at least server-accessible) table data, and to make updates to it following user activity like mouse gestures.

A basic client JavaScript library named `plot2Lib.js`, that facilitates this plot setup is included with STILTS; it can be found in the `stilts.jar` file at `uk/ac/starlink/ttools/server/plot2Lib.js`, and is available from the running server at `<plot-service-base>/plot2Lib.js`. It exports some variables in the `plot2` namespace; see comments in the file itself for documentation of how to use it. A minimal web page using this to present an interactive plot might look like:

       <html>
       <script src="plot2Lib.js"></script>
       <script>
          var serverUrl = "http://localhost:2112/stilts/plot/";
          onload = function() {
             var plotTxt = plot2.wordsToPlotTxt([
                "plot2sky",
                "layer1=mark",
                "in1=/data/catalogue.fits",
                "lon1=RA",
                "lat1=DEC"
             ]);
             var plotNode = plot2.createPlotNode(serverUrl, plotTxt);
             document.getElementsByTagName("body")[0].appendChild(plotNode);
          };
       </script>
       </html>

In this case the data file "`/data/catalogue.fits`" has to be available to the servlet; how this is arranged depends on the way the service is deployed.

JavaScript clients don't have to use the `plot2Lib.js` library; it's also possible to write custom code that talks to the RESTful API described in Section 11.1.2.

Next Previous Up Contents
Next: RESTful API
Up: Plot Service
Previous: Plot Service

STILTS - Starlink Tables Infrastructure Library Tool Set
Starlink User Note256
STILTS web page: http://www.starlink.ac.uk/stilts/
Author email: m.b.taylor@bristol.ac.uk
Mailing list: topcat-user@jiscmail.ac.uk