 angular.module('ldEditor').directive 'choropleth', ($timeout, ngProgress) ->
-
-  svg = null
-  mapGroup = null
 
   defaults =
     projection: d3.geo.mercator()

    template: "<div style='position:relative' class='choropleth-map'></div>"
    link: (scope, element, attrs) ->
      # set up initial svg object
      svg = d3.select(element[0])
        .append("svg")
          .attr("width", '100%')
          .attr("height", '0px')
      mapGroup = svg.append("g")
        .attr('class', 'map')

      $(element).append("""

  renderDataMap = (scope, map, data) ->
    path = d3.geo.path().projection(scope.projection || defaults.projection)

    mapPaths = scope.mapGroup.selectAll('path')
        .data(map.features)
    mapPaths.enter().append('path')
      .attr('d', path)

    bounds =  path.bounds(map)
    resizeMap(scope.svg, bounds)

    if data
      quantize = d3.scale.quantize()
