Skip to content

Instantly share code, notes, and snippets.

View mstanaland's full-sized avatar

Michael Stanaland mstanaland

View GitHub Profile
@mstanaland
mstanaland / README.md
Last active January 16, 2020 09:37
Formatting numbers with d3

Examples of commonly used number transformations using d3.format. Includes:

  • comma separator for large numbers
  • fixed decimal places
  • comma separator and fixed decimal places
  • abbreviation using unit suffix
  • dollars with commas and decimals
  • percent
@mstanaland
mstanaland / README.md
Last active June 15, 2020 05:34
Stacked bar chart with tooltips

A simple stacked coloumn graph built using d3's stack layout.

The SVG tooltip is based on this gist by Mike Bostock. In short, the tooltip's group, comprised of a rect and a text element, are created when the chart is first drawn and set to be hidden. Action is applied to the stacks' rects: on mouseover the group become visible; on mousemove the mouse's XY position is captured and used to transform/translate the group.

If you ajust the tooltip's XY offset, keep in mind that there can be no overlap between the group and the mouse's position or the group's visibility will remain hidden.