ml-time-graph 1.5.2 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- var S=class{static interpolateDataPoint(n,i,t){return {time:n.time+Math.round(t*(i.time-n.time)),value:(n.value??0)+t*((i.value??0)-(n.value??0))}}static interpolateAggregatedPoint(n,i,t){let a=(e,l)=>e!==null&&l!==null?e+t*(l-e):null;return {time:n.time+t*(i.time-n.time),min:a(n.min,i.min),max:a(n.max,i.max),avg:a(n.avg,i.avg),count:Math.round(n.count+t*(i.count-n.count))}}static getRuns(n,i,t=0){let a=[...n].sort((r,o)=>r.time-o.time),e=[],l=[],u=null;for(let r of a){let o=i(r),s=t>0&&u&&r.time-u.time>t;(o||s)&&l.length&&(e.push(l),l=[]),o||l.push(r),u=r;}return l.length&&e.push(l),e}static splitByBoundaries(n,i,t,a){if(n.length===0)return [];if(i.length===0)return [{data:n,zoneIndex:0}];let e=[...i].sort((o,s)=>o-s),l=[],u=o=>{let s=0;for(let m=0;m<e.length&&o>=e[m];m++)s=m+1;return s},r=[n[0]];for(let o=1;o<n.length;o++){let s=n[o-1],m=n[o],f=t(s),g=t(m),d;g>f?d=e.filter(v=>v>f&&v<=g):g<f?d=e.filter(v=>v>=g&&v<f).reverse():d=[];for(let v of d){let x=(v-f)/(g-f),p=a(s,m,x);r.push(p),l.push({data:r,zoneIndex:u((f+v)/2)}),r=[p];}r.push(m);}if(r.length>0){let o=t(r[0]),s=t(r[r.length-1]);l.push({data:r,zoneIndex:u((o+s)/2)});}return l}static splitByThreshold(n,i,t,a){let e=this.splitByBoundaries(n,[i],t,a),l={above:[],below:[]};for(let u of e)u.zoneIndex===0?l.below.push(u.data):l.above.push(u.data);return l}},E={pharma_cold:{limitLow:2,limitHigh:8,activationEnergy:83144},pharma_ambient:{limitLow:15,limitHigh:25,activationEnergy:83144},blood:{limitLow:2,limitHigh:6,activationEnergy:83144},food_chilled:{limitLow:0,limitHigh:4},frozen:{limitLow:-40,limitHigh:-18}},D=8.314462618,y=273.15;function N(n,i,t,a=1){let e=i.filter(h=>h.value!==null&&h.value!==void 0&&!isNaN(h.value)).map(h=>h.value);if(!e.length)return {time:n,min:null,max:null,avg:null,mkt:null,deltaMkt:null,stdDev:null,minutesAboveHigh:t?0:null,minutesBelowLow:t?0:null,count:0};let l=1/0,u=-1/0,r=0;for(let h of e)h<l&&(l=h),h>u&&(u=h),r+=h;let o=r/e.length,s=t?0:null,m=t?0:null;if(t)for(let h=0;h<i.length;h++){let c=i[h];if(c.value!==null&&c.value!==void 0){let M=i[h+1],w=(M?M.time-c.time:0)/(1e3*60);c.value>t.limitHigh&&(s+=w),c.value<t.limitLow&&(m+=w);}}let f=0,g=0,d=(t?.activationEnergy??83144)/D;for(let h of e){f+=Math.pow(h-o,2);let c=h+y;g+=Math.exp(-d/c);}let v=f/e.length,x=Math.sqrt(v),p=null,b=null;if(e.length>=a){let h=g/e.length,c=d/-Math.log(h);p=Number((c-y).toFixed(2)),b=Number((p-o).toFixed(2));}return {time:n,min:Number(l.toFixed(2)),max:Number(u.toFixed(2)),avg:Number(o.toFixed(2)),mkt:p,deltaMkt:b,stdDev:Number(x.toFixed(2)),minutesAboveHigh:s!==null?Number(s.toFixed(1)):null,minutesBelowLow:m!==null?Number(m.toFixed(1)):null,count:e.length}}function k(n,i="hourly",t,a,e=1){if(!n.length)return [];let l=i==="hourly"?36e5:i==="daily"?864e5:t??3600*1e3,u=[...n].sort((m,f)=>m.time-f.time),r=[],o=u[0].time,s=[];for(let m of u){for(;m.time-o>=l;)r.push(N(o,s,a,e)),o+=l,s=[];s.push(m);}return r.push(N(o,s,a,e)),r}function B(n,i){let t=1/0,a=-1/0,e=0;for(let u of i)u<t&&(t=u),u>a&&(a=u),e+=u;let l=e/i.length;return {time:n,min:t,max:a,avg:l,count:i.length}}function z(n,i=6e4){if(n.length<2)return [];let t=[...n].sort((e,l)=>e.time-l.time),a=[];for(let e=1;e<t.length;e++)t[e].time-t[e-1].time>i&&a.push({startTime:t[e-1].time,endTime:t[e].time});return a}function I(n){let i=[],t=0,a=0,e=0,l=0;for(let u of n)u.count>0&&(e++,u.minutesAboveHigh&&(t+=u.minutesAboveHigh),u.stdDev&&u.stdDev>a&&(a=u.stdDev),u.deltaMkt&&u.deltaMkt>2&&l++);return e===0?[]:(t>120&&i.push({type:"critical",message:`Kritische Gesamtbelastung: Das Produkt war im gesamten Zeitraum insgesamt ${Math.round(t)} Minuten zu warm.`,metric:"Total Excursion Time"}),l>e*.15&&i.push({type:"warning",message:"Frequent thermal shocks detected. The kinetic temperature deviates strongly from the average (possible regular door openings).",metric:"Delta MKT Instability"}),a>4&&i.push({type:"warning",message:`High instability measured. Maximum standard deviation was ${a}\xB0C. The cooling system controls imprecisely.`,metric:"Standard Deviation Peak"}),i)}function C(n,i){if(n.length<=i)return n;let t=[],a=Math.ceil(n.length/i);t.push(n[0]);for(let e=1;e<n.length;e+=a)t.push(n[Math.min(e,n.length-1)]);return t}function P(n,i="hourly",t){let a={limitLow:t.low,limitHigh:t.high,activationEnergy:t.activationEnergy};return k(n,i,t.interval,a,t.minCountForMkt??1)}var _=class{static compute(n){let i=n.map(r=>r.value).filter(r=>r!==null).sort((r,o)=>r-o);if(i.length===0)return {min:NaN,max:NaN,avg:NaN,mean:NaN,median:NaN,stdDev:NaN,count:0};let t=i.length,a=i.reduce((r,o)=>r+o,0)/t,e=t%2===1?i[Math.floor(t/2)]:(i[t/2-1]+i[t/2])/2,l=i.reduce((r,o)=>r+Math.pow(o-a,2),0)/t,u=Math.sqrt(l);return {min:i[0],max:i[t-1],avg:a,mean:a,median:e,stdDev:u,count:t}}static computeInRange(n,i,t){let a=n.filter(e=>e.time>=i&&e.time<=t);return this.compute(a)}};function q(n,i){let t=typeof n=="number"?n:n.mean,a=typeof n=="number"?i??NaN:n.stdDev;return !Number.isFinite(t)||!Number.isFinite(a)||t===0?null:Math.abs(a/t)*100}var R=83144;function F(n,i=83144){let t=i/8.314,a=0,e=0;for(let u of n)u!==null&&(a+=Math.exp(-t/(u+273.15)),e++);if(e===0)return null;let l=a/e;return t/-Math.log(l)-273.15}function G(n,i,t=83144){let a=new Array(n.length),e=0;for(let l=0;l<n.length;l++){let u=n[l].time,r=u-i;for(;e<l&&n[e].time<r;)e++;let o=n.slice(e,l+1).map(m=>m.value),s=F(o,t);a[l]={time:u,value:s,synthetic:true};}return a}function L(n){let i=0,t=0;for(let l of n)l!==null&&(i+=l,t++);if(t===0)return null;let a=i/t,e=0;for(let l of n){if(l===null)continue;let u=l-a;e+=u*u;}return Math.sqrt(e/t)}function A(n){let i=0,t=0;for(let l of n)l!==null&&(i+=l,t++);if(t<2)return null;let a=i/t,e=0;for(let l of n){if(l===null)continue;let u=l-a;e+=u*u;}return Math.sqrt(e/(t-1))}function K(n,i,t=false){let a=new Array(n.length),e=0,l=t?A:L;for(let u=0;u<n.length;u++){let r=n[u].time,o=r-i;for(;e<u&&n[e].time<o;)e++;let s=n.slice(e,u+1).map(f=>f.value),m=l(s);a[u]={time:r,value:m,synthetic:true};}return a}function O(n,i){let{high:t,low:a}=i,e={msAboveHigh:0,msBelowLow:0,globalMax:null,globalMin:null,excursions:[]},l=null;for(let u=0;u<n.length;u++){let r=n[u];if(r.value===null){l&&(e.excursions.push(l),l=null);continue}(e.globalMax===null||r.value>e.globalMax)&&(e.globalMax=r.value),(e.globalMin===null||r.value<e.globalMin)&&(e.globalMin=r.value);let o=t!==void 0&&r.value>t,s=a!==void 0&&r.value<a,m=o?"above":s?"below":null,f=n[u-1];if(f&&f.value!==null&&m!==null){let g=r.time-f.time;m==="above"?e.msAboveHigh+=g:e.msBelowLow+=g;}if(m===null){l&&(e.excursions.push(l),l=null);continue}l&&l.side===m?(l.endTime=r.time,l.durationMs=l.endTime-l.startTime,(m==="above"&&r.value>l.extremum||m==="below"&&r.value<l.extremum)&&(l.extremum=r.value)):(l&&e.excursions.push(l),l={startTime:r.time,endTime:r.time,side:m,extremum:r.value,durationMs:0});}return l&&e.excursions.push(l),e}function U(n){if(n.length===0)return [];let i=new Map;for(let a of n)for(let e of a.data){if(e.value===null)continue;let l=i.get(e.time);l||(l=[],i.set(e.time,l)),l.push({name:a.name,value:e.value});}let t=[];for(let a of [...i.keys()].sort((e,l)=>e-l)){let e=i.get(a);if(e.length===0){t.push({time:a,min:null,max:null,delta:null,minSensor:null,maxSensor:null});continue}let l=e[0],u=e[0];for(let r=1;r<e.length;r++)e[r].value<l.value&&(l=e[r]),e[r].value>u.value&&(u=e[r]);t.push({time:a,min:l.value,max:u.value,delta:e.length<2?null:u.value-l.value,minSensor:l.name,maxSensor:u.name});}return t}function V(n){let i=[];for(let e of n){let l=0,u=0,r=1/0,o=-1/0;for(let s of e.data)s.value!==null&&(l+=s.value,u++,s.value<r&&(r=s.value),s.value>o&&(o=s.value));u!==0&&i.push({name:e.name,mean:l/u,min:r,max:o,count:u});}if(i.length===0)return {sensors:[],hottest:null,coldest:null,meanDelta:null};let t=i[0],a=i[0];for(let e=1;e<i.length;e++)i[e].mean>t.mean&&(t=i[e]),i[e].mean<a.mean&&(a=i[e]);return {sensors:i,hottest:t,coldest:a,meanDelta:t.mean-a.mean}}function T(n){let i=0,t=0,a=0,e=0,l=0;for(let s of n)s.value!==null&&(i++,t+=s.time,a+=s.value,e+=s.time*s.value,l+=s.time*s.time);if(i<2)return null;let u=i*l-t*t;if(u===0)return null;let r=(i*e-t*a)/u,o=(a-r*t)/i;return {slope:r,intercept:o,n:i}}function H(n,i){if(n.length===0)return null;let t=n[n.length-1].time,a=t-i,e=n.filter(l=>l.time>=a&&l.time<=t);return T(e)}function W(n,i){let t=[],a=0;for(let e=0;e<n.length;e++){let l=n[e].time,u=l-i;for(;a<n.length&&n[a].time<u;)a++;let r=T(n.slice(a,e+1));t.push({time:l,fit:r});}return t}function Y(n,i,t={}){let a=t.lookbackMs??9e5,e=t.side??"either";if(n.length===0)return null;let l=n[n.length-1];if(l.value===null)return null;let u=H(n,a);if(!u||u.slope===0)return null;let r=u.slope>0&&l.value<i,o=u.slope<0&&l.value>i;if(e==="above"&&!r||e==="below"&&!o||e==="either"&&!r&&!o)return null;let s=(i-u.intercept)/u.slope,m=s-l.time;return m<=0?null:{msUntil:m,eta:s,fit:u,currentValue:l.value}}function Z(n,i={}){let t=i.refTempCelsius??121.11,a=i.zValueKelvin??10,e=0;for(let l=0;l<n.length-1;l++){let u=n[l],r=n[l+1];if(u.value===null||r.value===null)continue;let o=(r.time-u.time)/6e4;if(o<=0)continue;let s=Math.pow(10,(u.value-t)/a),m=Math.pow(10,(r.value-t)/a);e+=(s+m)/2*o;}return e}/*!
1
+ var E=class{static interpolateDataPoint(n,i,t){return {time:n.time+Math.round(t*(i.time-n.time)),value:(n.value??0)+t*((i.value??0)-(n.value??0))}}static interpolateAggregatedPoint(n,i,t){let a=(e,l)=>e!==null&&l!==null?e+t*(l-e):null;return {time:n.time+t*(i.time-n.time),min:a(n.min,i.min),max:a(n.max,i.max),avg:a(n.avg,i.avg),count:Math.round(n.count+t*(i.count-n.count))}}static getRuns(n,i,t=0){let a=[...n].sort((r,m)=>r.time-m.time),e=[],l=[],u=null;for(let r of a){let m=i(r),o=t>0&&u&&r.time-u.time>t;(m||o)&&l.length&&(e.push(l),l=[]),m||l.push(r),u=r;}return l.length&&e.push(l),e}static splitByBoundaries(n,i,t,a){if(n.length===0)return [];if(i.length===0)return [{data:n,zoneIndex:0,zoneLow:Number.NEGATIVE_INFINITY}];let e=[...i].sort((o,s)=>o-s),l=[],u=o=>o<=0?Number.NEGATIVE_INFINITY:e[o-1],r=o=>{let s=0;for(let f=0;f<e.length&&o>=e[f];f++)s=f+1;return s},m=[n[0]];for(let o=1;o<n.length;o++){let s=n[o-1],f=n[o],g=t(s),d=t(f),p;d>g?p=e.filter(v=>v>g&&v<=d):d<g?p=e.filter(v=>v>=d&&v<g).reverse():p=[];let b=g;for(let v of p){let x=(v-g)/(d-g),h=a(s,f,x);m.push(h);let c=r((b+v)/2);l.push({data:m,zoneIndex:c,zoneLow:u(c)}),m=[h],b=v;}(p.length===0||p[p.length-1]!==d)&&m.push(f);}if(m.length>1){let o=t(m[0]),s=t(m[m.length-1]),f=r((o+s)/2);l.push({data:m,zoneIndex:f,zoneLow:u(f)});}return l}static splitByThreshold(n,i,t,a){let e=this.splitByBoundaries(n,[i],t,a),l={above:[],below:[]};for(let u of e)u.zoneIndex===0?l.below.push(u.data):l.above.push(u.data);return l}},H={pharma_cold:{limitLow:2,limitHigh:8,activationEnergy:83144},pharma_ambient:{limitLow:15,limitHigh:25,activationEnergy:83144},blood:{limitLow:2,limitHigh:6,activationEnergy:83144},food_chilled:{limitLow:0,limitHigh:4},frozen:{limitLow:-40,limitHigh:-18}},D=8.314462618,N=273.15;function y(n,i,t,a=1){let e=i.filter(h=>h.value!==null&&h.value!==void 0&&!Number.isNaN(h.value)).map(h=>h.value);if(!e.length)return {time:n,min:null,max:null,avg:null,mkt:null,deltaMkt:null,stdDev:null,minutesAboveHigh:t?0:null,minutesBelowLow:t?0:null,count:0};let l=1/0,u=-1/0,r=0;for(let h of e)h<l&&(l=h),h>u&&(u=h),r+=h;let m=r/e.length,o=t?0:null,s=t?0:null;if(t)for(let h=0;h<i.length;h++){let c=i[h];if(c.value!==null&&c.value!==void 0){let M=i[h+1],w=(M?M.time-c.time:0)/(1e3*60);c.value>t.limitHigh&&(o+=w),c.value<t.limitLow&&(s+=w);}}let f=0,g=0,d=(t?.activationEnergy??83144)/D;for(let h of e){f+=Math.pow(h-m,2);let c=h+N;g+=Math.exp(-d/c);}let p=f/e.length,b=Math.sqrt(p),v=null,x=null;if(e.length>=a){let h=g/e.length,c=d/-Math.log(h);v=Number((c-N).toFixed(2)),x=Number((v-m).toFixed(2));}return {time:n,min:Number(l.toFixed(2)),max:Number(u.toFixed(2)),avg:Number(m.toFixed(2)),mkt:v,deltaMkt:x,stdDev:Number(b.toFixed(2)),minutesAboveHigh:o!==null?Number(o.toFixed(1)):null,minutesBelowLow:s!==null?Number(s.toFixed(1)):null,count:e.length}}function L(n,i="hourly",t,a,e=1){if(!n.length)return [];let l=i==="hourly"?36e5:i==="daily"?864e5:t??3600*1e3,u=[...n].sort((s,f)=>s.time-f.time),r=[],m=u[0].time,o=[];for(let s of u){for(;s.time-m>=l;)r.push(y(m,o,a,e)),m+=l,o=[];o.push(s);}return r.push(y(m,o,a,e)),r}function S(n,i){let t=1/0,a=-1/0,e=0;for(let u of i)u<t&&(t=u),u>a&&(a=u),e+=u;let l=e/i.length;return {time:n,min:t,max:a,avg:l,count:i.length}}function z(n,i=6e4){if(n.length<2)return [];let t=[...n].sort((e,l)=>e.time-l.time),a=[];for(let e=1;e<t.length;e++)t[e].time-t[e-1].time>i&&a.push({startTime:t[e-1].time,endTime:t[e].time});return a}function B(n){let i=[],t=0,a=0,e=0,l=0;for(let u of n)u.count>0&&(e++,u.minutesAboveHigh&&(t+=u.minutesAboveHigh),u.stdDev&&u.stdDev>a&&(a=u.stdDev),u.deltaMkt&&u.deltaMkt>2&&l++);return e===0?[]:(t>120&&i.push({type:"critical",message:`Kritische Gesamtbelastung: Das Produkt war im gesamten Zeitraum insgesamt ${Math.round(t)} Minuten zu warm.`,metric:"Total Excursion Time"}),l>e*.15&&i.push({type:"warning",message:"Frequent thermal shocks detected. The kinetic temperature deviates strongly from the average (possible regular door openings).",metric:"Delta MKT Instability"}),a>4&&i.push({type:"warning",message:`High instability measured. Maximum standard deviation was ${a}\xB0C. The cooling system controls imprecisely.`,metric:"Standard Deviation Peak"}),i)}function P(n,i){if(n.length<=i)return n;let t=[],a=Math.ceil(n.length/i);t.push(n[0]);for(let e=1;e<n.length;e+=a)t.push(n[Math.min(e,n.length-1)]);return t}function _(n,i="hourly",t){let a={limitLow:t.low,limitHigh:t.high,activationEnergy:t.activationEnergy};return L(n,i,t.interval,a,t.minCountForMkt??1)}var C=class{static compute(n){let i=n.map(r=>r.value).filter(r=>r!==null).sort((r,m)=>r-m);if(i.length===0)return {min:NaN,max:NaN,avg:NaN,mean:NaN,median:NaN,stdDev:NaN,count:0};let t=i.length,a=i.reduce((r,m)=>r+m,0)/t,e=t%2===1?i[Math.floor(t/2)]:(i[t/2-1]+i[t/2])/2,l=i.reduce((r,m)=>r+Math.pow(m-a,2),0)/t,u=Math.sqrt(l);return {min:i[0],max:i[t-1],avg:a,mean:a,median:e,stdDev:u,count:t}}static computeInRange(n,i,t){let a=n.filter(e=>e.time>=i&&e.time<=t);return this.compute(a)}};function q(n,i){let t=typeof n=="number"?n:n.mean,a=typeof n=="number"?i??NaN:n.stdDev;return !Number.isFinite(t)||!Number.isFinite(a)||t===0?null:Math.abs(a/t)*100}var G=83144;function F(n,i=83144){let t=i/8.314,a=0,e=0;for(let u of n)u!==null&&(a+=Math.exp(-t/(u+273.15)),e++);if(e===0)return null;let l=a/e;return t/-Math.log(l)-273.15}function R(n,i,t=83144){let a=new Array(n.length),e=0;for(let l=0;l<n.length;l++){let u=n[l].time,r=u-i;for(;e<l&&n[e].time<r;)e++;let m=n.slice(e,l+1).map(s=>s.value),o=F(m,t);a[l]={time:u,value:o,synthetic:true};}return a}function I(n){let i=0,t=0;for(let l of n)l!==null&&(i+=l,t++);if(t===0)return null;let a=i/t,e=0;for(let l of n){if(l===null)continue;let u=l-a;e+=u*u;}return Math.sqrt(e/t)}function k(n){let i=0,t=0;for(let l of n)l!==null&&(i+=l,t++);if(t<2)return null;let a=i/t,e=0;for(let l of n){if(l===null)continue;let u=l-a;e+=u*u;}return Math.sqrt(e/(t-1))}function V(n,i,t=false){let a=new Array(n.length),e=0,l=t?k:I;for(let u=0;u<n.length;u++){let r=n[u].time,m=r-i;for(;e<u&&n[e].time<m;)e++;let o=n.slice(e,u+1).map(f=>f.value),s=l(o);a[u]={time:r,value:s,synthetic:true};}return a}function K(n,i){let{high:t,low:a}=i,e={msAboveHigh:0,msBelowLow:0,globalMax:null,globalMin:null,excursions:[]},l=null;for(let u=0;u<n.length;u++){let r=n[u];if(r.value===null){l&&(e.excursions.push(l),l=null);continue}(e.globalMax===null||r.value>e.globalMax)&&(e.globalMax=r.value),(e.globalMin===null||r.value<e.globalMin)&&(e.globalMin=r.value);let m=t!==void 0&&r.value>t,o=a!==void 0&&r.value<a,s=m?"above":o?"below":null,f=n[u-1];if(f&&f.value!==null&&s!==null){let g=r.time-f.time;s==="above"?e.msAboveHigh+=g:e.msBelowLow+=g;}if(s===null){l&&(e.excursions.push(l),l=null);continue}l&&l.side===s?(l.endTime=r.time,l.durationMs=l.endTime-l.startTime,(s==="above"&&r.value>l.extremum||s==="below"&&r.value<l.extremum)&&(l.extremum=r.value)):(l&&e.excursions.push(l),l={startTime:r.time,endTime:r.time,side:s,extremum:r.value,durationMs:0});}return l&&e.excursions.push(l),e}function O(n){if(n.length===0)return [];let i=new Map;for(let a of n)for(let e of a.data){if(e.value===null)continue;let l=i.get(e.time);l||(l=[],i.set(e.time,l)),l.push({name:a.name,value:e.value});}let t=[];for(let a of [...i.keys()].sort((e,l)=>e-l)){let e=i.get(a);if(e.length===0){t.push({time:a,min:null,max:null,delta:null,minSensor:null,maxSensor:null});continue}let l=e[0],u=e[0];for(let r=1;r<e.length;r++)e[r].value<l.value&&(l=e[r]),e[r].value>u.value&&(u=e[r]);t.push({time:a,min:l.value,max:u.value,delta:e.length<2?null:u.value-l.value,minSensor:l.name,maxSensor:u.name});}return t}function U(n){let i=[];for(let e of n){let l=0,u=0,r=1/0,m=-1/0;for(let o of e.data)o.value!==null&&(l+=o.value,u++,o.value<r&&(r=o.value),o.value>m&&(m=o.value));u!==0&&i.push({name:e.name,mean:l/u,min:r,max:m,count:u});}if(i.length===0)return {sensors:[],hottest:null,coldest:null,meanDelta:null};let t=i[0],a=i[0];for(let e=1;e<i.length;e++)i[e].mean>t.mean&&(t=i[e]),i[e].mean<a.mean&&(a=i[e]);return {sensors:i,hottest:t,coldest:a,meanDelta:t.mean-a.mean}}function T(n){let i=0,t=0,a=0,e=0,l=0;for(let o of n)o.value!==null&&(i++,t+=o.time,a+=o.value,e+=o.time*o.value,l+=o.time*o.time);if(i<2)return null;let u=i*l-t*t;if(u===0)return null;let r=(i*e-t*a)/u,m=(a-r*t)/i;return {slope:r,intercept:m,n:i}}function A(n,i){if(n.length===0)return null;let t=n[n.length-1].time,a=t-i,e=n.filter(l=>l.time>=a&&l.time<=t);return T(e)}function Y(n,i){let t=[],a=0;for(let e=0;e<n.length;e++){let l=n[e].time,u=l-i;for(;a<n.length&&n[a].time<u;)a++;let r=T(n.slice(a,e+1));t.push({time:l,fit:r});}return t}function W(n,i,t={}){let a=t.lookbackMs??9e5,e=t.side??"either";if(n.length===0)return null;let l=n[n.length-1];if(l.value===null)return null;let u=A(n,a);if(!u||u.slope===0)return null;let r=u.slope>0&&l.value<i,m=u.slope<0&&l.value>i;if(e==="above"&&!r||e==="below"&&!m||e==="either"&&!r&&!m)return null;let o=(i-u.intercept)/u.slope,s=o-l.time;return s<=0?null:{msUntil:s,eta:o,fit:u,currentValue:l.value}}function Z(n,i={}){let t=i.refTempCelsius??121.11,a=i.zValueKelvin??10,e=0;for(let l=0;l<n.length-1;l++){let u=n[l],r=n[l+1];if(u.value===null||r.value===null)continue;let m=(r.time-u.time)/6e4;if(m<=0)continue;let o=Math.pow(10,(u.value-t)/a),s=Math.pow(10,(r.value-t)/a);e+=(o+s)/2*m;}return e}/*!
2
2
  * MLTimeGraph — Copyright (c) 2026 Michael Lechner
3
3
  * MIT with Attribution: free use incl. commercial requires visible credit to
4
4
  * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
@@ -12,4 +12,4 @@ var S=class{static interpolateDataPoint(n,i,t){return {time:n.time+Math.round(t*
12
12
  * MLTimeGraph — Copyright (c) 2026 Michael Lechner
13
13
  * MIT with Attribution: free use incl. commercial requires visible credit to
14
14
  * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
15
- */export{R as DEFAULT_ACTIVATION_ENERGY,E as PRODUCT_PROFILES,S as SeriesProcessor,_ as StatsAggregator,k as aggregateBySlot,P as aggregateWithStats,I as analyzeLongTermTrends,O as computeLimitExcursions,B as createAggr,H as currentTrend,z as detectGaps,C as downsample,Z as f0Sterilization,V as hotColdSpots,T as linearFit,F as mkt,Y as predictTimeToThreshold,G as rollingMkt,K as rollingStdDev,W as rollingTrend,A as sampleStdDev,U as spatialDelta,L as stdDev,q as varianceCoefficient};
15
+ */export{G as DEFAULT_ACTIVATION_ENERGY,H as PRODUCT_PROFILES,E as SeriesProcessor,C as StatsAggregator,L as aggregateBySlot,_ as aggregateWithStats,B as analyzeLongTermTrends,K as computeLimitExcursions,S as createAggr,A as currentTrend,z as detectGaps,P as downsample,Z as f0Sterilization,U as hotColdSpots,T as linearFit,F as mkt,W as predictTimeToThreshold,R as rollingMkt,V as rollingStdDev,Y as rollingTrend,k as sampleStdDev,O as spatialDelta,I as stdDev,q as varianceCoefficient};
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { L as LegendOrientation, R as Renderer, M as Marker, a as LegendItem, b as LayoutResult, c as RenderOutput } from './series_renderer-BxGvCHMY.js';
2
- export { T as Theme, d as drawMarker, g as getDefaultTheme, r as resetDefaultTheme, s as setDefaultTheme } from './series_renderer-BxGvCHMY.js';
3
- import { L as LineVariant, A as AnySeries, T as Threshold, H as Highlight, G as Gap, a as GapsConfig, b as Annotation, c as AnnotationBandConfig, D as DrawCommand, d as TimeScale, e as LinearScale, S as SeriesStyle, F as FillSpec, f as TimeSeries, g as HatchVariant, h as ThresholdLabelPosition, P as PointStyleType, i as AnnotationBandItem, j as AggregatedPoint, k as AggregatedSeries, l as DataPoint } from './scale-ByGpczxS.js';
4
- export { m as AggregationConfig, n as AggregationMode, o as DataPointRef, E as EnumMap, p as FillBound, q as FillDirectionType, r as FillRegion, s as FillSide, t as FillStyle, u as GapConfig, v as GapLabel, w as GapRegion, x as GapStyle, y as LineDashStyle, z as LineStyle, M as MarkerStyle, B as SVGLineStyle, C as SensorType, I as SeriesOverlay, J as SeriesOverlayKind, K as SeriesType, N as ShadowStyle, O as ThresholdLabelConfig, Q as getLineStyle, R as resolveDash } from './scale-ByGpczxS.js';
1
+ import { L as LegendOrientation, R as Renderer, M as Marker, a as LegendItem, b as LayoutResult, c as RenderOutput } from './series_renderer-COVNvq2x.js';
2
+ export { T as Theme, d as drawMarker, g as getDefaultTheme, r as resetDefaultTheme, s as setDefaultTheme } from './series_renderer-COVNvq2x.js';
3
+ import { L as LineVariant, A as AnySeries, T as Threshold, H as Highlight, G as Gap, a as GapsConfig, b as Annotation, c as AnnotationBandConfig, D as DrawCommand, d as TimeScale, e as LinearScale, S as SeriesStyle, F as FillSpec, f as TimeSeries, g as HatchVariant, h as ThresholdLabelPosition, P as PointStyleType, i as AnnotationBandItem, j as AggregatedPoint, k as AggregatedSeries, l as DataPoint } from './scale-D6NtEaUB.js';
4
+ export { m as AggregationConfig, n as AggregationMode, o as DataPointRef, E as EnumMap, p as FillBound, q as FillDirectionType, r as FillRegion, s as FillSide, t as FillStyle, u as GapConfig, v as GapLabel, w as GapRegion, x as GapStyle, y as LineDashStyle, z as LineStyle, M as MarkerStyle, B as SVGLineStyle, C as SensorType, I as SeriesOverlay, J as SeriesOverlayKind, K as SeriesType, N as ShadowStyle, O as ThresholdLabelConfig, Q as getLineStyle, R as resolveDash } from './scale-D6NtEaUB.js';
5
5
 
6
6
  /*!
7
7
  * MLTimeGraph — Copyright (c) 2026 Michael Lechner
@@ -169,7 +169,7 @@ interface MLTimeGraphOptions {
169
169
  annotationBands?: AnnotationBandConfig[];
170
170
  /**
171
171
  * First-class axes configuration: per-axis `label`, `format`, `ticks`, `grid`,
172
- * `axis`, `labels` (see API_DESIGN.md §7).
172
+ * `axis`, `labels` (see USAGE.md, "Axes").
173
173
  */
174
174
  axes?: AxesConfig;
175
175
  }
@@ -860,4 +860,78 @@ declare function parseSeries(obj: unknown): TimeSeries | DataPoint[];
860
860
  /** Parse aggregated series (AggregatedPoint[] — min/max/avg per slot) */
861
861
  declare function parseAggregated(obj: unknown): AggregatedSeries;
862
862
 
863
- export { AggregatedPoint, AggregatedSeries, Annotation, AnnotationBandBuilder, AnnotationBandConfig, AnnotationBandItem, AnnotationBandItemBuilder, AnnotationBuilder, AnySeries, type AxesConfig, type AxisLabelsStyle, type AxisStyle, DataPoint, DrawCommand, type FillBetweenThresholdsInput, FillSpec, Gap, GapsConfig, GraphBuilder, type GridLineStyle, type GridStyle, HatchVariant, Highlight, HighlightBuilder, LegendItem, type LegendOptions, LegendOrientation, type LegendPosition, type LimitStatsPoint, LineVariant, MLTimeGraph, type MLTimeGraphOptions, type Margin, Marker, MarkerBuilder, type MktPoint, PointStyleType, SVGRenderer, SeriesStyle, type StatsAggregatedPoint, type StdDevPoint, Threshold, ThresholdBuilder, ThresholdLabelPosition, type TickConfig, TimeSeries, TimeSeriesBuilder, type TooltipOptions, type TooltipSample, type XAxisConfig, type YAxisConfig, attachTooltip, fillBetweenThresholds, mount, parseAggregated, parseDataPoint, parseSeries };
863
+ /*!
864
+ * MLTimeGraph — Copyright (c) 2026 Michael Lechner
865
+ * MIT with Attribution: free use incl. commercial requires visible credit to
866
+ * "Michael Lechner". Commercial license (no attribution) on request. See LICENSE.
867
+ */
868
+
869
+ /** A timestamp in any of the shapes an adapter accepts. */
870
+ type TimeInput = number | string | Date;
871
+ /** How to read one field out of a row: by key, or by function. */
872
+ type FieldAccessor<T, R> = string | ((row: T) => R);
873
+ /** Options for {@link toDataPoints}. */
874
+ interface ToDataPointsSpec<T> {
875
+ /** Where the timestamp lives. Default: key `time`, or index 0 for tuples. */
876
+ time?: FieldAccessor<T, TimeInput>;
877
+ /** Where the value lives. Default: key `value`, or index 1 for tuples. */
878
+ value?: FieldAccessor<T, unknown>;
879
+ /** Optional per-point annotation text. */
880
+ annotation?: FieldAccessor<T, unknown>;
881
+ /**
882
+ * Unit of *numeric* timestamps. Default `'ms'` — no guessing.
883
+ *
884
+ * `'s'` multiplies by 1000 (Unix seconds, what most JSON APIs hand out).
885
+ * `'auto'` treats a number between 1e8 and 1e11 as seconds and everything
886
+ * else as milliseconds. The lower bound keeps relative time bases intact:
887
+ * a series that starts at 0, 1000, 2000 stays milliseconds.
888
+ *
889
+ * Strings and `Date`s are unambiguous and never affected by this.
890
+ */
891
+ timeUnit?: "ms" | "s" | "auto";
892
+ /**
893
+ * Sort by time ascending. Default `true`.
894
+ *
895
+ * The chart expects its points in order — unsorted input draws a line that
896
+ * runs backwards. Sorting already-sorted data changes nothing, so this is
897
+ * safe to leave on; set `false` if you sorted yourself and every millisecond
898
+ * of a large import counts.
899
+ */
900
+ sort?: boolean;
901
+ }
902
+ /**
903
+ * Turn foreign row shapes into the `DataPoint[]` the chart consumes.
904
+ *
905
+ * Handles the three shapes real data arrives in:
906
+ *
907
+ * ```ts
908
+ * // 1. Tuples — [time, value]
909
+ * toDataPoints([[1727000000000, 21.5], [1727003600000, 22.1]]);
910
+ *
911
+ * // 2. Objects with different field names
912
+ * toDataPoints(rows, { time: 'ts', value: 'val' });
913
+ *
914
+ * // 3. Anything else — read it yourself
915
+ * toDataPoints(rows, { time: (r) => Date.parse(r.recordedAt), value: (r) => r.payload.temp });
916
+ * ```
917
+ *
918
+ * Unix seconds (`timeUnit: 's'`), ISO strings and `Date`s are converted to
919
+ * milliseconds. A missing value (`null`, `undefined`, `NaN`, `''`) becomes a
920
+ * gap — the line breaks there. Anything genuinely broken throws, naming the
921
+ * row, instead of drawing a chart that is quietly wrong.
922
+ */
923
+ declare function toDataPoints<T>(rows: readonly T[], spec?: ToDataPointsSpec<T>): DataPoint[];
924
+ /**
925
+ * The same conversion for a whole series at once — the one-liner most callers
926
+ * actually want:
927
+ *
928
+ * ```ts
929
+ * series: [toSeries('Temperature', rows, { time: 'ts', value: 'val' })]
930
+ * ```
931
+ */
932
+ declare function toSeries<T>(name: string, rows: readonly T[], spec?: ToDataPointsSpec<T>): {
933
+ name: string;
934
+ data: DataPoint[];
935
+ };
936
+
937
+ export { AggregatedPoint, AggregatedSeries, Annotation, AnnotationBandBuilder, AnnotationBandConfig, AnnotationBandItem, AnnotationBandItemBuilder, AnnotationBuilder, AnySeries, type AxesConfig, type AxisLabelsStyle, type AxisStyle, DataPoint, DrawCommand, type FieldAccessor, type FillBetweenThresholdsInput, FillSpec, Gap, GapsConfig, GraphBuilder, type GridLineStyle, type GridStyle, HatchVariant, Highlight, HighlightBuilder, LegendItem, type LegendOptions, LegendOrientation, type LegendPosition, type LimitStatsPoint, LineVariant, MLTimeGraph, type MLTimeGraphOptions, type Margin, Marker, MarkerBuilder, type MktPoint, PointStyleType, SVGRenderer, SeriesStyle, type StatsAggregatedPoint, type StdDevPoint, Threshold, ThresholdBuilder, ThresholdLabelPosition, type TickConfig, type TimeInput, TimeSeries, TimeSeriesBuilder, type ToDataPointsSpec, type TooltipOptions, type TooltipSample, type XAxisConfig, type YAxisConfig, attachTooltip, fillBetweenThresholds, mount, parseAggregated, parseDataPoint, parseSeries, toDataPoints, toSeries };