An example that creates orbit paths and uses animateMotion to move several circles on those orbits. The code switches between plain JavaScript/Web API and d3 because I started out doing it in plain JS, then started using d3 to get over the namespace problems. Now that I've done that, it makes sense to do it all the d3 way, with data definitions of the 'planets' and enter/exit, but I gotta leave this for now.
#!/bin/bash | |
# Mails whatever it gets from stdin. | |
to="you@your.org" | |
subject="Something is happening on $HOSTNAME" | |
body="The first line of the email body.\n"; | |
while read -r line; do | |
[[ $line = \#* ]] && continue | |
body="$body$line\n" |
#!/bin/sh | |
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000 |
var mutationObserver = new MutationObserver( | |
function respondToMutation(mutations, observer) { | |
if (mutations.length < 1 || mutations[0].addedNodes.length !== 1) { | |
alert('Could not load a player to play the videos. Sorry.'); | |
} | |
else { | |
// Do a thing! | |
} | |
} | |
); |
function pluck(array, property) { | |
var plucked = []; | |
for (var i = 0; i < array.length; ++i) { | |
plucked.push(array[i][property]); | |
} | |
return plucked; | |
} |
var isMobileMediaQuery = 'only screen and (max-device-height: 568px)'; | |
if (window.matchMedia(isMobileMediaQuery).matches) { | |
transformString += ('rotate(' + | |
(textPaneIsHidden ? '90deg' : '-90deg') + ') '); | |
} |
// Adds a script tag using the given TypeKit url. When the TypeKit script | |
// arrives, it loads the TypeKit and calls the callback. | |
function loadATypeKit(typekitURL, done) { | |
var head = d3.select('head'); | |
var typekitScript = head.append('script').attr({ | |
type: 'text/javascript', | |
src: typekitURL | |
}); |
This example, using satirical data from The Onion, demonstrates how to wrap long axis labels to fit on multiple lines.
Update (jimkang): Added a data accessor function as a parameter to mbostock's wrap() so that it can fetch the text from the data source rather than using text().
The problem with text() is that it is built on textContent which "returns the text content of this node and its descendants." If a text element has several tspan descendants, it joins their contents without spaces. e.g. a text element with three tspans each containing 'why', 'are', and 'we' will give back 'whyarewe' through text(). The rest of wrap will proceed to treat that as one word, naturally.
This becomes an issue when wrap() is called multiple times on text elements that have already been processed by wrap().
function flattenTreeDepthFirst(rootNode) { | |
var nodes = [rootNode]; | |
var childArraysQueue = []; | |
if (rootNode.children) { | |
childArraysQueue.push(rootNode.children); | |
} | |
while (childArraysQueue.length > 0) { | |
var children = childArraysQueue[0]; |
NodeList.prototype.forEach = function nodeListEach(callback, thisArg) { | |
for (var i = 0; i < this.length; ++i) { | |
var value = this[i]; | |
if (thisArg) { | |
callback.bind(thisArg)(value, i, this); | |
} | |
else { | |
callback(value, i, this); | |
} | |
} |