Sha256: 89a1524e7388a886236adcaebd59615a47a01fe31efd26455be6c814064f6446
Contents?: true
Size: 1.29 KB
Versions: 1
Compression:
Stored size: 1.29 KB
Contents
class StaticChart class Area < StaticChart def defaults super.merge( line_weight: 0, axes: :right ) end def line_weight options[:line_weight] end def marker_colors options.fetch(:marker_colors, colors) end def data @data ||= stack_data(super) end def min options.fetch(:min, 0) # data.last.min end def max options.fetch(:max, data.flatten.compact.max) end def src src = Gchart.line( data: data.reverse, bar_colors: colors.reverse, bg: bg, axis_range: [[min, max]], min_value: min, max_value: max, size: size ) src << chm src << chls src << chxs src end protected def stack_data(data) return [] if data.empty? length = data.map(&:length).max last_line = [0] * length data.map { |line| last_line = length.times.map { |i| last_line.fetch(i, 0) + line.fetch(i, 0) } } end def markers marker_colors.reverse.each_with_index.map { |color, i| "B,#{color},#{i},0,0" } end def chls "&chls=" + (["#{line_weight},0,0"] * (data.length-1)).join("|") + "|0,0,0" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
houston-core-0.5.0.beta1 | app/models/static_chart/area.rb |