The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Using SVG in Borges

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
David Naseby

Posts: 40
Nickname: naseby
Registered: Jun, 2004

David Naseby is a coder from Sydney, who codes in Ruby far too much yet not nearly enough.
Using SVG in Borges Posted: Jun 16, 2004 10:44 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by David Naseby.
Original Post: Using SVG in Borges
Feed Title: naseby + ruby + stuff
Feed URL: http://homepages.ihug.com.au/~naseby/rss.xml
Feed Description: Random wanderings through Ruby.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by David Naseby
Latest Posts From naseby + ruby + stuff

Advertisement

I’ve just discovered Sean Russel’s SVG::Graph module, and I immediately had to play with it. If you don’t have an SVG plugin for your browser, you can pick up Adobe’s. I’ve just made the crudest possible embedding of a dynamically generated SVG into a Borges page, and I’m going to share it. If spike quality code offends you, turn away now….

....Really, this code is unhealthy, but it works. Turn away, squeamish souls….

Ok, you asked for it.

class SVGFrame < Borges::Component
  def render_content_on r

      require 'SVG/Graph/Schedule'

      title = "Project Schedule" 
      data1 = []
      @project.tasks.each do | task |
        data1 << task.name
        data1 << task.date_start.to_s
        data1 << task.date_due.to_s
      end

      graph = SVG::Graph::Schedule.new( {
                                       :width => 640,
                                       :height => 480,
                                       :graph_title => title,
                                       :show_graph_title => true,
                                       :no_css => true,
                                       :key => false,
                                       :scale_x_integers => true,
                                       :scale_y_integers => true,
                                       :show_data_labels => true,
                                       :show_y_guidelines => false,
                                       :show_x_guidelines => true,
                                       :show_x_title => true,
                                       :x_title => "Time",
                                       :show_y_title => false,
                                       :rotate_y_labels => true,
                                       :stagger_y_labels => true,
                                       :stagger_x_labels => true,
                                       :x_label_format => "%m/%d",
                                       :timescale_divisions => "1 weeks",
                                       :add_popups => true,
                                       :popup_format => "%m/%d/%y",
                                       :area_fill => true,
                                       :min_y_value => 0,
                                       })

      graph.add_data( 
                     :data => data1,
                     :title => "Data" 
                     )

      url = r.url_for_document graph.burn(), "text/xml" 
      r.text "" 
  end
end

This is clearly only a snippet – it assumes there’s a @project that contains tasks that have a name, a start date, and a due date, and also an infrastructure to run a Borges::Component. I need to wrap all this in some kind of Borges component to move away from the incredibly hackish and amateur r.text rendering of html. But it works! And its pretty. Thats awfully cool.

I’m this close to releasing a 0.0.1 quality Borges app for project management in the small. The final weeks of my current paying job are draining all of my time for now. By July, I will have left my current shop, and be on my own – I’m starting my own business. So if anyone out there needs some work done, you should contact me.

Read: Using SVG in Borges

Topic: Introduction to Ruby for Mac OS X Previous Topic   Next Topic Topic: RubyGems 0.3.0 Release

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use