lib/nyaplot/core.rb in nyaplot-0.1.6 vs lib/nyaplot/core.rb in nyaplot-0.2.0.rc1

- old
+ new

@@ -1,13 +1,10 @@ require 'erb' module Nyaplot - @@dep_libraries = { - d3:'https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min', - downloadable: 'http://cdn.rawgit.com/domitry/d3-downloadable/master/d3-downloadable' - } + @@dep_libraries = {d3:'http://d3js.org/d3.v3.min'} @@additional_libraries = {} @@extension_lists = [] def self.extension_lists @@extension_lists @@ -37,13 +34,56 @@ additional_libraries = @@additional_libraries js = ERB.new(template).result(binding) js end + def self.start_debug(port=9996) + require 'webrick' + path = File.expand_path("../../../nyaplotjs/release", __FILE__) + `ruby -e httpd #{path} -p #{port}` + + js = self.generate_init_code + js.gsub!("http.+nyaplot.js", "http://localhost:" + port.to_s + "/nyaplot.js") + IRuby.display(IRuby.javascript(js)) + end + # Enable to show plots on IRuby notebook def self.init_iruby js = self.generate_init_code IRuby.display(IRuby.javascript(js)) end - init_iruby if defined? IRuby + # Create multi-column layout + # @example + # include Nyaplot + # p1 = Plot.add(:scatter, x1, y1) + # p2 = Plot.add(:line, x2, y2) + # columns(p1, p2).draw + # + def columns(*plots) + panes = plots.map{|p| p.pane} + plot = Plot.new + plot.pane = Pane.columns(*panes) + plot + end + + # Create multi-row layout + # @example + # include Nyaplot + # p1 = Plot.add(:scatter, x1, y1) + # p2 = Plot.add(:line, x2, y2) + # p3 = Plot.add(:bar, x3, y3) + # rows(columns(p1, p2), p3).draw + # + def rows(*plots) + panes = plots.map{|p| p.pane} + plot = Plot.new + plot.pane = Pane.rows(*panes) + plot + end + + if $DEBUG_NYAPLOT == true + start_debug + else + init_iruby if defined? IRuby + end end