Class: Timeline

Inherits:
Object
  • Object
show all
Defined in:
lib/timeline.rb

Overview

Contains all the data and settings for a single Simile timeline

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Timeline

The main options that can be given to the timeline are

config

The configuration for timeline, including the bands configuration. This will be directly passed on to timline.js, see there for more documentation. If no :bands option is given, a default band is created for the timeline.

data

A TimelineSource object containing the data for this timeline OR a hash with the options to create the TimelineSource

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/timeline.rb', line 15

def initialize(options)
  raise(ArgumentError, 'Expecting an option hash here.') unless(options.is_a?(Hash))
  options.to_options!
  raise(ArgumentError, 'Expecting some data here') unless(options[:data])
  raise(ArgumentError, 'Expecting the configuration here') unless(options[:config])
  
  if(options[:data].is_a?(TimelineSource))
    @data = options[:data]
  else
    @data = TimelineSource.new(options[:data])
  end
  
  @config = options[:config].to_options 
  @config[:startDate] ||= year_to_iso8601(@data.first_year) if(@data.first_year)
  @config[:stopDate] ||= year_to_iso8601(@data.last_year) if(@data.last_year)
  @default_date ||= year_to_iso8601(@data.first_year + ((@data.last_year - @data.first_year) / 2)) if(@data.first_year && @data.last_year)
  @config[:bands] ||= default_band
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/timeline.rb', line 38

def empty?
  @data.empty?
end

#timeline_configObject



34
35
36
# File 'lib/timeline.rb', line 34

def timeline_config
  @config.to_json
end

#timeline_dataObject



42
43
44
# File 'lib/timeline.rb', line 42

def timeline_data
  @data.timeline_data
end