[wxruby-users] chart extension for wxRuby?

Ellis, Peter Peter_Ellis at nrel.gov
Thu Jan 31 14:47:04 EST 2008


That's fantastic!  I'll definitely took a closer look at this.

P

-----Original Message-----
From: wxruby-users-bounces at rubyforge.org
[mailto:wxruby-users-bounces at rubyforge.org] On Behalf Of Alex Fenton
Sent: Thursday, January 31, 2008 12:42 PM
To: General discussion of wxRuby
Subject: Re: [wxruby-users] chart extension for wxRuby?

Ellis, Peter wrote:
> Thanks, Alex.
>
> I was hoping that we wouldn't have to create our own, but we might do
it
> if that turns out to be the best solution.  I'll keep the list posted.

>   

Following your earlier message I had a closer look at Scruffy and Gruff.

Scruffy has the drawing code very nicely separated from the logic that 
organises the chart elements. So in about 20 mins I was able to replace 
enough of the svg-based drawing code with dc-based code to get it to 
draw the chart background, title, frame, axis and labels in a Wx::Window

(see below for the app code)

It's a fairly mechanical job of replacing calls to svg.text with 
dc.draw_text, svg.line with dc.draw_line etc in scruffy/components and 
scruffy/layers. I'm sure the individual chart types would need a little 
more work, but each is still only a couple of calls to the same basic 
methods. I would recommend looking into it.

hth
alex

__
require 'scruffy'
require 'wx'

class Chart < Wx::Window
  attr_reader :graph
  def initialize(*args)
    super
    evt_paint :on_paint
    @graph = Scruffy::Graph.new(:title => "Monthly Profits")
    graph.add(:line, 'John', [100, -20, 30, 60])
    graph.add(:line, 'Sara', [120, 50, -80, 20])
  end

  def on_paint
    paint do | dc |
      graph.render(dc, :width => size.width, :height => size.height)
    end
  end
end


Wx::App.run do
  frame = Wx::Frame.new(nil, :title => 'chart demo')
  chart = Chart.new(frame)
  frame.show
end



_______________________________________________
wxruby-users mailing list
wxruby-users at rubyforge.org
http://rubyforge.org/mailman/listinfo/wxruby-users


More information about the wxruby-users mailing list