This example is taken from Vega's gallery
The following is the Ruby code that generates lifelines.json.
require 'plotrb'
people = pdata.name('people').url('people.json')
events = pdata.name('events').url('events.json') do
format(:json) { parse 'when' => :date }
end
y_scale = ordinal_scale.name('y').from('people.label').to_height
x_scale = time_scale.name('x').from(['people.born', 'people.died']).to_width.round.in_years
events_mark_t = text_mark.from(events) do
enter do
x_start { scale(x_scale).from('when') }
y_start -10
angle -25
fill '#000'
text { from 'name' }
font 'Helvetica Neue'
font_size 10
end
end
events_mark_r = rect_mark.from(events) do
enter do
x_start { scale(x_scale).from('when') }
y_start -8
width 1
height { group(:height).offset(8) }
fill '#888'
end
end
people_mark_t = text_mark.from(people) do
enter do
x_start { scale(x_scale).from('born') }
y_start { scale(y_scale).from('label').offset(-3) }
fill '#000'
text { from('label') }
font 'Helvetica Neue'
font_size 10
end
end
people_mark_r = rect_mark.from(people) do
enter do
x_start { scale(x_scale).from('born') }
x_end { scale(x_scale).from('died') }
y_start { scale(y_scale).from('label') }
height 2
fill '#557'
end
end
people_mark_r2 = rect_mark.from(people) do
enter do
x_start { scale(x_scale).from('enter') }
x_end { scale(x_scale).from('leave') }
y_start { scale(y_scale).from('label').offset(-1) }
height 4
fill '#e44'
end
end
vis = visualization.name('lifelines').width(600).height(300) do
data people, events
scales x_scale, y_scale
axes x_axis.scale('x')
marks events_mark_t, events_mark_r, people_mark_t, people_mark_r, people_mark_r2
end
puts vis.generate_spec(:pretty)