<commit_before>module ReportFormatter
  class C3Formatter < Ruport::Formatter
    include ActionView::Helpers::UrlHelper
    include ChartCommon
    include MiqReport::Formatting
    renders :c3, :for => ReportRenderer

    # series handling methods
    def series_class
      C3Series
    end

    CONVERT_TYPES = {
      "ColumnThreed"         => "Column",
      "ParallelThreedColumn" => "Column",
      "StackedThreedColumn"  => "StackedColumn",
      "PieThreed"            => "Pie",
      "AreaThreed"           => "Area",
      "StackedAreaThreed"    => "StackedArea"
    }
    def add_series(label, data)
      @counter ||= 0
      @counter += 1
      series_id = @counter.to_s

      if chart_is_2d?
        mri.chart[:data][:columns] << [series_id, *data.map { |a| a[:value] }]
        mri.chart[:data][:names][series_id] = label
      else
        mri.chart[:data][:columns] = data.collect { |a| [a[:tooltip], a[:value]] }
      end

      if chart_is_stacked?
        mri.chart[:data][:groups][0] << series_id
      end
    end

    def add_axis_category_text(categories)
      if chart_is_2d?
        mri.chart[:axis][:x][:categories] = categories
      end
    end

    # report building methods
    def build_document_header
      super
      type = c3_convert_type("#{mri.graph[:type]}")
      mri.chart = {
        :miqChart => type,
        :data     => {:columns => []},
        :axis     => {}
      }

      if chart_is_2d?
        mri.chart[:data][:names] = {}
        mri.chart[:axis] = {
          :x => {
            :categories => []
          }
        }
      end

      # chart is numeric
      if mri.graph[:mode] == 'values'
        custom_format   = Array(mri[:col_formats])[Array(mri[:col_order]).index(raw_column_name)]
        format, options = javascript_format(mri.graph[:column].split(/(?<!:):(?!:)/)[0], custom_format)
        return unless format

        axis_formatter = {:function => format, :options => options}
        mri.chart[:axis][:y] = {:tick => {:format => axis_formatter}}
      end

      if chart_is_stacked?
        mri.chart[:data][:groups] = [[]]<commit_msg>Slice legend in 3D charts<commit_after>module ReportFormatter
  class C3Formatter < Ruport::Formatter
    include ActionView::Helpers::UrlHelper
    include ChartCommon
    include MiqReport::Formatting
    renders :c3, :for => ReportRenderer

    # series handling methods
    def series_class
      C3Series
    end

    CONVERT_TYPES = {
      "ColumnThreed"         => "Column",
      "ParallelThreedColumn" => "Column",
      "StackedThreedColumn"  => "StackedColumn",
      "PieThreed"            => "Pie",
      "AreaThreed"           => "Area",
      "StackedAreaThreed"    => "StackedArea"
    }
    def add_series(label, data)
      @counter ||= 0
      @counter += 1
      series_id = @counter.to_s

      if chart_is_2d?
        mri.chart[:data][:columns] << [series_id, *data.map { |a| a[:value] }]
        mri.chart[:data][:names][series_id] = label
      else
        mri.chart[:data][:columns] = data.collect { |a| [a[:tooltip], a[:value]] }
        data.each{ |a| mri.chart[:data][:names][a[:tooltip]] = slice_legend(a[:tooltip]) }
      end

      if chart_is_stacked?
        mri.chart[:data][:groups][0] << series_id
      end
    end

    def add_axis_category_text(categories)
      if chart_is_2d?
        mri.chart[:axis][:x][:categories] = categories
      end
    end

    # report building methods
    def build_document_header
      super
      type = c3_convert_type("#{mri.graph[:type]}")
      mri.chart = {
        :miqChart => type,
        :data     => {:columns => [], :names => {}},
        :axis     => {}
      }

      if chart_is_2d?
        mri.chart[:axis] = {
          :x => {
            :categories => []
          }
        }
      end

      # chart is numeric
      if mri.graph[:mode] == 'values'
        custom_format   = Array(mri[:col_formats])[Array(mri[:col_order]).index(raw_column_name)]
        format, options = javascript_format(mri.graph[:column].split(/(?<!:):(?!:)/)[0], custom_format)
        return unless format

        axis_formatter = {:function => format, :options => options}
        mri.chart[:axis][:y] = {:tick => {:format => axis_formatter}}
      end

      if chart_is_stacked?
        mri.chart[:data][:groups] = [[]]
{'fraction_non_alphanumeric': 0.15008118765947576, 'fraction_numerical': 0.005335189051264208, 'mean_word_length': 2.316923076923077, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 38, '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': '1522324', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1393, 'n_words': 254}