Skip to content

Instantly share code, notes, and snippets.

Avatar

Mike Bostock mbostock

View GitHub Profile
@mbostock
mbostock / base64.js
Created July 27, 2010 12:28
Base64.js
View base64.js
function encode(s) {
var c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
o = [];
for (var i = 0, n = s.length; i < n;) {
var c1 = s.charCodeAt(i++),
c2 = s.charCodeAt(i++),
c3 = s.charCodeAt(i++);
o.push(c.charAt(c1 >> 2));
o.push(c.charAt(((c1 & 3) << 4) | (c2 >> 4)));
o.push(c.charAt(i < n + 2 ? ((c2 & 15) << 2) | (c3 >> 6) : 64));
@mbostock
mbostock / perlin-worker.js
Created August 20, 2010 04:19
Polymaps / Procedural Perlin
View perlin-worker.js
onmessage = function(e) {
var data = e.data.data = [],
n = Math.pow(2, 7 - e.data.zoom),
x0 = e.data.column * n,
y0 = e.data.row * n,
w = e.data.size.x,
h = e.data.size.y;
for (var y = 0, i = 0; y < h; y++) {
for (var x = 0; x < w; x++) {
@mbostock
mbostock / app.yaml
Created August 26, 2010 05:05
polymaps.appspot.com
View app.yaml
application: polymaps
version: 1
runtime: python
api_version: 1
handlers:
- url: /state/.*
script: main.py
- url: /county/.*
@mbostock
mbostock / jsonp.diff
Created August 31, 2010 05:32
Polymaps / JSONP Queue
View jsonp.diff
diff --git a/src/Queue.js b/src/Queue.js
index d243c13..616dbc6 100644
--- a/src/Queue.js
+++ b/src/Queue.js
@@ -99,5 +99,41 @@ po.queue = (function() {
return {abort: abort};
}
- return {text: text, xml: xml, json: json, image: image};
+ function jsonp(src, callback) {
View gist:619560
git remote add mbostock git@github.com:mbostock/polymaps.git
git fetch mbostock
git merge --no-commit --no-ff mbostock/master
mate -w src/start.js
make
git add .
git commit
@mbostock
mbostock / gist:672899
Created November 11, 2010 17:55
Fast Pointing
View gist:672899
<html>
<head>
<title>Pointing</title>
<script type="text/javascript" src="http://github.com/mbostock/protovis/raw/v3.3.1/protovis.js"></script>
<style type="text/css">
#fig {
width: 450px;
height: 425px;
}
@mbostock
mbostock / transition-end.js
Created August 25, 2011 18:24
Transition End
View transition-end.js
d3_transitionPrototype.end = function() {
var subgroups = [],
subgroup,
subnode,
node;
for (var j = -1, m = this.length; ++j < m;) {
subgroups.push(subgroup = []);
for (var group = this[j], i = -1, n = group.length; ++i < n;) {
if (node = group[i]) {
@mbostock
mbostock / pie.js
Created November 14, 2011 16:09
Prototype Chart Template (WIP)
View pie.js
d3.mbostock.pie = function() {
var pie = {},
parent,
data;
var svg = d3.create("svg:svg");
function redraw() {
return pie;
}
@mbostock
mbostock / adopt.diff
Created November 14, 2011 21:45
d3.create + selection.adopt
View adopt.diff
diff --git a/src/core/create.js b/src/core/create.js
new file mode 100644
index 0000000..a284a67
--- /dev/null
+++ b/src/core/create.js
@@ -0,0 +1,5 @@
+d3.create = function(name) {
+ return d3.select((name = d3.ns.qualify(name)).local
+ ? document.createElementNS(name.space, name.local)
+ : document.createElement(name));
@mbostock
mbostock / dabblet.css
Created January 1, 2012 20:10
The first commented line is your dabblet’s title
View dabblet.css
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height:100%;