class Toji::Progress::Graph::MultiProgressNote

Constants

LINE_DASHES

Public Class Methods

new() click to toggle source
# File lib/toji/progress/graph/multi_progress_note.rb, line 12
def initialize
  @progresses = []
end

Public Instance Methods

<<(source, name=nil, dash: nil, enable_annotations: true) click to toggle source
# 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
Also aliased as: add
add(source, name=nil, dash: nil, enable_annotations: true)
Alias for: <<
annotations() click to toggle source
# File lib/toji/progress/graph/multi_progress_note.rb, line 48
def annotations
  @progresses.map {|progress|
    progress.annotations
  }.inject([], :+)
end
plot(keys=nil) click to toggle source
# 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) click to toggle source
# 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