commit b50c4f87aae9db761e101dd5198b5926ae969864
parent bfba122f7515e028967ac8564eb831d1e3f4a231
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Wed, 7 Oct 2026 17:56:10 +0530
parent bfba122f7515e028967ac8564eb831d1e3f4a231
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Wed, 7 Oct 2026 17:56:10 +0530
Boost amber axis only in light theme
3 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/out/tva-control.js b/out/tva-control.js @@ -1,5 +1,5 @@ -(()=>{(function(){function d(r,u=0){let a=Number(r);return Number.isFinite(a)?a:u}function X(r,u,a){return Math.max(u,Math.min(a,r))}function ce(r){return JSON.parse(JSON.stringify(r))}function Y(r){return String(r).replace(/-([a-z])/g,(u,a)=>a.toUpperCase())}function de(r){return String(r).replace(/[&<>"]/g,u=>({"&":"&","<":"<",">":">",'"':"""})[u])}function A(r,u){if(String(r).startsWith("#")&&r.length===7){let a=parseInt(r.slice(1,3),16),n=parseInt(r.slice(3,5),16),h=parseInt(r.slice(5,7),16);return`rgba(${a},${n},${h},${u})`}return r}function ee(r){return(Array.isArray(r)?r:r&&typeof r=="object"?Object.entries(r).map(([a,n])=>({name:a,days:n})):[]).map((a,n)=>({name:String(a.name||a.area||a.areaName||`Area ${n+1}`).trim(),days:d(a.days??a.pendencyDays??a.refillSpreadDays??a.currentDays)})).filter(a=>a.name)}function ue(r,u,a=15){if(!Number.isFinite(r)||!Number.isFinite(u))return"flat";let n=u-r;return n>=a?"up":n<=-a?"down":"flat"}function fe(r,u,a=Date.now()){return u?r?a-r>u:!0:!1}function z(r,u,a={}){if(!u)return r;let n={...r};return Object.entries(u).forEach(([h,i])=>{if(i==null||h==="type")return;let f=a[h]||h;f==="colors"&&i&&typeof i=="object"?n.colors={...n.colors||{},...i}:f==="metricFreshnessMinutes"&&i&&typeof i=="object"?n.metricFreshnessMinutes={...n.metricFreshnessMinutes||{},...i}:f.endsWith("Areas")?n[f]=ee(i):typeof n[f]=="number"?n[f]=d(i,n[f]):n[f]=i}),n}let me={normal:"#4f646e",stale:"#4f646e",disabled:"#777777"},te={staleText:null,neutralGradientMid:"#879aa3",staleLabelFill:null,normalLabelFill:null,normalLabelStroke:null,grid:null,detailGrid:null,tick:null,detailTick:null,transparent:"rgba(0,0,0,0)",white:"#fff",plotIcon:null};function S(r,u,a=!1){r.beginPath(),u.forEach(([n,h],i)=>i?r.lineTo(n,h):r.moveTo(n,h)),a&&r.closePath(),r.stroke()}function Ie(r,u,a,n,h){r.save(),r.strokeStyle=h,r.fillStyle=h,r.lineWidth=1.25,r.lineCap="round",r.lineJoin="round",u==="invoice"?(r.strokeRect(a-5,n+1,10,11.5),[4,7,10].forEach(i=>S(r,[[a-3,n+i],[a+3,n+i]]))):u==="person"?(r.beginPath(),r.arc(a,n+3.8,2.8,0,Math.PI*2),r.stroke(),r.beginPath(),r.moveTo(a-5,n+12),r.quadraticCurveTo(a,n+7.6,a+5,n+12),r.stroke()):u==="calendar"?(r.strokeRect(a-5,n+3,10,10),S(r,[[a-5,n+6],[a+5,n+6]]),S(r,[[a-2.8,n+1],[a-2.8,n+4]]),S(r,[[a+2.8,n+1],[a+2.8,n+4]]),r.fillRect(a-2.8,n+8,1.3,1.3),r.fillRect(a+1.5,n+8,1.3,1.3)):u==="deposit"?(r.strokeRect(a-5,n+4,10,8),S(r,[[a-6,n+4],[a,n+.5],[a+6,n+4]]),S(r,[[a-3,n+7],[a+3,n+7]]),S(r,[[a-3,n+10],[a+3,n+10]])):u==="hourglass"?S(r,[[a-5,n+1],[a+5,n+1],[a-5,n+12.5],[a+5,n+12.5]],!0):(S(r,[[a,n],[a-5.5,n+10.5],[a+5.5,n+10.5]],!0),S(r,[[a,n+3.5],[a,n+7.2]]),r.beginPath(),r.arc(a,n+9.2,.6,0,Math.PI*2),r.fill()),r.restore()}window.TvaControlInternals={getTrend:ue,isStale:fe,mergeData:z,normalizeAreas:ee},window.createTvaControl=function({canvas:u,container:a,config:n={},data:h={}}){!u&&a&&(u=a.querySelector("canvas")||a.appendChild(document.createElement("canvas"))),a=a||u.closest(".tva-control-container, .action-chart-container")||u.parentElement,a.classList.add("tva-control-container");let i=n&&Object.keys(n).length?n:h.init||{},f=i.parameters||[],B=i.warningLevels||[];if(!f.length)throw new Error("createTvaControl requires init.parameters");if(!B.length)throw new Error("createTvaControl requires init.warningLevels");let j=i.aliases||{},ae=f.map(e=>e.label),_=f.map(e=>e.key),q=B.filter(e=>e.showAxis!==!1).length*2+(i.extraAxes||[]).length,pe=()=>({colors:{...me,...i.colors||{}},uiColors:{...te,...i.uiColors||{}},staleAlpha:.35,trendThreshold:15}),s=z(pe(),h,j),re=e=>getComputedStyle(a).getPropertyValue(e).trim();function V(){let e=i.uiColors||{},t=(o,l,c)=>e[o]||re(l)||c;s.colors.normal=i.colors&&i.colors.normal?i.colors.normal:re("--tva-normal-line")||me.normal,s.colors.stale=i.colors&&i.colors.stale?i.colors.stale:re("--tva-stale-line")||s.colors.normal,s.uiColors={...te,...e,grid:t("grid","--tva-chart-grid","#222"),detailGrid:t("detailGrid","--tva-chart-detail-grid","#242424"),tick:t("tick","--tva-axis-text","#fff"),detailTick:t("detailTick","--tva-detail-axis-text","#aaa"),plotIcon:t("plotIcon","--tva-plot-icon",e.white||te.white),staleText:t("staleText","--tva-stale-text","#9aa6ac"),staleLabelFill:t("staleLabelFill","--tva-stale-label-fill","rgba(2,6,8,.84)"),normalLabelFill:t("normalLabelFill","--tva-normal-label-fill","rgba(5,34,30,.62)"),normalLabelStroke:t("normalLabelStroke","--tva-normal-label-stroke","rgba(116,137,148,.44)")}}V();let b=null,v="timeline",H=!0,L=0,x=1,J=null,R=Object.fromEntries(_.map(e=>[e,Date.now()]));h.updatedAt&&Object.entries(h.updatedAt).forEach(([e,t])=>{let o=typeof t=="string"?Date.parse(t):d(t,NaN);Number.isFinite(o)&&(R[e]=o)});let D=document.createElement("div");D.className="tva-chart-controls";let we=[{key:"timeline",label:i.title||"Timeline"},...f.filter(e=>e.detailMode).map(e=>({key:e.detailMode,label:e.detailTitle||`${e.label} Area Scan`}))].map(e=>`<option value="${de(e.key)}">${de(e.label)}</option>`).join("");D.innerHTML=` +(()=>{(function(){function d(r,u=0){let a=Number(r);return Number.isFinite(a)?a:u}function Y(r,u,a){return Math.max(u,Math.min(a,r))}function ce(r){return JSON.parse(JSON.stringify(r))}function ee(r){return String(r).replace(/-([a-z])/g,(u,a)=>a.toUpperCase())}function de(r){return String(r).replace(/[&<>"]/g,u=>({"&":"&","<":"<",">":">",'"':"""})[u])}function A(r,u){if(String(r).startsWith("#")&&r.length===7){let a=parseInt(r.slice(1,3),16),n=parseInt(r.slice(3,5),16),h=parseInt(r.slice(5,7),16);return`rgba(${a},${n},${h},${u})`}return r}function te(r){return(Array.isArray(r)?r:r&&typeof r=="object"?Object.entries(r).map(([a,n])=>({name:a,days:n})):[]).map((a,n)=>({name:String(a.name||a.area||a.areaName||`Area ${n+1}`).trim(),days:d(a.days??a.pendencyDays??a.refillSpreadDays??a.currentDays)})).filter(a=>a.name)}function ue(r,u,a=15){if(!Number.isFinite(r)||!Number.isFinite(u))return"flat";let n=u-r;return n>=a?"up":n<=-a?"down":"flat"}function fe(r,u,a=Date.now()){return u?r?a-r>u:!0:!1}function x(r,u,a={}){if(!u)return r;let n={...r};return Object.entries(u).forEach(([h,i])=>{if(i==null||h==="type")return;let f=a[h]||h;f==="colors"&&i&&typeof i=="object"?n.colors={...n.colors||{},...i}:f==="metricFreshnessMinutes"&&i&&typeof i=="object"?n.metricFreshnessMinutes={...n.metricFreshnessMinutes||{},...i}:f.endsWith("Areas")?n[f]=te(i):typeof n[f]=="number"?n[f]=d(i,n[f]):n[f]=i}),n}let me={normal:"#4f646e",stale:"#4f646e",disabled:"#777777"},ae={staleText:null,neutralGradientMid:"#879aa3",staleLabelFill:null,normalLabelFill:null,normalLabelStroke:null,grid:null,detailGrid:null,tick:null,detailTick:null,transparent:"rgba(0,0,0,0)",white:"#fff",plotIcon:null};function S(r,u,a=!1){r.beginPath(),u.forEach(([n,h],i)=>i?r.lineTo(n,h):r.moveTo(n,h)),a&&r.closePath(),r.stroke()}function we(r,u,a,n,h){r.save(),r.strokeStyle=h,r.fillStyle=h,r.lineWidth=1.25,r.lineCap="round",r.lineJoin="round",u==="invoice"?(r.strokeRect(a-5,n+1,10,11.5),[4,7,10].forEach(i=>S(r,[[a-3,n+i],[a+3,n+i]]))):u==="person"?(r.beginPath(),r.arc(a,n+3.8,2.8,0,Math.PI*2),r.stroke(),r.beginPath(),r.moveTo(a-5,n+12),r.quadraticCurveTo(a,n+7.6,a+5,n+12),r.stroke()):u==="calendar"?(r.strokeRect(a-5,n+3,10,10),S(r,[[a-5,n+6],[a+5,n+6]]),S(r,[[a-2.8,n+1],[a-2.8,n+4]]),S(r,[[a+2.8,n+1],[a+2.8,n+4]]),r.fillRect(a-2.8,n+8,1.3,1.3),r.fillRect(a+1.5,n+8,1.3,1.3)):u==="deposit"?(r.strokeRect(a-5,n+4,10,8),S(r,[[a-6,n+4],[a,n+.5],[a+6,n+4]]),S(r,[[a-3,n+7],[a+3,n+7]]),S(r,[[a-3,n+10],[a+3,n+10]])):u==="hourglass"?S(r,[[a-5,n+1],[a+5,n+1],[a-5,n+12.5],[a+5,n+12.5]],!0):(S(r,[[a,n],[a-5.5,n+10.5],[a+5.5,n+10.5]],!0),S(r,[[a,n+3.5],[a,n+7.2]]),r.beginPath(),r.arc(a,n+9.2,.6,0,Math.PI*2),r.fill()),r.restore()}window.TvaControlInternals={getTrend:ue,isStale:fe,mergeData:x,normalizeAreas:te},window.createTvaControl=function({canvas:u,container:a,config:n={},data:h={}}){!u&&a&&(u=a.querySelector("canvas")||a.appendChild(document.createElement("canvas"))),a=a||u.closest(".tva-control-container, .action-chart-container")||u.parentElement,a.classList.add("tva-control-container");let i=n&&Object.keys(n).length?n:h.init||{},f=i.parameters||[],B=i.warningLevels||[];if(!f.length)throw new Error("createTvaControl requires init.parameters");if(!B.length)throw new Error("createTvaControl requires init.warningLevels");let j=i.aliases||{},re=f.map(e=>e.label),_=f.map(e=>e.key),q=B.filter(e=>e.showAxis!==!1).length*2+(i.extraAxes||[]).length,pe=()=>({colors:{...me,...i.colors||{}},uiColors:{...ae,...i.uiColors||{}},staleAlpha:.35,trendThreshold:15}),s=x(pe(),h,j),W=e=>getComputedStyle(a).getPropertyValue(e).trim();function V(){let e=i.uiColors||{},t=(o,l,c)=>e[o]||W(l)||c;s.colors.normal=i.colors&&i.colors.normal?i.colors.normal:W("--tva-normal-line")||me.normal,s.colors.stale=i.colors&&i.colors.stale?i.colors.stale:W("--tva-stale-line")||s.colors.normal,s.uiColors={...ae,...e,grid:t("grid","--tva-chart-grid","#222"),detailGrid:t("detailGrid","--tva-chart-detail-grid","#242424"),tick:t("tick","--tva-axis-text","#fff"),detailTick:t("detailTick","--tva-detail-axis-text","#aaa"),plotIcon:t("plotIcon","--tva-plot-icon",e.white||ae.white),staleText:t("staleText","--tva-stale-text","#9aa6ac"),staleLabelFill:t("staleLabelFill","--tva-stale-label-fill","rgba(2,6,8,.84)"),normalLabelFill:t("normalLabelFill","--tva-normal-label-fill","rgba(5,34,30,.62)"),normalLabelStroke:t("normalLabelStroke","--tva-normal-label-stroke","rgba(116,137,148,.44)")}}V();let b=null,v="timeline",H=!0,L=0,J=1,K=null,R=Object.fromEntries(_.map(e=>[e,Date.now()]));h.updatedAt&&Object.entries(h.updatedAt).forEach(([e,t])=>{let o=typeof t=="string"?Date.parse(t):d(t,NaN);Number.isFinite(o)&&(R[e]=o)});let D=document.createElement("div");D.className="tva-chart-controls";let Ie=[{key:"timeline",label:i.title||"Timeline"},...f.filter(e=>e.detailMode).map(e=>({key:e.detailMode,label:e.detailTitle||`${e.label} Area Scan`}))].map(e=>`<option value="${de(e.key)}">${de(e.label)}</option>`).join("");D.innerHTML=` <button type="button" class="tva-chart-back" hidden>\u2190</button> - <label class="tva-chart-heading"><span class="sr-only">Chart type</span><select class="tva-chart-mode-select">${we}</select></label> + <label class="tva-chart-heading"><span class="sr-only">Chart type</span><select class="tva-chart-mode-select">${Ie}</select></label> <button type="button" class="tva-chart-fullscreen" title="Fullscreen chart" aria-label="Fullscreen chart"><span class="tva-fullscreen-icon" aria-hidden="true"></span></button> - `;let P=document.createElement("div");P.className="tva-alert-badge",P.hidden=!0,a.querySelector(".tva-chart-controls")||a.prepend(D),a.querySelector(".tva-alert-badge")||a.prepend(P),D.querySelector(".tva-chart-back").onclick=()=>se("timeline"),D.querySelector(".tva-chart-mode-select").onchange=e=>se(e.target.value),D.querySelector(".tva-chart-fullscreen").onclick=()=>{a.classList.toggle("tva-chart-fullscreen-mode"),ne(),b&&b.resize(),b&&b.update("none")};function be(e){return d(s[e.key],d(e.defaultValue))}function le(e,t,o,l){return d(e.thresholds&&e.thresholds[`${Y(t.key)}${o}`],l)}function Se(e){let t=be(e);return e.scale==="count10"?X(t*10,-100,100):e.scale==="daysCritical"?X(t/d(e.scaleBase,10)*100,0,d(e.scaleMax,165)):e.scale==="pendency"?t<=d(e.scaleIdeal,1)?0:X(t/d(e.scaleBase,3)*100,0,d(e.scaleMax,115)):t}function y(){return f.map(Se)}function I(e){return fe(R[f[e].key],d(f[e].refreshMinutes,0)*6e4)}function E(e){return s.colors[e.key]||s.colors[Y(e.key)]||s.colors.normal}function O(e,t){let o=null;return B.forEach(l=>{(t>le(f[e],l,"Upper",1/0)||t<le(f[e],l,"Lower",-1/0))&&(o=l)}),o}function K(e=!1){return e?s.colors.stale:A(s.colors.stale,d(s.staleAlpha,.35))}function Z(e,t){if(I(e))return K(!1);let o=O(e,t);return o?E(o):s.colors.normal}function he(e){let t=be(e),o=e.display||{},l=Number.isInteger(o.decimals)?o.decimals:0,c=Number.isInteger(t)||l===0?String(Math.round(t)):t.toFixed(l);return`${o.prefix||""}${c}${o.suffix||""}`}function oe(e){let t=y();return ue(J&&J[e],t[e],d(s.trendThreshold,15))}function ge(e){let t=Math.min(0,...e),o=Math.max(0,...e);t===o&&(t-=10,o+=10);let l=Math.max(8,(o-t)*.24);return{min:Math.floor(t-l),max:Math.ceil(o+l)}}function De(e){let t=y(),o=Z(e.p0DataIndex,t[e.p0DataIndex]),l=Z(e.p1DataIndex,t[e.p1DataIndex]);if(o===l||!e.p0||!e.p1)return l;let c=e.chart.ctx.createLinearGradient(e.p0.x,e.p0.y,e.p1.x,e.p1.y),m=I(e.p0DataIndex),g=I(e.p1DataIndex);if(m||g){let p=K(!1),M=K(!0),k=.12;return[[0,p],[Math.max(0,L-k),p],[L,M],[Math.min(1,L+k),p],[1,p]].sort((C,ie)=>C[0]-ie[0]).forEach(([C,ie])=>c.addColorStop(C,ie)),c}c.addColorStop(0,o);let T=O(e.p0DataIndex,t[e.p0DataIndex]),F=O(e.p1DataIndex,t[e.p1DataIndex]),w=T&&d(T.dominance,0),N=F&&d(F.dominance,0);return w?c.addColorStop(w,o):N?c.addColorStop(1-N,l):c.addColorStop(.5,s.uiColors.neutralGradientMid),c.addColorStop(1,l),c}let W=i.ambientGlow||{};function Ae(){return W.enabled!==!1&&W.enabled!==0}function Le(e){return e&&e.ambientGlow!==!1&&e.glow!==!1}function Me(e){if(v!=="timeline"||!Ae())return;let t=e.getDatasetMeta(q);if(!t||!e.chartArea)return;let o=y(),l=e.ctx;l.save(),l.beginPath(),l.rect(0,0,e.width,e.height),l.clip(),t.data.forEach((c,m)=>{if(I(m))return;let g=O(m,o[m]);if(!Le(g))return;let{x:T,y:F}=c.getProps(["x","y"],!0),w=g.glowColor||E(g),N=d(g.glowRadius,d(W.radius,72)),p=d(g.glowBlur,d(W.blur,36)),M=d(g.glowAlpha,d(W.alpha,.16)),k=N+p,C=l.createRadialGradient(T,F,0,T,F,k);C.addColorStop(0,A(w,M)),C.addColorStop(.34,A(w,M*.42)),C.addColorStop(.72,A(w,M*.12)),C.addColorStop(1,A(w,0)),l.fillStyle=C,l.fillRect(T-k,F-k,k*2,k*2)}),l.restore()}let Te={id:"tvaAmbientGlow",beforeDraw:Me},Fe={id:"tvaZeroAxis",beforeDatasetsDraw(e){if(v!=="timeline")return;let t=e.scales.y;if(!t)return;let o=t.getPixelForValue(0),l=e.ctx;l.save(),l.strokeStyle=A(s.colors.normal,.48),l.lineWidth=1.5,l.beginPath(),l.moveTo(0,o),l.lineTo(e.width,o),l.stroke(),l.restore()}};function Pe(e,t,o,l){let c=f[o],m=I(o),g=!m&&O(o,l[o]),T=g&&g.blink!==!1&&g.key!==B[0].key,{x:F,y:w}=t.getProps(["x","y"],!0),N=m?"STALE":he(c),p=e.ctx,M=w-e.chartArea.top<52?w+18:w-43;p.save(),p.globalAlpha=m?.72:T?H?1:.38:1,p.font="bold 9px monospace";let k=Math.max(28,p.measureText(N).width+10),C=Math.min(Math.max(F-k/2,e.chartArea.left+2),e.chartArea.right-k-2);p.fillStyle=m?s.uiColors.staleLabelFill:g?A(E(g),.18):s.uiColors.normalLabelFill,p.strokeStyle=m?K(!1):g?E(g):s.uiColors.normalLabelStroke,p.beginPath(),p.rect(C,M,k,31),p.fill(),p.stroke(),Ie(p,c.icon||"warning",C+k/2,M+3,m?s.uiColors.staleText:s.uiColors.plotIcon),p.fillStyle=m?s.uiColors.staleText:s.uiColors.plotIcon,p.textAlign="center",p.textBaseline="middle",p.fillText(N,C+k/2,M+24),p.restore()}let Ee={id:"tvaLabels",afterDatasetsDraw(e){if(v!=="timeline")return;let t=e.getDatasetMeta(q);if(!t)return;let o=y();t.data.forEach((l,c)=>Pe(e,l,c,o))}};function Oe(e,t){return f.map(o=>le(o,e,t,t==="Upper"?1/0:-1/0))}function $e(){return B.filter(e=>e.showAxis!==!1).flatMap(e=>["Upper","Lower"].map(t=>({label:`${e.label||e.key} ${t}`,data:Oe(e,t),borderColor:A(E(e),d(e.axisAlpha,.35)),borderWidth:d(e.axisWidth,1.6),borderDash:e.axisDash||[4,5],pointRadius:0,tension:.4})))}function Ge(){return(i.extraAxes||[]).map(e=>({label:e.label,data:f.map(t=>t.key===e.parameterKey?d(e.value):null),borderColor:e.color||s.colors.normal,borderWidth:d(e.width,1.4),borderDash:e.dash||[3,5],pointRadius:0,spanGaps:!1}))}function Ne(e){return{label:"Timeline Metric",data:e,borderWidth:3.5,tension:.4,fill:!1,borderColor:s.colors.normal,segment:{borderColor:De,borderDash:t=>I(t.p0DataIndex)||I(t.p1DataIndex)?[3,5]:[]},pointBorderColor:t=>Z(t.dataIndex,e[t.dataIndex]),pointBackgroundColor:t=>Z(t.dataIndex,e[t.dataIndex]),pointStyle:t=>I(t.dataIndex)||oe(t.dataIndex)==="flat"?"circle":"triangle",rotation:t=>oe(t.dataIndex)==="down"?180:0,pointRadius:t=>I(t.dataIndex)?3:oe(t.dataIndex)==="flat"?4:5.5,pointHoverRadius:8}}function Re(e,t){let o=t[0];o&&o.datasetIndex===q&&f[o.index].detailMode&&se(f[o.index].detailMode)}function Be(e){return{x:{offset:!1,border:{display:!1},grid:{color:s.uiColors.grid},ticks:{color:s.uiColors.tick,font:{weight:"bold",size:10},callback:(t,o)=>a.classList.contains("tva-chart-fullscreen-mode")?ae[o]:""}},y:{...ge(e),border:{display:!1},grid:{color:t=>t.tick.value===0?s.uiColors.transparent:s.uiColors.grid},ticks:{display:!1}}}}function ve(){let e=y();return{type:"line",data:{labels:ae,datasets:[...$e(),...Ge(),Ne(e)]},options:{responsive:!0,maintainAspectRatio:!1,layout:{padding:{left:2,right:6,top:d(i.topPadding,34),bottom:4}},onClick:Re,plugins:{title:{display:!1},legend:{display:!1},tooltip:{callbacks:{title:t=>t.length?ae[t[0].dataIndex]:"",label:t=>t.datasetIndex===q?he(f[t.dataIndex]):null}}},scales:Be(e)},plugins:[Te,Fe,Ee]}}function je(){return f.find(e=>e.detailMode===v)}function ke(e){return s.colors[e.level]||s.colors[Y(e.level)]||s.colors.normal}function ye(e,t){return t.findLast(o=>(e||0)>d(o.above,1/0))}function qe(){let e=je(),t=ee(s[e.areaKey]),o=t.map(c=>c.days),l=e.detailLevels||[];return{type:"bar",data:{labels:t.map(c=>c.name),datasets:[{data:o,borderWidth:1.2,borderRadius:8,backgroundColor:c=>{let m=ye(c.raw,l);return A(m?ke(m):s.colors.normal,m?.38:.3)},borderColor:c=>{let m=ye(c.raw,l);return m?ke(m):s.colors.normal}}]},options:{responsive:!0,maintainAspectRatio:!1,plugins:{title:{display:!1},subtitle:{display:!0,text:e.detailSubtitle||"",color:s.colors[l[0]&&l[0].level]||s.colors.normal,font:{size:10,weight:"bold"}},legend:{display:!1}},scales:{x:{grid:{color:s.uiColors.detailGrid},ticks:{color:s.uiColors.tick,font:{weight:"bold",size:10}}},y:{min:0,max:Math.max(...o,...l.map(c=>d(c.above,0)))+1.5,ticks:{color:s.uiColors.detailTick,callback:c=>`${c}d`}}}}}}function We(){return y().map((e,t)=>I(t)?null:O(t,e)).filter(Boolean).sort((e,t)=>d(t.priority,0)-d(e.priority,0))[0]}function ne(){let e=D.querySelector(".tva-chart-mode-select"),t=D.querySelector(".tva-chart-back"),o=D.querySelector(".tva-chart-fullscreen"),l=We(),c=l&&(l.borderBlink||l.blinkBorder||l.borderAlert);e&&(e.value=v),t.hidden=v==="timeline",o.classList.toggle("is-restore",a.classList.contains("tva-chart-fullscreen-mode")),P.hidden=v!=="timeline"||!l,P.innerHTML=l?`<span class="tva-alert-icon" aria-hidden="true"></span>${l.label||l.key.toUpperCase()}`:"",P.style.color=l?E(l):"",a.classList.toggle("tva-border-alert",!!c),c?a.style.setProperty("--tva-border-alert-color",E(l)):a.style.removeProperty("--tva-border-alert-color")}function Q(){b&&b.destroy(),b=new Chart(u.getContext("2d"),v==="timeline"?ve():qe()),ne()}let $=null,G=null;function Ue(){return v!=="timeline"?!1:y().some((e,t)=>{if(I(t))return!1;let o=O(t,e);return!!(o&&o.blink!==!1)})}function ze(){return v==="timeline"&&y().some((e,t)=>I(t))}function U(){let e=Ue();e&&!$?$=setInterval(()=>{H=!H,b&&v==="timeline"&&b.update("none")},d(i.blinkMs,1100)):!e&&$&&(clearInterval($),$=null,H=!0);let t=ze();t&&!G?G=setInterval(()=>{L+=x*.08,L>=1?(L=1,x=-1):L<=0&&(L=0,x=1),b&&v==="timeline"&&b.update("none")},d(i.staleSweepMs,140)):!t&&G&&(clearInterval(G),G=null,L=0,x=1)}function Ce(){if(!b||v!=="timeline"){Q(),U();return}let e=ve();b.data.labels=e.data.labels,e.data.datasets.forEach((o,l)=>{b.data.datasets[l]&&(b.data.datasets[l].data=o.data)});let t=b.data.datasets[q];t&&(t.data=y()),Object.assign(b.options.scales.y,ge(y())),ne(),U(),b.update("none")}function se(e){v=e,Q(),U()}Q(),U();function _e(){let e={...ce(s),updatedAt:ce(R)};return delete e.uiColors,e.colors&&(i.colors&&i.colors.normal||delete e.colors.normal,i.colors&&i.colors.stale||delete e.colors.stale),e}function Ve(e){let t=Date.now();Object.entries(e||{}).forEach(([o,l])=>{let c=j[o]||o;_.includes(c)&&l!==void 0&&l!==null&&(R[c]=t)}),e&&e.updatedAt&&typeof e.updatedAt=="object"&&Object.entries(e.updatedAt).forEach(([o,l])=>{let c=j[o]||o,m=typeof l=="string"?Date.parse(l):d(l,NaN);_.includes(c)&&Number.isFinite(m)&&(R[c]=m)})}return{update(e){let t=y();s=z(s,e,j),V(),y().some((o,l)=>o!==t[l])&&(J=t),Ve(e),Ce()},setData(e){J=y(),s=z(pe(),e,j),V(),R=Object.fromEntries(_.map(t=>[t,Date.now()])),Ce()},refreshTheme(){V(),Q(),U()},getData(){return _e()},destroy(){$&&clearInterval($),G&&clearInterval(G),a.classList.remove("tva-border-alert"),a.style.removeProperty("--tva-border-alert-color"),b&&b.destroy(),D.remove(),P.remove()}}}})();})(); + `;let P=document.createElement("div");P.className="tva-alert-badge",P.hidden=!0,a.querySelector(".tva-chart-controls")||a.prepend(D),a.querySelector(".tva-alert-badge")||a.prepend(P),D.querySelector(".tva-chart-back").onclick=()=>se("timeline"),D.querySelector(".tva-chart-mode-select").onchange=e=>se(e.target.value),D.querySelector(".tva-chart-fullscreen").onclick=()=>{a.classList.toggle("tva-chart-fullscreen-mode"),ne(),b&&b.resize(),b&&b.update("none")};function be(e){return d(s[e.key],d(e.defaultValue))}function le(e,t,o,l){return d(e.thresholds&&e.thresholds[`${ee(t.key)}${o}`],l)}function Se(e){let t=be(e);return e.scale==="count10"?Y(t*10,-100,100):e.scale==="daysCritical"?Y(t/d(e.scaleBase,10)*100,0,d(e.scaleMax,165)):e.scale==="pendency"?t<=d(e.scaleIdeal,1)?0:Y(t/d(e.scaleBase,3)*100,0,d(e.scaleMax,115)):t}function y(){return f.map(Se)}function w(e){return fe(R[f[e].key],d(f[e].refreshMinutes,0)*6e4)}function E(e){return s.colors[e.key]||s.colors[ee(e.key)]||s.colors.normal}function De(e){let t=W(`--tva-${e.key}-axis-alpha`);return d(t,d(e.axisAlpha,.35))}function Ae(e){let t=W(`--tva-${e.key}-axis-width`);return d(t,d(e.axisWidth,1.6))}function $(e,t){let o=null;return B.forEach(l=>{(t>le(f[e],l,"Upper",1/0)||t<le(f[e],l,"Lower",-1/0))&&(o=l)}),o}function Z(e=!1){return e?s.colors.stale:A(s.colors.stale,d(s.staleAlpha,.35))}function Q(e,t){if(w(e))return Z(!1);let o=$(e,t);return o?E(o):s.colors.normal}function he(e){let t=be(e),o=e.display||{},l=Number.isInteger(o.decimals)?o.decimals:0,c=Number.isInteger(t)||l===0?String(Math.round(t)):t.toFixed(l);return`${o.prefix||""}${c}${o.suffix||""}`}function oe(e){let t=y();return ue(K&&K[e],t[e],d(s.trendThreshold,15))}function ge(e){let t=Math.min(0,...e),o=Math.max(0,...e);t===o&&(t-=10,o+=10);let l=Math.max(8,(o-t)*.24);return{min:Math.floor(t-l),max:Math.ceil(o+l)}}function Le(e){let t=y(),o=Q(e.p0DataIndex,t[e.p0DataIndex]),l=Q(e.p1DataIndex,t[e.p1DataIndex]);if(o===l||!e.p0||!e.p1)return l;let c=e.chart.ctx.createLinearGradient(e.p0.x,e.p0.y,e.p1.x,e.p1.y),m=w(e.p0DataIndex),g=w(e.p1DataIndex);if(m||g){let p=Z(!1),M=Z(!0),k=.12;return[[0,p],[Math.max(0,L-k),p],[L,M],[Math.min(1,L+k),p],[1,p]].sort((C,ie)=>C[0]-ie[0]).forEach(([C,ie])=>c.addColorStop(C,ie)),c}c.addColorStop(0,o);let T=$(e.p0DataIndex,t[e.p0DataIndex]),F=$(e.p1DataIndex,t[e.p1DataIndex]),I=T&&d(T.dominance,0),N=F&&d(F.dominance,0);return I?c.addColorStop(I,o):N?c.addColorStop(1-N,l):c.addColorStop(.5,s.uiColors.neutralGradientMid),c.addColorStop(1,l),c}let U=i.ambientGlow||{};function Me(){return U.enabled!==!1&&U.enabled!==0}function Te(e){return e&&e.ambientGlow!==!1&&e.glow!==!1}function Fe(e){if(v!=="timeline"||!Me())return;let t=e.getDatasetMeta(q);if(!t||!e.chartArea)return;let o=y(),l=e.ctx;l.save(),l.beginPath(),l.rect(0,0,e.width,e.height),l.clip(),t.data.forEach((c,m)=>{if(w(m))return;let g=$(m,o[m]);if(!Te(g))return;let{x:T,y:F}=c.getProps(["x","y"],!0),I=g.glowColor||E(g),N=d(g.glowRadius,d(U.radius,72)),p=d(g.glowBlur,d(U.blur,36)),M=d(g.glowAlpha,d(U.alpha,.16)),k=N+p,C=l.createRadialGradient(T,F,0,T,F,k);C.addColorStop(0,A(I,M)),C.addColorStop(.34,A(I,M*.42)),C.addColorStop(.72,A(I,M*.12)),C.addColorStop(1,A(I,0)),l.fillStyle=C,l.fillRect(T-k,F-k,k*2,k*2)}),l.restore()}let Pe={id:"tvaAmbientGlow",beforeDraw:Fe},Ee={id:"tvaZeroAxis",beforeDatasetsDraw(e){if(v!=="timeline")return;let t=e.scales.y;if(!t)return;let o=t.getPixelForValue(0),l=e.ctx;l.save(),l.strokeStyle=A(s.colors.normal,.48),l.lineWidth=1.5,l.beginPath(),l.moveTo(0,o),l.lineTo(e.width,o),l.stroke(),l.restore()}};function $e(e,t,o,l){let c=f[o],m=w(o),g=!m&&$(o,l[o]),T=g&&g.blink!==!1&&g.key!==B[0].key,{x:F,y:I}=t.getProps(["x","y"],!0),N=m?"STALE":he(c),p=e.ctx,M=I-e.chartArea.top<52?I+18:I-43;p.save(),p.globalAlpha=m?.72:T?H?1:.38:1,p.font="bold 9px monospace";let k=Math.max(28,p.measureText(N).width+10),C=Math.min(Math.max(F-k/2,e.chartArea.left+2),e.chartArea.right-k-2);p.fillStyle=m?s.uiColors.staleLabelFill:g?A(E(g),.18):s.uiColors.normalLabelFill,p.strokeStyle=m?Z(!1):g?E(g):s.uiColors.normalLabelStroke,p.beginPath(),p.rect(C,M,k,31),p.fill(),p.stroke(),we(p,c.icon||"warning",C+k/2,M+3,m?s.uiColors.staleText:s.uiColors.plotIcon),p.fillStyle=m?s.uiColors.staleText:s.uiColors.plotIcon,p.textAlign="center",p.textBaseline="middle",p.fillText(N,C+k/2,M+24),p.restore()}let Oe={id:"tvaLabels",afterDatasetsDraw(e){if(v!=="timeline")return;let t=e.getDatasetMeta(q);if(!t)return;let o=y();t.data.forEach((l,c)=>$e(e,l,c,o))}};function Ge(e,t){return f.map(o=>le(o,e,t,t==="Upper"?1/0:-1/0))}function Ne(){return B.filter(e=>e.showAxis!==!1).flatMap(e=>["Upper","Lower"].map(t=>({label:`${e.label||e.key} ${t}`,data:Ge(e,t),borderColor:A(E(e),De(e)),borderWidth:Ae(e),borderDash:e.axisDash||[4,5],pointRadius:0,tension:.4})))}function Re(){return(i.extraAxes||[]).map(e=>({label:e.label,data:f.map(t=>t.key===e.parameterKey?d(e.value):null),borderColor:e.color||s.colors.normal,borderWidth:d(e.width,1.4),borderDash:e.dash||[3,5],pointRadius:0,spanGaps:!1}))}function Be(e){return{label:"Timeline Metric",data:e,borderWidth:3.5,tension:.4,fill:!1,borderColor:s.colors.normal,segment:{borderColor:Le,borderDash:t=>w(t.p0DataIndex)||w(t.p1DataIndex)?[3,5]:[]},pointBorderColor:t=>Q(t.dataIndex,e[t.dataIndex]),pointBackgroundColor:t=>Q(t.dataIndex,e[t.dataIndex]),pointStyle:t=>w(t.dataIndex)||oe(t.dataIndex)==="flat"?"circle":"triangle",rotation:t=>oe(t.dataIndex)==="down"?180:0,pointRadius:t=>w(t.dataIndex)?3:oe(t.dataIndex)==="flat"?4:5.5,pointHoverRadius:8}}function je(e,t){let o=t[0];o&&o.datasetIndex===q&&f[o.index].detailMode&&se(f[o.index].detailMode)}function qe(e){return{x:{offset:!1,border:{display:!1},grid:{color:s.uiColors.grid},ticks:{color:s.uiColors.tick,font:{weight:"bold",size:10},callback:(t,o)=>a.classList.contains("tva-chart-fullscreen-mode")?re[o]:""}},y:{...ge(e),border:{display:!1},grid:{color:t=>t.tick.value===0?s.uiColors.transparent:s.uiColors.grid},ticks:{display:!1}}}}function ve(){let e=y();return{type:"line",data:{labels:re,datasets:[...Ne(),...Re(),Be(e)]},options:{responsive:!0,maintainAspectRatio:!1,layout:{padding:{left:2,right:6,top:d(i.topPadding,34),bottom:4}},onClick:je,plugins:{title:{display:!1},legend:{display:!1},tooltip:{callbacks:{title:t=>t.length?re[t[0].dataIndex]:"",label:t=>t.datasetIndex===q?he(f[t.dataIndex]):null}}},scales:qe(e)},plugins:[Pe,Ee,Oe]}}function We(){return f.find(e=>e.detailMode===v)}function ke(e){return s.colors[e.level]||s.colors[ee(e.level)]||s.colors.normal}function ye(e,t){return t.findLast(o=>(e||0)>d(o.above,1/0))}function Ue(){let e=We(),t=te(s[e.areaKey]),o=t.map(c=>c.days),l=e.detailLevels||[];return{type:"bar",data:{labels:t.map(c=>c.name),datasets:[{data:o,borderWidth:1.2,borderRadius:8,backgroundColor:c=>{let m=ye(c.raw,l);return A(m?ke(m):s.colors.normal,m?.38:.3)},borderColor:c=>{let m=ye(c.raw,l);return m?ke(m):s.colors.normal}}]},options:{responsive:!0,maintainAspectRatio:!1,plugins:{title:{display:!1},subtitle:{display:!0,text:e.detailSubtitle||"",color:s.colors[l[0]&&l[0].level]||s.colors.normal,font:{size:10,weight:"bold"}},legend:{display:!1}},scales:{x:{grid:{color:s.uiColors.detailGrid},ticks:{color:s.uiColors.tick,font:{weight:"bold",size:10}}},y:{min:0,max:Math.max(...o,...l.map(c=>d(c.above,0)))+1.5,ticks:{color:s.uiColors.detailTick,callback:c=>`${c}d`}}}}}}function ze(){return y().map((e,t)=>w(t)?null:$(t,e)).filter(Boolean).sort((e,t)=>d(t.priority,0)-d(e.priority,0))[0]}function ne(){let e=D.querySelector(".tva-chart-mode-select"),t=D.querySelector(".tva-chart-back"),o=D.querySelector(".tva-chart-fullscreen"),l=ze(),c=l&&(l.borderBlink||l.blinkBorder||l.borderAlert);e&&(e.value=v),t.hidden=v==="timeline",o.classList.toggle("is-restore",a.classList.contains("tva-chart-fullscreen-mode")),P.hidden=v!=="timeline"||!l,P.innerHTML=l?`<span class="tva-alert-icon" aria-hidden="true"></span>${l.label||l.key.toUpperCase()}`:"",P.style.color=l?E(l):"",a.classList.toggle("tva-border-alert",!!c),c?a.style.setProperty("--tva-border-alert-color",E(l)):a.style.removeProperty("--tva-border-alert-color")}function X(){b&&b.destroy(),b=new Chart(u.getContext("2d"),v==="timeline"?ve():Ue()),ne()}let O=null,G=null;function xe(){return v!=="timeline"?!1:y().some((e,t)=>{if(w(t))return!1;let o=$(t,e);return!!(o&&o.blink!==!1)})}function _e(){return v==="timeline"&&y().some((e,t)=>w(t))}function z(){let e=xe();e&&!O?O=setInterval(()=>{H=!H,b&&v==="timeline"&&b.update("none")},d(i.blinkMs,1100)):!e&&O&&(clearInterval(O),O=null,H=!0);let t=_e();t&&!G?G=setInterval(()=>{L+=J*.08,L>=1?(L=1,J=-1):L<=0&&(L=0,J=1),b&&v==="timeline"&&b.update("none")},d(i.staleSweepMs,140)):!t&&G&&(clearInterval(G),G=null,L=0,J=1)}function Ce(){if(!b||v!=="timeline"){X(),z();return}let e=ve();b.data.labels=e.data.labels,e.data.datasets.forEach((o,l)=>{b.data.datasets[l]&&(b.data.datasets[l].data=o.data)});let t=b.data.datasets[q];t&&(t.data=y()),Object.assign(b.options.scales.y,ge(y())),ne(),z(),b.update("none")}function se(e){v=e,X(),z()}X(),z();function Ve(){let e={...ce(s),updatedAt:ce(R)};return delete e.uiColors,e.colors&&(i.colors&&i.colors.normal||delete e.colors.normal,i.colors&&i.colors.stale||delete e.colors.stale),e}function He(e){let t=Date.now();Object.entries(e||{}).forEach(([o,l])=>{let c=j[o]||o;_.includes(c)&&l!==void 0&&l!==null&&(R[c]=t)}),e&&e.updatedAt&&typeof e.updatedAt=="object"&&Object.entries(e.updatedAt).forEach(([o,l])=>{let c=j[o]||o,m=typeof l=="string"?Date.parse(l):d(l,NaN);_.includes(c)&&Number.isFinite(m)&&(R[c]=m)})}return{update(e){let t=y();s=x(s,e,j),V(),y().some((o,l)=>o!==t[l])&&(K=t),He(e),Ce()},setData(e){K=y(),s=x(pe(),e,j),V(),R=Object.fromEntries(_.map(t=>[t,Date.now()])),Ce()},refreshTheme(){V(),X(),z()},getData(){return Ve()},destroy(){O&&clearInterval(O),G&&clearInterval(G),a.classList.remove("tva-border-alert"),a.style.removeProperty("--tva-border-alert-color"),b&&b.destroy(),D.remove(),P.remove()}}}})();})();
diff --git a/tva-control.css b/tva-control.css @@ -63,6 +63,8 @@ --tva-normal-line: #4f646e; --tva-stale-line: #4f646e; --tva-border-alert-color: #ff1a1a; + --tva-amber-axis-alpha: 0.52; + --tva-amber-axis-width: 1.45; } .tva-control-container[data-tva-theme="light"], @@ -99,6 +101,8 @@ --tva-normal-line: var(--tva-light-normal-line); --tva-stale-line: var(--tva-light-normal-line); --tva-border-alert-color: var(--tva-light-border-alert-color); + --tva-amber-axis-alpha: 0.8; + --tva-amber-axis-width: 2.2; } @media (prefers-color-scheme: light) { @@ -136,6 +140,8 @@ --tva-normal-line: var(--tva-light-normal-line); --tva-stale-line: var(--tva-light-normal-line); --tva-border-alert-color: var(--tva-light-border-alert-color); + --tva-amber-axis-alpha: 0.8; + --tva-amber-axis-width: 2.2; } }
diff --git a/tva-control.js b/tva-control.js @@ -320,6 +320,14 @@ function levelColor(level) { return state.colors[level.key] || state.colors[camel(level.key)] || state.colors.normal; } + function levelAxisAlpha(level) { + const cssAlpha = cssVar(`--tva-${level.key}-axis-alpha`); + return number(cssAlpha, number(level.axisAlpha, 0.35)); + } + function levelAxisWidth(level) { + const cssWidth = cssVar(`--tva-${level.key}-axis-width`); + return number(cssWidth, number(level.axisWidth, 1.6)); + } function breachedLevel(i, v) { let hit = null; levels.forEach((l) => { @@ -528,8 +536,8 @@ ["Upper", "Lower"].map((side) => ({ label: `${l.label || l.key} ${side}`, data: thresholdDataset(l, side), - borderColor: colorWithAlpha(levelColor(l), number(l.axisAlpha, 0.35)), - borderWidth: number(l.axisWidth, 1.6), + borderColor: colorWithAlpha(levelColor(l), levelAxisAlpha(l)), + borderWidth: levelAxisWidth(l), borderDash: l.axisDash || [4, 5], pointRadius: 0, tension: 0.4,
: asapien/superpulse