 # Dataset utility class for internal use only
 class Dataset
     constructor: (options) ->
-        { @id,  @color, @source, @sourceParams, @index, @records, @paths, @lineplot, @ordinal, @element } = options
+        { @id,  @color, @source, @sourceParams, @index, @records, @paths, @lineplot, @ordinal, @element, @histogram } = options
         @syncDebounced = debounce(@sync, options.debounceTime)
 
     getSource: ->

            .call((recordElement) => @setupRecord(recordElement, dataset))

        p.exit().remove()

    drawPaths: (datasetElement, dataset, data) ->
        @scales.y.domain(d3.extent(data, (d) -> d[1]))

            )
        )

    setupBin: (binElement, dataset, y) ->
        binElement
            .attr("class", "bin")
            .attr("stroke", dataset.color)
            .attr("x", 1)
            .attr("width", (d) => @scales.x(d.x.getTime() + d.dx) - @scales.x(d.x) - 1)
            .attr("transform", (d) => "translate(" + @scales.x(new Date(d.x)) + ",-" + y(d.length) + ")")
            .attr("height", (d) -> y(d.length))

        binElement
          .on("mouseover", (bin) =>
            @element.dispatchEvent(
                new CustomEvent('binMouseover', {
                    detail: {
                        dataset: dataset.id,
                        start: bin.x,
                        end: new Date(bin.x.getTime() + bin.dx),
                        bin: bin
                    }
                    bubbles: true,
                    cancelable: true
                })
            )

            if bin.length
                names = bin.filter((r) -> r[2] && (r[2].name || r[2].id))
                  .map((r) -> (r[2].name || r[2].id))

                if names.length
                    @tooltip.transition()
                        .duration(200)
                        .style("opacity", .9)
                    @tooltip.html(names.join("<br>"))
                        .style("left", (d3.event.pageX) + "px")
                        .style("top", (d3.event.pageY - 28) + "px")
          )
          .on("mouseout", (bin) =>
            @element.dispatchEvent(
                new CustomEvent('binMouseout', {
                    detail: {
                        dataset: dataset.id,
                        start: bin.x,
                        end: new Date(bin.x.getTime() + bin.dx),
                        bin: bin
                    }
                    bubbles: true,
                    cancelable: true
                })
            )
            @tooltip.transition()
                .duration(500)
                .style("opacity", 0)
          )
          .on('click', (bin) =>
            @element.dispatchEvent(
                new CustomEvent('binClicked', {
                    detail: {
                        dataset: dataset.id,
                        start: bin.x,
                        end: new Date(bin.x.getTime() + bin.dx),
                        bin: bin
                    }
                    bubbles: true,
                    cancelable: true
                })
            )
          )

    drawRanges: (datasetElement, dataset, records) ->
        datasetElement.selectAll('rect').remove()

