Class: Toji::Progress::Graph::ProgressNote
- Inherits:
-
Object
- Object
- Toji::Progress::Graph::ProgressNote
- Defined in:
- lib/toji/progress/graph/progress_note.rb
Constant Summary collapse
- PLOT_KEYS =
[:temps, :preset_temp, :room_dry_temp, :room_wet_temp, :room_relative_humidity_from_dry_and_wet, :room_relative_humidity, :baume, :acid, :amino_acid, :alcohol, :bmd].freeze
- COLORS =
[ '#1f77b4', # muted blue '#ff7f0e', # safety orange '#2ca02c', # cooked asparagus green '#d62728', # brick red '#9467bd', # muted purple '#8c564b', # chestnut brown '#e377c2', # raspberry yogurt pink '#7f7f7f', # middle gray '#bcbd22', # curry yellow-green '#17becf' # blue-teal ].freeze
- PLOT_COLORS =
Hash[PLOT_KEYS.zip(COLORS)].freeze
- LINE_DASHES =
[ :solid, :dot, :dashdot, ].freeze
Instance Attribute Summary collapse
-
#dash ⇒ Object
Returns the value of attribute dash.
-
#enable_annotations ⇒ Object
Returns the value of attribute enable_annotations.
-
#name ⇒ Object
Returns the value of attribute name.
-
#progress ⇒ Object
readonly
Returns the value of attribute progress.
Instance Method Summary collapse
- #annotations ⇒ Object
-
#initialize(progress, name: nil, dash: :solid, enable_annotations: true) ⇒ ProgressNote
constructor
A new instance of ProgressNote.
- #plot(keys = nil) ⇒ Object
- #plot_data(keys = nil, use_name = false) ⇒ Object
- #table(keys = nil) ⇒ Object
- #table_data(keys = nil) ⇒ Object
Constructor Details
#initialize(progress, name: nil, dash: :solid, enable_annotations: true) ⇒ ProgressNote
Returns a new instance of ProgressNote.
34 35 36 37 38 39 |
# File 'lib/toji/progress/graph/progress_note.rb', line 34 def initialize(progress, name: nil, dash: :solid, enable_annotations: true) @progress = progress @name = name @dash = dash @enable_annotations = enable_annotations end |
Instance Attribute Details
#dash ⇒ Object
Returns the value of attribute dash.
31 32 33 |
# File 'lib/toji/progress/graph/progress_note.rb', line 31 def dash @dash end |
#enable_annotations ⇒ Object
Returns the value of attribute enable_annotations.
32 33 34 |
# File 'lib/toji/progress/graph/progress_note.rb', line 32 def enable_annotations @enable_annotations end |
#name ⇒ Object
Returns the value of attribute name.
30 31 32 |
# File 'lib/toji/progress/graph/progress_note.rb', line 30 def name @name end |
#progress ⇒ Object (readonly)
Returns the value of attribute progress.
29 30 31 |
# File 'lib/toji/progress/graph/progress_note.rb', line 29 def progress @progress end |
Instance Method Details
#annotations ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/toji/progress/graph/progress_note.rb', line 102 def annotations return [] if !@enable_annotations @progress.states.select{|s| s.mark}.map {|s| { x: s.elapsed_time_with_offset, y: s.temps.first || 0, xref: 'x', yref: 'y', text: s.mark, showarrow: true, arrowhead: 1, ax: 0, ay: -40 } } end |
#plot(keys = nil) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/toji/progress/graph/progress_note.rb', line 154 def plot(keys=nil) Plotly::Plot.new( data: plot_data(keys), layout: { xaxis: { dtick: DAY, tickvals: @progress.days.times.map{|d| d*DAY}, ticktext: @progress.day_labels }, annotations: annotations, } ) end |
#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 |
#table(keys = nil) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/toji/progress/graph/progress_note.rb', line 168 def table(keys=nil) data = table_data(keys) Plotly::Plot.new( data: [{ type: :table, header: { values: data[:header] }, cells: { values: data[:rows].transpose }, }], layout: { } ) end |
#table_data(keys = nil) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/toji/progress/graph/progress_note.rb', line 120 def table_data(keys=nil) if !keys keys = @progress.has_keys keys.delete(:elapsed_time) keys.delete(:time) keys.delete(:day) keys.delete(:moromi_day) if keys.include?(:display_baume) keys.delete(:baume) keys.delete(:nihonshudo) end else keys &= @progress.has_keys end rows = [] @progress.states.each {|state| rows << keys.map {|k| v = state&.send(k) if Array===v v.map(&:to_s).join(", ") elsif Float===v v.round(3).to_s elsif v v.to_s else "" end } } {header: keys, rows: rows} end |