             @options.width = @svg[0][0].clientWidth
             @options.height = @svg[0][0].clientHeight
 
+        @options.selectionLimit ||= null
         @options.brush ||= {}
         @options.brush.start ||= @options.start
-        @options.brush.end ||= new Date(new Date(@options.brush.start).setDate(@options.brush.start.getDate() + 3))
+        if @options.selectionLimit
+            @options.brush.end ||= new Date(@options.brush.start.getTime() + @options.selectionLimit * 1000)
+        else
+            @options.brush.end ||= new Date(new Date(@options.brush.start).setDate(@options.brush.start.getDate() + 3))
+
+        @selectionConstraint = [
+            new Date(@options.brush.start.getTime() - @options.selectionLimit * 1000),
+            new Date(@options.brush.end.getTime() + @options.selectionLimit * 1000)
+        ]
+
+        @options.display ||= {}
+        @options.display.start ||= @options.domain.start
+        @options.display.end ||= @options.domain.end
+
         @options.debounce ||= 50
         @options.ticksize ||= 3
         @options.datasets ||= []
-        @options.selectionLimit ||= -1
 
         @recordFilter = @options.recordFilter
 

        @brush = d3.svg.brush()
            .x(@scales.x)
            .on('brushstart', =>
                @options.lastZoom = {
                    scale: @options.zoom.scale(),
                    translate: [
                        @options.zoom.translate()[0],
                        @options.zoom.translate()[1],
                    ]
                }

                @options.zoom.on('zoom', null)
            )
            .on('brushend', =>
                @options.zoom
                    .scale(@options.lastZoom.scale)
                    .translate(@options.lastZoom.translate)
                    .on('zoom', => @redraw)

                # Check for selection limit and reduce to correct size
                if @options.selectionLimit > 0
                    @svg.selectAll('.brush')
                        .attr({fill: "#333"})
                    s = @brush.extent()
                    if (s[1]-s[0])/1000 >= @options.selectionLimit
                        tmpdate = new Date(@brush.extent()[0].getTime() + @options.selectionLimit * 1000)
                        @brush.extent([@brush.extent()[0], tmpdate])
                        d3.select(@element).select('g.brush').call(@brush)

                @element.dispatchEvent(
                    new CustomEvent('selectionChanged', {
                        detail: {

            )

        # create the zoom behavior
        minScale = (@options.display.start - @options.display.end) / (@options.domain.start - @options.domain.end)

        @options.zoom = d3.behavior.zoom()
            .x(@scales.x)
            .size([@options.width, @options.height])
            .scaleExtent([minScale, Infinity])
            .on('zoom', =>
                if @brushing
                    @options.zoom.scale(@prevScale)
                    @options.zoom.translate(@prevTranslate)
                else
                    [start, end] = @scales.x.domain();
                    @center(start, end)
            )
        @svg.call(@options.zoom)

        # initialize all datasets
