<commit_before>import _ from 'lodash'
import d3 from 'd3'

import qualitativeAxis from './qualitative-axis'

var defaults = {
  domain: _.constant([0, 1]),
  fontSize: 10,
  lineHeight: 1.2,
  padding: 0,
  scale: d3.scale.linear,
  thresholds: [],
  targets: [],
  format: String,

  margin: {
    top: 0,
    right: 0,
    bottom: 0,
    left: 0
  }
}

function BulletChart () {
}

_.extend(BulletChart.prototype, {
  defaults: defaults,

  initialize: function (el, data, options) {
    options = this._options = _.defaults({}, options, defaults)

    var n = Math.max(data.length, 1)
    var height = options.fontSize * n * options.lineHeight +
      options.fontSize * options.padding * (n - 1) +
      options.margin.top +
      options.margin.bottom

    this._width = el.clientWidth

    var svg = this._svg = d3.select(el).append('svg')
      .attr({
        'viewBox': '0 0 ' + this._width + ' ' + height,
        'width': this._width,
        'height': height
      })

    // Append the x-axis container and a blank background
    svg.append('g').attr('class', 'x axis')

    // Append a data layer
    svg.append('g')
      .attr({
        'class': 'data',
        'transform': 'translate(' + options.margin.left + ', ' + options.margin.top + ')'
      })

    this.update(data)
  },

  update: function (data, options) {
    options = _.assign(this._options, options)

    var margin = options.margin
    var svg = this._svg

    var n = Math.max(data.length, 1)
    var h = options.fontSize * n * options.lineHeight + options.fontSize * options.padding * (n - 1)
    var w = this._width - margin.left - margin.right

    var yScale = d3.scale.ordinal()
      .domain(_(data).flatten().map(options.y).uniq().value())
      .rangeRoundBands([h, 0])

    var y = _.flow(options.y, yScale)

    var xScale = options.scale()
      .domain(options.domain(data))
      .range([0, w])

    var x = _.flow(options.marker, xScale)
    var width = _.flow(options.value, xScale)

    var isEmpty = !_(data).map(options.value).all(_.isFinite)

    // Draw qualitative ranges
    if (!(isEmpty || _.isEmpty(options.thresholds) || _.isEmpty(options.targets))) {
      var tick = svg.select('.x.axis').selectAll('.tick').data(data)

      tick.enter()
        .append('g')
        .attr('class', 'tick')
        .style('fill', options.axisFill)
      tick.exit().remove()

      var rect = tick.selectAll('rect').data(function (d) {
        return isEmpty ? [] : [d]
      })
      rect.enter().append('rect')
        .style('fill', 'inherit')

      rect
        .attr({
          'height': h + margin.top + margin.bottom,
          'width': w
        })
    } else {
      svg.select('.x.axis')
        .call(qualitativeAxis()
          .height(h + margin.top + margin.bottom)
          .width(w)
          .scale(xScale)
          .threshold(d3.scale.threshold()
            .domain([])
            .range([''])
        )
          .colors(['#F2F2F2', '#F2F2F2'])
      )
    }

    svg.attr({
      'viewBox': '0 0 ' + w + ' ' + (h + margin.top + margin.bottom),
      'width': w,
      'height': h + margin.top + margin.bottom
    })

    svg.select('.data')
      .call(qualitativeAxis()
      .height(h + margin.top + margin.bottom)
      .scale(xScale)
      .threshold(d3.scale.threshold().domain(options.thresholds).range(options.targets))
    )

    var g = svg.select('.data')
      .attr('transform', 'translate(' + margin.left + ', ' + margin.top + ')')

    // Draw value
    var bar = g.selectAll('.bar').data(data)

    bar.enter().append('g')
    bar
      .attr({
        'class': 'bar',
        'y': y
      })
      .style('fill', options.dataFill)
    bar.exit().remove()

    var value = bar.selectAll('.value').data(function (d) {
      return isEmpty ? [] : [d]
    })

    var valueAttr = {
      'class': 'value',
      'height': yScale.rangeBand()
    }

    value.enter()
      .append('rect')
      .attr(valueAttr)
      .style('fill', 'inherit')<commit_msg>add border radius to bullet charts<commit_after>import _ from 'lodash'
import d3 from 'd3'

import qualitativeAxis from './qualitative-axis'

var defaults = {
  domain: _.constant([0, 1]),
  fontSize: 10,
  lineHeight: 1.2,
  padding: 0,
  scale: d3.scale.linear,
  thresholds: [],
  targets: [],
  format: String,

  margin: {
    top: 0,
    right: 0,
    bottom: 0,
    left: 0
  }
}

function BulletChart () {
}

_.extend(BulletChart.prototype, {
  defaults: defaults,

  initialize: function (el, data, options) {
    options = this._options = _.defaults({}, options, defaults)

    var n = Math.max(data.length, 1)
    var height = options.fontSize * n * options.lineHeight +
      options.fontSize * options.padding * (n - 1) +
      options.margin.top +
      options.margin.bottom

    this._width = el.clientWidth

    var svg = this._svg = d3.select(el).append('svg')
      .attr({
        'viewBox': '0 0 ' + this._width + ' ' + height,
        'width': this._width,
        'height': height
      })

    // Append the x-axis container and a blank background
    svg.append('g').attr('class', 'x axis')

    // Append a data layer
    svg.append('g')
      .attr({
        'class': 'data',
        'transform': 'translate(' + options.margin.left + ', ' + options.margin.top + ')'
      })

    this.update(data)
  },

  update: function (data, options) {
    options = _.assign(this._options, options)

    var margin = options.margin
    var svg = this._svg

    var n = Math.max(data.length, 1)
    var h = options.fontSize * n * options.lineHeight + options.fontSize * options.padding * (n - 1)
    var w = this._width - margin.left - margin.right

    var yScale = d3.scale.ordinal()
      .domain(_(data).flatten().map(options.y).uniq().value())
      .rangeRoundBands([h, 0])

    var y = _.flow(options.y, yScale)

    var xScale = options.scale()
      .domain(options.domain(data))
      .range([0, w])

    var x = _.flow(options.marker, xScale)
    var width = _.flow(options.value, xScale)

    var isEmpty = !_(data).map(options.value).all(_.isFinite)

    // Draw qualitative ranges
    if (!(isEmpty || _.isEmpty(options.thresholds) || _.isEmpty(options.targets))) {
      var tick = svg.select('.x.axis').selectAll('.tick').data(data)

      tick.enter()
        .append('g')
        .attr('class', 'tick')
        .style('fill', options.axisFill)
      tick.exit().remove()

      var rect = tick.selectAll('rect').data(function (d) {
        return isEmpty ? [] : [d]
      })
      rect.enter().append('rect')
        .style('fill', 'inherit')

      rect
        .attr({
          'height': h + margin.top + margin.bottom,
          'width': w,
          'ry': 5
        })
    } else {
      svg.select('.x.axis')
        .call(qualitativeAxis()
          .height(h + margin.top + margin.bottom)
          .width(w)
          .scale(xScale)
          .threshold(d3.scale.threshold()
            .domain([])
            .range([''])
        )
          .colors(['#F2F2F2', '#F2F2F2'])
      )
    }

    svg.attr({
      'viewBox': '0 0 ' + w + ' ' + (h + margin.top + margin.bottom),
      'width': w,
      'height': h + margin.top + margin.bottom
    })

    svg.select('.data')
      .call(qualitativeAxis()
      .height(h + margin.top + margin.bottom)
      .scale(xScale)
      .threshold(d3.scale.threshold().domain(options.thresholds).range(options.targets))
    )

    var g = svg.select('.data')
      .attr('transform', 'translate(' + margin.left + ', ' + margin.top + ')')

    // Draw value
    var bar = g.selectAll('.bar').data(data)

    bar.enter().append('g')
    bar
      .attr({
        'class': 'bar',
        'y': y
      })
      .style('fill', options.dataFill)
    bar.exit().remove()

    var value = bar.selectAll('.value').data(function (d) {
      return isEmpty ? [] : [d]
    })

    var valueAttr = {
      'class': 'value',
      'height': yScale.rangeBand(),
      'ry': 5
    }

    value.enter()
      .append('rect')
      .attr(valueAttr)
      .style({
        'fill': 'inherit',
        'stroke': '#fff'
      })
{'fraction_non_alphanumeric': 0.17374613003095976, 'fraction_numerical': 0.0086687306501548, 'mean_word_length': 2.169544740973312, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5187035', 'n_tokens_mistral': 2739, 'n_tokens_neox': 2627, 'n_words': 559}