ramnathv / rCharts

Interactive JS Charts from R
http://rcharts.io
Other
1.19k stars 654 forks source link

javascript literals ignored for setProjection in datamaps #415

Open ghost opened 10 years ago

ghost commented 10 years ago

This may be something which you are already aware of, but thought I'd document it in case it causes issues for anyone else.

As documented elsewhere, when creating a datamaps object using a custom topojson file, you have to define a new setProjection() function. In R, you do this using a string surrounded by javascript literals (#!):

d$set(setProjection = "#! function(element, options) {
                                    var projection = d3.geo.albersUsa()
                                      .scale(element.offsetWidth)
                                      .translate([element.offsetWidth / 2, element.offsetHeight / 2]);

                                     var path = d3.geo.path().projection(projection);
                                     return {path: path, projection: projection};
                                  } !#")

When you save to html using rMaps, the javascript literals are treated properly, and the output html includes the following:

"setProjection":  function(element, options) {
      var projection = d3.geo.albersUsa()
        .scale(100)
        .translate([element.offsetWidth / 2, element.offsetHeight / 2]);

       var path = d3.geo.path().projection(projection);
       return {path: path, projection: projection};
    } 

However, in rCharts, the js literals are ignored and the setProjection option shows up as a string rather than a function in the output html file:

"setProjection": "#! function(element, options) {\n                                    var projection = d3.geo.albersUsa()\n                                      .scale(element.offsetWidth)\n                                      .translate([element.offsetWidth / 2, element.offsetHeight / 2]);\n                               \n                                     var path = d3.geo.path().projection(projection);\n                                     return {path: path, projection: projection};\n                                  } !#",
ramnathv commented 10 years ago

Datamaps will be removed from rCharts as I have moved all development to rMaps.