mascot-vis 3.0.0 → 3.0.2
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/mascot-esm.js +186 -0
- package/package.json +3 -6
- package/dist/mascot-es.js +0 -27745
- package/dist/mascot-min.js +0 -186
- package/dist/mascot-umd.js +0 -27781
- package/js/depGraphVis.js +0 -66
- package/src-new-ts/action/createElement.ts +0 -91
- package/src-new-ts/action/encode.js +0 -20
- package/src-new-ts/action/repeat.js +0 -128
- package/src-new-ts/action/traverseScene.js +0 -41
- package/src-new-ts/data/Network.js +0 -2
- package/src-new-ts/data/Scope.js +0 -135
- package/src-new-ts/data/Table.js +0 -263
- package/src-new-ts/data/Tree.js +0 -3
- package/src-new-ts/data/field.ts +0 -115
- package/src-new-ts/data/import.ts +0 -96
- package/src-new-ts/data/predicate.ts +0 -82
- package/src-new-ts/depgraph/DepGraph.js +0 -178
- package/src-new-ts/depgraph/Edge.js +0 -9
- package/src-new-ts/depgraph/SceneGraph2DepGraph.js +0 -110
- package/src-new-ts/depgraph/Signal.js +0 -12
- package/src-new-ts/depgraph/operator/BoundsEvaluator.js +0 -30
- package/src-new-ts/depgraph/operator/Dataflow.js +0 -41
- package/src-new-ts/depgraph/operator/DomainBuilder.js +0 -50
- package/src-new-ts/depgraph/updateDepGraph.js +0 -45
- package/src-new-ts/depgraph/variable/BoundsVar.js +0 -81
- package/src-new-ts/depgraph/variable/ChannelVar.js +0 -17
- package/src-new-ts/depgraph/variable/DataScopeVar.js +0 -12
- package/src-new-ts/depgraph/variable/DomainVar.js +0 -15
- package/src-new-ts/depgraph/variable/FieldVar.js +0 -17
- package/src-new-ts/depgraph/variable/LayoutParameter.js +0 -8
- package/src-new-ts/depgraph/variable/ScaleVar.js +0 -13
- package/src-new-ts/depgraph/variable/Variable.js +0 -39
- package/src-new-ts/element/gradient/LinearGradient.js +0 -37
- package/src-new-ts/element/group/Collection.js +0 -109
- package/src-new-ts/element/group/Group.js +0 -307
- package/src-new-ts/element/group/Scene.js +0 -98
- package/src-new-ts/element/mark/CircleMark.ts +0 -85
- package/src-new-ts/element/mark/Mark.ts +0 -233
- package/src-new-ts/element/mark/PathMark.js +0 -483
- package/src-new-ts/element/mark/Segment.js +0 -29
- package/src-new-ts/element/mark/Vertex.js +0 -118
- package/src-new-ts/encode/Scale.ts +0 -115
- package/src-new-ts/index.ts +0 -19
- package/src-new-ts/layout/Layout.ts +0 -3
- package/src-new-ts/render/CanvasRenderer.ts +0 -24
- package/src-new-ts/render/SVGRenderer.js +0 -316
- package/src-new-ts/util.ts +0 -3
- package/src-old/action/Classify.js +0 -53
- package/src-old/action/Densify.js +0 -199
- package/src-old/action/Partition.js +0 -531
- package/src-old/action/Repeat.js +0 -106
- package/src-old/action/Repopulate.js +0 -44
- package/src-old/action/Stratify.js +0 -156
- package/src-old/basic/Gradient.js +0 -37
- package/src-old/basic/Point.js +0 -51
- package/src-old/basic/Rectangle.js +0 -63
- package/src-old/bind/bindToAngle.js +0 -56
- package/src-old/bind/bindToAreaMark.js +0 -360
- package/src-old/bind/bindToColor.js +0 -114
- package/src-old/bind/bindToLink.js +0 -81
- package/src-old/bind/bindToPosition.js +0 -283
- package/src-old/bind/bindToRadialDistance.js +0 -62
- package/src-old/bind/bindToSize.js +0 -235
- package/src-old/bind/bindToText.js +0 -60
- package/src-old/bind/bindToThickness.js +0 -100
- package/src-old/constraint/AffixConstraint.js +0 -129
- package/src-old/constraint/AlignConstraint.js +0 -58
- package/src-old/core/Encoding.js +0 -336
- package/src-old/core/Scale.js +0 -322
- package/src-old/core/SceneLoader.js +0 -290
- package/src-old/core/SceneValidator.js +0 -232
- package/src-old/core/SpecExecutor.js +0 -113
- package/src-old/core/SpecGenerator.js +0 -350
- package/src-old/data/DataImporter.js +0 -64
- package/src-old/data/DataScope.js +0 -124
- package/src-old/data/DataTable.js +0 -338
- package/src-old/data/Network.js +0 -106
- package/src-old/data/Tree.js +0 -251
- package/src-old/data/transform/Bin.js +0 -46
- package/src-old/data/transform/Filter.js +0 -48
- package/src-old/data/transform/Groupby.js +0 -18
- package/src-old/data/transform/KDE.js +0 -58
- package/src-old/data/transform/Sort.js +0 -14
- package/src-old/data/transform/Split.js +0 -5
- package/src-old/data/transform/partition.js +0 -46
- package/src-old/history/UndoRedoStack +0 -0
- package/src-old/index.js +0 -271
- package/src-old/indexSVG.js +0 -259
- package/src-old/interaction/Interaction.js +0 -91
- package/src-old/interaction/MouseEvent.js +0 -8
- package/src-old/interaction/Selection.js +0 -9
- package/src-old/interaction/brush.js +0 -362
- package/src-old/item/Segment.js +0 -29
- package/src-old/item/Vertex.js +0 -118
- package/src-old/item/composite/Collection.js +0 -106
- package/src-old/item/composite/Glyph.js +0 -19
- package/src-old/item/composite/Group.js +0 -310
- package/src-old/item/composite/Scene.js +0 -1251
- package/src-old/item/mark/ArcPath.js +0 -181
- package/src-old/item/mark/AreaPath.js +0 -78
- package/src-old/item/mark/CirclePath.js +0 -102
- package/src-old/item/mark/EllipsePath.js +0 -5
- package/src-old/item/mark/Image.js +0 -101
- package/src-old/item/mark/LinkPath.js +0 -118
- package/src-old/item/mark/Mark.js +0 -163
- package/src-old/item/mark/Path.js +0 -494
- package/src-old/item/mark/PointText.js +0 -201
- package/src-old/item/mark/PolygonPath.js +0 -64
- package/src-old/item/mark/RectPath.js +0 -88
- package/src-old/item/mark/RingPath.js +0 -92
- package/src-old/item/refs/Axis.js +0 -362
- package/src-old/item/refs/EncodingAxis.js +0 -515
- package/src-old/item/refs/Gridlines.js +0 -144
- package/src-old/item/refs/LayoutAxis.js +0 -316
- package/src-old/item/refs/Legend.js +0 -273
- package/src-old/layout/Circular.js +0 -95
- package/src-old/layout/Force.js +0 -52
- package/src-old/layout/Grid.js +0 -423
- package/src-old/layout/Layout.js +0 -13
- package/src-old/layout/Packing.js +0 -56
- package/src-old/layout/Stack.js +0 -264
- package/src-old/layout/Strata.js +0 -88
- package/src-old/layout/Sugiyama.js +0 -59
- package/src-old/layout/TidyTree.js +0 -105
- package/src-old/layout/Treemap.js +0 -87
- package/src-old/renderer/SVGInteractionHandler.js +0 -241
- package/src-old/renderer/SVGRenderer.js +0 -325
- package/src-old/renderer/WebGLRenderer.js +0 -1097
- package/src-old/renderer/WebGLRenderer2.js +0 -249
- package/src-old/renderer/threejs/Line2.js +0 -18
- package/src-old/renderer/threejs/LineGeometry.js +0 -77
- package/src-old/renderer/threejs/LineMaterial.js +0 -605
- package/src-old/renderer/threejs/LineSegments2.js +0 -281
- package/src-old/renderer/threejs/LineSegmentsGeometry.js +0 -226
- package/src-old/renderer/threejs/Wireframe.js +0 -51
- package/src-old/renderer/threejs/WireframeGeometry2.js +0 -16
- package/src-old/scale/areaSize.js +0 -0
- package/src-old/scale/domain.js +0 -38
- package/src-old/util/Constants.js +0 -180
- package/src-old/util/DataUtil.js +0 -35
- package/src-old/util/ItemUtil.js +0 -586
- package/src-old/util/Numerical.js +0 -33
- package/tests/demo-tests/README.md +0 -80
- package/tests/demo-tests/SVG2PNG.js +0 -56
- package/tests/demo-tests/demos2CanvasPNGs.js +0 -69
- package/tests/demo-tests/demos2ScenesSVGs.js +0 -100
- package/tests/demo-tests/pathElementWorker.js +0 -91
- package/tests/demo-tests/pixelTest.js +0 -62
- package/tests/demo-tests/renderDemos.html +0 -132
- package/tests/demo-tests/serializationTest.js +0 -36
- package/tests/demo-tests/serializeDemos.html +0 -134
- package/tests/unit-tests/README.md +0 -4
- package/tests/unit-tests/jasmine-browser.json +0 -21
- package/tests/unit-tests/jasmine.json +0 -14
- package/tests/unit-tests/testSpec.js +0 -274
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import LayoutAxis from "../item/refs/LayoutAxis";
|
|
2
|
-
import { LayoutType, Orientation } from "../util/Constants";
|
|
3
|
-
import { getEncodingKey, getPeers, isGuide } from "../util/ItemUtil";
|
|
4
|
-
|
|
5
|
-
const SceneValidator = {
|
|
6
|
-
|
|
7
|
-
itemTranslated: function(item, dx, dy) {
|
|
8
|
-
let scene = item.getScene();
|
|
9
|
-
if (!isGuide(item))
|
|
10
|
-
scene._reapplyConstraints(item);
|
|
11
|
-
|
|
12
|
-
let axes = scene.getRelatedAxes(item);
|
|
13
|
-
axes.forEach(a => {
|
|
14
|
-
if (a.encoding && a.encoding.scale.offset !== undefined)
|
|
15
|
-
a.encoding.scale.offset += a.channel === "x" || a.channel === "width" ? dx : dy;
|
|
16
|
-
if (dy !== 0 && (a.channel === "x" || a.channel === "width") && a._posArg !== undefined) {
|
|
17
|
-
a._posArg = a._posArg + dy;
|
|
18
|
-
}
|
|
19
|
-
if (dx !== 0 && (a.channel === "y" || a.channel === "height") && a._posArg !== undefined) {
|
|
20
|
-
a._posArg = a._posArg + dx;
|
|
21
|
-
}
|
|
22
|
-
a.reposition();
|
|
23
|
-
});
|
|
24
|
-
let gl = scene.getRelatedGridlines(item);
|
|
25
|
-
gl.forEach(l => l.updateLinePositions());
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
layoutChanged: function(item, peers, props) {
|
|
29
|
-
let scene = item.getScene();
|
|
30
|
-
scene._relayoutAncestors(item, peers);
|
|
31
|
-
|
|
32
|
-
let items = [item], c = item.firstChild
|
|
33
|
-
while (c) {
|
|
34
|
-
items.push(c);
|
|
35
|
-
c = c.firstChild;
|
|
36
|
-
}
|
|
37
|
-
for (let i of items)
|
|
38
|
-
i.getScene()._reapplyConstraints(i);
|
|
39
|
-
|
|
40
|
-
let reGenerateAxes = false;
|
|
41
|
-
for (let p of props) {
|
|
42
|
-
if (["numRows", "numCols", "layout", "childrenOrder"].indexOf(p) >= 0) {
|
|
43
|
-
reGenerateAxes = true;
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
//if grid layout changes to a single column or row, or stack layout's orientation changes, update axis channel
|
|
49
|
-
let updateChannel = false, channel;
|
|
50
|
-
if (item.layout) {
|
|
51
|
-
if (item.layout.type === LayoutType.Grid && (item.layout.numRows === 1 || item.layout.numCols === 1)) {
|
|
52
|
-
updateChannel = true;
|
|
53
|
-
channel = item.layout.numRows === 1 ? "x" : "y";
|
|
54
|
-
} else if (item.layout.type === LayoutType.Stack && props.indexOf("orientation") >= 0) {
|
|
55
|
-
updateChannel = true;
|
|
56
|
-
channel = item.layout.orientation === Orientation.Horizontal ? "x" : "y";
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (updateChannel) {
|
|
60
|
-
let axes = scene.getRelatedAxes(item).filter(d => d instanceof LayoutAxis && d._item.parent.classId === item.classId);
|
|
61
|
-
for (let a of axes) {
|
|
62
|
-
scene.removeItem(a);
|
|
63
|
-
let args = a.toJSON().args;
|
|
64
|
-
delete args["orientation"];
|
|
65
|
-
args.item = item.firstChild;
|
|
66
|
-
scene.axis(channel, a.field, args);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (reGenerateAxes) {
|
|
71
|
-
scene.reCreateRelatedAxes(item);
|
|
72
|
-
} else {
|
|
73
|
-
let axes = scene.getRelatedAxes(item);
|
|
74
|
-
axes.forEach(a => a.reposition());
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
let gl = scene.getRelatedGridlines(item);
|
|
78
|
-
gl.forEach(l => l.updateLinePositions());
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
scaleDomainSet: function(scale) {
|
|
82
|
-
for (let enc of scale.encodings) {
|
|
83
|
-
enc._map();
|
|
84
|
-
enc._apply();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
for (let enc of scale.encodings) {
|
|
88
|
-
enc.scene._updateAncestorBounds(enc.item, enc.items);
|
|
89
|
-
}
|
|
90
|
-
//reapply constraints
|
|
91
|
-
let items = scale.encodings.map( d => d.anyItem), classId2item = {};
|
|
92
|
-
for (let item of items) {
|
|
93
|
-
if (item.type === "vertex" || item.type === "segment")
|
|
94
|
-
classId2item[item.parent.classId] = item.parent;
|
|
95
|
-
else
|
|
96
|
-
classId2item[item.classId] = item;
|
|
97
|
-
}
|
|
98
|
-
for (let i of Object.values(classId2item))
|
|
99
|
-
i.getScene()._reapplyConstraints(i);
|
|
100
|
-
|
|
101
|
-
for (let enc of scale.encodings) {
|
|
102
|
-
let item = enc.anyItem;
|
|
103
|
-
let axes = enc.scene.getRelatedAxes(item);
|
|
104
|
-
for (let a of axes) {
|
|
105
|
-
if (a.encoding && a.encoding.scale === scale) {
|
|
106
|
-
a.tickValues = enc._inferTickValues(enc);
|
|
107
|
-
a.labelValues = enc._inferTickValues(enc);
|
|
108
|
-
a._positionPath();
|
|
109
|
-
if (a._showTitle)
|
|
110
|
-
a._positionTitle();
|
|
111
|
-
if (a._channel === "radialDistance" && a._rotate){
|
|
112
|
-
a._rotate = [a._rotate[0], a._item.parent.x, a._item.parent.y];
|
|
113
|
-
}
|
|
114
|
-
a._updateBounds();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
let gl = enc.scene.getRelatedGridlines(item);
|
|
118
|
-
gl.forEach(l => l.updateLinePositions());
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
scaleRangeSet: function(scale) {
|
|
123
|
-
for (let enc of scale.encodings) {
|
|
124
|
-
//enc._map();
|
|
125
|
-
enc._apply();
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
for (let enc of scale.encodings) {
|
|
129
|
-
enc.scene._relayoutAncestors(enc.item, enc.items);
|
|
130
|
-
}
|
|
131
|
-
//reapply constraints
|
|
132
|
-
let items = scale.encodings.map( d => d.anyItem), classId2item = {};
|
|
133
|
-
for (let item of items) {
|
|
134
|
-
if (item.type === "vertex" || item.type === "segment")
|
|
135
|
-
classId2item[item.parent.classId] = item.parent;
|
|
136
|
-
else
|
|
137
|
-
classId2item[item.classId] = item;
|
|
138
|
-
}
|
|
139
|
-
for (let i of Object.values(classId2item))
|
|
140
|
-
i.getScene()._reapplyConstraints(i);
|
|
141
|
-
|
|
142
|
-
for (let enc of scale.encodings) {
|
|
143
|
-
let item = enc.anyItem;
|
|
144
|
-
let axes = enc.scene.getRelatedAxes(item);
|
|
145
|
-
axes.forEach(a => a.reposition());
|
|
146
|
-
let gl = enc.scene.getRelatedGridlines(item);
|
|
147
|
-
gl.forEach(l => l.updateLinePositions());
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
itemResized: function(item, peers) {
|
|
152
|
-
let scene = item.getScene();
|
|
153
|
-
scene._relayoutAncestors(item, peers);
|
|
154
|
-
scene._reapplyConstraints(item);
|
|
155
|
-
let axes = scene.getRelatedAxes(item);
|
|
156
|
-
axes.forEach(a => a.reposition());
|
|
157
|
-
let gl = scene.getRelatedGridlines(item);
|
|
158
|
-
gl.forEach(l => l.updateLinePositions());
|
|
159
|
-
},
|
|
160
|
-
|
|
161
|
-
markDivided: function(path, collection) {
|
|
162
|
-
//update axis item argument
|
|
163
|
-
let scene = collection.getScene();
|
|
164
|
-
let axes = scene.getRelatedAxes(path);
|
|
165
|
-
for (let a of axes) {
|
|
166
|
-
if (a._item.classId === path.classId) {
|
|
167
|
-
a._item = collection;
|
|
168
|
-
a._items = getPeers(collection, scene);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
//update encoding item
|
|
173
|
-
let e = scene.encodings[getEncodingKey(path)];
|
|
174
|
-
if (e) {
|
|
175
|
-
scene.encodings[getEncodingKey(collection)] = {};
|
|
176
|
-
for (let channel of ["x", "y"]) {
|
|
177
|
-
const enc = e[channel];
|
|
178
|
-
if (!enc)
|
|
179
|
-
continue;
|
|
180
|
-
enc.anyItem = collection;
|
|
181
|
-
enc.items = getPeers(collection, scene);
|
|
182
|
-
scene.encodings[getEncodingKey(collection)][channel] = enc;
|
|
183
|
-
delete scene.encodings[getEncodingKey(path)][channel];
|
|
184
|
-
}
|
|
185
|
-
if (Object.keys(e).length === 0)
|
|
186
|
-
delete scene.encodings[getEncodingKey(path)];
|
|
187
|
-
}
|
|
188
|
-
//TODO: update constraints
|
|
189
|
-
},
|
|
190
|
-
|
|
191
|
-
markDensified: function(item, newItem) {
|
|
192
|
-
let scene = newItem.getScene();
|
|
193
|
-
let e = scene.encodings[getEncodingKey(item)];
|
|
194
|
-
if (e) {
|
|
195
|
-
scene.encodings[getEncodingKey(newItem)] = {};
|
|
196
|
-
for (let channel of ["x", "y"]) {
|
|
197
|
-
const enc = e[channel];
|
|
198
|
-
if (!enc)
|
|
199
|
-
continue;
|
|
200
|
-
enc.anyItem = newItem;
|
|
201
|
-
enc.items = getPeers(newItem, scene);
|
|
202
|
-
scene.encodings[getEncodingKey(newItem)][channel] = enc;
|
|
203
|
-
delete scene.encodings[getEncodingKey(item)][channel];
|
|
204
|
-
}
|
|
205
|
-
if (Object.keys(e) === 0)
|
|
206
|
-
delete scene.encodings[getEncodingKey(item)];
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
let axes = scene.getRelatedAxes(item);
|
|
210
|
-
for (let a of axes) {
|
|
211
|
-
if (a._item.classId === item.classId) {
|
|
212
|
-
a._item = newItem;
|
|
213
|
-
a._items = getPeers(newItem, scene);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
//TODO: update constraints
|
|
217
|
-
},
|
|
218
|
-
|
|
219
|
-
areaRebased: function(item) {
|
|
220
|
-
let scene = item.getScene();
|
|
221
|
-
let encodings = scene.encodings[getEncodingKey(item)];
|
|
222
|
-
for (let channel in encodings) {
|
|
223
|
-
encodings[channel]._apply();
|
|
224
|
-
}
|
|
225
|
-
let axes = scene.getRelatedAxes(item);
|
|
226
|
-
axes.forEach(a => a.reposition());
|
|
227
|
-
let gl = scene.getRelatedGridlines(item);
|
|
228
|
-
gl.forEach(l => l.updateLinePositions());
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
export default SceneValidator;
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { importCSV } from "../data/DataImporter";
|
|
2
|
-
import Scene from "../item/composite/Scene";
|
|
3
|
-
import { ConstraintType } from "../util/Constants";
|
|
4
|
-
import { getLayout } from "../util/ItemUtil";
|
|
5
|
-
import Scale from "./Scale";
|
|
6
|
-
|
|
7
|
-
export default class SpecExecutor {
|
|
8
|
-
|
|
9
|
-
constructor() {
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async run(spec) {
|
|
14
|
-
let scn;
|
|
15
|
-
let itmHash = {}, dataHash = {}, scales = {};
|
|
16
|
-
let data;
|
|
17
|
-
// console.log("spec");
|
|
18
|
-
for (let c of spec) {
|
|
19
|
-
//console.log(c);
|
|
20
|
-
switch (c.cmd) {
|
|
21
|
-
case "scene":
|
|
22
|
-
scn = new Scene(c.args);
|
|
23
|
-
break;
|
|
24
|
-
case "data":
|
|
25
|
-
data = await importCSV(c.url);
|
|
26
|
-
dataHash[c.output] = data;
|
|
27
|
-
break;
|
|
28
|
-
case "transform":
|
|
29
|
-
dataHash[c.output] = dataHash[c.input].transform(c.type, c.args);
|
|
30
|
-
break;
|
|
31
|
-
case "mark":
|
|
32
|
-
itmHash[c.output] = scn.mark(c.type, c.args);
|
|
33
|
-
break;
|
|
34
|
-
case "glyph":
|
|
35
|
-
itmHash[c.output] = scn.glyph(...c.input.map(d => itmHash[d]));
|
|
36
|
-
break;
|
|
37
|
-
case "attach":
|
|
38
|
-
scn.attach(itmHash[c.input], dataHash[c.data]);
|
|
39
|
-
break;
|
|
40
|
-
case "repeat": {
|
|
41
|
-
let coll = scn.repeat(itmHash[c.input], dataHash[c.data], c.args);
|
|
42
|
-
itmHash[c.output] = coll;
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
case "divide": {
|
|
46
|
-
let coll = scn.divide(itmHash[c.input], dataHash[c.data], c.args);
|
|
47
|
-
itmHash[c.output] = coll;
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
case "layout":
|
|
51
|
-
itmHash[c.input].layout = getLayout(c.type, c.args);
|
|
52
|
-
break;
|
|
53
|
-
case "sortChildren":
|
|
54
|
-
if ("field" in c.args)
|
|
55
|
-
itmHash[c.input].sortChildrenByData(c.args.field, c.args.reverse, c.args.order);
|
|
56
|
-
else if ("channel" in c.args)
|
|
57
|
-
itmHash[c.input].sortChildren(c.args.channel, c.args.reverse);
|
|
58
|
-
break;
|
|
59
|
-
case "scale": {
|
|
60
|
-
let scale = new Scale(c.type);
|
|
61
|
-
scale.id = c.id;
|
|
62
|
-
scale.domain = c.type == "time" ? c.domain.map(d => new Date(d)) : c.domain;
|
|
63
|
-
scale.range = c.range;
|
|
64
|
-
scale.clamp = c.clamp;
|
|
65
|
-
scale.isFlipped = c.isFlipped;
|
|
66
|
-
if ("offset" in c)
|
|
67
|
-
scale.offset = c.offset;
|
|
68
|
-
scales[scale.id] = scale;
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
case "encode": {
|
|
72
|
-
let itm, encKey = c.input;
|
|
73
|
-
if (encKey.indexOf("_v_") > 0) {
|
|
74
|
-
let idx = parseInt(encKey.split("_v_")[1]);
|
|
75
|
-
itm = itmHash[encKey.split("_v_")[0]].vertices[idx];
|
|
76
|
-
} else if (encKey.indexOf("_v") > 0) {
|
|
77
|
-
//TODO
|
|
78
|
-
} else if (encKey.indexOf("_s_") > 0) {
|
|
79
|
-
let idx = parseInt(encKey.split("_s_")[1]);
|
|
80
|
-
itm = itmHash[encKey.split("_s_")[0]].segments[idx];
|
|
81
|
-
} else if (encKey.indexOf("_s") > 0) {
|
|
82
|
-
//TODO
|
|
83
|
-
} else {
|
|
84
|
-
itm = itmHash[c.input];
|
|
85
|
-
}
|
|
86
|
-
if(c.scale && scales[c.scale])
|
|
87
|
-
c.args.scale = scales[c.scale];
|
|
88
|
-
scn.encode(itm, c.args);
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
case "constraint":
|
|
92
|
-
switch (c.type) {
|
|
93
|
-
case ConstraintType.Affix:
|
|
94
|
-
scn.affix(itmHash[c.item], itmHash[c.baseItem], c.channel, c.args);
|
|
95
|
-
break;
|
|
96
|
-
case ConstraintType.Align:
|
|
97
|
-
//TODO
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
break;
|
|
101
|
-
case "axis":
|
|
102
|
-
scn.axis(c.channel, c.field, c.args);
|
|
103
|
-
break;
|
|
104
|
-
case "legend":
|
|
105
|
-
scn.legend(c.channel, c.field, c.args);
|
|
106
|
-
break;
|
|
107
|
-
case "gridlines":
|
|
108
|
-
scn.gridlines(c.channel, c.field, c.args);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return scn;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
@@ -1,350 +0,0 @@
|
|
|
1
|
-
import Collection from "../item/composite/Collection";
|
|
2
|
-
import Glyph from "../item/composite/Glyph";
|
|
3
|
-
import Group from "../item/composite/Group";
|
|
4
|
-
import Mark from "../item/mark/Mark";
|
|
5
|
-
import { atlas_rowId, ConstraintType, ItemType, LayoutType } from "../util/Constants";
|
|
6
|
-
import { getEncodingKey, getPeers } from "../util/ItemUtil";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Generates an array of commands that would reconstruct a given scene
|
|
10
|
-
*/
|
|
11
|
-
export default class SpecGenerator {
|
|
12
|
-
|
|
13
|
-
constructor() {
|
|
14
|
-
this.axes = {};
|
|
15
|
-
this.guideCmds = [];
|
|
16
|
-
this.collectionCmds = [];
|
|
17
|
-
this.glyphCmds = [];
|
|
18
|
-
this.spec = [];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
run(scene) {
|
|
22
|
-
for (let c of scene.children) {
|
|
23
|
-
switch (c.type) {
|
|
24
|
-
case ItemType.Axis: {
|
|
25
|
-
let id = c.classId ? c.classId : c.id;
|
|
26
|
-
this.axes[id] = c;
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
case ItemType.Gridlines:
|
|
30
|
-
case ItemType.Legend:{
|
|
31
|
-
let json = c.toJSON();
|
|
32
|
-
this.guideCmds.push({
|
|
33
|
-
cmd: c.type,
|
|
34
|
-
channel: json.channel,
|
|
35
|
-
field: json.field,
|
|
36
|
-
args: json.args
|
|
37
|
-
});
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
case ItemType.Collection:
|
|
41
|
-
case ItemType.Group:
|
|
42
|
-
case ItemType.Glyph: {
|
|
43
|
-
let struct = [];
|
|
44
|
-
this._analyze(c, struct);
|
|
45
|
-
// console.log("struct", c.type);
|
|
46
|
-
// for (let s of struct)
|
|
47
|
-
// console.log(s);
|
|
48
|
-
for (let i = struct.length - 1; i > 0; i--) {
|
|
49
|
-
for (let f of struct[i].fields)
|
|
50
|
-
struct[i - 1].fields.delete(f);
|
|
51
|
-
}
|
|
52
|
-
for (let [i, s] of struct.entries()) {
|
|
53
|
-
if (s.item instanceof Mark) {
|
|
54
|
-
let m = {
|
|
55
|
-
cmd: "mark",
|
|
56
|
-
type: s.item.type,
|
|
57
|
-
output: s.item,
|
|
58
|
-
args: s.item.toJSON().args
|
|
59
|
-
};
|
|
60
|
-
this._inferMarkArgs(m, scene);
|
|
61
|
-
this.collectionCmds.push(m);
|
|
62
|
-
} else if (s.item instanceof Glyph) {
|
|
63
|
-
this.collectionCmds.push({
|
|
64
|
-
cmd: "glyph",
|
|
65
|
-
output: s.item,
|
|
66
|
-
input: struct.slice(0, i).map(d => d.item),
|
|
67
|
-
args: {}
|
|
68
|
-
})
|
|
69
|
-
} else if (s.item instanceof Collection) {
|
|
70
|
-
let f = [...struct[i-1].fields][0];
|
|
71
|
-
let o = {
|
|
72
|
-
cmd: "join",
|
|
73
|
-
input: struct[i-1].item,
|
|
74
|
-
output: s.item,
|
|
75
|
-
data: struct[i-1].item.dataScope.dataTable.id,
|
|
76
|
-
args: {field: f}
|
|
77
|
-
};
|
|
78
|
-
if (f == atlas_rowId)
|
|
79
|
-
delete o.field;
|
|
80
|
-
this.collectionCmds.push(o);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (s.item.dataScope && s.item.dataScope.fields.length == 0 && !s.item.parent.dataScope) {
|
|
84
|
-
this.collectionCmds.push({
|
|
85
|
-
cmd: "attach",
|
|
86
|
-
input: s.item,
|
|
87
|
-
data: s.item.dataScope.dataTable.id
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
default:
|
|
94
|
-
if (c instanceof Mark) {
|
|
95
|
-
let m = {
|
|
96
|
-
cmd: "mark",
|
|
97
|
-
type: c.type,
|
|
98
|
-
output: c,
|
|
99
|
-
args: c.toJSON().args
|
|
100
|
-
};
|
|
101
|
-
this._inferMarkArgs(m, scene);
|
|
102
|
-
this.glyphCmds.push(m);
|
|
103
|
-
}
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
this._inferJoin();
|
|
109
|
-
this._inferArgs(scene);
|
|
110
|
-
|
|
111
|
-
for (let a in this.axes){
|
|
112
|
-
let json = this.axes[a].toJSON();
|
|
113
|
-
this.guideCmds.push({
|
|
114
|
-
cmd: json.type,
|
|
115
|
-
channel: json.channel,
|
|
116
|
-
field: json.field,
|
|
117
|
-
args: json.args
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// console.log("collection commands");
|
|
122
|
-
// for (let c of this.collectionCmds)
|
|
123
|
-
// console.log(c);
|
|
124
|
-
// console.log("glyphs", this.glyphCmds);
|
|
125
|
-
// console.log("guides", this.guideCmds);
|
|
126
|
-
|
|
127
|
-
this._generateFullSpec(scene);
|
|
128
|
-
return this.spec;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
_inferJoin() {
|
|
132
|
-
for (let c of this.collectionCmds) {
|
|
133
|
-
if (c.cmd != "join") continue;
|
|
134
|
-
let itm = c.input, p = itm.parent;
|
|
135
|
-
switch (itm.type) {
|
|
136
|
-
case ItemType.Rect:
|
|
137
|
-
if (p.layout && p.layout.type == LayoutType.Stack)
|
|
138
|
-
c.cmd = "divide";
|
|
139
|
-
else
|
|
140
|
-
c.cmd = "repeat";
|
|
141
|
-
break;
|
|
142
|
-
default:
|
|
143
|
-
c.cmd = "repeat";
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
_inferArgs(scene) {
|
|
150
|
-
for (let c of this.collectionCmds) {
|
|
151
|
-
switch(c.cmd) {
|
|
152
|
-
case "mark":
|
|
153
|
-
this._inferMarkArgs(c, scene);
|
|
154
|
-
break;
|
|
155
|
-
case "divide":
|
|
156
|
-
this._inferDivideArgs(c, scene);
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
_inferDivideArgs(c) {
|
|
163
|
-
c.args.orientation = c.output.layout.orientation;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
_inferMarkArgs(c, scene) {
|
|
167
|
-
let itm = c.output, p = itm.parent;
|
|
168
|
-
let itmPeers = getPeers(itm, scene), parentPeers = getPeers(p, scene);
|
|
169
|
-
switch (itm.type) {
|
|
170
|
-
case ItemType.Rect:
|
|
171
|
-
if (p.layout && p.layout.type == LayoutType.Grid) {
|
|
172
|
-
c.args.width = p.layout.cellBounds[0].width;
|
|
173
|
-
c.args.height = p.layout.cellBounds[0].height;
|
|
174
|
-
} else if (p.layout && p.layout.type == LayoutType.Stack) {
|
|
175
|
-
c.args.width = Math.max(...parentPeers.map(d => d.bounds.width));
|
|
176
|
-
c.args.height = Math.max(...parentPeers.map(d => d.bounds.height));
|
|
177
|
-
} else {
|
|
178
|
-
c.args.width = Math.max(...itmPeers.map(d => d.bounds.width));
|
|
179
|
-
c.args.height = Math.max(...itmPeers.map(d => d.bounds.height));
|
|
180
|
-
}
|
|
181
|
-
c.args.left = Math.min(...itmPeers.map(d => d.bounds.left));
|
|
182
|
-
c.args.top = Math.min(...itmPeers.map(d => d.bounds.top));
|
|
183
|
-
break;
|
|
184
|
-
case ItemType.Line:
|
|
185
|
-
c.args.x1 = Math.min(...itmPeers.map(d => d.vertices[0].x));
|
|
186
|
-
c.args.y1 = Math.min(...itmPeers.map(d => d.vertices[0].y));
|
|
187
|
-
c.args.x2 = Math.min(...itmPeers.map(d => d.vertices[1].x));
|
|
188
|
-
c.args.y2 = Math.min(...itmPeers.map(d => d.vertices[1].y));
|
|
189
|
-
break;
|
|
190
|
-
case ItemType.Arc:
|
|
191
|
-
c.args.x = itm.x;
|
|
192
|
-
c.args.y = itm.y;
|
|
193
|
-
c.args.innerRadius = itm.innerRadius;
|
|
194
|
-
c.args.outerRadius = itm.outerRadius;
|
|
195
|
-
break;
|
|
196
|
-
default:
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
for (let s in itm.styles) {
|
|
200
|
-
c.args[s] = itm.styles[s];
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
_analyze(itm, result) {
|
|
205
|
-
if (itm instanceof Glyph) {
|
|
206
|
-
for (let c of itm.children)
|
|
207
|
-
this._analyze(c, result);
|
|
208
|
-
} else if (itm instanceof Group) {
|
|
209
|
-
this._analyze(itm.firstChild, result);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
let node = {type: itm.type, item: itm};
|
|
213
|
-
if (itm.dataScope)
|
|
214
|
-
node.fields = new Set(itm.dataScope.fields);
|
|
215
|
-
else
|
|
216
|
-
node.fields = new Set();
|
|
217
|
-
result.push(node);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
_generateFullSpec(scene) {
|
|
221
|
-
this.spec = [];
|
|
222
|
-
this.spec.push({
|
|
223
|
-
cmd: "scene",
|
|
224
|
-
args: {fillColor: scene.fillColor}
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
let tables = scene.getDataTables(); //, sourceTables = {};
|
|
228
|
-
let imports = {}, transforms = [];
|
|
229
|
-
for (let t in tables) {
|
|
230
|
-
let table = tables[t];
|
|
231
|
-
if (table.sourceDataTable) {
|
|
232
|
-
while (table.sourceDataTable) {
|
|
233
|
-
transforms.push({
|
|
234
|
-
cmd: "transform",
|
|
235
|
-
type: table.transform.type,
|
|
236
|
-
args: table.transform.args,
|
|
237
|
-
input: table.sourceDataTable.id,
|
|
238
|
-
output: table.id
|
|
239
|
-
});
|
|
240
|
-
table = table.sourceDataTable;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
if (!(table.id in imports)) {
|
|
244
|
-
imports[table.id] = {
|
|
245
|
-
cmd: "data",
|
|
246
|
-
url: table.url,
|
|
247
|
-
output: table.id
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
this.spec = this.spec.concat(Object.values(imports));
|
|
253
|
-
this.spec = this.spec.concat(transforms);
|
|
254
|
-
|
|
255
|
-
let sortChildren = [];
|
|
256
|
-
|
|
257
|
-
for (let c of this.collectionCmds) {
|
|
258
|
-
let l;
|
|
259
|
-
if (c.output && c.output.layout) {
|
|
260
|
-
l = {
|
|
261
|
-
cmd: "layout",
|
|
262
|
-
type: c.output.layout.type,
|
|
263
|
-
input: c.output.id,
|
|
264
|
-
args: c.output.layout.toJSON().args
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
this.spec.push(c);
|
|
268
|
-
if (c.output && c.output.childrenOrder) {
|
|
269
|
-
sortChildren.push({
|
|
270
|
-
cmd: "sortChildren",
|
|
271
|
-
args: c.output.childrenOrder,
|
|
272
|
-
input: c.output.id
|
|
273
|
-
})
|
|
274
|
-
}
|
|
275
|
-
if (l)
|
|
276
|
-
this.spec.push(l);
|
|
277
|
-
|
|
278
|
-
if (c.input && Array.isArray(c.input)) { //glyph
|
|
279
|
-
c.input = c.input.map(d => d.classId ? d.classId : d.id);
|
|
280
|
-
} else if (c.input)
|
|
281
|
-
c.input = c.input.classId ? c.input.classId : c.input.id;
|
|
282
|
-
if (c.output)
|
|
283
|
-
c.output = c.output.classId ? c.output.classId : c.output.id;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
let scales = {}, encodings = [];
|
|
287
|
-
for (let classId in scene.encodings) {
|
|
288
|
-
for (let channel in scene.encodings[classId]) {
|
|
289
|
-
let enc = scene.encodings[classId][channel];
|
|
290
|
-
if (enc.scale && !(enc.scale.id in scales)) {
|
|
291
|
-
scales[enc.scale.id] = enc.scale.toJSON();
|
|
292
|
-
}
|
|
293
|
-
let args = enc.toJSON().args;
|
|
294
|
-
args.field = enc.field;
|
|
295
|
-
args.channel = enc.channel;
|
|
296
|
-
delete args.datatable;
|
|
297
|
-
encodings.push({
|
|
298
|
-
cmd: "encode",
|
|
299
|
-
input: getEncodingKey(enc.anyItem),
|
|
300
|
-
scale: enc.scale.id,
|
|
301
|
-
args: args
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
for (let s in scales) {
|
|
307
|
-
let o = scales[s];
|
|
308
|
-
o.cmd = "scale";
|
|
309
|
-
this.spec.push(o);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
this.spec = this.spec.concat(encodings);
|
|
313
|
-
this.spec = this.spec.concat(sortChildren);
|
|
314
|
-
|
|
315
|
-
for (let c in scene.constraints) {
|
|
316
|
-
let constr = scene.constraints[c];
|
|
317
|
-
let o = {
|
|
318
|
-
cmd: "constraint",
|
|
319
|
-
type: constr.type,
|
|
320
|
-
args: {}
|
|
321
|
-
};
|
|
322
|
-
switch (constr.type) {
|
|
323
|
-
case ConstraintType.Affix:
|
|
324
|
-
o.item = constr.item.classId ? constr.item.classId : constr.item.id;
|
|
325
|
-
o.baseItem = constr.baseItem.classId ? constr.baseItem.classId : constr.baseItem.id;
|
|
326
|
-
o.channel = constr.channel;
|
|
327
|
-
o.args.itemAnchor = constr.itemAnchor;
|
|
328
|
-
o.args.baseAnchor = constr.baseAnchor;
|
|
329
|
-
o.args.offset = constr.offset;
|
|
330
|
-
break;
|
|
331
|
-
case ConstraintType.Align:
|
|
332
|
-
//TODO: need to actually do more to infer what items are being aligned
|
|
333
|
-
o.items = constr.items.map(d => d.classId ? d.classId : d.id);
|
|
334
|
-
o.anchor = constr.anchor;
|
|
335
|
-
break;
|
|
336
|
-
}
|
|
337
|
-
this.spec.push(o);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
for (let c of this.guideCmds) {
|
|
341
|
-
this.spec.push(c);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
for (let c of this.glyphCmds) {
|
|
345
|
-
if (c.output)
|
|
346
|
-
c.output = c.output.classId ? c.output.classId : c.output.id;
|
|
347
|
-
this.spec.push(c);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|