Skip to content

Instantly share code, notes, and snippets.

@rveciana
Last active Sep 23, 2016
Embed
What would you like to do?
geoAlbersUsa

This file shows how to use the geoAlbers projection from d3-composite-projections.

To change the file, edit draw.js and run

browserify draw.js > bundle.js

The dependencies are installed with:

npm install d3-composite-projections d3-geo d3-request d3-selection d3-transition topojson

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var d3_composite = require("d3-composite-projections");
var d3_geo = require("d3-geo");
var d3_request = require("d3-request");
var d3_selection = require("d3-selection");
var d3_transition = require("d3-transition");
var topojson = require("topojson");
var width = 960;
var height = 500;
var projection = d3_composite.geoAlbersUsa();
var path = d3_geo.geoPath()
.projection(projection);
var svg = d3_selection.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var t = d3_transition.transition()
.on("interrupt", function(d,i){
console.info(i);
});
d3_request.json("us.json", function(error, topojsonData) {
var us = topojson.feature(topojsonData, topojsonData.objects.states);
svg.selectAll(".region")
.data(us.features)
.enter()
.append("path")
.attr("d", path)
.attr("class","region")
.style("fill", "#aca")
.style("stroke", "#000")
.style("stroke-width", "0.5px")
.on("mouseover", function(d,i) {
d3_selection.select(this)
.transition(t)
.style("fill", "red");
})
.on("mouseout", function(d,i) {
d3_selection.select(this).interrupt();
d3_selection.select(this)
.transition(t)
.style("fill", "#aca");
});
svg
.append("path")
.style("fill","none")
.style("stroke","#f00")
.attr("d", projection.getCompositionBorders());
});
},{"d3-composite-projections":5,"d3-geo":10,"d3-request":13,"d3-selection":14,"d3-transition":16,"topojson":17}],2:[function(require,module,exports){
// https://d3js.org/d3-array/ Version 1.0.1. Copyright 2016 Mike Bostock.
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.d3 = global.d3 || {})));
}(this, function (exports) { 'use strict';
function ascending(a, b) {
return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
}
function bisector(compare) {
if (compare.length === 1) compare = ascendingComparator(compare);
return {
left: function(a, x, lo, hi) {
if (lo == null) lo = 0;
if (hi == null) hi = a.length;
while (lo < hi) {
var mid = lo + hi >>> 1;
if (compare(a[mid], x) < 0) lo = mid + 1;
else hi = mid;
}
return lo;
},
right: function(a, x, lo, hi) {
if (lo == null) lo = 0;
if (hi == null) hi = a.length;
while (lo < hi) {
var mid = lo + hi >>> 1;
if (compare(a[mid], x) > 0) hi = mid;
else lo = mid + 1;
}
return lo;
}
};
}
function ascendingComparator(f) {
return function(d, x) {
return ascending(f(d), x);
};
}
var ascendingBisect = bisector(ascending);
var bisectRight = ascendingBisect.right;
var bisectLeft = ascendingBisect.left;
function descending(a, b) {
return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
}
function number(x) {
return x === null ? NaN : +x;
}
function variance(array, f) {
var n = array.length,
m = 0,
a,
d,
s = 0,
i = -1,
j = 0;
if (f == null) {
while (++i < n) {
if (!isNaN(a = number(array[i]))) {
d = a - m;
m += d / ++j;
s += d * (a - m);
}
}
}
else {
while (++i < n) {
if (!isNaN(a = number(f(array[i], i, array)))) {
d = a - m;
m += d / ++j;
s += d * (a - m);
}
}
}
if (j > 1) return s / (j - 1);
}
function deviation(array, f) {
var v = variance(array, f);
return v ? Math.sqrt(v) : v;
}
function extent(array, f) {
var i = -1,
n = array.length,
a,
b,
c;
if (f == null) {
while (++i < n) if ((b = array[i]) != null && b >= b) { a = c = b; break; }
while (++i < n) if ((b = array[i]) != null) {
if (a > b) a = b;
if (c < b) c = b;
}
}
else {
while (++i < n) if ((b = f(array[i], i, array)) != null && b >= b) { a = c = b; break; }
while (++i < n) if ((b = f(array[i], i, array)) != null) {
if (a > b) a = b;
if (c < b) c = b;
}
}
return [a, c];
}
var array = Array.prototype;
var slice = array.slice;
var map = array.map;
function constant(x) {
return function() {
return x;
};
}
function identity(x) {
return x;
}
function range(start, stop, step) {
start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;
var i = -1,
n = Math.max(0, Math.ceil((stop - start) / step)) | 0,
range = new Array(n);
while (++i < n) {
range[i] = start + i * step;
}
return range;
}
var e10 = Math.sqrt(50);
var e5 = Math.sqrt(10);
var e2 = Math.sqrt(2);
function ticks(start, stop, count) {
var step = tickStep(start, stop, count);
return range(
Math.ceil(start / step) * step,
Math.floor(stop / step) * step + step / 2, // inclusive
step
);
}
function tickStep(start, stop, count) {
var step0 = Math.abs(stop - start) / Math.max(0, count),
step1 = Math.pow(10, Math.floor(Math.log(step0) / Math.LN10)),
error = step0 / step1;
if (error >= e10) step1 *= 10;
else if (error >= e5) step1 *= 5;
else if (error >= e2) step1 *= 2;
return stop < start ? -step1 : step1;
}
function sturges(values) {
return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
}
function histogram() {
var value = identity,
domain = extent,
threshold = sturges;
function histogram(data) {
var i,
n = data.length,
x,
values = new Array(n);
for (i = 0; i < n; ++i) {
values[i] = value(data[i], i, data);
}
var xz = domain(values),
x0 = xz[0],
x1 = xz[1],
tz = threshold(values, x0, x1);
// Convert number of thresholds into uniform thresholds.
if (!Array.isArray(tz)) tz = ticks(x0, x1, tz);
// Remove any thresholds outside the domain.
var m = tz.length;
while (tz[0] <= x0) tz.shift(), --m;
while (tz[m - 1] >= x1) tz.pop(), --m;
var bins = new Array(m + 1),
bin;
// Initialize bins.
for (i = 0; i <= m; ++i) {
bin = bins[i] = [];
bin.x0 = i > 0 ? tz[i - 1] : x0;
bin.x1 = i < m ? tz[i] : x1;
}
// Assign data to bins by value, ignoring any outside the domain.
for (i = 0; i < n; ++i) {
x = values[i];
if (x0 <= x && x <= x1) {
bins[bisectRight(tz, x, 0, m)].push(data[i]);
}
}
return bins;
}
histogram.value = function(_) {
return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
};
histogram.domain = function(_) {
return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
};
histogram.thresholds = function(_) {
return arguments.length ? (threshold = typeof _ === "function" ? _ : Array.isArray(_) ? constant(slice.call(_)) : constant(_), histogram) : threshold;
};
return histogram;
}
function quantile(array, p, f) {
if (f == null) f = number;
if (!(n = array.length)) return;
if ((p = +p) <= 0 || n < 2) return +f(array[0], 0, array);
if (p >= 1) return +f(array[n - 1], n - 1, array);
var n,
h = (n - 1) * p,
i = Math.floor(h),
a = +f(array[i], i, array),
b = +f(array[i + 1], i + 1, array);
return a + (b - a) * (h - i);
}
function freedmanDiaconis(values, min, max) {
values = map.call(values, number).sort(ascending);
return Math.ceil((max - min) / (2 * (quantile(values, 0.75) - quantile(values, 0.25)) * Math.pow(values.length, -1 / 3)));
}
function scott(values, min, max) {
return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
}
function max(array, f) {
var i = -1,
n = array.length,
a,
b;
if (f == null) {
while (++i < n) if ((b = array[i]) != null && b >= b) { a = b; break; }
while (++i < n) if ((b = array[i]) != null && b > a) a = b;
}
else {
while (++i < n) if ((b = f(array[i], i, array)) != null && b >= b) { a = b; break; }
while (++i < n) if ((b = f(array[i], i, array)) != null && b > a) a = b;
}
return a;
}
function mean(array, f) {
var s = 0,
n = array.length,
a,
i = -1,
j = n;
if (f == null) {
while (++i < n) if (!isNaN(a = number(array[i]))) s += a; else --j;
}
else {
while (++i < n) if (!isNaN(a = number(f(array[i], i, array)))) s += a; else --j;
}
if (j) return s / j;
}
function median(array, f) {
var numbers = [],
n = array.length,
a,
i = -1;
if (f == null) {
while (++i < n) if (!isNaN(a = number(array[i]))) numbers.push(a);
}
else {
while (++i < n) if (!isNaN(a = number(f(array[i], i, array)))) numbers.push(a);
}
return quantile(numbers.sort(ascending), 0.5);
}
function merge(arrays) {
var n = arrays.length,
m,
i = -1,
j = 0,
merged,
array;
while (++i < n) j += arrays[i].length;
merged = new Array(j);
while (--n >= 0) {
array = arrays[n];
m = array.length;
while (--m >= 0) {
merged[--j] = array[m];
}
}
return merged;
}
function min(array, f) {
var i = -1,
n = array.length,
a,
b;
if (f == null) {
while (++i < n) if ((b = array[i]) != null && b >= b) { a = b; break; }
while (++i < n) if ((b = array[i]) != null && a > b) a = b;
}
else {
while (++i < n) if ((b = f(array[i], i, array)) != null && b >= b) { a = b; break; }
while (++i < n) if ((b = f(array[i], i, array)) != null && a > b) a = b;
}
return a;
}
function pairs(array) {
var i = 0, n = array.length - 1, p = array[0], pairs = new Array(n < 0 ? 0 : n);
while (i < n) pairs[i] = [p, p = array[++i]];
return pairs;
}
function permute(array, indexes) {
var i = indexes.length, permutes = new Array(i);
while (i--) permutes[i] = array[indexes[i]];
return permutes;
}
function scan(array, compare) {
if (!(n = array.length)) return;
var i = 0,
n,
j = 0,
xi,
xj = array[j];
if (!compare) compare = ascending;
while (++i < n) if (compare(xi = array[i], xj) < 0 || compare(xj, xj) !== 0) xj = xi, j = i;
if (compare(xj, xj) === 0) return j;
}
function shuffle(array, i0, i1) {
var m = (i1 == null ? array.length : i1) - (i0 = i0 == null ? 0 : +i0),
t,
i;
while (m) {
i = Math.random() * m-- | 0;
t = array[m + i0];
array[m + i0] = array[i + i0];
array[i + i0] = t;
}
return array;
}
function sum(array, f) {
var s = 0,
n = array.length,
a,
i = -1;
if (f == null) {
while (++i < n) if (a = +array[i]) s += a; // Note: zero and null are equivalent.
}
else {
while (++i < n) if (a = +f(array[i], i, array)) s += a;
}
return s;
}
function transpose(matrix) {
if (!(n = matrix.length)) return [];
for (var i = -1, m = min(matrix, length), transpose = new Array(m); ++i < m;) {
for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n;) {
row[j] = matrix[j][i];
}
}
return transpose;
}
function length(d) {
return d.length;
}
function zip() {
return transpose(arguments);
}
exports.bisect = bisectRight;
exports.bisectRight = bisectRight;
exports.bisectLeft = bisectLeft;
exports.ascending = ascending;
exports.bisector = bisector;
exports.descending = descending;
exports.deviation = deviation;
exports.extent = extent;
exports.histogram = histogram;
exports.thresholdFreedmanDiaconis = freedmanDiaconis;
exports.thresholdScott = scott;
exports.thresholdSturges = sturges;
exports.max = max;
exports.mean = mean;
exports.median = median;
exports.merge = merge;
exports.min = min;
exports.pairs = pairs;
exports.permute = permute;
exports.quantile = quantile;
exports.range = range;
exports.scan = scan;
exports.shuffle = shuffle;
exports.sum = sum;
exports.ticks = ticks;
exports.tickStep = tickStep;
exports.transpose = transpose;
exports.variance = variance;
exports.zip = zip;
Object.defineProperty(exports, '__esModule', { value: true });
}));
},{}],3:[function(require,module,exports){
// https://d3js.org/d3-collection/ Version 1.0.1. Copyright 2016 Mike Bostock.
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.d3 = global.d3 || {})));
}(this, function (exports) { 'use strict';
var prefix = "$";
function Map() {}
Map.prototype = map.prototype = {
constructor: Map,
has: function(key) {
return (prefix + key) in this;
},
get: function(key) {
return this[prefix + key];
},
set: function(key, value) {
this[prefix + key] = value;
return this;
},
remove: function(key) {
var property = prefix + key;
return property in this && delete this[property];
},
clear: function() {
for (var property in this) if (property[0] === prefix) delete this[property];
},
keys: function() {
var keys = [];
for (var property in this) if (property[0] === prefix) keys.push(property.slice(1));
return keys;
},
values: function() {
var values = [];
for (var property in this) if (property[0] === prefix) values.push(this[property]);
return values;
},
entries: function() {
var entries = [];
for (var property in this) if (property[0] === prefix) entries.push({key: property.slice(1), value: this[property]});
return entries;
},
size: function() {
var size = 0;
for (var property in this) if (property[0] === prefix) ++size;
return size;
},
empty: function() {
for (var property in this) if (property[0] === prefix) return false;
return true;
},
each: function(f) {
for (var property in this) if (property[0] === prefix) f(this[property], property.slice(1), this);
}
};
function map(object, f) {
var map = new Map;
// Copy constructor.
if (object instanceof Map) object.each(function(value, key) { map.set(key, value); });
// Index array by numeric index or specified key function.
else if (Array.isArray(object)) {
var i = -1,
n = object.length,
o;
if (f == null) while (++i < n) map.set(i, object[i]);
else while (++i < n) map.set(f(o = object[i], i, object), o);
}
// Convert object to map.
else if (object) for (var key in object) map.set(key, object[key]);
return map;
}
function nest() {
var keys = [],
sortKeys = [],
sortValues,
rollup,
nest;
function apply(array, depth, createResult, setResult) {
if (depth >= keys.length) return rollup != null
? rollup(array) : (sortValues != null
? array.sort(sortValues)
: array);
var i = -1,
n = array.length,
key = keys[depth++],
keyValue,
value,
valuesByKey = map(),
values,
result = createResult();
while (++i < n) {
if (values = valuesByKey.get(keyValue = key(value = array[i]) + "")) {
values.push(value);
} else {
valuesByKey.set(keyValue, [value]);
}
}
valuesByKey.each(function(values, key) {
setResult(result, key, apply(values, depth, createResult, setResult));
});
return result;
}
function entries(map, depth) {
if (++depth > keys.length) return map;
var array, sortKey = sortKeys[depth - 1];
if (rollup != null && depth >= keys.length) array = map.entries();
else array = [], map.each(function(v, k) { array.push({key: k, values: entries(v, depth)}); });
return sortKey != null ? array.sort(function(a, b) { return sortKey(a.key, b.key); }) : array;
}
return nest = {
object: function(array) { return apply(array, 0, createObject, setObject); },
map: function(array) { return apply(array, 0, createMap, setMap); },
entries: function(array) { return entries(apply(array, 0, createMap, setMap), 0); },
key: function(d) { keys.push(d); return nest; },
sortKeys: function(order) { sortKeys[keys.length - 1] = order; return nest; },
sortValues: function(order) { sortValues = order; return nest; },
rollup: function(f) { rollup = f; return nest; }
};
}
function createObject() {
return {};
}
function setObject(object, key, value) {
object[key] = value;
}
function createMap() {
return map();
}
function setMap(map, key, value) {
map.set(key, value);
}
function Set() {}
var proto = map.prototype;
Set.prototype = set.prototype = {
constructor: Set,
has: proto.has,
add: function(value) {
value += "";
this[prefix + value] = value;
return this;
},
remove: proto.remove,
clear: proto.clear,
values: proto.keys,
size: proto.size,
empty: proto.empty,
each: proto.each
};
function set(object, f) {
var set = new Set;
// Copy constructor.
if (object instanceof Set) object.each(function(value) { set.add(value); });
// Otherwise, assume it’s an array.
else if (object) {
var i = -1, n = object.length;
if (f == null) while (++i < n) set.add(object[i]);
else while (++i < n) set.add(f(object[i], i, object));
}
return set;
}
function keys(map) {
var keys = [];
for (var key in map) keys.push(key);
return keys;
}
function values(map) {
var values = [];
for (var key in map) values.push(map[key]);
return values;
}
function entries(map) {
var entries = [];
for (var key in map) entries.push({key: key, value: map[key]});
return entries;
}
exports.nest = nest;
exports.set = set;
exports.map = map;
exports.keys = keys;
exports.values = values;
exports.entries = entries;
Object.defineProperty(exports, '__esModule', { value: true });
}));
},{}],4:[function(require,module,exports){
// https://d3js.org/d3-color/ Version 1.0.1. Copyright 2016 Mike Bostock.
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.d3 = global.d3 || {})));
}(this, function (exports) { 'use strict';
function define(constructor, factory, prototype) {
constructor.prototype = factory.prototype = prototype;
prototype.constructor = constructor;
}
function extend(parent, definition) {
var prototype = Object.create(parent.prototype);
for (var key in definition) prototype[key] = definition[key];
return prototype;
}
function Color() {}
var darker = 0.7;
var brighter = 1 / darker;
var reHex3 = /^#([0-9a-f]{3})$/;
var reHex6 = /^#([0-9a-f]{6})$/;
var reRgbInteger = /^rgb\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*\)$/;
var reRgbPercent = /^rgb\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/;
var reRgbaInteger = /^rgba\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/;
var reRgbaPercent = /^rgba\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/;
var reHslPercent = /^hsl\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/;
var reHslaPercent = /^hsla\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/;
var named = {
aliceblue: 0xf0f8ff,
antiquewhite: 0xfaebd7,
aqua: 0x00ffff,
aquamarine: 0x7fffd4,
azure: 0xf0ffff,
beige: 0xf5f5dc,
bisque: 0xffe4c4,
black: 0x000000,
blanchedalmond: 0xffebcd,
blue: 0x0000ff,
blueviolet: 0x8a2be2,
brown: 0xa52a2a,
burlywood: 0xdeb887,
cadetblue: 0x5f9ea0,
chartreuse: 0x7fff00,
chocolate: 0xd2691e,
coral: 0xff7f50,
cornflowerblue: 0x6495ed,
cornsilk: 0xfff8dc,
crimson: 0xdc143c,
cyan: 0x00ffff,
darkblue: 0x00008b,
darkcyan: 0x008b8b,
darkgoldenrod: 0xb8860b,
darkgray: 0xa9a9a9,
darkgreen: 0x006400,
darkgrey: 0xa9a9a9,
darkkhaki: 0xbdb76b,
darkmagenta: 0x8b008b,
darkolivegreen: 0x556b2f,
darkorange: 0xff8c00,
darkorchid: 0x9932cc,
darkred: 0x8b0000,
darksalmon: 0xe9967a,
darkseagreen: 0x8fbc8f,
darkslateblue: 0x483d8b,
darkslategray: 0x2f4f4f,
darkslategrey: 0x2f4f4f,
darkturquoise: 0x00ced1,
darkviolet: 0x9400d3,
deeppink: 0xff1493,
deepskyblue: 0x00bfff,
dimgray: 0x696969,
dimgrey: 0x696969,
dodgerblue: 0x1e90ff,
firebrick: 0xb22222,
floralwhite: 0xfffaf0,
forestgreen: 0x228b22,
fuchsia: 0xff00ff,
gainsboro: 0xdcdcdc,
ghostwhite: 0xf8f8ff,
gold: 0xffd700,
goldenrod: 0xdaa520,
gray: 0x808080,
green: 0x008000,
greenyellow: 0xadff2f,
grey: 0x808080,
honeydew: 0xf0fff0,
hotpink: 0xff69b4,
indianred: 0xcd5c5c,
indigo: 0x4b0082,
ivory: 0xfffff0,
khaki: 0xf0e68c,
lavender: 0xe6e6fa,
lavenderblush: 0xfff0f5,
lawngreen: 0x7cfc00,
lemonchiffon: 0xfffacd,
lightblue: 0xadd8e6,
lightcoral: 0xf08080,
lightcyan: 0xe0ffff,
lightgoldenrodyellow: 0xfafad2,
lightgray: 0xd3d3d3,
lightgreen: 0x90ee90,
lightgrey: 0xd3d3d3,
lightpink: 0xffb6c1,
lightsalmon: 0xffa07a,
lightseagreen: 0x20b2aa,
lightskyblue: 0x87cefa,
lightslategray: 0x778899,
lightslategrey: 0x778899,
lightsteelblue: 0xb0c4de,
lightyellow: 0xffffe0,
lime: 0x00ff00,
limegreen: 0x32cd32,
linen: 0xfaf0e6,
magenta: 0xff00ff,
maroon: 0x800000,
mediumaquamarine: 0x66cdaa,
mediumblue: 0x0000cd,
mediumorchid: 0xba55d3,
mediumpurple: 0x9370db,
mediumseagreen: 0x3cb371,
mediumslateblue: 0x7b68ee,
mediumspringgreen: 0x00fa9a,
mediumturquoise: 0x48d1cc,
mediumvioletred: 0xc71585,
midnightblue: 0x191970,
mintcream: 0xf5fffa,
mistyrose: 0xffe4e1,
moccasin: 0xffe4b5,
navajowhite: 0xffdead,
navy: 0x000080,
oldlace: 0xfdf5e6,
olive: 0x808000,
olivedrab: 0x6b8e23,
orange: 0xffa500,
orangered: 0xff4500,
orchid: 0xda70d6,
palegoldenrod: 0xeee8aa,
palegreen: 0x98fb98,
paleturquoise: 0xafeeee,
palevioletred: 0xdb7093,
papayawhip: 0xffefd5,
peachpuff: 0xffdab9,
peru: 0xcd853f,
pink: 0xffc0cb,
plum: 0xdda0dd,
powderblue: 0xb0e0e6,
purple: 0x800080,
rebeccapurple: 0x663399,
red: 0xff0000,
rosybrown: 0xbc8f8f,
royalblue: 0x4169e1,
saddlebrown: 0x8b4513,
salmon: 0xfa8072,
sandybrown: 0xf4a460,
seagreen: 0x2e8b57,
seashell: 0xfff5ee,
sienna: 0xa0522d,
silver: 0xc0c0c0,
skyblue: 0x87ceeb,
slateblue: 0x6a5acd,
slategray: 0x708090,
slategrey: 0x708090,
snow: 0xfffafa,
springgreen: 0x00ff7f,
steelblue: 0x4682b4,
tan: 0xd2b48c,
teal: 0x008080,
thistle: 0xd8bfd8,
tomato: 0xff6347,
turquoise: 0x40e0d0,
violet: 0xee82ee,
wheat: 0xf5deb3,
white: 0xffffff,
whitesmoke: 0xf5f5f5,
yellow: 0xffff00,
yellowgreen: 0x9acd32
};
define(Color, color, {
displayable: function() {
return this.rgb().displayable();
},
toString: function() {
return this.rgb() + "";
}
});
function color(format) {
var m;
format = (format + "").trim().toLowerCase();
return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), new Rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1)) // #f00
: (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
: (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
: (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
: (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
: (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
: (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
: (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
: named.hasOwnProperty(format) ? rgbn(named[format])
: format === "transparent" ? new Rgb(NaN, NaN, NaN, 0)
: null;
}
function rgbn(n) {
return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
}
function rgba(r, g, b, a) {
if (a <= 0) r = g = b = NaN;
return new Rgb(r, g, b, a);
}
function rgbConvert(o) {
if (!(o instanceof Color)) o = color(o);
if (!o) return new Rgb;
o = o.rgb();
return new Rgb(o.r, o.g, o.b, o.opacity);
}
function rgb(r, g, b, opacity) {
return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
}
function Rgb(r, g, b, opacity) {
this.r = +r;
this.g = +g;
this.b = +b;
this.opacity = +opacity;
}
define(Rgb, rgb, extend(Color, {
brighter: function(k) {
k = k == null ? brighter : Math.pow(brighter, k);
return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
},
darker: function(k) {
k = k == null ? darker : Math.pow(darker, k);
return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
},
rgb: function() {
return this;
},
displayable: function() {
return (0 <= this.r && this.r <= 255)
&& (0 <= this.g && this.g <= 255)
&& (0 <= this.b && this.b <= 255)
&& (0 <= this.opacity && this.opacity <= 1);
},
toString: function() {
var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
return (a === 1 ? "rgb(" : "rgba(")
+ Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
+ Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
+ Math.max(0, Math.min(255, Math.round(this.b) || 0))
+ (a === 1 ? ")" : ", " + a + ")");
}
}));
function hsla(h, s, l, a) {
if (a <= 0) h = s = l = NaN;
else if (l <= 0 || l >= 1) h = s = NaN;
else if (s <= 0) h = NaN;
return new Hsl(h, s, l, a);
}
function hslConvert(o) {
if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
if (!(o instanceof Color)) o = color(o);
if (!o) return new Hsl;
if (o instanceof Hsl) return o;
o = o.rgb();
var r = o.r / 255,
g = o.g / 255,
b = o.b / 255,
min = Math.min(r, g, b),
max = Math.max(r, g, b),
h = NaN,
s = max - min,
l = (max + min) / 2;
if (s) {
if (r === max) h = (g - b) / s + (g < b) * 6;
else if (g === max) h = (b - r) / s + 2;
else h = (r - g) / s + 4;
s /= l < 0.5 ? max + min : 2 - max - min;
h *= 60;
} else {
s = l > 0 && l < 1 ? 0 : h;
}
return new Hsl(h, s, l, o.opacity);
}
function hsl(h, s, l, opacity) {
return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
}
function Hsl(h, s, l, opacity) {
this.h = +h;
this.s = +s;
this.l = +l;
this.opacity = +opacity;
}
define(Hsl, hsl, extend(Color, {
brighter: function(k) {
k = k == null ? brighter : Math.pow(brighter, k);
return new Hsl(this.h, this.s, this.l * k, this.opacity);
},
darker: function(k) {
k = k == null ? darker : Math.pow(darker, k);
return new Hsl(this.h, this.s, this.l * k, this.opacity);
},
rgb: function() {
var h = this.h % 360 + (this.h < 0) * 360,
s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
l = this.l,
m2 = l + (l < 0.5 ? l : 1 - l) * s,
m1 = 2 * l - m2;
return new Rgb(
hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
hsl2rgb(h, m1, m2),
hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
this.opacity
);
},
displayable: function() {
return (0 <= this.s && this.s <= 1 || isNaN(this.s))
&& (0 <= this.l && this.l <= 1)
&& (0 <= this.opacity && this.opacity <= 1);
}
}));
/* From FvD 13.37, CSS Color Module Level 3 */
function hsl2rgb(h, m1, m2) {
return (h < 60 ? m1 + (m2 - m1) * h / 60
: h < 180 ? m2
: h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
: m1) * 255;
}
var deg2rad = Math.PI / 180;
var rad2deg = 180 / Math.PI;
var Kn = 18;
var Xn = 0.950470;
var Yn = 1;
var Zn = 1.088830;
var t0 = 4 / 29;
var t1 = 6 / 29;
var t2 = 3 * t1 * t1;
var t3 = t1 * t1 * t1;
function labConvert(o) {
if (o instanceof Lab) return new Lab(o.l, o.a, o.b, o.opacity);
if (o instanceof Hcl) {
var h = o.h * deg2rad;
return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity);
}
if (!(o instanceof Rgb)) o = rgbConvert(o);
var b = rgb2xyz(o.r),
a = rgb2xyz(o.g),
l = rgb2xyz(o.b),
x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn),
y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.0721750 * l) / Yn),
z = xyz2lab((0.0193339 * b + 0.1191920 * a + 0.9503041 * l) / Zn);
return new Lab(116 * y - 16, 500 * (x - y), 200 * (y - z), o.opacity);
}
function lab(l, a, b, opacity) {
return arguments.length === 1 ? labConvert(l) : new Lab(l, a, b, opacity == null ? 1 : opacity);
}
function Lab(l, a, b, opacity) {
this.l = +l;
this.a = +a;
this.b = +b;
this.opacity = +opacity;
}
define(Lab, lab, extend(Color, {
brighter: function(k) {
return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
},
darker: function(k) {
return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
},
rgb: function() {
var y = (this.l + 16) / 116,
x = isNaN(this.a) ? y : y + this.a / 500,
z = isNaN(this.b) ? y : y - this.b / 200;
y = Yn * lab2xyz(y);
x = Xn * lab2xyz(x);
z = Zn * lab2xyz(z);
return new Rgb(
xyz2rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB
xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
this.opacity
);
}
}));
function xyz2lab(t) {
return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
}
function lab2xyz(t) {
return t > t1 ? t * t * t : t2 * (t - t0);
}
function xyz2rgb(x) {
return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
}
function rgb2xyz(x) {
return (x /= 255) <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
}
function hclConvert(o) {
if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity);
if (!(o instanceof Lab)) o = labConvert(o);
var h = Math.atan2(o.b, o.a) * rad2deg;
return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity);
}
function hcl(h, c, l, opacity) {
return arguments.length === 1 ? hclConvert(h) : new Hcl(h, c, l, opacity == null ? 1 : opacity);
}
function Hcl(h, c, l, opacity) {
this.h = +h;
this.c = +c;
this.l = +l;
this.opacity = +opacity;
}
define(Hcl, hcl, extend(Color, {
brighter: function(k) {
return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
},
darker: function(k) {
return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
},
rgb: function() {
return labConvert(this).rgb();
}
}));
var A = -0.14861;
var B = +1.78277;
var C = -0.29227;
var D = -0.90649;
var E = +1.97294;
var ED = E * D;
var EB = E * B;
var BC_DA = B * C - D * A;
function cubehelixConvert(o) {
if (o instanceof Cubehelix) return new Cubehelix(o.h, o.s, o.l, o.opacity);
if (!(o instanceof Rgb)) o = rgbConvert(o);
var r = o.r / 255,
g = o.g / 255,
b = o.b / 255,
l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB),
bl = b - l,
k = (E * (g - l) - C * bl) / D,
s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1
h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN;
return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity);
}
function cubehelix(h, s, l, opacity) {
return arguments.length === 1 ? cubehelixConvert(h) : new Cubehelix(h, s, l, opacity == null ? 1 : opacity);
}
function Cubehelix(h, s, l, opacity) {
this.h = +h;
this.s = +s;
this.l = +l;
this.opacity = +opacity;
}
define(Cubehelix, cubehelix, extend(Color, {
brighter: function(k) {
k = k == null ? brighter : Math.pow(brighter, k);
return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
},
darker: function(k) {
k = k == null ? darker : Math.pow(darker, k);
return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
},
rgb: function() {
var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,
l = +this.l,
a = isNaN(this.s) ? 0 : this.s * l * (1 - l),
cosh = Math.cos(h),
sinh = Math.sin(h);
return new Rgb(
255 * (l + a * (A * cosh + B * sinh)),
255 * (l + a * (C * cosh + D * sinh)),
255 * (l + a * (E * cosh)),
this.opacity
);
}
}));
exports.color = color;
exports.rgb = rgb;
exports.hsl = hsl;
exports.lab = lab;
exports.hcl = hcl;
exports.cubehelix = cubehelix;
Object.defineProperty(exports, '__esModule', { value: true });
}));
},{}],5:[function(require,module,exports){
// http://geoexamples.com/d3-composite-projections/ Version 1.0.0. Copyright 2016 Roger Veciana i Rovira.
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-geo'), require('d3-path')) :
typeof define === 'function' && define.amd ? define(['exports', 'd3-geo', 'd3-path'], factory) :
(factory((global.d3 = global.d3 || {}),global.d3,global.d3));
}(this, function (exports,d3Geo,d3Path) { 'use strict';
var epsilon = 1e-6;
// The projections must have mutually exclusive clip regions on the sphere,
// as this will avoid emitting interleaving lines and polygons.
function multiplex(streams) {
var n = streams.length;
return {
point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
};
}
// A composite projection for the United States, configured by default for
// 960×500. Also works quite well at 960×600 with scale 1285. The set of
// standard parallels for each region comes from USGS, which is published here:
// http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
function albersUsa() {
var cache,
cacheStream,
lower48 = d3Geo.geoAlbers(), lower48Point,
alaska = d3Geo.geoConicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
hawaii = d3Geo.geoConicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
point, pointStream = {point: function(x, y) { point = [x, y]; }};
function albersUsa(coordinates) {
var x = coordinates[0], y = coordinates[1];
return point = null,
(lower48Point.point(x, y), point)
|| (alaskaPoint.point(x, y), point)
|| (hawaiiPoint.point(x, y), point);
}
albersUsa.invert = function(coordinates) {
var k = lower48.scale(),
t = lower48.translate(),
x = (coordinates[0] - t[0]) / k,
y = (coordinates[1] - t[1]) / k;
return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
: y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
: lower48).invert(coordinates);
};
albersUsa.stream = function(stream) {
return cache && cacheStream === stream ? cache : cache = multiplex([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream)]);
};
albersUsa.precision = function(_) {
if (!arguments.length) return lower48.precision();
lower48.precision(_), alaska.precision(_), hawaii.precision(_);
return albersUsa;
};
albersUsa.scale = function(_) {
if (!arguments.length) return lower48.scale();
lower48.scale(_), alaska.scale(_ * 0.35), hawaii.scale(_);
return albersUsa.translate(lower48.translate());
};
albersUsa.translate = function(_) {
if (!arguments.length) return lower48.translate();
var k = lower48.scale(), x = +_[0], y = +_[1];
lower48Point = lower48
.translate(_)
.clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
.stream(pointStream);
alaskaPoint = alaska
.translate([x - 0.307 * k, y + 0.201 * k])
.clipExtent([[x - 0.425 * k + epsilon, y + 0.120 * k + epsilon], [x - 0.214 * k - epsilon, y + 0.234 * k - epsilon]])
.stream(pointStream);
hawaiiPoint = hawaii
.translate([x - 0.205 * k, y + 0.212 * k])
.clipExtent([[x - 0.214 * k + epsilon, y + 0.166 * k + epsilon], [x - 0.115 * k - epsilon, y + 0.234 * k - epsilon]])
.stream(pointStream);
return albersUsa;
};
albersUsa.drawCompositionBorders = function(context) {
var hawaii1 = lower48([-102.91, 26.3]);
var hawaii2 = lower48([-104.0, 27.5]);
var hawaii3 = lower48([-108.0, 29.1]);
var hawaii4 = lower48([-110.0, 29.1]);
var alaska1 = lower48([-110.0, 26.7]);
var alaska2 = lower48([-112.8, 27.6]);
var alaska3 = lower48([-114.3, 30.6]);
var alaska4 = lower48([-119.3, 30.1]);
context.moveTo(hawaii1[0], hawaii1[1]);
context.lineTo(hawaii2[0], hawaii2[1]);
context.lineTo(hawaii3[0], hawaii3[1]);
context.lineTo(hawaii4[0], hawaii4[1]);
context.moveTo(alaska1[0], alaska1[1]);
context.lineTo(alaska2[0], alaska2[1]);
context.lineTo(alaska3[0], alaska3[1]);
context.lineTo(alaska4[0], alaska4[1]);
};
albersUsa.getCompositionBorders = function() {
var context = d3Path.path();
this.drawCompositionBorders(context);
return context.toString();
};
return albersUsa.scale(1070);
}
// The projections must have mutually exclusive clip regions on the sphere,
// as this will avoid emitting interleaving lines and polygons.
function multiplex$1(streams) {
var n = streams.length;
return {
point: function(x, y) { var i = -1; while (++i < n) streams[i].point(x, y); },
sphere: function() { var i = -1; while (++i < n) streams[i].sphere(); },
lineStart: function() { var i = -1; while (++i < n) streams[i].lineStart(); },
lineEnd: function() { var i = -1; while (++i < n) streams[i].lineEnd(); },
polygonStart: function() { var i = -1; while (++i < n) streams[i].polygonStart(); },
polygonEnd: function() { var i = -1; while (++i < n) streams[i].polygonEnd(); }
};
}
// A composite projection for the United States, configured by default for
// 960×500. Also works quite well at 960×600 with scale 1285. The set of
// standard parallels for each region comes from USGS, which is published here:
// http://egsc.usgs.gov/isb/pubs/MapProjections/projections.html#albers
function albersUsaTerritories() {
var cache,
cacheStream,
lower48 = d3Geo.geoAlbers(), lower48Point,
alaska = d3Geo.geoConicEqualArea().rotate([154, 0]).center([-2, 58.5]).parallels([55, 65]), alaskaPoint, // EPSG:3338
hawaii = d3Geo.geoConicEqualArea().rotate([157, 0]).center([-3, 19.9]).parallels([8, 18]), hawaiiPoint, // ESRI:102007
puertoRico = d3Geo.geoConicEqualArea().rotate([66, 0]).center([0, 18]).parallels([8, 18]), puertoRicoPoint, //Taken from https://bl.ocks.org/mbostock/5629120
samoa = d3Geo.geoEquirectangular().rotate([173, 14]), samoaPoint, // EPSG:4169
guam = d3Geo.geoEquirectangular().rotate([-145, -16.8]), guamPoint,
point, pointStream = {point: function(x, y) { point = [x, y]; }};
/*
var puertoRicoBbox = [[-68.3, 19], [-63.9, 17]];
var samoaBbox = [[-171, -14], [-168, -14.8]];
var guamBbox = [[144, 20.8], [146.5, 12.7]];
*/
function albersUsa(coordinates) {
var x = coordinates[0], y = coordinates[1];
return point = null,
(lower48Point.point(x, y), point) ||
(alaskaPoint.point(x, y), point) ||
(hawaiiPoint.point(x, y), point) ||
(puertoRicoPoint.point(x, y), point) ||
(samoaPoint.point(x, y), point) ||
(guamPoint.point(x, y), point);
}
albersUsa.invert = function(coordinates) {
var k = lower48.scale(),
t = lower48.translate(),
x = (coordinates[0] - t[0]) / k,
y = (coordinates[1] - t[1]) / k;
/*
//How are the return values calculated:
console.info("******");
var c0 = puertoRico(puertoRicoBbox[0]);
var x0 = (c0[0] - t[0]) / k;
var y0 = (c0[1] - t[1]) / k;
console.info("p0 puertoRico", x0 + ' - ' + y0);
var c1 = puertoRico(puertoRicoBbox[1]);
var x1 = (c1[0] - t[0]) / k;
var y1 = (c1[1] - t[1]) / k;
console.info("p1 puertoRico", x1 + ' - ' + y1);
c0 = samoa(samoaBbox[0]);
x0 = (c0[0] - t[0]) / k;
y0 = (c0[1] - t[1]) / k;
console.info("p0 samoa", x0 + ' - ' + y0);
c1 = samoa(samoaBbox[1]);
x1 = (c1[0] - t[0]) / k;
y1 = (c1[1] - t[1]) / k;
console.info("p1 samoa", x1 + ' - ' + y1);
c0 = guam(guamBbox[0]);
x0 = (c0[0] - t[0]) / k;
y0 = (c0[1] - t[1]) / k;
console.info("p0 guam", x0 + ' - ' + y0);
c1 = guam(guamBbox[1]);
x1 = (c1[0] - t[0]) / k;
y1 = (c1[1] - t[1]) / k;
console.info("p1 guam", x1 + ' - ' + y1);
*/
return (y >= 0.120 && y < 0.234 && x >= -0.425 && x < -0.214 ? alaska
: y >= 0.166 && y < 0.234 && x >= -0.214 && x < -0.115 ? hawaii
: y >= 0.2064 && y < 0.2413 && x >= 0.312 && x < 0.385 ? puertoRico
: y >= 0.09 && y < 0.1197 && x >= -0.4243 && x < -0.3232 ? samoa
: y >= -0.0518 && y < 0.0895 && x >= -0.4243 && x < -0.3824 ? guam
: lower48).invert(coordinates);
};
albersUsa.stream = function(stream) {
return cache && cacheStream === stream ? cache : cache = multiplex$1([lower48.stream(cacheStream = stream), alaska.stream(stream), hawaii.stream(stream), puertoRico.stream(stream), samoa.stream(stream), guam.stream(stream)]);
};
albersUsa.precision = function(_) {
if (!arguments.length) {return lower48.precision();}
lower48.precision(_);
alaska.precision(_);
hawaii.precision(_);
puertoRico.precision(_);
samoa.precision(_);
guam.precision(_);
return albersUsa;
};
albersUsa.scale = function(_) {
if (!arguments.length) {return lower48.scale();}
lower48.scale(_);
alaska.scale(_ * 0.35);
hawaii.scale(_);
puertoRico.scale(_);
samoa.scale(_* 2);
guam.scale(_);
return albersUsa.translate(lower48.translate());
};
albersUsa.translate = function(_) {
if (!arguments.length) {return lower48.translate();}
var k = lower48.scale(), x = +_[0], y = +_[1];
/*
var c0 = puertoRico.translate([x + 0.350 * k, y + 0.224 * k])(puertoRicoBbox[0]);
var x0 = (x - c0[0]) / k;
var y0 = (y - c0[1]) / k;
var c1 = puertoRico.translate([x + 0.350 * k, y + 0.224 * k])(puertoRicoBbox[1]);
var x1 = (x - c1[0]) / k;
var y1 = (y - c1[1]) / k;
console.info('puertoRico: p0: ' + x0 + ', ' + y0 + ' , p1: ' + x1 + ' - ' + y1);
console.info('.clipExtent([[x '+
(x0<0?'+ ':'- ') + Math.abs(x0.toFixed(4))+
' * k + epsilon, y '+
(y0<0?'+ ':'- ') + Math.abs(y0.toFixed(4))+
' * k + epsilon],[x '+
(x1<0?'+ ':'- ') + Math.abs(x1.toFixed(4))+
' * k - epsilon, y '+
(y1<0?'+ ':'- ') + Math.abs(y1.toFixed(4))+
' * k - epsilon]])');
c0 = samoa.translate([x - 0.492 * k, y + 0.09 * k])(samoaBbox[0]);
x0 = (x - c0[0]) / k;
y0 = (y - c0[1]) / k;
c1 = samoa.translate([x - 0.492 * k, y + 0.09 * k])(samoaBbox[1]);
x1 = (x - c1[0]) / k;
y1 = (y - c1[1]) / k;
console.info('samoa: p0: ' + x0 + ', ' + y0 + ' , p1: ' + x1 + ' - ' + y1);
console.info('.clipExtent([[x '+
(x0<0?'+ ':'- ') + Math.abs(x0.toFixed(4))+
' * k + epsilon, y '+
(y0<0?'+ ':'- ') + Math.abs(y0.toFixed(4))+
' * k + epsilon],[x '+
(x1<0?'+ ':'- ') + Math.abs(x1.toFixed(4))+
' * k - epsilon, y '+
(y1<0?'+ ':'- ') + Math.abs(y1.toFixed(4))+
' * k - epsilon]])');
c0 = guam.translate([x - 0.408 * k, y + 0.018 * k])(guamBbox[0]);
x0 = (x - c0[0]) / k;
y0 = (y - c0[1]) / k;
c1 = guam.translate([x - 0.408 * k, y + 0.018 * k])(guamBbox[1]);
x1 = (x - c1[0]) / k;
y1 = (y - c1[1]) / k;
console.info('guam: p0: ' + x0 + ', ' + y0 + ' , p1: ' + x1 + ' - ' + y1);
console.info('.clipExtent([[x '+
(x0<0?'+ ':'- ') + Math.abs(x0.toFixed(4))+
' * k + epsilon, y '+
(y0<0?'+ ':'- ') + Math.abs(y0.toFixed(4))+
' * k + epsilon],[x '+
(x1<0?'+ ':'- ') + Math.abs(x1.toFixed(4))+
' * k - epsilon, y '+
(y1<0?'+ ':'- ') + Math.abs(y1.toFixed(4))+
' * k - epsilon]])');
*/
lower48Point = lower48
.translate(_)
.clipExtent([[x - 0.455 * k, y - 0.238 * k], [x + 0.455 * k, y + 0.238 * k]])
.stream(pointStream);
alaskaPoint = alaska
.translate([x - 0.307 * k, y + 0.201 * k])
.clipExtent([[x - 0.425 * k + epsilon, y + 0.120 * k + epsilon], [x - 0.214 * k - epsilon, y + 0.233 * k - epsilon]])
.stream(pointStream);
hawaiiPoint = hawaii
.translate([x - 0.205 * k, y + 0.212 * k])
.clipExtent([[x - 0.214 * k + epsilon, y + 0.166 * k + epsilon], [x - 0.115 * k - epsilon, y + 0.233 * k - epsilon]])
.stream(pointStream);
puertoRicoPoint = puertoRico
.translate([x + 0.350 * k, y + 0.224 * k])
.clipExtent([[x + 0.312 * k + epsilon, y + 0.2064 * k + epsilon],[x + 0.385 * k - epsilon, y + 0.233 * k - epsilon]])
.stream(pointStream);
samoaPoint = samoa
.translate([x - 0.492 * k, y + 0.09 * k])
.clipExtent([[x - 0.4243 * k + epsilon, y + 0.0903 * k + epsilon],[x - 0.3233 * k - epsilon, y + 0.1197 * k - epsilon]])
.stream(pointStream);
guamPoint = guam
.translate([x - 0.408 * k, y + 0.018 * k])
.clipExtent([[x - 0.4244 * k + epsilon, y - 0.0519 * k + epsilon],[x - 0.3824 * k - epsilon, y + 0.0895 * k - epsilon]])
.stream(pointStream);
return albersUsa;
};
albersUsa.drawCompositionBorders = function(context) {
/*
console.info("CLIP EXTENT hawaii: ", hawaii.clipExtent());
console.info("UL BBOX:", lower48.invert([hawaii.clipExtent()[0][0], hawaii.clipExtent()[0][1]]));
console.info("UR BBOX:", lower48.invert([hawaii.clipExtent()[1][0], hawaii.clipExtent()[0][1]]));
console.info("LD BBOX:", lower48.invert([hawaii.clipExtent()[1][0], hawaii.clipExtent()[1][1]]));
console.info("LL BBOX:", lower48.invert([hawaii.clipExtent()[0][0], hawaii.clipExtent()[1][1]]));
console.info("CLIP EXTENT alaska: ", alaska.clipExtent());
console.info("UL BBOX:", lower48.invert([alaska.clipExtent()[0][0], alaska.clipExtent()[0][1]]));
console.info("UR BBOX:", lower48.invert([alaska.clipExtent()[1][0], alaska.clipExtent()[0][1]]));
console.info("LD BBOX:", lower48.invert([alaska.clipExtent()[1][0], alaska.clipExtent()[1][1]]));
console.info("LL BBOX:", lower48.invert([alaska.clipExtent()[0][0], alaska.clipExtent()[1][1]]));
console.info("CLIP EXTENT puertoRico: ", puertoRico.clipExtent());
console.info("UL BBOX:", lower48.invert([puertoRico.clipExtent()[0][0], puertoRico.clipExtent()[0][1]]));
console.info("UR BBOX:", lower48.invert([puertoRico.clipExtent()[1][0], puertoRico.clipExtent()[0][1]]));
console.info("LD BBOX:", lower48.invert([puertoRico.clipExtent()[1][0], puertoRico.clipExtent()[1][1]]));
console.info("LL BBOX:", lower48.invert([puertoRico.clipExtent()[0][0], puertoRico.clipExtent()[1][1]]));
console.info("CLIP EXTENT samoa: ", samoa.clipExtent());
console.info("UL BBOX:", lower48.invert([samoa.clipExtent()[0][0], samoa.clipExtent()[0][1]]));
console.info("UR BBOX:", lower48.invert([samoa.clipExtent()[1][0], samoa.clipExtent()[0][1]]));
console.info("LD BBOX:", lower48.invert([samoa.clipExtent()[1][0], samoa.clipExtent()[1][1]]));
console.info("LL BBOX:", lower48.invert([samoa.clipExtent()[0][0], samoa.clipExtent()[1][1]]));
console.info("CLIP EXTENT guam: ", guam.clipExtent());
console.info("UL BBOX:", lower48.invert([guam.clipExtent()[0][0], guam.clipExtent()[0][1]]));
console.info("UR BBOX:", lower48.invert([guam.clipExtent()[1][0], guam.clipExtent()[0][1]]));
console.info("LD BBOX:", lower48.invert([guam.clipExtent()[1][0], guam.clipExtent()[1][1]]));
console.info("LL BBOX:", lower48.invert([guam.clipExtent()[0][0], guam.clipExtent()[1][1]]));
*/
var ulhawaii = lower48([-110.4641, 28.2805]);
var urhawaii = lower48([-104.0597, 28.9528]);
var ldhawaii = lower48([-103.7049, 25.1031]);
var llhawaii = lower48([-109.8337, 24.4531]);
var ulalaska = lower48([ -124.4745, 28.1407]);
var uralaska = lower48([ -110.931, 30.8844]);
var ldalaska = lower48([-109.8337, 24.4531]);
var llalaska = lower48([-122.4628, 21.8562]);
var ulpuertoRico = lower48([-76.8579, 25.1544]);
var urpuertoRico = lower48([-72.429, 24.2097]);
var ldpuertoRico = lower48([-72.8265, 22.7056]);
var llpuertoRico = lower48([-77.1852, 23.6392]);
var ulsamoa = lower48([-125.0093, 29.7791]);
var ursamoa = lower48([-118.5193, 31.3262]);
var ldsamoa = lower48([-118.064, 29.6912]);
var llsamoa = lower48([-124.4369, 28.169]);
var ulguam = lower48([-128.1314, 37.4582]);
var urguam = lower48([-125.2132, 38.214]);
var ldguam = lower48([-122.3616, 30.5115]);
var llguam = lower48([-125.0315, 29.8211]);
context.moveTo(ulhawaii[0], ulhawaii[1]);
context.lineTo(urhawaii[0], urhawaii[1]);
context.lineTo(ldhawaii[0], ldhawaii[1]);
context.lineTo(ldhawaii[0], ldhawaii[1]);
context.lineTo(llhawaii[0], llhawaii[1]);
context.closePath();
context.moveTo(ulalaska[0], ulalaska[1]);
context.lineTo(uralaska[0], uralaska[1]);
context.lineTo(ldalaska[0], ldalaska[1]);
context.lineTo(ldalaska[0], ldalaska[1]);
context.lineTo(llalaska[0], llalaska[1]);
context.closePath();
context.moveTo(ulpuertoRico[0], ulpuertoRico[1]);
context.lineTo(urpuertoRico[0], urpuertoRico[1]);
context.lineTo(ldpuertoRico[0], ldpuertoRico[1]);
context.lineTo(ldpuertoRico[0], ldpuertoRico[1]);
context.lineTo(llpuertoRico[0], llpuertoRico[1]);
context.closePath();
context.moveTo(ulsamoa[0], ulsamoa[1]);
context.lineTo(ursamoa[0], ursamoa[1]);
context.lineTo(ldsamoa[0], ldsamoa[1]);
context.lineTo(ldsamoa[0], ldsamoa[1]);
context.lineTo(llsamoa[0], llsamoa[1]);
context.closePath();
context.moveTo(ulguam[0], ulguam[1]);
context.lineTo(urguam[0], urguam[1]);
context.lineTo(ldguam[0], ldguam[1]);
context.lineTo(ldguam[0], ldguam[1]);
context.lineTo(llguam[0], llguam[1]);
context.closePath();
};
albersUsa.getCompositionBorders = function() {
var context = d3Path.path();
this.drawCompositionBorders(context);
return context.toString();
};
return albersUsa.scale(1070);
}
// The projections must have mutually exclusive clip regions on the sphere,
// as this will avoid emitting interleaving lines and polygons.
function multiplex$2(streams) {
var n = streams.length;
return {
point: function(x, y) { var i = -1; while (++i < n) {streams[i].point(x, y); }},
sphere: function() { var i = -1; while (++i < n) {streams[i].sphere(); }},
lineStart: function() { var i = -1; while (++i < n) {streams[i].lineStart(); }},
lineEnd: function() { var i = -1; while (++i < n) {streams[i].lineEnd(); }},
polygonStart: function() { var i = -1; while (++i < n) {streams[i].polygonStart(); }},
polygonEnd: function() { var i = -1; while (++i < n) {streams[i].polygonEnd(); }}
};
}
// A composite projection for Spain, configured by default for 960×500.
function conicConformalSpain() {
var cache,
cacheStream,
iberianPeninsule = d3Geo.geoConicConformal().rotate([5, -38.6]).parallels([0,60]), iberianPeninsulePoint,
canaryIslands = d3Geo.geoConicConformal().rotate([5, -38.6]).parallels([0,60]), canaryIslandsPoint,
point, pointStream = {point: function(x, y) { point = [x, y]; }};
/*
var iberianPeninsuleBbox = [[-11, 46], [4, 35]];
var canaryIslandsBbox = [[-19.0, 28.85], [-12.7, 28.1]];
*/
function conicConformalSpain(coordinates) {
var x = coordinates[0], y = coordinates[1];
return point = null,
(iberianPeninsulePoint.point(x, y), point) ||
(canaryIslandsPoint.point(x, y), point);
}
conicConformalSpain.invert = function(coordinates) {
var k = iberianPeninsule.scale(),
t = iberianPeninsule.translate(),
x = (coordinates[0] - t[0]) / k,
y = (coordinates[1] - t[1]) / k;
/*
//How are the return values calculated:
var c0 = canaryIslands(canaryIslandsBbox[0]);
var x0 = (c0[0] - t[0]) / k;
var y0 = (c0[1] - t[1]) / k;
console.info("p0 canary islands", x0 + ' - ' + y0);
var c1 = canaryIslands(canaryIslandsBbox[1]);
var x1 = (c1[0] - t[0]) / k;
var y1 = (c1[1] - t[1]) / k;
console.info("p1 canary islands", x1 + ' - ' + y1);
*/
return (y >= 0.05346 && y< 0.0897 && x >= -0.13388 && x < -0.0322 ? canaryIslands
: iberianPeninsule).invert(coordinates);
};
conicConformalSpain.stream = function(stream) {
return cache && cacheStream === stream ? cache : cache = multiplex$2([iberianPeninsule.stream(cacheStream = stream), canaryIslands.stream(stream)]);
};
conicConformalSpain.precision = function(_) {
if (!arguments.length) {return iberianPeninsule.precision();}
iberianPeninsule.precision(_);
canaryIslands.precision(_);
return conicConformalSpain;
};
conicConformalSpain.scale = function(_) {
if (!arguments.length) {return iberianPeninsule.scale();}
iberianPeninsule.scale(_);
canaryIslands.scale(_);
return conicConformalSpain.translate(iberianPeninsule.translate());
};
conicConformalSpain.translate = function(_) {
if (!arguments.length) {return iberianPeninsule.translate();}
var k = iberianPeninsule.scale(), x = +_[0], y = +_[1];
/*
var c0 = iberianPeninsule(iberianPeninsuleBbox[0]);
var x0 = (x - c0[0]) / k;
var y0 = (y - c0[1]) / k;
var c1 = iberianPeninsule(iberianPeninsuleBbox[1]);
var x1 = (x - c1[0]) / k;
var y1 = (y - c1[1]) / k;
console.info('Iberian Peninsula: p0: ' + x0 + ', ' + y0 + ' , p1: ' + x1 + ' - ' + y1);
c0 = canaryIslands.translate([x + 0.1 * k, y - 0.094 * k])(canaryIslandsBbox[0]);
x0 = (x - c0[0]) / k;
y0 = (y - c0[1]) / k;
c1 = canaryIslands.translate([x + 0.1 * k, y - 0.094 * k])(canaryIslandsBbox[1]);
x1 = (x - c1[0]) / k;
y1 = (y - c1[1]) / k;
console.info('Canry Islands: p0: ' + x0 + ', ' + y0 + ' , p1: ' + x1 + ' - ' + y1);
*/
iberianPeninsulePoint = iberianPeninsule
.translate(_)
.clipExtent([[x - 0.06857 * k, y - 0.1288 * k],[x + 0.13249 * k, y + 0.05292 * k]])
.stream(pointStream);
canaryIslandsPoint = canaryIslands
.translate([x + 0.1 * k, y - 0.094 * k])
.clipExtent([[x - 0.1331 * k + epsilon, y + 0.053457 * k + epsilon],[x - 0.0354 * k - epsilon, y + 0.08969 * k - epsilon]])
.stream(pointStream);
return conicConformalSpain;
};
conicConformalSpain.drawCompositionBorders = function(context) {
/*
console.info("CLIP EXTENT: ", canaryIslands.clipExtent());
console.info("UL BBOX:", iberianPeninsule.invert([canaryIslands.clipExtent()[0][0], canaryIslands.clipExtent()[0][1]]));
console.info("UR BBOX:", iberianPeninsule.invert([canaryIslands.clipExtent()[1][0], canaryIslands.clipExtent()[0][1]]));
console.info("LD BBOX:", iberianPeninsule.invert([canaryIslands.clipExtent()[1][0], canaryIslands.clipExtent()[1][1]]));
*/
var ulCanaryIslands = iberianPeninsule([-14.0346750522884, 34.96500729877966]);
var urCanaryIslands = iberianPeninsule([-7.4208899681602025, 35.53698899616862]);
var ldCanaryIslands = iberianPeninsule([-7.314827535125545, 33.54359498636456]);
context.moveTo(ulCanaryIslands[0], ulCanaryIslands[1]);
context.lineTo(urCanaryIslands[0], urCanaryIslands[1]);
context.lineTo(ldCanaryIslands[0], ldCanaryIslands[1]);
};
conicConformalSpain.getCompositionBorders = function() {
var context = d3Path.path();
this.drawCompositionBorders(context);
return context.toString();
};
return conicConformalSpain.scale(2700);
}
// The projections must have mutually exclusive clip regions on the sphere,
// as this will avoid emitting interleaving lines and polygons.
function multiplex$3(streams) {
var n = streams.length;
return {
point: function(x, y) { var i = -1; while (++i < n) {streams[i].point(x, y); }},
sphere: function() { var i = -1; while (++i < n) {streams[i].sphere(); }},
lineStart: function() { var i = -1; while (++i < n) {streams[i].lineStart(); }},
lineEnd: function() { var i = -1; while (++i < n) {streams[i].lineEnd(); }},
polygonStart: function() { var i = -1; while (++i < n) {streams[i].polygonStart(); }},
polygonEnd: function() { var i = -1; while (++i < n) {streams[i].polygonEnd(); }}
};
}
// A composite projection for Portugal, configured by default for 960×500.
function conicConformalPortugal() {
var cache,
cacheStream,
iberianPeninsule = d3Geo.geoConicConformal().rotate([10, -39.3]).parallels([0, 60]), iberianPeninsulePoint,
madeira = d3Geo.geoConicConformal().rotate([17, -32.7]).parallels([0, 60]), madeiraPoint,
azores = d3Geo.geoConicConformal().rotate([27.8, -38.6]).parallels([0, 60]), azoresPoint,
point, pointStream = {point: function(x, y) { point = [x, y]; }};
/*
var iberianPeninsuleBbox = [[-11, 46], [4, 34]];
var madeiraBbox = [[-17.85, 33.6], [-16, 32.02]];
var azoresBbox = [[-32, 40.529], [-23.98, 35.75]];
*/
function conicConformalPortugal(coordinates) {
var x = coordinates[0], y = coordinates[1];
return point = null,
(iberianPeninsulePoint.point(x, y), point) ||
(madeiraPoint.point(x, y), point) ||
(azoresPoint.point(x, y), point);
}
conicConformalPortugal.invert = function(coordinates) {
var k = iberianPeninsule.scale(),
t = iberianPeninsule.translate(),
x = (coordinates[0] - t[0]) / k,
y = (coordinates[1] - t[1]) / k;
/*
//How are the return values calculated:
console.info("******");
var c0 = madeira(madeiraBbox[0]);
var x0 = (c0[0] - t[0]) / k;
var y0 = (c0[1] - t[1]) / k;
console.info("p0 madeira", x0 + ' - ' + y0);
var c1 = madeira(madeiraBbox[1]);
var x1 = (c1[0] - t[0]) / k;
var y1 = (c1[1] - t[1]) / k;
console.info("p1 madeira", x1 + ' - ' + y1);
c0 = azores(azoresBbox[0]);
x0 = (c0[0] - t[0]) / k;
y0 = (c0[1] - t[1]) / k;
console.info("p0 azores", x0 + ' - ' + y0);
c1 = azores(azoresBbox[1]);
x1 = (c1[0] - t[0]) / k;
y1 = (c1[1] - t[1]) / k;
console.info("p1 azores", x1 + ' - ' + y1);
*/
return (y >= 0.0093 && y< 0.03678 && x >= -0.03875 && x < -0.0116 ? madeira
: y >= -0.0412 && y< 0.0091 && x >= -0.07782 && x < -0.01166 ? azores
: iberianPeninsule).invert(coordinates);
};
conicConformalPortugal.stream = function(stream) {
return cache && cacheStream === stream ? cache : cache = multiplex$3([iberianPeninsule.stream(cacheStream = stream), madeira.stream(stream), azores.stream(stream)]);
};
conicConformalPortugal.precision = function(_) {
if (!arguments.length) {return iberianPeninsule.precision();}
iberianPeninsule.precision(_);
madeira.precision(_);
azores.precision(_);
return conicConformalPortugal;
};
conicConformalPortugal.scale = function(_) {
if (!arguments.length) {return iberianPeninsule.scale();}
iberianPeninsule.scale(_);
madeira.scale(_);
azores.scale(_ * 0.6);
return conicConformalPortugal.translate(iberianPeninsule.translate());
};
conicConformalPortugal.translate = function(_) {
if (!arguments.length) {return iberianPeninsule.translate();}
var k = iberianPeninsule.scale(), x = +_[0], y = +_[1];
/*
var c0 = iberianPeninsule(iberianPeninsuleBbox[0]);
var x0 = (x - c0[0]) / k;
var y0 = (y - c0[1]) / k;
var c1 = iberianPeninsule(iberianPeninsuleBbox[1]);
var x1 = (x - c1[0]) / k;
var y1 = (y - c1[1]) / k;
console.info('Iberian Peninsula: p0: ' + x0 + ', ' + y0 + ' , p1: ' + x1 + ' - ' + y1);
console.info('.clipExtent([[x '+
(x0<0?'+ ':'- ') + Math.abs(x0.toFixed(4))+
' * k, y '+
(y0<0?'+ ':'- ') + Math.abs(y0.toFixed(4))+
' * k],[x '+
(x1<0?'+ ':'- ') + Math.abs(x1.toFixed(4))+
' * k, y '+
(y1<0?'+ ':'- ') + Math.abs(y1.toFixed(4))+
' * k]])');
c0 = madeira.translate([x - 0.0265 * k, y + 0.025 * k])(madeiraBbox[0]);
x0 = (x - c0[0]) / k;
y0 = (y - c0[1]) / k;
c1 = madeira.translate([x - 0.0265 * k, y + 0.025 * k])(madeiraBbox[1]);
x1 = (x - c1[0]) / k;
y1 = (y - c1[1]) / k;
console.info('Madeira: p0: ' + x0 + ', ' + y0 + ' , p1: ' + x1 + ' - ' + y1);
console.info('.clipExtent([[x '+
(x0<0?'+ ':'- ') + Math.abs(x0.toFixed(4))+
' * k + epsilon, y '+
(y0<0?'+ ':'- ') + Math.abs(y0.toFixed(4))+
' * k + epsilon],[x '+
(x1<0?'+ ':'- ') + Math.abs(x1.toFixed(4))+
' * k - epsilon, y '+
(y1<0?'+ ':'- ') + Math.abs(y1.toFixed(4))+
' * k - epsilon]])');
c0 = azores.translate([x - 0.045 * k, y + -0.02 * k])(azoresBbox[0]);
x0 = (x - c0[0]) / k;
y0 = (y - c0[1]) / k;
c1 = azores.translate([x - 0.045 * k, y + -0.02 * k])(azoresBbox[1]);
x1 = (x - c1[0]) / k;
y1 = (y - c1[1]) / k;
console.info('Azores: p0: ' + x0 + ', ' + y0 + ' , p1: ' + x1 + ' - ' + y1);
console.info('.clipExtent([[x '+
(x0<0?'+ ':'- ') + Math.abs(x0.toFixed(4))+
' * k + epsilon, y '+
(y0<0?'+ ':'- ') + Math.abs(y0.toFixed(4))+
' * k + epsilon],[x '+
(x1<0?'+ ':'- ') + Math.abs(x1.toFixed(4))+
' * k - epsilon, y '+
(y1<0?'+ ':'- ') + Math.abs(y1.toFixed(4))+
' * k - epsilon]])');
*/
iberianPeninsulePoint = iberianPeninsule
.translate(_)
.clipExtent([[x - 0.0115 * k, y - 0.1138 * k],[x +0.2105 * k, y +0.0673 * k]])
.stream(pointStream);
madeiraPoint = madeira
.translate([x - 0.0265 * k, y + 0.025 * k])
.clipExtent([[x - 0.0388 * k + epsilon, y + 0.0093 * k + epsilon],[x - 0.0116 * k - epsilon, y + 0.0368 * k - epsilon]])
.stream(pointStream);
azoresPoint = azores
.translate([x - 0.045 * k, y + -0.02 * k])
.clipExtent([[x - 0.0778 * k + epsilon, y - 0.0413 * k + epsilon],[x - 0.0117 * k - epsilon, y + 0.0091 * k - epsilon]])
.stream(pointStream);
return conicConformalPortugal;
};
conicConformalPortugal.drawCompositionBorders = function(context) {
/*
console.info("CLIP EXTENT MADEIRA: ", madeira.clipExtent());
console.info("UL BBOX:", iberianPeninsule.invert([madeira.clipExtent()[0][0], madeira.clipExtent()[0][1]]));
console.info("UR BBOX:", iberianPeninsule.invert([madeira.clipExtent()[1][0], madeira.clipExtent()[0][1]]));
console.info("LD BBOX:", iberianPeninsule.invert([madeira.clipExtent()[1][0], madeira.clipExtent()[1][1]]));
console.info("LL BBOX:", iberianPeninsule.invert([madeira.clipExtent()[0][0], madeira.clipExtent()[1][1]]));
console.info("CLIP EXTENT AZORES: ", azores.clipExtent());
console.info("UL BBOX:", iberianPeninsule.invert([azores.clipExtent()[0][0], azores.clipExtent()[0][1]]));
console.info("UR BBOX:", iberianPeninsule.invert([azores.clipExtent()[1][0], azores.clipExtent()[0][1]]));
console.info("LD BBOX:", iberianPeninsule.invert([azores.clipExtent()[1][0], azores.clipExtent()[1][1]]));
console.info("LL BBOX:", iberianPeninsule.invert([azores.clipExtent()[0][0], azores.clipExtent()[1][1]]));
*/
var ulmadeira = iberianPeninsule([-12.8351, 38.7113]);
var urmadeira = iberianPeninsule([-10.8482, 38.7633]);
var ldmadeira = iberianPeninsule([-10.8181, 37.2072]);
var llmadeira = iberianPeninsule([-12.7345, 37.1573]);
var ulazores = iberianPeninsule([-16.0753, 41.4436]);
var urazores = iberianPeninsule([-10.9168, 41.6861]);
var ldazores = iberianPeninsule([-10.8557, 38.7747]);
var llazores = iberianPeninsule([-15.6728, 38.5505]);
context.moveTo(ulmadeira[0], ulmadeira[1]);
context.lineTo(urmadeira[0], urmadeira[1]);
context.lineTo(ldmadeira[0], ldmadeira[1]);
context.lineTo(ldmadeira[0], ldmadeira[1]);
context.lineTo(llmadeira[0], llmadeira[1]);
context.closePath();
context.moveTo(ulazores[0], ulazores[1]);
context.lineTo(urazores[0], urazores[1]);
context.lineTo(ldazores[0], ldazores[1]);
context.lineTo(ldazores[0], ldazores[1]);
context.lineTo(llazores[0], llazores[1]);
context.closePath();
};
conicConformalPortugal.getCompositionBorders = function() {
var context = d3Path.path();
this.drawCompositionBorders(context);
return context.toString();
};
return conicConformalPortugal.scale(4200);
}
// The projections must have mutually exclusive clip regions on the sphere,
// as this will avoid emitting interleaving lines and polygons.
function multiplex$4(streams) {
var n = streams.length;
return {
point: function(x, y) { var i = -1; while (++i < n) {streams[i].point(x, y); }},
sphere: function() { var i = -1; while (++i < n) {streams[i].sphere(); }},
lineStart: function() { var i = -1; while (++i < n) {streams[i].lineStart(); }},
lineEnd: function() { var i = -1; while (++i < n) {streams[i].lineEnd(); }},
polygonStart: function() { var i = -1; while (++i < n) {streams[i].polygonStart(); }},
polygonEnd: function() { var i = -1; while (++i < n) {streams[i].polygonEnd(); }}
};
}
// A composite projection for Ecuador, configured by default for 960×500.
function mercatorEcuador() {
var cache,
cacheStream,
mainland = d3Geo.geoMercator().rotate([80, 1.5]), mainlandPoint,
galapagos = d3Geo.geoMercator().rotate([90.73, 1]), galapagosPoint,
point, pointStream = {point: function(x, y) { point = [x, y]; }};
/*
var mainlandBbox = [[-81.5, 2.7], [-70.0, -6.0]];
var galapagosBbox = [[-92.2, 0.58], [-88.8, -1.8]];
*/
function mercatorEcuador(coordinates) {
var x = coordinates[0], y = coordinates[1];
return point = null,
(mainlandPoint.point(x, y), point) ||
(galapagosPoint.point(x, y), point);
}
mercatorEcuador.invert = function(coordinates) {
var k = mainland.scale(),
t = mainland.translate(),
x = (coordinates[0] - t[0]) / k,
y = (coordinates[1] - t[1]) / k;
/*
//How are the return values calculated:
var c0 = galapagos(galapagosBbox[0]);
var x0 = (c0[0] - t[0]) / k;
var y0 = (c0[1] - t[1]) / k;
console.info("p0 galapagos", x0 + ' - ' + y0);
var c1 = galapagos(galapagosBbox[1]);
var x1 = (c1[0] - t[0]) / k;
var y1 = (c1[1] - t[1]) / k;
console.info("p1 galapagos", x1 + ' - ' + y1);
*/
return (y >= -0.0676 && y< -0.026 && x >= -0.0857 && x < -0.0263 ? galapagos
: mainland).invert(coordinates);
};
mercatorEcuador.stream = function(stream) {
return cache && cacheStream === stream ? cache : cache = multiplex$4([mainland.stream(cacheStream = stream), galapagos.stream(stream)]);
};
mercatorEcuador.precision = function(_) {
if (!arguments.length) {return mainland.precision();}
mainland.precision(_);
galapagos.precision(_);
return mercatorEcuador;
};
mercatorEcuador.scale = function(_) {
if (!arguments.length) {return mainland.scale();}
mainland.scale(_);
galapagos.scale(_);
return mercatorEcuador.translate(mainland.translate());
};
mercatorEcuador.translate = function(_) {
if (!arguments.length) {return mainland.translate();}
var k = mainland.scale(), x = +_[0], y = +_[1];
/*
var c0 = mainland(mainlandBbox[0]);
var x0 = (x - c0[0]) / k;
var y0 = (y - c0[1]) / k;
var c1 = mainland(mainlandBbox[1]);
var x1 = (x - c1[0]) / k;
var y1 = (y - c1[1]) / k;
console.info('mainland: p0: ' + x0 + ', ' + y0 + ' , p1: ' + x1 + ' - ' + y1);
console.info('.clipExtent([[x '+
(x0<0?'+ ':'- ') + Math.abs(x0.toFixed(4))+
' * k, y '+
(y0<0?'+ ':'- ') + Math.abs(y0.toFixed(4))+
' * k],[x '+
(x1<0?'+ ':'- ') + Math.abs(x1.toFixed(4))+
' * k, y '+
(y1<0?'+ ':'- ') + Math.abs(y1.toFixed(4))+
' * k]])');
c0 = galapagos.translate([x - 0.06 * k, y - 0.04 * k])(galapagosBbox[0]);
x0 = (x - c0[0]) / k;
y0 = (y - c0[1]) / k;
c1 = galapagos.translate([x - 0.06 * k, y - 0.04 * k])(galapagosBbox[1]);
x1 = (x - c1[0]) / k;
y1 = (y - c1[1]) / k;
console.info('galapagos: p0: ' + x0 + ', ' + y0 + ' , p1: ' + x1 + ' - ' + y1);
console.info('.clipExtent([[x '+
(x0<0?'+ ':'- ') + Math.abs(x0.toFixed(4))+
' * k + epsilon, y '+
(y0<0?'+ ':'- ') + Math.abs(y0.toFixed(4))+
' * k + epsilon],[x '+
(x1<0?'+ ':'- ') + Math.abs(x1.toFixed(4))+
' * k - epsilon, y '+
(y1<0?'+ ':'- ') + Math.abs(y1.toFixed(4))+
' * k - epsilon]])');*/
mainlandPoint = mainland
.translate(_)
.clipExtent([[x - 0.0262 * k, y - 0.0734 * k],[x + 0.1741 * k, y + 0.079 * k]])
.stream(pointStream);
galapagosPoint = galapagos
.translate([x - 0.06 * k, y - 0.04 * k])
.clipExtent([[x - 0.0857 * k + epsilon, y - 0.0676 * k + epsilon],[x - 0.0263 * k - epsilon, y - 0.026 * k - epsilon]])
.stream(pointStream);
return mercatorEcuador;
};
mercatorEcuador.drawCompositionBorders = function(context) {
/*
console.info("CLIP EXTENT: ", galapagos.clipExtent());
console.info("UL BBOX:", mainland.invert([galapagos.clipExtent()[0][0], galapagos.clipExtent()[0][1]]));
console.info("UR BBOX:", mainland.invert([galapagos.clipExtent()[1][0], galapagos.clipExtent()[0][1]]));
console.info("LD BBOX:", mainland.invert([galapagos.clipExtent()[1][0], galapagos.clipExtent()[1][1]]));
console.info("LL BBOX:", mainland.invert([galapagos.clipExtent()[0][0], galapagos.clipExtent()[1][1]]));
*/
var ulgalapagos = mainland([-84.9032, 2.3757]);
var urgalapagos = mainland([-81.5047, 2.3708]);
var ldgalapagos = mainland([-81.5063, -0.01]);
var llgalapagos = mainland([-84.9086, -0.005]);
context.moveTo(ulgalapagos[0], ulgalapagos[1]);
context.lineTo(urgalapagos[0], urgalapagos[1]);
context.lineTo(ldgalapagos[0], ldgalapagos[1]);
context.lineTo(llgalapagos[0], llgalapagos[1]);
context.closePath();
};
mercatorEcuador.getCompositionBorders = function() {
var context = d3Path.path();
this.drawCompositionBorders(context);
return context.toString();
};
return mercatorEcuador.scale(3500);
}
// The projections must have mutually exclusive clip regions on the sphere,
// as this will avoid emitting interleaving lines and polygons.
function multiplex$5(streams) {
var n = streams.length;
return {
point: function(x, y) { var i = -1; while (++i < n) {streams[i].point(x, y); }},
sphere: function() { var i = -1; while (++i < n) {streams[i].sphere(); }},
lineStart: function() { var i = -1; while (++i < n) {streams[i].lineStart(); }},
lineEnd: function() { var i = -1; while (++i < n) {streams[i].lineEnd(); }},
polygonStart: function() { var i = -1; while (++i < n) {streams[i].polygonStart(); }},
polygonEnd: function() { var i = -1; while (++i < n) {streams[i].polygonEnd(); }}
};
}
// A composite projection for Chile, configured by default for 960×500.
function transverseMercatorChile() {
var cache,
cacheStream,
mainland = d3Geo.geoTransverseMercator().rotate([72, 37]), mainlandPoint,
antarctic = d3Geo.geoStereographic().rotate([72, 0]), antarcticPoint,
juanFernandez = d3Geo.geoMercator().rotate([80, 33.5]), juanFernandezPoint,
pascua = d3Geo.geoMercator().rotate([110, 25]), pascuaPoint,
point, pointStream = {point: function(x, y) { point = [x, y]; }};
/*