In [1]:
require 'daru/view'
Out[1]:
In [2]:
Daru::View.plotting_library = :googlecharts
Out[2]:
In [3]:
idx = Daru::Index.new ['President', 'Start', 'End']
data_rows = [
[ 'Washington', DateTime.new(1789, 3, 30), DateTime.new(1797, 2, 4) ],
[ 'Adams', DateTime.new(1797, 2, 4), DateTime.new(1801, 2, 4) ],
[ 'Jefferson', DateTime.new(1801, 2, 4), DateTime.new(1809, 2, 4) ]
]
df_presidents = Daru::DataFrame.rows(data_rows)
df_presidents.vectors = idx
df_presidents
Out[3]:
In [4]:
presidents_chart = Daru::View::Plot.new(df_presidents, type: :timeline)
presidents_chart.show_in_iruby
Out[4]:
In [5]:
df_presidents['Name'] = ['George Washington', 'John Adams', 'Thomas Jefferson']
Out[5]:
In [6]:
df_presidents['Term'] = ['1', '2', '3']
Out[6]:
In [7]:
df_presidents.delete_vector('President')
Out[7]:
In [8]:
df_presidents.order = ['Term', 'Name', 'Start', 'End']
Out[8]:
In [9]:
df_presidents
Out[9]:
In [10]:
presidents_label_chart = Daru::View::Plot.new(df_presidents, type: :timeline)
presidents_label_chart.show_in_iruby
Out[10]:
In [11]:
data = [
[ 'Position', 'Name', 'Start' ,'End'],
[ 'President', 'George Washington', DateTime.new(1789, 3, 30), DateTime.new(1797, 2, 4) ],
[ 'President', 'John Adams', DateTime.new(1797, 2, 4), DateTime.new(1801, 2, 4) ],
[ 'President', 'Thomas Jefferson', DateTime.new(1801, 2, 4), DateTime.new(1809, 2, 4) ],
[ 'Vice President', 'John Adams', DateTime.new(1789, 3, 21), DateTime.new(1797, 2, 4)],
[ 'Vice President', 'Thomas Jefferson', DateTime.new(1797, 2, 4), DateTime.new(1801, 2, 4)],
[ 'Vice President', 'Aaron Burr', DateTime.new(1801, 2, 4), DateTime.new(1805, 2, 4)],
[ 'Vice President', 'George Clinton', DateTime.new(1805, 2, 4), DateTime.new(1812, 3, 20)],
[ 'Secretary of State', 'John Jay', DateTime.new(1789, 8, 25), DateTime.new(1790, 2, 22)],
[ 'Secretary of State', 'Thomas Jefferson',DateTime.new(1790, 2, 22), DateTime.new(1793, 11, 30)],
[ 'Secretary of State', 'Edmund Randolph', DateTime.new(1794, 1, 2), DateTime.new(1795, 7, 20)],
[ 'Secretary of State', 'Timothy Pickering', DateTime.new(1795, 7, 20), DateTime.new(1800, 4, 12)],
[ 'Secretary of State', 'Charles Lee', DateTime.new(1800, 4, 13), DateTime.new(1800, 5, 5)],
[ 'Secretary of State', 'John Marshall', DateTime.new(1800, 5, 13), DateTime.new(1801, 2, 4)],
[ 'Secretary of State', 'Levi Lincoln', DateTime.new(1801, 2, 5), DateTime.new(1801, 4, 1)],
[ 'Secretary of State', 'James Madison', DateTime.new(1801, 4, 2), DateTime.new(1809, 2, 3)]
]
timeline_adv_table = Daru::View::Table.new(data, pageSize: 6)
timeline_adv_table.show_in_iruby
Out[11]:
In [12]:
position_chart = Daru::View::Plot.new(timeline_adv_table, type: :timeline)
position_chart.show_in_iruby
Out[12]:
In [13]:
presidents_label_chart = Daru::View::Plot.new(df_presidents, type: :timeline)
presidents_label_chart.show_in_iruby
Out[13]:
In [14]:
presidents_label_chart = Daru::View::Plot.new(df_presidents, type: :timeline, timeline: { groupByRowLabel: false })
presidents_label_chart.show_in_iruby
Out[14]:
In [15]:
data = {
cols: [{ type: 'string', id: 'Role' },
{ type: 'string', label: 'Name' },
{ type: 'date', label: 'Start' },{ type: 'date', label: 'End' }
],
rows: [{c:[{v: 'President'}, {v: 'George Washington'}, {v: DateTime.new(1789, 3, 30)}, {v: DateTime.new(1797, 2, 4)}]},
{c:[{v: 'President'}, {v: 'John Adams'}, {v: DateTime.new(1797, 2, 4)}, {v: DateTime.new(1801, 2, 4) }]},
{c:[{v: 'President'}, {v: 'Thomas Jefferson'}, {v: DateTime.new(1801, 2, 4)}, {v: DateTime.new(1809, 2, 4)}]},
]
}
timeline_1row_table = Daru::View::Table.new(data, height: 300, width: 200)
timeline_1row_table.show_in_iruby
Out[15]:
In [16]:
presidents_1row_chart = Daru::View::Plot.new(timeline_1row_table, type: :timeline, timeline: { groupByRowLabel: true })
presidents_1row_chart.show_in_iruby
Out[16]:
In [17]:
presidents_1row_chart = Daru::View::Plot.new(timeline_1row_table, type: :timeline, timeline: { groupByRowLabel: false })
presidents_1row_chart.show_in_iruby
Out[17]:
In [18]:
data = [
[ 'Room', 'Name', 'Start' ,'End'],
[ 'Magnolia Room', 'Beginning JavaScript', DateTime.new(2017,7,31,12,0,0), DateTime.new(2017,7,31,13,30,0) ],
[ 'Magnolia Room', 'Intermediate JavaScript', DateTime.new(2017,7,31,14,0,0), DateTime.new(2017,7,31,15,30,0) ],
[ 'Magnolia Room', 'Advanced JavaScript', DateTime.new(2017,7,31,16,0,0), DateTime.new(2017,7,31,17,30,0) ],
[ 'Willow Room', 'Beginning Google Charts', DateTime.new(2017,7,31,12,30,0), DateTime.new(2017,7,31,14,0,0) ],
[ 'Willow Room', 'Intermediate Google Charts', DateTime.new(2017,7,31,14,30,0), DateTime.new(2017,7,31,16,0,0) ],
[ 'Willow Room', 'Advanced Google Charts', DateTime.new(2017,7,31,16,30,0), DateTime.new(2017,7,31,18,0,0) ]
]
timeline_color_table = Daru::View::Table.new(data, pageSize: 6)
timeline_color_table.show_in_iruby
Out[18]:
In [19]:
timeline_color_chart = Daru::View::Plot.new(timeline_color_table.table, type: :timeline, timeline: { colorByRowLabel: true })
timeline_color_chart.show_in_iruby
Out[19]:
In [20]:
timeline_single_color_chart = Daru::View::Plot.new(timeline_color_table.table, type: :timeline, timeline: { singleColor: '#8d8' })
timeline_single_color_chart.show_in_iruby
Out[20]:
In [21]:
opts = {
timeline: { colorByRowLabel: true },
backgroundColor: '#ffd',
type: :timeline
}
timeline_bgcolor_chart = Daru::View::Plot.new(timeline_color_table.table, opts)
timeline_bgcolor_chart.show_in_iruby
Out[21]:
In [22]:
opts = {
colors: ['#cbb69d', '#603913', '#c69c6e'],
type: :timeline
}
timeline_bgcolor_chart = Daru::View::Plot.new(timeline_color_table.table, opts)
timeline_bgcolor_chart.show_in_iruby
Out[22]:
In [23]:
opts = {
colors: ['#cbb69d', '#603913', '#c69c6e'],
timeline: { rowLabelStyle: {fontName: 'Helvetica', fontSize: 24, color: '#603913' },
barLabelStyle: { fontName: 'Garamond', fontSize: 14 } },
type: :timeline
}
timeline_font_chart = Daru::View::Plot.new(timeline_color_table.table, opts)
timeline_font_chart.show_in_iruby
Out[23]:
In [24]:
presidents_1row_chart = Daru::View::Plot.new(timeline_1row_table, type: :timeline, timeline: { groupByRowLabel: true })
presidents_1row_chart.show_in_iruby
Out[24]:
In [25]:
opts = {
timeline: { showRowLabels: false },
# FixMe : not workin. refer : https://developers.google.com/chart/interactive/docs/gallery/timeline
avoidOverlappingGridLines: false,
type: :timeline
}
presidents_1row_chart = Daru::View::Plot.new(timeline_1row_table, opts)
presidents_1row_chart.show_in_iruby
Out[25]:
In [26]:
data = {
cols: [{ type: 'string', id: 'President' },
{ type: 'string', label: 'dummy bar label' },
{ type: 'string', role: 'tooltip' },
{ type: 'date', label: 'Start' },{ type: 'date', label: 'End' }
],
rows: [{c:[{v: 'Washington'}, {v: nil},{v: 'George'}, {v: DateTime.new(1789, 3, 30)}, {v: DateTime.new(1797, 2, 4)}]},
{c:[{v: 'Adams'}, {v: nil},{v: 'John'}, {v: DateTime.new(1797, 2, 4)}, {v: DateTime.new(1801, 2, 4) }]},
{c:[{v: 'Jefferson'}, {v: nil},{v: 'Thomas'}, {v: DateTime.new(1801, 2, 4)}, {v: DateTime.new(1809, 2, 4)}]},
]
}
timeline_tooltip_table = Daru::View::Table.new(data, height: 300, width: 200)
timeline_tooltip_table.show_in_iruby
Out[26]:
In [27]:
opts = {
type: :timeline
}
presidents_tooltip_chart = Daru::View::Plot.new(timeline_tooltip_table.table, opts)
presidents_tooltip_chart.show_in_iruby
Out[27]:
In [ ]: