Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Polymorphic graph widget problem
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Matt Gushee <matt@g...>
Subject: Re: [Caml-list] Polymorphic graph widget problem
On Fri, Aug 29, 2003 at 12:54:46PM +0100, Richard Jones wrote:
> As part of a project I'm doing at the moment, I've written a Gtk graph
> widget using lablgtk. The graph currently plots ints, so the type
> looks something like this:

Hi, Richard--

I am working on a vaguely similar application. I say vaguely, because
the problem domain is very similar, but the practical constraints are
very different: my application also creates charts based on numeric (and
textual) data, but the input will usually be represented as strings (SQL
results and maybe XML data sets) and creates bitmap graphics for the
web. So my approach is necessarily quite different from yours, and I
don't know if any of my techniques will be useful to you. But just in
case it will help, let me briefly describe what I am doing.

 * The two main active components in the system are the module types
   CHART_TYPE and RENDERER, defined as follows:

   module type CHART_TYPE =
       type t
       val create : string list list -> t
       val drawing : t -> cp_drawing
       val raw_drawing : t -> cp_drawing   (* W/O labels, axes, etc. -
                                              useful for composite
                                              charts *)

   module type RENDERER =
       type t
       val create : output_spec -> style -> t
       val reset : t -> output_spec -> t
       val render : cp_drawing -> unit

 * All modules conforming to CHART_TYPE will produce an instance of
   the 'cp_drawing' type, which is then passed to a RENDERER to
   produce an actual image. The 'cp_drawing' type represents an 
   abstract drawing--by which I mean that it includes shapes such as
   Rectangle, Ellipse, and so on, but all dimensions are expressed in
   an abstract way, and graphical properties such as line width, fill,
   etc. are unspecified (see example below).

 * All numbers are handled internally as floats. Whether they are 
   *displayed* as floats or integers will be based on a style specified
   by the user, who presumably knows which is most appropriate to the
   data being charted.

EXAMPLE (this is an actual toplevel session, edited for clarity)

    (* Create a chart, then a drawing based on it. *)
    let data = [["A";"121.8"];["B";"84.3"];["C";"98"];["D";"108.5"]];;
    let ch = SimpleColumnChart.create data;;
    let dr = SimpleColumnChart.drawing ch;;
    val dr : Chartpak.cp_drawing =
      {drawing_id = "simple_column_chart"; components = <abstr>}

    (* Here are the components--first the four columns *)
    {id = "rect-0"; tags = []; label = SingleLabel "A";
      figure = Rectangle (Slot 1, Start, AutoSizeCentered, Length 121.8)}
    {id = "rect-1"; tags = []; label = SingleLabel "B";
      figure = Rectangle (Slot 2, Start, AutoSizeCentered, Length 84.3)}
    {id = "rect-2"; tags = []; label = SingleLabel "C";
      figure = Rectangle (Slot 3, Start, AutoSizeCentered, Length 98.)}
    {id = "rect-3"; tags = []; label = SingleLabel "D";
      figure = Rectangle (Slot 4, Start, AutoSizeCentered, Length 108.5)}

    (* And here are the vertical and horizontal axes. Note that the 
       length of the vertical axis is wrong -- it should be at least as 
       long as the longest column. Thanks for helping me discover this 
       bug! *)
    {id = "line-0"; tags = []; label = FloatSeries (0., 100., 10.);
      figure = Line (Start, Start, AutoSizeCentered, Length 100.)}
    {id = "line-1"; tags = []; label = NoLabel;
      figure = Line (Start, Start, SpanTo (Slot 4), AutoSizeCentered)}
Matt Gushee                 When a nation follows the Way,
Englewood, Colorado, USA    Horses bear manure through           its fields;   When a nation ignores the Way,
                            Horses bear soldiers through
                                its streets.
                            --Lao Tzu (Peter Merel, trans.)

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: