Skip to content

Instantly share code, notes, and snippets.

View eesur's full-sized avatar

Sundar Singh eesur

View GitHub Profile
@eesur
eesur / .script-compiled.js
Created July 20, 2017 16:44
d3 | disco disco
var d3 = window.d3
/* const data = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90] */
var data = d3.range(9).map(function (n) { return n * 10; })
var sqrtScale = d3.scaleSqrt()
.domain([0, 100])
.range([0, 70])
var svg = d3.select('svg')
// const width = +svg.attr('width')
@eesur
eesur / .script-compiled.js
Last active June 27, 2017 17:11
d3 | reusable circle legend
function circleLegend(selection) {
var instance = {}
// set some defaults
var api = {
domain: [0, 100], // the values min and max
range: [0, 80], // the circle area/size mapping
values: [8, 34, 89], // values for circles
width: 500,
@eesur
eesur / .script-compiled.js
Last active June 8, 2017 16:54
d3 | concentric circles
var render = (function () {
// keys for concentric circles
var dataKeys = ['studentNumber', 'femalePercentRatio', 'malePercentRatio', 'intlStudentsPercent']
// helpers
var width = 300
var height = 250
var t = d3.transition()
@eesur
eesur / .script-compiled.js
Last active December 3, 2017 16:42
d3 | ratio bar chart
var render = (function () {
var svg = d3.select('svg')
var vis = svg.select('#vis')
var width = +svg.attr('width')
var height = +svg.attr('height')
var xScale = d3.scaleLinear()
.domain([0, 100])
.range([0, width])
@eesur
eesur / .script-compiled.js
Last active May 25, 2017 18:42
d3 | object literal as data
// data is an object literal
var data = {
'key_1': 10,
'key_2': 20,
'key_3': 30,
'key_4': 40,
'key_5': 50
}
// we create a nested array of the keys and map them with the values
@eesur
eesur / .script-compiled.js
Last active December 3, 2017 15:59
d3 | proportional circle area chart
var render = (function () {
var axis = [25, 50, 75, 100]
var sqrtScale = d3.scaleSqrt()
.domain([0, 100])
.range([0, 200])
var svg = d3.select('svg')
var vis = svg.select('#vis')
var width = +svg.attr('width')
@eesur
eesur / .script-compiled.js
Last active May 22, 2017 19:43
d3 | swarm with force
function render(nodes) {
var svg = d3.select('svg')
var width = +svg.attr('width')
var height = +svg.attr('height')
var vis = svg.select('g.vis')
var axis = svg.select('g.axis')
var f = d3.format('.2f')
var xScale = d3.scaleLinear()
.domain([0, 100])
@eesur
eesur / .script-compiled.js
Last active May 22, 2017 12:42
d3 | UI for MakeyMakey and lego characters
(function() {
// connect with MakeyMakey
var body = d3.select('body')
var quote = d3.select('h1#quote')
var author = d3.select('h3#author')
// background colours for each data file
var colours = {
space: '#FDBB30',
left_arrow: '#ec008c',
@eesur
eesur / .script-compiled.js
Last active May 23, 2017 10:56
d3 | Sol LeWitt’s Wall Drawing #118 (1971)
var width = window.innerWidth
var height = window.innerHeight
var svg = d3.select('svg')
.attr('width', width)
.attr('width', height)
var g = svg.select('#vis')
// create 50 items that have x and y uniformly random
var data = d3.range(50).map(function (n) {
return {
@eesur
eesur / .script-compiled.js
Last active November 28, 2017 15:21
d3 | force grouping via events
var data = [
{ name: '01', group: 'one', value: 55 },
{ name: '02', group: 'two', value: 21 },
{ name: '03', group: 'two', value: 55 },
{ name: '04', group: 'one', value: 89 },
{ name: '05', group: 'one', value: 144 },
{ name: '06', group: 'two', value: 144 },
{ name: '07', group: 'one', value: 233 },
{ name: '08', group: 'one', value: 377 },
{ name: '09', group: 'two', value: 89 }