   d3.format(".#{ndig}f")
 
 # reorganize lod/pos in data by chromosome
-reorgData = (data) ->
+reorgData = (data, lodvarname) ->
   data.posByChr = {}
   data.lodByChr = {}
   for chr,i in data.chrnames

  yscale = d3.scale.linear()
  xscale = null
  lodcurve = null

  ## the main function
  chart = (selection) ->
    selection.each (data) ->
      if !(ylim?)
        ylim = [0, d3.max(data.lod)]

      # Select the svg element, if it exists.
      svg = d3.select(this).selectAll("svg").data([data])

        yticks = yscale.ticks(nyticks)

      # reorganize lod,pos by chromosomes
      data = reorgData(data, lodvarname)
      
      # chromosome scales
      data = chrscales(data, width, chrGap)
