text: import {extent} from "d3-array";
  
  import {date} from "d3plus-axis";
  import {elem} from "d3plus-common";
  
  /**
      @function setTimeFilter
      @desc Determines whether or not to update the timeFilter method of the Viz.
      @param {Array|Date} The timeline selection given from the d3 brush.
      @private
  */
  function setTimeFilter(s) {
    var this$1 = this;
  
    if (JSON.stringify(s) !== JSON.stringify(this._timelineSelection)) {
      this._timelineSelection = s;
      if (!(s instanceof Array)) { s = [s, s]; }
      s = s.map(Number);
      this.timeFilter(function (d) {
        var ms = date(this$1._time(d)).getTime();
        return ms >= s[0] && ms <= s[1];
      }).render();
    }
  }
  
  /**
      @function _drawTimeline
      @desc Renders the timeline if this._time and this._timeline are not falsy and there are more than 1 tick available.
      @param {Array} data The filtered data array to be displayed.
      @private
  */
  export default function(data) {
    var this$1 = this;
    if ( data === void 0 ) data = [];
  
  
    var timelinePossible = this._time && this._timeline;
    var ticks = timelinePossible ? Array.from(new Set(this._data.map(this._time))).map(date) : [];
    timelinePossible = timelinePossible && ticks.length > 1;
  
    var transform = {transform: ("translate(" + (this._margin.left + this._padding.left) + ", 0)")};
  
    var timelineGroup = elem("g.d3plus-viz-timeline", {
      condition: timelinePossible,
      enter: transform,
      parent: this._select,
      transition: this._transition,
      update: transform
    }).node();
  
    if (timelinePossible) {
  
      var timeline = this._timelineClass
        .domain(extent(ticks))
        .duration(this._duration)
        .height(this._height - this._margin.bottom)
        .select(timelineGroup)
        .ticks(ticks.sort(function (a, b) { return +a - +b; }))
        .width(this._width - (this._margin.left + this._margin.right + this._padding.left + this._padding.right));
  
      if (this._timelineSelection === void 0) {
  
        var dates = extent(data.map(this._time).map(date));
        this._timelineSelection = dates[0] === dates[1] ? dates[0] : dates;
        timeline.selection(this._timelineSelection);
  
      }
  
      var config = this._timelineConfig;
  
      timeline
        .config(config)
        .on("brush", function (s) {
          setTimeFilter.bind(this$1)(s);
          if (config.on && config.on.brush) { config.on.brush(s); }
        })
        .on("end", function (s) {
          setTimeFilter.bind(this$1)(s);
          if (config.on && config.on.end) { config.on.end(s); }
        })
        .render();
  
      this._margin.bottom += timeline.outerBounds().height + timeline.padding() * 2;
  
    }
  
  }
  
  //# sourceMappingURL=_drawTimeline.js.map