[wxruby-users] chart extension for wxRuby?
Alex Fenton
alex at pressure.to
Thu Jan 31 14:41:58 EST 2008
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
More information about the wxruby-users
mailing list