data-navigator 2.3.0 → 2.4.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/index.cjs +99 -34
- package/dist/index.d.cts +265 -0
- package/dist/index.d.ts +265 -0
- package/dist/index.js +99 -34
- package/dist/structure.cjs +1 -1
- package/dist/structure.js +1 -1
- package/dist/text-chat.cjs +12 -12
- package/dist/text-chat.js +13 -13
- package/package.json +5 -5
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
type StructureOptions = {
|
|
2
|
+
data: GenericDataset;
|
|
3
|
+
idKey: DynamicNodeIdKey;
|
|
4
|
+
renderIdKey?: DynamicRenderIdKey;
|
|
5
|
+
dimensions?: DimensionOptions;
|
|
6
|
+
genericEdges?: EdgeOptions;
|
|
7
|
+
useDirectedEdges?: boolean;
|
|
8
|
+
dataType?: DataType;
|
|
9
|
+
addIds?: boolean;
|
|
10
|
+
keysForIdGeneration?: KeyList;
|
|
11
|
+
navigationRules?: NavigationRules;
|
|
12
|
+
};
|
|
13
|
+
type InputOptions = {
|
|
14
|
+
structure: Structure;
|
|
15
|
+
navigationRules: NavigationRules;
|
|
16
|
+
entryPoint?: NodeId;
|
|
17
|
+
exitPoint?: RenderId;
|
|
18
|
+
};
|
|
19
|
+
type RenderingOptions = {
|
|
20
|
+
elementData: ElementData | Nodes;
|
|
21
|
+
suffixId: string;
|
|
22
|
+
root: RootObject;
|
|
23
|
+
defaults?: RenderObject;
|
|
24
|
+
entryButton?: EntryObject;
|
|
25
|
+
exitElement?: ExitObject;
|
|
26
|
+
};
|
|
27
|
+
type DimensionOptions = {
|
|
28
|
+
values: DimensionList;
|
|
29
|
+
parentOptions?: {
|
|
30
|
+
level1Options?: {
|
|
31
|
+
order: AddOrReferenceNodeList;
|
|
32
|
+
behavior?: Level1Behavior;
|
|
33
|
+
navigationRules?: DimensionNavigationRules;
|
|
34
|
+
};
|
|
35
|
+
addLevel0?: NodeObject;
|
|
36
|
+
};
|
|
37
|
+
adjustDimensions?: AdjustingFunction;
|
|
38
|
+
};
|
|
39
|
+
type Structure = {
|
|
40
|
+
nodes: Nodes;
|
|
41
|
+
edges: Edges;
|
|
42
|
+
dimensions?: Dimensions;
|
|
43
|
+
navigationRules?: NavigationRules;
|
|
44
|
+
elementData?: ElementData;
|
|
45
|
+
};
|
|
46
|
+
type Nodes = Record<NodeId, NodeObject>;
|
|
47
|
+
type Edges = Record<EdgeId, EdgeObject>;
|
|
48
|
+
type Dimensions = Record<DimensionKey, DimensionObject>;
|
|
49
|
+
type NavigationRules = Record<NavId, NavObject>;
|
|
50
|
+
type ElementData = Record<RenderId, RenderObject>;
|
|
51
|
+
type DimensionDivisions = Record<NodeId, DivisionObject>;
|
|
52
|
+
type AddOrReferenceNodeList = Array<NodeToAddOrReference>;
|
|
53
|
+
type EdgeList = Array<EdgeId>;
|
|
54
|
+
type GenericDataset = Array<DatumObject>;
|
|
55
|
+
type NavigationList = Array<NavId>;
|
|
56
|
+
type DimensionNavigationPair = [NavId, NavId];
|
|
57
|
+
type NumericalExtentsPair = [number, number];
|
|
58
|
+
type DimensionList = Array<DimensionDatum>;
|
|
59
|
+
type EdgeOptions = Array<EdgeDatum>;
|
|
60
|
+
type KeyList = Array<string>;
|
|
61
|
+
type Semantics = ((RenderObject?: any, DatumObject?: any) => SemanticsObject) | SemanticsObject;
|
|
62
|
+
type SpatialProperties = ((RenderObject?: any, DatumObject?: any) => SpatialObject) | SpatialObject;
|
|
63
|
+
type Attributes = ((RenderObject?: any, DatumObject?: any) => AttributesObject) | AttributesObject;
|
|
64
|
+
type NodeObject = {
|
|
65
|
+
id: NodeId;
|
|
66
|
+
edges: EdgeList;
|
|
67
|
+
renderId?: RenderId;
|
|
68
|
+
renderingStrategy?: RenderingStrategy;
|
|
69
|
+
derivedNode?: DerivedNode;
|
|
70
|
+
dimensionLevel?: DimensionLevel;
|
|
71
|
+
[key: string | number]: any;
|
|
72
|
+
};
|
|
73
|
+
type EdgeObject = {
|
|
74
|
+
source: ((d: DatumObject, currentFocus: NodeId) => NodeId) | NodeId;
|
|
75
|
+
target: ((d: DatumObject, currentFocus: NodeId) => NodeId) | NodeId;
|
|
76
|
+
navigationRules: NavigationList;
|
|
77
|
+
edgeId?: EdgeId;
|
|
78
|
+
};
|
|
79
|
+
type EdgeDatum = {
|
|
80
|
+
edgeId: EdgeId;
|
|
81
|
+
edge: EdgeObject;
|
|
82
|
+
conditional?: ConditionalFunction;
|
|
83
|
+
};
|
|
84
|
+
type DimensionObject = {
|
|
85
|
+
nodeId: NodeId;
|
|
86
|
+
dimensionKey: DimensionKey;
|
|
87
|
+
divisions: DimensionDivisions;
|
|
88
|
+
operations: {
|
|
89
|
+
compressSparseDivisions: boolean;
|
|
90
|
+
sortFunction?: SortingFunction;
|
|
91
|
+
};
|
|
92
|
+
behavior?: DimensionBehavior;
|
|
93
|
+
navigationRules?: DimensionNavigationRules;
|
|
94
|
+
type?: DimensionType;
|
|
95
|
+
numericalExtents?: NumericalExtentsPair;
|
|
96
|
+
subdivisions?: NumericallySubdivide;
|
|
97
|
+
divisionOptions?: DivisionOptions;
|
|
98
|
+
};
|
|
99
|
+
type DimensionDatum = {
|
|
100
|
+
dimensionKey: DimensionKey;
|
|
101
|
+
behavior?: DimensionBehavior;
|
|
102
|
+
navigationRules?: DimensionNavigationRules;
|
|
103
|
+
type?: DimensionType;
|
|
104
|
+
operations?: DimensionOperations;
|
|
105
|
+
nodeId?: DynamicDimensionId;
|
|
106
|
+
renderId?: DynamicDimensionRenderId;
|
|
107
|
+
renderingStrategy?: RenderingStrategy;
|
|
108
|
+
divisionOptions?: DivisionOptions;
|
|
109
|
+
};
|
|
110
|
+
type DimensionNavigationRules = {
|
|
111
|
+
sibling_sibling: DimensionNavigationPair;
|
|
112
|
+
parent_child: DimensionNavigationPair;
|
|
113
|
+
};
|
|
114
|
+
type DivisionOptions = {
|
|
115
|
+
sortFunction?: SortingFunction;
|
|
116
|
+
divisionNodeIds?: (dimensionKey: DimensionKey, keyValue: any, i: number) => string;
|
|
117
|
+
divisionRenderIds?: (dimensionKey: DimensionKey, keyValue: any, i: number) => string;
|
|
118
|
+
renderingStrategy?: RenderingStrategy;
|
|
119
|
+
};
|
|
120
|
+
type DimensionOperations = {
|
|
121
|
+
filterFunction?: FilteringFunction;
|
|
122
|
+
sortFunction?: SortingFunction;
|
|
123
|
+
createNumericalSubdivisions?: NumericallySubdivide;
|
|
124
|
+
compressSparseDivisions?: boolean;
|
|
125
|
+
};
|
|
126
|
+
type DivisionObject = {
|
|
127
|
+
id: NodeId;
|
|
128
|
+
values: Nodes;
|
|
129
|
+
sortFunction?: SortingFunction;
|
|
130
|
+
numericalExtents?: NumericalExtentsPair;
|
|
131
|
+
};
|
|
132
|
+
type NavObject = {
|
|
133
|
+
direction: Direction;
|
|
134
|
+
key?: string;
|
|
135
|
+
};
|
|
136
|
+
type RenderObject = {
|
|
137
|
+
cssClass?: DynamicString;
|
|
138
|
+
spatialProperties?: SpatialProperties;
|
|
139
|
+
semantics?: Semantics;
|
|
140
|
+
parentSemantics?: Semantics;
|
|
141
|
+
existingElement?: ExistingElement;
|
|
142
|
+
showText?: boolean;
|
|
143
|
+
};
|
|
144
|
+
type RootObject = {
|
|
145
|
+
id: string;
|
|
146
|
+
cssClass?: string;
|
|
147
|
+
description?: string;
|
|
148
|
+
width?: string | number;
|
|
149
|
+
height?: string | number;
|
|
150
|
+
};
|
|
151
|
+
type EntryObject = {
|
|
152
|
+
include: boolean;
|
|
153
|
+
callbacks?: EntryCallbacks;
|
|
154
|
+
};
|
|
155
|
+
type ExitObject = {
|
|
156
|
+
include: boolean;
|
|
157
|
+
callbacks?: ExitCallbacks;
|
|
158
|
+
};
|
|
159
|
+
type SemanticsObject = {
|
|
160
|
+
label?: DynamicString;
|
|
161
|
+
elementType?: DynamicString;
|
|
162
|
+
role?: DynamicString;
|
|
163
|
+
attributes?: Attributes;
|
|
164
|
+
};
|
|
165
|
+
type SpatialObject = {
|
|
166
|
+
x?: DynamicNumber;
|
|
167
|
+
y?: DynamicNumber;
|
|
168
|
+
width?: DynamicNumber;
|
|
169
|
+
height?: DynamicNumber;
|
|
170
|
+
path?: DynamicString;
|
|
171
|
+
};
|
|
172
|
+
type DimensionBehavior = {
|
|
173
|
+
extents: ExtentType;
|
|
174
|
+
customBridgePrevious?: NodeId;
|
|
175
|
+
customBridgePost?: NodeId;
|
|
176
|
+
childmostNavigation?: ChildmostNavigationStrategy;
|
|
177
|
+
childmostMatching?: ChildmostMatchingStrategy;
|
|
178
|
+
};
|
|
179
|
+
type Level1Behavior = {
|
|
180
|
+
extents: Level0ExtentType;
|
|
181
|
+
customBridgePrevious?: NodeId;
|
|
182
|
+
customBridgePost?: NodeId;
|
|
183
|
+
};
|
|
184
|
+
type DescriptionOptions = {
|
|
185
|
+
omitKeyNames?: boolean;
|
|
186
|
+
semanticLabel?: string;
|
|
187
|
+
};
|
|
188
|
+
type ExistingElement = {
|
|
189
|
+
useForSpatialProperties: boolean;
|
|
190
|
+
spatialProperties?: SpatialProperties;
|
|
191
|
+
};
|
|
192
|
+
type EntryCallbacks = {
|
|
193
|
+
focus?: Function;
|
|
194
|
+
click?: Function;
|
|
195
|
+
};
|
|
196
|
+
type ExitCallbacks = {
|
|
197
|
+
focus?: Function;
|
|
198
|
+
blur?: Function;
|
|
199
|
+
};
|
|
200
|
+
type DatumObject = {
|
|
201
|
+
[key: string | number]: any;
|
|
202
|
+
};
|
|
203
|
+
type AttributesObject = {
|
|
204
|
+
[key: string]: string;
|
|
205
|
+
};
|
|
206
|
+
type DynamicNumber = ((r?: RenderObject, d?: DatumObject) => number) | number;
|
|
207
|
+
type DynamicString = ((r?: RenderObject, d?: DatumObject) => string) | string;
|
|
208
|
+
type DynamicNodeId = ((d?: DatumObject, dim?: DimensionDatum) => NodeId) | NodeId;
|
|
209
|
+
type DynamicRenderId = ((d?: DatumObject) => RenderId) | RenderId;
|
|
210
|
+
type DynamicNodeIdKey = ((d?: DatumObject) => string) | string;
|
|
211
|
+
type DynamicRenderIdKey = ((d?: DatumObject) => string) | string;
|
|
212
|
+
type DynamicDimensionId = ((d?: DimensionDatum, a?: GenericDataset) => NodeId) | NodeId;
|
|
213
|
+
type DynamicDimensionRenderId = ((d?: DimensionDatum, a?: GenericDataset) => RenderId) | RenderId;
|
|
214
|
+
type NumericallySubdivide = ((d?: DimensionKey, n?: Nodes) => number) | number;
|
|
215
|
+
type ChildmostMatchingStrategy = (index?: number, currentDivisionChild?: DatumObject, currentDivision?: DivisionObject, nextDivision?: DivisionObject) => DatumObject | undefined;
|
|
216
|
+
type AdjustingFunction = (d: Dimensions) => Dimensions;
|
|
217
|
+
type SortingFunction = (a: DatumObject, b: DatumObject, c?: any) => number;
|
|
218
|
+
type FilteringFunction = (a: DatumObject, b?: any) => boolean;
|
|
219
|
+
type ConditionalFunction = (n: NodeObject, d: EdgeDatum) => boolean;
|
|
220
|
+
type NodeId = string;
|
|
221
|
+
type EdgeId = string;
|
|
222
|
+
type RenderId = string;
|
|
223
|
+
type NavId = string;
|
|
224
|
+
type DimensionId = string;
|
|
225
|
+
type DimensionKey = string;
|
|
226
|
+
type NodeToAddOrReference = NodeObject | NodeId;
|
|
227
|
+
type Direction = 'target' | 'source';
|
|
228
|
+
type RenderingStrategy = 'outlineEach' | 'convexHull' | 'singleSquare' | 'custom';
|
|
229
|
+
type DimensionType = 'numerical' | 'categorical';
|
|
230
|
+
type ExtentType = 'circular' | 'terminal' | 'bridgedCousins' | 'bridgedCustom';
|
|
231
|
+
type ChildmostNavigationStrategy = 'within' | 'across';
|
|
232
|
+
type Level0ExtentType = 'circular' | 'terminal' | 'bridgedCustom';
|
|
233
|
+
type DataType = 'vega-lite' | 'vl' | 'Vega-Lite' | 'generic' | 'default';
|
|
234
|
+
type DimensionLevel = 0 | 1 | 2 | 3;
|
|
235
|
+
type DerivedNode = string;
|
|
236
|
+
type LLMMessage = {
|
|
237
|
+
role: 'user' | 'assistant' | 'system';
|
|
238
|
+
content: string;
|
|
239
|
+
};
|
|
240
|
+
type TextChatOptions = {
|
|
241
|
+
structure: Structure;
|
|
242
|
+
container: string | HTMLElement;
|
|
243
|
+
entryPoint?: NodeId;
|
|
244
|
+
describeNode?: (node: NodeObject) => string;
|
|
245
|
+
commandLabels?: Record<string, string>;
|
|
246
|
+
onNavigate?: (node: NodeObject) => void;
|
|
247
|
+
onExit?: () => void;
|
|
248
|
+
onClick?: (node: NodeObject) => void;
|
|
249
|
+
onHover?: (node: NodeObject) => void;
|
|
250
|
+
llm?: (messages: LLMMessage[]) => Promise<string | null>;
|
|
251
|
+
data?: Record<string, unknown>[];
|
|
252
|
+
};
|
|
253
|
+
type TextChatInstance = {
|
|
254
|
+
destroy: () => void;
|
|
255
|
+
getCurrentNode: () => NodeObject | null;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
declare const _default: {
|
|
259
|
+
structure: (options: StructureOptions) => Structure;
|
|
260
|
+
input: (options: InputOptions) => any;
|
|
261
|
+
rendering: (options: RenderingOptions) => any;
|
|
262
|
+
textChat: (options: TextChatOptions) => TextChatInstance;
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
export { type AddOrReferenceNodeList, type AdjustingFunction, type Attributes, type AttributesObject, type ChildmostMatchingStrategy, type ChildmostNavigationStrategy, type ConditionalFunction, type DataType, type DatumObject, type DerivedNode, type DescriptionOptions, type DimensionBehavior, type DimensionDatum, type DimensionDivisions, type DimensionId, type DimensionKey, type DimensionLevel, type DimensionList, type DimensionNavigationPair, type DimensionNavigationRules, type DimensionObject, type DimensionOperations, type DimensionOptions, type DimensionType, type Dimensions, type Direction, type DivisionObject, type DivisionOptions, type DynamicDimensionId, type DynamicDimensionRenderId, type DynamicNodeId, type DynamicNodeIdKey, type DynamicNumber, type DynamicRenderId, type DynamicRenderIdKey, type DynamicString, type EdgeDatum, type EdgeId, type EdgeList, type EdgeObject, type EdgeOptions, type Edges, type ElementData, type EntryCallbacks, type EntryObject, type ExistingElement, type ExitCallbacks, type ExitObject, type ExtentType, type FilteringFunction, type GenericDataset, type InputOptions, type KeyList, type LLMMessage, type Level0ExtentType, type Level1Behavior, type NavId, type NavObject, type NavigationList, type NavigationRules, type NodeId, type NodeObject, type NodeToAddOrReference, type Nodes, type NumericalExtentsPair, type NumericallySubdivide, type RenderId, type RenderObject, type RenderingOptions, type RenderingStrategy, type RootObject, type Semantics, type SemanticsObject, type SortingFunction, type SpatialObject, type SpatialProperties, type Structure, type StructureOptions, type TextChatInstance, type TextChatOptions, _default as default };
|
package/dist/index.js
CHANGED
|
@@ -439,7 +439,7 @@ var buildNodes = (options) => {
|
|
|
439
439
|
return nodes;
|
|
440
440
|
};
|
|
441
441
|
var scaffoldDimensions = (options, nodes) => {
|
|
442
|
-
var _a, _b;
|
|
442
|
+
var _a, _b, _c;
|
|
443
443
|
let dimensions = {};
|
|
444
444
|
if ((_b = (_a = options.dimensions) == null ? void 0 : _a.parentOptions) == null ? void 0 : _b.addLevel0) {
|
|
445
445
|
let level0 = options.dimensions.parentOptions.addLevel0;
|
|
@@ -453,10 +453,11 @@ var scaffoldDimensions = (options, nodes) => {
|
|
|
453
453
|
dim.numericalExtents[1] = max > val ? max : val;
|
|
454
454
|
};
|
|
455
455
|
options.data.forEach((d) => {
|
|
456
|
-
|
|
456
|
+
var _a2;
|
|
457
|
+
let ods = ((_a2 = options.dimensions) == null ? void 0 : _a2.values) || [];
|
|
457
458
|
let i = 0;
|
|
458
459
|
ods.forEach((dim) => {
|
|
459
|
-
var
|
|
460
|
+
var _a3, _b2, _c2, _d, _e, _f, _g, _h;
|
|
460
461
|
if (!dim.dimensionKey) {
|
|
461
462
|
console.error(
|
|
462
463
|
`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(
|
|
@@ -467,7 +468,7 @@ var scaffoldDimensions = (options, nodes) => {
|
|
|
467
468
|
}
|
|
468
469
|
if (dim.dimensionKey in d) {
|
|
469
470
|
let value = d[dim.dimensionKey];
|
|
470
|
-
let keepValue = typeof ((
|
|
471
|
+
let keepValue = typeof ((_a3 = dim.operations) == null ? void 0 : _a3.filterFunction) === "function" ? dim.operations.filterFunction(d, dim) : true;
|
|
471
472
|
if (value !== void 0 && keepValue) {
|
|
472
473
|
if (!dim.type) {
|
|
473
474
|
dim.type = typeof value === "bigint" || typeof value === "number" ? "numerical" : "categorical";
|
|
@@ -483,7 +484,7 @@ var scaffoldDimensions = (options, nodes) => {
|
|
|
483
484
|
type: dim.type,
|
|
484
485
|
operations: {
|
|
485
486
|
compressSparseDivisions: ((_b2 = dim.operations) == null ? void 0 : _b2.compressSparseDivisions) || false,
|
|
486
|
-
sortFunction: ((
|
|
487
|
+
sortFunction: ((_c2 = dim.operations) == null ? void 0 : _c2.sortFunction) || void 0
|
|
487
488
|
},
|
|
488
489
|
behavior: dim.behavior || {
|
|
489
490
|
extents: "circular"
|
|
@@ -557,7 +558,7 @@ var scaffoldDimensions = (options, nodes) => {
|
|
|
557
558
|
});
|
|
558
559
|
});
|
|
559
560
|
Object.keys(dimensions).forEach((s) => {
|
|
560
|
-
var _a2, _b2,
|
|
561
|
+
var _a2, _b2, _c2, _d, _e;
|
|
561
562
|
let dimension = dimensions[s];
|
|
562
563
|
let divisions = dimension.divisions;
|
|
563
564
|
if (dimension.type === "numerical") {
|
|
@@ -576,14 +577,18 @@ var scaffoldDimensions = (options, nodes) => {
|
|
|
576
577
|
let i = dimension.numericalExtents[0] + interval;
|
|
577
578
|
let divisionCount = 0;
|
|
578
579
|
let index = 0;
|
|
580
|
+
let lastDivisionId = null;
|
|
581
|
+
let prevBound = dimension.numericalExtents[0];
|
|
579
582
|
for (i = dimension.numericalExtents[0] + interval; i <= dimension.numericalExtents[1]; i += interval) {
|
|
580
|
-
let divisionId = typeof ((_a2 = dimension.divisionOptions) == null ? void 0 : _a2.divisionNodeIds) === "function" ? dimension.divisionOptions.divisionNodeIds(s, i, i) : dimension.nodeId + "_" + i;
|
|
583
|
+
let divisionId = typeof ((_a2 = dimension.divisionOptions) == null ? void 0 : _a2.divisionNodeIds) === "function" ? dimension.divisionOptions.divisionNodeIds(s, i, i) : createValidId(dimension.nodeId + "_" + i);
|
|
584
|
+
lastDivisionId = divisionId;
|
|
581
585
|
dimension.divisions[divisionId] = {
|
|
582
586
|
id: divisionId,
|
|
583
587
|
sortFunction: ((_b2 = dimension.divisionOptions) == null ? void 0 : _b2.sortFunction) || void 0,
|
|
584
|
-
values: {}
|
|
588
|
+
values: {},
|
|
589
|
+
numericalExtents: [prevBound, i]
|
|
585
590
|
};
|
|
586
|
-
let divisionRenderId = typeof ((
|
|
591
|
+
let divisionRenderId = typeof ((_c2 = dimension.divisionOptions) == null ? void 0 : _c2.divisionRenderIds) === "function" ? dimension.divisionOptions.divisionRenderIds(s, i, i) : divisionId;
|
|
587
592
|
nodes[divisionId] = {
|
|
588
593
|
id: divisionId,
|
|
589
594
|
renderId: divisionRenderId,
|
|
@@ -600,14 +605,21 @@ var scaffoldDimensions = (options, nodes) => {
|
|
|
600
605
|
let value = node[s];
|
|
601
606
|
if (value <= i) {
|
|
602
607
|
dimension.divisions[divisionId].values[node.id] = node;
|
|
608
|
+
index++;
|
|
603
609
|
} else {
|
|
604
|
-
i += interval;
|
|
605
610
|
limit = true;
|
|
606
611
|
}
|
|
607
|
-
index++;
|
|
608
612
|
}
|
|
613
|
+
prevBound = i;
|
|
609
614
|
divisionCount++;
|
|
610
615
|
}
|
|
616
|
+
if (lastDivisionId && index < valueKeys.length) {
|
|
617
|
+
while (index < valueKeys.length) {
|
|
618
|
+
let node = values[valueKeys[index]];
|
|
619
|
+
dimension.divisions[lastDivisionId].values[node.id] = node;
|
|
620
|
+
index++;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
611
623
|
delete divisions[s];
|
|
612
624
|
}
|
|
613
625
|
} else if (typeof ((_e = dimension.operations) == null ? void 0 : _e.sortFunction) === "function") {
|
|
@@ -659,7 +671,7 @@ var scaffoldDimensions = (options, nodes) => {
|
|
|
659
671
|
}
|
|
660
672
|
}
|
|
661
673
|
});
|
|
662
|
-
if (options.dimensions.adjustDimensions) {
|
|
674
|
+
if ((_c = options.dimensions) == null ? void 0 : _c.adjustDimensions) {
|
|
663
675
|
dimensions = options.dimensions.adjustDimensions(dimensions);
|
|
664
676
|
}
|
|
665
677
|
return dimensions;
|
|
@@ -796,13 +808,15 @@ var buildEdges = (options, nodes, dimensions) => {
|
|
|
796
808
|
} else {
|
|
797
809
|
createEdge(division.id, dimension.nodeId, dimension.navigationRules.parent_child, "source");
|
|
798
810
|
}
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
811
|
+
if (valueKeys.length > 0) {
|
|
812
|
+
const firstChildId = typeof options.idKey === "function" ? options.idKey(division.values[valueKeys[0]]) : options.idKey;
|
|
813
|
+
createEdge(
|
|
814
|
+
division.id,
|
|
815
|
+
division.values[valueKeys[0]][firstChildId],
|
|
816
|
+
dimension.navigationRules.parent_child,
|
|
817
|
+
"source"
|
|
818
|
+
);
|
|
819
|
+
}
|
|
806
820
|
let i = 0;
|
|
807
821
|
if (valueKeys.length >= 1) {
|
|
808
822
|
valueKeys.forEach((vk) => {
|
|
@@ -1438,22 +1452,31 @@ var getAllRuleNames = (structure) => {
|
|
|
1438
1452
|
return [];
|
|
1439
1453
|
return Object.keys(structure.navigationRules);
|
|
1440
1454
|
};
|
|
1441
|
-
var
|
|
1455
|
+
var damerauLevenshtein = (a, b) => {
|
|
1442
1456
|
const m = a.length;
|
|
1443
1457
|
const n = b.length;
|
|
1444
|
-
const dp = Array(n + 1);
|
|
1458
|
+
const dp = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));
|
|
1459
|
+
for (let i = 0; i <= m; i++)
|
|
1460
|
+
dp[i][0] = i;
|
|
1445
1461
|
for (let j = 0; j <= n; j++)
|
|
1446
|
-
dp[j] = j;
|
|
1462
|
+
dp[0][j] = j;
|
|
1447
1463
|
for (let i = 1; i <= m; i++) {
|
|
1448
|
-
let prev = dp[0];
|
|
1449
|
-
dp[0] = i;
|
|
1450
1464
|
for (let j = 1; j <= n; j++) {
|
|
1451
|
-
const
|
|
1452
|
-
dp[
|
|
1453
|
-
|
|
1465
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
1466
|
+
dp[i][j] = Math.min(
|
|
1467
|
+
dp[i - 1][j] + 1,
|
|
1468
|
+
// deletion
|
|
1469
|
+
dp[i][j - 1] + 1,
|
|
1470
|
+
// insertion
|
|
1471
|
+
dp[i - 1][j - 1] + cost
|
|
1472
|
+
// substitution
|
|
1473
|
+
);
|
|
1474
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
1475
|
+
dp[i][j] = Math.min(dp[i][j], dp[i - 2][j - 2] + cost);
|
|
1476
|
+
}
|
|
1454
1477
|
}
|
|
1455
1478
|
}
|
|
1456
|
-
return dp[n];
|
|
1479
|
+
return dp[m][n];
|
|
1457
1480
|
};
|
|
1458
1481
|
var maxTypoDistance = (len) => len <= 4 ? 1 : 2;
|
|
1459
1482
|
var fuzzyMatch = (input, candidates, labels = {}) => {
|
|
@@ -1487,7 +1510,7 @@ var fuzzyMatch = (input, candidates, labels = {}) => {
|
|
|
1487
1510
|
const typoMatches = [];
|
|
1488
1511
|
for (let i = 0; i < candidates.length; i++) {
|
|
1489
1512
|
const c = candidates[i];
|
|
1490
|
-
const nameDist =
|
|
1513
|
+
const nameDist = damerauLevenshtein(lower, c.toLowerCase());
|
|
1491
1514
|
if (nameDist <= threshold) {
|
|
1492
1515
|
typoMatches.push({ candidate: c, dist: nameDist });
|
|
1493
1516
|
continue;
|
|
@@ -1495,8 +1518,8 @@ var fuzzyMatch = (input, candidates, labels = {}) => {
|
|
|
1495
1518
|
if (labels[c]) {
|
|
1496
1519
|
const words = labels[c].toLowerCase().split(/\s+/);
|
|
1497
1520
|
for (let w = 0; w < words.length; w++) {
|
|
1498
|
-
if (
|
|
1499
|
-
typoMatches.push({ candidate: c, dist:
|
|
1521
|
+
if (damerauLevenshtein(lower, words[w]) <= threshold) {
|
|
1522
|
+
typoMatches.push({ candidate: c, dist: damerauLevenshtein(lower, words[w]) });
|
|
1500
1523
|
break;
|
|
1501
1524
|
}
|
|
1502
1525
|
}
|
|
@@ -1557,6 +1580,8 @@ var text_chat_default = (options) => {
|
|
|
1557
1580
|
commandLabels = {},
|
|
1558
1581
|
onNavigate,
|
|
1559
1582
|
onExit,
|
|
1583
|
+
onClick,
|
|
1584
|
+
onHover,
|
|
1560
1585
|
llm,
|
|
1561
1586
|
data
|
|
1562
1587
|
} = options;
|
|
@@ -1726,7 +1751,7 @@ var text_chat_default = (options) => {
|
|
|
1726
1751
|
} else {
|
|
1727
1752
|
addSystemMessage('Text navigation ready. Type "enter" to begin or "help" for available commands.');
|
|
1728
1753
|
}
|
|
1729
|
-
const specialCommands = ["enter", "help", "more", "more help", "clear"];
|
|
1754
|
+
const specialCommands = ["enter", "help", "more", "more help", "clear", "click", "select", "hover", "inspect"];
|
|
1730
1755
|
const moveToNode = (nodeId) => {
|
|
1731
1756
|
const node = inputHandler.moveTo(nodeId);
|
|
1732
1757
|
if (node) {
|
|
@@ -1777,15 +1802,55 @@ var text_chat_default = (options) => {
|
|
|
1777
1802
|
}
|
|
1778
1803
|
if (lower === "help") {
|
|
1779
1804
|
const llmHint = llm ? " You can also type any question about the data." : "";
|
|
1805
|
+
const interactionHints = [];
|
|
1806
|
+
if (onClick)
|
|
1807
|
+
interactionHints.push('"click" or "select"');
|
|
1808
|
+
if (onHover)
|
|
1809
|
+
interactionHints.push('"hover" or "inspect"');
|
|
1810
|
+
const interactionSuffix = interactionHints.length ? ` Interaction: ${interactionHints.join(", ")}.` : "";
|
|
1780
1811
|
if (!currentNodeId) {
|
|
1781
1812
|
addResponse(
|
|
1782
|
-
'Not yet in the structure. Type "enter" to begin navigating, or "move to <search>" to jump to a node.' + llmHint
|
|
1813
|
+
'Not yet in the structure. Type "enter" to begin navigating, or "move to <search>" to jump to a node.' + interactionSuffix + llmHint
|
|
1783
1814
|
);
|
|
1784
1815
|
} else {
|
|
1785
1816
|
const node = structure.nodes[currentNodeId];
|
|
1786
1817
|
const available = getAvailableRules(currentNodeId, node, structure);
|
|
1787
1818
|
const formatted = available.map((r) => formatRule(r, commandLabels));
|
|
1788
|
-
addResponse(
|
|
1819
|
+
addResponse(
|
|
1820
|
+
`Available: ${formatted.join(", ")}, move to <search>.` + interactionSuffix + llmHint
|
|
1821
|
+
);
|
|
1822
|
+
}
|
|
1823
|
+
return;
|
|
1824
|
+
}
|
|
1825
|
+
if (lower === "click" || lower === "select") {
|
|
1826
|
+
if (!currentNodeId) {
|
|
1827
|
+
addResponse('Not in the structure. Type "enter" to begin.');
|
|
1828
|
+
return;
|
|
1829
|
+
}
|
|
1830
|
+
const node = structure.nodes[currentNodeId];
|
|
1831
|
+
if (onClick && node) {
|
|
1832
|
+
onClick(node);
|
|
1833
|
+
addResponse(`Clicked: ${describeNode2(node)}`);
|
|
1834
|
+
} else {
|
|
1835
|
+
addResponse(
|
|
1836
|
+
onClick ? "Nothing to click here." : "Click interaction is not enabled for this chart."
|
|
1837
|
+
);
|
|
1838
|
+
}
|
|
1839
|
+
return;
|
|
1840
|
+
}
|
|
1841
|
+
if (lower === "hover" || lower === "inspect") {
|
|
1842
|
+
if (!currentNodeId) {
|
|
1843
|
+
addResponse('Not in the structure. Type "enter" to begin.');
|
|
1844
|
+
return;
|
|
1845
|
+
}
|
|
1846
|
+
const node = structure.nodes[currentNodeId];
|
|
1847
|
+
if (onHover && node) {
|
|
1848
|
+
onHover(node);
|
|
1849
|
+
addResponse(`Hovering over: ${describeNode2(node)}`);
|
|
1850
|
+
} else {
|
|
1851
|
+
addResponse(
|
|
1852
|
+
onHover ? "Nothing to hover over here." : "Hover interaction is not enabled for this chart."
|
|
1853
|
+
);
|
|
1789
1854
|
}
|
|
1790
1855
|
return;
|
|
1791
1856
|
}
|
package/dist/structure.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var U=Object.defineProperty,pe=Object.defineProperties,me=Object.getOwnPropertyDescriptor,Oe=Object.getOwnPropertyDescriptors,Ke=Object.getOwnPropertyNames,z=Object.getOwnPropertySymbols;var X=Object.prototype.hasOwnProperty,Ee=Object.prototype.propertyIsEnumerable;var Q=(e,o,i)=>o in e?U(e,o,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[o]=i,F=(e,o)=>{for(var i in o||(o={}))X.call(o,i)&&Q(e,i,o[i]);if(z)for(var i of z(o))Ee.call(o,i)&&Q(e,i,o[i]);return e},ee=(e,o)=>pe(e,Oe(o));var Ie=(e,o)=>{for(var i in o)U(e,i,{get:o[i],enumerable:!0})},Re=(e,o,i,c)=>{if(o&&typeof o=="object"||typeof o=="function")for(let y of Ke(o))!X.call(e,y)&&y!==i&&U(e,y,{get:()=>o[y],enumerable:!(c=me(o,y))||c.enumerable});return e};var xe=e=>Re(U({},"__esModule",{value:!0}),e);var De={};Ie(De,{addSimpleDataIDs:()=>de,buildEdges:()=>ue,buildNodeStructureFromVegaLite:()=>ae,buildNodes:()=>le,buildRules:()=>ge,buildStructure:()=>fe,default:()=>je,scaffoldDimensions:()=>ce});module.exports=xe(De);var ie={Escape:!0,Enter:!0,Backspace:!0,ArrowLeft:!0,ArrowRight:!0,ArrowUp:!0,ArrowDown:!0};var te=["KeyW","KeyJ","LeftBracket","RightBracket","Slash","Backslash"];var ne=[["LeftBracket","RightBracket"],["Slash","Backslash"]],q={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"}},se=[["left","right"],["up","down"],["backward","forward"],["previous","next"]];var re={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 oe=(e,o)=>{let i=Object.keys(e),c="";return i.forEach(y=>{c+=`${o&&o.omitKeyNames?"":y+": "}${e[y]}. `}),c+=o&&o.semanticLabel||"Data point.",c},J=e=>"_"+e.replace(/[^a-zA-Z0-9_-]+/g,"_");var je=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?ae(e):fe(e),ae=e=>{let o=re,i={},c={},y={},d=0,P=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,p=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,a=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,m=e.vegaLiteView._renderer._origin,t=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],E=(n,s)=>{if(n["data-navigator-id"])return n["data-navigator-id"];let f=`dn-node-${s}-${d}`;return d++,n["data-navigator-id"]=f,f},x=n=>{let s=i[n],f=s.index,g=s.level,h=s.parent,l=[],v=h.items[f-1];if(v){let u=E(v,g);if(i[u]){let O=`${u}-${s.id}`;l.push(O),c[O]||(c[O]={source:u,target:s.id,navigationRules:["left","right"]})}}let D=h.items[f+1];if(D){let u=E(D,g);if(i[u]){let O=`${s.id}-${u}`;l.push(O),c[O]||(c[O]={source:s.id,target:u,navigationRules:["left","right"]})}}if(g==="group"&&h.items[f].items){let O=(h.items[f].items[0].mark.items[0].items||h.items[f].items)[0],k=E(O,"item");if(i[k]){let r=`${s.id}-${k}`;l.push(r),c[r]||(c[r]={source:s.id,target:k,navigationRules:["parent","child"]})}}else if(g==="item"){let u=E(h,"group");if(i[u]){let O=`${u}-${s.id}`;l.push(O),c[O]||(c[O]={source:u,target:s.id,navigationRules:["parent","child"]})}}return e.exitFunction&&(l.push("any-exit"),c["any-exit"]||(c["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),l.push("any-undo"),c["any-undo"]||(c["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),l},K=(n,s,f,g,h)=>{let l=E(n,s),v="render-"+l,D=f||[0,0];i[l]={},i[l].d={},i[l].id=l,i[l].renderId=v,i[l].index=g,i[l].level=s,i[l].parent=h,y[v]={},y[v].renderId=v,y[v].spatialProperties={},y[v].spatialProperties.x=n.bounds.x1+D[0],y[v].spatialProperties.y=n.bounds.y1+D[1],y[v].spatialProperties.width=n.bounds.x2-n.bounds.x1,y[v].spatialProperties.height=n.bounds.y2-n.bounds.y1,y[v].cssClass="dn-vega-lite-node",n.datum&&Object.keys(n.datum).forEach(u=>{let O=n.datum[u];a(u,O,n.datum,s,e.vegaLiteSpec)&&(i[l].d[e.keyRenamingHash&&e.keyRenamingHash[u]?e.keyRenamingHash[u]:u]=O)}),y[v].semantics={},y[v].semantics.label=e.nodeDescriber?e.nodeDescriber(i[l].d,n,s):oe(i[l].d)},j=0;return t.items.forEach(n=>{if(P(n,j,e.vegaLiteSpec)){K(n,"group",m,j,t);let s=0,f=n.items[0].mark.items[0].items?n.items[0].mark.items[0]:n;f.items.forEach(g=>{p(g,s,n,e.vegaLiteSpec)&&K(g,"item",m,s,f),s++})}j++}),Object.keys(i).forEach(n=>{i[n].edges=x(n)}),{nodes:i,edges:c,elementData:y,navigationRules:o}},de=e=>{let o=0,i={};e.data.forEach(c=>{let y=typeof e.idKey=="function"?e.idKey(c):e.idKey;c[y]="_"+o,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(d=>{d in c&&(typeof c[d]=="string"?(i[d]||(i[d]=0),i[c[d]]||(i[c[d]]=0),c[y]+="_"+d+i[d]+"_"+c[d]+i[c[d]],i[d]++,i[c[d]]++):(i[d]||(i[d]=0),c[y]+="_"+d+i[d],i[d]++))}),o++})},le=e=>{let o={};return e.data.forEach(i=>{e.idKey||console.error("Building nodes. A key string must be supplied in options.idKey to specify the id keys of every node.");let c=typeof e.idKey=="function"?e.idKey(i):e.idKey,y=i[c];if(!y){console.error(`Building nodes. Each datum in options.data must contain an id. When matching the id key string ${c}, this datum has no id: ${JSON.stringify(i)}.`);return}if(o[y]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${y}.`);return}else{let d=typeof e.renderIdKey=="function"?e.renderIdKey(i):e.renderIdKey;o[y]={id:y,edges:[],renderId:d?i[d]||"":i.renderIdKey||"",data:i}}}),o},ce=(e,o)=>{var d,P;let i={};if((P=(d=e.dimensions)==null?void 0:d.parentOptions)!=null&&P.addLevel0){let p=e.dimensions.parentOptions.addLevel0;o[p.id]=ee(F({},p),{dimensionLevel:0})}let c=[...se],y=(p,a)=>{let m=a.numericalExtents[0],t=a.numericalExtents[1];a.numericalExtents[0]=m<p?m:p,a.numericalExtents[1]=t>p?t:p};return e.data.forEach(p=>{let a=e.dimensions.values||[],m=0;a.forEach(t=>{var E,x,K,j,b,n,s,f;if(!t.dimensionKey){console.error(`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(t)}.`);return}if(t.dimensionKey in p){let g=p[t.dimensionKey],h=typeof((E=t.operations)==null?void 0:E.filterFunction)=="function"?t.operations.filterFunction(p,t):!0;if(g!==void 0&&h){if(t.type||(t.type=typeof g=="bigint"||typeof g=="number"?"numerical":"categorical"),!i[t.dimensionKey]){let u=typeof t.nodeId=="function"?t.nodeId(t,e.data):t.nodeId||J(t.dimensionKey),O=typeof t.renderId=="function"?t.renderId(t,e.data):t.renderId||u;i[t.dimensionKey]={dimensionKey:t.dimensionKey,nodeId:u,divisions:{},numericalExtents:[1/0,-1/0],type:t.type,operations:{compressSparseDivisions:((x=t.operations)==null?void 0:x.compressSparseDivisions)||!1,sortFunction:((K=t.operations)==null?void 0:K.sortFunction)||void 0},behavior:t.behavior||{extents:"circular"},navigationRules:t.navigationRules||{sibling_sibling:c.length?[...c.shift()]:["previous_"+t.dimensionKey,"next_"+t.dimensionKey],parent_child:["parent_"+t.dimensionKey,"child"]}},o[u]={id:u,renderId:O,derivedNode:t.dimensionKey,edges:[],dimensionLevel:1,data:i[t.dimensionKey],renderingStrategy:t.renderingStrategy||"singleSquare"}}let l=i[t.dimensionKey],v=null;if(t.type==="categorical"){let u=typeof((j=t.divisionOptions)==null?void 0:j.divisionNodeIds)=="function"?t.divisionOptions.divisionNodeIds(t.dimensionKey,g,m):J(l.nodeId+"_"+g);if(v=l.divisions[u],!v){v=l.divisions[u]={id:u,sortFunction:((b=t.divisionOptions)==null?void 0:b.sortFunction)||void 0,values:{}};let O=typeof((n=t.divisionOptions)==null?void 0:n.divisionRenderIds)=="function"?t.divisionOptions.divisionRenderIds(t.dimensionKey,g,m):u;o[u]={id:u,renderId:O,derivedNode:t.dimensionKey,edges:[],dimensionLevel:2,data:F({},v),renderingStrategy:((s=t.divisionOptions)==null?void 0:s.renderingStrategy)||"singleSquare"},o[u].data[t.dimensionKey]=g}}else{v=l.divisions[l.nodeId],v||(v=l.divisions[l.nodeId]={id:l.nodeId,sortFunction:((f=t.divisionOptions)==null?void 0:f.sortFunction)||void 0,values:{}}),t.operations||(t.operations={});let u=t.operations.createNumericalSubdivisions;l.subdivisions=typeof u=="number"&&u<1?1:u||1,u!==1&&(l.divisionOptions||(l.divisionOptions=t.divisionOptions),y(g,l))}let D=typeof e.idKey=="function"?e.idKey(p):e.idKey;v.values[p[D]]=p}}m++})}),Object.keys(i).forEach(p=>{var E,x,K,j,b;let a=i[p],m=a.divisions;if(a.type==="numerical"){m[a.nodeId].values=Object.fromEntries(Object.entries(m[a.nodeId].values).sort((s,f)=>{var g;return typeof((g=a.operations)==null?void 0:g.sortFunction)=="function"?a.operations.sortFunction(s[1],f[1],a):s[1][p]-f[1][p]}));let n=m[a.nodeId].values;if(a.numericalExtents[0]!==1/0&&a.subdivisions!==1){let s=Object.keys(n),f=typeof a.subdivisions=="function"?a.subdivisions(p,n):a.subdivisions,h=(a.numericalExtents[1]-a.numericalExtents[0])/f,l=a.numericalExtents[0]+h,v=0,D=0;for(l=a.numericalExtents[0]+h;l<=a.numericalExtents[1];l+=h){let u=typeof((E=a.divisionOptions)==null?void 0:E.divisionNodeIds)=="function"?a.divisionOptions.divisionNodeIds(p,l,l):a.nodeId+"_"+l;a.divisions[u]={id:u,sortFunction:((x=a.divisionOptions)==null?void 0:x.sortFunction)||void 0,values:{}};let O=typeof((K=a.divisionOptions)==null?void 0:K.divisionRenderIds)=="function"?a.divisionOptions.divisionRenderIds(p,l,l):u;o[u]={id:u,renderId:O,derivedNode:p,edges:[],data:a.divisions[u],dimensionLevel:2,renderingStrategy:((j=a.divisionOptions)==null?void 0:j.renderingStrategy)||"singleSquare"};let k=!1;for(;!k&&D<s.length;){let r=n[s[D]];r[p]<=l?a.divisions[u].values[r.id]=r:(l+=h,k=!0),D++}v++}delete m[p]}}else typeof((b=a.operations)==null?void 0:b.sortFunction)=="function"&&(a.divisions=Object.fromEntries(Object.entries(m).sort((n,s)=>a.operations.sortFunction(n[1],s[1],a))));Object.keys(a.divisions).forEach(n=>{let s=a.divisions[n];typeof s.sortFunction=="function"&&(s.values=Object.fromEntries(Object.entries(s.values).sort((f,g)=>s.sortFunction(f[1],g[1],s))))})}),Object.keys(i).forEach(p=>{let a=i[p];if(a.operations.compressSparseDivisions){let m=Object.keys(a.divisions),t={},E=!0;if(m.forEach(x=>{let K=a.divisions[x],j=Object.keys(K.values);j.length<=1?j.forEach(b=>{t[b]=F({},K.values[b])}):E=!1}),E){let x={id:a.nodeId,values:t};m.forEach(K=>{delete o[K]}),a.divisions={},a.divisions[a.nodeId]=x}}}),e.dimensions.adjustDimensions&&(i=e.dimensions.adjustDimensions(i)),i},ue=(e,o,i)=>{var P,p,a,m,t,E,x,K,j,b;let c={},y=(n,s)=>{o[n].edges.indexOf(s)===-1&&o[n].edges.push(s)},d=(n,s,f,g)=>{let h=`${n}-${s}`,l=e.useDirectedEdges?`${s}-${h}`:h,v=!g||g==="source",D=!g||g==="target",u=O=>{c[O]?c[O].navigationRules.push(...f||[]):c[O]={source:n,target:s,navigationRules:f?[...f]:[]}};u(h),e.useDirectedEdges&&D&&u(l),v&&y(n,h),D&&y(s,l)};if(i&&Object.keys(i).length){let n=Object.keys(i),s=(a=(p=(P=e.dimensions)==null?void 0:P.parentOptions)==null?void 0:p.level1Options)==null?void 0:a.order,f=s||n,g=0,h=((m=e.dimensions)==null?void 0:m.parentOptions)||{},l=((E=(t=h.level1Options)==null?void 0:t.behavior)==null?void 0:E.extents)||"terminal",v=h.addLevel0,D=v?((K=(x=h.level1Options)==null?void 0:x.navigationRules)==null?void 0:K.parent_child)||["parent","child"]:[],u=((b=(j=h.level1Options)==null?void 0:j.navigationRules)==null?void 0:b.sibling_sibling)||["left","right"],O=typeof f[0]=="string"?s?o[f[0]]:o[i[f[0]].nodeId]:f[0];v&&d(v.id,O.id,D,"source"),f.forEach(k=>{let r=typeof k=="string"?s?o[k]:o[i[k].nodeId]:k;if(r===k&&!o[r.id]&&(o[r.id]=r),v&&(e.useDirectedEdges?d(r.id,v.id,D,"source"):d(v.id,r.id,D,"target")),g===f.length-1&&l==="circular")d(r.id,O.id,u);else if(g===f.length-1&&l==="bridgedCustom")d(r.id,h.level1Options.behavior.customBridgePost,u);else if(g<f.length-1){let A=typeof f[g+1]=="string"?s?o[f[g+1]]:o[i[f[g+1]].nodeId]:f[g+1];d(r.id,A.id,u)}!g&&l==="bridgedCustom"&&d(h.level1Options.behavior.customBridgePost,r.id,u),g++}),n.forEach(k=>{var M,H,W,Y;let r=i[k],A=((M=r.behavior)==null?void 0:M.childmostNavigation)||"within",ve=($,w,I,G)=>G.values[Object.keys(G.values)[$]]||void 0,ye=A==="across"&&((H=r.behavior)!=null&&H.childmostMatching)?(W=r.behavior)==null?void 0:W.childmostMatching:ve,L=((Y=r.behavior)==null?void 0:Y.extents)||"circular";r.divisions||console.error(`Parsing dimensions. The dimension using the key ${k} is missing the divisions property. dimension.divisions should be supplied. ${JSON.stringify(r)}.`);let R=Object.keys(r.divisions),T=r.divisions[R[0]];if(R.length!==1)d(r.nodeId,T.id,r.navigationRules.parent_child,"source");else{let $=Object.keys(T.values),w=typeof e.idKey=="function"?e.idKey(T.values[$[0]]):e.idKey;d(r.nodeId,T.values[$[0]][w],r.navigationRules.parent_child,"source")}let S=0;R.forEach($=>{let w=r.divisions[$];S===R.length-1&&(L==="circular"||L==="bridgedCousins"||L==="bridgedCustom")?d(w.id,r.divisions[R[0]].id,r.navigationRules.sibling_sibling):S<R.length-1&&d(w.id,r.divisions[R[S+1]].id,r.navigationRules.sibling_sibling);let I=Object.keys(w.values);e.useDirectedEdges?d(w.id,r.nodeId,r.navigationRules.parent_child,"source"):d(r.nodeId,w.id,r.navigationRules.parent_child,"target");let G=typeof e.idKey=="function"?e.idKey(w.values[I[0]]):e.idKey;d(w.id,w.values[I[0]][G],r.navigationRules.parent_child,"source");let B=0;I.length>=1&&I.forEach(he=>{let N=w.values[he],_=typeof e.idKey=="function"?e.idKey(N):e.idKey,Z=R.length!==1?w.id:r.nodeId;if(e.useDirectedEdges?d(N[_],Z,r.navigationRules.parent_child,"source"):d(Z,N[_],r.navigationRules.parent_child,"target"),A==="within"){if(B===I.length-1&&L==="circular"){let C=typeof e.idKey=="function"?e.idKey(w.values[I[0]]):e.idKey;d(N[_],w.values[I[0]][C],r.navigationRules.sibling_sibling)}else if(B===I.length-1&&L==="bridgedCousins")if(S!==R.length-1){let C=typeof e.idKey=="function"?e.idKey(r.divisions[R[S+1]].values[I[0]]):e.idKey;d(N[_],r.divisions[R[S+1]].values[I[0]][C],r.navigationRules.sibling_sibling)}else{let C=typeof e.idKey=="function"?e.idKey(r.divisions[R[0]].values[I[0]]):e.idKey;d(N[_],r.divisions[R[0]].values[I[0]][C],r.navigationRules.sibling_sibling)}else if(B===I.length-1&&L==="bridgedCustom")d(N[_],r.behavior.customBridgePost,r.navigationRules.sibling_sibling);else if(B<I.length-1){let C=typeof e.idKey=="function"?e.idKey(w.values[I[B+1]]):e.idKey;d(N[_],w.values[I[B+1]][C],r.navigationRules.sibling_sibling)}if(!B&&L==="bridgedCousins")if(S!==0){let C=typeof e.idKey=="function"?e.idKey(r.divisions[R[S-1]].values[I[I.length-1]]):e.idKey;d(r.divisions[R[S-1]].values[I[I.length-1]][C],N[_],r.navigationRules.sibling_sibling)}else{let C=typeof e.idKey=="function"?e.idKey(r.divisions[R[R.length-1]].values[I[I.length-1]]):e.idKey;d(r.divisions[R[R.length-1]].values[I[I.length-1]][C],N[_],r.navigationRules.sibling_sibling)}else!B&&L==="bridgedCustom"&&d(r.behavior.customBridgePrevious,N[_],r.navigationRules.sibling_sibling)}else if(S===R.length-1&&L==="bridgedCustom")d(N[_],r.behavior.customBridgePost,r.navigationRules.sibling_sibling);else if(!S&&L==="bridgedCustom")d(r.behavior.customBridgePrevious,N[_],r.navigationRules.sibling_sibling);else{let C=S===R.length-1&&L==="circular"?r.divisions[R[0]]:r.divisions[R[S+1]];if(C){let V=ye(B,N[_],w,C);if(V){let be=typeof e.idKey=="function"?e.idKey(V):e.idKey;d(N[_],V[be],r.navigationRules.sibling_sibling)}}}B++}),S++})})}return Object.keys(o).forEach(n=>{var f;let s=o[n];(f=e.genericEdges)!=null&&f.length&&e.genericEdges.forEach(g=>{c[g.edgeId]||(c[g.edgeId]=g.edge),(!g.conditional||g.conditional&&g.conditional(s,g))&&s.edges.push(g.edgeId)})}),c},ge=(e,o,i)=>{var y,d,P,p;let c=e.navigationRules;if(!c){let a=Object.keys(i||{});a.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 ${a.length}. Dimensions counted: ${a.join(", ")}.`);let m={},t={},E={},x=[...ne],K=[...te],j=(b,n)=>{let s=b&&n,f=!1,g=!1;if((m[b]||t[b])&&(t[b]=F({},m[b]),f=!0),n&&(m[n]||t[n])&&(t[n]=F({},m[n]),g=!0),s&&!f&&!g){x.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 h=[...x.shift()];K.splice(K.indexOf(h[0]),1),K.splice(K.indexOf(h[1]),1),t[b]={direction:e.useDirectedEdges?"target":"source",key:h[0]},t[n]={direction:"target",key:h[1]}}else{if(!t[b]&&K.length){let h=K.shift(),l=[];x.forEach(v=>{h!==v[0]&&h!==v[1]&&l.push(v)}),x=l,t[b]={direction:e.useDirectedEdges?"target":"source",key:h}}if(n&&!t[n]&&K.length){let h=K.shift(),l=[];x.forEach(v=>{h!==v[0]&&h!==v[1]&&l.push(v)}),x=l,t[n]={direction:"target",key:h}}K.length||(t[b]||(E[b]=b),n&&!t[n]&&(E[n]=n))}};if(Object.keys(q).forEach(b=>{let n=F({},q[b]);e.useDirectedEdges&&(n.direction="target"),m[b]=n}),a.length){if((d=(y=e.dimensions)==null?void 0:y.parentOptions)!=null&&d.addLevel0){let b=((p=(P=e.dimensions.parentOptions.level1Options)==null?void 0:P.navigationRules)==null?void 0:p.parent_child)||["parent","child"];j(b[0],b[1])}a.forEach(b=>{let n=i[b].navigationRules.parent_child,s=i[b].navigationRules.sibling_sibling;j(n[0],n[1]),j(s[0],s[1])})}if(Object.keys(o).forEach(b=>{o[b].navigationRules.forEach(n=>{t[n]||j(n)})}),Object.keys(E).length){let b={};Object.keys(t).forEach(s=>{b[t[s].key]=t[s].key}),Object.keys(m).forEach(s=>{!b[m[s].key]&&!ie[m[s].key]&&K.push(m[s].key)});let n=F({},E);E={},Object.keys(n).forEach(s=>{j(s)}),Object.keys(E).length&&console.error(`Building navigationRules. There are no more keys left to assign automatically. Recommended fixes: use fewer dimensions, use fewer GenericEdges, or build your own navigationRules. Rules remaining without keyboard keys: ${Object.keys(E).join(", ")}.`)}c=t}return c},fe=e=>{e.addIds&&de(e);let o=le(e),i=ce(e,o),c=ue(e,o,i),y=ge(e,c,i);return{nodes:o,edges:c,dimensions:i,navigationRules:y}};0&&(module.exports={addSimpleDataIDs,buildEdges,buildNodeStructureFromVegaLite,buildNodes,buildRules,buildStructure,scaffoldDimensions});
|
|
1
|
+
var V=Object.defineProperty,be=Object.defineProperties,pe=Object.getOwnPropertyDescriptor,me=Object.getOwnPropertyDescriptors,Oe=Object.getOwnPropertyNames,X=Object.getOwnPropertySymbols;var ie=Object.prototype.hasOwnProperty,Ke=Object.prototype.propertyIsEnumerable;var ee=(e,a,i)=>a in e?V(e,a,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[a]=i,F=(e,a)=>{for(var i in a||(a={}))ie.call(a,i)&&ee(e,i,a[i]);if(X)for(var i of X(a))Ke.call(a,i)&&ee(e,i,a[i]);return e},te=(e,a)=>be(e,me(a));var Ee=(e,a)=>{for(var i in a)V(e,i,{get:a[i],enumerable:!0})},Ie=(e,a,i,c)=>{if(a&&typeof a=="object"||typeof a=="function")for(let h of Oe(a))!ie.call(e,h)&&h!==i&&V(e,h,{get:()=>a[h],enumerable:!(c=pe(a,h))||c.enumerable});return e};var xe=e=>Ie(V({},"__esModule",{value:!0}),e);var je={};Ee(je,{addSimpleDataIDs:()=>ce,buildEdges:()=>fe,buildNodeStructureFromVegaLite:()=>le,buildNodes:()=>ue,buildRules:()=>ve,buildStructure:()=>ye,default:()=>Re,scaffoldDimensions:()=>ge});module.exports=xe(je);var ne={Escape:!0,Enter:!0,Backspace:!0,ArrowLeft:!0,ArrowRight:!0,ArrowUp:!0,ArrowDown:!0};var se=["KeyW","KeyJ","LeftBracket","RightBracket","Slash","Backslash"];var re=[["LeftBracket","RightBracket"],["Slash","Backslash"]],H={left:{key:"ArrowLeft",direction:"source"},right:{key:"ArrowRight",direction:"target"},up:{key:"ArrowUp",direction:"source"},down:{key:"ArrowDown",direction:"target"},child:{key:"Enter",direction:"target"},parent:{key:"Backspace",direction:"source"},backward:{key:"Comma",direction:"source"},forward:{key:"Period",direction:"target"},previous:{key:"Semicolon",direction:"source"},next:{key:"Quote",direction:"target"},exit:{key:"Escape",direction:"target"},help:{key:"KeyY",direction:"target"},undo:{key:"KeyZ",direction:"target"}},oe=[["left","right"],["up","down"],["backward","forward"],["previous","next"]];var ae={right:{key:"ArrowRight",direction:"target"},left:{key:"ArrowLeft",direction:"source"},down:{key:"ArrowDown",direction:"target"},up:{key:"ArrowUp",direction:"source"},child:{key:"Enter",direction:"target"},parent:{key:"Backspace",direction:"source"},exit:{key:"Escape",direction:"target"},undo:{key:"Period",direction:"target"},legend:{key:"KeyL",direction:"target"}};var de=(e,a)=>{let i=Object.keys(e),c="";return i.forEach(h=>{c+=`${a&&a.omitKeyNames?"":h+": "}${e[h]}. `}),c+=a&&a.semanticLabel||"Data point.",c},q=e=>"_"+e.replace(/[^a-zA-Z0-9_-]+/g,"_");var Re=e=>e.dataType==="vega-lite"||e.dataType==="vl"||e.dataType==="Vega-Lite"?le(e):ye(e),le=e=>{let a=ae,i={},c={},h={},d=0,B=e.groupInclusionCriteria?e.groupInclusionCriteria:()=>!0,P=e.itemInclusionCriteria?e.itemInclusionCriteria:()=>!0,m=e.datumInclusionCriteria?e.datumInclusionCriteria:()=>!0,s=e.vegaLiteView._renderer._origin,b=e.vegaLiteView._scenegraph.root.items[0].mark.items[0],I=(n,o)=>{if(n["data-navigator-id"])return n["data-navigator-id"];let l=`dn-node-${o}-${d}`;return d++,n["data-navigator-id"]=l,l},r=n=>{let o=i[n],l=o.index,u=o.level,y=o.parent,g=[],f=y.items[l-1];if(f){let v=I(f,u);if(i[v]){let K=`${v}-${o.id}`;g.push(K),c[K]||(c[K]={source:v,target:o.id,navigationRules:["left","right"]})}}let E=y.items[l+1];if(E){let v=I(E,u);if(i[v]){let K=`${o.id}-${v}`;g.push(K),c[K]||(c[K]={source:o.id,target:v,navigationRules:["left","right"]})}}if(u==="group"&&y.items[l].items){let K=(y.items[l].items[0].mark.items[0].items||y.items[l].items)[0],O=I(K,"item");if(i[O]){let t=`${o.id}-${O}`;g.push(t),c[t]||(c[t]={source:o.id,target:O,navigationRules:["parent","child"]})}}else if(u==="item"){let v=I(y,"group");if(i[v]){let K=`${v}-${o.id}`;g.push(K),c[K]||(c[K]={source:v,target:o.id,navigationRules:["parent","child"]})}}return e.exitFunction&&(g.push("any-exit"),c["any-exit"]||(c["any-exit"]={source:e.getCurrent,target:e.exitFunction,navigationRules:["exit"]})),g.push("any-undo"),c["any-undo"]||(c["any-undo"]={source:e.getCurrent,target:e.getPrevious,navigationRules:["undo"]}),g},x=(n,o,l,u,y)=>{let g=I(n,o),f="render-"+g,E=l||[0,0];i[g]={},i[g].d={},i[g].id=g,i[g].renderId=f,i[g].index=u,i[g].level=o,i[g].parent=y,h[f]={},h[f].renderId=f,h[f].spatialProperties={},h[f].spatialProperties.x=n.bounds.x1+E[0],h[f].spatialProperties.y=n.bounds.y1+E[1],h[f].spatialProperties.width=n.bounds.x2-n.bounds.x1,h[f].spatialProperties.height=n.bounds.y2-n.bounds.y1,h[f].cssClass="dn-vega-lite-node",n.datum&&Object.keys(n.datum).forEach(v=>{let K=n.datum[v];m(v,K,n.datum,o,e.vegaLiteSpec)&&(i[g].d[e.keyRenamingHash&&e.keyRenamingHash[v]?e.keyRenamingHash[v]:v]=K)}),h[f].semantics={},h[f].semantics.label=e.nodeDescriber?e.nodeDescriber(i[g].d,n,o):de(i[g].d)},j=0;return b.items.forEach(n=>{if(B(n,j,e.vegaLiteSpec)){x(n,"group",s,j,b);let o=0,l=n.items[0].mark.items[0].items?n.items[0].mark.items[0]:n;l.items.forEach(u=>{P(u,o,n,e.vegaLiteSpec)&&x(u,"item",s,o,l),o++})}j++}),Object.keys(i).forEach(n=>{i[n].edges=r(n)}),{nodes:i,edges:c,elementData:h,navigationRules:a}},ce=e=>{let a=0,i={};e.data.forEach(c=>{let h=typeof e.idKey=="function"?e.idKey(c):e.idKey;c[h]="_"+a,e.keysForIdGeneration&&e.keysForIdGeneration.forEach(d=>{d in c&&(typeof c[d]=="string"?(i[d]||(i[d]=0),i[c[d]]||(i[c[d]]=0),c[h]+="_"+d+i[d]+"_"+c[d]+i[c[d]],i[d]++,i[c[d]]++):(i[d]||(i[d]=0),c[h]+="_"+d+i[d],i[d]++))}),a++})},ue=e=>{let a={};return e.data.forEach(i=>{e.idKey||console.error("Building nodes. A key string must be supplied in options.idKey to specify the id keys of every node.");let c=typeof e.idKey=="function"?e.idKey(i):e.idKey,h=i[c];if(!h){console.error(`Building nodes. Each datum in options.data must contain an id. When matching the id key string ${c}, this datum has no id: ${JSON.stringify(i)}.`);return}if(a[h]){console.error(`Building nodes. Each id for data in options.data must be unique. This id is not unique: ${h}.`);return}else{let d=typeof e.renderIdKey=="function"?e.renderIdKey(i):e.renderIdKey;a[h]={id:h,edges:[],renderId:d?i[d]||"":i.renderIdKey||"",data:i}}}),a},ge=(e,a)=>{var d,B,P;let i={};if((B=(d=e.dimensions)==null?void 0:d.parentOptions)!=null&&B.addLevel0){let m=e.dimensions.parentOptions.addLevel0;a[m.id]=te(F({},m),{dimensionLevel:0})}let c=[...oe],h=(m,s)=>{let b=s.numericalExtents[0],I=s.numericalExtents[1];s.numericalExtents[0]=b<m?b:m,s.numericalExtents[1]=I>m?I:m};return e.data.forEach(m=>{var I;let s=((I=e.dimensions)==null?void 0:I.values)||[],b=0;s.forEach(r=>{var x,j,p,n,o,l,u,y;if(!r.dimensionKey){console.error(`Building nodes, parsing dimensions. Each dimension in options.dimensions must contain a dimensionKey. This dimension has no key: ${JSON.stringify(r)}.`);return}if(r.dimensionKey in m){let g=m[r.dimensionKey],f=typeof((x=r.operations)==null?void 0:x.filterFunction)=="function"?r.operations.filterFunction(m,r):!0;if(g!==void 0&&f){if(r.type||(r.type=typeof g=="bigint"||typeof g=="number"?"numerical":"categorical"),!i[r.dimensionKey]){let O=typeof r.nodeId=="function"?r.nodeId(r,e.data):r.nodeId||q(r.dimensionKey),t=typeof r.renderId=="function"?r.renderId(r,e.data):r.renderId||O;i[r.dimensionKey]={dimensionKey:r.dimensionKey,nodeId:O,divisions:{},numericalExtents:[1/0,-1/0],type:r.type,operations:{compressSparseDivisions:((j=r.operations)==null?void 0:j.compressSparseDivisions)||!1,sortFunction:((p=r.operations)==null?void 0:p.sortFunction)||void 0},behavior:r.behavior||{extents:"circular"},navigationRules:r.navigationRules||{sibling_sibling:c.length?[...c.shift()]:["previous_"+r.dimensionKey,"next_"+r.dimensionKey],parent_child:["parent_"+r.dimensionKey,"child"]}},a[O]={id:O,renderId:t,derivedNode:r.dimensionKey,edges:[],dimensionLevel:1,data:i[r.dimensionKey],renderingStrategy:r.renderingStrategy||"singleSquare"}}let E=i[r.dimensionKey],v=null;if(r.type==="categorical"){let O=typeof((n=r.divisionOptions)==null?void 0:n.divisionNodeIds)=="function"?r.divisionOptions.divisionNodeIds(r.dimensionKey,g,b):q(E.nodeId+"_"+g);if(v=E.divisions[O],!v){v=E.divisions[O]={id:O,sortFunction:((o=r.divisionOptions)==null?void 0:o.sortFunction)||void 0,values:{}};let t=typeof((l=r.divisionOptions)==null?void 0:l.divisionRenderIds)=="function"?r.divisionOptions.divisionRenderIds(r.dimensionKey,g,b):O;a[O]={id:O,renderId:t,derivedNode:r.dimensionKey,edges:[],dimensionLevel:2,data:F({},v),renderingStrategy:((u=r.divisionOptions)==null?void 0:u.renderingStrategy)||"singleSquare"},a[O].data[r.dimensionKey]=g}}else{v=E.divisions[E.nodeId],v||(v=E.divisions[E.nodeId]={id:E.nodeId,sortFunction:((y=r.divisionOptions)==null?void 0:y.sortFunction)||void 0,values:{}}),r.operations||(r.operations={});let O=r.operations.createNumericalSubdivisions;E.subdivisions=typeof O=="number"&&O<1?1:O||1,O!==1&&(E.divisionOptions||(E.divisionOptions=r.divisionOptions),h(g,E))}let K=typeof e.idKey=="function"?e.idKey(m):e.idKey;v.values[m[K]]=m}}b++})}),Object.keys(i).forEach(m=>{var r,x,j,p,n;let s=i[m],b=s.divisions;if(s.type==="numerical"){b[s.nodeId].values=Object.fromEntries(Object.entries(b[s.nodeId].values).sort((l,u)=>{var y;return typeof((y=s.operations)==null?void 0:y.sortFunction)=="function"?s.operations.sortFunction(l[1],u[1],s):l[1][m]-u[1][m]}));let o=b[s.nodeId].values;if(s.numericalExtents[0]!==1/0&&s.subdivisions!==1){let l=Object.keys(o),u=typeof s.subdivisions=="function"?s.subdivisions(m,o):s.subdivisions,g=(s.numericalExtents[1]-s.numericalExtents[0])/u,f=s.numericalExtents[0]+g,E=0,v=0,K=null,O=s.numericalExtents[0];for(f=s.numericalExtents[0]+g;f<=s.numericalExtents[1];f+=g){let t=typeof((r=s.divisionOptions)==null?void 0:r.divisionNodeIds)=="function"?s.divisionOptions.divisionNodeIds(m,f,f):q(s.nodeId+"_"+f);K=t,s.divisions[t]={id:t,sortFunction:((x=s.divisionOptions)==null?void 0:x.sortFunction)||void 0,values:{},numericalExtents:[O,f]};let $=typeof((j=s.divisionOptions)==null?void 0:j.divisionRenderIds)=="function"?s.divisionOptions.divisionRenderIds(m,f,f):t;a[t]={id:t,renderId:$,derivedNode:m,edges:[],data:s.divisions[t],dimensionLevel:2,renderingStrategy:((p=s.divisionOptions)==null?void 0:p.renderingStrategy)||"singleSquare"};let G=!1;for(;!G&&v<l.length;){let T=o[l[v]];T[m]<=f?(s.divisions[t].values[T.id]=T,v++):G=!0}O=f,E++}if(K&&v<l.length)for(;v<l.length;){let t=o[l[v]];s.divisions[K].values[t.id]=t,v++}delete b[m]}}else typeof((n=s.operations)==null?void 0:n.sortFunction)=="function"&&(s.divisions=Object.fromEntries(Object.entries(b).sort((o,l)=>s.operations.sortFunction(o[1],l[1],s))));Object.keys(s.divisions).forEach(o=>{let l=s.divisions[o];typeof l.sortFunction=="function"&&(l.values=Object.fromEntries(Object.entries(l.values).sort((u,y)=>l.sortFunction(u[1],y[1],l))))})}),Object.keys(i).forEach(m=>{let s=i[m];if(s.operations.compressSparseDivisions){let b=Object.keys(s.divisions),I={},r=!0;if(b.forEach(x=>{let j=s.divisions[x],p=Object.keys(j.values);p.length<=1?p.forEach(n=>{I[n]=F({},j.values[n])}):r=!1}),r){let x={id:s.nodeId,values:I};b.forEach(j=>{delete a[j]}),s.divisions={},s.divisions[s.nodeId]=x}}}),(P=e.dimensions)!=null&&P.adjustDimensions&&(i=e.dimensions.adjustDimensions(i)),i},fe=(e,a,i)=>{var B,P,m,s,b,I,r,x,j,p;let c={},h=(n,o)=>{a[n].edges.indexOf(o)===-1&&a[n].edges.push(o)},d=(n,o,l,u)=>{let y=`${n}-${o}`,g=e.useDirectedEdges?`${o}-${y}`:y,f=!u||u==="source",E=!u||u==="target",v=K=>{c[K]?c[K].navigationRules.push(...l||[]):c[K]={source:n,target:o,navigationRules:l?[...l]:[]}};v(y),e.useDirectedEdges&&E&&v(g),f&&h(n,y),E&&h(o,g)};if(i&&Object.keys(i).length){let n=Object.keys(i),o=(m=(P=(B=e.dimensions)==null?void 0:B.parentOptions)==null?void 0:P.level1Options)==null?void 0:m.order,l=o||n,u=0,y=((s=e.dimensions)==null?void 0:s.parentOptions)||{},g=((I=(b=y.level1Options)==null?void 0:b.behavior)==null?void 0:I.extents)||"terminal",f=y.addLevel0,E=f?((x=(r=y.level1Options)==null?void 0:r.navigationRules)==null?void 0:x.parent_child)||["parent","child"]:[],v=((p=(j=y.level1Options)==null?void 0:j.navigationRules)==null?void 0:p.sibling_sibling)||["left","right"],K=typeof l[0]=="string"?o?a[l[0]]:a[i[l[0]].nodeId]:l[0];f&&d(f.id,K.id,E,"source"),l.forEach(O=>{let t=typeof O=="string"?o?a[O]:a[i[O].nodeId]:O;if(t===O&&!a[t.id]&&(a[t.id]=t),f&&(e.useDirectedEdges?d(t.id,f.id,E,"source"):d(f.id,t.id,E,"target")),u===l.length-1&&g==="circular")d(t.id,K.id,v);else if(u===l.length-1&&g==="bridgedCustom")d(t.id,y.level1Options.behavior.customBridgePost,v);else if(u<l.length-1){let $=typeof l[u+1]=="string"?o?a[l[u+1]]:a[i[l[u+1]].nodeId]:l[u+1];d(t.id,$.id,v)}!u&&g==="bridgedCustom"&&d(y.level1Options.behavior.customBridgePost,t.id,v),u++}),n.forEach(O=>{var W,Y,Z,z;let t=i[O],$=((W=t.behavior)==null?void 0:W.childmostNavigation)||"within",G=(A,w,R,C)=>C.values[Object.keys(C.values)[A]]||void 0,T=$==="across"&&((Y=t.behavior)!=null&&Y.childmostMatching)?(Z=t.behavior)==null?void 0:Z.childmostMatching:G,L=((z=t.behavior)==null?void 0:z.extents)||"circular";t.divisions||console.error(`Parsing dimensions. The dimension using the key ${O} is missing the divisions property. dimension.divisions should be supplied. ${JSON.stringify(t)}.`);let D=Object.keys(t.divisions),U=t.divisions[D[0]];if(D.length!==1)d(t.nodeId,U.id,t.navigationRules.parent_child,"source");else{let A=Object.keys(U.values),w=typeof e.idKey=="function"?e.idKey(U.values[A[0]]):e.idKey;d(t.nodeId,U.values[A[0]][w],t.navigationRules.parent_child,"source")}let N=0;D.forEach(A=>{let w=t.divisions[A];N===D.length-1&&(L==="circular"||L==="bridgedCousins"||L==="bridgedCustom")?d(w.id,t.divisions[D[0]].id,t.navigationRules.sibling_sibling):N<D.length-1&&d(w.id,t.divisions[D[N+1]].id,t.navigationRules.sibling_sibling);let R=Object.keys(w.values);if(e.useDirectedEdges?d(w.id,t.nodeId,t.navigationRules.parent_child,"source"):d(t.nodeId,w.id,t.navigationRules.parent_child,"target"),R.length>0){let J=typeof e.idKey=="function"?e.idKey(w.values[R[0]]):e.idKey;d(w.id,w.values[R[0]][J],t.navigationRules.parent_child,"source")}let C=0;R.length>=1&&R.forEach(J=>{let k=w.values[J],S=typeof e.idKey=="function"?e.idKey(k):e.idKey,Q=D.length!==1?w.id:t.nodeId;if(e.useDirectedEdges?d(k[S],Q,t.navigationRules.parent_child,"source"):d(Q,k[S],t.navigationRules.parent_child,"target"),$==="within"){if(C===R.length-1&&L==="circular"){let _=typeof e.idKey=="function"?e.idKey(w.values[R[0]]):e.idKey;d(k[S],w.values[R[0]][_],t.navigationRules.sibling_sibling)}else if(C===R.length-1&&L==="bridgedCousins")if(N!==D.length-1){let _=typeof e.idKey=="function"?e.idKey(t.divisions[D[N+1]].values[R[0]]):e.idKey;d(k[S],t.divisions[D[N+1]].values[R[0]][_],t.navigationRules.sibling_sibling)}else{let _=typeof e.idKey=="function"?e.idKey(t.divisions[D[0]].values[R[0]]):e.idKey;d(k[S],t.divisions[D[0]].values[R[0]][_],t.navigationRules.sibling_sibling)}else if(C===R.length-1&&L==="bridgedCustom")d(k[S],t.behavior.customBridgePost,t.navigationRules.sibling_sibling);else if(C<R.length-1){let _=typeof e.idKey=="function"?e.idKey(w.values[R[C+1]]):e.idKey;d(k[S],w.values[R[C+1]][_],t.navigationRules.sibling_sibling)}if(!C&&L==="bridgedCousins")if(N!==0){let _=typeof e.idKey=="function"?e.idKey(t.divisions[D[N-1]].values[R[R.length-1]]):e.idKey;d(t.divisions[D[N-1]].values[R[R.length-1]][_],k[S],t.navigationRules.sibling_sibling)}else{let _=typeof e.idKey=="function"?e.idKey(t.divisions[D[D.length-1]].values[R[R.length-1]]):e.idKey;d(t.divisions[D[D.length-1]].values[R[R.length-1]][_],k[S],t.navigationRules.sibling_sibling)}else!C&&L==="bridgedCustom"&&d(t.behavior.customBridgePrevious,k[S],t.navigationRules.sibling_sibling)}else if(N===D.length-1&&L==="bridgedCustom")d(k[S],t.behavior.customBridgePost,t.navigationRules.sibling_sibling);else if(!N&&L==="bridgedCustom")d(t.behavior.customBridgePrevious,k[S],t.navigationRules.sibling_sibling);else{let _=N===D.length-1&&L==="circular"?t.divisions[D[0]]:t.divisions[D[N+1]];if(_){let M=T(C,k[S],w,_);if(M){let he=typeof e.idKey=="function"?e.idKey(M):e.idKey;d(k[S],M[he],t.navigationRules.sibling_sibling)}}}C++}),N++})})}return Object.keys(a).forEach(n=>{var l;let o=a[n];(l=e.genericEdges)!=null&&l.length&&e.genericEdges.forEach(u=>{c[u.edgeId]||(c[u.edgeId]=u.edge),(!u.conditional||u.conditional&&u.conditional(o,u))&&o.edges.push(u.edgeId)})}),c},ve=(e,a,i)=>{var h,d,B,P;let c=e.navigationRules;if(!c){let m=Object.keys(i||{});m.length>6&&console.error(`Building navigationRules. Dimension count is too high to automatically generate key commands. It is recommend you reduce your dimensions to 6 or fewer for end-user experience. If not, you must provide your own navigation rules in options.navigationRules. Details: Count is ${m.length}. Dimensions counted: ${m.join(", ")}.`);let s={},b={},I={},r=[...re],x=[...se],j=(p,n)=>{let o=p&&n,l=!1,u=!1;if((s[p]||b[p])&&(b[p]=F({},s[p]),l=!0),n&&(s[n]||b[n])&&(b[n]=F({},s[n]),u=!0),o&&!l&&!u){r.length||console.error("Building navigationRules. Dimension count is too high to automatically generate key commands, we have run out of keyboard key pairs to assign. You must either provide your own navigation rules in options.navigationRules, provide rules when generating dimensions, or reduce dimension count.");let y=[...r.shift()];x.splice(x.indexOf(y[0]),1),x.splice(x.indexOf(y[1]),1),b[p]={direction:e.useDirectedEdges?"target":"source",key:y[0]},b[n]={direction:"target",key:y[1]}}else{if(!b[p]&&x.length){let y=x.shift(),g=[];r.forEach(f=>{y!==f[0]&&y!==f[1]&&g.push(f)}),r=g,b[p]={direction:e.useDirectedEdges?"target":"source",key:y}}if(n&&!b[n]&&x.length){let y=x.shift(),g=[];r.forEach(f=>{y!==f[0]&&y!==f[1]&&g.push(f)}),r=g,b[n]={direction:"target",key:y}}x.length||(b[p]||(I[p]=p),n&&!b[n]&&(I[n]=n))}};if(Object.keys(H).forEach(p=>{let n=F({},H[p]);e.useDirectedEdges&&(n.direction="target"),s[p]=n}),m.length){if((d=(h=e.dimensions)==null?void 0:h.parentOptions)!=null&&d.addLevel0){let p=((P=(B=e.dimensions.parentOptions.level1Options)==null?void 0:B.navigationRules)==null?void 0:P.parent_child)||["parent","child"];j(p[0],p[1])}m.forEach(p=>{let n=i[p].navigationRules.parent_child,o=i[p].navigationRules.sibling_sibling;j(n[0],n[1]),j(o[0],o[1])})}if(Object.keys(a).forEach(p=>{a[p].navigationRules.forEach(n=>{b[n]||j(n)})}),Object.keys(I).length){let p={};Object.keys(b).forEach(o=>{p[b[o].key]=b[o].key}),Object.keys(s).forEach(o=>{!p[s[o].key]&&!ne[s[o].key]&&x.push(s[o].key)});let n=F({},I);I={},Object.keys(n).forEach(o=>{j(o)}),Object.keys(I).length&&console.error(`Building navigationRules. There are no more keys left to assign automatically. Recommended fixes: use fewer dimensions, use fewer GenericEdges, or build your own navigationRules. Rules remaining without keyboard keys: ${Object.keys(I).join(", ")}.`)}c=b}return c},ye=e=>{e.addIds&&ce(e);let a=ue(e),i=ge(e,a),c=fe(e,a,i),h=ve(e,c,i);return{nodes:a,edges:c,dimensions:i,navigationRules:h}};0&&(module.exports={addSimpleDataIDs,buildEdges,buildNodeStructureFromVegaLite,buildNodes,buildRules,buildStructure,scaffoldDimensions});
|