From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA01025; Fri, 29 Aug 2003 20:30:54 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA05115 for ; Fri, 29 Aug 2003 20:30:52 +0200 (MET DST) Received: from mz2.forethought.net (mzpi4.forethought.net [216.241.36.13]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h7TIUoT00227 for ; Fri, 29 Aug 2003 20:30:51 +0200 (MET DST) Received: from [216.241.35.41] (helo=swordfish) by mz2.forethought.net with esmtp (Exim 4.14) id 19so1J-0000fs-JR for caml-list@inria.fr; Fri, 29 Aug 2003 12:30:49 -0600 Received: from matt by swordfish with local (Exim 3.35 #1 (Debian)) id 19so1A-0004Jo-00 for ; Fri, 29 Aug 2003 12:30:40 -0600 Date: Fri, 29 Aug 2003 12:30:35 -0600 From: Matt Gushee To: caml-list@inria.fr Subject: Re: [Caml-list] Polymorphic graph widget problem Message-ID: <20030829183035.GF569@swordfish> Reply-To: Matt Gushee Mail-Followup-To: caml-list@inria.fr References: <20030829115446.GA879@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030829115446.GA879@redhat.com> User-Agent: Mutt/1.3.27i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; gushee:01 gushee:01 caml-list:01 widget:01 widget:01 lablgtk:01 plots:01 vaguely:01 vaguely:01 textual:01 renderer:01 val:01 val:01 renderer:01 conforming:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 = sig 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 *) end module type RENDERER = sig type t val create : output_spec -> style -> t val reset : t -> output_spec -> t val render : cp_drawing -> unit end * 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 = } (* 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 mgushee@havenrock.com its fields; http://www.havenrock.com/ When a nation ignores the Way, Horses bear soldiers through its streets. --Lao Tzu (Peter Merel, trans.) ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners