mascot-vis 2.1.0 → 3.0.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/README.md +4 -3
- package/dist/mascot-es.js +27745 -0
- package/dist/mascot-min.js +186 -199
- package/dist/mascot-umd.js +27781 -0
- package/js/depGraphVis.js +66 -0
- package/package.json +23 -15
- package/src-new-ts/action/createElement.ts +91 -0
- package/src-new-ts/action/encode.js +20 -0
- package/src-new-ts/action/repeat.js +128 -0
- package/src-new-ts/action/traverseScene.js +41 -0
- package/src-new-ts/data/Network.js +2 -0
- package/src-new-ts/data/Scope.js +135 -0
- package/src-new-ts/data/Table.js +263 -0
- package/src-new-ts/data/Tree.js +3 -0
- package/src-new-ts/data/field.ts +115 -0
- package/src-new-ts/data/import.ts +96 -0
- package/src-new-ts/data/predicate.ts +82 -0
- package/src-new-ts/depgraph/DepGraph.js +178 -0
- package/src-new-ts/depgraph/Edge.js +9 -0
- package/src-new-ts/depgraph/SceneGraph2DepGraph.js +110 -0
- package/src-new-ts/depgraph/Signal.js +12 -0
- package/src-new-ts/depgraph/operator/BoundsEvaluator.js +30 -0
- package/src-new-ts/depgraph/operator/Dataflow.js +41 -0
- package/src-new-ts/depgraph/operator/DomainBuilder.js +50 -0
- package/src-new-ts/depgraph/updateDepGraph.js +45 -0
- package/src-new-ts/depgraph/variable/BoundsVar.js +81 -0
- package/src-new-ts/depgraph/variable/ChannelVar.js +17 -0
- package/src-new-ts/depgraph/variable/DataScopeVar.js +12 -0
- package/src-new-ts/depgraph/variable/DomainVar.js +15 -0
- package/src-new-ts/depgraph/variable/FieldVar.js +17 -0
- package/src-new-ts/depgraph/variable/LayoutParameter.js +8 -0
- package/src-new-ts/depgraph/variable/ScaleVar.js +13 -0
- package/src-new-ts/depgraph/variable/Variable.js +39 -0
- package/src-new-ts/element/gradient/LinearGradient.js +37 -0
- package/src-new-ts/element/group/Collection.js +109 -0
- package/src-new-ts/element/group/Group.js +307 -0
- package/src-new-ts/element/group/Scene.js +98 -0
- package/src-new-ts/element/mark/CircleMark.ts +85 -0
- package/src-new-ts/element/mark/Mark.ts +233 -0
- package/src-new-ts/element/mark/PathMark.js +483 -0
- package/src-new-ts/element/mark/Segment.js +29 -0
- package/src-new-ts/element/mark/Vertex.js +118 -0
- package/src-new-ts/encode/Scale.ts +115 -0
- package/src-new-ts/index.ts +19 -0
- package/src-new-ts/layout/Layout.ts +3 -0
- package/src-new-ts/render/CanvasRenderer.ts +24 -0
- package/src-new-ts/render/SVGRenderer.js +316 -0
- package/src-new-ts/util.ts +3 -0
- package/src-old/action/Classify.js +53 -0
- package/src-old/action/Densify.js +199 -0
- package/src-old/action/Partition.js +531 -0
- package/src-old/action/Repeat.js +106 -0
- package/src-old/action/Repopulate.js +44 -0
- package/src-old/action/Stratify.js +156 -0
- package/src-old/basic/Gradient.js +37 -0
- package/src-old/basic/Point.js +51 -0
- package/src-old/basic/Rectangle.js +63 -0
- package/src-old/bind/bindToAngle.js +56 -0
- package/src-old/bind/bindToAreaMark.js +360 -0
- package/src-old/bind/bindToColor.js +114 -0
- package/src-old/bind/bindToLink.js +81 -0
- package/src-old/bind/bindToPosition.js +283 -0
- package/src-old/bind/bindToRadialDistance.js +62 -0
- package/src-old/bind/bindToSize.js +235 -0
- package/src-old/bind/bindToText.js +60 -0
- package/src-old/bind/bindToThickness.js +100 -0
- package/src-old/constraint/AffixConstraint.js +129 -0
- package/src-old/constraint/AlignConstraint.js +58 -0
- package/src-old/core/Encoding.js +336 -0
- package/src-old/core/Scale.js +322 -0
- package/src-old/core/SceneLoader.js +290 -0
- package/src-old/core/SceneValidator.js +232 -0
- package/src-old/core/SpecExecutor.js +113 -0
- package/src-old/core/SpecGenerator.js +350 -0
- package/src-old/data/DataImporter.js +64 -0
- package/src-old/data/DataScope.js +124 -0
- package/src-old/data/DataTable.js +338 -0
- package/src-old/data/Network.js +106 -0
- package/src-old/data/Tree.js +251 -0
- package/src-old/data/transform/Bin.js +46 -0
- package/src-old/data/transform/Filter.js +48 -0
- package/src-old/data/transform/Groupby.js +18 -0
- package/src-old/data/transform/KDE.js +58 -0
- package/src-old/data/transform/Sort.js +14 -0
- package/src-old/data/transform/Split.js +5 -0
- package/src-old/data/transform/partition.js +46 -0
- package/src-old/history/UndoRedoStack +0 -0
- package/src-old/index.js +271 -0
- package/src-old/indexSVG.js +259 -0
- package/src-old/interaction/Interaction.js +91 -0
- package/src-old/interaction/MouseEvent.js +8 -0
- package/src-old/interaction/Selection.js +9 -0
- package/src-old/interaction/brush.js +362 -0
- package/src-old/item/Segment.js +29 -0
- package/src-old/item/Vertex.js +118 -0
- package/src-old/item/composite/Collection.js +106 -0
- package/src-old/item/composite/Glyph.js +19 -0
- package/src-old/item/composite/Group.js +310 -0
- package/src-old/item/composite/Scene.js +1251 -0
- package/src-old/item/mark/ArcPath.js +181 -0
- package/src-old/item/mark/AreaPath.js +78 -0
- package/src-old/item/mark/CirclePath.js +102 -0
- package/src-old/item/mark/EllipsePath.js +5 -0
- package/src-old/item/mark/Image.js +101 -0
- package/src-old/item/mark/LinkPath.js +118 -0
- package/src-old/item/mark/Mark.js +163 -0
- package/src-old/item/mark/Path.js +494 -0
- package/src-old/item/mark/PointText.js +201 -0
- package/src-old/item/mark/PolygonPath.js +64 -0
- package/src-old/item/mark/RectPath.js +88 -0
- package/src-old/item/mark/RingPath.js +92 -0
- package/src-old/item/refs/Axis.js +362 -0
- package/src-old/item/refs/EncodingAxis.js +515 -0
- package/src-old/item/refs/Gridlines.js +144 -0
- package/src-old/item/refs/LayoutAxis.js +316 -0
- package/src-old/item/refs/Legend.js +273 -0
- package/src-old/layout/Circular.js +95 -0
- package/src-old/layout/Force.js +52 -0
- package/src-old/layout/Grid.js +423 -0
- package/src-old/layout/Layout.js +13 -0
- package/src-old/layout/Packing.js +56 -0
- package/src-old/layout/Stack.js +264 -0
- package/src-old/layout/Strata.js +88 -0
- package/src-old/layout/Sugiyama.js +59 -0
- package/src-old/layout/TidyTree.js +105 -0
- package/src-old/layout/Treemap.js +87 -0
- package/src-old/renderer/SVGInteractionHandler.js +241 -0
- package/src-old/renderer/SVGRenderer.js +325 -0
- package/src-old/renderer/WebGLRenderer.js +1097 -0
- package/src-old/renderer/WebGLRenderer2.js +249 -0
- package/src-old/renderer/threejs/Line2.js +18 -0
- package/src-old/renderer/threejs/LineGeometry.js +77 -0
- package/src-old/renderer/threejs/LineMaterial.js +605 -0
- package/src-old/renderer/threejs/LineSegments2.js +281 -0
- package/src-old/renderer/threejs/LineSegmentsGeometry.js +226 -0
- package/src-old/renderer/threejs/Wireframe.js +51 -0
- package/src-old/renderer/threejs/WireframeGeometry2.js +16 -0
- package/src-old/scale/areaSize.js +0 -0
- package/src-old/scale/domain.js +38 -0
- package/src-old/util/Constants.js +180 -0
- package/src-old/util/DataUtil.js +35 -0
- package/src-old/util/ItemUtil.js +586 -0
- package/src-old/util/Numerical.js +33 -0
- package/tests/demo-tests/README.md +80 -0
- package/tests/demo-tests/SVG2PNG.js +56 -0
- package/tests/demo-tests/demos2CanvasPNGs.js +69 -0
- package/tests/demo-tests/demos2ScenesSVGs.js +100 -0
- package/tests/demo-tests/pathElementWorker.js +91 -0
- package/tests/demo-tests/pixelTest.js +62 -0
- package/tests/demo-tests/renderDemos.html +132 -0
- package/tests/demo-tests/serializationTest.js +36 -0
- package/tests/demo-tests/serializeDemos.html +134 -0
- package/tests/unit-tests/README.md +4 -0
- package/tests/unit-tests/jasmine-browser.json +21 -0
- package/tests/unit-tests/jasmine.json +14 -0
- package/tests/unit-tests/testSpec.js +274 -0
- package/dist/mascot.js +0 -24920
- package/interactive.html +0 -592
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import {Errors, DataType, ItemType, Orientation, Alignment} from "../util/Constants";
|
|
2
|
+
import DataScope from "../data/DataScope";
|
|
3
|
+
import {getPeers, polar2Cartesian} from "../util/ItemUtil";
|
|
4
|
+
import Vertex from "../item/Vertex";
|
|
5
|
+
|
|
6
|
+
export function densifiable(compnt) {
|
|
7
|
+
if ([ItemType.Line, ItemType.Circle, ItemType.Rect, ItemType.Area].indexOf(compnt.type) < 0) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
if (!compnt.dataScope) {
|
|
11
|
+
return true;
|
|
12
|
+
} else {
|
|
13
|
+
let peers = getPeers(compnt, compnt.getScene());
|
|
14
|
+
for (let p of peers) {
|
|
15
|
+
if (p.dataScope.numTuples > 1)
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function densifyItem(scene, compnt, orientation, field, datatable, callback, startAngle, direction) {
|
|
23
|
+
let f = callback ? datatable.transformField(field, callback) : field;
|
|
24
|
+
let type = datatable.getFieldType(f);
|
|
25
|
+
|
|
26
|
+
if (type != DataType.String && type != DataType.Date && type != DataType.Number) {
|
|
27
|
+
throw new Error(Errors.DENSIFY_BY_NONCAT + ": " + f + " is " + type);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!densifiable(compnt, f, scene)) {
|
|
31
|
+
throw new Error(Errors.COMPNT_NON_DENSIFIABLE);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
switch (compnt.type) {
|
|
35
|
+
case ItemType.Line:
|
|
36
|
+
return _doLineDensify(scene, compnt, f, datatable);
|
|
37
|
+
case ItemType.Circle:
|
|
38
|
+
return _doCircleDensify(scene, compnt, f, datatable, startAngle, direction);
|
|
39
|
+
case ItemType.Rect:
|
|
40
|
+
case ItemType.Area:
|
|
41
|
+
return _doAreaDensify(scene, compnt, orientation, f, datatable);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function _doLineDensify(scene, compnt, field, datatable) {
|
|
47
|
+
let peers = getPeers(compnt, scene);
|
|
48
|
+
|
|
49
|
+
let toReturn;
|
|
50
|
+
for (let p of peers) {
|
|
51
|
+
let lineDS = p.dataScope ? p.dataScope : new DataScope(datatable);
|
|
52
|
+
let ds = datatable.getFieldSummary(field).unique.map(d => lineDS.cross(field, d));
|
|
53
|
+
ds = ds.filter(d => !d.isEmpty());
|
|
54
|
+
if (ds.length === 1) {
|
|
55
|
+
ds.push(ds[0].clone());
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let args = Object.assign({}, p.styles);
|
|
59
|
+
for (let vs of Vertex.styles){
|
|
60
|
+
if (p[vs])
|
|
61
|
+
args[vs] = p[vs];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//compute vertices
|
|
65
|
+
let x1 = p.vertices[0].x,
|
|
66
|
+
y1 = p.vertices[0].y,
|
|
67
|
+
x2 = p.vertices[1].x,
|
|
68
|
+
y2 = p.vertices[1].y;
|
|
69
|
+
|
|
70
|
+
let vertices = [], wd = x2 - x1, ht = y2 - y1;
|
|
71
|
+
for (let i = 0; i < ds.length; i++){
|
|
72
|
+
vertices.push([x1 + i * wd / (ds.length - 1), y1 + i * ht /(ds.length - 1)]);
|
|
73
|
+
}
|
|
74
|
+
args.vertices = vertices;
|
|
75
|
+
let polyLine = scene.mark("path", args);
|
|
76
|
+
polyLine.classId = compnt.id;
|
|
77
|
+
polyLine.dataScope = lineDS;
|
|
78
|
+
|
|
79
|
+
let parent = p.parent;
|
|
80
|
+
parent.addChild(polyLine);
|
|
81
|
+
parent.removeChild(p);
|
|
82
|
+
|
|
83
|
+
for (let [i, v] of polyLine.vertices.entries()){
|
|
84
|
+
if (v.dataScope)
|
|
85
|
+
v.dataScope = v.dataScope.merge(ds[i]);
|
|
86
|
+
else
|
|
87
|
+
v.dataScope = ds[i];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (p == compnt)
|
|
91
|
+
toReturn = polyLine;
|
|
92
|
+
}
|
|
93
|
+
return toReturn;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function _doAreaDensify(scene, compnt, orientation, field, datatable) {
|
|
97
|
+
let peers = getPeers(compnt, scene);
|
|
98
|
+
let toReturn;
|
|
99
|
+
|
|
100
|
+
for (let p of peers) {
|
|
101
|
+
// How to handle missing elements across different partitions in area mark?
|
|
102
|
+
let ft = datatable.getFieldType(field);
|
|
103
|
+
let areaDS = p.dataScope ? p.dataScope : new DataScope(datatable);
|
|
104
|
+
let ds = datatable.getFieldSummary(field).unique.map(d => areaDS.cross(field, d));
|
|
105
|
+
ds = ft == DataType.Number? ds : ds.filter(d => !d.isEmpty());
|
|
106
|
+
if (ds.length === 1) {
|
|
107
|
+
ds.push(ds[0].clone());
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (ft == DataType.Number || ft == DataType.Date) {
|
|
111
|
+
// sorting ds
|
|
112
|
+
ds.sort((a, b) => (a._field2value[field] > b._field2value[field]) ? 1 : -1)
|
|
113
|
+
}
|
|
114
|
+
let args = Object.assign({}, p.styles);
|
|
115
|
+
//compute vertices
|
|
116
|
+
let x1 = p.vertices[0].x,
|
|
117
|
+
y1 = p.vertices[0].y,
|
|
118
|
+
x2 = p.vertices[p.vertices.length - 2].x,
|
|
119
|
+
y2 = p.vertices[p.vertices.length - 2].y;
|
|
120
|
+
|
|
121
|
+
let vertices = [], wd = x2 - x1, ht = y2 - y1;
|
|
122
|
+
for(let j = 0; j < ds.length; j++) {
|
|
123
|
+
vertices.push(orientation == Orientation.Vertical ? [x2, y1 + (ds.length-1-j) * ht /(ds.length - 1)] : [x1 + j * wd / (ds.length - 1), y1]);
|
|
124
|
+
}
|
|
125
|
+
for(let j = 0; j < ds.length; j++) {
|
|
126
|
+
vertices.push(orientation == Orientation.Vertical ? [x1, y1 + j * ht /(ds.length - 1)] : [x1 + (ds.length-1-j) * wd / (ds.length - 1), y2]);
|
|
127
|
+
}
|
|
128
|
+
args.vertices = vertices;
|
|
129
|
+
let NewArea = scene.mark("area", args);
|
|
130
|
+
// Very Important: keep new areas' classID consistent
|
|
131
|
+
NewArea.classId = p.type == "area"? p.classId : "area" + p.classId.substring(9);
|
|
132
|
+
NewArea.dataScope = areaDS;
|
|
133
|
+
NewArea.orientation = orientation;
|
|
134
|
+
NewArea.baseline = orientation === Orientation.Horizontal ? Alignment.Bottom : Alignment.Left;
|
|
135
|
+
|
|
136
|
+
let parent = p.parent;
|
|
137
|
+
parent.addChild(NewArea);
|
|
138
|
+
parent.removeChild(p);
|
|
139
|
+
|
|
140
|
+
for (let [i, v] of NewArea.vertices.entries()){
|
|
141
|
+
// two boundary lines are encoded the same; possible to modify later according to the data encoding
|
|
142
|
+
if (i>=ds.length) {
|
|
143
|
+
v.dataScope = areaDS.merge(ds[ds.length*2-1-i]);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
v.dataScope = areaDS.merge(ds[i]);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (p == compnt) {
|
|
150
|
+
toReturn = NewArea;
|
|
151
|
+
// targetArea = NewArea;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return toReturn;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function _doCircleDensify(scene, compnt, field, datatable, startAngle, direction) {
|
|
158
|
+
let toReturn;
|
|
159
|
+
let peers = getPeers(compnt, scene);
|
|
160
|
+
peers.forEach(p => {
|
|
161
|
+
let circDS = p.dataScope ? p.dataScope : new DataScope(datatable);
|
|
162
|
+
let ds = datatable.getFieldSummary(field).unique.map(d => circDS.cross(field, d));
|
|
163
|
+
ds = ds.filter(d => !d.isEmpty());
|
|
164
|
+
let numVertices = ds.length;
|
|
165
|
+
if (numVertices < 3)
|
|
166
|
+
throw Error(Errors.INSUFFICIENT_DATA_SCOPES);
|
|
167
|
+
let k = 360/numVertices, vertices = [], angle = [];
|
|
168
|
+
let dirSign = direction == "clockwise" ? -1 : 1;
|
|
169
|
+
for (let i = 0; i < ds.length; i++){
|
|
170
|
+
let a = startAngle + dirSign * i * k;
|
|
171
|
+
angle[i] = a;
|
|
172
|
+
let coords = polar2Cartesian(p.x, p.y, p.radius, angle[i]);
|
|
173
|
+
vertices.push(coords);
|
|
174
|
+
}
|
|
175
|
+
let polygon = scene.mark("polygon", {x: p.x, y: p.y, radius: p.radius, vertices:vertices});
|
|
176
|
+
polygon.dataScope = circDS;
|
|
177
|
+
polygon.styles = Object.assign({}, p.styles);
|
|
178
|
+
for (let vs of Vertex.styles){
|
|
179
|
+
if (p[vs])
|
|
180
|
+
polygon[vs] = p[vs];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
let parent = p.parent;
|
|
184
|
+
parent.addChild(polygon);
|
|
185
|
+
parent.removeChild(p);
|
|
186
|
+
|
|
187
|
+
for (let [i, v] of polygon.vertices.entries()){
|
|
188
|
+
v.polarAngle = angle[i];
|
|
189
|
+
if (v.dataScope)
|
|
190
|
+
v.dataScope = v.dataScope.merge(ds[i]);
|
|
191
|
+
else
|
|
192
|
+
v.dataScope = ds[i];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (p == compnt)
|
|
196
|
+
toReturn = polygon;
|
|
197
|
+
});
|
|
198
|
+
return toReturn;
|
|
199
|
+
}
|