data-navigator 2.0.1 → 2.1.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 +41 -6
- package/dist/index.mjs +38 -5
- package/dist/src/data-navigator.d.ts +5 -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
|
}
|
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
|
}
|
|
@@ -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;
|
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 _},buildEdges:function(){return P},buildNodeStructureFromVegaLite:function(){return S},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"?S(e):F(e)},S=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}},_=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 S=t.operations.createNumericalSubdivisions;h.subdivisions=typeof S=="number"&&S<1?1:S||1,S!==1&&(h.divisionOptions||(h.divisionOptions=t.divisionOptions),l(v,h))}var _=typeof e.idKey=="function"?e.idKey(n):e.idKey;b.values[n[_]]=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;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&&_(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 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,o={},u={},h={},t=0,s=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,f=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,i=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,l=e.vegaLiteView._renderer._origin,v=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],d=(r,n)=>{if(r["data-navigator-id"])return r["data-navigator-id"];let b=`dn-node-${n}-${t}`;return t++,r["data-navigator-id"]=b,b},a=r=>{let n=o[r],b=n.index,p=n.level,j=n.parent,O=[],K=j.items[b-1];if(K){let g=d(K,p);if(o[g]){let E=`${g}-${n.id}`;O.push(E),u[E]||(u[E]={source:g,target:n.id,navigationRules:["left","right"]})}}let I=j.items[b+1];if(I){let g=d(I,p);if(o[g]){let E=`${n.id}-${g}`;O.push(E),u[E]||(u[E]={source:n.id,target:g,navigationRules:["left","right"]})}}if(p==="group"&&j.items[b].items){let E=(j.items[b].items[0].mark.items[0].items||j.items[b].items)[0],D=d(E,"item");if(o[D]){let _=`${n.id}-${D}`;O.push(_),u[_]||(u[_]={source:n.id,target:D,navigationRules:["parent","child"]})}}else if(p==="item"){let g=d(j,"group");if(o[g]){let E=`${g}-${n.id}`;O.push(E),u[E]||(u[E]={source:g,target:n.id,navigationRules:["parent","child"]})}}return e.exitFunction&&(O.push("any-exit"),u["any-exit"]||(u["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),O.push("any-undo"),u["any-undo"]||(u["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),O},m=(r,n,b,p,j)=>{let O=d(r,n),K="render-"+O,I=b||[0,0];o[O]={},o[O].d={},o[O].id=O,o[O].renderId=K,o[O].index=p,o[O].level=n,o[O].parent=j,h[K]={},h[K].renderId=K,h[K].spatialProperties={},h[K].spatialProperties.x=r.bounds.x1+I[0],h[K].spatialProperties.y=r.bounds.y1+I[1],h[K].spatialProperties.width=r.bounds.x2-r.bounds.x1,h[K].spatialProperties.height=r.bounds.y2-r.bounds.y1,h[K].cssClass="dn-vega-lite-node",r.datum&&Object.keys(r.datum).forEach(g=>{let E=r.datum[g];i(g,E,r.datum,n,e.vegaLiteSpec)&&(o[O].d[e.keyRenamingHash&&e.keyRenamingHash[g]?e.keyRenamingHash[g]:g]=E)}),h[K].semantics={},h[K].semantics.label=e.nodeDescriber?e.nodeDescriber(o[O].d,r,n):T(o[O].d)},c=0;return v.items.forEach(r=>{if(s(r,c,e.vegaLiteSpec)){m(r,"group",l,c,v);let n=0,b=r.items[0].mark.items[0].items?r.items[0].mark.items[0]:r;b.items.forEach(p=>{f(p,n,r,e.vegaLiteSpec)&&m(p,"item",l,n,b),n++})}c++}),Object.keys(o).forEach(r=>{o[r].edges=a(r)}),{nodes:o,edges:u,elementData:h,navigationRules:y}},V=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++})},q=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},A=(e,y)=>{let o={};if(e.dimensions?.parentOptions?.addLevel0){let t=e.dimensions.parentOptions.addLevel0;y[t.id]={...t,dimensionLevel:0}}let u=[...w],h=(t,s)=>{let f=s.numericalExtents[0],i=s.numericalExtents[1];s.numericalExtents[0]=f<t?f:t,s.numericalExtents[1]=i>t?i:t};return e.data.forEach(t=>{let s=e.dimensions.values||[],f=0;s.forEach(i=>{if(!i.dimensionKey){console.error(`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(i)}.`);return}if(i.dimensionKey in t){let l=t[i.dimensionKey],v=typeof i.operations?.filterFunction=="function"?i.operations.filterFunction(t,i):!0;if(l!==void 0&&v){if(i.type||(i.type=typeof l=="bigint"||typeof l=="number"?"numerical":"categorical"),!o[i.dimensionKey]){let c=typeof i.nodeId=="function"?i.nodeId(i,e.data):i.nodeId||F(i.dimensionKey),R=typeof i.renderId=="function"?i.renderId(i,e.data):i.renderId||c;o[i.dimensionKey]={dimensionKey:i.dimensionKey,nodeId:c,divisions:{},numericalExtents:[1/0,-1/0],type:i.type,operations:{compressSparseDivisions:i.operations?.compressSparseDivisions||!1,sortFunction:i.operations?.sortFunction||void 0},behavior:i.behavior||{extents:"circular"},navigationRules:i.navigationRules||{sibling_sibling:u.length?[...u.shift()]:["previous_"+i.dimensionKey,"next_"+i.dimensionKey],parent_child:["parent_"+i.dimensionKey,"child"]}},y[c]={id:c,renderId:R,derivedNode:i.dimensionKey,edges:[],dimensionLevel:1,data:o[i.dimensionKey],renderingStrategy:i.renderingStrategy||"singleSquare"}}let d=o[i.dimensionKey],a=null;if(i.type==="categorical"){let c=typeof i.divisionOptions?.divisionNodeIds=="function"?i.divisionOptions.divisionNodeIds(i.dimensionKey,l,f):F(d.nodeId+"_"+l);if(a=d.divisions[c],!a){a=d.divisions[c]={id:c,sortFunction:i.divisionOptions?.sortFunction||void 0,values:{}};let R=typeof i.divisionOptions?.divisionRenderIds=="function"?i.divisionOptions.divisionRenderIds(i.dimensionKey,l,f):c;y[c]={id:c,renderId:R,derivedNode:i.dimensionKey,edges:[],dimensionLevel:2,data:{...a},renderingStrategy:i.divisionOptions?.renderingStrategy||"singleSquare"},y[c].data[i.dimensionKey]=l}}else{a=d.divisions[d.nodeId],a||(a=d.divisions[d.nodeId]={id:d.nodeId,sortFunction:i.divisionOptions?.sortFunction||void 0,values:{}}),i.operations||(i.operations={});let c=i.operations.createNumericalSubdivisions;d.subdivisions=typeof c=="number"&&c<1?1:c||1,c!==1&&(d.divisionOptions||(d.divisionOptions=i.divisionOptions),h(l,d))}let m=typeof e.idKey=="function"?e.idKey(t):e.idKey;a.values[t[m]]=t}}f++})}),Object.keys(o).forEach(t=>{let s=o[t],f=s.divisions;if(s.type==="numerical"){f[s.nodeId].values=Object.fromEntries(Object.entries(f[s.nodeId].values).sort((v,d)=>typeof s.operations?.sortFunction=="function"?s.operations.sortFunction(v[1],d[1],s):v[1][t]-d[1][t]));let l=f[s.nodeId].values;if(s.numericalExtents[0]!==1/0&&s.subdivisions!==1){let v=Object.keys(l),d=typeof s.subdivisions=="function"?s.subdivisions(t,l):s.subdivisions,m=(s.numericalExtents[1]-s.numericalExtents[0])/d,c=s.numericalExtents[0]+m,R=0,r=0;for(c=s.numericalExtents[0]+m;c<=s.numericalExtents[1];c+=m){let n=typeof s.divisionOptions?.divisionNodeIds=="function"?s.divisionOptions.divisionNodeIds(t,c,c):s.nodeId+"_"+c;s.divisions[n]={id:n,sortFunction:s.divisionOptions?.sortFunction||void 0,values:{}};let b=typeof s.divisionOptions?.divisionRenderIds=="function"?s.divisionOptions.divisionRenderIds(t,c,c):n;y[n]={id:n,renderId:b,derivedNode:t,edges:[],data:s.divisions[n],dimensionLevel:2,renderingStrategy:s.divisionOptions?.renderingStrategy||"singleSquare"};let p=!1;for(;!p&&r<v.length;){let j=l[v[r]];j[t]<=c?s.divisions[n].values[j.id]=j:(c+=m,p=!0),r++}R++}delete f[t]}}else typeof s.operations?.sortFunction=="function"&&(s.divisions=Object.fromEntries(Object.entries(f).sort((l,v)=>s.operations.sortFunction(l[1],v[1],s))));Object.keys(s.divisions).forEach(l=>{let v=s.divisions[l];typeof v.sortFunction=="function"&&(v.values=Object.fromEntries(Object.entries(v.values).sort((d,a)=>v.sortFunction(d[1],a[1],v))))})}),Object.keys(o).forEach(t=>{let s=o[t];if(s.operations.compressSparseDivisions){let f=Object.keys(s.divisions),i={},l=!0;if(f.forEach(v=>{let d=s.divisions[v],a=Object.keys(d.values);a.length<=1?a.forEach(m=>{i[m]={...d.values[m]}}):l=!1}),l){let v={id:s.nodeId,values:i};f.forEach(d=>{delete y[d]}),s.divisions={},s.divisions[s.nodeId]=v}}}),e.dimensions.adjustDimensions&&(o=e.dimensions.adjustDimensions(o)),o},H=(e,y,o)=>{let u={},h=(s,f)=>{y[s].edges.indexOf(f)===-1&&y[s].edges.push(f)},t=(s,f,i,l)=>{let v=`${s}-${f}`,d=e.useDirectedEdges?`${f}-${v}`:v,a=!l||l==="source",m=!l||l==="target",c=R=>{u[R]?u[R].navigationRules.push(...i||[]):u[R]={source:s,target:f,navigationRules:i?[...i]:[]}};c(v),e.useDirectedEdges&&m&&c(d),a&&h(s,v),m&&h(f,d)};if(o&&Object.keys(o).length){let s=Object.keys(o),f=e.dimensions?.parentOptions?.level1Options?.order,i=f||s,l=0,v=e.dimensions?.parentOptions||{},d=v.level1Options?.behavior?.extents||"terminal",a=v.addLevel0,m=a?v.level1Options?.navigationRules?.parent_child||["parent","child"]:[],c=v.level1Options?.navigationRules?.sibling_sibling||["left","right"],R=typeof i[0]=="string"?f?y[i[0]]:y[o[i[0]].nodeId]:i[0];a&&t(a.id,R.id,m,"source"),i.forEach(r=>{let n=typeof r=="string"?f?y[r]:y[o[r].nodeId]:r;if(n===r&&!y[n.id]&&(y[n.id]=n),a&&(e.useDirectedEdges?t(n.id,a.id,m,"source"):t(a.id,n.id,m,"target")),l===i.length-1&&d==="circular")t(n.id,R.id,c);else if(l===i.length-1&&d==="bridgedCustom")t(n.id,v.level1Options.behavior.customBridgePost,c);else if(l<i.length-1){let b=typeof i[l+1]=="string"?f?y[i[l+1]]:y[o[i[l+1]].nodeId]:i[l+1];t(n.id,b.id,c)}!l&&d==="bridgedCustom"&&t(v.level1Options.behavior.customBridgePost,n.id,c),l++}),s.forEach(r=>{let n=o[r],b=n.behavior?.extents||"circular";n.divisions||console.error(`Parsing dimensions. The dimension using the key ${r} is missing the divisions property. dimension.divisions should be supplied. ${JSON.stringify(n)}.`);let p=Object.keys(n.divisions),j=n.divisions[p[0]];if(p.length!==1)t(n.nodeId,j.id,n.navigationRules.parent_child,"source");else{let K=Object.keys(j.values),I=typeof e.idKey=="function"?e.idKey(j.values[K[0]]):e.idKey;t(n.nodeId,j.values[K[0]][I],n.navigationRules.parent_child,"source")}let O=0;p.forEach(K=>{let I=n.divisions[K];O===p.length-1&&(b==="circular"||b==="bridgedCousins"||b==="bridgedCustom")?t(I.id,n.divisions[p[0]].id,n.navigationRules.sibling_sibling):O<p.length-1&&t(I.id,n.divisions[p[O+1]].id,n.navigationRules.sibling_sibling);let g=Object.keys(I.values);e.useDirectedEdges?t(I.id,n.nodeId,n.navigationRules.parent_child,"source"):t(n.nodeId,I.id,n.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],n.navigationRules.parent_child,"source");let D=0;g.length>1&&g.forEach(_=>{let x=I.values[_],S=typeof e.idKey=="function"?e.idKey(x):e.idKey,L=p.length!==1?I.id:n.nodeId;if(e.useDirectedEdges?t(x[S],L,n.navigationRules.parent_child,"source"):t(L,x[S],n.navigationRules.parent_child,"target"),D===g.length-1&&b==="circular"){let N=typeof e.idKey=="function"?e.idKey(I.values[g[0]]):e.idKey;t(x[S],I.values[g[0]][N],n.navigationRules.sibling_sibling)}else if(D===g.length-1&&b==="bridgedCousins")if(O!==p.length-1){let N=typeof e.idKey=="function"?e.idKey(n.divisions[p[O+1]].values[g[0]]):e.idKey;t(x[S],n.divisions[p[O+1]].values[g[0]][N],n.navigationRules.sibling_sibling)}else{let N=typeof e.idKey=="function"?e.idKey(n.divisions[p[0]].values[g[0]]):e.idKey;t(x[S],n.divisions[p[0]].values[g[0]][N],n.navigationRules.sibling_sibling)}else if(D===g.length-1&&b==="bridgedCustom")t(x[S],n.behavior.customBridgePost,n.navigationRules.sibling_sibling);else if(D<g.length-1){let N=typeof e.idKey=="function"?e.idKey(I.values[g[D+1]]):e.idKey;t(x[S],I.values[g[D+1]][N],n.navigationRules.sibling_sibling)}if(!D&&b==="bridgedCousins")if(O!==0){let N=typeof e.idKey=="function"?e.idKey(n.divisions[p[O-1]].values[g[g.length-1]]):e.idKey;t(n.divisions[p[O-1]].values[g[g.length-1]][N],x[S],n.navigationRules.sibling_sibling)}else{let N=typeof e.idKey=="function"?e.idKey(n.divisions[p[p.length-1]].values[g[g.length-1]]):e.idKey;t(n.divisions[p[p.length-1]].values[g[g.length-1]][N],x[S],n.navigationRules.sibling_sibling)}else!D&&b==="bridgedCustom"&&t(n.behavior.customBridgePrevious,x[S],n.navigationRules.sibling_sibling);D++}),O++})})}return Object.keys(y).forEach(s=>{let f=y[s];e.genericEdges?.length&&e.genericEdges.forEach(i=>{u[i.edgeId]||(u[i.edgeId]=i.edge),(!i.conditional||i.conditional&&i.conditional(f,i))&&f.edges.push(i.edgeId)})}),u},J=(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={},f={},i=[...k],l=[...P],v=(d,a)=>{let m=d&&a,c=!1,R=!1;if((t[d]||s[d])&&(s[d]={...t[d]},c=!0),a&&(t[a]||s[a])&&(s[a]={...t[a]},R=!0),m&&!c&&!R){i.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 r=[...i.shift()];l.splice(l.indexOf(r[0]),1),l.splice(l.indexOf(r[1]),1),s[d]={direction:e.useDirectedEdges?"target":"source",key:r[0]},s[a]={direction:"target",key:r[1]}}else{if(!s[d]&&l.length){let r=l.shift(),n=[];i.forEach(b=>{r!==b[0]&&r!==b[1]&&n.push(b)}),i=n,s[d]={direction:e.useDirectedEdges?"target":"source",key:r}}if(a&&!s[a]&&l.length){let r=l.shift(),n=[];i.forEach(b=>{r!==b[0]&&r!==b[1]&&n.push(b)}),i=n,s[a]={direction:"target",key:r}}l.length||(s[d]||(f[d]=d),a&&!s[a]&&(f[a]=a))}};if(Object.keys(C).forEach(d=>{let a={...C[d]};e.useDirectedEdges&&(a.direction="target"),t[d]=a}),h.length){if(e.dimensions?.parentOptions?.addLevel0){let d=e.dimensions.parentOptions.level1Options?.navigationRules?.parent_child||["parent","child"];v(d[0],d[1])}h.forEach(d=>{let a=o[d].navigationRules.parent_child,m=o[d].navigationRules.sibling_sibling;v(a[0],a[1]),v(m[0],m[1])})}if(Object.keys(y).forEach(d=>{y[d].navigationRules.forEach(a=>{s[a]||v(a)})}),Object.keys(f).length){let d={};Object.keys(s).forEach(m=>{d[s[m].key]=s[m].key}),Object.keys(t).forEach(m=>{!d[t[m].key]&&!$[t[m].key]&&l.push(t[m].key)});let a={...f};f={},Object.keys(a).forEach(m=>{v(m)}),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(", ")}.`)}u=s}return u},U=e=>{e.addIds&&V(e);let y=q(e),o=A(e,y),u=H(e,y,o),h=J(e,u,o);return{nodes:y,edges:u,dimensions:o,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};
|