Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ group :development do
gem "rspec", "~> 2.99.0"
gem "appraisal"
gem "rails", "~> 4.2.1"
gem 'json'
gem 'byebug'
gem 'iruby'
end
2 changes: 2 additions & 0 deletions lib/google_visualr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# Common
require "#{lib_path}/google_visualr/param_helpers"
require "#{lib_path}/google_visualr/display"
require "#{lib_path}/google_visualr/iruby_notebook"

# Base Classes
require "#{lib_path}/google_visualr/data_table"
Expand Down
10 changes: 10 additions & 0 deletions lib/google_visualr/base_chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module GoogleVisualr

class BaseChart
include GoogleVisualr::ParamHelpers
include GoogleVisualr::Display

DEFAULT_VERSION = "1.0".freeze

Expand Down Expand Up @@ -95,6 +96,15 @@ def draw_js(element_id)
js << "\n };"
js
end

def show_in_html(dom=nil)
show_html(self, dom)
end

def show_in_iruby(dom=nil)
show_iruby(self, dom)
end

end

end
1 change: 1 addition & 0 deletions lib/google_visualr/data_table.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'json'
module GoogleVisualr

class DataTable
Expand Down
32 changes: 32 additions & 0 deletions lib/google_visualr/display.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'securerandom'
require 'erb'

module GoogleVisualr
module Display

def show_script(chart, dom=nil, options={})
script_tag = options.fetch(:script_tag) { true }
if script_tag
chart.to_js(dom)
else
html = ""
html << chart.load_js(dom)
html << chart.draw_js(dom)
html
end
end

def show_html(chart, id=nil, options={})
path = File.expand_path("../templates/chart_div.erb", __FILE__)
template = File.read(path)
id ||= SecureRandom.uuid()
chart_script = show_script(chart, id, script_tag: false)
ERB.new(template).result(binding)
end

def show_iruby(chart, dom=nil)
IRuby.html(show_html(chart, dom))
end

end
end
17 changes: 17 additions & 0 deletions lib/google_visualr/iruby_notebook.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module GoogleVisualr

# generate initializing code
def self.generate_init_code
js_dir = File.expand_path("../js", __FILE__)
path = File.expand_path("../templates/init.inline.js.erb", __FILE__)
template = File.read(path)
ERB.new(template).result(binding)
end

# Enable to show plots on IRuby notebook
def self.init_iruby
js = self.generate_init_code
IRuby.display(IRuby.javascript(js))
end

end
44 changes: 44 additions & 0 deletions lib/google_visualr/js/google_visualr.js

Large diffs are not rendered by default.

225 changes: 225 additions & 0 deletions lib/google_visualr/js/loader.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions lib/google_visualr/notebook_example/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source "http://rubygems.org"

# iruby dependencies
gem 'rbczmq'
gem 'ffi-rzmq'
gem 'iruby'

gemspec :path => '../../../'
35 changes: 35 additions & 0 deletions lib/google_visualr/notebook_example/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
PATH
remote: ../../..
specs:
google_visualr (2.5.1)

GEM
remote: http://rubygems.org/
specs:
bond (0.5.1)
data_uri (0.1.0)
ffi (1.9.18)
ffi-rzmq (2.0.5)
ffi-rzmq-core (>= 1.0.6)
ffi-rzmq-core (1.0.6)
ffi
iruby (0.3)
bond (~> 0.5)
data_uri (~> 0.1)
mimemagic (~> 0.3)
multi_json (~> 1.11)
mimemagic (0.3.2)
multi_json (1.12.1)
rbczmq (1.7.9)

PLATFORMS
ruby

DEPENDENCIES
ffi-rzmq
google_visualr!
iruby
rbczmq

BUNDLED WITH
1.15.1
3,124 changes: 3,124 additions & 0 deletions lib/google_visualr/notebook_example/google_visualr_examples.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/google_visualr/param_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'date'
module GoogleVisualr

module ParamHelpers
Expand Down
4 changes: 4 additions & 0 deletions lib/google_visualr/templates/chart_div.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div id='<%= id %>'></div>
<script>
<%= chart_script %>
</script>
15 changes: 15 additions & 0 deletions lib/google_visualr/templates/init.inline.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

<%
Dir.foreach(js_dir) do |item|
next if item == '.' or item == '..'
contents = IO.read(File.join(js_dir, item), mode: 'r:UTF-8')
%>
/* BEGIN <%= item %>.js */
<%= contents %>
/* END <%= item %>.js */
<% end %>

var event = document.createEvent("HTMLEvents");
event.initEvent("load_googlecharts", false, false);
window.dispatchEvent(event);
console.log("Finish loading google chart js");