Module: LazyHighCharts

Defined in:
lib/daru/view/adapters/highcharts/display.rb,
lib/daru/view/adapters/highcharts/iruby_notebook.rb,
lib/daru/view/adapters/highcharts/layout_helper_iruby.rb

Defined Under Namespace

Modules: LayoutHelper Classes: HighChart

Class Method Summary collapse

Class Method Details

.generate_init_code(dependent_js) ⇒ Object

generate initializing code



5
6
7
8
9
10
11
12
13
14
# File 'lib/daru/view/adapters/highcharts/iruby_notebook.rb', line 5

def self.generate_init_code(dependent_js)
  js_dir = File.expand_path(
    '../../../../../vendor/assets/javascripts/highcharts', __dir__
  )
  path = File.expand_path(
    '../../templates/highcharts/init.inline.js.erb', __dir__
  )
  template = File.read(path)
  ERB.new(template).result(binding)
end

.generate_init_code_css(dependent_css) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/daru/view/adapters/highcharts/iruby_notebook.rb', line 16

def self.generate_init_code_css(dependent_css)
  css_dir = File.expand_path(
    '../../../../../vendor/assets/stylesheets/highcharts', __dir__
  )
  path = File.expand_path(
    '../../templates/highcharts/init.inline.css.erb', __dir__
  )
  template = File.read(path)
  ERB.new(template).result(binding)
end

.init_css(dependent_css = HIGHCHARTS_DEPENDENCIES_CSS) ⇒ String

Loads the dependent css required in styled mode

Parameters:

  • dependent (Array)

    css files required

Returns:

  • (String)

    CSS code of the dependent file(s)



31
32
33
34
35
36
37
38
39
# File 'lib/daru/view/adapters/highcharts/display.rb', line 31

def self.init_css(
  dependent_css=HIGHCHARTS_DEPENDENCIES_CSS
)
  css =  ''
  css << "\n<style type='text/css'>"
  css << LazyHighCharts.generate_init_code_css(dependent_css)
  css << "\n</style>"
  css
end

.init_iruby(dependent_js = HIGHCHARTS_DEPENDENCIES_IRUBY) ⇒ Object

Enable to show plots on IRuby notebook



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/daru/view/adapters/highcharts/iruby_notebook.rb', line 28

def self.init_iruby(
  dependent_js=HIGHCHARTS_DEPENDENCIES_IRUBY
)
  # TODO: include highstock.js for highstock and modules/*.js files for
  # exporting and getting data from various source like csv files etc.
  #
  # Highstock.js includes the highcharts.js, so only one of them required.
  # see: https://www.highcharts.com/errors/16
  #
  # Using Highmaps as a plugin for HighCharts so using map.js instead of
  # highmaps.js
  #
  # , 'modules/exporting.js' : for the exporting button
  # data.js for getting data as csv or html table.
  # 'highcharts-more.js' : for arearange and some other chart type
  # 'modules/offline-exporting.js': for enabling offline exporting. Used in
  #  #chart.extract_export_code method (to enable chart.exportChartLocal)
  #  to export the chart using code.
  # Note: Don't reorder the dependent_js elements. It must be loaded in
  # the same sequence. Otherwise some of the JS overlap and doesn't work.
  js = generate_init_code(dependent_js)
  IRuby.display(IRuby.javascript(js))
end

.init_javascript(dependent_js = HIGHCHARTS_DEPENDENCIES_WEB) ⇒ String

Loads the dependent javascript required

Parameters:

  • dependent (Array)

    js files required

Returns:

  • (String)

    js code of the dependent files



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/daru/view/adapters/highcharts/display.rb', line 10

def self.init_javascript(
  dependent_js=HIGHCHARTS_DEPENDENCIES_WEB
)
  # Highstock is based on Highcharts, meaning it has all the core
  # functionality of Highcharts, plus some additional features. So
  # highstock.js contains highcharts.js .If highstock.js is removed then
  # add highchart.js to make chart script work.
  #
  # Note: Don't reorder the dependent_js elements. It must be loaded in
  # the same sequence. Otherwise some of the JS overlap and doesn't work.
  js = ''
  js << "\n<script type='text/javascript'>"
  js << LazyHighCharts.generate_init_code(dependent_js)
  js << "\n</script>"
  js
end

.init_scriptString

Loads the dependent code required in styled mode

Returns:

  • (String)

    code of the dependent css and js file(s)



44
45
46
47
48
49
# File 'lib/daru/view/adapters/highcharts/display.rb', line 44

def self.init_script
  init_code = ''
  init_code << init_css
  init_code << init_javascript
  init_code
end