<commit_before>require 'chartify/chart_base'
require 'gruff'

# Example
# -------
# Chartify::Factory.build(:area) do |chart|
#   chart.data = [{hours_remain: 100, estimated_hours_remain: 100, day: 3.days.ago.to_date},
#              {hours_remain: 50, estimated_hours_remain: 45, day: 2.days.ago.to_date},
#              {hours_remain: 5, estimated_hours_remain: 10, day: 1.days.ago.to_date}]
#   chart.columns = {hours_remain: 'Hours remaining', estimated_hours_remain: 'Estimated hours remaining'}
#   chart.label_column = :day
# end
module Chartify
  class AreaChart < ChartBase
    def to_blob
      g = prepare_gruff(:area)

      data.each do |row|
        if row.kind_of?(Array)
          key, val = row[0], row[1]
        else
          key, val = row.key, row.val
        end
        g.data(key, val)
      end
      g.to_blob
    end
  end
end<commit_msg>Fixed area chart<commit_after>require 'chartify/chart_base'
require 'gruff'

# Example
# -------
# Chartify::Factory.build(:area) do |chart|
#   chart.data = [{hours_remain: 100, estimated_hours_remain: 100, day: 3.days.ago.to_date},
#              {hours_remain: 50, estimated_hours_remain: 45, day: 2.days.ago.to_date},
#              {hours_remain: 5, estimated_hours_remain: 10, day: 1.days.ago.to_date}]
#   chart.columns = {hours_remain: 'Hours remaining', estimated_hours_remain: 'Estimated hours remaining'}
#   chart.label_column = :day
# end
module Chartify
  class AreaChart < ChartBase
    def to_blob
      raise 'Need to specify label_column' unless label_column.present?
      g = prepare_gruff(:area)

      columns.each do |column|
        if column.kind_of?(Array)
          key, text = column[0], column[1]
        else
          key, text = column, column.to_s.humanize
        end

        g.data(text, data_for_column(key))
      end

      labels = {}
      data_for_column(label_column).each_with_index do |label, index|
        labels[index] = label.to_s
      end

      g.labels = labels
      g.to_blob
    end
  end
end
{'fraction_non_alphanumeric': 0.12065541211519365, 'fraction_numerical': 0.01787487586891758, 'mean_word_length': 2.7523277467411544, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '486636', 'n_tokens_mistral': 735, 'n_tokens_neox': 681, 'n_words': 156}