-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added HighMaps #92
Added HighMaps #92
Changes from 7 commits
196dba5
02237bf
634b1bb
75909cb
c293605
633be78
dc876d0
c242a7c
f423193
05e0e90
11479ed
b219f80
8d1449f
a801c65
5db05fa
2b15433
1b5990f
ba3dd19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
require_relative 'layout_helper_iruby' | ||
require_relative 'iruby_notebook' | ||
require 'daru/view/constants' | ||
|
||
module LazyHighCharts | ||
def self.init_script( | ||
dependent_js=['highstock.js', 'highcharts-more.js', 'modules/exporting.js', | ||
'highcharts-3d.js', 'modules/data.js'] | ||
dependent_js=[HIGHSTOCK, MAP, EXPORTING, HIGHCHARTS_3D, DATA] | ||
) | ||
# Highstock is based on Highcharts, meaning it has all the core | ||
# functionality of Highcharts, plus some additional features. So | ||
|
@@ -33,22 +33,25 @@ class HighChart | |
# | ||
def to_html(placeholder=random_canvas_id) | ||
chart_hash_must_be_present | ||
script = load_dependencies('web_frameworks') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So now each time dependencies will be loaded, whenever There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
# 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) | ||
script << high_map(placeholder, self) | ||
# When user wants to plot a HighStock | ||
elsif chart_class == 'StockChart' | ||
high_stock(placeholder, self) | ||
script << high_stock(placeholder, self) | ||
# When user wants to plot a HighChart | ||
elsif chart_class == 'Chart' | ||
high_chart(placeholder, self) | ||
script << high_chart(placeholder, self) | ||
end | ||
script | ||
end | ||
|
||
def show_in_iruby(placeholder=random_canvas_id) | ||
# TODO : placeholder pass, in plot#div | ||
load_dependencies('iruby') | ||
IRuby.html to_html_iruby(placeholder) | ||
end | ||
|
||
|
@@ -61,6 +64,47 @@ def to_html_iruby(placeholder=random_canvas_id) | |
high_chart_iruby(extract_chart_class, placeholder, self) | ||
end | ||
|
||
# Loads the dependent mapdata and dependent modules of the chart | ||
# | ||
# @param [String] to determine whether to load modules in IRuby or web | ||
# frameworks | ||
# @return [void, String] loads the initial script of the modules for IRuby | ||
# notebook and returns initial script of the modules for web frameworks | ||
def load_dependencies(type) | ||
dep_js = extract_dependencies | ||
if type == 'iruby' | ||
LazyHighCharts.init_iruby(dep_js) unless dep_js.nil? | ||
elsif type == 'web_frameworks' | ||
dep_js.nil? ? '' : LazyHighCharts.init_script(dep_js) | ||
end | ||
end | ||
|
||
# Extracts the required dependencies for the chart. User does not need | ||
# to provide any mapdata requirement explicity in the `options`. | ||
# MapData will be extracted using `options[:chart][:map]` already | ||
# provided by the user. In `modules` user needs to provide the required | ||
# modules (like tilemap in highcharts) in the form of Array. Once the | ||
# dependency is loaded on a page, there is no need to provide it again in | ||
# the `modules` option. | ||
# | ||
# @return [Array] the required dependencies (mapdata or modules) | ||
# to load the chart | ||
# rubocop:disable Metrics/AbcSize | ||
def extract_dependencies | ||
dep_js = [] | ||
# Mapdata dependencies | ||
if !options[:chart_class].nil? && options[:chart_class].capitalize == 'Map' | ||
dep_js.push('mapdata/' + options[:chart][:map].to_s + '.js') if | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. user input There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have kept the same folder structure provided in the highcharts dependencies. It is because the value provided by the user (it is in highcharts option and will be provided everytime user needs some mapdata dependency) in options[:chart][:map] will be the same as of the dependencies and by this folder structure it will be easy to retrieve the data. |
||
options[:chart] && options[:chart][:map] | ||
end | ||
# Dependencies provided in modules option (of highcharts mainly | ||
# like tilemap) by the user | ||
dep_js |= options.delete(:modules).map! { |js| "#{js}.js" } unless | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think , options created by us (like chart_class, modules, map ) must be in separate parameter. Only highcharts options must be passed as 2nd parameter. WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. User will put path for the js to load in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
options[:modules].nil? | ||
dep_js | ||
end | ||
# rubocop:enable Metrics/AbcSize | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you try to fix rubocop error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I tried removing it but the conditions are necessary. Please provide any suggestions to fix it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess, it must have method to check for map chart and chart class. if condition inside if condition looks bad. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried it earlier but still, there was rubocop error. I have separated out the method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO all the four conditions are necessary. Which one should I remove? |
||
|
||
# @return [String] the class of the chart | ||
def extract_chart_class | ||
# Provided by user and can take two values ('stock' or 'map'). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[HIGHSTOCK, MAP, EXPORTING, HIGHCHARTS_3D, DATA]
is also constant as web app highcharts dependencies.