In [2]:
require 'daru/view'
Out[2]:
In [3]:
# used for creating table and charts
Daru::View.plotting_library = :googlecharts
Out[3]:
In [3]:
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])
Out[3]:
In [4]:
t1 = Daru::View::Table.new(df)
Out[4]:
In [5]:
t1.table.class
Out[5]:
In [6]:
t1.table.cols
Out[6]:
In [7]:
t1.class
Out[7]:
In [8]:
t1.show_in_iruby
Out[8]:
In [9]:
t1.div
Out[9]:
In [10]:
IRuby.html t1.div
Out[10]:
In [11]:
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)
Out[11]:
In [12]:
t2 = Daru::View::Table.new(df2)
Out[12]:
In [13]:
t2.show_in_iruby
Out[13]:
In [41]:
# adding pagination
opts_pagination = {
showRowNumber: true, width: '100%', height: '100%' ,
page: 'enable',
pageSize: 2,
pagingSymbols: {
prev: 'prev',
next: 'next'
},
pagingButtonsConfiguration: 'auto'}
Out[41]:
In [15]:
t3 = Daru::View::Table.new(df2,opts)
Out[15]:
In [16]:
t3.show_in_iruby
Out[16]:
In [17]:
t3.class
Out[17]:
In [18]:
t4 = Daru::View::Table.new([],opts)
Out[18]:
In [19]:
# 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]
])
Out[19]:
In [20]:
t4.show_in_iruby
Out[20]:
In [21]:
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'}
]}
]
}
Out[21]:
In [22]:
t_ops = Daru::View::Table.new([],opts)
Out[22]:
In [23]:
t_ops.show_in_iruby # or t_ops.table
Out[23]:
In [24]:
t_update = Daru::View::Table.new
Out[24]:
In [25]:
t_update.table.new_column(type= 'string', 'Employee Name');
t_update.table.new_column(type= 'date', 'Start Date');
Out[25]:
In [26]:
t_update.table
Out[26]:
In [27]:
t_update.table.add_rows(6)
Out[27]:
In [28]:
t_update.table.set_cell(0, 0, 'Mike');
Out[28]:
In [29]:
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'));
Out[29]:
In [30]:
t_update.table
Out[30]:
In [31]:
t_update.table.get_column(0)
Out[31]:
In [32]:
t_update.table.get_row(0)
Out[32]:
In [33]:
t_update.table.get_cell(3,0)
Out[33]:
In [34]:
dv = Daru::Vector.new [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
t_vec = Daru::View::Table.new(dv)
Out[34]:
In [35]:
t_vec.table
Out[35]:
In [36]:
t_vec.table.options
Out[36]:
In [44]:
# set new options in the table. This feature is not present in the basic google_visualr
t_vec.table.options = opts_pagination
Out[44]:
In [45]:
t_vec.table
Out[45]:
In [69]:
# 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};
Out[69]:
In [70]:
t_vec.table.options = opts_css
Out[70]:
In [71]:
# FixMe: css is not working. May be there is other way to pass cssClassName
t_vec.table
Out[71]:
In [4]:
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
Out[4]:
In [5]:
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
Out[5]:
In [ ]: