data-navigator 2.0.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-QTJ23SVE.mjs +18 -0
- package/dist/chunk-SQY245BV.mjs +177 -0
- package/dist/index.js +89 -32
- package/dist/index.mjs +115 -50
- package/dist/src/data-navigator.d.ts +9 -1
- package/dist/structure.js +1 -1
- package/dist/structure.mjs +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/utilities.ts
|
|
2
|
+
var describeNode = (d, descriptionOptions) => {
|
|
3
|
+
const keys = Object.keys(d);
|
|
4
|
+
let description = "";
|
|
5
|
+
keys.forEach((key) => {
|
|
6
|
+
description += `${descriptionOptions && descriptionOptions.omitKeyNames ? "" : key + ": "}${d[key]}. `;
|
|
7
|
+
});
|
|
8
|
+
description += descriptionOptions && descriptionOptions.semanticLabel || "Data point.";
|
|
9
|
+
return description;
|
|
10
|
+
};
|
|
11
|
+
var createValidId = (s) => {
|
|
12
|
+
return "_" + s.replace(/[^a-zA-Z0-9_-]+/g, "_");
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
describeNode,
|
|
17
|
+
createValidId
|
|
18
|
+
};
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// src/consts.ts
|
|
2
|
+
var SemanticKeys = {
|
|
3
|
+
Escape: true,
|
|
4
|
+
Enter: true,
|
|
5
|
+
Backspace: true,
|
|
6
|
+
ArrowLeft: true,
|
|
7
|
+
ArrowRight: true,
|
|
8
|
+
ArrowUp: true,
|
|
9
|
+
ArrowDown: true
|
|
10
|
+
};
|
|
11
|
+
var defaultKeyBindings = {
|
|
12
|
+
ArrowLeft: "left",
|
|
13
|
+
ArrowRight: "right",
|
|
14
|
+
ArrowUp: "up",
|
|
15
|
+
ArrowDown: "down",
|
|
16
|
+
Period: "forward",
|
|
17
|
+
Comma: "backward",
|
|
18
|
+
Escape: "parent",
|
|
19
|
+
Enter: "child"
|
|
20
|
+
};
|
|
21
|
+
var TypicallyUnreservedKeys = ["KeyW", "KeyJ", "LeftBracket", "RightBracket", "Slash", "Backslash"];
|
|
22
|
+
var TypicallyUnreservedSoloKeys = ["KeyW", "KeyJ"];
|
|
23
|
+
var TypicallyUnreservedKeyPairs = [
|
|
24
|
+
["LeftBracket", "RightBracket"],
|
|
25
|
+
["Slash", "Backslash"]
|
|
26
|
+
];
|
|
27
|
+
var GenericFullNavigationRules = {
|
|
28
|
+
left: {
|
|
29
|
+
key: "ArrowLeft",
|
|
30
|
+
direction: "source"
|
|
31
|
+
},
|
|
32
|
+
right: {
|
|
33
|
+
key: "ArrowRight",
|
|
34
|
+
direction: "target"
|
|
35
|
+
},
|
|
36
|
+
up: {
|
|
37
|
+
key: "ArrowUp",
|
|
38
|
+
direction: "source"
|
|
39
|
+
},
|
|
40
|
+
down: {
|
|
41
|
+
key: "ArrowDown",
|
|
42
|
+
direction: "target"
|
|
43
|
+
},
|
|
44
|
+
child: {
|
|
45
|
+
key: "Enter",
|
|
46
|
+
direction: "target"
|
|
47
|
+
},
|
|
48
|
+
parent: {
|
|
49
|
+
key: "Backspace",
|
|
50
|
+
direction: "source"
|
|
51
|
+
},
|
|
52
|
+
backward: {
|
|
53
|
+
key: "Comma",
|
|
54
|
+
direction: "source"
|
|
55
|
+
},
|
|
56
|
+
forward: {
|
|
57
|
+
key: "Period",
|
|
58
|
+
direction: "target"
|
|
59
|
+
},
|
|
60
|
+
previous: {
|
|
61
|
+
key: "Semicolon",
|
|
62
|
+
direction: "source"
|
|
63
|
+
},
|
|
64
|
+
next: {
|
|
65
|
+
key: "Quote",
|
|
66
|
+
direction: "target"
|
|
67
|
+
},
|
|
68
|
+
exit: {
|
|
69
|
+
key: "Escape",
|
|
70
|
+
direction: "target"
|
|
71
|
+
},
|
|
72
|
+
help: {
|
|
73
|
+
key: "KeyY",
|
|
74
|
+
direction: "target"
|
|
75
|
+
},
|
|
76
|
+
undo: {
|
|
77
|
+
key: "KeyZ",
|
|
78
|
+
direction: "target"
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
var GenericFullNavigationDimensions = [
|
|
82
|
+
["left", "right"],
|
|
83
|
+
["up", "down"],
|
|
84
|
+
["backward", "forward"],
|
|
85
|
+
["previous", "next"]
|
|
86
|
+
];
|
|
87
|
+
var GenericFullNavigationPairs = {
|
|
88
|
+
left: ["left", "right"],
|
|
89
|
+
right: ["left", "right"],
|
|
90
|
+
up: ["up", "down"],
|
|
91
|
+
down: ["up", "down"],
|
|
92
|
+
backward: ["backward", "forward"],
|
|
93
|
+
forward: ["backward", "forward"],
|
|
94
|
+
previous: ["previous", "next"],
|
|
95
|
+
next: ["previous", "next"],
|
|
96
|
+
parent: ["parent", "child"],
|
|
97
|
+
child: ["parent", "child"],
|
|
98
|
+
exit: ["exit", "undo"],
|
|
99
|
+
undo: ["undo", "undo"]
|
|
100
|
+
};
|
|
101
|
+
var GenericLimitedNavigationRules = {
|
|
102
|
+
right: {
|
|
103
|
+
key: "ArrowRight",
|
|
104
|
+
direction: "target"
|
|
105
|
+
},
|
|
106
|
+
left: {
|
|
107
|
+
key: "ArrowLeft",
|
|
108
|
+
direction: "source"
|
|
109
|
+
},
|
|
110
|
+
down: {
|
|
111
|
+
key: "ArrowDown",
|
|
112
|
+
direction: "target"
|
|
113
|
+
},
|
|
114
|
+
up: {
|
|
115
|
+
key: "ArrowUp",
|
|
116
|
+
direction: "source"
|
|
117
|
+
},
|
|
118
|
+
child: {
|
|
119
|
+
key: "Enter",
|
|
120
|
+
direction: "target"
|
|
121
|
+
},
|
|
122
|
+
parent: {
|
|
123
|
+
key: "Backspace",
|
|
124
|
+
direction: "source"
|
|
125
|
+
},
|
|
126
|
+
exit: {
|
|
127
|
+
key: "Escape",
|
|
128
|
+
direction: "target"
|
|
129
|
+
},
|
|
130
|
+
undo: {
|
|
131
|
+
key: "Period",
|
|
132
|
+
direction: "target"
|
|
133
|
+
},
|
|
134
|
+
legend: {
|
|
135
|
+
key: "KeyL",
|
|
136
|
+
direction: "target"
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
var NodeElementDefaults = {
|
|
140
|
+
cssClass: "",
|
|
141
|
+
spatialProperties: {
|
|
142
|
+
x: 0,
|
|
143
|
+
y: 0,
|
|
144
|
+
width: 0,
|
|
145
|
+
height: 0,
|
|
146
|
+
path: ""
|
|
147
|
+
},
|
|
148
|
+
semantics: {
|
|
149
|
+
label: "",
|
|
150
|
+
elementType: "div",
|
|
151
|
+
role: "image",
|
|
152
|
+
attributes: void 0
|
|
153
|
+
},
|
|
154
|
+
parentSemantics: {
|
|
155
|
+
label: "",
|
|
156
|
+
elementType: "figure",
|
|
157
|
+
role: "figure",
|
|
158
|
+
attributes: void 0
|
|
159
|
+
},
|
|
160
|
+
existingElement: {
|
|
161
|
+
useForSpatialProperties: false,
|
|
162
|
+
spatialProperties: void 0
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export {
|
|
167
|
+
SemanticKeys,
|
|
168
|
+
defaultKeyBindings,
|
|
169
|
+
TypicallyUnreservedKeys,
|
|
170
|
+
TypicallyUnreservedSoloKeys,
|
|
171
|
+
TypicallyUnreservedKeyPairs,
|
|
172
|
+
GenericFullNavigationRules,
|
|
173
|
+
GenericFullNavigationDimensions,
|
|
174
|
+
GenericFullNavigationPairs,
|
|
175
|
+
GenericLimitedNavigationRules,
|
|
176
|
+
NodeElementDefaults
|
|
177
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -606,7 +606,7 @@ var scaffoldDimensions = function(options, nodes) {
|
|
|
606
606
|
dim.type = (typeof value === "undefined" ? "undefined" : _type_of(value)) === "bigint" || typeof value === "number" ? "numerical" : "categorical";
|
|
607
607
|
}
|
|
608
608
|
if (!dimensions[dim.dimensionKey]) {
|
|
609
|
-
var _dim_operations1;
|
|
609
|
+
var _dim_operations1, _dim_operations2;
|
|
610
610
|
var id2 = typeof dim.nodeId === "function" ? dim.nodeId(dim, options.data) : dim.nodeId || createValidId(dim.dimensionKey);
|
|
611
611
|
var renderId = typeof dim.renderId === "function" ? dim.renderId(dim, options.data) : dim.renderId || id2;
|
|
612
612
|
dimensions[dim.dimensionKey] = {
|
|
@@ -618,7 +618,10 @@ var scaffoldDimensions = function(options, nodes) {
|
|
|
618
618
|
-Infinity
|
|
619
619
|
],
|
|
620
620
|
type: dim.type,
|
|
621
|
-
|
|
621
|
+
operations: {
|
|
622
|
+
compressSparseDivisions: ((_dim_operations1 = dim.operations) === null || _dim_operations1 === void 0 ? void 0 : _dim_operations1.compressSparseDivisions) || false,
|
|
623
|
+
sortFunction: ((_dim_operations2 = dim.operations) === null || _dim_operations2 === void 0 ? void 0 : _dim_operations2.sortFunction) || void 0
|
|
624
|
+
},
|
|
622
625
|
behavior: dim.behavior || {
|
|
623
626
|
extents: "circular"
|
|
624
627
|
},
|
|
@@ -698,11 +701,13 @@ var scaffoldDimensions = function(options, nodes) {
|
|
|
698
701
|
});
|
|
699
702
|
});
|
|
700
703
|
Object.keys(dimensions).forEach(function(s) {
|
|
704
|
+
var _dimension_operations;
|
|
701
705
|
var dimension = dimensions[s];
|
|
702
706
|
var divisions = dimension.divisions;
|
|
703
707
|
if (dimension.type === "numerical") {
|
|
704
708
|
divisions[dimension.nodeId].values = Object.fromEntries(Object.entries(divisions[dimension.nodeId].values).sort(function(a, b) {
|
|
705
|
-
|
|
709
|
+
var _dimension_operations;
|
|
710
|
+
return typeof ((_dimension_operations = dimension.operations) === null || _dimension_operations === void 0 ? void 0 : _dimension_operations.sortFunction) === "function" ? dimension.operations.sortFunction(a[1], b[1], dimension) : a[1][s] - b[1][s];
|
|
706
711
|
}));
|
|
707
712
|
var values = divisions[dimension.nodeId].values;
|
|
708
713
|
if (dimension.numericalExtents[0] !== Infinity && dimension.subdivisions !== 1) {
|
|
@@ -747,9 +752,9 @@ var scaffoldDimensions = function(options, nodes) {
|
|
|
747
752
|
}
|
|
748
753
|
delete divisions[s];
|
|
749
754
|
}
|
|
750
|
-
} else if (typeof dimension.sortFunction === "function") {
|
|
755
|
+
} else if (typeof ((_dimension_operations = dimension.operations) === null || _dimension_operations === void 0 ? void 0 : _dimension_operations.sortFunction) === "function") {
|
|
751
756
|
dimension.divisions = Object.fromEntries(Object.entries(divisions).sort(function(a, b) {
|
|
752
|
-
return dimension.sortFunction(a[1], b[1], dimension);
|
|
757
|
+
return dimension.operations.sortFunction(a[1], b[1], dimension);
|
|
753
758
|
}));
|
|
754
759
|
}
|
|
755
760
|
var divisionKeys = Object.keys(dimension.divisions);
|
|
@@ -757,11 +762,41 @@ var scaffoldDimensions = function(options, nodes) {
|
|
|
757
762
|
var division = dimension.divisions[d];
|
|
758
763
|
if (typeof division.sortFunction === "function") {
|
|
759
764
|
division.values = Object.fromEntries(Object.entries(division.values).sort(function(a, b) {
|
|
760
|
-
return
|
|
765
|
+
return division.sortFunction(a[1], b[1], division);
|
|
761
766
|
}));
|
|
762
767
|
}
|
|
763
768
|
});
|
|
764
769
|
});
|
|
770
|
+
Object.keys(dimensions).forEach(function(s) {
|
|
771
|
+
var dimension = dimensions[s];
|
|
772
|
+
if (dimension.operations.compressSparseDivisions) {
|
|
773
|
+
var divisionKeys = Object.keys(dimension.divisions);
|
|
774
|
+
var values = {};
|
|
775
|
+
var sparse = true;
|
|
776
|
+
divisionKeys.forEach(function(d) {
|
|
777
|
+
var division = dimension.divisions[d];
|
|
778
|
+
var valueKeys = Object.keys(division.values);
|
|
779
|
+
if (valueKeys.length <= 1) {
|
|
780
|
+
valueKeys.forEach(function(vk) {
|
|
781
|
+
values[vk] = _object_spread({}, division.values[vk]);
|
|
782
|
+
});
|
|
783
|
+
} else {
|
|
784
|
+
sparse = false;
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
if (sparse) {
|
|
788
|
+
var newDivision = {
|
|
789
|
+
id: dimension.nodeId,
|
|
790
|
+
values: values
|
|
791
|
+
};
|
|
792
|
+
divisionKeys.forEach(function(d) {
|
|
793
|
+
delete nodes[d];
|
|
794
|
+
});
|
|
795
|
+
dimension.divisions = {};
|
|
796
|
+
dimension.divisions[dimension.nodeId] = newDivision;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
});
|
|
765
800
|
if (options.dimensions.adjustDimensions) {
|
|
766
801
|
dimensions = options.dimensions.adjustDimensions(dimensions);
|
|
767
802
|
}
|
|
@@ -851,9 +886,14 @@ var buildEdges = function(options, nodes, dimensions) {
|
|
|
851
886
|
l++;
|
|
852
887
|
});
|
|
853
888
|
dimensionKeys.forEach(function(s) {
|
|
854
|
-
var _dimension_behavior;
|
|
889
|
+
var _dimension_behavior, _dimension_behavior1, _dimension_behavior2, _dimension_behavior3;
|
|
855
890
|
var dimension = dimensions[s];
|
|
856
|
-
var
|
|
891
|
+
var strat = ((_dimension_behavior = dimension.behavior) === null || _dimension_behavior === void 0 ? void 0 : _dimension_behavior.childmostNavigation) || "within";
|
|
892
|
+
var matchByIndex = function(i, _a, _b, c) {
|
|
893
|
+
return c.values[Object.keys(c.values)[i]] || void 0;
|
|
894
|
+
};
|
|
895
|
+
var match = strat === "across" && ((_dimension_behavior1 = dimension.behavior) === null || _dimension_behavior1 === void 0 ? void 0 : _dimension_behavior1.childmostMatching) ? (_dimension_behavior2 = dimension.behavior) === null || _dimension_behavior2 === void 0 ? void 0 : _dimension_behavior2.childmostMatching : matchByIndex;
|
|
896
|
+
var extents2 = ((_dimension_behavior3 = dimension.behavior) === null || _dimension_behavior3 === void 0 ? void 0 : _dimension_behavior3.extents) || "circular";
|
|
857
897
|
if (!dimension.divisions) {
|
|
858
898
|
console.error("Parsing dimensions. The dimension using the key ".concat(s, " is missing the divisions property. dimension.divisions should be supplied. ").concat(JSON.stringify(dimension), "."));
|
|
859
899
|
}
|
|
@@ -893,33 +933,50 @@ var buildEdges = function(options, nodes, dimensions) {
|
|
|
893
933
|
} else {
|
|
894
934
|
createEdge(v[id], parentId, dimension.navigationRules.parent_child, "source");
|
|
895
935
|
}
|
|
896
|
-
if (
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
if (
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
936
|
+
if (strat === "within") {
|
|
937
|
+
if (i === valueKeys.length - 1 && extents2 === "circular") {
|
|
938
|
+
var targetId = typeof options.idKey === "function" ? options.idKey(division.values[valueKeys[0]]) : options.idKey;
|
|
939
|
+
createEdge(v[id], division.values[valueKeys[0]][targetId], dimension.navigationRules.sibling_sibling);
|
|
940
|
+
} else if (i === valueKeys.length - 1 && extents2 === "bridgedCousins") {
|
|
941
|
+
if (j !== divisionKeys.length - 1) {
|
|
942
|
+
var targetId1 = typeof options.idKey === "function" ? options.idKey(dimension.divisions[divisionKeys[j + 1]].values[valueKeys[0]]) : options.idKey;
|
|
943
|
+
createEdge(v[id], dimension.divisions[divisionKeys[j + 1]].values[valueKeys[0]][targetId1], dimension.navigationRules.sibling_sibling);
|
|
944
|
+
} else {
|
|
945
|
+
var targetId2 = typeof options.idKey === "function" ? options.idKey(dimension.divisions[divisionKeys[0]].values[valueKeys[0]]) : options.idKey;
|
|
946
|
+
createEdge(v[id], dimension.divisions[divisionKeys[0]].values[valueKeys[0]][targetId2], dimension.navigationRules.sibling_sibling);
|
|
947
|
+
}
|
|
948
|
+
} else if (i === valueKeys.length - 1 && extents2 === "bridgedCustom") {
|
|
949
|
+
createEdge(v[id], dimension.behavior.customBridgePost, dimension.navigationRules.sibling_sibling);
|
|
950
|
+
} else if (i < valueKeys.length - 1) {
|
|
951
|
+
var targetId3 = typeof options.idKey === "function" ? options.idKey(division.values[valueKeys[i + 1]]) : options.idKey;
|
|
952
|
+
createEdge(v[id], division.values[valueKeys[i + 1]][targetId3], dimension.navigationRules.sibling_sibling);
|
|
906
953
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
createEdge(dimension.
|
|
954
|
+
if (!i && extents2 === "bridgedCousins") {
|
|
955
|
+
if (j !== 0) {
|
|
956
|
+
var targetId4 = typeof options.idKey === "function" ? options.idKey(dimension.divisions[divisionKeys[j - 1]].values[valueKeys[valueKeys.length - 1]]) : options.idKey;
|
|
957
|
+
createEdge(dimension.divisions[divisionKeys[j - 1]].values[valueKeys[valueKeys.length - 1]][targetId4], v[id], dimension.navigationRules.sibling_sibling);
|
|
958
|
+
} else {
|
|
959
|
+
var targetId5 = typeof options.idKey === "function" ? options.idKey(dimension.divisions[divisionKeys[divisionKeys.length - 1]].values[valueKeys[valueKeys.length - 1]]) : options.idKey;
|
|
960
|
+
createEdge(dimension.divisions[divisionKeys[divisionKeys.length - 1]].values[valueKeys[valueKeys.length - 1]][targetId5], v[id], dimension.navigationRules.sibling_sibling);
|
|
961
|
+
}
|
|
962
|
+
} else if (!i && extents2 === "bridgedCustom") {
|
|
963
|
+
createEdge(dimension.behavior.customBridgePrevious, v[id], dimension.navigationRules.sibling_sibling);
|
|
964
|
+
}
|
|
965
|
+
} else {
|
|
966
|
+
if (j === divisionKeys.length - 1 && extents2 === "bridgedCustom") {
|
|
967
|
+
createEdge(v[id], dimension.behavior.customBridgePost, dimension.navigationRules.sibling_sibling);
|
|
968
|
+
} else if (!j && extents2 === "bridgedCustom") {
|
|
969
|
+
createEdge(dimension.behavior.customBridgePrevious, v[id], dimension.navigationRules.sibling_sibling);
|
|
917
970
|
} else {
|
|
918
|
-
var
|
|
919
|
-
|
|
971
|
+
var targetDivision = j === divisionKeys.length - 1 && extents2 === "circular" ? dimension.divisions[divisionKeys[0]] : dimension.divisions[divisionKeys[j + 1]];
|
|
972
|
+
if (targetDivision) {
|
|
973
|
+
var target = match(i, v[id], division, targetDivision);
|
|
974
|
+
if (target) {
|
|
975
|
+
var targetId6 = typeof options.idKey === "function" ? options.idKey(target) : options.idKey;
|
|
976
|
+
createEdge(v[id], target[targetId6], dimension.navigationRules.sibling_sibling);
|
|
977
|
+
}
|
|
978
|
+
}
|
|
920
979
|
}
|
|
921
|
-
} else if (!i && extents2 === "bridgedCustom") {
|
|
922
|
-
createEdge(dimension.behavior.customBridgePrevious, v[id], dimension.navigationRules.sibling_sibling);
|
|
923
980
|
}
|
|
924
981
|
i++;
|
|
925
982
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -439,7 +439,10 @@ var scaffoldDimensions = (options, nodes) => {
|
|
|
439
439
|
divisions: {},
|
|
440
440
|
numericalExtents: [Infinity, -Infinity],
|
|
441
441
|
type: dim.type,
|
|
442
|
-
|
|
442
|
+
operations: {
|
|
443
|
+
compressSparseDivisions: dim.operations?.compressSparseDivisions || false,
|
|
444
|
+
sortFunction: dim.operations?.sortFunction || void 0
|
|
445
|
+
},
|
|
443
446
|
behavior: dim.behavior || {
|
|
444
447
|
extents: "circular"
|
|
445
448
|
},
|
|
@@ -517,7 +520,7 @@ var scaffoldDimensions = (options, nodes) => {
|
|
|
517
520
|
if (dimension.type === "numerical") {
|
|
518
521
|
divisions[dimension.nodeId].values = Object.fromEntries(
|
|
519
522
|
Object.entries(divisions[dimension.nodeId].values).sort((a, b) => {
|
|
520
|
-
return typeof dimension.sortFunction === "function" ? dimension.sortFunction(a[1], b[1], dimension) : a[1][s] - b[1][s];
|
|
523
|
+
return typeof dimension.operations?.sortFunction === "function" ? dimension.operations.sortFunction(a[1], b[1], dimension) : a[1][s] - b[1][s];
|
|
521
524
|
})
|
|
522
525
|
);
|
|
523
526
|
let values = divisions[dimension.nodeId].values;
|
|
@@ -563,10 +566,10 @@ var scaffoldDimensions = (options, nodes) => {
|
|
|
563
566
|
}
|
|
564
567
|
delete divisions[s];
|
|
565
568
|
}
|
|
566
|
-
} else if (typeof dimension.sortFunction === "function") {
|
|
569
|
+
} else if (typeof dimension.operations?.sortFunction === "function") {
|
|
567
570
|
dimension.divisions = Object.fromEntries(
|
|
568
571
|
Object.entries(divisions).sort((a, b) => {
|
|
569
|
-
return dimension.sortFunction(a[1], b[1], dimension);
|
|
572
|
+
return dimension.operations.sortFunction(a[1], b[1], dimension);
|
|
570
573
|
})
|
|
571
574
|
);
|
|
572
575
|
}
|
|
@@ -576,12 +579,42 @@ var scaffoldDimensions = (options, nodes) => {
|
|
|
576
579
|
if (typeof division.sortFunction === "function") {
|
|
577
580
|
division.values = Object.fromEntries(
|
|
578
581
|
Object.entries(division.values).sort((a, b) => {
|
|
579
|
-
return
|
|
582
|
+
return division.sortFunction(a[1], b[1], division);
|
|
580
583
|
})
|
|
581
584
|
);
|
|
582
585
|
}
|
|
583
586
|
});
|
|
584
587
|
});
|
|
588
|
+
Object.keys(dimensions).forEach((s) => {
|
|
589
|
+
let dimension = dimensions[s];
|
|
590
|
+
if (dimension.operations.compressSparseDivisions) {
|
|
591
|
+
const divisionKeys = Object.keys(dimension.divisions);
|
|
592
|
+
const values = {};
|
|
593
|
+
let sparse = true;
|
|
594
|
+
divisionKeys.forEach((d) => {
|
|
595
|
+
const division = dimension.divisions[d];
|
|
596
|
+
const valueKeys = Object.keys(division.values);
|
|
597
|
+
if (valueKeys.length <= 1) {
|
|
598
|
+
valueKeys.forEach((vk) => {
|
|
599
|
+
values[vk] = { ...division.values[vk] };
|
|
600
|
+
});
|
|
601
|
+
} else {
|
|
602
|
+
sparse = false;
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
if (sparse) {
|
|
606
|
+
const newDivision = {
|
|
607
|
+
id: dimension.nodeId,
|
|
608
|
+
values
|
|
609
|
+
};
|
|
610
|
+
divisionKeys.forEach((d) => {
|
|
611
|
+
delete nodes[d];
|
|
612
|
+
});
|
|
613
|
+
dimension.divisions = {};
|
|
614
|
+
dimension.divisions[dimension.nodeId] = newDivision;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
});
|
|
585
618
|
if (options.dimensions.adjustDimensions) {
|
|
586
619
|
dimensions = options.dimensions.adjustDimensions(dimensions);
|
|
587
620
|
}
|
|
@@ -668,6 +701,11 @@ var buildEdges = (options, nodes, dimensions) => {
|
|
|
668
701
|
});
|
|
669
702
|
dimensionKeys.forEach((s) => {
|
|
670
703
|
const dimension = dimensions[s];
|
|
704
|
+
const strat = dimension.behavior?.childmostNavigation || "within";
|
|
705
|
+
const matchByIndex = (i, _a, _b, c) => {
|
|
706
|
+
return c.values[Object.keys(c.values)[i]] || void 0;
|
|
707
|
+
};
|
|
708
|
+
const match = strat === "across" && dimension.behavior?.childmostMatching ? dimension.behavior?.childmostMatching : matchByIndex;
|
|
671
709
|
let extents2 = dimension.behavior?.extents || "circular";
|
|
672
710
|
if (!dimension.divisions) {
|
|
673
711
|
console.error(
|
|
@@ -730,69 +768,96 @@ var buildEdges = (options, nodes, dimensions) => {
|
|
|
730
768
|
} else {
|
|
731
769
|
createEdge(v[id], parentId, dimension.navigationRules.parent_child, "source");
|
|
732
770
|
}
|
|
733
|
-
if (
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
v[id],
|
|
737
|
-
division.values[valueKeys[0]][targetId],
|
|
738
|
-
dimension.navigationRules.sibling_sibling
|
|
739
|
-
);
|
|
740
|
-
} else if (i === valueKeys.length - 1 && extents2 === "bridgedCousins") {
|
|
741
|
-
if (j !== divisionKeys.length - 1) {
|
|
742
|
-
const targetId = typeof options.idKey === "function" ? options.idKey(dimension.divisions[divisionKeys[j + 1]].values[valueKeys[0]]) : options.idKey;
|
|
771
|
+
if (strat === "within") {
|
|
772
|
+
if (i === valueKeys.length - 1 && extents2 === "circular") {
|
|
773
|
+
const targetId = typeof options.idKey === "function" ? options.idKey(division.values[valueKeys[0]]) : options.idKey;
|
|
743
774
|
createEdge(
|
|
744
775
|
v[id],
|
|
745
|
-
|
|
776
|
+
division.values[valueKeys[0]][targetId],
|
|
746
777
|
dimension.navigationRules.sibling_sibling
|
|
747
778
|
);
|
|
748
|
-
} else {
|
|
749
|
-
|
|
779
|
+
} else if (i === valueKeys.length - 1 && extents2 === "bridgedCousins") {
|
|
780
|
+
if (j !== divisionKeys.length - 1) {
|
|
781
|
+
const targetId = typeof options.idKey === "function" ? options.idKey(
|
|
782
|
+
dimension.divisions[divisionKeys[j + 1]].values[valueKeys[0]]
|
|
783
|
+
) : options.idKey;
|
|
784
|
+
createEdge(
|
|
785
|
+
v[id],
|
|
786
|
+
dimension.divisions[divisionKeys[j + 1]].values[valueKeys[0]][targetId],
|
|
787
|
+
dimension.navigationRules.sibling_sibling
|
|
788
|
+
);
|
|
789
|
+
} else {
|
|
790
|
+
const targetId = typeof options.idKey === "function" ? options.idKey(dimension.divisions[divisionKeys[0]].values[valueKeys[0]]) : options.idKey;
|
|
791
|
+
createEdge(
|
|
792
|
+
v[id],
|
|
793
|
+
dimension.divisions[divisionKeys[0]].values[valueKeys[0]][targetId],
|
|
794
|
+
dimension.navigationRules.sibling_sibling
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
} else if (i === valueKeys.length - 1 && extents2 === "bridgedCustom") {
|
|
750
798
|
createEdge(
|
|
751
799
|
v[id],
|
|
752
|
-
dimension.
|
|
800
|
+
dimension.behavior.customBridgePost,
|
|
801
|
+
dimension.navigationRules.sibling_sibling
|
|
802
|
+
);
|
|
803
|
+
} else if (i < valueKeys.length - 1) {
|
|
804
|
+
const targetId = typeof options.idKey === "function" ? options.idKey(division.values[valueKeys[i + 1]]) : options.idKey;
|
|
805
|
+
createEdge(
|
|
806
|
+
v[id],
|
|
807
|
+
division.values[valueKeys[i + 1]][targetId],
|
|
753
808
|
dimension.navigationRules.sibling_sibling
|
|
754
809
|
);
|
|
755
810
|
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
811
|
+
if (!i && extents2 === "bridgedCousins") {
|
|
812
|
+
if (j !== 0) {
|
|
813
|
+
const targetId = typeof options.idKey === "function" ? options.idKey(
|
|
814
|
+
dimension.divisions[divisionKeys[j - 1]].values[valueKeys[valueKeys.length - 1]]
|
|
815
|
+
) : options.idKey;
|
|
816
|
+
createEdge(
|
|
817
|
+
dimension.divisions[divisionKeys[j - 1]].values[valueKeys[valueKeys.length - 1]][targetId],
|
|
818
|
+
v[id],
|
|
819
|
+
dimension.navigationRules.sibling_sibling
|
|
820
|
+
);
|
|
821
|
+
} else {
|
|
822
|
+
const targetId = typeof options.idKey === "function" ? options.idKey(
|
|
823
|
+
dimension.divisions[divisionKeys[divisionKeys.length - 1]].values[valueKeys[valueKeys.length - 1]]
|
|
824
|
+
) : options.idKey;
|
|
825
|
+
createEdge(
|
|
826
|
+
dimension.divisions[divisionKeys[divisionKeys.length - 1]].values[valueKeys[valueKeys.length - 1]][targetId],
|
|
827
|
+
v[id],
|
|
828
|
+
dimension.navigationRules.sibling_sibling
|
|
829
|
+
);
|
|
830
|
+
}
|
|
831
|
+
} else if (!i && extents2 === "bridgedCustom") {
|
|
775
832
|
createEdge(
|
|
776
|
-
dimension.
|
|
833
|
+
dimension.behavior.customBridgePrevious,
|
|
777
834
|
v[id],
|
|
778
835
|
dimension.navigationRules.sibling_sibling
|
|
779
836
|
);
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
) : options.idKey;
|
|
837
|
+
}
|
|
838
|
+
} else {
|
|
839
|
+
if (j === divisionKeys.length - 1 && extents2 === "bridgedCustom") {
|
|
784
840
|
createEdge(
|
|
785
|
-
dimension.divisions[divisionKeys[divisionKeys.length - 1]].values[valueKeys[valueKeys.length - 1]][targetId],
|
|
786
841
|
v[id],
|
|
842
|
+
dimension.behavior.customBridgePost,
|
|
787
843
|
dimension.navigationRules.sibling_sibling
|
|
788
844
|
);
|
|
845
|
+
} else if (!j && extents2 === "bridgedCustom") {
|
|
846
|
+
createEdge(
|
|
847
|
+
dimension.behavior.customBridgePrevious,
|
|
848
|
+
v[id],
|
|
849
|
+
dimension.navigationRules.sibling_sibling
|
|
850
|
+
);
|
|
851
|
+
} else {
|
|
852
|
+
const targetDivision = j === divisionKeys.length - 1 && extents2 === "circular" ? dimension.divisions[divisionKeys[0]] : dimension.divisions[divisionKeys[j + 1]];
|
|
853
|
+
if (targetDivision) {
|
|
854
|
+
const target = match(i, v[id], division, targetDivision);
|
|
855
|
+
if (target) {
|
|
856
|
+
const targetId = typeof options.idKey === "function" ? options.idKey(target) : options.idKey;
|
|
857
|
+
createEdge(v[id], target[targetId], dimension.navigationRules.sibling_sibling);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
789
860
|
}
|
|
790
|
-
} else if (!i && extents2 === "bridgedCustom") {
|
|
791
|
-
createEdge(
|
|
792
|
-
dimension.behavior.customBridgePrevious,
|
|
793
|
-
v[id],
|
|
794
|
-
dimension.navigationRules.sibling_sibling
|
|
795
|
-
);
|
|
796
861
|
}
|
|
797
862
|
i++;
|
|
798
863
|
});
|
|
@@ -85,7 +85,10 @@ export type DimensionObject = {
|
|
|
85
85
|
nodeId: NodeId;
|
|
86
86
|
dimensionKey: DimensionKey;
|
|
87
87
|
divisions: DimensionDivisions;
|
|
88
|
-
|
|
88
|
+
operations: {
|
|
89
|
+
compressSparseDivisions: boolean;
|
|
90
|
+
sortFunction?: SortingFunction;
|
|
91
|
+
};
|
|
89
92
|
behavior?: DimensionBehavior;
|
|
90
93
|
navigationRules?: DimensionNavigationRules;
|
|
91
94
|
type?: DimensionType;
|
|
@@ -118,6 +121,7 @@ export type DimensionOperations = {
|
|
|
118
121
|
filterFunction?: FilteringFunction;
|
|
119
122
|
sortFunction?: SortingFunction;
|
|
120
123
|
createNumericalSubdivisions?: NumericallySubdivide;
|
|
124
|
+
compressSparseDivisions?: boolean;
|
|
121
125
|
};
|
|
122
126
|
export type DivisionObject = {
|
|
123
127
|
id: NodeId;
|
|
@@ -168,6 +172,8 @@ export type DimensionBehavior = {
|
|
|
168
172
|
extents: ExtentType;
|
|
169
173
|
customBridgePrevious?: NodeId;
|
|
170
174
|
customBridgePost?: NodeId;
|
|
175
|
+
childmostNavigation?: ChildmostNavigationStrategy;
|
|
176
|
+
childmostMatching?: ChildmostMatchingStrategy;
|
|
171
177
|
};
|
|
172
178
|
export type Level1Behavior = {
|
|
173
179
|
extents: Level0ExtentType;
|
|
@@ -205,6 +211,7 @@ export type DynamicRenderIdKey = ((d?: DatumObject) => string) | string;
|
|
|
205
211
|
export type DynamicDimensionId = ((d?: DimensionDatum, a?: GenericDataset) => NodeId) | NodeId;
|
|
206
212
|
export type DynamicDimensionRenderId = ((d?: DimensionDatum, a?: GenericDataset) => RenderId) | RenderId;
|
|
207
213
|
export type NumericallySubdivide = ((d?: DimensionKey, n?: Nodes) => number) | number;
|
|
214
|
+
export type ChildmostMatchingStrategy = (index?: number, currentDivisionChild?: DatumObject, currentDivision?: DivisionObject, nextDivision?: DivisionObject) => DatumObject | undefined;
|
|
208
215
|
export type AdjustingFunction = (d: Dimensions) => Dimensions;
|
|
209
216
|
export type SortingFunction = (a: DatumObject, b: DatumObject, c?: any) => number;
|
|
210
217
|
export type FilteringFunction = (a: DatumObject, b?: any) => boolean;
|
|
@@ -220,6 +227,7 @@ export type Direction = 'target' | 'source';
|
|
|
220
227
|
export type RenderingStrategy = 'outlineEach' | 'convexHull' | 'singleSquare' | 'custom';
|
|
221
228
|
export type DimensionType = 'numerical' | 'categorical';
|
|
222
229
|
export type ExtentType = 'circular' | 'terminal' | 'bridgedCousins' | 'bridgedCustom';
|
|
230
|
+
export type ChildmostNavigationStrategy = 'within' | 'across';
|
|
223
231
|
export type Level0ExtentType = 'circular' | 'terminal' | 'bridgedCustom';
|
|
224
232
|
export type DataType = 'vega-lite' | 'vl' | 'Vega-Lite' | 'generic' | 'default';
|
|
225
233
|
export type DimensionLevel = 0 | 1 | 2 | 3;
|
package/dist/structure.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e,i){if(i==null||i>e.length)i=e.length;for(var n=0,t=new Array(i);n<i;n++)t[n]=e[n];return t}function i(i){if(Array.isArray(i))return e(i)}function n(e,i,n){if(i in e){Object.defineProperty(e,i,{value:n,enumerable:true,configurable:true,writable:true})}else{e[i]=n}return e}function t(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function o(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function r(e){for(var i=1;i<arguments.length;i++){var t=arguments[i]!=null?arguments[i]:{};var o=Object.keys(t);if(typeof Object.getOwnPropertySymbols==="function"){o=o.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))}o.forEach(function(i){n(e,i,t[i])})}return e}function s(e,i){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);if(i){t=t.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})}n.push.apply(n,t)}return n}function a(e,i){i=i!=null?i:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(e,Object.getOwnPropertyDescriptors(i))}else{s(Object(i)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(i,n))})}return e}function d(e){return i(e)||t(e)||c(e)||o()}function u(e){"@swc/helpers - typeof";return e&&typeof Symbol!=="undefined"&&e.constructor===Symbol?"symbol":typeof e}function c(i,n){if(!i)return;if(typeof i==="string")return e(i,n);var t=Object.prototype.toString.call(i).slice(8,-1);if(t==="Object"&&i.constructor)t=i.constructor.name;if(t==="Map"||t==="Set")return Array.from(t);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return e(i,n)}var l=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var y=function(e,i){for(var n in i)l(e,n,{get:i[n],enumerable:!0})},p=function(e,i,n,t){var o=true,r=false,s=undefined;if(i&&typeof i=="object"||typeof i=="function")try{var a=function(){var o=u.value;!g.call(e,o)&&o!==n&&l(e,o,{get:function(){return i[o]},enumerable:!(t=v(i,o))||t.enumerable})};for(var d=f(i)[Symbol.iterator](),u;!(o=(u=d.next()).done);o=true)a()}catch(e){r=true;s=e}finally{try{if(!o&&d.return!=null){d.return()}}finally{if(r){throw s}}}return e};var m=function(e){return p(l({},"__esModule",{value:!0}),e)};var h={};y(h,{addSimpleDataIDs:function(){return S},buildEdges:function(){return P},buildNodeStructureFromVegaLite:function(){return _},buildNodes:function(){return x},buildRules:function(){return L},buildStructure:function(){return F},default:function(){return w},scaffoldDimensions:function(){return D}});module.exports=m(h);var b={Escape:!0,Enter:!0,Backspace:!0,ArrowLeft:!0,ArrowRight:!0,ArrowUp:!0,ArrowDown:!0};var O=["KeyW","KeyJ","LeftBracket","RightBracket","Slash","Backslash"];var k=[["LeftBracket","RightBracket"],["Slash","Backslash"]],E={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"}},K=[["left","right"],["up","down"],["backward","forward"],["previous","next"]];var I={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 R=function(e,i){var n=Object.keys(e),t="";return n.forEach(function(n){t+="".concat(i&&i.omitKeyNames?"":n+": ").concat(e[n],". ")}),t+=i&&i.semanticLabel||"Data point.",t},j=function(e){return"_"+e.replace(/[^a-zA-Z0-9_-]+/g,"_")};var w=function(e){return e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?_(e):F(e)},_=function(e){var i=I,n={},t={},o={},r=0,s=e.groupInclusionCriteria?e.groupInclusionCriteria:function(){return!0},a=e.itemInclusionCriteria?e.itemInclusionCriteria:function(){return!0},d=e.datumInclusionCriteria?e.datumInclusionCriteria:function(){return!0},u=e.vegaLiteView._renderer._origin,c=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],l=function(e,i){if(e["data-navigator-id"])return e["data-navigator-id"];var n="dn-node-".concat(i,"-").concat(r);return r++,e["data-navigator-id"]=n,n},v=function(i){var o=n[i],r=o.index,s=o.level,a=o.parent,d=[],u=a.items[r-1];if(u){var c=l(u,s);if(n[c]){var v="".concat(c,"-").concat(o.id);d.push(v),t[v]||(t[v]={source:c,target:o.id,navigationRules:["left","right"]})}}var f=a.items[r+1];if(f){var g=l(f,s);if(n[g]){var y="".concat(o.id,"-").concat(g);d.push(y),t[y]||(t[y]={source:o.id,target:g,navigationRules:["left","right"]})}}if(s==="group"&&a.items[r].items){var p=(a.items[r].items[0].mark.items[0].items||a.items[r].items)[0],m=l(p,"item");if(n[m]){var h="".concat(o.id,"-").concat(m);d.push(h),t[h]||(t[h]={source:o.id,target:m,navigationRules:["parent","child"]})}}else if(s==="item"){var b=l(a,"group");if(n[b]){var O="".concat(b,"-").concat(o.id);d.push(O),t[O]||(t[O]={source:b,target:o.id,navigationRules:["parent","child"]})}}return e.exitFunction&&(d.push("any-exit"),t["any-exit"]||(t["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),d.push("any-undo"),t["any-undo"]||(t["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),d},f=function(i,t,r,s,a){var u=l(i,t),c="render-"+u,v=r||[0,0];n[u]={},n[u].d={},n[u].id=u,n[u].renderId=c,n[u].index=s,n[u].level=t,n[u].parent=a,o[c]={},o[c].renderId=c,o[c].spatialProperties={},o[c].spatialProperties.x=i.bounds.x1+v[0],o[c].spatialProperties.y=i.bounds.y1+v[1],o[c].spatialProperties.width=i.bounds.x2-i.bounds.x1,o[c].spatialProperties.height=i.bounds.y2-i.bounds.y1,o[c].cssClass="dn-vega-lite-node",i.datum&&Object.keys(i.datum).forEach(function(o){var r=i.datum[o];d(o,r,i.datum,t,e.vegaLiteSpec)&&(n[u].d[e.keyRenamingHash&&e.keyRenamingHash[o]?e.keyRenamingHash[o]:o]=r)}),o[c].semantics={},o[c].semantics.label=e.nodeDescriber?e.nodeDescriber(n[u].d,i,t):R(n[u].d)},g=0;return c.items.forEach(function(i){if(s(i,g,e.vegaLiteSpec)){f(i,"group",u,g,c);var n=0,t=i.items[0].mark.items[0].items?i.items[0].mark.items[0]:i;t.items.forEach(function(o){a(o,n,i,e.vegaLiteSpec)&&f(o,"item",u,n,t),n++})}g++}),Object.keys(n).forEach(function(e){n[e].edges=v(e)}),{nodes:n,edges:t,elementData:o,navigationRules:i}},S=function(e){var i=0,n={};e.data.forEach(function(t){var o=typeof e.idKey=="function"?e.idKey(t):e.idKey;t[o]="_"+i,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(function(e){e in t&&(typeof t[e]=="string"?(n[e]||(n[e]=0),n[t[e]]||(n[t[e]]=0),t[o]+="_"+e+n[e]+"_"+t[e]+n[t[e]],n[e]++,n[t[e]]++):(n[e]||(n[e]=0),t[o]+="_"+e+n[e],n[e]++))}),i++})},x=function(e){var i={};return e.data.forEach(function(n){e.idKey||console.error("Building nodes. A key string must be supplied in options.idKey to specify the id keys of every node.");var t=typeof e.idKey=="function"?e.idKey(n):e.idKey,o=n[t];if(!o){console.error("Building nodes. Each datum in options.data must contain an id. When matching the id key string ".concat(t,", this datum has no id: ").concat(JSON.stringify(n),"."));return}if(i[o]){console.error("Building nodes. Each id for data in options.data must be unique. This id is not unique: ".concat(o,"."));return}else{var r=typeof e.renderIdKey=="function"?e.renderIdKey(n):e.renderIdKey;i[o]={id:o,edges:[],renderId:r?n[r]||"":n.renderIdKey||"",data:n}}}),i},D=function(e,i){var n,t;var o={};if((t=e.dimensions)===null||t===void 0?void 0:(n=t.parentOptions)===null||n===void 0?void 0:n.addLevel0){var s=e.dimensions.parentOptions.addLevel0;i[s.id]=a(r({},s),{dimensionLevel:0})}var c=d(K),l=function(e,i){var n=i.numericalExtents[0],t=i.numericalExtents[1];i.numericalExtents[0]=n<e?n:e,i.numericalExtents[1]=t>e?t:e};return e.data.forEach(function(n){var t=e.dimensions.values||[],s=0;t.forEach(function(t){if(!t.dimensionKey){console.error("Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ".concat(JSON.stringify(t),"."));return}if(t.dimensionKey in n){var a;var v=n[t.dimensionKey],f=typeof((a=t.operations)===null||a===void 0?void 0:a.filterFunction)=="function"?t.operations.filterFunction(n,t):!0;if(v!==void 0&&f){if(t.type||(t.type=(typeof v==="undefined"?"undefined":u(v))=="bigint"||typeof v=="number"?"numerical":"categorical"),!o[t.dimensionKey]){var g;var y=typeof t.nodeId=="function"?t.nodeId(t,e.data):t.nodeId||j(t.dimensionKey),p=typeof t.renderId=="function"?t.renderId(t,e.data):t.renderId||y;o[t.dimensionKey]={dimensionKey:t.dimensionKey,nodeId:y,divisions:{},numericalExtents:[1/0,-1/0],type:t.type,sortFunction:((g=t.operations)===null||g===void 0?void 0:g.sortFunction)||void 0,behavior:t.behavior||{extents:"circular"},navigationRules:t.navigationRules||{sibling_sibling:c.length?d(c.shift()):["previous_"+t.dimensionKey,"next_"+t.dimensionKey],parent_child:["parent_"+t.dimensionKey,"child"]}},i[y]={id:y,renderId:p,derivedNode:t.dimensionKey,edges:[],dimensionLevel:1,data:o[t.dimensionKey],renderingStrategy:t.renderingStrategy||"singleSquare"}}var m=o[t.dimensionKey],h=null;if(t.type==="categorical"){var b;var O=typeof((b=t.divisionOptions)===null||b===void 0?void 0:b.divisionNodeIds)=="function"?t.divisionOptions.divisionNodeIds(t.dimensionKey,v,s):j(m.nodeId+"_"+v);if(h=m.divisions[O],!h){var k,E,K;h=m.divisions[O]={id:O,sortFunction:((k=t.divisionOptions)===null||k===void 0?void 0:k.sortFunction)||void 0,values:{}};var I=typeof((E=t.divisionOptions)===null||E===void 0?void 0:E.divisionRenderIds)=="function"?t.divisionOptions.divisionRenderIds(t.dimensionKey,v,s):O;i[O]={id:O,renderId:I,derivedNode:t.dimensionKey,edges:[],dimensionLevel:2,data:r({},h),renderingStrategy:((K=t.divisionOptions)===null||K===void 0?void 0:K.renderingStrategy)||"singleSquare"},i[O].data[t.dimensionKey]=v}}else{var R;h=m.divisions[m.nodeId],h||(h=m.divisions[m.nodeId]={id:m.nodeId,sortFunction:((R=t.divisionOptions)===null||R===void 0?void 0:R.sortFunction)||void 0,values:{}}),t.operations||(t.operations={});var w=t.operations.createNumericalSubdivisions;m.subdivisions=typeof w=="number"&&w<1?1:w||1,w!==1&&(m.divisionOptions||(m.divisionOptions=t.divisionOptions),l(v,m))}var _=typeof e.idKey=="function"?e.idKey(n):e.idKey;h.values[n[_]]=n}}s++})}),Object.keys(o).forEach(function(e){var n=o[e],t=n.divisions;if(n.type==="numerical"){t[n.nodeId].values=Object.fromEntries(Object.entries(t[n.nodeId].values).sort(function(i,t){return typeof n.sortFunction=="function"?n.sortFunction(i[1],t[1],n):i[1][e]-t[1][e]}));var r=t[n.nodeId].values;if(n.numericalExtents[0]!==1/0&&n.subdivisions!==1){var s=Object.keys(r),a=typeof n.subdivisions=="function"?n.subdivisions(e,r):n.subdivisions,d=(n.numericalExtents[1]-n.numericalExtents[0])/a,u=n.numericalExtents[0]+d,c=0,l=0;for(u=n.numericalExtents[0]+d;u<=n.numericalExtents[1];u+=d){var v,f,g,y;var p=typeof((v=n.divisionOptions)===null||v===void 0?void 0:v.divisionNodeIds)=="function"?n.divisionOptions.divisionNodeIds(e,u,u):n.nodeId+"_"+u;n.divisions[p]={id:p,sortFunction:((f=n.divisionOptions)===null||f===void 0?void 0:f.sortFunction)||void 0,values:{}};var m=typeof((g=n.divisionOptions)===null||g===void 0?void 0:g.divisionRenderIds)=="function"?n.divisionOptions.divisionRenderIds(e,u,u):p;i[p]={id:p,renderId:m,derivedNode:e,edges:[],data:n.divisions[p],dimensionLevel:2,renderingStrategy:((y=n.divisionOptions)===null||y===void 0?void 0:y.renderingStrategy)||"singleSquare"};var h=!1;for(;!h&&l<s.length;){var b=r[s[l]];b[e]<=u?n.divisions[p].values[b.id]=b:(u+=d,h=!0),l++}c++}delete t[e]}}else typeof n.sortFunction=="function"&&(n.divisions=Object.fromEntries(Object.entries(t).sort(function(e,i){return n.sortFunction(e[1],i[1],n)})));Object.keys(n.divisions).forEach(function(e){var i=n.divisions[e];typeof i.sortFunction=="function"&&(i.values=Object.fromEntries(Object.entries(i.values).sort(function(e,t){return n.sortFunction(e[1],t[1],i)})))})}),e.dimensions.adjustDimensions&&(o=e.dimensions.adjustDimensions(o)),o},P=function(e,i,n){var t={},o=function(e,n){i[e].edges.indexOf(n)===-1&&i[e].edges.push(n)},r=function(i,n,r,s){var a="".concat(i,"-").concat(n),u=e.useDirectedEdges?"".concat(n,"-").concat(a):a,c=!s||s==="source",l=!s||s==="target",v=function(e){var o;t[e]?(o=t[e].navigationRules).push.apply(o,d(r||[])):t[e]={source:i,target:n,navigationRules:r?d(r):[]}};v(a),e.useDirectedEdges&&l&&v(u),c&&o(i,a),l&&o(n,u)};if(n&&Object.keys(n).length){var s,a,u,c,l,v,f,g,y,p;var m=Object.keys(n),h=(u=e.dimensions)===null||u===void 0?void 0:(a=u.parentOptions)===null||a===void 0?void 0:(s=a.level1Options)===null||s===void 0?void 0:s.order,b=h||m,O=0,k=((c=e.dimensions)===null||c===void 0?void 0:c.parentOptions)||{},E=((v=k.level1Options)===null||v===void 0?void 0:(l=v.behavior)===null||l===void 0?void 0:l.extents)||"terminal",K=k.addLevel0,I=K?((g=k.level1Options)===null||g===void 0?void 0:(f=g.navigationRules)===null||f===void 0?void 0:f.parent_child)||["parent","child"]:[],R=((p=k.level1Options)===null||p===void 0?void 0:(y=p.navigationRules)===null||y===void 0?void 0:y.sibling_sibling)||["left","right"],j=typeof b[0]=="string"?h?i[b[0]]:i[n[b[0]].nodeId]:b[0];K&&r(K.id,j.id,I,"source"),b.forEach(function(t){var o=typeof t=="string"?h?i[t]:i[n[t].nodeId]:t;if(o===t&&!i[o.id]&&(i[o.id]=o),K&&(e.useDirectedEdges?r(o.id,K.id,I,"source"):r(K.id,o.id,I,"target")),O===b.length-1&&E==="circular")r(o.id,j.id,R);else if(O===b.length-1&&E==="bridgedCustom")r(o.id,k.level1Options.behavior.customBridgePost,R);else if(O<b.length-1){var s=typeof b[O+1]=="string"?h?i[b[O+1]]:i[n[b[O+1]].nodeId]:b[O+1];r(o.id,s.id,R)}!O&&E==="bridgedCustom"&&r(k.level1Options.behavior.customBridgePost,o.id,R),O++}),m.forEach(function(i){var t;var o=n[i],s=((t=o.behavior)===null||t===void 0?void 0:t.extents)||"circular";o.divisions||console.error("Parsing dimensions. The dimension using the key ".concat(i," is missing the divisions property. dimension.divisions should be supplied. ").concat(JSON.stringify(o),"."));var a=Object.keys(o.divisions),d=o.divisions[a[0]];if(a.length!==1)r(o.nodeId,d.id,o.navigationRules.parent_child,"source");else{var u=Object.keys(d.values),c=typeof e.idKey=="function"?e.idKey(d.values[u[0]]):e.idKey;r(o.nodeId,d.values[u[0]][c],o.navigationRules.parent_child,"source")}var l=0;a.forEach(function(i){var n=o.divisions[i];l===a.length-1&&(s==="circular"||s==="bridgedCousins"||s==="bridgedCustom")?r(n.id,o.divisions[a[0]].id,o.navigationRules.sibling_sibling):l<a.length-1&&r(n.id,o.divisions[a[l+1]].id,o.navigationRules.sibling_sibling);var t=Object.keys(n.values);e.useDirectedEdges?r(n.id,o.nodeId,o.navigationRules.parent_child,"source"):r(o.nodeId,n.id,o.navigationRules.parent_child,"target");var d=typeof e.idKey=="function"?e.idKey(n.values[t[0]]):e.idKey;r(n.id,n.values[t[0]][d],o.navigationRules.parent_child,"source");var u=0;t.length>1&&t.forEach(function(i){var d=n.values[i],c=typeof e.idKey=="function"?e.idKey(d):e.idKey,v=a.length!==1?n.id:o.nodeId;if(e.useDirectedEdges?r(d[c],v,o.navigationRules.parent_child,"source"):r(v,d[c],o.navigationRules.parent_child,"target"),u===t.length-1&&s==="circular"){var f=typeof e.idKey=="function"?e.idKey(n.values[t[0]]):e.idKey;r(d[c],n.values[t[0]][f],o.navigationRules.sibling_sibling)}else if(u===t.length-1&&s==="bridgedCousins")if(l!==a.length-1){var g=typeof e.idKey=="function"?e.idKey(o.divisions[a[l+1]].values[t[0]]):e.idKey;r(d[c],o.divisions[a[l+1]].values[t[0]][g],o.navigationRules.sibling_sibling)}else{var y=typeof e.idKey=="function"?e.idKey(o.divisions[a[0]].values[t[0]]):e.idKey;r(d[c],o.divisions[a[0]].values[t[0]][y],o.navigationRules.sibling_sibling)}else if(u===t.length-1&&s==="bridgedCustom")r(d[c],o.behavior.customBridgePost,o.navigationRules.sibling_sibling);else if(u<t.length-1){var p=typeof e.idKey=="function"?e.idKey(n.values[t[u+1]]):e.idKey;r(d[c],n.values[t[u+1]][p],o.navigationRules.sibling_sibling)}if(!u&&s==="bridgedCousins")if(l!==0){var m=typeof e.idKey=="function"?e.idKey(o.divisions[a[l-1]].values[t[t.length-1]]):e.idKey;r(o.divisions[a[l-1]].values[t[t.length-1]][m],d[c],o.navigationRules.sibling_sibling)}else{var h=typeof e.idKey=="function"?e.idKey(o.divisions[a[a.length-1]].values[t[t.length-1]]):e.idKey;r(o.divisions[a[a.length-1]].values[t[t.length-1]][h],d[c],o.navigationRules.sibling_sibling)}else!u&&s==="bridgedCustom"&&r(o.behavior.customBridgePrevious,d[c],o.navigationRules.sibling_sibling);u++}),l++})})}return Object.keys(i).forEach(function(n){var o;var r=i[n];((o=e.genericEdges)===null||o===void 0?void 0:o.length)&&e.genericEdges.forEach(function(e){t[e.edgeId]||(t[e.edgeId]=e.edge),(!e.conditional||e.conditional&&e.conditional(r,e))&&r.edges.push(e.edgeId)})}),t},L=function(e,i,n){var t=e.navigationRules;if(!t){var o=Object.keys(n||{});o.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 ".concat(o.length,". Dimensions counted: ").concat(o.join(", "),"."));var s={},a={},u={},c=d(k),l=d(O),v=function(i,n){var t=i&&n,o=!1,v=!1;if((s[i]||a[i])&&(a[i]=r({},s[i]),o=!0),n&&(s[n]||a[n])&&(a[n]=r({},s[n]),v=!0),t&&!o&&!v){c.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.");var f=d(c.shift());l.splice(l.indexOf(f[0]),1),l.splice(l.indexOf(f[1]),1),a[i]={direction:e.useDirectedEdges?"target":"source",key:f[0]},a[n]={direction:"target",key:f[1]}}else{if(!a[i]&&l.length){var g=l.shift(),y=[];c.forEach(function(e){g!==e[0]&&g!==e[1]&&y.push(e)}),c=y,a[i]={direction:e.useDirectedEdges?"target":"source",key:g}}if(n&&!a[n]&&l.length){var p=l.shift(),m=[];c.forEach(function(e){p!==e[0]&&p!==e[1]&&m.push(e)}),c=m,a[n]={direction:"target",key:p}}l.length||(a[i]||(u[i]=i),n&&!a[n]&&(u[n]=n))}};if(Object.keys(E).forEach(function(i){var n=r({},E[i]);e.useDirectedEdges&&(n.direction="target"),s[i]=n}),o.length){var f,g;if((g=e.dimensions)===null||g===void 0?void 0:(f=g.parentOptions)===null||f===void 0?void 0:f.addLevel0){var y,p;var m=((p=e.dimensions.parentOptions.level1Options)===null||p===void 0?void 0:(y=p.navigationRules)===null||y===void 0?void 0:y.parent_child)||["parent","child"];v(m[0],m[1])}o.forEach(function(e){var i=n[e].navigationRules.parent_child,t=n[e].navigationRules.sibling_sibling;v(i[0],i[1]),v(t[0],t[1])})}if(Object.keys(i).forEach(function(e){i[e].navigationRules.forEach(function(e){a[e]||v(e)})}),Object.keys(u).length){var h={};Object.keys(a).forEach(function(e){h[a[e].key]=a[e].key}),Object.keys(s).forEach(function(e){!h[s[e].key]&&!b[s[e].key]&&l.push(s[e].key)});var K=r({},u);u={},Object.keys(K).forEach(function(e){v(e)}),Object.keys(u).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: ".concat(Object.keys(u).join(", "),"."))}t=a}return t},F=function(e){e.addIds&&S(e);var i=x(e),n=D(e,i),t=P(e,i,n),o=L(e,t,n);return{nodes:i,edges:t,dimensions:n,navigationRules:o}};0&&(module.exports={addSimpleDataIDs:addSimpleDataIDs,buildEdges:buildEdges,buildNodeStructureFromVegaLite:buildNodeStructureFromVegaLite,buildNodes:buildNodes,buildRules:buildRules,buildStructure:buildStructure,scaffoldDimensions:scaffoldDimensions});
|
|
1
|
+
function e(e,i){if(i==null||i>e.length)i=e.length;for(var n=0,t=new Array(i);n<i;n++)t[n]=e[n];return t}function i(i){if(Array.isArray(i))return e(i)}function n(e,i,n){if(i in e){Object.defineProperty(e,i,{value:n,enumerable:true,configurable:true,writable:true})}else{e[i]=n}return e}function t(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function o(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function r(e){for(var i=1;i<arguments.length;i++){var t=arguments[i]!=null?arguments[i]:{};var o=Object.keys(t);if(typeof Object.getOwnPropertySymbols==="function"){o=o.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))}o.forEach(function(i){n(e,i,t[i])})}return e}function s(e,i){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);if(i){t=t.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})}n.push.apply(n,t)}return n}function a(e,i){i=i!=null?i:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(e,Object.getOwnPropertyDescriptors(i))}else{s(Object(i)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(i,n))})}return e}function d(e){return i(e)||t(e)||c(e)||o()}function u(e){"@swc/helpers - typeof";return e&&typeof Symbol!=="undefined"&&e.constructor===Symbol?"symbol":typeof e}function c(i,n){if(!i)return;if(typeof i==="string")return e(i,n);var t=Object.prototype.toString.call(i).slice(8,-1);if(t==="Object"&&i.constructor)t=i.constructor.name;if(t==="Map"||t==="Set")return Array.from(t);if(t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return e(i,n)}var l=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var y=function(e,i){for(var n in i)l(e,n,{get:i[n],enumerable:!0})},p=function(e,i,n,t){var o=true,r=false,s=undefined;if(i&&typeof i=="object"||typeof i=="function")try{var a=function(){var o=u.value;!g.call(e,o)&&o!==n&&l(e,o,{get:function(){return i[o]},enumerable:!(t=v(i,o))||t.enumerable})};for(var d=f(i)[Symbol.iterator](),u;!(o=(u=d.next()).done);o=true)a()}catch(e){r=true;s=e}finally{try{if(!o&&d.return!=null){d.return()}}finally{if(r){throw s}}}return e};var m=function(e){return p(l({},"__esModule",{value:!0}),e)};var h={};y(h,{addSimpleDataIDs:function(){return S},buildEdges:function(){return P},buildNodeStructureFromVegaLite:function(){return _},buildNodes:function(){return x},buildRules:function(){return L},buildStructure:function(){return F},default:function(){return w},scaffoldDimensions:function(){return D}});module.exports=m(h);var b={Escape:!0,Enter:!0,Backspace:!0,ArrowLeft:!0,ArrowRight:!0,ArrowUp:!0,ArrowDown:!0};var O=["KeyW","KeyJ","LeftBracket","RightBracket","Slash","Backslash"];var k=[["LeftBracket","RightBracket"],["Slash","Backslash"]],E={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"}},K=[["left","right"],["up","down"],["backward","forward"],["previous","next"]];var I={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 R=function(e,i){var n=Object.keys(e),t="";return n.forEach(function(n){t+="".concat(i&&i.omitKeyNames?"":n+": ").concat(e[n],". ")}),t+=i&&i.semanticLabel||"Data point.",t},j=function(e){return"_"+e.replace(/[^a-zA-Z0-9_-]+/g,"_")};var w=function(e){return e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?_(e):F(e)},_=function(e){var i=I,n={},t={},o={},r=0,s=e.groupInclusionCriteria?e.groupInclusionCriteria:function(){return!0},a=e.itemInclusionCriteria?e.itemInclusionCriteria:function(){return!0},d=e.datumInclusionCriteria?e.datumInclusionCriteria:function(){return!0},u=e.vegaLiteView._renderer._origin,c=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],l=function(e,i){if(e["data-navigator-id"])return e["data-navigator-id"];var n="dn-node-".concat(i,"-").concat(r);return r++,e["data-navigator-id"]=n,n},v=function(i){var o=n[i],r=o.index,s=o.level,a=o.parent,d=[],u=a.items[r-1];if(u){var c=l(u,s);if(n[c]){var v="".concat(c,"-").concat(o.id);d.push(v),t[v]||(t[v]={source:c,target:o.id,navigationRules:["left","right"]})}}var f=a.items[r+1];if(f){var g=l(f,s);if(n[g]){var y="".concat(o.id,"-").concat(g);d.push(y),t[y]||(t[y]={source:o.id,target:g,navigationRules:["left","right"]})}}if(s==="group"&&a.items[r].items){var p=(a.items[r].items[0].mark.items[0].items||a.items[r].items)[0],m=l(p,"item");if(n[m]){var h="".concat(o.id,"-").concat(m);d.push(h),t[h]||(t[h]={source:o.id,target:m,navigationRules:["parent","child"]})}}else if(s==="item"){var b=l(a,"group");if(n[b]){var O="".concat(b,"-").concat(o.id);d.push(O),t[O]||(t[O]={source:b,target:o.id,navigationRules:["parent","child"]})}}return e.exitFunction&&(d.push("any-exit"),t["any-exit"]||(t["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),d.push("any-undo"),t["any-undo"]||(t["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),d},f=function(i,t,r,s,a){var u=l(i,t),c="render-"+u,v=r||[0,0];n[u]={},n[u].d={},n[u].id=u,n[u].renderId=c,n[u].index=s,n[u].level=t,n[u].parent=a,o[c]={},o[c].renderId=c,o[c].spatialProperties={},o[c].spatialProperties.x=i.bounds.x1+v[0],o[c].spatialProperties.y=i.bounds.y1+v[1],o[c].spatialProperties.width=i.bounds.x2-i.bounds.x1,o[c].spatialProperties.height=i.bounds.y2-i.bounds.y1,o[c].cssClass="dn-vega-lite-node",i.datum&&Object.keys(i.datum).forEach(function(o){var r=i.datum[o];d(o,r,i.datum,t,e.vegaLiteSpec)&&(n[u].d[e.keyRenamingHash&&e.keyRenamingHash[o]?e.keyRenamingHash[o]:o]=r)}),o[c].semantics={},o[c].semantics.label=e.nodeDescriber?e.nodeDescriber(n[u].d,i,t):R(n[u].d)},g=0;return c.items.forEach(function(i){if(s(i,g,e.vegaLiteSpec)){f(i,"group",u,g,c);var n=0,t=i.items[0].mark.items[0].items?i.items[0].mark.items[0]:i;t.items.forEach(function(o){a(o,n,i,e.vegaLiteSpec)&&f(o,"item",u,n,t),n++})}g++}),Object.keys(n).forEach(function(e){n[e].edges=v(e)}),{nodes:n,edges:t,elementData:o,navigationRules:i}},S=function(e){var i=0,n={};e.data.forEach(function(t){var o=typeof e.idKey=="function"?e.idKey(t):e.idKey;t[o]="_"+i,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(function(e){e in t&&(typeof t[e]=="string"?(n[e]||(n[e]=0),n[t[e]]||(n[t[e]]=0),t[o]+="_"+e+n[e]+"_"+t[e]+n[t[e]],n[e]++,n[t[e]]++):(n[e]||(n[e]=0),t[o]+="_"+e+n[e],n[e]++))}),i++})},x=function(e){var i={};return e.data.forEach(function(n){e.idKey||console.error("Building nodes. A key string must be supplied in options.idKey to specify the id keys of every node.");var t=typeof e.idKey=="function"?e.idKey(n):e.idKey,o=n[t];if(!o){console.error("Building nodes. Each datum in options.data must contain an id. When matching the id key string ".concat(t,", this datum has no id: ").concat(JSON.stringify(n),"."));return}if(i[o]){console.error("Building nodes. Each id for data in options.data must be unique. This id is not unique: ".concat(o,"."));return}else{var r=typeof e.renderIdKey=="function"?e.renderIdKey(n):e.renderIdKey;i[o]={id:o,edges:[],renderId:r?n[r]||"":n.renderIdKey||"",data:n}}}),i},D=function(e,i){var n,t;var o={};if((t=e.dimensions)===null||t===void 0?void 0:(n=t.parentOptions)===null||n===void 0?void 0:n.addLevel0){var s=e.dimensions.parentOptions.addLevel0;i[s.id]=a(r({},s),{dimensionLevel:0})}var c=d(K),l=function(e,i){var n=i.numericalExtents[0],t=i.numericalExtents[1];i.numericalExtents[0]=n<e?n:e,i.numericalExtents[1]=t>e?t:e};return e.data.forEach(function(n){var t=e.dimensions.values||[],s=0;t.forEach(function(t){if(!t.dimensionKey){console.error("Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ".concat(JSON.stringify(t),"."));return}if(t.dimensionKey in n){var a;var v=n[t.dimensionKey],f=typeof((a=t.operations)===null||a===void 0?void 0:a.filterFunction)=="function"?t.operations.filterFunction(n,t):!0;if(v!==void 0&&f){if(t.type||(t.type=(typeof v==="undefined"?"undefined":u(v))=="bigint"||typeof v=="number"?"numerical":"categorical"),!o[t.dimensionKey]){var g,y;var p=typeof t.nodeId=="function"?t.nodeId(t,e.data):t.nodeId||j(t.dimensionKey),m=typeof t.renderId=="function"?t.renderId(t,e.data):t.renderId||p;o[t.dimensionKey]={dimensionKey:t.dimensionKey,nodeId:p,divisions:{},numericalExtents:[1/0,-1/0],type:t.type,operations:{compressSparseDivisions:((g=t.operations)===null||g===void 0?void 0:g.compressSparseDivisions)||!1,sortFunction:((y=t.operations)===null||y===void 0?void 0:y.sortFunction)||void 0},behavior:t.behavior||{extents:"circular"},navigationRules:t.navigationRules||{sibling_sibling:c.length?d(c.shift()):["previous_"+t.dimensionKey,"next_"+t.dimensionKey],parent_child:["parent_"+t.dimensionKey,"child"]}},i[p]={id:p,renderId:m,derivedNode:t.dimensionKey,edges:[],dimensionLevel:1,data:o[t.dimensionKey],renderingStrategy:t.renderingStrategy||"singleSquare"}}var h=o[t.dimensionKey],b=null;if(t.type==="categorical"){var O;var k=typeof((O=t.divisionOptions)===null||O===void 0?void 0:O.divisionNodeIds)=="function"?t.divisionOptions.divisionNodeIds(t.dimensionKey,v,s):j(h.nodeId+"_"+v);if(b=h.divisions[k],!b){var E,K,I;b=h.divisions[k]={id:k,sortFunction:((E=t.divisionOptions)===null||E===void 0?void 0:E.sortFunction)||void 0,values:{}};var R=typeof((K=t.divisionOptions)===null||K===void 0?void 0:K.divisionRenderIds)=="function"?t.divisionOptions.divisionRenderIds(t.dimensionKey,v,s):k;i[k]={id:k,renderId:R,derivedNode:t.dimensionKey,edges:[],dimensionLevel:2,data:r({},b),renderingStrategy:((I=t.divisionOptions)===null||I===void 0?void 0:I.renderingStrategy)||"singleSquare"},i[k].data[t.dimensionKey]=v}}else{var w;b=h.divisions[h.nodeId],b||(b=h.divisions[h.nodeId]={id:h.nodeId,sortFunction:((w=t.divisionOptions)===null||w===void 0?void 0:w.sortFunction)||void 0,values:{}}),t.operations||(t.operations={});var _=t.operations.createNumericalSubdivisions;h.subdivisions=typeof _=="number"&&_<1?1:_||1,_!==1&&(h.divisionOptions||(h.divisionOptions=t.divisionOptions),l(v,h))}var S=typeof e.idKey=="function"?e.idKey(n):e.idKey;b.values[n[S]]=n}}s++})}),Object.keys(o).forEach(function(e){var n;var t=o[e],r=t.divisions;if(t.type==="numerical"){r[t.nodeId].values=Object.fromEntries(Object.entries(r[t.nodeId].values).sort(function(i,n){var o;return typeof((o=t.operations)===null||o===void 0?void 0:o.sortFunction)=="function"?t.operations.sortFunction(i[1],n[1],t):i[1][e]-n[1][e]}));var s=r[t.nodeId].values;if(t.numericalExtents[0]!==1/0&&t.subdivisions!==1){var a=Object.keys(s),d=typeof t.subdivisions=="function"?t.subdivisions(e,s):t.subdivisions,u=(t.numericalExtents[1]-t.numericalExtents[0])/d,c=t.numericalExtents[0]+u,l=0,v=0;for(c=t.numericalExtents[0]+u;c<=t.numericalExtents[1];c+=u){var f,g,y,p;var m=typeof((f=t.divisionOptions)===null||f===void 0?void 0:f.divisionNodeIds)=="function"?t.divisionOptions.divisionNodeIds(e,c,c):t.nodeId+"_"+c;t.divisions[m]={id:m,sortFunction:((g=t.divisionOptions)===null||g===void 0?void 0:g.sortFunction)||void 0,values:{}};var h=typeof((y=t.divisionOptions)===null||y===void 0?void 0:y.divisionRenderIds)=="function"?t.divisionOptions.divisionRenderIds(e,c,c):m;i[m]={id:m,renderId:h,derivedNode:e,edges:[],data:t.divisions[m],dimensionLevel:2,renderingStrategy:((p=t.divisionOptions)===null||p===void 0?void 0:p.renderingStrategy)||"singleSquare"};var b=!1;for(;!b&&v<a.length;){var O=s[a[v]];O[e]<=c?t.divisions[m].values[O.id]=O:(c+=u,b=!0),v++}l++}delete r[e]}}else typeof((n=t.operations)===null||n===void 0?void 0:n.sortFunction)=="function"&&(t.divisions=Object.fromEntries(Object.entries(r).sort(function(e,i){return t.operations.sortFunction(e[1],i[1],t)})));Object.keys(t.divisions).forEach(function(e){var i=t.divisions[e];typeof i.sortFunction=="function"&&(i.values=Object.fromEntries(Object.entries(i.values).sort(function(e,n){return i.sortFunction(e[1],n[1],i)})))})}),Object.keys(o).forEach(function(e){var n=o[e];if(n.operations.compressSparseDivisions){var t=Object.keys(n.divisions),s={},a=!0;if(t.forEach(function(e){var i=n.divisions[e],t=Object.keys(i.values);t.length<=1?t.forEach(function(e){s[e]=r({},i.values[e])}):a=!1}),a){var d={id:n.nodeId,values:s};t.forEach(function(e){delete i[e]}),n.divisions={},n.divisions[n.nodeId]=d}}}),e.dimensions.adjustDimensions&&(o=e.dimensions.adjustDimensions(o)),o},P=function(e,i,n){var t={},o=function(e,n){i[e].edges.indexOf(n)===-1&&i[e].edges.push(n)},r=function(i,n,r,s){var a="".concat(i,"-").concat(n),u=e.useDirectedEdges?"".concat(n,"-").concat(a):a,c=!s||s==="source",l=!s||s==="target",v=function(e){var o;t[e]?(o=t[e].navigationRules).push.apply(o,d(r||[])):t[e]={source:i,target:n,navigationRules:r?d(r):[]}};v(a),e.useDirectedEdges&&l&&v(u),c&&o(i,a),l&&o(n,u)};if(n&&Object.keys(n).length){var s,a,u,c,l,v,f,g,y,p;var m=Object.keys(n),h=(u=e.dimensions)===null||u===void 0?void 0:(a=u.parentOptions)===null||a===void 0?void 0:(s=a.level1Options)===null||s===void 0?void 0:s.order,b=h||m,O=0,k=((c=e.dimensions)===null||c===void 0?void 0:c.parentOptions)||{},E=((v=k.level1Options)===null||v===void 0?void 0:(l=v.behavior)===null||l===void 0?void 0:l.extents)||"terminal",K=k.addLevel0,I=K?((g=k.level1Options)===null||g===void 0?void 0:(f=g.navigationRules)===null||f===void 0?void 0:f.parent_child)||["parent","child"]:[],R=((p=k.level1Options)===null||p===void 0?void 0:(y=p.navigationRules)===null||y===void 0?void 0:y.sibling_sibling)||["left","right"],j=typeof b[0]=="string"?h?i[b[0]]:i[n[b[0]].nodeId]:b[0];K&&r(K.id,j.id,I,"source"),b.forEach(function(t){var o=typeof t=="string"?h?i[t]:i[n[t].nodeId]:t;if(o===t&&!i[o.id]&&(i[o.id]=o),K&&(e.useDirectedEdges?r(o.id,K.id,I,"source"):r(K.id,o.id,I,"target")),O===b.length-1&&E==="circular")r(o.id,j.id,R);else if(O===b.length-1&&E==="bridgedCustom")r(o.id,k.level1Options.behavior.customBridgePost,R);else if(O<b.length-1){var s=typeof b[O+1]=="string"?h?i[b[O+1]]:i[n[b[O+1]].nodeId]:b[O+1];r(o.id,s.id,R)}!O&&E==="bridgedCustom"&&r(k.level1Options.behavior.customBridgePost,o.id,R),O++}),m.forEach(function(i){var t,o,s,a;var d=n[i],u=((t=d.behavior)===null||t===void 0?void 0:t.childmostNavigation)||"within",c=function(e,i,n,t){return t.values[Object.keys(t.values)[e]]||void 0},l=u==="across"&&((o=d.behavior)===null||o===void 0?void 0:o.childmostMatching)?(s=d.behavior)===null||s===void 0?void 0:s.childmostMatching:c,v=((a=d.behavior)===null||a===void 0?void 0:a.extents)||"circular";d.divisions||console.error("Parsing dimensions. The dimension using the key ".concat(i," is missing the divisions property. dimension.divisions should be supplied. ").concat(JSON.stringify(d),"."));var f=Object.keys(d.divisions),g=d.divisions[f[0]];if(f.length!==1)r(d.nodeId,g.id,d.navigationRules.parent_child,"source");else{var y=Object.keys(g.values),p=typeof e.idKey=="function"?e.idKey(g.values[y[0]]):e.idKey;r(d.nodeId,g.values[y[0]][p],d.navigationRules.parent_child,"source")}var m=0;f.forEach(function(i){var n=d.divisions[i];m===f.length-1&&(v==="circular"||v==="bridgedCousins"||v==="bridgedCustom")?r(n.id,d.divisions[f[0]].id,d.navigationRules.sibling_sibling):m<f.length-1&&r(n.id,d.divisions[f[m+1]].id,d.navigationRules.sibling_sibling);var t=Object.keys(n.values);e.useDirectedEdges?r(n.id,d.nodeId,d.navigationRules.parent_child,"source"):r(d.nodeId,n.id,d.navigationRules.parent_child,"target");var o=typeof e.idKey=="function"?e.idKey(n.values[t[0]]):e.idKey;r(n.id,n.values[t[0]][o],d.navigationRules.parent_child,"source");var s=0;t.length>1&&t.forEach(function(i){var o=n.values[i],a=typeof e.idKey=="function"?e.idKey(o):e.idKey,c=f.length!==1?n.id:d.nodeId;if(e.useDirectedEdges?r(o[a],c,d.navigationRules.parent_child,"source"):r(c,o[a],d.navigationRules.parent_child,"target"),u==="within"){if(s===t.length-1&&v==="circular"){var g=typeof e.idKey=="function"?e.idKey(n.values[t[0]]):e.idKey;r(o[a],n.values[t[0]][g],d.navigationRules.sibling_sibling)}else if(s===t.length-1&&v==="bridgedCousins")if(m!==f.length-1){var y=typeof e.idKey=="function"?e.idKey(d.divisions[f[m+1]].values[t[0]]):e.idKey;r(o[a],d.divisions[f[m+1]].values[t[0]][y],d.navigationRules.sibling_sibling)}else{var p=typeof e.idKey=="function"?e.idKey(d.divisions[f[0]].values[t[0]]):e.idKey;r(o[a],d.divisions[f[0]].values[t[0]][p],d.navigationRules.sibling_sibling)}else if(s===t.length-1&&v==="bridgedCustom")r(o[a],d.behavior.customBridgePost,d.navigationRules.sibling_sibling);else if(s<t.length-1){var h=typeof e.idKey=="function"?e.idKey(n.values[t[s+1]]):e.idKey;r(o[a],n.values[t[s+1]][h],d.navigationRules.sibling_sibling)}if(!s&&v==="bridgedCousins")if(m!==0){var b=typeof e.idKey=="function"?e.idKey(d.divisions[f[m-1]].values[t[t.length-1]]):e.idKey;r(d.divisions[f[m-1]].values[t[t.length-1]][b],o[a],d.navigationRules.sibling_sibling)}else{var O=typeof e.idKey=="function"?e.idKey(d.divisions[f[f.length-1]].values[t[t.length-1]]):e.idKey;r(d.divisions[f[f.length-1]].values[t[t.length-1]][O],o[a],d.navigationRules.sibling_sibling)}else!s&&v==="bridgedCustom"&&r(d.behavior.customBridgePrevious,o[a],d.navigationRules.sibling_sibling)}else if(m===f.length-1&&v==="bridgedCustom")r(o[a],d.behavior.customBridgePost,d.navigationRules.sibling_sibling);else if(!m&&v==="bridgedCustom")r(d.behavior.customBridgePrevious,o[a],d.navigationRules.sibling_sibling);else{var k=m===f.length-1&&v==="circular"?d.divisions[f[0]]:d.divisions[f[m+1]];if(k){var E=l(s,o[a],n,k);if(E){var K=typeof e.idKey=="function"?e.idKey(E):e.idKey;r(o[a],E[K],d.navigationRules.sibling_sibling)}}}s++}),m++})})}return Object.keys(i).forEach(function(n){var o;var r=i[n];((o=e.genericEdges)===null||o===void 0?void 0:o.length)&&e.genericEdges.forEach(function(e){t[e.edgeId]||(t[e.edgeId]=e.edge),(!e.conditional||e.conditional&&e.conditional(r,e))&&r.edges.push(e.edgeId)})}),t},L=function(e,i,n){var t=e.navigationRules;if(!t){var o=Object.keys(n||{});o.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 ".concat(o.length,". Dimensions counted: ").concat(o.join(", "),"."));var s={},a={},u={},c=d(k),l=d(O),v=function(i,n){var t=i&&n,o=!1,v=!1;if((s[i]||a[i])&&(a[i]=r({},s[i]),o=!0),n&&(s[n]||a[n])&&(a[n]=r({},s[n]),v=!0),t&&!o&&!v){c.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.");var f=d(c.shift());l.splice(l.indexOf(f[0]),1),l.splice(l.indexOf(f[1]),1),a[i]={direction:e.useDirectedEdges?"target":"source",key:f[0]},a[n]={direction:"target",key:f[1]}}else{if(!a[i]&&l.length){var g=l.shift(),y=[];c.forEach(function(e){g!==e[0]&&g!==e[1]&&y.push(e)}),c=y,a[i]={direction:e.useDirectedEdges?"target":"source",key:g}}if(n&&!a[n]&&l.length){var p=l.shift(),m=[];c.forEach(function(e){p!==e[0]&&p!==e[1]&&m.push(e)}),c=m,a[n]={direction:"target",key:p}}l.length||(a[i]||(u[i]=i),n&&!a[n]&&(u[n]=n))}};if(Object.keys(E).forEach(function(i){var n=r({},E[i]);e.useDirectedEdges&&(n.direction="target"),s[i]=n}),o.length){var f,g;if((g=e.dimensions)===null||g===void 0?void 0:(f=g.parentOptions)===null||f===void 0?void 0:f.addLevel0){var y,p;var m=((p=e.dimensions.parentOptions.level1Options)===null||p===void 0?void 0:(y=p.navigationRules)===null||y===void 0?void 0:y.parent_child)||["parent","child"];v(m[0],m[1])}o.forEach(function(e){var i=n[e].navigationRules.parent_child,t=n[e].navigationRules.sibling_sibling;v(i[0],i[1]),v(t[0],t[1])})}if(Object.keys(i).forEach(function(e){i[e].navigationRules.forEach(function(e){a[e]||v(e)})}),Object.keys(u).length){var h={};Object.keys(a).forEach(function(e){h[a[e].key]=a[e].key}),Object.keys(s).forEach(function(e){!h[s[e].key]&&!b[s[e].key]&&l.push(s[e].key)});var K=r({},u);u={},Object.keys(K).forEach(function(e){v(e)}),Object.keys(u).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: ".concat(Object.keys(u).join(", "),"."))}t=a}return t},F=function(e){e.addIds&&S(e);var i=x(e),n=D(e,i),t=P(e,i,n),o=L(e,t,n);return{nodes:i,edges:t,dimensions:n,navigationRules:o}};0&&(module.exports={addSimpleDataIDs:addSimpleDataIDs,buildEdges:buildEdges,buildNodeStructureFromVegaLite:buildNodeStructureFromVegaLite,buildNodes:buildNodes,buildRules:buildRules,buildStructure:buildStructure,scaffoldDimensions:scaffoldDimensions});
|
package/dist/structure.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as T,b as F}from"./chunk-K476QBP2.mjs";import{a as $,c as P,e as k,f as C,g as w,i as B}from"./chunk-PEL3ZYDS.mjs";var z=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?G(e):U(e),G=e=>{let y=B,d={},l={},h={},t=0,s=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,f=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,n=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,u=e.vegaLiteView._renderer._origin,v=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],r=(o,i)=>{if(o["data-navigator-id"])return o["data-navigator-id"];let b=`dn-node-${i}-${t}`;return t++,o["data-navigator-id"]=b,b},a=o=>{let i=d[o],b=i.index,m=i.level,R=i.parent,O=[],K=R.items[b-1];if(K){let g=r(K,m);if(d[g]){let E=`${g}-${i.id}`;O.push(E),l[E]||(l[E]={source:g,target:i.id,navigationRules:["left","right"]})}}let I=R.items[b+1];if(I){let g=r(I,m);if(d[g]){let E=`${i.id}-${g}`;O.push(E),l[E]||(l[E]={source:i.id,target:g,navigationRules:["left","right"]})}}if(m==="group"&&R.items[b].items){let E=(R.items[b].items[0].mark.items[0].items||R.items[b].items)[0],x=r(E,"item");if(d[x]){let S=`${i.id}-${x}`;O.push(S),l[S]||(l[S]={source:i.id,target:x,navigationRules:["parent","child"]})}}else if(m==="item"){let g=r(R,"group");if(d[g]){let E=`${g}-${i.id}`;O.push(E),l[E]||(l[E]={source:g,target:i.id,navigationRules:["parent","child"]})}}return e.exitFunction&&(O.push("any-exit"),l["any-exit"]||(l["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),O.push("any-undo"),l["any-undo"]||(l["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),O},p=(o,i,b,m,R)=>{let O=r(o,i),K="render-"+O,I=b||[0,0];d[O]={},d[O].d={},d[O].id=O,d[O].renderId=K,d[O].index=m,d[O].level=i,d[O].parent=R,h[K]={},h[K].renderId=K,h[K].spatialProperties={},h[K].spatialProperties.x=o.bounds.x1+I[0],h[K].spatialProperties.y=o.bounds.y1+I[1],h[K].spatialProperties.width=o.bounds.x2-o.bounds.x1,h[K].spatialProperties.height=o.bounds.y2-o.bounds.y1,h[K].cssClass="dn-vega-lite-node",o.datum&&Object.keys(o.datum).forEach(g=>{let E=o.datum[g];n(g,E,o.datum,i,e.vegaLiteSpec)&&(d[O].d[e.keyRenamingHash&&e.keyRenamingHash[g]?e.keyRenamingHash[g]:g]=E)}),h[K].semantics={},h[K].semantics.label=e.nodeDescriber?e.nodeDescriber(d[O].d,o,i):T(d[O].d)},c=0;return v.items.forEach(o=>{if(s(o,c,e.vegaLiteSpec)){p(o,"group",u,c,v);let i=0,b=o.items[0].mark.items[0].items?o.items[0].mark.items[0]:o;b.items.forEach(m=>{f(m,i,o,e.vegaLiteSpec)&&p(m,"item",u,i,b),i++})}c++}),Object.keys(d).forEach(o=>{d[o].edges=a(o)}),{nodes:d,edges:l,elementData:h,navigationRules:y}},V=e=>{let y=0,d={};e.data.forEach(l=>{let h=typeof e.idKey=="function"?e.idKey(l):e.idKey;l[h]="_"+y,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(t=>{t in l&&(typeof l[t]=="string"?(d[t]||(d[t]=0),d[l[t]]||(d[l[t]]=0),l[h]+="_"+t+d[t]+"_"+l[t]+d[l[t]],d[t]++,d[l[t]]++):(d[t]||(d[t]=0),l[h]+="_"+t+d[t],d[t]++))}),y++})},q=e=>{let y={};return e.data.forEach(d=>{e.idKey||console.error("Building nodes. A key string must be supplied in options.idKey to specify the id keys of every node.");let l=typeof e.idKey=="function"?e.idKey(d):e.idKey,h=d[l];if(!h){console.error(`Building nodes. Each datum in options.data must contain an id. When matching the id key string ${l}, this datum has no id: ${JSON.stringify(d)}.`);return}if(y[h]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${h}.`);return}else{let t=typeof e.renderIdKey=="function"?e.renderIdKey(d):e.renderIdKey;y[h]={id:h,edges:[],renderId:t?d[t]||"":d.renderIdKey||"",data:d}}}),y},A=(e,y)=>{let d={};if(e.dimensions?.parentOptions?.addLevel0){let t=e.dimensions.parentOptions.addLevel0;y[t.id]={...t,dimensionLevel:0}}let l=[...w],h=(t,s)=>{let f=s.numericalExtents[0],n=s.numericalExtents[1];s.numericalExtents[0]=f<t?f:t,s.numericalExtents[1]=n>t?n:t};return e.data.forEach(t=>{let s=e.dimensions.values||[],f=0;s.forEach(n=>{if(!n.dimensionKey){console.error(`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(n)}.`);return}if(n.dimensionKey in t){let u=t[n.dimensionKey],v=typeof n.operations?.filterFunction=="function"?n.operations.filterFunction(t,n):!0;if(u!==void 0&&v){if(n.type||(n.type=typeof u=="bigint"||typeof u=="number"?"numerical":"categorical"),!d[n.dimensionKey]){let c=typeof n.nodeId=="function"?n.nodeId(n,e.data):n.nodeId||F(n.dimensionKey),j=typeof n.renderId=="function"?n.renderId(n,e.data):n.renderId||c;d[n.dimensionKey]={dimensionKey:n.dimensionKey,nodeId:c,divisions:{},numericalExtents:[1/0,-1/0],type:n.type,sortFunction:n.operations?.sortFunction||void 0,behavior:n.behavior||{extents:"circular"},navigationRules:n.navigationRules||{sibling_sibling:l.length?[...l.shift()]:["previous_"+n.dimensionKey,"next_"+n.dimensionKey],parent_child:["parent_"+n.dimensionKey,"child"]}},y[c]={id:c,renderId:j,derivedNode:n.dimensionKey,edges:[],dimensionLevel:1,data:d[n.dimensionKey],renderingStrategy:n.renderingStrategy||"singleSquare"}}let r=d[n.dimensionKey],a=null;if(n.type==="categorical"){let c=typeof n.divisionOptions?.divisionNodeIds=="function"?n.divisionOptions.divisionNodeIds(n.dimensionKey,u,f):F(r.nodeId+"_"+u);if(a=r.divisions[c],!a){a=r.divisions[c]={id:c,sortFunction:n.divisionOptions?.sortFunction||void 0,values:{}};let j=typeof n.divisionOptions?.divisionRenderIds=="function"?n.divisionOptions.divisionRenderIds(n.dimensionKey,u,f):c;y[c]={id:c,renderId:j,derivedNode:n.dimensionKey,edges:[],dimensionLevel:2,data:{...a},renderingStrategy:n.divisionOptions?.renderingStrategy||"singleSquare"},y[c].data[n.dimensionKey]=u}}else{a=r.divisions[r.nodeId],a||(a=r.divisions[r.nodeId]={id:r.nodeId,sortFunction:n.divisionOptions?.sortFunction||void 0,values:{}}),n.operations||(n.operations={});let c=n.operations.createNumericalSubdivisions;r.subdivisions=typeof c=="number"&&c<1?1:c||1,c!==1&&(r.divisionOptions||(r.divisionOptions=n.divisionOptions),h(u,r))}let p=typeof e.idKey=="function"?e.idKey(t):e.idKey;a.values[t[p]]=t}}f++})}),Object.keys(d).forEach(t=>{let s=d[t],f=s.divisions;if(s.type==="numerical"){f[s.nodeId].values=Object.fromEntries(Object.entries(f[s.nodeId].values).sort((v,r)=>typeof s.sortFunction=="function"?s.sortFunction(v[1],r[1],s):v[1][t]-r[1][t]));let u=f[s.nodeId].values;if(s.numericalExtents[0]!==1/0&&s.subdivisions!==1){let v=Object.keys(u),r=typeof s.subdivisions=="function"?s.subdivisions(t,u):s.subdivisions,p=(s.numericalExtents[1]-s.numericalExtents[0])/r,c=s.numericalExtents[0]+p,j=0,o=0;for(c=s.numericalExtents[0]+p;c<=s.numericalExtents[1];c+=p){let i=typeof s.divisionOptions?.divisionNodeIds=="function"?s.divisionOptions.divisionNodeIds(t,c,c):s.nodeId+"_"+c;s.divisions[i]={id:i,sortFunction:s.divisionOptions?.sortFunction||void 0,values:{}};let b=typeof s.divisionOptions?.divisionRenderIds=="function"?s.divisionOptions.divisionRenderIds(t,c,c):i;y[i]={id:i,renderId:b,derivedNode:t,edges:[],data:s.divisions[i],dimensionLevel:2,renderingStrategy:s.divisionOptions?.renderingStrategy||"singleSquare"};let m=!1;for(;!m&&o<v.length;){let R=u[v[o]];R[t]<=c?s.divisions[i].values[R.id]=R:(c+=p,m=!0),o++}j++}delete f[t]}}else typeof s.sortFunction=="function"&&(s.divisions=Object.fromEntries(Object.entries(f).sort((u,v)=>s.sortFunction(u[1],v[1],s))));Object.keys(s.divisions).forEach(u=>{let v=s.divisions[u];typeof v.sortFunction=="function"&&(v.values=Object.fromEntries(Object.entries(v.values).sort((r,a)=>s.sortFunction(r[1],a[1],v))))})}),e.dimensions.adjustDimensions&&(d=e.dimensions.adjustDimensions(d)),d},H=(e,y,d)=>{let l={},h=(s,f)=>{y[s].edges.indexOf(f)===-1&&y[s].edges.push(f)},t=(s,f,n,u)=>{let v=`${s}-${f}`,r=e.useDirectedEdges?`${f}-${v}`:v,a=!u||u==="source",p=!u||u==="target",c=j=>{l[j]?l[j].navigationRules.push(...n||[]):l[j]={source:s,target:f,navigationRules:n?[...n]:[]}};c(v),e.useDirectedEdges&&p&&c(r),a&&h(s,v),p&&h(f,r)};if(d&&Object.keys(d).length){let s=Object.keys(d),f=e.dimensions?.parentOptions?.level1Options?.order,n=f||s,u=0,v=e.dimensions?.parentOptions||{},r=v.level1Options?.behavior?.extents||"terminal",a=v.addLevel0,p=a?v.level1Options?.navigationRules?.parent_child||["parent","child"]:[],c=v.level1Options?.navigationRules?.sibling_sibling||["left","right"],j=typeof n[0]=="string"?f?y[n[0]]:y[d[n[0]].nodeId]:n[0];a&&t(a.id,j.id,p,"source"),n.forEach(o=>{let i=typeof o=="string"?f?y[o]:y[d[o].nodeId]:o;if(i===o&&!y[i.id]&&(y[i.id]=i),a&&(e.useDirectedEdges?t(i.id,a.id,p,"source"):t(a.id,i.id,p,"target")),u===n.length-1&&r==="circular")t(i.id,j.id,c);else if(u===n.length-1&&r==="bridgedCustom")t(i.id,v.level1Options.behavior.customBridgePost,c);else if(u<n.length-1){let b=typeof n[u+1]=="string"?f?y[n[u+1]]:y[d[n[u+1]].nodeId]:n[u+1];t(i.id,b.id,c)}!u&&r==="bridgedCustom"&&t(v.level1Options.behavior.customBridgePost,i.id,c),u++}),s.forEach(o=>{let i=d[o],b=i.behavior?.extents||"circular";i.divisions||console.error(`Parsing dimensions. The dimension using the key ${o} is missing the divisions property. dimension.divisions should be supplied. ${JSON.stringify(i)}.`);let m=Object.keys(i.divisions),R=i.divisions[m[0]];if(m.length!==1)t(i.nodeId,R.id,i.navigationRules.parent_child,"source");else{let K=Object.keys(R.values),I=typeof e.idKey=="function"?e.idKey(R.values[K[0]]):e.idKey;t(i.nodeId,R.values[K[0]][I],i.navigationRules.parent_child,"source")}let O=0;m.forEach(K=>{let I=i.divisions[K];O===m.length-1&&(b==="circular"||b==="bridgedCousins"||b==="bridgedCustom")?t(I.id,i.divisions[m[0]].id,i.navigationRules.sibling_sibling):O<m.length-1&&t(I.id,i.divisions[m[O+1]].id,i.navigationRules.sibling_sibling);let g=Object.keys(I.values);e.useDirectedEdges?t(I.id,i.nodeId,i.navigationRules.parent_child,"source"):t(i.nodeId,I.id,i.navigationRules.parent_child,"target");let E=typeof e.idKey=="function"?e.idKey(I.values[g[0]]):e.idKey;t(I.id,I.values[g[0]][E],i.navigationRules.parent_child,"source");let x=0;g.length>1&&g.forEach(S=>{let D=I.values[S],_=typeof e.idKey=="function"?e.idKey(D):e.idKey,L=m.length!==1?I.id:i.nodeId;if(e.useDirectedEdges?t(D[_],L,i.navigationRules.parent_child,"source"):t(L,D[_],i.navigationRules.parent_child,"target"),x===g.length-1&&b==="circular"){let N=typeof e.idKey=="function"?e.idKey(I.values[g[0]]):e.idKey;t(D[_],I.values[g[0]][N],i.navigationRules.sibling_sibling)}else if(x===g.length-1&&b==="bridgedCousins")if(O!==m.length-1){let N=typeof e.idKey=="function"?e.idKey(i.divisions[m[O+1]].values[g[0]]):e.idKey;t(D[_],i.divisions[m[O+1]].values[g[0]][N],i.navigationRules.sibling_sibling)}else{let N=typeof e.idKey=="function"?e.idKey(i.divisions[m[0]].values[g[0]]):e.idKey;t(D[_],i.divisions[m[0]].values[g[0]][N],i.navigationRules.sibling_sibling)}else if(x===g.length-1&&b==="bridgedCustom")t(D[_],i.behavior.customBridgePost,i.navigationRules.sibling_sibling);else if(x<g.length-1){let N=typeof e.idKey=="function"?e.idKey(I.values[g[x+1]]):e.idKey;t(D[_],I.values[g[x+1]][N],i.navigationRules.sibling_sibling)}if(!x&&b==="bridgedCousins")if(O!==0){let N=typeof e.idKey=="function"?e.idKey(i.divisions[m[O-1]].values[g[g.length-1]]):e.idKey;t(i.divisions[m[O-1]].values[g[g.length-1]][N],D[_],i.navigationRules.sibling_sibling)}else{let N=typeof e.idKey=="function"?e.idKey(i.divisions[m[m.length-1]].values[g[g.length-1]]):e.idKey;t(i.divisions[m[m.length-1]].values[g[g.length-1]][N],D[_],i.navigationRules.sibling_sibling)}else!x&&b==="bridgedCustom"&&t(i.behavior.customBridgePrevious,D[_],i.navigationRules.sibling_sibling);x++}),O++})})}return Object.keys(y).forEach(s=>{let f=y[s];e.genericEdges?.length&&e.genericEdges.forEach(n=>{l[n.edgeId]||(l[n.edgeId]=n.edge),(!n.conditional||n.conditional&&n.conditional(f,n))&&f.edges.push(n.edgeId)})}),l},J=(e,y,d)=>{let l=e.navigationRules;if(!l){let h=Object.keys(d||{});h.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 ${h.length}. Dimensions counted: ${h.join(", ")}.`);let t={},s={},f={},n=[...k],u=[...P],v=(r,a)=>{let p=r&&a,c=!1,j=!1;if((t[r]||s[r])&&(s[r]={...t[r]},c=!0),a&&(t[a]||s[a])&&(s[a]={...t[a]},j=!0),p&&!c&&!j){n.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 o=[...n.shift()];u.splice(u.indexOf(o[0]),1),u.splice(u.indexOf(o[1]),1),s[r]={direction:e.useDirectedEdges?"target":"source",key:o[0]},s[a]={direction:"target",key:o[1]}}else{if(!s[r]&&u.length){let o=u.shift(),i=[];n.forEach(b=>{o!==b[0]&&o!==b[1]&&i.push(b)}),n=i,s[r]={direction:e.useDirectedEdges?"target":"source",key:o}}if(a&&!s[a]&&u.length){let o=u.shift(),i=[];n.forEach(b=>{o!==b[0]&&o!==b[1]&&i.push(b)}),n=i,s[a]={direction:"target",key:o}}u.length||(s[r]||(f[r]=r),a&&!s[a]&&(f[a]=a))}};if(Object.keys(C).forEach(r=>{let a={...C[r]};e.useDirectedEdges&&(a.direction="target"),t[r]=a}),h.length){if(e.dimensions?.parentOptions?.addLevel0){let r=e.dimensions.parentOptions.level1Options?.navigationRules?.parent_child||["parent","child"];v(r[0],r[1])}h.forEach(r=>{let a=d[r].navigationRules.parent_child,p=d[r].navigationRules.sibling_sibling;v(a[0],a[1]),v(p[0],p[1])})}if(Object.keys(y).forEach(r=>{y[r].navigationRules.forEach(a=>{s[a]||v(a)})}),Object.keys(f).length){let r={};Object.keys(s).forEach(p=>{r[s[p].key]=s[p].key}),Object.keys(t).forEach(p=>{!r[t[p].key]&&!$[t[p].key]&&u.push(t[p].key)});let a={...f};f={},Object.keys(a).forEach(p=>{v(p)}),Object.keys(f).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(f).join(", ")}.`)}l=s}return l},U=e=>{e.addIds&&V(e);let y=q(e),d=A(e,y),l=H(e,y,d),h=J(e,l,d);return{nodes:y,edges:l,dimensions:d,navigationRules:h}};export{V as addSimpleDataIDs,H as buildEdges,G as buildNodeStructureFromVegaLite,q as buildNodes,J as buildRules,U as buildStructure,z as default,A as scaffoldDimensions};
|
|
1
|
+
import{a as q,b as P}from"./chunk-K476QBP2.mjs";import{a as w,c as B,e as T,f as $,g as G,i as V}from"./chunk-PEL3ZYDS.mjs";var ee=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?H(e):Q(e),H=e=>{let y=V,o={},u={},h={},t=0,s=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,g=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,n=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,l=e.vegaLiteView._renderer._origin,f=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],r=(d,i)=>{if(d["data-navigator-id"])return d["data-navigator-id"];let I=`dn-node-${i}-${t}`;return t++,d["data-navigator-id"]=I,I},a=d=>{let i=o[d],I=i.index,D=i.level,x=i.parent,m=[],v=x.items[I-1];if(v){let p=r(v,D);if(o[p]){let K=`${p}-${i.id}`;m.push(K),u[K]||(u[K]={source:p,target:i.id,navigationRules:["left","right"]})}}let S=x.items[I+1];if(S){let p=r(S,D);if(o[p]){let K=`${i.id}-${p}`;m.push(K),u[K]||(u[K]={source:i.id,target:p,navigationRules:["left","right"]})}}if(D==="group"&&x.items[I].items){let K=(x.items[I].items[0].mark.items[0].items||x.items[I].items)[0],E=r(K,"item");if(o[E]){let O=`${i.id}-${E}`;m.push(O),u[O]||(u[O]={source:i.id,target:E,navigationRules:["parent","child"]})}}else if(D==="item"){let p=r(x,"group");if(o[p]){let K=`${p}-${i.id}`;m.push(K),u[K]||(u[K]={source:p,target:i.id,navigationRules:["parent","child"]})}}return e.exitFunction&&(m.push("any-exit"),u["any-exit"]||(u["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),m.push("any-undo"),u["any-undo"]||(u["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),m},b=(d,i,I,D,x)=>{let m=r(d,i),v="render-"+m,S=I||[0,0];o[m]={},o[m].d={},o[m].id=m,o[m].renderId=v,o[m].index=D,o[m].level=i,o[m].parent=x,h[v]={},h[v].renderId=v,h[v].spatialProperties={},h[v].spatialProperties.x=d.bounds.x1+S[0],h[v].spatialProperties.y=d.bounds.y1+S[1],h[v].spatialProperties.width=d.bounds.x2-d.bounds.x1,h[v].spatialProperties.height=d.bounds.y2-d.bounds.y1,h[v].cssClass="dn-vega-lite-node",d.datum&&Object.keys(d.datum).forEach(p=>{let K=d.datum[p];n(p,K,d.datum,i,e.vegaLiteSpec)&&(o[m].d[e.keyRenamingHash&&e.keyRenamingHash[p]?e.keyRenamingHash[p]:p]=K)}),h[v].semantics={},h[v].semantics.label=e.nodeDescriber?e.nodeDescriber(o[m].d,d,i):q(o[m].d)},c=0;return f.items.forEach(d=>{if(s(d,c,e.vegaLiteSpec)){b(d,"group",l,c,f);let i=0,I=d.items[0].mark.items[0].items?d.items[0].mark.items[0]:d;I.items.forEach(D=>{g(D,i,d,e.vegaLiteSpec)&&b(D,"item",l,i,I),i++})}c++}),Object.keys(o).forEach(d=>{o[d].edges=a(d)}),{nodes:o,edges:u,elementData:h,navigationRules:y}},J=e=>{let y=0,o={};e.data.forEach(u=>{let h=typeof e.idKey=="function"?e.idKey(u):e.idKey;u[h]="_"+y,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(t=>{t in u&&(typeof u[t]=="string"?(o[t]||(o[t]=0),o[u[t]]||(o[u[t]]=0),u[h]+="_"+t+o[t]+"_"+u[t]+o[u[t]],o[t]++,o[u[t]]++):(o[t]||(o[t]=0),u[h]+="_"+t+o[t],o[t]++))}),y++})},U=e=>{let y={};return e.data.forEach(o=>{e.idKey||console.error("Building nodes. A key string must be supplied in options.idKey to specify the id keys of every node.");let u=typeof e.idKey=="function"?e.idKey(o):e.idKey,h=o[u];if(!h){console.error(`Building nodes. Each datum in options.data must contain an id. When matching the id key string ${u}, this datum has no id: ${JSON.stringify(o)}.`);return}if(y[h]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${h}.`);return}else{let t=typeof e.renderIdKey=="function"?e.renderIdKey(o):e.renderIdKey;y[h]={id:h,edges:[],renderId:t?o[t]||"":o.renderIdKey||"",data:o}}}),y},W=(e,y)=>{let o={};if(e.dimensions?.parentOptions?.addLevel0){let t=e.dimensions.parentOptions.addLevel0;y[t.id]={...t,dimensionLevel:0}}let u=[...G],h=(t,s)=>{let g=s.numericalExtents[0],n=s.numericalExtents[1];s.numericalExtents[0]=g<t?g:t,s.numericalExtents[1]=n>t?n:t};return e.data.forEach(t=>{let s=e.dimensions.values||[],g=0;s.forEach(n=>{if(!n.dimensionKey){console.error(`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(n)}.`);return}if(n.dimensionKey in t){let l=t[n.dimensionKey],f=typeof n.operations?.filterFunction=="function"?n.operations.filterFunction(t,n):!0;if(l!==void 0&&f){if(n.type||(n.type=typeof l=="bigint"||typeof l=="number"?"numerical":"categorical"),!o[n.dimensionKey]){let c=typeof n.nodeId=="function"?n.nodeId(n,e.data):n.nodeId||P(n.dimensionKey),j=typeof n.renderId=="function"?n.renderId(n,e.data):n.renderId||c;o[n.dimensionKey]={dimensionKey:n.dimensionKey,nodeId:c,divisions:{},numericalExtents:[1/0,-1/0],type:n.type,operations:{compressSparseDivisions:n.operations?.compressSparseDivisions||!1,sortFunction:n.operations?.sortFunction||void 0},behavior:n.behavior||{extents:"circular"},navigationRules:n.navigationRules||{sibling_sibling:u.length?[...u.shift()]:["previous_"+n.dimensionKey,"next_"+n.dimensionKey],parent_child:["parent_"+n.dimensionKey,"child"]}},y[c]={id:c,renderId:j,derivedNode:n.dimensionKey,edges:[],dimensionLevel:1,data:o[n.dimensionKey],renderingStrategy:n.renderingStrategy||"singleSquare"}}let r=o[n.dimensionKey],a=null;if(n.type==="categorical"){let c=typeof n.divisionOptions?.divisionNodeIds=="function"?n.divisionOptions.divisionNodeIds(n.dimensionKey,l,g):P(r.nodeId+"_"+l);if(a=r.divisions[c],!a){a=r.divisions[c]={id:c,sortFunction:n.divisionOptions?.sortFunction||void 0,values:{}};let j=typeof n.divisionOptions?.divisionRenderIds=="function"?n.divisionOptions.divisionRenderIds(n.dimensionKey,l,g):c;y[c]={id:c,renderId:j,derivedNode:n.dimensionKey,edges:[],dimensionLevel:2,data:{...a},renderingStrategy:n.divisionOptions?.renderingStrategy||"singleSquare"},y[c].data[n.dimensionKey]=l}}else{a=r.divisions[r.nodeId],a||(a=r.divisions[r.nodeId]={id:r.nodeId,sortFunction:n.divisionOptions?.sortFunction||void 0,values:{}}),n.operations||(n.operations={});let c=n.operations.createNumericalSubdivisions;r.subdivisions=typeof c=="number"&&c<1?1:c||1,c!==1&&(r.divisionOptions||(r.divisionOptions=n.divisionOptions),h(l,r))}let b=typeof e.idKey=="function"?e.idKey(t):e.idKey;a.values[t[b]]=t}}g++})}),Object.keys(o).forEach(t=>{let s=o[t],g=s.divisions;if(s.type==="numerical"){g[s.nodeId].values=Object.fromEntries(Object.entries(g[s.nodeId].values).sort((f,r)=>typeof s.operations?.sortFunction=="function"?s.operations.sortFunction(f[1],r[1],s):f[1][t]-r[1][t]));let l=g[s.nodeId].values;if(s.numericalExtents[0]!==1/0&&s.subdivisions!==1){let f=Object.keys(l),r=typeof s.subdivisions=="function"?s.subdivisions(t,l):s.subdivisions,b=(s.numericalExtents[1]-s.numericalExtents[0])/r,c=s.numericalExtents[0]+b,j=0,d=0;for(c=s.numericalExtents[0]+b;c<=s.numericalExtents[1];c+=b){let i=typeof s.divisionOptions?.divisionNodeIds=="function"?s.divisionOptions.divisionNodeIds(t,c,c):s.nodeId+"_"+c;s.divisions[i]={id:i,sortFunction:s.divisionOptions?.sortFunction||void 0,values:{}};let I=typeof s.divisionOptions?.divisionRenderIds=="function"?s.divisionOptions.divisionRenderIds(t,c,c):i;y[i]={id:i,renderId:I,derivedNode:t,edges:[],data:s.divisions[i],dimensionLevel:2,renderingStrategy:s.divisionOptions?.renderingStrategy||"singleSquare"};let D=!1;for(;!D&&d<f.length;){let x=l[f[d]];x[t]<=c?s.divisions[i].values[x.id]=x:(c+=b,D=!0),d++}j++}delete g[t]}}else typeof s.operations?.sortFunction=="function"&&(s.divisions=Object.fromEntries(Object.entries(g).sort((l,f)=>s.operations.sortFunction(l[1],f[1],s))));Object.keys(s.divisions).forEach(l=>{let f=s.divisions[l];typeof f.sortFunction=="function"&&(f.values=Object.fromEntries(Object.entries(f.values).sort((r,a)=>f.sortFunction(r[1],a[1],f))))})}),Object.keys(o).forEach(t=>{let s=o[t];if(s.operations.compressSparseDivisions){let g=Object.keys(s.divisions),n={},l=!0;if(g.forEach(f=>{let r=s.divisions[f],a=Object.keys(r.values);a.length<=1?a.forEach(b=>{n[b]={...r.values[b]}}):l=!1}),l){let f={id:s.nodeId,values:n};g.forEach(r=>{delete y[r]}),s.divisions={},s.divisions[s.nodeId]=f}}}),e.dimensions.adjustDimensions&&(o=e.dimensions.adjustDimensions(o)),o},Y=(e,y,o)=>{let u={},h=(s,g)=>{y[s].edges.indexOf(g)===-1&&y[s].edges.push(g)},t=(s,g,n,l)=>{let f=`${s}-${g}`,r=e.useDirectedEdges?`${g}-${f}`:f,a=!l||l==="source",b=!l||l==="target",c=j=>{u[j]?u[j].navigationRules.push(...n||[]):u[j]={source:s,target:g,navigationRules:n?[...n]:[]}};c(f),e.useDirectedEdges&&b&&c(r),a&&h(s,f),b&&h(g,r)};if(o&&Object.keys(o).length){let s=Object.keys(o),g=e.dimensions?.parentOptions?.level1Options?.order,n=g||s,l=0,f=e.dimensions?.parentOptions||{},r=f.level1Options?.behavior?.extents||"terminal",a=f.addLevel0,b=a?f.level1Options?.navigationRules?.parent_child||["parent","child"]:[],c=f.level1Options?.navigationRules?.sibling_sibling||["left","right"],j=typeof n[0]=="string"?g?y[n[0]]:y[o[n[0]].nodeId]:n[0];a&&t(a.id,j.id,b,"source"),n.forEach(d=>{let i=typeof d=="string"?g?y[d]:y[o[d].nodeId]:d;if(i===d&&!y[i.id]&&(y[i.id]=i),a&&(e.useDirectedEdges?t(i.id,a.id,b,"source"):t(a.id,i.id,b,"target")),l===n.length-1&&r==="circular")t(i.id,j.id,c);else if(l===n.length-1&&r==="bridgedCustom")t(i.id,f.level1Options.behavior.customBridgePost,c);else if(l<n.length-1){let I=typeof n[l+1]=="string"?g?y[n[l+1]]:y[o[n[l+1]].nodeId]:n[l+1];t(i.id,I.id,c)}!l&&r==="bridgedCustom"&&t(f.level1Options.behavior.customBridgePost,i.id,c),l++}),s.forEach(d=>{let i=o[d],I=i.behavior?.childmostNavigation||"within",D=(K,E,O,F)=>F.values[Object.keys(F.values)[K]]||void 0,x=I==="across"&&i.behavior?.childmostMatching?i.behavior?.childmostMatching:D,m=i.behavior?.extents||"circular";i.divisions||console.error(`Parsing dimensions. The dimension using the key ${d} is missing the divisions property. dimension.divisions should be supplied. ${JSON.stringify(i)}.`);let v=Object.keys(i.divisions),S=i.divisions[v[0]];if(v.length!==1)t(i.nodeId,S.id,i.navigationRules.parent_child,"source");else{let K=Object.keys(S.values),E=typeof e.idKey=="function"?e.idKey(S.values[K[0]]):e.idKey;t(i.nodeId,S.values[K[0]][E],i.navigationRules.parent_child,"source")}let p=0;v.forEach(K=>{let E=i.divisions[K];p===v.length-1&&(m==="circular"||m==="bridgedCousins"||m==="bridgedCustom")?t(E.id,i.divisions[v[0]].id,i.navigationRules.sibling_sibling):p<v.length-1&&t(E.id,i.divisions[v[p+1]].id,i.navigationRules.sibling_sibling);let O=Object.keys(E.values);e.useDirectedEdges?t(E.id,i.nodeId,i.navigationRules.parent_child,"source"):t(i.nodeId,E.id,i.navigationRules.parent_child,"target");let F=typeof e.idKey=="function"?e.idKey(E.values[O[0]]):e.idKey;t(E.id,E.values[O[0]][F],i.navigationRules.parent_child,"source");let C=0;O.length>1&&O.forEach(M=>{let R=E.values[M],N=typeof e.idKey=="function"?e.idKey(R):e.idKey,k=v.length!==1?E.id:i.nodeId;if(e.useDirectedEdges?t(R[N],k,i.navigationRules.parent_child,"source"):t(k,R[N],i.navigationRules.parent_child,"target"),I==="within"){if(C===O.length-1&&m==="circular"){let _=typeof e.idKey=="function"?e.idKey(E.values[O[0]]):e.idKey;t(R[N],E.values[O[0]][_],i.navigationRules.sibling_sibling)}else if(C===O.length-1&&m==="bridgedCousins")if(p!==v.length-1){let _=typeof e.idKey=="function"?e.idKey(i.divisions[v[p+1]].values[O[0]]):e.idKey;t(R[N],i.divisions[v[p+1]].values[O[0]][_],i.navigationRules.sibling_sibling)}else{let _=typeof e.idKey=="function"?e.idKey(i.divisions[v[0]].values[O[0]]):e.idKey;t(R[N],i.divisions[v[0]].values[O[0]][_],i.navigationRules.sibling_sibling)}else if(C===O.length-1&&m==="bridgedCustom")t(R[N],i.behavior.customBridgePost,i.navigationRules.sibling_sibling);else if(C<O.length-1){let _=typeof e.idKey=="function"?e.idKey(E.values[O[C+1]]):e.idKey;t(R[N],E.values[O[C+1]][_],i.navigationRules.sibling_sibling)}if(!C&&m==="bridgedCousins")if(p!==0){let _=typeof e.idKey=="function"?e.idKey(i.divisions[v[p-1]].values[O[O.length-1]]):e.idKey;t(i.divisions[v[p-1]].values[O[O.length-1]][_],R[N],i.navigationRules.sibling_sibling)}else{let _=typeof e.idKey=="function"?e.idKey(i.divisions[v[v.length-1]].values[O[O.length-1]]):e.idKey;t(i.divisions[v[v.length-1]].values[O[O.length-1]][_],R[N],i.navigationRules.sibling_sibling)}else!C&&m==="bridgedCustom"&&t(i.behavior.customBridgePrevious,R[N],i.navigationRules.sibling_sibling)}else if(p===v.length-1&&m==="bridgedCustom")t(R[N],i.behavior.customBridgePost,i.navigationRules.sibling_sibling);else if(!p&&m==="bridgedCustom")t(i.behavior.customBridgePrevious,R[N],i.navigationRules.sibling_sibling);else{let _=p===v.length-1&&m==="circular"?i.divisions[v[0]]:i.divisions[v[p+1]];if(_){let L=x(C,R[N],E,_);if(L){let A=typeof e.idKey=="function"?e.idKey(L):e.idKey;t(R[N],L[A],i.navigationRules.sibling_sibling)}}}C++}),p++})})}return Object.keys(y).forEach(s=>{let g=y[s];e.genericEdges?.length&&e.genericEdges.forEach(n=>{u[n.edgeId]||(u[n.edgeId]=n.edge),(!n.conditional||n.conditional&&n.conditional(g,n))&&g.edges.push(n.edgeId)})}),u},z=(e,y,o)=>{let u=e.navigationRules;if(!u){let h=Object.keys(o||{});h.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 ${h.length}. Dimensions counted: ${h.join(", ")}.`);let t={},s={},g={},n=[...T],l=[...B],f=(r,a)=>{let b=r&&a,c=!1,j=!1;if((t[r]||s[r])&&(s[r]={...t[r]},c=!0),a&&(t[a]||s[a])&&(s[a]={...t[a]},j=!0),b&&!c&&!j){n.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 d=[...n.shift()];l.splice(l.indexOf(d[0]),1),l.splice(l.indexOf(d[1]),1),s[r]={direction:e.useDirectedEdges?"target":"source",key:d[0]},s[a]={direction:"target",key:d[1]}}else{if(!s[r]&&l.length){let d=l.shift(),i=[];n.forEach(I=>{d!==I[0]&&d!==I[1]&&i.push(I)}),n=i,s[r]={direction:e.useDirectedEdges?"target":"source",key:d}}if(a&&!s[a]&&l.length){let d=l.shift(),i=[];n.forEach(I=>{d!==I[0]&&d!==I[1]&&i.push(I)}),n=i,s[a]={direction:"target",key:d}}l.length||(s[r]||(g[r]=r),a&&!s[a]&&(g[a]=a))}};if(Object.keys($).forEach(r=>{let a={...$[r]};e.useDirectedEdges&&(a.direction="target"),t[r]=a}),h.length){if(e.dimensions?.parentOptions?.addLevel0){let r=e.dimensions.parentOptions.level1Options?.navigationRules?.parent_child||["parent","child"];f(r[0],r[1])}h.forEach(r=>{let a=o[r].navigationRules.parent_child,b=o[r].navigationRules.sibling_sibling;f(a[0],a[1]),f(b[0],b[1])})}if(Object.keys(y).forEach(r=>{y[r].navigationRules.forEach(a=>{s[a]||f(a)})}),Object.keys(g).length){let r={};Object.keys(s).forEach(b=>{r[s[b].key]=s[b].key}),Object.keys(t).forEach(b=>{!r[t[b].key]&&!w[t[b].key]&&l.push(t[b].key)});let a={...g};g={},Object.keys(a).forEach(b=>{f(b)}),Object.keys(g).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(g).join(", ")}.`)}u=s}return u},Q=e=>{e.addIds&&J(e);let y=U(e),o=W(e,y),u=Y(e,y,o),h=z(e,u,o);return{nodes:y,edges:u,dimensions:o,navigationRules:h}};export{J as addSimpleDataIDs,Y as buildEdges,H as buildNodeStructureFromVegaLite,U as buildNodes,z as buildRules,Q as buildStructure,ee as default,W as scaffoldDimensions};
|