Skip to content

Commit d523244

Browse files
committed
Added docs
1 parent fddc318 commit d523244

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

lib/daru/view/adapters/datatables.rb

+70-1
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,96 @@ module DatatablesAdapter
1111

1212
# Read : https://datatables.net/ to understand
1313
# the datatables option concept.
14+
# Along with these options, a user can provide an additional option
15+
# html_options[:table_options] to cistomize the generated table
16+
# See the specs of daru-data_tables gem.
1417
#
15-
# TODO : this docs must be improved
18+
# @param data [Array, Daru::DataFrame, Daru::Vector] The data provided
19+
# by the user to generate the datatable
20+
# @param options [Hash] Various options provided by the user to
21+
# incorporate in datatable
22+
# @return [Daru::DataTables::DataTable] Returns the datatble object
23+
#
24+
# @example DataTable
25+
# Set Daru::View.table_library = :googlecharts (or set adapter option)
26+
# (Also set Daru::View.dependent_script(:googlecharts) in web
27+
# frameworks in head tag)
28+
# Formulate the data to visualize
29+
# idx = Daru::Index.new ['Year', 'Sales']
30+
# data_rows = [
31+
# ['2004', 1000],
32+
# ['2005', 1170],
33+
# ['2006', 660],
34+
# ['2007', 1030]
35+
# ]
36+
# df_sale_exp = Daru::DataFrame.rows(data_rows)
37+
# df_sale_exp.vectors = idx
38+
#
39+
# Set the options required
40+
# options1 = {
41+
# html_options: {
42+
# table_options: {
43+
# table_thead: "<thead>
44+
# <tr>
45+
# <th></th>
46+
# <th>C1</th>
47+
# <th>C2</th>
48+
# </tr>
49+
# </thead>",
50+
# width: '90%'
51+
# }
52+
# },
53+
# scrollX: true
54+
# }
55+
# options2 = {searching: false}
56+
#
57+
# Draw the Daru::View::Table object.
58+
# table = Daru::View::Table.new(df_sale_exp, options1)
59+
# table2 = Daru::View::Table.new(df_sale_exp, options2)
60+
# table3 = Daru::View::Table.new(df_sale_exp)
1661
def init_table(data=[], options={})
1762
@table = Daru::DataTables::DataTable.new(data, options)
1863
@table
1964
end
2065

66+
# @return [String] returns code of the dependent JS and CSS file(s)
2167
def init_script
2268
Daru::DataTables.init_script
2369
end
2470

71+
# @param table [Daru::DataTables::DataTable] table object to access
72+
# daru-data_table methods
73+
# @return [String] script and table (containg thead only) tags of the
74+
# datatable generated
2575
def generate_body(table)
2676
table.to_html
2777
end
2878

79+
# @param table [Daru::DataTables::DataTable] table object to access
80+
# daru-data_table methods
81+
# @return [void] writes the html code of the datatable to the file
82+
# @example
83+
# table = Daru::View::Table.new(data, options)
84+
# table.export_html_file
2985
def export_html_file(table, path='./table.html')
3086
path = File.expand_path(path, Dir.pwd)
3187
str = generate_html(table)
3288
File.write(path, str)
3389
end
3490

91+
# @param table [Daru::DataTables::DataTable] table object to access
92+
# daru-data_table methods
93+
# @return [void] shows the datatable in IRuby notebook
94+
# @example
95+
# table = Daru::View::Table.new(data, options)
96+
# table.show_in_iruby
3597
def show_in_iruby(table)
3698
table.show_in_iruby
3799
end
38100

101+
# @param table [Daru::DataTables::DataTable] table object to access
102+
# daru-data_table methods
103+
# @return [String] returns html code of the datatable generated
39104
def generate_html(table)
40105
path = File.expand_path(
41106
'../templates/datatables/static_html.erb', __dir__
@@ -47,6 +112,10 @@ def generate_html(table)
47112
ERB.new(template).result(binding)
48113
end
49114

115+
# @return [void] loads the dependent JS and CSS files in IRuby notebook
116+
# @example
117+
# table = Daru::View::Table.new(data, options)
118+
# table.init_iruby
50119
def init_iruby
51120
Daru::DataTables.init_iruby
52121
end

lib/daru/view/templates/datatables/static_html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
<body>
77
<%= table_script %>
88
</body>
9-
</html>
9+
</html>

0 commit comments

Comments
 (0)