<commit_before>class IterationChart
  
  @@types = {
    'points' => :points,
    'line' => :line,
    'area' => :area,
    'bar' => :bar
  }

  def initialize(parameters, project, current_user)
    @parameters = parameters
    @project = project
    @current_user = current_user
    
    @parameters['iteration-card-type'].nil? and raise "Requires parameter iteration-card-type"
    @parameters['series'].nil? and raise "Requires parameter series"
  end
    
  def execute
    tag_id = (0...8).map{65.+(rand(25)).chr}.join
    
    @iterations = @project.execute_mql('select number, name where type = "' + @parameters['iteration-card-type'] + '" order by number')
    
    series = @parameters['series'].reverse.inject([]){|series, definition|
      aseries = yaml_definition_to_series(definition)
      points = points_for_a_series(aseries)
      last_stacked = series.find{|s| s[:stack]}
      aseries[:points] = (!aseries[:stack] || last_stacked.nil?) ? points : sum_points(last_stacked[:points], points)
      series.unshift(aseries)
    }
    
    iterations_from = iteration_description_to_i(@parameters['iterations-from'])
    iterations_to = iteration_description_to_i(@parameters['iterations-to'])
     
    min_y = to_f_or_nil(@parameters['min'])
    max_y = to_f_or_nil(@parameters['max'])
    
    fill = (@parameters['transparent-fills'] != false)? 'true' : '1'
    show_legend = @parameters['legend'] != false
    legend_columns = to_i_or_nil(@parameters['legend'])

  <<-HTML
    <script language="javascript" type="text/javascript" src="../../../../plugin_assets/iteration_chart/javascripts/excanvas.compiled.js"></script>
    <script language="javascript" type="text/javascript" src="../../../../plugin_assets/iteration_chart/javascripts/jquery.min.js"></script>
    <script language="javascript" type="text/javascript" src="../../../../plugin_assets/iteration_chart/javascripts/jquery.flot.min.js"></script>
    <div id="iterchart#{tag_id}" style="width:600px;height:300px;"></div>
    #{show_legend ? "<div id='iterchartlegend#{tag_id}' style='width:600px;margin:0 auto;padding:10px'></div>" : ""}
    
    <script id="source" language="javascript" type="text/javascript">
    jQuery.noConflict();
    (function($) {
      $(function () {
        xlabels = [#{@iterations.collect{|iteration| '"' + iteration['name'] + '"'}.join(',')}];
        $.plot($('#iterchart#{tag_id}'), [
        #{series.collect{|aseries|
          '{' +
            [(aseries[:label].nil? ? nil : 'label:' + quote_if_string(aseries[:label]).to_s),
             (aseries[:color].nil? ? nil : 'color:' + quote_if_string(aseries[:color]).to_s),
             aseries[:types].collect{|type|
               case type
               when :points then "points:{show:true}"
               when :line then "lines:{show:true}"
               when :area then "lines:{show:true,fill:#{fill},lineWidth:1}"
               when :bar then "bars:{show:true,barWidth:1,align:'center',fill:#{fill}}"
               end
             },
             'data:[' + aseries[:points].collect{|point| '[' + point.join(',') + ']' }.join(',') + ']'
            ].flatten.compact.join(',') +
          '}'
        }.join(',')}
        ], {
          legend: {
            show: #{show_legend.to_s},
            container: '#iterchartlegend#{tag_id}',
            noColumns: #{legend_columns.nil? ? 'undefined' : legend_columns}
          },
          xaxis: {
            minTickSize: 1,
            min: #{iterations_from.nil? ? 'undefined' : iterations_from},
            max: #{iterations_to.nil? ? 'undefined' : iterations_to},
            tickFormatter: function(val, axis) {
              return (val == axis.min || xlabels[val] == undefined)? "" : xlabels[val];
            }
          },
          yaxis: {
            min: #{min_y.nil? ? 'undefined' : min_y},
            max: #{max_y.nil? ? 'undefined' : max_y}
          },
          grid: {
            markings: function (axes) {
              var markings = [];
              for (var x = Math.floor(axes.xaxis.min); x < axes.xaxis.max; x += 1) {
                markings.push({ xaxis:{ from:x, to:x, lineWidth:1, color:"#000000"}});
              }
              markings.push({ yaxis:{ from:0, to:0 }, lineWidth:2, color:"#000000" });
              return markings;
            }
          }
        });
      });
    })(jQuery);
    </script>
  HTML
  
  end
  
  def yaml_definition_to_series(definition)
    data = definition['data'] || []
    data = data.is_a?(Array) ? data : [{ 'query' => data }]
    {
      :label => definition['label'],
      :color => definition['color'],<commit_msg>Disable texttile in the HTML output and add IE only comment for excanvas<commit_after>class IterationChart
  
  @@types = {
    'points' => :points,
    'line' => :line,
    'area' => :area,
    'bar' => :bar
  }

  def initialize(parameters, project, current_user)
    @parameters = parameters
    @project = project
    @current_user = current_user
    
    @parameters['iteration-card-type'].nil? and raise "Requires parameter iteration-card-type"
    @parameters['series'].nil? and raise "Requires parameter series"
  end
    
  def execute
    tag_id = (0...8).map{65.+(rand(25)).chr}.join
    
    @iterations = @project.execute_mql('select number, name where type = "' + @parameters['iteration-card-type'] + '" order by number')
    
    series = @parameters['series'].reverse.inject([]){|series, definition|
      aseries = yaml_definition_to_series(definition)
      points = points_for_a_series(aseries)
      last_stacked = series.find{|s| s[:stack]}
      aseries[:points] = (!aseries[:stack] || last_stacked.nil?) ? points : sum_points(last_stacked[:points], points)
      series.unshift(aseries)
    }
    
    iterations_from = iteration_description_to_i(@parameters['iterations-from'])
    iterations_to = iteration_description_to_i(@parameters['iterations-to'])
     
    min_y = to_f_or_nil(@parameters['min'])
    max_y = to_f_or_nil(@parameters['max'])
    
    fill = (@parameters['transparent-fills'] != false)? 'true' : '1'
    show_legend = @parameters['legend'] != false
    legend_columns = to_i_or_nil(@parameters['legend'])

  <<-HTML
    <notextile>
    <!--[if IE]><script language="javascript" type="text/javascript" src="../../../../plugin_assets/iteration_chart/javascripts/excanvas.compiled.js"></script><![endif]-->
    <script language="javascript" type="text/javascript" src="../../../../plugin_assets/iteration_chart/javascripts/jquery.min.js"></script>
    <script language="javascript" type="text/javascript" src="../../../../plugin_assets/iteration_chart/javascripts/jquery.flot.min.js"></script>
    <div id="iterchart#{tag_id}" style="width:600px;height:300px;"></div>
    #{show_legend ? "<div id='iterchartlegend#{tag_id}' style='width:600px;margin:0 auto;padding:10px'></div>" : ""}
    
    <script id="source" language="javascript" type="text/javascript">
    jQuery.noConflict();
    (function($) {
      $(function () {
        xlabels = [#{@iterations.collect{|iteration| '"' + iteration['name'] + '"'}.join(',')}];
        $.plot($('#iterchart#{tag_id}'), [
        #{series.collect{|aseries|
          '{' +
            [(aseries[:label].nil? ? nil : 'label:' + quote_if_string(aseries[:label]).to_s),
             (aseries[:color].nil? ? nil : 'color:' + quote_if_string(aseries[:color]).to_s),
             aseries[:types].collect{|type|
               case type
               when :points then "points:{show:true}"
               when :line then "lines:{show:true}"
               when :area then "lines:{show:true,fill:#{fill},lineWidth:1}"
               when :bar then "bars:{show:true,barWidth:1,align:'center',fill:#{fill}}"
               end
             },
             'data:[' + aseries[:points].collect{|point| '[' + point.join(',') + ']' }.join(',') + ']'
            ].flatten.compact.join(',') +
          '}'
        }.join(',')}
        ], {
          legend: {
            show: #{show_legend.to_s},
            container: '#iterchartlegend#{tag_id}',
            noColumns: #{legend_columns.nil? ? 'undefined' : legend_columns}
          },
          xaxis: {
            minTickSize: 1,
            min: #{iterations_from.nil? ? 'undefined' : iterations_from},
            max: #{iterations_to.nil? ? 'undefined' : iterations_to},
            tickFormatter: function(val, axis) {
              return (val == axis.min || xlabels[val] == undefined)? "" : xlabels[val];
            }
          },
          yaxis: {
            min: #{min_y.nil? ? 'undefined' : min_y},
            max: #{max_y.nil? ? 'undefined' : max_y}
          },
          grid: {
            markings: function (axes) {
              var markings = [];
              for (var x = Math.floor(axes.xaxis.min); x < axes.xaxis.max; x += 1) {
                markings.push({ xaxis:{ from:x, to:x, lineWidth:1, color:"#000000"}});
              }
              markings.push({ yaxis:{ from:0, to:0 }, lineWidth:2, color:"#000000" });
              return markings;
            }
          }
        });
      });
    })(jQuery);
    </script>
    </notexttile>
  HTML
  
  end
  
  def yaml_definition_to_series(definition)
    data = definition['data'] || []
    data = data.is_a?(Array) ? data : [{ 'query' => data }]
    {
      :label => definition['label'],
      :color => definition['color'],
{'fraction_non_alphanumeric': 0.18163374265883608, 'fraction_numerical': 0.008328884143085958, 'mean_word_length': 2.609248554913295, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 45, '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': '1422034', 'n_tokens_mistral': 2975, 'n_tokens_neox': 2868, 'n_words': 482}