class Toji::Progress::Graph::ProgressNote
Constants
- COLORS
- LINE_DASHES
- PLOT_COLORS
- PLOT_KEYS
Attributes
dash[RW]
enable_annotations[RW]
name[RW]
progress[R]
Public Class Methods
new(progress, name: nil, dash: :solid, enable_annotations: true)
click to toggle source
# 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
Public Instance Methods
annotations()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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