-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata-navigator.ts
291 lines (232 loc) · 8.28 KB
/
data-navigator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
export type StructureOptions = {
data: GenericDataset;
idKey: DynamicNodeIdKey;
renderIdKey?: DynamicRenderIdKey;
dimensions?: DimensionOptions;
genericEdges?: EdgeOptions;
useDirectedEdges?: boolean;
dataType?: DataType;
addIds?: boolean;
keysForIdGeneration?: KeyList;
navigationRules?: NavigationRules;
};
export type InputOptions = {
structure: Structure;
navigationRules: NavigationRules;
entryPoint?: NodeId;
exitPoint?: RenderId;
};
export type RenderingOptions = {
elementData: ElementData | Nodes;
suffixId: string;
root: RootObject;
defaults?: RenderObject;
entryButton?: EntryObject;
exitElement?: ExitObject;
};
export type DimensionOptions = {
values: DimensionList;
parentOptions?: {
level1Options?: {
order: AddOrReferenceNodeList;
behavior?: Level1Behavior;
navigationRules?: DimensionNavigationRules;
};
addLevel0?: NodeObject;
};
adjustDimensions?: AdjustingFunction;
};
export type Structure = {
nodes: Nodes;
edges: Edges;
dimensions?: Dimensions;
navigationRules?: NavigationRules;
elementData?: ElementData;
};
export type Nodes = Record<NodeId, NodeObject>;
export type Edges = Record<EdgeId, EdgeObject>;
export type Dimensions = Record<DimensionKey, DimensionObject>;
export type NavigationRules = Record<NavId, NavObject>;
export type ElementData = Record<RenderId, RenderObject>;
export type DimensionDivisions = Record<NodeId, DivisionObject>;
export type AddOrReferenceNodeList = Array<NodeToAddOrReference>;
export type EdgeList = Array<EdgeId>;
export type GenericDataset = Array<DatumObject>;
export type NavigationList = Array<NavId>;
export type DimensionNavigationPair = [NavId, NavId];
export type NumericalExtentsPair = [number, number];
export type DimensionList = Array<DimensionDatum>;
export type EdgeOptions = Array<EdgeDatum>;
export type KeyList = Array<string>;
export type Semantics = ((RenderObject?, DatumObject?) => SemanticsObject) | SemanticsObject;
export type SpatialProperties = ((RenderObject?, DatumObject?) => SpatialObject) | SpatialObject;
export type Attributes = ((RenderObject?, DatumObject?) => AttributesObject) | AttributesObject;
export type NodeObject = {
id: NodeId;
edges: EdgeList;
renderId?: RenderId;
renderingStrategy?: RenderingStrategy;
derivedNode?: DerivedNode;
dimensionLevel?: DimensionLevel;
[key: string | number]: any; // NodeObjects can be lazily used as generic objects (like ElementObjects) too
};
export type EdgeObject = {
source: (() => NodeId) | NodeId;
target: (() => NodeId) | NodeId;
navigationRules: NavigationList;
edgeId?: EdgeId;
};
export type EdgeDatum = {
edgeId: EdgeId;
edge: EdgeObject;
conditional?: ConditionalFunction;
};
// output
export type DimensionObject = {
nodeId: NodeId;
dimensionKey: DimensionKey;
divisions: DimensionDivisions;
operations: {
compressSparseDivisions: boolean; // if no division more than 1 child, create 1 division with all children, runs after filtering and sorting
sortFunction?: SortingFunction; // by default sorts numerical in ascending, does not sort categorical
};
behavior?: DimensionBehavior;
navigationRules?: DimensionNavigationRules;
type?: DimensionType;
numericalExtents?: NumericalExtentsPair;
subdivisions?: NumericallySubdivide;
divisionOptions?: DivisionOptions;
};
// input
export type DimensionDatum = {
dimensionKey: DimensionKey;
behavior?: DimensionBehavior;
navigationRules?: DimensionNavigationRules;
type?: DimensionType;
operations?: DimensionOperations;
nodeId?: DynamicDimensionId;
renderId?: DynamicDimensionRenderId;
renderingStrategy?: RenderingStrategy;
divisionOptions?: DivisionOptions;
};
export type DimensionNavigationRules = {
sibling_sibling: DimensionNavigationPair;
parent_child: DimensionNavigationPair;
};
export type DivisionOptions = {
sortFunction?: SortingFunction; // by default does not sort
divisionNodeIds?: (dimensionKey: DimensionKey, keyValue: any, i: number) => string;
divisionRenderIds?: (dimensionKey: DimensionKey, keyValue: any, i: number) => string;
renderingStrategy?: RenderingStrategy;
};
export type DimensionOperations = {
filterFunction?: FilteringFunction;
sortFunction?: SortingFunction; // by default sorts numerical in ascending, does not sort categorical
createNumericalSubdivisions?: NumericallySubdivide; // (if not set, defaults to 1)
compressSparseDivisions?: boolean; // if no division more than 1 child, create 1 division with all children, runs after filtering and sorting
};
export type DivisionObject = {
id: NodeId;
values: Nodes;
sortFunction?: SortingFunction; // by default does not sort
};
export type NavObject = {
direction: Direction;
key?: string;
};
export type RenderObject = {
cssClass?: DynamicString;
spatialProperties?: SpatialProperties;
semantics?: Semantics;
parentSemantics?: Semantics;
existingElement?: ExistingElement;
showText?: boolean;
};
export type RootObject = {
id: string;
cssClass?: string;
description?: string;
width?: string | number;
height?: string | number;
};
export type EntryObject = {
include: boolean;
callbacks?: EntryCallbacks;
};
export type ExitObject = {
include: boolean;
callbacks?: ExitCallbacks;
};
export type SemanticsObject = {
label?: DynamicString;
elementType?: DynamicString;
role?: DynamicString;
attributes?: Attributes;
};
export type SpatialObject = {
x?: DynamicNumber;
y?: DynamicNumber;
width?: DynamicNumber;
height?: DynamicNumber;
path?: DynamicString;
};
export type DimensionBehavior = {
extents: ExtentType;
customBridgePrevious?: NodeId;
customBridgePost?: NodeId;
};
export type Level1Behavior = {
extents: Level0ExtentType;
customBridgePrevious?: NodeId;
customBridgePost?: NodeId;
};
export type DescriptionOptions = {
omitKeyNames?: boolean;
semanticLabel?: string;
};
export type ExistingElement = {
useForSpatialProperties: boolean;
spatialProperties?: SpatialProperties;
};
export type EntryCallbacks = {
focus?: Function;
click?: Function;
};
export type ExitCallbacks = {
focus?: Function;
blur?: Function;
};
export type DatumObject = {
[key: string | number]: any;
};
export type AttributesObject = {
[key: string]: string;
};
export type DynamicNumber = ((r?: RenderObject, d?: DatumObject) => number) | number;
export type DynamicString = ((r?: RenderObject, d?: DatumObject) => string) | string;
export type DynamicNodeId = ((d?: DatumObject, dim?: DimensionDatum) => NodeId) | NodeId;
export type DynamicRenderId = ((d?: DatumObject) => RenderId) | RenderId;
export type DynamicNodeIdKey = ((d?: DatumObject) => string) | string;
export type DynamicRenderIdKey = ((d?: DatumObject) => string) | string;
export type DynamicDimensionId = ((d?: DimensionDatum, a?: GenericDataset) => NodeId) | NodeId;
export type DynamicDimensionRenderId = ((d?: DimensionDatum, a?: GenericDataset) => RenderId) | RenderId;
export type NumericallySubdivide = ((d?: DimensionKey, n?: Nodes) => number) | number;
export type AdjustingFunction = (d: Dimensions) => Dimensions;
export type SortingFunction = (a: DatumObject, b: DatumObject, c?: any) => number;
export type FilteringFunction = (a: DatumObject, b?: any) => boolean;
export type ConditionalFunction = (n: NodeObject, d: EdgeDatum) => boolean;
export type NodeId = string;
export type EdgeId = string;
export type RenderId = string;
export type NavId = string;
export type DimensionId = string;
export type DimensionKey = string;
export type NodeToAddOrReference = NodeObject | NodeId;
export type Direction = 'target' | 'source';
export type RenderingStrategy = 'outlineEach' | 'convexHull' | 'singleSquare' | 'custom'; // this has yet to be implemented!
export type DimensionType = 'numerical' | 'categorical';
export type ExtentType = 'circular' | 'terminal' | 'bridgedCousins' | 'bridgedCustom';
export type Level0ExtentType = 'circular' | 'terminal' | 'bridgedCustom';
export type DataType = 'vega-lite' | 'vl' | 'Vega-Lite' | 'generic' | 'default';
export type DimensionLevel = 0 | 1 | 2 | 3;
export type DerivedNode = string;