Permalink
Browse files

Merge branch 'capture-globals' into 3.0.6

  • Loading branch information...
2 parents e35f3a6 + 46a586d commit aab354aec2b09c5e9a32e9c8e909337c3827e4d9 @mbostock mbostock committed Feb 6, 2013
View
2 Makefile
@@ -27,10 +27,10 @@ all: \
src/end.js
d3.core.js: \
+ src/core/core.js \
src/core/format-$(LOCALE).js \
src/compat/date.js \
src/compat/style.js \
- src/core/core.js \
src/core/class.js \
src/core/array.js \
src/core/map.js \
View
72 d3.js
@@ -1,26 +1,25 @@
-(function() {
+d3 = function() {
+ var π = Math.PI, ε = 1e-6, d3 = {
+ version: "3.0.5"
+ }, d3_radians = π / 180, d3_degrees = 180 / π, d3_document = document, d3_window = window;
+ function d3_target(d) {
+ return d.target;
+ }
+ function d3_source(d) {
+ return d.source;
+ }
var d3_format_decimalPoint = ".", d3_format_thousandsSeparator = ",", d3_format_grouping = [ 3, 3 ];
if (!Date.now) Date.now = function() {
return +new Date();
};
try {
- document.createElement("div").style.setProperty("opacity", 0, "");
+ d3_document.createElement("div").style.setProperty("opacity", 0, "");
} catch (error) {
- var d3_style_prototype = CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
+ var d3_style_prototype = d3_window.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
d3_style_prototype.setProperty = function(name, value, priority) {
d3_style_setProperty.call(this, name, value + "", priority);
};
}
- d3 = {
- version: "3.0.5"
- };
- var π = Math.PI, ε = 1e-6, d3_radians = π / 180, d3_degrees = 180 / π;
- function d3_target(d) {
- return d.target;
- }
- function d3_source(d) {
- return d.source;
- }
function d3_class(ctor, properties) {
try {
for (var key in properties) {
@@ -43,7 +42,7 @@
return Array.prototype.slice.call(pseudoarray);
}
try {
- d3_array(document.documentElement.childNodes)[0].nodeType;
+ d3_array(d3_document.documentElement.childNodes)[0].nodeType;
} catch (e) {
d3_array = d3_arrayCopy;
}
@@ -395,7 +394,7 @@
return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
};
d3.xhr = function(url, mimeType, callback) {
- var xhr = {}, dispatch = d3.dispatch("progress", "load", "error"), headers = {}, response = d3_identity, request = new (window.XDomainRequest && /^(http(s)?:)?\/\//.test(url) ? XDomainRequest : XMLHttpRequest)();
+ var xhr = {}, dispatch = d3.dispatch("progress", "load", "error"), headers = {}, response = d3_identity, request = new (d3_window.XDomainRequest && /^(http(s)?:)?\/\//.test(url) ? XDomainRequest : XMLHttpRequest)();
"onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
request.readyState > 3 && respond();
};
@@ -474,8 +473,8 @@
return d3.xhr(url, "text/html", callback).response(d3_html);
};
function d3_html(request) {
- var range = document.createRange();
- range.selectNode(document.body);
+ var range = d3_document.createRange();
+ range.selectNode(d3_document.body);
return range.createContextualFragment(request.responseText);
}
d3.xml = function() {
@@ -805,7 +804,7 @@
return dispatch;
}
d3.transform = function(string) {
- var g = document.createElementNS(d3.ns.prefix.svg, "g");
+ var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
return (d3.transform = function(string) {
g.setAttribute("transform", string);
var t = g.transform.baseVal.consolidate();
@@ -1440,7 +1439,7 @@
return n.querySelector(s);
}, d3_selectAll = function(s, n) {
return n.querySelectorAll(s);
- }, d3_selectRoot = document.documentElement, d3_selectMatcher = d3_selectRoot.matchesSelector || d3_selectRoot.webkitMatchesSelector || d3_selectRoot.mozMatchesSelector || d3_selectRoot.msMatchesSelector || d3_selectRoot.oMatchesSelector, d3_selectMatches = function(n, s) {
+ }, d3_selectRoot = d3_document.documentElement, d3_selectMatcher = d3_selectRoot.matchesSelector || d3_selectRoot.webkitMatchesSelector || d3_selectRoot.mozMatchesSelector || d3_selectRoot.msMatchesSelector || d3_selectRoot.oMatchesSelector, d3_selectMatches = function(n, s) {
return d3_selectMatcher.call(n, s);
};
if (typeof Sizzle === "function") {
@@ -1592,7 +1591,7 @@
for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
return this;
}
- if (n < 2) return getComputedStyle(this.node(), null).getPropertyValue(name);
+ if (n < 2) return d3_window.getComputedStyle(this.node(), null).getPropertyValue(name);
priority = "";
}
return this.each(d3_selection_style(name, value, priority));
@@ -1654,20 +1653,20 @@
d3_selectionPrototype.append = function(name) {
name = d3.ns.qualify(name);
function append() {
- return this.appendChild(document.createElementNS(this.namespaceURI, name));
+ return this.appendChild(d3_document.createElementNS(this.namespaceURI, name));
}
function appendNS() {
- return this.appendChild(document.createElementNS(name.space, name.local));
+ return this.appendChild(d3_document.createElementNS(name.space, name.local));
}
return this.select(name.local ? appendNS : append);
};
d3_selectionPrototype.insert = function(name, before) {
name = d3.ns.qualify(name);
function insert() {
- return this.insertBefore(document.createElementNS(this.namespaceURI, name), d3_select(before, this));
+ return this.insertBefore(d3_document.createElementNS(this.namespaceURI, name), d3_select(before, this));
}
function insertNS() {
- return this.insertBefore(document.createElementNS(name.space, name.local), d3_select(before, this));
+ return this.insertBefore(d3_document.createElementNS(name.space, name.local), d3_select(before, this));
}
return this.select(name.local ? insertNS : insert);
};
@@ -1891,7 +1890,7 @@
}
return d3_transition(subgroups, id);
};
- var d3_selectionRoot = d3_selection([ [ document ] ]);
+ var d3_selectionRoot = d3_selection([ [ d3_document ] ]);
d3_selectionRoot[0].parentNode = d3_selectRoot;
d3.select = function(selector) {
return typeof selector === "string" ? d3_selectionRoot.select(selector) : d3_selection([ [ selector ] ]);
@@ -2103,7 +2102,7 @@
}
return d3_transition_tween(this, "style." + name, value, function(b) {
function styleString() {
- var a = getComputedStyle(this, null).getPropertyValue(name), i;
+ var a = d3_window.getComputedStyle(this, null).getPropertyValue(name), i;
return a !== b && (i = interpolate(a, b), function(t) {
this.style.setProperty(name, i(t), priority);
});
@@ -2114,7 +2113,7 @@
d3_transitionPrototype.styleTween = function(name, tween, priority) {
if (arguments.length < 3) priority = "";
return this.tween("style." + name, function(d, i) {
- var f = tween.call(this, d, i, getComputedStyle(this, null).getPropertyValue(name));
+ var f = tween.call(this, d, i, d3_window.getComputedStyle(this, null).getPropertyValue(name));
return f && function(t) {
this.style.setProperty(name, f(t), priority);
};
@@ -2272,19 +2271,19 @@
}
return then;
}
- var d3_timer_frame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) {
+ var d3_timer_frame = d3_window.requestAnimationFrame || d3_window.webkitRequestAnimationFrame || d3_window.mozRequestAnimationFrame || d3_window.oRequestAnimationFrame || d3_window.msRequestAnimationFrame || function(callback) {
setTimeout(callback, 17);
};
d3.mouse = function(container) {
return d3_mousePoint(container, d3_eventSource());
};
- var d3_mouse_bug44083 = /WebKit/.test(navigator.userAgent) ? -1 : 0;
+ var d3_mouse_bug44083 = /WebKit/.test(d3_window.navigator.userAgent) ? -1 : 0;
function d3_mousePoint(container, e) {
var svg = container.ownerSVGElement || container;
if (svg.createSVGPoint) {
var point = svg.createSVGPoint();
- if (d3_mouse_bug44083 < 0 && (window.scrollX || window.scrollY)) {
- svg = d3.select(document.body).append("svg").style("position", "absolute").style("top", 0).style("left", 0);
+ if (d3_mouse_bug44083 < 0 && (d3_window.scrollX || d3_window.scrollY)) {
+ svg = d3.select(d3_document.body).append("svg").style("position", "absolute").style("top", 0).style("left", 0);
var ctm = svg[0][0].getScreenCTM();
d3_mouse_bug44083 = !(ctm.f || ctm.e);
svg.remove();
@@ -3529,7 +3528,7 @@
}
function brushstart() {
var target = this, eventTarget = d3.select(d3.event.target), event_ = event.of(target, arguments), g = d3.select(target), resizing = eventTarget.datum(), resizingX = !/^(n|s)$/.test(resizing) && x, resizingY = !/^(e|w)$/.test(resizing) && y, dragging = eventTarget.classed("extent"), center, origin = mouse(), offset;
- var w = d3.select(window).on("mousemove.brush", brushmove).on("mouseup.brush", brushend).on("touchmove.brush", brushmove).on("touchend.brush", brushend).on("keydown.brush", keydown).on("keyup.brush", keyup);
+ var w = d3.select(d3_window).on("mousemove.brush", brushmove).on("mouseup.brush", brushend).on("touchmove.brush", brushmove).on("touchend.brush", brushend).on("keydown.brush", keydown).on("keyup.brush", keyup);
if (dragging) {
origin[0] = extent[0][0] - origin[0];
origin[1] = extent[0][1] - origin[1];
@@ -3716,7 +3715,7 @@
}
function mousedown() {
var target = this, event_ = event.of(target, arguments), eventTarget = d3.event.target, touchId = d3.event.touches ? d3.event.changedTouches[0].identifier : null, offset, origin_ = point(), moved = 0;
- var w = d3.select(window).on(touchId != null ? "touchmove.drag-" + touchId : "mousemove.drag", dragmove).on(touchId != null ? "touchend.drag-" + touchId : "mouseup.drag", dragend, true);
+ var w = d3.select(d3_window).on(touchId != null ? "touchmove.drag-" + touchId : "mousemove.drag", dragmove).on(touchId != null ? "touchend.drag-" + touchId : "mouseup.drag", dragend, true);
if (origin) {
offset = origin.apply(target, arguments);
offset = [ offset.x - origin_[0], offset.y - origin_[1] ];
@@ -3839,8 +3838,8 @@
});
}
function mousedown() {
- var target = this, event_ = event.of(target, arguments), eventTarget = d3.event.target, moved = 0, w = d3.select(window).on("mousemove.zoom", mousemove).on("mouseup.zoom", mouseup), l = location(d3.mouse(target));
- window.focus();
+ var target = this, event_ = event.of(target, arguments), eventTarget = d3.event.target, moved = 0, w = d3.select(d3_window).on("mousemove.zoom", mousemove).on("mouseup.zoom", mouseup), l = location(d3.mouse(target));
+ d3_window.focus();
d3_eventCancel();
function mousemove() {
moved = 1;
@@ -7798,4 +7797,5 @@
d3.time.scale.utc = function() {
return d3_time_scale(d3.scale.linear(), d3_time_scaleUTCMethods, d3_time_scaleUTCFormat);
};
-})();
+ return d3;
+}();
View
8 d3.min.js
4 additions, 4 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
10 globals.js
@@ -1,11 +1,9 @@
var document = global.document = require("jsdom").jsdom("<html><head></head><body></body></html>"),
- window = global.window = document.createWindow(),
- navigator = global.navigator = window.navigator,
- getComputedStyle = global.getComputedStyle = window.getComputedStyle,
- CSSStyleDeclaration = global.CSSStyleDeclaration = window.CSSStyleDeclaration;
+ window = global.window = document.createWindow();
// https://github.com/chad3814/CSSStyleDeclaration/issues/3
-var CSSStyleDeclaration_setProperty = CSSStyleDeclaration.prototype.setProperty;
-CSSStyleDeclaration.prototype.setProperty = function(name, value, priority) {
+var CSSStyleDeclaration_prototype = window.CSSStyleDeclaration.prototype,
+ CSSStyleDeclaration_setProperty = CSSStyleDeclaration_prototype.setProperty;
+CSSStyleDeclaration_prototype.setProperty = function(name, value, priority) {
return CSSStyleDeclaration_setProperty.call(this, name + "", value == null ? null : value + "", priority == null ? null : priority + "");
};
View
2 index.js
@@ -1,4 +1,4 @@
-var globals = ["document", "window", "navigator", "CSSStyleDeclaration", "getComputedStyle", "d3"],
+var globals = ["document", "window", "d3"],
globalValues = {};
globals.forEach(function(g) {
View
2 src/behavior/drag.js
@@ -16,7 +16,7 @@ d3.behavior.drag = function() {
origin_ = point(),
moved = 0;
- var w = d3.select(window)
+ var w = d3.select(d3_window)
.on(touchId != null ? "touchmove.drag-" + touchId : "mousemove.drag", dragmove)
.on(touchId != null ? "touchend.drag-" + touchId : "mouseup.drag", dragend, true);
View
4 src/behavior/zoom.js
@@ -95,10 +95,10 @@ d3.behavior.zoom = function() {
event_ = event.of(target, arguments),
eventTarget = d3.event.target,
moved = 0,
- w = d3.select(window).on("mousemove.zoom", mousemove).on("mouseup.zoom", mouseup),
+ w = d3.select(d3_window).on("mousemove.zoom", mousemove).on("mouseup.zoom", mouseup),
l = location(d3.mouse(target));
- window.focus();
+ d3_window.focus();
d3_eventCancel();
function mousemove() {
View
4 src/compat/style.js
@@ -1,7 +1,7 @@
try {
- document.createElement("div").style.setProperty("opacity", 0, "");
+ d3_document.createElement("div").style.setProperty("opacity", 0, "");
} catch (error) {
- var d3_style_prototype = CSSStyleDeclaration.prototype,
+ var d3_style_prototype = d3_window.CSSStyleDeclaration.prototype,
d3_style_setProperty = d3_style_prototype.setProperty;
d3_style_prototype.setProperty = function(name, value, priority) {
d3_style_setProperty.call(this, name, value + "", priority);
View
4 src/component.js
@@ -1,6 +1,6 @@
-require("./core/core");
+var d3 = require("../index");
-require("util").puts(JSON.stringify({
+console.log(JSON.stringify({
"name": "d3",
"version": d3.version,
"main": "./d3.js"
View
2 src/core/array.js
@@ -11,7 +11,7 @@ function d3_arraySlice(pseudoarray) {
}
try {
- d3_array(document.documentElement.childNodes)[0].nodeType;
+ d3_array(d3_document.documentElement.childNodes)[0].nodeType;
} catch(e) {
d3_array = d3_arrayCopy;
}
View
7 src/core/core.js
@@ -1,9 +1,10 @@
-d3 = {version: "3.0.5"}; // semver
-
var π = Math.PI,
ε = 1e-6,
+ d3 = {version: "3.0.5"}, // semver
d3_radians = π / 180,
- d3_degrees = 180 / π;
+ d3_degrees = 180 / π,
+ d3_document = document,
+ d3_window = window;
function d3_target(d) {
return d.target;
View
4 src/core/html.js
@@ -3,7 +3,7 @@ d3.html = function(url, callback) {
};
function d3_html(request) {
- var range = document.createRange();
- range.selectNode(document.body);
+ var range = d3_document.createRange();
+ range.selectNode(d3_document.body);
return range.createContextualFragment(request.responseText);
}
View
7 src/core/mouse.js
@@ -3,15 +3,14 @@ d3.mouse = function(container) {
};
// https://bugs.webkit.org/show_bug.cgi?id=44083
-var d3_mouse_bug44083 = /WebKit/.test(navigator.userAgent) ? -1 : 0;
+var d3_mouse_bug44083 = /WebKit/.test(d3_window.navigator.userAgent) ? -1 : 0;
function d3_mousePoint(container, e) {
var svg = container.ownerSVGElement || container;
if (svg.createSVGPoint) {
var point = svg.createSVGPoint();
- if (d3_mouse_bug44083 < 0 && (window.scrollX || window.scrollY)) {
- svg = d3.select(document.body)
- .append("svg")
+ if (d3_mouse_bug44083 < 0 && (d3_window.scrollX || d3_window.scrollY)) {
+ svg = d3.select(d3_document.body).append("svg")
.style("position", "absolute")
.style("top", 0)
.style("left", 0);
View
4 src/core/selection-append.js
@@ -4,11 +4,11 @@ d3_selectionPrototype.append = function(name) {
name = d3.ns.qualify(name);
function append() {
- return this.appendChild(document.createElementNS(this.namespaceURI, name));
+ return this.appendChild(d3_document.createElementNS(this.namespaceURI, name));
}
function appendNS() {
- return this.appendChild(document.createElementNS(name.space, name.local));
+ return this.appendChild(d3_document.createElementNS(name.space, name.local));
}
return this.select(name.local ? appendNS : append);
View
4 src/core/selection-insert.js
@@ -6,13 +6,13 @@ d3_selectionPrototype.insert = function(name, before) {
function insert() {
return this.insertBefore(
- document.createElementNS(this.namespaceURI, name),
+ d3_document.createElementNS(this.namespaceURI, name),
d3_select(before, this));
}
function insertNS() {
return this.insertBefore(
- document.createElementNS(name.space, name.local),
+ d3_document.createElementNS(name.space, name.local),
d3_select(before, this));
}
View
2 src/core/selection-root.js
@@ -1,4 +1,4 @@
-var d3_selectionRoot = d3_selection([[document]]);
+var d3_selectionRoot = d3_selection([[d3_document]]);
d3_selectionRoot[0].parentNode = d3_selectRoot;
View
2 src/core/selection-style.js
@@ -13,7 +13,7 @@ d3_selectionPrototype.style = function(name, value, priority) {
}
// For style(string), return the computed style value for the first node.
- if (n < 2) return getComputedStyle(this.node(), null).getPropertyValue(name);
+ if (n < 2) return d3_window.getComputedStyle(this.node(), null).getPropertyValue(name);
// For style(string, string) or style(string, function), use the default
// priority. The priority is ignored for style(string, null).
View
2 src/core/selection.js
@@ -5,7 +5,7 @@ function d3_selection(groups) {
var d3_select = function(s, n) { return n.querySelector(s); },
d3_selectAll = function(s, n) { return n.querySelectorAll(s); },
- d3_selectRoot = document.documentElement,
+ d3_selectRoot = d3_document.documentElement,
d3_selectMatcher = d3_selectRoot.matchesSelector || d3_selectRoot.webkitMatchesSelector || d3_selectRoot.mozMatchesSelector || d3_selectRoot.msMatchesSelector || d3_selectRoot.oMatchesSelector,
d3_selectMatches = function(n, s) { return d3_selectMatcher.call(n, s); };
View
10 src/core/timer.js
@@ -90,9 +90,9 @@ function d3_timer_flush() {
return then;
}
-var d3_timer_frame = window.requestAnimationFrame
- || window.webkitRequestAnimationFrame
- || window.mozRequestAnimationFrame
- || window.oRequestAnimationFrame
- || window.msRequestAnimationFrame
+var d3_timer_frame = d3_window.requestAnimationFrame
+ || d3_window.webkitRequestAnimationFrame
+ || d3_window.mozRequestAnimationFrame
+ || d3_window.oRequestAnimationFrame
+ || d3_window.msRequestAnimationFrame
|| function(callback) { setTimeout(callback, 17); };
View
2 src/core/transform.js
@@ -1,5 +1,5 @@
d3.transform = function(string) {
- var g = document.createElementNS(d3.ns.prefix.svg, "g");
+ var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
return (d3.transform = function(string) {
g.setAttribute("transform", string);
var t = g.transform.baseVal.consolidate();
View
4 src/core/transition-style.js
@@ -31,7 +31,7 @@ d3_transitionPrototype.style = function(name, value, priority) {
// For style(name, string) or style(name, string, priority), set the style
// property with the specified name, using the specified priority.
function styleString() {
- var a = getComputedStyle(this, null).getPropertyValue(name), i;
+ var a = d3_window.getComputedStyle(this, null).getPropertyValue(name), i;
return a !== b && (i = interpolate(a, b), function(t) { this.style.setProperty(name, i(t), priority); });
}
@@ -43,7 +43,7 @@ d3_transitionPrototype.style = function(name, value, priority) {
d3_transitionPrototype.styleTween = function(name, tween, priority) {
if (arguments.length < 3) priority = "";
return this.tween("style." + name, function(d, i) {
- var f = tween.call(this, d, i, getComputedStyle(this, null).getPropertyValue(name));
+ var f = tween.call(this, d, i, d3_window.getComputedStyle(this, null).getPropertyValue(name));
return f && function(t) { this.style.setProperty(name, f(t), priority); };
});
};
View
2 src/core/xhr.js
@@ -3,7 +3,7 @@ d3.xhr = function(url, mimeType, callback) {
dispatch = d3.dispatch("progress", "load", "error"),
headers = {},
response = d3_identity,
- request = new (window.XDomainRequest && /^(http(s)?:)?\/\//.test(url) ? XDomainRequest : XMLHttpRequest);
+ request = new (d3_window.XDomainRequest && /^(http(s)?:)?\/\//.test(url) ? XDomainRequest : XMLHttpRequest);
"onload" in request
? request.onload = request.onerror = respond
View
2 src/end.js
@@ -1 +1 @@
-})();
+return d3;})();
View
4 src/package.js
@@ -1,6 +1,6 @@
-require("./core/core");
+var d3 = require("../index");
-require("util").puts(JSON.stringify({
+console.log(JSON.stringify({
"name": "d3",
"version": d3.version,
"description": "A small, free JavaScript library for manipulating documents based on data.",
View
2 src/start.js
@@ -1 +1 @@
-(function(){
+d3 = (function(){
View
2 src/svg/brush.js
@@ -93,7 +93,7 @@ d3.svg.brush = function() {
origin = mouse(),
offset;
- var w = d3.select(window)
+ var w = d3.select(d3_window)
.on("mousemove.brush", brushmove)
.on("mouseup.brush", brushend)
.on("touchmove.brush", brushmove)

0 comments on commit aab354a

Please sign in to comment.