About Voronoi Treemaps

What are Voronoi Treemaps?

Voronoi Treemaps are methods of visualizing hierarchical data, where each cell represents a portion of the data and the hierarchy is encoded by the nesting of cells within each other. Unlike traditional Treemaps, Voronoi Tree Maps do not use rectangles to represent the data, but rather use arbitrary polygons to represent the data. This allows for a more organic and natural representation of the data.

Traditional Treemap

This is a Traditional Treemap. Notice how the rectangles are used to represent the data. This can lead to a more rigid and less organic representation of the data.

Voronoi Treemap

This is a Voronoi Treemap representing the GDP of countries in asia. Notice how the polygons are used to represent the data. As you can see the data seems to have a more organic and natural representation.

Creating a Simple Voronoi Treemap with D3.js

In order to create a simple Voronoi treemap using D3.js, follow these steps:

  1. Initialize the HTML Structure:

    Set up the HTML structure with an SVG container where the treemap will be rendered.

    <svg id="simpleVoronoi"></svg>

    The <svg> element with the ID "simpleVoronoi" serves as the container for the Voronoi treemap.

  2. Import D3.js Library:

    Import the D3.js library by adding the following script tag just before your custom script:

    <script src="https://d3js.org/d3.v7.min.js"></script>

    This script tag imports the D3.js library from the official CDN, making D3.js functionalities available in your project.

  3. Initialize the Voronoi Treemap:

    Define constants for SVG dimensions, data, and necessary variables. Initialize the Voronoi treemap by calling functions to set up data, layout, and drawing.

    This block of code initializes constants, sets up the SVG container, and prepares data and layout for the Voronoi treemap.

    Constants like HEIGHT and WIDTH define the dimensions of the SVG container. Data, such as country names, weights, and colors, are stored in the data array. The init function initializes the treemap by calling other functions to set up data, layout, and drawing.

  4. Initialize Data and Layout:

    Define functions to initialize data and layout settings for the treemap.

    These functions initialize data and layout settings for the treemap, including the circling polygon and font scale.

    The initData function calculates the circling polygon and sets the font scale based on the provided data. The computeCirclingPolygon function calculates the vertices of the circling polygon, while the initLayout function sets up the SVG container and draws the circling polygon.

  5. Draw the Treemap:

    Create a function to draw the Voronoi treemap based on the provided data and layout.

    This function draws the Voronoi treemap based on the provided data and layout settings, including cells and labels.

    The drawTreemap function creates cells and labels for each data point in the treemap. It appends SVG elements for cells and labels, styles them accordingly, and positions them based on the calculated data. The cells represent the Voronoi regions, while the labels display country names and weights.

  6. Additional Info:

    You will notice in the tutorials that there are multiple functions that are not included in d3, that is because the operations necessary for the Voronoi treemap are imported via the d3-voronoi-treemap plugin. The documentation and installation instructions of which can be found using this link: here. This plugin hosts the relevant function calls to build a visualization of this model.

    d3.voronoiTreemap() creates a new voronoiTreemap with a set of default configuration values, functions, and algorithms, including clip, extent, size, convergenceRatio, maxIterationCount, minWeightRatio, and prng. Some of these standard methods are used in the tutorial and are fairly self-explanatory; they all play their part in the process for creating a Voronoi treemap.

    • clip: Used to set the clipping polygon for the treemap.
    • extent: Used to set the extent of the treemap.
    • size: Specifies the size of the treemap.
    • convergenceRatio: Sets the convergence ratio for the treemap.
    • maxIterationCount: Sets the maximum number of iterations for the treemap.
    • minWeightRatio: Sets the minimum weight ratio for the treemap.
    • prng: Sets the random number generator for the treemap.

    These methods are essential for configuring various aspects of the Voronoi treemap, such as the size, convergence behavior, and clipping boundaries. Understanding and properly configuring these parameters are crucial for effectively visualizing data using the Voronoi treemap technique.

    Voronoi General Background Processes

  1. Scatter Plot:

    A voronoi diagram starts with a set of 2d coordinate points plotted on a plane.

  2. Delaunay triangulation:

    Run a Delaunay triangulation on the set of two-dimensional points

  3. Circumcenters:

    Join the circumcenters of each triangle to get the voronoi diagram

  4. More details on the Voronoi diagram can be found here.

How Voronoi Treemaps are generated

The d3-voronoi-treemap.js library

This code sets up a module that can be used in both CommonJS and AMD (Asynchronous Module Definition) environments. It handles dependency injection, allowing the module to work with various module systems. The module takes exports and d3VoronoiMap as dependencies. It then passes these dependencies to the factory function.

_voronoiTreemap is the main function representing the Voronoi treemap algorithm. Additional functions are defined on _voronoiTreemap to get or set various parameters such as convergence ratio, max iteration count, etc.

recurse is a private function used internally to generate the Voronoi treemap recursively. It assigns the clipping polygon to the node and computes the Voronoi map for its children recursively.