Skip to content

Commit

Permalink
Added HighMaps
Browse files Browse the repository at this point in the history
  • Loading branch information
Prakriti-nith committed May 19, 2018
1 parent 5b5d7bc commit 0314f9e
Show file tree
Hide file tree
Showing 15 changed files with 11,217 additions and 19 deletions.
40 changes: 34 additions & 6 deletions lib/daru/view/adapters/highcharts/display.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

module LazyHighCharts
def self.init_script(
dependent_js=['highstock.js', 'modules/exporting.js',
'highcharts-3d.js', 'modules/data.js']
dependent_js=['highstock.js', 'maps/modules/map.js', 'highcharts-more.js',
'modules/exporting.js', 'modules/tilemap.js', 'highcharts-3d.js',
'modules/data.js', 'maps/custom/europe.js', 'maps/custom/us-all.js',
'maps/custom/world.js']
)
# Highstock is based on Highcharts, meaning it has all the core
# functionality of Highcharts, plus some additional features. So
Expand Down Expand Up @@ -33,13 +35,23 @@ class HighChart
#
def to_html(placeholder=random_canvas_id)
chart_hash_must_be_present
high_chart(placeholder, self)
# Helps to denote either of the three classes.
chart_class = extract_chart_class
# When user wants to plot a HighMap
if chart_class == 'Map'
high_map(placeholder, self)
# When user wants to plot a HighStock
elsif chart_class == 'StockChart'
high_stock(placeholder, self)
# No need to pass any value for HighChart
else
high_chart(placeholder, self)
end
end

def show_in_iruby(placeholder=random_canvas_id)
# TODO : placeholder pass, in plot#div
chart_hash_must_be_present
IRuby.html high_chart_iruby(placeholder, self)
IRuby.html to_html_iruby(placeholder)
end

# This method is not needed if `to_html` generates the same code. Here
Expand All @@ -48,7 +60,23 @@ def show_in_iruby(placeholder=random_canvas_id)
def to_html_iruby(placeholder=random_canvas_id)
# TODO : placeholder pass, in plot#div
chart_hash_must_be_present
high_chart_iruby(placeholder, self)
high_chart_iruby(extract_chart_class, placeholder, self)
end

# @return [String] the class of the chart
def extract_chart_class
# Provided by user and can take two values ('stock' or 'map').
chart_class = options.delete(:chart_class).to_s.downcase unless
options[:chart_class].nil?
chart_class =
if chart_class == 'map'
'Map'
elsif chart_class == 'stock'
'StockChart'
else
'Chart'
end
chart_class
end

def chart_hash_must_be_present
Expand Down
6 changes: 4 additions & 2 deletions lib/daru/view/adapters/highcharts/iruby_notebook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ def self.generate_init_code(dependent_js)

# Enable to show plots on IRuby notebook
def self.init_iruby(
dependent_js=['highcharts.js', 'modules/exporting.js',
'highcharts-3d.js', 'modules/data.js']
dependent_js=['highstock.js', 'maps/modules/map.js', 'highcharts-more.js',
'modules/exporting.js', 'modules/tilemap.js', 'highcharts-3d.js',
'modules/data.js', 'maps/custom/europe.js', 'maps/custom/us-all.js',
'maps/custom/world.js']
)
# TODO: include highstock.js for highstock and modules/*.js files for
# exporting and getting data from various source like csv files etc.
Expand Down
26 changes: 16 additions & 10 deletions lib/daru/view/adapters/highcharts/layout_helper_iruby.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
module LazyHighCharts
module LayoutHelper
def high_chart_iruby(placeholder, object, &block)
def high_chart_iruby(chart_class, placeholder, object, &block)
object.html_options[:id] = placeholder
object.options[:chart][:renderTo] = placeholder
high_graph_iruby(placeholder, object, &block).concat(content_tag('div', '', object.html_options))
build_html_output_iruby(
chart_class, placeholder, object, &block
).concat(content_tag('div', '', object.html_options))
end

def high_graph_iruby(placeholder, object, &block)
build_html_output_iruby('Chart', placeholder, object, &block)
def high_map(placeholder, object, &block)
object.html_options[:id] = placeholder
object.options[:chart][:renderTo] = placeholder
build_html_output(
'Map', placeholder, object, &block
).concat(content_tag('div', '', object.html_options))
end

private
Expand All @@ -29,18 +35,18 @@ def encapsulate_js_iruby(core_js)
"#{js_start_iruby} #{core_js} #{js_end_iruby}"
# Turbolinks.version < 5
elsif defined?(Turbolinks) && request_is_referrer?
to_s(eventlistener_page_load)
eventlistener_page_load(core_js)
elsif defined?(Turbolinks) && request_turbolinks_5_tureferrer?
to_s(eventlistener_turbolinks_load)
eventlistener_turbolinks_load(core_js)
else
to_s(call_core_js)
call_core_js(core_js)
end

defined?(raw) ? raw(js_output) : js_output
end
# rubocop:enable Metrics/PerceivedComplexity

def eventlistener_page_load
def eventlistener_page_load(core_js)
<<-EOJS
#{js_start_iruby}
var f = function(){
Expand All @@ -52,7 +58,7 @@ def eventlistener_page_load
EOJS
end

def eventlistener_turbolinks_load
def eventlistener_turbolinks_load(core_js)
<<-EOJS
#{js_start_iruby}
document.addEventListener("turbolinks:load", function() {
Expand All @@ -62,7 +68,7 @@ def eventlistener_turbolinks_load
EOJS
end

def call_core_js
def call_core_js(core_js)
<<-EOJS
#{js_start_iruby}
#{core_js}
Expand Down
Loading

0 comments on commit 0314f9e

Please sign in to comment.