data-navigator 2.4.0 → 2.4.1
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/index.cjs +47 -49
- package/dist/index.js +47 -49
- package/dist/structure.cjs +1 -1
- package/dist/structure.js +1 -1
- package/package.json +1 -1
- package/text-chat.css +2 -2
package/dist/index.cjs
CHANGED
|
@@ -626,7 +626,8 @@ var scaffoldDimensions = (options, nodes) => {
|
|
|
626
626
|
let node = values[valueKeys[index]];
|
|
627
627
|
let value = node[s];
|
|
628
628
|
if (value <= i) {
|
|
629
|
-
|
|
629
|
+
const leafId = typeof options.idKey === "function" ? options.idKey(node) : node[options.idKey];
|
|
630
|
+
dimension.divisions[divisionId].values[leafId] = node;
|
|
630
631
|
index++;
|
|
631
632
|
} else {
|
|
632
633
|
limit = true;
|
|
@@ -638,11 +639,12 @@ var scaffoldDimensions = (options, nodes) => {
|
|
|
638
639
|
if (lastDivisionId && index < valueKeys.length) {
|
|
639
640
|
while (index < valueKeys.length) {
|
|
640
641
|
let node = values[valueKeys[index]];
|
|
641
|
-
|
|
642
|
+
const leafId = typeof options.idKey === "function" ? options.idKey(node) : node[options.idKey];
|
|
643
|
+
dimension.divisions[lastDivisionId].values[leafId] = node;
|
|
642
644
|
index++;
|
|
643
645
|
}
|
|
644
646
|
}
|
|
645
|
-
delete divisions[
|
|
647
|
+
delete divisions[dimension.nodeId];
|
|
646
648
|
}
|
|
647
649
|
} else if (typeof ((_e = dimension.operations) == null ? void 0 : _e.sortFunction) === "function") {
|
|
648
650
|
dimension.divisions = Object.fromEntries(
|
|
@@ -808,6 +810,22 @@ var buildEdges = (options, nodes, dimensions) => {
|
|
|
808
810
|
"source"
|
|
809
811
|
);
|
|
810
812
|
}
|
|
813
|
+
const findNextNonEmptyDivIdx = (fromIdx) => {
|
|
814
|
+
for (let step = 1; step < divisionKeys.length; step++) {
|
|
815
|
+
const idx = (fromIdx + step) % divisionKeys.length;
|
|
816
|
+
if (Object.keys(dimension.divisions[divisionKeys[idx]].values).length > 0)
|
|
817
|
+
return idx;
|
|
818
|
+
}
|
|
819
|
+
return null;
|
|
820
|
+
};
|
|
821
|
+
const findPrevNonEmptyDivIdx = (fromIdx) => {
|
|
822
|
+
for (let step = 1; step < divisionKeys.length; step++) {
|
|
823
|
+
const idx = (fromIdx - step + divisionKeys.length) % divisionKeys.length;
|
|
824
|
+
if (Object.keys(dimension.divisions[divisionKeys[idx]].values).length > 0)
|
|
825
|
+
return idx;
|
|
826
|
+
}
|
|
827
|
+
return null;
|
|
828
|
+
};
|
|
811
829
|
let j = 0;
|
|
812
830
|
divisionKeys.forEach((d) => {
|
|
813
831
|
let division = dimension.divisions[d];
|
|
@@ -859,22 +877,13 @@ var buildEdges = (options, nodes, dimensions) => {
|
|
|
859
877
|
dimension.navigationRules.sibling_sibling
|
|
860
878
|
);
|
|
861
879
|
} else if (i === valueKeys.length - 1 && extents2 === "bridgedCousins") {
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
dimension.navigationRules.sibling_sibling
|
|
870
|
-
);
|
|
871
|
-
} else {
|
|
872
|
-
const targetId = typeof options.idKey === "function" ? options.idKey(dimension.divisions[divisionKeys[0]].values[valueKeys[0]]) : options.idKey;
|
|
873
|
-
createEdge(
|
|
874
|
-
v[id],
|
|
875
|
-
dimension.divisions[divisionKeys[0]].values[valueKeys[0]][targetId],
|
|
876
|
-
dimension.navigationRules.sibling_sibling
|
|
877
|
-
);
|
|
880
|
+
const nextIdx = findNextNonEmptyDivIdx(j);
|
|
881
|
+
if (nextIdx !== null) {
|
|
882
|
+
const nextDivValues = dimension.divisions[divisionKeys[nextIdx]].values;
|
|
883
|
+
const nextDivValueKeys = Object.keys(nextDivValues);
|
|
884
|
+
const targetDatum = nextDivValues[nextDivValueKeys[0]];
|
|
885
|
+
const targetId = typeof options.idKey === "function" ? options.idKey(targetDatum) : options.idKey;
|
|
886
|
+
createEdge(v[id], targetDatum[targetId], dimension.navigationRules.sibling_sibling);
|
|
878
887
|
}
|
|
879
888
|
} else if (i === valueKeys.length - 1 && extents2 === "bridgedCustom") {
|
|
880
889
|
createEdge(
|
|
@@ -891,24 +900,13 @@ var buildEdges = (options, nodes, dimensions) => {
|
|
|
891
900
|
);
|
|
892
901
|
}
|
|
893
902
|
if (!i && extents2 === "bridgedCousins") {
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
dimension.navigationRules.sibling_sibling
|
|
902
|
-
);
|
|
903
|
-
} else {
|
|
904
|
-
const targetId = typeof options.idKey === "function" ? options.idKey(
|
|
905
|
-
dimension.divisions[divisionKeys[divisionKeys.length - 1]].values[valueKeys[valueKeys.length - 1]]
|
|
906
|
-
) : options.idKey;
|
|
907
|
-
createEdge(
|
|
908
|
-
dimension.divisions[divisionKeys[divisionKeys.length - 1]].values[valueKeys[valueKeys.length - 1]][targetId],
|
|
909
|
-
v[id],
|
|
910
|
-
dimension.navigationRules.sibling_sibling
|
|
911
|
-
);
|
|
903
|
+
const prevIdx = findPrevNonEmptyDivIdx(j);
|
|
904
|
+
if (prevIdx !== null) {
|
|
905
|
+
const prevDivValues = dimension.divisions[divisionKeys[prevIdx]].values;
|
|
906
|
+
const prevDivValueKeys = Object.keys(prevDivValues);
|
|
907
|
+
const targetDatum = prevDivValues[prevDivValueKeys[prevDivValueKeys.length - 1]];
|
|
908
|
+
const targetId = typeof options.idKey === "function" ? options.idKey(targetDatum) : options.idKey;
|
|
909
|
+
createEdge(targetDatum[targetId], v[id], dimension.navigationRules.sibling_sibling);
|
|
912
910
|
}
|
|
913
911
|
} else if (!i && extents2 === "bridgedCustom") {
|
|
914
912
|
createEdge(
|
|
@@ -1506,9 +1504,7 @@ var fuzzyMatch = (input, candidates, labels = {}) => {
|
|
|
1506
1504
|
const exactName = candidates.find((c) => c.toLowerCase() === lower);
|
|
1507
1505
|
if (exactName)
|
|
1508
1506
|
return { match: exactName, ambiguous: [] };
|
|
1509
|
-
const exactLabel = candidates.find(
|
|
1510
|
-
(c) => labels[c] && labels[c].toLowerCase() === lower
|
|
1511
|
-
);
|
|
1507
|
+
const exactLabel = candidates.find((c) => labels[c] && labels[c].toLowerCase() === lower);
|
|
1512
1508
|
if (exactLabel)
|
|
1513
1509
|
return { match: exactLabel, ambiguous: [] };
|
|
1514
1510
|
const namePrefix = candidates.filter((c) => c.toLowerCase().startsWith(lower));
|
|
@@ -1768,8 +1764,12 @@ var text_chat_default = (options) => {
|
|
|
1768
1764
|
}
|
|
1769
1765
|
});
|
|
1770
1766
|
if (llm) {
|
|
1771
|
-
addSystemMessage(
|
|
1772
|
-
|
|
1767
|
+
addSystemMessage(
|
|
1768
|
+
'Text navigation ready. Type "enter" to begin navigating, "help" for commands, or ask a question about the data.'
|
|
1769
|
+
);
|
|
1770
|
+
addSystemMessage(
|
|
1771
|
+
'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.'
|
|
1772
|
+
);
|
|
1773
1773
|
} else {
|
|
1774
1774
|
addSystemMessage('Text navigation ready. Type "enter" to begin or "help" for available commands.');
|
|
1775
1775
|
}
|
|
@@ -1838,9 +1838,7 @@ var text_chat_default = (options) => {
|
|
|
1838
1838
|
const node = structure.nodes[currentNodeId];
|
|
1839
1839
|
const available = getAvailableRules(currentNodeId, node, structure);
|
|
1840
1840
|
const formatted = available.map((r) => formatRule(r, commandLabels));
|
|
1841
|
-
addResponse(
|
|
1842
|
-
`Available: ${formatted.join(", ")}, move to <search>.` + interactionSuffix + llmHint
|
|
1843
|
-
);
|
|
1841
|
+
addResponse(`Available: ${formatted.join(", ")}, move to <search>.` + interactionSuffix + llmHint);
|
|
1844
1842
|
}
|
|
1845
1843
|
return;
|
|
1846
1844
|
}
|
|
@@ -1854,9 +1852,7 @@ var text_chat_default = (options) => {
|
|
|
1854
1852
|
onClick(node);
|
|
1855
1853
|
addResponse(`Clicked: ${describeNode2(node)}`);
|
|
1856
1854
|
} else {
|
|
1857
|
-
addResponse(
|
|
1858
|
-
onClick ? "Nothing to click here." : "Click interaction is not enabled for this chart."
|
|
1859
|
-
);
|
|
1855
|
+
addResponse(onClick ? "Nothing to click here." : "Click interaction is not enabled for this chart.");
|
|
1860
1856
|
}
|
|
1861
1857
|
return;
|
|
1862
1858
|
}
|
|
@@ -1909,7 +1905,9 @@ var text_chat_default = (options) => {
|
|
|
1909
1905
|
return;
|
|
1910
1906
|
}
|
|
1911
1907
|
const llmHint = llm ? " Enter an API key above to ask questions about the data." : "";
|
|
1912
|
-
addResponse(
|
|
1908
|
+
addResponse(
|
|
1909
|
+
'Type "enter" to begin navigating the structure, or "move to <search>" to jump to a node.' + llmHint
|
|
1910
|
+
);
|
|
1913
1911
|
return;
|
|
1914
1912
|
}
|
|
1915
1913
|
const allRules = getAllRuleNames(structure);
|
package/dist/index.js
CHANGED
|
@@ -604,7 +604,8 @@ var scaffoldDimensions = (options, nodes) => {
|
|
|
604
604
|
let node = values[valueKeys[index]];
|
|
605
605
|
let value = node[s];
|
|
606
606
|
if (value <= i) {
|
|
607
|
-
|
|
607
|
+
const leafId = typeof options.idKey === "function" ? options.idKey(node) : node[options.idKey];
|
|
608
|
+
dimension.divisions[divisionId].values[leafId] = node;
|
|
608
609
|
index++;
|
|
609
610
|
} else {
|
|
610
611
|
limit = true;
|
|
@@ -616,11 +617,12 @@ var scaffoldDimensions = (options, nodes) => {
|
|
|
616
617
|
if (lastDivisionId && index < valueKeys.length) {
|
|
617
618
|
while (index < valueKeys.length) {
|
|
618
619
|
let node = values[valueKeys[index]];
|
|
619
|
-
|
|
620
|
+
const leafId = typeof options.idKey === "function" ? options.idKey(node) : node[options.idKey];
|
|
621
|
+
dimension.divisions[lastDivisionId].values[leafId] = node;
|
|
620
622
|
index++;
|
|
621
623
|
}
|
|
622
624
|
}
|
|
623
|
-
delete divisions[
|
|
625
|
+
delete divisions[dimension.nodeId];
|
|
624
626
|
}
|
|
625
627
|
} else if (typeof ((_e = dimension.operations) == null ? void 0 : _e.sortFunction) === "function") {
|
|
626
628
|
dimension.divisions = Object.fromEntries(
|
|
@@ -786,6 +788,22 @@ var buildEdges = (options, nodes, dimensions) => {
|
|
|
786
788
|
"source"
|
|
787
789
|
);
|
|
788
790
|
}
|
|
791
|
+
const findNextNonEmptyDivIdx = (fromIdx) => {
|
|
792
|
+
for (let step = 1; step < divisionKeys.length; step++) {
|
|
793
|
+
const idx = (fromIdx + step) % divisionKeys.length;
|
|
794
|
+
if (Object.keys(dimension.divisions[divisionKeys[idx]].values).length > 0)
|
|
795
|
+
return idx;
|
|
796
|
+
}
|
|
797
|
+
return null;
|
|
798
|
+
};
|
|
799
|
+
const findPrevNonEmptyDivIdx = (fromIdx) => {
|
|
800
|
+
for (let step = 1; step < divisionKeys.length; step++) {
|
|
801
|
+
const idx = (fromIdx - step + divisionKeys.length) % divisionKeys.length;
|
|
802
|
+
if (Object.keys(dimension.divisions[divisionKeys[idx]].values).length > 0)
|
|
803
|
+
return idx;
|
|
804
|
+
}
|
|
805
|
+
return null;
|
|
806
|
+
};
|
|
789
807
|
let j = 0;
|
|
790
808
|
divisionKeys.forEach((d) => {
|
|
791
809
|
let division = dimension.divisions[d];
|
|
@@ -837,22 +855,13 @@ var buildEdges = (options, nodes, dimensions) => {
|
|
|
837
855
|
dimension.navigationRules.sibling_sibling
|
|
838
856
|
);
|
|
839
857
|
} else if (i === valueKeys.length - 1 && extents2 === "bridgedCousins") {
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
dimension.navigationRules.sibling_sibling
|
|
848
|
-
);
|
|
849
|
-
} else {
|
|
850
|
-
const targetId = typeof options.idKey === "function" ? options.idKey(dimension.divisions[divisionKeys[0]].values[valueKeys[0]]) : options.idKey;
|
|
851
|
-
createEdge(
|
|
852
|
-
v[id],
|
|
853
|
-
dimension.divisions[divisionKeys[0]].values[valueKeys[0]][targetId],
|
|
854
|
-
dimension.navigationRules.sibling_sibling
|
|
855
|
-
);
|
|
858
|
+
const nextIdx = findNextNonEmptyDivIdx(j);
|
|
859
|
+
if (nextIdx !== null) {
|
|
860
|
+
const nextDivValues = dimension.divisions[divisionKeys[nextIdx]].values;
|
|
861
|
+
const nextDivValueKeys = Object.keys(nextDivValues);
|
|
862
|
+
const targetDatum = nextDivValues[nextDivValueKeys[0]];
|
|
863
|
+
const targetId = typeof options.idKey === "function" ? options.idKey(targetDatum) : options.idKey;
|
|
864
|
+
createEdge(v[id], targetDatum[targetId], dimension.navigationRules.sibling_sibling);
|
|
856
865
|
}
|
|
857
866
|
} else if (i === valueKeys.length - 1 && extents2 === "bridgedCustom") {
|
|
858
867
|
createEdge(
|
|
@@ -869,24 +878,13 @@ var buildEdges = (options, nodes, dimensions) => {
|
|
|
869
878
|
);
|
|
870
879
|
}
|
|
871
880
|
if (!i && extents2 === "bridgedCousins") {
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
dimension.navigationRules.sibling_sibling
|
|
880
|
-
);
|
|
881
|
-
} else {
|
|
882
|
-
const targetId = typeof options.idKey === "function" ? options.idKey(
|
|
883
|
-
dimension.divisions[divisionKeys[divisionKeys.length - 1]].values[valueKeys[valueKeys.length - 1]]
|
|
884
|
-
) : options.idKey;
|
|
885
|
-
createEdge(
|
|
886
|
-
dimension.divisions[divisionKeys[divisionKeys.length - 1]].values[valueKeys[valueKeys.length - 1]][targetId],
|
|
887
|
-
v[id],
|
|
888
|
-
dimension.navigationRules.sibling_sibling
|
|
889
|
-
);
|
|
881
|
+
const prevIdx = findPrevNonEmptyDivIdx(j);
|
|
882
|
+
if (prevIdx !== null) {
|
|
883
|
+
const prevDivValues = dimension.divisions[divisionKeys[prevIdx]].values;
|
|
884
|
+
const prevDivValueKeys = Object.keys(prevDivValues);
|
|
885
|
+
const targetDatum = prevDivValues[prevDivValueKeys[prevDivValueKeys.length - 1]];
|
|
886
|
+
const targetId = typeof options.idKey === "function" ? options.idKey(targetDatum) : options.idKey;
|
|
887
|
+
createEdge(targetDatum[targetId], v[id], dimension.navigationRules.sibling_sibling);
|
|
890
888
|
}
|
|
891
889
|
} else if (!i && extents2 === "bridgedCustom") {
|
|
892
890
|
createEdge(
|
|
@@ -1484,9 +1482,7 @@ var fuzzyMatch = (input, candidates, labels = {}) => {
|
|
|
1484
1482
|
const exactName = candidates.find((c) => c.toLowerCase() === lower);
|
|
1485
1483
|
if (exactName)
|
|
1486
1484
|
return { match: exactName, ambiguous: [] };
|
|
1487
|
-
const exactLabel = candidates.find(
|
|
1488
|
-
(c) => labels[c] && labels[c].toLowerCase() === lower
|
|
1489
|
-
);
|
|
1485
|
+
const exactLabel = candidates.find((c) => labels[c] && labels[c].toLowerCase() === lower);
|
|
1490
1486
|
if (exactLabel)
|
|
1491
1487
|
return { match: exactLabel, ambiguous: [] };
|
|
1492
1488
|
const namePrefix = candidates.filter((c) => c.toLowerCase().startsWith(lower));
|
|
@@ -1746,8 +1742,12 @@ var text_chat_default = (options) => {
|
|
|
1746
1742
|
}
|
|
1747
1743
|
});
|
|
1748
1744
|
if (llm) {
|
|
1749
|
-
addSystemMessage(
|
|
1750
|
-
|
|
1745
|
+
addSystemMessage(
|
|
1746
|
+
'Text navigation ready. Type "enter" to begin navigating, "help" for commands, or ask a question about the data.'
|
|
1747
|
+
);
|
|
1748
|
+
addSystemMessage(
|
|
1749
|
+
'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.'
|
|
1750
|
+
);
|
|
1751
1751
|
} else {
|
|
1752
1752
|
addSystemMessage('Text navigation ready. Type "enter" to begin or "help" for available commands.');
|
|
1753
1753
|
}
|
|
@@ -1816,9 +1816,7 @@ var text_chat_default = (options) => {
|
|
|
1816
1816
|
const node = structure.nodes[currentNodeId];
|
|
1817
1817
|
const available = getAvailableRules(currentNodeId, node, structure);
|
|
1818
1818
|
const formatted = available.map((r) => formatRule(r, commandLabels));
|
|
1819
|
-
addResponse(
|
|
1820
|
-
`Available: ${formatted.join(", ")}, move to <search>.` + interactionSuffix + llmHint
|
|
1821
|
-
);
|
|
1819
|
+
addResponse(`Available: ${formatted.join(", ")}, move to <search>.` + interactionSuffix + llmHint);
|
|
1822
1820
|
}
|
|
1823
1821
|
return;
|
|
1824
1822
|
}
|
|
@@ -1832,9 +1830,7 @@ var text_chat_default = (options) => {
|
|
|
1832
1830
|
onClick(node);
|
|
1833
1831
|
addResponse(`Clicked: ${describeNode2(node)}`);
|
|
1834
1832
|
} else {
|
|
1835
|
-
addResponse(
|
|
1836
|
-
onClick ? "Nothing to click here." : "Click interaction is not enabled for this chart."
|
|
1837
|
-
);
|
|
1833
|
+
addResponse(onClick ? "Nothing to click here." : "Click interaction is not enabled for this chart.");
|
|
1838
1834
|
}
|
|
1839
1835
|
return;
|
|
1840
1836
|
}
|
|
@@ -1887,7 +1883,9 @@ var text_chat_default = (options) => {
|
|
|
1887
1883
|
return;
|
|
1888
1884
|
}
|
|
1889
1885
|
const llmHint = llm ? " Enter an API key above to ask questions about the data." : "";
|
|
1890
|
-
addResponse(
|
|
1886
|
+
addResponse(
|
|
1887
|
+
'Type "enter" to begin navigating the structure, or "move to <search>" to jump to a node.' + llmHint
|
|
1888
|
+
);
|
|
1891
1889
|
return;
|
|
1892
1890
|
}
|
|
1893
1891
|
const allRules = getAllRuleNames(structure);
|
package/dist/structure.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var V=Object.defineProperty,be=Object.defineProperties,pe=Object.getOwnPropertyDescriptor,me=Object.getOwnPropertyDescriptors,Oe=Object.getOwnPropertyNames,X=Object.getOwnPropertySymbols;var ie=Object.prototype.hasOwnProperty,Ke=Object.prototype.propertyIsEnumerable;var ee=(e,a,i)=>a in e?V(e,a,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[a]=i,F=(e,a)=>{for(var i in a||(a={}))ie.call(a,i)&&ee(e,i,a[i]);if(X)for(var i of X(a))Ke.call(a,i)&&ee(e,i,a[i]);return e},te=(e,a)=>be(e,me(a));var Ee=(e,a)=>{for(var i in a)V(e,i,{get:a[i],enumerable:!0})},Ie=(e,a,i,c)=>{if(a&&typeof a=="object"||typeof a=="function")for(let h of Oe(a))!ie.call(e,h)&&h!==i&&V(e,h,{get:()=>a[h],enumerable:!(c=pe(a,h))||c.enumerable});return e};var xe=e=>Ie(V({},"__esModule",{value:!0}),e);var je={};Ee(je,{addSimpleDataIDs:()=>ce,buildEdges:()=>fe,buildNodeStructureFromVegaLite:()=>le,buildNodes:()=>ue,buildRules:()=>ve,buildStructure:()=>ye,default:()=>Re,scaffoldDimensions:()=>ge});module.exports=xe(je);var ne={Escape:!0,Enter:!0,Backspace:!0,ArrowLeft:!0,ArrowRight:!0,ArrowUp:!0,ArrowDown:!0};var se=["KeyW","KeyJ","LeftBracket","RightBracket","Slash","Backslash"];var re=[["LeftBracket","RightBracket"],["Slash","Backslash"]],H={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"}},oe=[["left","right"],["up","down"],["backward","forward"],["previous","next"]];var ae={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 de=(e,a)=>{let i=Object.keys(e),c="";return i.forEach(h=>{c+=`${a&&a.omitKeyNames?"":h+": "}${e[h]}. `}),c+=a&&a.semanticLabel||"Data point.",c},q=e=>"_"+e.replace(/[^a-zA-Z0-9_-]+/g,"_");var Re=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?le(e):ye(e),le=e=>{let a=ae,i={},c={},h={},d=0,B=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,P=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,m=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,s=e.vegaLiteView._renderer._origin,b=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],I=(n,o)=>{if(n["data-navigator-id"])return n["data-navigator-id"];let l=`dn-node-${o}-${d}`;return d++,n["data-navigator-id"]=l,l},r=n=>{let o=i[n],l=o.index,u=o.level,y=o.parent,g=[],f=y.items[l-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[l+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[l].items){let K=(y.items[l].items[0].mark.items[0].items||y.items[l].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:["parent","child"]})}}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:["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,l,u,y)=>{let g=I(n,o),f="render-"+g,E=l||[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+E[0],h[f].spatialProperties.y=n.bounds.y1+E[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):de(i[g].d)},j=0;return b.items.forEach(n=>{if(B(n,j,e.vegaLiteSpec)){x(n,"group",s,j,b);let o=0,l=n.items[0].mark.items[0].items?n.items[0].mark.items[0]:n;l.items.forEach(u=>{P(u,o,n,e.vegaLiteSpec)&&x(u,"item",s,o,l),o++})}j++}),Object.keys(i).forEach(n=>{i[n].edges=r(n)}),{nodes:i,edges:c,elementData:h,navigationRules:a}},ce=e=>{let a=0,i={};e.data.forEach(c=>{let h=typeof e.idKey=="function"?e.idKey(c):e.idKey;c[h]="_"+a,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(d=>{d in c&&(typeof c[d]=="string"?(i[d]||(i[d]=0),i[c[d]]||(i[c[d]]=0),c[h]+="_"+d+i[d]+"_"+c[d]+i[c[d]],i[d]++,i[c[d]]++):(i[d]||(i[d]=0),c[h]+="_"+d+i[d],i[d]++))}),a++})},ue=e=>{let a={};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(a[h]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${h}.`);return}else{let d=typeof e.renderIdKey=="function"?e.renderIdKey(i):e.renderIdKey;a[h]={id:h,edges:[],renderId:d?i[d]||"":i.renderIdKey||"",data:i}}}),a},ge=(e,a)=>{var d,B,P;let i={};if((B=(d=e.dimensions)==null?void 0:d.parentOptions)!=null&&B.addLevel0){let m=e.dimensions.parentOptions.addLevel0;a[m.id]=te(F({},m),{dimensionLevel:0})}let c=[...oe],h=(m,s)=>{let b=s.numericalExtents[0],I=s.numericalExtents[1];s.numericalExtents[0]=b<m?b: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)||[],b=0;s.forEach(r=>{var x,j,p,n,o,l,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||q(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:((j=r.operations)==null?void 0:j.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:["parent_"+r.dimensionKey,"child"]}},a[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,b):q(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((l=r.divisionOptions)==null?void 0:l.divisionRenderIds)=="function"?r.divisionOptions.divisionRenderIds(r.dimensionKey,g,b):O;a[O]={id:O,renderId:t,derivedNode:r.dimensionKey,edges:[],dimensionLevel:2,data:F({},v),renderingStrategy:((u=r.divisionOptions)==null?void 0:u.renderingStrategy)||"singleSquare"},a[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),h(g,E))}let K=typeof e.idKey=="function"?e.idKey(m):e.idKey;v.values[m[K]]=m}}b++})}),Object.keys(i).forEach(m=>{var r,x,j,p,n;let s=i[m],b=s.divisions;if(s.type==="numerical"){b[s.nodeId].values=Object.fromEntries(Object.entries(b[s.nodeId].values).sort((l,u)=>{var y;return typeof((y=s.operations)==null?void 0:y.sortFunction)=="function"?s.operations.sortFunction(l[1],u[1],s):l[1][m]-u[1][m]}));let o=b[s.nodeId].values;if(s.numericalExtents[0]!==1/0&&s.subdivisions!==1){let l=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):q(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 $=typeof((j=s.divisionOptions)==null?void 0:j.divisionRenderIds)=="function"?s.divisionOptions.divisionRenderIds(m,f,f):t;a[t]={id:t,renderId:$,derivedNode:m,edges:[],data:s.divisions[t],dimensionLevel:2,renderingStrategy:((p=s.divisionOptions)==null?void 0:p.renderingStrategy)||"singleSquare"};let G=!1;for(;!G&&v<l.length;){let T=o[l[v]];T[m]<=f?(s.divisions[t].values[T.id]=T,v++):G=!0}O=f,E++}if(K&&v<l.length)for(;v<l.length;){let t=o[l[v]];s.divisions[K].values[t.id]=t,v++}delete b[m]}}else typeof((n=s.operations)==null?void 0:n.sortFunction)=="function"&&(s.divisions=Object.fromEntries(Object.entries(b).sort((o,l)=>s.operations.sortFunction(o[1],l[1],s))));Object.keys(s.divisions).forEach(o=>{let l=s.divisions[o];typeof l.sortFunction=="function"&&(l.values=Object.fromEntries(Object.entries(l.values).sort((u,y)=>l.sortFunction(u[1],y[1],l))))})}),Object.keys(i).forEach(m=>{let s=i[m];if(s.operations.compressSparseDivisions){let b=Object.keys(s.divisions),I={},r=!0;if(b.forEach(x=>{let j=s.divisions[x],p=Object.keys(j.values);p.length<=1?p.forEach(n=>{I[n]=F({},j.values[n])}):r=!1}),r){let x={id:s.nodeId,values:I};b.forEach(j=>{delete a[j]}),s.divisions={},s.divisions[s.nodeId]=x}}}),(P=e.dimensions)!=null&&P.adjustDimensions&&(i=e.dimensions.adjustDimensions(i)),i},fe=(e,a,i)=>{var B,P,m,s,b,I,r,x,j,p;let c={},h=(n,o)=>{a[n].edges.indexOf(o)===-1&&a[n].edges.push(o)},d=(n,o,l,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(...l||[]):c[K]={source:n,target:o,navigationRules:l?[...l]:[]}};v(y),e.useDirectedEdges&&E&&v(g),f&&h(n,y),E&&h(o,g)};if(i&&Object.keys(i).length){let n=Object.keys(i),o=(m=(P=(B=e.dimensions)==null?void 0:B.parentOptions)==null?void 0:P.level1Options)==null?void 0:m.order,l=o||n,u=0,y=((s=e.dimensions)==null?void 0:s.parentOptions)||{},g=((I=(b=y.level1Options)==null?void 0:b.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)||["parent","child"]:[],v=((p=(j=y.level1Options)==null?void 0:j.navigationRules)==null?void 0:p.sibling_sibling)||["left","right"],K=typeof l[0]=="string"?o?a[l[0]]:a[i[l[0]].nodeId]:l[0];f&&d(f.id,K.id,E,"source"),l.forEach(O=>{let t=typeof O=="string"?o?a[O]:a[i[O].nodeId]:O;if(t===O&&!a[t.id]&&(a[t.id]=t),f&&(e.useDirectedEdges?d(t.id,f.id,E,"source"):d(f.id,t.id,E,"target")),u===l.length-1&&g==="circular")d(t.id,K.id,v);else if(u===l.length-1&&g==="bridgedCustom")d(t.id,y.level1Options.behavior.customBridgePost,v);else if(u<l.length-1){let $=typeof l[u+1]=="string"?o?a[l[u+1]]:a[i[l[u+1]].nodeId]:l[u+1];d(t.id,$.id,v)}!u&&g==="bridgedCustom"&&d(y.level1Options.behavior.customBridgePost,t.id,v),u++}),n.forEach(O=>{var W,Y,Z,z;let t=i[O],$=((W=t.behavior)==null?void 0:W.childmostNavigation)||"within",G=(A,w,R,C)=>C.values[Object.keys(C.values)[A]]||void 0,T=$==="across"&&((Y=t.behavior)!=null&&Y.childmostMatching)?(Z=t.behavior)==null?void 0:Z.childmostMatching:G,L=((z=t.behavior)==null?void 0:z.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),U=t.divisions[D[0]];if(D.length!==1)d(t.nodeId,U.id,t.navigationRules.parent_child,"source");else{let A=Object.keys(U.values),w=typeof e.idKey=="function"?e.idKey(U.values[A[0]]):e.idKey;d(t.nodeId,U.values[A[0]][w],t.navigationRules.parent_child,"source")}let N=0;D.forEach(A=>{let w=t.divisions[A];N===D.length-1&&(L==="circular"||L==="bridgedCousins"||L==="bridgedCustom")?d(w.id,t.divisions[D[0]].id,t.navigationRules.sibling_sibling):N<D.length-1&&d(w.id,t.divisions[D[N+1]].id,t.navigationRules.sibling_sibling);let R=Object.keys(w.values);if(e.useDirectedEdges?d(w.id,t.nodeId,t.navigationRules.parent_child,"source"):d(t.nodeId,w.id,t.navigationRules.parent_child,"target"),R.length>0){let J=typeof e.idKey=="function"?e.idKey(w.values[R[0]]):e.idKey;d(w.id,w.values[R[0]][J],t.navigationRules.parent_child,"source")}let C=0;R.length>=1&&R.forEach(J=>{let k=w.values[J],S=typeof e.idKey=="function"?e.idKey(k):e.idKey,Q=D.length!==1?w.id:t.nodeId;if(e.useDirectedEdges?d(k[S],Q,t.navigationRules.parent_child,"source"):d(Q,k[S],t.navigationRules.parent_child,"target"),$==="within"){if(C===R.length-1&&L==="circular"){let _=typeof e.idKey=="function"?e.idKey(w.values[R[0]]):e.idKey;d(k[S],w.values[R[0]][_],t.navigationRules.sibling_sibling)}else if(C===R.length-1&&L==="bridgedCousins")if(N!==D.length-1){let _=typeof e.idKey=="function"?e.idKey(t.divisions[D[N+1]].values[R[0]]):e.idKey;d(k[S],t.divisions[D[N+1]].values[R[0]][_],t.navigationRules.sibling_sibling)}else{let _=typeof e.idKey=="function"?e.idKey(t.divisions[D[0]].values[R[0]]):e.idKey;d(k[S],t.divisions[D[0]].values[R[0]][_],t.navigationRules.sibling_sibling)}else if(C===R.length-1&&L==="bridgedCustom")d(k[S],t.behavior.customBridgePost,t.navigationRules.sibling_sibling);else if(C<R.length-1){let _=typeof e.idKey=="function"?e.idKey(w.values[R[C+1]]):e.idKey;d(k[S],w.values[R[C+1]][_],t.navigationRules.sibling_sibling)}if(!C&&L==="bridgedCousins")if(N!==0){let _=typeof e.idKey=="function"?e.idKey(t.divisions[D[N-1]].values[R[R.length-1]]):e.idKey;d(t.divisions[D[N-1]].values[R[R.length-1]][_],k[S],t.navigationRules.sibling_sibling)}else{let _=typeof e.idKey=="function"?e.idKey(t.divisions[D[D.length-1]].values[R[R.length-1]]):e.idKey;d(t.divisions[D[D.length-1]].values[R[R.length-1]][_],k[S],t.navigationRules.sibling_sibling)}else!C&&L==="bridgedCustom"&&d(t.behavior.customBridgePrevious,k[S],t.navigationRules.sibling_sibling)}else if(N===D.length-1&&L==="bridgedCustom")d(k[S],t.behavior.customBridgePost,t.navigationRules.sibling_sibling);else if(!N&&L==="bridgedCustom")d(t.behavior.customBridgePrevious,k[S],t.navigationRules.sibling_sibling);else{let _=N===D.length-1&&L==="circular"?t.divisions[D[0]]:t.divisions[D[N+1]];if(_){let M=T(C,k[S],w,_);if(M){let he=typeof e.idKey=="function"?e.idKey(M):e.idKey;d(k[S],M[he],t.navigationRules.sibling_sibling)}}}C++}),N++})})}return Object.keys(a).forEach(n=>{var l;let o=a[n];(l=e.genericEdges)!=null&&l.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},ve=(e,a,i)=>{var h,d,B,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={},b={},I={},r=[...re],x=[...se],j=(p,n)=>{let o=p&&n,l=!1,u=!1;if((s[p]||b[p])&&(b[p]=F({},s[p]),l=!0),n&&(s[n]||b[n])&&(b[n]=F({},s[n]),u=!0),o&&!l&&!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),b[p]={direction:e.useDirectedEdges?"target":"source",key:y[0]},b[n]={direction:"target",key:y[1]}}else{if(!b[p]&&x.length){let y=x.shift(),g=[];r.forEach(f=>{y!==f[0]&&y!==f[1]&&g.push(f)}),r=g,b[p]={direction:e.useDirectedEdges?"target":"source",key:y}}if(n&&!b[n]&&x.length){let y=x.shift(),g=[];r.forEach(f=>{y!==f[0]&&y!==f[1]&&g.push(f)}),r=g,b[n]={direction:"target",key:y}}x.length||(b[p]||(I[p]=p),n&&!b[n]&&(I[n]=n))}};if(Object.keys(H).forEach(p=>{let n=F({},H[p]);e.useDirectedEdges&&(n.direction="target"),s[p]=n}),m.length){if((d=(h=e.dimensions)==null?void 0:h.parentOptions)!=null&&d.addLevel0){let p=((P=(B=e.dimensions.parentOptions.level1Options)==null?void 0:B.navigationRules)==null?void 0:P.parent_child)||["parent","child"];j(p[0],p[1])}m.forEach(p=>{let n=i[p].navigationRules.parent_child,o=i[p].navigationRules.sibling_sibling;j(n[0],n[1]),j(o[0],o[1])})}if(Object.keys(a).forEach(p=>{a[p].navigationRules.forEach(n=>{b[n]||j(n)})}),Object.keys(I).length){let p={};Object.keys(b).forEach(o=>{p[b[o].key]=b[o].key}),Object.keys(s).forEach(o=>{!p[s[o].key]&&!ne[s[o].key]&&x.push(s[o].key)});let n=F({},I);I={},Object.keys(n).forEach(o=>{j(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=b}return c},ye=e=>{e.addIds&&ce(e);let a=ue(e),i=ge(e,a),c=fe(e,a,i),h=ve(e,c,i);return{nodes:a,edges:c,dimensions:i,navigationRules:h}};0&&(module.exports={addSimpleDataIDs,buildEdges,buildNodeStructureFromVegaLite,buildNodes,buildRules,buildStructure,scaffoldDimensions});
|
|
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});
|
package/dist/structure.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as se,b as M}from"./chunk-YE5N6UCT.js";import{a as Z,c as ee,e as ie,f as J,g as ne,i as te}from"./chunk-MPFBSVCV.js";import{a as k,b as X}from"./chunk-RGY6OTGO.js";var ye=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?de(e):ge(e),de=e=>{let m=te,t={},g={},O={},r=0,P=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,w=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,b=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,s=e.vegaLiteView._renderer._origin,y=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],E=(n,d)=>{if(n["data-navigator-id"])return n["data-navigator-id"];let a=`dn-node-${d}-${r}`;return r++,n["data-navigator-id"]=a,a},o=n=>{let d=t[n],a=d.index,l=d.level,v=d.parent,u=[],c=v.items[a-1];if(c){let f=E(c,l);if(t[f]){let I=`${f}-${d.id}`;u.push(I),g[I]||(g[I]={source:f,target:d.id,navigationRules:["left","right"]})}}let K=v.items[a+1];if(K){let f=E(K,l);if(t[f]){let I=`${d.id}-${f}`;u.push(I),g[I]||(g[I]={source:d.id,target:f,navigationRules:["left","right"]})}}if(l==="group"&&v.items[a].items){let I=(v.items[a].items[0].mark.items[0].items||v.items[a].items)[0],p=E(I,"item");if(t[p]){let i=`${d.id}-${p}`;u.push(i),g[i]||(g[i]={source:d.id,target:p,navigationRules:["parent","child"]})}}else if(l==="item"){let f=E(v,"group");if(t[f]){let I=`${f}-${d.id}`;u.push(I),g[I]||(g[I]={source:f,target:d.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,d,a,l,v)=>{let u=E(n,d),c="render-"+u,K=a||[0,0];t[u]={},t[u].d={},t[u].id=u,t[u].renderId=c,t[u].index=l,t[u].level=d,t[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,d,e.vegaLiteSpec)&&(t[u].d[e.keyRenamingHash&&e.keyRenamingHash[f]?e.keyRenamingHash[f]:f]=I)}),O[c].semantics={},O[c].semantics.label=e.nodeDescriber?e.nodeDescriber(t[u].d,n,d):se(t[u].d)},x=0;return y.items.forEach(n=>{if(P(n,x,e.vegaLiteSpec)){j(n,"group",s,x,y);let d=0,a=n.items[0].mark.items[0].items?n.items[0].mark.items[0]:n;a.items.forEach(l=>{w(l,d,n,e.vegaLiteSpec)&&j(l,"item",s,d,a),d++})}x++}),Object.keys(t).forEach(n=>{t[n].edges=o(n)}),{nodes:t,edges:g,elementData:O,navigationRules:m}},re=e=>{let m=0,t={};e.data.forEach(g=>{let O=typeof e.idKey=="function"?e.idKey(g):e.idKey;g[O]="_"+m,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(r=>{r in g&&(typeof g[r]=="string"?(t[r]||(t[r]=0),t[g[r]]||(t[g[r]]=0),g[O]+="_"+r+t[r]+"_"+g[r]+t[g[r]],t[r]++,t[g[r]]++):(t[r]||(t[r]=0),g[O]+="_"+r+t[r],t[r]++))}),m++})},ae=e=>{let m={};return e.data.forEach(t=>{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(t):e.idKey,O=t[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(t)}.`);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 r=typeof e.renderIdKey=="function"?e.renderIdKey(t):e.renderIdKey;m[O]={id:O,edges:[],renderId:r?t[r]||"":t.renderIdKey||"",data:t}}}),m},le=(e,m)=>{var r,P,w;let t={};if((P=(r=e.dimensions)==null?void 0:r.parentOptions)!=null&&P.addLevel0){let b=e.dimensions.parentOptions.addLevel0;m[b.id]=X(k({},b),{dimensionLevel:0})}let g=[...ne],O=(b,s)=>{let y=s.numericalExtents[0],E=s.numericalExtents[1];s.numericalExtents[0]=y<b?y:b,s.numericalExtents[1]=E>b?E:b};return e.data.forEach(b=>{var E;let s=((E=e.dimensions)==null?void 0:E.values)||[],y=0;s.forEach(o=>{var j,x,h,n,d,a,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"),!t[o.dimensionKey]){let p=typeof o.nodeId=="function"?o.nodeId(o,e.data):o.nodeId||M(o.dimensionKey),i=typeof o.renderId=="function"?o.renderId(o,e.data):o.renderId||p;t[o.dimensionKey]={dimensionKey:o.dimensionKey,nodeId:p,divisions:{},numericalExtents:[1/0,-1/0],type:o.type,operations:{compressSparseDivisions:((x=o.operations)==null?void 0:x.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:t[o.dimensionKey],renderingStrategy:o.renderingStrategy||"singleSquare"}}let K=t[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):M(K.nodeId+"_"+u);if(f=K.divisions[p],!f){f=K.divisions[p]={id:p,sortFunction:((d=o.divisionOptions)==null?void 0:d.sortFunction)||void 0,values:{}};let i=typeof((a=o.divisionOptions)==null?void 0:a.divisionRenderIds)=="function"?o.divisionOptions.divisionRenderIds(o.dimensionKey,u,y):p;m[p]={id:p,renderId:i,derivedNode:o.dimensionKey,edges:[],dimensionLevel:2,data:k({},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(t).forEach(b=>{var o,j,x,h,n;let s=t[b],y=s.divisions;if(s.type==="numerical"){y[s.nodeId].values=Object.fromEntries(Object.entries(y[s.nodeId].values).sort((a,l)=>{var v;return typeof((v=s.operations)==null?void 0:v.sortFunction)=="function"?s.operations.sortFunction(a[1],l[1],s):a[1][b]-l[1][b]}));let d=y[s.nodeId].values;if(s.numericalExtents[0]!==1/0&&s.subdivisions!==1){let a=Object.keys(d),l=typeof s.subdivisions=="function"?s.subdivisions(b,d):s.subdivisions,u=(s.numericalExtents[1]-s.numericalExtents[0])/l,c=s.numericalExtents[0]+u,K=0,f=0,I=null,p=s.numericalExtents[0];for(c=s.numericalExtents[0]+u;c<=s.numericalExtents[1];c+=u){let i=typeof((o=s.divisionOptions)==null?void 0:o.divisionNodeIds)=="function"?s.divisionOptions.divisionNodeIds(b,c,c):M(s.nodeId+"_"+c);I=i,s.divisions[i]={id:i,sortFunction:((j=s.divisionOptions)==null?void 0:j.sortFunction)||void 0,values:{},numericalExtents:[p,c]};let B=typeof((x=s.divisionOptions)==null?void 0:x.divisionRenderIds)=="function"?s.divisionOptions.divisionRenderIds(b,c,c):i;m[i]={id:i,renderId:B,derivedNode:b,edges:[],data:s.divisions[i],dimensionLevel:2,renderingStrategy:((h=s.divisionOptions)==null?void 0:h.renderingStrategy)||"singleSquare"};let V=!1;for(;!V&&f<a.length;){let G=d[a[f]];G[b]<=c?(s.divisions[i].values[G.id]=G,f++):V=!0}p=c,K++}if(I&&f<a.length)for(;f<a.length;){let i=d[a[f]];s.divisions[I].values[i.id]=i,f++}delete y[b]}}else typeof((n=s.operations)==null?void 0:n.sortFunction)=="function"&&(s.divisions=Object.fromEntries(Object.entries(y).sort((d,a)=>s.operations.sortFunction(d[1],a[1],s))));Object.keys(s.divisions).forEach(d=>{let a=s.divisions[d];typeof a.sortFunction=="function"&&(a.values=Object.fromEntries(Object.entries(a.values).sort((l,v)=>a.sortFunction(l[1],v[1],a))))})}),Object.keys(t).forEach(b=>{let s=t[b];if(s.operations.compressSparseDivisions){let y=Object.keys(s.divisions),E={},o=!0;if(y.forEach(j=>{let x=s.divisions[j],h=Object.keys(x.values);h.length<=1?h.forEach(n=>{E[n]=k({},x.values[n])}):o=!1}),o){let j={id:s.nodeId,values:E};y.forEach(x=>{delete m[x]}),s.divisions={},s.divisions[s.nodeId]=j}}}),(w=e.dimensions)!=null&&w.adjustDimensions&&(t=e.dimensions.adjustDimensions(t)),t},ue=(e,m,t)=>{var P,w,b,s,y,E,o,j,x,h;let g={},O=(n,d)=>{m[n].edges.indexOf(d)===-1&&m[n].edges.push(d)},r=(n,d,a,l)=>{let v=`${n}-${d}`,u=e.useDirectedEdges?`${d}-${v}`:v,c=!l||l==="source",K=!l||l==="target",f=I=>{g[I]?g[I].navigationRules.push(...a||[]):g[I]={source:n,target:d,navigationRules:a?[...a]:[]}};f(v),e.useDirectedEdges&&K&&f(u),c&&O(n,v),K&&O(d,u)};if(t&&Object.keys(t).length){let n=Object.keys(t),d=(b=(w=(P=e.dimensions)==null?void 0:P.parentOptions)==null?void 0:w.level1Options)==null?void 0:b.order,a=d||n,l=0,v=((s=e.dimensions)==null?void 0:s.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=(x=v.level1Options)==null?void 0:x.navigationRules)==null?void 0:h.sibling_sibling)||["left","right"],I=typeof a[0]=="string"?d?m[a[0]]:m[t[a[0]].nodeId]:a[0];c&&r(c.id,I.id,K,"source"),a.forEach(p=>{let i=typeof p=="string"?d?m[p]:m[t[p].nodeId]:p;if(i===p&&!m[i.id]&&(m[i.id]=i),c&&(e.useDirectedEdges?r(i.id,c.id,K,"source"):r(c.id,i.id,K,"target")),l===a.length-1&&u==="circular")r(i.id,I.id,f);else if(l===a.length-1&&u==="bridgedCustom")r(i.id,v.level1Options.behavior.customBridgePost,f);else if(l<a.length-1){let B=typeof a[l+1]=="string"?d?m[a[l+1]]:m[t[a[l+1]].nodeId]:a[l+1];r(i.id,B.id,f)}!l&&u==="bridgedCustom"&&r(v.level1Options.behavior.customBridgePost,i.id,f),l++}),n.forEach(p=>{var U,W,Y,z;let i=t[p],B=((U=i.behavior)==null?void 0:U.childmostNavigation)||"within",V=(T,N,R,L)=>L.values[Object.keys(L.values)[T]]||void 0,G=B==="across"&&((W=i.behavior)!=null&&W.childmostMatching)?(Y=i.behavior)==null?void 0:Y.childmostMatching:V,$=((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 D=Object.keys(i.divisions),q=i.divisions[D[0]];if(D.length!==1)r(i.nodeId,q.id,i.navigationRules.parent_child,"source");else{let T=Object.keys(q.values),N=typeof e.idKey=="function"?e.idKey(q.values[T[0]]):e.idKey;r(i.nodeId,q.values[T[0]][N],i.navigationRules.parent_child,"source")}let S=0;D.forEach(T=>{let N=i.divisions[T];S===D.length-1&&($==="circular"||$==="bridgedCousins"||$==="bridgedCustom")?r(N.id,i.divisions[D[0]].id,i.navigationRules.sibling_sibling):S<D.length-1&&r(N.id,i.divisions[D[S+1]].id,i.navigationRules.sibling_sibling);let R=Object.keys(N.values);if(e.useDirectedEdges?r(N.id,i.nodeId,i.navigationRules.parent_child,"source"):r(i.nodeId,N.id,i.navigationRules.parent_child,"target"),R.length>0){let A=typeof e.idKey=="function"?e.idKey(N.values[R[0]]):e.idKey;r(N.id,N.values[R[0]][A],i.navigationRules.parent_child,"source")}let L=0;R.length>=1&&R.forEach(A=>{let _=N.values[A],C=typeof e.idKey=="function"?e.idKey(_):e.idKey,Q=D.length!==1?N.id:i.nodeId;if(e.useDirectedEdges?r(_[C],Q,i.navigationRules.parent_child,"source"):r(Q,_[C],i.navigationRules.parent_child,"target"),B==="within"){if(L===R.length-1&&$==="circular"){let F=typeof e.idKey=="function"?e.idKey(N.values[R[0]]):e.idKey;r(_[C],N.values[R[0]][F],i.navigationRules.sibling_sibling)}else if(L===R.length-1&&$==="bridgedCousins")if(S!==D.length-1){let F=typeof e.idKey=="function"?e.idKey(i.divisions[D[S+1]].values[R[0]]):e.idKey;r(_[C],i.divisions[D[S+1]].values[R[0]][F],i.navigationRules.sibling_sibling)}else{let F=typeof e.idKey=="function"?e.idKey(i.divisions[D[0]].values[R[0]]):e.idKey;r(_[C],i.divisions[D[0]].values[R[0]][F],i.navigationRules.sibling_sibling)}else if(L===R.length-1&&$==="bridgedCustom")r(_[C],i.behavior.customBridgePost,i.navigationRules.sibling_sibling);else if(L<R.length-1){let F=typeof e.idKey=="function"?e.idKey(N.values[R[L+1]]):e.idKey;r(_[C],N.values[R[L+1]][F],i.navigationRules.sibling_sibling)}if(!L&&$==="bridgedCousins")if(S!==0){let F=typeof e.idKey=="function"?e.idKey(i.divisions[D[S-1]].values[R[R.length-1]]):e.idKey;r(i.divisions[D[S-1]].values[R[R.length-1]][F],_[C],i.navigationRules.sibling_sibling)}else{let F=typeof e.idKey=="function"?e.idKey(i.divisions[D[D.length-1]].values[R[R.length-1]]):e.idKey;r(i.divisions[D[D.length-1]].values[R[R.length-1]][F],_[C],i.navigationRules.sibling_sibling)}else!L&&$==="bridgedCustom"&&r(i.behavior.customBridgePrevious,_[C],i.navigationRules.sibling_sibling)}else if(S===D.length-1&&$==="bridgedCustom")r(_[C],i.behavior.customBridgePost,i.navigationRules.sibling_sibling);else if(!S&&$==="bridgedCustom")r(i.behavior.customBridgePrevious,_[C],i.navigationRules.sibling_sibling);else{let F=S===D.length-1&&$==="circular"?i.divisions[D[0]]:i.divisions[D[S+1]];if(F){let H=G(L,_[C],N,F);if(H){let oe=typeof e.idKey=="function"?e.idKey(H):e.idKey;r(_[C],H[oe],i.navigationRules.sibling_sibling)}}}L++}),S++})})}return Object.keys(m).forEach(n=>{var a;let d=m[n];(a=e.genericEdges)!=null&&a.length&&e.genericEdges.forEach(l=>{g[l.edgeId]||(g[l.edgeId]=l.edge),(!l.conditional||l.conditional&&l.conditional(d,l))&&d.edges.push(l.edgeId)})}),g},ce=(e,m,t)=>{var O,r,P,w;let g=e.navigationRules;if(!g){let b=Object.keys(t||{});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 s={},y={},E={},o=[...ie],j=[...ee],x=(h,n)=>{let d=h&&n,a=!1,l=!1;if((s[h]||y[h])&&(y[h]=k({},s[h]),a=!0),n&&(s[n]||y[n])&&(y[n]=k({},s[n]),l=!0),d&&!a&&!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(J).forEach(h=>{let n=k({},J[h]);e.useDirectedEdges&&(n.direction="target"),s[h]=n}),b.length){if((r=(O=e.dimensions)==null?void 0:O.parentOptions)!=null&&r.addLevel0){let h=((w=(P=e.dimensions.parentOptions.level1Options)==null?void 0:P.navigationRules)==null?void 0:w.parent_child)||["parent","child"];x(h[0],h[1])}b.forEach(h=>{let n=t[h].navigationRules.parent_child,d=t[h].navigationRules.sibling_sibling;x(n[0],n[1]),x(d[0],d[1])})}if(Object.keys(m).forEach(h=>{m[h].navigationRules.forEach(n=>{y[n]||x(n)})}),Object.keys(E).length){let h={};Object.keys(y).forEach(d=>{h[y[d].key]=y[d].key}),Object.keys(s).forEach(d=>{!h[s[d].key]&&!Z[s[d].key]&&j.push(s[d].key)});let n=k({},E);E={},Object.keys(n).forEach(d=>{x(d)}),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},ge=e=>{e.addIds&&re(e);let m=ae(e),t=le(e,m),g=ue(e,m,t),O=ce(e,g,t);return{nodes:m,edges:g,dimensions:t,navigationRules:O}};export{re as addSimpleDataIDs,ue as buildEdges,de as buildNodeStructureFromVegaLite,ae as buildNodes,ce as buildRules,ge as buildStructure,ye as default,le as scaffoldDimensions};
|
|
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};
|
package/package.json
CHANGED
package/text-chat.css
CHANGED
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
border: 1px solid #ccc;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
.dn-text-chat-form input[type=
|
|
57
|
+
.dn-text-chat-form input[type='text'] {
|
|
58
58
|
flex: 1;
|
|
59
59
|
padding: 6px 8px;
|
|
60
60
|
border: none;
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
outline: none;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
.dn-text-chat-form input[type=
|
|
65
|
+
.dn-text-chat-form input[type='text']:focus {
|
|
66
66
|
box-shadow: inset 0 0 0 2px #1e3369;
|
|
67
67
|
}
|
|
68
68
|
|