python-plotto 0.3.0__tar.gz → 0.4.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.3.0/python_plotto.egg-info → python_plotto-0.4.0}/PKG-INFO +1 -1
  2. {python_plotto-0.3.0 → python_plotto-0.4.0}/plotto/__init__.py +1 -1
  3. {python_plotto-0.3.0 → python_plotto-0.4.0}/plotto/_assets/grammar.json +1 -1
  4. python_plotto-0.4.0/plotto/_assets/plotto.js +35 -0
  5. {python_plotto-0.3.0 → python_plotto-0.4.0}/plotto/_assets/theme.json +4 -4
  6. {python_plotto-0.3.0 → python_plotto-0.4.0}/plotto/plot.py +3 -0
  7. {python_plotto-0.3.0 → python_plotto-0.4.0/python_plotto.egg-info}/PKG-INFO +1 -1
  8. {python_plotto-0.3.0 → python_plotto-0.4.0}/tests/test_builder.py +1 -0
  9. {python_plotto-0.3.0 → python_plotto-0.4.0}/tests/test_output.py +1 -1
  10. python_plotto-0.3.0/plotto/_assets/plotto.js +0 -34
  11. {python_plotto-0.3.0 → python_plotto-0.4.0}/LICENSE +0 -0
  12. {python_plotto-0.3.0 → python_plotto-0.4.0}/README.md +0 -0
  13. {python_plotto-0.3.0 → python_plotto-0.4.0}/plotto/assets.py +0 -0
  14. {python_plotto-0.3.0 → python_plotto-0.4.0}/plotto/data.py +0 -0
  15. {python_plotto-0.3.0 → python_plotto-0.4.0}/plotto/output.py +0 -0
  16. {python_plotto-0.3.0 → python_plotto-0.4.0}/pyproject.toml +0 -0
  17. {python_plotto-0.3.0 → python_plotto-0.4.0}/python_plotto.egg-info/SOURCES.txt +0 -0
  18. {python_plotto-0.3.0 → python_plotto-0.4.0}/python_plotto.egg-info/dependency_links.txt +0 -0
  19. {python_plotto-0.3.0 → python_plotto-0.4.0}/python_plotto.egg-info/requires.txt +0 -0
  20. {python_plotto-0.3.0 → python_plotto-0.4.0}/python_plotto.egg-info/top_level.txt +0 -0
  21. {python_plotto-0.3.0 → python_plotto-0.4.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-plotto
3
- Version: 0.3.0
3
+ Version: 0.4.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.3.0"
6
+ __version__ = "0.4.0"
7
7
 
8
8
  from .plot import Plot, plot # noqa: E402
9
9
 
@@ -46,7 +46,7 @@
46
46
  "grid": ["free"],
47
47
  "free": ["x", "y", "both"],
48
48
  "labels": ["title", "subtitle", "x", "y", "color", "caption"],
49
- "theme": ["format", "width", "height", "size", "legend"],
49
+ "theme": ["format", "width", "height", "size", "legend", "aspect"],
50
50
  "legend": ["right", "bottom", "none"],
51
51
  "info": ["position"],
52
52
  "infoPosition": ["right", "bottom"]
@@ -0,0 +1,35 @@
1
+ var O={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","aspect"],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:500,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:960,height:600,size:22,line:2.5,point:4,reflow:!1}}};var De=O.layers,Se=[...new Set(Object.values(De).flatMap(t=>t.channels))];function Le(t,e={}){let n=[ze(t,"plot()")];for(let[s,o]of Object.entries(e))Se.includes(s)||Q("plot()","channel",s,Se),oe(n[0],o,"plot()");return new ne({data:n,mapping:e,layers:[],facet:null,scales:{},labels:{},info:null,theme:{style:"pastel"}})}var ne=class t{#e;constructor(e){this.#e=e}#n(e){return new t({...this.#e,...e})}#t(e,n={}){let s=De[e],o=`${e}()`,{data:r,...i}=n,l=this.#e.data,a=0;r!==void 0&&(l=[...l,ze(r,o)],a=l.length-1);let c=l[a].columns,u={type:e,mapping:{},set:{}};a&&(u.data=a);for(let[p,f]of Object.entries(i))s.channels.includes(p)&&typeof f=="string"&&f in c?u.mapping[p]=f:s.channels.includes(p)||s.options.includes(p)?u.set[p]=Wn(p,f,o,c):Q(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 oe(this.#e.data[0],e,"facet()"),wt(n,O.facet,"facet()"),Ce(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&&oe(this.#e.data[0],o,"grid()");return wt(s,O.grid,"grid()"),Ce(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(wt(n,O.scales[e],s),n.type!==void 0&&!O.scaleTypes.includes(n.type)&&Q(s,"type",n.type,O.scaleTypes),n.palette!==void 0&&!Array.isArray(n.palette)&&!(n.palette in T.palettes)&&Q(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:Rt(r))}return this.#n({scales:{...this.#e.scales,[e]:o}})}labels(e={}){return wt(e,O.labels,"labels()"),this.#n({labels:{...this.#e.labels,...e}})}info(e,n={}){wt(n,O.info,"info()");let s=n.position??"right";if(O.infoPosition.includes(s)||Q("info()","position",s,O.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=>Yn(r)),position:s}})}theme(e="pastel",n={}){if(wt(n,O.theme,"theme()"),e in T.styles||Q("theme()","style",e,Object.keys(T.styles)),n.format!==void 0&&!(n.format in T.formats)&&Q("theme()","format",n.format,Object.keys(T.formats)),n.legend!==void 0&&!O.legend.includes(n.legend)&&Q("theme()","legend",n.legend,O.legend),n.aspect!=null&&!(typeof n.aspect=="number"&&n.aspect>0))throw new Error("theme(): aspect must be a positive number (panel height / width), for example 1 for square panels");return 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 ze(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 Wn(t,e,n,s){let o=O.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)&&Q(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 Yn(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,Rt(n)]}function oe(t,e,n){if(!(e in t.columns))throw new Error(`${n}: "${e}" is not a column. Columns: ${Object.keys(t.columns).join(", ")}`)}function wt(t,e,n){for(let s of Object.keys(t))e.includes(s)||Q(n,"option",s,e)}function Ce(t,e){t!=null&&!O.free.includes(t)&&Q(e,"free",t,O.free)}function Q(t,e,n,s){throw new Error(`${t}: unknown ${e} "${n}". Valid: ${s.join(", ")}`)}import*as K from"https://cdn.jsdelivr.net/npm/@observablehq/plot@0.6.17/+esm";import*as Vt 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 Y from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var Xn=Object.keys(T.styles),Gn=Object.keys(T.formats),Vn=Object.keys(T.palettes),_n=Object.keys(T.schemes),Pe=["ink","muted","grid","tick","strip","accent","background"];function $e({style:t="pastel",format:e="screen",legend:n="right",...s}={}){if(!T.styles[t])throw new Error(`theme(): unknown style "${t}". Valid: ${Xn.join(", ")}`);if(!T.formats[e])throw new Error(`theme(): unknown format "${e}". Valid: ${Gn.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.fitHeight=i.reflow&&!a.fixedHeight,a.palette=re(a,a.palette),a}function re(t,e){let n=Array.isArray(e)?e:T.palettes[e];if(!n)throw new Error(`color(): unknown palette "${e}". Valid: ${Vn.join(", ")}`);return n.map(s=>vt(t,s)??s)}function Be(t,e){let n=o=>Y.piecewise(Y.interpolateLab,o.map(r=>vt(t,r)??r));if(Array.isArray(e))return n(e);if(T.schemes[e])return n(T.schemes[e]);let s=typeof e=="string"&&Y[`interpolate${e[0].toUpperCase()}${e.slice(1)}`];if(!s)throw new Error(`color(): unknown scheme "${e}". plotto schemes: ${_n.join(", ")}; or a d3 scheme such as viridis, magma, blues`);return s}function vt(t,e){if(typeof e=="string")return t.colors[e]?t.colors[e]:Pe.includes(e)?t[e]:Y.color(e)?e:void 0}function Oe(t){return[...Object.keys(t.colors),...Pe]}function se(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=Y.rgb(t);if(e(n)>.42)return{bg:n.formatHex(),fg:"#1F2328"};let s=Y.hcl(n);for(let o=0;o<20&&1.05/(e(Y.rgb(s))+.05)<4;o++)s=Y.hcl(s.h,s.c,s.l-4);return{bg:Y.rgb(s).formatHex(),fg:"#FFFFFF"}}function Te(t){return se(t).fg}function Ne(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 Tt={x:["x","xmin","xmax","xend"],y:["y","ymin","ymax","yend"]},je=.05,ie=864e5;function le(t,e){let n=t.scales[e]?.type;if(n)return n;for(let s of t.layers)for(let o of Tt[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 Ie(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 qe(t,e,n,s){let o=[];for(let i of s)for(let l of i.views)for(let a of Tt[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 Un(t,e,o);let r=$.extent(o.filter(i=>n!=="log"||i>0));return r[0]===void 0?n==="log"?[1,10]:[0,1]:Re(r,n)}function Un(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(Wt)}function Wt(t,e){return String(t).localeCompare(String(e),void 0,{numeric:!0})}function Re([t,e],n){if(n==="log"){let[o,r]=Re([Math.log10(t),Math.log10(e)],"linear");return[10**o,10**r]}let s=e>t?(e-t)*je:n==="time"?36e5:Math.abs(t)*je||1;return[t-s,e+s]}function kt(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:He(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:He(i,e,Number),format:s?$.format(s):$.tickFormat(o,r,n)}}function He(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*ie?"%Y-%m":n>=ie?"%m-%d":n>=6e4?e>ie?"%m-%d %H:%M":"%H:%M":"%H:%M:%S"}var Zn=$.format(",.4~r"),We={number:t=>t==null?"\u2013":Math.abs(t)>=1e15||t!==0&&Math.abs(t)<1e-4?$.format(".3~e")(t):Zn(t),time:$.utcFormat("%m-%d %H:%M"),string:t=>t==null?"\u2013":String(t)};function Ye(t){let e=t.theme,n=t.scales.color??{},s=t.layers.filter(m=>m.channels.color?.column);if(!s.length)return{kind:"none"};let o=s[0].channels.color.column,r=s.find(m=>m.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(m=>t.tables[m.table].columns[o]),l=i[0].type,a=i.flatMap(m=>m.values).filter(m=>m!==null),c=m=>vt(e,m)??m;if(l==="string"){let m=i.find(F=>F.levels)?.levels,v=new Set(a),h=n.limits??(m?m.filter(F=>v.has(F)):[...v].sort(Wt)),x=n.palette?re(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],E=new Map(h.map((F,S)=>[F,M(F,S)]));return{kind:"ordinal",column:o,domain:h,apply:F=>E.get(F)??e.muted}}let[u,p]=Jn(n.limits,$.extent(a)),f=Be(e,n.values??n.scheme??e.scheme),d=n.mid,g=m=>d===void 0?(m-u)/(p-u||1):m<d?.5*((m-u)/(d-u||1)):.5+.5*((m-d)/(p-d||1)),y=m=>m>=u&&m<=p,w=m=>m===null?e.muted:n.clamp||y(m)?f(Math.max(0,Math.min(1,g(m)))):e.muted;return{kind:"continuous",column:o,domain:[u,p],type:l,interpolate:f,apply:w,ramp:m=>w(u+m*(p-u))}}function Jn(t,e){return t?[t[0]??e[0],t[1]??e[1]]:e}function Xe(t){let e=t.facet;if(!e)return{kind:"none",nrow:1,ncol:1,panels:[ce(t,0,0,{},{})]};if(e.kind==="wrap"){let r=ae(t,e.by),i=e.ncol??Qn(r.length),l=r.map((a,c)=>ce(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?ae(t,e.rows):[null],s=e.cols?ae(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(ce(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 Qn(t){return t<=3?t:t<=6?Math.ceil(t/2):t<=12?Math.ceil(t/3):Math.ceil(Math.sqrt(t))}function ae(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(Wt)}function ce(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,f])=>String(l.columns[p].values[u])===f)):c});return{row:e,col:n,strips:o,rows:r}}import*as ft from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var to="http://www.w3.org/2000/svg";function P(t,e,n={}){let s=t.createElementNS(to,e);for(let[o,r]of Object.entries(n))r!=null&&s.setAttribute(o,String(r));return s}function V(t,e,n,s="text"){let o=P(t,s,n);return o.textContent=e,o}var Ge={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 eo=11904;function lt(t,e,n=!1,s="arial"){let o=Ge[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>=eo?1:.6}return r*e}function at(t,e,n,s,o){if(t=String(t),lt(t,e,s,o)<=n)return t;let r=[...t];for(;r.length>1&&lt(r.join("")+"\u2026",e,s,o)>n;)r.pop();return r.join("")+"\u2026"}function ht(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&&lt(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]=at(l.slice(r-1).join(" "),e,n,s,o),c}var no=3,oo=.45,ro={right:.3,bottom:.9},so={right:.6,bottom:.3},io=3;function Ve(t,e,{W:n,H:s,narrow:o}){if(!t.info)return null;let r=o?"bottom":t.info.position;return lo(t,e,t.info.entries,r,n,s*so[r])}function lo(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,p=l*2,f=n.map(([v,h])=>({key:String(v),value:h===null?"\u2013":String(h)})),d=v=>lt(v,l,!1,i),g=(v,h)=>{let x=Math.min(ft.max(v,S=>d(S.key))??0,h*oo),k=Math.max(l*3,h-x-u),M=0,E=v.map(S=>{let B=ht(S.value,l,k,!1,i,no),X={key:at(S.key,l,x,!1,i),full:S.key,lines:B,y:M};return M+=B.length*c,X}),F=ft.max(E,S=>ft.max(S.lines,d))??0;return{rows:E,keyW:x,width:x+u+F,height:M}},y=o*ro[s]-2*a,w=v=>{let h;if(s==="bottom"){let k=ft.max(v,S=>d(S.key)+u+d(S.value))??0,M=Math.max(1,Math.min(io,v.length,Math.floor((y+p)/(k+p)))),E=Math.ceil(v.length/M),F=(y-p*(M-1))/M;h=ft.range(M).map(S=>g(v.slice(S*E,(S+1)*E),F))}else h=[g(v,y)];let x=a;for(let k of h)k.x=x,x+=k.width+p;return{columns:h,width:x-p+a,height:(ft.max(h,k=>k.height)??0)+2*a}},b=f.length,m=w(f);for(;m.height>r&&b>1;)b--,m=w([...f.slice(0,b),{key:`+${f.length-b} more`,value:""}]);return{position:s,size:l,pad:a,lineH:c,keyGap:u,...m}}function _e(t,e,n,{x:s,y:o}){let r=P(t,"g",{class:"pt-info",transform:`translate(${s},${o})`,"font-size":e.size});r.append(P(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=V(t,a.key,{x:l.x,y:c,fill:n.muted,"text-anchor":"start"});a.key!==a.full&&u.append(V(t,a.full,{},"title")),r.append(u),a.lines.forEach((p,f)=>r.append(V(t,p,{x:l.x+l.keyW+e.keyGap,y:c+f*e.lineH,fill:n.ink,"text-anchor":"start"})))}return r}import*as A from"https://cdn.jsdelivr.net/npm/@observablehq/plot@0.6.17/+esm";import*as W from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";import*as C from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var Yt=80;function Nt(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 Ue(t,e,n){let s={mean:C.mean,median:C.median,min:C.min,max:C.max,sum:C.sum}[n],o={x:[],y:[],color:[],group:[]};for(let{key:r,idx:i}of Nt(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 Ke(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 Nt(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 f=t.y[u]??0;if(n!=="overlay"){let d=f>=0?a:c;[i.ymin[u],i.ymax[u]]=[d,d+f],f>=0?a+=f:c+=f}else[i.ymin[u],i.ymax[u]]=[0,f];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 Ze(t,e){let n=[...new Set(t.x.filter(l=>l!==null))].sort((l,a)=>l-a),o=(C.min(C.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 Je(t,e){let n=t.filter(i=>i!==null&&Number.isFinite(i)),[s,o]=C.extent(n);if(s===void 0)return[0,1];if(s===o)return[s-.5,o+.5];let r=C.ticks(...C.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 Qe(t,e,n,s){let o={x:[],xmin:[],xmax:[],y:[],color:[]},r=C.bin().domain([n[0],n.at(-1)]).thresholds(n.slice(1,-1));for(let{key:i,idx:l}of Nt(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 Xt(t){let e=t.filter(a=>a!==null&&Number.isFinite(a)).sort(C.ascending),[n,s,o]=[.25,.5,.75].map(a=>C.quantile(e,a)),r=o-n,i=C.min(e.filter(a=>a>=n-1.5*r)),l=C.max(e.filter(a=>a<=o+1.5*r));return{n:e.length,q1:n,median:s,q3:o,low:i,high:l,outliers:e.filter(a=>a<i||a>l)}}function tn(t,e){let n={x:[],y:[],color:[],group:[]};for(let{key:s,idx:o}of Nt(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=C.deviation(r),l=C.quantile(r,.75)-C.quantile(r,.25),a=.9*Math.min(i,l/1.34||i)*r.length**-.2||1,[c,u]=C.extent(r);for(let p of C.range(Yt).map(f=>c-3*a+(u-c+6*a)*f/(Yt-1))){let f=C.sum(r,d=>Math.exp(-.5*((p-d)/a)**2))/(r.length*a*Math.sqrt(2*Math.PI));n.x.push(p),n.y.push(f),n.color.push(s[0]),n.group.push(s[0])}}return n}function en(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 Nt(t,["color"],e)){let a=l.map(d=>[t.x[d],t.y[d]]).filter(([d,g])=>d!==null&&g!==null&&Number.isFinite(d)&&Number.isFinite(g));if(a.length<3)continue;a.sort((d,g)=>d[0]-g[0]);let[c,u]=[a[0][0],a.at(-1)[0]],p=C.range(Yt).map(d=>c+(u-c)*d/(Yt-1));(n==="loess"?co(a,p,s):ao(a,p)).forEach(({x:d,y:g,se:y})=>{let w=uo(a.length-2);r.x.push(d),r.y.push(g),r.ymin.push(o&&y!==void 0?g-w*y:null),r.ymax.push(o&&y!==void 0?g+w*y:null),r.color.push(i[0]),r.group.push(i[0])})}return r}function ao(t,e){let n=t.length,s=C.mean(t,c=>c[0]),o=C.mean(t,c=>c[1]),r=C.sum(t,c=>(c[0]-s)**2)||1,i=C.sum(t,c=>(c[0]-s)*(c[1]-o))/r,l=o-i*s,a=Math.sqrt(C.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 co(t,e,n){let s=Math.max(3,Math.ceil(n*t.length));return e.map(o=>{let r=t.map(([y,w])=>[Math.abs(y-o),y,w]).sort((y,w)=>y[0]-w[0]).slice(0,s),i=r.at(-1)[0]||1,[l,a,c,u,p]=[0,0,0,0,0];for(let[y,w,b]of r){let m=(1-(y/i)**3)**3;l+=m,a+=m*w,c+=m*b,u+=m*w*w,p+=m*w*b}let f=l*u-a*a,d=Math.abs(f)<1e-12?0:(l*p-a*c)/f,g=(c-d*a)/l;return{x:o,y:g+d*o}})}function uo(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}var po={solid:void 0,dashed:"6,4",dotted:"1.5,3",dashdot:"6,3,1.5,3"},z="frame",ot=(t,e)=>({stroke:t.colors(e),strokeWidth:t.options.size??t.theme.line,strokeOpacity:t.options.alpha??1,strokeDasharray:po[t.options.dash],strokeLinejoin:"round",strokeLinecap:"round"}),ct=(t,e,n=1)=>({fill:t.colors(e),fillOpacity:t.options.alpha??n}),U=t=>t.theme.palette[0],ho=t=>e=>[A.line(e.index,{x:e.v("x"),y:e.v("y"),z:e.groups(),curve:t,...ot(e,U(e)),clip:z})],nn={line:t=>[A.line(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),sort:{channel:"x"},...ot(t,U(t)),clip:z})],path:ho("linear"),step:t=>[A.line(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),sort:{channel:"x"},curve:"step-after",...ot(t,U(t)),clip:z})],point:t=>{let e={x:fo(t),y:t.v("y"),r:t.options.size??t.theme.point,...ct(t,U(t)),clip:z};return t.options.jitter&&t.kind.x==="category"&&(e.render=mo(t.options.jitter)),[A.dot(t.index,e)]},bar:t=>{let e={...ct(t,U(t),ue(t,1)),clip:z};if(t.kind.x!=="category")return[A.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[A.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 W.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 A.barY(W.range(i.length),{...e,...l,insetLeft:r*s+.5,insetRight:(n-1-r)*s+.5})})},hist:t=>[A.rect(t.index,{x1:t.v("xmin"),x2:t.v("xmax"),y1:t.v("ymin"),y2:t.v("ymax"),insetLeft:.5,insetRight:.5,...ct(t,U(t),ue(t)),clip:z})],density:t=>[A.areaY(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),fill:t.colors(U(t)),fillOpacity:.15,clip:z}),A.line(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),...ot(t,U(t)),clip:z})],area:t=>[A.areaY(t.index,{x:t.v("x"),y1:t.v("ymin"),y2:t.v("ymax"),z:t.groups(),...ct(t,U(t),ue(t,.8)),clip:z})],ribbon:t=>[A.areaY(t.index,{x:t.v("x"),y1:t.v("ymin"),y2:t.v("ymax"),z:t.groups(),...ct(t,U(t),.2),clip:z})],smooth:t=>{let e=[];return t.v("ymin").some(n=>n!==null)&&e.push(A.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:z})),e.push(A.line(t.index,{x:t.v("x"),y:t.v("y"),z:t.groups(),...ot(t,t.theme.accent),clip:z})),e},hline:t=>[A.ruleY(t.index,{y:t.v("y"),...ot(t,t.theme.muted),strokeWidth:t.options.size??1,clip:z})],vline:t=>[A.ruleX(t.index,{x:t.v("x"),...ot(t,t.theme.muted),strokeWidth:t.options.size??1,clip:z})],abline:t=>{let[e,n]=t.domain.x.map(Number),{slope:s=1,intercept:o=0}=t.options;return[A.line([0,1],{x:[e,n],y:[o+s*e,o+s*n],...ot(t,t.theme.muted),strokeWidth:t.options.size??1,clip:z})]},segment:t=>[A.link(t.index,{x1:t.v("x"),y1:t.v("y"),x2:t.v("xend"),y2:t.v("yend"),...ot(t,t.theme.ink),clip:z})],rect:t=>[A.rect(t.index,{x1:t.v("xmin"),x2:t.v("xmax"),y1:t.v("ymin"),y2:t.v("ymax"),...ct(t,U(t)),clip:z})],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[A.rect(t.index,{...n,...ct(t,t.theme.muted,.12),clip:z})]},tile:t=>{let e=ct(t,U(t)),[n,s]=[t.kind.x==="category",t.kind.y==="category"];if(n&&s)return[A.cell(t.index,{x:t.v("x"),y:t.v("y"),...e,inset:.5,clip:z})];let[o,r]=n?[]:Gt(t.v("x")),[i,l]=s?[]:Gt(t.v("y"));return n?[A.barY(t.index,{x:t.v("x"),y1:i,y2:l,...e,clip:z})]:s?[A.barX(t.index,{y:t.v("y"),x1:o,x2:r,...e,insetTop:.5,insetBottom:.5,clip:z})]:[A.rect(t.index,{x1:o,x2:r,y1:i,y2:l,...e,clip:z})]},text:t=>[A.text(t.index,{x:t.v("x"),y:t.v("y"),text:t.v("label"),fontSize:t.options.size??t.fonts.tick,...ct(t,t.theme.ink),clip:z})],errorbar:t=>{let e={...ot(t,t.theme.ink),strokeWidth:t.options.size??1.2},n=A.ruleX(t.index,{x:t.v("x"),y1:t.v("ymin"),y2:t.v("ymax"),...e,clip:z});if(t.kind.x==="category"){let i=t.bandwidth.x*.35,l=a=>A.tickY(t.index,{x:t.v("x"),y:t.v(a),...e,insetLeft:i,insetRight:i,clip:z});return[n,l("ymin"),l("ymax")]}let[s,o]=Gt(t.v("x"),.25),r=i=>A.link(t.index,{x1:s,x2:o,y1:t.v(i),y2:t.v(i),...e,clip:z});return[n,r("ymin"),r("ymax")]},box:t=>{let[e,n,s]=[t.v("x"),t.v("y"),t.colors(t.theme.muted)],o=[];for(let[a,c]of W.group(t.index,u=>e[u])){let u=Xt(c.map(p=>n[p]));u.n&&o.push({key:a,color:Array.isArray(s)?s[c[0]]:s,...u})}let r=o.flatMap(a=>a.outliers.map(c=>({key:a.key,v:c,color:a.color}))),i=a=>({insetLeft:t.bandwidth.x*a,insetRight:t.bandwidth.x*a}),l={x:"key",stroke:"color",strokeWidth:1.25,clip:z};return[A.ruleX(o,{...l,y1:"q3",y2:"high"}),A.ruleX(o,{...l,y1:"low",y2:"q1"}),A.tickY(o,{...l,y:"high",...i(.38)}),A.tickY(o,{...l,y:"low",...i(.38)}),A.barY(o,{...l,y1:"q1",y2:"q3",fill:"color",fillOpacity:t.options.alpha??.3,...i(.22)}),A.tickY(o,{x:"key",y:"median",stroke:t.theme.ink,strokeWidth:2.25,...i(.22),clip:z}),A.dot(r,{x:"key",y:"v",fill:"color",r:t.theme.point,clip:z})]}};function ue(t,e=.9){return t.options.position==="overlay"?.45:e}function Gt(t,e=.5){let n=t.map(Number),s=[...new Set(n)].sort((i,l)=>i-l),o=W.min(W.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 fo(t){let e=t.v("x");if(!t.options.jitter||t.kind.x==="category")return e;let n=W.randomUniform.source(W.randomLcg(42))(-1,1),[s]=Gt(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 mo(t){return(e,n,s,o,r,i)=>{let l=W.randomUniform.source(W.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 Mt from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var Et=18,At=6,rt={thick:12,long:150,slices:48},xo=3,yo=1.25,go=["line","path","step","density","smooth","hline","vline","abline","segment","errorbar"],bo=["bar","hist","area","ribbon","rect","tile","box"];function on(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=(h,x,k)=>lt(h,x,k,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 h=kt(e.type==="time"?"time":"linear",e.domain,4),x=h.major.map(h.format),k=Mt.max(x,S=>l(S,n.legend))??0,M=Math.min(rt.long,s?o:r-c-4),[E,F]=s?[M,rt.thick+n.legend*1.6]:[rt.thick+At+k,M];return{kind:"ramp",title:a,titleH:c,color:e,long:M,ticks:h.major,labels:x,width:Math.max(u,E),height:c+F,horizontal:s}}let p=t.layers.filter(h=>h.channels.color?.column),f=p.some(h=>bo.includes(h.type))?"square":p.some(h=>go.includes(h.type))?"line":"point",d=Math.round(n.legend*1.75),g=n.legend*yo,y=s?Math.max(80,o-Et-At):Math.max(110,Math.min(200,o*.2)),w=e.domain.map(h=>{let x=s?[at(h,n.legend,y,!1,i)]:ht(h,n.legend,y,!1,i,xo),k=Et+At+(Mt.max(x,M=>l(M,n.legend))??0);return{value:h,label:x.join(" "),lines:x,color:e.apply(h),w:k,h:d+(x.length-1)*g}});if(!s){let h=[[]],x=c;for(let E of w)x+E.h>r&&h.at(-1).length&&(h.push([]),x=c),h.at(-1).push(Object.assign(E,{y:x})),x+=E.h;let k=0;for(let E of h){for(let F of E)F.x=k;k+=(Mt.max(E,F=>F.w)??0)+n.legend}let M=Mt.max(h,E=>E.at(-1).y+E.at(-1).h)??c;return{kind:"swatches",title:a,titleH:c,key:f,rowH:d,lineH:g,items:w,width:Math.max(u,k-n.legend),height:M,horizontal:s}}let b=0,m=c;for(let h of w)b>0&&b+h.w>o&&([b,m]=[0,m+d]),Object.assign(h,{x:b,y:m}),b+=h.w+n.legend*1.5;let v=Math.max(u,Mt.max(w,h=>h.x+h.w)??0);return{kind:"swatches",title:a,titleH:c,key:f,rowH:d,lineH:g,items:w,width:v,height:m+d,horizontal:s}}function rn(t,e,n,s,o=new Set){let r=P(t,"g",{class:"pt-legend","font-size":s.legend});return e.title&&r.append(V(t,e.title,{y:s.legend,"font-weight":"bold","font-size":s.legend+1,fill:n.ink})),e.kind==="ramp"?vo(t,r,e,n,s):e.items.forEach((i,l)=>r.append(wo(t,e,i,l,n,o.has(i.value)))),r}function wo(t,e,n,s,o,r){let i=e.rowH/2,l=P(t,"g",{class:"pt-key","data-index":s,transform:`translate(${n.x},${n.y})`,opacity:r?.35:1}),a=P(t,"rect",{width:n.w,height:n.h,fill:"transparent"}),c=e.key==="line"?P(t,"line",{x1:1,x2:Et-1,y1:i,y2:i,stroke:n.color,"stroke-width":Math.max(2.5,o.line+1)}):e.key==="point"?P(t,"circle",{cx:Et/2,cy:i,r:Math.max(3.5,o.point+1),fill:n.color}):P(t,"rect",{x:3,y:i-6,width:12,height:12,fill:n.color}),u=P(t,"text",{x:Et+At,y:i,dy:"0.35em",fill:o.muted,"text-decoration":r?"line-through":null});return n.lines.forEach((p,f)=>u.append(f?V(t,p,{x:Et+At,dy:e.lineH},"tspan"):t.createTextNode(p))),n.lines.at(-1).endsWith("\u2026")&&u.append(V(t,n.value,{},"title")),l.append(a,c,u),l}function vo(t,e,n,s,o){let{color:r,horizontal:i,long:l}=n,[a,c]=r.domain.map(Number),u=f=>(Number(f)-a)/(c-a||1),p=n.titleH;for(let f=0;f<rt.slices;f++){let d=f/rt.slices,g=l/rt.slices+.5,y=r.ramp(i?d:1-d),w=i?{x:d*l,y:p,width:g,height:rt.thick}:{x:0,y:p+d*l,width:rt.thick,height:g};e.append(P(t,"rect",{...w,fill:y}))}n.ticks.forEach((f,d)=>{let g=u(f)*l,y=i?{x:g,y:p+rt.thick+o.legend*1.2,"text-anchor":"middle"}:{x:rt.thick+At,y:p+l-g,dy:"0.35em"};e.append(V(t,n.labels[d],{...y,fill:s.muted}))})}import*as j from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var mt={size:4,padding:3},sn=40,ko=3,pe=1.15,Mo=.22;function ln({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,p=(D,G,J)=>lt(D,G,J,u),f=i.base,d=Math.round(f*.9),g=Math.round(f*.8),{title:y,subtitle:w,caption:b,x:m,y:v}=t.labels,h=D=>r?.position===D?r:null,x=l-2*d-Math.min(180,l*Mo),k=y?ht(y,i.title,x,!0,u):[],M=w?ht(w,i.subtitle,x,!1,u):[],E=k.length*i.title*1.25+M.length*i.subtitle*1.4,F=d+E+(E?f*.7:0),S=m?i.axisTitle*1.7:0,B=v?i.axisTitle*1.7:0,X=b?i.tick*1.8:0,q=Math.max(o&&!o.horizontal?o.width:0,h("right")?.width??0),Ct=q?q+f*1.5:0,pt=o?.horizontal?o.height+f*.8:0,Z=h("bottom")?h("bottom").height+g:0,L={x:d+B,y:F,w:l-2*d-B-Ct,h:a-F-d-S-pt-X-Z},Dt=e.kind==="none"?0:Math.round(i.strip*2),Lt=e.kind==="wrap"?Dt:0,jt=e.kind==="grid"&&t.facet.cols?Dt+2:0,ye=e.kind==="grid"&&t.facet.rows?Dt+2:0,ge=t.facet?.free??{x:!1,y:!1},On=e.panels.length,be=D=>ge.y||D.col===0,zt=(D,G)=>ge.x||(e.kind==="wrap"?G+e.ncol>=On:D.row===e.nrow-1),H=L.w/e.ncol,I=L.h/e.nrow,st,it,Pt,Kt,dt,xt;for(let D=0;D<2;D++){Kt={x:Math.max(2,H/(n.x==="time"?110:75)),y:Math.max(2,I/45)},st=Array(e.ncol).fill(0),it=Array(e.nrow).fill(0),dt=!1,xt=new Map,Pt=0;let G=0;e.panels.forEach((N,R)=>{if(be(N)){let _=kt(n.y,s[R].y,Kt.y,t.scales.y?.format),bt=j.max(_.major,nt=>p(_.format(nt),i.tick))??0;if(st[N.col]=Math.max(st[N.col],Math.ceil(bt+mt.size+mt.padding+3)),N.row===0&&!Lt&&!jt&&n.y!=="category"){let[nt,Bt]=s[R].y,Ot=(n.y==="log"?j.scaleLog():j.scaleLinear()).domain([nt,Bt]).range([I,0]),qt=j.max(_.major.filter(Fe=>+Fe>=+nt&&+Fe<=+Bt));qt!==void 0&&(Pt=Math.max(Pt,Math.ceil(i.tick*.6-Ot(qt))))}}if(n.x==="category"&&zt(N,R)){let _=s[R].x,bt=H/(_.length+.2)*.95;for(let nt of _){let Bt=p(nt,i.tick);if(G=Math.max(G,Bt),Bt<=bt)continue;let Ot=ht(nt,i.tick,bt,!1,u,ko);Ot.at(-1).endsWith("\u2026")||j.max(Ot,qt=>p(qt,i.tick))>bt?dt=!0:xt.set(String(nt),Ot)}}});let J=Math.min(G,Math.max(I*.6,i.tick*10));dt&&(xt.clear(),e.panels.forEach((N,R)=>{if(!(n.x!=="category"||!zt(N,R)))for(let _ of s[R].x)p(_,i.tick)>J&&xt.set(String(_),[at(_,i.tick,J,!1,u)])}));let Ht=dt?1:j.max(xt.values(),N=>N.length)??1,It=dt?J*Math.sin(sn*Math.PI/180)+i.tick:i.tick*(1.2+pe*(Ht-1));dt&&e.panels.forEach((N,R)=>{if(N.col!==0||!zt(N,R))return;let _=H/(s[R].x.length+.2),nt=Math.min(p(s[R].x[0],i.tick),J)*Math.cos(sn*Math.PI/180)+i.tick*.5;st[0]=Math.max(st[0],Math.ceil(nt-.6*_))}),e.panels.forEach((N,R)=>{zt(N,R)&&(it[N.row]=Math.max(it[N.row],Math.ceil(It+mt.size+mt.padding+3)))}),H=(L.w-j.sum(st)-g*(e.ncol-1)-ye)/e.ncol,I=(L.h-Pt-j.sum(it)-e.nrow*Lt-jt-g*(e.nrow-1))/e.nrow}H=Math.max(20,H),I=Math.max(20,I);let Zt={w:H,h:I};c.aspect&&(I>H*c.aspect?I=H*c.aspect:H=I/c.aspect);let Tn=(Zt.h-I)*e.nrow/2,we=(Zt.w-H)*e.ncol/2,Nn=j.cumsum([L.x+we,...st.slice(0,-1).map(D=>D+H+g)]),jn=j.cumsum([L.y+Pt+jt+Tn,...it.slice(0,-1).map(D=>Lt+I+D+g)]),$t=e.panels.map((D,G)=>({x:Nn[D.col],y:jn[D.row]+Lt,w:st[D.col]+H,h:I+it[D.row],ml:st[D.col],mb:it[D.row],innerW:H,innerH:I,count:Kt,rotateX:dt,wrapX:xt,showX:zt(D,G),showY:be(D)})),Jt=[];e.panels.forEach((D,G)=>{let J=$t[G],Ht=J.x+J.ml,It=(N,R)=>at(N,i.strip,R-8,!0,u);D.strips.top!=null&&Jt.push({x:Ht,y:J.y-Lt-jt,w:H,h:Dt,text:It(D.strips.top,H),full:D.strips.top}),D.strips.right!=null&&Jt.push({x:Ht+H+2,y:J.y,w:Dt,h:I,text:It(D.strips.right,I),full:D.strips.right,vertical:!0})});let Qt=$t[0],ve=$t.find((D,G)=>e.panels[G].col===e.ncol-1)??Qt,yt=Qt.x+Qt.ml,te=ve.x+ve.w,ke=j.max($t,D=>D.y+D.h),gt=[],ee=d;for(let D of k)gt.push({text:D,attrs:{x:yt,y:ee+=i.title*1.05,"font-size":i.title,"font-weight":"bold",fill:c.ink,"text-anchor":"start"}}),ee+=i.title*.2;for(let D of M)gt.push({text:D,attrs:{x:yt,y:ee+=i.subtitle*1.3,"font-size":i.subtitle,fill:c.muted,"text-anchor":"start"}});if(m&&gt.push({text:m,attrs:{x:(yt+te)/2,y:ke+i.axisTitle*1.35,"text-anchor":"middle","font-size":i.axisTitle,fill:c.muted}}),v){let D=L.y+(L.h-j.sum(it))/2;gt.push({text:v,attrs:{transform:`translate(${d+we+i.axisTitle*.85},${D}) rotate(-90)`,"text-anchor":"middle","font-size":i.axisTitle,fill:c.muted}})}b&&gt.push({text:at(b,i.tick,l-2*d,!1,u),attrs:{x:yt,y:a-d-(pt||0)+i.tick*.2,"font-size":i.tick,fill:c.muted,"text-anchor":"start"}});let Me=te+ye+f*1.5,Ee=Me<l-d-q-1?Me:l-d-q,Hn=r?r.position==="right"?{x:Ee,y:L.y}:{x:Math.max(d,Math.min(yt,l-d-r.width)),y:ke+S+g/2}:null,Ae=h("right")?r.height+f:0,In=o?o.horizontal?{x:Math.max(d,(yt+te-o.width)/2),y:a-d-o.height}:{x:Ee,y:L.y+Ae+Math.max(0,(L.h-j.sum(it)-Ae-o.height)/2)}:null;return{panels:$t,strips:Jt,texts:gt,legend:In,info:Hn,area:L,room:Zt,rotateX:dt}}function an(t,e={}){if(typeof t?.spec=="function"&&(t=t.spec()),t?.version!==1)throw new Error("plotto: unknown spec version");let n=$e({...t.theme,...e}),s=t.data.map(Eo),o=t.layers.map(a=>Ao(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=Fo(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 Eo({columns:t}){let e=Object.keys(t),n=e.length?t[e[0]].values.length:1;return{columns:t,n}}function Ao(t,e,n,s){let o=O.layers[t.type];if(!o)throw new Error(`plotto: unknown layer type "${t.type}". Valid: ${Object.keys(O.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=vt(s,l.color.value);if(!u)throw new Error(`${t.type}(): "${l.color.value}" is not a column or a color. Theme colors: ${Oe(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 Fo(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"])}}function cn(t){return t.layers.map(e=>e.type!=="hist"||!e.channels.x.column?null:Je(t.tables[e.table].columns[e.channels.x.column].values,e.options.bins??30))}function de(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]=Ie(o,e,w,n);let c=n.length,u=e.options,p=(w,b,m)=>Ke(w,b,m,i),f=w=>w.x?.length??0,d=a,g=n;if(u.summary&&(e.type==="line"||e.type==="point"))d=Ue(a,c,u.summary);else if(e.type==="bar")d=p(a,c,u.position??"stack"),r.x!=="category"&&(d=Ze(d,c));else if(e.type==="area")d=p(a,c,u.position??"stack");else if(e.type==="hist"){let w=Qe(a,c,l[o.layers.indexOf(e)],u.density);d=p(w,f(w),u.position??"stack")}else e.type==="density"?d=tn(a,c):e.type==="smooth"&&(d=en(a,c,u));d!==a&&(g=null);let y={cols:d,n:d===a?c:f(d),rows:g};return y.hover=Co(o,e,y),y}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,p,f)=>({label:c,axis:u,values:p,values2:f}),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 un=560,pn=240,Do=1.2;function _t(t,{document:e=globalThis.document,width:n,domains:s,hidden:o=new Set}={}){let r=an(t),i=r.theme,l=Math.round(n??i.width),c=n&&i.reflow&&!i.fixedHeight?Math.max(pn,Math.round(l*i.height/i.width)):i.height;i.legend==="right"&&l<un&&(i.legend="bottom");let u=Ne(i),p=Xe(r),f={x:le(r,"x"),y:le(r,"y")},d=Ye(r),g={ns:r,kind:f,colorLevels:d.domain??[],edges:cn(r)};for(let M of p.panels)M.views=r.layers.map((E,F)=>de(g,E,M.rows[F],new Set));let y=Po(r,p,f),w=i.legend==="bottom",b=M=>{let E=Ve(r,u,{W:l,H:M,narrow:l<un}),F=E?.position==="right"?E.height+u.base:0,S=on(r,d,u,{horizontal:w,maxWidth:l*.9,maxHeight:M*.8-F});return{info:E,legend:S,layout:ln({ns:r,grid:p,kind:f,home:y,legend:S,info:E,fonts:u,W:l,H:M})}},{info:m,legend:v,layout:h}=b(c);if(i.aspect&&i.fitHeight){let M=c+p.nrow*(h.room.w*i.aspect-h.room.h);c=Math.round(Math.min(c*Do,Math.max(pn,M))),{info:m,legend:v,layout:h}=b(c)}let x=P(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(P(e,"rect",{width:l,height:c,fill:i.background}));for(let M of h.texts)x.append(V(e,M.text,M.attrs));m&&x.append(_e(e,m,i,h.info));for(let M of h.strips)x.append(Bo(e,M,i,u));let k={spec:t,ns:r,doc:e,svg:x,theme:i,fonts:u,grid:p,kind:f,color:d,ctx:g,legend:v,info:m,layout:h,home:y,W:l,H:c};return k.domains=s??y,k.hidden=o,k.panelLayer=x.appendChild(P(e,"g",{class:"pt-panels"})),v&&(k.legendG=x.appendChild(mn(k))),ut(k),k}function fn(t,e){return _t(t,e).svg.outerHTML}function ut(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)=>de(s,i,r.rows[l],o));t.filtered=o.size>0}t.panelLayer.replaceChildren(),t.panels=n.panels.map((r,i)=>Lo(t,r,i)),t.legendG&&t.legendG.replaceWith(t.legendG=mn(t))}function mn(t){let e=rn(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 Lo(t,e,n){let{ns:s,doc:o,theme:r,fonts:i,kind:l,color:a}=t,c=t.layout.panels[n],u={x:dn(l.x,t.domains[n].x),y:dn(l.y,t.domains[n].y)},p={x:l.x==="category"?c.innerW/(u.x.length+.2)*.8:0},f=s.layers.map((x,k)=>{let M=e.views[k],E=zo({view:M,layer:x,kind:l,color:a,theme:r,fonts:i,domain:u,bandwidth:p});return{layer:x,view:M,c:E,marks:M.n?nn[x.type](E):[]}}),d=x=>{let k=kt(l[x],t.domains[n][x],c.count[x],s.scales[x]?.format),M=E=>l[x]==="category"||+E>=+u[x][0]&&+E<=+u[x][1];return{major:k.major.filter(M),minor:k.minor,format:k.format}},g=d("x"),y=d("y"),w=x=>({stroke:x?r.gridMinor:r.grid,strokeOpacity:1,strokeWidth:x?.6:.9}),b={tickSize:mt.size,tickPadding:mt.padding,fontSize:i.tick,stroke:r.tick,fill:r.muted,label:null},m=[];if(l.x!=="category"&&m.push(K.gridX(g.minor,w(!0)),K.gridX(g.major,w(!1))),l.y!=="category"&&m.push(K.gridY(y.minor,w(!0)),K.gridY(y.major,w(!1))),m.push(...f.flatMap(x=>x.marks)),c.showX){let x=c.rotateX?{tickRotate:-40,textAnchor:"end"}:{},k=E=>c.wrapX.get(String(E))?.join(`
2
+ `)??g.format(E),M=c.wrapX.size?{tickFormat:k,lineHeight:pe}:{tickFormat:g.format};m.push(K.axisX(g.major,{...b,...x,anchor:"bottom",...M}))}c.showY&&m.push(K.axisY(y.major,{...b,anchor:"left",tickFormat:y.format}));let v=K.plot({document:o,width:c.w,height:c.h,marginLeft:c.ml,marginRight:0,marginTop:0,marginBottom:c.mb,x:hn(l.x,u.x),y:hn(l.y,u.y),color:{type:"identity"},marks:m}),h=P(o,"g",{class:"pt-panel","data-panel":n,transform:`translate(${c.x},${c.y})`,fill:"currentColor","text-anchor":"middle"});for(let x of[...v.childNodes])x.nodeName.toLowerCase()!=="style"&&h.append(x);return t.panelLayer.append(h),{g:h,plot:v,box:c,layers:f}}function zo({view:t,layer:e,kind:n,color:s,theme:o,fonts:r,domain:i,bandwidth:l}){let a=f=>Tt.x.includes(f)?"x":Tt.y.includes(f)?"y":null,c={},u=f=>{if(f in c)return c[f];let d=t.cols[f];return d&&n[a(f)]==="time"&&(d=d.map(g=>g===null?null:new Date(g))),c[f]=d},p=e.channels.color;return{index:Vt.range(t.n),v:u,options:e.options,colors:f=>p?"value"in p?p.value:u("color").map(s.apply):f,groups:()=>u("group")??(p?.column?u("color"):void 0),kind:n,theme:o,fonts:r,domain:i,bandwidth:l}}function dn(t,e){return t==="time"?e.map(n=>new Date(n)):e}function hn(t,e){return{type:{linear:"linear",log:"log",time:"utc",category:"band"}[t],domain:e,axis:null,...t==="category"?{padding:.2,round:!1}:{}}}function Po(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=Vt.group(e.panels.map((a,c)=>[a,c]),([a,c])=>o(i,a,c));for(let a of l.values()){let c=$o(t,i,n[i],a.map(([u])=>u));for(let[,u]of a)r[u][i]=c}}return r}function $o(t,e,n,s){let o=t.scales[e]?.limits;if(o&&(n==="category"||o.every(i=>i!==null)))return o;let r=qe(t,e,n,s);return o?[o[0]??r[0],o[1]??r[1]]:r}function Bo(t,e,n,s){let o=P(t,"g",{class:"pt-strip"});o.append(P(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=V(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(V(t,e.full,{},"title")),o.append(i),o}async function he(t,e,n=2){let s=gn(t,e?n*e.width/t.viewBox.baseVal.width:n),o={"image/png":s.then(Oo)};if(e){let r=i=>`<img src="${i.toDataURL("image/png")}" width="${e.width}" height="${e.height}">`;o["text/html"]=s.then(i=>new Blob([r(i)],{type:"text/html"}))}try{return await navigator.clipboard.write([new ClipboardItem(o)]),"Copied"}catch{return fe((await s).toDataURL("image/png"),"plot.png"),"Downloaded"}}async function xn(t){fe((await gn(t)).toDataURL("image/png"),"plot.png")}function yn(t){fe(bn(t),"plot.svg")}async function gn(t,e=2){let n=new Image;n.src=bn(t),await n.decode();let{width:s,height:o}=t.viewBox.baseVal,r=document.createElement("canvas");return r.width=Math.round(s*e),r.height=Math.round(o*e),r.getContext("2d").drawImage(n,0,0,r.width,r.height),r}function bn(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 Oo=t=>new Promise(e=>t.toBlob(e,"image/png"));function fe(t,e){let n=document.createElement("a");n.href=t,n.download=e,n.click()}import*as et from"https://cdn.jsdelivr.net/npm/d3@7.9.0/+esm";var kn=40,To=10,No=6,Mn=4,jo=6,Ho=["line","step","area","density","smooth","ribbon"],Io=["bar","hist","tile","box"],qo=["point","path","errorbar"];function En(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:y=>i.apply(y)+(i.bandwidth??0)/2,py:y=>l.apply(y)+(l.bandwidth??0)/2},p=Go(u,r,n);if(p)return{...p,panel:e};let f=Wo(u,r,n,s,o?.panel===e?o:null);if(f&&f.d<=To)return{...wn(u,f),panel:e};let d=Yo(u,r,n,s,o?.panel===e?o:null);if(d)return{...d,panel:e};let g=Vo(u,r,n,s);return g?{...g,panel:e}:f?{...wn(u,f),panel:e}:null}function St(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 tt(t,e,n){return n==null||Number.isNaN(n)?"\u2013":e&&t.kind[e]==="time"?Ro(t,e)(n):e&&t.kind[e]==="category"?String(n):typeof n=="number"?We.number(n):String(n)}function Ro(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]=et.utcFormat(o)}function Ft(t,e,n){return e.values2?`${tt(t,e.axis,e.values[n])} \u2013 ${tt(t,e.axis,e.values2[n])}`:tt(t,e.axis,e.values[n])}function Wo({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(!qo.includes(a.type)||!c.hover||!c.n)continue;let{hx:p,hy:f}=c.hover;for(let d=0;d<c.n;d++){if(p[d]===null||f[d]===null)continue;let g=Math.hypot(t(p[d])-s,e(f[d])-o);if(g>kn)continue;let y={layer:a,view:c,c:u,k:d,d:g,x:t(p[d]),y:e(f[d])};(!i||g<i.d)&&(i=y),r?.layer===a&&r.k===d&&(l=y)}}return l&&i&&i.d>l.d-Mn?l:i}function wn({state:t},{layer:e,view:n,c:s,k:o,x:r,y:i,d:l}){let a=St(t,e,n,s,o),c=e.channels.color?.column?tt(t,null,n.cols.color[o]):null,u=n.hover.fields.map(p=>({label:p.label,value:Ft(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 Yo({state:t,px:e,py:n},s,o,r,i){let l=[];for(let{layer:h,view:x,c:k}of s.layers){if(!Ho.includes(h.type)||!x.hover||!x.n)continue;let{hx:M,hy:E}=x.hover,F=k.groups()??[],S=new Map;for(let B=0;B<x.n;B++){if(M[B]===null||E[B]===null)continue;let X=Math.abs(e(M[B])-o),q=F[B]??"";X<=kn&&(!S.has(q)||X<S.get(q).dx)&&S.set(q,{layer:h,view:x,c:k,k:B,dx:X,series:q})}l.push(...S.values())}if(!l.length)return null;let a=et.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)<=No);for(let h of u)h.y=n(h.view.hover.hy[h.k]);let p=et.least(u,h=>Math.abs(h.y-r)),f=i?.series!==void 0&&u.find(h=>h.layer===i.layer&&h.series===i.series);f&&Math.abs(f.y-r)<Math.abs(p.y-r)+Mn&&(p=f);let d=h=>h.layer.channels.color?.column?tt(t,null,h.view.cols.color[h.k]):h.series!==""?String(h.series):h.view.hover.fields[1]?.label??h.layer.type,g=h=>St(t,h.layer,h.view,h.c,h.k),y=a.view.hover.fields[0],w=tt(t,"x",a.view.hover.hx[a.k]),b={crosshair:c,anchor:{x:c,y:r},layer:p.layer,series:p.series};if(u.length===1||u.length>jo){let h=[{label:y?.label??"x",value:w},{label:p.view.hover.fields[1]?.label??"y",value:vn(t,p.layer,p.view,p.k)}],x=u.length-1;return{...b,color:g(p),header:d(p),rows:h,note:x?`${x} other series at this x`:null,marks:[{x:c,y:p.y,color:g(p)}]}}let m=Xo(t);u.sort((h,x)=>m(h)-m(x)||h.y-x.y);let v=u.map(h=>({swatch:g(h),label:d(h),value:vn(t,h.layer,h.view,h.k),strong:h===p}));return{...b,color:t.theme.ink,header:y?`${y.label} ${w}`:w,rows:v,marks:u.map(h=>({x:c,y:h.y,color:g(h)}))}}function Xo(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 vn(t,e,n,s){let o=n.hover.fields;return e.type==="smooth"&&o[2]?`${Ft(t,o[1],s)} (${Ft(t,o[2],s)})`:Ft(t,o[1],s)}function Go(t,e,n){for(let{layer:s,view:o,c:r}of e.layers)if(s.type==="box"&&o.n)return Uo(t,s,o,r,n);return null}function Vo(t,e,n,s){let{state:o,sx:r,sy:i}=t;for(let{layer:l,view:a,c}of e.layers){if(!Io.includes(l.type)||l.type==="box"||!a.n)continue;let u=l.type==="tile",p=null;for(let y=0;y<a.n;y++){let[w,b]=Ko(l,a,y,r),m=Math.abs((w+b)/2-n);if(u?n<w-me(r,b-w)||n>b+me(r,b-w):m>b-w)continue;let[v,h]=Zo(l,a,y,i),[x,k]=[Math.min(v,h),Math.max(v,h)],M=u?me(i,k-x):0,E=s>=x-M&&s<=k+M;if(u&&!E)continue;let F=Math.round(m)*1e6+(E?0:1e5+x);(!p||F<p.score)&&(p={k:y,score:F,rect:{x:w,y:x,width:b-w,height:k-x}})}if(!p)continue;let{k:f,rect:d}=p,g=St(o,l,a,c,f);if(u){let y=o.ns.labels.color??l.channels.color?.column??"value",w=l.channels.color?.column?tt(o,null,a.cols.color[f]):null,b=a.hover.fields.filter(m=>m.label!==y).map(m=>({label:m.label,value:Ft(o,m,f)}));return{color:g,header:w!==null?`${y} ${w}`:null,rows:b,marks:[{rect:d,color:o.theme.ink}],anchor:{x:d.x+d.width,y:s}}}return _o(o,l,a,c,f,d)}return null}function me(t,e){return t.bandwidth!==void 0?(t.step-t.bandwidth)/2||e*.125:.5}function _o(t,e,n,s,o,r){let i=e.type==="hist"?f=>n.cols.xmin[f]===n.cols.xmin[o]:f=>String(n.cols.x[f])===String(n.cols.x[o]),l=et.range(n.n).filter(i),a=!!e.channels.color?.column,c=l.sort((f,d)=>a&&t.color.kind==="ordinal"?t.color.domain.indexOf(n.cols.color[f])-t.color.domain.indexOf(n.cols.color[d]):n.cols.ymax[d]-n.cols.ymax[f]).map(f=>({swatch:St(t,e,n,s,f),label:a?tt(t,null,n.cols.color[f]):n.hover.fields[1].label,value:tt(t,null,n.cols.value[f]),strong:f===o&&l.length>1}));(e.options.position??"stack")==="stack"&&l.length>1&&c.push({label:"total",value:tt(t,null,et.sum(l,f=>n.cols.value[f])),strong:!1,total:!0});let p=n.hover.fields[0];return{color:St(t,e,n,s,o),header:`${p.label} ${Ft(t,p,o)}`,rows:c,marks:[{rect:r,color:t.theme.ink}],anchor:{x:r.x+r.width,y:r.y}}}function Uo({state:t,sx:e},n,s,o,r){if(e.bandwidth===void 0)return null;let i=et.range(s.n).find(v=>{let h=e.apply(s.cols.x[v]);return r>=h&&r<=h+e.bandwidth});if(i===void 0)return null;let l=String(s.cols.x[i]),{n:a,q1:c,median:u,q3:p,low:f,high:d,outliers:g}=Xt(et.range(s.n).filter(v=>String(s.cols.x[v])===l).map(v=>s.cols.y[v])),y=v=>tt(t,"y",v),w=[{label:"max (whisker)",value:y(d)},{label:"q3",value:y(p)},{label:"median",value:y(u),strong:!0},{label:"q1",value:y(c)},{label:"min (whisker)",value:y(f)},{label:"n",value:String(a)}];g.length&&w.push({label:"outliers",value:String(g.length)});let b=e.apply(s.cols.x[i]);return{color:n.channels.color?.column?St(t,n,s,o,i):t.theme.ink,header:`${s.hover.fields[0].label} ${l}`,rows:w,marks:[],anchor:{x:b+e.bandwidth,y:null}}}function Ko(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=An(e.cols.x,s),r=s.apply(e.cols.x[n]);return[r-o,r+o]}function Zo(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=An(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 An(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 Jo={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"/>',slide:'<rect x="3.5" y="4.5" width="17" height="11"/><path d="M12 15.5v4M8 19.5h8M7 12.5l3-3 2.5 2 4.5-4"/>',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"/>'},Qo=`
3
+ .pt-root{position:relative;--pt-size:24px}
4
+ .pt-root svg{display:block;user-select:none;-webkit-user-select:none}
5
+ .pt-root .pt-key{cursor:pointer}
6
+ .pt-root:focus{outline:none}
7
+ .pt-bar{position:absolute;top:6px;right:6px;display:flex;align-items:stretch;z-index:3;background:var(--pt-bg);
8
+ border:1px solid var(--pt-line);opacity:0;transition:opacity .12s ease}
9
+ .pt-root:hover .pt-bar,.pt-root:focus-within .pt-bar,.pt-bar.pt-open{opacity:1}
10
+ @media (hover:none){.pt-bar{opacity:1}}
11
+ .pt-btn{all:unset;box-sizing:border-box;display:grid;place-items:center;width:var(--pt-size);height:var(--pt-size);
12
+ color:var(--pt-muted);cursor:pointer}
13
+ .pt-btn svg{width:58%;height:58%;fill:none;stroke:currentColor;stroke-width:1.75;stroke-linecap:square;stroke-linejoin:miter}
14
+ .pt-btn:hover{color:var(--pt-ink);background:var(--pt-soft)}
15
+ .pt-btn:focus-visible{outline:2px solid var(--pt-accent);outline-offset:-2px}
16
+ .pt-btn.pt-on{color:var(--pt-on-accent);background:var(--pt-accent)}
17
+ .pt-sep{width:1px;background:var(--pt-line)}
18
+ .pt-menu{position:absolute;top:100%;right:-1px;display:none;flex-direction:column;min-width:72px;margin-top:-1px;
19
+ background:var(--pt-bg);border:1px solid var(--pt-line)}
20
+ .pt-menu.pt-open{display:flex}
21
+ .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}
22
+ .pt-menu button:hover{color:var(--pt-on-accent);background:var(--pt-accent)}
23
+ .pt-tip{position:absolute;display:none;pointer-events:none;z-index:4;min-width:110px;max-width:280px;background:var(--pt-bg);
24
+ color:var(--pt-ink);border:1px solid var(--pt-c);line-height:1.3;font-variant-numeric:tabular-nums}
25
+ .pt-tip.pt-pinned{border-width:2px;box-shadow:3px 3px 0 color-mix(in srgb,var(--pt-c) 35%,transparent)}
26
+ .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}
27
+ .pt-tip .pt-rows{display:grid;grid-template-columns:auto minmax(0,1fr) auto;column-gap:7px;row-gap:0;padding:4px 7px 5px}
28
+ .pt-tip .pt-sw{width:8px;height:8px;align-self:center}
29
+ .pt-tip .pt-k{color:var(--pt-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
30
+ .pt-tip .pt-v{text-align:right;white-space:nowrap}
31
+ .pt-tip .pt-b{color:var(--pt-ink);font-weight:700}
32
+ .pt-tip .pt-t{border-top:1px solid var(--pt-line);padding-top:2px;margin-top:1px}
33
+ .pt-tip .pt-more{grid-column:1/-1;color:var(--pt-muted);font-size:.9em}
34
+ .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}
35
+ `;function Sn(t){if(t.getElementById("plotto-style"))return;let e=t.createElement("style");e.id="plotto-style",e.textContent=Qo,t.head.append(e)}function Cn(t,e){let n={bg:e.background,ink:e.ink,muted:e.muted,line:e.grid,soft:e.strip,accent:e.accent,"on-accent":Te(e.accent)};for(let[s,o]of Object.entries(n))t.style.setProperty(`--pt-${s}`,o)}function Dn(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=Fn(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=tr(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=Fn("check"),a.title=l,a.classList.add("pt-on"),setTimeout(()=>(a.innerHTML=c,a.title=u,a.classList.remove("pt-on")),1100)}}}function tr(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 Fn(t){return`<svg viewBox="0 0 24 24" aria-hidden="true">${Jo[t]}</svg>`}var Ut=5,xe=320,Ln=.75,er=300,nr={width:645,height:403},or=3;function rr(t,e){let n=typeof t?.spec=="function"?t.spec():t,s={...n.theme,format:"slide",width:null,height:null,size:null},o=e.domains===e.home?void 0:e.domains;return _t({...n,theme:s},{document:e.doc,domains:o,hidden:e.hidden})}function Pn(t,e,{interactive:n=!1,width:s}={}){let o=e.ownerDocument;Sn(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=d=>{let g=l.state&&{domains:l.state.domains===l.state.home?void 0:l.state.domains,hidden:l.state.hidden},y=_t(t,{document:o,width:d,...g}),w=l.state?.svg;y.overlay=y.svg.appendChild(P(o,"g",{class:"pt-overlay","pointer-events":"none"})),y.theme.reflow||(y.svg.setAttribute("width","100%"),y.svg.removeAttribute("height"),r.style.maxWidth=`${y.W}px`),w?w.replaceWith(y.svg):r.prepend(y.svg),l.state=y,Cn(r,y.theme),p.setSize(y.theme.reflow?y.W:Math.min(y.W,e.clientWidth||y.W))},u=[[{name:"copy",title:"Copy as PNG",action:d=>he(l.state.svg).then(g=>p.flash("copy",g))},{name:"slide",title:"Copy for a slide",action:()=>he(rr(t,l.state).svg,nr,or).then(d=>p.flash("slide",d))},{name:"download",title:"Download",menu:[["PNG",()=>xn(l.state.svg)],["SVG",()=>yn(l.state.svg)]]}]];n&&u.unshift([{name:"zoom",title:"Zoom: drag a box",action:()=>f("zoom")},{name:"pan",title:"Pan: drag the view",action:()=>f("pan")}],[{name:"zoomIn",title:"Zoom in",action:()=>zn(l,Ln)},{name:"zoomOut",title:"Zoom out",action:()=>zn(l,1/Ln)},{name:"home",title:"Reset view (double-click)",action:()=>$n(l)}]);let p=Dn(o,u);r.append(p.el,i);let f=d=>{l.mode=d,p.button("zoom").classList.toggle("pt-on",d==="zoom"),p.button("pan").classList.toggle("pt-on",d==="pan"),r.style.cursor=d==="pan"?"grab":""};try{let d=s??(e.clientWidth?Math.max(xe,e.clientWidth):void 0);c(d),e.replaceChildren(r)}catch(d){let g=Object.assign(o.createElement("div"),{className:"pt-error",textContent:`plotto: ${d.message}`});throw e.prepend(g),d}if(n&&(f("zoom"),sr(l,r,i)),l.state.theme.reflow&&s===void 0&&typeof ResizeObserver<"u"){let d;a=new ResizeObserver(()=>{clearTimeout(d),d=setTimeout(()=>{let g=Math.max(xe,Math.round(e.clientWidth));g&&g!==l.state.W&&c(g)},100)}),a.observe(e)}return l.redraw=()=>ut(l.state),l.resize=d=>c(Math.max(xe,d)),l.destroy=()=>a?.disconnect(),l}function sr(t,e,n){let s=null,o=null,r=()=>t.state.svg,i=b=>{let m=r().getBoundingClientRect(),v=t.state.W/m.width;return[(b.clientX-m.left)*v,(b.clientY-m.top)*v,v]},l=(b,m)=>t.state.layout.panels.findIndex(v=>b>=v.x+v.ml&&b<=v.x+v.ml+v.innerW&&m>=v.y&&m<=v.y+v.innerH),a=!1;e.addEventListener("pointerdown",b=>{if(b.button!==0||!r().contains(b.target))return;let[m,v]=i(b),h=l(m,v);h<0||(b.preventDefault(),e.focus({preventScroll:!0}),s={i:h,x:m,y:v,domains:t.state.domains,moving:!1,id:b.pointerId})}),e.addEventListener("pointermove",b=>{let[m,v,h]=i(b);if(s&&!s.moving&&Math.hypot(m-s.x,v-s.y)>=Ut&&(s.moving=!0,e.setPointerCapture(s.id),u(),w(),t.mode==="pan"&&(e.style.cursor="grabbing")),!s?.moving){!a&&!o&&(o=requestAnimationFrame(()=>(o=null,y(m,v,h))));return}if(t.mode==="pan")return cr(t,s,m,v);let x=t.state.layout.panels[s.i],k=Z=>Math.max(x.x+x.ml,Math.min(x.x+x.ml+x.innerW,Z)),M=Z=>Math.max(x.y,Math.min(x.y+x.innerH,Z)),[E,F]=[s.x,k(m)].sort((Z,L)=>Z-L),[S,B]=[s.y,M(v)].sort((Z,L)=>Z-L),X=B-S<Ut||t.state.kind.y==="category",q=F-E<Ut||t.state.kind.x==="category";if(X&&q)return t.state.overlay.replaceChildren();let Ct={x:q?x.x+x.ml:E,y:X?x.y:S,width:q?x.innerW:F-E,height:X?x.innerH:B-S},pt=t.state.theme.accent;t.state.overlay.replaceChildren(P(t.state.doc,"rect",{...Ct,fill:pt,"fill-opacity":.1,stroke:pt,"stroke-opacity":.7,"stroke-width":1})),s.box={x0:E,x1:F,y0:S,y1:B}}),e.addEventListener("pointerup",b=>{if(s?.moving&&t.mode==="zoom"&&s.box)ar(t,s.i,s.box);else if(s&&!s.moving){let[m,v,h]=i(b);a?(u(),y(m,v,h)):(y(m,v,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&&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 p=b=>t.state.doc.elementFromPoint(b.clientX,b.clientY),f=b=>p(b)?.closest?.(".pt-key");e.addEventListener("dblclick",b=>{let[m,v]=i(b);l(m,v)<0||(u(),w(),$n(t))});let d={value:void 0,time:0,before:null};e.addEventListener("click",b=>{let m=f(b);if(!m)return;let v=t.state.legend.items[Number(m.dataset.index)].value;t.clearHover();let h=performance.now();if(v===d.value&&h-d.time<er)return t.state.hidden=d.before,d={value:void 0,time:0,before:null},lr(t,v);d={value:v,time:h,before:t.state.hidden};let x=new Set(t.state.hidden);x.has(v)?x.delete(v):x.add(v),t.state.hidden=x,ut(t.state)});let g=null;function y(b,m,v){let h=t.state,x=l(b,m),k=x<0?null:h.layout.panels[x],M=k?En(h,x,b-k.x,m-k.y,g):null;if(g=M,!M)return w();let E=h.doc,F=[];if(M.crosshair!==void 0){let L=k.x+M.crosshair;F.push(P(E,"line",{x1:L,x2:L,y1:k.y,y2:k.y+k.innerH,stroke:h.theme.muted,"stroke-opacity":.55,"stroke-width":1}))}for(let L of M.marks)L.rect?F.push(P(E,"rect",{x:k.x+L.rect.x,y:k.y+L.rect.y,width:L.rect.width,height:L.rect.height,fill:"none",stroke:L.color,"stroke-width":1.5})):F.push(P(E,"circle",{cx:k.x+L.x,cy:k.y+L.y,r:h.theme.point+1.5,fill:L.color,stroke:h.theme.background,"stroke-width":1.5}));h.overlay.replaceChildren(...F);let S=se(M.color);n.style.setProperty("--pt-c",S.bg),n.style.setProperty("--pt-on-c",S.fg),n.style.font=`${h.fonts.hover}px ${h.theme.font}`,n.replaceChildren(...ir(E,M)),n.style.display="block";let B=(k.x+M.anchor.x)/v,X=m/v,q=e.clientWidth,Ct=e.clientHeight,pt=B+16+n.offsetWidth>q?B-16-n.offsetWidth:B+16,Z=Math.min(Math.max(0,X-18),Math.max(0,Ct-n.offsetHeight));n.style.left=`${Math.max(0,pt)}px`,n.style.top=`${Z}px`}function w(){n.style.display="none",s||t.state.overlay.replaceChildren()}}function ir(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 $n(t){t.clearHover?.(),t.state.domains=t.state.home,ut(t.state)}function lr(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)),ut(t.state)}function ar(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,f,d)=>{if(i.kind[p]==="category"||d-f<Ut)return;let g=a.scale(p),y=p==="x"?l.x:l.y,w=[g.invert(f-y),g.invert(d-y)].map(Number).sort((b,m)=>b-m);Bn(i,p,e).forEach(b=>c[b][p]=w)};u("x",n,s),u("y",o,r),i.domains=c,ut(i)}function zn(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:f=>f,a=i==="log"?f=>10**f:f=>f,[c,u]=s[r].map(f=>l(+f)),p=(c+u)/2;o[r]=[a(p-(u-c)/2*e),a(p+(u-c)/2*e)]}return o}),ut(n)}function cr(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 f=i.scale(a),d=o.kind[a]==="log",g=b=>d?Math.log10(b):b,y=g(+f.invert(c-p))-g(+f.invert(u-p)),w=e.domains[e.i][a].map(b=>d?10**(g(b)+y):+b+y);Bn(o,a,e.i).forEach(b=>l[b][a]=w)}o.domains=l,o.frame||(o.frame=requestAnimationFrame(()=>(o.frame=null,ut(o))))}function Bn(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:Le,draw:Pn,toSVG:fn};
@@ -124,7 +124,7 @@
124
124
  "formats": {
125
125
  "screen": {
126
126
  "width": 900,
127
- "height": 450,
127
+ "height": 500,
128
128
  "size": 12,
129
129
  "line": 1.5,
130
130
  "point": 2.5,
@@ -139,9 +139,9 @@
139
139
  "reflow": false
140
140
  },
141
141
  "slide": {
142
- "width": 1280,
143
- "height": 720,
144
- "size": 20,
142
+ "width": 960,
143
+ "height": 600,
144
+ "size": 22,
145
145
  "line": 2.5,
146
146
  "point": 4,
147
147
  "reflow": false
@@ -199,6 +199,9 @@ class Plot:
199
199
  _fail("theme()", "format", options["format"], list(THEMES["formats"]))
200
200
  if "legend" in options and options["legend"] not in GRAMMAR["legend"]:
201
201
  _fail("theme()", "legend", options["legend"], GRAMMAR["legend"])
202
+ aspect = options.get("aspect")
203
+ if aspect is not None and (isinstance(aspect, bool) or not isinstance(aspect, (int, float)) or aspect <= 0):
204
+ raise ValueError("theme(): aspect must be a positive number (panel height / width), for example 1 for square panels")
202
205
  return self._with(theme={"style": style, **options})
203
206
 
204
207
  def interactive(self) -> Plot:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-plotto
3
- Version: 0.3.0
3
+ Version: 0.4.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/
@@ -54,6 +54,7 @@ def test_only_used_columns_go_into_the_spec():
54
54
  (lambda p: p.line(dash="wavy"), 'unknown dash "wavy"'),
55
55
  (lambda p: p.x(type="polar"), 'unknown type "polar"'),
56
56
  (lambda p: p.theme("wota", legend="left"), 'unknown legend "left"'),
57
+ (lambda p: p.theme(aspect=0), "aspect must be a positive number"),
57
58
  (lambda p: p.theme("fancy"), 'unknown style "fancy"'),
58
59
  (lambda p: p.theme(format="poster"), 'unknown format "poster"'),
59
60
  (lambda p: p.hist(density="yes"), "density must be True or False"),
@@ -28,7 +28,7 @@ def test_notebook_output_is_html_with_the_static_svg_inside():
28
28
  def test_save_width_lays_out_at_that_width(tmp_path):
29
29
  P.save(tmp_path / "wide.png", scale=1, width=1600)
30
30
  png = (tmp_path / "wide.png").read_bytes()
31
- assert (int.from_bytes(png[16:20], "big"), int.from_bytes(png[20:24], "big")) == (1600, 800)
31
+ assert (int.from_bytes(png[16:20], "big"), int.from_bytes(png[20:24], "big")) == (1600, 889) # the screen ratio, 900 × 500
32
32
 
33
33
 
34
34
  def test_repr_names_the_layers():
@@ -1,34 +0,0 @@
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};
File without changes
File without changes
File without changes