diff --git a/assets/static/index.min.js b/assets/static/index.min.js index 2c8f9d7..4c165ff 100644 --- a/assets/static/index.min.js +++ b/assets/static/index.min.js @@ -1 +1 @@ -!function(){"use strict";function e(e){if(null==e)throw"item is null or undefined";return e}function t(e){if(null==e)throw"item is null or undefined";if(e instanceof HTMLButtonElement)return e;throw"item is not a button"}function n(t,n){e(document.getElementById(t)).innerText=n}function a(e,t){!function(e,t,n){document.getElementById(e)?.setAttribute(t,n)}(e,"style",t)}function i(e){document.querySelectorAll(e).forEach((e=>e.remove()))}function o(e){document.getElementById(e)?.remove()}function l(e,t){document.getElementById(e)?.classList.remove(t)}function r(e){l(e,"hidden")}function s(e){r(`current-water-quality-${e.water_quality.toLowerCase()}`),n(`current-water-quality-${e.water_quality.toLowerCase()}-status-text`,e.water_quality_text),i(".water-quality-loader")}const d=e=>e.wind_speed===e.gusts||"0"===e.gusts?e.wind_speed:`${e.wind_speed}-${e.gusts}`,c="#a8a29e",u={"#0bd674":"Good","#ffcd1e":"Fair to Good","#ff9500":"Poor","#f4496d":"Very Poor","#a8a29e":"Flat"};let g,p,m,w,f,v,y,h,x,_,b,E,A;function I(e){h=e.graph_max;const s=new Date(e.starting_at).getHours();if(s>20){let t=24-s;const n=p.length-(p.length-t)%24;p=e.wave_height_labels.slice(t,n),g=e.qualities.slice(t,n),m=e.wave_height_data.slice(t,n),w=e.wind_speed_data.slice(t,n),f=e.wind_direction_data.slice(t,n),v=e.wind_gust_data.slice(t,n),y=e.wave_period_data.slice(t,n),x=e.temperature.slice(t,n),_=e.dewpoint.slice(t,n),b=e.cloud_cover.slice(t,n),E=e.probability_of_precipitation.slice(t,n),A=e.probability_of_thunder.slice(t,n)}else{const t=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][new Date(e.starting_at).getDay()],n=[];for(let e=0;e=10&&e<12&&n.push(`${t} ${e} AM`),12===e&&n.push(`${t} ${e} PM`),e>12&&n.push(`${t} 0${e-12} PM`)):n.push(`${t} 12 AM`);const a=e.wave_height_labels.length+s-(e.wave_height_labels.length+s)%24;p=n.concat(e.wave_height_labels).slice(0,a),g=new Array(s).fill("#a8a29e").concat(e.qualities).slice(0,a),m=new Array(s).fill(0).concat(e.wave_height_data).slice(0,a),w=new Array(s).fill(0).concat(e.wind_speed_data).slice(0,a),f=new Array(s).fill(0).concat(e.wind_direction_data).slice(0,a),v=new Array(s).fill(0).concat(e.wind_gust_data).slice(0,a),y=new Array(s).fill(0).concat(e.wave_period_data).slice(0,a),x=new Array(s).fill(0).concat(e.temperature).slice(0,a),_=new Array(s).fill(0).concat(e.dewpoint).slice(0,a),b=new Array(s).fill(0).concat(e.cloud_cover).slice(0,a),E=new Array(s).fill(0).concat(e.probability_of_precipitation).slice(0,a),A=new Array(s).fill(0).concat(e.probability_of_thunder).slice(0,a)}let d=(new Date).getHours();const I=new Date(e.starting_at).getHours();d=d<0?(new Date).getHours():d;const $=document.getElementById("current-wave-height");""===$?.innerText&&($.innerText=e.current_wave_height,"0"==e.current_wave_height&&(a("wave-quality",`background-color: ${c}`),n("wave-quality-text",u[c]),a("wave-quality-text",`color: ${c}`),i(".wave-quality-loader")),a("wave-icon",`transform: rotate(${e.current_wave_direction}deg);`),i(".wavey"));const q=document.getElementById("current-wave-period");""===q?.innerText&&(q.innerText=e.current_wave_period,o("wavey-period-loader")),n("legend-label",p[d]),n("legend-quality",u[g[d]]),n("legend-wave-height",m[d]),n("legend-wind-speed",w[d]),a("legend-wind-icon",`transform: rotate(${f[d]}deg);`),n("legend-wave-period",y[d]),n("legend-wind-gust",v[d]),n("forecast-as-of",`Updated @ ${e.forecast_as_of}`),n("forecast-as-of-2",`Forecast Last Ran @ ${e.forecast_as_of}`),i(".loader"),r("forecast"),r("wave-quality"),r("legend-container"),l("forecast-as-of-container","animate-pulse"),l("forecast-as-of-container-2","animate-pulse"),r("temperature-legend-container"),n("temperature-legend-label",p[d]),n("temperature-legend-temperature",x[d]),n("temperature-legend-dewpoint",_[d]),r("precipitation-legend-container"),n("precipitation-legend-label",p[d]),n("precipitation-legend-precipitation",E[d]),n("precipitation-legend-thunder",A[d]),n("precipitation-legend-cloud-cover",b[d]),a("legend",`background-color: ${g[d]};`);const T=document.getElementById("forecast"),k={id:"vert",defaults:{width:1,dash:[3,3]},afterInit:(e,t,n)=>{e.corsair={x:0,y:0}},afterDraw:(e,t,n)=>{if(e.tooltip?._active?.length){let t=e.tooltip._active[0].element.x,a=e.scales.y,i=e.ctx;i.save(),i.beginPath(),i.moveTo(t,a.top),i.lineTo(t,a.bottom),i.lineWidth=1,i.setLineDash(n.dash),i.strokeStyle="#fff",i.stroke(),i.restore()}if(d-I>H){const t=e.ctx,n=e.scales.x.getPixelForValue(d-I);t.save(),t.strokeStyle="#3b3b42",t.lineWidth=1,t.beginPath(),t.moveTo(n,0),t.lineTo(n,e.height),t.stroke(),t.fillStyle="#3b3b42",t.font="bold 1rem ui-sans-serif, system-ui, sans-serif",t.fillText("Now",d>14&&24===F?n-45:n+5,15),t.restore()}}};function B(e){let t;t=e>=p.length-s?p.length-s-1:e;const i=0===H?I:H,o=g[t+H];a("legend",`background-color: ${o}`),n("legend-label",p[t+i]),n("legend-quality",u[o]),n("legend-wave-height",m[t+i]),n("legend-wind-speed",w[t+i]),a("legend-wind-icon",`transform: rotate(${f[t+i]}deg);`),n("legend-wave-period",y[t+i]),n("legend-wind-gust",v[t+i]),n("temperature-legend-label",p[t+i]),n("temperature-legend-temperature",x[t+i]),n("temperature-legend-dewpoint",_[t+i]),n("precipitation-legend-label",p[t+i]),n("precipitation-legend-precipitation",E[t+i]),n("precipitation-legend-thunder",A[t+i]),n("precipitation-legend-cloud-cover",b[t+i])}const L=(e,t,n)=>{const a=Chart.helpers.getRelativePosition(e,n),i=function(e){return 24===F||48===F?e&&e>0?e>=m.length-H?m.length-H-1:e:0:e&&e>0?e>=m.length?m.length-1:e:0}(n.scales.x.getValueForPixel(a.x));B(i)},M=(e,t)=>{const n=0===H?I:H;return 24===F?t%6==0?p[t+n]:null:48===F?t%8==0?p[t+n]:null:t%24==0?p[t+n]:null};const S=()=>window.innerWidth<768?24:window.innerWidth<1024?48:m.length;let F=S(),H=0,C=H+F;const D={size:24===F?14:18,weight:24===F?"lighter":"semi-bold"},P=new Chart(T,{type:"bar",plugins:[k],data:{labels:0===H?p.slice(I,C):p.slice(H,C),datasets:[{label:"wave height (feet)",data:0===H?m.slice(I,C):m.slice(H,C),pointStyle:!1,minBarLength:.1}]},options:{onHover:L,borderRadius:5,maintainAspectRatio:!1,plugins:{legend:{display:!1},tooltip:{enabled:!1}},elements:{bar:{backgroundColor:e=>(e=>g[e.dataIndex+H])(e)||"#4ade80"}},responsive:!0,interaction:{intersect:!1,axis:"x"},scales:{x:{ticks:{callback:M}},y:{beginAtZero:!0,max:h,ticks:{callback:function(e){return e%2!=0?"":e},font:D}}}}});function R(e){n("forecast-range",e)}function N(){if(0===H){let e=s>20&&(new Date).getHours()>20;R(24===F?e?"Tomorrow":"Today":e?`Tomorrow - ${p[H+25].split(" ")[0]}`:"Today - Tomorrow")}else if(24===F)R(p[H].split(" ")[0]);else{const e=p[C-1]??p[p.length-1];R(`${p[H].split(" ")[0]} - ${e.split(" ")[0]}`)}}function O(){const e=0===H?I:H;let t=p.slice(e,C);P.data.labels=t,P.data.datasets[0].data=m.slice(e,C),P.update(),V.data.labels=t,V.data.datasets[0].data=x.slice(e,C),V.update(),G.data.labels=t,G.data.datasets[0].data=E.slice(e,C),G.update()}N(),window.addEventListener("resize",(()=>{F=S(),H+F>p.length?(C=p.length,H=p.length-F):C=H+F,O(),B(0),0===H&&(t(document.getElementById("forecast-backward")).disabled=!0),H+F=m.length&&(t(document.getElementById("forecast-foreward")).disabled=!0),H>0&&(t(document.getElementById("forecast-backward")).disabled=!1),N()})),document.getElementById("forecast-backward")?.addEventListener("click",(()=>{H-F<0?(H=0,C=F):(C-=F,H-=F),O(),B(0===H?d:0),0===H&&(t(document.getElementById("forecast-backward")).disabled=!0),H+F{C+F>p.length?(C=p.length,H=C-F):(H+=F,C+=F),O(),B(0),H+F>=m.length&&(t(document.getElementById("forecast-foreward")).disabled=!0),H>0&&(t(document.getElementById("forecast-backward")).disabled=!1),N()}));const W=(e,t,n,a)=>({type:"bar",plugins:[k],data:{labels:0===H?p.slice(I,C):p.slice(H,C),datasets:[{label:n,data:e,pointStyle:!1,minBarLength:.1}]},options:{stacked:!0,onHover:L,maintainAspectRatio:!1,borderRadius:5,plugins:{legend:{display:!1},tooltip:{enabled:!1}},elements:{bar:t?{backgroundColor:t,borderColor:t}:{}},responsive:!0,interaction:{intersect:!1,axis:"x"},scales:{x:{ticks:{callback:M}},y:{beginAtZero:!0,max:a,ticks:{font:D}}}}}),J=document.getElementById("temperature-forecast"),V=new Chart(J,W(0===H?x.slice(I,C):x.slice(H,C),"pink","F",100)),z=document.getElementById("precipitation-forecast"),G=new Chart(z,W(0===H?E.slice(I,C):E.slice(H,C),null,"%",100));function Z(e){const t=P.getElementsAtEventForMode(e,"nearest",{axis:"x",intersect:!1},!0);if(t[0]){const e=t[0].datasetIndex,n=t[0].index;V.tooltip.setActiveElements([{datasetIndex:e,index:n}]),V.setActiveElements([{datasetIndex:e,index:n}]),V.update(),G.tooltip.setActiveElements([{datasetIndex:e,index:n}]),G.setActiveElements([{datasetIndex:e,index:n}]),G.update()}else V.tooltip.setActiveElements([],{x:0,y:0}),V.setActiveElements([],{x:0,y:0}),V.update(),G.tooltip.setActiveElements([],{x:0,y:0}),G.setActiveElements([],{x:0,y:0}),G.update()}function U(e){const t=V.getElementsAtEventForMode(e,"nearest",{axis:"x",intersect:!1},!0);if(t[0]){const e=t[0].datasetIndex,n=t[0].index;P.tooltip.setActiveElements([{datasetIndex:e,index:n}]),P.setActiveElements([{datasetIndex:e,index:n}]),P.update(),G.tooltip.setActiveElements([{datasetIndex:e,index:n}]),G.setActiveElements([{datasetIndex:e,index:n}]),G.update()}else P.tooltip.setActiveElements([],{x:0,y:0}),P.setActiveElements([],{x:0,y:0}),P.update(),G.tooltip.setActiveElements([],{x:0,y:0}),G.setActiveElements([],{x:0,y:0}),G.update()}function j(e){const t=G.getElementsAtEventForMode(e,"nearest",{axis:"x",intersect:!1},!0);if(t[0]){const e=t[0].datasetIndex,n=t[0].index;V.tooltip.setActiveElements([{datasetIndex:e,index:n}]),V.setActiveElements([{datasetIndex:e,index:n}]),V.update(),P.tooltip.setActiveElements([{datasetIndex:e,index:n}]),P.setActiveElements([{datasetIndex:e,index:n}]),P.update()}else V.tooltip.setActiveElements([],{x:0,y:0}),V.setActiveElements([],{x:0,y:0}),V.update(),P.tooltip.setActiveElements([],{x:0,y:0}),P.setActiveElements([],{x:0,y:0}),P.update()}P.canvas.onmousemove=Z,V.canvas.onmousemove=U,G.canvas.onmousemove=j,P.canvas.ontouchmove=Z,V.canvas.ontouchmove=U,G.canvas.ontouchmove=j}const $=e(document.querySelector("body"));new MutationObserver((t=>{for(const u of t)if(u.target instanceof HTMLElement&&("latest-data"===u.target.id&&((c=JSON.parse(u.target.innerText)).wave_height&&(n("current-wave-height",c.wave_height),a("wave-icon",`transform: rotate(${c.wave_direction}deg);`),i(".wavey")),c.wave_period&&(n("current-wave-period",c.wave_period),o("wavey-period-loader")),(""===e(document.getElementById("wave-quality-text")).innerText||c.wave_height||parseFloat(e(document.getElementById("current-wave-height")).innerText??"0")>=1)&&(a("wave-quality",`background-color: ${c.quality_color};`),n("wave-quality-text",c.quality_text),a("wave-quality-text",`color: ${c.quality_color}`),i(".wave-quality-loader")),n("current-water-temp",c.water_temp),n("current-air-temp",c.air_temp),n("current-air-temp-2",c.air_temp),n("wind",d(c)),n("as-of",`As of ${c.as_of}`),a("wind-icon",`transform: rotate(${c.wind_direction+180}deg);`),i(".latest-loader"),r("wind-icon-container"),r("wave-icon-container"),l("as-of-container","animate-pulse"),r("wave-quality")),"water-quality-data"===u.target.id&&s(JSON.parse(u.target.innerText)),"forecast-data"===u.target.id))try{I(JSON.parse(u.target.innerText))}catch{console.log("failed to parse forecast, trying again."),setTimeout((()=>{if(u.target instanceof HTMLElement){I(JSON.parse(u.target.innerText))}}),100)}var c})).observe($,{attributes:!0,childList:!0,subtree:!0})}(); +!function(){"use strict";function e(e){if(null==e)throw"item is null or undefined";return e}function t(e){if(null==e)throw"item is null or undefined";if(e instanceof HTMLButtonElement)return e;throw"item is not a button"}function n(t,n){e(document.getElementById(t)).innerText=n}function a(e,t){!function(e,t,n){document.getElementById(e)?.setAttribute(t,n)}(e,"style",t)}function i(e){document.querySelectorAll(e).forEach((e=>e.remove()))}function o(e){document.getElementById(e)?.remove()}function l(e,t){document.getElementById(e)?.classList.remove(t)}function r(e){l(e,"hidden")}function s(e){r(`current-water-quality-${e.water_quality.toLowerCase()}`),n(`current-water-quality-${e.water_quality.toLowerCase()}-status-text`,e.water_quality_text),i(".water-quality-loader")}const d=e=>e.wind_speed===e.gusts||"0"===e.gusts?e.wind_speed:`${e.wind_speed}-${e.gusts}`,c="#a8a29e",u={"#0bd674":"Good","#ffcd1e":"Fair to Good","#ff9500":"Poor","#f4496d":"Very Poor","#a8a29e":"Flat"};let g,p,m,w,f,v,y,h,x,_,b,E,A;function I(e){h=e.graph_max;const s=new Date(e.starting_at).getHours();if(s>20){let t=24-s;const n=p.length-(p.length-t)%24;p=e.wave_height_labels.slice(t,n),g=e.qualities.slice(t,n),m=e.wave_height_data.slice(t,n),w=e.wind_speed_data.slice(t,n),f=e.wind_direction_data.slice(t,n),v=e.wind_gust_data.slice(t,n),y=e.wave_period_data.slice(t,n),x=e.temperature.slice(t,n),_=e.dewpoint.slice(t,n),b=e.cloud_cover.slice(t,n),E=e.probability_of_precipitation.slice(t,n),A=e.probability_of_thunder.slice(t,n)}else{const t=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][new Date(e.starting_at).getDay()],n=[];for(let e=0;e=10&&e<12&&n.push(`${t} ${e} AM`),12===e&&n.push(`${t} ${e} PM`),e>12&&n.push(`${t} 0${e-12} PM`)):n.push(`${t} 12 AM`);const a=e.wave_height_labels.length+s-(e.wave_height_labels.length+s)%24;p=n.concat(e.wave_height_labels).slice(0,a),g=new Array(s).fill("#a8a29e").concat(e.qualities).slice(0,a),m=new Array(s).fill(0).concat(e.wave_height_data).slice(0,a),w=new Array(s).fill(0).concat(e.wind_speed_data).slice(0,a),f=new Array(s).fill(0).concat(e.wind_direction_data).slice(0,a),v=new Array(s).fill(0).concat(e.wind_gust_data).slice(0,a),y=new Array(s).fill(0).concat(e.wave_period_data).slice(0,a),x=new Array(s).fill(0).concat(e.temperature).slice(0,a),_=new Array(s).fill(0).concat(e.dewpoint).slice(0,a),b=new Array(s).fill(0).concat(e.cloud_cover).slice(0,a),E=new Array(s).fill(0).concat(e.probability_of_precipitation).slice(0,a),A=new Array(s).fill(0).concat(e.probability_of_thunder).slice(0,a)}let d=(new Date).getHours();const I=new Date(e.starting_at).getHours();d=d<0?(new Date).getHours():d;const $=document.getElementById("current-wave-height");""===$?.innerText&&($.innerText=e.current_wave_height,"0"==e.current_wave_height&&(a("wave-quality",`background-color: ${c}`),n("wave-quality-text",u[c]),a("wave-quality-text",`color: ${c}`),i(".wave-quality-loader")),a("wave-icon",`transform: rotate(${e.current_wave_direction}deg);`),i(".wavey"));const q=document.getElementById("current-wave-period");""===q?.innerText&&(q.innerText=e.current_wave_period,o("wavey-period-loader")),n("legend-label",p[d]),n("legend-quality",u[g[d]]),n("legend-wave-height",m[d]),n("legend-wind-speed",w[d]),a("legend-wind-icon",`transform: rotate(${f[d]}deg);`),n("legend-wave-period",y[d]),n("legend-wind-gust",v[d]),n("forecast-as-of",`Updated @ ${e.forecast_as_of}`),n("forecast-as-of-2",`Forecast Last Ran @ ${e.forecast_as_of}`),i(".loader"),r("forecast"),r("wave-quality"),r("legend-container"),l("forecast-as-of-container","animate-pulse"),l("forecast-as-of-container-2","animate-pulse"),r("temperature-legend-container"),n("temperature-legend-label",p[d]),n("temperature-legend-temperature",x[d]),n("temperature-legend-dewpoint",_[d]),r("precipitation-legend-container"),n("precipitation-legend-label",p[d]),n("precipitation-legend-precipitation",E[d]),n("precipitation-legend-thunder",A[d]),n("precipitation-legend-cloud-cover",b[d]),a("legend",`background-color: ${g[d]};`);const T=document.getElementById("forecast"),k={id:"vert",defaults:{width:1,dash:[3,3]},afterInit:(e,t,n)=>{e.corsair={x:0,y:0}},afterDraw:(e,t,n)=>{if(e.tooltip?._active?.length){let t=e.tooltip._active[0].element.x,a=e.scales.y,i=e.ctx;i.save(),i.beginPath(),i.moveTo(t,a.top),i.lineTo(t,a.bottom),i.lineWidth=1,i.setLineDash(n.dash),i.strokeStyle="#fff",i.stroke(),i.restore()}if(d-I>H){const t=e.ctx,n=e.scales.x.getPixelForValue(d-I);t.save(),t.strokeStyle="#3b3b42",t.lineWidth=1,t.beginPath(),t.moveTo(n,0),t.lineTo(n,e.height),t.stroke(),t.fillStyle="#3b3b42",t.font="bold 1rem ui-sans-serif, system-ui, sans-serif",t.fillText("Now",d>14&&24===F?n-45:n+5,15),t.restore()}}};function B(e){let t;t=e>=p.length-s?p.length-s-1:e;const i=0===H?I:H,o=g[t+H];a("legend",`background-color: ${o}`),n("legend-label",p[t+i]),n("legend-quality",u[o]),n("legend-wave-height",m[t+i]),n("legend-wind-speed",w[t+i]),a("legend-wind-icon",`transform: rotate(${f[t+i]}deg);`),n("legend-wave-period",y[t+i]),n("legend-wind-gust",v[t+i]),n("temperature-legend-label",p[t+i]),n("temperature-legend-temperature",x[t+i]),n("temperature-legend-dewpoint",_[t+i]),n("precipitation-legend-label",p[t+i]),n("precipitation-legend-precipitation",E[t+i]),n("precipitation-legend-thunder",A[t+i]),n("precipitation-legend-cloud-cover",b[t+i])}const L=(e,t,n)=>{const a=Chart.helpers.getRelativePosition(e,n),i=function(e){return 24===F||48===F?e&&e>0?e>=m.length-H?m.length-H-1:e:0:e&&e>0?e>=m.length?m.length-1:e:0}(n.scales.x.getValueForPixel(a.x));B(i)},M=(e,t)=>{const n=0===H?I:H;return 24===F?t%6==0?p[t+n]:null:48===F?t%8==0?p[t+n]:null:t%24==0?p[t+n]:null};const S=()=>window.innerWidth<768?24:window.innerWidth<1024?48:m.length;let F=S(),H=0,C=H+F;const D={size:24===F?14:18,weight:24===F?"lighter":"semi-bold"},P=new Chart(T,{type:"bar",plugins:[k],data:{labels:0===H?p.slice(I,C):p.slice(H,C),datasets:[{label:"wave height (feet)",data:0===H?m.slice(I,C):m.slice(H,C),pointStyle:!1,minBarLength:.1}]},options:{onHover:L,borderRadius:5,maintainAspectRatio:!1,plugins:{legend:{display:!1},tooltip:{enabled:!1}},elements:{bar:{backgroundColor:e=>(e=>0===H?g[e.dataIndex+I]:g[e.dataIndex+H])(e)||"#4ade80"}},responsive:!0,interaction:{intersect:!1,axis:"x"},scales:{x:{ticks:{callback:M}},y:{beginAtZero:!0,max:h,ticks:{callback:function(e){return e%2!=0?"":e},font:D}}}}});function R(e){n("forecast-range",e)}function N(){if(0===H){let e=s>20&&(new Date).getHours()>20;R(24===F?e?"Tomorrow":"Today":e?`Tomorrow - ${p[H+25].split(" ")[0]}`:"Today - Tomorrow")}else if(24===F)R(p[H].split(" ")[0]);else{const e=p[C-1]??p[p.length-1];R(`${p[H].split(" ")[0]} - ${e.split(" ")[0]}`)}}function O(){const e=0===H?I:H;let t=p.slice(e,C);P.data.labels=t,P.data.datasets[0].data=m.slice(e,C),P.update(),V.data.labels=t,V.data.datasets[0].data=x.slice(e,C),V.update(),G.data.labels=t,G.data.datasets[0].data=E.slice(e,C),G.update()}N(),window.addEventListener("resize",(()=>{F=S(),H+F>p.length?(C=p.length,H=p.length-F):C=H+F,O(),B(0),0===H&&(t(document.getElementById("forecast-backward")).disabled=!0),H+F=m.length&&(t(document.getElementById("forecast-foreward")).disabled=!0),H>0&&(t(document.getElementById("forecast-backward")).disabled=!1),N()})),document.getElementById("forecast-backward")?.addEventListener("click",(()=>{H-F<0?(H=0,C=F):(C-=F,H-=F),O(),B(0===H?d:0),0===H&&(t(document.getElementById("forecast-backward")).disabled=!0),H+F{C+F>p.length?(C=p.length,H=C-F):(H+=F,C+=F),O(),B(0),H+F>=m.length&&(t(document.getElementById("forecast-foreward")).disabled=!0),H>0&&(t(document.getElementById("forecast-backward")).disabled=!1),N()}));const W=(e,t,n,a)=>({type:"bar",plugins:[k],data:{labels:0===H?p.slice(I,C):p.slice(H,C),datasets:[{label:n,data:e,pointStyle:!1,minBarLength:.1}]},options:{stacked:!0,onHover:L,maintainAspectRatio:!1,borderRadius:5,plugins:{legend:{display:!1},tooltip:{enabled:!1}},elements:{bar:t?{backgroundColor:t,borderColor:t}:{}},responsive:!0,interaction:{intersect:!1,axis:"x"},scales:{x:{ticks:{callback:M}},y:{beginAtZero:!0,max:a,ticks:{font:D}}}}}),J=document.getElementById("temperature-forecast"),V=new Chart(J,W(0===H?x.slice(I,C):x.slice(H,C),"pink","F",100)),z=document.getElementById("precipitation-forecast"),G=new Chart(z,W(0===H?E.slice(I,C):E.slice(H,C),null,"%",100));function Z(e){const t=P.getElementsAtEventForMode(e,"nearest",{axis:"x",intersect:!1},!0);if(t[0]){const e=t[0].datasetIndex,n=t[0].index;V.tooltip.setActiveElements([{datasetIndex:e,index:n}]),V.setActiveElements([{datasetIndex:e,index:n}]),V.update(),G.tooltip.setActiveElements([{datasetIndex:e,index:n}]),G.setActiveElements([{datasetIndex:e,index:n}]),G.update()}else V.tooltip.setActiveElements([],{x:0,y:0}),V.setActiveElements([],{x:0,y:0}),V.update(),G.tooltip.setActiveElements([],{x:0,y:0}),G.setActiveElements([],{x:0,y:0}),G.update()}function U(e){const t=V.getElementsAtEventForMode(e,"nearest",{axis:"x",intersect:!1},!0);if(t[0]){const e=t[0].datasetIndex,n=t[0].index;P.tooltip.setActiveElements([{datasetIndex:e,index:n}]),P.setActiveElements([{datasetIndex:e,index:n}]),P.update(),G.tooltip.setActiveElements([{datasetIndex:e,index:n}]),G.setActiveElements([{datasetIndex:e,index:n}]),G.update()}else P.tooltip.setActiveElements([],{x:0,y:0}),P.setActiveElements([],{x:0,y:0}),P.update(),G.tooltip.setActiveElements([],{x:0,y:0}),G.setActiveElements([],{x:0,y:0}),G.update()}function j(e){const t=G.getElementsAtEventForMode(e,"nearest",{axis:"x",intersect:!1},!0);if(t[0]){const e=t[0].datasetIndex,n=t[0].index;V.tooltip.setActiveElements([{datasetIndex:e,index:n}]),V.setActiveElements([{datasetIndex:e,index:n}]),V.update(),P.tooltip.setActiveElements([{datasetIndex:e,index:n}]),P.setActiveElements([{datasetIndex:e,index:n}]),P.update()}else V.tooltip.setActiveElements([],{x:0,y:0}),V.setActiveElements([],{x:0,y:0}),V.update(),P.tooltip.setActiveElements([],{x:0,y:0}),P.setActiveElements([],{x:0,y:0}),P.update()}P.canvas.onmousemove=Z,V.canvas.onmousemove=U,G.canvas.onmousemove=j,P.canvas.ontouchmove=Z,V.canvas.ontouchmove=U,G.canvas.ontouchmove=j}const $=e(document.querySelector("body"));new MutationObserver((t=>{for(const u of t)if(u.target instanceof HTMLElement&&("latest-data"===u.target.id&&((c=JSON.parse(u.target.innerText)).wave_height&&(n("current-wave-height",c.wave_height),a("wave-icon",`transform: rotate(${c.wave_direction}deg);`),i(".wavey")),c.wave_period&&(n("current-wave-period",c.wave_period),o("wavey-period-loader")),(""===e(document.getElementById("wave-quality-text")).innerText||c.wave_height||parseFloat(e(document.getElementById("current-wave-height")).innerText??"0")>=1)&&(a("wave-quality",`background-color: ${c.quality_color};`),n("wave-quality-text",c.quality_text),a("wave-quality-text",`color: ${c.quality_color}`),i(".wave-quality-loader")),n("current-water-temp",c.water_temp),n("current-air-temp",c.air_temp),n("current-air-temp-2",c.air_temp),n("wind",d(c)),n("as-of",`As of ${c.as_of}`),a("wind-icon",`transform: rotate(${c.wind_direction+180}deg);`),i(".latest-loader"),r("wind-icon-container"),r("wave-icon-container"),l("as-of-container","animate-pulse"),r("wave-quality")),"water-quality-data"===u.target.id&&s(JSON.parse(u.target.innerText)),"forecast-data"===u.target.id))try{I(JSON.parse(u.target.innerText))}catch{console.log("failed to parse forecast, trying again."),setTimeout((()=>{if(u.target instanceof HTMLElement){I(JSON.parse(u.target.innerText))}}),100)}var c})).observe($,{attributes:!0,childList:!0,subtree:!0})}(); diff --git a/client/parseForecast.js b/client/parseForecast.js index 0eb6851..7f9b08b 100644 --- a/client/parseForecast.js +++ b/client/parseForecast.js @@ -248,7 +248,10 @@ export function parseForecast(data) { const ctx = document.getElementById("forecast"); - const quality = (ctx) => qualities[ctx.dataIndex + start]; + const quality = (ctx) => + start === 0 + ? qualities[ctx.dataIndex + dataStartingAt] + : qualities[ctx.dataIndex + start]; const plugin = { id: "vert",