Skip to content

Instantly share code, notes, and snippets.

View KevinRourke's full-sized avatar

Kevinr KevinRourke

  • Fast Action Data
  • Los Angeles, CA
View GitHub Profile
@KevinRourke
KevinRourke / README.md
Last active March 15, 2016 02:47
progressBarManager
@KevinRourke
KevinRourke / README.md
Created December 10, 2015 09:39
Bar Chart with Negative Values

Say your dataset is an array of numbers, and includes both positive and negative values. Use two scales to construct the bar chart: a quantitative scale (such as a [linear scale][1]) to compute the bar positions along the x-axis, and an [ordinal scale][2] with rangeBands to compute the bar positions along the y-axis.

For the quantitative scale, compute the data domain (the minimum and maximum value) using [d3.extent][3]:

var x = d3.scale.linear()
    .domain(d3.extent(data, function(d) { return d.value; }))
    .range([0, width]);

[Nicing][4] the scale will extend the extent slightly to the nearest round numbers. If you want the zero-value to be centered in the middle of the canvas, take the greater of the minimum and maximum value by magnitude, or simply hard-code the desired domain.

@KevinRourke
KevinRourke / README.md
Created December 10, 2015 09:26
Chord diagram showing co-occurrences.