var WidgetModel = require('../widget-model');
var _ = require('underscore');

/**
 * Model for a time-series widget
 */
module.exports = WidgetModel.extend({
  defaults: {
    normalized: true
  },

  defaultState: _.extend(
    {
      normalized: false
    },
    WidgetModel.prototype.defaultState
  ),

  getState: function () {
    var state = WidgetModel.prototype.getState.call(this);
    var start = this.dataviewModel.get('start');
    var end = this.dataviewModel.get('end');
    var data = this.dataviewModel.get('data');
    var lo = this.get('lo_index');
    var hi = this.get('hi_index');
    var l;
    var m;

    var checkRoughEqual = function (a, b) {
      if (_.isNumber(a) && _.isNumber(b) && (a !== b) && Math.abs(a - b) > Math.abs(start - end) * 0.01) {
        return true;
      }
      return false;
    };

    if (_.isNumber(lo) && _.isNumber(hi)) {
      l = data[lo].start;
      m = data[hi - 1].end;
    } else {
      l = start;
      m = end;
    }

    if (checkRoughEqual(start, l)) {
      state.min = l;
    }
    if (checkRoughEqual(end, m)) {
      state.max = m;
    }

    return state;
  }

});

@@ -867,16 +867,62 @@
 mber(hi)
+ && lo %3C data.length && (hi - 1) %3C data.length
 ) %7B%0A    
@@ -1172,13 +1172,12 @@
 te;%0A  %7D%0A
-%0A
 %7D);%0A

Fix out of bounds error of time-series filter