 
   {
     chart: chart
-  }
-
+  }
    # Data input domains
    xScale.domain data.map (d) -> d[xKey]  # TODO
    yScale.domain [ 0, d3.max(data, (d) -> d[yKey]) ]  # TODO
    # Select the svg element, if it exists.
    svg = selection.selectAll("svg").data [data]
    # Otherwise, create the skeletal chart.
    gEnter = svg.enter().append("svg").append("g")
    gEnter.append("g").attr "class", "x axis"
    gEnter.append("g").attr "class", "y axis"
    # Set the outer dimensions.
    svg.attr("width", width + margin.left + margin.right)
      .attr("height", height + margin.top + margin.bottom)
    g = svg.select("g")
      # move right x pixels, move down y pixels:
      .attr("transform", "translate(" + margin.left + "," + margin.top + ")")
    # Update the x-axis.
    g.select(".x.axis")
      .attr("transform", "translate(0," + height + ")")
      .call(xAxis)
    # Update the y-axis.
    g.select(".y.axis")
      .call(yAxis)
    # bars!
    bar = svg.selectAll('.bar').data data
    #  .data (data) -> data[yKey]
    bar.enter()
      .append("rect")
      .attr("class", (d) -> "bar b_#{d[xKey]}")
      .attr("x", (d) -> xScale(d[xKey]) + margin.left)
      .attr("width", 0)
      .attr("y", (d) -> height )
      .attr("height", (d) -> 0)
      .style "fill", "LightSteelBlue "
    bar.exit().remove()
    bar.transition()
      .duration(500)
      .attr("x", (d) -> xScale(d[xKey]) + margin.left)
      .attr("width", xScale.rangeBand())
      .attr("y", (d) -> yScale(d[yKey]) + margin.top )
      .attr "height", (d) -> height - yScale(d[yKey])

  chart.width = (c) ->
    return width  unless arguments.length

    format: d3.format(".0")
    xScale: d3.scale.ordinal()
    yScale: d3.scale.linear()
  }

  margin = conf.margin
  calculateHeight = nrtViz.utils.calculateHeight
  width = conf.width - conf.margin.left - conf.margin.right
  # calculateHeight: (width, widthRatio, heightRatio) ->
  height = calculateHeight(conf.width, 2, 1.2) - conf.margin.bottom - 
    conf.margin.top
  xKey = conf.xKey
  yKey = conf.yKey
  xAxis = d3.svg.axis().scale(conf.xScale).orient("bottom")
  yAxis = d3.svg.axis().scale(conf.yScale).orient("left")
    .tickFormat(conf.format)

  setSvg = (selection, data) ->
    svg = selection.selectAll("svg").data data
    svg.enter().append("svg")
      .attr("width", width + margin.left + margin.right)
      .attr("height", height + margin.top + margin.bottom)
    
  setGOuter = (selection, data) ->
    g = selection.selectAll('g.wrapper').data [data]
    g.enter().append('g').attr("class", "wrapper")
      .attr("transform", "translate(" + margin.left + "," + margin.top + ")")

  setgAxis = (selection, data) ->
    gAxis = selection.selectAll('g.axis').data [data]
    gAxis.enter().append('g').attr("class", "axis")
    gAxis.append("g").attr("class", "x axis")
    gAxis.append("g").attr("class", "y axis")
    # Update the x-axis.
    gAxis.select(".x.axis")
      .attr("transform", "translate(0," + height + ")")
      .call(xAxis)
    # Update the y-axis.
    gAxis.select(".y.axis")
      .call(yAxis)
    gAxis

  setGBars = (selection, data) ->
    gBars = selection.selectAll('g.bars').data [data]
    gBars.enter().append("g").attr("class", "bars")

  setBars =  (args) ->
    bars = args.selection.selectAll('.bar').data args.data
    bars.enter()
      .append("rect")
      .attr("class", (d) -> "bar b_#{d[xKey]}")
      .attr("x", (d) -> args.xScale(d[xKey]) + margin.left)
      .attr("width", 0)
      .attr("y", (d) -> height )
      .attr("height", (d) -> 0)
      .style "fill", "LightSteelBlue"
    bars.exit().remove()
    bars.transition()
      .duration(500)
      .attr("x", (d) -> args.xScale(d[xKey]))
      .attr("width", args.xScale.rangeBand())
      .attr("y", (d) -> args.yScale(d[yKey]))
      .attr "height", (d) -> height - args.yScale(d[yKey])
    bars

  chart = (selection) ->
    xScale = conf.xScale
    yScale = conf.yScale
    # rangeRoundBands [min, max], padding, outer-padding
    xScale.rangeRoundBands [0, width], .1, .1
    yScale.range [height, 0]
