Created
November 13, 2008 16:45
-
-
Save collin/24488 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'redshift' | |
class RGraph | |
attr_accessor :meta, :canvas | |
def initialize config, json='"{}"' | |
@meta = Document['#meta'] | |
@canvas = Document['canvas'].first | |
config.each do |key, value| | |
`Config.#{key} = #{value}` | |
end | |
paint | |
`var that = this` | |
Document.add_listener :resize do | |
puts :SHIT | |
end | |
end | |
def click_handler el, name | |
el.html += "<p>#{name}</p>" | |
el.listen :click do |el, e| | |
`this.native.onClick(#{el.properties[:id]})` | |
end | |
end | |
def compute | |
`this.native.compute()` | |
end | |
def plot | |
`this.native.plot()` | |
end | |
def snatch_canvas | |
`this.canvas = new Canvas('infovis', '#ccddee', '#772277')` | |
end | |
def build_rgraph | |
`var that = this` | |
`var rgraph = this.native = new RGraph(this.canvas, { | |
onCreateLabel: function(el, node) { | |
var str = c$String.m$new(node.data.name); | |
that.m$send($s('click_handler'), $E(el), str); | |
} | |
})` | |
`this.native.loadGraphFromJSON(graph)` | |
end | |
def paint | |
canvas_width = Window.width - meta.size[:x] | |
self.canvas.properties[:width] = canvas_width | |
self.canvas.properties[:height] = Window.height | |
self.canvas.set_styles(:width => canvas_width+'px', | |
:height => Window.height | |
) | |
snatch_canvas | |
build_rgraph | |
compute | |
plot | |
end | |
end | |
Document.ready? do | |
rgraph = RGraph.new({ | |
'interpolation' => "'linear'", | |
'levelDistance' => 133, | |
'drawConcentricCircles' => 4, | |
'nodeRadius' => 1 | |
}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment