require 'daru/view'
Install the spreadsheet gem version ~>1.1.1 for using spreadsheet functions. Install the mechanize gem version ~>2.7.5 for using mechanize functions.
true
Daru::View.plotting_library = :googlecharts
:googlecharts
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
President | Start | End | |
---|---|---|---|
0 | Washington | 1789-03-30T00:00:00+00:00 | 1797-02-04T00:00:00+00:00 |
1 | Adams | 1797-02-04T00:00:00+00:00 | 1801-02-04T00:00:00+00:00 |
2 | Jefferson | 1801-02-04T00:00:00+00:00 | 1809-02-04T00:00:00+00:00 |
presidents_chart = Daru::View::Plot.new(df_presidents, type: :timeline)
presidents_chart.show_in_iruby
df_presidents['Name'] = ['George Washington', 'John Adams', 'Thomas Jefferson']
["George Washington", "John Adams", "Thomas Jefferson"]
df_presidents['Term'] = ['1', '2', '3']
["1", "2", "3"]
df_presidents.delete_vector('President')
Start | End | Name | Term | |
---|---|---|---|---|
0 | 1789-03-30T00:00:00+00:00 | 1797-02-04T00:00:00+00:00 | George Washington | 1 |
1 | 1797-02-04T00:00:00+00:00 | 1801-02-04T00:00:00+00:00 | John Adams | 2 |
2 | 1801-02-04T00:00:00+00:00 | 1809-02-04T00:00:00+00:00 | Thomas Jefferson | 3 |
df_presidents.order = ['Term', 'Name', 'Start', 'End']
["Term", "Name", "Start", "End"]
df_presidents
Term | Name | Start | End | |
---|---|---|---|---|
0 | 1 | George Washington | 1789-03-30T00:00:00+00:00 | 1797-02-04T00:00:00+00:00 |
1 | 2 | John Adams | 1797-02-04T00:00:00+00:00 | 1801-02-04T00:00:00+00:00 |
2 | 3 | Thomas Jefferson | 1801-02-04T00:00:00+00:00 | 1809-02-04T00:00:00+00:00 |
presidents_label_chart = Daru::View::Plot.new(df_presidents, type: :timeline)
presidents_label_chart.show_in_iruby
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
position_chart = Daru::View::Plot.new(timeline_adv_table, type: :timeline)
position_chart.show_in_iruby
presidents_label_chart = Daru::View::Plot.new(df_presidents, type: :timeline)
presidents_label_chart.show_in_iruby
presidents_label_chart = Daru::View::Plot.new(df_presidents, type: :timeline, timeline: { groupByRowLabel: false })
presidents_label_chart.show_in_iruby
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
presidents_1row_chart = Daru::View::Plot.new(timeline_1row_table, type: :timeline, timeline: { groupByRowLabel: true })
presidents_1row_chart.show_in_iruby
presidents_1row_chart = Daru::View::Plot.new(timeline_1row_table, type: :timeline, timeline: { groupByRowLabel: false })
presidents_1row_chart.show_in_iruby
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
timeline_color_chart = Daru::View::Plot.new(timeline_color_table.table, type: :timeline, timeline: { colorByRowLabel: true })
timeline_color_chart.show_in_iruby
timeline_single_color_chart = Daru::View::Plot.new(timeline_color_table.table, type: :timeline, timeline: { singleColor: '#8d8' })
timeline_single_color_chart.show_in_iruby
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
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
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
presidents_1row_chart = Daru::View::Plot.new(timeline_1row_table, type: :timeline, timeline: { groupByRowLabel: true })
presidents_1row_chart.show_in_iruby
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
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
opts = {
type: :timeline
}
presidents_tooltip_chart = Daru::View::Plot.new(timeline_tooltip_table.table, opts)
presidents_tooltip_chart.show_in_iruby