Skip to content

Instantly share code, notes, and snippets.

@emilyinamillion
emilyinamillion / .block
Last active June 22, 2016 05:41
Line Chart
license: gpl-3.0
@emilyinamillion
emilyinamillion / README.md
Created June 21, 2016 23:36
Local Variables

It’s often desirable when using D3 to define local behavior, that is, behavior that is specific to an individual element, rather than the same for all elements in a selection. The simplest example of this is passing a function to selection.attr to compute an attribute value for each element.

But what happens if your local behavior is more complicated? What if you want multiple operations (multiple attributes, or elements) to have local behavior, but still share local state between them? For instance, when rendering small multiples of time-series data, you might want the same x-scale for all charts but distinct y-scales to compare the relative (not absolute) performance of each metric.

There are several ways to do this in D3:

  1. Make the y-scale global, but set the domain on the y-scale before use. (Example.)

  2. Use selection.each to create a local con

@emilyinamillion
emilyinamillion / README.md
Created June 12, 2016 00:45
Isometric "treemap"

A treemap algorithm is used to area-encode an array of random values, while an isometric projection is used to length-encode a second random value. Occlusion is extremely limited by the ordering of the treemap algorithm, making the diagram fairly readable (compare with a bar chart example that does not exhibit this property). This is possible because parallelepipedons are drawn by following the same ordering used by the treemap (to be honest, we tried and succedeed in using this method, but we are not aware of the internals of the treemap ordering algorithm that makes this possible).

An interaction tecnique is also put into place to let users focus on specific parallelepipedons by making the other ones translucent. This can be used to better evaluate their height. Because there are no fully occluded parallelepipedons, there is always a way to select a specific one.

Implementation note: we formerly used z as the name for the z axis, but this conflicted with

license: gpl-3.0
@emilyinamillion
emilyinamillion / .block
Last active June 11, 2016 19:09
Stacked-to-Multiples
license: gpl-3.0
@emilyinamillion
emilyinamillion / .block
Last active June 3, 2016 04:00
Rez-weapon-Packing
license: gpl-3.0
height: 960
border: no
@emilyinamillion
emilyinamillion / .block
Created May 23, 2016 23:06
Stacked Bar Chart
license: gpl-3.0
@emilyinamillion
emilyinamillion / README.md
Created May 22, 2016 22:05
Show / hide elements on mouse click with d3.js

This is a relativly straight forward graph with two lines. Each line and it's corresponding Y axis can be toggled on and off by clicking on the text labels at the bottom of the graph.

This example is based on the explanation given by 'mdml' in response to a Stack Overflow question on showing and hiding links and nodes.

It is used as an example of showing and hiding an element in d3.js using a separate element and described in the book D3 Tips and Tricks which can be downloaded for free from Leanpub.

forked from d3noob's block: Show / hide elements on mouse click with d3.js

@emilyinamillion
emilyinamillion / .block
Last active May 20, 2016 21:08
Stacked Bar Chart
license: gpl-3.0
height: 500
border: yes