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
Last active May 23, 2017 11:03
d3 | circle movement with voronoi overlay
var svg = d3.select('svg'),
width = +svg.attr('width'),
height = +svg.attr('height'),
radius = 32
var circles = d3.range(9).map(function () {
return {
x: Math.round(Math.random() * (width - radius * 2) + radius),
y: Math.round(Math.random() * (height - radius * 2) + radius)
}
@eesur
eesur / .script-compiled.js
Last active May 23, 2017 10:59
d3 | 1 triangle repeated
// x and y of each triangle point
var trianglePoints = [
[75, 0],
[0, 150],
[150, 150]
];
var w = +d3.select('svg').attr('width')
var h = +d3.select('svg').attr('height')
@eesur
eesur / .script-compiled.js
Last active May 23, 2017 11:01
d3 | Morphological Table 1
var data = [
{ // 0
ref: 'h1', // top horizontal line
x1: 0, y1: 0, // use 0 for start, 0.5 for midway, and 1 for end
x2: 1, y2: 0,
},
{ // 1
ref: 'h2', // mid horizontal line
x1: 0, y1: 0.5,
x2: 1, y2: 0.5,
@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 }
@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 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 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 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 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 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])