openfoodfacts / openfoodfacts-server

Open Food Facts database, API server and web interface - 🐪🦋 Perl, CSS and JS coders welcome 😊 For helping in Python, see Robotoff or taxonomy-editor
http://openfoodfacts.github.io/openfoodfacts-server/
GNU Affero General Public License v3.0
647 stars 374 forks source link

Consider using pie charts for nutritional values #539

Open aleksejrs opened 7 years ago

aleksejrs commented 7 years ago

Why

What

Small pie charts could be put into the columns of each table.

Part of

hangy commented 7 years ago

This donut chart could be cool to include "hierarchial" data (total fats, saturated unsaturated fats, …). We already use Highcharts for the product history, so this should be pretty straightforward.

aleksejrs commented 7 years ago

When space is restricted (a small chart): Russian milk has about 11% divided among 3 nutrients, so including "the rest" would make the chart almost useless. An example of a nutrient-only chart on Russian milk: http://static.openfoodfacts.org/images/products/464/001/735/0536/nutrition_ru.9.full.jpg (left; the one on the right shows energy)

aleksejrs commented 7 years ago

A variation of donut chart showing empty space where the depth does not reach the maximum depth (requires more space to be clear): https://en.wikipedia.org/wiki/Pie_chart#Ring_chart_.2F_Sunburst_chart_.2F_Multilevel_pie_chart (like Baobab or Filelight: https://commons.wikimedia.org/wiki/File:Disk_usage_(Boabab).png ) There is even empty space for "the rest".

hangy commented 7 years ago

The best match that I've found in Highcharts (up to now) would be http://jsfiddle.net/eonkddx3/, because the donut chart does not seem to work well with a lot of "rest"/undefined nutritional values.

aleksejrs commented 7 years ago

What about showing "rest" using the size (diameter or area) of an additional inner circle (or an outer annulus)?

aleksejrs commented 7 years ago

Maybe some kind of absolute maximum of energy per 100 g could be found, so that it looks proportional to the nutrients and can be rendered as a part of an annulus with a starting point.

aleksejrs commented 7 years ago

There are approximate energy densities for some nutrients (e.g., the table at the bottom of https://en.wikipedia.org/wiki/Food_energy#Nutrition_labels), that could be used to connect their parts in a render with separate segments of the energy annulus for each nutrient (fun, but maybe not worth it), or to really compare the average amounts with the stated ones and other data.

aleksejrs commented 7 years ago

There are some implementations using D3.js: https://github.com/d3/d3/wiki/Gallery Most of them need adding text and a state indicator, or contain third-party data and have no license specified.

Two years ago someone made his own implementation (code, MIT license in the master branch; article in Russian about writing it) and said D3.js was too big, and that it used SVG and so was too slow for mobile.

teolemon commented 7 years ago

http://duns.ethz.ch//request?query=ProductDetails&xml=MessageData&xml=MetaData&xsl=ListDetails&productId=131&lan=en&letter=A&pageKey=ListDetails

hangy commented 7 years ago

After some research, to me, it looks like Sunburst diagrams are really cool for displaying larger amounts of data with a little bit more depth/levels. But for what we have with nutrition values, a pie chart is more appropriate and doesn't require as much space.