Skip to content

Instantly share code, notes, and snippets.

@drzax
drzax / README.md
Created January 25, 2016 10:41 — forked from eesur/README.md
d3 | Reusable slopegraph

Reusable slopegraph inspired/adapted from Ben Van Dyke's example into a reusable chart.

This slopegraph example shows the number of personal computers installed in a country per household. This includes desktop PCs and laptops, but excludes smartphones and terminals connected to mainframe computers. All figures are calculated using total number of Personal Computers and the Total Number of Households.

data source

@drzax
drzax / elements.js
Created December 18, 2015 00:41
Javascript arrays
var elements = [
'Hydrogen',
'Helium',
'Lithium',
'Beryllium',
'Boron',
'Carbon',
'Nitrogen',
'Oxygen',
'Fluorine',
module.exports = function template(tmpl, data){
return tmpl.replace(/\{(\w*)\}/g,function(m,key){return data.hasOwnProperty(key)?data[key]:"";});
};

I can recommend some general d3 resources I've found helpful (some of which you've probably already found, if you've been looking).

For a real step-by-step, the series of tutorials by Scott Murray look quite good, though I've not done them myself. I have done a MOOC with Scott as an instructor and I can vouch for his teaching skills. I think they'd be very useful for someone very new to HTML/CSS/JS (I'm not sure if that describes you) who also wants to start with d3 at the same time.

If you want to dive right in, I'd start on Thinking with Joins and How Selections Work, and for a practical example of those concepts, check out the General Update Pattern examples (one, [two](https://www

@drzax
drzax / index.html
Created September 16, 2015 11:57
Data Viz - Module 2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3 with HTML Elements</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.js"></script>
</head>
<body>
<h1>Exercises for Module 2</h1>
@drzax
drzax / qualify.js
Created September 9, 2015 01:42
Qualify a URL in javascript. That is, convert a relative URL to an absolute URL
function qualifyURL(url) {
var a = document.createElement('a');
a.href = url;
return a.href;
}
@drzax
drzax / formatTime.js
Created August 28, 2015 06:17
A quick 12 hour time date formatter for javascript
function formatTime(date) {
var hrs = date.getHours();
return ((hrs + 11) % 12) + 1 + ':' + ("0"+date.getMinutes()).substr(-2,2) + ((hrs > 11) ? 'pm' : 'am');
}
We can't make this file beautiful and searchable because it's too large.
unixtime,track name,artist name
1141622472,Star Dusting,The Mountain Goats
1141622648,Corpus Christi Carol,Jeff Buckley
1141622841,Best Imitation Of Myself (Nyc 6/13/02 Roseland Ballroom),Ben Folds
1141623006,Wicked Annabella,The Kinks
1141623305,Father Lucifer,Tori Amos
1141623991,Go Ahead,Rilo Kiley
1141624400,Unison,Björk
1141624714,Hyperspeed (G-Force Part 2),The Prodigy
1141624974,It's Summertime,The Flaming Lips
@drzax
drzax / data.csv
Created August 24, 2015 05:12
data! from editdata.org!
time name
10 Simon
@drzax
drzax / monitor.sh
Created July 9, 2015 02:55
Quick and dirty site change monitoring
#!/bin/bash
while [ 1=1 ]; do
wget seattletimes.com -O st.html
git commit -a -m "Registered update"
sleep 600
done