diff --git a/DESCRIPTION b/DESCRIPTION
index ae186151..60fc2c87 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,7 +1,7 @@
Package: leaflet.extras
Type: Package
Title: Extra functionality for leaflet package
-Version: 0.1.3
+Version: 0.1.4
Authors@R: person("Bhaskar", "Karambelkar", email = "bhaskarvk@gmail.com",
role = c("aut", "cre"))
Description: Leaflet Javascript library provides many plugins some of which
diff --git a/NAMESPACE b/NAMESPACE
index 60b800c5..ada02b3a 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -6,10 +6,12 @@ export(addFullscreenControl)
export(addGeoJSONChoropleth)
export(addHash)
export(addPulseMarkers)
+export(addTopoJSONChoropleth)
export(addWMSLegend)
export(addWeatherMarkers)
export(addWebGLHeatmap)
export(clearGeoJSONChoropleth)
+export(clearTopoJSONChoropleth)
export(clearWebGLHeatmap)
export(enableTileCaching)
export(makePulseIcon)
@@ -17,6 +19,7 @@ export(makeWeatherIcon)
export(pulseIconList)
export(pulseIcons)
export(removeGeoJSONChoropleth)
+export(removeTopoJSONChoropleth)
export(removeWebGLHeatmap)
export(weatherIconList)
export(weatherIcons)
diff --git a/NEWS.md b/NEWS.md
index 46a283ed..521b6582 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,6 +1,11 @@
-# leaflet.extras 0.1.2
+# leaflet.extras 0.1.4
+
+* GeoJSON Choropleth now accepts popupOptions and labelOptions.
+* Added addTopoJSONChoropleth (Thanks [TrantorM](https://github.com/TrantorM)).
+
+# leaflet.extras 0.1.3
-* Added WMS Legend Control
+* Added WMS Legend Control.
# leaflet.extras 0.1.2
diff --git a/R/geojson-choropleth.R b/R/geojson-choropleth.R
index 348617d1..b768bcef 100644
--- a/R/geojson-choropleth.R
+++ b/R/geojson-choropleth.R
@@ -15,7 +15,9 @@ geoJSONChoroplethDependency <- function() {
#' @param group the group this layer will be added to
#' @param valueProperty The property to use for coloring
#' @param popupProperty The property to use for popup content
+#' @param popupOptions The Options for the popup
#' @param labelProperty The property to use for labelling.
+#' @param labelOptions The Options for the label
#' @param scale The scale to use from chroma.js
#' @param steps number of breakes
#' @param mode q for quantile, e for equidistant, k for k-means
@@ -38,8 +40,8 @@ geoJSONChoroplethDependency <- function() {
addGeoJSONChoropleth = function(
map, geojson, layerId = NULL, group = NULL,
valueProperty,
- labelProperty,
- popupProperty,
+ labelProperty, labelOptions = leaflet::labelOptions(),
+ popupProperty, popupOptions = leaflet::popupOptions(),
scale = c('white','red'),
steps =5,
mode = 'q',
@@ -48,8 +50,6 @@ addGeoJSONChoropleth = function(
color = "#03F",
weight = 1,
opacity = 0.5,
- #fill = TRUE,
- #fillColor = color,
fillOpacity = 0.2,
dashArray = NULL,
smoothFactor = 1.0,
@@ -60,7 +60,9 @@ addGeoJSONChoropleth = function(
options = list(
valueProperty=valueProperty,
popupProperty=popupProperty,
+ popupOptions=popupOptions,
labelProperty=labelProperty,
+ labelOptions=labelOptions,
scale=scale,
steps=steps,
mode=mode,
@@ -69,8 +71,6 @@ addGeoJSONChoropleth = function(
color=color,
weight=weight,
opacity=opacity,
- #fill=fill,
- #fillColor=fillColor,
fillOpacity=fillOpacity,
dashArray=dashArray,
smoothFactor=smoothFactor,
diff --git a/R/topojson-choropleth.R b/R/topojson-choropleth.R
new file mode 100644
index 00000000..57ead9f0
--- /dev/null
+++ b/R/topojson-choropleth.R
@@ -0,0 +1,96 @@
+# Source https://github.com/TrantorM/leaflet-choroplethTopoJSON
+topoJSONChoroplethDependency <- function() {
+ list(
+ htmltools::htmlDependency(
+ "topojson-choropleth",version = "0.1.0",
+ system.file("htmlwidgets/lib/topojson-choropleth", package = "leaflet.extras"),
+ script = c("choroplethTopoJSON.min.js","topojson-choropleth-bindings.js")
+ )
+ )
+}
+
+#' @param map The leaflet map
+#' @param data Geojson or topojson data: either as a list or a string
+#' @param layerId a unique ID for the layer
+#' @param group the group this layer will be added to
+#' @param valueProperty The property to use for coloring
+#' @param popupProperty The property to use for popup content
+#' @param popupOptions The Options for the popup
+#' @param labelProperty The property to use for labelling.
+#' @param labelOptions The Options for the label
+#' @param scale The scale to use from chroma.js
+#' @param steps number of breakes
+#' @param mode q for quantile, e for equidistant, k for k-means
+#' @param colors overrides scale with manual colors
+#' @param stroke whether to draw stroke along the path (e.g. the borders of
+#' polygons or circles)
+#' @param color stroke color
+#' @param weight stroke width in pixels
+#' @param opacity stroke opacity (or layer opacity for tile layers)
+#' circles)
+#' @param fillOpacity fill opacity
+#' @param dashArray a string that defines the stroke
+#' \href{https://developer.mozilla.org/en/SVG/Attribute/stroke-dasharray}{dash
+#' pattern}
+#' @param smoothFactor how much to simplify the polyline on each zoom level
+#' (more means better performance and less accurate representation)
+#' @param noClip whether to disable polyline clipping
+#' @rdname topojson-choropleth
+#' @export
+addTopoJSONChoropleth = function(
+ map, data, layerId = NULL, group = NULL,
+ valueProperty,
+ labelProperty, labelOptions = leaflet::labelOptions(),
+ popupProperty, popupOptions = leaflet::popupOptions(),
+ scale = c('white','red'),
+ steps =5,
+ mode = 'q',
+ colors = NULL,
+ stroke = TRUE,
+ color = "#03F",
+ weight = 1,
+ opacity = 0.5,
+ fillOpacity = 0.2,
+ dashArray = NULL,
+ smoothFactor = 1.0,
+ noClip = FALSE
+) {
+ map$dependencies <- c(map$dependencies,
+ topoJSONChoroplethDependency())
+ options = list(
+ valueProperty=valueProperty,
+ popupProperty=popupProperty,
+ popupOptions=popupOptions,
+ labelProperty=labelProperty,
+ labelOptions=labelOptions,
+ scale=scale,
+ steps=steps,
+ mode=mode,
+ colors=colors,
+ stroke=stroke,
+ color=color,
+ weight=weight,
+ opacity=opacity,
+ fillOpacity=fillOpacity,
+ dashArray=dashArray,
+ smoothFactor=smoothFactor,
+ noClip=noClip
+ )
+ leaflet::invokeMethod(
+ map, leaflet::getMapData(map), 'addTopoJSONChoropleth',
+ data, layerId, group, options)
+}
+
+#' removes the topojson choropleth.
+#' @rdname topojson-choropleth
+#' @export
+removeTopoJSONChoropleth = function(map, layerId) {
+ leaflet::invokeMethod(map, leaflet::getMapData(map), 'removeTopoJSONChoropleth', layerId)
+}
+
+#' clears the topojson choropleth.
+#' @rdname topojson-choropleth
+#' @export
+clearTopoJSONChoropleth = function(map) {
+ leaflet::invokeMethod(map, NULL, 'clearTopoJSONChoropleth')
+}
diff --git a/README.md b/README.md
index 3e7a5e75..9e73c6ec 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,8 @@ Plugins integrated so far
- [Pulse Icon](https://github.com/mapshakers/leaflet-icon-pulse) Demo at [Rpubs: Pulse Icons](http://rpubs.com/bhaskarvk/leaflet-pulseIcon)
- [Weather Markers](https://github.com/tallsam/Leaflet.weather-markers) Demo at [Rpubs: Weather Icons](http://rpubs.com/bhaskarvk/leaflet-weather)
-- [Geojson Choropleth](https://github.com/timwis/leaflet-choropleth) Demo at [Rpubs: GeoJSON Choropleth](http://rpubs.com/bhaskarvk/geojson-choropleth)
+- [GeoJSON Choropleth](https://github.com/timwis/leaflet-choropleth) Demo at [Rpubs: GeoJSON Choropleth](http://rpubs.com/bhaskarvk/geojson-choropleth)
+- [TopoJSON Choropleth](https://github.com/TrantorM/leaflet-choroplethTopoJSON) Demo at [Rpubs: GeoJSON Choropleth](http://rpubs.com/bhaskarvk/topojson-choropleth)
- [webgl-heatmap](https://github.com/ursudio/webgl-heatmap-leaflet) Demo at [Rpubs: Heatmap](http://rpubs.com/bhaskarvk/leaflet-heatmap)
- [Tile Caching](https://github.com/MazeMap/Leaflet.TileLayer.PouchDBCached) Demo at [Rpubs: Tile Caching](http://rpubs.com/bhaskarvk/TileLayer-Caching)
- [Leaflet Hash](https://github.com/mlevans/leaflet-hash)
diff --git a/docs/TileCaching.html b/docs/TileCaching.html
index a0ea002c..1c6ff465 100644
--- a/docs/TileCaching.html
+++ b/docs/TileCaching.html
@@ -2,7 +2,7 @@
-enableTileCaching. leaflet.extras 0.1.3
+enableTileCaching. leaflet.extras 0.1.4
@@ -32,7 +32,7 @@
-
leaflet.extras 0.1.3
+
leaflet.extras 0.1.4
Home
diff --git a/docs/fullscreen.html b/docs/fullscreen.html
index b200c1d2..8cf89c2a 100644
--- a/docs/fullscreen.html
+++ b/docs/fullscreen.html
@@ -2,7 +2,7 @@
-addFullscreenControl. leaflet.extras 0.1.3
+addFullscreenControl. leaflet.extras 0.1.4
@@ -32,7 +32,7 @@
-
leaflet.extras 0.1.3
+
leaflet.extras 0.1.4
Home
diff --git a/docs/geojson-choropleth.html b/docs/geojson-choropleth.html
index af36e588..10ed52dc 100644
--- a/docs/geojson-choropleth.html
+++ b/docs/geojson-choropleth.html
@@ -2,7 +2,7 @@
-addGeoJSONChoropleth. leaflet.extras 0.1.3
+addGeoJSONChoropleth. leaflet.extras 0.1.4
@@ -32,7 +32,7 @@
-
leaflet.extras 0.1.3
+
leaflet.extras 0.1.4
Home
@@ -55,10 +55,11 @@ removes the geojson choropleth.
Usage
addGeoJSONChoropleth ( map , geojson , layerId = NULL, group = NULL,
- valueProperty , labelProperty , popupProperty , scale = c ( "white" , "red" ) ,
- steps = 5 , mode = "q" , colors = NULL, stroke = TRUE , color = "#03F" ,
- weight = 1 , opacity = 0.5 , fillOpacity = 0.2 , dashArray = NULL,
- smoothFactor = 1 , noClip = FALSE )
+ valueProperty , labelProperty , labelOptions = leaflet :: labelOptions ( ) ,
+ popupProperty , popupOptions = leaflet :: popupOptions ( ) , scale = c ( "white" ,
+ "red" ) , steps = 5 , mode = "q" , colors = NULL, stroke = TRUE ,
+ color = "#03F" , weight = 1 , opacity = 0.5 , fillOpacity = 0.2 ,
+ dashArray = NULL, smoothFactor = 1 , noClip = FALSE )
removeGeoJSONChoropleth ( map , layerId )
@@ -78,8 +79,12 @@ Arguments
The property to use for coloring
labelProperty
The property to use for labelling.
+
labelOptions
+
The Options for the label
popupProperty
The property to use for popup content
+
popupOptions
+
The Options for the popup
scale
The scale to use from chroma.js
steps
diff --git a/docs/heatmap.html b/docs/heatmap.html
index f4b7f520..6a43c630 100644
--- a/docs/heatmap.html
+++ b/docs/heatmap.html
@@ -2,7 +2,7 @@
-
addWebGLHeatmap. leaflet.extras 0.1.3
+
addWebGLHeatmap. leaflet.extras 0.1.4
@@ -32,7 +32,7 @@
-
leaflet.extras 0.1.3
+
leaflet.extras 0.1.4
Home
diff --git a/docs/index.html b/docs/index.html
index 7d425f37..d9d26006 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -2,7 +2,7 @@
-Home. leaflet.extras 0.1.3
+Home. leaflet.extras 0.1.4
@@ -32,7 +32,7 @@
-
leaflet.extras 0.1.3
+
leaflet.extras 0.1.4
Home
@@ -55,7 +55,7 @@ leaflet.extras
The goal of leaflet.extras is to provide extra functionality to leaflet R package using various leaflet plugins.
-For now you'll have to build leaflet from github devtools::install('rstudio/leaflet')
+
For now you'll have to build leaflet from github devtools::install_github('rstudio/leaflet')
to try this out. Check out the inst/examples for what's been done so far.
Plugins integrated so far
@@ -63,7 +63,8 @@ leaflet.extras
Pulse Icon Demo at Rpubs: Pulse Icons
Weather Markers Demo at Rpubs: Weather Icons
-Geojson Choropleth Demo at Rpubs: GeoJSON Choropleth
+GeoJSON Choropleth Demo at Rpubs: GeoJSON Choropleth
+TopoJSON Choropleth Demo at Rpubs: GeoJSON Choropleth
webgl-heatmap Demo at Rpubs: Heatmap
Tile Caching Demo at Rpubs: Tile Caching
Leaflet Hash
diff --git a/docs/leaflet.extras.html b/docs/leaflet.extras.html
index 765c0764..2ea728d5 100644
--- a/docs/leaflet.extras.html
+++ b/docs/leaflet.extras.html
@@ -2,7 +2,7 @@
-leaflet.extras. leaflet.extras 0.1.3
+leaflet.extras. leaflet.extras 0.1.4
@@ -32,7 +32,7 @@
-
leaflet.extras 0.1.3
+
leaflet.extras 0.1.4
Home
diff --git a/docs/leaflethash.html b/docs/leaflethash.html
index 91b8eda3..1c475579 100644
--- a/docs/leaflethash.html
+++ b/docs/leaflethash.html
@@ -2,7 +2,7 @@
-addHash. leaflet.extras 0.1.3
+addHash. leaflet.extras 0.1.4
@@ -32,7 +32,7 @@
-
leaflet.extras 0.1.3
+
leaflet.extras 0.1.4
Home
diff --git a/docs/pulseMarkers.html b/docs/pulseMarkers.html
index 938429e0..ad98b5e0 100644
--- a/docs/pulseMarkers.html
+++ b/docs/pulseMarkers.html
@@ -2,7 +2,7 @@
-pulseIconList. leaflet.extras 0.1.3
+pulseIconList. leaflet.extras 0.1.4
@@ -32,7 +32,7 @@
-
leaflet.extras 0.1.3
+
leaflet.extras 0.1.4
Home
diff --git a/docs/reference.html b/docs/reference.html
index 392e3ea5..95e4d9f6 100644
--- a/docs/reference.html
+++ b/docs/reference.html
@@ -2,7 +2,7 @@
-Function reference. leaflet.extras 0.1.3
+Function reference. leaflet.extras 0.1.4
@@ -32,7 +32,7 @@
-
leaflet.extras 0.1.3
+
leaflet.extras 0.1.4
Home
@@ -67,6 +67,9 @@
addHash
Add dynamic URL Hash
+
+ addTopoJSONChoropleth
(clearTopoJSONChoropleth, removeTopoJSONChoropleth) removes the topojson choropleth.
+
addWebGLHeatmap
(clearWebGLHeatmap, removeWebGLHeatmap) Add a webgl heatmap
diff --git a/docs/topojson-choropleth.html b/docs/topojson-choropleth.html
new file mode 100644
index 00000000..00493734
--- /dev/null
+++ b/docs/topojson-choropleth.html
@@ -0,0 +1,148 @@
+
+
+
+
+addTopoJSONChoropleth. leaflet.extras 0.1.4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
removes the topojson choropleth.
+
+
+
+
Usage
+
addTopoJSONChoropleth ( map , data , layerId = NULL, group = NULL,
+ valueProperty , labelProperty , labelOptions = leaflet :: labelOptions ( ) ,
+ popupProperty , popupOptions = leaflet :: popupOptions ( ) , scale = c ( "white" ,
+ "red" ) , steps = 5 , mode = "q" , colors = NULL, stroke = TRUE ,
+ color = "#03F" , weight = 1 , opacity = 0.5 , fillOpacity = 0.2 ,
+ dashArray = NULL, smoothFactor = 1 , noClip = FALSE )
+
+removeTopoJSONChoropleth ( map , layerId )
+
+clearTopoJSONChoropleth ( map )
+
+
Arguments
+
+ map
+ The leaflet map
+ data
+ Geojson or topojson data: either as a list or a string
+ layerId
+ a unique ID for the layer
+ group
+ the group this layer will be added to
+ valueProperty
+ The property to use for coloring
+ labelProperty
+ The property to use for labelling.
+ labelOptions
+ The Options for the label
+ popupProperty
+ The property to use for popup content
+ popupOptions
+ The Options for the popup
+ scale
+ The scale to use from chroma.js
+ steps
+ number of breakes
+ mode
+ q for quantile, e for equidistant, k for k-means
+ colors
+ overrides scale with manual colors
+ stroke
+ whether to draw stroke along the path (e.g. the borders of
+polygons or circles)
+ color
+ stroke color
+ weight
+ stroke width in pixels
+ opacity
+ stroke opacity (or layer opacity for tile layers)
+circles)
+ fillOpacity
+ fill opacity
+ dashArray
+ a string that defines the stroke
+dash
+pattern
+ smoothFactor
+ how much to simplify the polyline on each zoom level
+(more means better performance and less accurate representation)
+ noClip
+ whether to disable polyline clipping
+
+
+
+
Description
+
+
removes the topojson choropleth.
+
+
clears the topojson choropleth.
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/docs/weatherMarkers.html b/docs/weatherMarkers.html
index 3163b4bd..2f258f1a 100644
--- a/docs/weatherMarkers.html
+++ b/docs/weatherMarkers.html
@@ -2,7 +2,7 @@
-weatherIconList. leaflet.extras 0.1.3
+weatherIconList. leaflet.extras 0.1.4
@@ -32,7 +32,7 @@
-
leaflet.extras 0.1.3
+
leaflet.extras 0.1.4
Home
diff --git a/docs/wms-legend.html b/docs/wms-legend.html
index 31e36437..0e219822 100644
--- a/docs/wms-legend.html
+++ b/docs/wms-legend.html
@@ -2,7 +2,7 @@
-addWMSLegend. leaflet.extras 0.1.3
+addWMSLegend. leaflet.extras 0.1.4
@@ -32,7 +32,7 @@
-
leaflet.extras 0.1.3
+
leaflet.extras 0.1.4
Home
diff --git a/inst/examples/topojson-choropleth.R b/inst/examples/topojson-choropleth.R
new file mode 100644
index 00000000..c125cb89
--- /dev/null
+++ b/inst/examples/topojson-choropleth.R
@@ -0,0 +1,17 @@
+library(leaflet.extras)
+
+R_topojsonObject_asString <-
+ readr::read_file('https://rawgit.com/TrantorM/leaflet-choropleth/gh-pages/examples/basic_topo/crimes_by_district.topojson')
+
+leaflet() %>%
+ setView(-75.14, 40, zoom = 11) %>%
+ #addTiles(urlTemplate = 'http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png',options = tileOptions(minZoom = 2, maxZoom = 18, tms = TRUE)) %>% # wmflabs.org not responding at the moment
+ addProviderTiles(providers$CartoDB.Positron) %>%
+ leaflet.extras::addTopoJSONChoropleth(
+ R_topojsonObject_asString,
+ valueProperty ='incidents',
+ scale = c('white','red'), mode='q', steps = 5,
+ popupProperty = JS("function(feature){return 'District ' + feature.properties.dist_num + ' ' + feature.properties.incidents.toLocaleString() + ' incidents';}"),
+ labelProperty = 'dist_num',
+ color='#ffffff', weight=1, fillOpacity = 0.7
+ )
diff --git a/inst/htmlwidgets/lib/geojson-choropleth/geojson-choropleth-bindings.js b/inst/htmlwidgets/lib/geojson-choropleth/geojson-choropleth-bindings.js
index 391e6520..1bffc548 100644
--- a/inst/htmlwidgets/lib/geojson-choropleth/geojson-choropleth-bindings.js
+++ b/inst/htmlwidgets/lib/geojson-choropleth/geojson-choropleth-bindings.js
@@ -8,6 +8,10 @@ LeafletWidget.methods.addGeoJSONChoropleth = function(data, layerId, group, opti
var labelProperty = options.labelProperty;
delete options.popupProperty;
delete options.labelProperty;
+ var popupOptions = options.popupOptions;
+ var labelOptions = options.labelOptions;
+ delete options.popupOptions;
+ delete options.labelOptions;
var globalOptions = $.extend({}, options);
globalOptions.onEachFeature = function(feature, layer) {
@@ -18,17 +22,41 @@ LeafletWidget.methods.addGeoJSONChoropleth = function(data, layerId, group, opti
if (typeof popupProperty !== "undefined" && popupProperty !== null) {
if(typeof popupProperty == "string") {
- layer.bindPopup(feature.properties[popupProperty]);
+ if(!$.isEmptyObject(popupOptions)) {
+ layer.bindPopup(feature.properties[popupProperty], popupOptions);
+ } else {
+ layer.bindPopup(feature.properties[popupProperty]);
+ }
} else if(typeof popupProperty == "function") {
- layer.bindPopup(popupProperty(feature));
+ if(!$.isEmptyObject(popupOptions)) {
+ layer.bindPopup(popupProperty(feature), popupOptions);
+ } else {
+ layer.bindPopup(popupProperty(feature));
+ }
}
}
if (typeof labelProperty !== "undefined" && labelProperty !== null) {
if(typeof labelProperty == "string") {
- layer.bindLabel(feature.properties[labelProperty]);
+ if(!$.isEmptyObject(labelOptions)) {
+ if(labelOptions.noHide) {
+ layer.bindLabel(feature.properties[labelProperty], labelOptions).showLabel();
+ } else {
+ layer.bindLabel(feature.properties[labelProperty], labelOptions);
+ }
+ } else {
+ layer.bindLabel(feature.properties[labelProperty]);
+ }
} else if(typeof labelProperty == "function") {
- layer.bindLabel(labelProperty(feature));
+ if(!$.isEmptyObject(labelOptions)) {
+ if(labelOptions.noHide) {
+ layer.bindLabel(labelProperty(feature), labelOptions).showLabel();
+ } else {
+ layer.bindLabel(labelProperty(feature), labelOptions);
+ }
+ } else {
+ layer.bindLabel(labelProperty(feature));
+ }
}
}
diff --git a/inst/htmlwidgets/lib/topojson-choropleth/choroplethTopoJSON.js b/inst/htmlwidgets/lib/topojson-choropleth/choroplethTopoJSON.js
new file mode 100644
index 00000000..a9474a93
--- /dev/null
+++ b/inst/htmlwidgets/lib/topojson-choropleth/choroplethTopoJSON.js
@@ -0,0 +1,76 @@
+var L = require('leaflet')
+var chroma = require('chroma-js')
+var _ = {
+ defaults: require('lodash/object/defaults'),
+ extend: require('lodash/object/extend')
+}
+
+var topojson = require("topojson");
+
+L.choroplethTopo = module.exports = function (geojson, opts) {
+ if (geojson.type === "Topology") {
+ for (key in geojson.objects) {
+ geojson = topojson.feature(geojson, geojson.objects[key]);
+ }
+ }
+ opts = opts || {}
+
+ // Set default options in case any weren't passed
+ _.defaults(opts, {
+ valueProperty: 'value',
+ scale: ['white', 'red'],
+ steps: 5,
+ mode: 'q'
+ })
+
+ // Save what the user passed as the style property for later use (since we're overriding it)
+ var userStyle = opts.style
+
+ // Calculate limits
+ var values = geojson.features.map(function (item) {
+ if (typeof opts.valueProperty === 'function') {
+ return opts.valueProperty(item)
+ } else {
+ return item.properties[opts.valueProperty]
+ }
+ })
+ var limits = chroma.limits(values, opts.mode, opts.steps - 1)
+
+ // Create color buckets
+ var colors = opts.colors || chroma.scale(opts.scale).colors(opts.steps)
+
+ return L.geoJson(geojson, _.extend(opts, {
+ limits: limits,
+ colors: colors,
+ style: function (feature) {
+ var style = {}
+ var featureValue
+
+ if (typeof opts.valueProperty === 'function') {
+ featureValue = opts.valueProperty(feature)
+ } else {
+ featureValue = feature.properties[opts.valueProperty]
+ }
+
+ if (!isNaN(featureValue)) {
+ // Find the bucket/step/limit that this value is less than and give it that color
+ for (var i = 0; i < limits.length; i++) {
+ if (featureValue <= limits[i]) {
+ style.fillColor = colors[i]
+ break
+ }
+ }
+ }
+
+ // Return this style, but include the user-defined style if it was passed
+ switch (typeof userStyle) {
+ case 'function':
+ return _.extend(userStyle(), style)
+ case 'object':
+ return _.extend(userStyle, style)
+ default:
+ return style
+ }
+ }
+ }))
+}
diff --git a/inst/htmlwidgets/lib/topojson-choropleth/choroplethTopoJSON.min.js b/inst/htmlwidgets/lib/topojson-choropleth/choroplethTopoJSON.min.js
new file mode 100644
index 00000000..c6eb092f
--- /dev/null
+++ b/inst/htmlwidgets/lib/topojson-choropleth/choroplethTopoJSON.min.js
@@ -0,0 +1,53 @@
+!function(n){function r(t){if(e[t])return e[t].exports;var f=e[t]={exports:{},id:t,loaded:!1};return n[t].call(f.exports,f,f.exports,r),f.loaded=!0,f.exports}var e={};return r.m=n,r.c=e,r.p="",r(0)}([function(n,r,e){var t=e(32),f=e(12),o={defaults:e(26),extend:e(27)},u=e(30);t.choroplethTopo=n.exports=function(n,r){if("Topology"===n.type)for(key in n.objects)n=u.feature(n,n.objects[key]);r=r||{},o.defaults(r,{valueProperty:"value",scale:["white","red"],steps:5,mode:"q"});var e=r.style,a=n.features.map(function(n){return"function"==typeof r.valueProperty?r.valueProperty(n):n.properties[r.valueProperty]}),c=f.limits(a,r.mode,r.steps-1),i=r.colors||f.scale(r.scale).colors(r.steps);return t.geoJson(n,o.extend(r,{limits:c,colors:i,style:function(n){var t,f={};if(t="function"==typeof r.valueProperty?r.valueProperty(n):n.properties[r.valueProperty],!isNaN(t))for(var u=0;u-1&&n%1==0&&n<=t}var t=9007199254740991;n.exports=e},function(n,r){function e(n){var r=typeof n;return!!n&&("object"==r||"function"==r)}n.exports=e},function(n,r,e){function t(n){return null!=n&&o(f(n))}var f=e(21),o=e(1);n.exports=t},function(n,r){function e(n,r){return n="number"==typeof n||t.test(n)?+n:-1,r=null==r?f:r,n>-1&&n%1==0&&ne&&(n=e),n},En=function(n){return n.length>=3?[].slice.call(n):n[0]},_=function(n){var r;for(r in n)r<3?(n[r]<0&&(n[r]=0),n[r]>255&&(n[r]=255)):3===r&&(n[r]<0&&(n[r]=0),n[r]>1&&(n[r]=1));return n},a=Math.PI,mn=Math.round,N=Math.cos,L=Math.floor,tn=Math.pow,D=Math.log,xn=Math.sin,kn=Math.sqrt,g=Math.atan2,Q=Math.max,b=Math.abs,l=2*a,c=a/3,o=a/180,i=180/a,k=function(){return arguments[0]instanceof e?arguments[0]:function(n,r,e){e.prototype=n.prototype;var t=new e,f=n.apply(t,r);return Object(f)===f?f:t}(e,arguments,function(){})},d=[],"undefined"!=typeof n&&null!==n&&null!=n.exports&&(n.exports=k),t=[],f=function(){return k}.apply(r,t),!(void 0!==f&&(n.exports=f)),k.version="1.1.1",h={},s=[],p=!1,e=function(){function n(){var n,r,e,t,f,o,u,a,c;for(o=this,r=[],a=0,t=arguments.length;a3?r[3]:1]},jn=function(n){return mn(255*(n<=.00304?12.92*n:1.055*tn(n,1/2.4)-.055))},I=function(n){return n>u.t1?n*n*n:u.t2*(n-u.t0)},u={Kn:18,Xn:.95047,Yn:1,Zn:1.08883,t0:.137931034,t1:.206896552,t2:.12841855,t3:.008856452},sn=function(){var n,r,e,t,f,o,u,a;return t=En(arguments),e=t[0],r=t[1],n=t[2],f=gn(e,r,n),o=f[0],u=f[1],a=f[2],[116*u-16,500*(o-u),200*(u-a)]},vn=function(n){return(n/=255)<=.04045?n/12.92:tn((n+.055)/1.055,2.4)},Pn=function(n){return n>u.t3?tn(n,1/3):n/u.t2+u.t0},gn=function(){var n,r,e,t,f,o,a;return t=En(arguments),e=t[0],r=t[1],n=t[2],e=vn(e),r=vn(r),n=vn(n),f=Pn((.4124564*e+.3575761*r+.1804375*n)/u.Xn),o=Pn((.2126729*e+.7151522*r+.072175*n)/u.Yn),a=Pn((.0193339*e+.119192*r+.9503041*n)/u.Zn),[f,o,a]},k.lab=function(){return function(n,r,e){e.prototype=n.prototype;var t=new e,f=n.apply(t,r);return Object(f)===f?f:t}(e,On.call(arguments).concat(["lab"]),function(){})},h.lab=U,e.prototype.lab=function(){return sn(this._rgb)},v=function(n){var r,e,t,f,o,u,a,c,i,l,s;return n=function(){var r,e,t;for(t=[],e=0,r=n.length;e=0&&r[3]<=1?"rgb":void 0}}),S=function(n){var r,e,t,f,o,u;if(n.match(/^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/))return 4!==n.length&&7!==n.length||(n=n.substr(1)),3===n.length&&(n=n.split(""),n=n[0]+n[0]+n[1]+n[1]+n[2]+n[2]),u=parseInt(n,16),f=u>>16,t=u>>8&255,e=255&u,[f,t,e,1];if(n.match(/^#?([A-Fa-f0-9]{8})$/))return 9===n.length&&(n=n.substr(1)),u=parseInt(n,16),f=u>>24&255,t=u>>16&255,e=u>>8&255,r=mn((255&u)/255*100)/100,[f,t,e,r];if(null!=h.css&&(o=h.css(n)))return o;throw"unknown color: "+n},un=function(n,r){var e,t,f,o,u,a,c;return null==r&&(r="rgb"),u=n[0],f=n[1],t=n[2],e=n[3],c=u<<16|f<<8|t,a="000000"+c.toString(16),a=a.substr(a.length-6),o="0"+mn(255*e).toString(16),o=o.substr(o.length-2),"#"+function(){switch(r.toLowerCase()){case"rgba":return a+o;case"argb":return o+a;default:return a}}()},h.hex=function(n){return S(n)},k.hex=function(){return function(n,r,e){e.prototype=n.prototype;var t=new e,f=n.apply(t,r);return Object(f)===f?f:t}(e,On.call(arguments).concat(["hex"]),function(){})},e.prototype.hex=function(n){return null==n&&(n="rgb"),un(this._rgb,n)},s.push({p:10,test:function(n){if(1===arguments.length&&"string"===Mn(n))return"hex"}}),B=function(){var n,r,e,t,f,o,u,a,c,i,l,s,p,h;if(n=En(arguments),f=n[0],l=n[1],u=n[2],0===l)c=t=r=255*u;else{for(h=[0,0,0],e=[0,0,0],p=u<.5?u*(1+l):u+l-u*l,s=2*u-p,f/=360,h[0]=f+1/3,h[1]=f,h[2]=f-1/3,o=a=0;a<=2;o=++a)h[o]<0&&(h[o]+=1),h[o]>1&&(h[o]-=1),6*h[o]<1?e[o]=s+6*(p-s)*h[o]:2*h[o]<1?e[o]=p:3*h[o]<2?e[o]=s+(p-s)*(2/3-h[o])*6:e[o]=s;i=[mn(255*e[0]),mn(255*e[1]),mn(255*e[2])],c=i[0],t=i[1],r=i[2]}return n.length>3?[c,t,r,n[3]]:[c,t,r]},cn=function(n,r,e){var t,f,o,u,a;return void 0!==n&&n.length>=3&&(u=n,n=u[0],r=u[1],e=u[2]),n/=255,r/=255,e/=255,o=Math.min(n,r,e),Q=Math.max(n,r,e),f=(Q+o)/2,Q===o?(a=0,t=Number.NaN):a=f<.5?(Q-o)/(Q+o):(Q-o)/(2-Q-o),n===Q?t=(r-e)/(Q-o):r===Q?t=2+(e-n)/(Q-o):e===Q&&(t=4+(n-r)/(Q-o)),t*=60,t<0&&(t+=360),[t,a,f]},k.hsl=function(){return function(n,r,e){e.prototype=n.prototype;var t=new e,f=n.apply(t,r);return Object(f)===f?f:t}(e,On.call(arguments).concat(["hsl"]),function(){})},h.hsl=B,e.prototype.hsl=function(){return cn(this._rgb)},R=function(){var n,r,e,t,f,o,u,a,c,i,l,s,p,h,d,b,g,v;if(n=En(arguments),f=n[0],b=n[1],v=n[2],v*=255,0===b)c=t=r=v;else switch(360===f&&(f=0),f>360&&(f-=360),f<0&&(f+=360),f/=60,o=L(f),e=f-o,u=v*(1-b),a=v*(1-b*e),g=v*(1-b*(1-e)),o){case 0:i=[v,g,u],c=i[0],t=i[1],r=i[2];break;case 1:l=[a,v,u],c=l[0],t=l[1],r=l[2];break;case 2:s=[u,v,g],c=s[0],t=s[1],r=s[2];break;case 3:p=[u,a,v],c=p[0],t=p[1],r=p[2];break;case 4:h=[g,u,v],c=h[0],t=h[1],r=h[2];break;case 5:d=[v,u,a],c=d[0],t=d[1],r=d[2]}return c=mn(c),t=mn(t),r=mn(r),[c,t,r,n.length>3?n[3]:1]},ln=function(){var n,r,e,t,f,o,u,a,c;return u=En(arguments),o=u[0],e=u[1],n=u[2],f=Math.min(o,e,n),Q=Math.max(o,e,n),r=Q-f,c=Q/255,0===Q?(t=Number.NaN,a=0):(a=r/Q,o===Q&&(t=(e-n)/r),e===Q&&(t=2+(n-o)/r),n===Q&&(t=4+(o-e)/r),t*=60,t<0&&(t+=360)),[t,a,c]},k.hsv=function(){return function(n,r,e){e.prototype=n.prototype;var t=new e,f=n.apply(t,r);return Object(f)===f?f:t}(e,On.call(arguments).concat(["hsv"]),function(){})},h.hsv=R,e.prototype.hsv=function(){return ln(this._rgb)},rn=function(n){var r,e,t;return"number"===Mn(n)&&n>=0&&n<=16777215?(t=n>>16,e=n>>8&255,r=255&n,[t,e,r,1]):(console.warn("unknown num color: "+n),[0,0,0,1])},dn=function(){var n,r,e,t;return t=En(arguments),e=t[0],r=t[1],n=t[2],(e<<16)+(r<<8)+n},k.num=function(n){return new e(n,"num")},e.prototype.num=function(n){return null==n&&(n="rgb"),dn(this._rgb,n)},h.num=rn,s.push({p:10,test:function(n){if(1===arguments.length&&"number"===Mn(n)&&n>=0&&n<=16777215)return"num"}}),P=function(n){var r,e,t,f,o,u,a,c;if(n=n.toLowerCase(),null!=k.colors&&k.colors[n])return S(k.colors[n]);if(o=n.match(/rgb\(\s*(\-?\d+),\s*(\-?\d+)\s*,\s*(\-?\d+)\s*\)/)){for(a=o.slice(1,4),f=u=0;u<=2;f=++u)a[f]=+a[f];a[3]=1}else if(o=n.match(/rgba\(\s*(\-?\d+),\s*(\-?\d+)\s*,\s*(\-?\d+)\s*,\s*([01]|[01]?\.\d+)\)/))for(a=o.slice(1,5),f=c=0;c<=3;f=++c)a[f]=+a[f];else if(o=n.match(/rgb\(\s*(\-?\d+(?:\.\d+)?)%,\s*(\-?\d+(?:\.\d+)?)%\s*,\s*(\-?\d+(?:\.\d+)?)%\s*\)/)){for(a=o.slice(1,4),f=r=0;r<=2;f=++r)a[f]=mn(2.55*a[f]);a[3]=1}else if(o=n.match(/rgba\(\s*(\-?\d+(?:\.\d+)?)%,\s*(\-?\d+(?:\.\d+)?)%\s*,\s*(\-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)/)){for(a=o.slice(1,5),f=e=0;e<=2;f=++e)a[f]=mn(2.55*a[f]);a[3]=+a[3]}else(o=n.match(/hsl\(\s*(\-?\d+(?:\.\d+)?),\s*(\-?\d+(?:\.\d+)?)%\s*,\s*(\-?\d+(?:\.\d+)?)%\s*\)/))?(t=o.slice(1,4),t[1]*=.01,t[2]*=.01,a=B(t),a[3]=1):(o=n.match(/hsla\(\s*(\-?\d+(?:\.\d+)?),\s*(\-?\d+(?:\.\d+)?)%\s*,\s*(\-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)/))&&(t=o.slice(1,4),t[1]*=.01,t[2]*=.01,a=B(t),a[3]=+o[4]);return a},on=function(n){var r;return r=n[3]<1?"rgba":"rgb","rgb"===r?r+"("+n.slice(0,3).map(mn).join(",")+")":"rgba"===r?r+"("+n.slice(0,3).map(mn).join(",")+","+n[3]+")":void 0},yn=function(n){return mn(100*n)/100},q=function(n,r){var e;return e=r<1?"hsla":"hsl",n[0]=yn(n[0]||0),n[1]=yn(100*n[1])+"%",n[2]=yn(100*n[2])+"%","hsla"===e&&(n[3]=r),e+"("+n.join(",")+")"},h.css=function(n){return P(n)},k.css=function(){return function(n,r,e){e.prototype=n.prototype;var t=new e,f=n.apply(t,r);return Object(f)===f?f:t}(e,On.call(arguments).concat(["css"]),function(){})},e.prototype.css=function(n){return null==n&&(n="rgb"),"rgb"===n.slice(0,3)?on(this._rgb):"hsl"===n.slice(0,3)?q(this.hsl(),this.alpha()):void 0},h.named=function(n){return S(Nn[n])},s.push({p:20,test:function(n){if(1===arguments.length&&null!=Nn[n])return"named"}}),e.prototype.name=function(n){var r,e;arguments.length&&(Nn[n]&&(this._rgb=S(Nn[n])),this._rgb[3]=1),r=this.hex();for(e in Nn)if(r===Nn[e])return e;return r},V=function(){var n,r,e,t;return t=En(arguments),e=t[0],n=t[1],r=t[2],r*=o,[e,N(r)*n,xn(r)*n]},K=function(){var n,r,e,t,f,o,u,a,c,i,l;return e=En(arguments),a=e[0],f=e[1],u=e[2],i=V(a,f,u),n=i[0],r=i[1],t=i[2],l=U(n,r,t),c=l[0],o=l[1],t=l[2],[Z(c,0,255),Z(o,0,255),Z(t,0,255),e.length>3?e[3]:1]},z=function(){var n,r,e,t,f,o;return o=En(arguments),f=o[0],n=o[1],r=o[2],e=kn(n*n+r*r),t=(g(r,n)*i+360)%360,0===mn(1e4*e)&&(t=Number.NaN),[f,e,t]},pn=function(){var n,r,e,t,f,o,u;return o=En(arguments),f=o[0],e=o[1],r=o[2],u=sn(f,e,r),t=u[0],n=u[1],r=u[2],z(t,n,r)},k.lch=function(){var n;return n=En(arguments),new e(n,"lch")},k.hcl=function(){var n;return n=En(arguments),new e(n,"hcl")},h.lch=K,h.hcl=function(){var n,r,e,t;return t=En(arguments),r=t[0],n=t[1],e=t[2],K([e,n,r])},e.prototype.lch=function(){return pn(this._rgb)},e.prototype.hcl=function(){return pn(this._rgb).reverse()},fn=function(n){var r,e,t,f,o,u,a,c,i;return null==n&&(n="rgb"),c=En(arguments),a=c[0],f=c[1],r=c[2],a/=255,f/=255,r/=255,o=1-Math.max(a,Math.max(f,r)),t=o<1?1/(1-o):0,e=(1-a-o)*t,u=(1-f-o)*t,i=(1-r-o)*t,[e,u,i,o]},M=function(){var n,r,e,t,f,o,u,a,c;return r=En(arguments),t=r[0],u=r[1],c=r[2],o=r[3],n=r.length>4?r[4]:1,1===o?[0,0,0,n]:(a=t>=1?0:mn(255*(1-t)*(1-o)),f=u>=1?0:mn(255*(1-u)*(1-o)),e=c>=1?0:mn(255*(1-c)*(1-o)),[a,f,e,n])},h.cmyk=function(){return M(En(arguments))},k.cmyk=function(){return function(n,r,e){e.prototype=n.prototype;var t=new e,f=n.apply(t,r);return Object(f)===f?f:t}(e,On.call(arguments).concat(["cmyk"]),function(){})},e.prototype.cmyk=function(){return fn(this._rgb)},h.gl=function(){var n,r,e,t,f;for(t=function(){var n,e;n=En(arguments),e=[];for(r in n)f=n[r],e.push(f);return e}.apply(this,arguments),n=e=0;e<=2;n=++e)t[n]*=255;return t},k.gl=function(){return function(n,r,e){e.prototype=n.prototype;var t=new e,f=n.apply(t,r);return Object(f)===f?f:t}(e,On.call(arguments).concat(["gl"]),function(){})},e.prototype.gl=function(){var n;return n=this._rgb,[n[0]/255,n[1]/255,n[2]/255,n[3]]},hn=function(n,r,e){var t;return t=En(arguments),n=t[0],r=t[1],e=t[2],n=J(n),r=J(r),e=J(e),.2126*n+.7152*r+.0722*e},J=function(n){return n/=255,n<=.03928?n/12.92:tn((n+.055)/1.055,2.4)},d=[],C=function(n,r,e,t){var f,o,u,a;for(null==e&&(e=.5),null==t&&(t="rgb"),"object"!==Mn(n)&&(n=k(n)),"object"!==Mn(r)&&(r=k(r)),u=0,o=d.length;un?o(e,c):o(c,u)},e=hn(this._rgb),this._rgb=(e>n?o(k("black"),this):o(this,k("white"))).rgba()),this):hn(this._rgb)},_n=function(n){var r,e,t,f;return f=n/100,f<66?(t=255,e=-155.25485562709179-.44596950469579133*(e=f-2)+104.49216199393888*D(e),r=f<20?0:-254.76935184120902+.8274096064007395*(r=f-10)+115.67994401066147*D(r)):(t=351.97690566805693+.114206453784165*(t=f-55)-40.25366309332127*D(t),e=325.4494125711974+.07943456536662342*(e=f-50)-28.0852963507957*D(e),r=255),_([t,e,r])},bn=function(){var n,r,e,t,f,o,u,a,c;for(u=En(arguments),o=u[0],e=u[1],n=u[2],f=1e3,t=4e4,r=.4;t-f>r;)c=.5*(t+f),a=_n(c),a[2]/a[0]>=n/o?t=c:f=c;return mn(c)},k.temperature=k.kelvin=function(){return function(n,r,e){e.prototype=n.prototype;var t=new e,f=n.apply(t,r);return Object(f)===f?f:t}(e,On.call(arguments).concat(["temperature"]),function(){})},h.temperature=h.kelvin=h.K=_n,e.prototype.temperature=function(){return bn(this._rgb)},e.prototype.kelvin=e.prototype.temperature,k.contrast=function(n,r){var t,f,o,u;return"string"!==(o=Mn(n))&&"number"!==o||(n=new e(n)),"string"!==(u=Mn(r))&&"number"!==u||(r=new e(r)),t=n.luminance(),f=r.luminance(),t>f?(t+.05)/(f+.05):(f+.05)/(t+.05)},e.prototype.get=function(n){var r,e,t,f,o,u;return t=this,o=n.split("."),f=o[0],r=o[1],u=t[f](),r?(e=f.indexOf(r),e>-1?u[e]:console.warn("unknown channel "+r+" in mode "+f)):u},e.prototype.set=function(n,r){var e,t,f,o,u,a;if(f=this,u=n.split("."),o=u[0],e=u[1],e)if(a=f[o](),t=o.indexOf(e),t>-1)if("string"===Mn(r))switch(r.charAt(0)){case"+":a[t]+=+r;break;case"-":a[t]+=+r;break;case"*":a[t]*=+r.substr(1);break;case"/":a[t]/=+r.substr(1);break;default:a[t]=+r}else a[t]=r;else console.warn("unknown channel "+e+" in mode "+o);else a=r;return f._rgb=k(a,o).alpha(f.alpha())._rgb,f},e.prototype.darken=function(n){var r,e;return null==n&&(n=1),e=this,r=e.lab(),r[0]-=u.Kn*n,k.lab(r).alpha(e.alpha())},e.prototype.brighten=function(n){return null==n&&(n=1),this.darken(-n)},e.prototype.darker=e.prototype.darken,e.prototype.brighter=e.prototype.brighten,e.prototype.saturate=function(n){var r,e;return null==n&&(n=1),e=this,r=e.lch(),r[1]+=n*u.Kn,r[1]<0&&(r[1]=0),k.lch(r).alpha(e.alpha())},e.prototype.desaturate=function(n){return null==n&&(n=1),this.saturate(-n)},e.prototype.premultiply=function(){var n,r;return r=this.rgb(),n=this.alpha(),k(r[0]*n,r[1]*n,r[2]*n,n)},y=function(n,r,e){if(!y[e])throw"unknown blend mode "+e;return y[e](n,r)},m=function(n){return function(r,e){var t,f;return t=k(e).rgb(),f=k(r).rgb(),k(n(t,f),"rgb")}},A=function(n){return function(r,e){var t,f,o;for(o=[],t=f=0;f<=3;t=++f)o[t]=n(r[t],e[t]);return o}},nn=function(n,r){return n},W=function(n,r){return n*r/255},j=function(n,r){return n>r?r:n},T=function(n,r){return n>r?n:r},wn=function(n,r){return 255*(1-(1-n/255)*(1-r/255))},en=function(n,r){return r<128?2*n*r/255:255*(1-2*(1-n/255)*(1-r/255))},x=function(n,r){return 255*(1-(1-r/255)/(n/255))},O=function(n,r){return 255===n?255:(n=255*(r/255)/(1-n/255),n>255?255:n)},y.normal=m(A(nn)),y.multiply=m(A(W)),y.screen=m(A(wn)),y.overlay=m(A(en)),y.darken=m(A(j)),y.lighten=m(A(T)),y.dodge=m(A(O)),y.burn=m(A(x)),k.blend=y,k.analyze=function(n){var r,e,t,f;for(t={min:Number.MAX_VALUE,max:Number.MAX_VALUE*-1,sum:0,values:[],count:0},e=0,r=n.length;et.max&&(t.max=f),t.count+=1);return t.domain=[t.min,t.max],t.limits=function(n,r){return k.limits(t,n,r)},t},k.scale=function(n,r){var e,t,f,o,u,a,c,i,l,s,p,h,d,b,g,v,y,m,w,x,_;return l="rgb",s=k("#ccc"),b=0,a=!1,u=[0,1],d=[],h=[0,0],e=!1,f=[],p=!1,i=0,c=1,o=!1,t={},x=function(n){var r,e,t,o,u,a,c;if(null==n&&(n=["#fff","#000"]),null!=n&&"string"===Mn(n)&&null!=(null!=(o=k.brewer)?o[n]:void 0)&&(n=k.brewer[n]),"array"===Mn(n)){for(n=n.slice(0),r=t=0,u=n.length-1;0<=u?t<=u:t>=u;r=0<=u?++t:--t)e=n[r],"string"===Mn(e)&&(n[r]=k(e));for(d.length=0,r=c=0,a=n.length-1;0<=a?c<=a:c>=a;r=0<=a?++c:--c)d.push(r/(n.length-1))}return w(),f=n},y=function(n){var r,t;if(null!=e){for(t=e.length-1,r=0;r=e[r];)r++;return r-1}return 0},_=function(n){return n},g=function(n){var r,t,f,o,u;return u=n,e.length>2&&(o=e.length-1,r=y(n),f=e[0]+(e[1]-e[0])*(0+.5*b),t=e[o-1]+(e[o]-e[o-1])*(1-.5*b),u=i+(e[r]+.5*(e[r+1]-e[r])-f)/(t-f)*(c-i)),u},m=function(n,r){var o,u,a,p,b,g,v,m;if(null==r&&(r=!1),isNaN(n))return s;if(r?m=n:e&&e.length>2?(o=y(n),m=o/(e.length-2),m=h[0]+m*(1-h[0]-h[1])):c!==i?(m=(n-i)/(c-i),m=h[0]+m*(1-h[0]-h[1]),m=Math.min(1,Math.max(0,m))):m=1,r||(m=_(m)),p=Math.floor(1e4*m),t[p])u=t[p];else{if("array"===Mn(f))for(a=b=0,v=d.length-1;0<=v?b<=v:b>=v;a=0<=v?++b:--b){if(g=d[a],m<=g){u=f[a];break}if(m>=g&&a===d.length-1){u=f[a];break}if(m>g&&m=l;r=0<=l?++s:--s)d.push(r/(t-1));return u=[i,c],v},v.mode=function(n){return arguments.length?(l=n,w(),v):l},v.range=function(n,r){return x(n,r),v},v.out=function(n){return p=n,v},v.spread=function(n){return arguments.length?(b=n,v):b},v.correctLightness=function(n){return null==n&&(n=!0),o=n,w(),_=o?function(n){var r,e,t,f,o,u,a,c,i;for(r=m(0,!0).lab()[0],e=m(1,!0).lab()[0],a=r>e,t=m(n,!0).lab()[0],o=r+(e-r)*n,f=t-o,c=0,i=1,u=20;Math.abs(f)>.01&&u-- >0;)!function(){return a&&(f*=-1),f<0?(c=n,n+=.5*(i-n)):(i=n,n+=.5*(c-n)),t=m(n,!0).lab()[0],f=t-o}();return n}:function(n){return n},v},v.padding=function(n){return null!=n?("number"===Mn(n)&&(n=[n,n]),h=n,v):h},v.colors=function(){var r,t,f,o,a,c,i,l,s;if(o=0,a="hex",1===arguments.length&&("string"===Mn(arguments[0])?a=arguments[0]:o=arguments[0]),2===arguments.length&&(o=arguments[0],a=arguments[1]),o)return t=u[0],r=u[1]-t,function(){i=[];for(var n=0;0<=o?no;0<=o?n++:n--)i.push(n);return i}.apply(this).map(function(n){return v(t+n/(o-1)*r)[a]()});if(n=[],l=[],e&&e.length>2)for(f=s=1,c=e.length;1<=c?sc;f=1<=c?++s:--s)l.push(.5*(e[f-1]+e[f]));else l=u;return l.map(function(n){return v(n)[a]()})},v},null==k.scales&&(k.scales={}),k.scales.cool=function(){return k.scale([k.hsl(180,1,.9),k.hsl(250,.7,.4)])},k.scales.hot=function(){return k.scale(["#000","#f00","#ff0","#fff"],[0,.25,.75,1]).mode("rgb")},k.analyze=function(n,r,e){var t,f,o,u,a,c,i;if(a={min:Number.MAX_VALUE,max:Number.MAX_VALUE*-1,sum:0,values:[],count:0},null==e&&(e=function(){return!0}),t=function(n){null==n||isNaN(n)||(a.values.push(n),a.sum+=n,na.max&&(a.max=n),a.count+=1)},i=function(n,f){if(e(n,f))return t(null!=r&&"function"===Mn(r)?r(n):null!=r&&"string"===Mn(r)||"number"===Mn(r)?n[r]:n)},"array"===Mn(n))for(u=0,o=n.length;u=X;M=1<=X?++R:--R)P.push(O+M/e*(Q-O));P.push(Q)}else if("l"===r.substr(0,1)){if(O<=0)throw"Logarithmic scales are only possible for values > 0";for(A=Math.LOG10E*D(O),j=Math.LOG10E*D(Q),P.push(O),M=ln=1,$=e-1;1<=$?ln<=$:ln>=$;M=1<=$?++ln:--ln)P.push(tn(10,A+M/e*(j-A)));P.push(Q)}else if("q"===r.substr(0,1)){for(P.push(O),M=t=1,T=e-1;1<=T?t<=T:t>=T;M=1<=T?++t:--t)C=cn.length*M/e,Y=L(C),Y===C?P.push(cn[Y]):(F=C-Y,P.push(cn[Y]*F+cn[Y+1]*(1-F)));P.push(Q)}else if("k"===r.substr(0,1)){for(G=cn.length,v=new Array(G),x=new Array(e),fn=!0,q=0,m=null,m=[],m.push(O),M=f=1,Z=e-1;1<=Z?f<=Z:f>=Z;M=1<=Z?++f:--f)m.push(O+M/e*(Q-O));for(m.push(Q);fn;){for(E=o=0,J=e-1;0<=J?o<=J:o>=J;E=0<=J?++o:--o)x[E]=0;for(M=u=0,H=G-1;0<=H?u<=H:u>=H;M=0<=H?++u:--u){for(an=cn[M],S=Number.MAX_VALUE,E=a=0,W=e-1;0<=W?a<=W:a>=W;E=0<=W?++a:--a)_=b(m[E]-an),_=nn;E=0<=nn?++c:--c)B[E]=null;for(M=i=0,rn=G-1;0<=rn?i<=rn:i>=rn;M=0<=rn?++i:--i)w=v[M],null===B[w]?B[w]=cn[M]:B[w]+=cn[M];for(E=l=0,en=e-1;0<=en?l<=en:l>=en;E=0<=en?++l:--l)B[E]*=1/x[E];for(fn=!1,E=s=0,z=e-1;0<=z?s<=z:s>=z;E=0<=z?++s:--s)if(B[E]!==m[M]){fn=!0;break}m=B,q++,q>200&&(fn=!1)}for(N={},E=p=0,U=e-1;0<=U?p<=U:p>=U;E=0<=U?++p:--p)N[E]=[];for(M=h=0,I=G-1;0<=I?h<=I:h>=I;M=0<=I?++h:--h)w=v[M],N[w].push(cn[M]);for(un=[],E=d=0,V=e-1;0<=V?d<=V:d>=V;E=0<=V?++d:--d)un.push(N[E][0]),un.push(N[E][N[E].length-1]);for(un=un.sort(function(n,r){return n-r}),P.push(un[0]),M=g=1,K=un.length-1;g<=K;M=g+=2)isNaN(un[M])||P.push(un[M])}return P},G=function(n,r,e){var t,f,o,u;return t=En(arguments),n=t[0],r=t[1],e=t[2],n/=360,n<1/3?(f=(1-r)/3,u=(1+r*N(l*n)/N(c-l*n))/3,o=1-(f+u)):n<2/3?(n-=1/3,u=(1-r)/3,o=(1+r*N(l*n)/N(c-l*n))/3,f=1-(u+o)):(n-=2/3,o=(1-r)/3,f=(1+r*N(l*n)/N(c-l*n))/3,u=1-(o+f)),u=Z(e*u*3),o=Z(e*o*3),f=Z(e*f*3),[255*u,255*o,255*f,t.length>3?t[3]:1]},an=function(){var n,r,e,t,f,o,u,a;return u=En(arguments),o=u[0],r=u[1],n=u[2],l=2*Math.PI,o/=255,r/=255,n/=255,f=Math.min(o,r,n),t=(o+r+n)/3,a=1-f/t,0===a?e=0:(e=(o-r+(o-n))/2,e/=Math.sqrt((o-r)*(o-r)+(o-n)*(r-n)),e=Math.acos(e),n>r&&(e=l-e),e/=l),[360*e,a,t]},k.hsi=function(){return function(n,r,e){e.prototype=n.prototype;var t=new e,f=n.apply(t,r);return Object(f)===f?f:t}(e,On.call(arguments).concat(["hsi"]),function(){})},h.hsi=G,e.prototype.hsi=function(){return an(this._rgb)},Y=function(n,r,e,t){var f,o,u,a,c,i,l,s,p,h,d,b,g;return"hsl"===t?(b=n.hsl(),g=r.hsl()):"hsv"===t?(b=n.hsv(),g=r.hsv()):"hsi"===t?(b=n.hsi(),g=r.hsi()):"lch"!==t&&"hcl"!==t||(t="hcl",b=n.hcl(),g=r.hcl()),"h"===t.substr(0,1)&&(u=b[0],h=b[1],i=b[2],a=g[0],d=g[1],l=g[2]),isNaN(u)||isNaN(a)?isNaN(u)?isNaN(a)?o=Number.NaN:(o=a,1!==i&&0!==i||"hsv"===t||(p=d)):(o=u,1!==l&&0!==l||"hsv"===t||(p=h)):(f=a>u&&a-u>180?a-(u+360):a180?a+360-u:a-u,o=u+e*f),null==p&&(p=h+e*(d-h)),c=i+e*(l-i),s=k[t](o,p,c)},d=d.concat(function(){var n,r,e,t;for(e=["hsv","hsl","hsi","hcl","lch"],t=[],r=0,n=e.length;r2?e[u-2]:void 0,c=u>2?e[2]:void 0,i=u>1?e[u-1]:void 0;for("function"==typeof a?(a=f(a,i,5),u-=2):(a="function"==typeof i?i:void 0,u-=a?1:0),c&&o(e[0],e[1],c)&&(a=u<3?void 0:a,u=1);++t0;++t>>1;n[f]1){var c,l=[],s={LineString:f,MultiLineString:o,Polygon:o,MultiPolygon:function(n){n.forEach(o)}};u(r),l.forEach(arguments.length<3?function(n){a.push(n[0].i)}:function(n){e(n[0].g,n[n.length-1].g)&&a.push(n[0].i)})}else for(var p=0,h=n.arcs.length;p1)for(var u,a,c=1,l=t(o[0]);cl&&(a=o[0],o[0]=o[c],o[c]=a,l=u);return o})}}function g(n){function r(n,r){n.forEach(function(n){n<0&&(n=~n);var e=f[n];e?e.push(r):f[n]=[r]})}function e(n,e){n.forEach(function(n){r(n,e)})}function t(n,r){"GeometryCollection"===n.type?n.geometries.forEach(function(n){t(n,r)}):n.type in a&&a[n.type](n.arcs,r)}var f={},u=n.map(function(){return[]}),a={LineString:r,MultiLineString:e,Polygon:e,MultiPolygon:function(n,r){n.forEach(function(n){e(n,r)})}};n.forEach(t);for(var c in f)for(var i=f[c],l=i.length,s=0;s0;){var e=(r+1>>1)-1,f=t[e];if(v(n,f)>=0)break;t[f._=r]=f,t[n._=r=e]=n}}function r(n,r){for(;;){var e=r+1<<1,o=e-1,u=r,a=t[u];if(o0&&(n=t[f],r(t[n._=0]=n,0)),e}},e.remove=function(e){var o,u=e._;if(t[u]===e)return u!==--f&&(o=t[f],(v(o,e)<0?n:r)(t[o._=u]=o,u)),u},e}function m(n,r){function f(n){a.remove(n),n[1][2]=r(n),a.push(n)}var o=e(n.transform),u=t(n.transform),a=y();return r||(r=p),n.arcs.forEach(function(n){var e,t,c,i,l=[],s=0;for(t=0,c=n.length;t