<commit_before>module ReportFormatter
  module ChartCommon
    def slice_legend(string, limit = LEGEND_LENGTH)
      string = string.to_s
      string = string.length > limit ? string.slice(0, limit) + "..." : string
      string.gsub(/\n/, ' ')
    end

    def nonblank_or_default(value)
      value.blank? ? BLANK_VALUE : value.to_s
    end

    def mri
      options.mri
    end

    def build_document_header
      raise "Can't create a graph without a sortby column" if mri.sortby.nil? &&
          mri.db != "MiqReport" # MiqReport based charts are already sorted
      raise "Graph type not specified" if mri.graph.nil? ||
          (mri.graph.is_a?(Hash) && mri.graph[:type].nil?)
    end

    def graph_options
      options.graph_options
    end

    def build_document_body
      return no_records_found_chart if mri.table.nil? || mri.table.data.blank?<commit_msg>Charts: use truncute to shorten texts. (transferred from ManageIQ/manageiq@1<PASSWORD>)<commit_after>module ReportFormatter
  module ChartCommon
    def slice_legend(string, limit = LEGEND_LENGTH)
      string.to_s.gsub(/\n/, ' ').truncate(limit)
    end

    def nonblank_or_default(value)
      value.blank? ? BLANK_VALUE : value.to_s
    end

    def mri
      options.mri
    end

    def build_document_header
      raise "Can't create a graph without a sortby column" if mri.sortby.nil? &&
          mri.db != "MiqReport" # MiqReport based charts are already sorted
      raise "Graph type not specified" if mri.graph.nil? ||
          (mri.graph.is_a?(Hash) && mri.graph[:type].nil?)
    end

    def graph_options
      options.graph_options
    end

    def build_document_body
      return no_records_found_chart if mri.table.nil? || mri.table.data.blank?
{'fraction_non_alphanumeric': 0.09707064905226881, 'fraction_numerical': 0.0011487650775416428, 'mean_word_length': 2.7869565217391306, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, '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': '2347727', 'n_tokens_mistral': 578, 'n_tokens_neox': 559, 'n_words': 140}