/* Overall PFD plus a passive, source-aware treatment walkthrough. */ (() => { 'use strict'; const stages=[ {id:'intake',name:'Intake and raw-water pumping',short:'Intake',river:'River water enters an intake. A screen intercepts larger debris, and raw-water pumps convey it to pretreatment.',groundwater:'Wells lift groundwater from the aquifer. Influent pumping brings it to the treatment plant.',result:'Raw water reaches the treatment train.'}, {id:'pretreat',name:'Pretreatment / pre-oxidation',short:'Pretreat',river:'Pre-oxidation conditions river water before coagulation. Chemical choice and application depend on source-water quality.',groundwater:'Sodium hypochlorite oxidizes arsenite As(III) to arsenate As(V), preparing it for removal.',result:'Water chemistry is conditioned before coagulation.'}, {id:'rapid',name:'Rapid mix / coagulation',short:'Rapid mix',description:'Ferric chloride is rapidly mixed with the water to prepare fine particles for aggregation and separation.',result:'Coagulant is dispersed through the water.'}, {id:'floc',name:'Flocculation',short:'Flocculation',description:'Gentle mixing and anionic polymer help small particles gather into larger floc.',result:'Larger floc forms for settling.'}, {id:'settle',name:'Sedimentation',short:'Sedimentation',description:'Floc settles below the clarified water. Water leaves from the upper outlet; sludge goes to thickening and drying beds.',result:'Most settleable solids leave the main water stream.'}, {id:'ozone',name:'Ozone contact',short:'Ozone contact',illustrative:true,description:'Ozone contacts the settled water before GAC filtration. This contactor is a retained conceptual addition.',result:'Ozone contact occurs before the filter.'}, {id:'filter',name:'GAC filtration',short:'GAC filtration',description:'GAC traps floc carried over from sedimentation. Nonionic polymer is added before filtration; effluent flows to the pump station.',result:'Filtered water is collected for pumping.'}, {id:'blend',name:'Pumping and blending',short:'Blending',river:'Filtered water is pumped to the finished-water system. Blending requires compatible water; the groundwater bypass applies only to the groundwater route.',groundwater:'Pumped filter effluent blends with groundwater bypass to meet the finished-water arsenic target.',result:'The combined stream proceeds to final treatment.'}, {id:'final',name:'Final chemical addition',short:'Final treatment',description:'Sodium hypochlorite is added for final disinfection. Phosphate is added for corrosion control in the distribution system.',result:'Final chlorine addition precedes chlorine contact.'}, {id:'contact',name:'Chlorine contact',short:'Chlorine contact',illustrative:true,description:'After final chlorination, water follows the contact channel before delivery. This basin is a retained conceptual addition.',result:'Chlorine contact is downstream of final chlorination.'}, {id:'tap',name:'Pumping and delivery',short:'Delivery',river:'Finished water is conveyed through the planned finished-water pumping and distribution system to customers.',groundwater:'Finished water leaves for Canutillo Booster Station and onward through the distribution system to customers.',result:'Water reaches the distribution system.'} ]; const positions={pretreat:[260,140],rapid:[420,140],floc:[580,140],settle:[740,140],ozone:[900,140],filter:[900,350],blend:[740,350],final:[580,350],contact:[420,350],tap:[260,350]}; const esc=t=>String(t).replace(/&/g,'&').replace(/''+esc(label)+''; // Uploaded vessel artwork plus equipment-specific vector symbols. Text is a caption, not the process block. function equipment(id,source,x,y,w=126,h=88){ let body=''; const assets={rapid:'./equipment/mixing-tank.png',floc:'./equipment/floc-tank.png',filter:'./equipment/media-filter.png'}; const tank=''; const dose=''; if(assets[id])body=''; else if(id==='intake'&&source==='river')body=''; else if(id==='intake')body=''; else if(id==='pretreat'||id==='final')body=tank+dose+''+(id==='final'?'':''); else if(id==='settle')body=''; else if(id==='ozone')body=tank+''+[[45,59],[59,58],[74,70],[86,54],[100,68],[119,53],[63,43],[105,42]].map(([a,b])=>'').join('')+''; else if(id==='contact')body=tank+''; else if(id==='blend')body=''; else if(id==='tap')body=''; return ''; } const captions={river:['River intake'],groundwater:['Groundwater wells'],pretreat:['Pre-oxidation'],rapid:['Rapid mix'],floc:['Flocculation'],settle:['Sedimentation'],ozone:['Ozone contact*'],filter:['GAC filter'],blend:['Pumping & blending'],final:['Final chemicals'],contact:['Chlorine contact*'],tap:['Delivery']}; function schematicNode(id,x,y,number,selected,source,sourceId,mobile){ const current=id==='intake'?selected==='intake'&&sourceId===source:selected===id,label=captions[sourceId||id]; return ''+equipment(id,sourceId||source,x,y,mobile?132:126,mobile?86:82)+txt(number,x-(sourceId?40:58),y-36,mobile?10:9,current?'#87621e':'#637d78')+label.map((t,i)=>txt(t,x,y+(mobile?54:53)+i*16,mobile?14:14,current?'#71521d':'#2e5357')).join('')+''; } function map(index,source){ const selected=stages[index].id,parts=[]; parts.push(''); const pipe=(d,active=false)=>''; parts.push(pipe('M144 80H172V140H188',source==='river'&&index<=1),pipe('M144 190H172V140H188',source==='groundwater'&&index<=1)); for(let i=1;i',txt('Groundwater bypass',450,250,12,'#796b99')); for(const [label,x] of [['Pre-oxidant',260],['Coagulant',420],['Polymer',580],['Ozone',900]])parts.push(txt(label,x,55,12,'#7d6a43')+''); parts.push(txt('Chlorine + phosphate',580,285,12,'#7d6a43')+''); parts.push(schematicNode('intake',74,80,'SOURCE',selected,source,'river'),schematicNode('intake',74,190,'SOURCE',selected,source,'groundwater')); for(let i=1;i');return parts.join(''); } function mapMobile(index,source){ const selected=stages[index].id,parts=[],xy={pretreat:[90,174],rapid:[270,174],floc:[270,296],settle:[90,296],ozone:[90,418],filter:[270,418],blend:[270,540],final:[90,540],contact:[90,662],tap:[270,662]}; parts.push(''); const pipe=(d,active)=>''; parts.push(pipe('M22 53H7V122H90V125',source==='river'&&index<=1),pipe('M202 53H178V122H90V125',source==='groundwater'&&index<=1)); for(let i=1;i180?'M338 '+a[1]+'H346V'+b[1]+'H340':'M22 '+a[1]+'H14V'+b[1]+'H20';parts.push(pipe(d,selected===stages[i+1].id));} parts.push(''); parts.push(schematicNode('intake',90,53,'SOURCE',selected,source,'river',true),schematicNode('intake',270,53,'SOURCE',selected,source,'groundwater',true)); for(let i=1;i',txt('Groundwater bypass',150,746,12,'#796b99'),txt('* Conceptual contact stages',180,766,12,'#796b99'),'');return parts.join(''); } window.ProcessFlow={stages,map,mapMobile}; window.initProcessWalkthrough=function(){ const $=s=>document.querySelector(s),root=$('#process-walkthrough'),diagram=$('#pfd-map'),figure=$('#pfd-figure'); const reduced=matchMedia('(prefers-reduced-motion: reduce)').matches; const duration=12000; let motionEnabled=!reduced; let index=0,source='river',playing=!reduced,disposed=false,raf=0,elapsed=reduced?duration:0,start=performance.now(),lastPaint=0; const tabs=['current','flow']; function setView(view){root.setAttribute('data-mobile-view',view);for(const id of tabs){const tab=$('#pfd-tab-'+id);tab.setAttribute('aria-selected',String(view===id));tab.setAttribute('tabindex',view===id?'0':'-1');}} for(const id of tabs)$('#pfd-tab-'+id).onclick=()=>setView(id); $('#pfd-mobile-tabs').onkeydown=e=>{if(!['ArrowLeft','ArrowRight','Home','End'].includes(e.key))return;e.preventDefault();const view=e.key==='Home'?'current':e.key==='End'?'flow':e.target.id==='pfd-tab-current'?'flow':'current';setView(view);$('#pfd-tab-'+view).focus();}; function draw(){figure.innerHTML=window.ProcessArt.scene(stages[index].id,Math.min(1,elapsed/duration),elapsed/1000*.4,source);$('#pfd-stage-progress').style.width=Math.min(100,elapsed/duration*100)+'%';} function render(){const s=stages[index];diagram.innerHTML='
'+map(index,source)+'
'+mapMobile(index,source)+'
';$('#pfd-stage-count').textContent=(index+1)+' / '+stages.length;$('#pfd-stage-label').textContent=s.illustrative?'CONCEPTUAL CONTACT STAGE':'CURRENT PROCESS';const title=index===0?(source==='river'?'River intake and pumping':'Groundwater wells and pumping'):s.name;$('#pfd-stage-title').textContent=title;$('#pfd-mobile-stage-title').textContent=title;$('#pfd-mobile-stage-index').textContent='STEP '+String(index+1).padStart(2,'0')+' / '+stages.length+(s.illustrative?' · CONCEPTUAL':'');$('#pfd-description').textContent=s[source]||s.description;$('#pfd-result').textContent=s.result;$('#pfd-previous').disabled=index===0;$('#pfd-next').disabled=index===stages.length-1;$('#pfd-play').textContent=playing?'Pause':elapsed>=duration?'Replay':'Play';$('#pfd-play').setAttribute('aria-label',playing?'Pause current animation':elapsed>=duration?'Replay current process animation':'Play current process animation');$('#pfd-play').setAttribute('aria-pressed',String(playing));root.classList.toggle('is-playing',playing);for(const id of ['river','groundwater'])$('#pfd-source-'+id).setAttribute('aria-pressed',String(source===id));draw();} function frame(now){if(disposed||!playing||document.hidden)return;elapsed=Math.min(duration,now-start);if(elapsed>=duration){playing=false;raf=0;render();return;}if(now-lastPaint>90){draw();lastPaint=now;}raf=requestAnimationFrame(frame);} function schedule(){cancelAnimationFrame(raf);raf=0;if(playing&&!document.hidden)raf=requestAnimationFrame(frame);} function select(i){cancelAnimationFrame(raf);index=Math.max(0,Math.min(stages.length-1,i));playing=motionEnabled;elapsed=playing?0:duration;start=performance.now()-elapsed;lastPaint=0;render();schedule();} $('#pfd-play').onclick=()=>{if(playing){elapsed=Math.min(duration,performance.now()-start);playing=false;motionEnabled=false;}else{if(elapsed>=duration)elapsed=0;playing=true;motionEnabled=true;start=performance.now()-elapsed;}render();schedule();};$('#pfd-previous').onclick=()=>select(index-1);$('#pfd-next').onclick=()=>select(index+1); $('#pfd-reset').onclick=()=>{motionEnabled=!reduced;select(0);setView('current');}; for(const id of ['river','groundwater'])$('#pfd-source-'+id).onclick=()=>{source=id;select(0);}; const activate=e=>{const n=e.target.closest('[data-stage]');if(!n)return;if(n.dataset.source)source=n.dataset.source;select(stages.findIndex(s=>s.id===n.dataset.stage));setView('current');$('#pfd-tab-current').focus();};diagram.onclick=activate;diagram.onkeydown=e=>{if(e.key==='Enter'||e.key===' '){e.preventDefault();activate(e);}}; const visibility=()=>{if(document.hidden){if(playing)elapsed=Math.min(duration,performance.now()-start);cancelAnimationFrame(raf);raf=0;}else{start=performance.now()-elapsed;schedule();}};document.addEventListener('visibilitychange',visibility);setView('current');render();schedule(); return()=>{disposed=true;cancelAnimationFrame(raf);document.removeEventListener('visibilitychange',visibility);diagram.onclick=diagram.onkeydown=null;$('#pfd-mobile-tabs').onkeydown=null;}; }; })();