@sjcrh/proteinpaint-client 2.63.0 → 2.63.2
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/README.md +9 -7
- package/dist/{2dmaf-70c0b6bb.js → 2dmaf-0cabb4a4.js} +1 -1
- package/dist/{ColorScale-b44d51ef.js → ColorScale-9800a609.js} +1 -1
- package/dist/{DEanalysis-b86d0874.js → DEanalysis-567989ff.js} +1 -1
- package/dist/{Disco-16cd51c0.js → Disco-5d1404ce.js} +1 -1
- package/dist/{Disco.UI-a38a12e6.js → Disco.UI-54228bb6.js} +1 -1
- package/dist/{DragControls-0c173a20.js → DragControls-a05737c2.js} +1 -1
- package/dist/{DziViewer-5c2d68e7.js → DziViewer-3f466d90.js} +2 -2
- package/dist/{FilterRxComp-0e75dd8d.js → FilterRxComp-fc769f34.js} +1 -1
- package/dist/{FilterStateless-ad3df967.js → FilterStateless-8f30f856.js} +1 -1
- package/dist/{HicApp-bcf8330c.js → HicApp-aac413df.js} +1 -1
- package/dist/{OrbitControls-c33cf781.js → OrbitControls-8b7f91ca.js} +1 -1
- package/dist/app-59194db0.js +1 -0
- package/dist/{app-f91922b4.js → app-71453429.js} +1 -1
- package/dist/{app-bfce9bf5.js → app-fb676934.js} +1 -1
- package/dist/app.js +1 -1
- package/dist/{bam-95f36008.js → bam-e7f6baea.js} +1 -1
- package/dist/{barchart-e2af00a8.js → barchart-ef4874c8.js} +1 -1
- package/dist/{barchart.events-272fd122.js → barchart.events-e24facf7.js} +1 -1
- package/dist/{bars.renderer-f0e5af5a.js → bars.renderer-c46d3f44.js} +1 -1
- package/dist/{block-ec76524e.js → block-4f585abe.js} +1 -1
- package/dist/block.lazyload-6f83d057.js +1 -0
- package/dist/{block.legend-f8cad7e4.js → block.legend-cec87c6f.js} +1 -1
- package/dist/{block.mds-20655637.js → block.mds-f5a11c42.js} +1 -1
- package/dist/{block.mds.cnv-5feb86a0.js → block.mds.cnv-25423c1e.js} +1 -1
- package/dist/{block.mds.expressionrank-c7043f35.js → block.mds.expressionrank-fc1996d5.js} +1 -1
- package/dist/{block.mds.expressionstat-4bf457f3.js → block.mds.expressionstat-45b6bf47.js} +1 -1
- package/dist/{block.mds.geneboxplot-132e5fe6.js → block.mds.geneboxplot-037df46d.js} +1 -1
- package/dist/{block.mds.junction-1f9810df.js → block.mds.junction-00161de6.js} +1 -1
- package/dist/{block.mds.svcnv-094c416f.js → block.mds.svcnv-0c257af4.js} +1 -1
- package/dist/{block.mds.svcnv.share-bb976e02.js → block.mds.svcnv.share-c0b9dfad.js} +1 -1
- package/dist/{block.mds2-7045e32c.js → block.mds2-9009f8d8.js} +1 -1
- package/dist/{block.svg-d8d76ba7.js → block.svg-86bbfcb0.js} +1 -1
- package/dist/{block.tk.aicheck-317d04bd.js → block.tk.aicheck-a5697794.js} +1 -1
- package/dist/{block.tk.ase-d1577ec1.js → block.tk.ase-ad1be47c.js} +1 -1
- package/dist/{block.tk.bam-3cdc13a0.js → block.tk.bam-14339d16.js} +1 -1
- package/dist/{block.tk.bedgraphdot-5304e06c.js → block.tk.bedgraphdot-efe19e56.js} +1 -1
- package/dist/{block.tk.bigwig.ui-0c96dce5.js → block.tk.bigwig.ui-a92f286b.js} +1 -1
- package/dist/{block.tk.hicstraw-39d89269.js → block.tk.hicstraw-57fbbe61.js} +1 -1
- package/dist/{block.tk.junction-b45b3a95.js → block.tk.junction-64c39cd5.js} +1 -1
- package/dist/{block.tk.junction.textmatrixui-6ec019e1.js → block.tk.junction.textmatrixui-09e5e02f.js} +1 -1
- package/dist/{block.tk.ld-5c54e58b.js → block.tk.ld-f681d099.js} +1 -1
- package/dist/{block.tk.menu-30a2c3a5.js → block.tk.menu-2563364c.js} +1 -1
- package/dist/{block.tk.pgv-7ff2dfaf.js → block.tk.pgv-9dfc00c0.js} +1 -1
- package/dist/{boxplot-7de25274.js → boxplot-a2e1ace0.js} +1 -1
- package/dist/brainImaging-21701238.js +1 -0
- package/dist/{brush-db0ed33a.js → brush-bb4566a3.js} +1 -1
- package/dist/{categorical-bc309399.js → categorical-a00f4ffc.js} +1 -1
- package/dist/{condition-f0eb2343.js → condition-2034db37.js} +1 -1
- package/dist/{controls-8d4972c8.js → controls-0467d2ec.js} +1 -1
- package/dist/{controls.btns-bad9e4cf.js → controls.btns-ad7b28a2.js} +1 -1
- package/dist/{controls.config-e0f394cb.js → controls.config-6cf816fb.js} +1 -1
- package/dist/{controls.divide-d8ac5a9b.js → controls.divide-3c0d52d7.js} +1 -1
- package/dist/{controls.overlay-3ac8773d.js → controls.overlay-3a55c2ec.js} +1 -1
- package/dist/{controls.term1-008f4be4.js → controls.term1-59f4cd60.js} +1 -1
- package/dist/cuminc-8d21132b.js +1 -0
- package/dist/{customdata.inputui-58cd9b32.js → customdata.inputui-40ba6d7f.js} +1 -1
- package/dist/{dataDownload-91da6dd6.js → dataDownload-bfa92dad.js} +1 -1
- package/dist/{databrowser.ui-c50862e4.js → databrowser.ui-4799f04d.js} +1 -1
- package/dist/{density-7c3f91eb.js → density-4c2b53f6.js} +1 -1
- package/dist/{dictionary-48a38837.js → dictionary-89e860ee.js} +1 -1
- package/dist/{drag-c354e2c6.js → drag-88d451b4.js} +1 -1
- package/dist/{e2pca-3bba91fa.js → e2pca-8a3f2566.js} +1 -1
- package/dist/{ep-144d8973.js → ep-5399c5cc.js} +1 -1
- package/dist/{fusion.parse-ae1253f4.js → fusion.parse-fc25e5bd.js} +1 -1
- package/dist/{geneExpClustering-96d09008.js → geneExpClustering-a916ebda.js} +1 -1
- package/dist/{geneExpression-d6494fd3.js → geneExpression-501e95c0.js} +1 -1
- package/dist/{geneExpression-9ca2da4f.js → geneExpression-9047481a.js} +1 -1
- package/dist/{geneExpression-be9b5da2.js → geneExpression-da4b50f0.js} +1 -1
- package/dist/{geneORA-85850143.js → geneORA-ffb2497e.js} +1 -1
- package/dist/{geneVariant-3df05e0c.js → geneVariant-7ab521d6.js} +1 -1
- package/dist/{geneVariant-3d674865.js → geneVariant-d79431a2.js} +1 -1
- package/dist/{genefusion.ui-3e2a3a73.js → genefusion.ui-3ce190c7.js} +1 -1
- package/dist/{geneset-3b761b2c.js → geneset-3522bcda.js} +1 -1
- package/dist/{genomeBrowser-2105a98f.js → genomeBrowser-9b72eb22.js} +1 -1
- package/dist/{genomeBrowser.controls-f9b9bf42.js → genomeBrowser.controls-bef8bf99.js} +1 -1
- package/dist/{groupsetting-4901d033.js → groupsetting-574ad150.js} +1 -1
- package/dist/{hierCluster-a7ff7f5a.js → hierCluster-3b14b2b3.js} +1 -1
- package/dist/{hierCluster.config-3d124abf.js → hierCluster.config-f8686a30.js} +1 -1
- package/dist/{hierCluster.interactivity-3463cc0b.js → hierCluster.interactivity-3b5f1e81.js} +1 -1
- package/dist/{hierCluster.renderers-668d0075.js → hierCluster.renderers-9f9a7cad.js} +1 -1
- package/dist/{html.legend-3e428f9e.js → html.legend-ef8066dd.js} +1 -1
- package/dist/{imagePlot-6d89200c.js → imagePlot-095b9a92.js} +1 -1
- package/dist/{lasso-393c1570.js → lasso-ef63631b.js} +1 -1
- package/dist/{launch.adhoc-9c59874e.js → launch.adhoc-1b356f97.js} +1 -1
- package/dist/{legacyDataset-26ead9cc.js → legacyDataset-056e9d4c.js} +1 -1
- package/dist/{log-4d74231e.js → log-ca1e2a74.js} +1 -1
- package/dist/{lollipop-59f65024.js → lollipop-6ad9ec3c.js} +1 -1
- package/dist/{maf-72e5b7da.js → maf-dfada1c8.js} +1 -1
- package/dist/{maftimeline-ed8aaae8.js → maftimeline-1b715a01.js} +1 -1
- package/dist/{matrix-3d09a31f.js → matrix-3fae58f8.js} +1 -1
- package/dist/matrix.cells-3620eb3a.js +1 -0
- package/dist/{matrix.cluster-acdfc6a7.js → matrix.cluster-15b8a865.js} +1 -1
- package/dist/{matrix.config-cd01ebbd.js → matrix.config-8247bea5.js} +1 -1
- package/dist/{matrix.controls-86eb8d5c.js → matrix.controls-dea65894.js} +1 -1
- package/dist/{matrix.data-e2d7ac16.js → matrix.data-121a1a8c.js} +1 -1
- package/dist/{matrix.dom-e5f91cc0.js → matrix.dom-83c5fa39.js} +1 -1
- package/dist/{matrix.groups-f1969b5c.js → matrix.groups-2e1202ef.js} +1 -1
- package/dist/{matrix.interactivity-92bc8332.js → matrix.interactivity-2b076155.js} +1 -1
- package/dist/{matrix.layout-29a8f334.js → matrix.layout-8dc54c05.js} +1 -1
- package/dist/{matrix.legend-8c28039e.js → matrix.legend-e0078739.js} +1 -1
- package/dist/matrix.renderers-0c8eddc9.js +1 -0
- package/dist/{matrix.serieses-e079f04a.js → matrix.serieses-2898da6b.js} +1 -1
- package/dist/{matrix.sort-e1f83454.js → matrix.sort-249d4a35.js} +1 -1
- package/dist/{matrix.sorterUi-2025f39d.js → matrix.sorterUi-d26208c8.js} +1 -1
- package/dist/{mavb-37fffd68.js → mavb-9a6fa2e9.js} +1 -1
- package/dist/{mds.fimo-68f0eaf5.js → mds.fimo-ce97371c.js} +1 -1
- package/dist/{mds.samplescatterplot-362f3591.js → mds.samplescatterplot-a54b9e93.js} +1 -1
- package/dist/{mds.survivalplot-f5bda05a.js → mds.survivalplot-c5093f73.js} +1 -1
- package/dist/{mdsjsonform-7f0b6cc7.js → mdsjsonform-09b4e1cb.js} +1 -1
- package/dist/metaboliteIntensity-eeb5ad12.js +1 -0
- package/dist/niceNumLabels-ddb76164.js +1 -0
- package/dist/{nodrag-777a34a5.js → nodrag-bed2488c.js} +1 -1
- package/dist/{numeric-2eb8c25b.js → numeric-d5536b1c.js} +1 -1
- package/dist/numeric.binary-d67da945.js +1 -0
- package/dist/numeric.continuous-9a0c88bc.js +1 -0
- package/dist/numeric.discrete-921f7097.js +1 -0
- package/dist/numeric.spline-649308d5.js +1 -0
- package/dist/{numeric.toggle-5316211b.js → numeric.toggle-52789fd2.js} +1 -1
- package/dist/{oncomatrix-cd9fa01b.js → oncomatrix-6950c48c.js} +1 -1
- package/dist/{parseData-1bfa9946.js → parseData-480d1ff3.js} +1 -1
- package/dist/{plot.2dvaf-1ed153c1.js → plot.2dvaf-1ecc4bbc.js} +1 -1
- package/dist/plot.app-c841507a.js +1 -0
- package/dist/{plot.barplot-61742e94.js → plot.barplot-24140b0f.js} +1 -1
- package/dist/{plot.boxplot-fe966ac3.js → plot.boxplot-87fe8ab2.js} +1 -1
- package/dist/{plot.brainImaging-d2c23bb7.js → plot.brainImaging-325ebded.js} +1 -1
- package/dist/{plot.disco-70d493f4.js → plot.disco-621d1b8e.js} +1 -1
- package/dist/{plot.dzi-14e6fdc4.js → plot.dzi-3a7e478e.js} +1 -1
- package/dist/{plot.ssgq-9d364d41.js → plot.ssgq-1949c207.js} +1 -1
- package/dist/{plot.vaf2cov-4d28015b.js → plot.vaf2cov-d03c6409.js} +1 -1
- package/dist/{profileBarchart-c104f8e2.js → profileBarchart-11755d7c.js} +1 -1
- package/dist/{profileHome-a555583d.js → profileHome-9c5e266b.js} +1 -1
- package/dist/{profilePlot-5ce5b6a0.js → profilePlot-8ee3034a.js} +1 -1
- package/dist/{profilePolar-610213d4.js → profilePolar-9fe70c32.js} +1 -1
- package/dist/{profileRadar-fddb18f7.js → profileRadar-0e744181.js} +1 -1
- package/dist/{profileRadarFacility-2c2db1dd.js → profileRadarFacility-102544c5.js} +1 -1
- package/dist/{recover-a08c8d01.js → recover-b1ec4fed.js} +1 -1
- package/dist/{regression.inputs-5718cf72.js → regression.inputs-ad548745.js} +1 -1
- package/dist/{regression.inputs.values.table-d587c1cf.js → regression.inputs.values.table-1618447a.js} +1 -1
- package/dist/{regression.results-748024be.js → regression.results-25008028.js} +1 -1
- package/dist/{renderPvalueTable-c435aefd.js → renderPvalueTable-46056189.js} +1 -1
- package/dist/sampleScatter-47dd82cb.js +1 -0
- package/dist/{sampleScatter.interactivity-e9c30652.js → sampleScatter.interactivity-cfa3451d.js} +1 -1
- package/dist/{sampleScatter.rendererThree-3e6c032e.js → sampleScatter.rendererThree-c5321d24.js} +2 -2
- package/dist/{sampleView-d6a91293.js → sampleView-30b97c7d.js} +1 -1
- package/dist/{samplelst-821ec148.js → samplelst-2bdc1b9d.js} +1 -1
- package/dist/{samplematrix-7aa0a780.js → samplematrix-4f0ec523.js} +1 -1
- package/dist/{scatter-2e2c76f4.js → scatter-8a337eeb.js} +1 -1
- package/dist/{selectGenomeWithTklst-51cd21a4.js → selectGenomeWithTklst-895106fb.js} +1 -1
- package/dist/{singleCellPlot-c7347a27.js → singleCellPlot-360eaec6.js} +1 -1
- package/dist/{singlecell-a668bb17.js → singlecell-29c1cbb1.js} +1 -1
- package/dist/{singlecell-7c851ef8.js → singlecell-75f8af89.js} +1 -1
- package/dist/{snplocus-fe6f4ba1.js → snplocus-0cafa73c.js} +1 -1
- package/dist/{snplst-751cea95.js → snplst-2284d5ce.js} +1 -1
- package/dist/{spliceevent.a53ss.diagram-b157f95d.js → spliceevent.a53ss.diagram-44ccabf9.js} +1 -1
- package/dist/{spliceevent.exonskip.diagram-071a3467.js → spliceevent.exonskip.diagram-c8d1bdf0.js} +1 -1
- package/dist/spliceevent.exonskip.getdefault-9fe16119.js +1 -0
- package/dist/{spliceevent.noeventdiagram-1c731f35.js → spliceevent.noeventdiagram-5e244090.js} +1 -1
- package/dist/{spliceevent.phrase-7a3bfb00.js → spliceevent.phrase-186eb050.js} +1 -1
- package/dist/{stattable-a7713026.js → stattable-886f7dad.js} +1 -1
- package/dist/{style.gdc-40ec2784.js → style.gdc-4ac9b96b.js} +1 -1
- package/dist/{summary-592d8f81.js → summary-ee2045a5.js} +1 -1
- package/dist/{sunburst-452df940.js → sunburst-bbff8818.js} +1 -1
- package/dist/survival-04e279f8.js +1 -0
- package/dist/{survival-450b6df4.js → survival-d7bd3c6b.js} +1 -1
- package/dist/{svg.download-56529955.js → svg.download-54c99186.js} +1 -1
- package/dist/{svg.legend-c82b153f.js → svg.legend-28652faa.js} +1 -1
- package/dist/{svgraph-3c5cd8d2.js → svgraph-a12d89da.js} +1 -1
- package/dist/{svmr-3dd531ef.js → svmr-248055c8.js} +1 -1
- package/dist/{table-d6c411fd.js → table-1dae543a.js} +1 -1
- package/dist/{table-bf604c50.js → table-b4a61573.js} +1 -1
- package/dist/{termInfo-96285f4a.js → termInfo-4c759483.js} +1 -1
- package/dist/{termsetting-9a7511e6.js → termsetting-636d2271.js} +1 -1
- package/dist/{tk-6a8e5bb0.js → tk-741d4674.js} +1 -1
- package/dist/{tp.ui-221efed6.js → tp.ui-23151bb1.js} +1 -1
- package/dist/{tvs.density-9fdae0cc.js → tvs.density-9fe0c7fd.js} +1 -1
- package/dist/{tvs.geneVariant-149e25b7.js → tvs.geneVariant-1b179327.js} +1 -1
- package/dist/tvs.numeric-b4cfc975.js +1 -0
- package/dist/{tvs.samplelst-a38e9c2b.js → tvs.samplelst-681358bc.js} +1 -1
- package/dist/{uiUtils-a6de7f14.js → uiUtils-74700a01.js} +1 -1
- package/dist/{variantBrowser-05375469.js → variantBrowser-910b4bcd.js} +1 -1
- package/dist/{vcf-58904308.js → vcf-16ba1e06.js} +1 -1
- package/dist/{violin-c1b78717.js → violin-a41b2e2b.js} +1 -1
- package/dist/{violin.interactivity-534d6993.js → violin.interactivity-bcf0ccc2.js} +1 -1
- package/dist/{violin.renderer-16540fb8.js → violin.renderer-149310eb.js} +1 -1
- package/dist/{violinRenderer-688abcb2.js → violinRenderer-71c9f3ab.js} +1 -1
- package/dist/{viridis-d3cf2713.js → viridis-81de7bcd.js} +1 -1
- package/dist/{y-2d48b9e4.js → y-76c7da8c.js} +1 -1
- package/dist/{zoom-2d4ede33.js → zoom-a40839cf.js} +1 -1
- package/package.json +7 -7
- package/dist/app-de19f41c.js +0 -1
- package/dist/block.lazyload-ebd949e4.js +0 -1
- package/dist/brainImaging-007edaa3.js +0 -1
- package/dist/cuminc-72257faf.js +0 -1
- package/dist/matrix.cells-a5157233.js +0 -1
- package/dist/matrix.renderers-3b8dfd04.js +0 -1
- package/dist/metaboliteIntensity-512257f3.js +0 -1
- package/dist/niceNumLabels-8fdc6507.js +0 -1
- package/dist/numeric.binary-0a3b17d2.js +0 -1
- package/dist/numeric.continuous-f77038de.js +0 -1
- package/dist/numeric.discrete-b977e88f.js +0 -1
- package/dist/numeric.spline-d64b1abe.js +0 -1
- package/dist/plot.app-91a1d78d.js +0 -1
- package/dist/sampleScatter-031f47de.js +0 -1
- package/dist/spliceevent.exonskip.getdefault-93feb627.js +0 -1
- package/dist/survival-6a4c4f12.js +0 -1
- package/dist/tvs.numeric-f9ce58bc.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{bP as t,ac as e,l as n,b8 as s}from"./app-f91922b4.js";import{a as r}from"./axisstyle-fac7f76b.js";import{C as o}from"./ColorScale-b44d51ef.js";import{c as i}from"./axis-6cb4f314.js";import{l as a}from"./log-4d74231e.js";function p({bp:t,g:e,color:n,scale:s,rowheight:r,labpad:o}){if(t.label){e.append("text").attr("font-family","Arial").attr("text-anchor","end").attr("dominant-baseline","central").attr("fill",n).attr("x",-o).attr("y",r/2).attr("font-size",Math.min(15,r)).text(t.label)}if(t.w1!=undefined){const o=s(t.w1);const i=s(t.w2);const a=s(t.p25);const p=s(t.p50);const l=s(t.p75);t.hline=e.append("line").attr("stroke",n).attr("shape-rendering","crispEdges").attr("x1",o).attr("x2",i).attr("y1",r/2).attr("y2",r/2);t.linew1=e.append("line").attr("stroke",n).attr("shape-rendering","crispEdges").attr("x1",o).attr("x2",o).attr("y1",0).attr("y2",r);t.linew2=e.append("line").attr("stroke",n).attr("shape-rendering","crispEdges").attr("x1",i).attr("x2",i).attr("y1",0).attr("y2",r);t.box=e.append("rect").attr("fill","white").attr("stroke",n).attr("shape-rendering","crispEdges").attr("x",a).attr("y",0).attr("width",l-a).attr("height",r);t.linep50=e.append("line").attr("stroke",n).attr("shape-rendering","crispEdges").attr("x1",p).attr("x2",p).attr("y1",0).attr("y2",r)}for(const o of t.out){e.append("circle").attr("stroke",n).attr("fill","white").attr("fill-opacity",0).attr("cx",s(o.value)).attr("cy",r/2).attr("r",r/3)}}function l(t,e,n,s){const r=[];if(Array.isArray(t)){for(const o of t){if(o.namekey=="regulomedb"){if(typeof e.chr=="string"&&e.pos!==undefined&&Number.isInteger(e.pos)){const t=`${e.chr}%3A${e.pos}-${e.pos+1}`;r.push(`<a href="${o.base}regions=${t}&genome=${s=="hg38"?"GRCh38":s}" target="_blank">${o.linkText}</a>`)}continue}c(o,e,n,r)}}else{c(t,e,n,r)}return r}function c(t,e,n,s){const r=e[t.namekey];if(r==undefined)return;const o=t.base+r;if(t.shownSeparately){s.push(`<a href="${o}" target="_blank">${t.linkText||r}</a>`);return}n.html(`<a href="${o}" target="_blank">${n.html()}</a>`)}const d="NA";const f="#126e08";const m=f;class u{constructor(t){this.opts=t;this.app=t.app;this.parent=t.parent;this.type="regression";g(this);const e=this.opts.holder;e.append("div").style("margin-top","10px").style("padding-top","20px").style("font-size","1.2em").style("opacity",.3).html("Results");this.dom={holder:e,err_div:e.append("div"),snplocusBlockDiv:e.append("div"),oneSetResultDiv:e.append("div").style("margin","10px")}}async main(){try{this.parent.inputs.dom.submitBtn.text("Running...");this.config=this.parent.config;this.state=this.parent.state;if(!this.state.formIsComplete||this.parent.inputs.hasError||this.config.hasUnsubmittedEdits&&!this.hasUnsubmittedEdits_nullify_singleuse){this.dom.holder.style("display","none");return}delete this.hasUnsubmittedEdits_nullify_singleuse;if(this.snplocusBlock){this.snplocusBlock.cloakOn()}const t=await this.app.vocabApi.getRegressionData(this.getDataRequestOpts());if(t.error)throw t.error;this.dom.err_div.style("display","none");this.dom.oneSetResultDiv.selectAll("*").remove();this.dom.holder.style("display","block");await this.displayResult(t);const e=this.dom.holder.node().getBoundingClientRect().top+window.scrollY;const n=document.querySelector(".sjpp-nav").getBoundingClientRect().height;window.scroll({behavior:"smooth",top:e-n})}catch(t){this.hasError=true;this.dom.holder.style("display","block");this.dom.err_div.style("display","block");e(this.dom.err_div,"Error: "+(t.error||t));this.parent.inputs.dom.submitBtn.property("disabled",true);console.error(t)}}getDataRequestOpts(){const t=this.config;const e={regressionType:t.regressionType,outcome:t.outcome,independent:t.independent};e.filter=this.parent.filter;return e}getIndependentInput(t){for(const e of this.parent.inputs.independent.inputLst){if(!e.term)continue;if(e.term.term.id==t)return e;if(e.term.term&&e.term.term.snps){for(const n of e.term.term.snps){if(n.snpid==t){const s={id:t,q:{geneticModel:e.term.q.geneticModel},term:{id:t,name:t},effectAllele:e.term.q.snp2effAle[t]};if(e.term.q.snp2refGrp){s.refGrp=e.term.q.snp2refGrp[t]}if(n.mlst){const r=n.mlst.find((n=>n.alt==e.term.q.snp2effAle[t]));if(r){s.term.name=r.mname}else{s.term.name=n.mlst[0].mname}}return{term:s}}}}}return{term:{id:t,q:{},term:{name:t}}}}}function g(t){t.displayResult=async e=>{const n=t.parent.inputs.independent.inputLst.find((t=>t.term&&t.term.term.type=="snplocus"));if(n){if(!t.snplocusBlock){t.dom.snplocusBlockDiv.append("div").style("margin-top","30px").style("opacity",.3).text("Click on a variant within the browser to view its regression results");t.snplocusBlock=await w(t,n,e.resultLst)}else{await v(t,n,e.resultLst)}return}delete t.snplocusBlock;t.dom.snplocusBlockDiv.selectAll("*").remove();if(!e.resultLst[0]||!e.resultLst[0].data)throw"result is not [ {data:{}} ]";t.displayResult_oneset(e.resultLst[0].data)};t.displayResult_oneset=e=>{t.dom.oneSetResultDiv.selectAll("*").remove();t.dom.LDresultDiv=t.dom.oneSetResultDiv.append("div");t.mayshow_warn(e);if(e.sampleSize)t.newDiv("Sample size:",e.sampleSize);if(e.eventCnt)t.newDiv("Number of events:",e.eventCnt);t.mayshow_headerRow(e);t.mayshow_splinePlots(e);t.mayshow_residuals(e);t.mayshow_coefficients(e);t.mayshow_totalSnpEffect(e);t.mayshow_type3(e);t.mayshow_tests(e);t.mayshow_other(e);t.mayshow_fisher(e);t.mayshow_wilcoxon(e);t.mayshow_cuminc(e)};t.newDiv=(e,n,s)=>{const r=t.dom.oneSetResultDiv.append("div").style("margin","20px 0px 10px 0px").attr("name",e);const o=r.append("div");o.append("span").style("text-decoration","underline").text(e);if(n){o.append("span").html(n).style("margin-left","5px")}return s?o:r.append("div").style("margin-left","20px")};t.mayshow_warn=e=>{if(!e.warnings)return;const n=t.newDiv("Warnings");const s=new Set(e.warnings);for(const t of s){n.append("p").style("margin","5px").text(t)}};t.mayshow_headerRow=e=>{if(!e.headerRow)return;const n=e.headerRow.k;const s=e.headerRow.v;const r=t.parent.inputs.independent.inputLst.find((t=>t.term&&t.term.term.type=="snplocus"));if(r){const e=r.term.term.snps.find((t=>t.snpid==s.snpid));const o=e.mlst[0];o.chr=e.chr;const i=t.newDiv(n,null,true);const a=i.append("span").text(`${o.chr}:${o.pos+1} ${o.ref&&o.alt?o.ref+">"+o.alt:""}`).style("margin-left","5px");const p=t.app.vocabApi.termdbConfig.urlTemplates?.ssm||t.app.vocabApi.termdbConfig.queries?.snvindel?.ssmUrl;if(p){const e=l(p,o,a,t.parent.genomeObj.name);if(e?.length){i.append("span").style("margin-left","10px").html(e.join(" "))}}let c;const d=`Genotypes: ${s.gtcounts.join(", ")}`;if(s.monomorphic){c=[d]}else{const t=`Effect allele: ${s.effAle}`;const e=`Allele frequency: ${s.af}`;c=[t,e,d]}i.append("span").html(` | ${c.join(" | ")}`)}else{t.newDiv(n,s)}};t.mayshow_splinePlots=e=>{if(!e.splinePlots)return;const n=t.newDiv("Cubic spline plots");for(const t of e.splinePlots){n.append("img").attr("src",t.src).style("width",t.size.width).style("height",t.size.height)}};t.mayshow_residuals=e=>{if(!e.residuals)return;const n=t.newDiv(e.residuals.label);const s=n.append("table").style("border-spacing","8px").attr("name","sjpp-residuals-table");const r=s.append("tr").style("opacity",.4);const o=s.append("tr");for(let t=0;t<e.residuals.header.length;t++){r.append("td").text(e.residuals.header[t]);o.append("td").text(e.residuals.rows[t])}};t.mayshow_cuminc=async e=>{if(!e.cuminc)return;const n=t.newDiv("Cumulative incidence test:");const s=await import("./cuminc-72257faf.js");const r=new s.Cuminc({holder:n,config:{term:t.config.outcome,term2:{term:{name:"Variant",values:{1:{key:1,label:"Has minor allele"},2:{key:2,label:"No minor allele"}}}}}});if(e.cuminc.ci_data){r.main(e.cuminc.ci_data)}else{n.append("div").style("margin","20px").text(e.cuminc.msg)}};t.mayshow_wilcoxon=e=>{if(!e.wilcoxon)return;const s=t.newDiv("Wilcoxon rank sum test:","p-value = "+e.wilcoxon.pvalue);if(e.wilcoxon.boxplots){const o=e.wilcoxon.boxplots;const a=20,l=400,c=160,d=40,f=20,u=10;const g=n().domain([o.minv,o.maxv]).range([0,l]);const h=s.append("svg").style("margin-top","10px").attr("width",c+f+l+10).attr("height",u*3+a*2+d);const y=h.append("g").attr("transform",`translate(${c+f},${u})`);p({g:y.append("g"),bp:o.hasEff,scale:g,rowheight:a,color:m,labpad:f});p({g:y.append("g").attr("transform",`translate(0,${a+u})`),bp:o.noEff,scale:g,rowheight:a,color:m,labpad:f});{const e=y.append("g").attr("transform",`translate(0,${a*2+u*2})`);const n=i().scale(g);r({axis:e.call(n),color:m,showline:true});e.append("text").text(t.config.outcome.term.name).attr("font-size",15).attr("x",l/2).attr("y",d-5).attr("text-anchor","middle").attr("fill",m)}}};t.mayshow_fisher=e=>{if(!e.fisher)return;const n=t.newDiv(e.fisher.isChi?"Chi-square test:":"Fisher's exact test:","p-value = "+e.fisher.pvalue);const s=n.append("table").style("margin","20px").style("border-spacing","5px").style("border-collapse","separate");for(const t of e.fisher.rows){const e=s.append("tr");for(const n of t){e.append("td").text(n)}}};t.mayshow_coefficients=e=>{if(!e.coefficients)return;const n=t.newDiv(e.coefficients.label);const s=n.append("table").style("border-spacing","0px").attr("data-testid","sjpp_regression_resultCoefficientTable");{const t=s.append("tr").style("opacity",.4);e.coefficients.header.forEach(((e,n)=>{t.append("td").text(e).style("padding","8px");if(n===1)t.append("td")}))}if(t.config.regressionType!="cox"){const t=s.append("tr").style("background","#eee");e.coefficients.intercept.forEach(((e,n)=>{t.append("td").text(e).style("padding","8px");if(n===1)t.append("td")}))}const r=t.getForestPlotter(e.coefficients.terms,e.coefficients.interactions);let o=t.config.regressionType=="cox"?1:0;for(const n in e.coefficients.terms){const i=e.coefficients.terms[n];const a=t.getIndependentInput(n).term;let p=s.append("tr").style("background",o++%2?"#eee":"none");const l=p.append("td").style("padding","8px");y(a,l);if(i.fields){{const t=p.append("td").style("padding","8px");N(t,a)}r(p.append("td"),i.fields);for(const t of i.fields){p.append("td").text(t).style("padding","8px")}}else if(i.categories){const e=[];const c=t.getIndependentInput(n);if(c.orderedLabels){for(const t of c.orderedLabels){if(i.categories[t])e.push(t)}}for(const t in i.categories){if(!e.includes(t))e.push(t)}l.attr("rowspan",e.length).style("vertical-align","top");let d=true;for(const t of e){if(d){d=false}else{p=s.append("tr").style("background",o++%2?"#eee":"none")}const e=p.append("td").style("padding","8px");N(e,a,t);r(p.append("td"),i.categories[t]);for(const e of i.categories[t]){p.append("td").text(e).style("padding","8px")}}}else{p.append("td").text("ERROR: no .fields[] or .categories{}")}}for(const n of e.coefficients.interactions){const e=s.append("tr").style("background",o++%2?"#eee":"none");const i=t.getIndependentInput(n.term1).term;const a=t.getIndependentInput(n.term2).term;{const t=e.append("td").style("padding","8px");h(t.append("div"),i?i.term.name+" : ":n.term1+" : ");h(t.append("div"),a?a.term.name:n.term2)}{const t=e.append("td").style("padding","8px");N(t.append("div"),i,n.category1);N(t.append("div"),a,n.category2)}r(e.append("td"),n.lst);for(const t of n.lst){e.append("td").text(t).style("padding","8px")}}const i=s.append("tr");i.append("td");i.append("td");r(i.append("td"));for(const t of e.coefficients.header)i.append("td")};t.mayshow_totalSnpEffect=e=>{if(!e.totalSnpEffect)return;const n=t.newDiv(e.totalSnpEffect.label);const s=n.append("table").style("border-spacing","0px");{const t=s.append("tr").style("opacity",.4);for(const n of e.totalSnpEffect.header){t.append("td").text(n).style("padding","8px")}}const r=s.append("tr").style("background","#eee");for(const t of e.totalSnpEffect.lst){r.append("td").text(t).style("padding","8px")}const o=t.getIndependentInput(e.totalSnpEffect.snp).term;const i=e.totalSnpEffect.interactions.map((e=>({t1:t.getIndependentInput(e.term1).term,t2:t.getIndependentInput(e.term2).term})));const a=`Total: total effect of removing the snp (${o.term.name}) and its interactions (${i.map((t=>t.t1.term.name+" : "+t.t2.term.name)).join(" ; ")}) from the model`;n.append("div").style("margin","20px 0px 20px 10px").style("font-size",".8em").style("text-align","left").style("color","#999").text(a)};t.mayshow_type3=e=>{if(!e.type3)return;const n=t.newDiv(e.type3.label);const s=n.append("table").style("border-spacing","0px");{const t=s.append("tr").style("opacity",.4);for(const n of e.type3.header){t.append("td").text(n).style("padding","8px")}}if(t.config.regressionType!="cox"){const t=s.append("tr").style("background","#eee");for(const n of e.type3.intercept){t.append("td").text(n).style("padding","8px")}}let r=t.config.regressionType=="cox"?1:0;for(const n in e.type3.terms){const o=e.type3.terms[n];const i=t.getIndependentInput(n).term;let a=s.append("tr").style("background",r++%2?"#eee":"none");const p=a.append("td").style("padding","8px");h(p,i.term.name);for(const t of o){a.append("td").text(t).style("padding","8px")}}for(const n of e.type3.interactions){const e=s.append("tr").style("background",r++%2?"#eee":"none");const o=t.getIndependentInput(n.term1).term;const i=t.getIndependentInput(n.term2).term;const a=e.append("td").style("padding","8px");h(a.append("div"),o.term.name+" : ");h(a.append("div"),i.term.name);for(const t of n.lst){e.append("td").text(t).style("padding","8px")}}};t.mayshow_tests=e=>{if(!e.tests)return;const n=t.newDiv(e.tests.label);const s=n.append("table").style("border-spacing","0px");const r=s.append("tr").style("opacity",.4);for(const t of e.tests.header){r.append("td").text(t).style("padding","8px")}let o=0;for(const t of e.tests.rows){const e=s.append("tr").style("background",o++%2?"none":"#eee");for(const n of t){e.append("td").text(n).style("padding","8px")}}};t.mayshow_other=e=>{if(!e.other)return;const n=t.newDiv(e.other.label);const s=n.append("table").style("border-spacing","8px");for(let t=0;t<e.other.header.length;t++){const n=s.append("tr");n.append("td").style("opacity",.4).text(e.other.header[t]);n.append("td").text(e.other.rows[t])}};t.getForestPlotter=(e,s)=>{let o,p,l,c,d,m,u;if(t.config.regressionType=="linear"){o=0;p=1;l=2;c="Beta value";d=0;m=null;u=null}else if(t.config.regressionType=="logistic"){o=0;p=1;l=2;c="Odds ratio";d=1;m=.1;u=10}else if(t.config.regressionType=="cox"){o=0;p=1;l=2;c="Hazard ratio";d=1;m=.1;u=10}else{throw"unknown regressionType"}const g=[];for(const t in e){const n=e[t];if(n.fields){b(n.fields)}else{for(const t in n.categories){b(n.categories[t])}}}for(const t of s){b(t.lst)}if(g.length==0){return()=>{}}g.sort(((t,e)=>t-e));if(m==null){m=g[0];u=g[g.length-1]}const h=150;const y=20;const x=10,w=10;const v=k(g);return(e,n)=>{if(!v){return}const s=e.append("svg").attr("width",h+x+w).attr("height",y);const a=s.append("g").attr("transform","translate("+x+",0)");if(!n){const e=t.config.regressionType=="logistic"?".1r":undefined;const n=i().ticks(4,e).scale(v);r({axis:a.call(n),color:f,showline:true});const o=12;a.append("text").attr("fill",f).text(c).attr("x",h/2).attr("y",y+o);s.attr("height",y+o);return}{const t=v(d);a.append("line").attr("x1",t).attr("y1",0).attr("x2",t).attr("y2",y).attr("stroke","#ccc")}const g=Number(n[o]),b=Number(n[p]),k=Number(n[l]);if(Number.isNaN(g)){return}a.append("circle").attr("cx",v(Math.min(Math.max(g,m),u))).attr("cy",y/2).attr("r",3).attr("fill",f);if(Number.isNaN(b)||Number.isNaN(k)){return}a.append("line").attr("x1",v(Math.min(Math.max(b,m),u))).attr("y1",y/2).attr("x2",v(Math.min(Math.max(k,m),u))).attr("y2",y/2).attr("stroke",f)};function b(t){const e=Number(t[o]);if(!Number.isNaN(e))g.push(e);const n=Number(t[p]),s=Number(t[l]);if(!Number.isNaN(n)&&!Number.isNaN(s)){g.push(n);g.push(s)}}function k(e){if(t.config.regressionType=="logistic"){let t=0;while(e[t]<=0){t++}if(t>=e.length||e[t]<=0){return}const n=e[t];const s=e[e.length-1];return a().domain([Math.max(n,m),Math.min(s,u)]).range([0,h]).nice()}if(t.config.regressionType=="linear"||t.config.regressionType=="cox"){return n().domain([Math.max(e[0],m),Math.min(e[e.length-1],u)]).range([0,h])}throw"unknown type"}}}function h(t,e){if(e.length<40){t.text(e)}else{t.text(e.substring(0,35)+" ...").attr("title",e)}}function y(t,e){h(e,t.term.name||tid);if(t.q.mode!="spline"&&"refGrp"in t&&t.refGrp!=d){e.append("div").style("font-size",".8em").style("opacity",.6).html('<span style="padding:1px 5px;border:1px solid #aaa;border-radius:10px;font-size:.7em">REF</span> '+(t.term.values&&t.term.values[t.refGrp]?t.term.values[t.refGrp].label:t.refGrp)+"</span>")}if(t.effectAllele){e.append("div").style("font-size",".8em").style("opacity",.6).html('<span style="padding:1px 5px;border:1px solid #aaa;border-radius:10px;font-size:.7em">EFFECT ALLELE</span> '+t.effectAllele+"</span>")}}function x(t,e){const n=[];for(const s of t.term.snps){const r={chr:s.chr,pos:s.pos,ssm_id:s.snpid};n.push(r);const o=t.q.snp2effAle[s.snpid];const i=s.mlst.find((t=>t.alt==o));if(i){Object.assign(r,i)}else{Object.assign(r,s.mlst[0])}r.regressionPvalue="NA";r.mlpv=0;const a=e.find((t=>t.id==s.snpid));if(!a){r.regressionResult={data:{err:["No result for this variant at "+s.snpid]}};continue}r.regressionResult=a;const p=a.data;if(!p)throw".data{} missing";if(p.type3){const t=A(p,s.snpid);if(t==undefined);else{r.regressionPvalue=t;r.mlpv=-Math.log10(t)}if(!p.coefficients||!p.coefficients.terms)throw".data.coefficients.terms{} missing";const e=p.coefficients.terms[s.snpid];if(!e)throw"snp missing from data.coefficients.terms{}";if(Array.isArray(e.fields)){r.regressionEstimate=e.fields[0]}else if(e.categories){const t=[];for(const n in e.categories){t.push(n+":"+e.categories[n][0])}r.regressionEstimate=" "+t.join(" ")}else{throw"unknown way to get snp estimates from coefficients table"}}else if(p.fisher){r.regressionPvalue=p.fisher.pvalue;r.mlpv=-Math.log10(p.fisher.pvalue);r.shapeTriangle=true}else if(p.wilcoxon){r.regressionPvalue=p.wilcoxon.pvalue;r.mlpv=-Math.log10(p.wilcoxon.pvalue);r.shapeTriangle=true}else if(p.cuminc){r.regressionPvalue=p.cuminc.pvalue;r.mlpv=-Math.log10(p.cuminc.pvalue);r.shapeTriangle=true}else{r.shapeCircle=true}}return n}async function w(t,e,n){const r={holder:t.dom.snplocusBlockDiv,genome:t.parent.genomeObj,chr:e.term.q.chr,start:e.term.q.start,stop:e.term.q.stop,nobox:true,tklst:[],onCoordinateChange:async n=>{for(const e of t.snplocusBlock.tklst){if(e.type=="mds3")delete e.skewer.hlssmid}const{chr:s,start:r,stop:o}=n[0];const i={term:{id:e.term.term.id,type:"snplocus"},q:JSON.parse(JSON.stringify(e.term.q))};i.q.chr=s;i.q.start=r;i.q.stop=o;const a=await import("./snplocus-fe6f4ba1.js");await a.fillTW(i,t.app.vocabApi);t.hasUnsubmittedEdits_nullify_singleuse=true;e.pill.runCallback(i)}};r.tklst.push({type:"mds3",name:"Variants",skewerModes:[{type:"numeric",byAttribute:"mlpv",label:"-log10 p-value",inuse:true,tooltipPrintValue:e=>D(e,t.config.regressionType)}],custom_variants:x(e.term,n),variantShapeName:{dot:"common variants analyzed by model-fitting",triangle:"rare variants analyzed by "+(t.config.regressionType=="linear"?"Wilcoxon rank sum test":t.config.regressionType=="logistic"?"Fisher's exact test":"Cumulative incidence test"),circle:"monomorphic variants skipped"},click_snvindel:async n=>{t.displayResult_oneset(n.regressionResult.data);await E(n,e,t);const s=t.dom.oneSetResultDiv.node().getBoundingClientRect().top+window.scrollY;const r=document.querySelector(".sjpp-nav").getBoundingClientRect().height;window.scroll({behavior:"smooth",top:s-r})}});s(t.parent.genomeObj,r.tklst);const o=await import("./block-ec76524e.js").then((function(t){return t.c}));return new o.Block(r)}async function v(t,e,n){const s=t.snplocusBlock.tklst.find((t=>t.type=="mds3"));s.custom_variants=x(e.term,n);const r=t.snplocusBlock.rglst[0];if(r.chr==e.term.q.chr&&r.start==e.term.q.start&&r.stop==e.term.q.stop){s.load()}else{await t.snplocusBlock.jump_1basedcoordinate(e.term.q)}t.snplocusBlock.cloakOff()}const b="#2E6594",k="#ff0000",_=t(b,k);async function E(t,e,n){if(!e.term.q.restrictAncestry){return}const s=n.snplocusBlock.tklst.find((t=>t.type=="mds3"));if(!s||!s.skewer||!s.skewer.nmg)return;for(const t of s.custom_variants)delete t.regressionR2;const r=n.dom.LDresultDiv.append("span").text("Loading LD data...");try{const o=await n.app.vocabApi.getLDdata(e.term.q.restrictAncestry.name,t);if(o.error)throw o.error;if(o.nodata||!o.lst||o.lst.length==0){r.text("No LD data");s.skewer.nmg.selectAll(".sja_aa_disk_fill").attr("fill",(t=>t.shapeCircle?"none":s.color4disc(t)));return}s.skewer.nmg.selectAll(".sja_aa_disk_fill").attr("fill",(e=>{if(e.pos==t.pos&&e.ref==t.ref&&e.alt==t.alt){return k}for(const t of o.lst){if(t.pos==e.pos&&t.alleles==e.ref+"."+e.alt){e.regressionR2=t.r2;return _(t.r2)}}return _(0)}));r.html(e.term.q.restrictAncestry.name+" LD r<sup>2</sup>");R(n.dom.LDresultDiv,_)}catch(t){r.text("Error: "+(t.message||t))}}function R(t,e){const n=t.append("span").style("margin-left","10px");const s=[];for(let t=0;t<=1;t+=.1){s.push(e(t))}const r=20;const i=15;const a=10;const p=150;const l=new o({holder:n,data:[0,1],topTicks:true,width:a*2+p,height:r+i,barheight:i,barwidth:p,fontSize:12,startColor:s[0],midColor:s[s.length-1],endColor:s[s.length-1],position:`${a},${r}`,tickSize:6});l.render()}function D(t,e){const n=[{k:"p-value",v:t.regressionPvalue}];if(t.regressionResult.AFstr){n.push({k:"AF",v:t.regressionResult.AFstr})}if(t.regressionEstimate){if(e=="linear")n.push({k:"beta",v:t.regressionEstimate});else if(e=="logistic")n.push({k:"odds ratio",v:t.regressionEstimate});else if(e=="cox")n.push({k:"hazard ratio",v:t.regressionEstimate});else throw"unknown regression type"}if(t.regressionR2){n.push({k:"LD r2",v:t.regressionR2})}return n}function A(t,e){let n;if(t.totalSnpEffect){n=t.totalSnpEffect.lst[t.totalSnpEffect.lst.length-1]}else{if(!t.type3.terms)throw".data{type3:{terms}} missing";if(!t.type3.terms[e])throw e+" missing in type3.terms{}";if(!Array.isArray(t.type3.terms[e]))throw`type3.terms[${snp.snpid}] not array`;n=t.type3.terms[e][t.type3.terms[e].length-1]}const s=Number(n);if(Number.isFinite(s)){return s}return undefined}function N(t,e,n){if(n){t.text(e&&e.term.values&&e.term.values[n]?e.term.values[n].label:n);return}t.style("opacity",.3);if("geneticModel"in e.q){const n=e.q.geneticModel;t.text(n==0?"(additive)":n==1?"(dominant)":"(recessive)");return}if(e.q.mode){t.text("("+e.q.mode+")");return}}var q=Object.freeze({__proto__:null,RegressionResults:u,showLDlegend:R});export{u as R,l as m,q as r,R as s};
|
|
1
|
+
import{bP as t,ac as e,l as n,b8 as s}from"./app-71453429.js";import{a as r}from"./axisstyle-fac7f76b.js";import{C as o}from"./ColorScale-9800a609.js";import{c as i}from"./axis-6cb4f314.js";import{l as a}from"./log-ca1e2a74.js";function p({bp:t,g:e,color:n,scale:s,rowheight:r,labpad:o}){if(t.label){e.append("text").attr("font-family","Arial").attr("text-anchor","end").attr("dominant-baseline","central").attr("fill",n).attr("x",-o).attr("y",r/2).attr("font-size",Math.min(15,r)).text(t.label)}if(t.w1!=undefined){const o=s(t.w1);const i=s(t.w2);const a=s(t.p25);const p=s(t.p50);const l=s(t.p75);t.hline=e.append("line").attr("stroke",n).attr("shape-rendering","crispEdges").attr("x1",o).attr("x2",i).attr("y1",r/2).attr("y2",r/2);t.linew1=e.append("line").attr("stroke",n).attr("shape-rendering","crispEdges").attr("x1",o).attr("x2",o).attr("y1",0).attr("y2",r);t.linew2=e.append("line").attr("stroke",n).attr("shape-rendering","crispEdges").attr("x1",i).attr("x2",i).attr("y1",0).attr("y2",r);t.box=e.append("rect").attr("fill","white").attr("stroke",n).attr("shape-rendering","crispEdges").attr("x",a).attr("y",0).attr("width",l-a).attr("height",r);t.linep50=e.append("line").attr("stroke",n).attr("shape-rendering","crispEdges").attr("x1",p).attr("x2",p).attr("y1",0).attr("y2",r)}for(const o of t.out){e.append("circle").attr("stroke",n).attr("fill","white").attr("fill-opacity",0).attr("cx",s(o.value)).attr("cy",r/2).attr("r",r/3)}}function l(t,e,n,s){const r=[];if(Array.isArray(t)){for(const o of t){if(o.namekey=="regulomedb"){if(typeof e.chr=="string"&&e.pos!==undefined&&Number.isInteger(e.pos)){const t=`${e.chr}%3A${e.pos}-${e.pos+1}`;r.push(`<a href="${o.base}regions=${t}&genome=${s=="hg38"?"GRCh38":s}" target="_blank">${o.linkText}</a>`)}continue}c(o,e,n,r)}}else{c(t,e,n,r)}return r}function c(t,e,n,s){const r=e[t.namekey];if(r==undefined)return;const o=t.base+r;if(t.shownSeparately){s.push(`<a href="${o}" target="_blank">${t.linkText||r}</a>`);return}n.html(`<a href="${o}" target="_blank">${n.html()}</a>`)}const d="NA";const f="#126e08";const m=f;class u{constructor(t){this.opts=t;this.app=t.app;this.parent=t.parent;this.type="regression";g(this);const e=this.opts.holder;e.append("div").style("margin-top","10px").style("padding-top","20px").style("font-size","1.2em").style("opacity",.3).html("Results");this.dom={holder:e,err_div:e.append("div"),snplocusBlockDiv:e.append("div"),oneSetResultDiv:e.append("div").style("margin","10px")}}async main(){try{this.parent.inputs.dom.submitBtn.text("Running...");this.config=this.parent.config;this.state=this.parent.state;if(!this.state.formIsComplete||this.parent.inputs.hasError||this.config.hasUnsubmittedEdits&&!this.hasUnsubmittedEdits_nullify_singleuse){this.dom.holder.style("display","none");return}delete this.hasUnsubmittedEdits_nullify_singleuse;if(this.snplocusBlock){this.snplocusBlock.cloakOn()}const t=await this.app.vocabApi.getRegressionData(this.getDataRequestOpts());if(t.error)throw t.error;this.dom.err_div.style("display","none");this.dom.oneSetResultDiv.selectAll("*").remove();this.dom.holder.style("display","block");await this.displayResult(t);const e=this.dom.holder.node().getBoundingClientRect().top+window.scrollY;const n=document.querySelector(".sjpp-nav").getBoundingClientRect().height;window.scroll({behavior:"smooth",top:e-n})}catch(t){this.hasError=true;this.dom.holder.style("display","block");this.dom.err_div.style("display","block");e(this.dom.err_div,"Error: "+(t.error||t));this.parent.inputs.dom.submitBtn.property("disabled",true);console.error(t)}}getDataRequestOpts(){const t=this.config;const e={regressionType:t.regressionType,outcome:t.outcome,independent:t.independent};e.filter=this.parent.filter;return e}getIndependentInput(t){for(const e of this.parent.inputs.independent.inputLst){if(!e.term)continue;if(e.term.term.id==t)return e;if(e.term.term&&e.term.term.snps){for(const n of e.term.term.snps){if(n.snpid==t){const s={id:t,q:{geneticModel:e.term.q.geneticModel},term:{id:t,name:t},effectAllele:e.term.q.snp2effAle[t]};if(e.term.q.snp2refGrp){s.refGrp=e.term.q.snp2refGrp[t]}if(n.mlst){const r=n.mlst.find((n=>n.alt==e.term.q.snp2effAle[t]));if(r){s.term.name=r.mname}else{s.term.name=n.mlst[0].mname}}return{term:s}}}}}return{term:{id:t,q:{},term:{name:t}}}}}function g(t){t.displayResult=async e=>{const n=t.parent.inputs.independent.inputLst.find((t=>t.term&&t.term.term.type=="snplocus"));if(n){if(!t.snplocusBlock){t.dom.snplocusBlockDiv.append("div").style("margin-top","30px").style("opacity",.3).text("Click on a variant within the browser to view its regression results");t.snplocusBlock=await w(t,n,e.resultLst)}else{await v(t,n,e.resultLst)}return}delete t.snplocusBlock;t.dom.snplocusBlockDiv.selectAll("*").remove();if(!e.resultLst[0]||!e.resultLst[0].data)throw"result is not [ {data:{}} ]";t.displayResult_oneset(e.resultLst[0].data)};t.displayResult_oneset=e=>{t.dom.oneSetResultDiv.selectAll("*").remove();t.dom.LDresultDiv=t.dom.oneSetResultDiv.append("div");t.mayshow_warn(e);if(e.sampleSize)t.newDiv("Sample size:",e.sampleSize);if(e.eventCnt)t.newDiv("Number of events:",e.eventCnt);t.mayshow_headerRow(e);t.mayshow_splinePlots(e);t.mayshow_residuals(e);t.mayshow_coefficients(e);t.mayshow_totalSnpEffect(e);t.mayshow_type3(e);t.mayshow_tests(e);t.mayshow_other(e);t.mayshow_fisher(e);t.mayshow_wilcoxon(e);t.mayshow_cuminc(e)};t.newDiv=(e,n,s)=>{const r=t.dom.oneSetResultDiv.append("div").style("margin","20px 0px 10px 0px").attr("name",e);const o=r.append("div");o.append("span").style("text-decoration","underline").text(e);if(n){o.append("span").html(n).style("margin-left","5px")}return s?o:r.append("div").style("margin-left","20px")};t.mayshow_warn=e=>{if(!e.warnings)return;const n=t.newDiv("Warnings");const s=new Set(e.warnings);for(const t of s){n.append("p").style("margin","5px").text(t)}};t.mayshow_headerRow=e=>{if(!e.headerRow)return;const n=e.headerRow.k;const s=e.headerRow.v;const r=t.parent.inputs.independent.inputLst.find((t=>t.term&&t.term.term.type=="snplocus"));if(r){const e=r.term.term.snps.find((t=>t.snpid==s.snpid));const o=e.mlst[0];o.chr=e.chr;const i=t.newDiv(n,null,true);const a=i.append("span").text(`${o.chr}:${o.pos+1} ${o.ref&&o.alt?o.ref+">"+o.alt:""}`).style("margin-left","5px");const p=t.app.vocabApi.termdbConfig.urlTemplates?.ssm||t.app.vocabApi.termdbConfig.queries?.snvindel?.ssmUrl;if(p){const e=l(p,o,a,t.parent.genomeObj.name);if(e?.length){i.append("span").style("margin-left","10px").html(e.join(" "))}}let c;const d=`Genotypes: ${s.gtcounts.join(", ")}`;if(s.monomorphic){c=[d]}else{const t=`Effect allele: ${s.effAle}`;const e=`Allele frequency: ${s.af}`;c=[t,e,d]}i.append("span").html(` | ${c.join(" | ")}`)}else{t.newDiv(n,s)}};t.mayshow_splinePlots=e=>{if(!e.splinePlots)return;const n=t.newDiv("Cubic spline plots");for(const t of e.splinePlots){n.append("img").attr("src",t.src).style("width",t.size.width).style("height",t.size.height)}};t.mayshow_residuals=e=>{if(!e.residuals)return;const n=t.newDiv(e.residuals.label);const s=n.append("table").style("border-spacing","8px").attr("name","sjpp-residuals-table");const r=s.append("tr").style("opacity",.4);const o=s.append("tr");for(let t=0;t<e.residuals.header.length;t++){r.append("td").text(e.residuals.header[t]);o.append("td").text(e.residuals.rows[t])}};t.mayshow_cuminc=async e=>{if(!e.cuminc)return;const n=t.newDiv("Cumulative incidence test:");const s=await import("./cuminc-8d21132b.js");const r=new s.Cuminc({holder:n,config:{term:t.config.outcome,term2:{term:{name:"Variant",values:{1:{key:1,label:"Has minor allele"},2:{key:2,label:"No minor allele"}}}}}});if(e.cuminc.ci_data){r.main(e.cuminc.ci_data)}else{n.append("div").style("margin","20px").text(e.cuminc.msg)}};t.mayshow_wilcoxon=e=>{if(!e.wilcoxon)return;const s=t.newDiv("Wilcoxon rank sum test:","p-value = "+e.wilcoxon.pvalue);if(e.wilcoxon.boxplots){const o=e.wilcoxon.boxplots;const a=20,l=400,c=160,d=40,f=20,u=10;const g=n().domain([o.minv,o.maxv]).range([0,l]);const h=s.append("svg").style("margin-top","10px").attr("width",c+f+l+10).attr("height",u*3+a*2+d);const y=h.append("g").attr("transform",`translate(${c+f},${u})`);p({g:y.append("g"),bp:o.hasEff,scale:g,rowheight:a,color:m,labpad:f});p({g:y.append("g").attr("transform",`translate(0,${a+u})`),bp:o.noEff,scale:g,rowheight:a,color:m,labpad:f});{const e=y.append("g").attr("transform",`translate(0,${a*2+u*2})`);const n=i().scale(g);r({axis:e.call(n),color:m,showline:true});e.append("text").text(t.config.outcome.term.name).attr("font-size",15).attr("x",l/2).attr("y",d-5).attr("text-anchor","middle").attr("fill",m)}}};t.mayshow_fisher=e=>{if(!e.fisher)return;const n=t.newDiv(e.fisher.isChi?"Chi-square test:":"Fisher's exact test:","p-value = "+e.fisher.pvalue);const s=n.append("table").style("margin","20px").style("border-spacing","5px").style("border-collapse","separate");for(const t of e.fisher.rows){const e=s.append("tr");for(const n of t){e.append("td").text(n)}}};t.mayshow_coefficients=e=>{if(!e.coefficients)return;const n=t.newDiv(e.coefficients.label);const s=n.append("table").style("border-spacing","0px").attr("data-testid","sjpp_regression_resultCoefficientTable");{const t=s.append("tr").style("opacity",.4);e.coefficients.header.forEach(((e,n)=>{t.append("td").text(e).style("padding","8px");if(n===1)t.append("td")}))}if(t.config.regressionType!="cox"){const t=s.append("tr").style("background","#eee");e.coefficients.intercept.forEach(((e,n)=>{t.append("td").text(e).style("padding","8px");if(n===1)t.append("td")}))}const r=t.getForestPlotter(e.coefficients.terms,e.coefficients.interactions);let o=t.config.regressionType=="cox"?1:0;for(const n in e.coefficients.terms){const i=e.coefficients.terms[n];const a=t.getIndependentInput(n).term;let p=s.append("tr").style("background",o++%2?"#eee":"none");const l=p.append("td").style("padding","8px");y(a,l);if(i.fields){{const t=p.append("td").style("padding","8px");N(t,a)}r(p.append("td"),i.fields);for(const t of i.fields){p.append("td").text(t).style("padding","8px")}}else if(i.categories){const e=[];const c=t.getIndependentInput(n);if(c.orderedLabels){for(const t of c.orderedLabels){if(i.categories[t])e.push(t)}}for(const t in i.categories){if(!e.includes(t))e.push(t)}l.attr("rowspan",e.length).style("vertical-align","top");let d=true;for(const t of e){if(d){d=false}else{p=s.append("tr").style("background",o++%2?"#eee":"none")}const e=p.append("td").style("padding","8px");N(e,a,t);r(p.append("td"),i.categories[t]);for(const e of i.categories[t]){p.append("td").text(e).style("padding","8px")}}}else{p.append("td").text("ERROR: no .fields[] or .categories{}")}}for(const n of e.coefficients.interactions){const e=s.append("tr").style("background",o++%2?"#eee":"none");const i=t.getIndependentInput(n.term1).term;const a=t.getIndependentInput(n.term2).term;{const t=e.append("td").style("padding","8px");h(t.append("div"),i?i.term.name+" : ":n.term1+" : ");h(t.append("div"),a?a.term.name:n.term2)}{const t=e.append("td").style("padding","8px");N(t.append("div"),i,n.category1);N(t.append("div"),a,n.category2)}r(e.append("td"),n.lst);for(const t of n.lst){e.append("td").text(t).style("padding","8px")}}const i=s.append("tr");i.append("td");i.append("td");r(i.append("td"));for(const t of e.coefficients.header)i.append("td")};t.mayshow_totalSnpEffect=e=>{if(!e.totalSnpEffect)return;const n=t.newDiv(e.totalSnpEffect.label);const s=n.append("table").style("border-spacing","0px");{const t=s.append("tr").style("opacity",.4);for(const n of e.totalSnpEffect.header){t.append("td").text(n).style("padding","8px")}}const r=s.append("tr").style("background","#eee");for(const t of e.totalSnpEffect.lst){r.append("td").text(t).style("padding","8px")}const o=t.getIndependentInput(e.totalSnpEffect.snp).term;const i=e.totalSnpEffect.interactions.map((e=>({t1:t.getIndependentInput(e.term1).term,t2:t.getIndependentInput(e.term2).term})));const a=`Total: total effect of removing the snp (${o.term.name}) and its interactions (${i.map((t=>t.t1.term.name+" : "+t.t2.term.name)).join(" ; ")}) from the model`;n.append("div").style("margin","20px 0px 20px 10px").style("font-size",".8em").style("text-align","left").style("color","#999").text(a)};t.mayshow_type3=e=>{if(!e.type3)return;const n=t.newDiv(e.type3.label);const s=n.append("table").style("border-spacing","0px");{const t=s.append("tr").style("opacity",.4);for(const n of e.type3.header){t.append("td").text(n).style("padding","8px")}}if(t.config.regressionType!="cox"){const t=s.append("tr").style("background","#eee");for(const n of e.type3.intercept){t.append("td").text(n).style("padding","8px")}}let r=t.config.regressionType=="cox"?1:0;for(const n in e.type3.terms){const o=e.type3.terms[n];const i=t.getIndependentInput(n).term;let a=s.append("tr").style("background",r++%2?"#eee":"none");const p=a.append("td").style("padding","8px");h(p,i.term.name);for(const t of o){a.append("td").text(t).style("padding","8px")}}for(const n of e.type3.interactions){const e=s.append("tr").style("background",r++%2?"#eee":"none");const o=t.getIndependentInput(n.term1).term;const i=t.getIndependentInput(n.term2).term;const a=e.append("td").style("padding","8px");h(a.append("div"),o.term.name+" : ");h(a.append("div"),i.term.name);for(const t of n.lst){e.append("td").text(t).style("padding","8px")}}};t.mayshow_tests=e=>{if(!e.tests)return;const n=t.newDiv(e.tests.label);const s=n.append("table").style("border-spacing","0px");const r=s.append("tr").style("opacity",.4);for(const t of e.tests.header){r.append("td").text(t).style("padding","8px")}let o=0;for(const t of e.tests.rows){const e=s.append("tr").style("background",o++%2?"none":"#eee");for(const n of t){e.append("td").text(n).style("padding","8px")}}};t.mayshow_other=e=>{if(!e.other)return;const n=t.newDiv(e.other.label);const s=n.append("table").style("border-spacing","8px");for(let t=0;t<e.other.header.length;t++){const n=s.append("tr");n.append("td").style("opacity",.4).text(e.other.header[t]);n.append("td").text(e.other.rows[t])}};t.getForestPlotter=(e,s)=>{let o,p,l,c,d,m,u;if(t.config.regressionType=="linear"){o=0;p=1;l=2;c="Beta value";d=0;m=null;u=null}else if(t.config.regressionType=="logistic"){o=0;p=1;l=2;c="Odds ratio";d=1;m=.1;u=10}else if(t.config.regressionType=="cox"){o=0;p=1;l=2;c="Hazard ratio";d=1;m=.1;u=10}else{throw"unknown regressionType"}const g=[];for(const t in e){const n=e[t];if(n.fields){b(n.fields)}else{for(const t in n.categories){b(n.categories[t])}}}for(const t of s){b(t.lst)}if(g.length==0){return()=>{}}g.sort(((t,e)=>t-e));if(m==null){m=g[0];u=g[g.length-1]}const h=150;const y=20;const x=10,w=10;const v=k(g);return(e,n)=>{if(!v){return}const s=e.append("svg").attr("width",h+x+w).attr("height",y);const a=s.append("g").attr("transform","translate("+x+",0)");if(!n){const e=t.config.regressionType=="logistic"?".1r":undefined;const n=i().ticks(4,e).scale(v);r({axis:a.call(n),color:f,showline:true});const o=12;a.append("text").attr("fill",f).text(c).attr("x",h/2).attr("y",y+o);s.attr("height",y+o);return}{const t=v(d);a.append("line").attr("x1",t).attr("y1",0).attr("x2",t).attr("y2",y).attr("stroke","#ccc")}const g=Number(n[o]),b=Number(n[p]),k=Number(n[l]);if(Number.isNaN(g)){return}a.append("circle").attr("cx",v(Math.min(Math.max(g,m),u))).attr("cy",y/2).attr("r",3).attr("fill",f);if(Number.isNaN(b)||Number.isNaN(k)){return}a.append("line").attr("x1",v(Math.min(Math.max(b,m),u))).attr("y1",y/2).attr("x2",v(Math.min(Math.max(k,m),u))).attr("y2",y/2).attr("stroke",f)};function b(t){const e=Number(t[o]);if(!Number.isNaN(e))g.push(e);const n=Number(t[p]),s=Number(t[l]);if(!Number.isNaN(n)&&!Number.isNaN(s)){g.push(n);g.push(s)}}function k(e){if(t.config.regressionType=="logistic"){let t=0;while(e[t]<=0){t++}if(t>=e.length||e[t]<=0){return}const n=e[t];const s=e[e.length-1];return a().domain([Math.max(n,m),Math.min(s,u)]).range([0,h]).nice()}if(t.config.regressionType=="linear"||t.config.regressionType=="cox"){return n().domain([Math.max(e[0],m),Math.min(e[e.length-1],u)]).range([0,h])}throw"unknown type"}}}function h(t,e){if(e.length<40){t.text(e)}else{t.text(e.substring(0,35)+" ...").attr("title",e)}}function y(t,e){h(e,t.term.name||tid);if(t.q.mode!="spline"&&"refGrp"in t&&t.refGrp!=d){e.append("div").style("font-size",".8em").style("opacity",.6).html('<span style="padding:1px 5px;border:1px solid #aaa;border-radius:10px;font-size:.7em">REF</span> '+(t.term.values&&t.term.values[t.refGrp]?t.term.values[t.refGrp].label:t.refGrp)+"</span>")}if(t.effectAllele){e.append("div").style("font-size",".8em").style("opacity",.6).html('<span style="padding:1px 5px;border:1px solid #aaa;border-radius:10px;font-size:.7em">EFFECT ALLELE</span> '+t.effectAllele+"</span>")}}function x(t,e){const n=[];for(const s of t.term.snps){const r={chr:s.chr,pos:s.pos,ssm_id:s.snpid};n.push(r);const o=t.q.snp2effAle[s.snpid];const i=s.mlst.find((t=>t.alt==o));if(i){Object.assign(r,i)}else{Object.assign(r,s.mlst[0])}r.regressionPvalue="NA";r.mlpv=0;const a=e.find((t=>t.id==s.snpid));if(!a){r.regressionResult={data:{err:["No result for this variant at "+s.snpid]}};continue}r.regressionResult=a;const p=a.data;if(!p)throw".data{} missing";if(p.type3){const t=A(p,s.snpid);if(t==undefined);else{r.regressionPvalue=t;r.mlpv=-Math.log10(t)}if(!p.coefficients||!p.coefficients.terms)throw".data.coefficients.terms{} missing";const e=p.coefficients.terms[s.snpid];if(!e)throw"snp missing from data.coefficients.terms{}";if(Array.isArray(e.fields)){r.regressionEstimate=e.fields[0]}else if(e.categories){const t=[];for(const n in e.categories){t.push(n+":"+e.categories[n][0])}r.regressionEstimate=" "+t.join(" ")}else{throw"unknown way to get snp estimates from coefficients table"}}else if(p.fisher){r.regressionPvalue=p.fisher.pvalue;r.mlpv=-Math.log10(p.fisher.pvalue);r.shapeTriangle=true}else if(p.wilcoxon){r.regressionPvalue=p.wilcoxon.pvalue;r.mlpv=-Math.log10(p.wilcoxon.pvalue);r.shapeTriangle=true}else if(p.cuminc){r.regressionPvalue=p.cuminc.pvalue;r.mlpv=-Math.log10(p.cuminc.pvalue);r.shapeTriangle=true}else{r.shapeCircle=true}}return n}async function w(t,e,n){const r={holder:t.dom.snplocusBlockDiv,genome:t.parent.genomeObj,chr:e.term.q.chr,start:e.term.q.start,stop:e.term.q.stop,nobox:true,tklst:[],onCoordinateChange:async n=>{for(const e of t.snplocusBlock.tklst){if(e.type=="mds3")delete e.skewer.hlssmid}const{chr:s,start:r,stop:o}=n[0];const i={term:{id:e.term.term.id,type:"snplocus"},q:JSON.parse(JSON.stringify(e.term.q))};i.q.chr=s;i.q.start=r;i.q.stop=o;const a=await import("./snplocus-0cafa73c.js");await a.fillTW(i,t.app.vocabApi);t.hasUnsubmittedEdits_nullify_singleuse=true;e.pill.runCallback(i)}};r.tklst.push({type:"mds3",name:"Variants",skewerModes:[{type:"numeric",byAttribute:"mlpv",label:"-log10 p-value",inuse:true,tooltipPrintValue:e=>D(e,t.config.regressionType)}],custom_variants:x(e.term,n),variantShapeName:{dot:"common variants analyzed by model-fitting",triangle:"rare variants analyzed by "+(t.config.regressionType=="linear"?"Wilcoxon rank sum test":t.config.regressionType=="logistic"?"Fisher's exact test":"Cumulative incidence test"),circle:"monomorphic variants skipped"},click_snvindel:async n=>{t.displayResult_oneset(n.regressionResult.data);await E(n,e,t);const s=t.dom.oneSetResultDiv.node().getBoundingClientRect().top+window.scrollY;const r=document.querySelector(".sjpp-nav").getBoundingClientRect().height;window.scroll({behavior:"smooth",top:s-r})}});s(t.parent.genomeObj,r.tklst);const o=await import("./block-4f585abe.js").then((function(t){return t.c}));return new o.Block(r)}async function v(t,e,n){const s=t.snplocusBlock.tklst.find((t=>t.type=="mds3"));s.custom_variants=x(e.term,n);const r=t.snplocusBlock.rglst[0];if(r.chr==e.term.q.chr&&r.start==e.term.q.start&&r.stop==e.term.q.stop){s.load()}else{await t.snplocusBlock.jump_1basedcoordinate(e.term.q)}t.snplocusBlock.cloakOff()}const b="#2E6594",k="#ff0000",_=t(b,k);async function E(t,e,n){if(!e.term.q.restrictAncestry){return}const s=n.snplocusBlock.tklst.find((t=>t.type=="mds3"));if(!s||!s.skewer||!s.skewer.nmg)return;for(const t of s.custom_variants)delete t.regressionR2;const r=n.dom.LDresultDiv.append("span").text("Loading LD data...");try{const o=await n.app.vocabApi.getLDdata(e.term.q.restrictAncestry.name,t);if(o.error)throw o.error;if(o.nodata||!o.lst||o.lst.length==0){r.text("No LD data");s.skewer.nmg.selectAll(".sja_aa_disk_fill").attr("fill",(t=>t.shapeCircle?"none":s.color4disc(t)));return}s.skewer.nmg.selectAll(".sja_aa_disk_fill").attr("fill",(e=>{if(e.pos==t.pos&&e.ref==t.ref&&e.alt==t.alt){return k}for(const t of o.lst){if(t.pos==e.pos&&t.alleles==e.ref+"."+e.alt){e.regressionR2=t.r2;return _(t.r2)}}return _(0)}));r.html(e.term.q.restrictAncestry.name+" LD r<sup>2</sup>");R(n.dom.LDresultDiv,_)}catch(t){r.text("Error: "+(t.message||t))}}function R(t,e){const n=t.append("span").style("margin-left","10px");const s=[];for(let t=0;t<=1;t+=.1){s.push(e(t))}const r=20;const i=15;const a=10;const p=150;const l=new o({holder:n,data:[0,1],topTicks:true,width:a*2+p,height:r+i,barheight:i,barwidth:p,fontSize:12,startColor:s[0],midColor:s[s.length-1],endColor:s[s.length-1],position:`${a},${r}`,tickSize:6});l.render()}function D(t,e){const n=[{k:"p-value",v:t.regressionPvalue}];if(t.regressionResult.AFstr){n.push({k:"AF",v:t.regressionResult.AFstr})}if(t.regressionEstimate){if(e=="linear")n.push({k:"beta",v:t.regressionEstimate});else if(e=="logistic")n.push({k:"odds ratio",v:t.regressionEstimate});else if(e=="cox")n.push({k:"hazard ratio",v:t.regressionEstimate});else throw"unknown regression type"}if(t.regressionR2){n.push({k:"LD r2",v:t.regressionR2})}return n}function A(t,e){let n;if(t.totalSnpEffect){n=t.totalSnpEffect.lst[t.totalSnpEffect.lst.length-1]}else{if(!t.type3.terms)throw".data{type3:{terms}} missing";if(!t.type3.terms[e])throw e+" missing in type3.terms{}";if(!Array.isArray(t.type3.terms[e]))throw`type3.terms[${snp.snpid}] not array`;n=t.type3.terms[e][t.type3.terms[e].length-1]}const s=Number(n);if(Number.isFinite(s)){return s}return undefined}function N(t,e,n){if(n){t.text(e&&e.term.values&&e.term.values[n]?e.term.values[n].label:n);return}t.style("opacity",.3);if("geneticModel"in e.q){const n=e.q.geneticModel;t.text(n==0?"(additive)":n==1?"(dominant)":"(recessive)");return}if(e.q.mode){t.text("("+e.q.mode+")");return}}var q=Object.freeze({__proto__:null,RegressionResults:u,showLDlegend:R});export{u as R,l as m,q as r,R as s};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{M as t,q as e}from"./app-
|
|
1
|
+
import{M as t,q as e}from"./app-71453429.js";import{p as s}from"./pointer-c7475677.js";function i(t,e){this._context=t;this._t=e}i.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN;this._point=0},lineEnd:function(){if(0<this._t&&this._t<1&&this._point===2)this._context.lineTo(this._x,this._y);if(this._line||this._line!==0&&this._point===1)this._context.closePath();if(this._line>=0)this._t=1-this._t,this._line=1-this._line},point:function(t,e){t=+t,e=+e;switch(this._point){case 0:this._point=1;this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:{if(this._t<=0){this._context.lineTo(this._x,e);this._context.lineTo(t,e)}else{var s=this._x*(1-this._t)+t*this._t;this._context.lineTo(s,this._y);this._context.lineTo(s,e)}break}}this._x=t,this._y=e}};function n(t){return new i(t,1)}function r(e,i,n=null){const r=n||new t({padding:"5px"});e.style("display","none");const o=i.style("fill","transparent").node();function a(t){const i=s(t,o);const n=i[0];const a=+l.xScale.invert(n).toFixed(l.decimals);const c=l.xScale(a);e.style("display","").attr("stroke","#aaa").attr("stroke-dasharray",4).attr("x1",c).attr("x2",c);const d=[];for(const t of l.serieses){const e=t.data;const s=e.map((t=>t.x));if(a>=Math.min(...s)&&a<=Math.max(...s)){const t=Math.max(...s.filter((t=>t<=a)));const i=e.find((e=>e.x==t));if(i)d.push(i.html)}}if(d.length){r.show(t.clientX,t.clientY).d.html(`${l.xTitleLabel}: ${a}<br>`+d.map((t=>t)).join(l.separator))}else{r.hide()}}i.on("mouseover",a).on("mousemove",a).on("mouseout",(()=>{e.style("display","none");r.hide()}));const l={separator:"<br>",decimals:1};return{update(t={}){Object.assign(l,t);const s=i.attr("x");const n=i.attr("y");e.attr("x1",s).attr("x2",s).attr("y1",n).attr("y2",i.attr("height")-n)},destroy(){i.on("mouseover",null).on("mousemove",null).on("mouseout",null)}}}function o({g:t,s:s,chart:i,term2values:n,term2toColor:r,onSerieClick:o}){const l={};const c=i.xTickValues.filter((t=>t>=i.xMin));for(const t of i.visibleSerieses){const e=[];let s=0,i=t.data[0],n=i,r=0;for(const o of c){while(i&&i.x<o){r+=i.ncensor;n=i;s++;i=t.data[s]}if(i&&i.x===o){e.push([o,i.nrisk,r])}else{e.push([o,n.nrisk-n.nevent-n.ncensor,r])}}l[t.seriesId]=e}const d=s.svgh-s.svgPadding.top-s.svgPadding.bottom+60;const p=i.serieses.map((t=>t.seriesId));if(n){p.sort(((t,e)=>{const s=n[t];const i=n[e];if(s&&i){if("order"in s&&"order"in i)return s.order-i.order;if(s.order)return s.order;if(i.order)return i.order;return 0}if(s)return s.order||0;if(i)return i.order||0;return 0}))}let h;t.selectAll(".sjpp-atrisk-title").remove();if(s.atRiskVisible){h=Object.keys(l).sort(((t,e)=>p.indexOf(t)-p.indexOf(e)));const e=i.serieses.length==1&&!i.serieses[0].seriesId;const n=t.append("text").attr("class","sjpp-atrisk-title").attr("transform",`translate(${s.atRiskLabelOffset}, ${e?2*s.axisTitleFontSize:0})`).attr("text-anchor","end").attr("font-size",`${s.axisTitleFontSize-4}px`).attr("cursor",i.serieses.length==1?"pointer":"default").text("Number at risk").on("click",i.serieses.length==1?t=>o({seriesId:""},t.clientX,t.clientY):null);if(r[""])n.style("fill",s.defaultColor);n.append("tspan").attr("x",0).attr("y",s.axisTitleFontSize-4).text("(# censored)")}else{h=[]}const f=t.attr("transform",`translate(0,${d})`).selectAll(":scope > g").data(h,(t=>t));f.exit().remove();f.each((function(t,n){const o=(n+1)*(2*s.axisTitleFontSize);const d=e(this).attr("transform",`translate(0,${o})`).attr("fill",r[""]?s.defaultColor:r[t].adjusted);a(d.select(":scope>g"),i,c,s,t,l[t])}));f.enter().append("g").each((function(t,n){const d=(n+1)*(2*s.axisTitleFontSize);const p=e(this).attr("transform",`translate(0,${d})`).attr("fill",r[""]?s.defaultColor:r[t].adjusted).on("click",(e=>o({seriesId:t},e.clientX,e.clientY)));const h=i.serieses.find((e=>e.seriesId===t));p.append("text").attr("transform",`translate(${s.atRiskLabelOffset}, 0)`).attr("text-anchor","end").attr("font-size",`${s.axisTitleFontSize-4}px`).attr("cursor","pointer").datum({seriesId:t}).text(t&&t!="*"?h.seriesLabel||t:"");a(p.append("g"),i,c,s,t,l[t])}))}function a(t,s,i,n,r,o){const a=o.slice().reverse();const l=i.map((t=>{if(t===0)return{seriesId:r,tickVal:t,atRisk:o[0][1],nCensored:o[0][2]};const e=a.find((e=>e[0]<=t));return{seriesId:r,tickVal:t,atRisk:e[1],nCensored:e[2]}}));const c=t.selectAll("text").data(l);c.exit().remove();c.attr("transform",(t=>`translate(${s.xScale(t.tickVal)},0)`)).attr("text-anchor","middle").attr("font-size",`${n.axisTitleFontSize-4}px`).attr("cursor","pointer").each(d);c.enter().append("text").attr("transform",(t=>`translate(${s.xScale(t.tickVal)},0)`)).attr("text-anchor","middle").attr("font-size",`${n.axisTitleFontSize-4}px`).attr("cursor","pointer").each(d);function d(t){const s=e(this).selectAll("tspan").data([t.atRisk,`(${t.nCensored})`]);s.exit().remove();s.attr("y",((t,e)=>e===0?0:e*(n.axisTitleFontSize-4))).text((t=>t));s.enter().append("tspan").attr("x",0).attr("y",((t,e)=>e===0?0:e*(n.axisTitleFontSize-4))).text((t=>t))}}function l({title:t,holder:s,plot:i,tests:n,s:r,bins:o,tip:a,setActiveMenu:l,updateHiddenPvalues:c}){let d;if(r.axisTitleFontSize){d=r.axisTitleFontSize-2}else d=15;const p=10;s.selectAll("*").remove();if(!i){throw`plot type '${i}' not recognized`}s.append("div").style("padding-bottom","5px").style("font-size",d+"px").style("font-weight","bold").text(t);const h=s.append("div").style("border","1px solid #ccc");if(i=="violin"&&n.pvalues.length>p||n.length>p){h.style("overflow","auto").style("height","220px")}const f=r.hiddenPvalues?n.filter((t=>!r.hiddenPvalues.find((e=>e.series1.id===t.series1.id&&e.series2.id===t.series2.id)))):n;if(i=="violin"?f.pvalues.length:f.length){const t=o&&o.length>0?o.map((t=>t.label)):null;if(t){for(const e of f){const s=[e.series1.id,e.series2.id].sort(((e,s)=>t.indexOf(e)-t.indexOf(s)));if(e.series2.id==s[0]){e.series1_new=e.series2;e.series2_new=e.series1;e.series1=e.series1_new;e.series2=e.series2_new;delete e.series1_new;delete e.series2_new}}f.sort(((e,s)=>t.indexOf(e.series1.id)-t.indexOf(s.series1.id)||t.indexOf(e.series2.id)-t.indexOf(s.series2.id)))}const e=h.append("table").style("width","100%");e.append("thead").append("tr").selectAll("td").data(["Group 1","Group 2","P-value"]).enter().append("td").style("padding","1px 8px 1px 2px").style("color","#858585").style("position","sticky").style("top","0px").style("background","white").style("font-size",d+"px").text((t=>t));const n=e.append("tbody");const a=n.selectAll("tr").data(i=="violin"?f.pvalues:f).enter().append("tr").attr("class",`pp-${i}-chartLegends-pvalue`);if(i=="survival"){a.on("click",((t,e)=>{const s=r.hiddenPvalues.slice();s.push(e);c(s)}))}a.selectAll("td").data((t=>[t.series1,t.series2,t.pvalue])).enter().append("td").attr("title",i?"Click to hide a p-value":"").style("color",i=="violin"?"black":t=>t.color).style("padding","1px 8px 1px 2px").style("font-size",d+"px").style("cursor",i=="survival"?"pointer":"auto").text((t=>i=="violin"?t:t.text));if(i=="cuminc"){if(f.find((t=>t.permutation))){s.append("div").style("margin-top","10px").style("font-size",d-2+"px").text("*computed by permutation of Gray's test statistic")}}}if(i=="survival"){const t=n.filter((t=>r.hiddenPvalues.find((e=>e.series1.id===t.series1.id&&e.series2.id===t.series2.id))));if(t.length){s.append("div").style("color","#aaa").style("cursor","pointer").html(`<span style='color:#aaa; font-weight:400'><span>Hidden tests (${t.length})</span>`).on("click",(s=>{a.clear();const i=a.d.append("div").selectAll("div").data(t).enter().append("div").each((function(t){l(true);const s=e(this);s.append("input").attr("type","checkbox").style("margin-right","5px");s.append("span").html(`${t.series1.id} vs ${t.series2.id}`)}));a.d.append("button").html("Show checked test(s)").on("click",(()=>{const t=[];i.filter((function(){return!e(this.firstChild).property("checked")})).each((e=>t.push(e)));c(t);a.hide()}));a.show(s.clientX,s.clientY)}))}}}export{o as a,r as g,l as r,n as s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{q as t,l as e,x as s,aV as a,aW as o,M as n,ao as i,O as r,az as l,aS as c,aT as p}from"./app-71453429.js";import{f as d}from"./termsetting-636d2271.js";import{controlsInit as f}from"./controls-0467d2ec.js";import{d as g}from"./zoom-a40839cf.js";import{d as m}from"./lasso-ef63631b.js";import{b as h,a as u,h as y,f as x,i as v,j as b}from"./recover-b1ec4fed.js";import{g as S,s as T}from"./sampleScatter.interactivity-cfa3451d.js";import{d as w}from"./svg.download-54c99186.js";import{c as C}from"./FilterRxComp-fc769f34.js";import{S as D,s as z,a as A,b as W,c as O,d as k,e as M,f as L}from"./symbol-fc7cbd41.js";import{a as G,m as $}from"./math-2fb199c6.js";import{s as _}from"./sampleScatter.rendererThree-c5321d24.js";import{c as j,b as I,d as N}from"./axis-6cb4f314.js";import{l as V}from"./line-264f8f9e.js";const q=G(3);var R={draw(t,e){const s=G(e+$(e/28,.75))*.59436;const a=s/2;const o=a*q;t.moveTo(0,s);t.lineTo(0,-s);t.moveTo(-o,-a);t.lineTo(o,a);t.moveTo(-o,a);t.lineTo(o,-a)}};var F={draw(t,e){const s=G(e)*.62625;t.moveTo(0,-s);t.lineTo(s,0);t.lineTo(0,s);t.lineTo(-s,0);t.closePath()}};var K={draw(t,e){const s=G(e-$(e/7,2))*.87559;t.moveTo(-s,0);t.lineTo(s,0);t.moveTo(0,s);t.lineTo(0,-s)}};var E={draw(t,e){const s=G(e)*.4431;t.moveTo(s,s);t.lineTo(s,-s);t.lineTo(-s,-s);t.lineTo(-s,s);t.closePath()}};const P=G(3);var J={draw(t,e){const s=G(e)*.6824;const a=s/2;const o=s*P/2;t.moveTo(0,-s);t.lineTo(o,a);t.lineTo(-o,a);t.closePath()}};var Y={draw(t,e){const s=G(e-$(e/6,1.7))*.6189;t.moveTo(-s,-s);t.lineTo(s,s);t.moveTo(-s,s);t.lineTo(s,-s)}};function B(t,e){return H(t)||X(t,e)||Z()}function H(t){if(Array.isArray(t))return t}function X(t,e){var s=[];var a=true;var o=false;var n=undefined;try{for(var i=t[Symbol.iterator](),r;!(a=(r=i.next()).done);a=true){s.push(r.value);if(e&&s.length===e)break}}catch(t){o=true;n=t}finally{try{if(!a&&i["return"]!=null)i["return"]()}finally{if(o)throw n}}return s}function Z(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function U(t,e,s,a){t=t.filter((function(t,a){var o=e(t,a),n=s(t,a);return o!=null&&isFinite(o)&&n!=null&&isFinite(n)}));if(a){t.sort((function(t,s){return e(t)-e(s)}))}var o=t.length,n=new Float64Array(o),i=new Float64Array(o);var r=0,l=0,c,p,d;for(var f=0;f<o;){d=t[f];n[f]=c=+e(d,f,t);i[f]=p=+s(d,f,t);++f;r+=(c-r)/f;l+=(p-l)/f}for(var g=0;g<o;++g){n[g]-=r;i[g]-=l}return[n,i,r,l]}function Q(t,e,s,a){var o=0;for(var n=0,i=t.length;n<i;n++){var r=t[n],l=+e(r,n,t),c=+s(r,n,t);if(l!=null&&isFinite(l)&&c!=null&&isFinite(c)){a(l,c,o++)}}}function tt(t,e,s,a,o){var n=0,i=0;Q(t,e,s,(function(t,e){var s=e-o(t),r=e-a;n+=s*s;i+=r*r}));return 1-n/i}function et(t){return Math.atan2(t[1][1]-t[0][1],t[1][0]-t[0][0])*180/Math.PI}function st(t){return[(t[0][0]+t[1][0])/2,(t[0][1]+t[1][1])/2]}function at(t,e,s){var a=Math.log(e-t)*Math.LOG10E+1|0;var o=1*Math.pow(10,-a/2-1),n=1e4;var i=[l(t),l(e)],r=0;while(c(i)&&r<n){}return i;function l(t){return[t,s(t)]}function c(t){r++;var e=t.length;var s=false;for(var a=0;a<e-1;a++){var n=t[a],i=t[a+1],c=st([n,i]),p=l(c[0]),d=et([n,c]),f=et([n,p]),g=Math.abs(d-f);if(g>o){t.splice(a+1,0,p);s=true}}return s}}function ot(t,e,s,a){var o=a-t*t,n=Math.abs(o)<1e-24?0:(s-t*e)/o,i=e-n*t;return[i,n]}function nt(){var t=function t(e){return e[0]},e=function t(e){return e[1]},s;function a(a){var o=0,n=0,i=0,r=0,l=0,c=s?+s[0]:Infinity,p=s?+s[1]:-Infinity;Q(a,t,e,(function(t,e){++o;n+=(t-n)/o;i+=(e-i)/o;r+=(t*e-r)/o;l+=(t*t-l)/o;if(!s){if(t<c)c=t;if(t>p)p=t}}));var d=ot(n,i,r,l),f=B(d,2),g=f[0],m=f[1],h=function t(e){return m*e+g},u=[[c,h(c)],[p,h(p)]];u.a=m;u.b=g;u.predict=h;u.rSquared=tt(a,t,e,i,h);return u}a.domain=function(t){return arguments.length?(s=t,a):s};a.x=function(e){return arguments.length?(t=e,a):t};a.y=function(t){return arguments.length?(e=t,a):e};return a}function it(){var t=function t(e){return e[0]},e=function t(e){return e[1]},s;function a(a){var o=U(a,t,e),n=B(o,4),i=n[0],r=n[1],l=n[2],c=n[3],p=i.length;var d=0,f=0,g=0,m=0,h=0,u,y,x,v;for(u=0;u<p;){y=i[u];x=r[u++];v=y*y;d+=(v-d)/u;f+=(v*y-f)/u;g+=(v*v-g)/u;m+=(y*x-m)/u;h+=(v*x-h)/u}var b=0,S=0,T=s?+s[0]:Infinity,w=s?+s[1]:-Infinity;Q(a,t,e,(function(t,e){S++;b+=(e-b)/S;if(!s){if(t<T)T=t;if(t>w)w=t}}));var C=g-d*d,D=d*C-f*f,z=(h*d-m*f)/D,A=(m*C-h*f)/D,W=-z*d,O=function t(e){e=e-l;return z*e*e+A*e+W+c};var k=at(T,w,O);k.a=z;k.b=A-2*z*l;k.c=W-A*l+z*l*l+c;k.predict=O;k.rSquared=tt(a,t,e,b,O);return k}a.domain=function(t){return arguments.length?(s=t,a):s};a.x=function(e){return arguments.length?(t=e,a):t};a.y=function(t){return arguments.length?(e=t,a):e};return a}function rt(){var t=function t(e){return e[0]},e=function t(e){return e[1]},s=3,a;function o(o){if(s===1){var n=nt().x(t).y(e).domain(a)(o);n.coefficients=[n.b,n.a];delete n.a;delete n.b;return n}if(s===2){var i=it().x(t).y(e).domain(a)(o);i.coefficients=[i.c,i.b,i.a];delete i.a;delete i.b;delete i.c;return i}var r=U(o,t,e),l=B(r,4),c=l[0],p=l[1],d=l[2],f=l[3],g=c.length,m=[],h=[],u=s+1;var y=0,x=0,v=a?+a[0]:Infinity,b=a?+a[1]:-Infinity;Q(o,t,e,(function(t,e){++x;y+=(e-y)/x;if(!a){if(t<v)v=t;if(t>b)b=t}}));var S,T,w,C,D;for(S=0;S<u;++S){for(w=0,C=0;w<g;++w){C+=Math.pow(c[w],S)*p[w]}m.push(C);D=new Float64Array(u);for(T=0;T<u;++T){for(w=0,C=0;w<g;++w){C+=Math.pow(c[w],S+T)}D[T]=C}h.push(D)}h.push(m);var z=ct(h),A=function t(e){e-=d;var s=f+z[0]+z[1]*e+z[2]*e*e;for(S=3;S<u;++S){s+=z[S]*Math.pow(e,S)}return s},W=at(v,b,A);W.coefficients=lt(u,z,-d,f);W.predict=A;W.rSquared=tt(o,t,e,y,A);return W}o.domain=function(t){return arguments.length?(a=t,o):a};o.x=function(e){return arguments.length?(t=e,o):t};o.y=function(t){return arguments.length?(e=t,o):e};o.order=function(t){return arguments.length?(s=t,o):s};return o}function lt(t,e,s,a){var o=Array(t);var n,i,r,l;for(n=0;n<t;++n){o[n]=0}for(n=t-1;n>=0;--n){r=e[n];l=1;o[n]+=r;for(i=1;i<=n;++i){l*=(n+1-i)/i;o[n-i]+=r*Math.pow(s,i)*l}}o[0]+=a;return o}function ct(t){var e=t.length-1,s=[];var a,o,n,i,r;for(a=0;a<e;++a){i=a;for(o=a+1;o<e;++o){if(Math.abs(t[a][o])>Math.abs(t[a][i])){i=o}}for(n=a;n<e+1;++n){r=t[n][a];t[n][a]=t[n][i];t[n][i]=r}for(o=a+1;o<e;++o){for(n=e;n>=a;n--){t[n][o]-=t[n][a]*t[a][o]/t[a][a]}}}for(o=e-1;o>=0;--o){r=0;for(n=o+1;n<e;++n){r+=t[n][o]*s[n]}s[o]=(t[e][o]-r)/t[o][o]}return s}const pt=64;function dt(l){_(l);l.render=function(){const t=l.mainDiv.selectAll(":scope > div").data(l.charts,(t=>t?.id));t.exit().remove();t.each(l.renderChart);t.enter().append("div").style("vertical-align","top").each(l.renderChart)};l.renderChart=function(e){e.chartDiv=t(this);const s=l.settings;e.chartDiv.style("opacity",0).style("display","inline-block");e.chartDiv.on("mouseover",(t=>{if(!l.onClick)l.showTooltip(t,e)}));e.chartDiv.on("click",(t=>l.showTooltip(t,e)));e.svg=e.chartDiv.select("svg").empty()?e.chartDiv.append("svg"):e.chartDiv.select("svg");c(e,s);e.chartDiv.transition().duration(s.duration).style("opacity",1)};l.initAxes=function(t){if(t.data.samples.length==0)return;t.xAxisScale=e().domain([t.xMin,t.xMax]).range([l.axisOffset.x,l.settings.svgw+l.axisOffset.x]);t.axisBottom=j(t.xAxisScale);t.yAxisScale=e().domain([t.yMax,t.yMin]).range([l.axisOffset.y,l.settings.svgh+l.axisOffset.y]);t.zAxisScale=e().domain([t.zMin,t.zMax]).range([0,l.settings.svgd]);t.xScaleMin=t.xAxisScale(t.xMin);t.xScaleMax=t.xAxisScale(t.xMax);t.yScaleMin=t.xAxisScale(t.yMin);t.yScaleMax=t.yAxisScale(t.yMax);t.zScaleMin=t.xAxisScale(t.zMin);t.zScaleMax=t.zAxisScale(t.zMax);t.axisLeft=I(t.yAxisScale);const a=l.config.settings.sampleScatter.defaultColor;if(!l.config.startColor?.[t.id]){if(!l.config.startColor)l.config.startColor={};l.config.startColor[t.id]=s(a).brighter().brighter().toString()}if(!l.config.stopColor?.[t.id]){if(!l.config.stopColor)l.config.stopColor={};l.config.stopColor[t.id]=s(a).darker().toString()}if(l.config.colorTW?.q.mode==="continuous"){const[s,a]=t.cohortSamples.filter((t=>!l.config.colorTW.term.values||!(t.category in l.config.colorTW.term.values))).reduce(((t,e)=>[e.category<t[0]?e.category:t[0],e.category>t[1]?e.category:t[1]]),[t.cohortSamples[0].category,t.cohortSamples[0].category]);t.colorGenerator=e().domain([s,a]).range([l.config.startColor[t.id],l.config.stopColor[t.id]])}};function c(t,e){const s=t.svg;let a=Math.min(20*40/t.colorLegend.size,25);if(a<12)a=12;let o=t.colorLegend.size*a;if(t.colorLegend.get("Ref")?.sampleCount>0)o+=60;const n=l.config.scaleDotTW?200:100;l.legendHeight=Math.max(o,t.shapeLegend.size*30)+n;const i=l.charts.length==1?e.svgw+800:e.svgw+(l.config.shapeTW?600:350);s.transition().duration(e.duration).attr("width",i).attr("height",Math.max(e.svgh+100,l.legendHeight));p(t);if(l.is3D)l.render3DSerie(t);else if(l.is2DLarge)l.render2DSerieLarge(t);else{d(t,e.duration);l.renderLegend(t,a)}}function p(t){const e=t.svg;let s,a,o;if(e.select(".sjpcb-scatter-mainG").size()==0){t.mainG=e.append("g").attr("class","sjpcb-scatter-mainG");s=e.append("g").attr("class","sjpcb-scatter-axis");a=e.append("g").attr("class","sjpcb-scatter-labelsG");t.xAxis=s.append("g").attr("class","sjpcb-scatter-x-axis");t.yAxis=s.append("g").attr("class","sjpcb-scatter-y-axis").attr("transform",`translate(${l.axisOffset.x}, 0)`);t.mainG.append("rect").attr("class","zoom").attr("x",l.axisOffset.x).attr("y",l.axisOffset.y-l.settings.size).attr("width",l.settings.svgw).attr("height",l.settings.svgh).attr("fill","white");t.serie=t.mainG.append("g").attr("class","sjpcb-scatter-series");t.regressionG=t.mainG.append("g").attr("class","sjpcb-scatter-lowess");const n=`${Date.now()}`;const i=`sjpp_clip_${n}`;l.defs=e.append("defs");o=l.defs.append("clipPath").attr("id",i).append("rect");const r=l.defs.append("linearGradient").attr("id",`linear-gradient-${t.id}`).attr("x1","0%").attr("y1","0%").attr("x2","100%").attr("y2","0%");l.startGradient[t.id]=r.append("stop").attr("offset","0%").attr("stop-color",l.config.startColor[t.id]);l.stopGradient[t.id]=r.append("stop").attr("offset","100%").attr("stop-color",l.config.stopColor[t.id]);t.mainG.attr("clip-path",`url(#${i})`);t.legendG=e.append("g").attr("class","sjpcb-scatter-legend")}else{t.mainG=e.select(".sjpcb-scatter-mainG");t.serie=t.mainG.select(".sjpcb-scatter-series");t.regressionG=t.mainG.select(".sjpcb-scatter-lowess");s=e.select(".sjpcb-scatter-axis");a=e.select(".sjpcb-scatter-labelsG");t.xAxis=s.select(".sjpcb-scatter-x-axis");t.yAxis=s.select(".sjpcb-scatter-y-axis");t.legendG=e.select(".sjpcb-scatter-legend");o=e.select(`defs > clipPath > rect`)}t.xAxis.attr("transform",`translate(0, ${l.settings.svgh+l.axisOffset.y})`);t.legendG.attr("transform",`translate(${l.settings.svgw+l.axisOffset.x+50}, 20)`);if(t.axisBottom){t.xAxis.call(t.axisBottom);t.yAxis.call(t.axisLeft)}const n=Math.sqrt(l.settings.size);if(l.settings.showAxes&&!(l.is2DLarge||l.is3D)){o.attr("x",l.axisOffset.x).attr("y",0).attr("width",l.settings.svgw+2*n).attr("height",l.settings.svgh+l.axisOffset.y);s.style("opacity",1);if(l.config.term){let e=l.config.term.term.name;if(!l.config.colorTW&&!l.config.shapeTW&&!l.config.term0)e=`${e}, n=${t.cohortSamples.length}`;a.selectAll("*").remove();a.append("text").attr("transform",`translate(${l.axisOffset.x+l.settings.svgw/2}, ${l.settings.svgh+l.axisOffset.y+40})`).attr("text-anchor","middle").text(e);if(l.config.term0&&!l.config.colorTW&&!l.config.shapeTW){const e=`${t.id}, n=${t.cohortSamples.length}`;a.append("text").attr("transform",`translate(${l.axisOffset.x+l.settings.svgw/2}, ${l.settings.svgh+l.axisOffset.y+65})`).attr("text-anchor","middle").text(e)}a.append("text").attr("transform",`translate(${l.axisOffset.x-50}, ${l.settings.svgh/2+l.axisOffset.y}) rotate(-90)`).attr("text-anchor","middle").text(l.config.term2.term.name)}}else{s.style("opacity",0);o.attr("x",l.axisOffset.x-n).attr("y",0).attr("width",l.settings.svgw+2*n).attr("height",l.settings.svgh+l.axisOffset.y+n)}}function d(t,e){if(l.canvas)l.canvas.remove();const s=t.serie;const a=t.data;const o=s.selectAll('path[name="serie"]').data(a.samples);o.exit().remove();o.transition().duration(e).attr("name","serie").attr("transform",(e=>f(t,e))).attr("d",(e=>l.getShape(t,e))).attr("fill",(e=>l.getColor(e,t))).attr("stroke",(e=>l.getColor(e,t))).attr("stroke-width",(t=>l.getStrokeWidth(t))).style("fill-opacity",(t=>l.getOpacity(t)));o.enter().append("path").attr("name","serie").attr("transform",(e=>f(t,e))).attr("d",(e=>l.getShape(t,e))).attr("fill",(e=>l.getColor(e,t))).attr("stroke",(e=>l.getColor(e,t))).attr("stroke-width",(t=>l.getStrokeWidth(t))).style("fill-opacity",(t=>l.getOpacity(t))).transition().duration(e);l.mayRenderRegression()}l.getStrokeWidth=function(t){const e=l.getOpacity(t);if(e<=.2)return 0;if(e==1.2)return 2;return 1};l.processData=async function(){for(const t of l.charts){l.initAxes(t);const e=l.config.settings.sampleScatter.regression;if(!e||e=="None")continue;let s;const a=[];await t.cohortSamples.forEach((e=>{const s=t.xAxisScale(e.x);const o=t.yAxisScale(e.y);a.push({x:s,y:o})}));let o;if(e=="Polynomial"){s=rt().x((t=>t.x)).y((t=>t.y)).order(3);o=s(a)}else if(e=="Lowess"){const t=[],e=[];for(const s of a){t.push(s.x);e.push(s.y)}o=await l.app.vocabApi.getLowessCurve({coords:{X:t,Y:e}})}else{throw`unsupported regression type='${e}'`}t.regressionCurve=o}};l.mayRenderRegression=async function(){for(const t of l.charts){t.regressionG?.selectAll("*").remove();if(t.regressionCurve){const e=V().x((t=>t[0])).y((t=>t[1]));const s=t.regressionG.append("path");s.attr("d",e(t.regressionCurve)).attr("stroke","blue").attr("fill","none").style("stroke-width","2")}}};l.getColor=function(t,e){if(l.config.colorTW?.q.mode=="continuous"&&"sampleId"in t){const s=e.colorGenerator(t.category);return s}if(t.category=="Default")return l.config.settings.sampleScatter.defaultColor;const s=e.colorLegend.get(t.category);return s.color};l.getOpacity=function(t){if("sampleId"in t){if(l.filterSampleStr){if(!t.sample?.toLowerCase().includes(l.filterSampleStr.toLowerCase()))return.2;else return 1.2}const e=t.hidden?.["category"]||t.hidden?.["shape"]?0:l.settings.opacity;return e}const e=l.settings.showRef?l.settings.opacity:0;return e};l.getShape=function(t,e,s=1){const a=t.shapeLegend.get(e.shape).shape%l.symbols.length;const o=!("sampleId"in e);if(!l.config.scaleDotTW||o){const t="sampleId"in e?l.settings.size:l.settings.refSize;return l.symbols[a].size(t*s/l.zoom)()}else{const o=l.settings.maxDotSize-l.settings.minDotSize;let n;if(l.settings.scaleDotOrder=="Ascending")n=l.settings.minDotSize+(e.scale-t.scaleMin)/(t.scaleMax-t.scaleMin)*o;else n=l.settings.maxDotSize-(e.scale-t.scaleMin)/(t.scaleMax-t.scaleMin)*o;const i=n*s/l.zoom;return l.symbols[a].size(i)()}};function f(t,e){const s=t.xAxisScale(e.x);const a=t.yAxisScale(e.y);const o=`translate(${s},${a})`;return o}l.lassoReset=t=>{const e=t.chartDiv.select(".sjpcb-scatter-mainG");if(t.lasso)t.lasso.items(e.select(".sjpcb-scatter-series").selectAll('path[name="serie"]')).targetArea(e).on("start",s).on("draw",a).on("end",o);function s(e){if(l.lassoOn){t.lasso.items().attr("d",(e=>l.getShape(t,e,1/2))).style("fill-opacity",(t=>l.getOpacity(t)!=0?.5:0)).classed("not_possible",true).classed("selected",false)}}function a(e){if(l.lassoOn){t.lasso.possibleItems().attr("d",(e=>l.getShape(t,e,2))).style("fill-opacity",(t=>l.getOpacity(t))).classed("not_possible",false).classed("possible",true);t.lasso.notPossibleItems().attr("d",(e=>l.getShape(t,e,1/2))).style("fill-opacity",(t=>l.getOpacity(t)!=0?.5:0)).classed("not_possible",true).classed("possible",false)}}function o(e){if(l.lassoOn){t.lasso.items().classed("not_possible",false).classed("possible",false);t.lasso.selectedItems().attr("d",(e=>l.getShape(t,e,2)));t.lasso.items().style("fill-opacity",(t=>l.getOpacity(t)));l.selectedItems=[];for(const e of t.lasso.selectedItems()){const t=e.__data__;if("sampleId"in t&&!(t.hidden["category"]||t.hidden["shape"]))l.selectedItems.push(e)}t.lasso.notSelectedItems().attr("d",(e=>l.getShape(t,e)));n(e.sourceEvent)}}function n(t){const e=l.selectedItems.map((t=>t.__data__));l.dom.tip.clear().hide();if(l.selectedItems.length==0)return;l.dom.tip.show(t.clientX,t.clientY);const s=l.dom.tip.d.append("div");s.append("div").attr("class","sja_menuoption sja_sharp_border").text(`List ${l.selectedItems.length} samples`).on("click",(t=>{l.dom.tip.hide();l.showTable({name:"Group "+(l.config.groups.length+1),items:e},t.clientX,t.clientY,true)}));s.append("div").attr("class","sja_menuoption sja_sharp_border").text("Add to a group").on("click",(async()=>{const t={name:"Group",items:e};const s=h([t]);const a=u(s);y(l.app,a,l.state.groups)}));s.append("div").attr("class","sja_menuoption sja_sharp_border").text("Add to a group and filter").on("click",(()=>{const t={name:"Group",items:e};const s=h([t]);const a=u(s);y(l.app,a,l.state.groups);l.addToFilter(s)}));if("sample"in e[0])s.append("div").attr("class","sja_menuoption sja_sharp_border").text("Show samples").on("click",(async t=>{const s=[];for(const t of e)s.push({sampleId:t.sampleId,sampleName:t.sample});l.app.dispatch({type:"plot_create",id:S(),config:{chartType:"sampleView",samples:s}});l.dom.tip.hide()}))}if(l.lassoOn){e.on(".zoom",null);e.on("mousedown.drag",null);e.call(t.lasso)}};l.addGroup=async function(t){t.plotId=l.id;await l.app.vocabApi.addGroup(t);l.dom.tip.hide()};l.setTools=function(){if(!l.charts[0])return;const t=l.config.settings.controls.isOpen;const e=l.dom.toolsDiv.style("background-color","white");e.selectAll("*").remove();let s="block";if(t)s="inline-block";const n=e.insert("div").style("display",s).style("margin","20px").attr("name","sjpp-reset-btn");a["restart"](n,{handler:x});const i=e.insert("div").style("display",s).style("margin","20px").attr("name","sjpp-zoom-in-btn");a["zoomIn"](i,{handler:u});const r=e.insert("div").style("display",s).style("margin","20px").attr("name","sjpp-zoom-out-btn");a["zoomOut"](r,{handler:y});const c=e.insert("div").style("display",s).style("margin","20px");const p=e.insert("div").style("display",s).style("margin","20px");if(!(l.is2DLarge||l.is3D)){a["search"](c,{handler:t=>l.searchSample(t)});a["lasso"](p,{handler:v,enabled:l.lassoOn})}l.dom.groupDiv=e.insert("div").style("display",s).style("margin","20px");const d=l.charts[0].mainG;const f=g().scaleExtent([.5,l.config.scaleDotTW?4:10]).on("zoom",h).filter((t=>{if(t.type==="wheel")return t.ctrlKey;return true}));if(l.config.scaleDotTW&&l.zoom>4)x();d.call(f);for(const t of l.charts){t.lasso=m();l.lassoReset(t)}l.updateGroupsButton();l.settings;function h(t){for(const e of l.charts){const s=t.transform.rescaleX(e.xAxisScale);const a=t.transform.rescaleY(e.yAxisScale);e.xAxis.call(e.axisBottom.scale(s));e.yAxis.call(e.axisLeft.scale(a));e.serie.attr("transform",t.transform);l.zoom=t.transform.scale(1).k;const o=e.serie.selectAll('path[name="serie"');o.attr("d",(t=>l.getShape(e,t)));if(l.lassoOn)e.lasso.selectedItems().attr("d",(t=>l.getShape(e,t,2)));if(l.config.scaleDotTW)l.drawScaleDotLegend(e)}}function u(){for(const t of l.charts)if(l.is2DLarge)l.zoom=l.zoom+.25;else f.scaleBy(t.mainG.transition().duration(750),1.5)}function y(){for(const t of l.charts)if(l.is2DLarge)l.zoom=l.zoom-.25;else f.scaleBy(t.mainG.transition().duration(750),.5)}function x(){for(const t of l.charts)if(l.is2DLarge)l.zoom=1;else t.mainG.transition().duration(750).call(f.transform,o);l.render()}function v(){l.lassoOn=!l.lassoOn;for(const t of l.charts){if(l.lassoOn){t.mainG.on(".zoom",null);t.mainG.call(t.lasso)}else{t.mainG.on("mousedown.drag",null);t.lasso.items().classed("not_possible",false);t.lasso.items().classed("possible",false);t.lasso.items().attr("r",l.settings.size).style("fill-opacity",(t=>l.getOpacity(t)));t.mainG.call(f);l.selectedItems=null}}p.select("*").remove();a["lasso"](p,{handler:v,enabled:l.lassoOn})}};l.updateGroupsButton=function(){l.dom.groupDiv.selectAll("*").remove();l.dom.tip.hide();if(l.config.groups.length==0)return;l.dom.groupDiv.append("button").style("border","none").style("background","transparent").style("padding",0).append("div").style("font-size","1.1em").html(`Σ${l.config.groups.length+1};`).on("click",(t=>{if(l.config.groups.length==1)l.showGroupMenu(t,l.config.groups[0]);else l.showGroupsMenu(t)}))};l.renderLegend=function(t,a){const o=t.legendG;o.selectAll("*").remove();let n=0;let i=25;if(!l.config.colorTW&&!l.config.shapeTW&&!l.config.colorColumn){if(l.config.scaleDotTW){t.scaleG=o.append("g").attr("transform",`translate(${n},${l.legendHeight-150})`);l.drawScaleDotLegend(t)}return}let r;let c=Math.min(.8,20/t.colorLegend.size);if(c<.5)c=.5;const p=o.style("font-size",`${c}em`);let d=l.config.term0?`${t.id}, n=${t.cohortSamples.length}`:`${t.cohortSamples.length} ${l.config.sampleType?l.config.sampleType+"s":"samples"}`;if(l.filterSampleStr)d+=`, search = ${l.filterSampleStr}`;p.append("text").attr("x",0).attr("y",i).text(d).style("font-weight","bold");i+=a+10;if(l.config.colorTW||l.config.colorColumn){r=`${f(l.config.colorTW?.term?.name||l.config.colorColumn.name,l.config.shapeTW==undefined)}`;const c=t.colorLegend.get("Ref");if(l.config.colorTW?.term?.type=="geneVariant"&&!l.config.colorTW?.q.groupsetting.inuse)i=l.renderGeneVariantLegend(t,n,i,o,l.config.colorTW,"category",t.colorLegend);else{p.append("text").attr("id","legendTitle").attr("x",n).attr("y",i).text(r).style("font-weight","bold");i+=a;if(l.config.colorTW?.q?.mode==="continuous"){const s=150;const[o,n]=t.colorGenerator.domain();const r=e().domain([o,n]).range([0,s]);const c=(n-o)/4;const d=[o,o+c,o+2*c,o+3*c,n];const f=N(r).tickValues(d);p.append("g").attr("transform",`translate(0, 100)`).call(f);t.startRect=p.append("rect").attr("x",-25).attr("y",100).attr("width",20).attr("height",20).style("fill",l.config.startColor[t.id]).on("click",(e=>l.editColor(t,"startColor",t.startRect)));t.stopRect=p.append("rect").attr("x",s+5).attr("y",100).attr("width",20).attr("height",20).style("fill",l.config.stopColor[t.id]).on("click",(e=>l.editColor(t,"stopColor",t.stopRect)));p.append("rect").attr("x",0).attr("y",100).attr("width",s).attr("height",20).style("fill",`url(#linear-gradient-${t.id})`);i+=a}else{for(const[e,s]of t.colorLegend){if(e=="Ref")continue;const r=e;const c=l.config.colorTW?.q.hiddenValues?e in l.config.colorTW.q.hiddenValues:false;const[d,f]=g(p,s,r,n,i,c);if(!l.config.colorColumn){d.on("click",(a=>l.onLegendClick(t,o,"colorTW",e,a,s)));f.on("click",(a=>l.onLegendClick(t,o,"colorTW",e,a,s)))}i+=a}}}if(c?.sampleCount>0){i=i+a;const e=o.append("g");e.append("text").attr("x",n).attr("y",i).text("Reference").style("font-weight","bold");i=i+a;let r=l.symbols[0].size(64)();const p=o.append("g");p.append("path").attr("transform",(t=>`translate(${n}, ${i})`)).style("fill",c.color).attr("d",r).style("stroke",s(c.color).darker());p.on("click",(e=>l.onLegendClick(t,o,"colorTW","Ref",e,c)));const d=o.append("g").append("text").attr("x",n+10).attr("y",i).text(`n=${c.sampleCount}`).style("text-decoration",!l.settings.showRef?"line-through":"none").attr("alignment-baseline","middle");d.on("click",(e=>l.onLegendClick(t,o,"colorTW","Ref",e,c)))}}if(l.config.scaleDotTW){t.scaleG=o.append("g").attr("transform",`translate(${n},${l.legendHeight-100})`);l.drawScaleDotLegend(t)}if(l.config.shapeTW){n=!l.config.colorTW?0:l.config.colorTW.term.type=="geneVariant"&&!l.config.colorTW.q.groupsetting.inuse?300:200;i=60;r=`${f(l.config.shapeTW.term.name)}`;if(l.config.shapeTW.term.type=="geneVariant"&&!l.config.shapeTW.q.groupsetting.inuse)l.renderGeneVariantLegend(t,n,i,o,l.config.shapeTW,"shape",t.shapeLegend);else{const e=o.append("g");e.append("text").attr("x",n).attr("y",i).text(r).style("font-weight","bold");i+=a+10;const c="gray";for(const[r,p]of t.shapeLegend){if(r=="Ref")continue;const d=p.shape%l.symbols.length;const f=l.symbols[d].size(pt)();const g=r;const m=p.sampleCount;const h=l.config.shapeTW.q.hiddenValues?r in l.config.shapeTW.q.hiddenValues:false;const u=e.append("g");u.append("path").attr("transform",(t=>`translate(${n}, ${i})`)).style("fill",c).attr("d",f).style("stroke",s(c).darker());u.append("text").attr("x",n+10).attr("y",i).text(`${g}, n=${m}`).style("text-decoration",h?"line-through":"none").attr("alignment-baseline","middle");i+=a;u.on("click",(e=>l.onLegendClick(t,o,"shapeTW",r,e,p)))}}}function f(t,e=false){if(t.length>25&&!e)t=t.slice(0,25)+"...";return t}function g(e,a,n,i,r,c=false){const p=Math.min(5*40/t.colorLegend.size,5);const d=e.append("g");d.append("circle").attr("cx",i).attr("cy",r).attr("r",p).style("fill",a.color).style("stroke",s(a.color).darker());if(!l.config.colorColumn)d.on("click",(e=>l.onLegendClick(t,o,"colorTW",key,e,a)));const f=e.append("g");f.append("text").attr("name","sjpp-scatter-legend-label").attr("x",i+10).attr("y",r).text(`${n}, n=${a.sampleCount}`).style("text-decoration",c?"line-through":"none").attr("alignment-baseline","middle");return[d,f]}};l.drawScaleDotLegend=function(e){const s=e.scaleG;s.selectAll("*").remove();const a=Math.sqrt(l.settings.minDotSize)/2*l.zoom;const o=Math.sqrt(l.settings.maxDotSize)/2*l.zoom;const i=30*l.zoom;const r=l.settings.scaleDotOrder;const c=s.append("g");c.append("text").text(l.config.scaleDotTW.term.name).style("font-weight","bold");let p=e.scaleMin;if(p%1!=0)p=p.toFixed(1);let d=e.scaleMax;if(d%1!=0)d=d.toFixed(1);const f=s.append("g").attr("transform",`translate(${40},${30})`);const g=5+p.toString().length*7;const m=20;f.append("circle").attr("r",r=="Ascending"?a:o).style("fill","#aaa").style("stroke","#aaa").attr("transform",`translate(0,${m})`);f.append("text").attr("x",r=="Ascending"?-a-g:-o-g).attr("y",m+5).style("font-size",".8em").attr("text-anchor","start").text(p);const h=s.append("g");h.attr("transform",`translate(${i+40},${m+30})`).append("circle").style("fill","#aaa").style("stroke","#aaa").attr("r",r=="Ascending"?o:a);h.append("text").attr("x",r=="Ascending"?o+10:a+10).attr("y",5).style("font-size",".8em").text(d);if(r=="Ascending"){f.append("line").attr("x1",0).attr("y1",m-a).attr("x2",i).attr("y2",m-o).style("stroke","#aaa");f.append("line").attr("x1",0).attr("y1",m+a).attr("x2",i).attr("y2",m+o).style("stroke","#aaa")}else{f.append("line").attr("x1",0).attr("y1",m-o).attr("x2",i).attr("y2",m-a).style("stroke","#aaa");f.append("line").attr("x1",0).attr("y1",m+o).attr("x2",i).attr("y2",m+a).style("stroke","#aaa")}s.append("rect").attr("width",110*l.zoom).attr("height",50).attr("fill","transparent").on("click",(e=>{const s=new n({padding:"3px"});const a=s.d;a.append("label").text("Min:");const o=a.append("input").attr("type","number").attr("min","1").attr("max","100").style("width","50px").attr("value",l.settings.minDotSize).on("change",(()=>{let t=parseFloat(o.node().value);if(t<mt){t=mt;o.node().value=mt}l.config.settings.sampleScatter.minDotSize=t;l.app.dispatch({type:"plot_edit",id:l.id,config:l.config})}));a.append("label").text("Max:");const i=a.append("input").attr("type","number").attr("min","1").attr("max","1000").style("width","50px").attr("value",l.settings.maxDotSize).on("change",(()=>{let t=parseFloat(i.node().value);if(t>ht){t=ht;i.node().value=ht}l.config.settings.sampleScatter.maxDotSize=t;l.app.dispatch({type:"plot_edit",id:l.id,config:l.config})}));const c=s.d.append("div");c.append("label").text("Order: ");const p=["Ascending","Descending"];c.selectAll("input").data(p).enter().append("div").style("display","inline-block").each(d);function d(e){const s=t(this);const a=s.append("input").attr("type","radio").attr("id",e).attr("value",e).property("checked",(t=>t==r));s.append("label").text(e).attr("for",e);a.on("change",(t=>{l.config.settings.sampleScatter.scaleDotOrder=t.target.value;c.selectAll("input").nodes().find((e=>e.value!=t.target.value)).checked=false;l.app.dispatch({type:"plot_edit",id:l.id,config:l.config})}))}s.showunder(e.target)}))};l.editColor=function(t,e,a){const o=l.config[e][t.id];const i=new n({padding:"3px"});const r=i.clear().d.append("Label").text("Color:").append("input").attr("type","color").attr("value",s(o).formatHex()).on("change",(()=>{const s=r.node().value;l.changeGradientColor(t,e,a,s);i.hide()}));i.showunder(a.node(),false)};l.changeGradientColor=function(t,a,o,n){const i=s(n).formatHex();l.config[a][t.id]=i;o.style("fill",i);t.colorGenerator=e().range([l.config.startColor[t.id],l.config.stopColor[t.id]]);l.startGradient[t.id].attr("stop-color",l.config.startColor[t.id]);l.stopGradient[t.id].attr("stop-color",l.config.stopColor[t.id]);l.app.dispatch({type:"plot_edit",id:l.id,config:l.config})};l.renderGeneVariantLegend=function(t,e,a,o,n,c,p){const d=125;const f=n.term.name.length>25?n.term.name.slice(0,25)+"...":n.term.name;let g=`${f}, n=${t.cohortSamples.length}`;const m=o.append("g").style("font-size","0.9em");m.append("text").attr("id","legendTitle").attr("x",e).attr("y",a).text(g).style("font-weight","bold");e+=d;const h=t.cohortSamples[0]["cat_info"][c];for(const[f,g]of h.entries()){a+=25;const f=g.dt;const h=i[g.origin]?.label;const u=h?`${h[0]} ${r[f]}`:r[f];m.append("text").attr("x",e).attr("y",a-25).text(h?`${h} ${r[f]}`:r[f]).style("font-weight","bold");for(const[i,r]of p){if(i=="Ref")continue;if(!i.includes(u))continue;const p=i.split(", ")[0];const f=m.append("g");if(c=="shape"){const t=r.shape%l.symbols.length;f.append("path").attr("transform",(t=>`translate(${e-d}, ${a-5})`)).style("fill","gray").attr("d",l.symbols[t].size(64)()).style("stroke",s("gray").darker())}else{f.append("circle").attr("cx",e-d).attr("cy",a-5).attr("r",5).style("fill",r.color).style("stroke",s(r.color).darker());f.on("click",(e=>l.onLegendClick(t,o,"colorTW",i,e,r)))}const g=n.q.hiddenValues?i in n.q.hiddenValues:false;m.append("g").append("text").attr("x",e-d+10).attr("y",a).attr("name","sjpp-scatter-legend-label").style("text-decoration",g?"line-through":"none").text(p).on("click",(e=>l.onLegendClick(t,m,c=="shape"?"shapeTW":"colorTW",i,e,r)));const h=i.split(", ")[1];if(i.includes(u))m.append("text").attr("x",e).attr("y",a).text(`${r.sampleCount}${r.hasOrigin?h[0]:""}`);a+=25}}return a}}var ft=Object.freeze({__proto__:null,setRenderers:dt});function gt(t,e){const s=new n({padding:"5px"});const a=t.d.append("div").style("padding","5px");a.append("div").html("Select variables to plot").style("font-size","0.9rem");let o,i;const r=a.append("div").style("padding-top","5px").html(" X ");const l=r.append("div").attr("class","sja_filter_tag_btn add_term_btn").text("+").on("click",(t=>{f(l,(t=>o=t))}));const c=a.append("div").html(" Y ");const p=c.append("div").attr("class","sja_filter_tag_btn add_term_btn").text("+").on("click",(t=>{f(p,(t=>i=t))}));const d=a.append("div").style("float","right").style("padding","5px").insert("button").text("Submit").property("disabled",true).on("click",(()=>{e.dispatch({type:"plot_create",config:{chartType:"sampleScatter",term:{term:o,q:{mode:"continuous"}},term2:{term:i,q:{mode:"continuous"}},name:"Dynamic scatter"}});t.hide()}));function f(a,n){const r={tree:{usecase:{detail:"numeric",target:"sampleScatter"}}};const l=[];if(o)l.push(o);if(i)l.push(i);x(a,(t=>{n(t);s.hide();a.selectAll("*").remove();a.text(t.name);if(o!=null&&i!=null)d.property("disabled",false)}),e,t,r,false,false,l)}}const mt=9;const ht=300;class ut{constructor(){this.type="sampleScatter";this.lassoOn=false;const t=[z,A,W,O,k,M,F,L,K,E,J,Y,R];this.symbols=t.map((t=>D(t)));this.zoom=1;this.startGradient={};this.stopGradient={}}async init(e){const s=this.opts.holder.insert("div").style("display","inline-block");const a=s.insert("div").style("display","inline-block").attr("class","pp-termdb-plot-controls");this.mainDiv=this.opts.holder.insert("div").style("display","inline-block").style("vertical-align","top");const o=80;this.axisOffset={x:o,y:30};this.dom={header:this.opts.header,loadingDiv:this.opts.holder.append("div").style("position","absolute").style("left","45%").style("top","60%"),tip:new n({padding:"0px"}),tooltip:new n({padding:"2px",offsetX:10,offsetY:0}),controlsHolder:a,toolsDiv:s.insert("div")};this.settings={};if(this.dom.header)this.dom.header.html("Scatter Plot");T(this);dt(this);document.addEventListener("scroll",(t=>this?.dom?.tooltip?.hide()));t(".sjpp-output-sandbox-content").on("scroll",(t=>this.dom.tooltip.hide()))}getState(t){const e=t.plots.find((t=>t.id===this.id));if(!e){throw`No plot with id='${this.id}' found. Did you set this.id before this.api = getComponentApi(this)?`}const s=v(t);return{config:e,termfilter:t.termfilter,supportedChartTypes:t.termdbConfig.supportedChartTypes[s],matrixplots:t.termdbConfig.matrixplots,vocab:t.vocab,termdbConfig:t.termdbConfig,groups:b(t)}}getDataRequestOpts(){const t=this.config;const e=[];if(t.term)e.push(t.term);if(t.term2)e.push(t.term2);const s={name:t.name,colorTW:t.colorTW,filter:this.getFilter(),coordTWs:e};if(t.colorColumn)s.colorColumn=t.colorColumn;if(t.shapeTW)s.shapeTW=t.shapeTW;if(t.scaleDotTW){if(!t.scaleDotTW.q)t.scaleDotTW.q={};t.scaleDotTW.q.mode="continuous";s.scaleDotTW=t.scaleDotTW}if(t.term0)s.divideByTW=t.term0;return s}async main(){this.config=JSON.parse(JSON.stringify(this.state.config));if(this.config.settings.sampleScatter.regression!=="None"&&this.config.term0){if(this.charts)for(const t of this.charts)t.chartDiv.selectAll("*").remove();this.dom.loadingDiv.style("display","block").html("Processing data...")}if(this.dom.header)this.dom.header.html(this.config.name+` <span style="opacity:.6;font-size:.7em;margin-left:10px;">SCATTER PLOT</span>`);c(this.settings,this.config.settings.sampleScatter);const t=this.getDataRequestOpts();if(t.coordTWs.length==1)return;const e=await this.app.vocabApi.getScatterData(t);if(e.error)throw e.error;this.charts=[];let s=0;for(const[t,a]of Object.entries(e)){if(!Array.isArray(a.samples))throw"data.samples[] not array";if(a.isLast)this.createChart(t,a,s);else this.createChart(t,a,0)}this.initRanges();this.is3D=this.config.term&&this.config.term0?.q.mode=="continuous";if(!this.config.colorColumn)await this.setControls();await this.processData();this.render();this.dom.loadingDiv.style("display","none");if(!this.is3D)this.setTools();this.dom.tip.hide()}createChart(t,e,s){const a=e.samples.filter((t=>"sampleId"in t));if(a.length>1e4)this.is2DLarge=true;const o=new Map(e.colorLegend);const n=new Map(e.shapeLegend);this.charts.splice(s,0,{id:t,data:e,cohortSamples:a,colorLegend:o,shapeLegend:n})}initRanges(){if(this.charts.length>1){const t=[];for(const e of this.charts)t.push(...e.data.samples);const e=t[0];const[s,a,o,n,i,r,l,c]=t.reduce(((t,e)=>[e.x<t[0]?e.x:t[0],e.x>t[1]?e.x:t[1],e.y<t[2]?e.y:t[2],e.y>t[3]?e.y:t[3],e.z<t[4]?e.z:t[4],e.z>t[5]?e.z:t[5],"scale"in e?e.scale<t[6]?e.scale:t[6]:Number.POSITIVE_INFINITY,"scale"in e?e.scale>t[7]?e.scale:t[7]:Number.NEGATIVE_INFINITY]),[e.x,e.x,e.y,e.y,e.z,e.z,e.scale,e.scale]);for(const t of this.charts){t.xMin=s;t.xMax=a;t.yMin=o;t.yMax=n;t.zMin=i;t.zMax=r;t.scaleMin=l;t.scaleMax=c}}else for(const t of this.charts){if(t.data.samples.length==0)return;const e=t.data.samples[0];const[s,a,o,n,i,r,l,c]=t.data.samples.reduce(((t,e)=>[e.x<t[0]?e.x:t[0],e.x>t[1]?e.x:t[1],e.y<t[2]?e.y:t[2],e.y>t[3]?e.y:t[3],e.z<t[4]?e.z:t[4],e.z>t[5]?e.z:t[5],"scale"in e?e.scale<t[6]?e.scale:t[6]:Number.POSITIVE_INFINITY,"scale"in e?e.scale>t[7]?e.scale:t[7]:Number.NEGATIVE_INFINITY]),[e.x,e.x,e.y,e.y,e.z,e.z,e.scale,e.scale]);t.xMin=s;t.xMax=a;t.yMin=o;t.yMax=n;t.zMin=i;t.zMax=r;t.scaleMin=l;t.scaleMax=c}}async setControls(){this.dom.controlsHolder.selectAll("*").remove();const t=this.charts[0]?.data.samples.find((t=>!("sampleId"in t)))||false;const e={type:"term",configKey:"scaleDotTW",chartType:"sampleScatter",usecase:{target:"sampleScatter",detail:"numeric"},title:"Scale sample by term value",label:"Scale by",vocabApi:this.app.vocabApi,numericEditMenuVersion:["continuous"]};const s={type:"term",configKey:"shapeTW",chartType:"sampleScatter",usecase:{target:"sampleScatter",detail:"shapeTW"},title:"Categories to assign a shape",label:"Shape",vocabApi:this.app.vocabApi};const a={label:"Sample area",type:"number",chartType:"sampleScatter",settingsKey:"size",title:"Sample area, in square pixels",min:0};const o={label:"Min area",type:"number",chartType:"sampleScatter",settingsKey:"minDotSize",title:"Minimum area, in square pixels",min:mt,max:ht};const n={label:"Max area",type:"number",chartType:"sampleScatter",settingsKey:"maxDotSize",title:"Maximum area, in square pixels",min:mt,max:ht};const i={label:"Scale order",type:"radio",chartType:"sampleScatter",settingsKey:"scaleDotOrder",options:[{label:"Ascending",value:"Ascending"},{label:"Descending",value:"Descending"}]};const r={label:"Reference size",type:"number",chartType:"sampleScatter",settingsKey:"refSize",title:"It represents the area of the reference symbol in square pixels",min:0};const l={boxLabel:"Visible",label:"Show axes",type:"checkbox",chartType:"sampleScatter",settingsKey:"showAxes",title:`Option to show/hide plot axes`};const c=[{type:"term",configKey:"colorTW",chartType:"sampleScatter",usecase:{target:"sampleScatter",detail:"colorTW"},title:"Categories to color the samples",label:"Color",vocabApi:this.app.vocabApi,numericEditMenuVersion:["continuous","discrete"]},{label:"Opacity",type:"number",chartType:"sampleScatter",settingsKey:"opacity",title:"It represents the opacity of the symbols",min:0,max:1,step:.1},{label:"Chart width",type:"number",chartType:"sampleScatter",settingsKey:"svgw"},{label:"Chart height",type:"number",chartType:"sampleScatter",settingsKey:"svgh"}];if(this.config.sampleCategory){const t=Object.values(this.config.sampleCategory.tw.term.values).map((t=>({label:t.label||t.key,value:t.key})));if(this.config.sampleCategory.order)t.sort(((t,e)=>{const s=this.config.sampleCategory.order.indexOf(t.value);const a=this.config.sampleCategory.order.indexOf(e.value);if(s<a)return-1;return 1}));if(!this.settings.sampleCategory)this.settings.sampleCategory=this.config.sampleCategory.defaultValue||"";t.push({label:"All",value:""});const e={label:"Sample type",type:"dropdown",chartType:"sampleScatter",settingsKey:"sampleCategory",options:t};c.push(e)}if(!this.is2DLarge){c.unshift({type:"term",configKey:"term0",chartType:"sampleScatter",usecase:{target:"sampleScatter",detail:"term0"},title:"Categories to divide by",label:this.config.term0?.q?.mode=="continuous"?"Z":"Divide by",vocabApi:this.app.vocabApi,numericEditMenuVersion:this.app.hasWebGL?.()?["discrete","continuous"]:["discrete"],processInput:t=>{if(t?.term.type=="integer"||t?.term.type=="float")t.q={mode:"continuous"}}})}else{c.push({label:"Sample size",type:"number",chartType:"sampleScatter",settingsKey:"threeSize",title:"Sample size",min:0,max:1,step:.001}),c.push({label:"Field of Vision",type:"number",chartType:"sampleScatter",settingsKey:"threeFOV",title:"Field of Vision",min:50,max:90,step:1})}if(this.config.term){c.unshift(...[{type:"term",configKey:"term",chartType:"sampleScatter",usecase:{target:"sampleScatter",detail:"numeric"},title:"X coordinate to plot the samples",label:"X",vocabApi:this.app.vocabApi,menuOptions:"!remove",numericEditMenuVersion:["continuous"]},{type:"term",configKey:"term2",chartType:"sampleScatter",usecase:{target:"sampleScatter",detail:"numeric"},title:"Y coordinate to plot the samples",label:"Y",vocabApi:this.app.vocabApi,menuOptions:"!remove",numericEditMenuVersion:["continuous"]}]);if(!this.is3D){c.splice(4,0,s);c.splice(5,0,e);if(this.config.scaleDotTW){c.splice(6,0,o);c.splice(7,0,n);c.splice(8,0,i);if(t)c.splice(9,0,r)}else{c.splice(6,0,a);if(t)c.splice(7,0,r)}c.push({label:"Show regression",type:"dropdown",chartType:"sampleScatter",settingsKey:"regression",options:[{label:"None",value:"None"},{label:"Lowess",value:"Lowess"},{label:"Polynomial",value:"Polynomial"}]})}else{c.push({label:"Chart depth",type:"number",chartType:"sampleScatter",settingsKey:"svgd"});c.push({label:"Field of vision",title:"Camera field of view, in degrees",type:"number",chartType:"sampleScatter",settingsKey:"fov"})}c.push(l);c.push({label:"Default color",type:"color",chartType:"sampleScatter",settingsKey:"defaultColor"})}else if(!this.is2DLarge){c.splice(2,0,s);c.splice(3,0,e);if(this.config.scaleDotTW){c.splice(4,0,o);c.splice(5,0,n);c.splice(6,0,i);if(t)c.splice(7,0,r)}else{c.splice(4,0,a);if(t)c.splice(5,0,r)}c.push(l)}this.components={controls:await f({app:this.app,id:this.id,holder:this.dom.controlsHolder,inputs:c})};this.components.controls.on("downloadClick.scatter",(()=>{if(this.is2DLarge||this.is3D){const t=this.canvas.toDataURL("image/png");yt(t)}else for(const t of this.charts)w(t.svg,"scatter.svg",this.opts.holder.node())}))}getFilter(){const t={type:"tvslst",in:true,join:"and",lst:[]};const e="sampleCategory"in this.settings?this.settings.sampleCategory:this.config.sampleCategory?.defaultValue;if(e){const s=this.config.sampleCategory.tw;t.lst.push({type:"tvs",tvs:{term:s.term,values:[{key:e}]}})}const s=C([this.state.termfilter.filter,t]);return s}}function yt(t){const e=document.createElement("a");e.setAttribute("download","image");document.body.appendChild(e);e.click();e.remove();e.href=t;e.click();e.remove()}async function xt(t,e){try{if(t.colorTW)await d(t.colorTW,e.vocabApi);if(t.shapeTW)await d(t.shapeTW,e.vocabApi);if(t.term)await d(t.term,e.vocabApi);if(t.term2)await d(t.term2,e.vocabApi);if(t.term0)await d(t.term0,e.vocabApi);if(t.scaleDotTW)await d(t.scaleDotTW,e.vocabApi);if(t.sampleCategory)await d(t.sampleCategory.tw,e.vocabApi);let s=Tt();if(t.settings)c(s,t.settings);if(!t.term&&!t.term2)s.showAxes=false;const a={groups:[],settings:{controls:{isOpen:false},sampleScatter:s}};const o=c(a,t);if(o.term0?.q?.mode=="continuous"&&!e.hasWebGL())throw"Can not load Z/Divide by term in continuous mode as WebGL is not supported";return o}catch(t){console.log(t);throw`${t} [sampleScatter getPlotConfig()]`}}const vt=l(ut);const bt=vt;function St(t,e){const s=t.append("div");if(e.state.termdbConfig.scatterplots)for(const t of e.state.termdbConfig.scatterplots){s.append("div").attr("class","sja_menuoption sja_sharp_border").text(t.name).on("click",(()=>{let s={chartType:"sampleScatter",name:t.name};if(t.sampleCategory)s.sampleCategory={tw:JSON.parse(JSON.stringify(t.sampleCategory.tw)),order:t.sampleCategory.order,defaultValue:t.sampleCategory.defaultValue};if(t.sampleType)s.sampleType=t.sampleType;if(t.colorTW)s.colorTW=JSON.parse(JSON.stringify(t.colorTW));else if(t.colorColumn)s.colorColumn=JSON.parse(JSON.stringify(t.colorColumn));if("shapeTW"in t)s.shapeTW=JSON.parse(JSON.stringify(t.shapeTW));if(t.settings)s.settings=JSON.parse(JSON.stringify(t.settings));e.app.dispatch({type:"plot_create",config:s});e.dom.tip.hide()}))}s.append("div");if(!e.state.termdbConfig.hiddenChartTypes?.includes("dynamicScatter"))gt(e.dom.tip,e.app)}function Tt(){return{size:16,minDotSize:9,maxDotSize:144,scaleDotOrder:"Ascending",refSize:9,svgw:500,svgh:500,svgd:500,axisTitleFontSize:16,showAxes:true,showRef:true,opacity:.8,defaultColor:p,regression:"None",fov:50,threeSize:.002,threeFOV:70}}async function wt(t,e,s){const a={holder:t,state:{vocab:e.vocab,plots:[{chartType:"sampleScatter",subfolder:"plots",name:s.name,colorTW:s.colorTW,sampleType:s.sampleType,sampleCategory:{tw:JSON.parse(JSON.stringify(s.sampleCategory.tw)),order:s.sampleCategory.order,defaultValue:s.sampleCategory.defaultValue}}]}};const o=await import("./plot.app-c841507a.js");await o.appInit(a)}var Ct=Object.freeze({__proto__:null,minDotSize:mt,maxDotSize:ht,downloadImage:yt,getPlotConfig:xt,scatterInit:vt,componentInit:bt,makeChartBtnMenu:St,getDefaultScatterSettings:Tt,renderScatter:wt});export{Ct as a,Tt as g,ft as s};
|
package/dist/{sampleScatter.interactivity-e9c30652.js → sampleScatter.interactivity-cfa3451d.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{az as e,M as t,ae as s,q as o,ac as i,aP as a,S as n,aQ as r,E as l,x as p,a1 as d}from"./app-f91922b4.js";import{r as c}from"./table-d6c411fd.js";import{a as h,b as m,c as u}from"./FilterRxComp-0e75dd8d.js";import{c as f,g as y,r as g,a as b,b as v,d as x,e as w,f as S,o as k,h as C}from"./recover-a08c8d01.js";import{t as _}from"./downloadTextfile-5723af95.js";import{searchSampleInput as T}from"./sampleView-d6a91293.js";class D{constructor(e){this.type="search";N(this);j(this)}async init(e){this.dom={holder:this.opts.holder,holderNode:this.opts.holder.node(),tip:new t({padding:"5px"})};this.initUI()}reactsTo(e){return e.type.startsWith("search")||e.type.startsWith("cohort")}getState(e){return{cohortStr:e.activeCohort==-1||!e.termdbConfig.selectCohort?"":e.termdbConfig.selectCohort.values[e.activeCohort].keys.slice().sort().join(","),search:e.search,nav:e.nav}}async main(){this.dom.holder.style("display",this.state.search.isVisible&&this.state.nav.header_mode!="only_buttons"?"inline-block":"none")}async doSearch(e){if(!e){this.clear({hide:true});this.bus.emit("postSearch",[]);return}const t=await this.app.vocabApi.findTerm(e,this.state.cohortStr,this.opts.usecase);if(!t.lst||t.lst.length==0){this.noResult()}else{this.showTerms(t)}this.bus.emit("postSearch",t)}}const A=e(D);function N(e){e.initUI=()=>{e.dom.holder.style("display",e.search&&e.search.isVisible==false?"none":"inline-block");e.dom.input=e.dom.holder.style("text-align","center").append("input").attr("type","search").attr("class","tree_search").attr("placeholder","Search").style("width","180px").style("display","block").on("input",s.debounce(e.onInput,300));e.dom.resultDiv=e.dom.tip.d.style("border-left",e.opts.resultsHolder?"":"solid 1px rgb(133,182,225)").style("padding-left","5px")};e.noResult=()=>{e.clear();e.dom.resultDiv.append("div").text("No match").style("padding","3px 3px 3px 0px").style("opacity",.5)};e.showTerms=t=>{if(e.opts.disable_terms)t.lst.forEach((t=>{if(t.disabled)e.opts.disable_terms.push(t)}));e.clear({hide:!t.lst.length});if(t.lst.length){e.dom.resultDiv.append("table").selectAll().data(t.lst).enter().append("tr").each(e.showTerm)}};e.showTerm=function(t){const s=o(this);const i=s.append("td").text(t.name);if(t.type){i.style("cursor","pointer").attr("class","sja_menuoption").on("click",(()=>{e.app.dispatch({type:"plot_create",config:{chartType:t.type=="survival"?"survival":"summary",term:{term:t}}});e.clear({hide:true})}))}else{i.style("padding","5px 10px").style("opacity",.5)}s.append("td").text((t.__ancestorNames||[]).join(" > ")).style("opacity",.5).style("font-size",".7em")};e.clear=(t={})=>{e.dom.tip.clear();if(t.hide)e.dom.tip.hide();else e.dom.tip.showunder(e.dom.holderNode)}}function j(e){e.onInput=async()=>{const t=e.dom.input.property("value");try{await e.doSearch(t)}catch(t){e.clear();i(e.dom.resultDiv,"Error: "+(t.message||t));if(t.stack)console.log(t.stack)}}}class O{constructor(){this.type="sessionBtn";this.route="termdb";this.embedderOrigin=window.location.origin;this.hostURL=sessionStorage.getItem("hostURL")||this.embedderOrigin}async init(e){const s=new t({padding:"0px"});this.dom={button:this.opts.button,tip:s};this.dom.button.on("click",(()=>{this.dom.tip.clear();this.showMenu()}));this.dslabel=e.vocab.dslabel;this.savedSessions=JSON.parse(localStorage.getItem("savedMassSessions")||`{}`);this.requiredAuth=e.termdbConfig?.requiredAuth?.find((e=>e.route==this.route&&e.type=="jwt"))}async showMenu(){this.dom.tip.clear().d.style("padding",0);const e=[{label:`Open`,title:"Recover a saved session",callback:this.open},{label:`Save`,title:"Save the current view",callback:this.save},{label:`Share`,title:"Create a URL link to share this view",callback:this.getSessionUrl}];if(!this.serverCachedSessions)await this.setServerCachedSessions();if(Object.keys(this.savedSessions).length||Object.keys(this.serverCachedSessions).length){e.push({label:`Delete`,title:"Delete a saved session",callback:this.delete})}this.dom.tip.clear().d.selectAll(".sja_menuoption sja_sharp_border").data(e).enter().append("div").attr("class","sja_menuoption sja_sharp_border").attr("title",(e=>e.title)).html((e=>e.label)).on("click",((e,t)=>{this.dom.tip.clear().d.style("padding","10px");this.showBackBtn();t.callback.call(this)}));this.dom.tip.showunder(this.dom.button.node())}async open(){const e=`sjpp-session-open-radio-`+Math.random().toString().slice(-6);this.dom.tip.d.append("div").style("display","none").style("padding","3px 9px").html(`\n\t\t\t<b>Open in</b>\n\t\t\t<label>\n\t\t\t\t<input type='radio' name='${e}' value='new' style='margin-right: 0; vertical-align: bottom'/>\n\t\t\t\t<span>a new tab</span>\n\t\t\t</label>\n\t\t\t<label style='margin-left: 5px'>\n\t\t\t\t<input type='radio' name='${e}' value='current' checked=checked style='margin-right: 0; vertical-align: bottom'/>\n\t\t\t\t<span>current tab</span>\n\t\t\t</label>\n\t\t`);const t=await this.listSessions({trClickHandler:async(t,s)=>{const{loc:o,id:i}=s;if(!i)return;if(o.includes("browser")){this.sessionName=i;const t=this.savedSessions[i];const s=this.dom.tip.d.node().querySelector(`[name="${e}"]:checked`).value;if(s=="current"){this.app.dispatch({type:"app_refresh",state:t})}else if(window.location.origin==this.hostURL){window.open(`/?mass-session-id=${i}&src=browser`)}else{if(t.embedder)a({state:t});else{const{protocol:e,host:s,search:o,origin:i,href:n}=window.location;const r={protocol:e,host:s,search:o,origin:i,href:n};a({state:Object.assign({embedder:r},t)})}}this.dom.tip.hide()}else if(o=="server"){const t=this.app.vocabApi.mayGetAuthHeaders(this.route);const s={id:i,route:this.route,dslabel:this.dslabel,embedder:window.location.hostname};const o=await n(`/massSession?`,{headers:t,body:s});if(!o.state)throw o.error||"unable to get the cached session from the server";this.savedSessions[i]=o.state;const r=this.dom.tip.d.node().querySelector(`[name="${e}"]:checked`).value;if(r=="current"){this.app.dispatch({type:"app_refresh",state:o.state})}else if(window.location.origin==this.hostURL){window.open(`/?mass-session-id=${i}&src=cred&dslabel=${this.dslabel}&route=${this.route}`)}else{a(o)}this.dom.tip.hide()}}});t.headtr.select("th").html("Open from");const s=t.tbody.insert("tr","tr");s.append("td").style("text-align","center").style("padding","3px 9px").html("Local file");const o=s.append("td").style("text-align","left").append("label");o.append("span").style("padding","3px 9px").style("text-decoration","underline").style("cursor","pointer").html("Choose File");o.append("input").attr("type","file").attr("placeholder","file name").style("opacity",0).style("width","0.1px").style("height","0.1px").style("position","absolute").on("change",(async()=>{const t=event.target.files.item(0);const s=await t.text();let o=t.name;if(this.savedSessions[o]){o=prompt(`Leave as-is to overwrite a session with the same name, or enter a different session name.`,o)}this.sessionName=o;const i=JSON.parse(s);this.savedSessions[o]=i;localStorage.setItem("savedMassSessions",JSON.stringify(this.savedSessions));const n=this.dom.tip.d.node().querySelector(`[name="${e}"]:checked`).value;if(n=="current"){this.app.dispatch({type:"app_refresh",state:i})}else if(window.location.origin==this.hostURL){window.open(`/?mass-session-id=${o}&src=browser`)}else{if(i.embedder)a({state:i});else{const{protocol:e,host:t,search:s,origin:o,href:n}=window.location;const r={protocol:e,host:t,search:s,origin:o,href:n};a({state:Object.assign({embedder:r},i)})}}this.dom.tip.hide()}))}async listSessions(e={}){const t=this.dom.tip.d.append("table").attr("class","sjpp-controls-table");const s=t.append("thead").append("tr");s.selectAll("th").data(["Cache Location","Session ID"]).enter().append("th").style("text-align",((e,t)=>t===0?"center":"left")).style("padding","3px 9px").html((e=>e));const o=Object.keys(this.savedSessions).map((e=>({loc:"browser",id:e})));if(!this.serverCachedSessions)await this.setServerCachedSessions();o.push(...this.serverCachedSessions.map((e=>({loc:"server",id:e}))));const i=t.append("tbody");const a=i.selectAll("tr").data(o).enter().append("tr").on("click",e.trClickHandler||null);a.selectAll("td").data((e=>[e,e])).enter().append("td").style("text-align",((e,t)=>t===0?"center":"left")).style("padding","3px 9px").style("cursor","pointer").html(((e,t)=>t===0?e.loc:e.id));if(!this.serverCachedSessions.length&&this.requiredAuth&&!this.app.vocabApi.hasVerifiedToken()){t.append("tbody").append("tr").selectAll("td").data(["server","requires sign-in"]).enter().append("td").style("text-align",((e,t)=>t===0?"center":"left")).style("padding","3px 9px").html((e=>e))}return{table:t,headtr:s,tbody:i,trs:a}}async setServerCachedSessions(){const e=this.app.getState();this.requiredAuth=e.termdbConfig?.requiredAuth?.find((e=>e.route==this.route&&e.type=="jwt"));if(!this.requiredAuth){this.serverCachedSessions=[];return}const t=this.app.vocabApi.mayGetAuthHeaders(this.route);const s={route:this.route,dslabel:this.dslabel,embedder:window.location.hostname};const o=await n("/sessionIds",{headers:t,body:s});this.serverCachedSessions=o.sessionIds||[]}async save(e){const t=this.dom.tip.d;const s=t.append("div");s.append("span").html("Save as");const o=Object.keys(this.savedSessions);if(!this.serverCachedSessions)await this.setServerCachedSessions();o.push(...this.serverCachedSessions.filter((e=>!o.includes(e))));const i=this.sessionName||"unnamed-session";const a=s.append("input").attr("type","text").attr("placeholder",i).style("width","220px").on("input",(()=>{n.selectAll("*").remove();const e=a.property("value");const t=o.filter((t=>t===e));const s=o.filter((t=>t.startsWith(e)));const i=o.filter((t=>t.includes(e)&&t!==e&&!s.includes(t)));n.selectAll("div").data([...t,...s,...i]).enter().append("div").attr("class","sja_menuoption").html((e=>e)).on("click",((e,t)=>{a.property("value",t);n.selectAll("*").remove()}))}));const n=t.append("div");const r=t.append("div");r.append("span").html("Save to ");r.append("button").style("min-width","80px").html("Browser").attr("title",`Save the session in your current browser's cache. The session can be easily recovered, but not shared among your other devices`).on("click",(()=>{this.sessionName=a.property("value")||i;this.savedSessions[this.sessionName]=this.app.getState();localStorage.setItem("savedMassSessions",JSON.stringify(this.savedSessions));this.confirmAction(`Cached '<b>${this.sessionName}</b>' in browser`)}));r.append("button").style("min-width","80px").html("File").attr("title",`Save the session into a local file. The session can be easily recoved using the 'Open from local file' option.`).on("click",(()=>{const e=a.property("value")||i;this.savedSessions[e]=this.app.getState();this.download(e);this.confirmAction(`Downloaded '<b>${e}</b>'`)}));if(this.requiredAuth){const e=this.app.vocabApi.hasVerifiedToken()?"":"Requires sign-in. ";r.append("button").style("min-width","80px").html("Server").attr("title",`${e}Save the session into a remote server. The session can be easily shared across your different devices and recovered using the 'Open from server' option.`).property("disabled",!this.app.vocabApi.hasVerifiedToken()).on("click",(async()=>{if(!this.app.vocabApi.hasVerifiedToken()){alert("Requires sign-in");return}const e=a.property("value")||i;this.savedSessions[e]=this.app.getState();const t=await this.getSessionUrl(e);if(t.id!=e)throw`error saving ${e}`;this.confirmAction(`Saved '<b>${e}</b>' on the server`)}))}}download(e=""){const t=e||this.sessionName;const s=t?.endsWith(".txt")?"":".txt";const o=`${t}${s}`;_(o,JSON.stringify(this.savedSessions[t]))}async getSessionUrl(e=""){const t=this.app.vocabApi.mayGetAuthHeaders("termdb");const s=structuredClone(this.app.getState());const{protocol:o,host:i,search:r,origin:l,href:p}=window.location;s.embedder={protocol:o,host:i,search:r,origin:l,href:p};if(e){s.__sessionFor__={route:this.route,filename:e,dslabel:this.dslabel,embedder:window.location.hostname}}const d=await n("/massSession",{headers:t,method:"POST",body:JSON.stringify(s)});if(e){return d}else{const e=`${this.hostURL}/?mass-session-id=${d.id}&noheader=1`;this.dom.tip.showunder(this.dom.button.node());const t=this.dom.tip.d.append("div").style("margin","10px");t.append("div").style("margin-bottom","12px").html(`Click the link to recover this session. Bookmark or share this link.`);const o=t.append("a").attr("href",e).attr("target","_blank").html(d.id);if(this.hostURL!=window.location.origin){o.on("click",(e=>{e.preventDefault();a({state:s},window.location.origin);return false}))}t.append("div").html(`\n\t\t\t\t\t<br>\n\t\t\t\t\t<div style="max-width: 400px; font-size: 1em; opacity:.6">\n\t\t\t\t\t<span>NOTES</span>\n\t\t\t\t\t<ul>\n\t\t\t\t\t<li>A recovered session may hide data or views to users that are not authorized to access the saved datasets or features.</li>\n\t\t\t\t\t<li>This session will be saved for ${this.opts.massSessionDuration} days.</li>\n\t\t\t\t\t</ul>\n\t\t\t\t\t</div>`);setTimeout((()=>{this.dom.button.property("disabled",false)}),1e3)}}async delete(){const e=await this.listSessions({trClickHandler:function(s){const i=this.lastChild.querySelector("input");const a=s.target==i?i.checked:!i.checked;o(this).style("text-decoration",a?"line-through":"");if(s.target!=i)i.checked=a;const n=e.table.node().querySelectorAll("input:checked");t.property("disabled",n.length?false:true)}});e.headtr.append("th").html("Delete");e.trs.each((function(e){o(this).append("td").style("text-align","center").append("input").attr("type","checkbox").attr("value",e.id)}));const t=this.dom.tip.d.append("div").style("text-align","center").append("button").html("Delete selected sessions").property("disabled",true).on("click",(async()=>{const t=e.table.node().querySelectorAll("input");const s=[];for(const e of t){if(o(e).property("checked")){const t=e.parentNode.parentNode.__data__;if(t.loc=="browser"){delete this.savedSessions[e.value]}else if(t.loc=="server"){delete this.serverCachedSessions[e.value];s.push(e.value)}else throw`unknown cache location=${t.loc}`}}localStorage.setItem("savedMassSessions",JSON.stringify(this.savedSessions));try{const e=this.app.vocabApi.mayGetAuthHeaders("termdb");const t={ids:s,route:this.route,dslabel:this.dslabel,embedder:window.location.hostname};const o=n(`/massSession?`,{method:"DELETE",headers:e,body:t})}catch(e){throw e}this.dom.tip.hide()}))}showBackBtn(){this.dom.tip.d.append("div").attr("class","sja_clbtext2").style("margin-bottom","10px").style("cursor","pointer").html(`< Session Menu`).on("click",(()=>this.showMenu()))}confirmAction(e){this.dom.tip.clear().d.append("div").html(e).transition().delay(3e3).duration(1e3).style("opacity",0);setTimeout((()=>{this.dom.tip.hide()}),3500)}}const I=e(O);let L=0;const $="_MASS_AUTOID_"+Math.random().toString().slice(-6);let W=(+new Date).toString().slice(-8);const M=new t({padding:"0px",offsetX:0,offsetY:0});M.d.style("z-index",5555);const q={top:"COHORT",mid:"NONE",btm:"",subheader:"cohort"};const R={top:"CHARTS",mid:"NONE",btm:"",subheader:"charts"};const U={top:"GROUPS",mid:"NONE",btm:"",subheader:"groups"};const E={top:"FILTER",mid:"NONE",btm:"",subheader:"filter"};function H(){return $+"_"+W++}class V{constructor(e){this.type="nav";this.instanceNum=L++;this.activeTab=0;this.activeCohort=0;this.searching=false;this.samplecounts={};this.massSessionDuration=e.massSessionDuration;this.sessionDaysLeft=e.app.opts.sessionDaysLeft||null;this.sessionId=e.app.opts.sessionId||null;B(this);G(this)}async init(e){try{this.cohortFilter=h(e.termfilter.filter,"cohortFilter");this.initUI(e);this.initCohort(e);this.components=await r({search:A({app:this.app,holder:this.dom.searchDiv,usecase:{target:"barchart",detail:"term"}}),filter:m({app:this.app,vocabApi:this.app.vocabApi,holder:this.dom.subheader.filter.append("div"),hideLabel:this.opts.header_mode==="with_tabs",emptyLabel:"+Add new filter",callback:e=>{this.app.dispatch({type:"filter_replace",filter:e})}}),charts:f({app:this.app,holder:this.dom.subheader.charts,vocab:this.opts.vocab}),groups:y({app:this.app,holder:this.dom.subheader.groups,vocab:this.opts.vocab}),recover:g({app:this.app,holder:this.dom.recoverDiv,getState:e=>e,reactsTo:e=>e.type!="plot_edit",maxHistoryLen:5}),sessionBtn:I({app:this.app,button:this.dom.saveBtn,massSessionDuration:this.opts.massSessionDuration,sessionDaysLeft:this.app.opts.sessionDaysLeft||null})});this.mayShowMessage_sessionDaysLeft()}catch(e){throw e}}reactsTo(e){if(e.type.includes("cache_termq"))return true;if(e.type.startsWith("filter"))return true;if(e.type.startsWith("cohort"))return true;if(e.type.startsWith("tab"))return true;if(e.type=="plot_create")return true;if(e.type=="plot_delete")return true;if(e.type=="app_refresh")return true;if(e.type.endsWith("_customTerm"))return true;if(e.type.endsWith("_group"))return true}getState(e){return{searching:this.searching,nav:e.nav,activeCohort:e.activeCohort,termdbConfig:e.termdbConfig,filter:e.termfilter.filter,plots:e.plots,groups:e.groups}}async main(){this.dom.tabDiv.style("display",this.state.nav.header_mode==="with_tabs"?"inline-block":"none");this.dom.tip.hide();this.activeTab=this.state.nav.activeTab;this.prevCohort=this.activeCohort;this.activeCohort=+this.state.activeCohort;this.filterUiRoot=h(this.state.filter,"filterUiRoot");this.cohortFilter=h(this.state.filter,"cohortFilter");if(this.cohortNames){this.activeCohortName=this.cohortNames[this.activeCohort];if(this.activeCohort!==-1)this.activeCohortLabel=this.state.termdbConfig.selectCohort.values[this.activeCohort].shortLabel}this.filterJSON=JSON.stringify(this.state.filter);this.cohortsData=await this.app.vocabApi.getCohortsData();if(this.state.nav.header_mode==="with_tabs"){if(!(this.activeCohortName in this.samplecounts)){this.samplecounts[this.activeCohortName]=await this.app.vocabApi.getCohortSampleCount(this.activeCohortName)}if(!(this.filterJSON in this.samplecounts)){if(!this.filterUiRoot||!this.filterUiRoot.lst.length){this.samplecounts[this.filterJSON]=this.samplecounts[this.activeCohortName]}else{const e=await this.app.vocabApi.getFilteredSampleCount(this.filterJSON);this.samplecounts[this.filterJSON]=e}}}this.updateUI()}}const z=e(V);function G(e){e.initUI=s=>{const o=e.opts.holder.append("div").style("white-space","nowrap");let i=o.append("div").style("display","inline-block").style("float","right").style("font-size","1.1em").style("margin-top","50px").text(s.termdbConfig?.title?.text||"");const a=o.append("div").style("display","none").style("vertical-align","bottom");const n=o.append("div").style("vertical-align","top").style("margin","10px").style("display","inline-block");e.opts.holder.attr("class","sjpp-nav");e.dom={holder:e.opts.holder,header:o,tabDiv:a,controlsDiv:n,searchDiv:n.append("div").style("margin","10px"),sessionDiv:n.append("div").style("display","inline-block"),recoverDiv:n.append("div").style("display","inline-block"),helpDiv:n.append("div").style("display","none"),sessionElapsedMessageDiv:n.append("div").style("display","none"),subheaderDiv:e.opts.holder.append("div").style("display","block").style("padding-top","5px").style("border-bottom","1px solid #000"),messageDiv:e.opts.holder.append("div").style("margin","30px").style("display","none"),titleDiv:i,tip:new t({padding:"5px"})};if(s.nav.header_mode=="only_buttons"){e.dom.tabDiv.style("display","none");e.dom.recoverDiv.style("display","none");i.style("margin-top","95px").style("font-size","0.9em");if(s.termdbConfig.title?.link)i.on("click",(()=>window.open(s.termdbConfig.title.link,"_blank"))).on("mouseover",(()=>i.style("cursor","pointer")))}if(e.opts.header_mode==="with_cohortHtmlSelect"){e.dom.cohortStandaloneDiv=o.append("div").style("display","inline-block").style("margin","10px").style("vertical-align","top");e.dom.cohortStandaloneDiv.append("label").html("Cohort: ");e.dom.cohortSelect=e.dom.cohortStandaloneDiv.append("select").on("change",(function(){e.app.dispatch({type:"cohort_set",activeCohort:+this.value})}));e.dom.cohortSelect.selectAll("option").data(s.termdbConfig.selectCohort.values).enter().append("option").attr("value",((e,t)=>t)).property("selected",((e,t)=>t===s.activeCohort)).html((e=>e.shortLabel))}e.dom.subheader=Object.freeze({search:e.dom.subheaderDiv.append("div").style("display","none"),groups:e.dom.subheaderDiv.append("div").style("display","none"),charts:e.dom.subheaderDiv.append("div").style("display","none"),cohort:e.dom.subheaderDiv.append("div").style("display","none"),filter:e.dom.subheaderDiv.append("div").style("display","none"),cart:e.dom.subheaderDiv.append("div").style("display","none").html("<br/>Cart feature under construction - work in progress<br/> <br/>")});e.tabs=[R,U,E];if(s.termdbConfig.selectCohort)e.tabs.unshift(q);const r=e.dom.tabDiv.append("table").style("border-collapse","collapse");r.selectAll("tr").data(["top","mid","btm"]).enter().append("tr").style("font-size",((e,t)=>t==1?"20px":"12px")).selectAll("td").data(((t,s)=>e.tabs.map(((e,o)=>({rowNum:s,key:t,colNum:o,label:e[t],subheader:e.subheader}))))).enter().append("td").style("display","none").style("width","100px").style("padding",(e=>e.rowNum===0?"12px 12px 3px 12px":"3px 12px")).style("text-align","center").style("border-left","1px solid #ccc").style("border-right","1px solid #ccc").style("color","#aaa").style("cursor","pointer").html((e=>e.label)).on("click",e.setTab);e.dom.trs=r.selectAll("tr");e.dom.tds=r.selectAll("td");e.subheaderKeys=e.tabs.map((e=>e.subheader));e.dom.saveBtn=e.dom.sessionDiv.append("button").style("margin","10px").text("Session ▼");if(e.sessionDaysLeft!=null){e.dom.fileBtn=e.dom.sessionDiv.append("button").style("margin","10px").text("Export Session").on("click",(t=>{e.getSessionFile(t)}))}const l=s.termdbConfig.helpPages;if(l){e.dom.helpBtn=e.dom.helpDiv.style("display","inline-block").append("button").style("margin","10px").html("Help ▼").on("click",(e=>{const t=e.target.getBoundingClientRect();const s=M.clear().show(t.left-0,t.top+t.height+5).d.append("div");for(const e of l){s.append("div").style("margin","15px").append("a").attr("href",e.url).attr("target","_blank").text(e.label)}}))}};e.mayShowMessage_sessionDaysLeft=()=>{if(!Number.isFinite(e.sessionDaysLeft)){return}e.dom.sessionElapsedMessageDiv.style("display","block");e.dom.remainingDaysMessage=e.dom.sessionElapsedMessageDiv.append("div").style("display","block").style("opacity","0.65").html(`<u>${e.sessionDaysLeft} days</u> left until this session is removed. Click the "Save Session" button to create a new one.`)};e.updateUI=async(t=false)=>{if(!e.dom.subheaderDiv)return;if(e.activeTab&&e.state.termdbConfig.selectCohort&&e.activeCohort==-1){e.dom.subheaderDiv.style("display","none");e.dom.messageDiv.selectAll("text").remove();e.dom.messageDiv.style("display","").text('No cohort selected. Please select a cohort in the "COHORT" tab.')}else{let s="block";if(t){s=e.dom.subheaderDiv.style("display")=="none"?"block":"none"}if(e.dom.subheaderDiv)e.dom.subheaderDiv.style("display",s);if(e.dom.messageDiv)e.dom.messageDiv.style("display","none")}const s=e.state.termdbConfig.selectCohort;e.dom.searchDiv.style("display",s&&e.activeCohort==-1||e.state.nav.header_mode=="only_buttons"?"none":"inline-block");e.dom.header.style("border-bottom",e.state.nav.header_mode==="with_tabs"?"1px solid #000":"");e.dom.tds.style("display","").style("color",(t=>t.colNum==e.activeTab?"#000":"#aaa")).style("background-color",(t=>t.colNum==e.activeTab?"#ececec":"transparent")).html((function(t,s){if(t.key=="top")return this.innerHTML;if(t.subheader=="groups"){if(t.key=="mid")return e.state.groups.length||"NONE";return""}if(t.subheader==="charts"){const s=e.state.plots.length;if(t.key=="mid")return!s?"NONE":s;else return""}else if(t.subheader==="cohort"){if(e.activeCohortName&&e.activeCohortName in e.samplecounts){return t.key=="top"?this.innerHTML:t.key=="mid"?e.activeCohortLabel:"n="+e.samplecounts[e.activeCohortName]}else{return t.key=="mid"?"NONE":this.innerHTML}}else if(t.subheader==="filter"){const s=e.filterUiRoot?e.filterUiRoot:{lst:[]};if(s.lst.length===0){return t.key==="mid"?"NONE":e.samplecounts["undefined"]?`n=${e.samplecounts["undefined"]}`:""}else{const o=e.samplecounts[e.filterJSON]!=undefined?"n="+e.samplecounts[e.filterJSON]:"";return t.key==="mid"?s.lst.length:o}}else{return t.key==="mid"?this.innerHTML:" "}}));for(const t in e.dom.subheader){e.dom.subheader[t].style("display",e.tabs[e.activeTab].subheader===t?"block":"none")}e.renderCohortsTable();if(e.opts.header_mode==="with_cohort_select"){e.dom.cohortSelect.selectAll("option").property("value",appState.activeCohort)}};e.renderCohortsTable=()=>{if(!e.dom.cohortTable)return;e.dom.cohortTable.selectAll("*").remove();const t=[{label:"Feature"}];const s=[];const o=e.cohortsData;if("error"in o)throw o.error;for(const e of o.features)s.push([{value:e.name}]);for(const e of o.cohorts){t.push({label:e.cohort?`${e.name} (${e.cohort})`:e.name});for(const[t,i]of o.features.entries()){const a=o.cfeatures.find((t=>t.idfeature===i.idfeature&&t.cohort===e.cohort));if(a)s[t].push({value:a.value})}}c({rows:s,columns:t,div:e.dom.cohortTable,showLines:false,maxHeight:"60vh"});e.dom.cohortTable.select("table").style("border-collapse","collapse");e.dom.cohortTable.selectAll(`tbody > tr > td`).style("background-color","transparent");const i=e.state.termdbConfig.selectCohort;const a=i.values[e.activeCohort].keys;let n=`tbody > tr > td:nth-child(${e.activeCohort+2})`;const r=a.length>1;if(r){n="";for(const e of a){const t=o.cohorts.map((e=>e.cohort)).indexOf(e);if(n!=="")n+=",";n+=`tbody > tr > td:nth-child(${t+2})`}}const l=e.dom.cohortTable.selectAll(n);l.style("background-color","yellow");e.dom.cohortInputs.property("checked",((t,s)=>s===e.activeCohort))};e.initCohort=async t=>{const s=t.termdbConfig.selectCohort;if(!s)return;e.dom.tds.filter((e=>e.colNum===0)).style("display","");e.cohortNames=s.values.map((e=>e.keys.slice().sort().join(",")));if(s.title){e.dom.cohortTitle=e.dom.subheader.cohort.append("h2").style("margin-left","10px").text(s.title)}if(s.description){e.dom.cohortDescription=e.dom.subheader.cohort.append("div").style("margin-left","10px").html(s.description)}if(s.prompt){e.dom.cohortPrompt=e.dom.subheader.cohort.append("div").style("margin-left","10px").style("padding-top","30px").style("padding-bottom","10px").style("font-weight","bold").text(s.prompt)}e.dom.cohortOpts=e.dom.subheader.cohort.append("div").style("margin-bottom","30px").style("margin-left","10px");e.dom.cohortOpts.append("table").selectAll("tr").data(s.values).enter().append("tr").each((function(t,s){const i=o(this);const a=i.append("td");const n="sja-termdb-cohort-"+e.instanceNum;const r=n+"-"+s;a.append("input").attr("type","radio").attr("name",n).attr("id",r).attr("value",s).property("checked",s===e.activeCohort).style("margin-right","5px").style("margin-left","0px").on("click",(()=>{e.app.dispatch({type:"cohort_set",activeCohort:s})}));a.append("label").attr("for",r).attr("colspan",2).style("cursor","pointer").html((e=>e.label));i.selectAll("td").style("max-width","600px").style("padding-bottom","10px").style("padding-right","20px").style("vertical-align","top")}));e.dom.cohortInputs=e.dom.cohortOpts.selectAll("input");e.dom.cohortTable=e.dom.subheader.cohort.append("div");if(s.asterisk){e.dom.cohortAsterisk=e.dom.subheader.cohort.append("div").style("margin-left","10px").style("padding-top","20px").style("padding-bottom","20px").style("font-size","small").text(s.asterisk)}}}function B(e){e.setTab=async(t,s)=>{if(s.colNum===e.activeTab&&!e.searching){e.prevCohort=e.activeCohort;await e.updateUI(true);if(e.bus)e.bus.emit("postRender");return}e.activeTab=s.colNum;e.searching=false;e.app.dispatch({type:"tab_set",activeTab:e.activeTab});if(e.activeTab==1&&e.activeCohort!=-1&&!e.state.plots.length){e.app.dispatch({type:"plot_create",id:H(),config:{chartType:"dictionary"}})}};e.getSessionFile=async t=>{const s=await n(`/massSession?id=${e.sessionId}`);const o=document.createElement("a");const i="data:application/json;charset=utf-8,"+encodeURIComponent(JSON.stringify(s.state));o.setAttribute("href",i);o.download=`${e.sessionId}.json`;o.click();o.remove()}}function F(e){e.showTooltip=function(t,s){const o=t.type=="click";e.onClick=o;if(o)e.searchMenu?.hide();if(!(t.target.tagName=="path"&&t.target.getAttribute("name")=="serie")){if(e.onClick&&o){e.onClick=false;e.dom.tooltip.hide();return}if(!o){e.dom.tooltip.hide()}return}const i=t.target.__data__;const a="sample"in i;let n=10;n=n/e.zoom;const r=s.data.samples.filter((t=>{const o=J(t.x,t.y,i.x,i.y,s);if(!("sampleId"in t)&&(!e.settings.showRef||e.settings.refSize==0))return false;return e.getOpacity(t)>0&&o<n}));r.sort(((t,s)=>{if(!("sampleId"in t))return 1;if(e.config.term){if(t.x<s.x)return-1;if(t.x>s.x)return 1;if(t.y<s.y)return-1;return 1}if(e.config.colorTW){if(e.config.colorTW.term.type=="categorical"){if(t.category.includes(l.WT.label)||t.category.includes(l.Blank.label))return 1}else{if(t.category<s.category)return-1;else if(t.category>s.category)return 1}}if(t.shape.includes(l.WT.label)||t.shape.includes(l.Blank.label))return 1;return-1}));if(r.length==0)return;const d=[];const c=e.config.term?true:false;const h=e=>`${e.x.toPrecision(2)},${e.y.toPrecision(2)}`;for(const e of r){const t=h(e);let s=d.find((e=>e.id==t));if(!s){s={id:t,parentId:null,samples:[e],level:1,category:null,children:[]};d.push(s);if(c){const o=C("x",e);const i={id:o,parentId:t,samples:[e],level:2,category:"X",children:[],value:o};d.push(i);s.children.push(i);const a=C("y",e);const n={id:`${a}${o}`,parent:i,parentId:o,samples:[e],level:3,category:"Y",children:[],value:a};i.children.push(n);d.push(n);s.xnode=i;s.ynode=n}}else{s.samples.push(e);if(c){s.xnode.samples.push(e);s.ynode.samples.push(e)}}}let m=c?4:2;let u=c?["y","x",""]:[""];if(e.config.colorTW)k("category",e.config.colorTW);if(e.config.shapeTW)k("shape",e.config.shapeTW,e.config.colorTW);if(e.config.scaleDotTW)k("scale",e.config.scaleDotTW,e.config.shapeTW);e.dom.tooltip.clear();const f=e.dom.tooltip.d.style("padding","5px");const y=e.state.termdbConfig.queries?.singleSampleGenomeQuantification;const g=e.state.termdbConfig.queries?.singleSampleMutation;if(r.length>1)f.append("div").style("color","#aaa").style("padding","3px").style("font-weight","bold").html(`${r.length} Samples`);const b=f.append("div").style("max-height","400px").style("overflow","scroll");if(r.length>3)b.attr("class","sjpp_show_scrollbar");const v=b.append("table").style("width","100%");const x=d.filter((e=>c?e.level==1:e.level==2));if(c)for(const e of x){if(r.length>1)v.append("tr").append("td").attr("colspan",3).style("border-top","1px solid #aaa");for(const t of e.children){S(t)}}else for(const e of x){if(r.length>1)v.append("tr").append("td").attr("colspan",3).style("border-top","1px solid #aaa");S(e)}e.dom.tooltip.show(t.clientX,t.clientY,true,false);function w(t){const s=t=="category"?e.config.colorTW:t=="shape"?e.config.shapeTW:t=="scale"?e.config.scaleDotTW:t=="X"&&e.config.term?e.config.term:t=="Y"&&e.config.term2?e.config.term2:null;return s}function S(t){const i=w(t.category);t.added=true;let n;const d=t.samples[0];if(d.category!="Ref"){let n=v.append("tr");const c=i!=null&&(i==e.config.colorTW||i==e.config.shapeTW);let h=i?i.term.name:t.category;if(r.length>1&&!a)h=h+` (${t.samples.length})`;n.append("td").style("color","#aaa").text(h);const m=n.append("td");if(c){const a=i==e.config.colorTW?e.getColor(d,s):e.config.colorTW?"gray":e.settings.defaultColor;const r=i==e.config.colorTW?s.shapeLegend.get("Ref").shape%e.symbols.length:s.shapeLegend.get(d.shape).shape%e.symbols.length;const c=e.symbols[r].size(64)();let u="black";const f=p("white").toString();if(i?.term.type=="geneVariant"&&!i.q.groupsetting.inuse){for(const e in l){const s=l[e];if(t.value.includes(s.label)){if(p(s.color).toString()!=f)u=s.color;break}}if(o){n.append("td").append("button").text("Lollipop").on("click",(async t=>{await e.openLollipop(h);e.dom.tip.hide()}))}}let y=t.value.toString().length;const g=y*9+60;const b=m.append("svg").attr("width",g).attr("height","25px");const v=b.append("g").attr("transform","translate(10, 14)");v.append("path").attr("d",c).attr("fill",a).attr("stroke","#aaa");const x=v.append("text").attr("x",12).attr("y",6).attr("font-size","0.9em");x.append("tspan").text(t.value).attr("fill",u)}else m.style("padding","2px").text(`${t.value}`)}for(const e of t.children)if(!e.added)S(e);if(t.children.length==0&&a){for(const s of t.samples){if("info"in s)for(const[e,t]of Object.entries(s.info)){n=v.append("tr");n.append("td").style("color","#aaa").text(e);n.append("td").text(t)}n=v.append("tr");n.append("td").style("color","#aaa").text("Sample");n.append("td").style("padding","2px").text(s.sample);if("sampleId"in s&&o){n.append("td").append("button").text("Sample view").on("click",(t=>e.openSampleView(s)));if(g)n.append("td").append("button").text("Disco").on("click",(async t=>e.openDiscoPlot(s)));if(y)n.append("td").append("button").text("Met Array").on("click",(async t=>e.openMetArray(s)))}}}}function k(e,t,s){for(const o of r){const i=C(e,o,t);let a="";for(const e of u)a+=C(e,o,s);const n=i+a;let r=d.find((e=>e.id==n&&e.parentId==a));let l=d.find((e=>e.id==a));if(!r){r={id:n,parentId:a,samples:[],level:m,category:e,children:[],value:i};d.push(r)}r.samples.push(o);if(l)l.children.push(r)}m++;u.unshift(e)}function C(e,t,s){if(e=="")return"";let o=t[e];if(s?.term.type=="geneVariant"&&!s.q.groupsetting.inuse){const s=o.split(", ")[0];for(const i in l){const a=l[i];if(s==a.label){const s=t.cat_info[e].find((e=>e.class==a.key)).mname;if(s)o=`${s} ${o}`}}}if(typeof o=="number"&&o%1!=0)o=o.toPrecision(2);return o}};e.openSampleView=function(t){e.dom.tooltip.hide();e.onClick=false;e.app.dispatch({type:"plot_create",id:H(),config:{chartType:"sampleView",sample:{sampleId:t.sampleId,sampleName:t.sample}}});e.dom.tip.hide()};e.openMetArray=async function(t){e.dom.tooltip.hide();e.onClick=false;t.sample_id=t.sample;for(const s in e.state.termdbConfig.queries.singleSampleGenomeQuantification){const o=d(e.opts.plotDiv);o.header.text(t.sample_id);const i=await import("./plot.ssgq-9d364d41.js");await i.plotSingleSampleGenomeQuantification(e.state.termdbConfig,e.state.vocab.dslabel,s,t,o.body.append("div").style("margin","20px"),e.app.opts.genome)}e.dom.tip.hide()};e.openDiscoPlot=async function(t){e.dom.tooltip.hide();e.onClick=false;t.sample_id=t.sample;const s=d(e.opts.plotDiv);s.header.text(t.sample_id);const o=await import("./plot.disco-70d493f4.js");o.default(e.state.termdbConfig,e.state.vocab.dslabel,t,s.body,e.app.opts.genome)};e.openLollipop=async function(t){e.dom.tooltip.hide();e.onClick=false;const s=d(e.opts.plotDiv||select(e.opts.holder.node().parentNode));s.header.text(t);const o={holder:s.body.append("div").style("margin","20px"),genome:e.app.opts.genome,nobox:true,query:t,tklst:[{type:"mds3",dslabel:e.app.opts.state.vocab.dslabel,filter0:e.state.termfilter.filter0,filterObj:e.state.termfilter.filter}]};const i=await import("./app-f91922b4.js").then((function(e){return e.c3}));await i.default(o)};e.onLegendClick=function(s,o,i,a,n,r){const l=e.config[i];const d=l.q.hiddenValues?a in l.q.hiddenValues:false;const c=new t({padding:"0px"});const h=c.d.append("div");h.append("div").attr("class","sja_menuoption sja_sharp_border").text(d?"Show":"Hide").on("click",(()=>{e.hideCategory(o,l,a,!d);c.hide();const t={};t[i]=l;e.app.dispatch({type:"plot_edit",id:e.id,config:t})}));h.append("div").attr("class","sja_menuoption sja_sharp_border").text("Show only").on("click",(()=>{const t=i=="colorTW"?s.colorLegend:s.shapeLegend;for(const s of t.keys())e.hideCategory(o,l,s,l.term.type=="geneVariant"&&!l.q.groupsetting.inuse?!s.startsWith(a):s!=a);c.hide();const n={};n[i]=l;e.app.dispatch({type:"plot_edit",id:e.id,config:n})}));h.append("div").attr("class","sja_menuoption sja_sharp_border").text("Show all").on("click",(()=>{c.hide();const t=i=="colorTW"?s.colorLegend:s.shapeLegend;for(const s of t.keys())e.hideCategory(o,l,s,false);const a={};a[i]=l;e.app.dispatch({type:"plot_edit",id:e.id,config:a})}));if(r.color){const t=p(r.color).formatHex();const s=h.append("div").attr("class","sja_sharp_border").style("padding","0px 10px").text("Color:").append("input").attr("type","color").attr("value",t).on("change",(()=>{e.changeColor(a,s.node().value);c.hide()}))}c.showunder(n.target)};e.hideCategory=function(t,s,o,i){if(o=="Ref"){e.settings.showRef=!i;e.app.dispatch({type:"plot_edit",id:e.id,config:{settings:{sampleScatter:e.settings}}})}if(!s.q.hiddenValues)s.q.hiddenValues={};const a=!(s.term.type=="geneVariant"&&!s.q.groupsetting.inuse)&&s.term.values[o]?s.term.values[o]:{key:o,label:o};const n=t.selectAll(`text[name="sjpp-scatter-legend-label"]`).nodes();const r=n.find((e=>o.startsWith(e.innerHTML)))?.parentElement;if(r)r.style["text-decoration"]=i?"line-through":"none";if(!i)delete s.q.hiddenValues[o];else s.q.hiddenValues[o]=a};e.changeColor=async function(t,s){const o=e.config.colorTW;if(!(o.term.type=="geneVariant"&&!o.q.groupsetting.inuse)&&o.term.values[t])o.term.values[t].color=s;else{if(!o.term.values)o.term.values={};o.term.values[t]={key:t,label:t,color:s}}await e.app.dispatch({type:"plot_edit",id:e.id,config:{colorTW:o}})};e.searchSample=async function(s){if(!this.searchMenu){this.searchMenu=new t({padding:"3px"});this.samplesData=await this.app.vocabApi.getSamplesByName({filter:e.state.termfilter.filter});const s=e=>{};T(this.searchMenu.d,this.samplesData,s,(t=>e.filterSamples(t)))}this.searchMenu.show(s.clientX,s.clientY,false)};e.filterSamples=function(t){this.filterSampleStr=t;e.render()};e.getCategoryInfo=function(e,t){if(!(t in e))return"";return e[t]};e.addToFilter=function(t){const s=h(e.state.termfilter.filter,"filterUiRoot");const o=u([s,b(t)]);o.tag="filterUiRoot";e.app.dispatch({type:"filter_replace",filter:o})};e.showTable=function(t,s,o,i){let a=[];const n=[];const r=t.items[0];if("sample"in r)n.push(f("Sample","label"));if(e.config.colorTW)n.push(f(e.config.colorTW.term.name,"label"));if(e.config.shapeTW)n.push(f(e.config.shapeTW.term.name,"label"));let l=false;for(const s of t.items){const t=[];if("sample"in s)t.push(f(s.sample));if(e.config.colorTW)t.push(f(e.getCategoryInfo(s,"category")));if(e.config.shapeTW)t.push(f(e.getCategoryInfo(s,"shape")));if("info"in s){l=true;const e=[];for(const[t,o]of Object.entries(s.info))e.push(`${t}: ${o}`);t.push(f(e.join(", ")))}a.push(t)}if(l)n.push(f("Info","label"));e.dom.tip.clear();const p=e.dom.tip.d.append("div").style("padding","5px");const d=p.append("div").style("margin-top","5px");const h=d.append("div").html(" "+t.name).style("font-size","0.9rem").on("click",(()=>{const s=h.select("input").empty();if(!s)return;h.html("");const o=h.append("input").attr("value",t.name).on("change",(async()=>{const s=o.node().value;if(s)e.renameGroup(t,s);else o.node().value=t.name;h.html(" "+t.name)}));o.node().focus();o.node().select()}));const m=p.append("div");const u=[];if(i){const t={text:"Add to a group",callback:t=>{const s=[];for(const o of t)s.push(e.selectedItems[o].__data__);const o={name:`Group ${e.config.groups.length+1}`,items:s,index:e.config.groups.length};const i=b(v([o]));C(e.app,i,e.state.groups)}};u.push(t)}else{const a={text:"Delete samples",callback:a=>{t.items=t.items.filter(((e,t,s)=>!(t in a)));e.showTable(t,s,o,i)}};u.push(a)}c({rows:a,columns:n,div:m,showLines:true,maxWidth:n.length*"15"+"vw",maxHeight:"35vh",buttons:u,selectAll:true});e.dom.tip.show(s,o,false,false);function f(e,t="value"){let s={};s[t]=e;return s}};e.showGroupMenu=function(t,s){e.dom.tip.clear();e.dom.tip.show(t.clientX,t.clientY,false,true);const o=e.dom.tip.d.append("div");const i=e.config.name?e.config.name:"Summary scatter";const a=v([s],i+" groups");const n=o.append("div").attr("name","sjpp-group-input-div").html(" "+s.name).style("font-size","0.9rem").on("click",(()=>{const t=n.select("input").empty();if(!t)return;n.html("");const o=n.append("input").attr("value",s.name).on("change",(async()=>{const t=o.node().value;if(t)e.renameGroup(s,t);else o.node().value=s.name;n.html(" "+s.name)}));o.node().focus();o.node().select()}));o.append("div").attr("class","sja_menuoption sja_sharp_border").text(`Edit ${s.items.length} samples`).on("click",(o=>{e.dom.tip.hide();e.showTable(s,t.clientX,t.clientY,false)}));e.addCommonMenuItems(o,a);o.append("div").attr("class","sja_menuoption sja_sharp_border").text(`Delete group`).on("click",(async t=>{await e.app.vocabApi.deleteGroup(s.name);e.dom.tip.hide()}));o.append("div").attr("class","sja_menuoption sja_sharp_border").text("Add to filter").on("click",(()=>{e.addToFilter(a);e.app.dispatch({type:"plot_edit",id:e.id,config:{groups:e.config.groups}})}));o.append("div").attr("class","sja_menuoption sja_sharp_border").text(s.showOnly?"Show All":"Show Only").on("click",(()=>{s.showOnly=!s.showOnly;e.app.dispatch({type:"plot_edit",id:e.id,config:{groups:e.config.groups}})}))};e.renameGroup=async function(t,s){const o=e.config.groups.findIndex((e=>e.name==s));if(o!=-1)alert(`Group named ${s} already exists`);else await e.app.dispatch({type:"rename_group",index:t.index,newName:s})};e.addCommonMenuItems=function(t,s){x(e.dom.tip,t,s,e.app,e.id,e.state);if(e.state.supportedChartTypes.includes("survival"))w("survival",t,"Compare survival",e.dom.tip,s,e.id,this);if(e.state.supportedChartTypes.includes("cuminc"))w("cuminc",t,"Compare cumulative incidence",e.dom.tip,s,e.id,this);const o=t.append("div").attr("class","sja_menuoption sja_sharp_border").html("Summarize");o.insert("div").html("›").style("float","right");o.on("click",(async t=>{S(o,(t=>{k(t,s,e.app,e.id)}),e.app,e.dom.tip)}))};e.showGroupsMenu=function(t){e.dom.tip.clear();e.dom.tip.show(t.clientX,t.clientY,false,true);const s=e.dom.tip.d.append("div");const o=e.config.name?e.config.name:"Summary scatter";const i=v(e.config.groups,o+" groups");let a=s.append("div");for(const[o,i]of e.config.groups.entries()){a=s.append("div").attr("class","sja_menuoption sja_sharp_border");a.insert("div").style("display","inline-block").text(` ${i.name}: ${i.items.length} `);a.append("div").style("display","inline-block").style("float","right").html(" ›");a.on("click",(s=>{e.dom.tip.clear().hide();e.showGroupMenu(t,i)}))}e.addCommonMenuItems(s,i);a=s.append("div").attr("class","sja_menuoption sja_sharp_border").text("Delete groups").on("click",(async t=>{for(const t of e.config.groups)await e.app.vocabApi.deleteGroup(t.name);e.app.dispatch({type:"plot_edit",id:e.id,config:{groups:[]}})}))}}function J(e,t,s,o,i){const a=i.xAxisScale(s)-i.xAxisScale(e);const n=i.yAxisScale(o)-i.yAxisScale(t);const r=Math.sqrt(Math.pow(a,2)+Math.pow(n,2));return r}var P=Object.freeze({__proto__:null,setInteractivity:F});export{P as a,H as g,z as n,F as s};
|
|
1
|
+
import{az as e,M as t,ae as s,q as o,ac as i,aP as a,S as n,aQ as r,E as l,x as p,a1 as d}from"./app-71453429.js";import{r as c}from"./table-1dae543a.js";import{a as h,b as m,c as u}from"./FilterRxComp-fc769f34.js";import{c as f,g as y,r as g,a as b,b as v,d as x,e as w,f as S,o as k,h as C}from"./recover-b1ec4fed.js";import{t as _}from"./downloadTextfile-5723af95.js";import{searchSampleInput as T}from"./sampleView-30b97c7d.js";class D{constructor(e){this.type="search";N(this);j(this)}async init(e){this.dom={holder:this.opts.holder,holderNode:this.opts.holder.node(),tip:new t({padding:"5px"})};this.initUI()}reactsTo(e){return e.type.startsWith("search")||e.type.startsWith("cohort")}getState(e){return{cohortStr:e.activeCohort==-1||!e.termdbConfig.selectCohort?"":e.termdbConfig.selectCohort.values[e.activeCohort].keys.slice().sort().join(","),search:e.search,nav:e.nav}}async main(){this.dom.holder.style("display",this.state.search.isVisible&&this.state.nav.header_mode!="only_buttons"?"inline-block":"none")}async doSearch(e){if(!e){this.clear({hide:true});this.bus.emit("postSearch",[]);return}const t=await this.app.vocabApi.findTerm(e,this.state.cohortStr,this.opts.usecase);if(!t.lst||t.lst.length==0){this.noResult()}else{this.showTerms(t)}this.bus.emit("postSearch",t)}}const A=e(D);function N(e){e.initUI=()=>{e.dom.holder.style("display",e.search&&e.search.isVisible==false?"none":"inline-block");e.dom.input=e.dom.holder.style("text-align","center").append("input").attr("type","search").attr("class","tree_search").attr("placeholder","Search").style("width","180px").style("display","block").on("input",s.debounce(e.onInput,300));e.dom.resultDiv=e.dom.tip.d.style("border-left",e.opts.resultsHolder?"":"solid 1px rgb(133,182,225)").style("padding-left","5px")};e.noResult=()=>{e.clear();e.dom.resultDiv.append("div").text("No match").style("padding","3px 3px 3px 0px").style("opacity",.5)};e.showTerms=t=>{if(e.opts.disable_terms)t.lst.forEach((t=>{if(t.disabled)e.opts.disable_terms.push(t)}));e.clear({hide:!t.lst.length});if(t.lst.length){e.dom.resultDiv.append("table").selectAll().data(t.lst).enter().append("tr").each(e.showTerm)}};e.showTerm=function(t){const s=o(this);const i=s.append("td").text(t.name);if(t.type){i.style("cursor","pointer").attr("class","sja_menuoption").on("click",(()=>{e.app.dispatch({type:"plot_create",config:{chartType:t.type=="survival"?"survival":"summary",term:{term:t}}});e.clear({hide:true})}))}else{i.style("padding","5px 10px").style("opacity",.5)}s.append("td").text((t.__ancestorNames||[]).join(" > ")).style("opacity",.5).style("font-size",".7em")};e.clear=(t={})=>{e.dom.tip.clear();if(t.hide)e.dom.tip.hide();else e.dom.tip.showunder(e.dom.holderNode)}}function j(e){e.onInput=async()=>{const t=e.dom.input.property("value");try{await e.doSearch(t)}catch(t){e.clear();i(e.dom.resultDiv,"Error: "+(t.message||t));if(t.stack)console.log(t.stack)}}}class O{constructor(){this.type="sessionBtn";this.route="termdb";this.embedderOrigin=window.location.origin;this.hostURL=sessionStorage.getItem("hostURL")||this.embedderOrigin}async init(e){const s=new t({padding:"0px"});this.dom={button:this.opts.button,tip:s};this.dom.button.on("click",(()=>{this.dom.tip.clear();this.showMenu()}));this.dslabel=e.vocab.dslabel;this.savedSessions=JSON.parse(localStorage.getItem("savedMassSessions")||`{}`);this.requiredAuth=e.termdbConfig?.requiredAuth?.find((e=>e.route==this.route&&e.type=="jwt"))}async showMenu(){this.dom.tip.clear().d.style("padding",0);const e=[{label:`Open`,title:"Recover a saved session",callback:this.open},{label:`Save`,title:"Save the current view",callback:this.save},{label:`Share`,title:"Create a URL link to share this view",callback:this.getSessionUrl}];if(!this.serverCachedSessions)await this.setServerCachedSessions();if(Object.keys(this.savedSessions).length||Object.keys(this.serverCachedSessions).length){e.push({label:`Delete`,title:"Delete a saved session",callback:this.delete})}this.dom.tip.clear().d.selectAll(".sja_menuoption sja_sharp_border").data(e).enter().append("div").attr("class","sja_menuoption sja_sharp_border").attr("title",(e=>e.title)).html((e=>e.label)).on("click",((e,t)=>{this.dom.tip.clear().d.style("padding","10px");this.showBackBtn();t.callback.call(this)}));this.dom.tip.showunder(this.dom.button.node())}async open(){const e=`sjpp-session-open-radio-`+Math.random().toString().slice(-6);this.dom.tip.d.append("div").style("display","none").style("padding","3px 9px").html(`\n\t\t\t<b>Open in</b>\n\t\t\t<label>\n\t\t\t\t<input type='radio' name='${e}' value='new' style='margin-right: 0; vertical-align: bottom'/>\n\t\t\t\t<span>a new tab</span>\n\t\t\t</label>\n\t\t\t<label style='margin-left: 5px'>\n\t\t\t\t<input type='radio' name='${e}' value='current' checked=checked style='margin-right: 0; vertical-align: bottom'/>\n\t\t\t\t<span>current tab</span>\n\t\t\t</label>\n\t\t`);const t=await this.listSessions({trClickHandler:async(t,s)=>{const{loc:o,id:i}=s;if(!i)return;if(o.includes("browser")){this.sessionName=i;const t=this.savedSessions[i];const s=this.dom.tip.d.node().querySelector(`[name="${e}"]:checked`).value;if(s=="current"){this.app.dispatch({type:"app_refresh",state:t})}else if(window.location.origin==this.hostURL){window.open(`/?mass-session-id=${i}&src=browser`)}else{if(t.embedder)a({state:t});else{const{protocol:e,host:s,search:o,origin:i,href:n}=window.location;const r={protocol:e,host:s,search:o,origin:i,href:n};a({state:Object.assign({embedder:r},t)})}}this.dom.tip.hide()}else if(o=="server"){const t=this.app.vocabApi.mayGetAuthHeaders(this.route);const s={id:i,route:this.route,dslabel:this.dslabel,embedder:window.location.hostname};const o=await n(`/massSession?`,{headers:t,body:s});if(!o.state)throw o.error||"unable to get the cached session from the server";this.savedSessions[i]=o.state;const r=this.dom.tip.d.node().querySelector(`[name="${e}"]:checked`).value;if(r=="current"){this.app.dispatch({type:"app_refresh",state:o.state})}else if(window.location.origin==this.hostURL){window.open(`/?mass-session-id=${i}&src=cred&dslabel=${this.dslabel}&route=${this.route}`)}else{a(o)}this.dom.tip.hide()}}});t.headtr.select("th").html("Open from");const s=t.tbody.insert("tr","tr");s.append("td").style("text-align","center").style("padding","3px 9px").html("Local file");const o=s.append("td").style("text-align","left").append("label");o.append("span").style("padding","3px 9px").style("text-decoration","underline").style("cursor","pointer").html("Choose File");o.append("input").attr("type","file").attr("placeholder","file name").style("opacity",0).style("width","0.1px").style("height","0.1px").style("position","absolute").on("change",(async()=>{const t=event.target.files.item(0);const s=await t.text();let o=t.name;if(this.savedSessions[o]){o=prompt(`Leave as-is to overwrite a session with the same name, or enter a different session name.`,o)}this.sessionName=o;const i=JSON.parse(s);this.savedSessions[o]=i;localStorage.setItem("savedMassSessions",JSON.stringify(this.savedSessions));const n=this.dom.tip.d.node().querySelector(`[name="${e}"]:checked`).value;if(n=="current"){this.app.dispatch({type:"app_refresh",state:i})}else if(window.location.origin==this.hostURL){window.open(`/?mass-session-id=${o}&src=browser`)}else{if(i.embedder)a({state:i});else{const{protocol:e,host:t,search:s,origin:o,href:n}=window.location;const r={protocol:e,host:t,search:s,origin:o,href:n};a({state:Object.assign({embedder:r},i)})}}this.dom.tip.hide()}))}async listSessions(e={}){const t=this.dom.tip.d.append("table").attr("class","sjpp-controls-table");const s=t.append("thead").append("tr");s.selectAll("th").data(["Cache Location","Session ID"]).enter().append("th").style("text-align",((e,t)=>t===0?"center":"left")).style("padding","3px 9px").html((e=>e));const o=Object.keys(this.savedSessions).map((e=>({loc:"browser",id:e})));if(!this.serverCachedSessions)await this.setServerCachedSessions();o.push(...this.serverCachedSessions.map((e=>({loc:"server",id:e}))));const i=t.append("tbody");const a=i.selectAll("tr").data(o).enter().append("tr").on("click",e.trClickHandler||null);a.selectAll("td").data((e=>[e,e])).enter().append("td").style("text-align",((e,t)=>t===0?"center":"left")).style("padding","3px 9px").style("cursor","pointer").html(((e,t)=>t===0?e.loc:e.id));if(!this.serverCachedSessions.length&&this.requiredAuth&&!this.app.vocabApi.hasVerifiedToken()){t.append("tbody").append("tr").selectAll("td").data(["server","requires sign-in"]).enter().append("td").style("text-align",((e,t)=>t===0?"center":"left")).style("padding","3px 9px").html((e=>e))}return{table:t,headtr:s,tbody:i,trs:a}}async setServerCachedSessions(){const e=this.app.getState();this.requiredAuth=e.termdbConfig?.requiredAuth?.find((e=>e.route==this.route&&e.type=="jwt"));if(!this.requiredAuth){this.serverCachedSessions=[];return}const t=this.app.vocabApi.mayGetAuthHeaders(this.route);const s={route:this.route,dslabel:this.dslabel,embedder:window.location.hostname};const o=await n("/sessionIds",{headers:t,body:s});this.serverCachedSessions=o.sessionIds||[]}async save(e){const t=this.dom.tip.d;const s=t.append("div");s.append("span").html("Save as");const o=Object.keys(this.savedSessions);if(!this.serverCachedSessions)await this.setServerCachedSessions();o.push(...this.serverCachedSessions.filter((e=>!o.includes(e))));const i=this.sessionName||"unnamed-session";const a=s.append("input").attr("type","text").attr("placeholder",i).style("width","220px").on("input",(()=>{n.selectAll("*").remove();const e=a.property("value");const t=o.filter((t=>t===e));const s=o.filter((t=>t.startsWith(e)));const i=o.filter((t=>t.includes(e)&&t!==e&&!s.includes(t)));n.selectAll("div").data([...t,...s,...i]).enter().append("div").attr("class","sja_menuoption").html((e=>e)).on("click",((e,t)=>{a.property("value",t);n.selectAll("*").remove()}))}));const n=t.append("div");const r=t.append("div");r.append("span").html("Save to ");r.append("button").style("min-width","80px").html("Browser").attr("title",`Save the session in your current browser's cache. The session can be easily recovered, but not shared among your other devices`).on("click",(()=>{this.sessionName=a.property("value")||i;this.savedSessions[this.sessionName]=this.app.getState();localStorage.setItem("savedMassSessions",JSON.stringify(this.savedSessions));this.confirmAction(`Cached '<b>${this.sessionName}</b>' in browser`)}));r.append("button").style("min-width","80px").html("File").attr("title",`Save the session into a local file. The session can be easily recoved using the 'Open from local file' option.`).on("click",(()=>{const e=a.property("value")||i;this.savedSessions[e]=this.app.getState();this.download(e);this.confirmAction(`Downloaded '<b>${e}</b>'`)}));if(this.requiredAuth){const e=this.app.vocabApi.hasVerifiedToken()?"":"Requires sign-in. ";r.append("button").style("min-width","80px").html("Server").attr("title",`${e}Save the session into a remote server. The session can be easily shared across your different devices and recovered using the 'Open from server' option.`).property("disabled",!this.app.vocabApi.hasVerifiedToken()).on("click",(async()=>{if(!this.app.vocabApi.hasVerifiedToken()){alert("Requires sign-in");return}const e=a.property("value")||i;this.savedSessions[e]=this.app.getState();const t=await this.getSessionUrl(e);if(t.id!=e)throw`error saving ${e}`;this.confirmAction(`Saved '<b>${e}</b>' on the server`)}))}}download(e=""){const t=e||this.sessionName;const s=t?.endsWith(".txt")?"":".txt";const o=`${t}${s}`;_(o,JSON.stringify(this.savedSessions[t]))}async getSessionUrl(e=""){const t=this.app.vocabApi.mayGetAuthHeaders("termdb");const s=structuredClone(this.app.getState());const{protocol:o,host:i,search:r,origin:l,href:p}=window.location;s.embedder={protocol:o,host:i,search:r,origin:l,href:p};if(e){s.__sessionFor__={route:this.route,filename:e,dslabel:this.dslabel,embedder:window.location.hostname}}const d=await n("/massSession",{headers:t,method:"POST",body:JSON.stringify(s)});if(e){return d}else{const e=`${this.hostURL}/?mass-session-id=${d.id}&noheader=1`;this.dom.tip.showunder(this.dom.button.node());const t=this.dom.tip.d.append("div").style("margin","10px");t.append("div").style("margin-bottom","12px").html(`Click the link to recover this session. Bookmark or share this link.`);const o=t.append("a").attr("href",e).attr("target","_blank").html(d.id);if(this.hostURL!=window.location.origin){o.on("click",(e=>{e.preventDefault();a({state:s},window.location.origin);return false}))}t.append("div").html(`\n\t\t\t\t\t<br>\n\t\t\t\t\t<div style="max-width: 400px; font-size: 1em; opacity:.6">\n\t\t\t\t\t<span>NOTES</span>\n\t\t\t\t\t<ul>\n\t\t\t\t\t<li>A recovered session may hide data or views to users that are not authorized to access the saved datasets or features.</li>\n\t\t\t\t\t<li>This session will be saved for ${this.opts.massSessionDuration} days.</li>\n\t\t\t\t\t</ul>\n\t\t\t\t\t</div>`);setTimeout((()=>{this.dom.button.property("disabled",false)}),1e3)}}async delete(){const e=await this.listSessions({trClickHandler:function(s){const i=this.lastChild.querySelector("input");const a=s.target==i?i.checked:!i.checked;o(this).style("text-decoration",a?"line-through":"");if(s.target!=i)i.checked=a;const n=e.table.node().querySelectorAll("input:checked");t.property("disabled",n.length?false:true)}});e.headtr.append("th").html("Delete");e.trs.each((function(e){o(this).append("td").style("text-align","center").append("input").attr("type","checkbox").attr("value",e.id)}));const t=this.dom.tip.d.append("div").style("text-align","center").append("button").html("Delete selected sessions").property("disabled",true).on("click",(async()=>{const t=e.table.node().querySelectorAll("input");const s=[];for(const e of t){if(o(e).property("checked")){const t=e.parentNode.parentNode.__data__;if(t.loc=="browser"){delete this.savedSessions[e.value]}else if(t.loc=="server"){delete this.serverCachedSessions[e.value];s.push(e.value)}else throw`unknown cache location=${t.loc}`}}localStorage.setItem("savedMassSessions",JSON.stringify(this.savedSessions));try{const e=this.app.vocabApi.mayGetAuthHeaders("termdb");const t={ids:s,route:this.route,dslabel:this.dslabel,embedder:window.location.hostname};const o=n(`/massSession?`,{method:"DELETE",headers:e,body:t})}catch(e){throw e}this.dom.tip.hide()}))}showBackBtn(){this.dom.tip.d.append("div").attr("class","sja_clbtext2").style("margin-bottom","10px").style("cursor","pointer").html(`< Session Menu`).on("click",(()=>this.showMenu()))}confirmAction(e){this.dom.tip.clear().d.append("div").html(e).transition().delay(3e3).duration(1e3).style("opacity",0);setTimeout((()=>{this.dom.tip.hide()}),3500)}}const I=e(O);let L=0;const $="_MASS_AUTOID_"+Math.random().toString().slice(-6);let W=(+new Date).toString().slice(-8);const M=new t({padding:"0px",offsetX:0,offsetY:0});M.d.style("z-index",5555);const q={top:"COHORT",mid:"NONE",btm:"",subheader:"cohort"};const R={top:"CHARTS",mid:"NONE",btm:"",subheader:"charts"};const U={top:"GROUPS",mid:"NONE",btm:"",subheader:"groups"};const E={top:"FILTER",mid:"NONE",btm:"",subheader:"filter"};function H(){return $+"_"+W++}class V{constructor(e){this.type="nav";this.instanceNum=L++;this.activeTab=0;this.activeCohort=0;this.searching=false;this.samplecounts={};this.massSessionDuration=e.massSessionDuration;this.sessionDaysLeft=e.app.opts.sessionDaysLeft||null;this.sessionId=e.app.opts.sessionId||null;B(this);G(this)}async init(e){try{this.cohortFilter=h(e.termfilter.filter,"cohortFilter");this.initUI(e);this.initCohort(e);this.components=await r({search:A({app:this.app,holder:this.dom.searchDiv,usecase:{target:"barchart",detail:"term"}}),filter:m({app:this.app,vocabApi:this.app.vocabApi,holder:this.dom.subheader.filter.append("div"),hideLabel:this.opts.header_mode==="with_tabs",emptyLabel:"+Add new filter",callback:e=>{this.app.dispatch({type:"filter_replace",filter:e})}}),charts:f({app:this.app,holder:this.dom.subheader.charts,vocab:this.opts.vocab}),groups:y({app:this.app,holder:this.dom.subheader.groups,vocab:this.opts.vocab}),recover:g({app:this.app,holder:this.dom.recoverDiv,getState:e=>e,reactsTo:e=>e.type!="plot_edit",maxHistoryLen:5}),sessionBtn:I({app:this.app,button:this.dom.saveBtn,massSessionDuration:this.opts.massSessionDuration,sessionDaysLeft:this.app.opts.sessionDaysLeft||null})});this.mayShowMessage_sessionDaysLeft()}catch(e){throw e}}reactsTo(e){if(e.type.includes("cache_termq"))return true;if(e.type.startsWith("filter"))return true;if(e.type.startsWith("cohort"))return true;if(e.type.startsWith("tab"))return true;if(e.type=="plot_create")return true;if(e.type=="plot_delete")return true;if(e.type=="app_refresh")return true;if(e.type.endsWith("_customTerm"))return true;if(e.type.endsWith("_group"))return true}getState(e){return{searching:this.searching,nav:e.nav,activeCohort:e.activeCohort,termdbConfig:e.termdbConfig,filter:e.termfilter.filter,plots:e.plots,groups:e.groups}}async main(){this.dom.tabDiv.style("display",this.state.nav.header_mode==="with_tabs"?"inline-block":"none");this.dom.tip.hide();this.activeTab=this.state.nav.activeTab;this.prevCohort=this.activeCohort;this.activeCohort=+this.state.activeCohort;this.filterUiRoot=h(this.state.filter,"filterUiRoot");this.cohortFilter=h(this.state.filter,"cohortFilter");if(this.cohortNames){this.activeCohortName=this.cohortNames[this.activeCohort];if(this.activeCohort!==-1)this.activeCohortLabel=this.state.termdbConfig.selectCohort.values[this.activeCohort].shortLabel}this.filterJSON=JSON.stringify(this.state.filter);this.cohortsData=await this.app.vocabApi.getCohortsData();if(this.state.nav.header_mode==="with_tabs"){if(!(this.activeCohortName in this.samplecounts)){this.samplecounts[this.activeCohortName]=await this.app.vocabApi.getCohortSampleCount(this.activeCohortName)}if(!(this.filterJSON in this.samplecounts)){if(!this.filterUiRoot||!this.filterUiRoot.lst.length){this.samplecounts[this.filterJSON]=this.samplecounts[this.activeCohortName]}else{const e=await this.app.vocabApi.getFilteredSampleCount(this.filterJSON);this.samplecounts[this.filterJSON]=e}}}this.updateUI()}}const z=e(V);function G(e){e.initUI=s=>{const o=e.opts.holder.append("div").style("white-space","nowrap");let i=o.append("div").style("display","inline-block").style("float","right").style("font-size","1.1em").style("margin-top","50px").text(s.termdbConfig?.title?.text||"");const a=o.append("div").style("display","none").style("vertical-align","bottom");const n=o.append("div").style("vertical-align","top").style("margin","10px").style("display","inline-block");e.opts.holder.attr("class","sjpp-nav");e.dom={holder:e.opts.holder,header:o,tabDiv:a,controlsDiv:n,searchDiv:n.append("div").style("margin","10px"),sessionDiv:n.append("div").style("display","inline-block"),recoverDiv:n.append("div").style("display","inline-block"),helpDiv:n.append("div").style("display","none"),sessionElapsedMessageDiv:n.append("div").style("display","none"),subheaderDiv:e.opts.holder.append("div").style("display","block").style("padding-top","5px").style("border-bottom","1px solid #000"),messageDiv:e.opts.holder.append("div").style("margin","30px").style("display","none"),titleDiv:i,tip:new t({padding:"5px"})};if(s.nav.header_mode=="only_buttons"){e.dom.tabDiv.style("display","none");e.dom.recoverDiv.style("display","none");i.style("margin-top","95px").style("font-size","0.9em");if(s.termdbConfig.title?.link)i.on("click",(()=>window.open(s.termdbConfig.title.link,"_blank"))).on("mouseover",(()=>i.style("cursor","pointer")))}if(e.opts.header_mode==="with_cohortHtmlSelect"){e.dom.cohortStandaloneDiv=o.append("div").style("display","inline-block").style("margin","10px").style("vertical-align","top");e.dom.cohortStandaloneDiv.append("label").html("Cohort: ");e.dom.cohortSelect=e.dom.cohortStandaloneDiv.append("select").on("change",(function(){e.app.dispatch({type:"cohort_set",activeCohort:+this.value})}));e.dom.cohortSelect.selectAll("option").data(s.termdbConfig.selectCohort.values).enter().append("option").attr("value",((e,t)=>t)).property("selected",((e,t)=>t===s.activeCohort)).html((e=>e.shortLabel))}e.dom.subheader=Object.freeze({search:e.dom.subheaderDiv.append("div").style("display","none"),groups:e.dom.subheaderDiv.append("div").style("display","none"),charts:e.dom.subheaderDiv.append("div").style("display","none"),cohort:e.dom.subheaderDiv.append("div").style("display","none"),filter:e.dom.subheaderDiv.append("div").style("display","none"),cart:e.dom.subheaderDiv.append("div").style("display","none").html("<br/>Cart feature under construction - work in progress<br/> <br/>")});e.tabs=[R,U,E];if(s.termdbConfig.selectCohort)e.tabs.unshift(q);const r=e.dom.tabDiv.append("table").style("border-collapse","collapse");r.selectAll("tr").data(["top","mid","btm"]).enter().append("tr").style("font-size",((e,t)=>t==1?"20px":"12px")).selectAll("td").data(((t,s)=>e.tabs.map(((e,o)=>({rowNum:s,key:t,colNum:o,label:e[t],subheader:e.subheader}))))).enter().append("td").style("display","none").style("width","100px").style("padding",(e=>e.rowNum===0?"12px 12px 3px 12px":"3px 12px")).style("text-align","center").style("border-left","1px solid #ccc").style("border-right","1px solid #ccc").style("color","#aaa").style("cursor","pointer").html((e=>e.label)).on("click",e.setTab);e.dom.trs=r.selectAll("tr");e.dom.tds=r.selectAll("td");e.subheaderKeys=e.tabs.map((e=>e.subheader));e.dom.saveBtn=e.dom.sessionDiv.append("button").style("margin","10px").text("Session ▼");if(e.sessionDaysLeft!=null){e.dom.fileBtn=e.dom.sessionDiv.append("button").style("margin","10px").text("Export Session").on("click",(t=>{e.getSessionFile(t)}))}const l=s.termdbConfig.helpPages;if(l){e.dom.helpBtn=e.dom.helpDiv.style("display","inline-block").append("button").style("margin","10px").html("Help ▼").on("click",(e=>{const t=e.target.getBoundingClientRect();const s=M.clear().show(t.left-0,t.top+t.height+5).d.append("div");for(const e of l){s.append("div").style("margin","15px").append("a").attr("href",e.url).attr("target","_blank").text(e.label)}}))}};e.mayShowMessage_sessionDaysLeft=()=>{if(!Number.isFinite(e.sessionDaysLeft)){return}e.dom.sessionElapsedMessageDiv.style("display","block");e.dom.remainingDaysMessage=e.dom.sessionElapsedMessageDiv.append("div").style("display","block").style("opacity","0.65").html(`<u>${e.sessionDaysLeft} days</u> left until this session is removed. Click the "Save Session" button to create a new one.`)};e.updateUI=async(t=false)=>{if(!e.dom.subheaderDiv)return;if(e.activeTab&&e.state.termdbConfig.selectCohort&&e.activeCohort==-1){e.dom.subheaderDiv.style("display","none");e.dom.messageDiv.selectAll("text").remove();e.dom.messageDiv.style("display","").text('No cohort selected. Please select a cohort in the "COHORT" tab.')}else{let s="block";if(t){s=e.dom.subheaderDiv.style("display")=="none"?"block":"none"}if(e.dom.subheaderDiv)e.dom.subheaderDiv.style("display",s);if(e.dom.messageDiv)e.dom.messageDiv.style("display","none")}const s=e.state.termdbConfig.selectCohort;e.dom.searchDiv.style("display",s&&e.activeCohort==-1||e.state.nav.header_mode=="only_buttons"?"none":"inline-block");e.dom.header.style("border-bottom",e.state.nav.header_mode==="with_tabs"?"1px solid #000":"");e.dom.tds.style("display","").style("color",(t=>t.colNum==e.activeTab?"#000":"#aaa")).style("background-color",(t=>t.colNum==e.activeTab?"#ececec":"transparent")).html((function(t,s){if(t.key=="top")return this.innerHTML;if(t.subheader=="groups"){if(t.key=="mid")return e.state.groups.length||"NONE";return""}if(t.subheader==="charts"){const s=e.state.plots.length;if(t.key=="mid")return!s?"NONE":s;else return""}else if(t.subheader==="cohort"){if(e.activeCohortName&&e.activeCohortName in e.samplecounts){return t.key=="top"?this.innerHTML:t.key=="mid"?e.activeCohortLabel:"n="+e.samplecounts[e.activeCohortName]}else{return t.key=="mid"?"NONE":this.innerHTML}}else if(t.subheader==="filter"){const s=e.filterUiRoot?e.filterUiRoot:{lst:[]};if(s.lst.length===0){return t.key==="mid"?"NONE":e.samplecounts["undefined"]?`n=${e.samplecounts["undefined"]}`:""}else{const o=e.samplecounts[e.filterJSON]!=undefined?"n="+e.samplecounts[e.filterJSON]:"";return t.key==="mid"?s.lst.length:o}}else{return t.key==="mid"?this.innerHTML:" "}}));for(const t in e.dom.subheader){e.dom.subheader[t].style("display",e.tabs[e.activeTab].subheader===t?"block":"none")}e.renderCohortsTable();if(e.opts.header_mode==="with_cohort_select"){e.dom.cohortSelect.selectAll("option").property("value",appState.activeCohort)}};e.renderCohortsTable=()=>{if(!e.dom.cohortTable)return;e.dom.cohortTable.selectAll("*").remove();const t=[{label:"Feature"}];const s=[];const o=e.cohortsData;if("error"in o)throw o.error;for(const e of o.features)s.push([{value:e.name}]);for(const e of o.cohorts){t.push({label:e.cohort?`${e.name} (${e.cohort})`:e.name});for(const[t,i]of o.features.entries()){const a=o.cfeatures.find((t=>t.idfeature===i.idfeature&&t.cohort===e.cohort));if(a)s[t].push({value:a.value})}}c({rows:s,columns:t,div:e.dom.cohortTable,showLines:false,maxHeight:"60vh"});e.dom.cohortTable.select("table").style("border-collapse","collapse");e.dom.cohortTable.selectAll(`tbody > tr > td`).style("background-color","transparent");const i=e.state.termdbConfig.selectCohort;const a=i.values[e.activeCohort].keys;let n=`tbody > tr > td:nth-child(${e.activeCohort+2})`;const r=a.length>1;if(r){n="";for(const e of a){const t=o.cohorts.map((e=>e.cohort)).indexOf(e);if(n!=="")n+=",";n+=`tbody > tr > td:nth-child(${t+2})`}}const l=e.dom.cohortTable.selectAll(n);l.style("background-color","yellow");e.dom.cohortInputs.property("checked",((t,s)=>s===e.activeCohort))};e.initCohort=async t=>{const s=t.termdbConfig.selectCohort;if(!s)return;e.dom.tds.filter((e=>e.colNum===0)).style("display","");e.cohortNames=s.values.map((e=>e.keys.slice().sort().join(",")));if(s.title){e.dom.cohortTitle=e.dom.subheader.cohort.append("h2").style("margin-left","10px").text(s.title)}if(s.description){e.dom.cohortDescription=e.dom.subheader.cohort.append("div").style("margin-left","10px").html(s.description)}if(s.prompt){e.dom.cohortPrompt=e.dom.subheader.cohort.append("div").style("margin-left","10px").style("padding-top","30px").style("padding-bottom","10px").style("font-weight","bold").text(s.prompt)}e.dom.cohortOpts=e.dom.subheader.cohort.append("div").style("margin-bottom","30px").style("margin-left","10px");e.dom.cohortOpts.append("table").selectAll("tr").data(s.values).enter().append("tr").each((function(t,s){const i=o(this);const a=i.append("td");const n="sja-termdb-cohort-"+e.instanceNum;const r=n+"-"+s;a.append("input").attr("type","radio").attr("name",n).attr("id",r).attr("value",s).property("checked",s===e.activeCohort).style("margin-right","5px").style("margin-left","0px").on("click",(()=>{e.app.dispatch({type:"cohort_set",activeCohort:s})}));a.append("label").attr("for",r).attr("colspan",2).style("cursor","pointer").html((e=>e.label));i.selectAll("td").style("max-width","600px").style("padding-bottom","10px").style("padding-right","20px").style("vertical-align","top")}));e.dom.cohortInputs=e.dom.cohortOpts.selectAll("input");e.dom.cohortTable=e.dom.subheader.cohort.append("div");if(s.asterisk){e.dom.cohortAsterisk=e.dom.subheader.cohort.append("div").style("margin-left","10px").style("padding-top","20px").style("padding-bottom","20px").style("font-size","small").text(s.asterisk)}}}function B(e){e.setTab=async(t,s)=>{if(s.colNum===e.activeTab&&!e.searching){e.prevCohort=e.activeCohort;await e.updateUI(true);if(e.bus)e.bus.emit("postRender");return}e.activeTab=s.colNum;e.searching=false;e.app.dispatch({type:"tab_set",activeTab:e.activeTab});if(e.activeTab==1&&e.activeCohort!=-1&&!e.state.plots.length){e.app.dispatch({type:"plot_create",id:H(),config:{chartType:"dictionary"}})}};e.getSessionFile=async t=>{const s=await n(`/massSession?id=${e.sessionId}`);const o=document.createElement("a");const i="data:application/json;charset=utf-8,"+encodeURIComponent(JSON.stringify(s.state));o.setAttribute("href",i);o.download=`${e.sessionId}.json`;o.click();o.remove()}}function F(e){e.showTooltip=function(t,s){const o=t.type=="click";e.onClick=o;if(o)e.searchMenu?.hide();if(!(t.target.tagName=="path"&&t.target.getAttribute("name")=="serie")){if(e.onClick&&o){e.onClick=false;e.dom.tooltip.hide();return}if(!o){e.dom.tooltip.hide()}return}const i=t.target.__data__;const a="sample"in i;let n=10;n=n/e.zoom;const r=s.data.samples.filter((t=>{const o=J(t.x,t.y,i.x,i.y,s);if(!("sampleId"in t)&&(!e.settings.showRef||e.settings.refSize==0))return false;return e.getOpacity(t)>0&&o<n}));r.sort(((t,s)=>{if(!("sampleId"in t))return 1;if(e.config.term){if(t.x<s.x)return-1;if(t.x>s.x)return 1;if(t.y<s.y)return-1;return 1}if(e.config.colorTW){if(e.config.colorTW.term.type=="categorical"){if(t.category.includes(l.WT.label)||t.category.includes(l.Blank.label))return 1}else{if(t.category<s.category)return-1;else if(t.category>s.category)return 1}}if(t.shape.includes(l.WT.label)||t.shape.includes(l.Blank.label))return 1;return-1}));if(r.length==0)return;const d=[];const c=e.config.term?true:false;const h=e=>`${e.x.toPrecision(2)},${e.y.toPrecision(2)}`;for(const e of r){const t=h(e);let s=d.find((e=>e.id==t));if(!s){s={id:t,parentId:null,samples:[e],level:1,category:null,children:[]};d.push(s);if(c){const o=C("x",e);const i={id:o,parentId:t,samples:[e],level:2,category:"X",children:[],value:o};d.push(i);s.children.push(i);const a=C("y",e);const n={id:`${a}${o}`,parent:i,parentId:o,samples:[e],level:3,category:"Y",children:[],value:a};i.children.push(n);d.push(n);s.xnode=i;s.ynode=n}}else{s.samples.push(e);if(c){s.xnode.samples.push(e);s.ynode.samples.push(e)}}}let m=c?4:2;let u=c?["y","x",""]:[""];if(e.config.colorTW)k("category",e.config.colorTW);if(e.config.shapeTW)k("shape",e.config.shapeTW,e.config.colorTW);if(e.config.scaleDotTW)k("scale",e.config.scaleDotTW,e.config.shapeTW);e.dom.tooltip.clear();const f=e.dom.tooltip.d.style("padding","5px");const y=e.state.termdbConfig.queries?.singleSampleGenomeQuantification;const g=e.state.termdbConfig.queries?.singleSampleMutation;if(r.length>1)f.append("div").style("color","#aaa").style("padding","3px").style("font-weight","bold").html(`${r.length} Samples`);const b=f.append("div").style("max-height","400px").style("overflow","scroll");if(r.length>3)b.attr("class","sjpp_show_scrollbar");const v=b.append("table").style("width","100%");const x=d.filter((e=>c?e.level==1:e.level==2));if(c)for(const e of x){if(r.length>1)v.append("tr").append("td").attr("colspan",3).style("border-top","1px solid #aaa");for(const t of e.children){S(t)}}else for(const e of x){if(r.length>1)v.append("tr").append("td").attr("colspan",3).style("border-top","1px solid #aaa");S(e)}e.dom.tooltip.show(t.clientX,t.clientY,true,false);function w(t){const s=t=="category"?e.config.colorTW:t=="shape"?e.config.shapeTW:t=="scale"?e.config.scaleDotTW:t=="X"&&e.config.term?e.config.term:t=="Y"&&e.config.term2?e.config.term2:null;return s}function S(t){const i=w(t.category);t.added=true;let n;const d=t.samples[0];if(d.category!="Ref"){let n=v.append("tr");const c=i!=null&&(i==e.config.colorTW||i==e.config.shapeTW);let h=i?i.term.name:t.category;if(r.length>1&&!a)h=h+` (${t.samples.length})`;n.append("td").style("color","#aaa").text(h);const m=n.append("td");if(c){const a=i==e.config.colorTW?e.getColor(d,s):e.config.colorTW?"gray":e.settings.defaultColor;const r=i==e.config.colorTW?s.shapeLegend.get("Ref").shape%e.symbols.length:s.shapeLegend.get(d.shape).shape%e.symbols.length;const c=e.symbols[r].size(64)();let u="black";const f=p("white").toString();if(i?.term.type=="geneVariant"&&!i.q.groupsetting.inuse){for(const e in l){const s=l[e];if(t.value.includes(s.label)){if(p(s.color).toString()!=f)u=s.color;break}}if(o){n.append("td").append("button").text("Lollipop").on("click",(async t=>{await e.openLollipop(h);e.dom.tip.hide()}))}}let y=t.value.toString().length;const g=y*9+60;const b=m.append("svg").attr("width",g).attr("height","25px");const v=b.append("g").attr("transform","translate(10, 14)");v.append("path").attr("d",c).attr("fill",a).attr("stroke","#aaa");const x=v.append("text").attr("x",12).attr("y",6).attr("font-size","0.9em");x.append("tspan").text(t.value).attr("fill",u)}else m.style("padding","2px").text(`${t.value}`)}for(const e of t.children)if(!e.added)S(e);if(t.children.length==0&&a){for(const s of t.samples){if("info"in s)for(const[e,t]of Object.entries(s.info)){n=v.append("tr");n.append("td").style("color","#aaa").text(e);n.append("td").text(t)}n=v.append("tr");n.append("td").style("color","#aaa").text("Sample");n.append("td").style("padding","2px").text(s.sample);if("sampleId"in s&&o){n.append("td").append("button").text("Sample view").on("click",(t=>e.openSampleView(s)));if(g)n.append("td").append("button").text("Disco").on("click",(async t=>e.openDiscoPlot(s)));if(y)n.append("td").append("button").text("Met Array").on("click",(async t=>e.openMetArray(s)))}}}}function k(e,t,s){for(const o of r){const i=C(e,o,t);let a="";for(const e of u)a+=C(e,o,s);const n=i+a;let r=d.find((e=>e.id==n&&e.parentId==a));let l=d.find((e=>e.id==a));if(!r){r={id:n,parentId:a,samples:[],level:m,category:e,children:[],value:i};d.push(r)}r.samples.push(o);if(l)l.children.push(r)}m++;u.unshift(e)}function C(e,t,s){if(e=="")return"";let o=t[e];if(s?.term.type=="geneVariant"&&!s.q.groupsetting.inuse){const s=o.split(", ")[0];for(const i in l){const a=l[i];if(s==a.label){const s=t.cat_info[e].find((e=>e.class==a.key)).mname;if(s)o=`${s} ${o}`}}}if(typeof o=="number"&&o%1!=0)o=o.toPrecision(2);return o}};e.openSampleView=function(t){e.dom.tooltip.hide();e.onClick=false;e.app.dispatch({type:"plot_create",id:H(),config:{chartType:"sampleView",sample:{sampleId:t.sampleId,sampleName:t.sample}}});e.dom.tip.hide()};e.openMetArray=async function(t){e.dom.tooltip.hide();e.onClick=false;t.sample_id=t.sample;for(const s in e.state.termdbConfig.queries.singleSampleGenomeQuantification){const o=d(e.opts.plotDiv);o.header.text(t.sample_id);const i=await import("./plot.ssgq-1949c207.js");await i.plotSingleSampleGenomeQuantification(e.state.termdbConfig,e.state.vocab.dslabel,s,t,o.body.append("div").style("margin","20px"),e.app.opts.genome)}e.dom.tip.hide()};e.openDiscoPlot=async function(t){e.dom.tooltip.hide();e.onClick=false;t.sample_id=t.sample;const s=d(e.opts.plotDiv);s.header.text(t.sample_id);const o=await import("./plot.disco-621d1b8e.js");o.default(e.state.termdbConfig,e.state.vocab.dslabel,t,s.body,e.app.opts.genome)};e.openLollipop=async function(t){e.dom.tooltip.hide();e.onClick=false;const s=d(e.opts.plotDiv||select(e.opts.holder.node().parentNode));s.header.text(t);const o={holder:s.body.append("div").style("margin","20px"),genome:e.app.opts.genome,nobox:true,query:t,tklst:[{type:"mds3",dslabel:e.app.opts.state.vocab.dslabel,filter0:e.state.termfilter.filter0,filterObj:e.state.termfilter.filter}]};const i=await import("./app-71453429.js").then((function(e){return e.c3}));await i.default(o)};e.onLegendClick=function(s,o,i,a,n,r){const l=e.config[i];const d=l.q.hiddenValues?a in l.q.hiddenValues:false;const c=new t({padding:"0px"});const h=c.d.append("div");h.append("div").attr("class","sja_menuoption sja_sharp_border").text(d?"Show":"Hide").on("click",(()=>{e.hideCategory(o,l,a,!d);c.hide();const t={};t[i]=l;e.app.dispatch({type:"plot_edit",id:e.id,config:t})}));h.append("div").attr("class","sja_menuoption sja_sharp_border").text("Show only").on("click",(()=>{const t=i=="colorTW"?s.colorLegend:s.shapeLegend;for(const s of t.keys())e.hideCategory(o,l,s,l.term.type=="geneVariant"&&!l.q.groupsetting.inuse?!s.startsWith(a):s!=a);c.hide();const n={};n[i]=l;e.app.dispatch({type:"plot_edit",id:e.id,config:n})}));h.append("div").attr("class","sja_menuoption sja_sharp_border").text("Show all").on("click",(()=>{c.hide();const t=i=="colorTW"?s.colorLegend:s.shapeLegend;for(const s of t.keys())e.hideCategory(o,l,s,false);const a={};a[i]=l;e.app.dispatch({type:"plot_edit",id:e.id,config:a})}));if(r.color){const t=p(r.color).formatHex();const s=h.append("div").attr("class","sja_sharp_border").style("padding","0px 10px").text("Color:").append("input").attr("type","color").attr("value",t).on("change",(()=>{e.changeColor(a,s.node().value);c.hide()}))}c.showunder(n.target)};e.hideCategory=function(t,s,o,i){if(o=="Ref"){e.settings.showRef=!i;e.app.dispatch({type:"plot_edit",id:e.id,config:{settings:{sampleScatter:e.settings}}})}if(!s.q.hiddenValues)s.q.hiddenValues={};const a=!(s.term.type=="geneVariant"&&!s.q.groupsetting.inuse)&&s.term.values[o]?s.term.values[o]:{key:o,label:o};const n=t.selectAll(`text[name="sjpp-scatter-legend-label"]`).nodes();const r=n.find((e=>o.startsWith(e.innerHTML)))?.parentElement;if(r)r.style["text-decoration"]=i?"line-through":"none";if(!i)delete s.q.hiddenValues[o];else s.q.hiddenValues[o]=a};e.changeColor=async function(t,s){const o=e.config.colorTW;if(!(o.term.type=="geneVariant"&&!o.q.groupsetting.inuse)&&o.term.values[t])o.term.values[t].color=s;else{if(!o.term.values)o.term.values={};o.term.values[t]={key:t,label:t,color:s}}await e.app.dispatch({type:"plot_edit",id:e.id,config:{colorTW:o}})};e.searchSample=async function(s){if(!this.searchMenu){this.searchMenu=new t({padding:"3px"});this.samplesData=await this.app.vocabApi.getSamplesByName({filter:e.state.termfilter.filter});const s=e=>{};T(this.searchMenu.d,this.samplesData,s,(t=>e.filterSamples(t)))}this.searchMenu.show(s.clientX,s.clientY,false)};e.filterSamples=function(t){this.filterSampleStr=t;e.render()};e.getCategoryInfo=function(e,t){if(!(t in e))return"";return e[t]};e.addToFilter=function(t){const s=h(e.state.termfilter.filter,"filterUiRoot");const o=u([s,b(t)]);o.tag="filterUiRoot";e.app.dispatch({type:"filter_replace",filter:o})};e.showTable=function(t,s,o,i){let a=[];const n=[];const r=t.items[0];if("sample"in r)n.push(f("Sample","label"));if(e.config.colorTW)n.push(f(e.config.colorTW.term.name,"label"));if(e.config.shapeTW)n.push(f(e.config.shapeTW.term.name,"label"));let l=false;for(const s of t.items){const t=[];if("sample"in s)t.push(f(s.sample));if(e.config.colorTW)t.push(f(e.getCategoryInfo(s,"category")));if(e.config.shapeTW)t.push(f(e.getCategoryInfo(s,"shape")));if("info"in s){l=true;const e=[];for(const[t,o]of Object.entries(s.info))e.push(`${t}: ${o}`);t.push(f(e.join(", ")))}a.push(t)}if(l)n.push(f("Info","label"));e.dom.tip.clear();const p=e.dom.tip.d.append("div").style("padding","5px");const d=p.append("div").style("margin-top","5px");const h=d.append("div").html(" "+t.name).style("font-size","0.9rem").on("click",(()=>{const s=h.select("input").empty();if(!s)return;h.html("");const o=h.append("input").attr("value",t.name).on("change",(async()=>{const s=o.node().value;if(s)e.renameGroup(t,s);else o.node().value=t.name;h.html(" "+t.name)}));o.node().focus();o.node().select()}));const m=p.append("div");const u=[];if(i){const t={text:"Add to a group",callback:t=>{const s=[];for(const o of t)s.push(e.selectedItems[o].__data__);const o={name:`Group ${e.config.groups.length+1}`,items:s,index:e.config.groups.length};const i=b(v([o]));C(e.app,i,e.state.groups)}};u.push(t)}else{const a={text:"Delete samples",callback:a=>{t.items=t.items.filter(((e,t,s)=>!(t in a)));e.showTable(t,s,o,i)}};u.push(a)}c({rows:a,columns:n,div:m,showLines:true,maxWidth:n.length*"15"+"vw",maxHeight:"35vh",buttons:u,selectAll:true});e.dom.tip.show(s,o,false,false);function f(e,t="value"){let s={};s[t]=e;return s}};e.showGroupMenu=function(t,s){e.dom.tip.clear();e.dom.tip.show(t.clientX,t.clientY,false,true);const o=e.dom.tip.d.append("div");const i=e.config.name?e.config.name:"Summary scatter";const a=v([s],i+" groups");const n=o.append("div").attr("name","sjpp-group-input-div").html(" "+s.name).style("font-size","0.9rem").on("click",(()=>{const t=n.select("input").empty();if(!t)return;n.html("");const o=n.append("input").attr("value",s.name).on("change",(async()=>{const t=o.node().value;if(t)e.renameGroup(s,t);else o.node().value=s.name;n.html(" "+s.name)}));o.node().focus();o.node().select()}));o.append("div").attr("class","sja_menuoption sja_sharp_border").text(`Edit ${s.items.length} samples`).on("click",(o=>{e.dom.tip.hide();e.showTable(s,t.clientX,t.clientY,false)}));e.addCommonMenuItems(o,a);o.append("div").attr("class","sja_menuoption sja_sharp_border").text(`Delete group`).on("click",(async t=>{await e.app.vocabApi.deleteGroup(s.name);e.dom.tip.hide()}));o.append("div").attr("class","sja_menuoption sja_sharp_border").text("Add to filter").on("click",(()=>{e.addToFilter(a);e.app.dispatch({type:"plot_edit",id:e.id,config:{groups:e.config.groups}})}));o.append("div").attr("class","sja_menuoption sja_sharp_border").text(s.showOnly?"Show All":"Show Only").on("click",(()=>{s.showOnly=!s.showOnly;e.app.dispatch({type:"plot_edit",id:e.id,config:{groups:e.config.groups}})}))};e.renameGroup=async function(t,s){const o=e.config.groups.findIndex((e=>e.name==s));if(o!=-1)alert(`Group named ${s} already exists`);else await e.app.dispatch({type:"rename_group",index:t.index,newName:s})};e.addCommonMenuItems=function(t,s){x(e.dom.tip,t,s,e.app,e.id,e.state);if(e.state.supportedChartTypes.includes("survival"))w("survival",t,"Compare survival",e.dom.tip,s,e.id,this);if(e.state.supportedChartTypes.includes("cuminc"))w("cuminc",t,"Compare cumulative incidence",e.dom.tip,s,e.id,this);const o=t.append("div").attr("class","sja_menuoption sja_sharp_border").html("Summarize");o.insert("div").html("›").style("float","right");o.on("click",(async t=>{S(o,(t=>{k(t,s,e.app,e.id)}),e.app,e.dom.tip)}))};e.showGroupsMenu=function(t){e.dom.tip.clear();e.dom.tip.show(t.clientX,t.clientY,false,true);const s=e.dom.tip.d.append("div");const o=e.config.name?e.config.name:"Summary scatter";const i=v(e.config.groups,o+" groups");let a=s.append("div");for(const[o,i]of e.config.groups.entries()){a=s.append("div").attr("class","sja_menuoption sja_sharp_border");a.insert("div").style("display","inline-block").text(` ${i.name}: ${i.items.length} `);a.append("div").style("display","inline-block").style("float","right").html(" ›");a.on("click",(s=>{e.dom.tip.clear().hide();e.showGroupMenu(t,i)}))}e.addCommonMenuItems(s,i);a=s.append("div").attr("class","sja_menuoption sja_sharp_border").text("Delete groups").on("click",(async t=>{for(const t of e.config.groups)await e.app.vocabApi.deleteGroup(t.name);e.app.dispatch({type:"plot_edit",id:e.id,config:{groups:[]}})}))}}function J(e,t,s,o,i){const a=i.xAxisScale(s)-i.xAxisScale(e);const n=i.yAxisScale(o)-i.yAxisScale(t);const r=Math.sqrt(Math.pow(a,2)+Math.pow(n,2));return r}var P=Object.freeze({__proto__:null,setInteractivity:F});export{P as a,H as g,z as n,F as s};
|