<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://thechange.wiki/index.php?action=history&amp;feed=atom&amp;title=Code%3Amake-flow-diagram1.html</id>
	<title>Code:make-flow-diagram1.html - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://thechange.wiki/index.php?action=history&amp;feed=atom&amp;title=Code%3Amake-flow-diagram1.html"/>
	<link rel="alternate" type="text/html" href="https://thechange.wiki/index.php?title=Code:make-flow-diagram1.html&amp;action=history"/>
	<updated>2026-04-26T14:14:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://thechange.wiki/index.php?title=Code:make-flow-diagram1.html&amp;diff=283&amp;oldid=prev</id>
		<title>Elie: Created page with &quot;This javascript/HTML canvas generates the &quot;flow diagram&quot; of :File:food-funnel.png.  If you want to generate a different flow diagram, you can save your own version of this and modify the draw() function to your liking.  &lt;syntaxhighlight lang=&quot;html&quot;&gt; &lt;html&gt;&lt;head&gt;  &lt;script&gt;   // This draw() is the main function: Change it according to how you want your diagram:   function draw() {    primary = 5454;      // crops harvested        leftStart();    go(5000);    branch(491...&quot;</title>
		<link rel="alternate" type="text/html" href="https://thechange.wiki/index.php?title=Code:make-flow-diagram1.html&amp;diff=283&amp;oldid=prev"/>
		<updated>2022-08-27T04:35:02Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;This javascript/HTML canvas generates the &amp;quot;flow diagram&amp;quot; of &lt;a href=&quot;/File:food-funnel.png&quot; title=&quot;File:food-funnel.png&quot;&gt;File:food-funnel.png&lt;/a&gt;.  If you want to generate a different flow diagram, you can save your own version of this and modify the draw() function to your liking.  &amp;lt;syntaxhighlight lang=&amp;quot;html&amp;quot;&amp;gt; &amp;lt;html&amp;gt;&amp;lt;head&amp;gt;  &amp;lt;script&amp;gt;   // This draw() is the main function: Change it according to how you want your diagram:   function draw() {    primary = 5454;      // crops harvested        leftStart();    go(5000);    branch(491...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This javascript/HTML canvas generates the &amp;quot;flow diagram&amp;quot; of [[:File:food-funnel.png]].&lt;br /&gt;
&lt;br /&gt;
If you want to generate a different flow diagram, you can save your own version of this and modify the draw() function to your liking.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&lt;br /&gt;
 &amp;lt;script&amp;gt;&lt;br /&gt;
  // This draw() is the main function: Change it according to how you want your diagram:&lt;br /&gt;
  function draw() {&lt;br /&gt;
   primary = 5454;      // crops harvested&lt;br /&gt;
   &lt;br /&gt;
   leftStart();&lt;br /&gt;
   go(5000);&lt;br /&gt;
   branch(491);         // biofuel&lt;br /&gt;
   go(9000);&lt;br /&gt;
   branch(493);         // food loss&lt;br /&gt;
   end();&lt;br /&gt;
&lt;br /&gt;
   rightStart();&lt;br /&gt;
   go(5000);&lt;br /&gt;
   transform(1964,518); // livestock&lt;br /&gt;
   go(5000);&lt;br /&gt;
   branch(591);         // food waste&lt;br /&gt;
   go(14000);&lt;br /&gt;
   merge(252);   // for comparison: what would be needed to end global hunger&lt;br /&gt;
   end();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  // The rest of these functions are just the &amp;quot;internals&amp;quot; to make it all work:&lt;br /&gt;
  function ctx_moveTo(x,y) { ctx.moveTo(Math.round(x), Math.round(y)); }&lt;br /&gt;
  function ctx_lineTo(x,y) { ctx.lineTo(Math.round(x), Math.round(y)); }&lt;br /&gt;
  function leftStart() { sign = -1; start(); }&lt;br /&gt;
  function rightStart() { sign = 1; start(); }&lt;br /&gt;
  function start() {&lt;br /&gt;
   scale = first/primary;&lt;br /&gt;
   cursor_x = (width + sign*first)/2;&lt;br /&gt;
   cursor_y = rim;&lt;br /&gt;
   ctx.beginPath();&lt;br /&gt;
   ctx.lineWidth = &amp;quot;2&amp;quot;;&lt;br /&gt;
   ctx.strokeStyle = &amp;quot;#000000&amp;quot;;&lt;br /&gt;
   ctx_moveTo(cursor_x + sign*rim, 0);&lt;br /&gt;
   ctx_lineTo(cursor_x, rim);&lt;br /&gt;
   ctx.stroke();&lt;br /&gt;
  }&lt;br /&gt;
  function go(distance) {&lt;br /&gt;
   ctx.beginPath();&lt;br /&gt;
   ctx_moveTo(cursor_x, cursor_y);&lt;br /&gt;
   cursor_y += distance*scale;&lt;br /&gt;
   ctx_lineTo(cursor_x, cursor_y);&lt;br /&gt;
   ctx.stroke();&lt;br /&gt;
  }&lt;br /&gt;
  function branch(thickness) {&lt;br /&gt;
   ctx.beginPath();&lt;br /&gt;
   ctx_moveTo(cursor_x, cursor_y);&lt;br /&gt;
   ctx_lineTo(cursor_x + sign*reach, cursor_y + reach);&lt;br /&gt;
   ctx_lineTo(sign&amp;lt;0 ? 0:width,      cursor_y + reach);&lt;br /&gt;
   ctx_moveTo(sign&amp;lt;0 ? 0:width,      cursor_y + reach + thickness*scale);&lt;br /&gt;
   ctx_lineTo(cursor_x + sign*reach - sign*thickness*scale*(SQRT2-1),&lt;br /&gt;
                                     cursor_y + reach + thickness*scale);&lt;br /&gt;
   cursor_x -= thickness*scale*sign;&lt;br /&gt;
   cursor_y += thickness*scale*(SQRT2-1);&lt;br /&gt;
   ctx_lineTo(cursor_x, cursor_y);&lt;br /&gt;
   ctx.stroke();&lt;br /&gt;
  }&lt;br /&gt;
  function merge(thickness) {&lt;br /&gt;
   ctx.beginPath();&lt;br /&gt;
   ctx_moveTo(cursor_x, cursor_y);&lt;br /&gt;
   ctx_lineTo(cursor_x + sign*reach, cursor_y - reach);&lt;br /&gt;
   ctx_lineTo(sign&amp;lt;0 ? 0:width,      cursor_y - reach);&lt;br /&gt;
   ctx_moveTo(sign&amp;lt;0 ? 0:width,      cursor_y - reach + thickness*scale);&lt;br /&gt;
   ctx_lineTo(cursor_x + sign*reach + sign*thickness*scale*(SQRT2-1),&lt;br /&gt;
                                     cursor_y - reach + thickness*scale);&lt;br /&gt;
   cursor_x += thickness*scale*sign;&lt;br /&gt;
   cursor_y += thickness*scale*(SQRT2-1);&lt;br /&gt;
   ctx_lineTo(cursor_x, cursor_y);&lt;br /&gt;
   ctx.stroke();&lt;br /&gt;
  }&lt;br /&gt;
  function transform(before, after) {&lt;br /&gt;
   before *= scale; after *= scale;&lt;br /&gt;
   var dif = before-after; var adif = Math.abs(dif);&lt;br /&gt;
   ctx.beginPath();&lt;br /&gt;
   ctx_moveTo(cursor_x - sign*before, cursor_y);&lt;br /&gt;
   ctx_lineTo(cursor_x - sign*before, cursor_y + adif*3);&lt;br /&gt;
   ctx_moveTo(cursor_x - sign*dif,    cursor_y + adif*3);&lt;br /&gt;
   ctx_lineTo(cursor_x - sign*dif,    cursor_y + adif*2);&lt;br /&gt;
   ctx_lineTo(cursor_x,               cursor_y + adif);&lt;br /&gt;
   ctx_lineTo(cursor_x,               cursor_y);&lt;br /&gt;
   ctx.stroke();&lt;br /&gt;
   cursor_x -= sign*(before-after);&lt;br /&gt;
   cursor_y += adif*3;&lt;br /&gt;
  }&lt;br /&gt;
  function end() {&lt;br /&gt;
   ctx.beginPath();&lt;br /&gt;
   ctx_moveTo(cursor_x, cursor_y);&lt;br /&gt;
   cursor_y = height;&lt;br /&gt;
   ctx_lineTo(cursor_x, cursor_y);&lt;br /&gt;
   ctx.stroke();&lt;br /&gt;
  }&lt;br /&gt;
  function init() {&lt;br /&gt;
   ctx = document.getElementById(&amp;quot;canvas&amp;quot;).getContext(&amp;quot;2d&amp;quot;);&lt;br /&gt;
   ctx.canvas.height = document.body.clientHeight * 2; // temporary height to get the scrollbar so clientWidth is accurate below&lt;br /&gt;
   width = ctx.canvas.width  = document.body.clientWidth; // fit canvas to width&lt;br /&gt;
   height= ctx.canvas.height = ctx.canvas.width * 4;      // 1:4 aspect ratio&lt;br /&gt;
   rim   = 8; // pixels at the at the top of the diagram (&amp;quot;the rim of the funnel&amp;quot;)&lt;br /&gt;
   first = width * 0.4; // the width of the first part of the diagram (&amp;quot;the primary&amp;quot;)&lt;br /&gt;
   reach = width * 0.1; // how far the branches/merges reach&lt;br /&gt;
   SQRT2 = Math.sqrt(2); // constant&lt;br /&gt;
   ctx.fillStyle = &amp;quot;#FFFFFF&amp;quot;;&lt;br /&gt;
   ctx.fillRect(0, 0, width, height);&lt;br /&gt;
   draw();&lt;br /&gt;
  }&lt;br /&gt;
 &amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&amp;lt;body onload=&amp;quot;init()&amp;quot; onresize=&amp;quot;init()&amp;quot; style=&amp;quot;margin:0;padding:0;text-align:center&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;canvas id=&amp;quot;canvas&amp;quot;&amp;gt;&amp;lt;/canvas&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Elie</name></author>
	</entry>
</feed>