Skip to content

Instantly share code, notes, and snippets.

function updateWindow(){
x = w.innerWidth || e.clientWidth || g.clientWidth;
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
svg.attr("width", x).attr("height", y);
}
window.onresize = updateWindow;
//SHADOW
// filter chain comes from:
// https://github.com/wbzyl/d3-notes/blob/master/hello-drop-shadow.html
// cpbotha added explanatory comments
// read more about SVG filter effects here: http://www.w3.org/TR/SVG/filters.html
// filters go in defs element
var defs = svg.append("defs");
// create filter with id #drop-shadow
@johsh
johsh / gist:dbbd38dc553efc683d7f
Created June 25, 2014 12:36
simple getDistance
function getDistance(p1, p2) {
return Math.sqrt(squared(p1.x-p2.x) + squared(p1.y-p2.y));
}
function squared(x){
return x*x;
}
@johsh
johsh / d3 - moveToFront
Created March 18, 2014 20:58
d3 - moveToFront
//define globally
d3.selection.prototype.moveToFront = function() {
return this.each(function(){
this.parentNode.appendChild(this);
});
};
//set locally in respective elements
var sel = d3.select(this);
@johsh
johsh / python server
Created March 14, 2014 14:41
py, run simple python server
python -m SimpleHTTPServer 8888
@johsh
johsh / intersect_safe
Created March 14, 2014 14:12
js, intersects two arrays in an efficient way, without destroying them
/* finds the intersection of
* two arrays in a simple fashion.
*
* PARAMS
* a - first array, must already be sorted
* b - second array, must already be sorted
*
* NOTES
*
* Should have O(n) operations, where n is
@johsh
johsh / replaceAll
Created March 14, 2014 14:11
js, replaceAll instead of replace (first)
//find = this has to be replaced...
//replace = with that str
//str = in this str, please
function replaceAll(find, replace, str) {
return str.replace(new RegExp(find, 'g'), replace);
}