Skip to content

Instantly share code, notes, and snippets.

@collin
Created November 13, 2008 16:45
Show Gist options
  • Save collin/24488 to your computer and use it in GitHub Desktop.
Save collin/24488 to your computer and use it in GitHub Desktop.
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