Sha256: a428b81d5980638d01bc914b0e39ee1d5a1fa5093ff6b0875646c1cb6a9ce3c3

Contents?: true

Size: 1.21 KB

Versions: 17

Compression:

Stored size: 1.21 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

17 entries across 17 versions & 1 rubygems

Version Path
houston-core-0.8.0.pre app/models/static_chart/area.rb
houston-core-0.7.0 app/models/static_chart/area.rb
houston-core-0.7.0.beta4 app/models/static_chart/area.rb
houston-core-0.7.0.beta3 app/models/static_chart/area.rb
houston-core-0.7.0.beta2 app/models/static_chart/area.rb
houston-core-0.7.0.beta app/models/static_chart/area.rb
houston-core-0.6.3 app/models/static_chart/area.rb
houston-core-0.6.2 app/models/static_chart/area.rb
houston-core-0.6.1 app/models/static_chart/area.rb
houston-core-0.6.0 app/models/static_chart/area.rb
houston-core-0.5.6 app/models/static_chart/area.rb
houston-core-0.5.5 app/models/static_chart/area.rb
houston-core-0.5.4 app/models/static_chart/area.rb
houston-core-0.5.3 app/models/static_chart/area.rb
houston-core-0.5.2 app/models/static_chart/area.rb
houston-core-0.5.1 app/models/static_chart/area.rb
houston-core-0.5.0 app/models/static_chart/area.rb