<commit_before>//PieChart extends Chart

GeoDash.PieChart = ezoop.ExtendedClass(GeoDash.Chart, {
  className: 'PieChart'
  , defaults: {
    label: 'label'
    , value: 'value'
    , colors: ["#f00", "#0f0", "#00f"]
    , innerRadius: 10
    , opacity: 1
    , drawX: false
    , drawY: false
    , title: false
    , padding: 10
    , legend: false
    , legendPosition: 'middle'
    , hover: true
    , arclabels: false
    , gdClass: 'chart-html piechart-svg'
    , valueFormat: d3.format(',.0f')
    , formatPercent: d3.format('.2f')
    , hoverTemplate: "{{label}}: {{value}} ({{percent}}%)"
    , labelColor: "#ccc"
    , legendWidth: 80
    , arcstroke: 2
    , margin: {
      top: 10
      , right: 10
      , bottom: 10
      , left: 10
    }
  }
  , initialize: function (el, options) {
  }
  , setColors: function(colors){
    this.color = d3.scale.ordinal()
      .range(colors);
  }
  , update: function(data){
    //if(GeoDash.Browser.ielt9) return
    var self = this

    var diameter = Math.min(this.xrange, this.yrange)
    var radius = ( diameter / 2 ) - 4

    this.arc = d3.svg.arc()
      .outerRadius(radius)
      .innerRadius(this.options.innerRadius)

    this.pie = d3.layout.pie()
      .sort(null)
      .value(function(d) { return d[self.options.value] })



    this.total = 0
    data.forEach(function(d, i) {
      d[self.options.value] = +d[self.options.value]
      if(+d[self.options.value] < 0) {
        data.splice(i, 1)
      } else {
        self.total += +d[self.options.value]
      }
    })
    this.data = data
    this.updateChart()
  }
  , updateChart: function() {
    var self = this
    
    this.color = d3.scale.ordinal()
       .range(this.options.colors)

    var g = this.svg.selectAll(".arc")
      .data(this.pie(this.data))

    g.select('path')
      .style("fill", function(d) { return self.color(d.data[self.options.label]) })
      .attr("d", this.arc)

    g.enter()
      .append("g")
      .attr("class", "arc")
      .append("path")
      .attr("d", this.arc)
      .attr("fill", function(d) { return self.color(d.data[self.options.label]) })
      .attr("fill-opacity", this.options.opacity)
      .attr("stroke-width", this.options.arcstroke)
      .on('mouseover', function (d, i) {
        if(!GeoDash.Browser.touch) {
          self.mouseOver(d, i, this)
        }
      })
      .on('mouseout', function (d, i) {
        if(!GeoDash.Browser.touch) {
          self.mouseOut(d, i, this)
        }
      })
      .on('click', function (d, i) {
        if(self.activeBar === i) {
          self.activeBar = -1
          self.mouseOut(d, i, this)
        } else {
          self.activeBar = i
          self.mouseOver(d, i, this)
        }
      })

    g.exit().remove()

    if(this.options.arclabels) {
      var t = self.svg.selectAll(".arc-text")
            .data(this.pie(this.data))

      t.select("text")
        .attr("transform", function(d) { return "translate(" + self.arc.centroid(d) + ")"; })
        .text(function(d) { return d.data[self.options.label] + ' (' + d.value + ')' })

      t.enter().append("g")
        .attr("class", "arc-text")
        .append("text")
        .attr("transform", function(d) { return "translate(" + self.arc.centroid(d) + ")" })
        .attr("dy", ".35em")
        .style("text-anchor", "middle")
        .style("fill", self.options.labelColor)
        .text(function(d) { return d.data[self.options.label] + ' (' + d.value + ')' })

      t.exit().remove()
    }

    this.updateLegend()
  }
  , mouseOver: function(d, i, el) {<commit_msg>add total and abbreviate options<commit_after>//PieChart extends Chart

GeoDash.PieChart = ezoop.ExtendedClass(GeoDash.Chart, {
  className: 'PieChart'
  , defaults: {
    label: 'label'
    , value: 'value'
    , colors: ["#f00", "#0f0", "#00f"]
    , innerRadius: 10
    , opacity: 1
    , drawX: false
    , drawY: false
    , title: false
    , padding: 10
    , legend: false
    , legendPosition: 'middle'
    , hover: true
    , arclabels: false
    , gdClass: 'chart-html piechart-svg'
    , valueFormat: d3.format(',.0f')
    , formatPercent: d3.format('.2f')
    , hoverTemplate: "{{label}}: {{value}} ({{percent}}%)"
    , labelColor: "#ccc"
    , legendWidth: 80
    , arcstroke: 2
    , abbreviate: false
    , total: false
    , margin: {
      top: 10
      , right: 10
      , bottom: 10
      , left: 10
    }
  }
  , initialize: function (el, options) {
  }
  , setColors: function(colors){
    this.color = d3.scale.ordinal()
      .range(colors);
  }
  , update: function(data){
    //if(GeoDash.Browser.ielt9) return
    var self = this

    var diameter = Math.min(this.xrange, this.yrange)
    var radius = ( diameter / 2 ) - 4

    this.arc = d3.svg.arc()
      .outerRadius(radius)
      .innerRadius(this.options.innerRadius)

    this.pie = d3.layout.pie()
      .sort(null)
      .value(function(d) { return d[self.options.value] })


    if(!this.options.total) {
      this.total = 0
      data.forEach(function(d, i) {
        d[self.options.value] = +d[self.options.value]
        if(+d[self.options.value] < 0) {
          data.splice(i, 1)
        } else {
          self.total += +d[self.options.value]
        }
      })
    } else {
      this.total = this.options.total
    }
    this.data = data
    this.updateChart()
  }
  , updateChart: function() {
    var self = this
    
    this.color = d3.scale.ordinal()
       .range(this.options.colors)

    var g = this.svg.selectAll(".arc")
      .data(this.pie(this.data))

    g.select('path')
      .style("fill", function(d) { return self.color(d.data[self.options.label]) })
      .attr("d", this.arc)

    g.enter()
      .append("g")
      .attr("class", "arc")
      .append("path")
      .attr("d", this.arc)
      .attr("fill", function(d) { return self.color(d.data[self.options.label]) })
      .attr("fill-opacity", this.options.opacity)
      .attr("stroke-width", this.options.arcstroke)
      .on('mouseover', function (d, i) {
        if(!GeoDash.Browser.touch) {
          self.mouseOver(d, i, this)
        }
      })
      .on('mouseout', function (d, i) {
        if(!GeoDash.Browser.touch) {
          self.mouseOut(d, i, this)
        }
      })
      .on('click', function (d, i) {
        if(self.activeBar === i) {
          self.activeBar = -1
          self.mouseOut(d, i, this)
        } else {
          self.activeBar = i
          self.mouseOver(d, i, this)
        }
      })

    g.exit().remove()

    if(this.options.arclabels) {
      var t = self.svg.selectAll(".arc-text")
            .data(this.pie(this.data))

      t.select("text")
        .attr("transform", function(d) { return "translate(" + self.arc.centroid(d) + ")"; })
        .text(function(d) {
          var label = d.data[self.options.label]
          if(self.options.abbreviate) {
            label = label.substring(0, self.options.abbreviate) + '..'
          }
          return label + ' (' + d.value + ')' 
        })

      t.enter().append("g")
        .attr("class", "arc-text")
        .append("text")
        .attr("transform", function(d) { return "translate(" + self.arc.centroid(d) + ")" })
        .attr("dy", ".35em")
        .style("text-anchor", "middle")
        .style("fill", self.options.labelColor)
        .text(function(d) {
          var label = d.data[self.options.label]
          if(self.options.abbreviate) {
            if(label.length > self.options.abbreviate) {
              label = label.substring(0, self.options.abbreviate) + '..'
            }
          }
          return label + ' (' + d.value + ')' 
        })

      t.exit().remove()
    }

    this.updateLegend()
  }
  , mouseOver: function(d, i, el) {
{'fraction_non_alphanumeric': 0.1776016629855788, 'fraction_numerical': 0.010393659867480837, 'mean_word_length': 2.0620525059665873, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '5249799', 'n_tokens_mistral': 2769, 'n_tokens_neox': 2678, 'n_words': 470}