Skip to content

Instantly share code, notes, and snippets.

View emmasaunders's full-sized avatar

Emma Saunders emmasaunders

  • London, UK
View GitHub Profile
@emmasaunders
emmasaunders / readme.md
Last active May 12, 2016 10:23
Making a d3 block

##Explanation Anyone can share their d3 creations on bl.ocks.org. This page explains how to do it. These instructions are mainly for people who want to display thumbnail images on their block (which is the hard part of creating a d3 block). The instructions are going to be most accurate for those using a mac, who have used terminal before (and downloaded various libraries) but who are generally unfamiliar with the terminal app and git commands. Hope it helps!

##Instructions

  1. Create an account, if required, at https://gist.github.com/. If graphic width is set in absolute terms to be greater than 960 x 500px, you might need to make it smaller. (100% width and 100% height that end up being larger than these dimensions is fine.)
  2. Go to your personal page eg https://gist.github.com/emmasaunders. Click New gist. Type in gist description.
  3. Type in index.html and copy and paste the contents of the page you are trying to re-create (which is p
@emmasaunders
emmasaunders / d3Functions.json
Last active August 6, 2016 17:51
d3 commands (v3)
{
"name": "d3",
"children": [
{
"name": "svg",
"children": [
{"name":"axis"},
{ "name":"line", "children": [{"name":"radial"}]},
{ "name":"area", "children": [{"name":"radial"}] },
@emmasaunders
emmasaunders / index.html
Last active August 6, 2016 17:51
d3 svg text alignment (v3)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>SVG text alignment using d3.js</title>
<script type="text/javascript" src="https://d3js.org/d3.v3.min.js"></script>
<style>
html, body {
margin: 0;
@emmasaunders
emmasaunders / axis.js
Last active August 6, 2016 17:51
d3 axis (v3)
var chartWidth = 300;
var chartHeight = 50;
var stringDates = ['1/1/2003', '2/1/2003', '3/1/2003', '4/1/2003', '5/1/2003', '6/1/2003'];
var parseDate = d3.time.format("%m/%d/%Y").parse;
var a = d3.scale.ordinal().domain(['Apples','Oranges','Pears','Plums']).rangePoints([0,chartWidth]);
var b = d3.scale.ordinal().domain([1, 2, 3, 4]).rangePoints([0, chartWidth]);
var c = d3.scale.ordinal().domain([1, 2, 3, 4]).rangePoints([0, chartWidth], 1);
var d = d3.scale.ordinal().domain([1, 2, 3, 4]).rangeRoundBands([0, chartWidth]);
@emmasaunders
emmasaunders / index.html
Last active August 6, 2016 17:52
d3 interpolate (v3)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Interpolation methods in d3.js</title>
<script type="text/javascript" src="https://d3js.org/d3.v2.js"></script>
@emmasaunders
emmasaunders / flow.json
Last active August 6, 2016 17:52
Tree diagram (v3)
{
"name": "Oil, gas, coal",
"children": [
{
"name": "Ethylene",
"children": [
{"name":"LDPE", "children": [{ "name":"Food packaging, film, rubbish bags, nappies, toys, housewares","class":"last"}]},
{"name":"LLDPE", "children": [{ "name":"Food packaging, film, rubbish bags, nappies, toys, housewares", "class":"last"}]},
{"name":"HDPE", "children": [{ "name":"Drums, crates, housewares, bottles, food containers", "class":"last"}]},
@emmasaunders
emmasaunders / index.html
Last active August 6, 2016 17:52
Spiral calendar (v3)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Calendar spiral in d3.js</title>
<script type="text/javascript" src="https://d3js.org/d3.v3.min.js"></script>
<style>
body {
font-family: 'Helvetica', sans-serif;
margin: 0px;
@emmasaunders
emmasaunders / index.html
Last active October 19, 2016 14:24
Line chart from csv (v3)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Line chart from CSV using d3.js</title>
<script type="text/javascript" src="https://d3js.org/d3.v3.min.js"></script>
<style>
html, body {
margin: 0;
@emmasaunders
emmasaunders / index.html
Last active October 19, 2016 14:34
d3 color scales & colorbrewer (v3)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>D3 and colorbrewer color ranges in d3.js</title>
<script type="text/javascript" src="https://d3js.org/d3.v3.min.js"></script>
<script src="http://colorbrewer2.org/export/colorbrewer.js"></script>
<style>
html, body {
@emmasaunders
emmasaunders / d3Functions.json
Last active October 20, 2016 10:23
Tree (v4)
{
"name": "d3",
"children": [
{
"name": "svg",
"children": [
{"name":"axis"},
{ "name":"line", "children": [{"name":"radial"}]},
{ "name":"area", "children": [{"name":"radial"}] },