require 'daru/view' # used for creating table and charts Daru::View.plotting_library = :googlecharts df = Daru::DataFrame.new({b: [11,12,13,14,15], a: [1,2,3,4,5], c: [11,22,33,44,55]}, order: [:a, :b, :c], index: [:one, :two, :three, :four, :five]) t1 = Daru::View::Table.new(df) t1.table.class t1.table.cols t1.class t1.show_in_iruby t1.div IRuby.html t1.div rows = [ ['Mike', {v: 10000, f: '$10,000'}, true], ['Jim', {v:8000, f: '$8,000'}, false], ['Alice', {v: 12500, f: '$12,500'}, true], ['Bob', {v: 7000, f: '$7,000'}, true] ] df2 = Daru::DataFrame.rows(rows) t2 = Daru::View::Table.new(df2) t2.show_in_iruby # adding pagination opts_pagination = { showRowNumber: true, width: '100%', height: '100%' , page: 'enable', pageSize: 2, pagingSymbols: { prev: 'prev', next: 'next' }, pagingButtonsConfiguration: 'auto'} t3 = Daru::View::Table.new(df2,opts_pagination) t3.show_in_iruby t3.class t4 = Daru::View::Table.new([],opts_pagination) # users are free to use the Google charts features, by accessing the google chart table using `#table` # Add Column Headers t4.table.new_column('string', 'Year' ) t4.table.new_column('number', 'Sales') t4.table.new_column('number', 'Expenses') t4.table.new_column('number', 'Expenses2') # Add Rows and Values t4.table.add_rows([ ['2004', 1000, 400, 1111], ['2005', 1170, 460, 2111], ['2006', 660, 1120, 3111], ['2007', 1030, 540, 1112] ]) t4.show_in_iruby opts = { cols: [ {id: 'A', label: 'NEW A', type: 'string'}, {id: 'B', label: 'B-label', type: 'number'}, {id: 'C', label: 'C-label', type: 'date'} ], rows: [ {c:[ {v: 'a'}, {v: 1.0, f: 'One'}, {:v => Date.parse('2008-1-28 00:31:26'), f: '2/28/08 12:31 AM'} ]}, {c:[ {v: 'b'}, {v: 2.0, f: 'Two'}, {:v =>Date.parse('2008-2-12 00:31:27'), f: '3/30/08 12:31 AM'} ]}, {c:[ {v: 'c'}, {v: 3.0, f: 'Three'}, {v: Date.parse('2008-3-30 00:31:26'), f: '4/30/08 12:31 AM'} ]} ] } t_ops = Daru::View::Table.new([],opts) t_ops.show_in_iruby # or t_ops.table t_update = Daru::View::Table.new t_update.table.new_column(type= 'string', 'Employee Name'); t_update.table.new_column(type= 'date', 'Start Date'); t_update.table t_update.table.add_rows(6) t_update.table.set_cell(0, 0, 'Mike'); t_update.table.set_cell(0, 1, Date.parse('2008-1-28')); t_update.table.set_cell(1, 0, 'Bob'); t_update.table.set_cell(1, 1, Date.parse('2007-5-1')); t_update.table.set_cell(2, 0, 'Alice'); t_update.table.set_cell(2, 1, Date.parse('2006-7-16')); t_update.table.set_cell(3, 0, 'Frank'); t_update.table.set_cell(3, 1, Date.parse('2007-11-28')); t_update.table.set_cell(4, 0, 'Floyd'); t_update.table.set_cell(4, 1, Date.parse('2005-3-13')); t_update.table.set_cell(5, 0, 'Fritz'); t_update.table.set_cell(5, 1, Date.parse('2007-9-2')); t_update.table t_update.table.get_column(0) t_update.table.get_row(0) t_update.table.get_cell(3,0) dv = Daru::Vector.new [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175] t_vec = Daru::View::Table.new(dv) t_vec.table t_vec.table.options # set new options in the table. This feature is not present in the basic google_visualr t_vec.table.options = opts_pagination t_vec.table # css styling cssClassNames = { 'headerRow': 'italic-darkblue-font large-font bold-font', 'tableRow': '', 'oddTableRow': 'beige-background', 'selectedTableRow': 'orange-background large-font', 'hoverTableRow': '', 'headerCell': 'gold-border', 'tableCell': '', 'rowNumberCell': 'underline-blue-font' }; opts_css = {'showRowNumber': true, pageSize: 5, 'allowHtml': true, 'cssClassNames': cssClassNames}; t_vec.table.options = opts_css # FixMe: css is not working. May be there is other way to pass cssClassName t_vec.table data = { cols: [{id: 'Name', label: 'Name', type: 'string'}, {id: 'Salary', label: 'Salary', type: 'number'}, {type: 'boolean', label: 'Full Time Employee' }, ], rows: [ {c:[{v: 'Mike'}, {v: 10000, f: '$10,000'}, {v: true}]}, {c:[{v: 'Jim'}, {v:8000, f: '$8,000'}, {v: false}]}, {c:[{v: 'Alice'}, {v: 12500, f: '$12,500'}, {v: true}]}, {c:[{v: 'Bob'}, {v: 7000, f: '$7,000'}, {v: true}]}, ] } table = Daru::View::Table.new(data, height: 300, width: 200) table.show_in_iruby data = [ ['Galaxy', 'Distance', 'Brightness'], ['Canis Major Dwarf', 8000, 230.3], ['Sagittarius Dwarf', 24000, 4000.5], ['Ursa Major II Dwarf', 30000, 1412.3], ['Lg. Magellanic Cloud', 50000, 120.9], ['Bootes I', 60000, 1223.1] ] table = Daru::View::Table.new(data) table.show_in_iruby