<commit_before>define([
  './axis'
],
function (Axis) {

  var XAxis = Axis.extend({

    classed: 'x-axis',
    position: 'bottom',
    orient: 'bottom',
    offsetY: 8,
    tickPadding: 6,
    render: function () {
      Axis.prototype.render.apply(this, arguments);
      if (this.useEllipses) {
        this.ellipsifyAxisLabels();
      }
    },
    ellipsifyAxisLabels: function() {

      // Manually add ellipses to x-axis labels if they are longer than the
      // space allocated for each data item.
      // We do this by hand with D3, because SVG text elements don't support
      // CSS ellipsis styles or line breaks.
      var labels = d3.selectAll('.x-axis .tick text');
      if (!this.svg) {
        this.svg = d3.select('svg'); // For unit tests.
      }
      var svgWidth = this.svg.style('width').replace('px','');
      var blockWidth = svgWidth / this.collection.first().get('values').length;

      labels.each(function() {

        if (d3.select(this).attr('original-text') === null) {
          d3.select(this).attr('original-length-px', this.getComputedTextLength());
          d3.select(this).attr('original-text', d3.select(this).text());
        }

        var textLength = d3.select(this).attr('original-length-px');
        var text = d3.select(this).attr('original-text');

        if (textLength > (blockWidth)) {
          var percentTooLong = blockWidth / textLength;
          var lastChar = (text.length * percentTooLong) - 3;
          d3.select(this).text(text.substring(0,lastChar) + "…");
        } else {
          d3.select(this).text(text);
        }

      });
    },

    getScale: function () {
      return this.scales.x;
    },

    onChangeSelected: function (groupSelected, groupIndexSelected, modelSelected, indexSelected) {
      var ticks = this.componentWrapper.selectAll('.tick');
      ticks.classed('selected', false);

      if (indexSelected != null) {
        d3.select(ticks[0][indexSelected]).classed('selected', true);
      }
    },

    configs: {
      hour: {
        ticks: [d3.time.hour.utc, 6],
        tickFormat: function () {
          return _.bind(function (d, index) {
            var date = this.getMoment(d);
            if (date.hours() === 0) {
              return 'midnight';
            } else if (date.hours() === 12) {
              return 'midday';
            } else {
              return this.getMoment(d).format('ha');
            }
          }, this);
        }
      },
      day: {
        ticks: [d3.time.mondays.utc, 1],
        tickFormat: function () {
          return _.bind(function (d, index) {
            return this.getMoment(d).format('D MMM');
          }, this);
        }
      },
      week: {
        ticks: [d3.time.mondays.utc, 1],
        tickFormat: function () {
          return _.bind(function (d, index) {
            return this.getMoment(d).format('D MMM');
          }, this);
        }
      },
      month: {
        ticks: [d3.time.month.utc, 1],
        tickFormat: function () {
          return _.bind(function (d, index) {
            var val = this.getMoment(d).format('MMM');
            if (d.getMonth() === 0) {
              val += " " + this.getMoment(d).format('YYYY');
            }
            return val;
          }, this);
        }<commit_msg>Fix client-side error (D3 not loaded) in old IE<commit_after>define([
  'd3loader!',
  './axis'
],
function (d3, Axis) {

  var XAxis = Axis.extend({

    d3: d3,

    classed: 'x-axis',
    position: 'bottom',
    orient: 'bottom',
    offsetY: 8,
    tickPadding: 6,
    render: function () {
      Axis.prototype.render.apply(this, arguments);
      if (this.useEllipses) {
        this.ellipsifyAxisLabels();
      }
    },
    ellipsifyAxisLabels: function() {

      // Manually add ellipses to x-axis labels if they are longer than the
      // space allocated for each data item.
      // We do this by hand with D3, because SVG text elements don't support
      // CSS ellipsis styles or line breaks.
      var labels = d3.selectAll('.x-axis .tick text');
      if (!this.svg) {
        this.svg = d3.select('svg'); // For unit tests.
      }
      var svgWidth = this.svg.style('width').replace('px','');
      var blockWidth = svgWidth / this.collection.first().get('values').length;

      labels.each(function() {

        if (d3.select(this).attr('original-text') === null) {
          d3.select(this).attr('original-length-px', this.getComputedTextLength());
          d3.select(this).attr('original-text', d3.select(this).text());
        }

        var textLength = d3.select(this).attr('original-length-px');
        var text = d3.select(this).attr('original-text');

        if (textLength > (blockWidth)) {
          var percentTooLong = blockWidth / textLength;
          var lastChar = (text.length * percentTooLong) - 3;
          d3.select(this).text(text.substring(0,lastChar) + "…");
        } else {
          d3.select(this).text(text);
        }

      });
    },

    getScale: function () {
      return this.scales.x;
    },

    onChangeSelected: function (groupSelected, groupIndexSelected, modelSelected, indexSelected) {
      var ticks = this.componentWrapper.selectAll('.tick');
      ticks.classed('selected', false);

      if (indexSelected != null) {
        d3.select(ticks[0][indexSelected]).classed('selected', true);
      }
    },

    configs: {
      hour: {
        ticks: function () {
          var d3 = this.d3;
          return [d3.time.hour.utc, 6];
        },
        tickFormat: function () {
          return _.bind(function (d, index) {
            var date = this.getMoment(d);
            if (date.hours() === 0) {
              return 'midnight';
            } else if (date.hours() === 12) {
              return 'midday';
            } else {
              return this.getMoment(d).format('ha');
            }
          }, this);
        }
      },
      day: {
        ticks: function () {
          var d3 = this.d3;
          return [d3.time.mondays.utc, 1];
        },
        tickFormat: function () {
          return _.bind(function (d, index) {
            return this.getMoment(d).format('D MMM');
          }, this);
        }
      },
      week: {
        ticks: function () {
          var d3 = this.d3;
          return [d3.time.mondays.utc, 1];
        },
        tickFormat: function () {
          return _.bind(function (d, index) {
            return this.getMoment(d).format('D MMM');
          }, this);
        }
      },
      month: {
        ticks: function () {
          var d3 = this.d3;
          return [d3.time.month.utc, 1];
        },
        tickFormat: function () {
          return _.bind(function (d, index) {
            var val = this.getMoment(d).format('MMM');
            if (d.getMonth() === 0) {
              val += " " + this.getMoment(d).format('YYYY');
            }
            return val;
          }, this);
        }
{'fraction_non_alphanumeric': 0.1531791907514451, 'fraction_numerical': 0.010260115606936416, 'mean_word_length': 1.8214431308601713, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7301594', 'n_tokens_mistral': 2173, 'n_tokens_neox': 2113, 'n_words': 452}