<commit_before>/**
 * Ico - SVG graphing library - linegraph, areagraph and stacked areagraph file
 *
 * Copyright (c) 2009 <NAME> (kilianvalkhof.com) - Originally developed by <NAME> (http://alexyoung.org)
 * Visit ico.kilianvalkhof.com for more information and changelogs.
 * Licensed under the MIT license. http://www.opensource.org/licenses/mit-license.php
 *
 */
"use strict";
Ico.LineGraph = Class.create(Ico.BaseGraph, {
  chartDefaults: function () {
    return{
      line : true,
      start_at_zero : true,
      stroke_width : 5
    };
  },
  setChartSpecificOptions: function () {
    if (typeof this.options.curve_amount === 'undefined') {
      this.options.curve_amount = 10;
    }
  },

  calculateStep: function () {
    return (this.graph_width - (this.options.plot_padding * 2)) / (this.data_size - 1);
  },

  startPlot: function (cursor, x, y, colour) {
    cursor.moveTo(x, y);
  },
  drawPlot: function (index, cursor, x, y, colour, coords, datalabel, element, graphindex) {

    if (this.options.markers === 'circle') {
      this.drawGraphMarkers(index, x, y, colour, datalabel, element);
    } else if (this.options.markers === 'value') {
      this.drawGraphValueMarkers(index, x, y, colour, datalabel, element, graphindex);
    }
    if (index === 0) {
      return this.startPlot(cursor, x-0.5, y, colour);
    }

    if (this.options.curve_amount) {
      cursor.cplineTo(x, y, this.options.curve_amount);
    } else {
      cursor.lineTo(x, y);
    }
  },
  drawGraphMarkers: function (index, x, y, colour, datalabel, element) {
    var circle = this.paper.circle(x, y, this.options.marker_size),
        old_marker_size = this.options.marker_size,
        colour2 = this.options.hover_colour || colour,
        new_marker_size;
    circle.attr({ 'stroke-width': '1px', stroke: this.options.background_colour, fill: colour });
    this.globalMarkerSet.push(circle);

    circle.node.onmouseover = function (e) {
      new_marker_size = parseInt(1.7*old_marker_size, 10);
      circle.animate({r : new_marker_size,fill : colour2}, 200);
    }.bind(this);

    circle.node.onmouseout = function () {
      circle.animate({r : old_marker_size, fill : colour}, 200);
    };
  },
  drawGraphValueMarkers: function (index, x, y, colour, datalabel, element, graphindex) {
    if (this.options.odd_horizontal_offset>1) {
          index += this.options.odd_horizontal_offset;
      }
    index -= this.options.stacked_fill || this.options.area ? 1 : 0;
    var currentset = this.options.stacked ? this.real_data : this.data_sets,
        currentvalue = currentset.collect(function (data_set) {return data_set[1][index];})[graphindex],
        vertical_label_unit = this.options.vertical_label_unit||"";

    if (currentvalue) {
      currentvalue = ""+currentvalue.toString().split('.');
      if (currentvalue[1]) {
        currentvalue[1] = currentvalue[1].truncate(3, '');
      }
    }
    if (
      (this.options.line||this.options.stacked) || //if the option is a line graph
      ((this.options.stacked_fill||this.options.area) && index != -1) && //if it's stacked or an area and it's not the first
      typeof currentvalue != "undefined") { //if there is a current value

      var rectx = x-(this.step/2),
          recty = this.options.stacked ? y-(this.graph_height/18): y-(this.graph_height/6),
          rectw = this.step,
          recth = this.options.stacked ? this.graph_height/9     : this.graph_height/3,
          circle = this.paper.circle(x, y, this.options.marker_size),
          block = this.paper.rect(rectx, recty, rectw, recth);

      circle.attr({ 'stroke-width': '1px', stroke: this.options.background_colour, fill: colour,opacity:0});
      block.attr({fill:colour, 'stroke-width': 0, stroke : colour,opacity:0}).toFront();

      if (this.options.datalabels) {
        datalabel = datalabel+": "+currentvalue;
        datalabel += this.options.vertical_label_unit ? " "+this.options.vertical_label_unit:"";
      } else {
        datalabel = currentvalue.toString();
        datalabel += this.options.vertical_label_unit ? " "+this.options.vertical_label_unit:"";
      }
      var hoverSet = this.paper.set(),
          textpadding = 4,
          text = this.paper.text(circle.attrs.cx, circle.attrs.cy-(this.options.font_size*1.5)-2*textpadding, datalabel);
      text.attr({'font-size': this.options.font_size, fill:this.options.hover_text_colour,opacity: 1});
      var textbox = text.getBBox(),
          roundRect= this.paper.rect(
            text.attrs.x-(textbox.width/2)-textpadding,
            text.attrs.y-(textbox.height/2)-textpadding,
            textbox.width+(textpadding*2),
            textbox.height+(textpadding*2),
            textpadding*1.5);
      roundRect.attr({fill : this.options.label_colour, opacity : 1, stroke : 0, "stroke-color":this.options.label_colour});

      var nib = this.paper.path();
      nib.attr({fill: this.options.label_colour, opacity: 1, stroke : 0, "stroke-color" : this.options.label_colour});
      nib.moveTo(text.attrs.x-textpadding,text.attrs.y+(textbox.height/2)+textpadding-1.5);
      nib.lineTo(text.attrs.x,text.attrs.y+(textbox.height/2)+(2*textpadding-0.5));
      nib.lineTo(text.attrs.x+textpadding,text.attrs.y+(textbox.height/2)+textpadding-1.5);
      nib.andClose();

      text.toFront();
      hoverSet.push(circle,roundRect,nib,text).attr({opacity:0}).toFront();
      this.checkHoverPos({rect:roundRect,set:hoverSet,marker:circle,nib:nib,textpadding:textpadding});
      this.globalHoverSet.push(hoverSet);
      this.globalBlockSet.push(block);

      block.node.onmouseover = function (e) {
        hoverSet.animate({opacity:1},200);
      };

      block.node.onmouseout = function (e) {
        hoverSet.animate({opacity:0},200);
      };
    }
  }
});

Ico.AreaGraph = Class.create(Ico.LineGraph, {
  chartDefaults: function () {
    return {
      area:true,
      area_opacity:false
    };
  },
  setChartSpecificOptions: function () {
    if (typeof this.options.curve_amount === 'undefined') {
      this.options.curve_amount = 10;
    }
  },
  drawPlot: function (index, cursor, x, y, colour, coords, datalabel, element, graphindex) {
    var filltype = this.options.area||this.options.stacked_fill;
    if (this.options.markers === 'circle') {
      if (filltype === true) {
        if (index !== 0 && index !== coords.length-1) {
          this.drawGraphMarkers(index, x, y, colour, datalabel, element);
        }
      } else {
         this.drawGraphMarkers(index, x, y, colour, datalabel, element);
      }
    } else if (this.options.markers === 'value') {
      this.drawGraphValueMarkers(index, x, y, colour, datalabel, element, graphindex);
    }

    x -= 0.5;
    if (index === 0) {
      return this.startPlot(cursor, x, y, colour);
    }

    if (this.options.curve_amount && index > 1 && (index < coords.length-1)) {
      cursor.cplineTo(x, y, this.options.curve_amount);
    } else if (this.options.curve_amount && !filltype && (index = 1 || (index = coords.length-1))) {
      cursor.cplineTo(x, y, this.options.curve_amount);
    } else {
      cursor.lineTo(x, y);
    }
  }
});

Ico.StackGraph = Class.create(Ico.AreaGraph, {
  chartDefaults: function () {
    return {
      stacked:true,
      stacked_fill:true,
      stroke_width : 5
    };
  },
  normaliserOptions: function () {
  },
  stackData: function (stacked_data) {
    this.stacked_data = stacked_data.collect(
      function (data_set) {
        return data_set[1];<commit_msg>simplify the hover selection code<commit_after>/**
 * Ico - SVG graphing library - linegraph, areagraph and stacked areagraph file
 *
 * Copyright (c) 2009 <NAME> (kilianvalkhof.com) - Originally developed by <NAME> (http://alexyoung.org)
 * Visit ico.kilianvalkhof.com for more information and changelogs.
 * Licensed under the MIT license. http://www.opensource.org/licenses/mit-license.php
 *
 */
"use strict";
Ico.LineGraph = Class.create(Ico.BaseGraph, {
  chartDefaults: function () {
    return{
      line : true,
      start_at_zero : true,
      stroke_width : 5
    };
  },
  setChartSpecificOptions: function () {
    if (typeof this.options.curve_amount === 'undefined') {
      this.options.curve_amount = 10;
    }
  },

  calculateStep: function () {
    return (this.graph_width - (this.options.plot_padding * 2)) / (this.data_size - 1);
  },

  startPlot: function (cursor, x, y, colour) {
    cursor.moveTo(x, y);
  },
  drawPlot: function (index, cursor, x, y, colour, coords, datalabel, element, graphindex) {

    if (this.options.markers === 'circle') {
      this.drawGraphMarkers(index, x, y, colour, datalabel, element);
    } else if (this.options.markers === 'value') {
      this.drawGraphValueMarkers(index, x, y, colour, datalabel, element, graphindex);
    }
    if (index === 0) {
      return this.startPlot(cursor, x-0.5, y, colour);
    }

    if (this.options.curve_amount) {
      cursor.cplineTo(x, y, this.options.curve_amount);
    } else {
      cursor.lineTo(x, y);
    }
  },
  drawGraphMarkers: function (index, x, y, colour, datalabel, element) {
    var circle = this.paper.circle(x, y, this.options.marker_size),
        old_marker_size = this.options.marker_size,
        colour2 = this.options.hover_colour || colour,
        new_marker_size;
    circle.attr({ 'stroke-width': '1px', stroke: this.options.background_colour, fill: colour });
    this.globalMarkerSet.push(circle);

    circle.node.onmouseover = function (e) {
      new_marker_size = parseInt(1.7*old_marker_size, 10);
      circle.animate({r : new_marker_size,fill : colour2}, 200);
    }.bind(this);

    circle.node.onmouseout = function () {
      circle.animate({r : old_marker_size, fill : colour}, 200);
    };
  },
  drawGraphValueMarkers: function (index, x, y, colour, datalabel, element, graphindex) {
    if (this.options.odd_horizontal_offset>1) {
          index += this.options.odd_horizontal_offset;
      }
    index -= this.options.stacked_fill || this.options.area ? 1 : 0;
    var currentset = this.options.stacked ? this.real_data : this.data_sets,
        currentvalue = currentset.collect(function (data_set) {return data_set[1][index];})[graphindex],
        vertical_label_unit = this.options.vertical_label_unit||"";

    if (currentvalue) {
      currentvalue = ""+currentvalue.toString().split('.');
      if (currentvalue[1]) {
        currentvalue[1] = currentvalue[1].truncate(3, '');
      }
    }
    if (
      (this.options.line||this.options.stacked) || //if the option is a line graph
      ((this.options.stacked_fill||this.options.area) && index != -1) && //if it's stacked or an area and it's not the first
      typeof currentvalue != "undefined") { //if there is a current value

      var rectx = x-(this.step/2),
          recty = this.options.stacked ? y-(this.graph_height/18): y-(this.graph_height/6),
          rectw = this.step,
          recth = this.options.stacked ? this.graph_height/9     : this.graph_height/3,
          circle = this.paper.circle(x, y, this.options.marker_size),
          block = this.paper.rect(rectx, recty, rectw, recth);

      circle.attr({ 'stroke-width': '1px', stroke: this.options.background_colour, fill: colour,opacity:0});
      block.attr({fill:colour, 'stroke-width': 0, stroke : colour,opacity:0}).toFront();

      if (this.options.datalabels) {
        datalabel = datalabel+": "+currentvalue;
        datalabel += this.options.vertical_label_unit ? " "+this.options.vertical_label_unit:"";
      } else {
        datalabel = currentvalue.toString();
        datalabel += this.options.vertical_label_unit ? " "+this.options.vertical_label_unit:"";
      }
      var hoverSet = this.paper.set(),
          textpadding = 4,
          text = this.paper.text(circle.attrs.cx, circle.attrs.cy-(this.options.font_size*1.5)-2*textpadding, datalabel);
      text.attr({'font-size': this.options.font_size, fill:this.options.hover_text_colour,opacity: 1});
      var textbox = text.getBBox(),
          roundRect= this.paper.rect(
            text.attrs.x-(textbox.width/2)-textpadding,
            text.attrs.y-(textbox.height/2)-textpadding,
            textbox.width+(textpadding*2),
            textbox.height+(textpadding*2),
            textpadding*1.5);
      roundRect.attr({fill : this.options.label_colour, opacity : 1, stroke : 0, "stroke-color":this.options.label_colour});

      var nib = this.paper.path();
      nib.attr({fill: this.options.label_colour, opacity: 1, stroke : 0, "stroke-color" : this.options.label_colour});
      nib.moveTo(text.attrs.x-textpadding,text.attrs.y+(textbox.height/2)+textpadding-1.5);
      nib.lineTo(text.attrs.x,text.attrs.y+(textbox.height/2)+(2*textpadding-0.5));
      nib.lineTo(text.attrs.x+textpadding,text.attrs.y+(textbox.height/2)+textpadding-1.5);
      nib.andClose();

      text.toFront();
      hoverSet.push(circle,roundRect,nib,text).attr({opacity:0}).toFront();
      this.checkHoverPos({rect:roundRect,set:hoverSet,marker:circle,nib:nib,textpadding:textpadding});
      this.globalHoverSet.push(hoverSet);
      this.globalBlockSet.push(block);

      block.node.onmouseover = function (e) {
        hoverSet.animate({opacity:1},200);
      };

      block.node.onmouseout = function (e) {
        hoverSet.animate({opacity:0},200);
      };
    }
  }
});

Ico.AreaGraph = Class.create(Ico.LineGraph, {
  chartDefaults: function () {
    return {
      area:true,
      area_opacity:false
    };
  },
  setChartSpecificOptions: function () {
    if (typeof this.options.curve_amount === 'undefined') {
      this.options.curve_amount = 10;
    }
  },
  drawPlot: function (index, cursor, x, y, colour, coords, datalabel, element, graphindex) {
    var filltype = this.options.area||this.options.stacked_fill;

    if(filltype === true) {
      if (index !== 0 && index !== coords.length-1) {
        if (this.options.markers === 'circle') {
          this.drawGraphMarkers(index, x, y, colour, datalabel, element);
        } else {
          this.drawGraphValueMarkers(index, x, y, colour, datalabel, element, graphindex);
        }
      }
    } else {
      if (this.options.markers === 'circle') {
        this.drawGraphMarkers(index, x, y, colour, datalabel, element);
      } else {
        this.drawGraphValueMarkers(index, x, y, colour, datalabel, element, graphindex);
      }
    }

    x -= 0.5;
    if (index === 0) {
      return this.startPlot(cursor, x, y, colour);
    }

    if (this.options.curve_amount && index > 1 && (index < coords.length-1)) {
      cursor.cplineTo(x, y, this.options.curve_amount);
    } else if (this.options.curve_amount && !filltype && (index = 1 || (index = coords.length-1))) {
      cursor.cplineTo(x, y, this.options.curve_amount);
    } else {
      cursor.lineTo(x, y);
    }
  }
});

Ico.StackGraph = Class.create(Ico.AreaGraph, {
  chartDefaults: function () {
    return {
      stacked:true,
      stacked_fill:true,
      stroke_width : 5
    };
  },
  normaliserOptions: function () {
  },
  stackData: function (stacked_data) {
    this.stacked_data = stacked_data.collect(
      function (data_set) {
        return data_set[1];
{'fraction_non_alphanumeric': 0.15107533975458504, 'fraction_numerical': 0.012006861063464836, 'mean_word_length': 3.0391686650679457, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '465429', 'n_tokens_mistral': 5174, 'n_tokens_neox': 4975, 'n_words': 922}