Skip to content

Instantly share code, notes, and snippets.

View alansmithy's full-sized avatar

Alan Smith alansmithy

View GitHub Profile
@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 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 / .block
Last active April 26, 2019 06:17
Pictogram grid in d3js
license: mit