data-navigator 2.4.1 → 3.0.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-7YO7HC2V.js +1 -0
- package/dist/chunk-EXUS2ZKK.js +1 -0
- package/dist/chunk-UNB4R2QN.js +1 -0
- package/dist/chunk-UZ7O3OBE.js +1 -0
- package/dist/chunk-XOJI42HR.js +1 -0
- package/dist/chunk-YWWPZKYP.js +1 -0
- package/dist/consts.cjs +1 -1
- package/dist/consts.js +1 -1
- package/dist/index.cjs +419 -19
- package/dist/index.d.cts +103 -2
- package/dist/index.d.ts +103 -2
- package/dist/index.js +406 -19
- 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 +1 -1
- package/dist/utilities.cjs +1 -1
- package/dist/utilities.js +1 -1
- package/package.json +1 -1
package/dist/rendering.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{c as H}from"./chunk-XOJI42HR.js";import{a as o,c as m,d as L,e as k,f as B,q as P,s as O}from"./chunk-7YO7HC2V.js";var T,w,v,h,E,S,j=class extends HTMLElement{constructor(){super(...arguments);L(this,E);L(this,T,[]);L(this,w,O);L(this,v,"label");L(this,h,!1)}static get observedAttributes(){return["title"]}set commands(b){k(this,T,b),m(this,h)&&B(this,E,S).call(this)}get commands(){return m(this,T)}set columns(b){k(this,w,b),m(this,h)&&B(this,E,S).call(this)}get columns(){return m(this,w)}set kbdColumn(b){k(this,v,b),m(this,h)&&B(this,E,S).call(this)}get kbdColumn(){return m(this,v)}attributeChangedCallback(){m(this,h)&&B(this,E,S).call(this)}connectedCallback(){k(this,h,!0),B(this,E,S).call(this)}disconnectedCallback(){k(this,h,!1)}};T=new WeakMap,w=new WeakMap,v=new WeakMap,h=new WeakMap,E=new WeakSet,S=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,T)){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:P.cssClass,spatialProperties:o({},P.spatialProperties),semantics:o({},P.semantics),parentSemantics:o({},P.parentSemantics),existingElement:o({},P.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],z=f&&i?c[g]:p==null?void 0:p[g],V=(G=r[u])==null?void 0:G[g];return typeof p=="function"?p(a,n.datum):typeof z=="function"?z(a,n.datum):z||V||(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 I=document.createElement(s("semantics","elementType")),F=s("semantics","attributes");typeof F=="object"&&Object.keys(F).forEach(u=>{d.setAttribute(u,F[u])}),I.setAttribute("role",s("semantics","role")),I.classList.add("dn-node-text"),a.showText&&(I.innerText=a.semantics.label);let M=s("semantics","label");M||console.error("Accessibility error: a label must be supplied to every rendered element using semantics.label."),I.setAttribute("aria-label",M),d.appendChild(I);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=H(n.navigationRules),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=H,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 J=Object.defineProperty,Ke=Object.defineProperties,Ee=Object.getOwnPropertyDescriptor,Ie=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?J(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,Ie(d));var Re=(e,d)=>{for(var i in d)J(e,i,{get:d[i],enumerable:!0})},De=(e,d,i,c)=>{if(d&&typeof d=="object"||typeof d=="function")for(let b of xe(d))!se.call(e,b)&&b!==i&&J(e,b,{get:()=>d[b],enumerable:!(c=Ee(d,b))||c.enumerable});return e};var ke=e=>De(J({},"__esModule",{value:!0}),e);var Ne={};Re(Ne,{addSimpleDataIDs:()=>fe,buildEdges:()=>be,buildNodeStructureFromVegaLite:()=>ge,buildNodes:()=>ve,buildRules:()=>he,buildStructure:()=>pe,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"},"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"}},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"},"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 ue=(e,d)=>{let i=Object.keys(e),c="";return i.forEach(b=>{c+=`${d&&d.omitKeyNames?"":b+": "}${e[b]}. `}),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):pe(e),ge=e=>{let d=ce,i={},c={},b={},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,h=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],I=(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=I(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 E=y.items[a+1];if(E){let v=I(E,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=I(K,"item");if(i[O]){let t=`${o.id}-${O}`;g.push(t),c[t]||(c[t]={source:o.id,target:O,navigationRules:["drill-out","drill-in"]})}}else if(u==="item"){let v=I(y,"group");if(i[v]){let K=`${v}-${o.id}`;g.push(K),c[K]||(c[K]={source:v,target:o.id,navigationRules:["drill-out","drill-in"]})}}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=I(n,o),f="render-"+g,E=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,b[f]={},b[f].renderId=f,b[f].spatialProperties={},b[f].spatialProperties.x=n.bounds.x1+E[0],b[f].spatialProperties.y=n.bounds.y1+E[1],b[f].spatialProperties.width=n.bounds.x2-n.bounds.x1,b[f].spatialProperties.height=n.bounds.y2-n.bounds.y1,b[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)}),b[f].semantics={},b[f].semantics.label=e.nodeDescriber?e.nodeDescriber(i[g].d,n,o):ue(i[g].d)},R=0;return h.items.forEach(n=>{if(L(n,R,e.vegaLiteSpec)){x(n,"group",s,R,h);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++})}R++}),Object.keys(i).forEach(n=>{i[n].edges=r(n)}),{nodes:i,edges:c,elementData:b,navigationRules:d}},fe=e=>{let d=0,i={};e.data.forEach(c=>{let b=typeof e.idKey=="function"?e.idKey(c):e.idKey;c[b]="_"+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[b]+="_"+l+i[l]+"_"+c[l]+i[c[l]],i[l]++,i[c[l]]++):(i[l]||(i[l]=0),c[b]+="_"+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,b=i[c];if(!b){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[b]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${b}.`);return}else{let l=typeof e.renderIdKey=="function"?e.renderIdKey(i):e.renderIdKey;d[b]={id:b,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],b=(m,s)=>{let h=s.numericalExtents[0],I=s.numericalExtents[1];s.numericalExtents[0]=h<m?h:m,s.numericalExtents[1]=I>m?I:m};return e.data.forEach(m=>{var I;let s=((I=e.dimensions)==null?void 0:I.values)||[],h=0;s.forEach(r=>{var x,R,p,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:((R=r.operations)==null?void 0:R.compressSparseDivisions)||!1,sortFunction:((p=r.operations)==null?void 0:p.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:["drill-out_"+r.dimensionKey,"drill-in"]}},d[O]={id:O,renderId:t,derivedNode:r.dimensionKey,edges:[],dimensionLevel:1,data:i[r.dimensionKey],renderingStrategy:r.renderingStrategy||"singleSquare"}}let E=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,h):H(E.nodeId+"_"+g);if(v=E.divisions[O],!v){v=E.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,h):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=E.divisions[E.nodeId],v||(v=E.divisions[E.nodeId]={id:E.nodeId,sortFunction:((y=r.divisionOptions)==null?void 0:y.sortFunction)||void 0,values:{}}),r.operations||(r.operations={});let O=r.operations.createNumericalSubdivisions;E.subdivisions=typeof O=="number"&&O<1?1:O||1,O!==1&&(E.divisionOptions||(E.divisionOptions=r.divisionOptions),b(g,E))}let K=typeof e.idKey=="function"?e.idKey(m):e.idKey;v.values[m[K]]=m}}h++})}),Object.keys(i).forEach(m=>{var r,x,R,p,n;let s=i[m],h=s.divisions;if(s.type==="numerical"){h[s.nodeId].values=Object.fromEntries(Object.entries(h[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=h[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,E=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((R=s.divisionOptions)==null?void 0:R.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:((p=s.divisionOptions)==null?void 0:p.renderingStrategy)||"singleSquare"};let M=!1;for(;!M&&v<a.length;){let G=o[a[v]];if(G[m]<=f){let D=typeof e.idKey=="function"?e.idKey(G):G[e.idKey];s.divisions[t].values[D]=G,v++}else M=!0}O=f,E++}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 h[s.nodeId]}}else typeof((n=s.operations)==null?void 0:n.sortFunction)=="function"&&(s.divisions=Object.fromEntries(Object.entries(h).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 h=Object.keys(s.divisions),I={},r=!0;if(h.forEach(x=>{let R=s.divisions[x],p=Object.keys(R.values);p.length<=1?p.forEach(n=>{I[n]=T({},R.values[n])}):r=!1}),r){let x={id:s.nodeId,values:I};h.forEach(R=>{delete d[R]}),s.divisions={},s.divisions[s.nodeId]=x}}}),(P=e.dimensions)!=null&&P.adjustDimensions&&(i=e.dimensions.adjustDimensions(i)),i},be=(e,d,i)=>{var L,P,m,s,h,I,r,x,R,p;let c={},b=(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",E=!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&&E&&v(g),f&&b(n,y),E&&b(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=((I=(h=y.level1Options)==null?void 0:h.behavior)==null?void 0:I.extents)||"terminal",f=y.addLevel0,E=f?((x=(r=y.level1Options)==null?void 0:r.navigationRules)==null?void 0:x.parent_child)||["drill-out","drill-in"]:[],v=((p=(R=y.level1Options)==null?void 0:R.navigationRules)==null?void 0:p.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,E,"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,E,"source"):l(f.id,t.id,E,"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",M=(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:M,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 D=Object.keys(t.divisions),q=t.divisions[D[0]];if(D.length!==1)l(t.nodeId,q.id,t.navigationRules.parent_child,"source");else{let F=Object.keys(q.values),j=typeof e.idKey=="function"?e.idKey(q.values[F[0]]):e.idKey;l(t.nodeId,q.values[F[0]][j],t.navigationRules.parent_child,"source")}let me=F=>{for(let j=1;j<D.length;j++){let k=(F+j)%D.length;if(Object.keys(t.divisions[D[k]].values).length>0)return k}return null},Oe=F=>{for(let j=1;j<D.length;j++){let k=(F-j+D.length)%D.length;if(Object.keys(t.divisions[D[k]].values).length>0)return k}return null},B=0;D.forEach(F=>{let j=t.divisions[F];B===D.length-1&&(S==="circular"||S==="bridgedCousins"||S==="bridgedCustom")?l(j.id,t.divisions[D[0]].id,t.navigationRules.sibling_sibling):B<D.length-1&&l(j.id,t.divisions[D[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=D.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[D[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[D[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===D.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===D.length-1&&S==="circular"?t.divisions[D[0]]:t.divisions[D[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},he=(e,d,i)=>{var b,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={},h={},I={},r=[...ae],x=[...de],R=(p,n)=>{let o=p&&n,a=!1,u=!1;if((s[p]||h[p])&&(h[p]=T({},s[p]),a=!0),n&&(s[n]||h[n])&&(h[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),h[p]={direction:e.useDirectedEdges?"target":"source",key:y[0]},h[n]={direction:"target",key:y[1]}}else{if(!h[p]&&x.length){let y=x.shift(),g=[];r.forEach(f=>{y!==f[0]&&y!==f[1]&&g.push(f)}),r=g,h[p]={direction:e.useDirectedEdges?"target":"source",key:y}}if(n&&!h[n]&&x.length){let y=x.shift(),g=[];r.forEach(f=>{y!==f[0]&&y!==f[1]&&g.push(f)}),r=g,h[n]={direction:"target",key:y}}x.length||(h[p]||(I[p]=p),n&&!h[n]&&(I[n]=n))}};if(Object.keys(Z).forEach(p=>{let n=T({},Z[p]);e.useDirectedEdges&&(n.direction="target"),s[p]=n}),m.length){if((l=(b=e.dimensions)==null?void 0:b.parentOptions)!=null&&l.addLevel0){let p=((P=(L=e.dimensions.parentOptions.level1Options)==null?void 0:L.navigationRules)==null?void 0:P.parent_child)||["drill-out","drill-in"];R(p[0],p[1])}m.forEach(p=>{let n=i[p].navigationRules.parent_child,o=i[p].navigationRules.sibling_sibling;R(n[0],n[1]),R(o[0],o[1])})}if(Object.keys(d).forEach(p=>{d[p].navigationRules.forEach(n=>{h[n]||R(n)})}),Object.keys(I).length){let p={};Object.keys(h).forEach(o=>{p[h[o].key]=h[o].key}),Object.keys(s).forEach(o=>{!p[s[o].key]&&!oe[s[o].key]&&x.push(s[o].key)});let n=T({},I);I={},Object.keys(n).forEach(o=>{R(o)}),Object.keys(I).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(I).join(", ")}.`)}c=h}return c},pe=e=>{e.addIds&&fe(e);let d=ve(e),i=ye(e,d),c=be(e,d,i),b=he(e,c,i);return{nodes:d,edges:c,dimensions:i,navigationRules:b}};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 de,b as J}from"./chunk-XOJI42HR.js";import{a as V,b as ie,h as ne,j as te,l as se,m as Y,n as oe,p as re}from"./chunk-7YO7HC2V.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:["drill-out","drill-in"]})}}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:["drill-out","drill-in"]})}}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:["drill-out_"+o.dimensionKey,"drill-in"]}},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)||["drill-out","drill-in"]:[],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)||["drill-out","drill-in"];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};
|
package/dist/text-chat.cjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
var q=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var
|
|
1
|
+
var q=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var me=Object.prototype.hasOwnProperty;var he=(t,e)=>{for(var i in e)q(t,i,{get:e[i],enumerable:!0})},ge=(t,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of pe(e))!me.call(t,r)&&r!==i&&q(t,r,{get:()=>e[r],enumerable:!(s=ue(e,r))||s.enumerable});return t};var fe=t=>ge(q({},"__esModule",{value:!0}),t);var B=(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 Ne={};he(Ne,{default:()=>xe});module.exports=fe(Ne);var G={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down",Period:"forward",Comma:"backward",Escape:"drill-out",Enter:"drill-in"};var J={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 ne=t=>{let e={},i=G,s=J;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 b={target:typeof a.target=="string"?a.target:a.target(o,r),source:typeof a.source=="string"?a.source:a.source(o,r)};return b[d.direction]!==r?b[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=G,s=J)},e.setNavigationKeyBindings(t.navigationRules),e};var ye=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.`},ve=(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)},re=t=>t.navigationRules?Object.keys(t.navigationRules):[],z=(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]},be=t=>t<=4?1:2,we=(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 b=i[a].toLowerCase();return b.startsWith(s)?!0:b.split(/\s+/).some(T=>T.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=be(s.length),g=[];for(let a=0;a<e.length;a++){let b=e[a],T=z(s,b.toLowerCase());if(T<=f){g.push({candidate:b,dist:T});continue}if(i[b]){let v=i[b].toLowerCase().split(/\s+/);for(let R=0;R<v.length;R++)if(z(s,v[R])<=f){g.push({candidate:b,dist:z(s,v[R])});break}}}return g.length===1?{match:g[0].candidate,ambiguous:[]}:g.length>1?(g.sort((a,b)=>a.dist-b.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,ke=(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 b=d.data[g[a]];b!=null&&typeof b!="object"&&String(b).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},xe=t=>{var te;let{structure:e,container:i,entryPoint:s,describeNode:r=ye,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 b=s||(e.dimensions?(te=e.dimensions[Object.keys(e.dimensions)[0]])==null?void 0:te.nodeId:Object.keys(e.nodes)[0]),T=ne({structure:e,navigationRules:e.navigationRules||{},entryPoint:b}),v=null,R=Math.random().toString(36).slice(2,8),L=[],C=-1,O=null,P=[],oe=()=>{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(v){let
|
|
13
|
+
`}if(v){let h=e.nodes[v];l+=`CURRENT POSITION: ${h?r(h):v}
|
|
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},$=document.createElement("div");$.className="dn-text-chat";let k=document.createElement("div");k.className="dn-text-chat-log",k.setAttribute("role","log"),k.setAttribute("aria-live","polite"),$.appendChild(k);let U=document.createElement("div");U.className="dn-text-chat-controls";let W=document.createElement("label"),S=document.createElement("input");S.type="checkbox",S.checked=!0,S.addEventListener("change",()=>{k.setAttribute("aria-live",S.checked?"polite":"off")}),W.appendChild(S),W.appendChild(document.createTextNode(" Automatically announce to screen readers")),U.appendChild(W),$.appendChild(U);let I=document.createElement("form");I.className="dn-text-chat-form";let M=document.createElement("label");M.setAttribute("for",`dn-text-chat-input-${R}`),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-${R}`,x.autocomplete="off",x.setAttribute("placeholder","Type a command...");let Y=document.createElement("button");Y.type="submit",Y.textContent="Send",I.appendChild(M),I.appendChild(x),I.appendChild(Y),$.appendChild(I),a.appendChild($);let Z="";x.addEventListener("keydown",l=>{if(l.key==="ArrowUp"){if(l.preventDefault(),L.length===0)return;C===-1?(Z=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=Z)}});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},D=l=>F(l,"dn-text-chat-system"),ie=l=>F(`> ${l}`,"dn-text-chat-input-echo"),y=l=>F(l,"dn-text-chat-response"),ae=(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(H=>{let A=document.createElement("li");A.textContent=H,E.appendChild(A)}),m.appendChild(E),k.appendChild(m),k.scrollTop=k.scrollHeight},Q=l=>B(void 0,null,function*(){let h={role:"system",content:oe()};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?(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"],_=l=>{let h=T.moveTo(l);h?(v=h.id,o&&o(h),y(`Moved to: ${r(h)}`)):y("Could not move to that node.")},ee=l=>B(void 0,null,function*(){let h=l.trim();if(!h)return;ie(h);let m=h.toLowerCase();if(O){let u=parseInt(h,10);if(!isNaN(u)&&u>=1&&u<=O.length){let w=O[u-1];O=null,_(w.nodeId);return}O=null}if(m==="clear"){k.innerHTML="",D('Chat cleared. Type "help" for available commands.');return}if(m==="enter"){if(v){y('Already in the structure. Type "help" to see available commands.');return}let u=T.enter();if(!u){y("Could not enter the structure. No entry point found.");return}v=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(!v)y('Not yet in the structure. Type "enter" to begin navigating, or "move to <search>" to jump to a node.'+j+u);else{let le=e.nodes[v],ce=ve(v,le,e).map(de=>V(de,n));y(`Available: ${ce.join(", ")}, move to <search>.`+j+u)}return}if(m==="click"||m==="select"){if(!v){y('Not in the structure. Type "enter" to begin.');return}let u=e.nodes[v];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(!v){y('Not in the structure. Type "enter" to begin.');return}let u=e.nodes[v];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=ke(u,e,r);w.length===0?y(`No nodes found matching "${u}".`):w.length===1?_(w[0].nodeId):(O=w,ae(`Found ${w.length} matches. Type a number to move there:`,w.map(j=>j.description)));return}if(m==="more"||m==="more help"){let w=re(e).map(j=>V(j,n));y(`All navigation rules: ${w.join(", ")}.`);return}if(!v){if(f&&(yield Q(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=re(e),{match:E,ambiguous:H}=we(m,[...N,...X],n);if(E&&X.includes(E)){yield ee(E);return}if(!E&&H.length>0){let u=H.map(w=>V(w,n));y(`Did you mean: ${u.join(", ")}?`);return}if(!E){if(f&&(yield Q(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 A=E,se=n[A]||A;if(A==="exit"){v=null,p&&p(),y('Exited the structure. Type "enter" to re-enter.');return}let K=T.move(v,A);K?(v=K.id,o&&o(K),y(`${se}: ${r(K)}`)):y(`Cannot move "${A}" from here.`)});return I.addEventListener("submit",l=>B(void 0,null,function*(){l.preventDefault();let h=x.value.trim();h&&(L.push(h),C=-1),yield ee(x.value),x.value="",x.focus()})),{destroy(){a.removeChild($)},getCurrentNode(){return v&&e.nodes[v]||null}}};
|
package/dist/text-chat.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as _}from"./chunk-
|
|
1
|
+
import{a as _}from"./chunk-UNB4R2QN.js";import{g as q}from"./chunk-7YO7HC2V.js";var ce=e=>{var o,d,u,a,n;if((o=e.semantics)!=null&&o.label){let t=typeof e.semantics.label=="function"?e.semantics.label():e.semantics.label;if(t)return t}if(!e.derivedNode)return e.data?Object.keys(e.data).map(t=>`${t}: ${e.data[t]}`).join(". ")+". Data point.":e.id;if((d=e.data)!=null&&d.dimensionKey){let t=0,v=Object.keys(e.data.divisions||{});v.forEach(p=>{t+=Object.keys(e.data.divisions[p].values||{}).length});let b=`${e.derivedNode}.`;return b+=v.length&&t?` ${v.length} division${v.length>1?"s":""}, ${t} datapoint${t>1?"s":""}.`:" No child data points.",b+=` ${e.data.type} dimension.`,b}return`${e.derivedNode}: ${(u=e.data)==null?void 0:u[e.derivedNode]}. ${Object.keys(((a=e.data)==null?void 0:a.values)||{}).length} child data point${Object.keys(((n=e.data)==null?void 0:n.values)||{}).length>1?"s":""}. Division.`},le=(e,o,d)=>{let u=new Set,a=d.navigationRules||{};return o.edges&&o.edges.forEach(n=>{let t=d.edges[n];t&&t.navigationRules.forEach(v=>{let b=a[v];if(!b)return;let p=b.direction==="target"?t.target:t.source,g=typeof p=="function"?p(o,e):p;g&&g!==e&&u.add(v)})}),Array.from(u)},ee=e=>e.navigationRules?Object.keys(e.navigationRules):[],K=(e,o)=>{let d=e.length,u=o.length,a=Array.from({length:d+1},()=>Array(u+1).fill(0));for(let n=0;n<=d;n++)a[n][0]=n;for(let n=0;n<=u;n++)a[0][n]=n;for(let n=1;n<=d;n++)for(let t=1;t<=u;t++){let v=e[n-1]===o[t-1]?0:1;a[n][t]=Math.min(a[n-1][t]+1,a[n][t-1]+1,a[n-1][t-1]+v),n>1&&t>1&&e[n-1]===o[t-2]&&e[n-2]===o[t-1]&&(a[n][t]=Math.min(a[n][t],a[n-2][t-2]+v))}return a[d][u]},de=e=>e<=4?1:2,ue=(e,o,d={})=>{let u=e.toLowerCase().trim(),a=o.find(l=>l.toLowerCase()===u);if(a)return{match:a,ambiguous:[]};let n=o.find(l=>d[l]&&d[l].toLowerCase()===u);if(n)return{match:n,ambiguous:[]};let t=o.filter(l=>l.toLowerCase().startsWith(u));if(t.length===1)return{match:t[0],ambiguous:[]};let v=o.filter(l=>{if(!d[l])return!1;let x=d[l].toLowerCase();return x.startsWith(u)?!0:x.split(/\s+/).some(T=>T.startsWith(u))}),b=new Set([...t,...v]),p=Array.from(b);if(p.length===1)return{match:p[0],ambiguous:[]};if(p.length>1)return{match:null,ambiguous:p};let g=de(u.length),f=[];for(let l=0;l<o.length;l++){let x=o[l],T=K(u,x.toLowerCase());if(T<=g){f.push({candidate:x,dist:T});continue}if(d[x]){let m=d[x].toLowerCase().split(/\s+/);for(let A=0;A<m.length;A++)if(K(u,m[A])<=g){f.push({candidate:x,dist:K(u,m[A])});break}}}return f.length===1?{match:f[0].candidate,ambiguous:[]}:f.length>1?(f.sort((l,x)=>l.dist-x.dist),f[0].dist<f[1].dist?{match:f[0].candidate,ambiguous:[]}:{match:null,ambiguous:f.map(l=>l.candidate)}):{match:null,ambiguous:[]}},z=(e,o)=>o[e]?`${o[e]} (${e})`:e,he=(e,o,d,u=10)=>{let a=e.toLowerCase(),n=[],t=Object.keys(o.nodes);for(let v=0;v<t.length&&n.length<u;v++){let b=t[v],p=o.nodes[b],g=!1;if(p.data&&!g){let f=Object.keys(p.data);for(let l=0;l<f.length&&!g;l++){let x=p.data[f[l]];x!=null&&typeof x!="object"&&String(x).toLowerCase().includes(a)&&(g=!0)}}!g&&p.derivedNode&&p.derivedNode.toLowerCase().includes(a)&&(g=!0),!g&&b.toLowerCase().includes(a)&&(g=!0),g&&n.push({nodeId:b,description:d(p)})}return n},ge=e=>{var Z;let{structure:o,container:d,entryPoint:u,describeNode:a=ce,commandLabels:n={},onNavigate:t,onExit:v,onClick:b,onHover:p,llm:g,data:f}=e,l=typeof d=="string"?document.getElementById(d):d;if(!l)throw new Error(`textChat: container "${d}" not found`);let x=u||(o.dimensions?(Z=o.dimensions[Object.keys(o.dimensions)[0]])==null?void 0:Z.nodeId:Object.keys(o.nodes)[0]),T=_({structure:o,navigationRules:o.navigationRules||{},entryPoint:x}),m=null,A=Math.random().toString(36).slice(2,8),L=[],E=-1,I=null,M=[],te=()=>{let s=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
|
|
2
2
|
|
|
3
3
|
`;if(f&&f.length>0){let c=Object.keys(f[0]),i=f.slice(0,3).map(w=>JSON.stringify(w)).join(`
|
|
4
4
|
`);s+=`DATASET SUMMARY:
|
package/dist/utilities.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var a=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var s=(t,e)=>{for(var i in e)a(t,i,{get:e[i],enumerable:!0})},p=(t,e,i,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of d(e))!c.call(t,r)&&r!==i&&a(t,r,{get:()=>e[r],enumerable:!(o=l(e,r))||o.enumerable});return t};var u=t=>p(a({},"__esModule",{value:!0}),t);var w={};s(w,{createValidId:()=>m,describeNode:()=>g,getGenericCommandsFromNavRules:()=>y});module.exports=u(w);var n={"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"}};var g=(t,e)=>{let i=Object.keys(t),o="";return i.forEach(r=>{o+=`${e&&e.omitKeyNames?"":r+": "}${t[r]}. `}),o+=e&&e.semanticLabel||"Data point.",o},m=t=>"_"+t.replace(/[^a-zA-Z0-9_-]+/g,"_");function y(t){return t?Object.keys(t).map(e=>n[e]).filter(Boolean):[]}0&&(module.exports={createValidId,describeNode,getGenericCommandsFromNavRules});
|
package/dist/utilities.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b}from"./chunk-
|
|
1
|
+
import{a,b,c}from"./chunk-XOJI42HR.js";import"./chunk-7YO7HC2V.js";export{b as createValidId,a as describeNode,c as getGenericCommandsFromNavRules};
|