Sha256: ee768cea46fdc563d09972d04fe6678455ea503a0cbb65f1b4c635aa83d9f06c

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

require 'erb'

module Nyaplot

  @@dep_libraries = {d3:'http://d3js.org/d3.v3.min'}
  @@additional_libraries = {}
  @@extension_lists = []

  def self.extension_lists
    @@extension_lists
  end

  # Tell JavaScript back-end library to load some extension libraries
  # @param [String] name The name of JavaScript extension library to load
  def self.add_extension(name)
    @@extension_lists.push(name)
  end

  # Load extension library to IRuby notebook after Nyaplotjs is loaded
  def self.add_dependency(name, url)
    @@dep_libraries[name]=url;
  end

  # Load extension library to IRuby notebook before Nyaplotjs is loaded
  def self.add_additional_library(name, url)
    @@additional_libraries[name]=url
  end

  # generate initializing code
  def self.generate_init_code
    path = File.expand_path("../templates/init.js.erb", __FILE__)
    template = File.read(path)
    dep_libraries = @@dep_libraries
    additional_libraries = @@additional_libraries
    js = ERB.new(template).result(binding)
    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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nyaplot-0.1.4 lib/nyaplot/core.rb
nyaplot-0.1.3 lib/nyaplot/core.rb
nyaplot-0.1.2 lib/nyaplot/core.rb
nyaplot-0.1.1 lib/nyaplot/core.rb