Open joelgombin opened 10 years ago
This makes sense. In fact, I should only be loading the minimal js file required for the plot at hand. So, if scope is usa
, I should load only the us
version, while if the user specifies a dataURL
, I should only load datamaps.non.min.js
.
Thanks for an excellent suggestion. I will leave this issue open to serve as a to-do item for me.
To Do
I would make a pull request to help if only I were more familiar with reference classes!
The trouble is that currently, the logic for what js files to include is in config.yml. To implement, what you suggest, I need to remove datamaps.all.min.js
from config.yml
and insert the right js file dynamically using the addAssets
method seen here. The basic idea will be to determine what js
file to add depending on scope
.
If you can write a simple function that accepts the scope
variable as an argument, and returns the path to the correct js
file to add, then it would be easy to use it in the ichoropleth
function.
I guess this should do the trick?
getJSdependancy <- function(scope) {
switch(scope,
"usa" = "http://datamaps.github.io/scripts/datamaps.usa.min.js",
"world" = "http://datamaps.github.io/scripts/datamaps.world.min.js",
"http://datamaps.github.io/scripts/datamaps.none.min.js")
}
Yes, that sounds about right. I would modify it a bit.
getJSdependency <- function(scope, baseurl = "http://datamaps.github.io/scripts/datamaps"){
map = switch(scope, usa = "usa", world = "world", "none")
paste(baseurl, map, "min.js", sep = ".")
}
This provides us the flexibility to set baseurl to a local folder or an online one.
By default,
rMaps
links to http://datamaps.github.io/scripts/datamaps.all.min.js. But when using a customtopojson
file, this is actually overkill, and linking to http://datamaps.github.io/scripts/datamaps.none.min.js would be enough (and of course quicker to load).