Class: Toji::Progress::Graph::MultiProgressNote

Inherits:
Object
  • Object
show all
Defined in:
lib/toji/progress/graph/multi_progress_note.rb

Constant Summary collapse

LINE_DASHES =
[
  :solid,
  :dot,
  :dashdot,
].freeze

Instance Method Summary collapse

Constructor Details

#initializeMultiProgressNote

Returns a new instance of MultiProgressNote.



12
13
14
# File 'lib/toji/progress/graph/multi_progress_note.rb', line 12

def initialize
  @progresses = []
end

Instance Method Details

#<<(source, name = nil, dash: nil, enable_annotations: true) ⇒ Object Also known as: add



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/toji/progress/graph/multi_progress_note.rb', line 16

def <<(source, name=nil, dash: nil, enable_annotations: true)
  if !dash
    dash = LINE_DASHES[@progresses.length % LINE_DASHES.length]
  end

  if !name
    name = "Progress #{@progresses.length}"
  end

  case source
  when ProgressNote
    progress = source.dup
    progress.name = name
    progress.dash = dash
    progress.enable_annotations = enable_annotations
  when Progress
    progress = source.progress_note(name: name, dash: dash, enable_annotations: enable_annotations)
  else
    raise Error, "ArgumentError: Toji::Progress::Graph::ProgressNote or Toji::Progress::Progress required"
  end

  @progresses << progress
  self
end

#annotationsObject



48
49
50
51
52
# File 'lib/toji/progress/graph/multi_progress_note.rb', line 48

def annotations
  @progresses.map {|progress|
    progress.annotations
  }.inject([], :+)
end

#plot(keys = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/toji/progress/graph/multi_progress_note.rb', line 54

def plot(keys=nil)
  progresses = @progresses.map(&:progress)
  max_days = progresses.map(&:days).max
  index = progresses.index{|progress| progress.days==max_days}
  day_labels = progresses[index].day_labels

  Plotly::Plot.new(
    data: plot_data(keys),
    layout: {
      xaxis: {
        dtick: DAY,
        tickvals: max_days.times.map{|d| d*DAY},
        ticktext: day_labels
      },
      annotations: annotations,
    }
  )
end

#plot_data(keys = nil) ⇒ Object



42
43
44
45
46
# File 'lib/toji/progress/graph/multi_progress_note.rb', line 42

def plot_data(keys=nil)
  @progresses.map {|progress|
    progress.plot_data(keys, true)
  }.inject([], :+)
end