Skip to main content
100%

Zoomable Treemap Bar Chart

✓ Published0🌍 Public
TThanaporn-sk
Last edited Oct 30, 2019
Created on Oct 30, 2019

This zoomable treemap bar chart visualizes U.S. trade imports and exports from 1995 onward, with each year split into two bars for import and export values. Clicking a country zooms into its trade data, while a checkbox toggles between raw and inflation-adjusted figures. The visualization uses D3 v4’s `d3.hierarchy`, `d3.treemap`, `d3.scaleBand`, and `d3.axisBottom` to render SVG rectangles and axes, with transitions animating the zoom. Data comes from the U.S. Census Bureau’s foreign trade balance records.

AI-generated description

Block-a-Day #12. Update of Treemap Bar Chart to enable zooming into a specific country on click.

Data Sources: Census

What I Learned: In a bit of treemap implementation trivia, nodes without a parent value of zero (i.e. those in a different continent than the selected country) will have NaN for their position values, as a result of a divide by zero, while those with a parent value but no value of their own will have position values, although width and height of, obviously, zero. I was originally just catching the NaNs, but this resulted in nodes flying to two different positions, thus the checking of d.value to determine how to position the nodes.

What I'd Do With More Time: Might be interesting if the transition was to vertically expand and fade the non-selected countries, to reinforce the idea of zooming in.

Block-a-Day

Just what it sounds like. For fifteen days, I will make a D3.js v4 block every single day. Rules:

  1. Ideas over implementation. Do something novel, don't sweat the details.
  2. No more than two hours can be spent on coding (give or take).
  3. Every. Single. Day.

Previously

forked from <a href='http://bl.ocks.org/cmgiven/'>cmgiven</a>'s block: <a href='http://bl.ocks.org/cmgiven/4541f6de7b6fbef482aaa43f3a71f8d4'>Zoomable Treemap Bar Chart</a>

mit Licensed

Similar vizzes