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

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

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

    bounds =  path.bounds(map)
    resizeMap(bounds)

    if data
      quantize = d3.scale.quantize()


  # sets the viewBox attribute on the svg element to cover the whole map
  # dynamically adjusts the snippet height to the ratio to the viewBox
  resizeMap = (svg, bounds) ->
    svgHeight = bounds[1][1] - bounds[0][1]
    svgWidth = bounds[1][0] - bounds[0][0]
    svg.attr('viewBox', "#{bounds[0][0]} #{bounds[0][1]} #{svgWidth} #{svgHeight}")
