python-plotto 0.1.0__tar.gz → 0.2.0__tar.gz

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.
Files changed (21) hide show
  1. {python_plotto-0.1.0/python_plotto.egg-info → python_plotto-0.2.0}/PKG-INFO +1 -1
  2. {python_plotto-0.1.0 → python_plotto-0.2.0}/plotto/__init__.py +1 -1
  3. {python_plotto-0.1.0 → python_plotto-0.2.0}/plotto/_assets/grammar.json +3 -1
  4. python_plotto-0.2.0/plotto/_assets/plotto.js +34 -0
  5. {python_plotto-0.1.0 → python_plotto-0.2.0}/plotto/plot.py +45 -3
  6. {python_plotto-0.1.0 → python_plotto-0.2.0/python_plotto.egg-info}/PKG-INFO +1 -1
  7. {python_plotto-0.1.0 → python_plotto-0.2.0}/tests/test_builder.py +12 -0
  8. python_plotto-0.1.0/plotto/_assets/plotto.js +0 -34
  9. {python_plotto-0.1.0 → python_plotto-0.2.0}/LICENSE +0 -0
  10. {python_plotto-0.1.0 → python_plotto-0.2.0}/README.md +0 -0
  11. {python_plotto-0.1.0 → python_plotto-0.2.0}/plotto/_assets/theme.json +0 -0
  12. {python_plotto-0.1.0 → python_plotto-0.2.0}/plotto/assets.py +0 -0
  13. {python_plotto-0.1.0 → python_plotto-0.2.0}/plotto/data.py +0 -0
  14. {python_plotto-0.1.0 → python_plotto-0.2.0}/plotto/output.py +0 -0
  15. {python_plotto-0.1.0 → python_plotto-0.2.0}/pyproject.toml +0 -0
  16. {python_plotto-0.1.0 → python_plotto-0.2.0}/python_plotto.egg-info/SOURCES.txt +0 -0
  17. {python_plotto-0.1.0 → python_plotto-0.2.0}/python_plotto.egg-info/dependency_links.txt +0 -0
  18. {python_plotto-0.1.0 → python_plotto-0.2.0}/python_plotto.egg-info/requires.txt +0 -0
  19. {python_plotto-0.1.0 → python_plotto-0.2.0}/python_plotto.egg-info/top_level.txt +0 -0
  20. {python_plotto-0.1.0 → python_plotto-0.2.0}/setup.cfg +0 -0
  21. {python_plotto-0.1.0 → python_plotto-0.2.0}/tests/test_output.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-plotto
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Grammar-of-graphics plots for notebooks, web pages and slides with one renderer.
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://theoradusz.github.io/plotto/
@@ -3,7 +3,7 @@
3
3
  https://github.com/theoradusz/plotto
4
4
  """
5
5
 
6
- __version__ = "0.1.0"
6
+ __version__ = "0.2.0"
7
7
 
8
8
  from .plot import Plot, plot # noqa: E402
9
9
 
@@ -47,5 +47,7 @@
47
47
  "free": ["x", "y", "both"],
48
48
  "labels": ["title", "subtitle", "x", "y", "color", "caption"],
49
49
  "theme": ["format", "width", "height", "size", "legend"],
50
- "legend": ["right", "bottom", "none"]
50
+ "legend": ["right", "bottom", "none"],
51
+ "info": ["position"],
52
+ "infoPosition": ["right", "bottom"]
51
53
  }
@@ -0,0 +1,34 @@
1
+ var P={options:{size:"number",alpha:"number",dash:["solid","dashed","dotted","dashdot"],jitter:"number",summary:["mean","median","min","max","sum"],slope:"number",intercept:"number",position:["stack","dodge","overlay"],bins:"number",density:"boolean",method:["lm","loess"],span:"number",band:"boolean"},layers:{line:{channels:["x","y","color","group","tooltip"],options:["size","alpha","dash","summary"],requires:["x","y"]},path:{channels:["x","y","color","group","tooltip"],options:["size","alpha","dash"],requires:["x","y"]},step:{channels:["x","y","color","group","tooltip"],options:["size","alpha","dash"],requires:["x","y"]},point:{channels:["x","y","color","tooltip"],options:["size","alpha","jitter","summary"],requires:["x","y"]},bar:{channels:["x","y","color","tooltip"],options:["alpha","position"],requires:["x","y"]},hist:{channels:["x","color"],options:["alpha","bins","density","position"],requires:["x"]},density:{channels:["x","color"],options:["size","alpha","dash"],requires:["x"]},area:{channels:["x","y","color","group"],options:["alpha","position"],requires:["x","y"]},ribbon:{channels:["x","ymin","ymax","color","group"],options:["alpha"],requires:["x","ymin","ymax"]},smooth:{channels:["x","y","color"],options:["size","alpha","dash","method","span","band"],requires:["x","y"]},hline:{channels:["y","color"],options:["size","alpha","dash"],requires:["y"],inherit:!1},vline:{channels:["x","color"],options:["size","alpha","dash"],requires:["x"],inherit:!1},abline:{channels:["color"],options:["slope","intercept","size","alpha","dash"],requires:[],inherit:!1},segment:{channels:["x","y","xend","yend","color"],options:["size","alpha","dash"],requires:["x","y","xend","yend"]},rect:{channels:["xmin","xmax","ymin","ymax","color","tooltip"],options:["alpha"],requires:["xmin","xmax","ymin","ymax"]},band:{channels:["xmin","xmax","ymin","ymax","color"],options:["alpha"],requires:[],inherit:!1},tile:{channels:["x","y","color","tooltip"],options:["alpha"],requires:["x","y","color"]},text:{channels:["x","y","label","color"],options:["size","alpha"],requires:["x","y","label"]},errorbar:{channels:["x","ymin","ymax","color"],options:["size","alpha"],requires:["x","ymin","ymax"]},box:{channels:["x","y","color"],options:["alpha"],requires:["x","y"]}},scales:{x:["type","limits","format"],y:["type","limits","format"],color:["values","palette","scheme","limits","mid","clamp"]},scaleTypes:["linear","log","time","category"],facet:["free","ncol"],grid:["free"],free:["x","y","both"],labels:["title","subtitle","x","y","color","caption"],theme:["format","width","height","size","legend"],legend:["right","bottom","none"],info:["position"],infoPosition:["right","bottom"]};var T={styles:{pastel:{font:"Helvetica, Arial, 'Liberation Sans', sans-serif",metrics:"arial",background:"#FFFEFB",ink:"#3A3631",muted:"#7A736A",grid:"#ECE8E1",gridMinor:"#F6F3EE",tick:"#D6D0C6",strip:"#F4F0E9",accent:"#3E8A99",palette:"pastel",scheme:"ai",colors:{blue:"#7AA6DA",orange:"#EF977F",green:"#7DB89A",purple:"#A79BD6",pink:"#E48FAE",yellow:"#DDB459",teal:"#63B7C1",red:"#CF7468",brown:"#BB9C84",gray:"#97A1AD"},weight:1.25},wota:{font:"'M PLUS 1p', sans-serif",metrics:"mplus",ink:"#333333",muted:"#666666",grid:"#D9D9D9",gridMinor:"#EFEFEF",tick:"#BBBBBB",strip:"#EEF1FA",accent:"#5C6BC0",palette:"wota",scheme:"sakura",colors:{pink:"#E4007F",blue:"#5C6BC0",teal:"#00A3A3",orange:"#F5A623",purple:"#8E44AD",gray:"#7F7F7F",green:"#3BA55C",red:"#D7263D",yellow:"#F2C14E",brown:"#8D6E63"},weight:1,background:"#FFFFFF"},paper:{ink:"#000000",muted:"#333333",grid:"#E6E6E6",gridMinor:"#F5F5F5",tick:"#8C8C8C",strip:"#EBEBEB",accent:"#0072B2",palette:["blue","orange","green","pink","yellow","teal","red","brown","purple","gray"],scheme:"viridis",colors:{blue:"#0072B2",orange:"#E69F00",green:"#009E73",pink:"#CC79A7",yellow:"#F0E442",teal:"#56B4E9",red:"#D55E00",brown:"#8C6D31",purple:"#6A3D9A",gray:"#7F7F7F"},weight:1,background:"#FFFFFF"},dark:{background:"#16181D",ink:"#E8EAED",muted:"#A6ABB3",grid:"#2E323A",gridMinor:"#22252B",tick:"#4F5560",strip:"#252933",accent:"#8AB4F8",palette:["blue","orange","green","purple","pink","yellow","teal","red","brown","gray"],scheme:"yuhi",colors:{blue:"#8AB4F8",orange:"#FBA94C",green:"#81C995",purple:"#C58AF9",pink:"#FF8BCB",yellow:"#FDD663",teal:"#78D9D3",red:"#F28B82",brown:"#C8A27A",gray:"#9AA0A6"},weight:1.15}},palettes:{pastel:["#7AA6DA","#EF977F","#7DB89A","#A79BD6","#E48FAE","#DDB459","#63B7C1","#CF7468","#BB9C84","#97A1AD"],wota:["#E4007F","#5C6BC0","#00A3A3","#F5A623","#8E44AD","#7F7F7F","#3BA55C","#D7263D","#F2C14E","#8D6E63"],sakura:["#E16B8C","#5DAC81","#8B81C3","#FFB11B","#7DB9DE","#F596AA","#B9887D","#91AD70"],aizome:["#0F2540","#51A8DD","#66BAB7","#656765","#0D5661","#A5DEE4","#7B90D2"],momiji:["#CB4042","#FFB11B","#6C6A2D","#6D2E5B","#ED784A","#734338","#C99833"],tableau:["#4E79A7","#F28E2B","#E15759","#76B7B2","#59A14F","#EDC948","#B07AA1","#FF9DA7","#9C755F","#BAB0AC"]},schemes:{ai:["#F4F8F8","#A5DEE4","#33A6B8","#0D5661","#0F2540"],sakura:["#FEF4F4","#FEDFE1","#F596AA","#D05A6E","#8E354A","#4A1D30"],matcha:["#F8F6E3","#D7E3B5","#91AD70","#5DAC81","#1B813E","#0B3B2A"],yuhi:["#FFF3D6","#FFB11B","#ED784A","#CB4042","#6D2E5B","#26113A"],sumi:["#FCFAF2","#BDC0BA","#828282","#434343","#1C1C1C"],aiaka:["#0F2540","#33A6B8","#A5DEE4","#F7F6F0","#F4A7A0","#CB4042","#5C1A1B"]},formats:{screen:{width:900,height:450,size:12,line:1.5,point:2.5,reflow:!0},report:{width:640,height:400,size:10,line:1.2,point:2,reflow:!1},slide:{width:1280,height:720,size:20,line:2.5,point:4,reflow:!1}}};var me=P.layers,de=[...new Set(Object.values(me).flatMap(t=>t.channels))];function fe(t,e={}){let n=[xe(t,"plot()")];for(let[s,o]of Object.entries(e))de.includes(s)||_("plot()","channel",s,de),Gt(n[0],o,"plot()");return new Xt({data:n,mapping:e,layers:[],facet:null,scales:{},labels:{},info:null,theme:{style:"pastel"}})}var Xt=class t{#e;constructor(e){this.#e=e}#n(e){return new t({...this.#e,...e})}#t(e,n={}){let s=me[e],o=`${e}()`,{data:r,...i}=n,l=this.#e.data,a=0;r!==void 0&&(l=[...l,xe(r,o)],a=l.length-1);let c=l[a].columns,u={type:e,mapping:{},set:{}};a&&(u.data=a);for(let[d,h]of Object.entries(i))s.channels.includes(d)&&typeof h=="string"&&h in c?u.mapping[d]=h:s.channels.includes(d)||s.options.includes(d)?u.set[d]=Sn(d,h,o,c):_(o,"option",d,["data",...s.channels,...s.options]);return this.#n({data:l,layers:[...this.#e.layers,u]})}line(e){return this.#t("line",e)}step(e){return this.#t("step",e)}bar(e){return this.#t("bar",e)}hist(e){return this.#t("hist",e)}density(e){return this.#t("density",e)}area(e){return this.#t("area",e)}ribbon(e){return this.#t("ribbon",e)}smooth(e){return this.#t("smooth",e)}path(e){return this.#t("path",e)}point(e){return this.#t("point",e)}hline(e){return this.#t("hline",e)}vline(e){return this.#t("vline",e)}abline(e){return this.#t("abline",e)}segment(e){return this.#t("segment",e)}rect(e){return this.#t("rect",e)}band(e){return this.#t("band",e)}tile(e){return this.#t("tile",e)}text(e){return this.#t("text",e)}errorbar(e){return this.#t("errorbar",e)}box(e){return this.#t("box",e)}facet(e,n={}){return Gt(this.#e.data[0],e,"facet()"),xt(n,P.facet,"facet()"),he(n.free,"facet()"),this.#n({facet:{wrap:e,free:n.free??null,ncol:n.ncol??null}})}grid({rows:e=null,cols:n=null,...s}={}){if(e===null&&n===null)throw new Error("grid(): set rows, cols or both");for(let o of[e,n])o!==null&&Gt(this.#e.data[0],o,"grid()");return xt(s,P.grid,"grid()"),he(s.free,"grid()"),this.#n({facet:{rows:e,cols:n,free:s.free??null}})}x(e){return this.#o("x",e)}y(e){return this.#o("y",e)}color(e){return this.#o("color",e)}#o(e,n={}){let s=`${e}()`;if(xt(n,P.scales[e],s),n.type!==void 0&&!P.scaleTypes.includes(n.type)&&_(s,"type",n.type,P.scaleTypes),n.palette!==void 0&&!Array.isArray(n.palette)&&!(n.palette in T.palettes)&&_(s,"palette",n.palette,Object.keys(T.palettes)),n.mid!==void 0&&typeof n.mid!="number")throw new Error(`${s}: mid must be a number`);let o={...n};if(o.limits){if(!Array.isArray(o.limits))throw new Error(`${s}: limits must be a list, for example [0, 10] or [0, null]`);o.limits=o.limits.map(r=>r==null?null:Bt(r))}return this.#n({scales:{...this.#e.scales,[e]:o}})}labels(e={}){return xt(e,P.labels,"labels()"),this.#n({labels:{...this.#e.labels,...e}})}info(e,n={}){xt(n,P.info,"info()");let s=n.position??"right";if(P.infoPosition.includes(s)||_("info()","position",s,P.infoPosition),e==null)return this.#n({info:null});let o=Array.isArray(e)?e:typeof e=="object"?Object.entries(e):null;if(!o)throw new Error("info(): entries must be an object or a list of [key, value] pairs");return this.#n({info:{entries:o.map(r=>Cn(r)),position:s}})}theme(e="pastel",n={}){return xt(n,P.theme,"theme()"),e in T.styles||_("theme()","style",e,Object.keys(T.styles)),n.format!==void 0&&!(n.format in T.formats)&&_("theme()","format",n.format,Object.keys(T.formats)),n.legend!==void 0&&!P.legend.includes(n.legend)&&_("theme()","legend",n.legend,P.legend),this.#n({theme:{style:e,...n}})}spec(){let e=this.#e,n=e.data.map(()=>new Set);for(let o of Object.values(e.mapping))n.forEach((r,i)=>o in e.data[i].columns&&r.add(o));for(let o of e.layers)for(let r of Object.values(o.mapping))n[o.data??0].add(r);for(let o of[e.facet?.wrap,e.facet?.rows,e.facet?.cols])o&&n.forEach((r,i)=>o in e.data[i].columns&&r.add(o));return{version:1,data:e.data.map((o,r)=>({columns:Object.fromEntries([...n[r]].map(i=>[i,o.columns[i]]))})),mapping:e.mapping,layers:e.layers,facet:e.facet,scales:e.scales,labels:e.labels,...e.info?{info:e.info}:{},theme:e.theme}}};function xe(t,e){if(!Array.isArray(t))throw new Error(`${e}: data must be an array of row objects`);let n=[...new Set(t.flatMap(Object.keys))],s={};for(let o of n){let r=t.map(c=>c[o]??null),i=r.find(c=>c!==null&&!Number.isNaN(c)),l=i instanceof Date?"time":typeof i=="number"?"number":"string",a=r.map(c=>c===null||Number.isNaN(c)?null:l==="string"?String(c):Bt(c));s[o]={type:l,values:a}}return{columns:s}}function Bt(t){return t instanceof Date?t.getTime()-t.getTimezoneOffset()*6e4:typeof t=="number"&&!Number.isInteger(t)?Number(t.toPrecision(6)):t}function Sn(t,e,n,s){let o=P.options[t];if(t==="tooltip"||t==="group")throw new Error(`${n}: ${t} must be a column. Columns: ${Object.keys(s).join(", ")}`);if(Array.isArray(o)&&!o.includes(e)&&_(n,t,e,o),o==="number"&&typeof e!="number")throw new Error(`${n}: ${t} must be a number`);if(o==="boolean"&&typeof e!="boolean")throw new Error(`${n}: ${t} must be true or false`);if(t==="color"||t==="label")return e;if(typeof e=="string"&&!o)throw new Error(`${n}: "${e}" is not a column. Columns: ${Object.keys(s).join(", ")}`);return Bt(e)}function Cn(t){if(!Array.isArray(t)||t.length!==2||typeof t[0]!="string")throw new Error("info(): each entry must be a [key, value] pair with a string key");let[e,n]=t;if(n==null||typeof n=="number"&&Number.isNaN(n))return[e,null];if(!["string","number","boolean"].includes(typeof n))throw new Error(`info(): the value of "${e}" must be a string, a number, a boolean or null. Format other values as a string`);return[e,Bt(n)]}function Gt(t,e,n){if(!(e in t.columns))throw new Error(`${n}: "${e}" is not a column. Columns: ${Object.keys(t.columns).join(", ")}`)}function xt(t,e,n){for(let s of Object.keys(t))e.includes(s)||_(n,"option",s,e)}function he(t,e){t!=null&&!P.free.includes(t)&&_(e,"free",t,P.free)}function _(t,e,n,s){throw new Error(`${t}: unknown ${e} "${n}". Valid: ${s.join(", ")}`)}import*as X from"https://cdn.jsdelivr.net/npm/@observablehq/plot@0.6.17/+esm";import*as Tt from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";import*as L from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";import*as H from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var Dn=Object.keys(T.styles),zn=Object.keys(T.formats),$n=Object.keys(T.palettes),Bn=Object.keys(T.schemes),ye=["ink","muted","grid","tick","strip","accent","background"];function ge({style:t="pastel",format:e="screen",legend:n="right",...s}={}){if(!T.styles[t])throw new Error(`theme(): unknown style "${t}". Valid: ${Dn.join(", ")}`);if(!T.formats[e])throw new Error(`theme(): unknown format "${e}". Valid: ${zn.join(", ")}`);let o=T.styles.pastel,r=T.styles[t],i=T.formats[e],l=s.width!=null;for(let c of Object.keys(s))s[c]==null&&delete s[c];let a={...o,...r,colors:{...o.colors,...r.colors},...i,legend:n,...s,style:t,format:e};return a.reflow=i.reflow&&!l,a.line=i.line*(r.weight??o.weight??1),a.point=i.point*Math.sqrt(r.weight??o.weight??1),s.width!=null&&s.height==null&&(a.height=Math.round(s.width*i.height/i.width)),a.fixedHeight=s.height!=null,a.palette=Vt(a,a.palette),a}function Vt(t,e){let n=Array.isArray(e)?e:T.palettes[e];if(!n)throw new Error(`color(): unknown palette "${e}". Valid: ${$n.join(", ")}`);return n.map(s=>yt(t,s)??s)}function be(t,e){let n=o=>H.piecewise(H.interpolateLab,o.map(r=>yt(t,r)??r));if(Array.isArray(e))return n(e);if(T.schemes[e])return n(T.schemes[e]);let s=typeof e=="string"&&H[`interpolate${e[0].toUpperCase()}${e.slice(1)}`];if(!s)throw new Error(`color(): unknown scheme "${e}". plotto schemes: ${Bn.join(", ")}; or a d3 scheme such as viridis, magma, blues`);return s}function yt(t,e){if(typeof e=="string")return t.colors[e]?t.colors[e]:ye.includes(e)?t[e]:H.color(e)?e:void 0}function we(t){return[...Object.keys(t.colors),...ye]}function Ut(t){let e=o=>{let r=[o.r,o.g,o.b].map(i=>(i/=255,i<=.03928?i/12.92:((i+.055)/1.055)**2.4));return .2126*r[0]+.7152*r[1]+.0722*r[2]},n=H.rgb(t);if(e(n)>.42)return{bg:n.formatHex(),fg:"#1F2328"};let s=H.hcl(n);for(let o=0;o<20&&1.05/(e(H.rgb(s))+.05)<4;o++)s=H.hcl(s.h,s.c,s.l-4);return{bg:H.rgb(s).formatHex(),fg:"#FFFFFF"}}function ve(t){return Ut(t).fg}function ke(t){let e=t.size;return{base:e,tick:e-1,title:Math.round(e*1.35),subtitle:e,strip:e-1,legend:e-1,axisTitle:e,hover:Math.max(11,e-1)}}var At={x:["x","xmin","xmax","xend"],y:["y","ymin","ymax","yend"]},Me=.05,_t=864e5;function Kt(t,e){let n=t.scales[e]?.type;if(n)return n;for(let s of t.layers)for(let o of At[e]){let r=s.channels[o]?.column;if(!r)continue;let i=t.tables[s.table].columns[r].type;return i==="time"?"time":i==="string"?"category":"linear"}return"linear"}function Ae(t,e,n,s){let o=e.channels[n];if(!o)return;if("value"in o)return s.map(()=>o.value);let r=t.tables[e.table].columns[o.column].values;return s.map(i=>r[i])}function Fe(t,e,n,s){let o=[];for(let i of s)for(let l of i.views)for(let a of At[e]){let c=l.cols[a];if(c)for(let u of c)u!=null&&(n==="category"||Number.isFinite(u))&&o.push(u)}if(n==="category")return Ln(t,e,o);let r=L.extent(o.filter(i=>n!=="log"||i>0));return r[0]===void 0?n==="log"?[1,10]:[0,1]:Se(r,n)}function Ln(t,e,n){let s=t.layers.map(r=>r.channels[e]?.column&&t.tables[r.table].columns[r.channels[e].column].levels).find(Boolean),o=new Set(n.map(String));return s?s.filter(r=>o.has(r)):[...o].sort(Lt)}function Lt(t,e){return String(t).localeCompare(String(e),void 0,{numeric:!0})}function Se([t,e],n){if(n==="log"){let[o,r]=Se([Math.log10(t),Math.log10(e)],"linear");return[10**o,10**r]}let s=e>t?(e-t)*Me:n==="time"?36e5:Math.abs(t)*Me||1;return[t-s,e+s]}function gt(t,e,n,s){if(t==="category")return{major:e,minor:[],format:String};let[o,r]=e;if(t==="time"){let l=L.scaleUtc().domain([new Date(o),new Date(r)]).ticks(n),a=s??On(l,r-o);return{major:l,minor:Ee(l,e,c=>+c).map(c=>new Date(c)),format:L.utcFormat(a)}}if(t==="log"){let l=L.range(Math.ceil(Math.log10(o)),Math.floor(Math.log10(r))+1).map(u=>10**u),a=l.length>=2?l:L.scaleLog().domain(e).ticks(n).filter(u=>[1,2,5].includes(Math.round(u/10**Math.floor(Math.log10(u)+1e-9)))),c=l.flatMap(u=>L.range(2,10).map(d=>u/10*d)).filter(u=>u>o&&u<r);return{major:a,minor:c,format:L.format(s??"~g")}}let i=L.ticks(o,r,n);return{major:i,minor:Ee(i,e,Number),format:s?L.format(s):L.tickFormat(o,r,n)}}function Ee(t,[e,n],s){if(t.length<2)return[];let o=s(t[1])-s(t[0]);return[s(t[0])-o/2,...t.map(i=>s(i)+o/2)].filter(i=>i>e&&i<n)}function On(t,e){let n=t.length>=2?t[1]-t[0]:e;return n>=28*_t?"%Y-%m":n>=_t?"%m-%d":n>=6e4?e>_t?"%m-%d %H:%M":"%H:%M":"%H:%M:%S"}var Pn=L.format(",.4~r"),Ce={number:t=>t==null?"\u2013":Math.abs(t)>=1e15||t!==0&&Math.abs(t)<1e-4?L.format(".3~e")(t):Pn(t),time:L.utcFormat("%m-%d %H:%M"),string:t=>t==null?"\u2013":String(t)};function De(t){let e=t.theme,n=t.scales.color??{},s=t.layers.filter(f=>f.channels.color?.column);if(!s.length)return{kind:"none"};let o=s[0].channels.color.column,r=s.find(f=>f.channels.color.column!==o);if(r)throw new Error(`plotto: color maps "${o}" and "${r.channels.color.column}". Map color to one column only`);let i=s.map(f=>t.tables[f.table].columns[o]),l=i[0].type,a=i.flatMap(f=>f.values).filter(f=>f!==null),c=f=>yt(e,f)??f;if(l==="string"){let f=i.find(F=>F.levels)?.levels,y=new Set(a),m=n.limits??(f?f.filter(F=>y.has(F)):[...y].sort(Lt)),x=n.palette?Vt(e,n.palette):e.palette,k=n.values,M=Array.isArray(k)?(F,S)=>c(k[S%k.length]):k?(F,S)=>c(k[F]??x[S%x.length]):(F,S)=>x[S%x.length],A=new Map(m.map((F,S)=>[F,M(F,S)]));return{kind:"ordinal",column:o,domain:m,apply:F=>A.get(F)??e.muted}}let[u,d]=Tn(n.limits,L.extent(a)),h=be(e,n.values??n.scheme??e.scheme),p=n.mid,v=f=>p===void 0?(f-u)/(d-u||1):f<p?.5*((f-u)/(p-u||1)):.5+.5*((f-p)/(d-p||1)),g=f=>f>=u&&f<=d,w=f=>f===null?e.muted:n.clamp||g(f)?h(Math.max(0,Math.min(1,v(f)))):e.muted;return{kind:"continuous",column:o,domain:[u,d],type:l,interpolate:h,apply:w,ramp:f=>w(u+f*(d-u))}}function Tn(t,e){return t?[t[0]??e[0],t[1]??e[1]]:e}function ze(t){let e=t.facet;if(!e)return{kind:"none",nrow:1,ncol:1,panels:[Jt(t,0,0,{},{})]};if(e.kind==="wrap"){let r=Zt(t,e.by),i=e.ncol??Nn(r.length),l=r.map((a,c)=>Jt(t,Math.floor(c/i),c%i,{[e.by]:a},{top:a}));return{kind:"wrap",nrow:Math.ceil(r.length/i),ncol:i,panels:l}}let n=e.rows?Zt(t,e.rows):[null],s=e.cols?Zt(t,e.cols):[null],o=[];return n.forEach((r,i)=>s.forEach((l,a)=>{let c={};e.rows&&(c[e.rows]=r),e.cols&&(c[e.cols]=l),o.push(Jt(t,i,a,c,{top:i===0?l:null,right:a===s.length-1?r:null}))})),{kind:"grid",nrow:n.length,ncol:s.length,panels:o}}function Nn(t){return t<=3?t:t<=6?Math.ceil(t/2):t<=12?Math.ceil(t/3):Math.ceil(Math.sqrt(t))}function Zt(t,e){let n=t.tables[0].columns[e];return n.levels?n.levels.filter(s=>n.values.includes(s)):[...new Set(n.values.filter(s=>s!==null).map(String))].sort(Lt)}function Jt(t,e,n,s,o){let r=t.layers.map(i=>{let l=t.tables[i.table];if(!Object.values(i.channels).some(u=>u.column))return[0];let a=Object.entries(s).filter(([u])=>u in l.columns),c=Array.from({length:l.n},(u,d)=>d);return a.length?c.filter(u=>a.every(([d,h])=>String(l.columns[d].values[u])===h)):c});return{row:e,col:n,strips:o,rows:r}}import*as ct from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var jn="http://www.w3.org/2000/svg";function B(t,e,n={}){let s=t.createElementNS(jn,e);for(let[o,r]of Object.entries(n))r!=null&&s.setAttribute(o,String(r));return s}function W(t,e,n,s="text"){let o=B(t,s,n);return o.textContent=e,o}var $e={arial:{regular:[.278,.278,.355,.556,.556,.889,.667,.191,.333,.333,.389,.584,.278,.333,.278,.278,.556,.556,.556,.556,.556,.556,.556,.556,.556,.556,.278,.278,.584,.584,.584,.556,1.015,.667,.667,.722,.722,.667,.611,.778,.722,.278,.5,.667,.556,.833,.722,.778,.667,.778,.722,.667,.611,.722,.667,.944,.667,.667,.611,.278,.278,.278,.469,.556,.333,.556,.556,.5,.556,.556,.278,.556,.556,.222,.222,.5,.222,.833,.556,.556,.556,.556,.333,.5,.278,.556,.5,.722,.5,.5,.5,.334,.26,.334,.584],bold:[.278,.333,.474,.556,.556,.889,.722,.238,.333,.333,.389,.584,.278,.333,.278,.278,.556,.556,.556,.556,.556,.556,.556,.556,.556,.556,.333,.333,.584,.584,.584,.611,.975,.722,.722,.722,.722,.667,.611,.778,.722,.278,.556,.722,.611,.833,.722,.778,.667,.778,.722,.667,.611,.722,.667,.944,.667,.667,.611,.333,.278,.333,.584,.556,.333,.556,.611,.556,.611,.556,.333,.611,.611,.278,.278,.556,.278,.889,.611,.611,.611,.611,.389,.556,.333,.611,.556,.778,.556,.556,.5,.389,.28,.389,.584]},mplus:{regular:[.29,.363,.4,.678,.605,.847,.712,.237,.385,.385,.527,.733,.304,.457,.283,.507,.62,.62,.62,.62,.62,.62,.62,.62,.62,.62,.363,.384,.667,.753,.667,.611,.823,.693,.598,.695,.682,.587,.572,.745,.71,.317,.527,.633,.585,.857,.713,.793,.6,.785,.62,.573,.653,.683,.693,.953,.65,.67,.637,.47,.507,.47,.653,.583,.278,.548,.578,.522,.578,.552,.522,.573,.573,.307,.347,.562,.307,.805,.568,.57,.573,.573,.453,.497,.512,.558,.557,.81,.553,.557,.547,.513,.343,.513,.69],bold:[.304,.425,.478,.692,.625,.901,.753,.291,.426,.426,.536,.735,.351,.471,.338,.546,.64,.64,.64,.64,.64,.64,.64,.64,.64,.64,.418,.431,.681,.755,.681,.628,.818,.715,.62,.703,.696,.601,.586,.756,.735,.351,.558,.678,.6,.878,.735,.798,.628,.798,.651,.608,.668,.705,.715,.971,.678,.698,.651,.501,.546,.501,.695,.609,.336,.576,.606,.54,.606,.57,.543,.601,.605,.335,.378,.603,.335,.843,.6,.585,.601,.601,.485,.525,.533,.59,.581,.831,.585,.585,.568,.535,.381,.535,.705]}};var Hn=11904;function nt(t,e,n=!1,s="arial"){let o=$e[s][n?"bold":"regular"],r=0;for(let i of String(t)){let l=i.codePointAt(0);l>=32&&l<127?r+=o[l-32]:r+=l>=Hn?1:.6}return r*e}function at(t,e,n,s,o){if(t=String(t),nt(t,e,s,o)<=n)return t;let r=[...t];for(;r.length>1&&nt(r.join("")+"\u2026",e,s,o)>n;)r.pop();return r.join("")+"\u2026"}function Ft(t,e,n,s,o,r=2){let i=String(t).split(/\s+/),l=[],a="";for(let u of i){let d=a?`${a} ${u}`:u;a&&nt(d,e,s,o)>n?(l.push(a),a=u):a=d}if(l.push(a),l.length<=r)return l;let c=l.slice(0,r);return c[r-1]=at(l.slice(r-1).join(" "),e,n,s,o),c}var In=3,Rn=.45,qn={right:.3,bottom:.9},Wn={right:.6,bottom:.3},Yn=3;function Be(t,e,{W:n,H:s,narrow:o}){if(!t.info)return null;let r=o?"bottom":t.info.position;return Xn(t,e,t.info.entries,r,n,s*Wn[r])}function Xn(t,e,n,s,o,r){let i=t.theme.metrics,l=e.legend,a=Math.round(l*.8),c=l*1.35,u=l,d=l*2,h=n.map(([y,m])=>({key:String(y),value:m===null?"\u2013":String(m)})),p=y=>nt(y,l,!1,i),v=(y,m)=>{let x=Math.min(ct.max(y,S=>p(S.key))??0,m*Rn),k=Math.max(l*3,m-x-u),M=0,A=y.map(S=>{let O=Ft(S.value,l,k,!1,i,In),I={key:at(S.key,l,x,!1,i),full:S.key,lines:O,y:M};return M+=O.length*c,I}),F=ct.max(A,S=>ct.max(S.lines,p))??0;return{rows:A,keyW:x,width:x+u+F,height:M}},g=o*qn[s]-2*a,w=y=>{let m;if(s==="bottom"){let k=ct.max(y,S=>p(S.key)+u+p(S.value))??0,M=Math.max(1,Math.min(Yn,y.length,Math.floor((g+d)/(k+d)))),A=Math.ceil(y.length/M),F=(g-d*(M-1))/M;m=ct.range(M).map(S=>v(y.slice(S*A,(S+1)*A),F))}else m=[v(y,g)];let x=a;for(let k of m)k.x=x,x+=k.width+d;return{columns:m,width:x-d+a,height:(ct.max(m,k=>k.height)??0)+2*a}},b=h.length,f=w(h);for(;f.height>r&&b>1;)b--,f=w([...h.slice(0,b),{key:`+${h.length-b} more`,value:""}]);return{position:s,size:l,pad:a,lineH:c,keyGap:u,...f}}function Le(t,e,n,{x:s,y:o}){let r=B(t,"g",{class:"pt-info",transform:`translate(${s},${o})`,"font-size":e.size});r.append(B(t,"rect",{width:e.width,height:e.height,fill:n.strip}));let i=e.lineH*.75;for(let l of e.columns)for(let a of l.rows){let c=e.pad+a.y+i,u=W(t,a.key,{x:l.x,y:c,fill:n.muted,"text-anchor":"start"});a.key!==a.full&&u.append(W(t,a.full,{},"title")),r.append(u),a.lines.forEach((d,h)=>r.append(W(t,d,{x:l.x+l.keyW+e.keyGap,y:c+h*e.lineH,fill:n.ink,"text-anchor":"start"})))}return r}import*as E from"https://cdn.jsdelivr.net/npm/@observablehq/plot@0.6.17/+esm";import*as q from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var Gn={solid:void 0,dashed:"6,4",dotted:"1.5,3",dashdot:"6,3,1.5,3"},$="frame",Q=(t,e)=>({stroke:t.colors(e),strokeWidth:t.options.size??t.theme.line,strokeOpacity:t.options.alpha??1,strokeDasharray:Gn[t.options.dash],strokeLinejoin:"round",strokeLinecap:"round"}),ot=(t,e,n=1)=>({fill:t.colors(e),fillOpacity:t.options.alpha??n}),Y=t=>t.theme.palette[0],Vn=t=>e=>[E.line(e.index,{x:e.v("x"),y:e.v("y"),z:e.groups(),curve:t,...Q(e,Y(e)),clip:$})],Oe={line:t=>[E.line(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),sort:{channel:"x"},...Q(t,Y(t)),clip:$})],path:Vn("linear"),step:t=>[E.line(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),sort:{channel:"x"},curve:"step-after",...Q(t,Y(t)),clip:$})],point:t=>{let e={x:Un(t),y:t.v("y"),r:t.options.size??t.theme.point,...ot(t,Y(t)),clip:$};return t.options.jitter&&t.kind.x==="category"&&(e.render=_n(t.options.jitter)),[E.dot(t.index,e)]},bar:t=>{let e={...ot(t,Y(t),Qt(t,1)),clip:$};if(t.kind.x!=="category")return[E.rect(t.index,{x1:t.v("xmin"),x2:t.v("xmax"),y1:t.v("ymin"),y2:t.v("ymax"),...e})];let n=t.v("slots")[0]??1;if(n===1)return[E.barY(t.index,{x:t.v("x"),y1:t.v("ymin"),y2:t.v("ymax"),...e})];let s=t.bandwidth.x/n,o=(r,i)=>Array.isArray(r)?i.map(l=>r[l]):r;return q.range(n).map(r=>{let i=t.index.filter(a=>t.v("slot")[a]===r),l={x:o(t.v("x"),i),y1:o(t.v("ymin"),i),y2:o(t.v("ymax"),i),fill:o(e.fill,i)};return E.barY(q.range(i.length),{...e,...l,insetLeft:r*s+.5,insetRight:(n-1-r)*s+.5})})},hist:t=>[E.rect(t.index,{x1:t.v("xmin"),x2:t.v("xmax"),y1:t.v("ymin"),y2:t.v("ymax"),insetLeft:.5,insetRight:.5,...ot(t,Y(t),Qt(t)),clip:$})],density:t=>[E.areaY(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),fill:t.colors(Y(t)),fillOpacity:.15,clip:$}),E.line(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),...Q(t,Y(t)),clip:$})],area:t=>[E.areaY(t.index,{x:t.v("x"),y1:t.v("ymin"),y2:t.v("ymax"),z:t.groups(),...ot(t,Y(t),Qt(t,.8)),clip:$})],ribbon:t=>[E.areaY(t.index,{x:t.v("x"),y1:t.v("ymin"),y2:t.v("ymax"),z:t.groups(),...ot(t,Y(t),.2),clip:$})],smooth:t=>{let e=[];return t.v("ymin").some(n=>n!==null)&&e.push(E.areaY(t.index,{x:t.v("x"),y1:t.v("ymin"),y2:t.v("ymax"),z:t.groups(),fill:t.colors(t.theme.muted),fillOpacity:.15,clip:$})),e.push(E.line(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),...Q(t,t.theme.accent),clip:$})),e},hline:t=>[E.ruleY(t.index,{y:t.v("y"),...Q(t,t.theme.muted),strokeWidth:t.options.size??1,clip:$})],vline:t=>[E.ruleX(t.index,{x:t.v("x"),...Q(t,t.theme.muted),strokeWidth:t.options.size??1,clip:$})],abline:t=>{let[e,n]=t.domain.x.map(Number),{slope:s=1,intercept:o=0}=t.options;return[E.line([0,1],{x:[e,n],y:[o+s*e,o+s*n],...Q(t,t.theme.muted),strokeWidth:t.options.size??1,clip:$})]},segment:t=>[E.link(t.index,{x1:t.v("x"),y1:t.v("y"),x2:t.v("xend"),y2:t.v("yend"),...Q(t,t.theme.ink),clip:$})],rect:t=>[E.rect(t.index,{x1:t.v("xmin"),x2:t.v("xmax"),y1:t.v("ymin"),y2:t.v("ymax"),...ot(t,Y(t)),clip:$})],band:t=>{let e=(s,o,r)=>t.v(s)??t.index.map(()=>t.domain[o][r]),n={x1:e("xmin","x",0),x2:e("xmax","x",1),y1:e("ymin","y",0),y2:e("ymax","y",1)};return[E.rect(t.index,{...n,...ot(t,t.theme.muted,.12),clip:$})]},tile:t=>{let e=ot(t,Y(t)),[n,s]=[t.kind.x==="category",t.kind.y==="category"];if(n&&s)return[E.cell(t.index,{x:t.v("x"),y:t.v("y"),...e,inset:.5,clip:$})];let[o,r]=n?[]:Ot(t.v("x")),[i,l]=s?[]:Ot(t.v("y"));return n?[E.barY(t.index,{x:t.v("x"),y1:i,y2:l,...e,clip:$})]:s?[E.barX(t.index,{y:t.v("y"),x1:o,x2:r,...e,insetTop:.5,insetBottom:.5,clip:$})]:[E.rect(t.index,{x1:o,x2:r,y1:i,y2:l,...e,clip:$})]},text:t=>[E.text(t.index,{x:t.v("x"),y:t.v("y"),text:t.v("label"),fontSize:t.options.size??t.fonts.tick,...ot(t,t.theme.ink),clip:$})],errorbar:t=>{let e={...Q(t,t.theme.ink),strokeWidth:t.options.size??1.2},n=E.ruleX(t.index,{x:t.v("x"),y1:t.v("ymin"),y2:t.v("ymax"),...e,clip:$});if(t.kind.x==="category"){let i=t.bandwidth.x*.35,l=a=>E.tickY(t.index,{x:t.v("x"),y:t.v(a),...e,insetLeft:i,insetRight:i,clip:$});return[n,l("ymin"),l("ymax")]}let[s,o]=Ot(t.v("x"),.25),r=i=>E.link(t.index,{x1:s,x2:o,y1:t.v(i),y2:t.v(i),...e,clip:$});return[n,r("ymin"),r("ymax")]},box:t=>[E.boxY(t.index,{x:t.v("x"),y:t.v("y"),fill:t.colors(t.theme.strip),fillOpacity:t.options.alpha??1,stroke:t.theme.ink,strokeWidth:1,r:t.theme.point})]};function Qt(t,e=.9){return t.options.position==="overlay"?.45:e}function Ot(t,e=.5){let n=t.map(Number),s=[...new Set(n)].sort((i,l)=>i-l),o=q.min(q.pairs(s),([i,l])=>l-i)??1,r=t[0]instanceof Date?i=>new Date(i):i=>i;return[n.map(i=>r(i-o*e)),n.map(i=>r(i+o*e))]}function Un(t){let e=t.v("x");if(!t.options.jitter||t.kind.x==="category")return e;let n=q.randomUniform.source(q.randomLcg(42))(-1,1),[s]=Ot(e,t.options.jitter);return e.map((o,r)=>+o+(+o-+s[r])*n()).map(o=>e[0]instanceof Date?new Date(o):o)}function _n(t){return(e,n,s,o,r,i)=>{let l=q.randomUniform.source(q.randomLcg(42))(-1,1),a=n.scales.x?.bandwidth??20,c=Float64Array.from(s.x,u=>u+l()*a*t*.5);return i(e,n,{...s,x:c},o,r)}}import*as bt from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var St=18,Ct=6,tt={thick:12,long:150,slices:48},Kn=["line","path","step","density","smooth","hline","vline","abline","segment","errorbar"],Zn=["bar","hist","area","ribbon","rect","tile","box"];function Pe(t,e,n,{horizontal:s,maxWidth:o,maxHeight:r}){if(e.kind==="none"||t.theme.legend==="none")return null;let i=t.theme.metrics,l=(y,m,x)=>nt(y,m,x,i),a=t.labels.color===null?null:t.labels.color??e.column,c=a?n.legend*1.8:0,u=a?l(a,n.legend+1,!0):0;if(e.kind==="continuous"){let y=gt(e.type==="time"?"time":"linear",e.domain,4),m=y.major.map(y.format),x=bt.max(m,F=>l(F,n.legend))??0,k=Math.min(tt.long,s?o:r-c-4),[M,A]=s?[k,tt.thick+n.legend*1.6]:[tt.thick+Ct+x,k];return{kind:"ramp",title:a,titleH:c,color:e,long:k,ticks:y.major,labels:m,width:Math.max(u,M),height:c+A,horizontal:s}}let d=t.layers.filter(y=>y.channels.color?.column),h=d.some(y=>Zn.includes(y.type))?"square":d.some(y=>Kn.includes(y.type))?"line":"point",p=Math.round(n.legend*1.75),v=Math.max(80,(s?o:220)-St-Ct),g=e.domain.map(y=>{let m=at(y,n.legend,v,!1,i);return{value:y,label:m,color:e.apply(y),w:St+Ct+l(m,n.legend)}});if(!s){let y=Math.max(1,Math.floor((r-c)/p)),m=bt.range(Math.ceil(g.length/y)).map(M=>g.slice(M*y,(M+1)*y)),x=0;for(let M of m)M.forEach((A,F)=>Object.assign(A,{x,y:c+F*p})),x+=(bt.max(M,A=>A.w)??0)+n.legend;let k=Math.min(g.length,y);return{kind:"swatches",title:a,titleH:c,key:h,rowH:p,items:g,width:Math.max(u,x-n.legend),height:c+k*p,horizontal:s}}let w=0,b=c;for(let y of g)w>0&&w+y.w>o&&([w,b]=[0,b+p]),Object.assign(y,{x:w,y:b}),w+=y.w+n.legend*1.5;let f=Math.max(u,bt.max(g,y=>y.x+y.w)??0);return{kind:"swatches",title:a,titleH:c,key:h,rowH:p,items:g,width:f,height:b+p,horizontal:s}}function Te(t,e,n,s,o=new Set){let r=B(t,"g",{class:"pt-legend","font-size":s.legend});return e.title&&r.append(W(t,e.title,{y:s.legend,"font-weight":"bold","font-size":s.legend+1,fill:n.ink})),e.kind==="ramp"?Qn(t,r,e,n,s):e.items.forEach((i,l)=>r.append(Jn(t,e,i,l,n,o.has(i.value)))),r}function Jn(t,e,n,s,o,r){let i=e.rowH/2,l=B(t,"g",{class:"pt-key","data-index":s,transform:`translate(${n.x},${n.y})`,opacity:r?.35:1}),a=B(t,"rect",{width:n.w,height:e.rowH,fill:"transparent"}),c=e.key==="line"?B(t,"line",{x1:1,x2:St-1,y1:i,y2:i,stroke:n.color,"stroke-width":Math.max(2.5,o.line+1)}):e.key==="point"?B(t,"circle",{cx:St/2,cy:i,r:Math.max(3.5,o.point+1),fill:n.color}):B(t,"rect",{x:3,y:i-6,width:12,height:12,fill:n.color}),u=W(t,n.label,{x:St+Ct,y:i,dy:"0.35em",fill:o.muted,"text-decoration":r?"line-through":null});return l.append(a,c,u),l}function Qn(t,e,n,s,o){let{color:r,horizontal:i,long:l}=n,[a,c]=r.domain.map(Number),u=h=>(Number(h)-a)/(c-a||1),d=n.titleH;for(let h=0;h<tt.slices;h++){let p=h/tt.slices,v=l/tt.slices+.5,g=r.ramp(i?p:1-p),w=i?{x:p*l,y:d,width:v,height:tt.thick}:{x:0,y:d+p*l,width:tt.thick,height:v};e.append(B(t,"rect",{...w,fill:g}))}n.ticks.forEach((h,p)=>{let v=u(h)*l,g=i?{x:v,y:d+tt.thick+o.legend*1.2,"text-anchor":"middle"}:{x:tt.thick+Ct,y:d+l-v,dy:"0.35em"};e.append(W(t,n.labels[p],{...g,fill:s.muted}))})}import*as K from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var dt={size:4,padding:3},to=40,eo=.22;function Ne({ns:t,grid:e,kind:n,home:s,legend:o,info:r,fonts:i,W:l,H:a}){let c=t.theme,u=c.metrics,d=(C,R,it)=>nt(C,R,it,u),h=i.base,p=Math.round(h*.9),v=Math.round(h*.8),{title:g,subtitle:w,caption:b,x:f,y}=t.labels,m=C=>r?.position===C?r:null,x=l-2*p-Math.min(180,l*eo),k=g?Ft(g,i.title,x,!0,u):[],M=w?Ft(w,i.subtitle,x,!1,u):[],A=k.length*i.title*1.25+M.length*i.subtitle*1.4,F=p+A+(A?h*.7:0),S=f?i.axisTitle*1.7:0,O=y?i.axisTitle*1.7:0,I=b?i.tick*1.8:0,j=Math.max(o&&!o.horizontal?o.width:0,m("right")?.width??0),kt=j?j+h*1.5:0,st=o?.horizontal?o.height+h*.8:0,G=m("bottom")?m("bottom").height+v:0,z={x:p+O,y:F,w:l-2*p-O-kt,h:a-F-p-S-st-I-G},Mt=e.kind==="none"?0:Math.round(i.strip*2),zt=e.kind==="wrap"?Mt:0,jt=e.kind==="grid"&&t.facet.cols?Mt+2:0,bn=e.kind==="grid"&&t.facet.rows?Mt+2:0,se=t.facet?.free??{x:!1,y:!1},wn=e.panels.length,ie=C=>se.y||C.col===0,Ht=(C,R)=>se.x||(e.kind==="wrap"?R+e.ncol>=wn:C.row===e.nrow-1),V=z.w/e.ncol,J=z.h/e.nrow,ut,et,It,Et;for(let C=0;C<2;C++){It={x:Math.max(2,V/(n.x==="time"?110:75)),y:Math.max(2,J/45)},ut=Array(e.ncol).fill(0),et=Array(e.nrow).fill(0),Et=!1;let R=0;e.panels.forEach((U,lt)=>{if(ie(U)){let pt=gt(n.y,s[lt].y,It.y,t.scales.y?.format),ft=K.max(pt.major,Yt=>d(pt.format(Yt),i.tick))??0;ut[U.col]=Math.max(ut[U.col],Math.ceil(ft+dt.size+dt.padding+3))}if(n.x==="category"&&Ht(U,lt)){let pt=s[lt].x,ft=K.max(pt,Yt=>d(Yt,i.tick))??0;R=Math.max(R,ft),ft>V/(pt.length+.2)*.95&&(Et=!0)}});let it=Et?Math.min(R,J*.6)*Math.sin(to*Math.PI/180)+i.tick:i.tick*1.2;e.panels.forEach((U,lt)=>{Ht(U,lt)&&(et[U.row]=Math.max(et[U.row],Math.ceil(it+dt.size+dt.padding+3)))}),V=(z.w-K.sum(ut)-v*(e.ncol-1)-bn)/e.ncol,J=(z.h-K.sum(et)-e.nrow*zt-jt-v*(e.nrow-1))/e.nrow}V=Math.max(20,V),J=Math.max(20,J);let vn=K.cumsum([z.x,...ut.slice(0,-1).map(C=>C+V+v)]),kn=K.cumsum([z.y+jt,...et.slice(0,-1).map(C=>zt+J+C+v)]),$t=e.panels.map((C,R)=>({x:vn[C.col],y:kn[C.row]+zt,w:ut[C.col]+V,h:J+et[C.row],ml:ut[C.col],mb:et[C.row],innerW:V,innerH:J,count:It,rotateX:Et,showX:Ht(C,R),showY:ie(C)})),Rt=[];e.panels.forEach((C,R)=>{let it=$t[R],U=it.x+it.ml,lt=(pt,ft)=>at(pt,i.strip,ft-8,!0,u);C.strips.top!=null&&Rt.push({x:U,y:it.y-zt-jt,w:V,h:Mt,text:lt(C.strips.top,V),full:C.strips.top}),C.strips.right!=null&&Rt.push({x:U+V+2,y:it.y,w:Mt,h:J,text:lt(C.strips.right,J),full:C.strips.right,vertical:!0})});let qt=$t[0],le=$t.find((C,R)=>e.panels[R].col===e.ncol-1)??qt,ht=qt.x+qt.ml,ae=le.x+le.w,ce=z.y+z.h,mt=[],Wt=p;for(let C of k)mt.push({text:C,attrs:{x:ht,y:Wt+=i.title*1.05,"font-size":i.title,"font-weight":"bold",fill:c.ink,"text-anchor":"start"}}),Wt+=i.title*.2;for(let C of M)mt.push({text:C,attrs:{x:ht,y:Wt+=i.subtitle*1.3,"font-size":i.subtitle,fill:c.muted,"text-anchor":"start"}});if(f&&mt.push({text:f,attrs:{x:(ht+ae)/2,y:ce+i.axisTitle*1.35,"text-anchor":"middle","font-size":i.axisTitle,fill:c.muted}}),y){let C=z.y+(z.h-K.sum(et))/2;mt.push({text:y,attrs:{transform:`translate(${p+i.axisTitle*.85},${C}) rotate(-90)`,"text-anchor":"middle","font-size":i.axisTitle,fill:c.muted}})}b&&mt.push({text:at(b,i.tick,l-2*p,!1,u),attrs:{x:ht,y:a-p-(st||0)+i.tick*.2,"font-size":i.tick,fill:c.muted,"text-anchor":"start"}});let ue=l-p-j,Mn=r?r.position==="right"?{x:ue,y:z.y}:{x:Math.max(p,Math.min(ht,l-p-r.width)),y:ce+S+v/2}:null,pe=m("right")?r.height+h:0,En=o?o.horizontal?{x:Math.max(p,(ht+ae-o.width)/2),y:a-p-o.height}:{x:ue,y:z.y+pe+Math.max(0,(z.h-K.sum(et)-pe-o.height)/2)}:null;return{panels:$t,strips:Rt,texts:mt,legend:En,info:Mn,area:z,rotateX:Et}}function je(t,e={}){if(typeof t?.spec=="function"&&(t=t.spec()),t?.version!==1)throw new Error("plotto: unknown spec version");let n=ge({...t.theme,...e}),s=t.data.map(no),o=t.layers.map(a=>oo(a,t.mapping??{},s,n));if(!o.length)throw new Error("plotto: the plot has no layers. Add one, for example .line() or .point()");let r=ro(t.facet),i={...so(o),...t.labels},l=t.info?.entries?.length?{entries:t.info.entries,position:t.info.position??"right"}:null;return{tables:s,layers:o,facet:r,scales:t.scales??{},labels:i,info:l,theme:n}}function no({columns:t}){let e=Object.keys(t),n=e.length?t[e[0]].values.length:1;return{columns:t,n}}function oo(t,e,n,s){let o=P.layers[t.type];if(!o)throw new Error(`plotto: unknown layer type "${t.type}". Valid: ${Object.keys(P.layers).join(", ")}`);let r=t.data??0,i=n[r].columns,l={};for(let u of o.channels)t.mapping?.[u]!==void 0?l[u]={column:t.mapping[u]}:t.set?.[u]!==void 0?l[u]={value:t.set[u]}:o.inherit!==!1&&e[u]in i&&(l[u]={column:e[u]});let a=o.requires.filter(u=>!l[u]);if(a.length)throw new Error(`${t.type}(): set ${a.join(" and ")}, as a column name or a value`);if(l.color&&"value"in l.color){let u=yt(s,l.color.value);if(!u)throw new Error(`${t.type}(): "${l.color.value}" is not a column or a color. Theme colors: ${we(s).join(", ")}`);l.color={value:u}}let c={};for(let u of o.options)t.set?.[u]!==void 0&&(c[u]=t.set[u]);return{type:t.type,table:r,channels:l,options:c}}function ro(t){if(!t)return null;let e={x:["x","both"].includes(t.free),y:["y","both"].includes(t.free)};return t.wrap?{kind:"wrap",by:t.wrap,ncol:t.ncol??null,free:e}:{kind:"grid",rows:t.rows??null,cols:t.cols??null,free:e}}function so(t){let e=o=>{for(let r of t)for(let i of o)if(r.channels[i]?.column)return r.channels[i].column},n=t.find(o=>o.type==="hist"||o.type==="density"),s=e(["y","ymin","yend"])??(n?n.type==="density"||n.options.density?"density":"count":void 0);return{x:e(["x","xmin","xend"]),y:s,color:e(["color"])}}import*as D from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var Pt=80;function Dt(t,e,n){let s=new Map;for(let o=0;o<n;o++){let r=e.map(l=>t[l]?.[o]??null),i=JSON.stringify(r);s.has(i)||s.set(i,{key:r,idx:[]}),s.get(i).idx.push(o)}return[...s.values()]}function He(t,e,n){let s={mean:D.mean,median:D.median,min:D.min,max:D.max,sum:D.sum}[n],o={x:[],y:[],color:[],group:[]};for(let{key:r,idx:i}of Dt(t,["x","color","group"],e))r[0]!==null&&(o.x.push(r[0]),o.y.push(s(i,l=>t.y[l])),o.color.push(r[1]),o.group.push(r[2]));return o}function Ie(t,e,n,s){let o=l=>t.color?s.indexOf(t.color[l]):0,r=t.color?s.filter(l=>t.color.includes(l)):[null],i={...t,ymin:new Array(e),ymax:new Array(e),value:t.y.slice(),slot:new Array(e),slots:new Array(e)};for(let{idx:l}of Dt(t,n==="dodge"?["x","color"]:["x"],e)){l.sort((u,d)=>o(u)-o(d));let a=0,c=0;l.forEach((u,d)=>{let h=t.y[u]??0;if(n!=="overlay"){let p=h>=0?a:c;[i.ymin[u],i.ymax[u]]=[p,p+h],h>=0?a+=h:c+=h}else[i.ymin[u],i.ymax[u]]=[0,h];i.slot[u]=n==="dodge"&&t.color?r.indexOf(t.color[u]):0,i.slots[u]=n==="dodge"?r.length:1})}return i.y=i.ymax,i}function Re(t,e){let n=[...new Set(t.x.filter(l=>l!==null))].sort((l,a)=>l-a),o=(D.min(D.pairs(n),([l,a])=>a-l)??1)*.9,r=[],i=[];for(let l=0;l<e;l++){let a=o/t.slots[l];r.push(t.x[l]-o/2+t.slot[l]*a),i.push(t.x[l]-o/2+(t.slot[l]+1)*a)}return{...t,xmin:r,xmax:i}}function qe(t,e){let n=t.filter(i=>i!==null&&Number.isFinite(i)),[s,o]=D.extent(n);if(s===void 0)return[0,1];if(s===o)return[s-.5,o+.5];let r=D.ticks(...D.nice(s,o,e),e);return r[0]>s&&r.unshift(r[0]-(r[1]-r[0])),r.at(-1)<o&&r.push(r.at(-1)+(r[1]-r[0])),r}function We(t,e,n,s){let o={x:[],xmin:[],xmax:[],y:[],color:[]},r=D.bin().domain([n[0],n.at(-1)]).thresholds(n.slice(1,-1));for(let{key:i,idx:l}of Dt(t,["color"],e)){let a=l.map(c=>t.x[c]).filter(c=>c!==null&&Number.isFinite(c));for(let c of r(a)){let u=c.length;o.x.push((c.x0+c.x1)/2),o.xmin.push(c.x0),o.xmax.push(c.x1),o.y.push(s?u/(a.length*(c.x1-c.x0)||1):u),o.color.push(i[0])}}return o}function Ye(t,e){let n={x:[],y:[],color:[],group:[]};for(let{key:s,idx:o}of Dt(t,["color"],e)){let r=o.map(d=>t.x[d]).filter(d=>d!==null&&Number.isFinite(d));if(r.length<2)continue;let i=D.deviation(r),l=D.quantile(r,.75)-D.quantile(r,.25),a=.9*Math.min(i,l/1.34||i)*r.length**-.2||1,[c,u]=D.extent(r);for(let d of D.range(Pt).map(h=>c-3*a+(u-c+6*a)*h/(Pt-1))){let h=D.sum(r,p=>Math.exp(-.5*((d-p)/a)**2))/(r.length*a*Math.sqrt(2*Math.PI));n.x.push(d),n.y.push(h),n.color.push(s[0]),n.group.push(s[0])}}return n}function Xe(t,e,{method:n="lm",span:s=.75,band:o=!0}){let r={x:[],y:[],ymin:[],ymax:[],color:[],group:[]};for(let{key:i,idx:l}of Dt(t,["color"],e)){let a=l.map(p=>[t.x[p],t.y[p]]).filter(([p,v])=>p!==null&&v!==null&&Number.isFinite(p)&&Number.isFinite(v));if(a.length<3)continue;a.sort((p,v)=>p[0]-v[0]);let[c,u]=[a[0][0],a.at(-1)[0]],d=D.range(Pt).map(p=>c+(u-c)*p/(Pt-1));(n==="loess"?lo(a,d,s):io(a,d)).forEach(({x:p,y:v,se:g})=>{let w=ao(a.length-2);r.x.push(p),r.y.push(v),r.ymin.push(o&&g!==void 0?v-w*g:null),r.ymax.push(o&&g!==void 0?v+w*g:null),r.color.push(i[0]),r.group.push(i[0])})}return r}function io(t,e){let n=t.length,s=D.mean(t,c=>c[0]),o=D.mean(t,c=>c[1]),r=D.sum(t,c=>(c[0]-s)**2)||1,i=D.sum(t,c=>(c[0]-s)*(c[1]-o))/r,l=o-i*s,a=Math.sqrt(D.sum(t,c=>(c[1]-l-i*c[0])**2)/Math.max(1,n-2));return e.map(c=>({x:c,y:l+i*c,se:a*Math.sqrt(1/n+(c-s)**2/r)}))}function lo(t,e,n){let s=Math.max(3,Math.ceil(n*t.length));return e.map(o=>{let r=t.map(([g,w])=>[Math.abs(g-o),g,w]).sort((g,w)=>g[0]-w[0]).slice(0,s),i=r.at(-1)[0]||1,[l,a,c,u,d]=[0,0,0,0,0];for(let[g,w,b]of r){let f=(1-(g/i)**3)**3;l+=f,a+=f*w,c+=f*b,u+=f*w*w,d+=f*w*b}let h=l*u-a*a,p=Math.abs(h)<1e-12?0:(l*d-a*c)/h,v=(c-p*a)/l;return{x:o,y:v+p*o}})}function ao(t){let e=[12.71,4.3,3.18,2.78,2.57,2.45,2.36,2.31,2.26,2.23,2.2,2.18,2.16,2.14,2.13,2.12,2.11,2.1,2.09,2.09];return t<1?NaN:t<=e.length?e[t-1]:t<=30?2.05:t<=60?2:1.96}function Ge(t){return t.layers.map(e=>e.type!=="hist"||!e.channels.x.column?null:qe(t.tables[e.table].columns[e.channels.x.column].values,e.options.bins??30))}function te(t,e,n,s){let{ns:o,kind:r,colorLevels:i,edges:l}=t;if(s.size&&e.channels.color?.column){let w=o.tables[e.table].columns[e.channels.color.column].values;n=n.filter(b=>!s.has(w[b]))}let a={};for(let w of Object.keys(e.channels))a[w]=Ae(o,e,w,n);let c=n.length,u=e.options,d=(w,b,f)=>Ie(w,b,f,i),h=w=>w.x?.length??0,p=a,v=n;if(u.summary&&(e.type==="line"||e.type==="point"))p=He(a,c,u.summary);else if(e.type==="bar")p=d(a,c,u.position??"stack"),r.x!=="category"&&(p=Re(p,c));else if(e.type==="area")p=d(a,c,u.position??"stack");else if(e.type==="hist"){let w=We(a,c,l[o.layers.indexOf(e)],u.density);p=d(w,h(w),u.position??"stack")}else e.type==="density"?p=Ye(a,c):e.type==="smooth"&&(p=Xe(a,c,u));p!==a&&(v=null);let g={cols:p,n:p===a?c:h(p),rows:v};return g.hover=co(o,e,g),g}function co(t,e,{cols:n,rows:s}){let o=t.labels.x||e.channels.x?.column||"x",r=t.labels.y||e.channels.y?.column||"y",i=(c,u,d,h)=>({label:c,axis:u,values:d,values2:h}),l=i(o,"x",n.x),a=e.channels.tooltip?.column&&s?[i(e.channels.tooltip.column,null,n.tooltip)]:[];switch(e.type){case"line":case"path":case"step":case"point":return{hx:n.x,hy:n.y,fields:[l,i(r,"y",n.y),...a]};case"bar":case"area":return{hx:n.x,hy:n.ymax,fields:[l,i(r,"y",n.value),...a]};case"hist":return{hx:n.x,hy:n.ymax,fields:[i(o,"x",n.xmin,n.xmax),i(e.options.density?"density":"count",null,n.value)]};case"density":return{hx:n.x,hy:n.y,fields:[l,i("density",null,n.y)]};case"smooth":{let c=n.ymin.some(u=>u!==null)?[i("95% CI","y",n.ymin,n.ymax)]:[];return{hx:n.x,hy:n.y,fields:[l,i(r,"y",n.y),...c]}}case"ribbon":return{hx:n.x,hy:n.ymax,fields:[l,i(r,"y",n.ymin,n.ymax)]};case"errorbar":return{hx:n.x,hy:n.ymax,fields:[l,i(r,"y",n.ymin,n.ymax)]};case"tile":{let c=e.channels.color?.column?[i(t.labels.color??"value",null,n.color)]:[];return{hx:n.x,hy:n.y,fields:[l,i(r,"y",n.y),...c,...a],tile:!0}}case"box":return{hx:n.x,hy:n.y,fields:[l,i(r,"y",n.y)]};default:return null}}var Ve=560,uo=240;function ee(t,{document:e=globalThis.document,width:n,domains:s,hidden:o=new Set}={}){let r=je(t),i=r.theme,l=Math.round(n??i.width),c=n&&i.reflow&&!i.fixedHeight?Math.max(uo,Math.round(l*i.height/i.width)):i.height;i.legend==="right"&&l<Ve&&(i.legend="bottom");let u=ke(i),d=ze(r),h={x:Kt(r,"x"),y:Kt(r,"y")},p=De(r),v={ns:r,kind:h,colorLevels:p.domain??[],edges:Ge(r)};for(let M of d.panels)M.views=r.layers.map((A,F)=>te(v,A,M.rows[F],new Set));let g=mo(r,d,h),w=i.legend==="bottom",b=Be(r,u,{W:l,H:c,narrow:l<Ve}),f=b?.position==="right"?b.height+u.base:0,y=Pe(r,p,u,{horizontal:w,maxWidth:l*.9,maxHeight:c*.8-f}),m=Ne({ns:r,grid:d,kind:h,home:g,legend:y,info:b,fonts:u,W:l,H:c}),x=B(e,"svg",{xmlns:"http://www.w3.org/2000/svg",width:l,height:c,viewBox:`0 0 ${l} ${c}`,"font-family":i.font,"font-size":u.base,style:`color:${i.ink}`});x.append(B(e,"rect",{width:l,height:c,fill:i.background}));for(let M of m.texts)x.append(W(e,M.text,M.attrs));b&&x.append(Le(e,b,i,m.info));for(let M of m.strips)x.append(xo(e,M,i,u));let k={spec:t,ns:r,doc:e,svg:x,theme:i,fonts:u,grid:d,kind:h,color:p,ctx:v,legend:y,info:b,layout:m,home:g,W:l,H:c};return k.domains=s??g,k.hidden=o,k.panelLayer=x.appendChild(B(e,"g",{class:"pt-panels"})),y&&(k.legendG=x.appendChild(Ze(k))),rt(k),k}function Ke(t,e){return ee(t,e).svg.outerHTML}function rt(t){let{ns:e,grid:n,ctx:s,hidden:o}=t;if(o.size||t.filtered){for(let r of n.panels)r.views=e.layers.map((i,l)=>te(s,i,r.rows[l],o));t.filtered=o.size>0}t.panelLayer.replaceChildren(),t.panels=n.panels.map((r,i)=>po(t,r,i)),t.legendG&&t.legendG.replaceWith(t.legendG=Ze(t))}function Ze(t){let e=Te(t.doc,t.legend,t.theme,t.fonts,t.hidden);return e.setAttribute("transform",`translate(${t.layout.legend.x},${t.layout.legend.y})`),e}function po(t,e,n){let{ns:s,doc:o,theme:r,fonts:i,kind:l,color:a}=t,c=t.layout.panels[n],u={x:Ue(l.x,t.domains[n].x),y:Ue(l.y,t.domains[n].y)},d={x:l.x==="category"?c.innerW/(u.x.length+.2)*.8:0},h=s.layers.map((x,k)=>{let M=e.views[k],A=ho({view:M,layer:x,kind:l,color:a,theme:r,fonts:i,domain:u,bandwidth:d});return{layer:x,view:M,c:A,marks:M.n?Oe[x.type](A):[]}}),p=x=>{let k=gt(l[x],t.domains[n][x],c.count[x],s.scales[x]?.format),M=A=>l[x]==="category"||+A>=+u[x][0]&&+A<=+u[x][1];return{major:k.major.filter(M),minor:k.minor,format:k.format}},v=p("x"),g=p("y"),w=x=>({stroke:x?r.gridMinor:r.grid,strokeOpacity:1,strokeWidth:x?.6:.9}),b={tickSize:dt.size,tickPadding:dt.padding,fontSize:i.tick,stroke:r.tick,fill:r.muted,label:null},f=[];if(l.x!=="category"&&f.push(X.gridX(v.minor,w(!0)),X.gridX(v.major,w(!1))),l.y!=="category"&&f.push(X.gridY(g.minor,w(!0)),X.gridY(g.major,w(!1))),f.push(...h.flatMap(x=>x.marks)),c.showX){let x=c.rotateX?{tickRotate:-40,textAnchor:"end"}:{};f.push(X.axisX(v.major,{...b,...x,anchor:"bottom",tickFormat:v.format}))}c.showY&&f.push(X.axisY(g.major,{...b,anchor:"left",tickFormat:g.format}));let y=X.plot({document:o,width:c.w,height:c.h,marginLeft:c.ml,marginRight:0,marginTop:0,marginBottom:c.mb,x:_e(l.x,u.x),y:_e(l.y,u.y),color:{type:"identity"},marks:f}),m=B(o,"g",{class:"pt-panel","data-panel":n,transform:`translate(${c.x},${c.y})`,fill:"currentColor","text-anchor":"middle"});for(let x of[...y.childNodes])x.nodeName.toLowerCase()!=="style"&&m.append(x);return t.panelLayer.append(m),{g:m,plot:y,box:c,layers:h}}function ho({view:t,layer:e,kind:n,color:s,theme:o,fonts:r,domain:i,bandwidth:l}){let a=h=>At.x.includes(h)?"x":At.y.includes(h)?"y":null,c={},u=h=>{if(h in c)return c[h];let p=t.cols[h];return p&&n[a(h)]==="time"&&(p=p.map(v=>v===null?null:new Date(v))),c[h]=p},d=e.channels.color;return{index:Tt.range(t.n),v:u,options:e.options,colors:h=>d?"value"in d?d.value:u("color").map(s.apply):h,groups:()=>u("group")??(d?.column?u("color"):void 0),kind:n,theme:o,fonts:r,domain:i,bandwidth:l}}function Ue(t,e){return t==="time"?e.map(n=>new Date(n)):e}function _e(t,e){return{type:{linear:"linear",log:"log",time:"utc",category:"band"}[t],domain:e,axis:null,...t==="category"?{padding:.2,round:!1}:{}}}function mo(t,e,n){let s=t.facet?.free??{x:!1,y:!1},o=(i,l,a)=>s[i]?e.kind==="grid"?i==="x"?`c${l.col}`:`r${l.row}`:`p${a}`:"all",r=e.panels.map(()=>({}));for(let i of["x","y"]){let l=Tt.group(e.panels.map((a,c)=>[a,c]),([a,c])=>o(i,a,c));for(let a of l.values()){let c=fo(t,i,n[i],a.map(([u])=>u));for(let[,u]of a)r[u][i]=c}}return r}function fo(t,e,n,s){let o=t.scales[e]?.limits;if(o&&(n==="category"||o.every(i=>i!==null)))return o;let r=Fe(t,e,n,s);return o?[o[0]??r[0],o[1]??r[1]]:r}function xo(t,e,n,s){let o=B(t,"g",{class:"pt-strip"});o.append(B(t,"rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:n.strip}));let r=e.vertical?{transform:`translate(${e.x+e.w/2},${e.y+e.h/2}) rotate(90)`,dy:"0.35em"}:{x:e.x+e.w/2,y:e.y+e.h/2,dy:"0.35em"},i=W(t,e.text,{...r,"text-anchor":"middle","font-weight":"bold","font-size":s.strip,fill:n.ink});return e.text!==String(e.full)&&i.append(W(t,e.full,{},"title")),o.append(i),o}async function Je(t){let e=en(t);try{return await navigator.clipboard.write([new ClipboardItem({"image/png":e.then(yo)})]),"Copied"}catch{return ne((await e).toDataURL("image/png"),"plot.png"),"Downloaded"}}async function Qe(t){ne((await en(t)).toDataURL("image/png"),"plot.png")}function tn(t){ne(nn(t),"plot.svg")}async function en(t){let e=new Image;e.src=nn(t),await e.decode();let{width:n,height:s}=t.viewBox.baseVal,o=document.createElement("canvas");return o.width=n*2,o.height=s*2,o.getContext("2d").drawImage(e,0,0,o.width,o.height),o}function nn(t){let e=t.cloneNode(!0);e.querySelector(".pt-overlay")?.remove();let{width:n,height:s}=t.viewBox.baseVal;e.setAttribute("width",n),e.setAttribute("height",s);let o=new TextEncoder().encode(new XMLSerializer().serializeToString(e)),r="";for(let i of o)r+=String.fromCharCode(i);return`data:image/svg+xml;base64,${btoa(r)}`}var yo=t=>new Promise(e=>t.toBlob(e,"image/png"));function ne(t,e){let n=document.createElement("a");n.href=t,n.download=e,n.click()}import*as N from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var sn=40,go=10,bo=6,ln=4,wo=6,vo=["line","step","area","density","smooth","ribbon"],ko=["bar","hist","tile","box"],Mo=["point","path","errorbar"];function an(t,e,n,s,o){let r=t.panels[e],i=r.plot.scale("x"),l=r.plot.scale("y"),u={state:t,sx:i,sy:l,px:g=>i.apply(g)+(i.bandwidth??0)/2,py:g=>l.apply(g)+(l.bandwidth??0)/2},d=Co(u,r,n);if(d)return{...d,panel:e};let h=Ao(u,r,n,s,o?.panel===e?o:null);if(h&&h.d<=go)return{...on(u,h),panel:e};let p=Fo(u,r,n,s,o?.panel===e?o:null);if(p)return{...p,panel:e};let v=Do(u,r,n,s);return v?{...v,panel:e}:h?{...on(u,h),panel:e}:null}function vt(t,e,n,s,o){let r=e.channels.color;return r?"value"in r?r.value:t.color.apply(n.cols.color[o]):e.type==="smooth"?t.theme.accent:t.theme.palette[0]}function Z(t,e,n){return n==null||Number.isNaN(n)?"\u2013":e&&t.kind[e]==="time"?Eo(t,e)(n):e&&t.kind[e]==="category"?String(n):typeof n=="number"?Ce.number(n):String(n)}function Eo(t,e){if(t.timeFormats??={},t.timeFormats[e])return t.timeFormats[e];let n=t.grid.panels.flatMap(r=>r.views.flatMap(i=>i.cols[e]??[])).filter(r=>r!==null),s=r=>n.every(i=>r(new Date(i))),o=s(r=>r.getUTCDate()===1&&r.getUTCHours()===0&&r.getUTCMinutes()===0)?"%Y-%m":s(r=>r.getUTCHours()===0&&r.getUTCMinutes()===0)?"%Y-%m-%d":s(r=>r.getUTCSeconds()===0)?"%m-%d %H:%M":"%m-%d %H:%M:%S";return t.timeFormats[e]=N.utcFormat(o)}function wt(t,e,n){return e.values2?`${Z(t,e.axis,e.values[n])} \u2013 ${Z(t,e.axis,e.values2[n])}`:Z(t,e.axis,e.values[n])}function Ao({px:t,py:e},n,s,o,r){let i=null,l=null;for(let{layer:a,view:c,c:u}of n.layers){if(!Mo.includes(a.type)||!c.hover||!c.n)continue;let{hx:d,hy:h}=c.hover;for(let p=0;p<c.n;p++){if(d[p]===null||h[p]===null)continue;let v=Math.hypot(t(d[p])-s,e(h[p])-o);if(v>sn)continue;let g={layer:a,view:c,c:u,k:p,d:v,x:t(d[p]),y:e(h[p])};(!i||v<i.d)&&(i=g),r?.layer===a&&r.k===p&&(l=g)}}return l&&i&&i.d>l.d-ln?l:i}function on({state:t},{layer:e,view:n,c:s,k:o,x:r,y:i,d:l}){let a=vt(t,e,n,s,o),c=e.channels.color?.column?Z(t,null,n.cols.color[o]):null,u=n.hover.fields.map(d=>({label:d.label,value:wt(t,d,o)})).filter(d=>d.value!==c);return{layer:e,k:o,d:l,color:a,header:c,rows:u,marks:[{x:r,y:i,color:a}],anchor:{x:r,y:i}}}function Fo({state:t,px:e,py:n},s,o,r,i){let l=[];for(let{layer:m,view:x,c:k}of s.layers){if(!vo.includes(m.type)||!x.hover||!x.n)continue;let{hx:M,hy:A}=x.hover,F=k.groups()??[],S=new Map;for(let O=0;O<x.n;O++){if(M[O]===null||A[O]===null)continue;let I=Math.abs(e(M[O])-o),j=F[O]??"";I<=sn&&(!S.has(j)||I<S.get(j).dx)&&S.set(j,{layer:m,view:x,c:k,k:O,dx:I,series:j})}l.push(...S.values())}if(!l.length)return null;let a=N.least(l,m=>m.dx),c=e(a.view.hover.hx[a.k]),u=l.filter(m=>Math.abs(e(m.view.hover.hx[m.k])-c)<=bo);for(let m of u)m.y=n(m.view.hover.hy[m.k]);let d=N.least(u,m=>Math.abs(m.y-r)),h=i?.series!==void 0&&u.find(m=>m.layer===i.layer&&m.series===i.series);h&&Math.abs(h.y-r)<Math.abs(d.y-r)+ln&&(d=h);let p=m=>m.layer.channels.color?.column?Z(t,null,m.view.cols.color[m.k]):m.series!==""?String(m.series):m.view.hover.fields[1]?.label??m.layer.type,v=m=>vt(t,m.layer,m.view,m.c,m.k),g=a.view.hover.fields[0],w=Z(t,"x",a.view.hover.hx[a.k]),b={crosshair:c,anchor:{x:c,y:r},layer:d.layer,series:d.series};if(u.length===1||u.length>wo){let m=[{label:g?.label??"x",value:w},{label:d.view.hover.fields[1]?.label??"y",value:rn(t,d.layer,d.view,d.k)}],x=u.length-1;return{...b,color:v(d),header:p(d),rows:m,note:x?`${x} other series at this x`:null,marks:[{x:c,y:d.y,color:v(d)}]}}let f=So(t);u.sort((m,x)=>f(m)-f(x)||m.y-x.y);let y=u.map(m=>({swatch:v(m),label:p(m),value:rn(t,m.layer,m.view,m.k),strong:m===d}));return{...b,color:t.theme.ink,header:g?`${g.label} ${w}`:w,rows:y,marks:u.map(m=>({x:c,y:m.y,color:v(m)}))}}function So(t){let{color:e}=t;return n=>{let s=n.layer.channels.color?.column?n.view.cols.color[n.k]:null;return s===null?t.ns.layers.indexOf(n.layer):e.kind==="ordinal"?e.domain.indexOf(s):typeof s=="number"?s:0}}function rn(t,e,n,s){let o=n.hover.fields;return e.type==="smooth"&&o[2]?`${wt(t,o[1],s)} (${wt(t,o[2],s)})`:wt(t,o[1],s)}function Co(t,e,n){for(let{layer:s,view:o,c:r}of e.layers)if(s.type==="box"&&o.n)return $o(t,s,o,r,n);return null}function Do(t,e,n,s){let{state:o,sx:r,sy:i}=t;for(let{layer:l,view:a,c}of e.layers){if(!ko.includes(l.type)||l.type==="box"||!a.n)continue;let u=l.type==="tile",d=null;for(let g=0;g<a.n;g++){let[w,b]=Bo(l,a,g,r),f=Math.abs((w+b)/2-n);if(u?n<w-oe(r,b-w)||n>b+oe(r,b-w):f>b-w)continue;let[y,m]=Lo(l,a,g,i),[x,k]=[Math.min(y,m),Math.max(y,m)],M=u?oe(i,k-x):0,A=s>=x-M&&s<=k+M;if(u&&!A)continue;let F=Math.round(f)*1e6+(A?0:1e5+x);(!d||F<d.score)&&(d={k:g,score:F,rect:{x:w,y:x,width:b-w,height:k-x}})}if(!d)continue;let{k:h,rect:p}=d,v=vt(o,l,a,c,h);if(u){let g=o.ns.labels.color??l.channels.color?.column??"value",w=l.channels.color?.column?Z(o,null,a.cols.color[h]):null,b=a.hover.fields.filter(f=>f.label!==g).map(f=>({label:f.label,value:wt(o,f,h)}));return{color:v,header:w!==null?`${g} ${w}`:null,rows:b,marks:[{rect:p,color:o.theme.ink}],anchor:{x:p.x+p.width,y:s}}}return zo(o,l,a,c,h,p)}return null}function oe(t,e){return t.bandwidth!==void 0?(t.step-t.bandwidth)/2||e*.125:.5}function zo(t,e,n,s,o,r){let i=e.type==="hist"?h=>n.cols.xmin[h]===n.cols.xmin[o]:h=>String(n.cols.x[h])===String(n.cols.x[o]),l=N.range(n.n).filter(i),a=!!e.channels.color?.column,c=l.sort((h,p)=>a&&t.color.kind==="ordinal"?t.color.domain.indexOf(n.cols.color[h])-t.color.domain.indexOf(n.cols.color[p]):n.cols.ymax[p]-n.cols.ymax[h]).map(h=>({swatch:vt(t,e,n,s,h),label:a?Z(t,null,n.cols.color[h]):n.hover.fields[1].label,value:Z(t,null,n.cols.value[h]),strong:h===o&&l.length>1}));(e.options.position??"stack")==="stack"&&l.length>1&&c.push({label:"total",value:Z(t,null,N.sum(l,h=>n.cols.value[h])),strong:!1,total:!0});let d=n.hover.fields[0];return{color:vt(t,e,n,s,o),header:`${d.label} ${wt(t,d,o)}`,rows:c,marks:[{rect:r,color:t.theme.ink}],anchor:{x:r.x+r.width,y:r.y}}}function $o({state:t,sx:e},n,s,o,r){if(e.bandwidth===void 0)return null;let i=N.range(s.n).find(m=>{let x=e.apply(s.cols.x[m]);return r>=x&&r<=x+e.bandwidth});if(i===void 0)return null;let l=String(s.cols.x[i]),a=N.range(s.n).filter(m=>String(s.cols.x[m])===l).map(m=>s.cols.y[m]).filter(m=>m!==null).sort(N.ascending),[c,u,d]=[.25,.5,.75].map(m=>N.quantile(a,m)),h=d-c,p=N.min(a.filter(m=>m>=c-1.5*h)),v=N.max(a.filter(m=>m<=d+1.5*h)),g=a.filter(m=>m<p||m>v).length,w=m=>Z(t,"y",m),b=[{label:"max (whisker)",value:w(v)},{label:"q3",value:w(d)},{label:"median",value:w(u),strong:!0},{label:"q1",value:w(c)},{label:"min (whisker)",value:w(p)},{label:"n",value:String(a.length)}];g&&b.push({label:"outliers",value:String(g)});let f=e.apply(s.cols.x[i]);return{color:n.channels.color?.column?vt(t,n,s,o,i):t.theme.ink,header:`${s.hover.fields[0].label} ${l}`,rows:b,marks:[],anchor:{x:f+e.bandwidth,y:null}}}function Bo(t,e,n,s){if(e.cols.xmin&&t.type!=="tile")return[s.apply(e.cols.xmin[n]),s.apply(e.cols.xmax[n])];if(s.bandwidth!==void 0){let i=e.cols.slots?.[n]??1,l=s.bandwidth/i,a=s.apply(e.cols.x[n])+(e.cols.slot?.[n]??0)*l;return[a,a+l]}let o=cn(e.cols.x,s),r=s.apply(e.cols.x[n]);return[r-o,r+o]}function Lo(t,e,n,s){if(t.type==="tile"){if(s.bandwidth!==void 0)return[s.apply(e.cols.y[n]),s.apply(e.cols.y[n])+s.bandwidth];let o=cn(e.cols.y,s),r=s.apply(e.cols.y[n]);return[r-o,r+o]}return[s.apply(e.cols.ymin[n]),s.apply(e.cols.ymax[n])]}function cn(t,e){let n=[...new Set(t.map(Number))].sort((o,r)=>o-r),s=1/0;for(let o=1;o<n.length;o++)s=Math.min(s,n[o]-n[o-1]);return Number.isFinite(s)?Math.abs(e.apply(n[0]+s)-e.apply(n[0]))/2:6}var Oo={zoom:'<path d="M4 9V4h5M15 4h5v5M20 15v5h-5M9 20H4v-5"/><rect x="9" y="9" width="6" height="6"/>',pan:'<path d="M12 3v18M3 12h18M12 3l-2.5 2.5M12 3l2.5 2.5M12 21l-2.5-2.5M12 21l2.5-2.5M3 12l2.5-2.5M3 12l2.5 2.5M21 12l-2.5-2.5M21 12l-2.5 2.5"/>',zoomIn:'<path d="M12 5v14M5 12h14"/>',zoomOut:'<path d="M5 12h14"/>',home:'<path d="M4 11l8-7 8 7M6 9.5V20h12V9.5"/>',copy:'<rect x="8.5" y="8.5" width="11" height="11"/><path d="M15.5 8.5V4.5h-11v11h4"/>',download:'<path d="M12 4v11M7.5 10.5L12 15l4.5-4.5M5 19.5h14"/>',check:'<path d="M5 12.5l4.5 4.5L19 7.5"/>'},Po=`
2
+ .pt-root{position:relative;--pt-size:24px}
3
+ .pt-root svg{display:block;user-select:none;-webkit-user-select:none}
4
+ .pt-root .pt-key{cursor:pointer}
5
+ .pt-root:focus{outline:none}
6
+ .pt-bar{position:absolute;top:6px;right:6px;display:flex;align-items:stretch;z-index:3;background:var(--pt-bg);
7
+ border:1px solid var(--pt-line);opacity:0;transition:opacity .12s ease}
8
+ .pt-root:hover .pt-bar,.pt-root:focus-within .pt-bar,.pt-bar.pt-open{opacity:1}
9
+ @media (hover:none){.pt-bar{opacity:1}}
10
+ .pt-btn{all:unset;box-sizing:border-box;display:grid;place-items:center;width:var(--pt-size);height:var(--pt-size);
11
+ color:var(--pt-muted);cursor:pointer}
12
+ .pt-btn svg{width:58%;height:58%;fill:none;stroke:currentColor;stroke-width:1.75;stroke-linecap:square;stroke-linejoin:miter}
13
+ .pt-btn:hover{color:var(--pt-ink);background:var(--pt-soft)}
14
+ .pt-btn:focus-visible{outline:2px solid var(--pt-accent);outline-offset:-2px}
15
+ .pt-btn.pt-on{color:var(--pt-on-accent);background:var(--pt-accent)}
16
+ .pt-sep{width:1px;background:var(--pt-line)}
17
+ .pt-menu{position:absolute;top:100%;right:-1px;display:none;flex-direction:column;min-width:72px;margin-top:-1px;
18
+ background:var(--pt-bg);border:1px solid var(--pt-line)}
19
+ .pt-menu.pt-open{display:flex}
20
+ .pt-menu button{all:unset;padding:5px 12px;font:600 11px/1.4 system-ui,sans-serif;letter-spacing:.04em;color:var(--pt-ink);cursor:pointer}
21
+ .pt-menu button:hover{color:var(--pt-on-accent);background:var(--pt-accent)}
22
+ .pt-tip{position:absolute;display:none;pointer-events:none;z-index:4;min-width:110px;max-width:280px;background:var(--pt-bg);
23
+ color:var(--pt-ink);border:1px solid var(--pt-c);line-height:1.3;font-variant-numeric:tabular-nums}
24
+ .pt-tip.pt-pinned{border-width:2px;box-shadow:3px 3px 0 color-mix(in srgb,var(--pt-c) 35%,transparent)}
25
+ .pt-tip .pt-head{padding:3px 7px;background:var(--pt-c);color:var(--pt-on-c);font-weight:700;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
26
+ .pt-tip .pt-rows{display:grid;grid-template-columns:auto minmax(0,1fr) auto;column-gap:7px;row-gap:0;padding:4px 7px 5px}
27
+ .pt-tip .pt-sw{width:8px;height:8px;align-self:center}
28
+ .pt-tip .pt-k{color:var(--pt-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
29
+ .pt-tip .pt-v{text-align:right;white-space:nowrap}
30
+ .pt-tip .pt-b{color:var(--pt-ink);font-weight:700}
31
+ .pt-tip .pt-t{border-top:1px solid var(--pt-line);padding-top:2px;margin-top:1px}
32
+ .pt-tip .pt-more{grid-column:1/-1;color:var(--pt-muted);font-size:.9em}
33
+ .pt-error{padding:8px 10px;border-left:3px solid #d93025;background:#fdecea;color:#5f2120;font:12px/1.4 ui-monospace,monospace;white-space:pre-wrap}
34
+ `;function pn(t){if(t.getElementById("plotto-style"))return;let e=t.createElement("style");e.id="plotto-style",e.textContent=Po,t.head.append(e)}function dn(t,e){let n={bg:e.background,ink:e.ink,muted:e.muted,line:e.grid,soft:e.strip,accent:e.accent,"on-accent":ve(e.accent)};for(let[s,o]of Object.entries(n))t.style.setProperty(`--pt-${s}`,o)}function hn(t,e){let n=t.createElement("div");n.className="pt-bar";let s={},o=null;e.forEach((i,l)=>{l&&n.append(Object.assign(t.createElement("div"),{className:"pt-sep"}));for(let a of i){let c=t.createElement("button");c.className="pt-btn",c.type="button",c.title=a.title,c.setAttribute("aria-label",a.title),c.innerHTML=un(a.name),c.addEventListener("pointerdown",u=>u.stopPropagation()),c.addEventListener("click",u=>(u.stopPropagation(),a.menu?r():a.action(c))),n.append(c),s[a.name]=c,a.menu&&(o=To(t,n,a.menu))}});function r(){let i=!o.classList.contains("pt-open");o.classList.toggle("pt-open",i),n.classList.toggle("pt-open",i)}return o&&t.addEventListener("click",()=>o.classList.contains("pt-open")&&r()),{el:n,button:i=>s[i],setSize:i=>n.parentElement?.style.setProperty("--pt-size",`${Math.round(Math.min(30,Math.max(22,i/34)))}px`),flash(i,l){let a=s[i],[c,u]=[a.innerHTML,a.title];a.innerHTML=un("check"),a.title=l,a.classList.add("pt-on"),setTimeout(()=>(a.innerHTML=c,a.title=u,a.classList.remove("pt-on")),1100)}}}function To(t,e,n){let s=t.createElement("div");s.className="pt-menu";for(let[o,r]of n){let i=t.createElement("button");i.type="button",i.textContent=o,i.addEventListener("click",l=>(l.stopPropagation(),s.classList.remove("pt-open"),e.classList.remove("pt-open"),r())),s.append(i)}return e.append(s),s}function un(t){return`<svg viewBox="0 0 24 24" aria-hidden="true">${Oo[t]}</svg>`}var Nt=5,re=320,mn=.75,No=300;function xn(t,e,{interactive:n=!1,width:s}={}){let o=e.ownerDocument;pn(o);let r=o.createElement("div");r.className="pt-root";let i=Object.assign(o.createElement("div"),{className:"pt-tip"}),l={state:null,mode:"zoom"},a=null,c=p=>{let v=l.state&&{domains:l.state.domains===l.state.home?void 0:l.state.domains,hidden:l.state.hidden},g=ee(t,{document:o,width:p,...v}),w=l.state?.svg;g.overlay=g.svg.appendChild(B(o,"g",{class:"pt-overlay","pointer-events":"none"})),g.theme.reflow||(g.svg.setAttribute("width","100%"),g.svg.removeAttribute("height"),r.style.maxWidth=`${g.W}px`),w?w.replaceWith(g.svg):r.prepend(g.svg),l.state=g,dn(r,g.theme),d.setSize(g.theme.reflow?g.W:Math.min(g.W,e.clientWidth||g.W))},u=[[{name:"copy",title:"Copy as PNG",action:p=>Je(l.state.svg).then(v=>d.flash("copy",v))},{name:"download",title:"Download",menu:[["PNG",()=>Qe(l.state.svg)],["SVG",()=>tn(l.state.svg)]]}]];n&&u.unshift([{name:"zoom",title:"Zoom: drag a box",action:()=>h("zoom")},{name:"pan",title:"Pan: drag the view",action:()=>h("pan")}],[{name:"zoomIn",title:"Zoom in",action:()=>fn(l,mn)},{name:"zoomOut",title:"Zoom out",action:()=>fn(l,1/mn)},{name:"home",title:"Reset view (double-click)",action:()=>yn(l)}]);let d=hn(o,u);r.append(d.el,i);let h=p=>{l.mode=p,d.button("zoom").classList.toggle("pt-on",p==="zoom"),d.button("pan").classList.toggle("pt-on",p==="pan"),r.style.cursor=p==="pan"?"grab":""};try{let p=s??(e.clientWidth?Math.max(re,e.clientWidth):void 0);c(p),e.replaceChildren(r)}catch(p){let v=Object.assign(o.createElement("div"),{className:"pt-error",textContent:`plotto: ${p.message}`});throw e.prepend(v),p}if(n&&(h("zoom"),jo(l,r,i)),l.state.theme.reflow&&s===void 0&&typeof ResizeObserver<"u"){let p;a=new ResizeObserver(()=>{clearTimeout(p),p=setTimeout(()=>{let v=Math.max(re,Math.round(e.clientWidth));v&&v!==l.state.W&&c(v)},100)}),a.observe(e)}return l.redraw=()=>rt(l.state),l.resize=p=>c(Math.max(re,p)),l.destroy=()=>a?.disconnect(),l}function jo(t,e,n){let s=null,o=null,r=()=>t.state.svg,i=b=>{let f=r().getBoundingClientRect(),y=t.state.W/f.width;return[(b.clientX-f.left)*y,(b.clientY-f.top)*y,y]},l=(b,f)=>t.state.layout.panels.findIndex(y=>b>=y.x+y.ml&&b<=y.x+y.ml+y.innerW&&f>=y.y&&f<=y.y+y.innerH),a=!1;e.addEventListener("pointerdown",b=>{if(b.button!==0||!r().contains(b.target))return;let[f,y]=i(b),m=l(f,y);m<0||(b.preventDefault(),e.focus({preventScroll:!0}),s={i:m,x:f,y,domains:t.state.domains,moving:!1,id:b.pointerId})}),e.addEventListener("pointermove",b=>{let[f,y,m]=i(b);if(s&&!s.moving&&Math.hypot(f-s.x,y-s.y)>=Nt&&(s.moving=!0,e.setPointerCapture(s.id),u(),w(),t.mode==="pan"&&(e.style.cursor="grabbing")),!s?.moving){!a&&!o&&(o=requestAnimationFrame(()=>(o=null,g(f,y,m))));return}if(t.mode==="pan")return qo(t,s,f,y);let x=t.state.layout.panels[s.i],k=G=>Math.max(x.x+x.ml,Math.min(x.x+x.ml+x.innerW,G)),M=G=>Math.max(x.y,Math.min(x.y+x.innerH,G)),[A,F]=[s.x,k(f)].sort((G,z)=>G-z),[S,O]=[s.y,M(y)].sort((G,z)=>G-z),I=O-S<Nt||t.state.kind.y==="category",j=F-A<Nt||t.state.kind.x==="category";if(I&&j)return t.state.overlay.replaceChildren();let kt={x:j?x.x+x.ml:A,y:I?x.y:S,width:j?x.innerW:F-A,height:I?x.innerH:O-S},st=t.state.theme.accent;t.state.overlay.replaceChildren(B(t.state.doc,"rect",{...kt,fill:st,"fill-opacity":.1,stroke:st,"stroke-opacity":.7,"stroke-width":1})),s.box={x0:A,x1:F,y0:S,y1:O}}),e.addEventListener("pointerup",b=>{if(s?.moving&&t.mode==="zoom"&&s.box)Ro(t,s.i,s.box);else if(s&&!s.moving){let[f,y,m]=i(b);a?(u(),g(f,y,m)):(g(f,y,m),n.style.display==="block"&&c())}t.mode==="pan"&&(e.style.cursor="grab"),a||t.state.overlay.replaceChildren(),s=null}),e.addEventListener("pointerleave",()=>!s&&!a&&w()),e.addEventListener("keydown",b=>b.key==="Escape"&&(u(),w())),e.tabIndex=-1,t.clearHover=()=>(u(),w());function c(){a=!0,n.classList.add("pt-pinned")}function u(){a=!1,n.classList.remove("pt-pinned")}let d=b=>t.state.doc.elementFromPoint(b.clientX,b.clientY),h=b=>d(b)?.closest?.(".pt-key");e.addEventListener("dblclick",b=>{let[f,y]=i(b);l(f,y)<0||(u(),w(),yn(t))});let p={value:void 0,time:0,before:null};e.addEventListener("click",b=>{let f=h(b);if(!f)return;let y=t.state.legend.items[Number(f.dataset.index)].value;t.clearHover();let m=performance.now();if(y===p.value&&m-p.time<No)return t.state.hidden=p.before,p={value:void 0,time:0,before:null},Io(t,y);p={value:y,time:m,before:t.state.hidden};let x=new Set(t.state.hidden);x.has(y)?x.delete(y):x.add(y),t.state.hidden=x,rt(t.state)});let v=null;function g(b,f,y){let m=t.state,x=l(b,f),k=x<0?null:m.layout.panels[x],M=k?an(m,x,b-k.x,f-k.y,v):null;if(v=M,!M)return w();let A=m.doc,F=[];if(M.crosshair!==void 0){let z=k.x+M.crosshair;F.push(B(A,"line",{x1:z,x2:z,y1:k.y,y2:k.y+k.innerH,stroke:m.theme.muted,"stroke-opacity":.55,"stroke-width":1}))}for(let z of M.marks)z.rect?F.push(B(A,"rect",{x:k.x+z.rect.x,y:k.y+z.rect.y,width:z.rect.width,height:z.rect.height,fill:"none",stroke:z.color,"stroke-width":1.5})):F.push(B(A,"circle",{cx:k.x+z.x,cy:k.y+z.y,r:m.theme.point+1.5,fill:z.color,stroke:m.theme.background,"stroke-width":1.5}));m.overlay.replaceChildren(...F);let S=Ut(M.color);n.style.setProperty("--pt-c",S.bg),n.style.setProperty("--pt-on-c",S.fg),n.style.font=`${m.fonts.hover}px ${m.theme.font}`,n.replaceChildren(...Ho(A,M)),n.style.display="block";let O=(k.x+M.anchor.x)/y,I=f/y,j=e.clientWidth,kt=e.clientHeight,st=O+16+n.offsetWidth>j?O-16-n.offsetWidth:O+16,G=Math.min(Math.max(0,I-18),Math.max(0,kt-n.offsetHeight));n.style.left=`${Math.max(0,st)}px`,n.style.top=`${G}px`}function w(){n.style.display="none",s||t.state.overlay.replaceChildren()}}function Ho(t,e){let n=(r,i,l)=>Object.assign(t.createElement(r),{className:i,textContent:l??""}),s=[];e.header&&s.push(n("div","pt-head",e.header));let o=n("div","pt-rows");for(let r of e.rows){let i=n("span","pt-sw");r.swatch&&(i.style.background=r.swatch);let l=[i,n("span","pt-k",r.label),n("span","pt-v",r.value)];r.strong&&l.forEach(a=>a.classList.add("pt-b")),r.total&&l.forEach(a=>a.classList.add("pt-t")),o.append(...l)}return e.note&&o.append(n("span","pt-more",e.note)),s.push(o),s}function yn(t){t.clearHover?.(),t.state.domains=t.state.home,rt(t.state)}function Io(t,e){let n=t.state.legend.items.map(o=>o.value),s=t.state.hidden.size===n.length-1&&!t.state.hidden.has(e);t.state.hidden=s?new Set:new Set(n.filter(o=>o!==e)),rt(t.state)}function Ro(t,e,{x0:n,x1:s,y0:o,y1:r}){let i=t.state,l=i.layout.panels[e],a=i.panels[e].plot,c=i.domains.map(d=>({...d})),u=(d,h,p)=>{if(i.kind[d]==="category"||p-h<Nt)return;let v=a.scale(d),g=d==="x"?l.x:l.y,w=[v.invert(h-g),v.invert(p-g)].map(Number).sort((b,f)=>b-f);gn(i,d,e).forEach(b=>c[b][d]=w)};u("x",n,s),u("y",o,r),i.domains=c,rt(i)}function fn(t,e){t.clearHover?.();let n=t.state;n.domains=n.domains.map(s=>{let o={...s};for(let r of["x","y"]){let i=n.kind[r];if(i==="category")continue;let l=i==="log"?Math.log10:h=>h,a=i==="log"?h=>10**h:h=>h,[c,u]=s[r].map(h=>l(+h)),d=(c+u)/2;o[r]=[a(d-(u-c)/2*e),a(d+(u-c)/2*e)]}return o}),rt(n)}function qo(t,e,n,s){let o=t.state,r=o.layout.panels[e.i],i=o.panels[e.i].plot,l=e.domains.map(a=>({...a}));for(let[a,c,u,d]of[["x",e.x,n,r.x],["y",e.y,s,r.y]]){if(o.kind[a]==="category")continue;let h=i.scale(a),p=o.kind[a]==="log",v=b=>p?Math.log10(b):b,g=v(+h.invert(c-d))-v(+h.invert(u-d)),w=e.domains[e.i][a].map(b=>p?10**(v(b)+g):+b+g);gn(o,a,e.i).forEach(b=>l[b][a]=w)}o.domains=l,o.frame||(o.frame=requestAnimationFrame(()=>(o.frame=null,rt(o))))}function gn(t,e,n){let s=t.ns.facet?.free?.[e],o=t.grid.panels[n];return t.grid.panels.flatMap((r,i)=>s?t.grid.kind!=="grid"?i===n?[i]:[]:(e==="x"?r.col===o.col:r.row===o.row)?[i]:[]:[i])}globalThis.plotto={plot:fe,draw:xn,toSVG:Ke};
@@ -8,6 +8,8 @@ from __future__ import annotations
8
8
 
9
9
  import json
10
10
 
11
+ import numpy as np
12
+
11
13
  from . import assets, output
12
14
  from .data import to_column, to_frame, to_value
13
15
 
@@ -24,7 +26,16 @@ def plot(data, **mapping) -> Plot:
24
26
  if ch not in PLOT_CHANNELS:
25
27
  _fail("plot()", "channel", ch, PLOT_CHANNELS)
26
28
  _need_column(frame, col, "plot()")
27
- state = {"data": [frame], "mapping": mapping, "layers": [], "facet": None, "scales": {}, "labels": {}, "theme": {"style": "pastel"}}
29
+ state = {
30
+ "data": [frame],
31
+ "mapping": mapping,
32
+ "layers": [],
33
+ "facet": None,
34
+ "scales": {},
35
+ "labels": {},
36
+ "info": None,
37
+ "theme": {"style": "pastel"},
38
+ }
28
39
  return Plot(state)
29
40
 
30
41
 
@@ -163,6 +174,22 @@ class Plot:
163
174
  _check_keys(options, GRAMMAR["labels"], "labels()")
164
175
  return self._with(labels={**self._s["labels"], **options})
165
176
 
177
+ def info(self, entries, **options) -> Plot:
178
+ """A key/value table about the data or the experiment: info({"location": "hayama"}, position="right"). None removes it."""
179
+ _check_keys(options, GRAMMAR["info"], "info()")
180
+ position = options.get("position", "right")
181
+ if position not in GRAMMAR["infoPosition"]:
182
+ _fail("info()", "position", position, GRAMMAR["infoPosition"])
183
+ if entries is None:
184
+ return self._with(info=None)
185
+ if isinstance(entries, dict):
186
+ pairs = list(entries.items())
187
+ elif isinstance(entries, (list, tuple)):
188
+ pairs = list(entries)
189
+ else:
190
+ raise ValueError("info(): entries must be a dict or a list of (key, value) pairs")
191
+ return self._with(info={"entries": [_info_entry(pair) for pair in pairs], "position": position})
192
+
166
193
  def theme(self, style="pastel", **options) -> Plot:
167
194
  """The look (style) and the output size (format): theme("wota", format="slide")."""
168
195
  _check_keys(options, GRAMMAR["theme"], "theme()")
@@ -199,7 +226,7 @@ class Plot:
199
226
  for i in range(len(s["data"])):
200
227
  use(i, col)
201
228
  data = [{"columns": {c: to_column(frame[c]) for c in used[i]}} for i, frame in enumerate(s["data"])]
202
- return {
229
+ spec = {
203
230
  "version": 1,
204
231
  "data": data,
205
232
  "mapping": s["mapping"],
@@ -207,8 +234,11 @@ class Plot:
207
234
  "facet": s["facet"],
208
235
  "scales": s["scales"],
209
236
  "labels": s["labels"],
210
- "theme": s["theme"],
211
237
  }
238
+ if s["info"]:
239
+ spec["info"] = s["info"]
240
+ spec["theme"] = s["theme"]
241
+ return spec
212
242
 
213
243
  def save(self, path, scale=2, width=None, height=None):
214
244
  """Write the plot as .svg or .png. scale: PNG px per figure px. width, height: the figure size in px."""
@@ -247,6 +277,18 @@ def _constant(key, value, where, columns):
247
277
  return to_value(value)
248
278
 
249
279
 
280
+ def _info_entry(pair):
281
+ """One [key, value] entry of info(). Numbers keep 6 significant digits; the renderer writes the value as text."""
282
+ if not isinstance(pair, (list, tuple)) or len(pair) != 2 or not isinstance(pair[0], str):
283
+ raise ValueError("info(): each entry must be a (key, value) pair with a string key")
284
+ key, value = pair
285
+ if value is None or isinstance(value, (str, bool, np.bool_)):
286
+ return [key, None if value is None else value if isinstance(value, str) else bool(value)]
287
+ if isinstance(value, (int, float, np.integer, np.floating)):
288
+ return [key, to_value(value)]
289
+ raise ValueError(f'info(): the value of "{key}" must be a string, a number, a boolean or None. Format other values as a string')
290
+
291
+
250
292
  def _need_column(frame, col, where):
251
293
  if col not in frame.columns:
252
294
  raise ValueError(f'{where}: "{col}" is not a column. Columns: {", ".join(map(str, frame.columns))}')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-plotto
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Grammar-of-graphics plots for notebooks, web pages and slides with one renderer.
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://theoradusz.github.io/plotto/
@@ -2,6 +2,7 @@ import json
2
2
  import subprocess
3
3
  from pathlib import Path
4
4
 
5
+ import numpy as np
5
6
  import pandas as pd
6
7
  import pytest
7
8
 
@@ -59,6 +60,9 @@ def test_only_used_columns_go_into_the_spec():
59
60
  (lambda p: p.bar(position="beside"), 'unknown position "beside"'),
60
61
  (lambda p: p.color(palette="rainbow"), 'unknown palette "rainbow"'),
61
62
  (lambda p: p.y(limits=5), "limits must be a list"),
63
+ (lambda p: p.info({"a": 1}, position="left"), 'unknown position "left"'),
64
+ (lambda p: p.info({"date": pd.Timestamp("2026-10-01")}), "Format other values as a string"),
65
+ (lambda p: p.info("hayama"), "entries must be"),
62
66
  ],
63
67
  )
64
68
  def test_errors_name_the_problem_and_the_valid_names(build, message):
@@ -91,3 +95,11 @@ def test_categories_keep_their_order_and_missing_values_are_null():
91
95
  columns = plot(df, x="day", y="v").point().spec()["data"][0]["columns"]
92
96
  assert columns["day"]["levels"] == ["Mon", "Tue"]
93
97
  assert columns["v"]["values"] == [1.5, None]
98
+
99
+
100
+ def test_info_keeps_the_order_and_numpy_values():
101
+ p = plot(pd.DataFrame(FIXTURE["rows"]), x="t", y="v").line()
102
+ info = p.info({"n": np.int64(3), "x": np.float64(2.0), "ok": np.bool_(True), "none": None}).spec()["info"]
103
+ assert info == {"entries": [["n", 3], ["x", 2.0], ["ok", True], ["none", None]], "position": "right"}
104
+ assert "info" not in p.spec()
105
+ assert "info" not in p.info({"a": 1}).info(None).spec()
@@ -1,34 +0,0 @@
1
- var N={options:{size:"number",alpha:"number",dash:["solid","dashed","dotted","dashdot"],jitter:"number",summary:["mean","median","min","max","sum"],slope:"number",intercept:"number",position:["stack","dodge","overlay"],bins:"number",density:"boolean",method:["lm","loess"],span:"number",band:"boolean"},layers:{line:{channels:["x","y","color","group","tooltip"],options:["size","alpha","dash","summary"],requires:["x","y"]},path:{channels:["x","y","color","group","tooltip"],options:["size","alpha","dash"],requires:["x","y"]},step:{channels:["x","y","color","group","tooltip"],options:["size","alpha","dash"],requires:["x","y"]},point:{channels:["x","y","color","tooltip"],options:["size","alpha","jitter","summary"],requires:["x","y"]},bar:{channels:["x","y","color","tooltip"],options:["alpha","position"],requires:["x","y"]},hist:{channels:["x","color"],options:["alpha","bins","density","position"],requires:["x"]},density:{channels:["x","color"],options:["size","alpha","dash"],requires:["x"]},area:{channels:["x","y","color","group"],options:["alpha","position"],requires:["x","y"]},ribbon:{channels:["x","ymin","ymax","color","group"],options:["alpha"],requires:["x","ymin","ymax"]},smooth:{channels:["x","y","color"],options:["size","alpha","dash","method","span","band"],requires:["x","y"]},hline:{channels:["y","color"],options:["size","alpha","dash"],requires:["y"],inherit:!1},vline:{channels:["x","color"],options:["size","alpha","dash"],requires:["x"],inherit:!1},abline:{channels:["color"],options:["slope","intercept","size","alpha","dash"],requires:[],inherit:!1},segment:{channels:["x","y","xend","yend","color"],options:["size","alpha","dash"],requires:["x","y","xend","yend"]},rect:{channels:["xmin","xmax","ymin","ymax","color","tooltip"],options:["alpha"],requires:["xmin","xmax","ymin","ymax"]},band:{channels:["xmin","xmax","ymin","ymax","color"],options:["alpha"],requires:[],inherit:!1},tile:{channels:["x","y","color","tooltip"],options:["alpha"],requires:["x","y","color"]},text:{channels:["x","y","label","color"],options:["size","alpha"],requires:["x","y","label"]},errorbar:{channels:["x","ymin","ymax","color"],options:["size","alpha"],requires:["x","ymin","ymax"]},box:{channels:["x","y","color"],options:["alpha"],requires:["x","y"]}},scales:{x:["type","limits","format"],y:["type","limits","format"],color:["values","palette","scheme","limits","mid","clamp"]},scaleTypes:["linear","log","time","category"],facet:["free","ncol"],grid:["free"],free:["x","y","both"],labels:["title","subtitle","x","y","color","caption"],theme:["format","width","height","size","legend"],legend:["right","bottom","none"]};var O={styles:{pastel:{font:"Helvetica, Arial, 'Liberation Sans', sans-serif",metrics:"arial",background:"#FFFEFB",ink:"#3A3631",muted:"#7A736A",grid:"#ECE8E1",gridMinor:"#F6F3EE",tick:"#D6D0C6",strip:"#F4F0E9",accent:"#3E8A99",palette:"pastel",scheme:"ai",colors:{blue:"#7AA6DA",orange:"#EF977F",green:"#7DB89A",purple:"#A79BD6",pink:"#E48FAE",yellow:"#DDB459",teal:"#63B7C1",red:"#CF7468",brown:"#BB9C84",gray:"#97A1AD"},weight:1.25},wota:{font:"'M PLUS 1p', sans-serif",metrics:"mplus",ink:"#333333",muted:"#666666",grid:"#D9D9D9",gridMinor:"#EFEFEF",tick:"#BBBBBB",strip:"#EEF1FA",accent:"#5C6BC0",palette:"wota",scheme:"sakura",colors:{pink:"#E4007F",blue:"#5C6BC0",teal:"#00A3A3",orange:"#F5A623",purple:"#8E44AD",gray:"#7F7F7F",green:"#3BA55C",red:"#D7263D",yellow:"#F2C14E",brown:"#8D6E63"},weight:1,background:"#FFFFFF"},paper:{ink:"#000000",muted:"#333333",grid:"#E6E6E6",gridMinor:"#F5F5F5",tick:"#8C8C8C",strip:"#EBEBEB",accent:"#0072B2",palette:["blue","orange","green","pink","yellow","teal","red","brown","purple","gray"],scheme:"viridis",colors:{blue:"#0072B2",orange:"#E69F00",green:"#009E73",pink:"#CC79A7",yellow:"#F0E442",teal:"#56B4E9",red:"#D55E00",brown:"#8C6D31",purple:"#6A3D9A",gray:"#7F7F7F"},weight:1,background:"#FFFFFF"},dark:{background:"#16181D",ink:"#E8EAED",muted:"#A6ABB3",grid:"#2E323A",gridMinor:"#22252B",tick:"#4F5560",strip:"#252933",accent:"#8AB4F8",palette:["blue","orange","green","purple","pink","yellow","teal","red","brown","gray"],scheme:"yuhi",colors:{blue:"#8AB4F8",orange:"#FBA94C",green:"#81C995",purple:"#C58AF9",pink:"#FF8BCB",yellow:"#FDD663",teal:"#78D9D3",red:"#F28B82",brown:"#C8A27A",gray:"#9AA0A6"},weight:1.15}},palettes:{pastel:["#7AA6DA","#EF977F","#7DB89A","#A79BD6","#E48FAE","#DDB459","#63B7C1","#CF7468","#BB9C84","#97A1AD"],wota:["#E4007F","#5C6BC0","#00A3A3","#F5A623","#8E44AD","#7F7F7F","#3BA55C","#D7263D","#F2C14E","#8D6E63"],sakura:["#E16B8C","#5DAC81","#8B81C3","#FFB11B","#7DB9DE","#F596AA","#B9887D","#91AD70"],aizome:["#0F2540","#51A8DD","#66BAB7","#656765","#0D5661","#A5DEE4","#7B90D2"],momiji:["#CB4042","#FFB11B","#6C6A2D","#6D2E5B","#ED784A","#734338","#C99833"],tableau:["#4E79A7","#F28E2B","#E15759","#76B7B2","#59A14F","#EDC948","#B07AA1","#FF9DA7","#9C755F","#BAB0AC"]},schemes:{ai:["#F4F8F8","#A5DEE4","#33A6B8","#0D5661","#0F2540"],sakura:["#FEF4F4","#FEDFE1","#F596AA","#D05A6E","#8E354A","#4A1D30"],matcha:["#F8F6E3","#D7E3B5","#91AD70","#5DAC81","#1B813E","#0B3B2A"],yuhi:["#FFF3D6","#FFB11B","#ED784A","#CB4042","#6D2E5B","#26113A"],sumi:["#FCFAF2","#BDC0BA","#828282","#434343","#1C1C1C"],aiaka:["#0F2540","#33A6B8","#A5DEE4","#F7F6F0","#F4A7A0","#CB4042","#5C1A1B"]},formats:{screen:{width:900,height:450,size:12,line:1.5,point:2.5,reflow:!0},report:{width:640,height:400,size:10,line:1.2,point:2,reflow:!1},slide:{width:1280,height:720,size:20,line:2.5,point:4,reflow:!1}}};var le=N.layers,se=[...new Set(Object.values(le).flatMap(t=>t.channels))];function ae(t,e={}){let n=[ce(t,"plot()")];for(let[s,o]of Object.entries(e))se.includes(s)||Z("plot()","channel",s,se),qt(n[0],o,"plot()");return new Ht({data:n,mapping:e,layers:[],facet:null,scales:{},labels:{},theme:{style:"pastel"}})}var Ht=class t{#e;constructor(e){this.#e=e}#n(e){return new t({...this.#e,...e})}#t(e,n={}){let s=le[e],o=`${e}()`,{data:r,...i}=n,l=this.#e.data,a=0;r!==void 0&&(l=[...l,ce(r,o)],a=l.length-1);let c=l[a].columns,u={type:e,mapping:{},set:{}};a&&(u.data=a);for(let[p,d]of Object.entries(i))s.channels.includes(p)&&typeof d=="string"&&d in c?u.mapping[p]=d:s.channels.includes(p)||s.options.includes(p)?u.set[p]=xn(p,d,o,c):Z(o,"option",p,["data",...s.channels,...s.options]);return this.#n({data:l,layers:[...this.#e.layers,u]})}line(e){return this.#t("line",e)}step(e){return this.#t("step",e)}bar(e){return this.#t("bar",e)}hist(e){return this.#t("hist",e)}density(e){return this.#t("density",e)}area(e){return this.#t("area",e)}ribbon(e){return this.#t("ribbon",e)}smooth(e){return this.#t("smooth",e)}path(e){return this.#t("path",e)}point(e){return this.#t("point",e)}hline(e){return this.#t("hline",e)}vline(e){return this.#t("vline",e)}abline(e){return this.#t("abline",e)}segment(e){return this.#t("segment",e)}rect(e){return this.#t("rect",e)}band(e){return this.#t("band",e)}tile(e){return this.#t("tile",e)}text(e){return this.#t("text",e)}errorbar(e){return this.#t("errorbar",e)}box(e){return this.#t("box",e)}facet(e,n={}){return qt(this.#e.data[0],e,"facet()"),kt(n,N.facet,"facet()"),ie(n.free,"facet()"),this.#n({facet:{wrap:e,free:n.free??null,ncol:n.ncol??null}})}grid({rows:e=null,cols:n=null,...s}={}){if(e===null&&n===null)throw new Error("grid(): set rows, cols or both");for(let o of[e,n])o!==null&&qt(this.#e.data[0],o,"grid()");return kt(s,N.grid,"grid()"),ie(s.free,"grid()"),this.#n({facet:{rows:e,cols:n,free:s.free??null}})}x(e){return this.#o("x",e)}y(e){return this.#o("y",e)}color(e){return this.#o("color",e)}#o(e,n={}){let s=`${e}()`;if(kt(n,N.scales[e],s),n.type!==void 0&&!N.scaleTypes.includes(n.type)&&Z(s,"type",n.type,N.scaleTypes),n.palette!==void 0&&!Array.isArray(n.palette)&&!(n.palette in O.palettes)&&Z(s,"palette",n.palette,Object.keys(O.palettes)),n.mid!==void 0&&typeof n.mid!="number")throw new Error(`${s}: mid must be a number`);let o={...n};if(o.limits){if(!Array.isArray(o.limits))throw new Error(`${s}: limits must be a list, for example [0, 10] or [0, null]`);o.limits=o.limits.map(r=>r==null?null:Rt(r))}return this.#n({scales:{...this.#e.scales,[e]:o}})}labels(e={}){return kt(e,N.labels,"labels()"),this.#n({labels:{...this.#e.labels,...e}})}theme(e="pastel",n={}){return kt(n,N.theme,"theme()"),e in O.styles||Z("theme()","style",e,Object.keys(O.styles)),n.format!==void 0&&!(n.format in O.formats)&&Z("theme()","format",n.format,Object.keys(O.formats)),n.legend!==void 0&&!N.legend.includes(n.legend)&&Z("theme()","legend",n.legend,N.legend),this.#n({theme:{style:e,...n}})}spec(){let e=this.#e,n=e.data.map(()=>new Set);for(let o of Object.values(e.mapping))n.forEach((r,i)=>o in e.data[i].columns&&r.add(o));for(let o of e.layers)for(let r of Object.values(o.mapping))n[o.data??0].add(r);for(let o of[e.facet?.wrap,e.facet?.rows,e.facet?.cols])o&&n.forEach((r,i)=>o in e.data[i].columns&&r.add(o));return{version:1,data:e.data.map((o,r)=>({columns:Object.fromEntries([...n[r]].map(i=>[i,o.columns[i]]))})),mapping:e.mapping,layers:e.layers,facet:e.facet,scales:e.scales,labels:e.labels,theme:e.theme}}};function ce(t,e){if(!Array.isArray(t))throw new Error(`${e}: data must be an array of row objects`);let n=[...new Set(t.flatMap(Object.keys))],s={};for(let o of n){let r=t.map(c=>c[o]??null),i=r.find(c=>c!==null&&!Number.isNaN(c)),l=i instanceof Date?"time":typeof i=="number"?"number":"string",a=r.map(c=>c===null||Number.isNaN(c)?null:l==="string"?String(c):Rt(c));s[o]={type:l,values:a}}return{columns:s}}function Rt(t){return t instanceof Date?t.getTime()-t.getTimezoneOffset()*6e4:typeof t=="number"&&!Number.isInteger(t)?Number(t.toPrecision(6)):t}function xn(t,e,n,s){let o=N.options[t];if(t==="tooltip"||t==="group")throw new Error(`${n}: ${t} must be a column. Columns: ${Object.keys(s).join(", ")}`);if(Array.isArray(o)&&!o.includes(e)&&Z(n,t,e,o),o==="number"&&typeof e!="number")throw new Error(`${n}: ${t} must be a number`);if(o==="boolean"&&typeof e!="boolean")throw new Error(`${n}: ${t} must be true or false`);if(t==="color"||t==="label")return e;if(typeof e=="string"&&!o)throw new Error(`${n}: "${e}" is not a column. Columns: ${Object.keys(s).join(", ")}`);return Rt(e)}function qt(t,e,n){if(!(e in t.columns))throw new Error(`${n}: "${e}" is not a column. Columns: ${Object.keys(t.columns).join(", ")}`)}function kt(t,e,n){for(let s of Object.keys(t))e.includes(s)||Z(n,"option",s,e)}function ie(t,e){t!=null&&!N.free.includes(t)&&Z(e,"free",t,N.free)}function Z(t,e,n,s){throw new Error(`${t}: unknown ${e} "${n}". Valid: ${s.join(", ")}`)}import*as V from"https://cdn.jsdelivr.net/npm/@observablehq/plot@0.6.17/+esm";import*as Bt from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";import*as $ from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";import*as H from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var yn=Object.keys(O.styles),gn=Object.keys(O.formats),bn=Object.keys(O.palettes),wn=Object.keys(O.schemes),ue=["ink","muted","grid","tick","strip","accent","background"];function pe({style:t="pastel",format:e="screen",legend:n="right",...s}={}){if(!O.styles[t])throw new Error(`theme(): unknown style "${t}". Valid: ${yn.join(", ")}`);if(!O.formats[e])throw new Error(`theme(): unknown format "${e}". Valid: ${gn.join(", ")}`);let o=O.styles.pastel,r=O.styles[t],i=O.formats[e],l=s.width!=null;for(let c of Object.keys(s))s[c]==null&&delete s[c];let a={...o,...r,colors:{...o.colors,...r.colors},...i,legend:n,...s,style:t,format:e};return a.reflow=i.reflow&&!l,a.line=i.line*(r.weight??o.weight??1),a.point=i.point*Math.sqrt(r.weight??o.weight??1),s.width!=null&&s.height==null&&(a.height=Math.round(s.width*i.height/i.width)),a.fixedHeight=s.height!=null,a.palette=It(a,a.palette),a}function It(t,e){let n=Array.isArray(e)?e:O.palettes[e];if(!n)throw new Error(`color(): unknown palette "${e}". Valid: ${bn.join(", ")}`);return n.map(s=>ht(t,s)??s)}function de(t,e){let n=o=>H.piecewise(H.interpolateLab,o.map(r=>ht(t,r)??r));if(Array.isArray(e))return n(e);if(O.schemes[e])return n(O.schemes[e]);let s=typeof e=="string"&&H[`interpolate${e[0].toUpperCase()}${e.slice(1)}`];if(!s)throw new Error(`color(): unknown scheme "${e}". plotto schemes: ${wn.join(", ")}; or a d3 scheme such as viridis, magma, blues`);return s}function ht(t,e){if(typeof e=="string")return t.colors[e]?t.colors[e]:ue.includes(e)?t[e]:H.color(e)?e:void 0}function me(t){return[...Object.keys(t.colors),...ue]}function Yt(t){let e=o=>{let r=[o.r,o.g,o.b].map(i=>(i/=255,i<=.03928?i/12.92:((i+.055)/1.055)**2.4));return .2126*r[0]+.7152*r[1]+.0722*r[2]},n=H.rgb(t);if(e(n)>.42)return{bg:n.formatHex(),fg:"#1F2328"};let s=H.hcl(n);for(let o=0;o<20&&1.05/(e(H.rgb(s))+.05)<4;o++)s=H.hcl(s.h,s.c,s.l-4);return{bg:H.rgb(s).formatHex(),fg:"#FFFFFF"}}function he(t){return Yt(t).fg}function fe(t){let e=t.size;return{base:e,tick:e-1,title:Math.round(e*1.35),subtitle:e,strip:e-1,legend:e-1,axisTitle:e,hover:Math.max(11,e-1)}}var Et={x:["x","xmin","xmax","xend"],y:["y","ymin","ymax","yend"]},xe=.05,Wt=864e5;function Vt(t,e){let n=t.scales[e]?.type;if(n)return n;for(let s of t.layers)for(let o of Et[e]){let r=s.channels[o]?.column;if(!r)continue;let i=t.tables[s.table].columns[r].type;return i==="time"?"time":i==="string"?"category":"linear"}return"linear"}function ge(t,e,n,s){let o=e.channels[n];if(!o)return;if("value"in o)return s.map(()=>o.value);let r=t.tables[e.table].columns[o.column].values;return s.map(i=>r[i])}function be(t,e,n,s){let o=[];for(let i of s)for(let l of i.views)for(let a of Et[e]){let c=l.cols[a];if(c)for(let u of c)u!=null&&(n==="category"||Number.isFinite(u))&&o.push(u)}if(n==="category")return vn(t,e,o);let r=$.extent(o.filter(i=>n!=="log"||i>0));return r[0]===void 0?n==="log"?[1,10]:[0,1]:we(r,n)}function vn(t,e,n){let s=t.layers.map(r=>r.channels[e]?.column&&t.tables[r.table].columns[r.channels[e].column].levels).find(Boolean),o=new Set(n.map(String));return s?s.filter(r=>o.has(r)):[...o].sort(Ct)}function Ct(t,e){return String(t).localeCompare(String(e),void 0,{numeric:!0})}function we([t,e],n){if(n==="log"){let[o,r]=we([Math.log10(t),Math.log10(e)],"linear");return[10**o,10**r]}let s=e>t?(e-t)*xe:n==="time"?36e5:Math.abs(t)*xe||1;return[t-s,e+s]}function ft(t,e,n,s){if(t==="category")return{major:e,minor:[],format:String};let[o,r]=e;if(t==="time"){let l=$.scaleUtc().domain([new Date(o),new Date(r)]).ticks(n),a=s??kn(l,r-o);return{major:l,minor:ye(l,e,c=>+c).map(c=>new Date(c)),format:$.utcFormat(a)}}if(t==="log"){let l=$.range(Math.ceil(Math.log10(o)),Math.floor(Math.log10(r))+1).map(u=>10**u),a=l.length>=2?l:$.scaleLog().domain(e).ticks(n).filter(u=>[1,2,5].includes(Math.round(u/10**Math.floor(Math.log10(u)+1e-9)))),c=l.flatMap(u=>$.range(2,10).map(p=>u/10*p)).filter(u=>u>o&&u<r);return{major:a,minor:c,format:$.format(s??"~g")}}let i=$.ticks(o,r,n);return{major:i,minor:ye(i,e,Number),format:s?$.format(s):$.tickFormat(o,r,n)}}function ye(t,[e,n],s){if(t.length<2)return[];let o=s(t[1])-s(t[0]);return[s(t[0])-o/2,...t.map(i=>s(i)+o/2)].filter(i=>i>e&&i<n)}function kn(t,e){let n=t.length>=2?t[1]-t[0]:e;return n>=28*Wt?"%Y-%m":n>=Wt?"%m-%d":n>=6e4?e>Wt?"%m-%d %H:%M":"%H:%M":"%H:%M:%S"}var En=$.format(",.4~r"),ve={number:t=>t==null?"\u2013":Math.abs(t)>=1e15||t!==0&&Math.abs(t)<1e-4?$.format(".3~e")(t):En(t),time:$.utcFormat("%m-%d %H:%M"),string:t=>t==null?"\u2013":String(t)};function ke(t){let e=t.theme,n=t.scales.color??{},s=t.layers.filter(f=>f.channels.color?.column);if(!s.length)return{kind:"none"};let o=s[0].channels.color.column,r=s.find(f=>f.channels.color.column!==o);if(r)throw new Error(`plotto: color maps "${o}" and "${r.channels.color.column}". Map color to one column only`);let i=s.map(f=>t.tables[f.table].columns[o]),l=i[0].type,a=i.flatMap(f=>f.values).filter(f=>f!==null),c=f=>ht(e,f)??f;if(l==="string"){let f=i.find(S=>S.levels)?.levels,g=new Set(a),h=n.limits??(f?f.filter(S=>g.has(S)):[...g].sort(Ct)),y=n.palette?It(e,n.palette):e.palette,k=n.values,M=Array.isArray(k)?(S,B)=>c(k[B%k.length]):k?(S,B)=>c(k[S]??y[B%y.length]):(S,B)=>y[B%y.length],C=new Map(h.map((S,B)=>[S,M(S,B)]));return{kind:"ordinal",column:o,domain:h,apply:S=>C.get(S)??e.muted}}let[u,p]=Mn(n.limits,$.extent(a)),d=de(e,n.values??n.scheme??e.scheme),m=n.mid,v=f=>m===void 0?(f-u)/(p-u||1):f<m?.5*((f-u)/(m-u||1)):.5+.5*((f-m)/(p-m||1)),x=f=>f>=u&&f<=p,b=f=>f===null?e.muted:n.clamp||x(f)?d(Math.max(0,Math.min(1,v(f)))):e.muted;return{kind:"continuous",column:o,domain:[u,p],type:l,interpolate:d,apply:b,ramp:f=>b(u+f*(p-u))}}function Mn(t,e){return t?[t[0]??e[0],t[1]??e[1]]:e}function Ee(t){let e=t.facet;if(!e)return{kind:"none",nrow:1,ncol:1,panels:[Gt(t,0,0,{},{})]};if(e.kind==="wrap"){let r=Xt(t,e.by),i=e.ncol??An(r.length),l=r.map((a,c)=>Gt(t,Math.floor(c/i),c%i,{[e.by]:a},{top:a}));return{kind:"wrap",nrow:Math.ceil(r.length/i),ncol:i,panels:l}}let n=e.rows?Xt(t,e.rows):[null],s=e.cols?Xt(t,e.cols):[null],o=[];return n.forEach((r,i)=>s.forEach((l,a)=>{let c={};e.rows&&(c[e.rows]=r),e.cols&&(c[e.cols]=l),o.push(Gt(t,i,a,c,{top:i===0?l:null,right:a===s.length-1?r:null}))})),{kind:"grid",nrow:n.length,ncol:s.length,panels:o}}function An(t){return t<=3?t:t<=6?Math.ceil(t/2):t<=12?Math.ceil(t/3):Math.ceil(Math.sqrt(t))}function Xt(t,e){let n=t.tables[0].columns[e];return n.levels?n.levels.filter(s=>n.values.includes(s)):[...new Set(n.values.filter(s=>s!==null).map(String))].sort(Ct)}function Gt(t,e,n,s,o){let r=t.layers.map(i=>{let l=t.tables[i.table];if(!Object.values(i.channels).some(u=>u.column))return[0];let a=Object.entries(s).filter(([u])=>u in l.columns),c=Array.from({length:l.n},(u,p)=>p);return a.length?c.filter(u=>a.every(([p,d])=>String(l.columns[p].values[u])===d)):c});return{row:e,col:n,strips:o,rows:r}}import*as E from"https://cdn.jsdelivr.net/npm/@observablehq/plot@0.6.17/+esm";import*as Y from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var Fn={solid:void 0,dashed:"6,4",dotted:"1.5,3",dashdot:"6,3,1.5,3"},D="frame",J=(t,e)=>({stroke:t.colors(e),strokeWidth:t.options.size??t.theme.line,strokeOpacity:t.options.alpha??1,strokeDasharray:Fn[t.options.dash],strokeLinejoin:"round",strokeLinecap:"round"}),ot=(t,e,n=1)=>({fill:t.colors(e),fillOpacity:t.options.alpha??n}),W=t=>t.theme.palette[0],Sn=t=>e=>[E.line(e.index,{x:e.v("x"),y:e.v("y"),z:e.groups(),curve:t,...J(e,W(e)),clip:D})],Me={line:t=>[E.line(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),sort:{channel:"x"},...J(t,W(t)),clip:D})],path:Sn("linear"),step:t=>[E.line(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),sort:{channel:"x"},curve:"step-after",...J(t,W(t)),clip:D})],point:t=>{let e={x:Cn(t),y:t.v("y"),r:t.options.size??t.theme.point,...ot(t,W(t)),clip:D};return t.options.jitter&&t.kind.x==="category"&&(e.render=Dn(t.options.jitter)),[E.dot(t.index,e)]},bar:t=>{let e={...ot(t,W(t),Ut(t,1)),clip:D};if(t.kind.x!=="category")return[E.rect(t.index,{x1:t.v("xmin"),x2:t.v("xmax"),y1:t.v("ymin"),y2:t.v("ymax"),...e})];let n=t.v("slots")[0]??1;if(n===1)return[E.barY(t.index,{x:t.v("x"),y1:t.v("ymin"),y2:t.v("ymax"),...e})];let s=t.bandwidth.x/n,o=(r,i)=>Array.isArray(r)?i.map(l=>r[l]):r;return Y.range(n).map(r=>{let i=t.index.filter(a=>t.v("slot")[a]===r),l={x:o(t.v("x"),i),y1:o(t.v("ymin"),i),y2:o(t.v("ymax"),i),fill:o(e.fill,i)};return E.barY(Y.range(i.length),{...e,...l,insetLeft:r*s+.5,insetRight:(n-1-r)*s+.5})})},hist:t=>[E.rect(t.index,{x1:t.v("xmin"),x2:t.v("xmax"),y1:t.v("ymin"),y2:t.v("ymax"),insetLeft:.5,insetRight:.5,...ot(t,W(t),Ut(t)),clip:D})],density:t=>[E.areaY(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),fill:t.colors(W(t)),fillOpacity:.15,clip:D}),E.line(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),...J(t,W(t)),clip:D})],area:t=>[E.areaY(t.index,{x:t.v("x"),y1:t.v("ymin"),y2:t.v("ymax"),z:t.groups(),...ot(t,W(t),Ut(t,.8)),clip:D})],ribbon:t=>[E.areaY(t.index,{x:t.v("x"),y1:t.v("ymin"),y2:t.v("ymax"),z:t.groups(),...ot(t,W(t),.2),clip:D})],smooth:t=>{let e=[];return t.v("ymin").some(n=>n!==null)&&e.push(E.areaY(t.index,{x:t.v("x"),y1:t.v("ymin"),y2:t.v("ymax"),z:t.groups(),fill:t.colors(t.theme.muted),fillOpacity:.15,clip:D})),e.push(E.line(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),...J(t,t.theme.accent),clip:D})),e},hline:t=>[E.ruleY(t.index,{y:t.v("y"),...J(t,t.theme.muted),strokeWidth:t.options.size??1,clip:D})],vline:t=>[E.ruleX(t.index,{x:t.v("x"),...J(t,t.theme.muted),strokeWidth:t.options.size??1,clip:D})],abline:t=>{let[e,n]=t.domain.x.map(Number),{slope:s=1,intercept:o=0}=t.options;return[E.line([0,1],{x:[e,n],y:[o+s*e,o+s*n],...J(t,t.theme.muted),strokeWidth:t.options.size??1,clip:D})]},segment:t=>[E.link(t.index,{x1:t.v("x"),y1:t.v("y"),x2:t.v("xend"),y2:t.v("yend"),...J(t,t.theme.ink),clip:D})],rect:t=>[E.rect(t.index,{x1:t.v("xmin"),x2:t.v("xmax"),y1:t.v("ymin"),y2:t.v("ymax"),...ot(t,W(t)),clip:D})],band:t=>{let e=(s,o,r)=>t.v(s)??t.index.map(()=>t.domain[o][r]),n={x1:e("xmin","x",0),x2:e("xmax","x",1),y1:e("ymin","y",0),y2:e("ymax","y",1)};return[E.rect(t.index,{...n,...ot(t,t.theme.muted,.12),clip:D})]},tile:t=>{let e=ot(t,W(t)),[n,s]=[t.kind.x==="category",t.kind.y==="category"];if(n&&s)return[E.cell(t.index,{x:t.v("x"),y:t.v("y"),...e,inset:.5,clip:D})];let[o,r]=n?[]:Dt(t.v("x")),[i,l]=s?[]:Dt(t.v("y"));return n?[E.barY(t.index,{x:t.v("x"),y1:i,y2:l,...e,clip:D})]:s?[E.barX(t.index,{y:t.v("y"),x1:o,x2:r,...e,insetTop:.5,insetBottom:.5,clip:D})]:[E.rect(t.index,{x1:o,x2:r,y1:i,y2:l,...e,clip:D})]},text:t=>[E.text(t.index,{x:t.v("x"),y:t.v("y"),text:t.v("label"),fontSize:t.options.size??t.fonts.tick,...ot(t,t.theme.ink),clip:D})],errorbar:t=>{let e={...J(t,t.theme.ink),strokeWidth:t.options.size??1.2},n=E.ruleX(t.index,{x:t.v("x"),y1:t.v("ymin"),y2:t.v("ymax"),...e,clip:D});if(t.kind.x==="category"){let i=t.bandwidth.x*.35,l=a=>E.tickY(t.index,{x:t.v("x"),y:t.v(a),...e,insetLeft:i,insetRight:i,clip:D});return[n,l("ymin"),l("ymax")]}let[s,o]=Dt(t.v("x"),.25),r=i=>E.link(t.index,{x1:s,x2:o,y1:t.v(i),y2:t.v(i),...e,clip:D});return[n,r("ymin"),r("ymax")]},box:t=>[E.boxY(t.index,{x:t.v("x"),y:t.v("y"),fill:t.colors(t.theme.strip),fillOpacity:t.options.alpha??1,stroke:t.theme.ink,strokeWidth:1,r:t.theme.point})]};function Ut(t,e=.9){return t.options.position==="overlay"?.45:e}function Dt(t,e=.5){let n=t.map(Number),s=[...new Set(n)].sort((i,l)=>i-l),o=Y.min(Y.pairs(s),([i,l])=>l-i)??1,r=t[0]instanceof Date?i=>new Date(i):i=>i;return[n.map(i=>r(i-o*e)),n.map(i=>r(i+o*e))]}function Cn(t){let e=t.v("x");if(!t.options.jitter||t.kind.x==="category")return e;let n=Y.randomUniform.source(Y.randomLcg(42))(-1,1),[s]=Dt(e,t.options.jitter);return e.map((o,r)=>+o+(+o-+s[r])*n()).map(o=>e[0]instanceof Date?new Date(o):o)}function Dn(t){return(e,n,s,o,r,i)=>{let l=Y.randomUniform.source(Y.randomLcg(42))(-1,1),a=n.scales.x?.bandwidth??20,c=Float64Array.from(s.x,u=>u+l()*a*t*.5);return i(e,n,{...s,x:c},o,r)}}import*as yt from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var zn="http://www.w3.org/2000/svg";function L(t,e,n={}){let s=t.createElementNS(zn,e);for(let[o,r]of Object.entries(n))r!=null&&s.setAttribute(o,String(r));return s}function lt(t,e,n,s="text"){let o=L(t,s,n);return o.textContent=e,o}var Ae={arial:{regular:[.278,.278,.355,.556,.556,.889,.667,.191,.333,.333,.389,.584,.278,.333,.278,.278,.556,.556,.556,.556,.556,.556,.556,.556,.556,.556,.278,.278,.584,.584,.584,.556,1.015,.667,.667,.722,.722,.667,.611,.778,.722,.278,.5,.667,.556,.833,.722,.778,.667,.778,.722,.667,.611,.722,.667,.944,.667,.667,.611,.278,.278,.278,.469,.556,.333,.556,.556,.5,.556,.556,.278,.556,.556,.222,.222,.5,.222,.833,.556,.556,.556,.556,.333,.5,.278,.556,.5,.722,.5,.5,.5,.334,.26,.334,.584],bold:[.278,.333,.474,.556,.556,.889,.722,.238,.333,.333,.389,.584,.278,.333,.278,.278,.556,.556,.556,.556,.556,.556,.556,.556,.556,.556,.333,.333,.584,.584,.584,.611,.975,.722,.722,.722,.722,.667,.611,.778,.722,.278,.556,.722,.611,.833,.722,.778,.667,.778,.722,.667,.611,.722,.667,.944,.667,.667,.611,.333,.278,.333,.584,.556,.333,.556,.611,.556,.611,.556,.333,.611,.611,.278,.278,.556,.278,.889,.611,.611,.611,.611,.389,.556,.333,.611,.556,.778,.556,.556,.5,.389,.28,.389,.584]},mplus:{regular:[.29,.363,.4,.678,.605,.847,.712,.237,.385,.385,.527,.733,.304,.457,.283,.507,.62,.62,.62,.62,.62,.62,.62,.62,.62,.62,.363,.384,.667,.753,.667,.611,.823,.693,.598,.695,.682,.587,.572,.745,.71,.317,.527,.633,.585,.857,.713,.793,.6,.785,.62,.573,.653,.683,.693,.953,.65,.67,.637,.47,.507,.47,.653,.583,.278,.548,.578,.522,.578,.552,.522,.573,.573,.307,.347,.562,.307,.805,.568,.57,.573,.573,.453,.497,.512,.558,.557,.81,.553,.557,.547,.513,.343,.513,.69],bold:[.304,.425,.478,.692,.625,.901,.753,.291,.426,.426,.536,.735,.351,.471,.338,.546,.64,.64,.64,.64,.64,.64,.64,.64,.64,.64,.418,.431,.681,.755,.681,.628,.818,.715,.62,.703,.696,.601,.586,.756,.735,.351,.558,.678,.6,.878,.735,.798,.628,.798,.651,.608,.668,.705,.715,.971,.678,.698,.651,.501,.546,.501,.695,.609,.336,.576,.606,.54,.606,.57,.543,.601,.605,.335,.378,.603,.335,.843,.6,.585,.601,.601,.485,.525,.533,.59,.581,.831,.585,.585,.568,.535,.381,.535,.705]}};var Bn=11904;function ut(t,e,n=!1,s="arial"){let o=Ae[s][n?"bold":"regular"],r=0;for(let i of String(t)){let l=i.codePointAt(0);l>=32&&l<127?r+=o[l-32]:r+=l>=Bn?1:.6}return r*e}function xt(t,e,n,s,o){if(t=String(t),ut(t,e,s,o)<=n)return t;let r=[...t];for(;r.length>1&&ut(r.join("")+"\u2026",e,s,o)>n;)r.pop();return r.join("")+"\u2026"}function _t(t,e,n,s,o,r=2){let i=String(t).split(/\s+/),l=[],a="";for(let u of i){let p=a?`${a} ${u}`:u;a&&ut(p,e,s,o)>n?(l.push(a),a=u):a=p}if(l.push(a),l.length<=r)return l;let c=l.slice(0,r);return c[r-1]=xt(l.slice(r-1).join(" "),e,n,s,o),c}var Mt=18,At=6,Q={thick:12,long:150,slices:48},$n=["line","path","step","density","smooth","hline","vline","abline","segment","errorbar"],Ln=["bar","hist","area","ribbon","rect","tile","box"];function Fe(t,e,n,{horizontal:s,maxWidth:o,maxHeight:r}){if(e.kind==="none"||t.theme.legend==="none")return null;let i=t.theme.metrics,l=(g,h,y)=>ut(g,h,y,i),a=t.labels.color===null?null:t.labels.color??e.column,c=a?n.legend*1.8:0,u=a?l(a,n.legend+1,!0):0;if(e.kind==="continuous"){let g=ft(e.type==="time"?"time":"linear",e.domain,4),h=g.major.map(g.format),y=yt.max(h,S=>l(S,n.legend))??0,k=Math.min(Q.long,s?o:r-c-4),[M,C]=s?[k,Q.thick+n.legend*1.6]:[Q.thick+At+y,k];return{kind:"ramp",title:a,titleH:c,color:e,long:k,ticks:g.major,labels:h,width:Math.max(u,M),height:c+C,horizontal:s}}let p=t.layers.filter(g=>g.channels.color?.column),d=p.some(g=>Ln.includes(g.type))?"square":p.some(g=>$n.includes(g.type))?"line":"point",m=Math.round(n.legend*1.75),v=Math.max(80,(s?o:220)-Mt-At),x=e.domain.map(g=>{let h=xt(g,n.legend,v,!1,i);return{value:g,label:h,color:e.apply(g),w:Mt+At+l(h,n.legend)}});if(!s){let g=Math.max(1,Math.floor((r-c)/m)),h=yt.range(Math.ceil(x.length/g)).map(M=>x.slice(M*g,(M+1)*g)),y=0;for(let M of h)M.forEach((C,S)=>Object.assign(C,{x:y,y:c+S*m})),y+=(yt.max(M,C=>C.w)??0)+n.legend;let k=Math.min(x.length,g);return{kind:"swatches",title:a,titleH:c,key:d,rowH:m,items:x,width:Math.max(u,y-n.legend),height:c+k*m,horizontal:s}}let b=0,w=c;for(let g of x)b>0&&b+g.w>o&&([b,w]=[0,w+m]),Object.assign(g,{x:b,y:w}),b+=g.w+n.legend*1.5;let f=Math.max(u,yt.max(x,g=>g.x+g.w)??0);return{kind:"swatches",title:a,titleH:c,key:d,rowH:m,items:x,width:f,height:w+m,horizontal:s}}function Se(t,e,n,s,o=new Set){let r=L(t,"g",{class:"pt-legend","font-size":s.legend});return e.title&&r.append(lt(t,e.title,{y:s.legend,"font-weight":"bold","font-size":s.legend+1,fill:n.ink})),e.kind==="ramp"?Pn(t,r,e,n,s):e.items.forEach((i,l)=>r.append(On(t,e,i,l,n,o.has(i.value)))),r}function On(t,e,n,s,o,r){let i=e.rowH/2,l=L(t,"g",{class:"pt-key","data-index":s,transform:`translate(${n.x},${n.y})`,opacity:r?.35:1}),a=L(t,"rect",{width:n.w,height:e.rowH,fill:"transparent"}),c=e.key==="line"?L(t,"line",{x1:1,x2:Mt-1,y1:i,y2:i,stroke:n.color,"stroke-width":Math.max(2.5,o.line+1)}):e.key==="point"?L(t,"circle",{cx:Mt/2,cy:i,r:Math.max(3.5,o.point+1),fill:n.color}):L(t,"rect",{x:3,y:i-6,width:12,height:12,fill:n.color}),u=lt(t,n.label,{x:Mt+At,y:i,dy:"0.35em",fill:o.muted,"text-decoration":r?"line-through":null});return l.append(a,c,u),l}function Pn(t,e,n,s,o){let{color:r,horizontal:i,long:l}=n,[a,c]=r.domain.map(Number),u=d=>(Number(d)-a)/(c-a||1),p=n.titleH;for(let d=0;d<Q.slices;d++){let m=d/Q.slices,v=l/Q.slices+.5,x=r.ramp(i?m:1-m),b=i?{x:m*l,y:p,width:v,height:Q.thick}:{x:0,y:p+m*l,width:Q.thick,height:v};e.append(L(t,"rect",{...b,fill:x}))}n.ticks.forEach((d,m)=>{let v=u(d)*l,x=i?{x:v,y:p+Q.thick+o.legend*1.2,"text-anchor":"middle"}:{x:Q.thick+At,y:p+l-v,dy:"0.35em"};e.append(lt(t,n.labels[m],{...x,fill:s.muted}))})}import*as U from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var pt={size:4,padding:3},Tn=40,jn=.22;function Ce({ns:t,grid:e,kind:n,home:s,legend:o,fonts:r,W:i,H:l}){let a=t.theme,c=a.metrics,u=(F,I,st)=>ut(F,I,st,c),p=r.base,d=Math.round(p*.9),m=Math.round(p*.8),{title:v,subtitle:x,caption:b,x:w,y:f}=t.labels,g=i-2*d-Math.min(180,i*jn),h=v?_t(v,r.title,g,!0,c):[],y=x?_t(x,r.subtitle,g,!1,c):[],k=h.length*r.title*1.25+y.length*r.subtitle*1.4,M=d+k+(k?p*.7:0),C=w?r.axisTitle*1.7:0,S=f?r.axisTitle*1.7:0,B=b?r.tick*1.8:0,j=o&&!o.horizontal?o.width+p*1.5:0,q=o?.horizontal?o.height+p*.8:0,z={x:d+S,y:M,w:i-2*d-S-j,h:l-M-d-C-q-B},tt=e.kind==="none"?0:Math.round(r.strip*2),et=e.kind==="wrap"?tt:0,R=e.kind==="grid"&&t.facet.cols?tt+2:0,T=e.kind==="grid"&&t.facet.rows?tt+2:0,ee=t.facet?.free??{x:!1,y:!1},cn=e.panels.length,ne=F=>ee.y||F.col===0,Lt=(F,I)=>ee.x||(e.kind==="wrap"?I+e.ncol>=cn:F.row===e.nrow-1),X=z.w/e.ncol,K=z.h/e.nrow,at,nt,Ot,wt;for(let F=0;F<2;F++){Ot={x:Math.max(2,X/(n.x==="time"?110:75)),y:Math.max(2,K/45)},at=Array(e.ncol).fill(0),nt=Array(e.nrow).fill(0),wt=!1;let I=0;e.panels.forEach((G,it)=>{if(ne(G)){let ct=ft(n.y,s[it].y,Ot.y,t.scales.y?.format),mt=U.max(ct.major,Nt=>u(ct.format(Nt),r.tick))??0;at[G.col]=Math.max(at[G.col],Math.ceil(mt+pt.size+pt.padding+3))}if(n.x==="category"&&Lt(G,it)){let ct=s[it].x,mt=U.max(ct,Nt=>u(Nt,r.tick))??0;I=Math.max(I,mt),mt>X/(ct.length+.2)*.95&&(wt=!0)}});let st=wt?Math.min(I,K*.6)*Math.sin(Tn*Math.PI/180)+r.tick:r.tick*1.2;e.panels.forEach((G,it)=>{Lt(G,it)&&(nt[G.row]=Math.max(nt[G.row],Math.ceil(st+pt.size+pt.padding+3)))}),X=(z.w-U.sum(at)-m*(e.ncol-1)-T)/e.ncol,K=(z.h-U.sum(nt)-e.nrow*et-R-m*(e.nrow-1))/e.nrow}X=Math.max(20,X),K=Math.max(20,K);let un=U.cumsum([z.x,...at.slice(0,-1).map(F=>F+X+m)]),pn=U.cumsum([z.y+R,...nt.slice(0,-1).map(F=>et+K+F+m)]),St=e.panels.map((F,I)=>({x:un[F.col],y:pn[F.row]+et,w:at[F.col]+X,h:K+nt[F.row],ml:at[F.col],mb:nt[F.row],innerW:X,innerH:K,count:Ot,rotateX:wt,showX:Lt(F,I),showY:ne(F)})),Pt=[];e.panels.forEach((F,I)=>{let st=St[I],G=st.x+st.ml,it=(ct,mt)=>xt(ct,r.strip,mt-8,!0,c);F.strips.top!=null&&Pt.push({x:G,y:st.y-et-R,w:X,h:tt,text:it(F.strips.top,X),full:F.strips.top}),F.strips.right!=null&&Pt.push({x:G+X+2,y:st.y,w:tt,h:K,text:it(F.strips.right,K),full:F.strips.right,vertical:!0})});let Tt=St[0],oe=St.find((F,I)=>e.panels[I].col===e.ncol-1)??Tt,vt=Tt.x+Tt.ml,re=oe.x+oe.w,dn=z.y+z.h,dt=[],jt=d;for(let F of h)dt.push({text:F,attrs:{x:vt,y:jt+=r.title*1.05,"font-size":r.title,"font-weight":"bold",fill:a.ink,"text-anchor":"start"}}),jt+=r.title*.2;for(let F of y)dt.push({text:F,attrs:{x:vt,y:jt+=r.subtitle*1.3,"font-size":r.subtitle,fill:a.muted,"text-anchor":"start"}});if(w&&dt.push({text:w,attrs:{x:(vt+re)/2,y:dn+r.axisTitle*1.35,"text-anchor":"middle","font-size":r.axisTitle,fill:a.muted}}),f){let F=z.y+(z.h-U.sum(nt))/2;dt.push({text:f,attrs:{transform:`translate(${d+r.axisTitle*.85},${F}) rotate(-90)`,"text-anchor":"middle","font-size":r.axisTitle,fill:a.muted}})}b&&dt.push({text:xt(b,r.tick,i-2*d,!1,c),attrs:{x:vt,y:l-d-(q||0)+r.tick*.2,"font-size":r.tick,fill:a.muted,"text-anchor":"start"}});let mn=o?o.horizontal?{x:Math.max(d,(vt+re-o.width)/2),y:l-d-o.height}:{x:i-d-o.width,y:z.y+Math.max(0,(z.h-U.sum(nt)-o.height)/2)}:null;return{panels:St,strips:Pt,texts:dt,legend:mn,area:z,rotateX:wt}}function De(t,e={}){if(typeof t?.spec=="function"&&(t=t.spec()),t?.version!==1)throw new Error("plotto: unknown spec version");let n=pe({...t.theme,...e}),s=t.data.map(Nn),o=t.layers.map(l=>Hn(l,t.mapping??{},s,n));if(!o.length)throw new Error("plotto: the plot has no layers. Add one, for example .line() or .point()");let r=qn(t.facet),i={...Rn(o),...t.labels};return{tables:s,layers:o,facet:r,scales:t.scales??{},labels:i,theme:n}}function Nn({columns:t}){let e=Object.keys(t),n=e.length?t[e[0]].values.length:1;return{columns:t,n}}function Hn(t,e,n,s){let o=N.layers[t.type];if(!o)throw new Error(`plotto: unknown layer type "${t.type}". Valid: ${Object.keys(N.layers).join(", ")}`);let r=t.data??0,i=n[r].columns,l={};for(let u of o.channels)t.mapping?.[u]!==void 0?l[u]={column:t.mapping[u]}:t.set?.[u]!==void 0?l[u]={value:t.set[u]}:o.inherit!==!1&&e[u]in i&&(l[u]={column:e[u]});let a=o.requires.filter(u=>!l[u]);if(a.length)throw new Error(`${t.type}(): set ${a.join(" and ")}, as a column name or a value`);if(l.color&&"value"in l.color){let u=ht(s,l.color.value);if(!u)throw new Error(`${t.type}(): "${l.color.value}" is not a column or a color. Theme colors: ${me(s).join(", ")}`);l.color={value:u}}let c={};for(let u of o.options)t.set?.[u]!==void 0&&(c[u]=t.set[u]);return{type:t.type,table:r,channels:l,options:c}}function qn(t){if(!t)return null;let e={x:["x","both"].includes(t.free),y:["y","both"].includes(t.free)};return t.wrap?{kind:"wrap",by:t.wrap,ncol:t.ncol??null,free:e}:{kind:"grid",rows:t.rows??null,cols:t.cols??null,free:e}}function Rn(t){let e=o=>{for(let r of t)for(let i of o)if(r.channels[i]?.column)return r.channels[i].column},n=t.find(o=>o.type==="hist"||o.type==="density"),s=e(["y","ymin","yend"])??(n?n.type==="density"||n.options.density?"density":"count":void 0);return{x:e(["x","xmin","xend"]),y:s,color:e(["color"])}}import*as A from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var zt=80;function Ft(t,e,n){let s=new Map;for(let o=0;o<n;o++){let r=e.map(l=>t[l]?.[o]??null),i=JSON.stringify(r);s.has(i)||s.set(i,{key:r,idx:[]}),s.get(i).idx.push(o)}return[...s.values()]}function ze(t,e,n){let s={mean:A.mean,median:A.median,min:A.min,max:A.max,sum:A.sum}[n],o={x:[],y:[],color:[],group:[]};for(let{key:r,idx:i}of Ft(t,["x","color","group"],e))r[0]!==null&&(o.x.push(r[0]),o.y.push(s(i,l=>t.y[l])),o.color.push(r[1]),o.group.push(r[2]));return o}function Be(t,e,n,s){let o=l=>t.color?s.indexOf(t.color[l]):0,r=t.color?s.filter(l=>t.color.includes(l)):[null],i={...t,ymin:new Array(e),ymax:new Array(e),value:t.y.slice(),slot:new Array(e),slots:new Array(e)};for(let{idx:l}of Ft(t,n==="dodge"?["x","color"]:["x"],e)){l.sort((u,p)=>o(u)-o(p));let a=0,c=0;l.forEach((u,p)=>{let d=t.y[u]??0;if(n!=="overlay"){let m=d>=0?a:c;[i.ymin[u],i.ymax[u]]=[m,m+d],d>=0?a+=d:c+=d}else[i.ymin[u],i.ymax[u]]=[0,d];i.slot[u]=n==="dodge"&&t.color?r.indexOf(t.color[u]):0,i.slots[u]=n==="dodge"?r.length:1})}return i.y=i.ymax,i}function $e(t,e){let n=[...new Set(t.x.filter(l=>l!==null))].sort((l,a)=>l-a),o=(A.min(A.pairs(n),([l,a])=>a-l)??1)*.9,r=[],i=[];for(let l=0;l<e;l++){let a=o/t.slots[l];r.push(t.x[l]-o/2+t.slot[l]*a),i.push(t.x[l]-o/2+(t.slot[l]+1)*a)}return{...t,xmin:r,xmax:i}}function Le(t,e){let n=t.filter(i=>i!==null&&Number.isFinite(i)),[s,o]=A.extent(n);if(s===void 0)return[0,1];if(s===o)return[s-.5,o+.5];let r=A.ticks(...A.nice(s,o,e),e);return r[0]>s&&r.unshift(r[0]-(r[1]-r[0])),r.at(-1)<o&&r.push(r.at(-1)+(r[1]-r[0])),r}function Oe(t,e,n,s){let o={x:[],xmin:[],xmax:[],y:[],color:[]},r=A.bin().domain([n[0],n.at(-1)]).thresholds(n.slice(1,-1));for(let{key:i,idx:l}of Ft(t,["color"],e)){let a=l.map(c=>t.x[c]).filter(c=>c!==null&&Number.isFinite(c));for(let c of r(a)){let u=c.length;o.x.push((c.x0+c.x1)/2),o.xmin.push(c.x0),o.xmax.push(c.x1),o.y.push(s?u/(a.length*(c.x1-c.x0)||1):u),o.color.push(i[0])}}return o}function Pe(t,e){let n={x:[],y:[],color:[],group:[]};for(let{key:s,idx:o}of Ft(t,["color"],e)){let r=o.map(p=>t.x[p]).filter(p=>p!==null&&Number.isFinite(p));if(r.length<2)continue;let i=A.deviation(r),l=A.quantile(r,.75)-A.quantile(r,.25),a=.9*Math.min(i,l/1.34||i)*r.length**-.2||1,[c,u]=A.extent(r);for(let p of A.range(zt).map(d=>c-3*a+(u-c+6*a)*d/(zt-1))){let d=A.sum(r,m=>Math.exp(-.5*((p-m)/a)**2))/(r.length*a*Math.sqrt(2*Math.PI));n.x.push(p),n.y.push(d),n.color.push(s[0]),n.group.push(s[0])}}return n}function Te(t,e,{method:n="lm",span:s=.75,band:o=!0}){let r={x:[],y:[],ymin:[],ymax:[],color:[],group:[]};for(let{key:i,idx:l}of Ft(t,["color"],e)){let a=l.map(m=>[t.x[m],t.y[m]]).filter(([m,v])=>m!==null&&v!==null&&Number.isFinite(m)&&Number.isFinite(v));if(a.length<3)continue;a.sort((m,v)=>m[0]-v[0]);let[c,u]=[a[0][0],a.at(-1)[0]],p=A.range(zt).map(m=>c+(u-c)*m/(zt-1));(n==="loess"?Yn(a,p,s):In(a,p)).forEach(({x:m,y:v,se:x})=>{let b=Wn(a.length-2);r.x.push(m),r.y.push(v),r.ymin.push(o&&x!==void 0?v-b*x:null),r.ymax.push(o&&x!==void 0?v+b*x:null),r.color.push(i[0]),r.group.push(i[0])})}return r}function In(t,e){let n=t.length,s=A.mean(t,c=>c[0]),o=A.mean(t,c=>c[1]),r=A.sum(t,c=>(c[0]-s)**2)||1,i=A.sum(t,c=>(c[0]-s)*(c[1]-o))/r,l=o-i*s,a=Math.sqrt(A.sum(t,c=>(c[1]-l-i*c[0])**2)/Math.max(1,n-2));return e.map(c=>({x:c,y:l+i*c,se:a*Math.sqrt(1/n+(c-s)**2/r)}))}function Yn(t,e,n){let s=Math.max(3,Math.ceil(n*t.length));return e.map(o=>{let r=t.map(([x,b])=>[Math.abs(x-o),x,b]).sort((x,b)=>x[0]-b[0]).slice(0,s),i=r.at(-1)[0]||1,[l,a,c,u,p]=[0,0,0,0,0];for(let[x,b,w]of r){let f=(1-(x/i)**3)**3;l+=f,a+=f*b,c+=f*w,u+=f*b*b,p+=f*b*w}let d=l*u-a*a,m=Math.abs(d)<1e-12?0:(l*p-a*c)/d,v=(c-m*a)/l;return{x:o,y:v+m*o}})}function Wn(t){let e=[12.71,4.3,3.18,2.78,2.57,2.45,2.36,2.31,2.26,2.23,2.2,2.18,2.16,2.14,2.13,2.12,2.11,2.1,2.09,2.09];return t<1?NaN:t<=e.length?e[t-1]:t<=30?2.05:t<=60?2:1.96}function je(t){return t.layers.map(e=>e.type!=="hist"||!e.channels.x.column?null:Le(t.tables[e.table].columns[e.channels.x.column].values,e.options.bins??30))}function Kt(t,e,n,s){let{ns:o,kind:r,colorLevels:i,edges:l}=t;if(s.size&&e.channels.color?.column){let b=o.tables[e.table].columns[e.channels.color.column].values;n=n.filter(w=>!s.has(b[w]))}let a={};for(let b of Object.keys(e.channels))a[b]=ge(o,e,b,n);let c=n.length,u=e.options,p=(b,w,f)=>Be(b,w,f,i),d=b=>b.x?.length??0,m=a,v=n;if(u.summary&&(e.type==="line"||e.type==="point"))m=ze(a,c,u.summary);else if(e.type==="bar")m=p(a,c,u.position??"stack"),r.x!=="category"&&(m=$e(m,c));else if(e.type==="area")m=p(a,c,u.position??"stack");else if(e.type==="hist"){let b=Oe(a,c,l[o.layers.indexOf(e)],u.density);m=p(b,d(b),u.position??"stack")}else e.type==="density"?m=Pe(a,c):e.type==="smooth"&&(m=Te(a,c,u));m!==a&&(v=null);let x={cols:m,n:m===a?c:d(m),rows:v};return x.hover=Vn(o,e,x),x}function Vn(t,e,{cols:n,rows:s}){let o=t.labels.x||e.channels.x?.column||"x",r=t.labels.y||e.channels.y?.column||"y",i=(c,u,p,d)=>({label:c,axis:u,values:p,values2:d}),l=i(o,"x",n.x),a=e.channels.tooltip?.column&&s?[i(e.channels.tooltip.column,null,n.tooltip)]:[];switch(e.type){case"line":case"path":case"step":case"point":return{hx:n.x,hy:n.y,fields:[l,i(r,"y",n.y),...a]};case"bar":case"area":return{hx:n.x,hy:n.ymax,fields:[l,i(r,"y",n.value),...a]};case"hist":return{hx:n.x,hy:n.ymax,fields:[i(o,"x",n.xmin,n.xmax),i(e.options.density?"density":"count",null,n.value)]};case"density":return{hx:n.x,hy:n.y,fields:[l,i("density",null,n.y)]};case"smooth":{let c=n.ymin.some(u=>u!==null)?[i("95% CI","y",n.ymin,n.ymax)]:[];return{hx:n.x,hy:n.y,fields:[l,i(r,"y",n.y),...c]}}case"ribbon":return{hx:n.x,hy:n.ymax,fields:[l,i(r,"y",n.ymin,n.ymax)]};case"errorbar":return{hx:n.x,hy:n.ymax,fields:[l,i(r,"y",n.ymin,n.ymax)]};case"tile":{let c=e.channels.color?.column?[i(t.labels.color??"value",null,n.color)]:[];return{hx:n.x,hy:n.y,fields:[l,i(r,"y",n.y),...c,...a],tile:!0}}case"box":return{hx:n.x,hy:n.y,fields:[l,i(r,"y",n.y)]};default:return null}}var Xn=560,Gn=240;function Zt(t,{document:e=globalThis.document,width:n,domains:s,hidden:o=new Set}={}){let r=De(t),i=r.theme,l=Math.round(n??i.width),c=n&&i.reflow&&!i.fixedHeight?Math.max(Gn,Math.round(l*i.height/i.width)):i.height;i.legend==="right"&&l<Xn&&(i.legend="bottom");let u=fe(i),p=Ee(r),d={x:Vt(r,"x"),y:Vt(r,"y")},m=ke(r),v={ns:r,kind:d,colorLevels:m.domain??[],edges:je(r)};for(let y of p.panels)y.views=r.layers.map((k,M)=>Kt(v,k,y.rows[M],new Set));let x=Kn(r,p,d),b=i.legend==="bottom",w=Fe(r,m,u,{horizontal:b,maxWidth:l*.9,maxHeight:c*.8}),f=Ce({ns:r,grid:p,kind:d,home:x,legend:w,fonts:u,W:l,H:c}),g=L(e,"svg",{xmlns:"http://www.w3.org/2000/svg",width:l,height:c,viewBox:`0 0 ${l} ${c}`,"font-family":i.font,"font-size":u.base,style:`color:${i.ink}`});g.append(L(e,"rect",{width:l,height:c,fill:i.background}));for(let y of f.texts)g.append(lt(e,y.text,y.attrs));for(let y of f.strips)g.append(Jn(e,y,i,u));let h={spec:t,ns:r,doc:e,svg:g,theme:i,fonts:u,grid:p,kind:d,color:m,ctx:v,legend:w,layout:f,home:x,W:l,H:c};return h.domains=s??x,h.hidden=o,h.panelLayer=g.appendChild(L(e,"g",{class:"pt-panels"})),w&&(h.legendG=g.appendChild(Re(h))),rt(h),h}function qe(t,e){return Zt(t,e).svg.outerHTML}function rt(t){let{ns:e,grid:n,ctx:s,hidden:o}=t;if(o.size||t.filtered){for(let r of n.panels)r.views=e.layers.map((i,l)=>Kt(s,i,r.rows[l],o));t.filtered=o.size>0}t.panelLayer.replaceChildren(),t.panels=n.panels.map((r,i)=>Un(t,r,i)),t.legendG&&t.legendG.replaceWith(t.legendG=Re(t))}function Re(t){let e=Se(t.doc,t.legend,t.theme,t.fonts,t.hidden);return e.setAttribute("transform",`translate(${t.layout.legend.x},${t.layout.legend.y})`),e}function Un(t,e,n){let{ns:s,doc:o,theme:r,fonts:i,kind:l,color:a}=t,c=t.layout.panels[n],u={x:Ne(l.x,t.domains[n].x),y:Ne(l.y,t.domains[n].y)},p={x:l.x==="category"?c.innerW/(u.x.length+.2)*.8:0},d=s.layers.map((y,k)=>{let M=e.views[k],C=_n({view:M,layer:y,kind:l,color:a,theme:r,fonts:i,domain:u,bandwidth:p});return{layer:y,view:M,c:C,marks:M.n?Me[y.type](C):[]}}),m=y=>{let k=ft(l[y],t.domains[n][y],c.count[y],s.scales[y]?.format),M=C=>l[y]==="category"||+C>=+u[y][0]&&+C<=+u[y][1];return{major:k.major.filter(M),minor:k.minor,format:k.format}},v=m("x"),x=m("y"),b=y=>({stroke:y?r.gridMinor:r.grid,strokeOpacity:1,strokeWidth:y?.6:.9}),w={tickSize:pt.size,tickPadding:pt.padding,fontSize:i.tick,stroke:r.tick,fill:r.muted,label:null},f=[];if(l.x!=="category"&&f.push(V.gridX(v.minor,b(!0)),V.gridX(v.major,b(!1))),l.y!=="category"&&f.push(V.gridY(x.minor,b(!0)),V.gridY(x.major,b(!1))),f.push(...d.flatMap(y=>y.marks)),c.showX){let y=c.rotateX?{tickRotate:-40,textAnchor:"end"}:{};f.push(V.axisX(v.major,{...w,...y,anchor:"bottom",tickFormat:v.format}))}c.showY&&f.push(V.axisY(x.major,{...w,anchor:"left",tickFormat:x.format}));let g=V.plot({document:o,width:c.w,height:c.h,marginLeft:c.ml,marginRight:0,marginTop:0,marginBottom:c.mb,x:He(l.x,u.x),y:He(l.y,u.y),color:{type:"identity"},marks:f}),h=L(o,"g",{class:"pt-panel","data-panel":n,transform:`translate(${c.x},${c.y})`,fill:"currentColor","text-anchor":"middle"});for(let y of[...g.childNodes])y.nodeName.toLowerCase()!=="style"&&h.append(y);return t.panelLayer.append(h),{g:h,plot:g,box:c,layers:d}}function _n({view:t,layer:e,kind:n,color:s,theme:o,fonts:r,domain:i,bandwidth:l}){let a=d=>Et.x.includes(d)?"x":Et.y.includes(d)?"y":null,c={},u=d=>{if(d in c)return c[d];let m=t.cols[d];return m&&n[a(d)]==="time"&&(m=m.map(v=>v===null?null:new Date(v))),c[d]=m},p=e.channels.color;return{index:Bt.range(t.n),v:u,options:e.options,colors:d=>p?"value"in p?p.value:u("color").map(s.apply):d,groups:()=>u("group")??(p?.column?u("color"):void 0),kind:n,theme:o,fonts:r,domain:i,bandwidth:l}}function Ne(t,e){return t==="time"?e.map(n=>new Date(n)):e}function He(t,e){return{type:{linear:"linear",log:"log",time:"utc",category:"band"}[t],domain:e,axis:null,...t==="category"?{padding:.2,round:!1}:{}}}function Kn(t,e,n){let s=t.facet?.free??{x:!1,y:!1},o=(i,l,a)=>s[i]?e.kind==="grid"?i==="x"?`c${l.col}`:`r${l.row}`:`p${a}`:"all",r=e.panels.map(()=>({}));for(let i of["x","y"]){let l=Bt.group(e.panels.map((a,c)=>[a,c]),([a,c])=>o(i,a,c));for(let a of l.values()){let c=Zn(t,i,n[i],a.map(([u])=>u));for(let[,u]of a)r[u][i]=c}}return r}function Zn(t,e,n,s){let o=t.scales[e]?.limits;if(o&&(n==="category"||o.every(i=>i!==null)))return o;let r=be(t,e,n,s);return o?[o[0]??r[0],o[1]??r[1]]:r}function Jn(t,e,n,s){let o=L(t,"g",{class:"pt-strip"});o.append(L(t,"rect",{x:e.x,y:e.y,width:e.w,height:e.h,fill:n.strip}));let r=e.vertical?{transform:`translate(${e.x+e.w/2},${e.y+e.h/2}) rotate(90)`,dy:"0.35em"}:{x:e.x+e.w/2,y:e.y+e.h/2,dy:"0.35em"},i=lt(t,e.text,{...r,"text-anchor":"middle","font-weight":"bold","font-size":s.strip,fill:n.ink});return e.text!==String(e.full)&&i.append(lt(t,e.full,{},"title")),o.append(i),o}async function Ie(t){let e=Ve(t);try{return await navigator.clipboard.write([new ClipboardItem({"image/png":e.then(Qn)})]),"Copied"}catch{return Jt((await e).toDataURL("image/png"),"plot.png"),"Downloaded"}}async function Ye(t){Jt((await Ve(t)).toDataURL("image/png"),"plot.png")}function We(t){Jt(Xe(t),"plot.svg")}async function Ve(t){let e=new Image;e.src=Xe(t),await e.decode();let{width:n,height:s}=t.viewBox.baseVal,o=document.createElement("canvas");return o.width=n*2,o.height=s*2,o.getContext("2d").drawImage(e,0,0,o.width,o.height),o}function Xe(t){let e=t.cloneNode(!0);e.querySelector(".pt-overlay")?.remove();let{width:n,height:s}=t.viewBox.baseVal;e.setAttribute("width",n),e.setAttribute("height",s);let o=new TextEncoder().encode(new XMLSerializer().serializeToString(e)),r="";for(let i of o)r+=String.fromCharCode(i);return`data:image/svg+xml;base64,${btoa(r)}`}var Qn=t=>new Promise(e=>t.toBlob(e,"image/png"));function Jt(t,e){let n=document.createElement("a");n.href=t,n.download=e,n.click()}import*as P from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var _e=40,to=10,eo=6,Ke=4,no=6,oo=["line","step","area","density","smooth","ribbon"],ro=["bar","hist","tile","box"],so=["point","path","errorbar"];function Ze(t,e,n,s,o){let r=t.panels[e],i=r.plot.scale("x"),l=r.plot.scale("y"),u={state:t,sx:i,sy:l,px:x=>i.apply(x)+(i.bandwidth??0)/2,py:x=>l.apply(x)+(l.bandwidth??0)/2},p=uo(u,r,n);if(p)return{...p,panel:e};let d=lo(u,r,n,s,o?.panel===e?o:null);if(d&&d.d<=to)return{...Ge(u,d),panel:e};let m=ao(u,r,n,s,o?.panel===e?o:null);if(m)return{...m,panel:e};let v=po(u,r,n,s);return v?{...v,panel:e}:d?{...Ge(u,d),panel:e}:null}function bt(t,e,n,s,o){let r=e.channels.color;return r?"value"in r?r.value:t.color.apply(n.cols.color[o]):e.type==="smooth"?t.theme.accent:t.theme.palette[0]}function _(t,e,n){return n==null||Number.isNaN(n)?"\u2013":e&&t.kind[e]==="time"?io(t,e)(n):e&&t.kind[e]==="category"?String(n):typeof n=="number"?ve.number(n):String(n)}function io(t,e){if(t.timeFormats??={},t.timeFormats[e])return t.timeFormats[e];let n=t.grid.panels.flatMap(r=>r.views.flatMap(i=>i.cols[e]??[])).filter(r=>r!==null),s=r=>n.every(i=>r(new Date(i))),o=s(r=>r.getUTCDate()===1&&r.getUTCHours()===0&&r.getUTCMinutes()===0)?"%Y-%m":s(r=>r.getUTCHours()===0&&r.getUTCMinutes()===0)?"%Y-%m-%d":s(r=>r.getUTCSeconds()===0)?"%m-%d %H:%M":"%m-%d %H:%M:%S";return t.timeFormats[e]=P.utcFormat(o)}function gt(t,e,n){return e.values2?`${_(t,e.axis,e.values[n])} \u2013 ${_(t,e.axis,e.values2[n])}`:_(t,e.axis,e.values[n])}function lo({px:t,py:e},n,s,o,r){let i=null,l=null;for(let{layer:a,view:c,c:u}of n.layers){if(!so.includes(a.type)||!c.hover||!c.n)continue;let{hx:p,hy:d}=c.hover;for(let m=0;m<c.n;m++){if(p[m]===null||d[m]===null)continue;let v=Math.hypot(t(p[m])-s,e(d[m])-o);if(v>_e)continue;let x={layer:a,view:c,c:u,k:m,d:v,x:t(p[m]),y:e(d[m])};(!i||v<i.d)&&(i=x),r?.layer===a&&r.k===m&&(l=x)}}return l&&i&&i.d>l.d-Ke?l:i}function Ge({state:t},{layer:e,view:n,c:s,k:o,x:r,y:i,d:l}){let a=bt(t,e,n,s,o),c=e.channels.color?.column?_(t,null,n.cols.color[o]):null,u=n.hover.fields.map(p=>({label:p.label,value:gt(t,p,o)})).filter(p=>p.value!==c);return{layer:e,k:o,d:l,color:a,header:c,rows:u,marks:[{x:r,y:i,color:a}],anchor:{x:r,y:i}}}function ao({state:t,px:e,py:n},s,o,r,i){let l=[];for(let{layer:h,view:y,c:k}of s.layers){if(!oo.includes(h.type)||!y.hover||!y.n)continue;let{hx:M,hy:C}=y.hover,S=k.groups()??[],B=new Map;for(let j=0;j<y.n;j++){if(M[j]===null||C[j]===null)continue;let q=Math.abs(e(M[j])-o),z=S[j]??"";q<=_e&&(!B.has(z)||q<B.get(z).dx)&&B.set(z,{layer:h,view:y,c:k,k:j,dx:q,series:z})}l.push(...B.values())}if(!l.length)return null;let a=P.least(l,h=>h.dx),c=e(a.view.hover.hx[a.k]),u=l.filter(h=>Math.abs(e(h.view.hover.hx[h.k])-c)<=eo);for(let h of u)h.y=n(h.view.hover.hy[h.k]);let p=P.least(u,h=>Math.abs(h.y-r)),d=i?.series!==void 0&&u.find(h=>h.layer===i.layer&&h.series===i.series);d&&Math.abs(d.y-r)<Math.abs(p.y-r)+Ke&&(p=d);let m=h=>h.layer.channels.color?.column?_(t,null,h.view.cols.color[h.k]):h.series!==""?String(h.series):h.view.hover.fields[1]?.label??h.layer.type,v=h=>bt(t,h.layer,h.view,h.c,h.k),x=a.view.hover.fields[0],b=_(t,"x",a.view.hover.hx[a.k]),w={crosshair:c,anchor:{x:c,y:r},layer:p.layer,series:p.series};if(u.length===1||u.length>no){let h=[{label:x?.label??"x",value:b},{label:p.view.hover.fields[1]?.label??"y",value:Ue(t,p.layer,p.view,p.k)}],y=u.length-1;return{...w,color:v(p),header:m(p),rows:h,note:y?`${y} other series at this x`:null,marks:[{x:c,y:p.y,color:v(p)}]}}let f=co(t);u.sort((h,y)=>f(h)-f(y)||h.y-y.y);let g=u.map(h=>({swatch:v(h),label:m(h),value:Ue(t,h.layer,h.view,h.k),strong:h===p}));return{...w,color:t.theme.ink,header:x?`${x.label} ${b}`:b,rows:g,marks:u.map(h=>({x:c,y:h.y,color:v(h)}))}}function co(t){let{color:e}=t;return n=>{let s=n.layer.channels.color?.column?n.view.cols.color[n.k]:null;return s===null?t.ns.layers.indexOf(n.layer):e.kind==="ordinal"?e.domain.indexOf(s):typeof s=="number"?s:0}}function Ue(t,e,n,s){let o=n.hover.fields;return e.type==="smooth"&&o[2]?`${gt(t,o[1],s)} (${gt(t,o[2],s)})`:gt(t,o[1],s)}function uo(t,e,n){for(let{layer:s,view:o,c:r}of e.layers)if(s.type==="box"&&o.n)return ho(t,s,o,r,n);return null}function po(t,e,n,s){let{state:o,sx:r,sy:i}=t;for(let{layer:l,view:a,c}of e.layers){if(!ro.includes(l.type)||l.type==="box"||!a.n)continue;let u=l.type==="tile",p=null;for(let x=0;x<a.n;x++){let[b,w]=fo(l,a,x,r),f=Math.abs((b+w)/2-n);if(u?n<b-Qt(r,w-b)||n>w+Qt(r,w-b):f>w-b)continue;let[g,h]=xo(l,a,x,i),[y,k]=[Math.min(g,h),Math.max(g,h)],M=u?Qt(i,k-y):0,C=s>=y-M&&s<=k+M;if(u&&!C)continue;let S=Math.round(f)*1e6+(C?0:1e5+y);(!p||S<p.score)&&(p={k:x,score:S,rect:{x:b,y,width:w-b,height:k-y}})}if(!p)continue;let{k:d,rect:m}=p,v=bt(o,l,a,c,d);if(u){let x=o.ns.labels.color??l.channels.color?.column??"value",b=l.channels.color?.column?_(o,null,a.cols.color[d]):null,w=a.hover.fields.filter(f=>f.label!==x).map(f=>({label:f.label,value:gt(o,f,d)}));return{color:v,header:b!==null?`${x} ${b}`:null,rows:w,marks:[{rect:m,color:o.theme.ink}],anchor:{x:m.x+m.width,y:s}}}return mo(o,l,a,c,d,m)}return null}function Qt(t,e){return t.bandwidth!==void 0?(t.step-t.bandwidth)/2||e*.125:.5}function mo(t,e,n,s,o,r){let i=e.type==="hist"?d=>n.cols.xmin[d]===n.cols.xmin[o]:d=>String(n.cols.x[d])===String(n.cols.x[o]),l=P.range(n.n).filter(i),a=!!e.channels.color?.column,c=l.sort((d,m)=>a&&t.color.kind==="ordinal"?t.color.domain.indexOf(n.cols.color[d])-t.color.domain.indexOf(n.cols.color[m]):n.cols.ymax[m]-n.cols.ymax[d]).map(d=>({swatch:bt(t,e,n,s,d),label:a?_(t,null,n.cols.color[d]):n.hover.fields[1].label,value:_(t,null,n.cols.value[d]),strong:d===o&&l.length>1}));(e.options.position??"stack")==="stack"&&l.length>1&&c.push({label:"total",value:_(t,null,P.sum(l,d=>n.cols.value[d])),strong:!1,total:!0});let p=n.hover.fields[0];return{color:bt(t,e,n,s,o),header:`${p.label} ${gt(t,p,o)}`,rows:c,marks:[{rect:r,color:t.theme.ink}],anchor:{x:r.x+r.width,y:r.y}}}function ho({state:t,sx:e},n,s,o,r){if(e.bandwidth===void 0)return null;let i=P.range(s.n).find(h=>{let y=e.apply(s.cols.x[h]);return r>=y&&r<=y+e.bandwidth});if(i===void 0)return null;let l=String(s.cols.x[i]),a=P.range(s.n).filter(h=>String(s.cols.x[h])===l).map(h=>s.cols.y[h]).filter(h=>h!==null).sort(P.ascending),[c,u,p]=[.25,.5,.75].map(h=>P.quantile(a,h)),d=p-c,m=P.min(a.filter(h=>h>=c-1.5*d)),v=P.max(a.filter(h=>h<=p+1.5*d)),x=a.filter(h=>h<m||h>v).length,b=h=>_(t,"y",h),w=[{label:"max (whisker)",value:b(v)},{label:"q3",value:b(p)},{label:"median",value:b(u),strong:!0},{label:"q1",value:b(c)},{label:"min (whisker)",value:b(m)},{label:"n",value:String(a.length)}];x&&w.push({label:"outliers",value:String(x)});let f=e.apply(s.cols.x[i]);return{color:n.channels.color?.column?bt(t,n,s,o,i):t.theme.ink,header:`${s.hover.fields[0].label} ${l}`,rows:w,marks:[],anchor:{x:f+e.bandwidth,y:null}}}function fo(t,e,n,s){if(e.cols.xmin&&t.type!=="tile")return[s.apply(e.cols.xmin[n]),s.apply(e.cols.xmax[n])];if(s.bandwidth!==void 0){let i=e.cols.slots?.[n]??1,l=s.bandwidth/i,a=s.apply(e.cols.x[n])+(e.cols.slot?.[n]??0)*l;return[a,a+l]}let o=Je(e.cols.x,s),r=s.apply(e.cols.x[n]);return[r-o,r+o]}function xo(t,e,n,s){if(t.type==="tile"){if(s.bandwidth!==void 0)return[s.apply(e.cols.y[n]),s.apply(e.cols.y[n])+s.bandwidth];let o=Je(e.cols.y,s),r=s.apply(e.cols.y[n]);return[r-o,r+o]}return[s.apply(e.cols.ymin[n]),s.apply(e.cols.ymax[n])]}function Je(t,e){let n=[...new Set(t.map(Number))].sort((o,r)=>o-r),s=1/0;for(let o=1;o<n.length;o++)s=Math.min(s,n[o]-n[o-1]);return Number.isFinite(s)?Math.abs(e.apply(n[0]+s)-e.apply(n[0]))/2:6}var yo={zoom:'<path d="M4 9V4h5M15 4h5v5M20 15v5h-5M9 20H4v-5"/><rect x="9" y="9" width="6" height="6"/>',pan:'<path d="M12 3v18M3 12h18M12 3l-2.5 2.5M12 3l2.5 2.5M12 21l-2.5-2.5M12 21l2.5-2.5M3 12l2.5-2.5M3 12l2.5 2.5M21 12l-2.5-2.5M21 12l-2.5 2.5"/>',zoomIn:'<path d="M12 5v14M5 12h14"/>',zoomOut:'<path d="M5 12h14"/>',home:'<path d="M4 11l8-7 8 7M6 9.5V20h12V9.5"/>',copy:'<rect x="8.5" y="8.5" width="11" height="11"/><path d="M15.5 8.5V4.5h-11v11h4"/>',download:'<path d="M12 4v11M7.5 10.5L12 15l4.5-4.5M5 19.5h14"/>',check:'<path d="M5 12.5l4.5 4.5L19 7.5"/>'},go=`
2
- .pt-root{position:relative;--pt-size:24px}
3
- .pt-root svg{display:block;user-select:none;-webkit-user-select:none}
4
- .pt-root .pt-key{cursor:pointer}
5
- .pt-root:focus{outline:none}
6
- .pt-bar{position:absolute;top:6px;right:6px;display:flex;align-items:stretch;z-index:3;background:var(--pt-bg);
7
- border:1px solid var(--pt-line);opacity:0;transition:opacity .12s ease}
8
- .pt-root:hover .pt-bar,.pt-root:focus-within .pt-bar,.pt-bar.pt-open{opacity:1}
9
- @media (hover:none){.pt-bar{opacity:1}}
10
- .pt-btn{all:unset;box-sizing:border-box;display:grid;place-items:center;width:var(--pt-size);height:var(--pt-size);
11
- color:var(--pt-muted);cursor:pointer}
12
- .pt-btn svg{width:58%;height:58%;fill:none;stroke:currentColor;stroke-width:1.75;stroke-linecap:square;stroke-linejoin:miter}
13
- .pt-btn:hover{color:var(--pt-ink);background:var(--pt-soft)}
14
- .pt-btn:focus-visible{outline:2px solid var(--pt-accent);outline-offset:-2px}
15
- .pt-btn.pt-on{color:var(--pt-on-accent);background:var(--pt-accent)}
16
- .pt-sep{width:1px;background:var(--pt-line)}
17
- .pt-menu{position:absolute;top:100%;right:-1px;display:none;flex-direction:column;min-width:72px;margin-top:-1px;
18
- background:var(--pt-bg);border:1px solid var(--pt-line)}
19
- .pt-menu.pt-open{display:flex}
20
- .pt-menu button{all:unset;padding:5px 12px;font:600 11px/1.4 system-ui,sans-serif;letter-spacing:.04em;color:var(--pt-ink);cursor:pointer}
21
- .pt-menu button:hover{color:var(--pt-on-accent);background:var(--pt-accent)}
22
- .pt-tip{position:absolute;display:none;pointer-events:none;z-index:4;min-width:110px;max-width:280px;background:var(--pt-bg);
23
- color:var(--pt-ink);border:1px solid var(--pt-c);line-height:1.3;font-variant-numeric:tabular-nums}
24
- .pt-tip.pt-pinned{border-width:2px;box-shadow:3px 3px 0 color-mix(in srgb,var(--pt-c) 35%,transparent)}
25
- .pt-tip .pt-head{padding:3px 7px;background:var(--pt-c);color:var(--pt-on-c);font-weight:700;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
26
- .pt-tip .pt-rows{display:grid;grid-template-columns:auto minmax(0,1fr) auto;column-gap:7px;row-gap:0;padding:4px 7px 5px}
27
- .pt-tip .pt-sw{width:8px;height:8px;align-self:center}
28
- .pt-tip .pt-k{color:var(--pt-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
29
- .pt-tip .pt-v{text-align:right;white-space:nowrap}
30
- .pt-tip .pt-b{color:var(--pt-ink);font-weight:700}
31
- .pt-tip .pt-t{border-top:1px solid var(--pt-line);padding-top:2px;margin-top:1px}
32
- .pt-tip .pt-more{grid-column:1/-1;color:var(--pt-muted);font-size:.9em}
33
- .pt-error{padding:8px 10px;border-left:3px solid #d93025;background:#fdecea;color:#5f2120;font:12px/1.4 ui-monospace,monospace;white-space:pre-wrap}
34
- `;function tn(t){if(t.getElementById("plotto-style"))return;let e=t.createElement("style");e.id="plotto-style",e.textContent=go,t.head.append(e)}function en(t,e){let n={bg:e.background,ink:e.ink,muted:e.muted,line:e.grid,soft:e.strip,accent:e.accent,"on-accent":he(e.accent)};for(let[s,o]of Object.entries(n))t.style.setProperty(`--pt-${s}`,o)}function nn(t,e){let n=t.createElement("div");n.className="pt-bar";let s={},o=null;e.forEach((i,l)=>{l&&n.append(Object.assign(t.createElement("div"),{className:"pt-sep"}));for(let a of i){let c=t.createElement("button");c.className="pt-btn",c.type="button",c.title=a.title,c.setAttribute("aria-label",a.title),c.innerHTML=Qe(a.name),c.addEventListener("pointerdown",u=>u.stopPropagation()),c.addEventListener("click",u=>(u.stopPropagation(),a.menu?r():a.action(c))),n.append(c),s[a.name]=c,a.menu&&(o=bo(t,n,a.menu))}});function r(){let i=!o.classList.contains("pt-open");o.classList.toggle("pt-open",i),n.classList.toggle("pt-open",i)}return o&&t.addEventListener("click",()=>o.classList.contains("pt-open")&&r()),{el:n,button:i=>s[i],setSize:i=>n.parentElement?.style.setProperty("--pt-size",`${Math.round(Math.min(30,Math.max(22,i/34)))}px`),flash(i,l){let a=s[i],[c,u]=[a.innerHTML,a.title];a.innerHTML=Qe("check"),a.title=l,a.classList.add("pt-on"),setTimeout(()=>(a.innerHTML=c,a.title=u,a.classList.remove("pt-on")),1100)}}}function bo(t,e,n){let s=t.createElement("div");s.className="pt-menu";for(let[o,r]of n){let i=t.createElement("button");i.type="button",i.textContent=o,i.addEventListener("click",l=>(l.stopPropagation(),s.classList.remove("pt-open"),e.classList.remove("pt-open"),r())),s.append(i)}return e.append(s),s}function Qe(t){return`<svg viewBox="0 0 24 24" aria-hidden="true">${yo[t]}</svg>`}var $t=5,te=320,on=.75,wo=300;function sn(t,e,{interactive:n=!1,width:s}={}){let o=e.ownerDocument;tn(o);let r=o.createElement("div");r.className="pt-root";let i=Object.assign(o.createElement("div"),{className:"pt-tip"}),l={state:null,mode:"zoom"},a=null,c=m=>{let v=l.state&&{domains:l.state.domains===l.state.home?void 0:l.state.domains,hidden:l.state.hidden},x=Zt(t,{document:o,width:m,...v}),b=l.state?.svg;x.overlay=x.svg.appendChild(L(o,"g",{class:"pt-overlay","pointer-events":"none"})),x.theme.reflow||(x.svg.setAttribute("width","100%"),x.svg.removeAttribute("height"),r.style.maxWidth=`${x.W}px`),b?b.replaceWith(x.svg):r.prepend(x.svg),l.state=x,en(r,x.theme),p.setSize(x.theme.reflow?x.W:Math.min(x.W,e.clientWidth||x.W))},u=[[{name:"copy",title:"Copy as PNG",action:m=>Ie(l.state.svg).then(v=>p.flash("copy",v))},{name:"download",title:"Download",menu:[["PNG",()=>Ye(l.state.svg)],["SVG",()=>We(l.state.svg)]]}]];n&&u.unshift([{name:"zoom",title:"Zoom: drag a box",action:()=>d("zoom")},{name:"pan",title:"Pan: drag the view",action:()=>d("pan")}],[{name:"zoomIn",title:"Zoom in",action:()=>rn(l,on)},{name:"zoomOut",title:"Zoom out",action:()=>rn(l,1/on)},{name:"home",title:"Reset view (double-click)",action:()=>ln(l)}]);let p=nn(o,u);r.append(p.el,i);let d=m=>{l.mode=m,p.button("zoom").classList.toggle("pt-on",m==="zoom"),p.button("pan").classList.toggle("pt-on",m==="pan"),r.style.cursor=m==="pan"?"grab":""};try{let m=s??(e.clientWidth?Math.max(te,e.clientWidth):void 0);c(m),e.replaceChildren(r)}catch(m){let v=Object.assign(o.createElement("div"),{className:"pt-error",textContent:`plotto: ${m.message}`});throw e.prepend(v),m}if(n&&(d("zoom"),vo(l,r,i)),l.state.theme.reflow&&s===void 0&&typeof ResizeObserver<"u"){let m;a=new ResizeObserver(()=>{clearTimeout(m),m=setTimeout(()=>{let v=Math.max(te,Math.round(e.clientWidth));v&&v!==l.state.W&&c(v)},100)}),a.observe(e)}return l.redraw=()=>rt(l.state),l.resize=m=>c(Math.max(te,m)),l.destroy=()=>a?.disconnect(),l}function vo(t,e,n){let s=null,o=null,r=()=>t.state.svg,i=w=>{let f=r().getBoundingClientRect(),g=t.state.W/f.width;return[(w.clientX-f.left)*g,(w.clientY-f.top)*g,g]},l=(w,f)=>t.state.layout.panels.findIndex(g=>w>=g.x+g.ml&&w<=g.x+g.ml+g.innerW&&f>=g.y&&f<=g.y+g.innerH),a=!1;e.addEventListener("pointerdown",w=>{if(w.button!==0||!r().contains(w.target))return;let[f,g]=i(w),h=l(f,g);h<0||(w.preventDefault(),e.focus({preventScroll:!0}),s={i:h,x:f,y:g,domains:t.state.domains,moving:!1,id:w.pointerId})}),e.addEventListener("pointermove",w=>{let[f,g,h]=i(w);if(s&&!s.moving&&Math.hypot(f-s.x,g-s.y)>=$t&&(s.moving=!0,e.setPointerCapture(s.id),u(),b(),t.mode==="pan"&&(e.style.cursor="grabbing")),!s?.moving){!a&&!o&&(o=requestAnimationFrame(()=>(o=null,x(f,g,h))));return}if(t.mode==="pan")return Ao(t,s,f,g);let y=t.state.layout.panels[s.i],k=R=>Math.max(y.x+y.ml,Math.min(y.x+y.ml+y.innerW,R)),M=R=>Math.max(y.y,Math.min(y.y+y.innerH,R)),[C,S]=[s.x,k(f)].sort((R,T)=>R-T),[B,j]=[s.y,M(g)].sort((R,T)=>R-T),q=j-B<$t||t.state.kind.y==="category",z=S-C<$t||t.state.kind.x==="category";if(q&&z)return t.state.overlay.replaceChildren();let tt={x:z?y.x+y.ml:C,y:q?y.y:B,width:z?y.innerW:S-C,height:q?y.innerH:j-B},et=t.state.theme.accent;t.state.overlay.replaceChildren(L(t.state.doc,"rect",{...tt,fill:et,"fill-opacity":.1,stroke:et,"stroke-opacity":.7,"stroke-width":1})),s.box={x0:C,x1:S,y0:B,y1:j}}),e.addEventListener("pointerup",w=>{if(s?.moving&&t.mode==="zoom"&&s.box)Mo(t,s.i,s.box);else if(s&&!s.moving){let[f,g,h]=i(w);a?(u(),x(f,g,h)):(x(f,g,h),n.style.display==="block"&&c())}t.mode==="pan"&&(e.style.cursor="grab"),a||t.state.overlay.replaceChildren(),s=null}),e.addEventListener("pointerleave",()=>!s&&!a&&b()),e.addEventListener("keydown",w=>w.key==="Escape"&&(u(),b())),e.tabIndex=-1,t.clearHover=()=>(u(),b());function c(){a=!0,n.classList.add("pt-pinned")}function u(){a=!1,n.classList.remove("pt-pinned")}let p=w=>t.state.doc.elementFromPoint(w.clientX,w.clientY),d=w=>p(w)?.closest?.(".pt-key");e.addEventListener("dblclick",w=>{let[f,g]=i(w);l(f,g)<0||(u(),b(),ln(t))});let m={value:void 0,time:0,before:null};e.addEventListener("click",w=>{let f=d(w);if(!f)return;let g=t.state.legend.items[Number(f.dataset.index)].value;t.clearHover();let h=performance.now();if(g===m.value&&h-m.time<wo)return t.state.hidden=m.before,m={value:void 0,time:0,before:null},Eo(t,g);m={value:g,time:h,before:t.state.hidden};let y=new Set(t.state.hidden);y.has(g)?y.delete(g):y.add(g),t.state.hidden=y,rt(t.state)});let v=null;function x(w,f,g){let h=t.state,y=l(w,f),k=y<0?null:h.layout.panels[y],M=k?Ze(h,y,w-k.x,f-k.y,v):null;if(v=M,!M)return b();let C=h.doc,S=[];if(M.crosshair!==void 0){let T=k.x+M.crosshair;S.push(L(C,"line",{x1:T,x2:T,y1:k.y,y2:k.y+k.innerH,stroke:h.theme.muted,"stroke-opacity":.55,"stroke-width":1}))}for(let T of M.marks)T.rect?S.push(L(C,"rect",{x:k.x+T.rect.x,y:k.y+T.rect.y,width:T.rect.width,height:T.rect.height,fill:"none",stroke:T.color,"stroke-width":1.5})):S.push(L(C,"circle",{cx:k.x+T.x,cy:k.y+T.y,r:h.theme.point+1.5,fill:T.color,stroke:h.theme.background,"stroke-width":1.5}));h.overlay.replaceChildren(...S);let B=Yt(M.color);n.style.setProperty("--pt-c",B.bg),n.style.setProperty("--pt-on-c",B.fg),n.style.font=`${h.fonts.hover}px ${h.theme.font}`,n.replaceChildren(...ko(C,M)),n.style.display="block";let j=(k.x+M.anchor.x)/g,q=f/g,z=e.clientWidth,tt=e.clientHeight,et=j+16+n.offsetWidth>z?j-16-n.offsetWidth:j+16,R=Math.min(Math.max(0,q-18),Math.max(0,tt-n.offsetHeight));n.style.left=`${Math.max(0,et)}px`,n.style.top=`${R}px`}function b(){n.style.display="none",s||t.state.overlay.replaceChildren()}}function ko(t,e){let n=(r,i,l)=>Object.assign(t.createElement(r),{className:i,textContent:l??""}),s=[];e.header&&s.push(n("div","pt-head",e.header));let o=n("div","pt-rows");for(let r of e.rows){let i=n("span","pt-sw");r.swatch&&(i.style.background=r.swatch);let l=[i,n("span","pt-k",r.label),n("span","pt-v",r.value)];r.strong&&l.forEach(a=>a.classList.add("pt-b")),r.total&&l.forEach(a=>a.classList.add("pt-t")),o.append(...l)}return e.note&&o.append(n("span","pt-more",e.note)),s.push(o),s}function ln(t){t.clearHover?.(),t.state.domains=t.state.home,rt(t.state)}function Eo(t,e){let n=t.state.legend.items.map(o=>o.value),s=t.state.hidden.size===n.length-1&&!t.state.hidden.has(e);t.state.hidden=s?new Set:new Set(n.filter(o=>o!==e)),rt(t.state)}function Mo(t,e,{x0:n,x1:s,y0:o,y1:r}){let i=t.state,l=i.layout.panels[e],a=i.panels[e].plot,c=i.domains.map(p=>({...p})),u=(p,d,m)=>{if(i.kind[p]==="category"||m-d<$t)return;let v=a.scale(p),x=p==="x"?l.x:l.y,b=[v.invert(d-x),v.invert(m-x)].map(Number).sort((w,f)=>w-f);an(i,p,e).forEach(w=>c[w][p]=b)};u("x",n,s),u("y",o,r),i.domains=c,rt(i)}function rn(t,e){t.clearHover?.();let n=t.state;n.domains=n.domains.map(s=>{let o={...s};for(let r of["x","y"]){let i=n.kind[r];if(i==="category")continue;let l=i==="log"?Math.log10:d=>d,a=i==="log"?d=>10**d:d=>d,[c,u]=s[r].map(d=>l(+d)),p=(c+u)/2;o[r]=[a(p-(u-c)/2*e),a(p+(u-c)/2*e)]}return o}),rt(n)}function Ao(t,e,n,s){let o=t.state,r=o.layout.panels[e.i],i=o.panels[e.i].plot,l=e.domains.map(a=>({...a}));for(let[a,c,u,p]of[["x",e.x,n,r.x],["y",e.y,s,r.y]]){if(o.kind[a]==="category")continue;let d=i.scale(a),m=o.kind[a]==="log",v=w=>m?Math.log10(w):w,x=v(+d.invert(c-p))-v(+d.invert(u-p)),b=e.domains[e.i][a].map(w=>m?10**(v(w)+x):+w+x);an(o,a,e.i).forEach(w=>l[w][a]=b)}o.domains=l,o.frame||(o.frame=requestAnimationFrame(()=>(o.frame=null,rt(o))))}function an(t,e,n){let s=t.ns.facet?.free?.[e],o=t.grid.panels[n];return t.grid.panels.flatMap((r,i)=>s?t.grid.kind!=="grid"?i===n?[i]:[]:(e==="x"?r.col===o.col:r.row===o.row)?[i]:[]:[i])}globalThis.plotto={plot:ae,draw:sn,toSVG:qe};
File without changes
File without changes
File without changes