<commit_before>buckets = require "../../../../../util/buckets.coffee"
closest = require "../../../../../util/closest.coffee"

module.exports = (vars, axis, buffer) ->

  if vars[axis].scale.value isnt "share" and !vars[axis].range.value and vars[axis].reset

    testScale = vars[axis].scale.viz.copy()
    testScale.clamp(false) if "clamp" of testScale

    if axis is vars.axes.discrete

      domain = testScale.domain()

      if typeof domain[0] is "string"
        i = domain.length
        while i >= 0
          domain.splice(i, 0, "d3plus_buffer_"+i)
          i--
        range = testScale.range()
        range = buckets d3.extent(range), domain.length
        vars[axis].scale.viz.domain(domain).range(range)

      else

        domain = domain.slice().reverse() if axis.indexOf("y") is 0

        if vars[axis].ticks.values.length is 1
          if vars[axis].value is vars.time.value and
             vars.data.time.ticks.length isnt 1
            closestTime = closest(vars.data.time.ticks, domain[0])
            timeIndex = vars.data.time.ticks.indexOf(closestTime)
            if timeIndex > 0
              domain[0] = vars.data.time.ticks[timeIndex - 1]
            else
              diff = vars.data.time.ticks[timeIndex + 1] - closestTime
              domain[0] = new Date(closestTime.getTime() - diff)
            if timeIndex < vars.data.time.ticks.length - 1
              domain[1] = vars.data.time.ticks[timeIndex + 1]
            else
              diff = closestTime - vars.data.time.ticks[timeIndex - 1]
              domain[1] = new Date(closestTime.getTime() + diff)
          else
            domain[0] -= 1
            domain[1] += 1

        else if vars.axes.scale

          difference = Math.abs domain[1] - domain[0]<commit_msg>fixes issue with single-entry discrete number axis (closes #485)<commit_after>buckets = require "../../../../../util/buckets.coffee"
closest = require "../../../../../util/closest.coffee"

module.exports = (vars, axis, buffer) ->

  if vars[axis].scale.value isnt "share" and !vars[axis].range.value and vars[axis].reset

    testScale = vars[axis].scale.viz.copy()
    testScale.clamp(false) if "clamp" of testScale

    if axis is vars.axes.discrete

      domain = testScale.domain()

      if typeof domain[0] is "string"
        i = domain.length
        while i >= 0
          domain.splice(i, 0, "d3plus_buffer_"+i)
          i--
        range = testScale.range()
        range = buckets d3.extent(range), domain.length
        vars[axis].scale.viz.domain(domain).range(range)

      else

        domain = domain.slice().reverse() if axis.indexOf("y") is 0

        if vars[axis].ticks.values.length is 1
          domain = [domain[0], domain[0]]
          if vars[axis].value is vars.time.value and
             vars.data.time.ticks.length isnt 1
            closestTime = closest(vars.data.time.ticks, domain[0])
            timeIndex = vars.data.time.ticks.indexOf(closestTime)
            if timeIndex > 0
              domain[0] = vars.data.time.ticks[timeIndex - 1]
            else
              diff = vars.data.time.ticks[timeIndex + 1] - closestTime
              domain[0] = new Date(closestTime.getTime() - diff)
            if timeIndex < vars.data.time.ticks.length - 1
              domain[1] = vars.data.time.ticks[timeIndex + 1]
            else
              diff = closestTime - vars.data.time.ticks[timeIndex - 1]
              domain[1] = new Date(closestTime.getTime() + diff)
          else
            domain[0] -= 1
            domain[1] += 1

        else if vars.axes.scale

          difference = Math.abs domain[1] - domain[0]
{'fraction_non_alphanumeric': 0.13542526837324526, 'fraction_numerical': 0.015139003578309936, 'mean_word_length': 1.9212218649517685, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '5211225', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1106, 'n_words': 248}