Skip to content

Understanding daru view adapter concept

Shekhar Prasad Rajak edited this page Sep 1, 2017 · 2 revisions

daru-view uses the adapter design pattern and try composite design pattern, if needed.

  • Adapter pattern’s motivation is that we can reuse existing gems if we can modify the interface.

  • Daru-view joins functionalities of independent or incompatible interfaces of different gems.

How adapter is used in daru-view

Set library globally

User can set the plotting_library and table_library globally using following line :

 Daru::View.plotting_library = :libray_name   # library_name can be :nyaplot, :highcharts, :googlecharts 
 Daru::View.table_library = :libray_name   # library_name can be :googlecharts, :data_tables

Note: Google charts tools has both plotting and table drawing features. So adding google chart as plotting library automatically set it as table_library as well.

What it does internally :

When user set the library in IRuby notebook, all the dependent js files is loaded for that iruby notebook. So only that library's chart script will work. It loads the JS files only once (not each time of the chart generation).

When user is in web application then user must load the js files in the layout of the application (must execute below line), mostly on head tag of the web page :

 Daru::View.dependent_script(:library_name)   # library_name can be :googlecharts, :highcharts, :nyaplot, :datatables

Above line will load the dependent js for the library on that layout file. You can load the multiple library js files similar way on the same web page. User can see the examples present in spec/dummy_rails, sinatra, nanoc for better understanding.

Set it for particular object only

daru-view Plot and Table can take one of the option adapter, which will set the adapter for the particular object of these class.

Note: Since we know that setting library (say A) load the dependent JS of the only library (A). So if user have to take care of dependent js files that are loaded in the webpage or iruby notebook. If the js file of the particular library is not loaded then must load it as well using the above concept.

  • Define common objects and use it for defining composite objects.
Clone this wiki locally