The Tale of the Donut Chart

Donuts

Table of Contents


The Tale

One day, I found myself needing to embed a donut chart on a web page. The different sections of the chart were to resemble percentages. By default, the chart library displays percentages to one decimal place (e.g. 12.3%), which I didn't want, as the decimals added clutter.

Simple enough, I thought, before rounding the inputs to the nearest percentage.

Until I noticed a little detail — the rounded percentages don't always add up to 100 (e.g. [33.3%, 33.3%, 33.3%]).

I'm sure there's a simple solution, I thought, while Googling the problem, only to find a lovely list of complicated processes. After floating through the endless stream of solutions, I decided to go with the largest remainder method, which is the name of several related approaches used to "allocat[e] seats proportionally for representative assemblies with party list voting systems". Groovy.

With a little Googling I couldn't find someone else's code that I wanted to use. It was time to implement the largest remainder method with the Hare quota. This is a good idea — it's used for legislative elections in Russia, Ukraine, Lithuania, Tunisia, etc.

A little while later, I had the perfect donut chart.


The Takeaways

  • Never assume you know the true complexity of a task (see planning fallacy)
  • Never assume you can accurately estimate the time it will take to complete a task (see Hofstadter's Law)
  • Donut charts can lead you to deep philosophical questions of error and fairness, and inparticular can lead you to voting systems

Sources

Main image: By Elisa Kerschbaumer, hosted by Unsplash, license

The Tale
The Takeaways