@ndmspc/ndmvr-core 1.1.2-rc.5 → 1.1.2-rc.6
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.
- package/dist/index.es.js +15 -14
- package/dist/index.umd.js +3 -3
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1018,20 +1018,20 @@ function et(e) {
|
|
|
1018
1018
|
}
|
|
1019
1019
|
return t;
|
|
1020
1020
|
}, n = [];
|
|
1021
|
-
n[0] = { content: t(e.fArray) }, e.fArrays && Object.keys(e?.fArrays).forEach((r) => {
|
|
1021
|
+
n[0] = { content: t(e.fArray?.filter((e) => e !== 0)) }, e.fArrays && Object.keys(e?.fArrays).forEach((r) => {
|
|
1022
1022
|
n[0] = {
|
|
1023
1023
|
...n[0],
|
|
1024
|
-
[r]: e.fArrays[r].max ?? t(e.fArrays[r].values)
|
|
1024
|
+
[r]: e.fArrays[r].max ?? t(e.fArrays[r].values?.filter((e) => e !== 0))
|
|
1025
1025
|
};
|
|
1026
1026
|
});
|
|
1027
1027
|
let r = (e, i = 1) => {
|
|
1028
1028
|
n[i] || (n[i] = {}), Object.entries(e).forEach(([e, a]) => {
|
|
1029
1029
|
a.forEach((a) => {
|
|
1030
1030
|
if (!a) return;
|
|
1031
|
-
let o = t(a.fArray);
|
|
1031
|
+
let o = t(a.fArray?.filter((e) => e !== 0));
|
|
1032
1032
|
(!(e in n[i]) || o > n[i][e]) && (n[i][e] = o), a.fArrays && Object.keys(a.fArrays).forEach((e) => {
|
|
1033
1033
|
let r = a.fArrays[e].max;
|
|
1034
|
-
(!(e in n[i]) || r > n[i][e]) && (n[i][e] = r), n[i][e] = Math.max(n[i][e], a.fArrays[e].max ?? t(a.fArrays[e].values));
|
|
1034
|
+
(!(e in n[i]) || r > n[i][e]) && (n[i][e] = r), n[i][e] = Math.max(n[i][e], a.fArrays[e].max ?? t(a.fArrays[e].values?.filter((e) => e !== 0)));
|
|
1035
1035
|
}), a.children && r(a.children, i + 1);
|
|
1036
1036
|
});
|
|
1037
1037
|
});
|
|
@@ -1693,7 +1693,7 @@ var $ = class {
|
|
|
1693
1693
|
o.fXaxis.fNbins,
|
|
1694
1694
|
o.fYaxis.fNbins,
|
|
1695
1695
|
o.fZaxis.fNbins
|
|
1696
|
-
]), u, d, f, p, m = o.fArrays?.[this.selectedArray]?.outside ?? !1, h = this.selectedSet.indexOf(c), g = this.availableSets.indexOf(c), _ = o.fArrays ? o.fArrays[Object.keys(o.fArrays)[0]].values : !1, v = this.availableAxes[a], y = this.config.scale.scaleBy === "value";
|
|
1696
|
+
]), u, d, f, p, m = o.fArrays?.[this.selectedArray]?.outside ?? !1, h = this.selectedSet.indexOf(c), g = this.availableSets.indexOf(c), _ = o.fArrays ? o.fArrays[Object.keys(o.fArrays)[0]].values ?? !1 : !1, v = this.availableAxes[a], y = this.config.scale.scaleBy === "value";
|
|
1697
1697
|
if (c) if (this.config.scale.sets === "fixed") ({min: u, max: d} = this.minMaxValue[a + this.pointer.parentPath.length][c].value), {min: p, max: f} = this.minMaxValue[a + this.pointer.parentPath.length][c].error;
|
|
1698
1698
|
else if (this.config.scale.sets === "relative") {
|
|
1699
1699
|
let e = o.fSumw2.filter((e) => e !== 0), t = y ? o.fArray.filter((e) => e !== 0) : e;
|
|
@@ -1735,12 +1735,13 @@ var $ = class {
|
|
|
1735
1735
|
x: l.getValueAt(0),
|
|
1736
1736
|
y: l.getValueAt(1),
|
|
1737
1737
|
z: l.getValueAt(2)
|
|
1738
|
-
}, S = Ye(s.position.z, s.scale.z, qe(Je(o, e, T, s?.scale, s?.position, a, r))), w = this.config.scale.scaleBy === "value" ? u : p, O = this.config.scale.scaleBy === "value" ? d : f;
|
|
1739
|
-
w
|
|
1740
|
-
let
|
|
1741
|
-
if (
|
|
1738
|
+
}, S = Ye(s.position.z, s.scale.z, qe(Je(o, e, T, s?.scale, s?.position, a, r))), w = this.config.scale.scaleBy === "value" ? u : p, O = this.config.scale.scaleBy === "value" ? d : f, k = _ || this.selectedArray === "content" ? this.getBinContent(o, e.x, e.y, e.z, this.selectedArray) : O, A = _ || this.selectedArray === "content" ? this.getBinError(o, e.x, e.y, e.z, this.selectedArray) : 0;
|
|
1739
|
+
console.log("scaleMin", w, "scaleMax", O, "content", k);
|
|
1740
|
+
let j = this.config.scale.scaleBy === "value" ? k : A, M = 1;
|
|
1741
|
+
if (w === O) M = 1;
|
|
1742
|
+
else if (j >= w == !m) {
|
|
1742
1743
|
let e = v[0].scaleType === "log10" ? Math.log(1 + (j - w)) / Math.log(1 + (O - w)) : (j - w) / (O - w);
|
|
1743
|
-
if (!m) M =
|
|
1744
|
+
if (!m) M = (D - E) * e + E, M > 1 && (M = 1);
|
|
1744
1745
|
else {
|
|
1745
1746
|
let e = (k - void 0) / (void 0 - void 0);
|
|
1746
1747
|
M = Number.isInteger(k) && k === 0 ? M = 0 : (D - E) * e + E;
|
|
@@ -1983,8 +1984,8 @@ var $ = class {
|
|
|
1983
1984
|
], i = (e) => {
|
|
1984
1985
|
let t = [];
|
|
1985
1986
|
t.push({
|
|
1986
|
-
|
|
1987
|
-
|
|
1987
|
+
size: "linear",
|
|
1988
|
+
color: "linear"
|
|
1988
1989
|
});
|
|
1989
1990
|
let a = Number.parseInt(e._typename.substring(2, 3), 10);
|
|
1990
1991
|
for (let n = 0; n < a; n++) {
|
|
@@ -1993,8 +1994,8 @@ var $ = class {
|
|
|
1993
1994
|
axis: i,
|
|
1994
1995
|
fTitle: a.fTitle,
|
|
1995
1996
|
fName: a.fName,
|
|
1996
|
-
|
|
1997
|
-
|
|
1997
|
+
size: "linear",
|
|
1998
|
+
color: "linear",
|
|
1998
1999
|
fXmax: a.fXmax,
|
|
1999
2000
|
fXmin: a.fXmin
|
|
2000
2001
|
});
|
package/dist/index.umd.js
CHANGED
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
<div class="regionUI baseColor" style="bottom: 10px; right: 10px;">
|
|
34
34
|
</div>
|
|
35
35
|
</div>
|
|
36
|
-
`}},de=async e=>{let t;t=e.startsWith(`root://`)?e.replace(/^root:\/\//,`https://`).replace(/\/\//g,`/`):e,console.log(`Fetching from URL: ${t}`);let n=await fetch(t);if(!n.ok)throw Error(`Response status: ${n.status}`);return n.json()},fe=class{raycaster;mouse;cameraElement;sceneElement;singleClickTimer;dbClickTimeout;configSub;rendererElement;raycastOn;constructor(e,t){this.singleClickTimer=null,this.dbClickTimeout=190,this.raycastOn=!0,this.rendererElement=t,this.raycaster=new r.Raycaster,this.mouse=new r.Vector2,this.sceneElement=e,this.checkInterval=1,this.lastCheck=void 0,e.traverse(e=>{e.isCamera&&(this.cameraElement=e)}),this.mousemoveEventHandle=this.mousemoveEventHandle.bind(this),this.clickEventHandle=this.clickEventHandle.bind(this),this.setupRaycasting(),this.configSub=L().getObservable().subscribe(e=>{this.dbClickTimeout=e.config.environment.dbClickTimeout??190})}setupRaycasting(){window.addEventListener(`mousemove`,this.mousemoveEventHandle),window.addEventListener(`click`,this.clickEventHandle)}destroyRaycasting(){window.removeEventListener(`mousemove`,this.mousemoveEventHandle),window.removeEventListener(`click`,this.clickEventHandle)}toggleRaycasting(){this.raycastOn=!this.raycastOn,this.raycastOn?this.setupRaycasting():this.destroyRaycasting()}mousemoveEventHandle(e){let t=performance.now();t-this.lastCheck<this.checkInterval||(this.lastCheck=t,this.updateRaycaster(e))}clickEventHandle(e){let t=this.rendererElement.getBoundingClientRect();this.mouse.x=(e.clientX-t.left)/t.width*2-1,this.mouse.y=-((e.clientY-t.top)/t.height)*2+1,this.raycaster.setFromCamera(this.mouse,this.cameraElement);let n=Date.now(),r=(this.lastClick?n-this.lastClick:1/0)<this.dbClickTimeout;this.singleClickTimer&&=(clearTimeout(this.singleClickTimer),null),r?(this.raycaster._triggerSource=e.shiftKey?`shiftmousedbclick`:`mousedbclick`,this.handleRaycast()):this.singleClickTimer=setTimeout(()=>{this.raycaster._triggerSource=e.shiftKey?`shiftmouseclick`:`mouseclick`,this.handleRaycast(),this.singleClickTimer=null},this.dbClickTimeout),this.lastClick=n}handleRaycast(){this.raycaster.intersectObjects(this.sceneElement.children,!0).length}updateRaycaster(e){let t=this.rendererElement.getBoundingClientRect();this.mouse.x=(e.clientX-t.left)/t.width*2-1,this.mouse.y=-((e.clientY-t.top)/t.height)*2+1,this.raycaster.setFromCamera(this.mouse,this.cameraElement),this.raycaster._triggerSource=`mousemove`,this.raycaster.intersectObjects(this.sceneElement.children,!0)}},U=class{constructor(e){this.limits=new Int32Array(e),this.values=new Int32Array(e.length)}increment(){for(let e=0;e<this.values.length;e++){if(this.values[e]++,this.values[e]<this.limits[e])return!0;this.values[e]=0}return!1}getIndex(){let e=0,t=1;for(let n=0;n<this.values.length;n++)e+=this.values[n]*t,t*=this.limits[n];return e}setFromNumber(e){for(let t=0;t<this.limits.length;t++)this.values[t]=Math.floor(e%this.limits[t]),e=Math.floor(e/this.limits[t])}getValueAt(e){return this.values[e]}getValues(){return[...this.values]}reset(){this.values.fill(0)}};function pe(e,t){return t<=0?e.fXmin:t>e.fNbins?e.fXmax:e.GetBinLowEdge(t+1)}function W(e,t,n,r,i,a,o){let s=t+1,c=e.GetBinLowEdge(s),l=pe(e,s),u=Math.abs(l-c);if(o.size=u,o.pos=c+u*.5-e.fXmin,n){let t=(e.fXmax-e.fXmin)*e.fNbins/(n*e.fNbins);o.pos/=t,o.size/=t,o.size*=1-r,o.pos-=n*.5,o.pos+=i}}function me(e,t,n,r,i,a,o){W(e.fXaxis,t.x,n?.x,r?.x,i?.x,a,o.x),W(e.fYaxis,t.y,n?.z,r?.y,i?.z,a,o.y),W(e.fZaxis,t.z,n?.y,r?.z,i?.y,a,o.z)}function G(e){let t=e.y.size,n=e.y.pos;return e.y.size=e.z.size,e.y.pos=e.z.pos,e.z.size=t,e.z.pos=n,e}function K(e,t,n,r,i,a,o){return me(e,t,r,n,i,a,o),o}function he(e,t,n){return n.z.pos=2*e-n.z.pos,n}function ge(e,t){if(e.length!==t.length)return!1;let n={};for(let t of e)n[t]=(n[t]||0)+1;for(let e of t){if(!n[e])return!1;n[e]--}return!0}function _e(e,t){if(!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++){let r=Object.keys(e[n]),i=Object.keys(t[n]);if(r.length!==i.length)return!1;for(let i of r){if(!t[n].hasOwnProperty(i))return!1;let r=e[n][i],a=t[n][i];if(typeof r!=typeof a)return!1;if(typeof r==`object`){if(!r||!a){if(r!==a)return!1;continue}let e=Object.keys(r),t=Object.keys(a);if(e.length!==t.length)return!1;for(let t of e)if(!a.hasOwnProperty(t)||r[t]!==a[t])return!1}else if(r!==a)return!1}}return!0}function q(e,t,n,r){let i=Array(e.length).fill(0),a=(t,o,s)=>{let c=o.fXaxis.fNbins,l=o.fYaxis.fNbins;o.fZaxis.fNbins;let u=n.slice(-n.length+t+1).reduce((e,t)=>e*t,1);if(i[s]+=(e[t].x+e[t].y*c+e[t].z*c*l)*u,t+1<e.length){let n;n=o.children.content?o.children.content[o.getBin(e[t].x+1,e[t].y+1,e[t].z+1)]:o.children[r[0]][o.getBin(e[t].x+1,e[t].y+1,e[t].z+1)],s>t&&a(t+1,n,s)}};for(let n=0;n<e.length;n++)a(0,t,n);return i}function J(e,t,n){let r=Array(e.length).fill(0);for(let i=0;i<e.length;i++)if(r[i]=t.getBin(e[i].x+1,e[i].y+1,e[i].z+1),t.children)t=t.children?.content?t.children.content[r[i]]:t.children[n[0]]?.[r[i]];else return r;return r}function Y(e,t,n,r,i,a=0){let o=[`x`,`y`,`z`],s=Number.parseInt(n._typename.substring(2,3),10),c={};if(e[0]){for(let t=0;t<s;t++){let r=o[t],i=n[`f${r.toUpperCase()}axis`],a=e[0][r];c[r]={min:i.GetBinLowEdge(a+1),max:i.GetBinCenter(a+1)*2-i.GetBinLowEdge(a+1),name:i.fName,title:i.fTitle,label:i.fLabels?.arr[a]?.fString}}c={...c,color:r.getColorAt(a,t),name:n.fName}}if(e[1]){let o;return n.children?.content?o=n.children.content[n.getBin(e[0].x+1,e[0].y+1,e[0].z+1)]:n.children?.[i[0]]&&(o=n.children[i[0]][n.getBin(e[0].x+1,e[0].y+1,e[0].z+1)]),[c,...Y(e.slice(1),t,o,r,i,a+1)]}else return[c]}function ve(e,t,n,r){let i=0,a=n.slice(1),o=[];for(let e=0;e<a.length;e++){let t=a.slice(e).reduce((e,t)=>e*t,1);o.push(t)}let s=(t,n)=>{let{fNbins:a}=n.fXaxis,{fNbins:c}=n.fYaxis,{fNbins:l}=n.fZaxis,u=e[t].x+e[t].y*a+e[t].z*a*c;if(i+=u*o[t],t+1<e.length){let i=ye(n,e[t],r);s(t+1,i)}};return s(0,t),i}function ye(e,t,n){let r=e.getBin(t.x+1,t.y+1,t.z+1);return e.children.content?e.children.content[r]:e.children[n[0]][r]}function X(e,t,n){let r=t.splice(0,1)[0];return t.length>0?X(e.children.content[r],t,n):e.children.content?e.children.content[r]:e.children[n][r]}function be(e){if(!e)return;let t=e=>{let t=-1/0;if(!e)return null;for(let n=0;n<e.length;n++){let r=e[n];r>t&&(t=r)}return t},n=[];n[0]={content:t(e.fArray)},e.fArrays&&Object.keys(e?.fArrays).forEach(r=>{n[0]={...n[0],[r]:e.fArrays[r].max??t(e.fArrays[r].values)}});let r=(e,i=1)=>{n[i]||(n[i]={}),Object.entries(e).forEach(([e,a])=>{a.forEach(a=>{if(!a)return;let o=t(a.fArray);(!(e in n[i])||o>n[i][e])&&(n[i][e]=o),a.fArrays&&Object.keys(a.fArrays).forEach(e=>{let r=a.fArrays[e].max;(!(e in n[i])||r>n[i][e])&&(n[i][e]=r),n[i][e]=Math.max(n[i][e],a.fArrays[e].max??t(a.fArrays[e].values))}),a.children&&r(a.children,i+1)})})};return e.children&&r(e.children),n}function xe(e,t){if(!e)return;let n=e=>{if(!e)return null;let t=0;for(let n=0;n<e.length;n++){let r=e[n];r>t&&(t=r)}return t},r=[];r[0]={content:n(e.fSumw2)},e.fArrays&&Object.keys(e?.fArrays).forEach(t=>{e.fArrays[t].errors&&(r[0]={...r[0],[t]:n(e.fArrays[t].errors)??Math.sqrt(e.fArrays[t].max)})});let i=(e,t=1)=>{r[t]||(r[t]={}),Object.entries(e).forEach(([e,a])=>{a.forEach(a=>{if(!a)return;let o=n(a.fSumw2),s=isNaN(o)?0:o;(!(e in r[t])||s>r[t][e])&&(r[t][e]=s),a.fArrays&&Object.keys(a.fArrays).forEach(e=>{a.fArrays[e].errors&&((!(e in r[t])||s>r[t][e])&&(r[t][e]=s),r[t][e]=Math.max(r[t][e],n(a.fArrays[e].errors)??Math.sqrt(a.fArrays[e].max)))}),a.children&&i(a.children,t+1)})})};e.children&&i(e.children);for(let e=0;e<r.length;e++)Object.keys(r[e]).forEach(n=>{r[e][n]===0&&(r[e][n]=Math.sqrt(t[e][n]))});return r}function Se(e,t){if(!e)return;let n=e=>{let t=1/0;if(!e)return null;for(let n=0;n<e.length;n++){let r=e[n];r!==0&&r<t&&(t=r)}return t},r=[];r[0]={content:n(e.fSumw2)},e.fArrays&&Object.keys(e?.fArrays).forEach(t=>{e.fArrays[t].errors&&(r[0]={...r[0],[t]:n(e.fArrays[t].errors)??Math.sqrt(e.fArrays[t].min)})});let i=(t,a=1)=>{r[a]||(r[a]={}),Object.entries(t).forEach(([t,o])=>{o.forEach(o=>{if(!o)return;let s=n(o.fSumw2),c=isNaN(s)?0:s;(!(t in r[a])||c<r[a][t])&&(r[a][t]=c),o.fArrays&&Object.keys(o.fArrays).forEach(t=>{o.fArrays[t].errors&&((!(t in r[a])||c<r[a][t])&&(r[a][t]=c),r[a][t]=Math.min(r[a][t],n(o.fArrays[t]?.errors?.filter(e=>e>0))??Math.sqrt(e.fArrays[t].min)))}),o.children&&i(o.children,a+1)})})};e.children&&i(e.children);for(let e=0;e<r.length;e++)Object.keys(r[e]).forEach(n=>{(r[e][n]===0||r[e][n]===1/0)&&(r[e][n]=Math.sqrt(t[e][n]))});return r}function Ce(e){if(!e)return;let t=e=>{let t=1/0;if(!e)return null;for(let n=0;n<e.length;n++){let r=e[n];r<t&&(t=r)}return t},n=[];n[0]={content:t(e.fArray.filter(e=>e!==0))},e.fArrays&&Object.keys(e?.fArrays).forEach(r=>{n[0]={...n[0],[r]:e.fArrays[r].min??t(e.fArrays[r]?.values?.filter(e=>e!==0))}});let r=(e,i=1)=>{n[i]||(n[i]={}),Object.entries(e).forEach(([e,a])=>{a.forEach(a=>{if(!a)return;let o=t(a.fArray.filter(e=>e!==0));(!(e in n[i])||o<n[i][e])&&(n[i][e]=o),a.fArrays&&Object.keys(a.fArrays).forEach(e=>{let r=a.fArrays[e].min;(!(e in n[i])||r<n[i][e])&&(n[i][e]=r),n[i][e]=Math.min(n[i][e],a.fArrays[e].min??t(a.fArrays[e]?.values?.filter(e=>e!==0)))}),a.children&&r(a.children,i+1)})})};return e.children&&r(e.children),n}function we(e){if(!e)return;let t=e.fXaxis.fNbins*e.fYaxis.fNbins*e.fZaxis.fNbins,n=[];n.push(t);let r=(e,t=1)=>{let i=0;return t>=n.length&&n.push(1),Object.entries(e).forEach((e,a)=>{e[1].forEach(e=>{e&&(i=e.fXaxis.fNbins*e.fYaxis.fNbins*e.fZaxis.fNbins,i>n[t]&&(n[t]=i),e.children&&r(e.children,t+1))})}),n};return e.children&&r(e.children),n.push(1),n}function Te(e,t,n){new r.Color(e.color.default.min).toArray(n,0),new r.Color(e.color.default.max).toArray(n,3);let i=1;e.color.layer.forEach(e=>{let t=i*6;new r.Color(e.min).toArray(n,t),new r.Color(e.max).toArray(n,t+3),i++}),e.color.set.forEach(e=>{let t=i*6;new r.Color(e.min).toArray(n,t),new r.Color(e.max).toArray(n,t+3),i++}),t.uniforms.colorPairs={value:n},t.uniformsNeedUpdate=!0}function Ee(e,t,n,r,i,a,o){let s=((e,t,n)=>{let r;return r=o===`log10`?Math.log(1+(e-t))/Math.log(1+(n-t)):(e-t)/(n-t),r>1&&(r=1),isNaN(r)||r===1/0?0:r})(t,n,r),c=0;return e.set[i]?c=1+e.layer.length+i:e.layer[a]&&(c=1+a),c+s}function De(e,t,n,r,i,a,o){if(!(1/e==-1/0||e<0))return o[0]=t[e],o[1]=t[e+1],o[2]=t[e+2],o[3]=n[e],o[4]=n[e+1],o[5]=n[e+2],o;let s=Math.abs(e),c=a===null?r[i]:r[i][a];return o[0]=c.pos[s],o[1]=c.pos[s+1],o[2]=c.pos[s+2],o[3]=c.scale[s],o[4]=c.scale[s+1],o[5]=c.scale[s+2],o}var Oe=e=>{if(!e)return!1;for(let t in e)if(t!==`content`&&Object.prototype.hasOwnProperty.call(e,t)&&e[t]&&typeof e[t]==`object`&&Object.keys(e[t]).length>0)return!0;return!1};function Z(e,t,n,r,i,a,o){let s=t.fXaxis.fNbins,c=t.fYaxis.fNbins,l=t.fZaxis.fNbins,u=0,d=0,f=new Float32Array((s*c*l-1)*3),p=new Float32Array((s*c*l-1)*3),m=new Float32Array(s*c*l-1),h=new Float32Array(s*c*l-1),g=new Float32Array(s*c*l-1),_=new Float32Array(6),v=new Float32Array(6),y=e=>{let t=x*3;f[t]=e[0],f[t+1]=e[1],f[t+2]=e[2],p[t]=e[3],p[t+1]=e[4],p[t+2]=e[5],m[x]=e[6],h[x]=e[7],g[x]=e[8]},b=(t,n,r,i)=>{De(t,f,p,e,r,i,_),De(n,f,p,e,r,i,v);let a=_[0]-_[3]*.5<v[0]-v[3]*.5?_[0]-_[3]*.5:v[0]-v[3]*.5,o=_[1]-_[4]*.5<v[1]-v[4]*.5?_[1]-_[4]*.5:v[1]-v[4]*.5,s=_[2]-_[5]*.5<v[2]-v[5]*.5?_[2]-_[5]*.5:v[2]-v[5]*.5,c=_[0]+_[3]*.5>v[0]+v[3]*.5?_[0]+_[3]*.5:v[0]+v[3]*.5,l=_[1]+_[4]*.5>v[1]+v[4]*.5?_[1]+_[4]*.5:v[1]+v[4]*.5,u=_[2]+_[5]*.5>v[2]+v[5]*.5?_[2]+_[5]*.5:v[2]+v[5]*.5,d=new Float32Array(9);return d[0]=(a+c)*.5,d[1]=(o+l)*.5,d[2]=(s+u)*.5,d[3]=c-a,d[4]=l-o,d[5]=u-s,d},x=0;for(let e=0;e<c;e++){for(let e=0;e<l;e++){let e=u+o,t=Array(s);for(let n=0;n<s;n++)t[n]=-n-e;for(;t.length>1;){let e=0,i=Math.floor(t.length/2);for(let o=0;o<i;o++){let i=t[e],o=t[e+1],s=b(i*3,o*3,n,r);t.splice(e,2,x),Q(s,a),s[6]=1/i==-1/0||i<0?i:g[i],s[7]=1/o==-1/0||o<0?o:g[o],s[8]=d,y(s),x+=1,d+=1,e+=1}}u+=s}let e=Array(l);for(let t=0;t<l;t++)e[t]=x-1-(l-1-t)*(s-1);for(;e.length>1;){let t=0,i=Math.floor(e.length/2);for(let o=0;o<i;o++){let i=e[t],o=e[t+1],s=b(i*3,o*3,n,r);e.splice(t,2,x),Q(s,a),s[6]=g[i],s[7]=g[o],s[8]=d,y(s),x+=1,d+=1,t+=1}}}let S=Array(c);for(let e=0;e<c;e++)S[e]=x-1-(c-1-e)*(s*l-1);for(;S.length>1;){let e=0,t=Math.floor(S.length/2);for(let i=0;i<t;i++){let t=S[e],i=S[e+1],o=b(t*3,i*3,n,r);S.splice(e,2,x),Q(o,a),o[6]=g[t],o[7]=g[i],o[8]=d,y(o),x+=1,d+=1,e+=1}}return{pos:f,scale:p,left:m,right:h}}function ke(e,t,n,r,i,a,o,s){let c=Array(e.length).fill().map(e=>[]);c[c.length-1]=Array.from({length:a.length},()=>[]),i===null?c[0]=[Z(e,t,n,null,a,o,0)]:(c[0]=Array(a.length),r.forEach(r=>c[0][a.indexOf(r)]=Z(e,t,n,a.indexOf(r),a,o,0)));let l=(t,n,i)=>{if(!t.children)return;let u=new U([t.fXaxis.fNbins,t.fYaxis.fNbins,t.fZaxis.fNbins]),d=t.fXaxis.fNbins*t.fYaxis.fNbins*t.fZaxis.fNbins,f=s.slice(1,n-1).reduce((e,t)=>e*t,s[1]),p=s[n];for(let m=0;m<d;m++){let d={x:u.getValueAt(0),y:u.getValueAt(1),z:u.getValueAt(2)};if(t?.children?.content){let r=t.children.content[t.getBin(d.x+1,d.y+1,d.z+1)];if(!r){if(u.increment()===!1)break;continue}c[n][m+i]=Z(e,r,n,null,a,o,(m+i)*p),l(r,n+1,(u.getIndex()+i)*f)}else Oe(t.children)&&r.forEach((r=>{let h=a.indexOf(r),g=(m+i)*p,_=!1;for(let t=g;t<g+s[n];t++)if(e[n][h].rendered[t]!==-1){_=!0;break}if(!_){c[n][h].push(null);return}let v=t.children[r][t.getBin(d.x+1,d.z+1,d.y+1)];v&&(c[n][h][m+i]=Z(e,v,n,h,a,o,(m+i)*p),l(v,n+1,(u.getIndex()+i)*f))}));if(u.increment()===!1)break}};return l(t,1,0),c}function Q(e,t){let n=t.elements,r=Math.sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]),i=Math.sqrt(n[4]*n[4]+n[5]*n[5]+n[6]*n[6]),a=Math.sqrt(n[8]*n[8]+n[9]*n[9]+n[10]*n[10]);e[0]=e[0]*r+n[12],e[1]=e[1]*i+n[13],e[2]=e[2]*a+n[14],e[3]*=r,e[4]*=i,e[5]*=a}var $=class{rootObj=void 0;origin=void 0;parentPath=[];path=void 0;title=void 0;range=[];isOnSet=null;isHistogramFilled=!0;constructor(e){this.rootObj=e,this.origin=this.rootObj,this.title=this.origin.fTitle,this.path=this.origin.fName}setOriginToChild(e,t,n){if(!e)return;let r=e.splice(0,1);if(this.origin?.children){if(this.origin.children?.content)this.parentPath.push({origin:this.origin,range:n.splice(0,1),bin:r}),this.origin=this.origin.children.content[r],this.isOnSet=null;else if(Object.keys(this.origin.children).includes(t)){if(this.parentPath.push({origin:this.origin,range:n.splice(0,1),bin:r}),!this.origin.children[t][r]){this.isHistogramFilled=!1,this.path+=`/empty`,this.origin=null;return}this.origin=this.origin.children[t][r],this.isOnSet=t}else{console.error(`Bad set or index specified.`);return}this.title=this.origin.fTitle,this.path=this.path+`/`+this.origin.fName,e.length>0&&this.setOriginToChild(e,t,n)}}getChildByPosition(e,t,n=this.origin){if(!e||e.length===0)return{...n};let r=e.splice(0,1)[0];return n?.children?n.children?.content?this.getChildByPosition(e,t,n.children.content[r]):Object.keys(n.children).includes(t)?this.getChildByPosition(e,t,n.children[t][r]):(console.error(`Bad set or index specified.`),null):{...n}}setOriginToParent(e=1){if(e<=0||this.parentPath.length===0)return;let t=this.path.lastIndexOf(`/`);this.path=this.path.slice(0,t);let n=this.parentPath.pop();n&&(this.origin=n.origin),this.title=this.origin.fTitle,this.setOriginToParent(e-1),this.isOnSet=null,this.isHistogramFilled=!0}},Ae=class{wireframe=void 0;instGeom=void 0;material=void 0;totalInstances=void 0;maxInstancesPerLayer=void 0;instancePositions=void 0;instanceScales=void 0;instanceColors=void 0;colorArray=void 0;configSub=void 0;stateSub=void 0;config=void 0;numOfavailableSets=void 0;visibility=!0;id=void 0;constructor(e,t,n,i){this.config=n,this.maxInstancesPerLayer=e,this.id=i;let a=new r.EdgesGeometry(new r.BoxGeometry(1,1,1));this.instGeom=new r.InstancedBufferGeometry,this.instGeom.instanceCount=0,this.instGeom.frustumCulled=!1,this.instGeom.index=a.index;for(let e in a.attributes)this.instGeom.setAttribute(e,a.attributes[e]);this.material=this.createMaterial(),this.colorArray=new Float32Array(96),this.fillColorArray(),this.instancePositions=new Float32Array(3),this.instanceScales=new Float32Array(3),this.instanceColors=new Float32Array(1),this.instGeom.setAttribute(`instancePosition`,new r.InstancedBufferAttribute(this.instancePositions,3)),this.instGeom.setAttribute(`instanceScale`,new r.InstancedBufferAttribute(this.instanceScales,3)),this.instGeom.setAttribute(`instanceColorIndex`,new r.InstancedBufferAttribute(this.instanceColors,1)),this.wireframe=new r.LineSegments(this.instGeom,this.material),this.wireframe.frustumCulled=!1,this.stateSub=v(this.id).getObservable().subscribe(e=>{this.numOfavailableSets=e.sets.length})}pushVisibleInstances(e,t,n){let i=this.wireframe.parent;i&&(i.remove(this.wireframe),this.instGeom.dispose());let a=this.config.display.start??0,o=this.config.display.end??e.length-1,s=[],c=e.length-1;{let t=(Array.isArray(e[c])?e[c][n]:e[c]).rendered,r=new Uint8Array(t.length);for(let e=0;e<t.length;e++)r[e]=t[e]===-1?0:1;s[c]=r}for(let r=c-1;r>=0;r--){let i=(Array.isArray(e[r])?e[r][n]:e[r]).rendered,a=s[r+1],o=t[r+1]||0,c=new Uint8Array(i.length);for(let e=0;e<i.length;e++){if(i[e]!==-1){c[e]=1;continue}let t=e*o,n=t+o;for(let r=t;r<n;r++)if(a[r]){c[e]=1;break}}s[r]=c}let l=(e,t)=>e<a||e>o?!1:s[e][t]===1,u=(r,i)=>{let a=0,o=r,s=i;for(;o+1<e.length;){o++,s*=t[o];let i=e[o],c=Array.isArray(i)?i[n===-1?0:n]:i;for(let e=s;e<s+t[o];e++)if(c.rendered[e]!==-1){a=o-r;break}}return a},d=0;for(let t=0;t<e.length;t++){let n=e[t];if(!Array.isArray(n))for(let e=0;e<n.rendered.length;e++)l(t,e)&&d++}let f=new Float32Array(d*3),p=new Float32Array(d*3),m=new Float32Array(d),h=0;for(let t=0;t<e.length;t++){let r=e[t],i=this.getColorIndex(t,n);if(!Array.isArray(r)){for(let e=0;e<r.rendered.length;e++)if(l(t,e)){let n=u(t,e)*.05;f[h*3]=r.pos[e*3],f[h*3+1]=r.pos[e*3+1],f[h*3+2]=r.pos[e*3+2],p[h*3]=r.scale[e*3]+n,p[h*3+1]=r.scale[e*3+1]+n,p[h*3+2]=r.scale[e*3+2]+n,m[h++]=i}}}let g=new r.EdgesGeometry(new r.BoxGeometry(1,1,1));this.instGeom=new r.InstancedBufferGeometry,this.instGeom.instanceCount=d,this.instGeom.frustumCulled=!1,this.instGeom.index=g.index;let _=g.attributes;for(let e in _)this.instGeom.setAttribute(e,_[e]);this.instancePositions=f,this.instanceScales=p,this.instanceColors=m,this.instGeom.setAttribute(`instancePosition`,new r.InstancedBufferAttribute(f,3)),this.instGeom.setAttribute(`instanceScale`,new r.InstancedBufferAttribute(p,3)),this.instGeom.setAttribute(`instanceColorIndex`,new r.InstancedBufferAttribute(m,1)),this.wireframe=new r.LineSegments(this.instGeom,this.material),this.wireframe.frustumCulled=!1,i&&i.add(this.wireframe)}toggleVisibility(e,t,n){this.visibility=!this.visibility,this.visibility?this.pushVisibleInstances(e,t,n):this.clearWireframe()}dispose(){this.instancePositions=[],this.instanceScales=[],this.wireframe.parent.remove(this.wireframe),this.instGeom.dispose()}clearWireframe(){this.instancePositions=new Float32Array(3),this.instanceScales=new Float32Array(3),this.instanceColors=new Float32Array(1),this.instGeom.dispose(),this.instGeom.instanceCount=0}fillColorArray(){new r.Color(this.config.color.default).toArray(this.colorArray,0);let e=1;this.config.color.layer.map(e=>new r.Color(e)).forEach(t=>{let n=e*3;t.toArray(this.colorArray,n),e++}),this.config.color.set.map(e=>new r.Color(e)).forEach(t=>{let n=e*3;t.toArray(this.colorArray,n),e++}),this.material.uniforms.colorArray={value:this.colorArray},this.material.uniformsNeedUpdate=!0}createMaterial(){return new r.ShaderMaterial({vertexShader:`
|
|
36
|
+
`}},de=async e=>{let t;t=e.startsWith(`root://`)?e.replace(/^root:\/\//,`https://`).replace(/\/\//g,`/`):e,console.log(`Fetching from URL: ${t}`);let n=await fetch(t);if(!n.ok)throw Error(`Response status: ${n.status}`);return n.json()},fe=class{raycaster;mouse;cameraElement;sceneElement;singleClickTimer;dbClickTimeout;configSub;rendererElement;raycastOn;constructor(e,t){this.singleClickTimer=null,this.dbClickTimeout=190,this.raycastOn=!0,this.rendererElement=t,this.raycaster=new r.Raycaster,this.mouse=new r.Vector2,this.sceneElement=e,this.checkInterval=1,this.lastCheck=void 0,e.traverse(e=>{e.isCamera&&(this.cameraElement=e)}),this.mousemoveEventHandle=this.mousemoveEventHandle.bind(this),this.clickEventHandle=this.clickEventHandle.bind(this),this.setupRaycasting(),this.configSub=L().getObservable().subscribe(e=>{this.dbClickTimeout=e.config.environment.dbClickTimeout??190})}setupRaycasting(){window.addEventListener(`mousemove`,this.mousemoveEventHandle),window.addEventListener(`click`,this.clickEventHandle)}destroyRaycasting(){window.removeEventListener(`mousemove`,this.mousemoveEventHandle),window.removeEventListener(`click`,this.clickEventHandle)}toggleRaycasting(){this.raycastOn=!this.raycastOn,this.raycastOn?this.setupRaycasting():this.destroyRaycasting()}mousemoveEventHandle(e){let t=performance.now();t-this.lastCheck<this.checkInterval||(this.lastCheck=t,this.updateRaycaster(e))}clickEventHandle(e){let t=this.rendererElement.getBoundingClientRect();this.mouse.x=(e.clientX-t.left)/t.width*2-1,this.mouse.y=-((e.clientY-t.top)/t.height)*2+1,this.raycaster.setFromCamera(this.mouse,this.cameraElement);let n=Date.now(),r=(this.lastClick?n-this.lastClick:1/0)<this.dbClickTimeout;this.singleClickTimer&&=(clearTimeout(this.singleClickTimer),null),r?(this.raycaster._triggerSource=e.shiftKey?`shiftmousedbclick`:`mousedbclick`,this.handleRaycast()):this.singleClickTimer=setTimeout(()=>{this.raycaster._triggerSource=e.shiftKey?`shiftmouseclick`:`mouseclick`,this.handleRaycast(),this.singleClickTimer=null},this.dbClickTimeout),this.lastClick=n}handleRaycast(){this.raycaster.intersectObjects(this.sceneElement.children,!0).length}updateRaycaster(e){let t=this.rendererElement.getBoundingClientRect();this.mouse.x=(e.clientX-t.left)/t.width*2-1,this.mouse.y=-((e.clientY-t.top)/t.height)*2+1,this.raycaster.setFromCamera(this.mouse,this.cameraElement),this.raycaster._triggerSource=`mousemove`,this.raycaster.intersectObjects(this.sceneElement.children,!0)}},U=class{constructor(e){this.limits=new Int32Array(e),this.values=new Int32Array(e.length)}increment(){for(let e=0;e<this.values.length;e++){if(this.values[e]++,this.values[e]<this.limits[e])return!0;this.values[e]=0}return!1}getIndex(){let e=0,t=1;for(let n=0;n<this.values.length;n++)e+=this.values[n]*t,t*=this.limits[n];return e}setFromNumber(e){for(let t=0;t<this.limits.length;t++)this.values[t]=Math.floor(e%this.limits[t]),e=Math.floor(e/this.limits[t])}getValueAt(e){return this.values[e]}getValues(){return[...this.values]}reset(){this.values.fill(0)}};function pe(e,t){return t<=0?e.fXmin:t>e.fNbins?e.fXmax:e.GetBinLowEdge(t+1)}function W(e,t,n,r,i,a,o){let s=t+1,c=e.GetBinLowEdge(s),l=pe(e,s),u=Math.abs(l-c);if(o.size=u,o.pos=c+u*.5-e.fXmin,n){let t=(e.fXmax-e.fXmin)*e.fNbins/(n*e.fNbins);o.pos/=t,o.size/=t,o.size*=1-r,o.pos-=n*.5,o.pos+=i}}function me(e,t,n,r,i,a,o){W(e.fXaxis,t.x,n?.x,r?.x,i?.x,a,o.x),W(e.fYaxis,t.y,n?.z,r?.y,i?.z,a,o.y),W(e.fZaxis,t.z,n?.y,r?.z,i?.y,a,o.z)}function G(e){let t=e.y.size,n=e.y.pos;return e.y.size=e.z.size,e.y.pos=e.z.pos,e.z.size=t,e.z.pos=n,e}function K(e,t,n,r,i,a,o){return me(e,t,r,n,i,a,o),o}function he(e,t,n){return n.z.pos=2*e-n.z.pos,n}function ge(e,t){if(e.length!==t.length)return!1;let n={};for(let t of e)n[t]=(n[t]||0)+1;for(let e of t){if(!n[e])return!1;n[e]--}return!0}function _e(e,t){if(!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++){let r=Object.keys(e[n]),i=Object.keys(t[n]);if(r.length!==i.length)return!1;for(let i of r){if(!t[n].hasOwnProperty(i))return!1;let r=e[n][i],a=t[n][i];if(typeof r!=typeof a)return!1;if(typeof r==`object`){if(!r||!a){if(r!==a)return!1;continue}let e=Object.keys(r),t=Object.keys(a);if(e.length!==t.length)return!1;for(let t of e)if(!a.hasOwnProperty(t)||r[t]!==a[t])return!1}else if(r!==a)return!1}}return!0}function q(e,t,n,r){let i=Array(e.length).fill(0),a=(t,o,s)=>{let c=o.fXaxis.fNbins,l=o.fYaxis.fNbins;o.fZaxis.fNbins;let u=n.slice(-n.length+t+1).reduce((e,t)=>e*t,1);if(i[s]+=(e[t].x+e[t].y*c+e[t].z*c*l)*u,t+1<e.length){let n;n=o.children.content?o.children.content[o.getBin(e[t].x+1,e[t].y+1,e[t].z+1)]:o.children[r[0]][o.getBin(e[t].x+1,e[t].y+1,e[t].z+1)],s>t&&a(t+1,n,s)}};for(let n=0;n<e.length;n++)a(0,t,n);return i}function J(e,t,n){let r=Array(e.length).fill(0);for(let i=0;i<e.length;i++)if(r[i]=t.getBin(e[i].x+1,e[i].y+1,e[i].z+1),t.children)t=t.children?.content?t.children.content[r[i]]:t.children[n[0]]?.[r[i]];else return r;return r}function Y(e,t,n,r,i,a=0){let o=[`x`,`y`,`z`],s=Number.parseInt(n._typename.substring(2,3),10),c={};if(e[0]){for(let t=0;t<s;t++){let r=o[t],i=n[`f${r.toUpperCase()}axis`],a=e[0][r];c[r]={min:i.GetBinLowEdge(a+1),max:i.GetBinCenter(a+1)*2-i.GetBinLowEdge(a+1),name:i.fName,title:i.fTitle,label:i.fLabels?.arr[a]?.fString}}c={...c,color:r.getColorAt(a,t),name:n.fName}}if(e[1]){let o;return n.children?.content?o=n.children.content[n.getBin(e[0].x+1,e[0].y+1,e[0].z+1)]:n.children?.[i[0]]&&(o=n.children[i[0]][n.getBin(e[0].x+1,e[0].y+1,e[0].z+1)]),[c,...Y(e.slice(1),t,o,r,i,a+1)]}else return[c]}function ve(e,t,n,r){let i=0,a=n.slice(1),o=[];for(let e=0;e<a.length;e++){let t=a.slice(e).reduce((e,t)=>e*t,1);o.push(t)}let s=(t,n)=>{let{fNbins:a}=n.fXaxis,{fNbins:c}=n.fYaxis,{fNbins:l}=n.fZaxis,u=e[t].x+e[t].y*a+e[t].z*a*c;if(i+=u*o[t],t+1<e.length){let i=ye(n,e[t],r);s(t+1,i)}};return s(0,t),i}function ye(e,t,n){let r=e.getBin(t.x+1,t.y+1,t.z+1);return e.children.content?e.children.content[r]:e.children[n[0]][r]}function X(e,t,n){let r=t.splice(0,1)[0];return t.length>0?X(e.children.content[r],t,n):e.children.content?e.children.content[r]:e.children[n][r]}function be(e){if(!e)return;let t=e=>{let t=-1/0;if(!e)return null;for(let n=0;n<e.length;n++){let r=e[n];r>t&&(t=r)}return t},n=[];n[0]={content:t(e.fArray?.filter(e=>e!==0))},e.fArrays&&Object.keys(e?.fArrays).forEach(r=>{n[0]={...n[0],[r]:e.fArrays[r].max??t(e.fArrays[r].values?.filter(e=>e!==0))}});let r=(e,i=1)=>{n[i]||(n[i]={}),Object.entries(e).forEach(([e,a])=>{a.forEach(a=>{if(!a)return;let o=t(a.fArray?.filter(e=>e!==0));(!(e in n[i])||o>n[i][e])&&(n[i][e]=o),a.fArrays&&Object.keys(a.fArrays).forEach(e=>{let r=a.fArrays[e].max;(!(e in n[i])||r>n[i][e])&&(n[i][e]=r),n[i][e]=Math.max(n[i][e],a.fArrays[e].max??t(a.fArrays[e].values?.filter(e=>e!==0)))}),a.children&&r(a.children,i+1)})})};return e.children&&r(e.children),n}function xe(e,t){if(!e)return;let n=e=>{if(!e)return null;let t=0;for(let n=0;n<e.length;n++){let r=e[n];r>t&&(t=r)}return t},r=[];r[0]={content:n(e.fSumw2)},e.fArrays&&Object.keys(e?.fArrays).forEach(t=>{e.fArrays[t].errors&&(r[0]={...r[0],[t]:n(e.fArrays[t].errors)??Math.sqrt(e.fArrays[t].max)})});let i=(e,t=1)=>{r[t]||(r[t]={}),Object.entries(e).forEach(([e,a])=>{a.forEach(a=>{if(!a)return;let o=n(a.fSumw2),s=isNaN(o)?0:o;(!(e in r[t])||s>r[t][e])&&(r[t][e]=s),a.fArrays&&Object.keys(a.fArrays).forEach(e=>{a.fArrays[e].errors&&((!(e in r[t])||s>r[t][e])&&(r[t][e]=s),r[t][e]=Math.max(r[t][e],n(a.fArrays[e].errors)??Math.sqrt(a.fArrays[e].max)))}),a.children&&i(a.children,t+1)})})};e.children&&i(e.children);for(let e=0;e<r.length;e++)Object.keys(r[e]).forEach(n=>{r[e][n]===0&&(r[e][n]=Math.sqrt(t[e][n]))});return r}function Se(e,t){if(!e)return;let n=e=>{let t=1/0;if(!e)return null;for(let n=0;n<e.length;n++){let r=e[n];r!==0&&r<t&&(t=r)}return t},r=[];r[0]={content:n(e.fSumw2)},e.fArrays&&Object.keys(e?.fArrays).forEach(t=>{e.fArrays[t].errors&&(r[0]={...r[0],[t]:n(e.fArrays[t].errors)??Math.sqrt(e.fArrays[t].min)})});let i=(t,a=1)=>{r[a]||(r[a]={}),Object.entries(t).forEach(([t,o])=>{o.forEach(o=>{if(!o)return;let s=n(o.fSumw2),c=isNaN(s)?0:s;(!(t in r[a])||c<r[a][t])&&(r[a][t]=c),o.fArrays&&Object.keys(o.fArrays).forEach(t=>{o.fArrays[t].errors&&((!(t in r[a])||c<r[a][t])&&(r[a][t]=c),r[a][t]=Math.min(r[a][t],n(o.fArrays[t]?.errors?.filter(e=>e>0))??Math.sqrt(e.fArrays[t].min)))}),o.children&&i(o.children,a+1)})})};e.children&&i(e.children);for(let e=0;e<r.length;e++)Object.keys(r[e]).forEach(n=>{(r[e][n]===0||r[e][n]===1/0)&&(r[e][n]=Math.sqrt(t[e][n]))});return r}function Ce(e){if(!e)return;let t=e=>{let t=1/0;if(!e)return null;for(let n=0;n<e.length;n++){let r=e[n];r<t&&(t=r)}return t},n=[];n[0]={content:t(e.fArray.filter(e=>e!==0))},e.fArrays&&Object.keys(e?.fArrays).forEach(r=>{n[0]={...n[0],[r]:e.fArrays[r].min??t(e.fArrays[r]?.values?.filter(e=>e!==0))}});let r=(e,i=1)=>{n[i]||(n[i]={}),Object.entries(e).forEach(([e,a])=>{a.forEach(a=>{if(!a)return;let o=t(a.fArray.filter(e=>e!==0));(!(e in n[i])||o<n[i][e])&&(n[i][e]=o),a.fArrays&&Object.keys(a.fArrays).forEach(e=>{let r=a.fArrays[e].min;(!(e in n[i])||r<n[i][e])&&(n[i][e]=r),n[i][e]=Math.min(n[i][e],a.fArrays[e].min??t(a.fArrays[e]?.values?.filter(e=>e!==0)))}),a.children&&r(a.children,i+1)})})};return e.children&&r(e.children),n}function we(e){if(!e)return;let t=e.fXaxis.fNbins*e.fYaxis.fNbins*e.fZaxis.fNbins,n=[];n.push(t);let r=(e,t=1)=>{let i=0;return t>=n.length&&n.push(1),Object.entries(e).forEach((e,a)=>{e[1].forEach(e=>{e&&(i=e.fXaxis.fNbins*e.fYaxis.fNbins*e.fZaxis.fNbins,i>n[t]&&(n[t]=i),e.children&&r(e.children,t+1))})}),n};return e.children&&r(e.children),n.push(1),n}function Te(e,t,n){new r.Color(e.color.default.min).toArray(n,0),new r.Color(e.color.default.max).toArray(n,3);let i=1;e.color.layer.forEach(e=>{let t=i*6;new r.Color(e.min).toArray(n,t),new r.Color(e.max).toArray(n,t+3),i++}),e.color.set.forEach(e=>{let t=i*6;new r.Color(e.min).toArray(n,t),new r.Color(e.max).toArray(n,t+3),i++}),t.uniforms.colorPairs={value:n},t.uniformsNeedUpdate=!0}function Ee(e,t,n,r,i,a,o){let s=((e,t,n)=>{let r;return r=o===`log10`?Math.log(1+(e-t))/Math.log(1+(n-t)):(e-t)/(n-t),r>1&&(r=1),isNaN(r)||r===1/0?0:r})(t,n,r),c=0;return e.set[i]?c=1+e.layer.length+i:e.layer[a]&&(c=1+a),c+s}function De(e,t,n,r,i,a,o){if(!(1/e==-1/0||e<0))return o[0]=t[e],o[1]=t[e+1],o[2]=t[e+2],o[3]=n[e],o[4]=n[e+1],o[5]=n[e+2],o;let s=Math.abs(e),c=a===null?r[i]:r[i][a];return o[0]=c.pos[s],o[1]=c.pos[s+1],o[2]=c.pos[s+2],o[3]=c.scale[s],o[4]=c.scale[s+1],o[5]=c.scale[s+2],o}var Oe=e=>{if(!e)return!1;for(let t in e)if(t!==`content`&&Object.prototype.hasOwnProperty.call(e,t)&&e[t]&&typeof e[t]==`object`&&Object.keys(e[t]).length>0)return!0;return!1};function Z(e,t,n,r,i,a,o){let s=t.fXaxis.fNbins,c=t.fYaxis.fNbins,l=t.fZaxis.fNbins,u=0,d=0,f=new Float32Array((s*c*l-1)*3),p=new Float32Array((s*c*l-1)*3),m=new Float32Array(s*c*l-1),h=new Float32Array(s*c*l-1),g=new Float32Array(s*c*l-1),_=new Float32Array(6),v=new Float32Array(6),y=e=>{let t=x*3;f[t]=e[0],f[t+1]=e[1],f[t+2]=e[2],p[t]=e[3],p[t+1]=e[4],p[t+2]=e[5],m[x]=e[6],h[x]=e[7],g[x]=e[8]},b=(t,n,r,i)=>{De(t,f,p,e,r,i,_),De(n,f,p,e,r,i,v);let a=_[0]-_[3]*.5<v[0]-v[3]*.5?_[0]-_[3]*.5:v[0]-v[3]*.5,o=_[1]-_[4]*.5<v[1]-v[4]*.5?_[1]-_[4]*.5:v[1]-v[4]*.5,s=_[2]-_[5]*.5<v[2]-v[5]*.5?_[2]-_[5]*.5:v[2]-v[5]*.5,c=_[0]+_[3]*.5>v[0]+v[3]*.5?_[0]+_[3]*.5:v[0]+v[3]*.5,l=_[1]+_[4]*.5>v[1]+v[4]*.5?_[1]+_[4]*.5:v[1]+v[4]*.5,u=_[2]+_[5]*.5>v[2]+v[5]*.5?_[2]+_[5]*.5:v[2]+v[5]*.5,d=new Float32Array(9);return d[0]=(a+c)*.5,d[1]=(o+l)*.5,d[2]=(s+u)*.5,d[3]=c-a,d[4]=l-o,d[5]=u-s,d},x=0;for(let e=0;e<c;e++){for(let e=0;e<l;e++){let e=u+o,t=Array(s);for(let n=0;n<s;n++)t[n]=-n-e;for(;t.length>1;){let e=0,i=Math.floor(t.length/2);for(let o=0;o<i;o++){let i=t[e],o=t[e+1],s=b(i*3,o*3,n,r);t.splice(e,2,x),Q(s,a),s[6]=1/i==-1/0||i<0?i:g[i],s[7]=1/o==-1/0||o<0?o:g[o],s[8]=d,y(s),x+=1,d+=1,e+=1}}u+=s}let e=Array(l);for(let t=0;t<l;t++)e[t]=x-1-(l-1-t)*(s-1);for(;e.length>1;){let t=0,i=Math.floor(e.length/2);for(let o=0;o<i;o++){let i=e[t],o=e[t+1],s=b(i*3,o*3,n,r);e.splice(t,2,x),Q(s,a),s[6]=g[i],s[7]=g[o],s[8]=d,y(s),x+=1,d+=1,t+=1}}}let S=Array(c);for(let e=0;e<c;e++)S[e]=x-1-(c-1-e)*(s*l-1);for(;S.length>1;){let e=0,t=Math.floor(S.length/2);for(let i=0;i<t;i++){let t=S[e],i=S[e+1],o=b(t*3,i*3,n,r);S.splice(e,2,x),Q(o,a),o[6]=g[t],o[7]=g[i],o[8]=d,y(o),x+=1,d+=1,e+=1}}return{pos:f,scale:p,left:m,right:h}}function ke(e,t,n,r,i,a,o,s){let c=Array(e.length).fill().map(e=>[]);c[c.length-1]=Array.from({length:a.length},()=>[]),i===null?c[0]=[Z(e,t,n,null,a,o,0)]:(c[0]=Array(a.length),r.forEach(r=>c[0][a.indexOf(r)]=Z(e,t,n,a.indexOf(r),a,o,0)));let l=(t,n,i)=>{if(!t.children)return;let u=new U([t.fXaxis.fNbins,t.fYaxis.fNbins,t.fZaxis.fNbins]),d=t.fXaxis.fNbins*t.fYaxis.fNbins*t.fZaxis.fNbins,f=s.slice(1,n-1).reduce((e,t)=>e*t,s[1]),p=s[n];for(let m=0;m<d;m++){let d={x:u.getValueAt(0),y:u.getValueAt(1),z:u.getValueAt(2)};if(t?.children?.content){let r=t.children.content[t.getBin(d.x+1,d.y+1,d.z+1)];if(!r){if(u.increment()===!1)break;continue}c[n][m+i]=Z(e,r,n,null,a,o,(m+i)*p),l(r,n+1,(u.getIndex()+i)*f)}else Oe(t.children)&&r.forEach((r=>{let h=a.indexOf(r),g=(m+i)*p,_=!1;for(let t=g;t<g+s[n];t++)if(e[n][h].rendered[t]!==-1){_=!0;break}if(!_){c[n][h].push(null);return}let v=t.children[r][t.getBin(d.x+1,d.z+1,d.y+1)];v&&(c[n][h][m+i]=Z(e,v,n,h,a,o,(m+i)*p),l(v,n+1,(u.getIndex()+i)*f))}));if(u.increment()===!1)break}};return l(t,1,0),c}function Q(e,t){let n=t.elements,r=Math.sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]),i=Math.sqrt(n[4]*n[4]+n[5]*n[5]+n[6]*n[6]),a=Math.sqrt(n[8]*n[8]+n[9]*n[9]+n[10]*n[10]);e[0]=e[0]*r+n[12],e[1]=e[1]*i+n[13],e[2]=e[2]*a+n[14],e[3]*=r,e[4]*=i,e[5]*=a}var $=class{rootObj=void 0;origin=void 0;parentPath=[];path=void 0;title=void 0;range=[];isOnSet=null;isHistogramFilled=!0;constructor(e){this.rootObj=e,this.origin=this.rootObj,this.title=this.origin.fTitle,this.path=this.origin.fName}setOriginToChild(e,t,n){if(!e)return;let r=e.splice(0,1);if(this.origin?.children){if(this.origin.children?.content)this.parentPath.push({origin:this.origin,range:n.splice(0,1),bin:r}),this.origin=this.origin.children.content[r],this.isOnSet=null;else if(Object.keys(this.origin.children).includes(t)){if(this.parentPath.push({origin:this.origin,range:n.splice(0,1),bin:r}),!this.origin.children[t][r]){this.isHistogramFilled=!1,this.path+=`/empty`,this.origin=null;return}this.origin=this.origin.children[t][r],this.isOnSet=t}else{console.error(`Bad set or index specified.`);return}this.title=this.origin.fTitle,this.path=this.path+`/`+this.origin.fName,e.length>0&&this.setOriginToChild(e,t,n)}}getChildByPosition(e,t,n=this.origin){if(!e||e.length===0)return{...n};let r=e.splice(0,1)[0];return n?.children?n.children?.content?this.getChildByPosition(e,t,n.children.content[r]):Object.keys(n.children).includes(t)?this.getChildByPosition(e,t,n.children[t][r]):(console.error(`Bad set or index specified.`),null):{...n}}setOriginToParent(e=1){if(e<=0||this.parentPath.length===0)return;let t=this.path.lastIndexOf(`/`);this.path=this.path.slice(0,t);let n=this.parentPath.pop();n&&(this.origin=n.origin),this.title=this.origin.fTitle,this.setOriginToParent(e-1),this.isOnSet=null,this.isHistogramFilled=!0}},Ae=class{wireframe=void 0;instGeom=void 0;material=void 0;totalInstances=void 0;maxInstancesPerLayer=void 0;instancePositions=void 0;instanceScales=void 0;instanceColors=void 0;colorArray=void 0;configSub=void 0;stateSub=void 0;config=void 0;numOfavailableSets=void 0;visibility=!0;id=void 0;constructor(e,t,n,i){this.config=n,this.maxInstancesPerLayer=e,this.id=i;let a=new r.EdgesGeometry(new r.BoxGeometry(1,1,1));this.instGeom=new r.InstancedBufferGeometry,this.instGeom.instanceCount=0,this.instGeom.frustumCulled=!1,this.instGeom.index=a.index;for(let e in a.attributes)this.instGeom.setAttribute(e,a.attributes[e]);this.material=this.createMaterial(),this.colorArray=new Float32Array(96),this.fillColorArray(),this.instancePositions=new Float32Array(3),this.instanceScales=new Float32Array(3),this.instanceColors=new Float32Array(1),this.instGeom.setAttribute(`instancePosition`,new r.InstancedBufferAttribute(this.instancePositions,3)),this.instGeom.setAttribute(`instanceScale`,new r.InstancedBufferAttribute(this.instanceScales,3)),this.instGeom.setAttribute(`instanceColorIndex`,new r.InstancedBufferAttribute(this.instanceColors,1)),this.wireframe=new r.LineSegments(this.instGeom,this.material),this.wireframe.frustumCulled=!1,this.stateSub=v(this.id).getObservable().subscribe(e=>{this.numOfavailableSets=e.sets.length})}pushVisibleInstances(e,t,n){let i=this.wireframe.parent;i&&(i.remove(this.wireframe),this.instGeom.dispose());let a=this.config.display.start??0,o=this.config.display.end??e.length-1,s=[],c=e.length-1;{let t=(Array.isArray(e[c])?e[c][n]:e[c]).rendered,r=new Uint8Array(t.length);for(let e=0;e<t.length;e++)r[e]=t[e]===-1?0:1;s[c]=r}for(let r=c-1;r>=0;r--){let i=(Array.isArray(e[r])?e[r][n]:e[r]).rendered,a=s[r+1],o=t[r+1]||0,c=new Uint8Array(i.length);for(let e=0;e<i.length;e++){if(i[e]!==-1){c[e]=1;continue}let t=e*o,n=t+o;for(let r=t;r<n;r++)if(a[r]){c[e]=1;break}}s[r]=c}let l=(e,t)=>e<a||e>o?!1:s[e][t]===1,u=(r,i)=>{let a=0,o=r,s=i;for(;o+1<e.length;){o++,s*=t[o];let i=e[o],c=Array.isArray(i)?i[n===-1?0:n]:i;for(let e=s;e<s+t[o];e++)if(c.rendered[e]!==-1){a=o-r;break}}return a},d=0;for(let t=0;t<e.length;t++){let n=e[t];if(!Array.isArray(n))for(let e=0;e<n.rendered.length;e++)l(t,e)&&d++}let f=new Float32Array(d*3),p=new Float32Array(d*3),m=new Float32Array(d),h=0;for(let t=0;t<e.length;t++){let r=e[t],i=this.getColorIndex(t,n);if(!Array.isArray(r)){for(let e=0;e<r.rendered.length;e++)if(l(t,e)){let n=u(t,e)*.05;f[h*3]=r.pos[e*3],f[h*3+1]=r.pos[e*3+1],f[h*3+2]=r.pos[e*3+2],p[h*3]=r.scale[e*3]+n,p[h*3+1]=r.scale[e*3+1]+n,p[h*3+2]=r.scale[e*3+2]+n,m[h++]=i}}}let g=new r.EdgesGeometry(new r.BoxGeometry(1,1,1));this.instGeom=new r.InstancedBufferGeometry,this.instGeom.instanceCount=d,this.instGeom.frustumCulled=!1,this.instGeom.index=g.index;let _=g.attributes;for(let e in _)this.instGeom.setAttribute(e,_[e]);this.instancePositions=f,this.instanceScales=p,this.instanceColors=m,this.instGeom.setAttribute(`instancePosition`,new r.InstancedBufferAttribute(f,3)),this.instGeom.setAttribute(`instanceScale`,new r.InstancedBufferAttribute(p,3)),this.instGeom.setAttribute(`instanceColorIndex`,new r.InstancedBufferAttribute(m,1)),this.wireframe=new r.LineSegments(this.instGeom,this.material),this.wireframe.frustumCulled=!1,i&&i.add(this.wireframe)}toggleVisibility(e,t,n){this.visibility=!this.visibility,this.visibility?this.pushVisibleInstances(e,t,n):this.clearWireframe()}dispose(){this.instancePositions=[],this.instanceScales=[],this.wireframe.parent.remove(this.wireframe),this.instGeom.dispose()}clearWireframe(){this.instancePositions=new Float32Array(3),this.instanceScales=new Float32Array(3),this.instanceColors=new Float32Array(1),this.instGeom.dispose(),this.instGeom.instanceCount=0}fillColorArray(){new r.Color(this.config.color.default).toArray(this.colorArray,0);let e=1;this.config.color.layer.map(e=>new r.Color(e)).forEach(t=>{let n=e*3;t.toArray(this.colorArray,n),e++}),this.config.color.set.map(e=>new r.Color(e)).forEach(t=>{let n=e*3;t.toArray(this.colorArray,n),e++}),this.material.uniforms.colorArray={value:this.colorArray},this.material.uniformsNeedUpdate=!0}createMaterial(){return new r.ShaderMaterial({vertexShader:`
|
|
37
37
|
attribute vec3 instancePosition;
|
|
38
38
|
attribute vec3 instanceScale;
|
|
39
39
|
attribute float instanceColorIndex;
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
void main() {
|
|
55
55
|
gl_FragColor = vec4(vColor, 1.0);
|
|
56
56
|
}
|
|
57
|
-
`,transparent:!1})}getColorIndex(e,t){return this.config.color.set[t]?this.config.color.layer.length+1:this.config.color.layer[e]?e+1:0}getColorAt(e,t){return this.config.color.set[t]?this.config.color.set[t]:this.config.color.layer[e]?this.config.color.layer[e]:this.config.color.default}},je=class{id=void 0;functionSub=void 0;configSub=void 0;dispatchSub=void 0;rootObj=void 0;config=void 0;limits={scale:{x:20,y:10,z:20},position:{x:0,y:0,z:-5}};mouseEvents=[];keydownEvents=[];keyupEvents=[];keyBindings={};renderHistory=[];opts=void 0;constructor(e,n,r){this.rootObj=e.obj,this.id=n,this.opts=r,this.config=L().mergeHistogramConfig(this?.opts?.config),this.functionSub=x().getObservable().pipe((0,t.filter)(e=>e.target.entity===`nested-histogram`&&(e.target.id.includes(`*`)||e.target.id.includes(this.id)))).subscribe(e=>this.functionSubjectHandler(e)),this.configSub=L().getObservable().pipe((0,t.filter)(e=>e.target.id.includes(`*`)||e.target.id.includes(this.id))).subscribe(e=>this.configSubjectHandler(e)),this.dispatchSub=f().getObservable().pipe((0,t.filter)(e=>e.target.id===`*`||e.target.id===this.id)).subscribe(e=>this.dispatchSubjectHandler(e)),this.initDefaultFunctions()}remove(){this.functionSub.unsubscribe(),this.configSub.unsubscribe(),this.dispatchSub.unsubscribe(),window.removeEventListener(`keydown`,this.keyDownHandler),window.removeEventListener(`keydown`,this.keyUpHandler)}initDefaultFunctions(){this.keyDownHandler=this.keyDownHandler.bind(this),this.keyUpHandler=this.keyUpHandler.bind(this),this.raycastHandler=this.raycastHandler.bind(this),this.mouseClickDefault=this.mouseClickDefault.bind(this),this.mousemoveDefault=this.mousemoveDefault.bind(this),this.shiftMouseClickDefault=this.shiftMouseClickDefault.bind(this),this.mouseDBClickDefault=this.mouseDBClickDefault.bind(this),this.shiftMouseDBClickDefault=this.shiftMouseDBClickDefault.bind(this),window.addEventListener(`keydown`,this.keyDownHandler),window.addEventListener(`keydown`,this.keyUpHandler),this.addEvent(`mouseclick`,this.mouseClickDefault),this.addEvent(`mousemove`,this.mousemoveDefault),this.addEvent(`shiftmouseclick`,this.shiftMouseClickDefault),this.addEvent(`mousedbclick`,this.mouseDBClickDefault),this.addEvent(`shiftmousedbclick`,this.shiftMouseDBClickDefault)}configSubjectHandler(e){console.log(`default configSubjectHandler: `,e)}functionSubjectHandler(e){if(e.flag===`add`)if(e.function)this.addEvent(e.event,e.function);else switch(e.event){case`mousemove`:this.addEvent(e.event,this.mousemoveDefault);break;case`mouseclick`:this.addEvent(e.event,this.mouseClickDefault);break;case`shiftmouseclick`:this.addEvent(e.event,this.shiftMouseClickDefault);break;case`mousedbclick`:this.addEvent(e.event,this.mouseDBClickDefault);break;case`shiftmousedbclick`:this.addEvent(e.event,this.shiftMouseDBClickDefault);break}else if(e.flag===`remove`&&e.function)this.removeEvent(e.event,e.function);else if(e.flag===`remove`)switch(e?.state){case`keydown`:this.keydownEvents=[];break;case`keyup`:this.keyupEvents=[];break;default:this.mouseEvents=this.mouseEvents.filter(t=>t.event!==e.event)}else e.flag===`removeAll`&&(this.keydownEvents=[],this.keyupEvents=[],this.mouseEvents=[])}addEvent(e,t){e?.state===`keydown`?this.keydownEvents.push({key:e.key,function:t}):e?.state===`keyup`?this.keyupEvents.push({key:e.key,function:t}):this.mouseEvents.push({event:e,function:t})}removeEvent(e,t){let n=this.mouseEvents.find(e=>e===t);n&&this.mouseEvents.splice(n,1)}mouseClickDefault(e){console.log(`mouse click default`)}mousemoveDefault(e){console.log(`mouse move default`)}shiftMouseClickDefault(e){console.log(`shift mouse click`)}mouseDBClickDefault(e){console.log(`mouseDBClick default`)}shiftMouseDBClickDefault(e){console.log(`shift mouse db click default`)}dispatchSubjectHandler(e){console.log(`dispatch: `,e)}},Me=class extends je{stateSub=void 0;pointer=void 0;wireframe=void 0;BVHTree=[];minMaxValue=[];maxInstancesPerLayer=void 0;maxContentPerLayer=void 0;maxErrorPerLayer=void 0;totalInstances=void 0;color=new r.Color;matrixCache=void 0;selectedSet=[];selectedArray=`content`;availableSets=[];dirtyInstance=[];mesh=void 0;instGeom=void 0;material=void 0;instancePositions=void 0;instanceScales=void 0;instanceColors=void 0;colorArray=void 0;constructor(e,t,n){if(!e||!e.obj)throw console.error(`THnPainter constructor: histo or histo.obj is undefined`,e),Error(`THnPainter: histo or histo.obj is undefined`);super(e,t,n),console.log(`THnPainter constructor start: `),this.pointer=new $(this.rootObj),this.handleStateChange=this.handleStateChange.bind(this),this.stateSub=v(this.id).getObservable().subscribe(this.handleStateChange),this.init(!0),console.log(`THnPainter constructor end, mesh: `,this.mesh,`meshParent: `,this?.mesh?.parent??`undefined`)}async updateHistogram(e){if(!e||!e.obj)throw console.error(`THnPainter constructor: histo or histo.obj is undefined`,e),Error(`THnPainter: histo or histo.obj is undefined`);console.log(`THnPainter updateHistogram start => histo: `,e,`, mesh: `,this.mesh,`uuid: `,this.mesh.uuid,`mesh.parent: `,this?.mesh?.parent??`undefined`);let t,n=this.mesh.parent;if(console.log(`THnPainter updateHistogram parent is defined, removing mesh: `,this.mesh,`uuid: `,this.mesh.uuid,`mesh.parent: `,this?.mesh?.parent??`undefined`),this.pointer.isHistogramFilled&&(t=this.mesh.raycast,this.mesh.raycast=()=>{},this.wireframe.dispose(),this.instGeom.dispose()),this.matrixCache=[],this.BVHTree=[],this.availableSets=[],this.selectedSet=[],this.availableAxes=[],this.minMaxValue=[],v(this.id).next({sets:[],selectedSet:[],arrays:[`content`],selectedArray:`content`,minMaxValue:[]}),n&&(console.log(`THnPainter updateHistogram parent is undefined`,this.mesh,`uuid: `,this.mesh.uuid,`mesh.parent: `,this?.mesh?.parent??`undefined`),n.remove(this.mesh)),console.log(`THnPainter re-init in update: `,e,`mesh.uuid: `,this.mesh.uuid,`mesh.parent: `,this?.mesh?.parent??`undefined`),this.rootObj=e.obj,this.pointer=new $(this.rootObj),this.init(!0),await this.renderHistogram(0,this.totalInstances,0),this.mesh.raycast=t,console.log(`THnPainter re-init in update SUCCESSFULL, now adding mesh to parent: `,e,`mesh.uuid: `,this.mesh.uuid,`mesh.parent: `,this?.mesh?.parent??`undefined`),n)n.add(this.mesh),n.add(this.wireframe.wireframe),console.log(`THnPainter mesh successfully added to parent: `,this.mesh,`uuid: `,this.mesh.uuid,`mesh.parent: `,this?.mesh?.parent??`undefined`);else throw ReferenceError(`THnPainter: parent is undefined`)}remove(){super.remove(),this.matrixCache=[],this.instGeom.dispose(),this.mesh.parent&&(this.mesh.parent.remove(this.mesh),this.wireframe.dispose()),this.stateSub.unsubscribe()}init(e=!1){if(this.maxInstancesPerLayer=we(this.pointer.origin),e){this.maxContentPerLayer=be(this.pointer.origin),this.minContentPerLayer=Ce(this.pointer.origin),this.maxErrorPerLayer=xe(this.pointer.origin,this.maxContentPerLayer),this.minErrorPerLayer=Se(this.pointer.origin,this.minContentPerLayer),this.setAvailableSets(this.pointer.origin),this.setAvailableArrays(this.pointer.origin),this.setAvailableAxes(this.pointer.origin);let e=Array(this.maxContentPerLayer.length);for(let t=0;t<this.maxContentPerLayer.length;t++)e[t]={},Object.keys(this.maxContentPerLayer[t]).forEach(n=>{e[t][n]={value:{min:this.minContentPerLayer[t][n],max:this.maxContentPerLayer[t][n]},error:{min:this.minErrorPerLayer[t][n],max:this.maxErrorPerLayer[t][n]}}});console.log(`minMaxValues: `,e),v(this.id).next({...v(this.id).getValue(),minMaxValue:e})}this.totalInstances=this.maxInstancesPerLayer.reduce((e,t)=>e*t,1),this.setupInsBufGeom(),this.wireframe=new Ae(this.maxInstancesPerLayer,this.matrixCache,this.config.wireframe,this.id)}setupMatrixCache(){this.matrixCache=Array(this.maxInstancesPerLayer.length-1);let e=this.availableSets.length>0;e&&(this.matrixCache[this.matrixCache.length-1]=Array(this.availableSets.length));let t=this.maxInstancesPerLayer[0];for(let n=0;n<this.maxInstancesPerLayer.length-1-(e?1:0);n++)this.matrixCache[n]={pos:new Float32Array(t*3),scale:new Float32Array(t*3),rendered:new Float32Array(t).fill(-1)},t*=this.maxInstancesPerLayer[n+1];if(!e)return;let n=this.matrixCache[this.matrixCache.length-1];for(let e=0;e<n.length;e++)n[e]={pos:new Float32Array(t*3),scale:new Float32Array(t*3),rendered:new Float32Array(t).fill(-1)}}setupInsBufGeom(){this.setupMatrixCache();let e=this.maxInstancesPerLayer.reduce((e,t)=>e*t,1);this.selectedSet.length>1&&(e*=this.selectedSet.length);let t=new r.BoxGeometry(1,1,1);this.instGeom=new r.InstancedBufferGeometry,this.instGeom.instanceCount=0,this.instGeom.frustumCulled=!1,this.instGeom.index=t.index;for(let e in t.attributes)this.instGeom.setAttribute(e,t.attributes[e]);this.material=this.createMaterial(),this.colorArray=new Float32Array(192),this.material.uniforms.colorArray={value:this.colorArray},Te(this.config,this.material,this.colorArray),this.instancePositions=new Float32Array(3),this.instanceScales=new Float32Array(3),this.instanceColors=new Float32Array(1),this.instGeom.setAttribute(`instancePosition`,new r.InstancedBufferAttribute(this.instancePositions,3)),this.instGeom.setAttribute(`instanceScale`,new r.InstancedBufferAttribute(this.instanceScales,3)),this.instGeom.setAttribute(`instanceColorIndex`,new r.InstancedBufferAttribute(this.instanceColors,1)),this.mesh=new r.Mesh(this.instGeom,this.material),this.mesh.raycast=this.raycastHandler,this.mesh.frustumCulled=!1,this.material.uniforms.colorArray={value:this.colorArray},this.mesh.material.uniformsNeedUpdate=!0}pushVisibleInstances(){let e=this.mesh.parent;e&&(e.remove(this.mesh),this.instGeom.dispose());let t=0;for(let e=0;e<this.matrixCache.length;e++){let n=this.matrixCache[e];if(Array.isArray(n))for(let e=0;e<n.length;e++){let r=n[e];for(let e=0;e<r.rendered.length;e++)r.rendered[e]!==-1&&t++}else for(let e=0;e<n.rendered.length;e++)n.rendered[e]!==-1&&t++}let n=new Float32Array(t*3),i=new Float32Array(t*3),a=new Float32Array(t),o=0;for(let e=0;e<this.matrixCache.length;e++){let t=this.matrixCache[e];if(Array.isArray(t))for(let e=0;e<t.length;e++){let r=t[e];for(let e=0;e<r.rendered.length;e++)r.rendered[e]!==-1&&(n[o*3]=r.pos[e*3],n[o*3+1]=r.pos[e*3+1],n[o*3+2]=r.pos[e*3+2],i[o*3]=r.scale[e*3],i[o*3+1]=r.scale[e*3+1],i[o*3+2]=r.scale[e*3+2],a[o++]=r.rendered[e])}else for(let e=0;e<t.rendered.length;e++)t.rendered[e]!==-1&&(n[o*3]=t.pos[e*3],n[o*3+1]=t.pos[e*3+1],n[o*3+2]=t.pos[e*3+2],i[o*3]=t.scale[e*3],i[o*3+1]=t.scale[e*3+1],i[o*3+2]=t.scale[e*3+2],a[o++]=t.rendered[e])}let s=new r.BoxGeometry(1,1,1);this.instGeom=new r.InstancedBufferGeometry,this.instGeom.instanceCount=t,this.instGeom.frustumCulled=!1,this.instGeom.index=s.index;let c=s.attributes;for(let e in c)this.instGeom.setAttribute(e,c[e]);this.instancePositions=n,this.instanceScales=i,this.instanceColors=a,this.instGeom.setAttribute(`instancePosition`,new r.InstancedBufferAttribute(n,3)),this.instGeom.setAttribute(`instanceScale`,new r.InstancedBufferAttribute(i,3)),this.instGeom.setAttribute(`instanceColorIndex`,new r.InstancedBufferAttribute(a,1)),this.mesh=new r.Mesh(this.instGeom,this.material),this.mesh.raycast=this.raycastHandler,this.mesh.frustumCulled=!1,e&&e.add(this.mesh)}setMatrixCacheAt(e,t,n,r,i){let a=t===null?this.matrixCache[e]:this.matrixCache[e][t];a.pos[n*3]=r.x.pos,a.pos[n*3+1]=r.y.pos,a.pos[n*3+2]=r.z.pos,a.scale[n*3]=r.x.size,a.scale[n*3+1]=r.y.size,a.scale[n*3+2]=r.z.size,a.rendered[n]=i}async renderHistogram(e,t,n){if(!this.pointer||n>=this.maxInstancesPerLayer.length-1)return;this.logRender({procedure:`render`,value:{startIndex:e,endIndex:t,layer:n}});let i={x:{size:0,pos:0},y:{size:0,pos:0},z:{size:0,pos:0}},a=async(e,t,o,s,c,l)=>{if(o>n||!s)return;let u=new U([s.fXaxis.fNbins,s.fYaxis.fNbins,s.fZaxis.fNbins]),d,f,p,m,h=s.fArrays?.[this.selectedArray]?.outside??!1,g=this.selectedSet.indexOf(l),_=this.availableSets.indexOf(l),v=s.fArrays?s.fArrays[Object.keys(s.fArrays)[0]].values:!1,y=this.availableAxes[o],b=this.config.scale.scaleBy===`value`;if(l)if(this.config.scale.sets===`fixed`)({min:d,max:f}=this.minMaxValue[o+this.pointer.parentPath.length][l].value),{min:m,max:p}=this.minMaxValue[o+this.pointer.parentPath.length][l].error;else if(this.config.scale.sets===`relative`){let e=s.fSumw2.filter(e=>e!==0),t=b?s.fArray.filter(e=>e!==0):e;d=Math.min(...t),f=Math.max(...t),p=this.maxErrorPerLayer[o+this.pointer.parentPath.length][l],m=this.minErrorPerLayer[o+this.pointer.parentPath.length][l]}else d=b?this.minContentPerLayer[o+this.pointer.parentPath.length][l]:-.1,f=b?this.maxContentPerLayer[o+this.pointer.parentPath.length][l]:this.maxErrorPerLayer[o+this.pointer.parentPath.length][l],p=this.maxErrorPerLayer[o+this.pointer.parentPath.length][l],m=this.minErrorPerLayer[o+this.pointer.parentPath.length][l];else if(this.selectedArray!==`content`&&s.fArrays&&v)if(this.config.scale.parameter===`fixed`)({min:d,max:f}=this.minMaxValue[o+this.pointer.parentPath.length][this.selectedArray].value),{min:m,max:p}=this.minMaxValue[o+this.pointer.parentPath.length][this.selectedArray].error;else if(this.config.scale.parameter===`relative`){let e=s.fArrays[this.selectedArray].errors.filter(e=>e!==0),t=b?s.fArrays[this.selectedArray].values.filter(e=>e!==0):e;d=Math.min(...t),f=Math.max(...t),p=this.maxErrorPerLayer[o+this.pointer.parentPath.length][this.selectedArray],m=this.minErrorPerLayer[o+this.pointer.parentPath.length][this.selectedArray]}else d=b?this.minContentPerLayer[0][this.selectedArray]:-.1,f=b?this.maxContentPerLayer[0][this.selectedArray]:this.maxErrorPerLayer[0][this.selectedArray],p=this.maxErrorPerLayer[0][this.selectedArray],m=this.minErrorPerLayer[0][this.selectedArray];else{let e=this.pointer.isOnSet??`content`;if(this.config.scale.content===`fixed`)({min:d,max:f}=this.minMaxValue[o+this.pointer.parentPath.length][e].value),{min:m,max:p}=this.minMaxValue[o+this.pointer.parentPath.length][e].error;else if(this.config.scale.content===`relative`){let t=s.fSumw2.filter(e=>e!==0),n=b?s.fArray.filter(e=>e!==0):t;d=Math.min(...n),f=Math.max(...n),p=this.maxErrorPerLayer[o+this.pointer.parentPath.length][e],m=this.minErrorPerLayer[o+this.pointer.parentPath.length][e]}else d=b?this.minContentPerLayer[o+this.pointer.parentPath.length][e]:-.1,f=b?this.maxContentPerLayer[o+this.pointer.parentPath.length][e]:this.maxErrorPerLayer[o+this.pointer.parentPath.length][e],p=this.maxErrorPerLayer[o+this.pointer.parentPath.length][e],m=this.minErrorPerLayer[o+this.pointer.parentPath.length][e]}d===f&&(d=f-.2);let x=s._typename.substring(0,3)===`TH3`,S=s._typename.substring(0,3)===`TH2`,C=s._typename.substring(0,3)===`TH1`,w=this.maxInstancesPerLayer.slice(o+1).reduce((e,t)=>e*t,1);u.setFromNumber(e/w);let T=this.config.padding.layer[o]??this.config.padding.default,E=!this.config.padding.layer[o]&&C?{x:T.x,y:T.y,z:T.z}:{...T};l&&this.config.padding.sets&&C&&(E={x:this.config.padding.sets.x,y:0,z:0}),this.pointer.isOnSet&&(E={x:0,y:0,z:0});let{min:D,max:O}=this.config.scale?.layer?.[o]?this.config.scale?.layer[o]:this.config.scale.default;for(let b=e;b<t;b+=w){let e={x:u.getValueAt(0),y:u.getValueAt(1),z:u.getValueAt(2)},C=he(c.position.z,c.scale.z,G(K(s,e,E,c?.scale,c?.position,o,i))),T=this.config.scale.scaleBy===`value`?d:m,k=this.config.scale.scaleBy===`value`?f:p;T===k&&(T-=T*.1);let A=v||this.selectedArray===`content`?this.getBinContent(s,e.x,e.y,e.z,this.selectedArray):k,j=v||this.selectedArray===`content`?this.getBinError(s,e.x,e.y,e.z,this.selectedArray):0,M=this.config.scale.scaleBy===`value`?A:j,N=1;if(M>=T==!h){let e=y[0].scaleType===`log10`?Math.log(1+(M-T))/Math.log(1+(k-T)):(M-T)/(k-T);if(!h)N=Number.isInteger(M)&&M===0&&this.config.scale.scaleBy===`value`?N=0:(O-D)*e+D,N>1&&(N=1);else{let e=(A-void 0)/(void 0-void 0);N=Number.isInteger(A)&&A===0?N=0:(O-D)*e+D}}else N=0;this.config.color.scaleBy===`value`?this.color=Ee(this.config.color,M,T,k,_,o,y[0].errorType):this.color=Ee(this.config.color,j,m,p,_,o,y[0].errorType);let P=C.y.size*N;if(N===0)C.x.size=0,C.z.size=0,C.y.size=0;else if(x)C.x.size*=N,C.z.size*=N,C.y.size=P;else if(S)C.y.pos-=(C.y.size-P)/2,C.y.size=P;else if(C.y.pos-=(C.y.size-P)/2,C.y.size=P,l){let e=this.config.TH1ZScale.set;C.z.size=e||.01}else this.config.TH1ZScale?.layer?.[o]?C.z.size=c.scale.z*this.config.TH1ZScale.layer[o]:C.z.size=c.scale.z*this.config.TH1ZScale.default;if(l)C.z.size=.01,C.z.pos+=(g-(this.selectedSet.length-1)/2)*.1,this.setMatrixCacheAt(o,_,b/w,C,o===n&&N!==0?this.color:-1);else{let e=null;this.pointer.isOnSet&&(C.z.size=.01,C.z.pos+=(g-(this.selectedSet.length-1)/2)*.1,e=this.availableSets.indexOf(this.pointer.isOnSet)),this.setMatrixCacheAt(o,e,b/w,C,o===n&&N!==0?this.color:-1)}if(o===n){let e=b;l&&(e+=this.totalInstances*g)}else{let n=s.getBin(e.x+1,e.y+1,e.z+1),i,c={position:new r.Vector3(C.x.pos,C.y.pos,C.z.pos),scale:new r.Vector3(C.x.size,C.y.size,C.z.size)};s.children.content?(i=s.children.content[n],a(b,t,o+1,i,c)):this.selectedSet.forEach(e=>{i=s.children[e][n],a(b,t,o+1,i,c,e)})}if(!u.increment())break}};this.pointer.isOnSet?await Promise.all(this.selectedSet.map(n=>a(e,t,0,X(this.pointer.rootObj,this.pointer.parentPath.map(e=>e.bin[0]),n),this.limits,n))):await a(e,t,0,this.pointer.origin,this.limits),this.pointer.isOnSet||this.wireframe.pushVisibleInstances(this.matrixCache,this.maxInstancesPerLayer,this.availableSets.indexOf(this.selectedSet[0])),this.pushVisibleInstances();let o=this.availableSets.indexOf(this.pointer.isOnSet)===-1?null:this.availableSets.indexOf(this.pointer.isOnSet);return this.BVHTree=ke(this.matrixCache,this.pointer.origin,0,this.selectedSet,o,this.availableSets,this.mesh.matrixWorld,this.maxInstancesPerLayer),this.mesh}createMaterial(){return new r.ShaderMaterial({vertexShader:`
|
|
57
|
+
`,transparent:!1})}getColorIndex(e,t){return this.config.color.set[t]?this.config.color.layer.length+1:this.config.color.layer[e]?e+1:0}getColorAt(e,t){return this.config.color.set[t]?this.config.color.set[t]:this.config.color.layer[e]?this.config.color.layer[e]:this.config.color.default}},je=class{id=void 0;functionSub=void 0;configSub=void 0;dispatchSub=void 0;rootObj=void 0;config=void 0;limits={scale:{x:20,y:10,z:20},position:{x:0,y:0,z:-5}};mouseEvents=[];keydownEvents=[];keyupEvents=[];keyBindings={};renderHistory=[];opts=void 0;constructor(e,n,r){this.rootObj=e.obj,this.id=n,this.opts=r,this.config=L().mergeHistogramConfig(this?.opts?.config),this.functionSub=x().getObservable().pipe((0,t.filter)(e=>e.target.entity===`nested-histogram`&&(e.target.id.includes(`*`)||e.target.id.includes(this.id)))).subscribe(e=>this.functionSubjectHandler(e)),this.configSub=L().getObservable().pipe((0,t.filter)(e=>e.target.id.includes(`*`)||e.target.id.includes(this.id))).subscribe(e=>this.configSubjectHandler(e)),this.dispatchSub=f().getObservable().pipe((0,t.filter)(e=>e.target.id===`*`||e.target.id===this.id)).subscribe(e=>this.dispatchSubjectHandler(e)),this.initDefaultFunctions()}remove(){this.functionSub.unsubscribe(),this.configSub.unsubscribe(),this.dispatchSub.unsubscribe(),window.removeEventListener(`keydown`,this.keyDownHandler),window.removeEventListener(`keydown`,this.keyUpHandler)}initDefaultFunctions(){this.keyDownHandler=this.keyDownHandler.bind(this),this.keyUpHandler=this.keyUpHandler.bind(this),this.raycastHandler=this.raycastHandler.bind(this),this.mouseClickDefault=this.mouseClickDefault.bind(this),this.mousemoveDefault=this.mousemoveDefault.bind(this),this.shiftMouseClickDefault=this.shiftMouseClickDefault.bind(this),this.mouseDBClickDefault=this.mouseDBClickDefault.bind(this),this.shiftMouseDBClickDefault=this.shiftMouseDBClickDefault.bind(this),window.addEventListener(`keydown`,this.keyDownHandler),window.addEventListener(`keydown`,this.keyUpHandler),this.addEvent(`mouseclick`,this.mouseClickDefault),this.addEvent(`mousemove`,this.mousemoveDefault),this.addEvent(`shiftmouseclick`,this.shiftMouseClickDefault),this.addEvent(`mousedbclick`,this.mouseDBClickDefault),this.addEvent(`shiftmousedbclick`,this.shiftMouseDBClickDefault)}configSubjectHandler(e){console.log(`default configSubjectHandler: `,e)}functionSubjectHandler(e){if(e.flag===`add`)if(e.function)this.addEvent(e.event,e.function);else switch(e.event){case`mousemove`:this.addEvent(e.event,this.mousemoveDefault);break;case`mouseclick`:this.addEvent(e.event,this.mouseClickDefault);break;case`shiftmouseclick`:this.addEvent(e.event,this.shiftMouseClickDefault);break;case`mousedbclick`:this.addEvent(e.event,this.mouseDBClickDefault);break;case`shiftmousedbclick`:this.addEvent(e.event,this.shiftMouseDBClickDefault);break}else if(e.flag===`remove`&&e.function)this.removeEvent(e.event,e.function);else if(e.flag===`remove`)switch(e?.state){case`keydown`:this.keydownEvents=[];break;case`keyup`:this.keyupEvents=[];break;default:this.mouseEvents=this.mouseEvents.filter(t=>t.event!==e.event)}else e.flag===`removeAll`&&(this.keydownEvents=[],this.keyupEvents=[],this.mouseEvents=[])}addEvent(e,t){e?.state===`keydown`?this.keydownEvents.push({key:e.key,function:t}):e?.state===`keyup`?this.keyupEvents.push({key:e.key,function:t}):this.mouseEvents.push({event:e,function:t})}removeEvent(e,t){let n=this.mouseEvents.find(e=>e===t);n&&this.mouseEvents.splice(n,1)}mouseClickDefault(e){console.log(`mouse click default`)}mousemoveDefault(e){console.log(`mouse move default`)}shiftMouseClickDefault(e){console.log(`shift mouse click`)}mouseDBClickDefault(e){console.log(`mouseDBClick default`)}shiftMouseDBClickDefault(e){console.log(`shift mouse db click default`)}dispatchSubjectHandler(e){console.log(`dispatch: `,e)}},Me=class extends je{stateSub=void 0;pointer=void 0;wireframe=void 0;BVHTree=[];minMaxValue=[];maxInstancesPerLayer=void 0;maxContentPerLayer=void 0;maxErrorPerLayer=void 0;totalInstances=void 0;color=new r.Color;matrixCache=void 0;selectedSet=[];selectedArray=`content`;availableSets=[];dirtyInstance=[];mesh=void 0;instGeom=void 0;material=void 0;instancePositions=void 0;instanceScales=void 0;instanceColors=void 0;colorArray=void 0;constructor(e,t,n){if(!e||!e.obj)throw console.error(`THnPainter constructor: histo or histo.obj is undefined`,e),Error(`THnPainter: histo or histo.obj is undefined`);super(e,t,n),console.log(`THnPainter constructor start: `),this.pointer=new $(this.rootObj),this.handleStateChange=this.handleStateChange.bind(this),this.stateSub=v(this.id).getObservable().subscribe(this.handleStateChange),this.init(!0),console.log(`THnPainter constructor end, mesh: `,this.mesh,`meshParent: `,this?.mesh?.parent??`undefined`)}async updateHistogram(e){if(!e||!e.obj)throw console.error(`THnPainter constructor: histo or histo.obj is undefined`,e),Error(`THnPainter: histo or histo.obj is undefined`);console.log(`THnPainter updateHistogram start => histo: `,e,`, mesh: `,this.mesh,`uuid: `,this.mesh.uuid,`mesh.parent: `,this?.mesh?.parent??`undefined`);let t,n=this.mesh.parent;if(console.log(`THnPainter updateHistogram parent is defined, removing mesh: `,this.mesh,`uuid: `,this.mesh.uuid,`mesh.parent: `,this?.mesh?.parent??`undefined`),this.pointer.isHistogramFilled&&(t=this.mesh.raycast,this.mesh.raycast=()=>{},this.wireframe.dispose(),this.instGeom.dispose()),this.matrixCache=[],this.BVHTree=[],this.availableSets=[],this.selectedSet=[],this.availableAxes=[],this.minMaxValue=[],v(this.id).next({sets:[],selectedSet:[],arrays:[`content`],selectedArray:`content`,minMaxValue:[]}),n&&(console.log(`THnPainter updateHistogram parent is undefined`,this.mesh,`uuid: `,this.mesh.uuid,`mesh.parent: `,this?.mesh?.parent??`undefined`),n.remove(this.mesh)),console.log(`THnPainter re-init in update: `,e,`mesh.uuid: `,this.mesh.uuid,`mesh.parent: `,this?.mesh?.parent??`undefined`),this.rootObj=e.obj,this.pointer=new $(this.rootObj),this.init(!0),await this.renderHistogram(0,this.totalInstances,0),this.mesh.raycast=t,console.log(`THnPainter re-init in update SUCCESSFULL, now adding mesh to parent: `,e,`mesh.uuid: `,this.mesh.uuid,`mesh.parent: `,this?.mesh?.parent??`undefined`),n)n.add(this.mesh),n.add(this.wireframe.wireframe),console.log(`THnPainter mesh successfully added to parent: `,this.mesh,`uuid: `,this.mesh.uuid,`mesh.parent: `,this?.mesh?.parent??`undefined`);else throw ReferenceError(`THnPainter: parent is undefined`)}remove(){super.remove(),this.matrixCache=[],this.instGeom.dispose(),this.mesh.parent&&(this.mesh.parent.remove(this.mesh),this.wireframe.dispose()),this.stateSub.unsubscribe()}init(e=!1){if(this.maxInstancesPerLayer=we(this.pointer.origin),e){this.maxContentPerLayer=be(this.pointer.origin),this.minContentPerLayer=Ce(this.pointer.origin),this.maxErrorPerLayer=xe(this.pointer.origin,this.maxContentPerLayer),this.minErrorPerLayer=Se(this.pointer.origin,this.minContentPerLayer),this.setAvailableSets(this.pointer.origin),this.setAvailableArrays(this.pointer.origin),this.setAvailableAxes(this.pointer.origin);let e=Array(this.maxContentPerLayer.length);for(let t=0;t<this.maxContentPerLayer.length;t++)e[t]={},Object.keys(this.maxContentPerLayer[t]).forEach(n=>{e[t][n]={value:{min:this.minContentPerLayer[t][n],max:this.maxContentPerLayer[t][n]},error:{min:this.minErrorPerLayer[t][n],max:this.maxErrorPerLayer[t][n]}}});console.log(`minMaxValues: `,e),v(this.id).next({...v(this.id).getValue(),minMaxValue:e})}this.totalInstances=this.maxInstancesPerLayer.reduce((e,t)=>e*t,1),this.setupInsBufGeom(),this.wireframe=new Ae(this.maxInstancesPerLayer,this.matrixCache,this.config.wireframe,this.id)}setupMatrixCache(){this.matrixCache=Array(this.maxInstancesPerLayer.length-1);let e=this.availableSets.length>0;e&&(this.matrixCache[this.matrixCache.length-1]=Array(this.availableSets.length));let t=this.maxInstancesPerLayer[0];for(let n=0;n<this.maxInstancesPerLayer.length-1-(e?1:0);n++)this.matrixCache[n]={pos:new Float32Array(t*3),scale:new Float32Array(t*3),rendered:new Float32Array(t).fill(-1)},t*=this.maxInstancesPerLayer[n+1];if(!e)return;let n=this.matrixCache[this.matrixCache.length-1];for(let e=0;e<n.length;e++)n[e]={pos:new Float32Array(t*3),scale:new Float32Array(t*3),rendered:new Float32Array(t).fill(-1)}}setupInsBufGeom(){this.setupMatrixCache();let e=this.maxInstancesPerLayer.reduce((e,t)=>e*t,1);this.selectedSet.length>1&&(e*=this.selectedSet.length);let t=new r.BoxGeometry(1,1,1);this.instGeom=new r.InstancedBufferGeometry,this.instGeom.instanceCount=0,this.instGeom.frustumCulled=!1,this.instGeom.index=t.index;for(let e in t.attributes)this.instGeom.setAttribute(e,t.attributes[e]);this.material=this.createMaterial(),this.colorArray=new Float32Array(192),this.material.uniforms.colorArray={value:this.colorArray},Te(this.config,this.material,this.colorArray),this.instancePositions=new Float32Array(3),this.instanceScales=new Float32Array(3),this.instanceColors=new Float32Array(1),this.instGeom.setAttribute(`instancePosition`,new r.InstancedBufferAttribute(this.instancePositions,3)),this.instGeom.setAttribute(`instanceScale`,new r.InstancedBufferAttribute(this.instanceScales,3)),this.instGeom.setAttribute(`instanceColorIndex`,new r.InstancedBufferAttribute(this.instanceColors,1)),this.mesh=new r.Mesh(this.instGeom,this.material),this.mesh.raycast=this.raycastHandler,this.mesh.frustumCulled=!1,this.material.uniforms.colorArray={value:this.colorArray},this.mesh.material.uniformsNeedUpdate=!0}pushVisibleInstances(){let e=this.mesh.parent;e&&(e.remove(this.mesh),this.instGeom.dispose());let t=0;for(let e=0;e<this.matrixCache.length;e++){let n=this.matrixCache[e];if(Array.isArray(n))for(let e=0;e<n.length;e++){let r=n[e];for(let e=0;e<r.rendered.length;e++)r.rendered[e]!==-1&&t++}else for(let e=0;e<n.rendered.length;e++)n.rendered[e]!==-1&&t++}let n=new Float32Array(t*3),i=new Float32Array(t*3),a=new Float32Array(t),o=0;for(let e=0;e<this.matrixCache.length;e++){let t=this.matrixCache[e];if(Array.isArray(t))for(let e=0;e<t.length;e++){let r=t[e];for(let e=0;e<r.rendered.length;e++)r.rendered[e]!==-1&&(n[o*3]=r.pos[e*3],n[o*3+1]=r.pos[e*3+1],n[o*3+2]=r.pos[e*3+2],i[o*3]=r.scale[e*3],i[o*3+1]=r.scale[e*3+1],i[o*3+2]=r.scale[e*3+2],a[o++]=r.rendered[e])}else for(let e=0;e<t.rendered.length;e++)t.rendered[e]!==-1&&(n[o*3]=t.pos[e*3],n[o*3+1]=t.pos[e*3+1],n[o*3+2]=t.pos[e*3+2],i[o*3]=t.scale[e*3],i[o*3+1]=t.scale[e*3+1],i[o*3+2]=t.scale[e*3+2],a[o++]=t.rendered[e])}let s=new r.BoxGeometry(1,1,1);this.instGeom=new r.InstancedBufferGeometry,this.instGeom.instanceCount=t,this.instGeom.frustumCulled=!1,this.instGeom.index=s.index;let c=s.attributes;for(let e in c)this.instGeom.setAttribute(e,c[e]);this.instancePositions=n,this.instanceScales=i,this.instanceColors=a,this.instGeom.setAttribute(`instancePosition`,new r.InstancedBufferAttribute(n,3)),this.instGeom.setAttribute(`instanceScale`,new r.InstancedBufferAttribute(i,3)),this.instGeom.setAttribute(`instanceColorIndex`,new r.InstancedBufferAttribute(a,1)),this.mesh=new r.Mesh(this.instGeom,this.material),this.mesh.raycast=this.raycastHandler,this.mesh.frustumCulled=!1,e&&e.add(this.mesh)}setMatrixCacheAt(e,t,n,r,i){let a=t===null?this.matrixCache[e]:this.matrixCache[e][t];a.pos[n*3]=r.x.pos,a.pos[n*3+1]=r.y.pos,a.pos[n*3+2]=r.z.pos,a.scale[n*3]=r.x.size,a.scale[n*3+1]=r.y.size,a.scale[n*3+2]=r.z.size,a.rendered[n]=i}async renderHistogram(e,t,n){if(!this.pointer||n>=this.maxInstancesPerLayer.length-1)return;this.logRender({procedure:`render`,value:{startIndex:e,endIndex:t,layer:n}});let i={x:{size:0,pos:0},y:{size:0,pos:0},z:{size:0,pos:0}},a=async(e,t,o,s,c,l)=>{if(o>n||!s)return;let u=new U([s.fXaxis.fNbins,s.fYaxis.fNbins,s.fZaxis.fNbins]),d,f,p,m,h=s.fArrays?.[this.selectedArray]?.outside??!1,g=this.selectedSet.indexOf(l),_=this.availableSets.indexOf(l),v=s.fArrays?s.fArrays[Object.keys(s.fArrays)[0]].values??!1:!1,y=this.availableAxes[o],b=this.config.scale.scaleBy===`value`;if(l)if(this.config.scale.sets===`fixed`)({min:d,max:f}=this.minMaxValue[o+this.pointer.parentPath.length][l].value),{min:m,max:p}=this.minMaxValue[o+this.pointer.parentPath.length][l].error;else if(this.config.scale.sets===`relative`){let e=s.fSumw2.filter(e=>e!==0),t=b?s.fArray.filter(e=>e!==0):e;d=Math.min(...t),f=Math.max(...t),p=this.maxErrorPerLayer[o+this.pointer.parentPath.length][l],m=this.minErrorPerLayer[o+this.pointer.parentPath.length][l]}else d=b?this.minContentPerLayer[o+this.pointer.parentPath.length][l]:-.1,f=b?this.maxContentPerLayer[o+this.pointer.parentPath.length][l]:this.maxErrorPerLayer[o+this.pointer.parentPath.length][l],p=this.maxErrorPerLayer[o+this.pointer.parentPath.length][l],m=this.minErrorPerLayer[o+this.pointer.parentPath.length][l];else if(this.selectedArray!==`content`&&s.fArrays&&v)if(this.config.scale.parameter===`fixed`)({min:d,max:f}=this.minMaxValue[o+this.pointer.parentPath.length][this.selectedArray].value),{min:m,max:p}=this.minMaxValue[o+this.pointer.parentPath.length][this.selectedArray].error;else if(this.config.scale.parameter===`relative`){let e=s.fArrays[this.selectedArray].errors.filter(e=>e!==0),t=b?s.fArrays[this.selectedArray].values.filter(e=>e!==0):e;d=Math.min(...t),f=Math.max(...t),p=this.maxErrorPerLayer[o+this.pointer.parentPath.length][this.selectedArray],m=this.minErrorPerLayer[o+this.pointer.parentPath.length][this.selectedArray]}else d=b?this.minContentPerLayer[0][this.selectedArray]:-.1,f=b?this.maxContentPerLayer[0][this.selectedArray]:this.maxErrorPerLayer[0][this.selectedArray],p=this.maxErrorPerLayer[0][this.selectedArray],m=this.minErrorPerLayer[0][this.selectedArray];else{let e=this.pointer.isOnSet??`content`;if(this.config.scale.content===`fixed`)({min:d,max:f}=this.minMaxValue[o+this.pointer.parentPath.length][e].value),{min:m,max:p}=this.minMaxValue[o+this.pointer.parentPath.length][e].error;else if(this.config.scale.content===`relative`){let t=s.fSumw2.filter(e=>e!==0),n=b?s.fArray.filter(e=>e!==0):t;d=Math.min(...n),f=Math.max(...n),p=this.maxErrorPerLayer[o+this.pointer.parentPath.length][e],m=this.minErrorPerLayer[o+this.pointer.parentPath.length][e]}else d=b?this.minContentPerLayer[o+this.pointer.parentPath.length][e]:-.1,f=b?this.maxContentPerLayer[o+this.pointer.parentPath.length][e]:this.maxErrorPerLayer[o+this.pointer.parentPath.length][e],p=this.maxErrorPerLayer[o+this.pointer.parentPath.length][e],m=this.minErrorPerLayer[o+this.pointer.parentPath.length][e]}d===f&&(d=f-.2);let x=s._typename.substring(0,3)===`TH3`,S=s._typename.substring(0,3)===`TH2`,C=s._typename.substring(0,3)===`TH1`,w=this.maxInstancesPerLayer.slice(o+1).reduce((e,t)=>e*t,1);u.setFromNumber(e/w);let T=this.config.padding.layer[o]??this.config.padding.default,E=!this.config.padding.layer[o]&&C?{x:T.x,y:T.y,z:T.z}:{...T};l&&this.config.padding.sets&&C&&(E={x:this.config.padding.sets.x,y:0,z:0}),this.pointer.isOnSet&&(E={x:0,y:0,z:0});let{min:D,max:O}=this.config.scale?.layer?.[o]?this.config.scale?.layer[o]:this.config.scale.default;for(let b=e;b<t;b+=w){let e={x:u.getValueAt(0),y:u.getValueAt(1),z:u.getValueAt(2)},C=he(c.position.z,c.scale.z,G(K(s,e,E,c?.scale,c?.position,o,i))),T=this.config.scale.scaleBy===`value`?d:m,k=this.config.scale.scaleBy===`value`?f:p,A=v||this.selectedArray===`content`?this.getBinContent(s,e.x,e.y,e.z,this.selectedArray):k,j=v||this.selectedArray===`content`?this.getBinError(s,e.x,e.y,e.z,this.selectedArray):0;console.log(`scaleMin`,T,`scaleMax`,k,`content`,A);let M=this.config.scale.scaleBy===`value`?A:j,N=1;if(T===k)N=1;else if(M>=T==!h){let e=y[0].scaleType===`log10`?Math.log(1+(M-T))/Math.log(1+(k-T)):(M-T)/(k-T);if(!h)N=(O-D)*e+D,N>1&&(N=1);else{let e=(A-void 0)/(void 0-void 0);N=Number.isInteger(A)&&A===0?N=0:(O-D)*e+D}}else N=0;this.config.color.scaleBy===`value`?this.color=Ee(this.config.color,M,T,k,_,o,y[0].errorType):this.color=Ee(this.config.color,j,m,p,_,o,y[0].errorType);let P=C.y.size*N;if(N===0)C.x.size=0,C.z.size=0,C.y.size=0;else if(x)C.x.size*=N,C.z.size*=N,C.y.size=P;else if(S)C.y.pos-=(C.y.size-P)/2,C.y.size=P;else if(C.y.pos-=(C.y.size-P)/2,C.y.size=P,l){let e=this.config.TH1ZScale.set;C.z.size=e||.01}else this.config.TH1ZScale?.layer?.[o]?C.z.size=c.scale.z*this.config.TH1ZScale.layer[o]:C.z.size=c.scale.z*this.config.TH1ZScale.default;if(l)C.z.size=.01,C.z.pos+=(g-(this.selectedSet.length-1)/2)*.1,this.setMatrixCacheAt(o,_,b/w,C,o===n&&N!==0?this.color:-1);else{let e=null;this.pointer.isOnSet&&(C.z.size=.01,C.z.pos+=(g-(this.selectedSet.length-1)/2)*.1,e=this.availableSets.indexOf(this.pointer.isOnSet)),this.setMatrixCacheAt(o,e,b/w,C,o===n&&N!==0?this.color:-1)}if(o===n){let e=b;l&&(e+=this.totalInstances*g)}else{let n=s.getBin(e.x+1,e.y+1,e.z+1),i,c={position:new r.Vector3(C.x.pos,C.y.pos,C.z.pos),scale:new r.Vector3(C.x.size,C.y.size,C.z.size)};s.children.content?(i=s.children.content[n],a(b,t,o+1,i,c)):this.selectedSet.forEach(e=>{i=s.children[e][n],a(b,t,o+1,i,c,e)})}if(!u.increment())break}};this.pointer.isOnSet?await Promise.all(this.selectedSet.map(n=>a(e,t,0,X(this.pointer.rootObj,this.pointer.parentPath.map(e=>e.bin[0]),n),this.limits,n))):await a(e,t,0,this.pointer.origin,this.limits),this.pointer.isOnSet||this.wireframe.pushVisibleInstances(this.matrixCache,this.maxInstancesPerLayer,this.availableSets.indexOf(this.selectedSet[0])),this.pushVisibleInstances();let o=this.availableSets.indexOf(this.pointer.isOnSet)===-1?null:this.availableSets.indexOf(this.pointer.isOnSet);return this.BVHTree=ke(this.matrixCache,this.pointer.origin,0,this.selectedSet,o,this.availableSets,this.mesh.matrixWorld,this.maxInstancesPerLayer),this.mesh}createMaterial(){return new r.ShaderMaterial({vertexShader:`
|
|
58
58
|
attribute vec3 instancePosition;
|
|
59
59
|
attribute vec3 instanceScale;
|
|
60
60
|
attribute float instanceColorIndex;
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
void main() {
|
|
83
83
|
gl_FragColor = vec4(vColor, 1.0);
|
|
84
84
|
}
|
|
85
|
-
`,transparent:!1})}mouseClickDefault(e){this.showChildHistogram(e.index),e.selectedArray!==`content`&&e.jsrootObj?.fArrays[e.selectedArray]?.values&&(e.jsrootObj.fArray=e.jsrootObj.fArrays[e.selectedArray]?.values,e.jsrootObj.fSumw2=e.jsrootObj.fArrays[e.selectedArray]?.errors,e.jsrootObj.fMinimum=e.jsrootObj.fArrays[e.selectedArray]?.min,e.jsrootObj.fMaximum=e.jsrootObj.fArrays[e.selectedArray]?.max),F().next({id:this.id+`-cinema`,obj:e.jsrootObj})}getBinPosScaleByIndexMC(e,t){let n=t&&t!==`content`?this.matrixCache[e.length-1][this.availableSets.indexOf(t)]:this.matrixCache[e.length-1],r=e.at(-1)/this.maxInstancesPerLayer.slice(e.length).reduce((e,t)=>e*t,1)*3;return{position:n.pos.slice(r,r+3),scale:n.scale.slice(r,r+3)}}getBinPosScaleByIndex(e,t,n,r){let i=({scale:e,position:t})=>({scale:{x:e[0],y:e[1],z:e[2]},position:{x:t[0],y:t[1],z:t[2]}}),a=e.length-1,o=a===0?this.limits:i(this.getBinPosScaleByIndexMC(e.slice(0,-1),null)),s={x:{size:0,pos:0},y:{size:0,pos:0},z:{size:0,pos:0}},c=n._typename.substring(0,3)===`TH1`,l=this.config.padding.layer[a]??this.config.padding.default,u=!this.config.padding.layer[a]&&c?{x:l.x,y:l.y,z:l.z}:{...l};return t&&this.config.padding.sets&&c&&(u={x:this.config.padding.sets.x,y:0,z:0}),this.pointer.isOnSet&&(u={x:0,y:0,z:0}),he(o.position.z,o.scale.z,G(K(n,r,u,o?.scale,o?.position,a,s))),{position:[s.x.pos,s.y.pos,s.z.pos],scale:[s.x.size,s.y.size,s.z.size]}}mousemoveDefault(e){if(((e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],i=t[n];if(r.x!==i.x||r.y!==i.y||r.z!==i.z)return!1}return!0})(e.index,this.dirtyInstance)){this.dirtyInstance=null;return}let t=this.pointer.parentPath.map(e=>{let t=e.range[0];return{bin:e.bin[0],...t}});e.range=e.range.map((t,n)=>{let r=e.jsrootInstance[n];return{...t,bin:r}});let n={...e,level:t.length,range:t.concat(e.range)},{range:r,level:i,content:a,error:o,set:s,triggerSource:c,instanceId:l}=n,u={coords:r,level:i,content:a,error:o,set:s,triggerSource:c,instanceId:l,binPosSize:this.getBinPosScaleByIndexMC(n.instanceId,n.set),binWholePosSize:this.getBinPosScaleByIndex(n.instanceId,n.set,n.jsrootObj,n.index.at(-1))};z().next(u)}shiftMouseClickDefault(e){this.hideChildHistogram(e.index)}mouseDBClickDefault(e){e.set?this.setPointerToChild(e.index,e.set):this.setPointerToChild(e.index,this.selectedSet[0])}shiftMouseDBClickDefault(e){this.setPointerToParent()}intersectionHandler(e,t){this.mouseEvents.filter(e=>e.event===t).forEach(t=>t.function(e,this)),this.dirtyInstance=e.index}raycastHandler(e,t){try{let n=this.checkIntersectionBVH(e.ray)[0];if(n){let r=e._triggerSource;this.intersectionHandler(n,r),t.push(n)}}catch(e){console.log(e)}}handleStateChange(e){if(ge(e.sets,this.availableSets)&&(!ge(e.selectedSet,this.selectedSet)||this.selectedArray!==e.selectedArray)){this.selectedArray=e.selectedArray,this.selectedSet=e.selectedSet;let t=this.mesh.parent;this.instGeom.dispose(),t.remove(this.mesh),this.setupInsBufGeom(),t.add(this.mesh),this.renderHistogramHistory()}else this.minMaxValue.length!==0&&_e(e.minMaxValue,this.minMaxValue)?this.renderHistogramHistory():(this.availableSets=e.sets,this.selectedSet=e.selectedSet,this.minMaxValue=e.minMaxValue,this.availableAxes=e.availableAxes)}async renderHistogramHistory(){let e=this.renderHistory;this.renderHistory=[];for(let t of e)t.procedure===`render`?await this.renderHistogram(t.value.startIndex,t.value.endIndex,t.value.layer):t.procedure===`hide`&&this.hideChildHistogram(t.value)}async setPointerToChild(e,t){let n=this.mesh.parent;this.matrixCache=[],this.instGeom.dispose(),this.wireframe.dispose(),n.remove(this.mesh);let r=Y(e,t,this.pointer.origin,this.wireframe,this.selectedSet);if(this.pointer.setOriginToChild(J(e,this.pointer.origin,this.selectedSet),t,r),!this.pointer.isHistogramFilled){this.mesh=k(this.limits,this.setPointerToParent.bind(this)),n.add(this.mesh);return}this.init(!1),console.log(`path: `,this.pointer.path),console.log(`title: `,this.pointer.title),await this.renderHistogram(0,this.totalInstances,0),n.add(this.mesh),n.add(this.wireframe.wireframe),this.pointer.isOnSet&&this.wireframe.toggleVisibility(this.matrixCache,this.maxInstancesPerLayer,this.availableSets.indexOf(t))}async setPointerToParent(){let e=this.mesh.parent;e.remove(this.mesh),this.pointer.isHistogramFilled&&(this.matrixCache=[],this.instGeom.dispose(),this.wireframe.dispose()),this.pointer.setOriginToParent(1),console.log(`path: `,this.pointer.path),console.log(`title: `,this.pointer.title),this.init(!1),await this.renderHistogram(0,this.totalInstances,0),e.add(this.mesh),e.add(this.wireframe.wireframe)}showChildHistogram(e){let t=q(e,this.pointer.origin,this.maxInstancesPerLayer,this.selectedSet),n=this.maxInstancesPerLayer.slice(-this.maxInstancesPerLayer.length+e.length).reduce((e,t)=>e*t,1);this.renderHistogram(t.slice(-1)[0],t.slice(-1)[0]+n,e.length)}hideChildHistogram(e){if(e.length===1)return;let t=this.maxInstancesPerLayer.slice(e.length-1),n=this.maxInstancesPerLayer.slice(e.length-1,this.maxInstancesPerLayer.length-1),r=t.reduce((e,t)=>e*t,1),i=ve(e,this.pointer.origin,this.maxInstancesPerLayer,this.selectedSet),a=Math.floor(i/r)*r;this.clearMatrixCacheRange(a,r,n,e.length-1),this.logRender({procedure:`hide`,value:e}),this.renderHistogram(a,a+r,e.length-2),this.renderHistory.pop()}clearMatrixCacheRange(e,t,n,r){let i=e,a=t,o={x:{pos:0,size:0},y:{pos:0,size:0},z:{pos:0,size:0}};for(let e=r+n.length-1;e>=r;e--){if(Array.isArray(this.matrixCache[e]))for(let t=0;t<this.matrixCache[e].length;t++)for(let n=i;n<i+a;n++)this.setMatrixCacheAt(e,t,n,o,-1);else for(let t=i;t<i+a;t++)this.setMatrixCacheAt(e,null,t,o,-1);e>r&&(i/=n[e-r],a/=n[e-r])}}setAvailableAxes(e){let t=v(this.id).getValue(),n=[],r=[`x`,`y`,`z`],i=e=>{let t=[];t.push({scaleType:`linear`,errorType:`linear`});let a=Number.parseInt(e._typename.substring(2,3),10);for(let n=0;n<a;n++){let i=r[n],a=e[`f${i.toUpperCase()}axis`];t.push({axis:i,fTitle:a.fTitle,fName:a.fName,scaleType:`linear`,errorType:`linear`,fXmax:a.fXmax,fXmin:a.fXmin})}n.push(t),e.children&&i(e.children[Object.keys(e.children)[0]].find(e=>e!==null))};i(e),t.availableAxes=n,v(this.id).next(t)}setAvailableSets(e){if(e.children?.content){let t=e.children.content.find(e=>e);this.setAvailableSets(t)}else if(e?.children){let t=v(this.id).getValue();t.sets=Object.keys(e.children),t.selectedSet.length===0?(this.selectedSet.push(t.sets[0]),t.selectedSet.push(t.sets[0])):this.selectedSet.every(e=>t.sets.find(t=>t===e))||(t.selectedSet=[t.sets[0]]),v(this.id).next(t)}else{let e=v(this.id).getValue();e.sets=[],e.selectedSet=[]}}setAvailableArrays(e){let t=v(this.id).getValue();t.arrays=[],e.fArrays&&(t.arrays=Object.keys(e.fArrays)),t.arrays.unshift(`content`);let n=e=>{let r=e.find(e=>e);r.fArrays&&(t.arrays=t.arrays.concat(Object.keys(r.fArrays))),r.children?.content&&n(r.children.content)};e.children?.content&&n(e.children.content),t.arrays=[...new Set(t.arrays)],v(this.id).next(t)}configSubjectHandler(e){this.config=L().mergeHistogramConfig(this?.opts?.config),this.keyBindings=T(e.config.bindings);let t=e.config.environment.histogramPads.find(e=>e.id===this.id);t&&!O(this.limits,t)&&this.renderHistory.length>0&&(this.limits={...t},this.renderHistogramHistory()),this.limits={...t}}keyDownHandler(e){let t=e.code.match(/^(?:Digit|Numpad)(\d+)$/);if(t){if(parseInt(t[1])>this.matrixCache.length)return;let e=new r.Object3D;e.scale.set(0,0,0),e.updateMatrix();let n=this.maxInstancesPerLayer.reduce((e,t)=>e*t,1);this.selectedSet.length>1&&(n*=this.selectedSet.length),this.setupMatrixCache(),this.wireframe.clearWireframe(),this.renderHistogram(0,this.totalInstances,parseInt(t[1])-1)}else e.key===this.keyBindings.hideOutlines?this.wireframe.toggleVisibility(this.matrixCache,this.maxInstancesPerLayer,this.availableSets.indexOf(this.selectedSet[0])):e.key===this.keyBindings.resetHistogram?this.resetHistogram():e.key===this.keyBindings.goToPreviousLayer&&this.setPointerToParent()}keyUpHandler(e){}resetHistogram(){this.updateHistogram({obj:this.rootObj})}logRender(e){e.procedure===`render`&&e.value.startIndex===0&&e.value.endIndex===this.totalInstances&&(this.renderHistory=[]),this.renderHistory.push(e)}getBinContent(e,t,n,r,i){if(i===`content`||!e.fArrays)return e.getBinContent(t+1,n+1,r+1);{let a=e.getBin(t+1,n+1,r+1);return e.fArrays?.[i].values[a]}}getBinError(e,t,n,r,i){let a=e.getBin(t+1,n+1,r+1);return i===`content`||!e.fArrays?e.fSumw2.length===0?e.getBinError(a):e.fSumw2[a]:e.fArrays?.[i].errors[a]}checkIntersectionBVH(e){let t=new r.Vector3,n=(e,t,n,i)=>{if(t<0||1/t==-1/0){let n=t*-1,a=i&&i!==`content`?this.matrixCache[e]?.[this.availableSets.indexOf(i)]:this.matrixCache[e];return a?new r.Box3().setFromCenterAndSize(new r.Vector3(a.pos[n*3],a.pos[n*3+1],a.pos[n*3+2]),new r.Vector3(a.scale[n*3],a.scale[n*3+1],a.scale[n*3+2])):void 0}else{let a=i&&i!==`content`?Array.isArray(this.BVHTree[e][this.availableSets.indexOf(i)])?this.BVHTree[e][this.availableSets.indexOf(i)][n]:this.BVHTree[e][this.availableSets.indexOf(i)]:this.BVHTree[e][n];return a?new r.Box3().setFromCenterAndSize(new r.Vector3(a.pos[t*3],a.pos[t*3+1],a.pos[t*3+2]),new r.Vector3(a.scale[t*3],a.scale[t*3+1],a.scale[t*3+2])):void 0}},i=(e,t)=>{let n=0,r=e,i=t;for(;r+1<this.matrixCache.length;){r++;let t=this.matrixCache[r];if(Array.isArray(t))this.selectedSet.forEach(a=>{let o=this.availableSets.indexOf(a);for(let a=i;a<i+this.maxInstancesPerLayer[r];a++)if(t[o].rendered[a]!==-1){n=r-e;break}});else{if(!t)return n;for(let a=i;a<i+this.maxInstancesPerLayer[r];a++)if(t.rendered[a]!==-1){n=r-e;break}}i*=this.maxInstancesPerLayer[r+1]}return n},a=(r,i,a,o)=>{let s=o&&o!==`content`?Array.isArray(this.BVHTree[a][this.availableSets.indexOf(o)])?this.BVHTree[a][this.availableSets.indexOf(o)][i]:this.BVHTree[a][this.availableSets.indexOf(o)]:this.BVHTree[a][i],c=n(a,s.left[r],i,o),l=n(a,s.right[r],i,o),u=[];return e.intersectBox(c,t)?u.push({index:s.left[r],target:t.clone(),distance:e.origin.distanceTo(t)}):u.push(null),e.intersectBox(l,t)?u.push({index:s.right[r],target:t.clone(),distance:e.origin.distanceTo(t)}):u.push(null),u},o=(e,t,n)=>{let r=[],i=o=>{if(o.index<0||1/o.index==-1/0){r.push(o);return}let[s,c]=a(o.index,t,e,n);s&&i(s),c&&i(c)},o=n&&n!==`content`?Array.isArray(this.BVHTree[e][this.availableSets.indexOf(n)])?this.BVHTree[e][this.availableSets.indexOf(n)][t]:this.BVHTree[e][this.availableSets.indexOf(n)]:this.BVHTree[e][t];return!o||o.length===0||i({index:o.left.length-1,target:null,distance:null}),r},s=(e,t,n=0,r=[],a=null)=>{let c=[],l=this.maxInstancesPerLayer[t+1],u=this.maxInstancesPerLayer[t]*this.maxInstancesPerLayer[t+1],d=e.fArrays?e.fArrays[Object.keys(e.fArrays)[0]].values:!1;return o(t,n,a).forEach(o=>{let f=Math.abs(o.index)-n*this.maxInstancesPerLayer[t],p=f%e.fXaxis.fNbins,m=Math.floor(f%(e.fXaxis.fNbins*e.fYaxis.fNbins)/e.fXaxis.fNbins),h=Math.floor(f/(e.fXaxis.fNbins*e.fYaxis.fNbins)),g=[...r,{x:p,y:m,z:h}];if(e.children){let r=Object.entries(e.children).flatMap(([r,a])=>{let c=e.getBin(p+1,m+1,h+1),d=a?.[c];if(!d||!(i(t,n*u+(p+m*e.fXaxis.fNbins+h*(e.fXaxis.fNbins*e.fYaxis.fNbins))*l,null)>0))return[];let f=s(d,t+1,Math.abs(o.index),g,r);return r!==`content`&&(f=f.map(e=>({...e,set:r}))),f});if(r.length>0)c.push(...r);else{let r=n*this.maxInstancesPerLayer[t]+(p+m*e.fXaxis.fNbins+h*(e.fXaxis.fNbins*e.fYaxis.fNbins));(a&&a!==`content`?this.matrixCache[t]?.[this.availableSets.indexOf(a)]:this.matrixCache[t]).rendered[r]!==-1&&c.push({index:g,target:o.target,distance:o.distance,set:a,selectedArray:this.selectedArray,instanceId:q(g,this.pointer.origin,this.maxInstancesPerLayer,this.selectedSet),jsrootInstance:J(g,this.pointer.origin,this.selectedSet),range:Y(g,a,this.pointer.origin,this.wireframe,this.selectedSet),origin:this,jsrootObj:e,content:this.getBinContent(e,p,m,h,d?this.selectedArray:`content`),error:this.getBinError(e,p,m,h,d?this.selectedArray:`content`)})}}else c.push({index:g,target:o.target,distance:o.distance,set:a,selectedArray:this.selectedArray,instanceId:q(g,this.pointer.origin,this.maxInstancesPerLayer,this.selectedSet),jsrootInstance:J(g,this.pointer.origin,this.selectedSet),range:Y(g,a,this.pointer.origin,this.wireframe,this.selectedSet),origin:this,object:this.mesh,jsrootObj:e,content:this.getBinContent(e,p,m,h,d?this.selectedArray:`content`),error:this.getBinError(e,p,m,h,d?this.selectedArray:`content`)})}),c.sort((e,t)=>e.distance-t.distance)};if(this.pointer.isOnSet===null)return s(this.pointer.origin,0,0,[],this.pointer.isOnSet);{let e=this.selectedSet.map(e=>s(X(this.pointer.rootObj,this.pointer.parentPath.map(e=>e.bin[0]),e),0,0,[],e)).filter(e=>e.length!==0),t=Math.min(...e.map(e=>e[0].distance));return e.find(e=>e[0].distance===t)??[]}}dispatchSubjectHandler(e){if(!e.event.jsrootInstance){let t=e.event.index.map(e=>({x:e.x-1,y:e.y-1,z:e.z-1})),n=this.pointer.getChildByPosition(J([...t]).slice(0,-1),e.event.set,this.selectedSet);e.event={index:t,set:e.event.set,jsrootInstance:J(t,this.pointer.origin,this.selectedSet),range:Y(t,e.event.set,this.pointer.origin,this.wireframe,this.selectedSet),origin:this,jsrootObj:n,content:this.getBinContent(n,t[0].x+1,t[0].y+1,t[0].z+1,n.fArrays[Object.keys(n.fArrays)[0]].values?this.selectedArray:`content`),error:n.getBinError(t[0].x+1,t[0].y+1,t[0].z+1)}}this.intersectionHandler(e.event,e.event.source)}},Ne=class{plane=void 0;cinemaSub=void 0;position;rotation;scale;id;configSub=void 0;constructor(e,i,a,o,s){let c=new r.PlaneGeometry(o.x,o.y),l=new r.MeshBasicMaterial({color:new r.Color().setHex(16777215),side:r.DoubleSide});this.plane||(this.plane=new r.Mesh(c,l),this.plane.position.set(i.x,i.y,i.z)),e&&this.updateTexture(e),this.id=s,this.position=i,this.rotation=a,this.scale=o,this.cinemaSub=F().getObservable().pipe((0,t.filter)(e=>e.id===this.id||e.id===`*`)).subscribe(e=>{let t=e.obj;(0,n.makeImage)({format:`png`,option:`pE`,object:t,width:1200,height:600}).then(e=>{this.updateTexture(e)})}),this.configSub=L().getObservable().pipe((0,t.filter)(e=>e.target.id.includes(`*`)||e.target.id.includes(this.id))).subscribe(e=>{let t=e.config.environment.canvasPads.filter(e=>e.id===this.id||e.id===`*`);t.length!==0&&(this.position=t[0].limits.position,this.rotation=t[0].limits.rotation,this.scale=t[0].limits.scale,this.updateMesh())})}updateMesh(){this.plane.scale.set(this.scale.x,this.scale.y,this.scale.z),this.plane.position.set(this.position.x,this.position.y,this.position.z);let e=Math.PI/180;this.plane.rotation.set(this.rotation.x*e,this.rotation.y*e,this.rotation.z*e)}updateTexture(e){if(!e){console.warn(`updateTexture called with null/undefined`);return}let t=new r.TextureLoader;if(typeof e==`string`&&(e.startsWith(`data:`)||e.startsWith(`http`)))t.load(e,e=>{this.plane.material.map=e,this.plane.material.needsUpdate=!0},void 0,e=>console.error(`Texture load failed`,e));else if(e instanceof HTMLImageElement){let t=new r.Texture(e);t.needsUpdate=!0,this.plane.material.map=t,this.plane.material.needsUpdate=!0}else console.error(`Unsupported image type passed to updateTexture:`,e)}remove(){this.plane.parent&&(this.plane.parent.remove(this.plane),this.cinemaSub.unsubscribe(),this.configSub.unsubscribe())}getPlane(){return this.plane}},Pe=class extends r.Loader{constructor(e){super(e)}load(e,t,n,i){let a=this,o=new r.FileLoader(this.manager);o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,function(e){let n=a.parse(JSON.parse(e));t&&t(n)},n,i)}parse(e){return new Fe(e)}},Fe=class{constructor(e){this.isFont=!0,this.type=`Font`,this.data=e}generateShapes(e,t=100,n=`ltr`){let r=[],i=Ie(e,t,this.data,n);for(let e=0,t=i.length;e<t;e++)r.push(...i[e].toShapes());return r}};function Ie(e,t,n,r){let i=Array.from(e),a=t/n.resolution,o=(n.boundingBox.yMax-n.boundingBox.yMin+n.underlineThickness)*a,s=[],c=0,l=0;(r==`rtl`||r==`tb`)&&i.reverse();for(let e=0;e<i.length;e++){let t=i[e];if(t===`
|
|
85
|
+
`,transparent:!1})}mouseClickDefault(e){this.showChildHistogram(e.index),e.selectedArray!==`content`&&e.jsrootObj?.fArrays[e.selectedArray]?.values&&(e.jsrootObj.fArray=e.jsrootObj.fArrays[e.selectedArray]?.values,e.jsrootObj.fSumw2=e.jsrootObj.fArrays[e.selectedArray]?.errors,e.jsrootObj.fMinimum=e.jsrootObj.fArrays[e.selectedArray]?.min,e.jsrootObj.fMaximum=e.jsrootObj.fArrays[e.selectedArray]?.max),F().next({id:this.id+`-cinema`,obj:e.jsrootObj})}getBinPosScaleByIndexMC(e,t){let n=t&&t!==`content`?this.matrixCache[e.length-1][this.availableSets.indexOf(t)]:this.matrixCache[e.length-1],r=e.at(-1)/this.maxInstancesPerLayer.slice(e.length).reduce((e,t)=>e*t,1)*3;return{position:n.pos.slice(r,r+3),scale:n.scale.slice(r,r+3)}}getBinPosScaleByIndex(e,t,n,r){let i=({scale:e,position:t})=>({scale:{x:e[0],y:e[1],z:e[2]},position:{x:t[0],y:t[1],z:t[2]}}),a=e.length-1,o=a===0?this.limits:i(this.getBinPosScaleByIndexMC(e.slice(0,-1),null)),s={x:{size:0,pos:0},y:{size:0,pos:0},z:{size:0,pos:0}},c=n._typename.substring(0,3)===`TH1`,l=this.config.padding.layer[a]??this.config.padding.default,u=!this.config.padding.layer[a]&&c?{x:l.x,y:l.y,z:l.z}:{...l};return t&&this.config.padding.sets&&c&&(u={x:this.config.padding.sets.x,y:0,z:0}),this.pointer.isOnSet&&(u={x:0,y:0,z:0}),he(o.position.z,o.scale.z,G(K(n,r,u,o?.scale,o?.position,a,s))),{position:[s.x.pos,s.y.pos,s.z.pos],scale:[s.x.size,s.y.size,s.z.size]}}mousemoveDefault(e){if(((e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],i=t[n];if(r.x!==i.x||r.y!==i.y||r.z!==i.z)return!1}return!0})(e.index,this.dirtyInstance)){this.dirtyInstance=null;return}let t=this.pointer.parentPath.map(e=>{let t=e.range[0];return{bin:e.bin[0],...t}});e.range=e.range.map((t,n)=>{let r=e.jsrootInstance[n];return{...t,bin:r}});let n={...e,level:t.length,range:t.concat(e.range)},{range:r,level:i,content:a,error:o,set:s,triggerSource:c,instanceId:l}=n,u={coords:r,level:i,content:a,error:o,set:s,triggerSource:c,instanceId:l,binPosSize:this.getBinPosScaleByIndexMC(n.instanceId,n.set),binWholePosSize:this.getBinPosScaleByIndex(n.instanceId,n.set,n.jsrootObj,n.index.at(-1))};z().next(u)}shiftMouseClickDefault(e){this.hideChildHistogram(e.index)}mouseDBClickDefault(e){e.set?this.setPointerToChild(e.index,e.set):this.setPointerToChild(e.index,this.selectedSet[0])}shiftMouseDBClickDefault(e){this.setPointerToParent()}intersectionHandler(e,t){this.mouseEvents.filter(e=>e.event===t).forEach(t=>t.function(e,this)),this.dirtyInstance=e.index}raycastHandler(e,t){try{let n=this.checkIntersectionBVH(e.ray)[0];if(n){let r=e._triggerSource;this.intersectionHandler(n,r),t.push(n)}}catch(e){console.log(e)}}handleStateChange(e){if(ge(e.sets,this.availableSets)&&(!ge(e.selectedSet,this.selectedSet)||this.selectedArray!==e.selectedArray)){this.selectedArray=e.selectedArray,this.selectedSet=e.selectedSet;let t=this.mesh.parent;this.instGeom.dispose(),t.remove(this.mesh),this.setupInsBufGeom(),t.add(this.mesh),this.renderHistogramHistory()}else this.minMaxValue.length!==0&&_e(e.minMaxValue,this.minMaxValue)?this.renderHistogramHistory():(this.availableSets=e.sets,this.selectedSet=e.selectedSet,this.minMaxValue=e.minMaxValue,this.availableAxes=e.availableAxes)}async renderHistogramHistory(){let e=this.renderHistory;this.renderHistory=[];for(let t of e)t.procedure===`render`?await this.renderHistogram(t.value.startIndex,t.value.endIndex,t.value.layer):t.procedure===`hide`&&this.hideChildHistogram(t.value)}async setPointerToChild(e,t){let n=this.mesh.parent;this.matrixCache=[],this.instGeom.dispose(),this.wireframe.dispose(),n.remove(this.mesh);let r=Y(e,t,this.pointer.origin,this.wireframe,this.selectedSet);if(this.pointer.setOriginToChild(J(e,this.pointer.origin,this.selectedSet),t,r),!this.pointer.isHistogramFilled){this.mesh=k(this.limits,this.setPointerToParent.bind(this)),n.add(this.mesh);return}this.init(!1),console.log(`path: `,this.pointer.path),console.log(`title: `,this.pointer.title),await this.renderHistogram(0,this.totalInstances,0),n.add(this.mesh),n.add(this.wireframe.wireframe),this.pointer.isOnSet&&this.wireframe.toggleVisibility(this.matrixCache,this.maxInstancesPerLayer,this.availableSets.indexOf(t))}async setPointerToParent(){let e=this.mesh.parent;e.remove(this.mesh),this.pointer.isHistogramFilled&&(this.matrixCache=[],this.instGeom.dispose(),this.wireframe.dispose()),this.pointer.setOriginToParent(1),console.log(`path: `,this.pointer.path),console.log(`title: `,this.pointer.title),this.init(!1),await this.renderHistogram(0,this.totalInstances,0),e.add(this.mesh),e.add(this.wireframe.wireframe)}showChildHistogram(e){let t=q(e,this.pointer.origin,this.maxInstancesPerLayer,this.selectedSet),n=this.maxInstancesPerLayer.slice(-this.maxInstancesPerLayer.length+e.length).reduce((e,t)=>e*t,1);this.renderHistogram(t.slice(-1)[0],t.slice(-1)[0]+n,e.length)}hideChildHistogram(e){if(e.length===1)return;let t=this.maxInstancesPerLayer.slice(e.length-1),n=this.maxInstancesPerLayer.slice(e.length-1,this.maxInstancesPerLayer.length-1),r=t.reduce((e,t)=>e*t,1),i=ve(e,this.pointer.origin,this.maxInstancesPerLayer,this.selectedSet),a=Math.floor(i/r)*r;this.clearMatrixCacheRange(a,r,n,e.length-1),this.logRender({procedure:`hide`,value:e}),this.renderHistogram(a,a+r,e.length-2),this.renderHistory.pop()}clearMatrixCacheRange(e,t,n,r){let i=e,a=t,o={x:{pos:0,size:0},y:{pos:0,size:0},z:{pos:0,size:0}};for(let e=r+n.length-1;e>=r;e--){if(Array.isArray(this.matrixCache[e]))for(let t=0;t<this.matrixCache[e].length;t++)for(let n=i;n<i+a;n++)this.setMatrixCacheAt(e,t,n,o,-1);else for(let t=i;t<i+a;t++)this.setMatrixCacheAt(e,null,t,o,-1);e>r&&(i/=n[e-r],a/=n[e-r])}}setAvailableAxes(e){let t=v(this.id).getValue(),n=[],r=[`x`,`y`,`z`],i=e=>{let t=[];t.push({size:`linear`,color:`linear`});let a=Number.parseInt(e._typename.substring(2,3),10);for(let n=0;n<a;n++){let i=r[n],a=e[`f${i.toUpperCase()}axis`];t.push({axis:i,fTitle:a.fTitle,fName:a.fName,size:`linear`,color:`linear`,fXmax:a.fXmax,fXmin:a.fXmin})}n.push(t),e.children&&i(e.children[Object.keys(e.children)[0]].find(e=>e!==null))};i(e),t.availableAxes=n,v(this.id).next(t)}setAvailableSets(e){if(e.children?.content){let t=e.children.content.find(e=>e);this.setAvailableSets(t)}else if(e?.children){let t=v(this.id).getValue();t.sets=Object.keys(e.children),t.selectedSet.length===0?(this.selectedSet.push(t.sets[0]),t.selectedSet.push(t.sets[0])):this.selectedSet.every(e=>t.sets.find(t=>t===e))||(t.selectedSet=[t.sets[0]]),v(this.id).next(t)}else{let e=v(this.id).getValue();e.sets=[],e.selectedSet=[]}}setAvailableArrays(e){let t=v(this.id).getValue();t.arrays=[],e.fArrays&&(t.arrays=Object.keys(e.fArrays)),t.arrays.unshift(`content`);let n=e=>{let r=e.find(e=>e);r.fArrays&&(t.arrays=t.arrays.concat(Object.keys(r.fArrays))),r.children?.content&&n(r.children.content)};e.children?.content&&n(e.children.content),t.arrays=[...new Set(t.arrays)],v(this.id).next(t)}configSubjectHandler(e){this.config=L().mergeHistogramConfig(this?.opts?.config),this.keyBindings=T(e.config.bindings);let t=e.config.environment.histogramPads.find(e=>e.id===this.id);t&&!O(this.limits,t)&&this.renderHistory.length>0&&(this.limits={...t},this.renderHistogramHistory()),this.limits={...t}}keyDownHandler(e){let t=e.code.match(/^(?:Digit|Numpad)(\d+)$/);if(t){if(parseInt(t[1])>this.matrixCache.length)return;let e=new r.Object3D;e.scale.set(0,0,0),e.updateMatrix();let n=this.maxInstancesPerLayer.reduce((e,t)=>e*t,1);this.selectedSet.length>1&&(n*=this.selectedSet.length),this.setupMatrixCache(),this.wireframe.clearWireframe(),this.renderHistogram(0,this.totalInstances,parseInt(t[1])-1)}else e.key===this.keyBindings.hideOutlines?this.wireframe.toggleVisibility(this.matrixCache,this.maxInstancesPerLayer,this.availableSets.indexOf(this.selectedSet[0])):e.key===this.keyBindings.resetHistogram?this.resetHistogram():e.key===this.keyBindings.goToPreviousLayer&&this.setPointerToParent()}keyUpHandler(e){}resetHistogram(){this.updateHistogram({obj:this.rootObj})}logRender(e){e.procedure===`render`&&e.value.startIndex===0&&e.value.endIndex===this.totalInstances&&(this.renderHistory=[]),this.renderHistory.push(e)}getBinContent(e,t,n,r,i){if(i===`content`||!e.fArrays)return e.getBinContent(t+1,n+1,r+1);{let a=e.getBin(t+1,n+1,r+1);return e.fArrays?.[i].values[a]}}getBinError(e,t,n,r,i){let a=e.getBin(t+1,n+1,r+1);return i===`content`||!e.fArrays?e.fSumw2.length===0?e.getBinError(a):e.fSumw2[a]:e.fArrays?.[i].errors[a]}checkIntersectionBVH(e){let t=new r.Vector3,n=(e,t,n,i)=>{if(t<0||1/t==-1/0){let n=t*-1,a=i&&i!==`content`?this.matrixCache[e]?.[this.availableSets.indexOf(i)]:this.matrixCache[e];return a?new r.Box3().setFromCenterAndSize(new r.Vector3(a.pos[n*3],a.pos[n*3+1],a.pos[n*3+2]),new r.Vector3(a.scale[n*3],a.scale[n*3+1],a.scale[n*3+2])):void 0}else{let a=i&&i!==`content`?Array.isArray(this.BVHTree[e][this.availableSets.indexOf(i)])?this.BVHTree[e][this.availableSets.indexOf(i)][n]:this.BVHTree[e][this.availableSets.indexOf(i)]:this.BVHTree[e][n];return a?new r.Box3().setFromCenterAndSize(new r.Vector3(a.pos[t*3],a.pos[t*3+1],a.pos[t*3+2]),new r.Vector3(a.scale[t*3],a.scale[t*3+1],a.scale[t*3+2])):void 0}},i=(e,t)=>{let n=0,r=e,i=t;for(;r+1<this.matrixCache.length;){r++;let t=this.matrixCache[r];if(Array.isArray(t))this.selectedSet.forEach(a=>{let o=this.availableSets.indexOf(a);for(let a=i;a<i+this.maxInstancesPerLayer[r];a++)if(t[o].rendered[a]!==-1){n=r-e;break}});else{if(!t)return n;for(let a=i;a<i+this.maxInstancesPerLayer[r];a++)if(t.rendered[a]!==-1){n=r-e;break}}i*=this.maxInstancesPerLayer[r+1]}return n},a=(r,i,a,o)=>{let s=o&&o!==`content`?Array.isArray(this.BVHTree[a][this.availableSets.indexOf(o)])?this.BVHTree[a][this.availableSets.indexOf(o)][i]:this.BVHTree[a][this.availableSets.indexOf(o)]:this.BVHTree[a][i],c=n(a,s.left[r],i,o),l=n(a,s.right[r],i,o),u=[];return e.intersectBox(c,t)?u.push({index:s.left[r],target:t.clone(),distance:e.origin.distanceTo(t)}):u.push(null),e.intersectBox(l,t)?u.push({index:s.right[r],target:t.clone(),distance:e.origin.distanceTo(t)}):u.push(null),u},o=(e,t,n)=>{let r=[],i=o=>{if(o.index<0||1/o.index==-1/0){r.push(o);return}let[s,c]=a(o.index,t,e,n);s&&i(s),c&&i(c)},o=n&&n!==`content`?Array.isArray(this.BVHTree[e][this.availableSets.indexOf(n)])?this.BVHTree[e][this.availableSets.indexOf(n)][t]:this.BVHTree[e][this.availableSets.indexOf(n)]:this.BVHTree[e][t];return!o||o.length===0||i({index:o.left.length-1,target:null,distance:null}),r},s=(e,t,n=0,r=[],a=null)=>{let c=[],l=this.maxInstancesPerLayer[t+1],u=this.maxInstancesPerLayer[t]*this.maxInstancesPerLayer[t+1],d=e.fArrays?e.fArrays[Object.keys(e.fArrays)[0]].values:!1;return o(t,n,a).forEach(o=>{let f=Math.abs(o.index)-n*this.maxInstancesPerLayer[t],p=f%e.fXaxis.fNbins,m=Math.floor(f%(e.fXaxis.fNbins*e.fYaxis.fNbins)/e.fXaxis.fNbins),h=Math.floor(f/(e.fXaxis.fNbins*e.fYaxis.fNbins)),g=[...r,{x:p,y:m,z:h}];if(e.children){let r=Object.entries(e.children).flatMap(([r,a])=>{let c=e.getBin(p+1,m+1,h+1),d=a?.[c];if(!d||!(i(t,n*u+(p+m*e.fXaxis.fNbins+h*(e.fXaxis.fNbins*e.fYaxis.fNbins))*l,null)>0))return[];let f=s(d,t+1,Math.abs(o.index),g,r);return r!==`content`&&(f=f.map(e=>({...e,set:r}))),f});if(r.length>0)c.push(...r);else{let r=n*this.maxInstancesPerLayer[t]+(p+m*e.fXaxis.fNbins+h*(e.fXaxis.fNbins*e.fYaxis.fNbins));(a&&a!==`content`?this.matrixCache[t]?.[this.availableSets.indexOf(a)]:this.matrixCache[t]).rendered[r]!==-1&&c.push({index:g,target:o.target,distance:o.distance,set:a,selectedArray:this.selectedArray,instanceId:q(g,this.pointer.origin,this.maxInstancesPerLayer,this.selectedSet),jsrootInstance:J(g,this.pointer.origin,this.selectedSet),range:Y(g,a,this.pointer.origin,this.wireframe,this.selectedSet),origin:this,jsrootObj:e,content:this.getBinContent(e,p,m,h,d?this.selectedArray:`content`),error:this.getBinError(e,p,m,h,d?this.selectedArray:`content`)})}}else c.push({index:g,target:o.target,distance:o.distance,set:a,selectedArray:this.selectedArray,instanceId:q(g,this.pointer.origin,this.maxInstancesPerLayer,this.selectedSet),jsrootInstance:J(g,this.pointer.origin,this.selectedSet),range:Y(g,a,this.pointer.origin,this.wireframe,this.selectedSet),origin:this,object:this.mesh,jsrootObj:e,content:this.getBinContent(e,p,m,h,d?this.selectedArray:`content`),error:this.getBinError(e,p,m,h,d?this.selectedArray:`content`)})}),c.sort((e,t)=>e.distance-t.distance)};if(this.pointer.isOnSet===null)return s(this.pointer.origin,0,0,[],this.pointer.isOnSet);{let e=this.selectedSet.map(e=>s(X(this.pointer.rootObj,this.pointer.parentPath.map(e=>e.bin[0]),e),0,0,[],e)).filter(e=>e.length!==0),t=Math.min(...e.map(e=>e[0].distance));return e.find(e=>e[0].distance===t)??[]}}dispatchSubjectHandler(e){if(!e.event.jsrootInstance){let t=e.event.index.map(e=>({x:e.x-1,y:e.y-1,z:e.z-1})),n=this.pointer.getChildByPosition(J([...t]).slice(0,-1),e.event.set,this.selectedSet);e.event={index:t,set:e.event.set,jsrootInstance:J(t,this.pointer.origin,this.selectedSet),range:Y(t,e.event.set,this.pointer.origin,this.wireframe,this.selectedSet),origin:this,jsrootObj:n,content:this.getBinContent(n,t[0].x+1,t[0].y+1,t[0].z+1,n.fArrays[Object.keys(n.fArrays)[0]].values?this.selectedArray:`content`),error:n.getBinError(t[0].x+1,t[0].y+1,t[0].z+1)}}this.intersectionHandler(e.event,e.event.source)}},Ne=class{plane=void 0;cinemaSub=void 0;position;rotation;scale;id;configSub=void 0;constructor(e,i,a,o,s){let c=new r.PlaneGeometry(o.x,o.y),l=new r.MeshBasicMaterial({color:new r.Color().setHex(16777215),side:r.DoubleSide});this.plane||(this.plane=new r.Mesh(c,l),this.plane.position.set(i.x,i.y,i.z)),e&&this.updateTexture(e),this.id=s,this.position=i,this.rotation=a,this.scale=o,this.cinemaSub=F().getObservable().pipe((0,t.filter)(e=>e.id===this.id||e.id===`*`)).subscribe(e=>{let t=e.obj;(0,n.makeImage)({format:`png`,option:`pE`,object:t,width:1200,height:600}).then(e=>{this.updateTexture(e)})}),this.configSub=L().getObservable().pipe((0,t.filter)(e=>e.target.id.includes(`*`)||e.target.id.includes(this.id))).subscribe(e=>{let t=e.config.environment.canvasPads.filter(e=>e.id===this.id||e.id===`*`);t.length!==0&&(this.position=t[0].limits.position,this.rotation=t[0].limits.rotation,this.scale=t[0].limits.scale,this.updateMesh())})}updateMesh(){this.plane.scale.set(this.scale.x,this.scale.y,this.scale.z),this.plane.position.set(this.position.x,this.position.y,this.position.z);let e=Math.PI/180;this.plane.rotation.set(this.rotation.x*e,this.rotation.y*e,this.rotation.z*e)}updateTexture(e){if(!e){console.warn(`updateTexture called with null/undefined`);return}let t=new r.TextureLoader;if(typeof e==`string`&&(e.startsWith(`data:`)||e.startsWith(`http`)))t.load(e,e=>{this.plane.material.map=e,this.plane.material.needsUpdate=!0},void 0,e=>console.error(`Texture load failed`,e));else if(e instanceof HTMLImageElement){let t=new r.Texture(e);t.needsUpdate=!0,this.plane.material.map=t,this.plane.material.needsUpdate=!0}else console.error(`Unsupported image type passed to updateTexture:`,e)}remove(){this.plane.parent&&(this.plane.parent.remove(this.plane),this.cinemaSub.unsubscribe(),this.configSub.unsubscribe())}getPlane(){return this.plane}},Pe=class extends r.Loader{constructor(e){super(e)}load(e,t,n,i){let a=this,o=new r.FileLoader(this.manager);o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(e,function(e){let n=a.parse(JSON.parse(e));t&&t(n)},n,i)}parse(e){return new Fe(e)}},Fe=class{constructor(e){this.isFont=!0,this.type=`Font`,this.data=e}generateShapes(e,t=100,n=`ltr`){let r=[],i=Ie(e,t,this.data,n);for(let e=0,t=i.length;e<t;e++)r.push(...i[e].toShapes());return r}};function Ie(e,t,n,r){let i=Array.from(e),a=t/n.resolution,o=(n.boundingBox.yMax-n.boundingBox.yMin+n.underlineThickness)*a,s=[],c=0,l=0;(r==`rtl`||r==`tb`)&&i.reverse();for(let e=0;e<i.length;e++){let t=i[e];if(t===`
|
|
86
86
|
`)c=0,l-=o;else{let e=Le(t,a,c,l,n);r==`tb`?(c=0,l+=n.ascender*a):c+=e.offsetX,s.push(e.path)}}return s}function Le(e,t,n,i,a){let o=a.glyphs[e]||a.glyphs[`?`];if(!o){console.error(`THREE.Font: character "`+e+`" does not exists in font family `+a.familyName+`.`);return}let s=new r.ShapePath,c,l,u,d,f,p,m,h;if(o.o){let e=o._cachedOutline||=o.o.split(` `);for(let r=0,a=e.length;r<a;)switch(e[r++]){case`m`:c=e[r++]*t+n,l=e[r++]*t+i,s.moveTo(c,l);break;case`l`:c=e[r++]*t+n,l=e[r++]*t+i,s.lineTo(c,l);break;case`q`:u=e[r++]*t+n,d=e[r++]*t+i,f=e[r++]*t+n,p=e[r++]*t+i,s.quadraticCurveTo(f,p,u,d);break;case`b`:u=e[r++]*t+n,d=e[r++]*t+i,f=e[r++]*t+n,p=e[r++]*t+i,m=e[r++]*t+n,h=e[r++]*t+i,s.bezierCurveTo(f,p,m,h,u,d);break}}return{offsetX:o.ha*t,path:s}}var Re=class{constructor(e,n={}){this.camera=e,this.options={backgroundColor:11184810,textColor:1,titleColor:0,padding:.002,lineHeight:.002,textSize:10,width:.031,...n},this.loader=new Pe,this.queue=new t.Subject;let i=!1,a=null;this.queueSub=this.queue.pipe((0,t.concatMap)(e=>i?(a=e,t.EMPTY):(i=!0,(0,t.from)(this.updateVisualization(e)).pipe((0,t.finalize)(()=>{if(i=!1,a){let e=a;a=null,this.queue.next(e)}}))))).subscribe(),this.group=new r.Group}parseData(e){let t=[];if(e.title&&t.push({text:e.title,isTitle:!0}),e.coords&&Array.isArray(e.coords)&&e.coords.forEach(e=>{Object.entries(e).forEach(([e,n])=>{if(n&&typeof n==`object`&&!(`isColor`in n)){let r=`${e} = [${n.min.toFixed(2)}, ${n.max.toFixed(2)})`;t.push({text:r,isTitle:!1})}})}),e.index&&Array.isArray(e.index)&&e.index.forEach(n=>{let r=`bin = ${e.object.bins[e.instanceId]}`;Object.entries(n).forEach(([e,t])=>{r+=`, ${e}: ${t}`}),t.push({text:r,isTitle:!1})}),e.content!==void 0){let n=Number.isInteger(e.content)?`content = ${e.content}`:`content = ${e.content.toFixed(2)}`;t.push({text:n,isTitle:!1})}if(e.error!==void 0){let n=Number.isInteger(e.error)?`error = ${e.error}`:`error = ${e.error.toFixed(2)}`;t.push({text:n,isTitle:!1})}return t}createBackgroundPanel(e){let{width:t,backgroundColor:n}=this.options;return new r.Mesh(new r.PlaneGeometry(t,e),new r.MeshBasicMaterial({color:n,side:r.DoubleSide}))}async updateVisualization(e){for(e===null&&this.clear();this.group.children.length>0;){let e=this.group.children[0];e.geometry&&e.geometry.dispose(),e.material&&e.material.dispose(),this.group.remove(e)}let t=this.parseData(e);if(t.length===0)return;let{padding:i,lineHeight:a,textSize:o,textColor:s,titleColor:c,width:l}=this.options,u=t.length*a+i*2,d=this.createBackgroundPanel(u);this.group.add(d);let f=u/2-i-a/2;for(let e=0;e<t.length;e++){let r=t[e],u=f-e*a;try{let e=(0,n.create)(`TLatex`);e.fTitle=r.text,e.fTextAlign=12,e.fTextFont=2,e.fTitleFont=2,e.fLabelFont=2,e.fTextColor=r.isTitle?c:s,e.fTextSize=r.isTitle?o+2:o;let t=await(0,n.build3d)(e,`p`,u*100,``,``);t.scale.set(16e-5,16e-5,16e-5),t.position.x=-(l/2)+i,t.position.y=u,t.position.z=.001,this.group.add(t)}catch(e){console.error(`Error creating text line:`,e)}}let p=new r.Vector3(e.point.x,e.point.y,e.point.z);this.camera.worldToLocal(p);let m=new r.Vector3().subVectors(p,this.camera.position).normalize(),h=new r.Vector3().copy(this.camera.position).addScaledVector(m,.1),g=new r.Box3().setFromObject(this.group),_=new r.Vector3;g.getSize(_);let v=_.clone().multiplyScalar(.5);h.add(new r.Vector3(v.x,v.y,0)),this.group.position.copy(h),this.camera.add(this.group)}getGroup(){return this.group}setPosition(e,t,n){this.group.position.set(e,t,n)}setRotation(e,t,n){this.group.rotation.set(e,t,n)}clear(){for(;this.group.children.length>0;){let e=this.group.children[0];e.geometry&&e.geometry.dispose(),e.material&&e.material.dispose(),this.group.remove(e)}}dispose(){for(this.queueSub.unsubscribe();this.group.children.length>0;){let e=this.group.children[0];e.geometry&&e.geometry.dispose(),e.material&&e.material.dispose(),this.group.remove(e)}}},ze=class{histogramGroup=void 0;binInfoComponent=void 0;id=void 0;configSub=void 0;rootObj=void 0;histoSub=void 0;dummyEl=void 0;defaultRaycastHandler=void 0;mouseEvents=[];color=new r.Color;colorTarget=new r.Color(65535);buildPromise=void 0;constructor(e,n,i){this.id=e,this.rootObj=n,this.camera=i,this.histogramGroup=new r.Group,this.dummyEl=document.getElementById(`dummyDiv`+e),this.dummyEl&&document.body.removeChild(this.dummyEl),this.binInfoComponent=new Re(this.camera,{backgroundColor:3556687,textColor:0,titleColor:0}),this.dummyEl=document.createElement(`div`),this.dummyEl.id=`dummyDiv`+e,document.body.appendChild(this.dummyEl),this.configSub=L().getObservable().pipe((0,t.filter)(e=>e.target.id.includes(`*`)||e.target.id.includes(this.id))).subscribe(e=>{this.config={...e.config};let t=this.config.environment.histogramPads.find(e=>e.id===this.id).position;this.histogramGroup.position.set(t.x,t.y,t.z)}),this.sub=x().getObservable().pipe((0,t.filter)(e=>e.target.id.includes(`*`)||e.target.id.includes(this.id))).subscribe(e=>{if(e.flag===`add`)if(e.function)this.addEvent(e.event,e.function);else switch(e.event){case`mousemove`:this.addEvent(e.event,this.mousemoveDefault);break;case`mouseclick`:this.addEvent(e.event,this.mouseClickDefault);break;case`shiftmouseclick`:this.addEvent(e.event,this.shiftMouseClickDefault);break;case`mousedbclick`:this.addEvent(e.event,this.mouseDBClickDefault);break;case`shiftmousedbclick`:this.addEvent(e.event,this.shiftMouseDBClickDefault);break}else if(e.flag===`remove`&&e.function)this.removeEvent(e.event,e.function);else if(e.flag===`remove`)switch(e?.state){case`keydown`:this.keydownEvents=[];break;case`keyup`:this.keyupEvents=[];break;default:this.mouseEvents=this.mouseEvents.filter(t=>t.event!==e.event),this.mousemoveDefault({object:this.getInstancedMesh(),instanceId:null})}else e.flag===`removeAll`&&(this.keydownEvents=[],this.keyupEvents=[],this.mouseEvents=[])}),this.raycastHandler=this.raycastHandler.bind(this),this.mouseClickDefault=this.mouseClickDefault.bind(this),this.mousemoveDefault=this.mousemoveDefault.bind(this),this.shiftMouseClickDefault=this.shiftMouseClickDefault.bind(this),this.mouseDBClickDefault=this.mouseDBClickDefault.bind(this),this.shiftMouseDBClickDefault=this.shiftMouseDBClickDefault.bind(this),this.addEvent(`mouseclick`,this.mouseClickDefault),this.addEvent(`mousemove`,this.mousemoveDefault),this.addEvent(`shiftmouseclick`,this.shiftMouseClickDefault),this.addEvent(`mousedbclick`,this.mouseDBClickDefault),this.addEvent(`shiftmousedbclick`,this.shiftMouseDBClickDefault),this.buildPromise=this.renderWithBuild3d()}updateHistogram(e){this.rootObj=e,this.histogramGroup.clear(),this.buildPromise=this.renderWithBuild3d()}renderWithBuild3d(){return(0,n.build3d)(this.rootObj).then(e=>{let t=this.config.environment.histogramPads.find(e=>e.id===this.id)?.scale,n=new r.Box3().setFromObject(e),i=new r.Vector3;n.getSize(i),e.scale.set(t.x/i.x,t.z/i.y,t.y/i.z),e.rotateX(-Math.PI/2),e.translateZ(-(t.y/2)),this.histogramGroup.add(e);let a=this.getInstancedMesh();a&&(this.defaultRaycastHandler=a.raycast.bind(a),a.raycast=this.raycastHandler.bind(this))}).catch(e=>{let t=this.config.environment.histogramPads.find(e=>e.id===this.id);throw console.log(`JSROOT was not able to build object: `,e,t),{message:e,scale:t?.scale,position:t?.position}})}raycastHandler(e,t){this.defaultRaycastHandler(e,t),setTimeout(()=>{let n=t.filter(e=>e.instanceId!==void 0).sort((e,t)=>e.distance-t.distance)[0];if(!n){this.mouseEvents.filter(e=>e.event===`mousemove`).forEach(e=>e.function({instanceId:void 0,object:this.getInstancedMesh()},this));return}let r=n.object.bins[n.instanceId],i=this.rootObj.fXaxis.fNbins+2,a=this.rootObj.fYaxis.fNbins+2,o={x:r%i,y:Math.floor(r%(i*a)/i),z:Math.floor(r/(i*a))},s=this.getRangeByPosition([o]),c=this.rootObj.fName,l={...n,index:[o],coords:[{...s,bin:r,name:c}],content:this.rootObj.getBinContent(o.x,o.y,o.z),error:this.rootObj.getBinError(o.x,o.y,o.z)};this.mouseEvents.filter(t=>t.event===e._triggerSource).forEach(e=>e.function(l,this)),this.dirtyInstance=n.instanceId},0)}addEvent(e,t){e?.state===`keydown`?this.keydownEvents.push({key:e.key,function:t}):e?.state===`keyup`?this.keyupEvents.push({key:e.key,function:t}):this.mouseEvents.push({event:e,function:t})}removeEvent(e,t){let n=this.mouseEvents.find(e=>e===t);n&&this.mouseEvents.splice(n,1)}mouseClickDefault(e){console.log(`mouseclick default`)}mousemoveDefault(e){if(e.instanceId===this.dirtyInstance)return;let t=e.object;if(this.dirtyInstance!==void 0){t.getColorAt(this.dirtyInstance,this.color);let e=.5;this.color.lerp(this.colorTarget,-e/(1-e)),t.setColorAt(this.dirtyInstance,this.color)}this.dirtyInstance=e.instanceId,t.getColorAt(this.dirtyInstance,this.color),this.color.lerp(this.colorTarget,.5),t.setColorAt(this.dirtyInstance,this.color),t.instanceColor.needsUpdate=!0,this.binInfoComponent.queue.next(e),z().next(e)}shiftMouseClickDefault(e){console.log(`shiftMouseClickDefault`)}mouseDBClickDefault(e){console.log(`mouseDBClickDefault`)}shiftMouseDBClickDefault(e){console.log(`shiftMouseDBClickDefault`)}getInstancedMesh(e=this.histogramGroup){if(!e)return null;if(e.isInstancedMesh===!0)return e;if(e.children&&e.children.length>0)for(let t of e.children){let e=this.getInstancedMesh(t);if(e)return e}return null}getRangeByPosition(e){let t=[`x`,`y`,`z`],n=Number.parseInt(this.rootObj._typename.substring(2,3),10),i={};if(e[0]){for(let r=0;r<n;r++){let n=t[r],a=this.rootObj[`f${n.toUpperCase()}axis`],o=e[0][n];i[n]={min:a.GetBinLowEdge(o),max:a.GetBinCenter(o)*2-a.GetBinLowEdge(o),name:a.fName,title:a.fTitle}}i={...i,color:new r.Color(0)}}return i}remove(){this.histogramGroup.parent.remove(this.histogramGroup),this.dummyEl=document.getElementById(`dummyDiv`+this.id),this.dummyEl&&document.body.removeChild(this.dummyEl),this.configSub.unsubscribe(),this.sub.unsubscribe()}getHistogramMesh(){return this.histogramGroup}};e.CanvasClass=Ne,e.HistogramJsrootClass=ze,e.HistogramPointerClass=$,e.MobileController=ue,e.NdmvrRaycaster=fe,e.THnPainter=Me,e.binInfoSubjectGet=z,e.brokerManagerGet=s,e.canvasSubjectGet=F,e.configSubjectGet=L,e.dispatchSubjectGet=f,e.fetchTFile=de,e.functionSubjectGet=x,e.getCameraComponent=ae,e.histogramSubjectGet=N,e.httpRequest=l,e.initNdmvrAframe=c,e.inputDeviceSubjectGet=h,e.stateSubjectGet=v});
|