data-navigator 2.4.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-6CCTSMRV.js +1 -0
- package/dist/chunk-7YO7HC2V.js +1 -0
- package/dist/chunk-B5HGEXMZ.js +1 -0
- package/dist/chunk-EXUS2ZKK.js +1 -0
- package/dist/chunk-QT52GVQM.js +1 -0
- package/dist/chunk-UNB4R2QN.js +1 -0
- package/dist/chunk-UZ7O3OBE.js +1 -0
- package/dist/chunk-XDJWEEXI.js +1 -0
- package/dist/chunk-XOJI42HR.js +1 -0
- package/dist/chunk-YWWPZKYP.js +1 -0
- package/dist/chunk-ZP2ZNIC7.js +1 -0
- package/dist/chunk-ZTY2OAPD.js +1 -0
- package/dist/consts.cjs +1 -1
- package/dist/consts.js +1 -1
- package/dist/index.cjs +907 -35
- package/dist/index.d.cts +169 -2
- package/dist/index.d.ts +169 -2
- package/dist/index.js +892 -35
- package/dist/input.cjs +1 -1
- package/dist/input.js +1 -1
- package/dist/rendering.cjs +1 -1
- package/dist/rendering.js +1 -1
- package/dist/structure.cjs +1 -1
- package/dist/structure.js +1 -1
- package/dist/text-chat.cjs +10 -10
- package/dist/text-chat.js +6 -6
- package/dist/utilities.cjs +1 -1
- package/dist/utilities.js +1 -1
- package/package.json +1 -1
package/dist/input.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var p=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var
|
|
1
|
+
var p=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var v=(r,t)=>{for(var o in t)p(r,o,{get:t[o],enumerable:!0})},x=(r,t,o,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of m(t))!b.call(r,e)&&e!==o&&p(r,e,{get:()=>t[e],enumerable:!(l=k(t,e))||l.enumerable});return r};var h=r=>x(p({},"__esModule",{value:!0}),r);var E={};v(E,{default:()=>R});module.exports=h(E);var g={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down",Period:"forward",Comma:"backward",Escape:"drill-out",Enter:"drill-in"};var f={left:{key:"ArrowLeft",direction:"source"},right:{key:"ArrowRight",direction:"target"},up:{key:"ArrowUp",direction:"source"},down:{key:"ArrowDown",direction:"target"},"drill-in":{key:"Enter",direction:"target"},"drill-out":{key:"Backspace",direction:"source"},backward:{key:"Comma",direction:"source"},forward:{key:"Period",direction:"target"},previous:{key:"Semicolon",direction:"source"},next:{key:"Quote",direction:"target"},exit:{key:"Escape",direction:"target"},help:{key:"KeyY",direction:"target"},undo:{key:"KeyZ",direction:"target"}};var R=r=>{let t={},o=g,l=f;return t.moveTo=e=>{let i=r.structure.nodes[e];if(i)return i},t.move=(e,i)=>{if(e){let a=r.structure.nodes[e];if(a.edges){let d=null,s=0,u=l[i];if(!u)return;let w=(c,n)=>{if(c!==i)return null;let y={target:typeof n.target=="string"?n.target:n.target(a,e),source:typeof n.source=="string"?n.source:n.source(a,e)};return y[u.direction]!==e?y[u.direction]:null};for(s=0;s<a.edges.length;s++){let c=r.structure.edges[a.edges[s]];if(c.navigationRules.forEach(n=>{d||(d=w(n,c))}),d)break}return d?t.moveTo(d):void 0}}},t.enter=()=>{if(r.entryPoint)return t.moveTo(r.entryPoint);console.error("No entry point was specified in InputOptions, returning undefined")},t.exit=()=>{if(r.exitPoint)return r.exitPoint;console.error("No exit point was specified in InputOptions, returning undefined")},t.keydownValidator=e=>{let i=o[e.code];if(i)return i},t.focus=e=>{let i=document.getElementById(e);i&&i.focus()},t.setNavigationKeyBindings=e=>{e?(o={},l=e,Object.keys(e).forEach(i=>{let a=e[i];o[a.key]=i})):(o=g,l=f)},t.setNavigationKeyBindings(r.navigationRules),t};
|
package/dist/input.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-QT52GVQM.js";import"./chunk-B5HGEXMZ.js";export{a as default};
|
package/dist/rendering.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var b=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames,N=Object.getOwnPropertySymbols;var T=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var O=(e,r,i)=>r in e?b(e,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[r]=i,o=(e,r)=>{for(var i in r||(r={}))T.call(r,i)&&O(e,i,r[i]);if(N)for(var i of N(r))j.call(r,i)&&O(e,i,r[i]);return e};var F=(e,r)=>{for(var i in r)b(e,i,{get:r[i],enumerable:!0})},U=(e,r,i,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let m of I(r))!T.call(e,m)&&m!==i&&b(e,m,{get:()=>r[m],enumerable:!(t=K(r,m))||t.enumerable});return e};var z=e=>U(b({},"__esModule",{value:!0}),e);var $={};F($,{default:()=>G});module.exports=z($);var w={cssClass:void 0,spatialProperties:{x:0,y:0,width:0,height:0,path:""},semantics:{label:"",elementType:"div",role:"image",attributes:void 0},parentSemantics:{label:"",elementType:"figure",role:"figure",attributes:void 0},existingElement:{useForSpatialProperties:!1,spatialProperties:void 0}};var G=e=>{let r=l=>{t.wrapper.setAttribute("aria-activedescendant",l.srcElement.id)},i=()=>{t.wrapper.setAttribute("aria-activedescendant","")},t={},m=!1,n={cssClass:w.cssClass,spatialProperties:o({},w.spatialProperties),semantics:o({},w.semantics),parentSemantics:o({},w.parentSemantics),existingElement:o({},w.existingElement)};return e.defaults&&(n.cssClass=e.defaults.cssClass||n.cssClass,n.spatialProperties=e.defaults.spatialProperties?o(o({},n.spatialProperties),e.defaults.spatialProperties):n.spatialProperties,n.semantics=e.defaults.semantics?o(o({},n.semantics),e.defaults.semantics):n.semantics,n.parentSemantics=e.defaults.parentSemantics?o(o({},n.parentSemantics),e.defaults.parentSemantics):n.parentSemantics,n.existingElement=e.defaults.existingElement?o(o({},n.existingElement),e.defaults.existingElement):n.existingElement),t.initialize=()=>{var l;if(m){console.error(`The renderer wrapper has already been initialized successfully, RenderingOptions.suffixId is: ${e.suffixId}. No further action was taken.`);return}if(e.root&&document.getElementById(e.root.id))t.root=document.getElementById(e.root.id);else{console.error("No root element found, cannot build: RenderingOptions.root.id must reference an existing DOM element in order to render children.");return}if(t.root.style.position="relative",t.root.classList.add("dn-root"),!e.suffixId){console.error("No suffix id found: options.suffixId must be specified.");return}return t.wrapper=document.createElement("div"),t.wrapper.id="dn-wrapper-"+e.suffixId,t.wrapper.setAttribute("role","application"),t.wrapper.setAttribute("aria-label",e.root.description||"Data navigation structure"),t.wrapper.setAttribute("aria-activedescendant",""),t.wrapper.classList.add("dn-wrapper"),t.wrapper.style.width=e.root&&e.root.width?e.root.width:"100%",e.root&&e.root.height&&(t.wrapper.style.height=e.root.height),e.entryButton&&e.entryButton.include&&(t.entryButton=document.createElement("button"),t.entryButton.id="dn-entry-button-"+e.suffixId,t.entryButton.classList.add("dn-entry-button"),t.entryButton.innerText="Enter navigation area",e.entryButton.callbacks&&e.entryButton.callbacks.click&&t.entryButton.addEventListener("click",e.entryButton.callbacks.click),e.entryButton.callbacks&&e.entryButton.callbacks.focus&&t.entryButton.addEventListener("focus",e.entryButton.callbacks.focus),t.wrapper.appendChild(t.entryButton)),t.root.appendChild(t.wrapper),(l=e.exitElement)!=null&&l.include&&(t.exitElement=document.createElement("div"),t.exitElement.id="dn-exit-"+e.suffixId,t.exitElement.classList.add("dn-exit-position"),t.exitElement.innerText="End of data structure.",t.exitElement.setAttribute("aria-label","End of data structure."),t.exitElement.setAttribute("role","note"),t.exitElement.setAttribute("tabindex","-1"),t.exitElement.style.display="none",t.exitElement.addEventListener("focus",d=>{var c,y;t.exitElement.style.display="block",t.clearStructure(),(y=(c=e.exitElement)==null?void 0:c.callbacks)!=null&&y.focus&&e.exitElement.callbacks.focus(d)}),t.exitElement.addEventListener("blur",d=>{var c,y;t.exitElement.style.display="none",(y=(c=e.exitElement)==null?void 0:c.callbacks)!=null&&y.blur&&e.exitElement.callbacks.blur(d)}),t.root.appendChild(t.exitElement)),m=!0,t.root},t.render=l=>{let d=l.renderId+"",c=e.elementData[d];if(!c){console.warn(`Render data not found with renderId: ${d}. Failed to render.`);return}if(!m){console.error("render() was called before initialize(), renderer must be initialized first.");return}let y=!1,B={},s=(u,g,p)=>{var C;let f=c[u]||n[u],A=p&&y?B[g]:f==null?void 0:f[g],D=(C=n[u])==null?void 0:C[g];return typeof f=="function"?f(c,l.datum):typeof A=="function"?A(c,l.datum):A||D||(g?void 0:f)};y=s("existingElement","useForSpatialProperties"),B=s("existingElement","spatialProperties");let L=parseFloat(s("spatialProperties","width",!0)||0),P=parseFloat(s("spatialProperties","height",!0)||0),h=parseFloat(s("spatialProperties","x",!0)||0),E=parseFloat(s("spatialProperties","y",!0)||0),a=document.createElement(s("parentSemantics","elementType")),k=s("parentSemantics","attributes");typeof k=="object"&&Object.keys(k).forEach(u=>{a.setAttribute(u,k[u])}),a.setAttribute("role",s("parentSemantics","role")),a.id=d,a.classList.add("dn-node"),a.classList.add(s("cssClass")),a.style.width=L+"px",a.style.height=P+"px",a.style.left=h+"px",a.style.top=E+"px",a.setAttribute("tabindex","0"),a.addEventListener("focus",r),a.addEventListener("blur",i);let x=document.createElement(s("semantics","elementType")),v=s("semantics","attributes");typeof v=="object"&&Object.keys(v).forEach(u=>{a.setAttribute(u,v[u])}),x.setAttribute("role",s("semantics","role")),x.classList.add("dn-node-text"),c.showText&&(x.innerText=c.semantics.label);let S=s("semantics","label");S||console.error("Accessibility error: a label must be supplied to every rendered element using semantics.label."),x.setAttribute("aria-label",S),a.appendChild(x);let R=s("spatialProperties","path");if(R){let u=L+h+10,g=P+E+10,p=document.createElementNS("http://www.w3.org/2000/svg","svg");p.setAttribute("width",u+""),p.setAttribute("height",g+""),p.setAttribute("viewBox",`0 0 ${u} ${g}`),p.style.left=-h+"px",p.style.top=-E+"px",p.classList.add("dn-node-svg"),p.setAttribute("role","presentation"),p.setAttribute("focusable","false");let f=document.createElementNS("http://www.w3.org/2000/svg","path");f.setAttribute("d",R),f.classList.add("dn-node-path"),p.appendChild(f),a.appendChild(p)}return t.wrapper.appendChild(a),a},t.remove=l=>{let d=document.getElementById(l);t.wrapper.getAttribute("aria-activedescendant")===l&&t.wrapper.setAttribute("aria-activedescendant",""),d&&(d.removeEventListener("focus",r),d.removeEventListener("blur",i),d.remove())},t.clearStructure=()=>{[...t.wrapper.children].forEach(l=>{t.entryButton&&t.entryButton===l||t.remove(l.id)})},t};
|
|
1
|
+
var T=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames,H=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable;var _=(e,r,n)=>r in e?T(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,p=(e,r)=>{for(var n in r||(r={}))W.call(r,n)&&_(e,n,r[n]);if(H)for(var n of H(r))X.call(r,n)&&_(e,n,r[n]);return e};var ee=(e,r)=>{for(var n in r)T(e,n,{get:r[n],enumerable:!0})},te=(e,r,n,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let l of q(r))!W.call(e,l)&&l!==n&&T(e,l,{get:()=>r[l],enumerable:!(t=Y(r,l))||t.enumerable});return e};var re=e=>te(T({},"__esModule",{value:!0}),e);var z=(e,r,n)=>{if(!r.has(e))throw TypeError("Cannot "+n)};var f=(e,r,n)=>(z(e,r,"read from private field"),n?n.call(e):r.get(e)),B=(e,r,n)=>{if(r.has(e))throw TypeError("Cannot add the same private member more than once");r instanceof WeakSet?r.add(e):r.set(e,n)},N=(e,r,n,t)=>(z(e,r,"write to private field"),t?t.call(e,n):r.set(e,n),n);var R=(e,r,n)=>(z(e,r,"access private method"),n);var se={};ee(se,{default:()=>ie});module.exports=re(se);var P={cssClass:void 0,spatialProperties:{x:0,y:0,width:0,height:0,path:""},semantics:{label:"",elementType:"div",role:"image",attributes:void 0},parentSemantics:{label:"",elementType:"figure",role:"figure",attributes:void 0},existingElement:{useForSpatialProperties:!1,spatialProperties:void 0}},Z={ArrowLeft:"\u2190",ArrowRight:"\u2192",ArrowUp:"\u2191",ArrowDown:"\u2193",Enter:"Enter",Backspace:"Backspace",Escape:"Esc",Space:"Space",Tab:"Tab",BracketLeft:"[",BracketRight:"]",Backslash:"\\",Slash:"/",Comma:",",Period:".",Semicolon:";",Quote:"'",Minus:"-",Equal:"="},J={"drill-in":{label:"Enter",description:"Drill in"},"drill-out":{label:"Backspace",description:"Drill out"},exit:{label:"Esc",description:"Exit"},left:{label:"\u2190",description:"Previous data point"},right:{label:"\u2192",description:"Next data point"},up:{label:"\u2191",description:"Previous data point"},down:{label:"\u2193",description:"Next data point"},backward:{label:",",description:"Move backward"},forward:{label:".",description:"Move forward"},previous:{label:";",description:"Previous"},next:{label:"'",description:"Next"},undo:{label:"Z",description:"Undo"},help:{label:"Y",description:"Help"},legend:{label:"L",description:"Legend"}},Q=[{label:"Command",id:"description"},{label:"Key",id:"label"}];var S,k,v,y,x,D,j=class extends HTMLElement{constructor(){super(...arguments);B(this,x);B(this,S,[]);B(this,k,Q);B(this,v,"label");B(this,y,!1)}static get observedAttributes(){return["title"]}set commands(n){N(this,S,n),f(this,y)&&R(this,x,D).call(this)}get commands(){return f(this,S)}set columns(n){N(this,k,n),f(this,y)&&R(this,x,D).call(this)}get columns(){return f(this,k)}set kbdColumn(n){N(this,v,n),f(this,y)&&R(this,x,D).call(this)}get kbdColumn(){return f(this,v)}attributeChangedCallback(){f(this,y)&&R(this,x,D).call(this)}connectedCallback(){N(this,y,!0),R(this,x,D).call(this)}disconnectedCallback(){N(this,y,!1)}};S=new WeakMap,k=new WeakMap,v=new WeakMap,y=new WeakMap,x=new WeakSet,D=function(){this.replaceChildren();let n=[];for(let s of f(this,k)){let d=document.createElement("th");d.classList.add("dn-commands-table-th"),d.textContent=s.label,n.push(d)}let t=document.createElement("tr");t.classList.add("dn-commands-table-thead-tr");for(let s of n)t.appendChild(s);let l=document.createElement("thead");l.classList.add("dn-commands-table-thead"),l.appendChild(t);let o=document.createElement("tbody");o.classList.add("dn-commands-table-tbody");for(let s of f(this,S)){let d=[];for(let i of f(this,k)){let A=s[i.id],w=document.createElement("td");if(w.classList.add("dn-commands-table-td"),f(this,v)!==null&&i.id===f(this,v)&&A){let E=document.createElement("kbd");E.classList.add("dn-commands-table-td-kbd"),E.textContent=A,w.append(E)}else w.textContent=A;d.push(w)}let m=document.createElement("tr");m.classList.add("dn-commands-table-tbody-tr");for(let i of d)m.appendChild(i);o.appendChild(m)}let a=document.createElement("table");a.classList.add("dn-commands-table");let c=this.getAttribute("title");if(c){let s=document.createElement("caption");s.classList.add("dn-commands-table-caption"),s.textContent=c,a.appendChild(s)}else a.setAttribute("aria-label","Commands table");a.appendChild(l),a.appendChild(o),this.appendChild(a)};var ne=e=>e?Z[e]||e.replace(/^Key/,"").replace(/^Digit/,""):"",ae=e=>{let r=e.replace(/[-_]+/g," ").trim();return r.charAt(0).toUpperCase()+r.slice(1)};function G(e,r){return e?Object.keys(e).map(n=>{let t=e[n],l=J[n];return{label:t!=null&&t.key?ne(t.key):(l==null?void 0:l.label)||"",description:(r==null?void 0:r[n])||(l==null?void 0:l.description)||ae(n),command:n}}):[]}var ie=e=>{let r=a=>{t.wrapper.setAttribute("aria-activedescendant",a.srcElement.id)},n=()=>{t.wrapper.setAttribute("aria-activedescendant","")},t={},l=!1,o={cssClass:P.cssClass,spatialProperties:p({},P.spatialProperties),semantics:p({},P.semantics),parentSemantics:p({},P.parentSemantics),existingElement:p({},P.existingElement)};return e.defaults&&(o.cssClass=e.defaults.cssClass||o.cssClass,o.spatialProperties=e.defaults.spatialProperties?p(p({},o.spatialProperties),e.defaults.spatialProperties):o.spatialProperties,o.semantics=e.defaults.semantics?p(p({},o.semantics),e.defaults.semantics):o.semantics,o.parentSemantics=e.defaults.parentSemantics?p(p({},o.parentSemantics),e.defaults.parentSemantics):o.parentSemantics,o.existingElement=e.defaults.existingElement?p(p({},o.existingElement),e.defaults.existingElement):o.existingElement),t.initialize=()=>{var a,c;if(l){console.error(`The renderer wrapper has already been initialized successfully, RenderingOptions.suffixId is: ${e.suffixId}. No further action was taken.`);return}if(e.root&&document.getElementById(e.root.id))t.root=document.getElementById(e.root.id);else{console.error("No root element found, cannot build: RenderingOptions.root.id must reference an existing DOM element in order to render children.");return}if(t.root.style.position="relative",t.root.classList.add("dn-root"),!e.suffixId){console.error("No suffix id found: options.suffixId must be specified.");return}return t.wrapper=document.createElement("div"),t.wrapper.id="dn-wrapper-"+e.suffixId,t.wrapper.setAttribute("role","application"),t.wrapper.setAttribute("aria-label",e.root.description||"Data navigation structure"),t.wrapper.setAttribute("aria-activedescendant",""),t.wrapper.classList.add("dn-wrapper"),t.wrapper.style.width=e.root&&e.root.width?e.root.width:"100%",e.root&&e.root.height&&(t.wrapper.style.height=e.root.height),(a=e.commandsElement)!=null&&a.include&&t.initializeCommands(e.commandsElement),e.entryButton&&e.entryButton.include&&(t.entryButton=document.createElement("button"),t.entryButton.id="dn-entry-button-"+e.suffixId,t.entryButton.classList.add("dn-entry-button"),t.entryButton.innerText="Enter navigation area",e.entryButton.callbacks&&e.entryButton.callbacks.click&&t.entryButton.addEventListener("click",e.entryButton.callbacks.click),e.entryButton.callbacks&&e.entryButton.callbacks.focus&&t.entryButton.addEventListener("focus",e.entryButton.callbacks.focus),t.wrapper.appendChild(t.entryButton)),t.root.appendChild(t.wrapper),(c=e.exitElement)!=null&&c.include&&(t.exitElement=document.createElement("div"),t.exitElement.id="dn-exit-"+e.suffixId,t.exitElement.classList.add("dn-exit-position"),t.exitElement.innerText="End of data structure.",t.exitElement.setAttribute("aria-label","End of data structure."),t.exitElement.setAttribute("role","note"),t.exitElement.setAttribute("tabindex","-1"),t.exitElement.style.display="none",t.exitElement.addEventListener("focus",s=>{var d,m;t.exitElement.style.display="block",t.clearStructure(),(m=(d=e.exitElement)==null?void 0:d.callbacks)!=null&&m.focus&&e.exitElement.callbacks.focus(s)}),t.exitElement.addEventListener("blur",s=>{var d,m;t.exitElement.style.display="none",(m=(d=e.exitElement)==null?void 0:d.callbacks)!=null&&m.blur&&e.exitElement.callbacks.blur(s)}),t.root.appendChild(t.exitElement)),l=!0,t.root},t.render=a=>{let c=a.renderId+"",s=e.elementData[c];if(!s){console.warn(`Render data not found with renderId: ${c}. Failed to render.`);return}if(!l){console.error("render() was called before initialize(), renderer must be initialized first.");return}let d=!1,m={},i=(b,C,h)=>{var $;let g=s[b]||o[b],U=h&&d?m[C]:g==null?void 0:g[C],V=($=o[b])==null?void 0:$[C];return typeof g=="function"?g(s,a.datum):typeof U=="function"?U(s,a.datum):U||V||(C?void 0:g)};d=i("existingElement","useForSpatialProperties"),m=i("existingElement","spatialProperties");let A=parseFloat(i("spatialProperties","width",!0)||0),w=parseFloat(i("spatialProperties","height",!0)||0),E=parseFloat(i("spatialProperties","x",!0)||0),K=parseFloat(i("spatialProperties","y",!0)||0),u=document.createElement(i("parentSemantics","elementType")),I=i("parentSemantics","attributes");typeof I=="object"&&Object.keys(I).forEach(b=>{u.setAttribute(b,I[b])}),u.setAttribute("role",i("parentSemantics","role")),u.id=c,u.classList.add("dn-node"),u.classList.add(i("cssClass")),u.style.width=A+"px",u.style.height=w+"px",u.style.left=E+"px",u.style.top=K+"px",u.setAttribute("tabindex","0"),u.addEventListener("focus",r),u.addEventListener("blur",n);let L=document.createElement(i("semantics","elementType")),F=i("semantics","attributes");typeof F=="object"&&Object.keys(F).forEach(b=>{L.setAttribute(b,F[b])}),L.setAttribute("role",i("semantics","role")),L.classList.add("dn-node-text");let O=i("semantics","label");s.showText&&(L.innerText=O),O||console.error("Accessibility error: a label must be supplied to every rendered element using semantics.label."),L.setAttribute("aria-label",O),u.appendChild(L);let M=i("spatialProperties","path");if(M){let b=A+E+10,C=w+K+10,h=document.createElementNS("http://www.w3.org/2000/svg","svg");h.setAttribute("width",b+""),h.setAttribute("height",C+""),h.setAttribute("viewBox",`0 0 ${b} ${C}`),h.style.left=-E+"px",h.style.top=-K+"px",h.classList.add("dn-node-svg"),h.setAttribute("role","presentation"),h.setAttribute("focusable","false");let g=document.createElementNS("http://www.w3.org/2000/svg","path");g.setAttribute("d",M),g.classList.add("dn-node-path"),h.appendChild(g),u.appendChild(h)}return t.wrapper.appendChild(u),u},t.remove=a=>{let c=document.getElementById(a);t.wrapper.getAttribute("aria-activedescendant")===a&&t.wrapper.setAttribute("aria-activedescendant",""),c&&(c.removeEventListener("focus",r),c.removeEventListener("blur",n),c.remove())},t.clearStructure=()=>{[...t.wrapper.children].forEach(a=>{t.entryButton&&t.entryButton===a||t.remove(a.id)})},t.initializeCommands=a=>{let c=document.getElementById(a==null?void 0:a.rootId);if(!c){console.error("Commands root element not found in document.");return}let s=a.commands,d=G(a.navigationRules,a.descriptions),m=s?typeof s=="function"?s(d):s:d;customElements.get("dn-commands-table")||customElements.define("dn-commands-table",j);let i=document.createElement("dn-commands-table");return a!=null&&a.title&&i.setAttribute("title",a.title),i.commands=m,a.columns&&(i.columns=a.columns),c.appendChild(i),i},t.getGenericCommandsFromNavRules=G,t.CommandsTable=j,t};
|
package/dist/rendering.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{d as M}from"./chunk-ZTY2OAPD.js";import{a as o,c as m,d as k,e as B,f as P,q as S,t as V}from"./chunk-B5HGEXMZ.js";var I,w,v,h,E,T,j=class extends HTMLElement{constructor(){super(...arguments);k(this,E);k(this,I,[]);k(this,w,V);k(this,v,"label");k(this,h,!1)}static get observedAttributes(){return["title"]}set commands(b){B(this,I,b),m(this,h)&&P(this,E,T).call(this)}get commands(){return m(this,I)}set columns(b){B(this,w,b),m(this,h)&&P(this,E,T).call(this)}get columns(){return m(this,w)}set kbdColumn(b){B(this,v,b),m(this,h)&&P(this,E,T).call(this)}get kbdColumn(){return m(this,v)}attributeChangedCallback(){m(this,h)&&P(this,E,T).call(this)}connectedCallback(){B(this,h,!0),P(this,E,T).call(this)}disconnectedCallback(){B(this,h,!1)}};I=new WeakMap,w=new WeakMap,v=new WeakMap,h=new WeakMap,E=new WeakSet,T=function(){this.replaceChildren();let b=[];for(let a of m(this,w)){let i=document.createElement("th");i.classList.add("dn-commands-table-th"),i.textContent=a.label,b.push(i)}let e=document.createElement("tr");e.classList.add("dn-commands-table-thead-tr");for(let a of b)e.appendChild(a);let x=document.createElement("thead");x.classList.add("dn-commands-table-thead"),x.appendChild(e);let r=document.createElement("tbody");r.classList.add("dn-commands-table-tbody");for(let a of m(this,I)){let i=[];for(let s of m(this,w)){let A=a[s.id],C=document.createElement("td");if(C.classList.add("dn-commands-table-td"),m(this,v)!==null&&s.id===m(this,v)&&A){let y=document.createElement("kbd");y.classList.add("dn-commands-table-td-kbd"),y.textContent=A,C.append(y)}else C.textContent=A;i.push(C)}let c=document.createElement("tr");c.classList.add("dn-commands-table-tbody-tr");for(let s of i)c.appendChild(s);r.appendChild(c)}let n=document.createElement("table");n.classList.add("dn-commands-table");let l=this.getAttribute("title");if(l){let a=document.createElement("caption");a.classList.add("dn-commands-table-caption"),a.textContent=l,n.appendChild(a)}else n.setAttribute("aria-label","Commands table");n.appendChild(x),n.appendChild(r),this.appendChild(n)};var X=t=>{let R=n=>{e.wrapper.setAttribute("aria-activedescendant",n.srcElement.id)},b=()=>{e.wrapper.setAttribute("aria-activedescendant","")},e={},x=!1,r={cssClass:S.cssClass,spatialProperties:o({},S.spatialProperties),semantics:o({},S.semantics),parentSemantics:o({},S.parentSemantics),existingElement:o({},S.existingElement)};return t.defaults&&(r.cssClass=t.defaults.cssClass||r.cssClass,r.spatialProperties=t.defaults.spatialProperties?o(o({},r.spatialProperties),t.defaults.spatialProperties):r.spatialProperties,r.semantics=t.defaults.semantics?o(o({},r.semantics),t.defaults.semantics):r.semantics,r.parentSemantics=t.defaults.parentSemantics?o(o({},r.parentSemantics),t.defaults.parentSemantics):r.parentSemantics,r.existingElement=t.defaults.existingElement?o(o({},r.existingElement),t.defaults.existingElement):r.existingElement),e.initialize=()=>{var n,l;if(x){console.error(`The renderer wrapper has already been initialized successfully, RenderingOptions.suffixId is: ${t.suffixId}. No further action was taken.`);return}if(t.root&&document.getElementById(t.root.id))e.root=document.getElementById(t.root.id);else{console.error("No root element found, cannot build: RenderingOptions.root.id must reference an existing DOM element in order to render children.");return}if(e.root.style.position="relative",e.root.classList.add("dn-root"),!t.suffixId){console.error("No suffix id found: options.suffixId must be specified.");return}return e.wrapper=document.createElement("div"),e.wrapper.id="dn-wrapper-"+t.suffixId,e.wrapper.setAttribute("role","application"),e.wrapper.setAttribute("aria-label",t.root.description||"Data navigation structure"),e.wrapper.setAttribute("aria-activedescendant",""),e.wrapper.classList.add("dn-wrapper"),e.wrapper.style.width=t.root&&t.root.width?t.root.width:"100%",t.root&&t.root.height&&(e.wrapper.style.height=t.root.height),(n=t.commandsElement)!=null&&n.include&&e.initializeCommands(t.commandsElement),t.entryButton&&t.entryButton.include&&(e.entryButton=document.createElement("button"),e.entryButton.id="dn-entry-button-"+t.suffixId,e.entryButton.classList.add("dn-entry-button"),e.entryButton.innerText="Enter navigation area",t.entryButton.callbacks&&t.entryButton.callbacks.click&&e.entryButton.addEventListener("click",t.entryButton.callbacks.click),t.entryButton.callbacks&&t.entryButton.callbacks.focus&&e.entryButton.addEventListener("focus",t.entryButton.callbacks.focus),e.wrapper.appendChild(e.entryButton)),e.root.appendChild(e.wrapper),(l=t.exitElement)!=null&&l.include&&(e.exitElement=document.createElement("div"),e.exitElement.id="dn-exit-"+t.suffixId,e.exitElement.classList.add("dn-exit-position"),e.exitElement.innerText="End of data structure.",e.exitElement.setAttribute("aria-label","End of data structure."),e.exitElement.setAttribute("role","note"),e.exitElement.setAttribute("tabindex","-1"),e.exitElement.style.display="none",e.exitElement.addEventListener("focus",a=>{var i,c;e.exitElement.style.display="block",e.clearStructure(),(c=(i=t.exitElement)==null?void 0:i.callbacks)!=null&&c.focus&&t.exitElement.callbacks.focus(a)}),e.exitElement.addEventListener("blur",a=>{var i,c;e.exitElement.style.display="none",(c=(i=t.exitElement)==null?void 0:i.callbacks)!=null&&c.blur&&t.exitElement.callbacks.blur(a)}),e.root.appendChild(e.exitElement)),x=!0,e.root},e.render=n=>{let l=n.renderId+"",a=t.elementData[l];if(!a){console.warn(`Render data not found with renderId: ${l}. Failed to render.`);return}if(!x){console.error("render() was called before initialize(), renderer must be initialized first.");return}let i=!1,c={},s=(u,g,f)=>{var G;let p=a[u]||r[u],H=f&&i?c[g]:p==null?void 0:p[g],W=(G=r[u])==null?void 0:G[g];return typeof p=="function"?p(a,n.datum):typeof H=="function"?H(a,n.datum):H||W||(g?void 0:p)};i=s("existingElement","useForSpatialProperties"),c=s("existingElement","spatialProperties");let A=parseFloat(s("spatialProperties","width",!0)||0),C=parseFloat(s("spatialProperties","height",!0)||0),y=parseFloat(s("spatialProperties","x",!0)||0),N=parseFloat(s("spatialProperties","y",!0)||0),d=document.createElement(s("parentSemantics","elementType")),D=s("parentSemantics","attributes");typeof D=="object"&&Object.keys(D).forEach(u=>{d.setAttribute(u,D[u])}),d.setAttribute("role",s("parentSemantics","role")),d.id=l,d.classList.add("dn-node"),d.classList.add(s("cssClass")),d.style.width=A+"px",d.style.height=C+"px",d.style.left=y+"px",d.style.top=N+"px",d.setAttribute("tabindex","0"),d.addEventListener("focus",R),d.addEventListener("blur",b);let L=document.createElement(s("semantics","elementType")),F=s("semantics","attributes");typeof F=="object"&&Object.keys(F).forEach(u=>{L.setAttribute(u,F[u])}),L.setAttribute("role",s("semantics","role")),L.classList.add("dn-node-text");let z=s("semantics","label");a.showText&&(L.innerText=z),z||console.error("Accessibility error: a label must be supplied to every rendered element using semantics.label."),L.setAttribute("aria-label",z),d.appendChild(L);let $=s("spatialProperties","path");if($){let u=A+y+10,g=C+N+10,f=document.createElementNS("http://www.w3.org/2000/svg","svg");f.setAttribute("width",u+""),f.setAttribute("height",g+""),f.setAttribute("viewBox",`0 0 ${u} ${g}`),f.style.left=-y+"px",f.style.top=-N+"px",f.classList.add("dn-node-svg"),f.setAttribute("role","presentation"),f.setAttribute("focusable","false");let p=document.createElementNS("http://www.w3.org/2000/svg","path");p.setAttribute("d",$),p.classList.add("dn-node-path"),f.appendChild(p),d.appendChild(f)}return e.wrapper.appendChild(d),d},e.remove=n=>{let l=document.getElementById(n);e.wrapper.getAttribute("aria-activedescendant")===n&&e.wrapper.setAttribute("aria-activedescendant",""),l&&(l.removeEventListener("focus",R),l.removeEventListener("blur",b),l.remove())},e.clearStructure=()=>{[...e.wrapper.children].forEach(n=>{e.entryButton&&e.entryButton===n||e.remove(n.id)})},e.initializeCommands=n=>{let l=document.getElementById(n==null?void 0:n.rootId);if(!l){console.error("Commands root element not found in document.");return}let a=n.commands,i=M(n.navigationRules,n.descriptions),c=a?typeof a=="function"?a(i):a:i;customElements.get("dn-commands-table")||customElements.define("dn-commands-table",j);let s=document.createElement("dn-commands-table");return n!=null&&n.title&&s.setAttribute("title",n.title),s.commands=c,n.columns&&(s.columns=n.columns),l.appendChild(s),s},e.getGenericCommandsFromNavRules=M,e.CommandsTable=j,e};export{X as default};
|
package/dist/structure.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var M=Object.defineProperty,Ke=Object.defineProperties,Ie=Object.getOwnPropertyDescriptor,Ee=Object.getOwnPropertyDescriptors,xe=Object.getOwnPropertyNames,te=Object.getOwnPropertySymbols;var se=Object.prototype.hasOwnProperty,je=Object.prototype.propertyIsEnumerable;var ne=(e,d,i)=>d in e?M(e,d,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[d]=i,T=(e,d)=>{for(var i in d||(d={}))se.call(d,i)&&ne(e,i,d[i]);if(te)for(var i of te(d))je.call(d,i)&&ne(e,i,d[i]);return e},re=(e,d)=>Ke(e,Ee(d));var De=(e,d)=>{for(var i in d)M(e,i,{get:d[i],enumerable:!0})},Re=(e,d,i,c)=>{if(d&&typeof d=="object"||typeof d=="function")for(let h of xe(d))!se.call(e,h)&&h!==i&&M(e,h,{get:()=>d[h],enumerable:!(c=Ie(d,h))||c.enumerable});return e};var ke=e=>Re(M({},"__esModule",{value:!0}),e);var Ne={};De(Ne,{addSimpleDataIDs:()=>fe,buildEdges:()=>he,buildNodeStructureFromVegaLite:()=>ge,buildNodes:()=>ve,buildRules:()=>pe,buildStructure:()=>be,default:()=>we,scaffoldDimensions:()=>ye});module.exports=ke(Ne);var oe={Escape:!0,Enter:!0,Backspace:!0,ArrowLeft:!0,ArrowRight:!0,ArrowUp:!0,ArrowDown:!0};var de=["KeyW","KeyJ","LeftBracket","RightBracket","Slash","Backslash"];var ae=[["LeftBracket","RightBracket"],["Slash","Backslash"]],Z={left:{key:"ArrowLeft",direction:"source"},right:{key:"ArrowRight",direction:"target"},up:{key:"ArrowUp",direction:"source"},down:{key:"ArrowDown",direction:"target"},child:{key:"Enter",direction:"target"},parent:{key:"Backspace",direction:"source"},backward:{key:"Comma",direction:"source"},forward:{key:"Period",direction:"target"},previous:{key:"Semicolon",direction:"source"},next:{key:"Quote",direction:"target"},exit:{key:"Escape",direction:"target"},help:{key:"KeyY",direction:"target"},undo:{key:"KeyZ",direction:"target"}},le=[["left","right"],["up","down"],["backward","forward"],["previous","next"]];var ce={right:{key:"ArrowRight",direction:"target"},left:{key:"ArrowLeft",direction:"source"},down:{key:"ArrowDown",direction:"target"},up:{key:"ArrowUp",direction:"source"},child:{key:"Enter",direction:"target"},parent:{key:"Backspace",direction:"source"},exit:{key:"Escape",direction:"target"},undo:{key:"Period",direction:"target"},legend:{key:"KeyL",direction:"target"}};var ue=(e,d)=>{let i=Object.keys(e),c="";return i.forEach(h=>{c+=`${d&&d.omitKeyNames?"":h+": "}${e[h]}. `}),c+=d&&d.semanticLabel||"Data point.",c},H=e=>"_"+e.replace(/[^a-zA-Z0-9_-]+/g,"_");var we=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?ge(e):be(e),ge=e=>{let d=ce,i={},c={},h={},l=0,L=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,P=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,m=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,s=e.vegaLiteView._renderer._origin,p=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],E=(n,o)=>{if(n["data-navigator-id"])return n["data-navigator-id"];let a=`dn-node-${o}-${l}`;return l++,n["data-navigator-id"]=a,a},r=n=>{let o=i[n],a=o.index,u=o.level,y=o.parent,g=[],f=y.items[a-1];if(f){let v=E(f,u);if(i[v]){let K=`${v}-${o.id}`;g.push(K),c[K]||(c[K]={source:v,target:o.id,navigationRules:["left","right"]})}}let I=y.items[a+1];if(I){let v=E(I,u);if(i[v]){let K=`${o.id}-${v}`;g.push(K),c[K]||(c[K]={source:o.id,target:v,navigationRules:["left","right"]})}}if(u==="group"&&y.items[a].items){let K=(y.items[a].items[0].mark.items[0].items||y.items[a].items)[0],O=E(K,"item");if(i[O]){let t=`${o.id}-${O}`;g.push(t),c[t]||(c[t]={source:o.id,target:O,navigationRules:["parent","child"]})}}else if(u==="item"){let v=E(y,"group");if(i[v]){let K=`${v}-${o.id}`;g.push(K),c[K]||(c[K]={source:v,target:o.id,navigationRules:["parent","child"]})}}return e.exitFunction&&(g.push("any-exit"),c["any-exit"]||(c["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),g.push("any-undo"),c["any-undo"]||(c["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),g},x=(n,o,a,u,y)=>{let g=E(n,o),f="render-"+g,I=a||[0,0];i[g]={},i[g].d={},i[g].id=g,i[g].renderId=f,i[g].index=u,i[g].level=o,i[g].parent=y,h[f]={},h[f].renderId=f,h[f].spatialProperties={},h[f].spatialProperties.x=n.bounds.x1+I[0],h[f].spatialProperties.y=n.bounds.y1+I[1],h[f].spatialProperties.width=n.bounds.x2-n.bounds.x1,h[f].spatialProperties.height=n.bounds.y2-n.bounds.y1,h[f].cssClass="dn-vega-lite-node",n.datum&&Object.keys(n.datum).forEach(v=>{let K=n.datum[v];m(v,K,n.datum,o,e.vegaLiteSpec)&&(i[g].d[e.keyRenamingHash&&e.keyRenamingHash[v]?e.keyRenamingHash[v]:v]=K)}),h[f].semantics={},h[f].semantics.label=e.nodeDescriber?e.nodeDescriber(i[g].d,n,o):ue(i[g].d)},D=0;return p.items.forEach(n=>{if(L(n,D,e.vegaLiteSpec)){x(n,"group",s,D,p);let o=0,a=n.items[0].mark.items[0].items?n.items[0].mark.items[0]:n;a.items.forEach(u=>{P(u,o,n,e.vegaLiteSpec)&&x(u,"item",s,o,a),o++})}D++}),Object.keys(i).forEach(n=>{i[n].edges=r(n)}),{nodes:i,edges:c,elementData:h,navigationRules:d}},fe=e=>{let d=0,i={};e.data.forEach(c=>{let h=typeof e.idKey=="function"?e.idKey(c):e.idKey;c[h]="_"+d,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(l=>{l in c&&(typeof c[l]=="string"?(i[l]||(i[l]=0),i[c[l]]||(i[c[l]]=0),c[h]+="_"+l+i[l]+"_"+c[l]+i[c[l]],i[l]++,i[c[l]]++):(i[l]||(i[l]=0),c[h]+="_"+l+i[l],i[l]++))}),d++})},ve=e=>{let d={};return e.data.forEach(i=>{e.idKey||console.error("Building nodes. A key string must be supplied in options.idKey to specify the id keys of every node.");let c=typeof e.idKey=="function"?e.idKey(i):e.idKey,h=i[c];if(!h){console.error(`Building nodes. Each datum in options.data must contain an id. When matching the id key string ${c}, this datum has no id: ${JSON.stringify(i)}.`);return}if(d[h]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${h}.`);return}else{let l=typeof e.renderIdKey=="function"?e.renderIdKey(i):e.renderIdKey;d[h]={id:h,edges:[],renderId:l?i[l]||"":i.renderIdKey||"",data:i}}}),d},ye=(e,d)=>{var l,L,P;let i={};if((L=(l=e.dimensions)==null?void 0:l.parentOptions)!=null&&L.addLevel0){let m=e.dimensions.parentOptions.addLevel0;d[m.id]=re(T({},m),{dimensionLevel:0})}let c=[...le],h=(m,s)=>{let p=s.numericalExtents[0],E=s.numericalExtents[1];s.numericalExtents[0]=p<m?p:m,s.numericalExtents[1]=E>m?E:m};return e.data.forEach(m=>{var E;let s=((E=e.dimensions)==null?void 0:E.values)||[],p=0;s.forEach(r=>{var x,D,b,n,o,a,u,y;if(!r.dimensionKey){console.error(`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(r)}.`);return}if(r.dimensionKey in m){let g=m[r.dimensionKey],f=typeof((x=r.operations)==null?void 0:x.filterFunction)=="function"?r.operations.filterFunction(m,r):!0;if(g!==void 0&&f){if(r.type||(r.type=typeof g=="bigint"||typeof g=="number"?"numerical":"categorical"),!i[r.dimensionKey]){let O=typeof r.nodeId=="function"?r.nodeId(r,e.data):r.nodeId||H(r.dimensionKey),t=typeof r.renderId=="function"?r.renderId(r,e.data):r.renderId||O;i[r.dimensionKey]={dimensionKey:r.dimensionKey,nodeId:O,divisions:{},numericalExtents:[1/0,-1/0],type:r.type,operations:{compressSparseDivisions:((D=r.operations)==null?void 0:D.compressSparseDivisions)||!1,sortFunction:((b=r.operations)==null?void 0:b.sortFunction)||void 0},behavior:r.behavior||{extents:"circular"},navigationRules:r.navigationRules||{sibling_sibling:c.length?[...c.shift()]:["previous_"+r.dimensionKey,"next_"+r.dimensionKey],parent_child:["parent_"+r.dimensionKey,"child"]}},d[O]={id:O,renderId:t,derivedNode:r.dimensionKey,edges:[],dimensionLevel:1,data:i[r.dimensionKey],renderingStrategy:r.renderingStrategy||"singleSquare"}}let I=i[r.dimensionKey],v=null;if(r.type==="categorical"){let O=typeof((n=r.divisionOptions)==null?void 0:n.divisionNodeIds)=="function"?r.divisionOptions.divisionNodeIds(r.dimensionKey,g,p):H(I.nodeId+"_"+g);if(v=I.divisions[O],!v){v=I.divisions[O]={id:O,sortFunction:((o=r.divisionOptions)==null?void 0:o.sortFunction)||void 0,values:{}};let t=typeof((a=r.divisionOptions)==null?void 0:a.divisionRenderIds)=="function"?r.divisionOptions.divisionRenderIds(r.dimensionKey,g,p):O;d[O]={id:O,renderId:t,derivedNode:r.dimensionKey,edges:[],dimensionLevel:2,data:T({},v),renderingStrategy:((u=r.divisionOptions)==null?void 0:u.renderingStrategy)||"singleSquare"},d[O].data[r.dimensionKey]=g}}else{v=I.divisions[I.nodeId],v||(v=I.divisions[I.nodeId]={id:I.nodeId,sortFunction:((y=r.divisionOptions)==null?void 0:y.sortFunction)||void 0,values:{}}),r.operations||(r.operations={});let O=r.operations.createNumericalSubdivisions;I.subdivisions=typeof O=="number"&&O<1?1:O||1,O!==1&&(I.divisionOptions||(I.divisionOptions=r.divisionOptions),h(g,I))}let K=typeof e.idKey=="function"?e.idKey(m):e.idKey;v.values[m[K]]=m}}p++})}),Object.keys(i).forEach(m=>{var r,x,D,b,n;let s=i[m],p=s.divisions;if(s.type==="numerical"){p[s.nodeId].values=Object.fromEntries(Object.entries(p[s.nodeId].values).sort((a,u)=>{var y;return typeof((y=s.operations)==null?void 0:y.sortFunction)=="function"?s.operations.sortFunction(a[1],u[1],s):a[1][m]-u[1][m]}));let o=p[s.nodeId].values;if(s.numericalExtents[0]!==1/0&&s.subdivisions!==1){let a=Object.keys(o),u=typeof s.subdivisions=="function"?s.subdivisions(m,o):s.subdivisions,g=(s.numericalExtents[1]-s.numericalExtents[0])/u,f=s.numericalExtents[0]+g,I=0,v=0,K=null,O=s.numericalExtents[0];for(f=s.numericalExtents[0]+g;f<=s.numericalExtents[1];f+=g){let t=typeof((r=s.divisionOptions)==null?void 0:r.divisionNodeIds)=="function"?s.divisionOptions.divisionNodeIds(m,f,f):H(s.nodeId+"_"+f);K=t,s.divisions[t]={id:t,sortFunction:((x=s.divisionOptions)==null?void 0:x.sortFunction)||void 0,values:{},numericalExtents:[O,f]};let A=typeof((D=s.divisionOptions)==null?void 0:D.divisionRenderIds)=="function"?s.divisionOptions.divisionRenderIds(m,f,f):t;d[t]={id:t,renderId:A,derivedNode:m,edges:[],data:s.divisions[t],dimensionLevel:2,renderingStrategy:((b=s.divisionOptions)==null?void 0:b.renderingStrategy)||"singleSquare"};let q=!1;for(;!q&&v<a.length;){let G=o[a[v]];if(G[m]<=f){let R=typeof e.idKey=="function"?e.idKey(G):G[e.idKey];s.divisions[t].values[R]=G,v++}else q=!0}O=f,I++}if(K&&v<a.length)for(;v<a.length;){let t=o[a[v]],A=typeof e.idKey=="function"?e.idKey(t):t[e.idKey];s.divisions[K].values[A]=t,v++}delete p[s.nodeId]}}else typeof((n=s.operations)==null?void 0:n.sortFunction)=="function"&&(s.divisions=Object.fromEntries(Object.entries(p).sort((o,a)=>s.operations.sortFunction(o[1],a[1],s))));Object.keys(s.divisions).forEach(o=>{let a=s.divisions[o];typeof a.sortFunction=="function"&&(a.values=Object.fromEntries(Object.entries(a.values).sort((u,y)=>a.sortFunction(u[1],y[1],a))))})}),Object.keys(i).forEach(m=>{let s=i[m];if(s.operations.compressSparseDivisions){let p=Object.keys(s.divisions),E={},r=!0;if(p.forEach(x=>{let D=s.divisions[x],b=Object.keys(D.values);b.length<=1?b.forEach(n=>{E[n]=T({},D.values[n])}):r=!1}),r){let x={id:s.nodeId,values:E};p.forEach(D=>{delete d[D]}),s.divisions={},s.divisions[s.nodeId]=x}}}),(P=e.dimensions)!=null&&P.adjustDimensions&&(i=e.dimensions.adjustDimensions(i)),i},he=(e,d,i)=>{var L,P,m,s,p,E,r,x,D,b;let c={},h=(n,o)=>{d[n].edges.indexOf(o)===-1&&d[n].edges.push(o)},l=(n,o,a,u)=>{let y=`${n}-${o}`,g=e.useDirectedEdges?`${o}-${y}`:y,f=!u||u==="source",I=!u||u==="target",v=K=>{c[K]?c[K].navigationRules.push(...a||[]):c[K]={source:n,target:o,navigationRules:a?[...a]:[]}};v(y),e.useDirectedEdges&&I&&v(g),f&&h(n,y),I&&h(o,g)};if(i&&Object.keys(i).length){let n=Object.keys(i),o=(m=(P=(L=e.dimensions)==null?void 0:L.parentOptions)==null?void 0:P.level1Options)==null?void 0:m.order,a=o||n,u=0,y=((s=e.dimensions)==null?void 0:s.parentOptions)||{},g=((E=(p=y.level1Options)==null?void 0:p.behavior)==null?void 0:E.extents)||"terminal",f=y.addLevel0,I=f?((x=(r=y.level1Options)==null?void 0:r.navigationRules)==null?void 0:x.parent_child)||["parent","child"]:[],v=((b=(D=y.level1Options)==null?void 0:D.navigationRules)==null?void 0:b.sibling_sibling)||["left","right"],K=typeof a[0]=="string"?o?d[a[0]]:d[i[a[0]].nodeId]:a[0];f&&l(f.id,K.id,I,"source"),a.forEach(O=>{let t=typeof O=="string"?o?d[O]:d[i[O].nodeId]:O;if(t===O&&!d[t.id]&&(d[t.id]=t),f&&(e.useDirectedEdges?l(t.id,f.id,I,"source"):l(f.id,t.id,I,"target")),u===a.length-1&&g==="circular")l(t.id,K.id,v);else if(u===a.length-1&&g==="bridgedCustom")l(t.id,y.level1Options.behavior.customBridgePost,v);else if(u<a.length-1){let A=typeof a[u+1]=="string"?o?d[a[u+1]]:d[i[a[u+1]].nodeId]:a[u+1];l(t.id,A.id,v)}!u&&g==="bridgedCustom"&&l(y.level1Options.behavior.customBridgePost,t.id,v),u++}),n.forEach(O=>{var z,Q,X,ee;let t=i[O],A=((z=t.behavior)==null?void 0:z.childmostNavigation)||"within",q=(F,j,k,w)=>w.values[Object.keys(w.values)[F]]||void 0,G=A==="across"&&((Q=t.behavior)!=null&&Q.childmostMatching)?(X=t.behavior)==null?void 0:X.childmostMatching:q,S=((ee=t.behavior)==null?void 0:ee.extents)||"circular";t.divisions||console.error(`Parsing dimensions. The dimension using the key ${O} is missing the divisions property. dimension.divisions should be supplied. ${JSON.stringify(t)}.`);let R=Object.keys(t.divisions),J=t.divisions[R[0]];if(R.length!==1)l(t.nodeId,J.id,t.navigationRules.parent_child,"source");else{let F=Object.keys(J.values),j=typeof e.idKey=="function"?e.idKey(J.values[F[0]]):e.idKey;l(t.nodeId,J.values[F[0]][j],t.navigationRules.parent_child,"source")}let me=F=>{for(let j=1;j<R.length;j++){let k=(F+j)%R.length;if(Object.keys(t.divisions[R[k]].values).length>0)return k}return null},Oe=F=>{for(let j=1;j<R.length;j++){let k=(F-j+R.length)%R.length;if(Object.keys(t.divisions[R[k]].values).length>0)return k}return null},B=0;R.forEach(F=>{let j=t.divisions[F];B===R.length-1&&(S==="circular"||S==="bridgedCousins"||S==="bridgedCustom")?l(j.id,t.divisions[R[0]].id,t.navigationRules.sibling_sibling):B<R.length-1&&l(j.id,t.divisions[R[B+1]].id,t.navigationRules.sibling_sibling);let k=Object.keys(j.values);if(e.useDirectedEdges?l(j.id,t.nodeId,t.navigationRules.parent_child,"source"):l(t.nodeId,j.id,t.navigationRules.parent_child,"target"),k.length>0){let W=typeof e.idKey=="function"?e.idKey(j.values[k[0]]):e.idKey;l(j.id,j.values[k[0]][W],t.navigationRules.parent_child,"source")}let w=0;k.length>=1&&k.forEach(W=>{let N=j.values[W],_=typeof e.idKey=="function"?e.idKey(N):e.idKey,ie=R.length!==1?j.id:t.nodeId;if(e.useDirectedEdges?l(N[_],ie,t.navigationRules.parent_child,"source"):l(ie,N[_],t.navigationRules.parent_child,"target"),A==="within"){if(w===k.length-1&&S==="circular"){let C=typeof e.idKey=="function"?e.idKey(j.values[k[0]]):e.idKey;l(N[_],j.values[k[0]][C],t.navigationRules.sibling_sibling)}else if(w===k.length-1&&S==="bridgedCousins"){let C=me(B);if(C!==null){let $=t.divisions[R[C]].values,V=Object.keys($),U=$[V[0]],Y=typeof e.idKey=="function"?e.idKey(U):e.idKey;l(N[_],U[Y],t.navigationRules.sibling_sibling)}}else if(w===k.length-1&&S==="bridgedCustom")l(N[_],t.behavior.customBridgePost,t.navigationRules.sibling_sibling);else if(w<k.length-1){let C=typeof e.idKey=="function"?e.idKey(j.values[k[w+1]]):e.idKey;l(N[_],j.values[k[w+1]][C],t.navigationRules.sibling_sibling)}if(!w&&S==="bridgedCousins"){let C=Oe(B);if(C!==null){let $=t.divisions[R[C]].values,V=Object.keys($),U=$[V[V.length-1]],Y=typeof e.idKey=="function"?e.idKey(U):e.idKey;l(U[Y],N[_],t.navigationRules.sibling_sibling)}}else!w&&S==="bridgedCustom"&&l(t.behavior.customBridgePrevious,N[_],t.navigationRules.sibling_sibling)}else if(B===R.length-1&&S==="bridgedCustom")l(N[_],t.behavior.customBridgePost,t.navigationRules.sibling_sibling);else if(!B&&S==="bridgedCustom")l(t.behavior.customBridgePrevious,N[_],t.navigationRules.sibling_sibling);else{let C=B===R.length-1&&S==="circular"?t.divisions[R[0]]:t.divisions[R[B+1]];if(C){let $=G(w,N[_],j,C);if($){let V=typeof e.idKey=="function"?e.idKey($):e.idKey;l(N[_],$[V],t.navigationRules.sibling_sibling)}}}w++}),B++})})}return Object.keys(d).forEach(n=>{var a;let o=d[n];(a=e.genericEdges)!=null&&a.length&&e.genericEdges.forEach(u=>{c[u.edgeId]||(c[u.edgeId]=u.edge),(!u.conditional||u.conditional&&u.conditional(o,u))&&o.edges.push(u.edgeId)})}),c},pe=(e,d,i)=>{var h,l,L,P;let c=e.navigationRules;if(!c){let m=Object.keys(i||{});m.length>6&&console.error(`Building navigationRules. Dimension count is too high to automatically generate key commands. It is recommend you reduce your dimensions to 6 or fewer for end-user experience. If not, you must provide your own navigation rules in options.navigationRules. Details: Count is ${m.length}. Dimensions counted: ${m.join(", ")}.`);let s={},p={},E={},r=[...ae],x=[...de],D=(b,n)=>{let o=b&&n,a=!1,u=!1;if((s[b]||p[b])&&(p[b]=T({},s[b]),a=!0),n&&(s[n]||p[n])&&(p[n]=T({},s[n]),u=!0),o&&!a&&!u){r.length||console.error("Building navigationRules. Dimension count is too high to automatically generate key commands, we have run out of keyboard key pairs to assign. You must either provide your own navigation rules in options.navigationRules, provide rules when generating dimensions, or reduce dimension count.");let y=[...r.shift()];x.splice(x.indexOf(y[0]),1),x.splice(x.indexOf(y[1]),1),p[b]={direction:e.useDirectedEdges?"target":"source",key:y[0]},p[n]={direction:"target",key:y[1]}}else{if(!p[b]&&x.length){let y=x.shift(),g=[];r.forEach(f=>{y!==f[0]&&y!==f[1]&&g.push(f)}),r=g,p[b]={direction:e.useDirectedEdges?"target":"source",key:y}}if(n&&!p[n]&&x.length){let y=x.shift(),g=[];r.forEach(f=>{y!==f[0]&&y!==f[1]&&g.push(f)}),r=g,p[n]={direction:"target",key:y}}x.length||(p[b]||(E[b]=b),n&&!p[n]&&(E[n]=n))}};if(Object.keys(Z).forEach(b=>{let n=T({},Z[b]);e.useDirectedEdges&&(n.direction="target"),s[b]=n}),m.length){if((l=(h=e.dimensions)==null?void 0:h.parentOptions)!=null&&l.addLevel0){let b=((P=(L=e.dimensions.parentOptions.level1Options)==null?void 0:L.navigationRules)==null?void 0:P.parent_child)||["parent","child"];D(b[0],b[1])}m.forEach(b=>{let n=i[b].navigationRules.parent_child,o=i[b].navigationRules.sibling_sibling;D(n[0],n[1]),D(o[0],o[1])})}if(Object.keys(d).forEach(b=>{d[b].navigationRules.forEach(n=>{p[n]||D(n)})}),Object.keys(E).length){let b={};Object.keys(p).forEach(o=>{b[p[o].key]=p[o].key}),Object.keys(s).forEach(o=>{!b[s[o].key]&&!oe[s[o].key]&&x.push(s[o].key)});let n=T({},E);E={},Object.keys(n).forEach(o=>{D(o)}),Object.keys(E).length&&console.error(`Building navigationRules. There are no more keys left to assign automatically. Recommended fixes: use fewer dimensions, use fewer GenericEdges, or build your own navigationRules. Rules remaining without keyboard keys: ${Object.keys(E).join(", ")}.`)}c=p}return c},be=e=>{e.addIds&&fe(e);let d=ve(e),i=ye(e,d),c=he(e,d,i),h=pe(e,c,i);return{nodes:d,edges:c,dimensions:i,navigationRules:h}};0&&(module.exports={addSimpleDataIDs,buildEdges,buildNodeStructureFromVegaLite,buildNodes,buildRules,buildStructure,scaffoldDimensions});
|
|
1
|
+
var re=Object.defineProperty,ke=Object.defineProperties,De=Object.getOwnPropertyDescriptor,we=Object.getOwnPropertyDescriptors,Se=Object.getOwnPropertyNames,de=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable;var le=(e,t,n)=>t in e?re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,T=(e,t)=>{for(var n in t||(t={}))ce.call(t,n)&&le(e,n,t[n]);if(de)for(var n of de(t))_e.call(t,n)&&le(e,n,t[n]);return e},Y=(e,t)=>ke(e,we(t));var Ce=(e,t)=>{for(var n in t)re(e,n,{get:t[n],enumerable:!0})},Le=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Se(t))!ce.call(e,r)&&r!==n&&re(e,r,{get:()=>t[r],enumerable:!(i=De(t,r))||i.enumerable});return e};var $e=e=>Le(re({},"__esModule",{value:!0}),e);var Ae={};Ce(Ae,{addSimpleDataIDs:()=>Ie,buildEdges:()=>Ne,buildNodeStructureFromVegaLite:()=>Oe,buildNodes:()=>xe,buildRules:()=>Re,buildStructure:()=>je,default:()=>Be,scaffoldDimensions:()=>Ke});module.exports=$e(Ae);var ue={Escape:!0,Enter:!0,Backspace:!0,ArrowLeft:!0,ArrowRight:!0,ArrowUp:!0,ArrowDown:!0};var ge=["KeyW","KeyJ","BracketLeft","BracketRight","Slash","Backslash"];var fe=[["BracketLeft","BracketRight"],["Slash","Backslash"]],oe={left:{key:"ArrowLeft",direction:"source"},right:{key:"ArrowRight",direction:"target"},up:{key:"ArrowUp",direction:"source"},down:{key:"ArrowDown",direction:"target"},"drill-in":{key:"Enter",direction:"target"},"drill-out":{key:"Backspace",direction:"source"},backward:{key:"Comma",direction:"source"},forward:{key:"Period",direction:"target"},previous:{key:"Semicolon",direction:"source"},next:{key:"Quote",direction:"target"},exit:{key:"Escape",direction:"target"},help:{key:"KeyY",direction:"target"},undo:{key:"KeyZ",direction:"target"}},ye=[["left","right"],["up","down"],["backward","forward"],["previous","next"]];var ve={right:{key:"ArrowRight",direction:"target"},left:{key:"ArrowLeft",direction:"source"},down:{key:"ArrowDown",direction:"target"},up:{key:"ArrowUp",direction:"source"},"drill-in":{key:"Enter",direction:"target"},"drill-out":{key:"Backspace",direction:"source"},exit:{key:"Escape",direction:"target"},undo:{key:"Period",direction:"target"},legend:{key:"KeyL",direction:"target"}};var he=(e,t)=>{let n=Object.keys(e),i="";return n.forEach(r=>{i+=`${t&&t.omitKeyNames?"":r+": "}${e[r]}. `}),i+=t&&t.semanticLabel||"Data point.",i},ie=e=>"_"+e.replace(/[^a-zA-Z0-9_-]+/g,"_");var te=(e,t,n)=>{let i=(r,c)=>{let f=e[r];if(!f){console.error(`Building edges. Node ${r} does not exist, so edge ${c} was not added to it.`);return}f.edges||(f.edges=[]),f.edges.indexOf(c)===-1&&f.edges.push(c)};return(r,c,f,C)=>{if(!r||!c||r===c)return;let b=`${r}-${c}`,s=n?`${c}-${b}`:b,R=!C||C==="source",w=!C||C==="target",o=_=>{t[_]?(f||[]).forEach(L=>{t[_].navigationRules.indexOf(L)===-1&&t[_].navigationRules.push(L)}):t[_]={source:r,target:c,navigationRules:f?[...f]:[]}};o(b),n&&w&&o(s),R&&i(r,b),w&&i(c,s)}},W=(e,t,n,i="terminal")=>{for(let r=0;r<t.length-1;r++)e(t[r],t[r+1],n);i==="circular"&&t.length>1&&e(t[t.length-1],t[0],n)};var pe=e=>{var r,c,f;let t=e.frame,n=((c=(r=e.dimensions)==null?void 0:r.values)==null?void 0:c.length)||0;if(!t||n<2||(f=e.dimensions.parentOptions)!=null&&f.addLevel0)return e;let i=t.data||{id:"data",edges:[],semantics:{label:"Data"}};return Y(T({},e),{dimensions:Y(T({},e.dimensions),{parentOptions:Y(T({},e.dimensions.parentOptions||{}),{addLevel0:Y(T({},i),{edges:i.edges||[]})})})})},me=(e,t,n,i)=>{var L,K,v;let r=e.frame;if(!r)return;if(!i||!t[i]){console.error("Building frame. No top data node was found to place under the frame.");return}let c=te(t,n,e.useDirectedEdges),f=((L=r.navigationRules)==null?void 0:L.sibling_sibling)||["left","right"],C=((K=r.navigationRules)==null?void 0:K.parent_child)||["drill-out","drill-in"],b=((v=r.behavior)==null?void 0:v.extents)||"circular",s=r.root;t[s.id]=Y(T({},s),{edges:[...s.edges||[]],depth:0,frameRole:"root"});let R=(r.elements||[]).map(a=>(t[a.id]=Y(T({},a),{edges:[...a.edges||[]],depth:1,parentId:s.id,frameRole:"element"}),a.id)),w=i;r.data&&r.data.id!==i&&(t[r.data.id]=Y(T({},r.data),{edges:[...r.data.edges||[]]}),c(r.data.id,i,C,"source"),c(r.data.id,i,C,"target"),t[i].parentId=r.data.id,w=r.data.id);let o=t[w];o.frameRole="data",o.depth=1,o.parentId=s.id;let _=[...R,w];return c(s.id,_[0],C,"source"),_.forEach(a=>c(s.id,a,C,"target")),W(c,_,f,b),{rootId:s.id,elementIds:R,dataId:w,parentRules:C}};var be=(e,t,n)=>{var F,z,U;let i=e.spatialGrid;if(!i)return;let r=te(t,n,e.useDirectedEdges),c=((F=i.navigationRules)==null?void 0:F.x)||["left","right"],f=((z=i.navigationRules)==null?void 0:z.y)||["up","down"],C=((U=i.navigationRules)==null?void 0:U.parent_child)||["drill-out","drill-in"],b=i.extents||"terminal",s=i.levelNavigation!=="within",R=i.skipEmpty!==!1,w=i.leaves||"points",o=y=>y[typeof e.idKey=="function"?e.idKey(y):e.idKey],_=e.data.filter(y=>typeof y[i.xKey]=="number"&&typeof y[i.yKey]=="number"),L=(y,g)=>{if(g)return g;let I=1/0,O=-1/0;return _.forEach(x=>{I=Math.min(I,x[y]),O=Math.max(O,x[y])}),[I,O]},K=L(i.xKey,i.xExtent),v=L(i.yKey,i.yExtent),a=(y,[g,I],O)=>I===g?0:Math.max(0,Math.min(O-1,Math.floor((y-g)/(I-g)*O))),h=T(T({},{id:"grid",edges:[],semantics:{label:"Grid"}}),i.root||{});h.edges=h.edges||[],h.depth=0,h.data=Y(T({},h.data||{}),{xKey:i.xKey,yKey:i.yKey,xExtent:K,yExtent:v,levels:i.levels,count:_.length}),t[h.id]=h;let m=(y,g,I)=>i.cellIds?i.cellIds(y,g,I):ie(`${h.id}_L${y}_${g}_${I}`),u=[];i.levels.forEach((y,g)=>{let I={},O=(x,P)=>{let q=`${x}_${P}`;if(I[q])return I[q];let $=m(g,x,P),G=(K[1]-K[0])/y,V=(v[1]-v[0])/y,X=h.id;if(g>0){let H=i.levels[g-1],M=u[g-1][`${Math.floor(x*H/y)}_${Math.floor(P*H/y)}`];X=M==null?void 0:M.id,M==null||M.children.push($)}return I[q]={id:$,col:x,row:P,parent:X,children:[]},t[$]={id:$,renderId:$,edges:[],depth:g+1,parentId:X,data:{level:g,col:x,row:P,cellsPerAxis:y,xExtent:[K[0]+x*G,K[0]+(x+1)*G],yExtent:[v[0]+P*V,v[0]+(P+1)*V],count:0}},I[q]};if(!R)for(let x=0;x<y;x++)for(let P=0;P<y;P++)O(x,P);_.forEach(x=>O(a(x[i.xKey],K,y),a(x[i.yKey],v,y))),u.push(I)});let E=u[u.length-1],j=i.levels[i.levels.length-1],l=[],S={};_.forEach(y=>{let g=o(y);if(!t[g])return;i.levels.forEach((O,x)=>{let P=u[x][`${a(y[i.xKey],K,O)}_${a(y[i.yKey],v,O)}`];t[P.id].data.count++});let I=E[`${a(y[i.xKey],K,j)}_${a(y[i.yKey],v,j)}`];I.children.push(g),S[g]=I.id,l.push(g),t[g].parentId=I.id,t[g].depth=i.levels.length+1});let D=(y,g)=>g.row-y.row||y.col-g.col,N=Object.values(u[0]).sort(D);N.length&&r(h.id,N[0].id,C,"source"),N.forEach(y=>r(h.id,y.id,C,"target"));let d=y=>t[y].data;u.forEach((y,g)=>{Object.values(y).forEach(I=>{if(!I.children.length)return;let O;g===u.length-1?O=[...I.children].sort((x,P)=>k(x,P))[0]:O=[...I.children].sort((x,P)=>D(d(x),d(P)))[0],r(I.id,O,C,"source"),I.children.forEach(x=>r(I.id,x,C,"target"))})});let Z=y=>{let g={},I={};y.forEach(O=>{let x=d(O);(g[x.row]=g[x.row]||[]).push(O),(I[x.col]=I[x.col]||[]).push(O)}),Object.values(g).forEach(O=>W(r,O.sort((x,P)=>d(x).col-d(P).col),c,b)),Object.values(I).forEach(O=>W(r,O.sort((x,P)=>d(P).row-d(x).row),f,b))};u.forEach((y,g)=>{let I=Object.values(y);if(s||g===0)Z(I.map(O=>O.id));else{let O={};I.forEach(x=>(O[x.parent]=O[x.parent]||[]).push(x.id)),Object.values(O).forEach(Z)}});function k(y,g){let I=t[y].data,O=t[g].data;return I[i.xKey]-O[i.xKey]||O[i.yKey]-I[i.yKey]}let B=(y,g)=>{let I=t[y].data,O=t[g].data;return O[i.yKey]-I[i.yKey]||I[i.xKey]-O[i.xKey]},A=y=>{if(w==="cells"){let g={},I={};y.forEach(O=>{let x=t[O].data;(g[x[i.yKey]]=g[x[i.yKey]]||[]).push(O),(I[x[i.xKey]]=I[x[i.xKey]]||[]).push(O)}),Object.values(g).forEach(O=>W(r,O.sort(k),c,b)),Object.values(I).forEach(O=>W(r,O.sort(B),f,b))}else W(r,[...y].sort(k),c,b),W(r,[...y].sort(B),f,b)};return s?A(l):Object.values(E).forEach(y=>A(y.children)),{rootId:h.id,levels:i.levels,cellsByLevel:u.map(y=>Object.values(y).map(g=>g.id)),leafIds:l,parentRules:C}};var Ee=(e,t,n)=>{var _,L;let i=e.hierarchy;if(!i)return;let r=te(t,n,e.useDirectedEdges),c=((_=i.navigationRules)==null?void 0:_.sibling_sibling)||["left","right"],f=((L=i.navigationRules)==null?void 0:L.parent_child)||["drill-out","drill-in"],C=i.extents||"circular",b=K=>K[typeof e.idKey=="function"?e.idKey(K):e.idKey],s={},R;if(e.data.forEach(K=>{let v=b(K),a=K[i.parentKey];if(a==null||a===""){if(R){console.error(`Building hierarchy. More than one root was found: ${R} and ${v}. Using ${R}.`);return}R=v}else s[a]||(s[a]=[]),s[a].push(K)}),!R){console.error("Building hierarchy. No root row was found. One row must have an empty parent.");return}let w=[],o=(K,v,a)=>{let p=t[K];if(!p){console.error(`Building hierarchy. Row ${K} has no node. Check idKey.`);return}p.depth=a,v&&(p.parentId=v),w[a]||(w[a]=[]),w[a].push(K);let h=s[K]||[];i.sortFunction&&(h=[...h].sort((u,E)=>i.sortFunction(u,E)));let m=h.map(b);p.childCount=m.length,m.length&&(r(K,m[0],f,"source"),m.forEach(u=>r(K,u,f,"target")),i.levelNavigation!=="across"&&W(r,m,c,C)),m.forEach(u=>o(u,K,a+1))};return o(R,void 0,0),i.levelNavigation==="across"&&w.forEach(K=>W(r,K,c,C)),{rootId:R,depthCount:w.length,parentRules:f}};var Be=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?Oe(e):je(e),Oe=e=>{let t=ve,n={},i={},r={},c=0,f=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,C=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,b=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,s=e.vegaLiteView._renderer._origin,R=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],w=(v,a)=>{if(v["data-navigator-id"])return v["data-navigator-id"];let p=`dn-node-${a}-${c}`;return c++,v["data-navigator-id"]=p,p},o=v=>{let a=n[v],p=a.index,h=a.level,m=a.parent,u=[],E=m.items[p-1];if(E){let l=w(E,h);if(n[l]){let S=`${l}-${a.id}`;u.push(S),i[S]||(i[S]={source:l,target:a.id,navigationRules:["left","right"]})}}let j=m.items[p+1];if(j){let l=w(j,h);if(n[l]){let S=`${a.id}-${l}`;u.push(S),i[S]||(i[S]={source:a.id,target:l,navigationRules:["left","right"]})}}if(h==="group"&&m.items[p].items){let S=(m.items[p].items[0].mark.items[0].items||m.items[p].items)[0],D=w(S,"item");if(n[D]){let N=`${a.id}-${D}`;u.push(N),i[N]||(i[N]={source:a.id,target:D,navigationRules:["drill-out","drill-in"]})}}else if(h==="item"){let l=w(m,"group");if(n[l]){let S=`${l}-${a.id}`;u.push(S),i[S]||(i[S]={source:l,target:a.id,navigationRules:["drill-out","drill-in"]})}}return e.exitFunction&&(u.push("any-exit"),i["any-exit"]||(i["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),u.push("any-undo"),i["any-undo"]||(i["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),u},_=(v,a,p,h,m)=>{let u=w(v,a),E="render-"+u,j=p||[0,0];n[u]={},n[u].d={},n[u].id=u,n[u].renderId=E,n[u].index=h,n[u].level=a,n[u].parent=m,r[E]={},r[E].renderId=E,r[E].spatialProperties={},r[E].spatialProperties.x=v.bounds.x1+j[0],r[E].spatialProperties.y=v.bounds.y1+j[1],r[E].spatialProperties.width=v.bounds.x2-v.bounds.x1,r[E].spatialProperties.height=v.bounds.y2-v.bounds.y1,r[E].cssClass="dn-vega-lite-node",v.datum&&Object.keys(v.datum).forEach(l=>{let S=v.datum[l];b(l,S,v.datum,a,e.vegaLiteSpec)&&(n[u].d[e.keyRenamingHash&&e.keyRenamingHash[l]?e.keyRenamingHash[l]:l]=S)}),r[E].semantics={},r[E].semantics.label=e.nodeDescriber?e.nodeDescriber(n[u].d,v,a):he(n[u].d)},L=0;return R.items.forEach(v=>{if(f(v,L,e.vegaLiteSpec)){_(v,"group",s,L,R);let a=0,p=v.items[0].mark.items[0].items?v.items[0].mark.items[0]:v;p.items.forEach(h=>{C(h,a,v,e.vegaLiteSpec)&&_(h,"item",s,a,p),a++})}L++}),Object.keys(n).forEach(v=>{n[v].edges=o(v)}),{nodes:n,edges:i,elementData:r,navigationRules:t}},Ie=e=>{let t=0,n={};e.data.forEach(i=>{let r=typeof e.idKey=="function"?e.idKey(i):e.idKey;i[r]="_"+t,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(c=>{c in i&&(typeof i[c]=="string"?(n[c]||(n[c]=0),n[i[c]]||(n[i[c]]=0),i[r]+="_"+c+n[c]+"_"+i[c]+n[i[c]],n[c]++,n[i[c]]++):(n[c]||(n[c]=0),i[r]+="_"+c+n[c],n[c]++))}),t++})},xe=e=>{let t={};return e.data.forEach(n=>{e.idKey||console.error("Building nodes. A key string must be supplied in options.idKey to specify the id keys of every node.");let i=typeof e.idKey=="function"?e.idKey(n):e.idKey,r=n[i];if(!r){console.error(`Building nodes. Each datum in options.data must contain an id. When matching the id key string ${i}, this datum has no id: ${JSON.stringify(n)}.`);return}if(t[r]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${r}.`);return}else{let c=typeof e.renderIdKey=="function"?e.renderIdKey(n):e.renderIdKey;t[r]={id:r,edges:[],renderId:c?n[c]||"":n.renderIdKey||"",data:n}}}),t},Ke=(e,t)=>{var c,f,C;let n={};if((f=(c=e.dimensions)==null?void 0:c.parentOptions)!=null&&f.addLevel0){let b=e.dimensions.parentOptions.addLevel0;t[b.id]=Y(T({},b),{dimensionLevel:0})}let i=[...ye],r=(b,s)=>{let R=s.numericalExtents[0],w=s.numericalExtents[1];s.numericalExtents[0]=R<b?R:b,s.numericalExtents[1]=w>b?w:b};return e.data.forEach(b=>{var w;let s=((w=e.dimensions)==null?void 0:w.values)||[],R=0;s.forEach(o=>{var _,L,K,v,a,p,h,m;if(!o.dimensionKey){console.error(`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(o)}.`);return}if(o.dimensionKey in b){let u=b[o.dimensionKey],E=typeof((_=o.operations)==null?void 0:_.filterFunction)=="function"?o.operations.filterFunction(b,o):!0;if(u!==void 0&&E){if(o.type||(o.type=typeof u=="bigint"||typeof u=="number"?"numerical":"categorical"),!n[o.dimensionKey]){let D=typeof o.nodeId=="function"?o.nodeId(o,e.data):o.nodeId||ie(o.dimensionKey),N=typeof o.renderId=="function"?o.renderId(o,e.data):o.renderId||D;n[o.dimensionKey]={dimensionKey:o.dimensionKey,nodeId:D,divisions:{},numericalExtents:[1/0,-1/0],type:o.type,operations:{compressSparseDivisions:((L=o.operations)==null?void 0:L.compressSparseDivisions)||!1,sortFunction:((K=o.operations)==null?void 0:K.sortFunction)||void 0},behavior:o.behavior||{extents:"circular"},navigationRules:o.navigationRules||{sibling_sibling:i.length?[...i.shift()]:["previous_"+o.dimensionKey,"next_"+o.dimensionKey],parent_child:["drill-out_"+o.dimensionKey,"drill-in"]}},t[D]={id:D,renderId:N,derivedNode:o.dimensionKey,edges:[],dimensionLevel:1,data:n[o.dimensionKey],renderingStrategy:o.renderingStrategy||"singleSquare"}}let j=n[o.dimensionKey],l=null;if(o.type==="categorical"){let D=typeof((v=o.divisionOptions)==null?void 0:v.divisionNodeIds)=="function"?o.divisionOptions.divisionNodeIds(o.dimensionKey,u,R):ie(j.nodeId+"_"+u);if(l=j.divisions[D],!l){l=j.divisions[D]={id:D,sortFunction:((a=o.divisionOptions)==null?void 0:a.sortFunction)||void 0,values:{}};let N=typeof((p=o.divisionOptions)==null?void 0:p.divisionRenderIds)=="function"?o.divisionOptions.divisionRenderIds(o.dimensionKey,u,R):D;t[D]={id:D,renderId:N,derivedNode:o.dimensionKey,edges:[],dimensionLevel:2,data:T({},l),renderingStrategy:((h=o.divisionOptions)==null?void 0:h.renderingStrategy)||"singleSquare"},t[D].data[o.dimensionKey]=u}}else{l=j.divisions[j.nodeId],l||(l=j.divisions[j.nodeId]={id:j.nodeId,sortFunction:((m=o.divisionOptions)==null?void 0:m.sortFunction)||void 0,values:{}}),o.operations||(o.operations={});let D=o.operations.createNumericalSubdivisions;j.subdivisions=typeof D=="number"&&D<1?1:D||1,D!==1&&(j.divisionOptions||(j.divisionOptions=o.divisionOptions),r(u,j))}let S=typeof e.idKey=="function"?e.idKey(b):e.idKey;l.values[b[S]]=b}}R++})}),Object.keys(n).forEach(b=>{var o,_,L,K,v;let s=n[b],R=s.divisions;if(s.type==="numerical"){R[s.nodeId].values=Object.fromEntries(Object.entries(R[s.nodeId].values).sort((p,h)=>{var m;return typeof((m=s.operations)==null?void 0:m.sortFunction)=="function"?s.operations.sortFunction(p[1],h[1],s):p[1][b]-h[1][b]}));let a=R[s.nodeId].values;if(s.numericalExtents[0]!==1/0&&s.subdivisions!==1){let p=Object.keys(a),h=typeof s.subdivisions=="function"?s.subdivisions(b,a):s.subdivisions,u=(s.numericalExtents[1]-s.numericalExtents[0])/h,E=s.numericalExtents[0]+u,j=0,l=0,S=null,D=s.numericalExtents[0];for(E=s.numericalExtents[0]+u;E<=s.numericalExtents[1];E+=u){let N=typeof((o=s.divisionOptions)==null?void 0:o.divisionNodeIds)=="function"?s.divisionOptions.divisionNodeIds(b,E,E):ie(s.nodeId+"_"+E);S=N,s.divisions[N]={id:N,sortFunction:((_=s.divisionOptions)==null?void 0:_.sortFunction)||void 0,values:{},numericalExtents:[D,E]};let d=typeof((L=s.divisionOptions)==null?void 0:L.divisionRenderIds)=="function"?s.divisionOptions.divisionRenderIds(b,E,E):N;t[N]={id:N,renderId:d,derivedNode:b,edges:[],data:s.divisions[N],dimensionLevel:2,renderingStrategy:((K=s.divisionOptions)==null?void 0:K.renderingStrategy)||"singleSquare"};let Z=!1;for(;!Z&&l<p.length;){let k=a[p[l]];if(k[b]<=E){let A=typeof e.idKey=="function"?e.idKey(k):k[e.idKey];s.divisions[N].values[A]=k,l++}else Z=!0}D=E,j++}if(S&&l<p.length)for(;l<p.length;){let N=a[p[l]],d=typeof e.idKey=="function"?e.idKey(N):N[e.idKey];s.divisions[S].values[d]=N,l++}delete R[s.nodeId]}}else typeof((v=s.operations)==null?void 0:v.sortFunction)=="function"&&(s.divisions=Object.fromEntries(Object.entries(R).sort((a,p)=>s.operations.sortFunction(a[1],p[1],s))));Object.keys(s.divisions).forEach(a=>{let p=s.divisions[a];typeof p.sortFunction=="function"&&(p.values=Object.fromEntries(Object.entries(p.values).sort((h,m)=>p.sortFunction(h[1],m[1],p))))})}),Object.keys(n).forEach(b=>{let s=n[b];if(s.operations.compressSparseDivisions){let R=Object.keys(s.divisions),w={},o=!0;if(R.forEach(_=>{let L=s.divisions[_],K=Object.keys(L.values);K.length<=1?K.forEach(v=>{w[v]=T({},L.values[v])}):o=!1}),o){let _={id:s.nodeId,values:w};R.forEach(L=>{delete t[L]}),s.divisions={},s.divisions[s.nodeId]=_}}}),(C=e.dimensions)!=null&&C.adjustDimensions&&(n=e.dimensions.adjustDimensions(n)),n},Ne=(e,t,n,i)=>{var C,b,s,R,w,o,_,L,K,v;let r=i||{},c=(a,p)=>{t[a].edges.indexOf(p)===-1&&t[a].edges.push(p)},f=(a,p,h,m)=>{let u=`${a}-${p}`,E=e.useDirectedEdges?`${p}-${u}`:u,j=!m||m==="source",l=!m||m==="target",S=D=>{r[D]?r[D].navigationRules.push(...h||[]):r[D]={source:a,target:p,navigationRules:h?[...h]:[]}};S(u),e.useDirectedEdges&&l&&S(E),j&&c(a,u),l&&c(p,E)};if(n&&Object.keys(n).length){let a=Object.keys(n),p=(s=(b=(C=e.dimensions)==null?void 0:C.parentOptions)==null?void 0:b.level1Options)==null?void 0:s.order,h=p||a,m=0,u=((R=e.dimensions)==null?void 0:R.parentOptions)||{},E=((o=(w=u.level1Options)==null?void 0:w.behavior)==null?void 0:o.extents)||"terminal",j=u.addLevel0,l=j?((L=(_=u.level1Options)==null?void 0:_.navigationRules)==null?void 0:L.parent_child)||["drill-out","drill-in"]:[],S=((v=(K=u.level1Options)==null?void 0:K.navigationRules)==null?void 0:v.sibling_sibling)||["left","right"],D=typeof h[0]=="string"?p?t[h[0]]:t[n[h[0]].nodeId]:h[0];j&&f(j.id,D.id,l,"source"),h.forEach(N=>{let d=typeof N=="string"?p?t[N]:t[n[N].nodeId]:N;if(d===N&&!t[d.id]&&(t[d.id]=d),j&&(e.useDirectedEdges?f(d.id,j.id,l,"source"):f(j.id,d.id,l,"target")),m===h.length-1&&E==="circular")f(d.id,D.id,S);else if(m===h.length-1&&E==="bridgedCustom")f(d.id,u.level1Options.behavior.customBridgePost,S);else if(m<h.length-1){let Z=typeof h[m+1]=="string"?p?t[h[m+1]]:t[n[h[m+1]].nodeId]:h[m+1];f(d.id,Z.id,S)}!m&&E==="bridgedCustom"&&f(u.level1Options.behavior.customBridgePrevious,d.id,S),m++}),a.forEach(N=>{var I,O,x,P;let d=n[N],Z=((I=d.behavior)==null?void 0:I.childmostNavigation)||"within",k=(q,$,G,V)=>V.values[Object.keys(V.values)[q]]||void 0,B=Z==="across"&&((O=d.behavior)!=null&&O.childmostMatching)?(x=d.behavior)==null?void 0:x.childmostMatching:k,A=((P=d.behavior)==null?void 0:P.extents)||"circular";d.divisions||console.error(`Parsing dimensions. The dimension using the key ${N} is missing the divisions property. dimension.divisions should be supplied. ${JSON.stringify(d)}.`);let F=Object.keys(d.divisions),z=d.divisions[F[0]];if(F.length!==1)f(d.nodeId,z.id,d.navigationRules.parent_child,"source");else{let q=Object.keys(z.values),$=typeof e.idKey=="function"?e.idKey(z.values[q[0]]):e.idKey;f(d.nodeId,z.values[q[0]][$],d.navigationRules.parent_child,"source")}let U=q=>{for(let $=1;$<F.length;$++){let G=(q+$)%F.length;if(Object.keys(d.divisions[F[G]].values).length>0)return G}return null},y=q=>{for(let $=1;$<F.length;$++){let G=(q-$+F.length)%F.length;if(Object.keys(d.divisions[F[G]].values).length>0)return G}return null},g=0;F.forEach(q=>{let $=d.divisions[q];g===F.length-1&&(A==="circular"||A==="bridgedCousins"||A==="bridgedCustom")?f($.id,d.divisions[F[0]].id,d.navigationRules.sibling_sibling):g<F.length-1&&f($.id,d.divisions[F[g+1]].id,d.navigationRules.sibling_sibling);let G=Object.keys($.values);if(e.useDirectedEdges?f($.id,d.nodeId,d.navigationRules.parent_child,"source"):f(d.nodeId,$.id,d.navigationRules.parent_child,"target"),G.length>0){let X=typeof e.idKey=="function"?e.idKey($.values[G[0]]):e.idKey;f($.id,$.values[G[0]][X],d.navigationRules.parent_child,"source")}let V=0;G.length>=1&&G.forEach(X=>{let H=$.values[X],M=typeof e.idKey=="function"?e.idKey(H):e.idKey,ae=F.length!==1?$.id:d.nodeId;if(e.useDirectedEdges?f(H[M],ae,d.navigationRules.parent_child,"source"):f(ae,H[M],d.navigationRules.parent_child,"target"),Z==="within"){if(V===G.length-1&&A==="circular"){let J=typeof e.idKey=="function"?e.idKey($.values[G[0]]):e.idKey;f(H[M],$.values[G[0]][J],d.navigationRules.sibling_sibling)}else if(V===G.length-1&&A==="bridgedCousins"){let J=U(g);if(J!==null){let Q=d.divisions[F[J]].values,ee=Object.keys(Q),ne=Q[ee[0]],se=typeof e.idKey=="function"?e.idKey(ne):e.idKey;f(H[M],ne[se],d.navigationRules.sibling_sibling)}}else if(V===G.length-1&&A==="bridgedCustom")f(H[M],d.behavior.customBridgePost,d.navigationRules.sibling_sibling);else if(V<G.length-1){let J=typeof e.idKey=="function"?e.idKey($.values[G[V+1]]):e.idKey;f(H[M],$.values[G[V+1]][J],d.navigationRules.sibling_sibling)}if(!V&&A==="bridgedCousins"){let J=y(g);if(J!==null){let Q=d.divisions[F[J]].values,ee=Object.keys(Q),ne=Q[ee[ee.length-1]],se=typeof e.idKey=="function"?e.idKey(ne):e.idKey;f(ne[se],H[M],d.navigationRules.sibling_sibling)}}else!V&&A==="bridgedCustom"&&f(d.behavior.customBridgePrevious,H[M],d.navigationRules.sibling_sibling)}else if(g===F.length-1&&A==="bridgedCustom")f(H[M],d.behavior.customBridgePost,d.navigationRules.sibling_sibling);else if(!g&&A==="bridgedCustom")f(d.behavior.customBridgePrevious,H[M],d.navigationRules.sibling_sibling);else{let J=g===F.length-1&&A==="circular"?d.divisions[F[0]]:d.divisions[F[g+1]];if(J){let Q=B(V,H[M],$,J);if(Q){let ee=typeof e.idKey=="function"?e.idKey(Q):e.idKey;f(H[M],Q[ee],d.navigationRules.sibling_sibling)}}}V++}),g++})})}return Object.keys(t).forEach(a=>{var h;let p=t[a];(h=e.genericEdges)!=null&&h.length&&e.genericEdges.forEach(m=>{r[m.edgeId]||(r[m.edgeId]=m.edge),(!m.conditional||m.conditional&&m.conditional(p,m))&&p.edges.push(m.edgeId)})}),r},Re=(e,t,n)=>{var r,c,f,C,b,s,R,w,o,_,L,K,v,a,p,h,m,u;let i=e.navigationRules;if(!i){let E=Object.keys(n||{});E.length>6&&console.error(`Building navigationRules. Dimension count is too high to automatically generate key commands. It is recommend you reduce your dimensions to 6 or fewer for end-user experience. If not, you must provide your own navigation rules in options.navigationRules. Details: Count is ${E.length}. Dimensions counted: ${E.join(", ")}.`);let j={},l={},S={},D=[...fe],N=[...ge],d=(k,B)=>{let A=k&&B,F=!1,z=!1;if((j[k]||l[k])&&(l[k]=T({},j[k]),F=!0),B&&(j[B]||l[B])&&(l[B]=T({},j[B]),z=!0),A&&!F&&!z){D.length||console.error("Building navigationRules. Dimension count is too high to automatically generate key commands, we have run out of keyboard key pairs to assign. You must either provide your own navigation rules in options.navigationRules, provide rules when generating dimensions, or reduce dimension count.");let U=[...D.shift()];N.splice(N.indexOf(U[0]),1),N.splice(N.indexOf(U[1]),1),l[k]={direction:e.useDirectedEdges?"target":"source",key:U[0]},l[B]={direction:"target",key:U[1]}}else{if(!l[k]&&N.length){let U=N.shift(),y=[];D.forEach(g=>{U!==g[0]&&U!==g[1]&&y.push(g)}),D=y,l[k]={direction:e.useDirectedEdges?"target":"source",key:U}}if(B&&!l[B]&&N.length){let U=N.shift(),y=[];D.forEach(g=>{U!==g[0]&&U!==g[1]&&y.push(g)}),D=y,l[B]={direction:"target",key:U}}N.length||(l[k]||(S[k]=k),B&&!l[B]&&(S[B]=B))}};if(Object.keys(oe).forEach(k=>{let B=T({},oe[k]);e.useDirectedEdges&&(B.direction="target"),j[k]=B}),E.length){if((c=(r=e.dimensions)==null?void 0:r.parentOptions)!=null&&c.addLevel0){let k=((C=(f=e.dimensions.parentOptions.level1Options)==null?void 0:f.navigationRules)==null?void 0:C.parent_child)||["drill-out","drill-in"];d(k[0],k[1])}E.forEach(k=>{let B=n[k].navigationRules.parent_child,A=n[k].navigationRules.sibling_sibling;d(B[0],B[1]),d(A[0],A[1])})}if([(s=(b=e.frame)==null?void 0:b.navigationRules)==null?void 0:s.parent_child,(w=(R=e.frame)==null?void 0:R.navigationRules)==null?void 0:w.sibling_sibling,(_=(o=e.spatialGrid)==null?void 0:o.navigationRules)==null?void 0:_.x,(K=(L=e.spatialGrid)==null?void 0:L.navigationRules)==null?void 0:K.y,(a=(v=e.spatialGrid)==null?void 0:v.navigationRules)==null?void 0:a.parent_child,(h=(p=e.hierarchy)==null?void 0:p.navigationRules)==null?void 0:h.parent_child,(u=(m=e.hierarchy)==null?void 0:m.navigationRules)==null?void 0:u.sibling_sibling].forEach(k=>{k&&!l[k[0]]&&!l[k[1]]&&d(k[0],k[1])}),Object.keys(t).forEach(k=>{t[k].navigationRules.forEach(B=>{l[B]||d(B)})}),Object.keys(S).length){let k={};Object.keys(l).forEach(A=>{k[l[A].key]=l[A].key}),Object.keys(j).forEach(A=>{!k[j[A].key]&&!ue[j[A].key]&&N.push(j[A].key)});let B=T({},S);S={},Object.keys(B).forEach(A=>{d(A)}),Object.keys(S).length&&console.error(`Building navigationRules. There are no more keys left to assign automatically. Recommended fixes: use fewer dimensions, use fewer GenericEdges, or build your own navigationRules. Rules remaining without keyboard keys: ${Object.keys(S).join(", ")}.`)}i=l}return i},je=e=>{var R,w,o;e.addIds&&Ie(e);let t=pe(e),n=xe(t),i=Ke(t,n),r={},c=be(t,n,r),f=Ee(t,n,r),C;if(t.frame){let _=Object.keys(i||{}),L=(c==null?void 0:c.rootId)||(f==null?void 0:f.rootId)||((o=(w=(R=t.dimensions)==null?void 0:R.parentOptions)==null?void 0:w.addLevel0)==null?void 0:o.id)||(_.length===1?i[_[0]].nodeId:void 0);C=me(t,n,r,L)}r=Ne(t,n,i,r);let b=Re(t,r,i),s={nodes:n,edges:r,dimensions:i,navigationRules:b};return C&&(s.frame=C),c&&(s.spatialGrid=c),f&&(s.hierarchy=f),s};0&&(module.exports={addSimpleDataIDs,buildEdges,buildNodeStructureFromVegaLite,buildNodes,buildRules,buildStructure,scaffoldDimensions});
|
package/dist/structure.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as de,b as J}from"./chunk-YE5N6UCT.js";import{a as ne,c as te,e as se,f as Y,g as oe,i as re}from"./chunk-MPFBSVCV.js";import{a as V,b as ie}from"./chunk-RGY6OTGO.js";var pe=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?ue(e):he(e),ue=e=>{let m=re,s={},g={},O={},a=0,$=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,k=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,b=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,t=e.vegaLiteView._renderer._origin,y=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],E=(n,r)=>{if(n["data-navigator-id"])return n["data-navigator-id"];let d=`dn-node-${r}-${a}`;return a++,n["data-navigator-id"]=d,d},o=n=>{let r=s[n],d=r.index,l=r.level,v=r.parent,u=[],c=v.items[d-1];if(c){let f=E(c,l);if(s[f]){let I=`${f}-${r.id}`;u.push(I),g[I]||(g[I]={source:f,target:r.id,navigationRules:["left","right"]})}}let K=v.items[d+1];if(K){let f=E(K,l);if(s[f]){let I=`${r.id}-${f}`;u.push(I),g[I]||(g[I]={source:r.id,target:f,navigationRules:["left","right"]})}}if(l==="group"&&v.items[d].items){let I=(v.items[d].items[0].mark.items[0].items||v.items[d].items)[0],p=E(I,"item");if(s[p]){let i=`${r.id}-${p}`;u.push(i),g[i]||(g[i]={source:r.id,target:p,navigationRules:["parent","child"]})}}else if(l==="item"){let f=E(v,"group");if(s[f]){let I=`${f}-${r.id}`;u.push(I),g[I]||(g[I]={source:f,target:r.id,navigationRules:["parent","child"]})}}return e.exitFunction&&(u.push("any-exit"),g["any-exit"]||(g["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),u.push("any-undo"),g["any-undo"]||(g["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),u},j=(n,r,d,l,v)=>{let u=E(n,r),c="render-"+u,K=d||[0,0];s[u]={},s[u].d={},s[u].id=u,s[u].renderId=c,s[u].index=l,s[u].level=r,s[u].parent=v,O[c]={},O[c].renderId=c,O[c].spatialProperties={},O[c].spatialProperties.x=n.bounds.x1+K[0],O[c].spatialProperties.y=n.bounds.y1+K[1],O[c].spatialProperties.width=n.bounds.x2-n.bounds.x1,O[c].spatialProperties.height=n.bounds.y2-n.bounds.y1,O[c].cssClass="dn-vega-lite-node",n.datum&&Object.keys(n.datum).forEach(f=>{let I=n.datum[f];b(f,I,n.datum,r,e.vegaLiteSpec)&&(s[u].d[e.keyRenamingHash&&e.keyRenamingHash[f]?e.keyRenamingHash[f]:f]=I)}),O[c].semantics={},O[c].semantics.label=e.nodeDescriber?e.nodeDescriber(s[u].d,n,r):de(s[u].d)},D=0;return y.items.forEach(n=>{if($(n,D,e.vegaLiteSpec)){j(n,"group",t,D,y);let r=0,d=n.items[0].mark.items[0].items?n.items[0].mark.items[0]:n;d.items.forEach(l=>{k(l,r,n,e.vegaLiteSpec)&&j(l,"item",t,r,d),r++})}D++}),Object.keys(s).forEach(n=>{s[n].edges=o(n)}),{nodes:s,edges:g,elementData:O,navigationRules:m}},ce=e=>{let m=0,s={};e.data.forEach(g=>{let O=typeof e.idKey=="function"?e.idKey(g):e.idKey;g[O]="_"+m,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(a=>{a in g&&(typeof g[a]=="string"?(s[a]||(s[a]=0),s[g[a]]||(s[g[a]]=0),g[O]+="_"+a+s[a]+"_"+g[a]+s[g[a]],s[a]++,s[g[a]]++):(s[a]||(s[a]=0),g[O]+="_"+a+s[a],s[a]++))}),m++})},ge=e=>{let m={};return e.data.forEach(s=>{e.idKey||console.error("Building nodes. A key string must be supplied in options.idKey to specify the id keys of every node.");let g=typeof e.idKey=="function"?e.idKey(s):e.idKey,O=s[g];if(!O){console.error(`Building nodes. Each datum in options.data must contain an id. When matching the id key string ${g}, this datum has no id: ${JSON.stringify(s)}.`);return}if(m[O]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${O}.`);return}else{let a=typeof e.renderIdKey=="function"?e.renderIdKey(s):e.renderIdKey;m[O]={id:O,edges:[],renderId:a?s[a]||"":s.renderIdKey||"",data:s}}}),m},fe=(e,m)=>{var a,$,k;let s={};if(($=(a=e.dimensions)==null?void 0:a.parentOptions)!=null&&$.addLevel0){let b=e.dimensions.parentOptions.addLevel0;m[b.id]=ie(V({},b),{dimensionLevel:0})}let g=[...oe],O=(b,t)=>{let y=t.numericalExtents[0],E=t.numericalExtents[1];t.numericalExtents[0]=y<b?y:b,t.numericalExtents[1]=E>b?E:b};return e.data.forEach(b=>{var E;let t=((E=e.dimensions)==null?void 0:E.values)||[],y=0;t.forEach(o=>{var j,D,h,n,r,d,l,v;if(!o.dimensionKey){console.error(`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(o)}.`);return}if(o.dimensionKey in b){let u=b[o.dimensionKey],c=typeof((j=o.operations)==null?void 0:j.filterFunction)=="function"?o.operations.filterFunction(b,o):!0;if(u!==void 0&&c){if(o.type||(o.type=typeof u=="bigint"||typeof u=="number"?"numerical":"categorical"),!s[o.dimensionKey]){let p=typeof o.nodeId=="function"?o.nodeId(o,e.data):o.nodeId||J(o.dimensionKey),i=typeof o.renderId=="function"?o.renderId(o,e.data):o.renderId||p;s[o.dimensionKey]={dimensionKey:o.dimensionKey,nodeId:p,divisions:{},numericalExtents:[1/0,-1/0],type:o.type,operations:{compressSparseDivisions:((D=o.operations)==null?void 0:D.compressSparseDivisions)||!1,sortFunction:((h=o.operations)==null?void 0:h.sortFunction)||void 0},behavior:o.behavior||{extents:"circular"},navigationRules:o.navigationRules||{sibling_sibling:g.length?[...g.shift()]:["previous_"+o.dimensionKey,"next_"+o.dimensionKey],parent_child:["parent_"+o.dimensionKey,"child"]}},m[p]={id:p,renderId:i,derivedNode:o.dimensionKey,edges:[],dimensionLevel:1,data:s[o.dimensionKey],renderingStrategy:o.renderingStrategy||"singleSquare"}}let K=s[o.dimensionKey],f=null;if(o.type==="categorical"){let p=typeof((n=o.divisionOptions)==null?void 0:n.divisionNodeIds)=="function"?o.divisionOptions.divisionNodeIds(o.dimensionKey,u,y):J(K.nodeId+"_"+u);if(f=K.divisions[p],!f){f=K.divisions[p]={id:p,sortFunction:((r=o.divisionOptions)==null?void 0:r.sortFunction)||void 0,values:{}};let i=typeof((d=o.divisionOptions)==null?void 0:d.divisionRenderIds)=="function"?o.divisionOptions.divisionRenderIds(o.dimensionKey,u,y):p;m[p]={id:p,renderId:i,derivedNode:o.dimensionKey,edges:[],dimensionLevel:2,data:V({},f),renderingStrategy:((l=o.divisionOptions)==null?void 0:l.renderingStrategy)||"singleSquare"},m[p].data[o.dimensionKey]=u}}else{f=K.divisions[K.nodeId],f||(f=K.divisions[K.nodeId]={id:K.nodeId,sortFunction:((v=o.divisionOptions)==null?void 0:v.sortFunction)||void 0,values:{}}),o.operations||(o.operations={});let p=o.operations.createNumericalSubdivisions;K.subdivisions=typeof p=="number"&&p<1?1:p||1,p!==1&&(K.divisionOptions||(K.divisionOptions=o.divisionOptions),O(u,K))}let I=typeof e.idKey=="function"?e.idKey(b):e.idKey;f.values[b[I]]=b}}y++})}),Object.keys(s).forEach(b=>{var o,j,D,h,n;let t=s[b],y=t.divisions;if(t.type==="numerical"){y[t.nodeId].values=Object.fromEntries(Object.entries(y[t.nodeId].values).sort((d,l)=>{var v;return typeof((v=t.operations)==null?void 0:v.sortFunction)=="function"?t.operations.sortFunction(d[1],l[1],t):d[1][b]-l[1][b]}));let r=y[t.nodeId].values;if(t.numericalExtents[0]!==1/0&&t.subdivisions!==1){let d=Object.keys(r),l=typeof t.subdivisions=="function"?t.subdivisions(b,r):t.subdivisions,u=(t.numericalExtents[1]-t.numericalExtents[0])/l,c=t.numericalExtents[0]+u,K=0,f=0,I=null,p=t.numericalExtents[0];for(c=t.numericalExtents[0]+u;c<=t.numericalExtents[1];c+=u){let i=typeof((o=t.divisionOptions)==null?void 0:o.divisionNodeIds)=="function"?t.divisionOptions.divisionNodeIds(b,c,c):J(t.nodeId+"_"+c);I=i,t.divisions[i]={id:i,sortFunction:((j=t.divisionOptions)==null?void 0:j.sortFunction)||void 0,values:{},numericalExtents:[p,c]};let T=typeof((D=t.divisionOptions)==null?void 0:D.divisionRenderIds)=="function"?t.divisionOptions.divisionRenderIds(b,c,c):i;m[i]={id:i,renderId:T,derivedNode:b,edges:[],data:t.divisions[i],dimensionLevel:2,renderingStrategy:((h=t.divisionOptions)==null?void 0:h.renderingStrategy)||"singleSquare"};let A=!1;for(;!A&&f<d.length;){let G=r[d[f]];if(G[b]<=c){let R=typeof e.idKey=="function"?e.idKey(G):G[e.idKey];t.divisions[i].values[R]=G,f++}else A=!0}p=c,K++}if(I&&f<d.length)for(;f<d.length;){let i=r[d[f]],T=typeof e.idKey=="function"?e.idKey(i):i[e.idKey];t.divisions[I].values[T]=i,f++}delete y[t.nodeId]}}else typeof((n=t.operations)==null?void 0:n.sortFunction)=="function"&&(t.divisions=Object.fromEntries(Object.entries(y).sort((r,d)=>t.operations.sortFunction(r[1],d[1],t))));Object.keys(t.divisions).forEach(r=>{let d=t.divisions[r];typeof d.sortFunction=="function"&&(d.values=Object.fromEntries(Object.entries(d.values).sort((l,v)=>d.sortFunction(l[1],v[1],d))))})}),Object.keys(s).forEach(b=>{let t=s[b];if(t.operations.compressSparseDivisions){let y=Object.keys(t.divisions),E={},o=!0;if(y.forEach(j=>{let D=t.divisions[j],h=Object.keys(D.values);h.length<=1?h.forEach(n=>{E[n]=V({},D.values[n])}):o=!1}),o){let j={id:t.nodeId,values:E};y.forEach(D=>{delete m[D]}),t.divisions={},t.divisions[t.nodeId]=j}}}),(k=e.dimensions)!=null&&k.adjustDimensions&&(s=e.dimensions.adjustDimensions(s)),s},ve=(e,m,s)=>{var $,k,b,t,y,E,o,j,D,h;let g={},O=(n,r)=>{m[n].edges.indexOf(r)===-1&&m[n].edges.push(r)},a=(n,r,d,l)=>{let v=`${n}-${r}`,u=e.useDirectedEdges?`${r}-${v}`:v,c=!l||l==="source",K=!l||l==="target",f=I=>{g[I]?g[I].navigationRules.push(...d||[]):g[I]={source:n,target:r,navigationRules:d?[...d]:[]}};f(v),e.useDirectedEdges&&K&&f(u),c&&O(n,v),K&&O(r,u)};if(s&&Object.keys(s).length){let n=Object.keys(s),r=(b=(k=($=e.dimensions)==null?void 0:$.parentOptions)==null?void 0:k.level1Options)==null?void 0:b.order,d=r||n,l=0,v=((t=e.dimensions)==null?void 0:t.parentOptions)||{},u=((E=(y=v.level1Options)==null?void 0:y.behavior)==null?void 0:E.extents)||"terminal",c=v.addLevel0,K=c?((j=(o=v.level1Options)==null?void 0:o.navigationRules)==null?void 0:j.parent_child)||["parent","child"]:[],f=((h=(D=v.level1Options)==null?void 0:D.navigationRules)==null?void 0:h.sibling_sibling)||["left","right"],I=typeof d[0]=="string"?r?m[d[0]]:m[s[d[0]].nodeId]:d[0];c&&a(c.id,I.id,K,"source"),d.forEach(p=>{let i=typeof p=="string"?r?m[p]:m[s[p].nodeId]:p;if(i===p&&!m[i.id]&&(m[i.id]=i),c&&(e.useDirectedEdges?a(i.id,c.id,K,"source"):a(c.id,i.id,K,"target")),l===d.length-1&&u==="circular")a(i.id,I.id,f);else if(l===d.length-1&&u==="bridgedCustom")a(i.id,v.level1Options.behavior.customBridgePost,f);else if(l<d.length-1){let T=typeof d[l+1]=="string"?r?m[d[l+1]]:m[s[d[l+1]].nodeId]:d[l+1];a(i.id,T.id,f)}!l&&u==="bridgedCustom"&&a(v.level1Options.behavior.customBridgePost,i.id,f),l++}),n.forEach(p=>{var z,Q,X,Z;let i=s[p],T=((z=i.behavior)==null?void 0:z.childmostNavigation)||"within",A=(w,x,N,S)=>S.values[Object.keys(S.values)[w]]||void 0,G=T==="across"&&((Q=i.behavior)!=null&&Q.childmostMatching)?(X=i.behavior)==null?void 0:X.childmostMatching:A,C=((Z=i.behavior)==null?void 0:Z.extents)||"circular";i.divisions||console.error(`Parsing dimensions. The dimension using the key ${p} is missing the divisions property. dimension.divisions should be supplied. ${JSON.stringify(i)}.`);let R=Object.keys(i.divisions),H=i.divisions[R[0]];if(R.length!==1)a(i.nodeId,H.id,i.navigationRules.parent_child,"source");else{let w=Object.keys(H.values),x=typeof e.idKey=="function"?e.idKey(H.values[w[0]]):e.idKey;a(i.nodeId,H.values[w[0]][x],i.navigationRules.parent_child,"source")}let ae=w=>{for(let x=1;x<R.length;x++){let N=(w+x)%R.length;if(Object.keys(i.divisions[R[N]].values).length>0)return N}return null},le=w=>{for(let x=1;x<R.length;x++){let N=(w-x+R.length)%R.length;if(Object.keys(i.divisions[R[N]].values).length>0)return N}return null},P=0;R.forEach(w=>{let x=i.divisions[w];P===R.length-1&&(C==="circular"||C==="bridgedCousins"||C==="bridgedCustom")?a(x.id,i.divisions[R[0]].id,i.navigationRules.sibling_sibling):P<R.length-1&&a(x.id,i.divisions[R[P+1]].id,i.navigationRules.sibling_sibling);let N=Object.keys(x.values);if(e.useDirectedEdges?a(x.id,i.nodeId,i.navigationRules.parent_child,"source"):a(i.nodeId,x.id,i.navigationRules.parent_child,"target"),N.length>0){let U=typeof e.idKey=="function"?e.idKey(x.values[N[0]]):e.idKey;a(x.id,x.values[N[0]][U],i.navigationRules.parent_child,"source")}let S=0;N.length>=1&&N.forEach(U=>{let _=x.values[U],F=typeof e.idKey=="function"?e.idKey(_):e.idKey,ee=R.length!==1?x.id:i.nodeId;if(e.useDirectedEdges?a(_[F],ee,i.navigationRules.parent_child,"source"):a(ee,_[F],i.navigationRules.parent_child,"target"),T==="within"){if(S===N.length-1&&C==="circular"){let L=typeof e.idKey=="function"?e.idKey(x.values[N[0]]):e.idKey;a(_[F],x.values[N[0]][L],i.navigationRules.sibling_sibling)}else if(S===N.length-1&&C==="bridgedCousins"){let L=ae(P);if(L!==null){let B=i.divisions[R[L]].values,q=Object.keys(B),M=B[q[0]],W=typeof e.idKey=="function"?e.idKey(M):e.idKey;a(_[F],M[W],i.navigationRules.sibling_sibling)}}else if(S===N.length-1&&C==="bridgedCustom")a(_[F],i.behavior.customBridgePost,i.navigationRules.sibling_sibling);else if(S<N.length-1){let L=typeof e.idKey=="function"?e.idKey(x.values[N[S+1]]):e.idKey;a(_[F],x.values[N[S+1]][L],i.navigationRules.sibling_sibling)}if(!S&&C==="bridgedCousins"){let L=le(P);if(L!==null){let B=i.divisions[R[L]].values,q=Object.keys(B),M=B[q[q.length-1]],W=typeof e.idKey=="function"?e.idKey(M):e.idKey;a(M[W],_[F],i.navigationRules.sibling_sibling)}}else!S&&C==="bridgedCustom"&&a(i.behavior.customBridgePrevious,_[F],i.navigationRules.sibling_sibling)}else if(P===R.length-1&&C==="bridgedCustom")a(_[F],i.behavior.customBridgePost,i.navigationRules.sibling_sibling);else if(!P&&C==="bridgedCustom")a(i.behavior.customBridgePrevious,_[F],i.navigationRules.sibling_sibling);else{let L=P===R.length-1&&C==="circular"?i.divisions[R[0]]:i.divisions[R[P+1]];if(L){let B=G(S,_[F],x,L);if(B){let q=typeof e.idKey=="function"?e.idKey(B):e.idKey;a(_[F],B[q],i.navigationRules.sibling_sibling)}}}S++}),P++})})}return Object.keys(m).forEach(n=>{var d;let r=m[n];(d=e.genericEdges)!=null&&d.length&&e.genericEdges.forEach(l=>{g[l.edgeId]||(g[l.edgeId]=l.edge),(!l.conditional||l.conditional&&l.conditional(r,l))&&r.edges.push(l.edgeId)})}),g},ye=(e,m,s)=>{var O,a,$,k;let g=e.navigationRules;if(!g){let b=Object.keys(s||{});b.length>6&&console.error(`Building navigationRules. Dimension count is too high to automatically generate key commands. It is recommend you reduce your dimensions to 6 or fewer for end-user experience. If not, you must provide your own navigation rules in options.navigationRules. Details: Count is ${b.length}. Dimensions counted: ${b.join(", ")}.`);let t={},y={},E={},o=[...se],j=[...te],D=(h,n)=>{let r=h&&n,d=!1,l=!1;if((t[h]||y[h])&&(y[h]=V({},t[h]),d=!0),n&&(t[n]||y[n])&&(y[n]=V({},t[n]),l=!0),r&&!d&&!l){o.length||console.error("Building navigationRules. Dimension count is too high to automatically generate key commands, we have run out of keyboard key pairs to assign. You must either provide your own navigation rules in options.navigationRules, provide rules when generating dimensions, or reduce dimension count.");let v=[...o.shift()];j.splice(j.indexOf(v[0]),1),j.splice(j.indexOf(v[1]),1),y[h]={direction:e.useDirectedEdges?"target":"source",key:v[0]},y[n]={direction:"target",key:v[1]}}else{if(!y[h]&&j.length){let v=j.shift(),u=[];o.forEach(c=>{v!==c[0]&&v!==c[1]&&u.push(c)}),o=u,y[h]={direction:e.useDirectedEdges?"target":"source",key:v}}if(n&&!y[n]&&j.length){let v=j.shift(),u=[];o.forEach(c=>{v!==c[0]&&v!==c[1]&&u.push(c)}),o=u,y[n]={direction:"target",key:v}}j.length||(y[h]||(E[h]=h),n&&!y[n]&&(E[n]=n))}};if(Object.keys(Y).forEach(h=>{let n=V({},Y[h]);e.useDirectedEdges&&(n.direction="target"),t[h]=n}),b.length){if((a=(O=e.dimensions)==null?void 0:O.parentOptions)!=null&&a.addLevel0){let h=((k=($=e.dimensions.parentOptions.level1Options)==null?void 0:$.navigationRules)==null?void 0:k.parent_child)||["parent","child"];D(h[0],h[1])}b.forEach(h=>{let n=s[h].navigationRules.parent_child,r=s[h].navigationRules.sibling_sibling;D(n[0],n[1]),D(r[0],r[1])})}if(Object.keys(m).forEach(h=>{m[h].navigationRules.forEach(n=>{y[n]||D(n)})}),Object.keys(E).length){let h={};Object.keys(y).forEach(r=>{h[y[r].key]=y[r].key}),Object.keys(t).forEach(r=>{!h[t[r].key]&&!ne[t[r].key]&&j.push(t[r].key)});let n=V({},E);E={},Object.keys(n).forEach(r=>{D(r)}),Object.keys(E).length&&console.error(`Building navigationRules. There are no more keys left to assign automatically. Recommended fixes: use fewer dimensions, use fewer GenericEdges, or build your own navigationRules. Rules remaining without keyboard keys: ${Object.keys(E).join(", ")}.`)}g=y}return g},he=e=>{e.addIds&&ce(e);let m=ge(e),s=fe(e,m),g=ve(e,m,s),O=ye(e,g,s);return{nodes:m,edges:g,dimensions:s,navigationRules:O}};export{ce as addSimpleDataIDs,ve as buildEdges,ue as buildNodeStructureFromVegaLite,ge as buildNodes,ye as buildRules,he as buildStructure,pe as default,fe as scaffoldDimensions};
|
|
1
|
+
import{a as ge,b as ie}from"./chunk-ZTY2OAPD.js";import{a as M,b as Y,h as de,j as ae,l as le,m as re,n as ce,p as ue}from"./chunk-B5HGEXMZ.js";var te=(e,r,s)=>{let i=(t,c)=>{let f=e[t];if(!f){console.error(`Building edges. Node ${t} does not exist, so edge ${c} was not added to it.`);return}f.edges||(f.edges=[]),f.edges.indexOf(c)===-1&&f.edges.push(c)};return(t,c,f,k)=>{if(!t||!c||t===c)return;let p=`${t}-${c}`,n=s?`${c}-${p}`:p,R=!k||k==="source",S=!k||k==="target",o=C=>{r[C]?(f||[]).forEach(L=>{r[C].navigationRules.indexOf(L)===-1&&r[C].navigationRules.push(L)}):r[C]={source:t,target:c,navigationRules:f?[...f]:[]}};o(p),s&&S&&o(n),R&&i(t,p),S&&i(c,n)}},X=(e,r,s,i="terminal")=>{for(let t=0;t<r.length-1;t++)e(r[t],r[t+1],s);i==="circular"&&r.length>1&&e(r[r.length-1],r[0],s)};var fe=e=>{var t,c,f;let r=e.frame,s=((c=(t=e.dimensions)==null?void 0:t.values)==null?void 0:c.length)||0;if(!r||s<2||(f=e.dimensions.parentOptions)!=null&&f.addLevel0)return e;let i=r.data||{id:"data",edges:[],semantics:{label:"Data"}};return Y(M({},e),{dimensions:Y(M({},e.dimensions),{parentOptions:Y(M({},e.dimensions.parentOptions||{}),{addLevel0:Y(M({},i),{edges:i.edges||[]})})})})},ye=(e,r,s,i)=>{var L,x,v;let t=e.frame;if(!t)return;if(!i||!r[i]){console.error("Building frame. No top data node was found to place under the frame.");return}let c=te(r,s,e.useDirectedEdges),f=((L=t.navigationRules)==null?void 0:L.sibling_sibling)||["left","right"],k=((x=t.navigationRules)==null?void 0:x.parent_child)||["drill-out","drill-in"],p=((v=t.behavior)==null?void 0:v.extents)||"circular",n=t.root;r[n.id]=Y(M({},n),{edges:[...n.edges||[]],depth:0,frameRole:"root"});let R=(t.elements||[]).map(d=>(r[d.id]=Y(M({},d),{edges:[...d.edges||[]],depth:1,parentId:n.id,frameRole:"element"}),d.id)),S=i;t.data&&t.data.id!==i&&(r[t.data.id]=Y(M({},t.data),{edges:[...t.data.edges||[]]}),c(t.data.id,i,k,"source"),c(t.data.id,i,k,"target"),r[i].parentId=t.data.id,S=t.data.id);let o=r[S];o.frameRole="data",o.depth=1,o.parentId=n.id;let C=[...R,S];return c(n.id,C[0],k,"source"),C.forEach(d=>c(n.id,d,k,"target")),X(c,C,f,p),{rootId:n.id,elementIds:R,dataId:S,parentRules:k}};var ve=(e,r,s)=>{var P,z,V;let i=e.spatialGrid;if(!i)return;let t=te(r,s,e.useDirectedEdges),c=((P=i.navigationRules)==null?void 0:P.x)||["left","right"],f=((z=i.navigationRules)==null?void 0:z.y)||["up","down"],k=((V=i.navigationRules)==null?void 0:V.parent_child)||["drill-out","drill-in"],p=i.extents||"terminal",n=i.levelNavigation!=="within",R=i.skipEmpty!==!1,S=i.leaves||"points",o=y=>y[typeof e.idKey=="function"?e.idKey(y):e.idKey],C=e.data.filter(y=>typeof y[i.xKey]=="number"&&typeof y[i.yKey]=="number"),L=(y,g)=>{if(g)return g;let E=1/0,O=-1/0;return C.forEach(K=>{E=Math.min(E,K[y]),O=Math.max(O,K[y])}),[E,O]},x=L(i.xKey,i.xExtent),v=L(i.yKey,i.yExtent),d=(y,[g,E],O)=>E===g?0:Math.max(0,Math.min(O-1,Math.floor((y-g)/(E-g)*O))),h=M(M({},{id:"grid",edges:[],semantics:{label:"Grid"}}),i.root||{});h.edges=h.edges||[],h.depth=0,h.data=Y(M({},h.data||{}),{xKey:i.xKey,yKey:i.yKey,xExtent:x,yExtent:v,levels:i.levels,count:C.length}),r[h.id]=h;let b=(y,g,E)=>i.cellIds?i.cellIds(y,g,E):ie(`${h.id}_L${y}_${g}_${E}`),u=[];i.levels.forEach((y,g)=>{let E={},O=(K,A)=>{let J=`${K}_${A}`;if(E[J])return E[J];let w=b(g,K,A),G=(x[1]-x[0])/y,H=(v[1]-v[0])/y,Z=h.id;if(g>0){let q=i.levels[g-1],T=u[g-1][`${Math.floor(K*q/y)}_${Math.floor(A*q/y)}`];Z=T==null?void 0:T.id,T==null||T.children.push(w)}return E[J]={id:w,col:K,row:A,parent:Z,children:[]},r[w]={id:w,renderId:w,edges:[],depth:g+1,parentId:Z,data:{level:g,col:K,row:A,cellsPerAxis:y,xExtent:[x[0]+K*G,x[0]+(K+1)*G],yExtent:[v[0]+A*H,v[0]+(A+1)*H],count:0}},E[J]};if(!R)for(let K=0;K<y;K++)for(let A=0;A<y;A++)O(K,A);C.forEach(K=>O(d(K[i.xKey],x,y),d(K[i.yKey],v,y))),u.push(E)});let I=u[u.length-1],j=i.levels[i.levels.length-1],l=[],$={};C.forEach(y=>{let g=o(y);if(!r[g])return;i.levels.forEach((O,K)=>{let A=u[K][`${d(y[i.xKey],x,O)}_${d(y[i.yKey],v,O)}`];r[A.id].data.count++});let E=I[`${d(y[i.xKey],x,j)}_${d(y[i.yKey],v,j)}`];E.children.push(g),$[g]=E.id,l.push(g),r[g].parentId=E.id,r[g].depth=i.levels.length+1});let _=(y,g)=>g.row-y.row||y.col-g.col,N=Object.values(u[0]).sort(_);N.length&&t(h.id,N[0].id,k,"source"),N.forEach(y=>t(h.id,y.id,k,"target"));let a=y=>r[y].data;u.forEach((y,g)=>{Object.values(y).forEach(E=>{if(!E.children.length)return;let O;g===u.length-1?O=[...E.children].sort((K,A)=>D(K,A))[0]:O=[...E.children].sort((K,A)=>_(a(K),a(A)))[0],t(E.id,O,k,"source"),E.children.forEach(K=>t(E.id,K,k,"target"))})});let W=y=>{let g={},E={};y.forEach(O=>{let K=a(O);(g[K.row]=g[K.row]||[]).push(O),(E[K.col]=E[K.col]||[]).push(O)}),Object.values(g).forEach(O=>X(t,O.sort((K,A)=>a(K).col-a(A).col),c,p)),Object.values(E).forEach(O=>X(t,O.sort((K,A)=>a(A).row-a(K).row),f,p))};u.forEach((y,g)=>{let E=Object.values(y);if(n||g===0)W(E.map(O=>O.id));else{let O={};E.forEach(K=>(O[K.parent]=O[K.parent]||[]).push(K.id)),Object.values(O).forEach(W)}});function D(y,g){let E=r[y].data,O=r[g].data;return E[i.xKey]-O[i.xKey]||O[i.yKey]-E[i.yKey]}let F=(y,g)=>{let E=r[y].data,O=r[g].data;return O[i.yKey]-E[i.yKey]||E[i.xKey]-O[i.xKey]},B=y=>{if(S==="cells"){let g={},E={};y.forEach(O=>{let K=r[O].data;(g[K[i.yKey]]=g[K[i.yKey]]||[]).push(O),(E[K[i.xKey]]=E[K[i.xKey]]||[]).push(O)}),Object.values(g).forEach(O=>X(t,O.sort(D),c,p)),Object.values(E).forEach(O=>X(t,O.sort(F),f,p))}else X(t,[...y].sort(D),c,p),X(t,[...y].sort(F),f,p)};return n?B(l):Object.values(I).forEach(y=>B(y.children)),{rootId:h.id,levels:i.levels,cellsByLevel:u.map(y=>Object.values(y).map(g=>g.id)),leafIds:l,parentRules:k}};var he=(e,r,s)=>{var C,L;let i=e.hierarchy;if(!i)return;let t=te(r,s,e.useDirectedEdges),c=((C=i.navigationRules)==null?void 0:C.sibling_sibling)||["left","right"],f=((L=i.navigationRules)==null?void 0:L.parent_child)||["drill-out","drill-in"],k=i.extents||"circular",p=x=>x[typeof e.idKey=="function"?e.idKey(x):e.idKey],n={},R;if(e.data.forEach(x=>{let v=p(x),d=x[i.parentKey];if(d==null||d===""){if(R){console.error(`Building hierarchy. More than one root was found: ${R} and ${v}. Using ${R}.`);return}R=v}else n[d]||(n[d]=[]),n[d].push(x)}),!R){console.error("Building hierarchy. No root row was found. One row must have an empty parent.");return}let S=[],o=(x,v,d)=>{let m=r[x];if(!m){console.error(`Building hierarchy. Row ${x} has no node. Check idKey.`);return}m.depth=d,v&&(m.parentId=v),S[d]||(S[d]=[]),S[d].push(x);let h=n[x]||[];i.sortFunction&&(h=[...h].sort((u,I)=>i.sortFunction(u,I)));let b=h.map(p);m.childCount=b.length,b.length&&(t(x,b[0],f,"source"),b.forEach(u=>t(x,u,f,"target")),i.levelNavigation!=="across"&&X(t,b,c,k)),b.forEach(u=>o(u,x,d+1))};return o(R,void 0,0),i.levelNavigation==="across"&&S.forEach(x=>X(t,x,c,k)),{rootId:R,depthCount:S.length,parentRules:f}};var Ae=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?me(e):Ke(e),me=e=>{let r=ue,s={},i={},t={},c=0,f=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,k=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,p=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,n=e.vegaLiteView._renderer._origin,R=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],S=(v,d)=>{if(v["data-navigator-id"])return v["data-navigator-id"];let m=`dn-node-${d}-${c}`;return c++,v["data-navigator-id"]=m,m},o=v=>{let d=s[v],m=d.index,h=d.level,b=d.parent,u=[],I=b.items[m-1];if(I){let l=S(I,h);if(s[l]){let $=`${l}-${d.id}`;u.push($),i[$]||(i[$]={source:l,target:d.id,navigationRules:["left","right"]})}}let j=b.items[m+1];if(j){let l=S(j,h);if(s[l]){let $=`${d.id}-${l}`;u.push($),i[$]||(i[$]={source:d.id,target:l,navigationRules:["left","right"]})}}if(h==="group"&&b.items[m].items){let $=(b.items[m].items[0].mark.items[0].items||b.items[m].items)[0],_=S($,"item");if(s[_]){let N=`${d.id}-${_}`;u.push(N),i[N]||(i[N]={source:d.id,target:_,navigationRules:["drill-out","drill-in"]})}}else if(h==="item"){let l=S(b,"group");if(s[l]){let $=`${l}-${d.id}`;u.push($),i[$]||(i[$]={source:l,target:d.id,navigationRules:["drill-out","drill-in"]})}}return e.exitFunction&&(u.push("any-exit"),i["any-exit"]||(i["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),u.push("any-undo"),i["any-undo"]||(i["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),u},C=(v,d,m,h,b)=>{let u=S(v,d),I="render-"+u,j=m||[0,0];s[u]={},s[u].d={},s[u].id=u,s[u].renderId=I,s[u].index=h,s[u].level=d,s[u].parent=b,t[I]={},t[I].renderId=I,t[I].spatialProperties={},t[I].spatialProperties.x=v.bounds.x1+j[0],t[I].spatialProperties.y=v.bounds.y1+j[1],t[I].spatialProperties.width=v.bounds.x2-v.bounds.x1,t[I].spatialProperties.height=v.bounds.y2-v.bounds.y1,t[I].cssClass="dn-vega-lite-node",v.datum&&Object.keys(v.datum).forEach(l=>{let $=v.datum[l];p(l,$,v.datum,d,e.vegaLiteSpec)&&(s[u].d[e.keyRenamingHash&&e.keyRenamingHash[l]?e.keyRenamingHash[l]:l]=$)}),t[I].semantics={},t[I].semantics.label=e.nodeDescriber?e.nodeDescriber(s[u].d,v,d):ge(s[u].d)},L=0;return R.items.forEach(v=>{if(f(v,L,e.vegaLiteSpec)){C(v,"group",n,L,R);let d=0,m=v.items[0].mark.items[0].items?v.items[0].mark.items[0]:v;m.items.forEach(h=>{k(h,d,v,e.vegaLiteSpec)&&C(h,"item",n,d,m),d++})}L++}),Object.keys(s).forEach(v=>{s[v].edges=o(v)}),{nodes:s,edges:i,elementData:t,navigationRules:r}},be=e=>{let r=0,s={};e.data.forEach(i=>{let t=typeof e.idKey=="function"?e.idKey(i):e.idKey;i[t]="_"+r,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(c=>{c in i&&(typeof i[c]=="string"?(s[c]||(s[c]=0),s[i[c]]||(s[i[c]]=0),i[t]+="_"+c+s[c]+"_"+i[c]+s[i[c]],s[c]++,s[i[c]]++):(s[c]||(s[c]=0),i[t]+="_"+c+s[c],s[c]++))}),r++})},pe=e=>{let r={};return e.data.forEach(s=>{e.idKey||console.error("Building nodes. A key string must be supplied in options.idKey to specify the id keys of every node.");let i=typeof e.idKey=="function"?e.idKey(s):e.idKey,t=s[i];if(!t){console.error(`Building nodes. Each datum in options.data must contain an id. When matching the id key string ${i}, this datum has no id: ${JSON.stringify(s)}.`);return}if(r[t]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${t}.`);return}else{let c=typeof e.renderIdKey=="function"?e.renderIdKey(s):e.renderIdKey;r[t]={id:t,edges:[],renderId:c?s[c]||"":s.renderIdKey||"",data:s}}}),r},Ie=(e,r)=>{var c,f,k;let s={};if((f=(c=e.dimensions)==null?void 0:c.parentOptions)!=null&&f.addLevel0){let p=e.dimensions.parentOptions.addLevel0;r[p.id]=Y(M({},p),{dimensionLevel:0})}let i=[...ce],t=(p,n)=>{let R=n.numericalExtents[0],S=n.numericalExtents[1];n.numericalExtents[0]=R<p?R:p,n.numericalExtents[1]=S>p?S:p};return e.data.forEach(p=>{var S;let n=((S=e.dimensions)==null?void 0:S.values)||[],R=0;n.forEach(o=>{var C,L,x,v,d,m,h,b;if(!o.dimensionKey){console.error(`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(o)}.`);return}if(o.dimensionKey in p){let u=p[o.dimensionKey],I=typeof((C=o.operations)==null?void 0:C.filterFunction)=="function"?o.operations.filterFunction(p,o):!0;if(u!==void 0&&I){if(o.type||(o.type=typeof u=="bigint"||typeof u=="number"?"numerical":"categorical"),!s[o.dimensionKey]){let _=typeof o.nodeId=="function"?o.nodeId(o,e.data):o.nodeId||ie(o.dimensionKey),N=typeof o.renderId=="function"?o.renderId(o,e.data):o.renderId||_;s[o.dimensionKey]={dimensionKey:o.dimensionKey,nodeId:_,divisions:{},numericalExtents:[1/0,-1/0],type:o.type,operations:{compressSparseDivisions:((L=o.operations)==null?void 0:L.compressSparseDivisions)||!1,sortFunction:((x=o.operations)==null?void 0:x.sortFunction)||void 0},behavior:o.behavior||{extents:"circular"},navigationRules:o.navigationRules||{sibling_sibling:i.length?[...i.shift()]:["previous_"+o.dimensionKey,"next_"+o.dimensionKey],parent_child:["drill-out_"+o.dimensionKey,"drill-in"]}},r[_]={id:_,renderId:N,derivedNode:o.dimensionKey,edges:[],dimensionLevel:1,data:s[o.dimensionKey],renderingStrategy:o.renderingStrategy||"singleSquare"}}let j=s[o.dimensionKey],l=null;if(o.type==="categorical"){let _=typeof((v=o.divisionOptions)==null?void 0:v.divisionNodeIds)=="function"?o.divisionOptions.divisionNodeIds(o.dimensionKey,u,R):ie(j.nodeId+"_"+u);if(l=j.divisions[_],!l){l=j.divisions[_]={id:_,sortFunction:((d=o.divisionOptions)==null?void 0:d.sortFunction)||void 0,values:{}};let N=typeof((m=o.divisionOptions)==null?void 0:m.divisionRenderIds)=="function"?o.divisionOptions.divisionRenderIds(o.dimensionKey,u,R):_;r[_]={id:_,renderId:N,derivedNode:o.dimensionKey,edges:[],dimensionLevel:2,data:M({},l),renderingStrategy:((h=o.divisionOptions)==null?void 0:h.renderingStrategy)||"singleSquare"},r[_].data[o.dimensionKey]=u}}else{l=j.divisions[j.nodeId],l||(l=j.divisions[j.nodeId]={id:j.nodeId,sortFunction:((b=o.divisionOptions)==null?void 0:b.sortFunction)||void 0,values:{}}),o.operations||(o.operations={});let _=o.operations.createNumericalSubdivisions;j.subdivisions=typeof _=="number"&&_<1?1:_||1,_!==1&&(j.divisionOptions||(j.divisionOptions=o.divisionOptions),t(u,j))}let $=typeof e.idKey=="function"?e.idKey(p):e.idKey;l.values[p[$]]=p}}R++})}),Object.keys(s).forEach(p=>{var o,C,L,x,v;let n=s[p],R=n.divisions;if(n.type==="numerical"){R[n.nodeId].values=Object.fromEntries(Object.entries(R[n.nodeId].values).sort((m,h)=>{var b;return typeof((b=n.operations)==null?void 0:b.sortFunction)=="function"?n.operations.sortFunction(m[1],h[1],n):m[1][p]-h[1][p]}));let d=R[n.nodeId].values;if(n.numericalExtents[0]!==1/0&&n.subdivisions!==1){let m=Object.keys(d),h=typeof n.subdivisions=="function"?n.subdivisions(p,d):n.subdivisions,u=(n.numericalExtents[1]-n.numericalExtents[0])/h,I=n.numericalExtents[0]+u,j=0,l=0,$=null,_=n.numericalExtents[0];for(I=n.numericalExtents[0]+u;I<=n.numericalExtents[1];I+=u){let N=typeof((o=n.divisionOptions)==null?void 0:o.divisionNodeIds)=="function"?n.divisionOptions.divisionNodeIds(p,I,I):ie(n.nodeId+"_"+I);$=N,n.divisions[N]={id:N,sortFunction:((C=n.divisionOptions)==null?void 0:C.sortFunction)||void 0,values:{},numericalExtents:[_,I]};let a=typeof((L=n.divisionOptions)==null?void 0:L.divisionRenderIds)=="function"?n.divisionOptions.divisionRenderIds(p,I,I):N;r[N]={id:N,renderId:a,derivedNode:p,edges:[],data:n.divisions[N],dimensionLevel:2,renderingStrategy:((x=n.divisionOptions)==null?void 0:x.renderingStrategy)||"singleSquare"};let W=!1;for(;!W&&l<m.length;){let D=d[m[l]];if(D[p]<=I){let B=typeof e.idKey=="function"?e.idKey(D):D[e.idKey];n.divisions[N].values[B]=D,l++}else W=!0}_=I,j++}if($&&l<m.length)for(;l<m.length;){let N=d[m[l]],a=typeof e.idKey=="function"?e.idKey(N):N[e.idKey];n.divisions[$].values[a]=N,l++}delete R[n.nodeId]}}else typeof((v=n.operations)==null?void 0:v.sortFunction)=="function"&&(n.divisions=Object.fromEntries(Object.entries(R).sort((d,m)=>n.operations.sortFunction(d[1],m[1],n))));Object.keys(n.divisions).forEach(d=>{let m=n.divisions[d];typeof m.sortFunction=="function"&&(m.values=Object.fromEntries(Object.entries(m.values).sort((h,b)=>m.sortFunction(h[1],b[1],m))))})}),Object.keys(s).forEach(p=>{let n=s[p];if(n.operations.compressSparseDivisions){let R=Object.keys(n.divisions),S={},o=!0;if(R.forEach(C=>{let L=n.divisions[C],x=Object.keys(L.values);x.length<=1?x.forEach(v=>{S[v]=M({},L.values[v])}):o=!1}),o){let C={id:n.nodeId,values:S};R.forEach(L=>{delete r[L]}),n.divisions={},n.divisions[n.nodeId]=C}}}),(k=e.dimensions)!=null&&k.adjustDimensions&&(s=e.dimensions.adjustDimensions(s)),s},Oe=(e,r,s,i)=>{var k,p,n,R,S,o,C,L,x,v;let t=i||{},c=(d,m)=>{r[d].edges.indexOf(m)===-1&&r[d].edges.push(m)},f=(d,m,h,b)=>{let u=`${d}-${m}`,I=e.useDirectedEdges?`${m}-${u}`:u,j=!b||b==="source",l=!b||b==="target",$=_=>{t[_]?t[_].navigationRules.push(...h||[]):t[_]={source:d,target:m,navigationRules:h?[...h]:[]}};$(u),e.useDirectedEdges&&l&&$(I),j&&c(d,u),l&&c(m,I)};if(s&&Object.keys(s).length){let d=Object.keys(s),m=(n=(p=(k=e.dimensions)==null?void 0:k.parentOptions)==null?void 0:p.level1Options)==null?void 0:n.order,h=m||d,b=0,u=((R=e.dimensions)==null?void 0:R.parentOptions)||{},I=((o=(S=u.level1Options)==null?void 0:S.behavior)==null?void 0:o.extents)||"terminal",j=u.addLevel0,l=j?((L=(C=u.level1Options)==null?void 0:C.navigationRules)==null?void 0:L.parent_child)||["drill-out","drill-in"]:[],$=((v=(x=u.level1Options)==null?void 0:x.navigationRules)==null?void 0:v.sibling_sibling)||["left","right"],_=typeof h[0]=="string"?m?r[h[0]]:r[s[h[0]].nodeId]:h[0];j&&f(j.id,_.id,l,"source"),h.forEach(N=>{let a=typeof N=="string"?m?r[N]:r[s[N].nodeId]:N;if(a===N&&!r[a.id]&&(r[a.id]=a),j&&(e.useDirectedEdges?f(a.id,j.id,l,"source"):f(j.id,a.id,l,"target")),b===h.length-1&&I==="circular")f(a.id,_.id,$);else if(b===h.length-1&&I==="bridgedCustom")f(a.id,u.level1Options.behavior.customBridgePost,$);else if(b<h.length-1){let W=typeof h[b+1]=="string"?m?r[h[b+1]]:r[s[h[b+1]].nodeId]:h[b+1];f(a.id,W.id,$)}!b&&I==="bridgedCustom"&&f(u.level1Options.behavior.customBridgePrevious,a.id,$),b++}),d.forEach(N=>{var E,O,K,A;let a=s[N],W=((E=a.behavior)==null?void 0:E.childmostNavigation)||"within",D=(J,w,G,H)=>H.values[Object.keys(H.values)[J]]||void 0,F=W==="across"&&((O=a.behavior)!=null&&O.childmostMatching)?(K=a.behavior)==null?void 0:K.childmostMatching:D,B=((A=a.behavior)==null?void 0:A.extents)||"circular";a.divisions||console.error(`Parsing dimensions. The dimension using the key ${N} is missing the divisions property. dimension.divisions should be supplied. ${JSON.stringify(a)}.`);let P=Object.keys(a.divisions),z=a.divisions[P[0]];if(P.length!==1)f(a.nodeId,z.id,a.navigationRules.parent_child,"source");else{let J=Object.keys(z.values),w=typeof e.idKey=="function"?e.idKey(z.values[J[0]]):e.idKey;f(a.nodeId,z.values[J[0]][w],a.navigationRules.parent_child,"source")}let V=J=>{for(let w=1;w<P.length;w++){let G=(J+w)%P.length;if(Object.keys(a.divisions[P[G]].values).length>0)return G}return null},y=J=>{for(let w=1;w<P.length;w++){let G=(J-w+P.length)%P.length;if(Object.keys(a.divisions[P[G]].values).length>0)return G}return null},g=0;P.forEach(J=>{let w=a.divisions[J];g===P.length-1&&(B==="circular"||B==="bridgedCousins"||B==="bridgedCustom")?f(w.id,a.divisions[P[0]].id,a.navigationRules.sibling_sibling):g<P.length-1&&f(w.id,a.divisions[P[g+1]].id,a.navigationRules.sibling_sibling);let G=Object.keys(w.values);if(e.useDirectedEdges?f(w.id,a.nodeId,a.navigationRules.parent_child,"source"):f(a.nodeId,w.id,a.navigationRules.parent_child,"target"),G.length>0){let Z=typeof e.idKey=="function"?e.idKey(w.values[G[0]]):e.idKey;f(w.id,w.values[G[0]][Z],a.navigationRules.parent_child,"source")}let H=0;G.length>=1&&G.forEach(Z=>{let q=w.values[Z],T=typeof e.idKey=="function"?e.idKey(q):e.idKey,oe=P.length!==1?w.id:a.nodeId;if(e.useDirectedEdges?f(q[T],oe,a.navigationRules.parent_child,"source"):f(oe,q[T],a.navigationRules.parent_child,"target"),W==="within"){if(H===G.length-1&&B==="circular"){let U=typeof e.idKey=="function"?e.idKey(w.values[G[0]]):e.idKey;f(q[T],w.values[G[0]][U],a.navigationRules.sibling_sibling)}else if(H===G.length-1&&B==="bridgedCousins"){let U=V(g);if(U!==null){let Q=a.divisions[P[U]].values,ee=Object.keys(Q),ne=Q[ee[0]],se=typeof e.idKey=="function"?e.idKey(ne):e.idKey;f(q[T],ne[se],a.navigationRules.sibling_sibling)}}else if(H===G.length-1&&B==="bridgedCustom")f(q[T],a.behavior.customBridgePost,a.navigationRules.sibling_sibling);else if(H<G.length-1){let U=typeof e.idKey=="function"?e.idKey(w.values[G[H+1]]):e.idKey;f(q[T],w.values[G[H+1]][U],a.navigationRules.sibling_sibling)}if(!H&&B==="bridgedCousins"){let U=y(g);if(U!==null){let Q=a.divisions[P[U]].values,ee=Object.keys(Q),ne=Q[ee[ee.length-1]],se=typeof e.idKey=="function"?e.idKey(ne):e.idKey;f(ne[se],q[T],a.navigationRules.sibling_sibling)}}else!H&&B==="bridgedCustom"&&f(a.behavior.customBridgePrevious,q[T],a.navigationRules.sibling_sibling)}else if(g===P.length-1&&B==="bridgedCustom")f(q[T],a.behavior.customBridgePost,a.navigationRules.sibling_sibling);else if(!g&&B==="bridgedCustom")f(a.behavior.customBridgePrevious,q[T],a.navigationRules.sibling_sibling);else{let U=g===P.length-1&&B==="circular"?a.divisions[P[0]]:a.divisions[P[g+1]];if(U){let Q=F(H,q[T],w,U);if(Q){let ee=typeof e.idKey=="function"?e.idKey(Q):e.idKey;f(q[T],Q[ee],a.navigationRules.sibling_sibling)}}}H++}),g++})})}return Object.keys(r).forEach(d=>{var h;let m=r[d];(h=e.genericEdges)!=null&&h.length&&e.genericEdges.forEach(b=>{t[b.edgeId]||(t[b.edgeId]=b.edge),(!b.conditional||b.conditional&&b.conditional(m,b))&&m.edges.push(b.edgeId)})}),t},Ee=(e,r,s)=>{var t,c,f,k,p,n,R,S,o,C,L,x,v,d,m,h,b,u;let i=e.navigationRules;if(!i){let I=Object.keys(s||{});I.length>6&&console.error(`Building navigationRules. Dimension count is too high to automatically generate key commands. It is recommend you reduce your dimensions to 6 or fewer for end-user experience. If not, you must provide your own navigation rules in options.navigationRules. Details: Count is ${I.length}. Dimensions counted: ${I.join(", ")}.`);let j={},l={},$={},_=[...le],N=[...ae],a=(D,F)=>{let B=D&&F,P=!1,z=!1;if((j[D]||l[D])&&(l[D]=M({},j[D]),P=!0),F&&(j[F]||l[F])&&(l[F]=M({},j[F]),z=!0),B&&!P&&!z){_.length||console.error("Building navigationRules. Dimension count is too high to automatically generate key commands, we have run out of keyboard key pairs to assign. You must either provide your own navigation rules in options.navigationRules, provide rules when generating dimensions, or reduce dimension count.");let V=[..._.shift()];N.splice(N.indexOf(V[0]),1),N.splice(N.indexOf(V[1]),1),l[D]={direction:e.useDirectedEdges?"target":"source",key:V[0]},l[F]={direction:"target",key:V[1]}}else{if(!l[D]&&N.length){let V=N.shift(),y=[];_.forEach(g=>{V!==g[0]&&V!==g[1]&&y.push(g)}),_=y,l[D]={direction:e.useDirectedEdges?"target":"source",key:V}}if(F&&!l[F]&&N.length){let V=N.shift(),y=[];_.forEach(g=>{V!==g[0]&&V!==g[1]&&y.push(g)}),_=y,l[F]={direction:"target",key:V}}N.length||(l[D]||($[D]=D),F&&!l[F]&&($[F]=F))}};if(Object.keys(re).forEach(D=>{let F=M({},re[D]);e.useDirectedEdges&&(F.direction="target"),j[D]=F}),I.length){if((c=(t=e.dimensions)==null?void 0:t.parentOptions)!=null&&c.addLevel0){let D=((k=(f=e.dimensions.parentOptions.level1Options)==null?void 0:f.navigationRules)==null?void 0:k.parent_child)||["drill-out","drill-in"];a(D[0],D[1])}I.forEach(D=>{let F=s[D].navigationRules.parent_child,B=s[D].navigationRules.sibling_sibling;a(F[0],F[1]),a(B[0],B[1])})}if([(n=(p=e.frame)==null?void 0:p.navigationRules)==null?void 0:n.parent_child,(S=(R=e.frame)==null?void 0:R.navigationRules)==null?void 0:S.sibling_sibling,(C=(o=e.spatialGrid)==null?void 0:o.navigationRules)==null?void 0:C.x,(x=(L=e.spatialGrid)==null?void 0:L.navigationRules)==null?void 0:x.y,(d=(v=e.spatialGrid)==null?void 0:v.navigationRules)==null?void 0:d.parent_child,(h=(m=e.hierarchy)==null?void 0:m.navigationRules)==null?void 0:h.parent_child,(u=(b=e.hierarchy)==null?void 0:b.navigationRules)==null?void 0:u.sibling_sibling].forEach(D=>{D&&!l[D[0]]&&!l[D[1]]&&a(D[0],D[1])}),Object.keys(r).forEach(D=>{r[D].navigationRules.forEach(F=>{l[F]||a(F)})}),Object.keys($).length){let D={};Object.keys(l).forEach(B=>{D[l[B].key]=l[B].key}),Object.keys(j).forEach(B=>{!D[j[B].key]&&!de[j[B].key]&&N.push(j[B].key)});let F=M({},$);$={},Object.keys(F).forEach(B=>{a(B)}),Object.keys($).length&&console.error(`Building navigationRules. There are no more keys left to assign automatically. Recommended fixes: use fewer dimensions, use fewer GenericEdges, or build your own navigationRules. Rules remaining without keyboard keys: ${Object.keys($).join(", ")}.`)}i=l}return i},Ke=e=>{var R,S,o;e.addIds&&be(e);let r=fe(e),s=pe(r),i=Ie(r,s),t={},c=ve(r,s,t),f=he(r,s,t),k;if(r.frame){let C=Object.keys(i||{}),L=(c==null?void 0:c.rootId)||(f==null?void 0:f.rootId)||((o=(S=(R=r.dimensions)==null?void 0:R.parentOptions)==null?void 0:S.addLevel0)==null?void 0:o.id)||(C.length===1?i[C[0]].nodeId:void 0);k=ye(r,s,t,L)}t=Oe(r,s,i,t);let p=Ee(r,t,i),n={nodes:s,edges:t,dimensions:i,navigationRules:p};return k&&(n.frame=k),c&&(n.spatialGrid=c),f&&(n.hierarchy=f),n};export{be as addSimpleDataIDs,Oe as buildEdges,me as buildNodeStructureFromVegaLite,pe as buildNodes,Ee as buildRules,Ke as buildStructure,Ae as default,Ie as scaffoldDimensions};
|
package/dist/text-chat.cjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
var
|
|
1
|
+
var G=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var ve=Object.prototype.hasOwnProperty;var be=(t,e)=>{for(var i in e)G(t,i,{get:e[i],enumerable:!0})},we=(t,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ye(e))!ve.call(t,r)&&r!==i&&G(t,r,{get:()=>e[r],enumerable:!(s=fe(e,r))||s.enumerable});return t};var ke=t=>we(G({},"__esModule",{value:!0}),t);var U=(t,e,i)=>new Promise((s,r)=>{var n=c=>{try{p(i.next(c))}catch(d){r(d)}},o=c=>{try{p(i.throw(c))}catch(d){r(d)}},p=c=>c.done?s(c.value):Promise.resolve(c.value).then(n,o);p((i=i.apply(t,e)).next())});var Re={};be(Re,{default:()=>Te});module.exports=ke(Re);var J={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down",Period:"forward",Comma:"backward",Escape:"drill-out",Enter:"drill-in"};var z={left:{key:"ArrowLeft",direction:"source"},right:{key:"ArrowRight",direction:"target"},up:{key:"ArrowUp",direction:"source"},down:{key:"ArrowDown",direction:"target"},"drill-in":{key:"Enter",direction:"target"},"drill-out":{key:"Backspace",direction:"source"},backward:{key:"Comma",direction:"source"},forward:{key:"Period",direction:"target"},previous:{key:"Semicolon",direction:"source"},next:{key:"Quote",direction:"target"},exit:{key:"Escape",direction:"target"},help:{key:"KeyY",direction:"target"},undo:{key:"KeyZ",direction:"target"}};var se=t=>{let e={},i=J,s=z;return e.moveTo=r=>{let n=t.structure.nodes[r];if(n)return n},e.move=(r,n)=>{if(r){let o=t.structure.nodes[r];if(o.edges){let p=null,c=0,d=s[n];if(!d)return;let f=(g,a)=>{if(g!==n)return null;let v={target:typeof a.target=="string"?a.target:a.target(o,r),source:typeof a.source=="string"?a.source:a.source(o,r)};return v[d.direction]!==r?v[d.direction]:null};for(c=0;c<o.edges.length;c++){let g=t.structure.edges[o.edges[c]];if(g.navigationRules.forEach(a=>{p||(p=f(a,g))}),p)break}return p?e.moveTo(p):void 0}}},e.enter=()=>{if(t.entryPoint)return e.moveTo(t.entryPoint);console.error("No entry point was specified in InputOptions, returning undefined")},e.exit=()=>{if(t.exitPoint)return t.exitPoint;console.error("No exit point was specified in InputOptions, returning undefined")},e.keydownValidator=r=>{let n=i[r.code];if(n)return n},e.focus=r=>{let n=document.getElementById(r);n&&n.focus()},e.setNavigationKeyBindings=r=>{r?(i={},s=r,Object.keys(r).forEach(n=>{let o=r[n];i[o.key]=n})):(i=J,s=z)},e.setNavigationKeyBindings(t.navigationRules),e};var xe=t=>{var e,i,s,r,n;if((e=t.semantics)!=null&&e.label){let o=typeof t.semantics.label=="function"?t.semantics.label():t.semantics.label;if(o)return o}if(!t.derivedNode)return t.data?Object.keys(t.data).map(o=>`${o}: ${t.data[o]}`).join(". ")+". Data point.":t.id;if((i=t.data)!=null&&i.dimensionKey){let o=0,p=Object.keys(t.data.divisions||{});p.forEach(d=>{o+=Object.keys(t.data.divisions[d].values||{}).length});let c=`${t.derivedNode}.`;return c+=p.length&&o?` ${p.length} division${p.length>1?"s":""}, ${o} datapoint${o>1?"s":""}.`:" No child data points.",c+=` ${t.data.type} dimension.`,c}return`${t.derivedNode}: ${(s=t.data)==null?void 0:s[t.derivedNode]}. ${Object.keys(((r=t.data)==null?void 0:r.values)||{}).length} child data point${Object.keys(((n=t.data)==null?void 0:n.values)||{}).length>1?"s":""}. Division.`},Ne=(t,e,i)=>{let s=new Set,r=i.navigationRules||{};return e.edges&&e.edges.forEach(n=>{let o=i.edges[n];o&&o.navigationRules.forEach(p=>{let c=r[p];if(!c)return;let d=c.direction==="target"?o.target:o.source,f=typeof d=="function"?d(e,t):d;f&&f!==t&&s.add(p)})}),Array.from(s)},le=t=>t.navigationRules?Object.keys(t.navigationRules):[],Q=(t,e)=>{let i=t.length,s=e.length,r=Array.from({length:i+1},()=>Array(s+1).fill(0));for(let n=0;n<=i;n++)r[n][0]=n;for(let n=0;n<=s;n++)r[0][n]=n;for(let n=1;n<=i;n++)for(let o=1;o<=s;o++){let p=t[n-1]===e[o-1]?0:1;r[n][o]=Math.min(r[n-1][o]+1,r[n][o-1]+1,r[n-1][o-1]+p),n>1&&o>1&&t[n-1]===e[o-2]&&t[n-2]===e[o-1]&&(r[n][o]=Math.min(r[n][o],r[n-2][o-2]+p))}return r[i][s]},Ce=t=>t<=4?1:2,Ee=(t,e,i={})=>{let s=t.toLowerCase().trim(),r=e.find(a=>a.toLowerCase()===s);if(r)return{match:r,ambiguous:[]};let n=e.find(a=>i[a]&&i[a].toLowerCase()===s);if(n)return{match:n,ambiguous:[]};let o=e.filter(a=>a.toLowerCase().startsWith(s));if(o.length===1)return{match:o[0],ambiguous:[]};let p=e.filter(a=>{if(!i[a])return!1;let v=i[a].toLowerCase();return v.startsWith(s)?!0:v.split(/\s+/).some(R=>R.startsWith(s))}),c=new Set([...o,...p]),d=Array.from(c);if(d.length===1)return{match:d[0],ambiguous:[]};if(d.length>1)return{match:null,ambiguous:d};let f=Ce(s.length),g=[];for(let a=0;a<e.length;a++){let v=e[a],R=Q(s,v.toLowerCase());if(R<=f){g.push({candidate:v,dist:R});continue}if(i[v]){let S=i[v].toLowerCase().split(/\s+/);for(let A=0;A<S.length;A++)if(Q(s,S[A])<=f){g.push({candidate:v,dist:Q(s,S[A])});break}}}return g.length===1?{match:g[0].candidate,ambiguous:[]}:g.length>1?(g.sort((a,v)=>a.dist-v.dist),g[0].dist<g[1].dist?{match:g[0].candidate,ambiguous:[]}:{match:null,ambiguous:g.map(a=>a.candidate)}):{match:null,ambiguous:[]}},V=(t,e)=>e[t]?`${e[t]} (${t})`:t,Ae=(t,e,i,s=10)=>{let r=t.toLowerCase(),n=[],o=Object.keys(e.nodes);for(let p=0;p<o.length&&n.length<s;p++){let c=o[p],d=e.nodes[c],f=!1;if(d.data&&!f){let g=Object.keys(d.data);for(let a=0;a<g.length&&!f;a++){let v=d.data[g[a]];v!=null&&typeof v!="object"&&String(v).toLowerCase().includes(r)&&(f=!0)}}!f&&d.derivedNode&&d.derivedNode.toLowerCase().includes(r)&&(f=!0),!f&&c.toLowerCase().includes(r)&&(f=!0),f&&n.push({nodeId:c,description:i(d)})}return n},Te=t=>{var re,oe,ie,ae;let{structure:e,container:i,entryPoint:s,describeNode:r=xe,commandLabels:n={},onNavigate:o,onExit:p,onClick:c,onHover:d,llm:f,data:g}=t,a=typeof i=="string"?document.getElementById(i):i;if(!a)throw new Error(`textChat: container "${i}" not found`);let v=Object.keys(e.nodes).find(l=>e.nodes[l].dimensionLevel===0),R=e.dimensions?(re=e.dimensions[Object.keys(e.dimensions)[0]])==null?void 0:re.nodeId:void 0,S=s||((oe=e.frame)==null?void 0:oe.rootId)||v||((ie=e.spatialGrid)==null?void 0:ie.rootId)||((ae=e.hierarchy)==null?void 0:ae.rootId)||R||Object.keys(e.nodes)[0],A=se({structure:e,navigationRules:e.navigationRules||{},entryPoint:S}),b=null,Z=Math.random().toString(36).slice(2,8),L=[],C=-1,I=null,P=[],ce=()=>{let l=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
|
|
2
2
|
|
|
3
|
-
`;if(g&&g.length>0){let
|
|
4
|
-
`);
|
|
5
|
-
- Columns: ${
|
|
3
|
+
`;if(g&&g.length>0){let h=Object.keys(g[0]),m=g.slice(0,3).map(N=>JSON.stringify(N)).join(`
|
|
4
|
+
`);l+=`DATASET SUMMARY:
|
|
5
|
+
- Columns: ${h.join(", ")}
|
|
6
6
|
- Rows: ${g.length}
|
|
7
7
|
- Sample (first 3):
|
|
8
8
|
${m}
|
|
9
9
|
|
|
10
|
-
`,
|
|
10
|
+
`,l+=`FULL DATASET (JSON):
|
|
11
11
|
`+JSON.stringify(g)+`
|
|
12
12
|
|
|
13
|
-
`}if(
|
|
13
|
+
`}if(b){let h=e.nodes[b];l+=`CURRENT POSITION: ${h?r(h):b}
|
|
14
14
|
|
|
15
|
-
`}else
|
|
15
|
+
`}else l+=`CURRENT POSITION: Not yet navigated into the structure.
|
|
16
16
|
|
|
17
|
-
`;return
|
|
17
|
+
`;return l+=`PRIORITY: Always prefer answers that can be verified against the dataset. For any statistical or quantitative claim (averages, comparisons, trends, extremes), briefly describe the method you used. Avoid open-ended or contextual claims that go beyond what the data can support \u2014 if the user asks something that cannot be checked against the dataset, say so and suggest they verify externally.
|
|
18
18
|
|
|
19
|
-
`,
|
|
19
|
+
`,l+=`VERIFICATION: When the user asks you to verify a claim, write a short Python script (using the dataset as a JSON array) that computes the answer, and show the expected output. If the claim is too open-ended to verify with code, explain why and recommend external verification.
|
|
20
20
|
|
|
21
|
-
`,
|
|
21
|
+
`,l+='IMPORTANT: Your responses may contain errors. The user has been told they can ask you to "verify" any answer, and you will attempt to provide a Python script to check it.',l},O=document.createElement("div");O.className="dn-text-chat";let k=document.createElement("div");k.className="dn-text-chat-log",k.setAttribute("role","log"),k.setAttribute("aria-live","polite"),O.appendChild(k);let W=document.createElement("div");W.className="dn-text-chat-controls";let Y=document.createElement("label"),D=document.createElement("input");D.type="checkbox",D.checked=!0,D.addEventListener("change",()=>{k.setAttribute("aria-live",D.checked?"polite":"off")}),Y.appendChild(D),Y.appendChild(document.createTextNode(" Automatically announce to screen readers")),W.appendChild(Y),O.appendChild(W);let $=document.createElement("form");$.className="dn-text-chat-form";let M=document.createElement("label");M.setAttribute("for",`dn-text-chat-input-${Z}`),M.className="dn-text-chat-sr-only",M.textContent="Navigation command";let x=document.createElement("input");x.type="text",x.id=`dn-text-chat-input-${Z}`,x.autocomplete="off",x.setAttribute("placeholder","Type a command...");let q=document.createElement("button");q.type="submit",q.textContent="Send",$.appendChild(M),$.appendChild(x),$.appendChild(q),O.appendChild($),a.appendChild(O);let X="";x.addEventListener("keydown",l=>{if(l.key==="ArrowUp"){if(l.preventDefault(),L.length===0)return;C===-1?(X=x.value,C=L.length-1):C>0&&C--,x.value=L[C]}else if(l.key==="ArrowDown"){if(l.preventDefault(),C===-1)return;C<L.length-1?(C++,x.value=L[C]):(C=-1,x.value=X)}});let F=(l,h)=>{let m=document.createElement("div");m.className=`dn-text-chat-message ${h}`,m.textContent=l,k.appendChild(m),k.scrollTop=k.scrollHeight},B=l=>F(l,"dn-text-chat-system"),de=l=>F(`> ${l}`,"dn-text-chat-input-echo"),y=l=>F(l,"dn-text-chat-response"),ue=(l,h)=>{let m=document.createElement("div");m.className="dn-text-chat-message dn-text-chat-response";let N=document.createElement("span");N.textContent=l,m.appendChild(N);let E=document.createElement("ol");E.className="dn-text-chat-choices",h.forEach(K=>{let T=document.createElement("li");T.textContent=K,E.appendChild(T)}),m.appendChild(E),k.appendChild(m),k.scrollTop=k.scrollHeight},_=l=>U(void 0,null,function*(){let h={role:"system",content:ce()};P.push({role:"user",content:l});let m=document.createElement("div");m.className="dn-text-chat-message dn-text-chat-llm-thinking",m.textContent="Thinking...",k.appendChild(m),k.scrollTop=k.scrollHeight;try{let N=yield f([h,...P]);return k.removeChild(m),N===null?(P.pop(),null):(P.push({role:"assistant",content:N}),y(N),N)}catch(N){return k.removeChild(m),P.pop(),y(`Error: ${N.message||"Could not get a response."}`),""}});f?(B('Text navigation ready. Type "enter" to begin navigating, "help" for commands, or ask a question about the data.'),B('Note: AI-generated answers may be inaccurate. You can ask the model to "verify" any answer \u2014 it will attempt to provide a Python script that checks the claim against the dataset. If a claim cannot be verified with code, it should be verified externally.')):B('Text navigation ready. Type "enter" to begin or "help" for available commands.');let ee=["enter","help","more","more help","clear","click","select","hover","inspect"],te=l=>{let h=A.moveTo(l);h?(b=h.id,o&&o(h),y(`Moved to: ${r(h)}`)):y("Could not move to that node.")},ne=l=>U(void 0,null,function*(){let h=l.trim();if(!h)return;de(h);let m=h.toLowerCase();if(I){let u=parseInt(h,10);if(!isNaN(u)&&u>=1&&u<=I.length){let w=I[u-1];I=null,te(w.nodeId);return}I=null}if(m==="clear"){k.innerHTML="",B('Chat cleared. Type "help" for available commands.');return}if(m==="enter"){if(b){y('Already in the structure. Type "help" to see available commands.');return}let u=A.enter();if(!u){y("Could not enter the structure. No entry point found.");return}b=u.id,o&&o(u),y(`Entered: ${r(u)}`);return}if(m==="help"){let u=f?" You can also type any question about the data.":"",w=[];c&&w.push('"click" or "select"'),d&&w.push('"hover" or "inspect"');let j=w.length?` Interaction: ${w.join(", ")}.`:"";if(!b)y('Not yet in the structure. Type "enter" to begin navigating, or "move to <search>" to jump to a node.'+j+u);else{let me=e.nodes[b],he=Ne(b,me,e).map(ge=>V(ge,n));y(`Available: ${he.join(", ")}, move to <search>.`+j+u)}return}if(m==="click"||m==="select"){if(!b){y('Not in the structure. Type "enter" to begin.');return}let u=e.nodes[b];c&&u?(c(u),y(`Clicked: ${r(u)}`)):y(c?"Nothing to click here.":"Click interaction is not enabled for this chart.");return}if(m==="hover"||m==="inspect"){if(!b){y('Not in the structure. Type "enter" to begin.');return}let u=e.nodes[b];d&&u?(d(u),y(`Hovering over: ${r(u)}`)):y(d?"Nothing to hover over here.":"Hover interaction is not enabled for this chart.");return}if(m.startsWith("move to ")){let u=h.slice(8).trim();if(!u){y("Usage: move to <search term>");return}let w=Ae(u,e,r);w.length===0?y(`No nodes found matching "${u}".`):w.length===1?te(w[0].nodeId):(I=w,ue(`Found ${w.length} matches. Type a number to move there:`,w.map(j=>j.description)));return}if(m==="more"||m==="more help"){let w=le(e).map(j=>V(j,n));y(`All navigation rules: ${w.join(", ")}.`);return}if(!b){if(f&&(yield _(h))!==null)return;y('Type "enter" to begin navigating the structure, or "move to <search>" to jump to a node.'+(f?" Enter an API key above to ask questions about the data.":""));return}let N=le(e),{match:E,ambiguous:K}=Ee(m,[...N,...ee],n);if(E&&ee.includes(E)){yield ne(E);return}if(!E&&K.length>0){let u=K.map(w=>V(w,n));y(`Did you mean: ${u.join(", ")}?`);return}if(!E){if(f&&(yield _(h))!==null)return;let u=f?" Enter an API key above to ask questions about the data.":"";y(`Unknown command "${h}". Type "help" for available commands.`+u);return}let T=E,pe=n[T]||T;if(T==="exit"){b=null,p&&p(),y('Exited the structure. Type "enter" to re-enter.');return}let H=A.move(b,T);H?(b=H.id,o&&o(H),y(`${pe}: ${r(H)}`)):y(`Cannot move "${T}" from here.`)});return $.addEventListener("submit",l=>U(void 0,null,function*(){l.preventDefault();let h=x.value.trim();h&&(L.push(h),C=-1),yield ne(x.value),x.value="",x.focus()})),{destroy(){a.removeChild(O)},getCurrentNode(){return b&&e.nodes[b]||null}}};
|
package/dist/text-chat.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as se}from"./chunk-QT52GVQM.js";import{g as F}from"./chunk-B5HGEXMZ.js";var me=t=>{var e,d,u,a,o;if((e=t.semantics)!=null&&e.label){let n=typeof t.semantics.label=="function"?t.semantics.label():t.semantics.label;if(n)return n}if(!t.derivedNode)return t.data?Object.keys(t.data).map(n=>`${n}: ${t.data[n]}`).join(". ")+". Data point.":t.id;if((d=t.data)!=null&&d.dimensionKey){let n=0,f=Object.keys(t.data.divisions||{});f.forEach(m=>{n+=Object.keys(t.data.divisions[m].values||{}).length});let b=`${t.derivedNode}.`;return b+=f.length&&n?` ${f.length} division${f.length>1?"s":""}, ${n} datapoint${n>1?"s":""}.`:" No child data points.",b+=` ${t.data.type} dimension.`,b}return`${t.derivedNode}: ${(u=t.data)==null?void 0:u[t.derivedNode]}. ${Object.keys(((a=t.data)==null?void 0:a.values)||{}).length} child data point${Object.keys(((o=t.data)==null?void 0:o.values)||{}).length>1?"s":""}. Division.`},pe=(t,e,d)=>{let u=new Set,a=d.navigationRules||{};return e.edges&&e.edges.forEach(o=>{let n=d.edges[o];n&&n.navigationRules.forEach(f=>{let b=a[f];if(!b)return;let m=b.direction==="target"?n.target:n.source,p=typeof m=="function"?m(e,t):m;p&&p!==t&&u.add(f)})}),Array.from(u)},ae=t=>t.navigationRules?Object.keys(t.navigationRules):[],z=(t,e)=>{let d=t.length,u=e.length,a=Array.from({length:d+1},()=>Array(u+1).fill(0));for(let o=0;o<=d;o++)a[o][0]=o;for(let o=0;o<=u;o++)a[0][o]=o;for(let o=1;o<=d;o++)for(let n=1;n<=u;n++){let f=t[o-1]===e[n-1]?0:1;a[o][n]=Math.min(a[o-1][n]+1,a[o][n-1]+1,a[o-1][n-1]+f),o>1&&n>1&&t[o-1]===e[n-2]&&t[o-2]===e[n-1]&&(a[o][n]=Math.min(a[o][n],a[o-2][n-2]+f))}return a[d][u]},ge=t=>t<=4?1:2,fe=(t,e,d={})=>{let u=t.toLowerCase().trim(),a=e.find(l=>l.toLowerCase()===u);if(a)return{match:a,ambiguous:[]};let o=e.find(l=>d[l]&&d[l].toLowerCase()===u);if(o)return{match:o,ambiguous:[]};let n=e.filter(l=>l.toLowerCase().startsWith(u));if(n.length===1)return{match:n[0],ambiguous:[]};let f=e.filter(l=>{if(!d[l])return!1;let x=d[l].toLowerCase();return x.startsWith(u)?!0:x.split(/\s+/).some(I=>I.startsWith(u))}),b=new Set([...n,...f]),m=Array.from(b);if(m.length===1)return{match:m[0],ambiguous:[]};if(m.length>1)return{match:null,ambiguous:m};let p=ge(u.length),g=[];for(let l=0;l<e.length;l++){let x=e[l],I=z(u,x.toLowerCase());if(I<=p){g.push({candidate:x,dist:I});continue}if(d[x]){let M=d[x].toLowerCase().split(/\s+/);for(let T=0;T<M.length;T++)if(z(u,M[T])<=p){g.push({candidate:x,dist:z(u,M[T])});break}}}return g.length===1?{match:g[0].candidate,ambiguous:[]}:g.length>1?(g.sort((l,x)=>l.dist-x.dist),g[0].dist<g[1].dist?{match:g[0].candidate,ambiguous:[]}:{match:null,ambiguous:g.map(l=>l.candidate)}):{match:null,ambiguous:[]}},B=(t,e)=>e[t]?`${e[t]} (${t})`:t,ve=(t,e,d,u=10)=>{let a=t.toLowerCase(),o=[],n=Object.keys(e.nodes);for(let f=0;f<n.length&&o.length<u;f++){let b=n[f],m=e.nodes[b],p=!1;if(m.data&&!p){let g=Object.keys(m.data);for(let l=0;l<g.length&&!p;l++){let x=m.data[g[l]];x!=null&&typeof x!="object"&&String(x).toLowerCase().includes(a)&&(p=!0)}}!p&&m.derivedNode&&m.derivedNode.toLowerCase().includes(a)&&(p=!0),!p&&b.toLowerCase().includes(a)&&(p=!0),p&&o.push({nodeId:b,description:d(m)})}return o},Ce=t=>{var ee,te,ne,oe;let{structure:e,container:d,entryPoint:u,describeNode:a=me,commandLabels:o={},onNavigate:n,onExit:f,onClick:b,onHover:m,llm:p,data:g}=t,l=typeof d=="string"?document.getElementById(d):d;if(!l)throw new Error(`textChat: container "${d}" not found`);let x=Object.keys(e.nodes).find(s=>e.nodes[s].dimensionLevel===0),I=e.dimensions?(ee=e.dimensions[Object.keys(e.dimensions)[0]])==null?void 0:ee.nodeId:void 0,M=u||((te=e.frame)==null?void 0:te.rootId)||x||((ne=e.spatialGrid)==null?void 0:ne.rootId)||((oe=e.hierarchy)==null?void 0:oe.rootId)||I||Object.keys(e.nodes)[0],T=se({structure:e,navigationRules:e.navigationRules||{},entryPoint:M}),v=null,G=Math.random().toString(36).slice(2,8),L=[],E=-1,A=null,S=[],re=()=>{let s=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
|
|
2
2
|
|
|
3
|
-
`;if(
|
|
3
|
+
`;if(g&&g.length>0){let c=Object.keys(g[0]),i=g.slice(0,3).map(w=>JSON.stringify(w)).join(`
|
|
4
4
|
`);s+=`DATASET SUMMARY:
|
|
5
5
|
- Columns: ${c.join(", ")}
|
|
6
|
-
- Rows: ${
|
|
6
|
+
- Rows: ${g.length}
|
|
7
7
|
- Sample (first 3):
|
|
8
8
|
${i}
|
|
9
9
|
|
|
10
10
|
`,s+=`FULL DATASET (JSON):
|
|
11
|
-
`+JSON.stringify(
|
|
11
|
+
`+JSON.stringify(g)+`
|
|
12
12
|
|
|
13
|
-
`}if(
|
|
13
|
+
`}if(v){let c=e.nodes[v];s+=`CURRENT POSITION: ${c?a(c):v}
|
|
14
14
|
|
|
15
15
|
`}else s+=`CURRENT POSITION: Not yet navigated into the structure.
|
|
16
16
|
|
|
@@ -18,4 +18,4 @@ import{a as _}from"./chunk-FP25I6TN.js";import"./chunk-MPFBSVCV.js";import{c as
|
|
|
18
18
|
|
|
19
19
|
`,s+=`VERIFICATION: When the user asks you to verify a claim, write a short Python script (using the dataset as a JSON array) that computes the answer, and show the expected output. If the claim is too open-ended to verify with code, explain why and recommend external verification.
|
|
20
20
|
|
|
21
|
-
`,s+='IMPORTANT: Your responses may contain errors. The user has been told they can ask you to "verify" any answer, and you will attempt to provide a Python script to check it.',s},
|
|
21
|
+
`,s+='IMPORTANT: Your responses may contain errors. The user has been told they can ask you to "verify" any answer, and you will attempt to provide a Python script to check it.',s},j=document.createElement("div");j.className="dn-text-chat";let C=document.createElement("div");C.className="dn-text-chat-log",C.setAttribute("role","log"),C.setAttribute("aria-live","polite"),j.appendChild(C);let W=document.createElement("div");W.className="dn-text-chat-controls";let Y=document.createElement("label"),P=document.createElement("input");P.type="checkbox",P.checked=!0,P.addEventListener("change",()=>{C.setAttribute("aria-live",P.checked?"polite":"off")}),Y.appendChild(P),Y.appendChild(document.createTextNode(" Automatically announce to screen readers")),W.appendChild(Y),j.appendChild(W);let O=document.createElement("form");O.className="dn-text-chat-form";let H=document.createElement("label");H.setAttribute("for",`dn-text-chat-input-${G}`),H.className="dn-text-chat-sr-only",H.textContent="Navigation command";let N=document.createElement("input");N.type="text",N.id=`dn-text-chat-input-${G}`,N.autocomplete="off",N.setAttribute("placeholder","Type a command...");let J=document.createElement("button");J.type="submit",J.textContent="Send",O.appendChild(H),O.appendChild(N),O.appendChild(J),j.appendChild(O),l.appendChild(j);let V="";N.addEventListener("keydown",s=>{if(s.key==="ArrowUp"){if(s.preventDefault(),L.length===0)return;E===-1?(V=N.value,E=L.length-1):E>0&&E--,N.value=L[E]}else if(s.key==="ArrowDown"){if(s.preventDefault(),E===-1)return;E<L.length-1?(E++,N.value=L[E]):(E=-1,N.value=V)}});let K=(s,c)=>{let i=document.createElement("div");i.className=`dn-text-chat-message ${c}`,i.textContent=s,C.appendChild(i),C.scrollTop=C.scrollHeight},D=s=>K(s,"dn-text-chat-system"),ie=s=>K(`> ${s}`,"dn-text-chat-input-echo"),h=s=>K(s,"dn-text-chat-response"),ce=(s,c)=>{let i=document.createElement("div");i.className="dn-text-chat-message dn-text-chat-response";let w=document.createElement("span");w.textContent=s,i.appendChild(w);let k=document.createElement("ol");k.className="dn-text-chat-choices",c.forEach(U=>{let $=document.createElement("li");$.textContent=U,k.appendChild($)}),i.appendChild(k),C.appendChild(i),C.scrollTop=C.scrollHeight},Q=s=>F(void 0,null,function*(){let c={role:"system",content:re()};S.push({role:"user",content:s});let i=document.createElement("div");i.className="dn-text-chat-message dn-text-chat-llm-thinking",i.textContent="Thinking...",C.appendChild(i),C.scrollTop=C.scrollHeight;try{let w=yield p([c,...S]);return C.removeChild(i),w===null?(S.pop(),null):(S.push({role:"assistant",content:w}),h(w),w)}catch(w){return C.removeChild(i),S.pop(),h(`Error: ${w.message||"Could not get a response."}`),""}});p?(D('Text navigation ready. Type "enter" to begin navigating, "help" for commands, or ask a question about the data.'),D('Note: AI-generated answers may be inaccurate. You can ask the model to "verify" any answer \u2014 it will attempt to provide a Python script that checks the claim against the dataset. If a claim cannot be verified with code, it should be verified externally.')):D('Text navigation ready. Type "enter" to begin or "help" for available commands.');let X=["enter","help","more","more help","clear","click","select","hover","inspect"],Z=s=>{let c=T.moveTo(s);c?(v=c.id,n&&n(c),h(`Moved to: ${a(c)}`)):h("Could not move to that node.")},_=s=>F(void 0,null,function*(){let c=s.trim();if(!c)return;ie(c);let i=c.toLowerCase();if(A){let r=parseInt(c,10);if(!isNaN(r)&&r>=1&&r<=A.length){let y=A[r-1];A=null,Z(y.nodeId);return}A=null}if(i==="clear"){C.innerHTML="",D('Chat cleared. Type "help" for available commands.');return}if(i==="enter"){if(v){h('Already in the structure. Type "help" to see available commands.');return}let r=T.enter();if(!r){h("Could not enter the structure. No entry point found.");return}v=r.id,n&&n(r),h(`Entered: ${a(r)}`);return}if(i==="help"){let r=p?" You can also type any question about the data.":"",y=[];b&&y.push('"click" or "select"'),m&&y.push('"hover" or "inspect"');let R=y.length?` Interaction: ${y.join(", ")}.`:"";if(!v)h('Not yet in the structure. Type "enter" to begin navigating, or "move to <search>" to jump to a node.'+R+r);else{let de=e.nodes[v],ue=pe(v,de,e).map(he=>B(he,o));h(`Available: ${ue.join(", ")}, move to <search>.`+R+r)}return}if(i==="click"||i==="select"){if(!v){h('Not in the structure. Type "enter" to begin.');return}let r=e.nodes[v];b&&r?(b(r),h(`Clicked: ${a(r)}`)):h(b?"Nothing to click here.":"Click interaction is not enabled for this chart.");return}if(i==="hover"||i==="inspect"){if(!v){h('Not in the structure. Type "enter" to begin.');return}let r=e.nodes[v];m&&r?(m(r),h(`Hovering over: ${a(r)}`)):h(m?"Nothing to hover over here.":"Hover interaction is not enabled for this chart.");return}if(i.startsWith("move to ")){let r=c.slice(8).trim();if(!r){h("Usage: move to <search term>");return}let y=ve(r,e,a);y.length===0?h(`No nodes found matching "${r}".`):y.length===1?Z(y[0].nodeId):(A=y,ce(`Found ${y.length} matches. Type a number to move there:`,y.map(R=>R.description)));return}if(i==="more"||i==="more help"){let y=ae(e).map(R=>B(R,o));h(`All navigation rules: ${y.join(", ")}.`);return}if(!v){if(p&&(yield Q(c))!==null)return;h('Type "enter" to begin navigating the structure, or "move to <search>" to jump to a node.'+(p?" Enter an API key above to ask questions about the data.":""));return}let w=ae(e),{match:k,ambiguous:U}=fe(i,[...w,...X],o);if(k&&X.includes(k)){yield _(k);return}if(!k&&U.length>0){let r=U.map(y=>B(y,o));h(`Did you mean: ${r.join(", ")}?`);return}if(!k){if(p&&(yield Q(c))!==null)return;let r=p?" Enter an API key above to ask questions about the data.":"";h(`Unknown command "${c}". Type "help" for available commands.`+r);return}let $=k,le=o[$]||$;if($==="exit"){v=null,f&&f(),h('Exited the structure. Type "enter" to re-enter.');return}let q=T.move(v,$);q?(v=q.id,n&&n(q),h(`${le}: ${a(q)}`)):h(`Cannot move "${$}" from here.`)});return O.addEventListener("submit",s=>F(void 0,null,function*(){s.preventDefault();let c=N.value.trim();c&&(L.push(c),E=-1),yield _(N.value),N.value="",N.focus()})),{destroy(){l.removeChild(j)},getCurrentNode(){return v&&e.nodes[v]||null}}};export{Ce as default};
|