Data type coercion

The emphasis in Waterloo is on producing a chart library for use in science - and particularly to support its use from environments such as MATLAB and R.

In these environments, data is most naturally stored in vectors and matrices i.e. as primitive arrays at the programming level.

A basic design feature of the Waterloo graphics routines is that it also uses arrays to represent data. This allows for fast exchange of data between the visualisation tools in Waterloo and data processing packages running in the same Java Virtual Machine.


The default data type for representing data in Waterloo plots is
  1. As a boxed java.lang.Double[] - for xData and yData
  2. As a primitive double[] - for all other vectors

The Groovy API always attempts to coerce user-supplied data to type double[]. This means that users of properly object-oriented languages such as Java, Groovy and Scala can take advantage of the OOP features of those languages. The following code can be used in Groovy:

                    import kcl.waterloo.plot.WPlot
                    p=WPlot.scatter(['XData', 1..10, 'YData', 1..10])
                    
because the IntRange variables (specified as "1..10") will be coerced to double[]'s when passed to the Java API.