Water tool · project 03 of 19
Water flow converter.
Acre-feet per year to MGD and back, without rounding mistakes.
How to use it
- Type a number in either box: acre-feet per year or MGD. The other side updates at once.
- Use the direction switch or tap a row in the quick-reference table for common values.
- Press Full screen to put it on the projector in a meeting.
Where it helps most
- Water-rights and capacity meetings where people switch units in mid-sentence.
- Checking a number in a report without opening a spreadsheet.
- A pattern for any two-way converter your own field keeps doing by hand.
The idea
In water-rights and capacity meetings people switch between acre-feet per year and million gallons per day all the time. I wanted a fast two-way converter with meeting-ready numbers and no rounding mistakes.
The build
Claude built a bidirectional calculator that uses the full-precision factor (43,560 ft³ per acre-ft, 7.48 gal per ft³ derived from 1,728/231), formats results for presentations, works on a phone, and deployed it at sghadimi.com/tools/flow-converter.
Free to take
Build your own.
Copy the skill, paste it into your own AI, and say what you want different. How to use a skill, step by step ›
Get the skillThe instructions your AI follows. Works in Claude, ChatGPT, Gemini or any other
Build a single-file web app: a two-way unit converter between acre-feet per year and million gallons per day (MGD).
Rules:
- Use the exact factor, not a rounded one: 1 acre-ft = 43,560 ft³; 1 ft³ = 1,728/231 US gallons; a year is 365 days. So MGD = (acre-ft/yr × 43,560 × 1,728) / (231 × 365 × 1,000,000).
- Typing in either field updates the other instantly. Show the formula and the factor under the result.
- Format numbers with thousands separators and a user-selectable number of decimals.
- Add one-tap presets (e.g. 1,000 / 10,000 / 50,000 acre-ft/yr and 1 / 10 / 20 MGD) and a copy-result button.
- Large, readable type for projecting in a meeting; works on a phone.
- No libraries, no network calls.
After building, show me three worked examples and confirm 1 MGD ≈ 1,120.14 acre-ft/yr.
Get the code3 files, exactly as they run on this site
index.html31 lines
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="light">
<title>Acre-ft/year ↔ MGD | Engineering Flow Converter</title>
<meta name="description" content="Convert acre-feet per year to million gallons per day (MGD) and back, without rounding mistakes. A free flow converter for water engineers.">
<link rel="icon" href="../../favicon.svg" type="image/svg+xml">
<link rel="stylesheet" href="./converter.css">
</head>
<body>
<div class="shell">
<header class="mast">
<div><div class="eyebrow">EPWater · Engineering Meeting Tool</div><h1>Flow ↔ Annual Volume</h1><p class="sub">Bidirectional acre-ft/year and MGD calculator · Clear, meeting-ready numbers</p></div>
<div class="topbar"><button type="button" class="btn" id="reset">Reset</button><button type="button" class="btn" id="fullscreen">Full screen ⛶</button></div>
</header>
<section class="panel controls" aria-label="Live conversion calculator">
<div class="controltop"><span class="label">Conversion direction</span><div class="modes" role="group" aria-label="Conversion direction"><button type="button" class="mode" id="modeAf" aria-pressed="true">acre-ft/year → MGD</button><button type="button" class="mode" id="modeMgd" aria-pressed="false">MGD → acre-ft/year</button></div></div>
<div class="converter"><div class="fieldbox"><label for="inputVal" id="inputLabel">Annual volume · acre-ft/year</label><input id="inputVal" type="number" min="0" step="1" value="11200" inputmode="decimal" aria-describedby="error"/><div class="err" id="error" role="status"></div></div><button class="swap" id="swap" aria-label="Reverse conversion direction" title="Reverse conversion direction">⇄</button><div class="fieldbox out" aria-live="polite"><div class="outlabel" id="outputLabel">Average flow · MGD</div><output class="value" id="outputVal">10</output></div></div>
<div class="formulanote"><span><strong>Easy meeting conversion:</strong> 1,000 acre-ft/year ≈ <strong>0.89 MGD</strong></span><span id="formula">MGD ≈ (acre-ft/year ÷ 1,000) × 0.89</span></div>
</section>
<div class="main">
<section class="panel chartpanel"><div class="chartbar"><div><h2>Interactive conversion graph</h2><p>Horizontal: acre-ft/year · Vertical: MGD</p></div><span class="legend"><i class="legend-dot"></i>Selected value</span></div><svg id="plot" class="plot" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 570" role="img" tabindex="0" aria-label="Conversion graph. Click or drag along the line to select a value."></svg><p class="hint">Click or drag to select in 0.5-MGD steps · Enter a number above for greater precision.</p></section>
<aside class="panel tablepanel"><h2>10–100 MGD quick reference</h2><p>Click any row to populate the live calculator</p><table aria-label="Annual average flow conversion quick reference"><thead><tr><th>Flow<br>(MGD)</th><th>Volume<br>(acre-ft/year)</th></tr></thead><tbody id="tableBody"></tbody></table><div class="chipline"><span class="label">Common values:</span><button class="chip" data-preset="10">10 MGD</button><button class="chip" data-preset="20">20 MGD</button><button class="chip" data-preset="50">50 MGD</button><button class="chip" data-preset="100">100 MGD</button></div></aside>
</div>
<footer><strong>Basis:</strong> 1 acre-foot = 43,560 ft³; 1 ft³ = 1,728 in³; 1 U.S. gallon = 231 in³; 365 days/year. The calculator uses the full-precision conversion factor internally. Results represent <strong>annual average flow</strong>, not plant peak-day capacity. Table values rounded to nearest acre-foot. <div class="source">References: <a href="https://www.nist.gov/pml/us-surveyfoot/revised-unit-conversion-factors" target="_blank" rel="noopener">NIST — unit conversion factors</a> · <a href="https://pubs.usgs.gov/circ/2004/circ1268/htdocs/text-conversion.html" target="_blank" rel="noopener">USGS — conversion factors</a>. Works offline; no external libraries or server connections.</div></footer>
</div>
<script src="./converter.js" defer></script>
</body>
</html>
converter.js72 lines
'use strict';
const AF_TO_MGD=(43560*1728)/(231*365*1000000);
const $=id=>document.getElementById(id);
let mode='af';
const format=(v,dp=2)=>Number(v).toLocaleString('en-US',{minimumFractionDigits:0,maximumFractionDigits:dp});
const fmtInput=(v,dp=0)=>Number(v.toFixed(dp)).toString();
const inputForMGD=v=>mode==='af'?fmtInput(v/AF_TO_MGD,0):fmtInput(v,2);
const escapeXml=s=>String(s).replaceAll('&','&').replaceAll('<','<').replaceAll('>','>').replaceAll('"','"');
const input=$('inputVal'), output=$('outputVal');
const W=960,H=570,P={left:100,right:42,top:30,bottom:84};
const chart={x:P.left,y:P.top,w:W-P.left-P.right,h:H-P.top-P.bottom};
let mgd=11200*AF_TO_MGD,af=11200,maxY=100;
function setMGD(v){const n=Math.max(0,v);input.value=inputForMGD(n);refresh();}
function setMode(next){if(mode===next)return;const n=mode==='af'?Number(input.value)*AF_TO_MGD:Number(input.value);mode=next;input.value=Number.isFinite(n)&&n>=0?inputForMGD(n):'0';input.step=mode==='af'?'1':'0.01';$('modeAf').setAttribute('aria-pressed',String(mode==='af'));$('modeMgd').setAttribute('aria-pressed',String(mode==='mgd'));$('inputLabel').textContent=mode==='af'?'Annual volume · acre-ft/year':'Average flow · MGD';$('outputLabel').textContent=mode==='af'?'Average flow · MGD':'Annual volume · acre-ft/year';$('formula').textContent=mode==='af'?'MGD ≈ (acre-ft/year ÷ 1,000) × 0.89':'acre-ft/year = MGD × 1,120.142396';refresh();}
function redraw(){
maxY=Math.max(100,Math.ceil(mgd/10)*10);if(mgd>0 && mgd>=maxY) maxY+=10;
const maxX=maxY/AF_TO_MGD;
const X=v=>chart.x+(v/maxX)*chart.w,Y=v=>chart.y+chart.h-(v/maxY)*chart.h;
let s='';
s+=`<rect x="${chart.x}" y="${chart.y}" width="${chart.w}" height="${chart.h}" fill="#fbfdfe" rx="5"/>`;
for(let i=0;i<=5;i++){
const f=i/5, yy=Y(maxY*f), xx=X(maxX*f);
s+=`<line x1="${chart.x}" y1="${yy}" x2="${chart.x+chart.w}" y2="${yy}" stroke="#dbe7ec" stroke-width="${i===0?2:1}"/>`;
s+=`<text x="${chart.x-14}" y="${yy+5}" text-anchor="end" font-size="17" fill="#547185">${format(maxY*f,0)}</text>`;
s+=`<line x1="${xx}" y1="${chart.y}" x2="${xx}" y2="${chart.y+chart.h}" stroke="#e4ebf0" stroke-width="1"/>`;
s+=`<text x="${xx}" y="${chart.y+chart.h+29}" text-anchor="middle" font-size="16" fill="#547185">${format(maxX*f,0)}</text>`;
}
s+=`<path d="M ${X(0)} ${Y(0)} L ${X(maxX)} ${Y(maxY)}" fill="none" stroke="#126b98" stroke-width="5" stroke-linecap="round"/>`;
if(Number.isFinite(mgd)&&mgd>=0){
let px=X(af),py=Y(mgd);
s+=`<line x1="${px}" y1="${py}" x2="${px}" y2="${Y(0)}" stroke="#008b85" stroke-dasharray="6 7" stroke-width="2"/>`;
s+=`<line x1="${chart.x}" y1="${py}" x2="${px}" y2="${py}" stroke="#008b85" stroke-dasharray="6 7" stroke-width="2"/>`;
s+=`<circle cx="${px}" cy="${py}" r="13" fill="white" stroke="#008b85" stroke-width="5"/>`;
s+=`<circle cx="${px}" cy="${py}" r="5" fill="#008b85"/>`;
const label1=`${format(mgd,2)} MGD`,label2=`${format(af,0)} acre-ft/yr`;
const labelWidth=218,labelHeight=65;
const bx=Math.max(chart.x+8,Math.min(px+20,chart.x+chart.w-labelWidth-8));
const by=Math.max(chart.y+8,Math.min(py-82,chart.y+chart.h-labelHeight-8));
s+=`<rect x="${bx}" y="${by}" width="${labelWidth}" height="${labelHeight}" rx="10" fill="#10364d"/>`;
s+=`<text x="${bx+14}" y="${by+27}" font-size="22" font-weight="800" fill="white">${escapeXml(label1)}</text>`;
s+=`<text x="${bx+14}" y="${by+48}" font-size="16" fill="#cee7f1">${escapeXml(label2)}</text>`;
}
s+=`<text x="${chart.x+chart.w/2}" y="${H-13}" font-size="20" font-weight="700" text-anchor="middle" fill="#294d64">Annual volume (acre-ft/year)</text>`;
s+=`<text x="26" y="${chart.y+chart.h/2}" transform="rotate(-90 26 ${chart.y+chart.h/2})" font-size="20" font-weight="700" text-anchor="middle" fill="#294d64">Average flow (MGD)</text>`;
$('plot').innerHTML=s;
$('plot').setAttribute('aria-label',`Conversion graph. Selected ${format(af,0)} acre-feet per year equals ${format(mgd,2)} MGD. Click or drag to select a value.`);
}
function refresh(){
let raw=input.value.trim(),val=Number(raw),valid=raw!==''&&Number.isFinite(val)&&val>=0;
if(!valid){$('error').textContent=raw===''?'Enter a value to convert.':'Enter a nonnegative number.';output.textContent='—';return;}
$('error').textContent='';
if(mode==='af'){af=val;mgd=val*AF_TO_MGD;output.textContent=format(mgd,2)}else{mgd=val;af=val/AF_TO_MGD;output.textContent=format(af,0)}
redraw();
document.querySelectorAll('#tableBody tr').forEach(tr=>tr.classList.toggle('active',Math.abs(Number(tr.dataset.mgd)-mgd)<0.005));
}
function graphToMGD(e){let rect=$('plot').getBoundingClientRect();let ux=(e.clientX-rect.left)/rect.width*W;let fraction=Math.min(1,Math.max(0,(ux-chart.x)/chart.w));setMGD(Math.round(fraction*maxY*2)/2);}
let dragging=false;
$('plot').addEventListener('pointerdown',e=>{dragging=true;$('plot').setPointerCapture(e.pointerId);graphToMGD(e)});
$('plot').addEventListener('pointermove',e=>{if(dragging)graphToMGD(e)});
$('plot').addEventListener('pointerup',()=>{dragging=false});$('plot').addEventListener('pointercancel',()=>{dragging=false});
$('plot').addEventListener('keydown',e=>{if(e.key==='ArrowRight'||e.key==='ArrowUp'){e.preventDefault();setMGD(mgd+1)}if(e.key==='ArrowLeft'||e.key==='ArrowDown'){e.preventDefault();setMGD(Math.max(0,mgd-1))}});
$('modeAf').addEventListener('click',()=>setMode('af'));
$('modeMgd').addEventListener('click',()=>setMode('mgd'));
$('swap').addEventListener('click',()=>setMode(mode==='af'?'mgd':'af'));
$('reset').addEventListener('click',()=>{mode='mgd';setMode('af');input.value='11200';refresh()});
input.addEventListener('input',refresh);
$('fullscreen').addEventListener('click',()=>{if(!document.fullscreenElement){document.documentElement.requestFullscreen?.()}else document.exitFullscreen?.()});
$('tableBody').innerHTML=Array.from({length:10},(_,i)=>{let m=(i+1)*10;return `<tr data-mgd="${m}" tabindex="0" title="Use ${m} MGD"><td>${m}</td><td>${format(m/AF_TO_MGD,0)}</td></tr>`}).join('');
document.querySelectorAll('#tableBody tr').forEach(tr=>{let fn=()=>setMGD(Number(tr.dataset.mgd));tr.addEventListener('click',fn);tr.addEventListener('keydown',e=>{if(e.key==='Enter'||e.key===' '){e.preventDefault();fn()}})});
document.querySelectorAll('[data-preset]').forEach(b=>b.addEventListener('click',()=>setMGD(Number(b.dataset.preset))));
refresh();
converter.css18 lines
:root{--ink:#102d43;--muted:#547185;--edge:#d7e3ea;--bg:#f1f5f8;--panel:#fff;--blue:#126b98;--teal:#008b85;--soft:#e9f5f6;--softBlue:#e9f3fa}
*{box-sizing:border-box}body{margin:0;background:var(--bg);font:16px/1.45 system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;color:var(--ink)}
.shell{max-width:1510px;margin:auto;padding:24px 30px 34px}.mast{display:flex;align-items:flex-start;justify-content:space-between;gap:24px;margin-bottom:23px}
.eyebrow{font-size:12px;letter-spacing:.17em;text-transform:uppercase;font-weight:800;color:var(--blue)}h1{margin:4px 0 5px;letter-spacing:-.035em;font-size:clamp(24px,3vw,40px);line-height:1.1}.sub{color:var(--muted);margin:0;font-size:14px}
button,input{font:inherit}.btn{background:white;color:var(--ink);border:1px solid var(--edge);border-radius:10px;padding:9px 14px;cursor:pointer;font-weight:650}.btn:hover{border-color:var(--blue)}.btn:focus-visible,.mode:focus-visible,.chip:focus-visible,.plot:focus-visible,input:focus-visible{outline:3px solid #48bdb8;outline-offset:3px}
.topbar{display:flex;gap:9px;flex-wrap:wrap;align-items:center}.panel{background:white;border:1px solid var(--edge);border-radius:17px;box-shadow:0 3px 15px rgba(15,49,70,.035)}
.controls{padding:20px 23px 21px;margin-bottom:18px}.controltop{display:flex;flex-wrap:wrap;justify-content:space-between;align-items:center;gap:18px;margin-bottom:18px}.label{font-size:12px;font-weight:800;letter-spacing:.10em;text-transform:uppercase;color:var(--muted)}
.modes{display:flex;gap:4px;border:1px solid var(--edge);padding:4px;background:#f5f9fb;border-radius:12px}.mode{background:transparent;color:#49677a;font-size:14px;font-weight:750;border:0;border-radius:8px;padding:10px 15px;cursor:pointer}.mode[aria-pressed="true"]{background:var(--ink);color:white;box-shadow:0 2px 4px #142c4040}
.converter{display:grid;grid-template-columns:minmax(0,1fr) 44px minmax(0,1fr);align-items:center;gap:16px}.fieldbox{border:1px solid var(--edge);border-radius:13px;padding:15px 18px;min-width:0}.fieldbox.out{border-color:#b0d6d4;background:#f1faf9}.fieldbox label,.fieldbox .outlabel{display:block;font-size:13px;font-weight:700;color:#4a687b;margin-bottom:7px}.fieldbox input{border:0;outline:0;background:transparent;color:var(--ink);width:100%;font-size:clamp(27px,3vw,46px);font-weight:780;letter-spacing:-.03em;font-variant-numeric:tabular-nums;min-width:0}.fieldbox input:focus-visible{outline:none}.value{display:block;font-size:clamp(27px,3vw,46px);font-weight:800;color:#077a74;letter-spacing:-.04em;font-variant-numeric:tabular-nums;overflow-wrap:anywhere}.swap{background:#eaf3f8;color:var(--blue);border:0;border-radius:50%;height:42px;width:42px;cursor:pointer;font-size:24px;font-weight:bold;transition:.12s}.swap:hover{transform:rotate(180deg)}
.formulanote{margin-top:15px;display:flex;justify-content:space-between;gap:14px;flex-wrap:wrap;font-size:13px;color:var(--muted)}.formulanote strong{color:var(--ink)}
.main{display:grid;grid-template-columns:minmax(0,2.2fr) minmax(290px,1fr);gap:18px}.chartpanel{padding:20px 21px 14px;min-width:0}.chartbar{display:flex;justify-content:space-between;align-items:start;gap:12px;margin-bottom:10px}.chartbar h2,.tablepanel h2{margin:0;font-size:19px;letter-spacing:-.02em}.chartbar p,.tablepanel p{margin:4px 0 0;font-size:12px;color:var(--muted)}.legend{font-size:12px;font-weight:700;color:var(--blue);white-space:nowrap;margin-top:4px}.legend-dot{display:inline-block;width:10px;height:10px;background:var(--teal);border-radius:50%;margin-right:5px}
.plot{width:100%;display:block;touch-action:none;cursor:crosshair;border-radius:9px}svg text{font-family:system-ui,-apple-system,"Segoe UI",Arial,sans-serif}.hint{font-size:12px;color:var(--muted);text-align:center;margin:4px 0 0}
.tablepanel{padding:19px 19px 15px}.tablepanel table{border-collapse:collapse;width:100%;margin-top:15px;font-size:14px;font-variant-numeric:tabular-nums}.tablepanel th{text-align:right;padding:9px 8px;border-bottom:2px solid var(--edge);color:var(--muted);font-size:12px}.tablepanel td{text-align:right;padding:9px 8px;border-bottom:1px solid #edf2f5}.tablepanel tr:last-child td{border:0}.tablepanel tr{cursor:pointer}.tablepanel tbody tr:hover,.tablepanel tbody tr:focus-within{background:var(--softBlue)}.tablepanel tr.active{background:var(--soft)}.chipline{display:flex;gap:6px;align-items:center;flex-wrap:wrap;margin-top:15px}.chip{border:1px solid var(--edge);border-radius:999px;background:white;color:var(--muted);font-size:12px;padding:5px 10px;cursor:pointer}.chip:hover{border-color:var(--blue);color:var(--blue)}
footer{font-size:12px;color:var(--muted);line-height:1.65;padding:16px 3px 0}footer a{color:#126b98}.source{margin-top:2px}.err{color:#b42e2e;font-size:12px;margin-top:5px;min-height:0}
@media(max-width:950px){.main{grid-template-columns:1fr}.tablepanel table{font-size:14px}.tablepanel tbody{display:grid;grid-template-columns:1fr 1fr;column-gap:16px}.tablepanel thead{display:none}.tablepanel tr{display:flex;justify-content:space-between;border-bottom:1px solid #edf2f5}.tablepanel td{border:0}.tablepanel td:first-child:after{content:' MGD';color:var(--muted);font-size:11px}}
@media(max-width:620px){.shell{padding:14px}.mast{flex-direction:column;gap:10px}.controls{padding:16px}.controltop{align-items:stretch;flex-direction:column}.mode{flex:1;padding:9px 8px;font-size:12px}.converter{grid-template-columns:1fr;gap:7px}.swap{justify-self:center;transform:rotate(90deg);height:34px;width:34px;font-size:20px}.swap:hover{transform:rotate(270deg)}.fieldbox{padding:13px}.fieldbox input,.value{font-size:34px}.chartpanel{padding:15px 11px}.chartbar{padding:0 4px}.legend{font-size:10px}.hint{font-size:11px}.tablepanel{padding:15px}}
@media print{body{background:white}.shell{max-width:none;padding:0}.mast{margin-bottom:12px}.btn,.topbar,.swap,.hint{display:none}.panel{box-shadow:none;break-inside:avoid}.controls{padding:8px 14px}.main{grid-template-columns:1.9fr 1fr}footer{font-size:10px}}
Have an idea of your own?
Look around your day, find the thing that wastes your time, and build the fix. Everything here is free to help you start. If you would rather I built it, or you just want to talk an idea through, write to me.