Skip to content

Instantly share code, notes, and snippets.

View alansmithy's full-sized avatar

Alan Smith alansmithy

View GitHub Profile
@alansmithy
alansmithy / .block
Last active April 26, 2019 06:17
Pictogram grid in d3js
license: mit
@alansmithy
alansmithy / README.md
Last active June 21, 2019 19:39
d3js - enter(), update() and exit()

This is a simple example of enter/update/exit in d3js.

2 arrays - of differing length - are used to generate alternating sequences of bubbles.

.enter() creates the initial join of data to elements, creating one circle element for every data element in the array.

After the button is clicked, the alternative array is rejoined to the graphical elements.

Because each array is of a different length, this means we must use .exit() to remove any circle elements no longer needed and create any new circle elements by using .enter().

@alansmithy
alansmithy / README.md
Last active August 29, 2015 14:19
Using Pym.js to create a dynamic, responsive graphic

Pym.js

Pym.js by NPR is a really useful tool for deploying responsive SVG graphics.

Pym.js works by creating dynamic iframes on a (parent) page which can transmit window-size changes to an embedded (child) page. The child can also send changes back to the parent if interaction causes the embedded item to change in height. Crucially, the child page can be set to redraw its content when a window is resized, allowing different content to be generated depending on the size of the iframe.

This playful (and artistically inept) example illustrates the concept by using d3 to draw different images (a 'landscape' landscape and a 'portrait' portrait) depending on the window width. To see it properly using bl.ocks.org, you'll need to launch into the new window view - then just resize the window by dragging the window in and out (the switch happens at 600px).

You can read more about using pym.js on the NPR Blog

@alansmithy
alansmithy / README.md
Last active March 15, 2019 15:53
Heatmap Calendar in d3js

###Calendar heatmap

A calendar heatmap using a simple csv file structure of date and value. These kinds of displays are good for highlighting patterns in time series data where there might be multiple time patterns present - i.e. daily/weekly/monthly/seasonal. A great implementation of this kind of graphic is the Wisconsin crash calendar.

This particular implementation produces just one svg element with a discrete group element for every year referenced in the data set.

@alansmithy
alansmithy / index.html
Last active November 1, 2015 19:14
The Costner Effect
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<title>The Costner Effect</title>
<style>
body{font-family:sans-serif;background-color:#dedede}
#container {
width: 800px;
margin-left: auto;
@alansmithy
alansmithy / index.html
Last active November 5, 2015 18:31
'Squeezed'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Tax credit changes and the low income family</title>
<script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
<style type="text/css">
body, text{font-family:metric,sans-serif;}
h2{font-weight:500;font-size:21px;margin-bottom:-10px;}
@alansmithy
alansmithy / .block
Last active May 9, 2017 01:52
European map
license: mit
@alansmithy
alansmithy / .block
Last active May 9, 2017 01:52
A Europe of Two Halves
license: mit
@alansmithy
alansmithy / .block
Last active May 9, 2017 01:41
d3-annotation
license: mit
@alansmithy
alansmithy / .block
Last active May 12, 2017 08:29
Table
license: mit