Method: Toji::Progress::Graph::ProgressNote#plot_data

Defined in:
lib/toji/progress/graph/progress_note.rb

#plot_data(keys = nil, use_name = false) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/toji/progress/graph/progress_note.rb', line 41

def plot_data(keys=nil, use_name=false)
  if !keys
    keys = @progress.has_keys
  end

  name = ""
  if use_name && @name
    name = "#{@name} "
  end

  result = []

  keys &= PLOT_KEYS

  keys.each {|key|
    xs = []
    ys = []
    text = []
    @progress.states.each {|s|
      val = s.send(key)
      if val
        [val].flatten.each_with_index {|v,i|
          xs << s.elapsed_time_with_offset + i
          ys << v
          text << s.display_time
        }
      end
    }

    line_shape = :linear
    if key==:preset_temp
      line_shape = :hv
    end

    result << {x: xs, y: ys, text: text, name: "#{name}#{key}", line: {dash: @dash, shape: line_shape}, marker: {color: PLOT_COLORS[key]}}
  }

  if 0<@progress.states.length && 0<@progress.day_offset
    result = result.map{|h|
      h[:x].unshift(0)
      h[:y].unshift(nil)
      h[:text].unshift(nil)
      h
    }
  end

  #if 0<@progress.states.length && @progress.states.last.time.strftime("%T")!="00:00:00"
  #  t = @progress.states.last.elapsed_time_with_offset
  #  t -= (t % DAY) - DAY
  #
  #  result = result.map{|h|
  #    h[:x] << t
  #    h[:y] << nil
  #    h[:text] << nil
  #    h
  #  }
  #end

  result
end