mascot-vis 2.0.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 -24446
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import * as d3 from 'd3';
|
|
2
|
+
import { atlas_rowId, ItemType } from '../util/Constants';
|
|
3
|
+
import { getPeers } from "../util/ItemUtil";
|
|
4
|
+
import Brush from '../interaction/brush';
|
|
5
|
+
|
|
6
|
+
export default class SVGInteractionHandler {
|
|
7
|
+
|
|
8
|
+
constructor(svgRenderer) {
|
|
9
|
+
this._renderer = svgRenderer;
|
|
10
|
+
this._globalPredicates = {};
|
|
11
|
+
}
|
|
12
|
+
created = 0;
|
|
13
|
+
|
|
14
|
+
processInteraction(i, scene) {
|
|
15
|
+
if (!i.target || !i.targetEval || !i.targetEval['false']) return
|
|
16
|
+
if (i.listener.type == ItemType.Scene) {
|
|
17
|
+
const originalProperties = [];
|
|
18
|
+
getPeers(i.target, scene).forEach(path => {
|
|
19
|
+
const obj = {};
|
|
20
|
+
Object.keys(i.targetEval['false']).forEach(prop => {
|
|
21
|
+
obj[prop] = (path[prop]);
|
|
22
|
+
});
|
|
23
|
+
originalProperties.push(obj);
|
|
24
|
+
});
|
|
25
|
+
// if (i.event == 'click') {
|
|
26
|
+
// this._processClick(i, scene, originalProperties);
|
|
27
|
+
// }
|
|
28
|
+
if (i.event == 'brush' || i.event == 'click') {
|
|
29
|
+
if (this.created == 0) {
|
|
30
|
+
// new Brush(this._renderer._svgId, '#9c3131', null).brush()
|
|
31
|
+
this.created = new Brush(this._renderer._svgId, '#9c3131', i.hitObject._bounds).brush();
|
|
32
|
+
document.addEventListener('brush', (e) => {
|
|
33
|
+
this._processBrush1(i, scene, originalProperties, e.detail.selection ? { selection: e.detail.selection } : null);
|
|
34
|
+
if (e.detail.selection == undefined) {
|
|
35
|
+
this._processClick(i, scene, originalProperties, e.detail.e);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
_processBrush1(i, scene, originalProperties, e) {
|
|
46
|
+
let brushPredicateEvaluators = {};
|
|
47
|
+
if (i.event == 'brush') {
|
|
48
|
+
if (i.predicate.length <= 0) return;
|
|
49
|
+
i.predicate.forEach(ele => {
|
|
50
|
+
if (ele.type == 'range') {
|
|
51
|
+
let rangeData = []
|
|
52
|
+
if (i.hitObject.type == 'axis') {
|
|
53
|
+
i.hitObject._labels.children.forEach(_ => {
|
|
54
|
+
rangeData.push({
|
|
55
|
+
axisCoordinate: _[ele.channel], actualValue: _.text
|
|
56
|
+
})
|
|
57
|
+
});
|
|
58
|
+
} else if (i.hitObject.type == 'collection') {
|
|
59
|
+
i.hitObject.children.forEach(_ => {
|
|
60
|
+
rangeData.push({
|
|
61
|
+
axisCoordinate: _[ele.channel], actualValue: _.dataScope.getFieldValue(ele.field)
|
|
62
|
+
})
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
rangeData.sort((a, b) => a.axisCoordinate - b.axisCoordinate)
|
|
66
|
+
brushPredicateEvaluators[ele.channel] = {
|
|
67
|
+
_actualLabels: rangeData.map(e => e.actualValue),
|
|
68
|
+
_axisCoordinates: rangeData.map(e => e.axisCoordinate)
|
|
69
|
+
}
|
|
70
|
+
rangeData = null;
|
|
71
|
+
} else {
|
|
72
|
+
// Brush should not have other predicates
|
|
73
|
+
// Confirm with Leo
|
|
74
|
+
throw new Error(`Event Type Brush should not have ${i.predicate.type} as Predicate Type`)
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (e && e.selection) {
|
|
79
|
+
let _r = {
|
|
80
|
+
'x': [e.selection[0][0], e.selection[1][0]],
|
|
81
|
+
'y': [e.selection[0][1], e.selection[1][1]]
|
|
82
|
+
}
|
|
83
|
+
let _range = { 'x': null, 'y': null };
|
|
84
|
+
|
|
85
|
+
Object.entries(brushPredicateEvaluators).forEach(entry => {
|
|
86
|
+
const [key, value] = entry;
|
|
87
|
+
let val1 = value._actualLabels[d3.bisect(value._axisCoordinates, _r[key][0])]
|
|
88
|
+
let val2 = value._actualLabels[d3.bisect(value._axisCoordinates, _r[key][1]) - 1]
|
|
89
|
+
_range[key] = {
|
|
90
|
+
_high: val1 >= val2 ? val1 : val2,
|
|
91
|
+
_low: val1 < val2 ? val1 : val2
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
let _x = i.predicate.filter(e => _range['x'] && e.channel == 'x')[0]
|
|
95
|
+
let _y = i.predicate.filter(e => _range['y'] && e.channel == 'y')[0];
|
|
96
|
+
let _1, _2 = false;
|
|
97
|
+
getPeers(i.target, scene).forEach((path, _i) => {
|
|
98
|
+
if (_x) {
|
|
99
|
+
_1 = _range['x']['_high'] >= path.dataScope.getFieldValue(_x['field']) &&
|
|
100
|
+
_range['x']['_low'] <= path.dataScope.getFieldValue(_x['field'])
|
|
101
|
+
}
|
|
102
|
+
if (_y) {
|
|
103
|
+
_2 = _range['y']['_high'] >= path.dataScope.getFieldValue(_y['field']) &&
|
|
104
|
+
_range['y']['_low'] <= path.dataScope.getFieldValue(_y['field'])
|
|
105
|
+
}
|
|
106
|
+
if ((_x == undefined && _2) || (_y == undefined && _1) || (_1 && _2)) {
|
|
107
|
+
this.setTargetProperties(originalProperties[_i], path);
|
|
108
|
+
} else {
|
|
109
|
+
this.setTargetProperties(i.targetEval['false'], path);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
} else {
|
|
113
|
+
getPeers(i.target, scene).forEach((path, _i) => {
|
|
114
|
+
this.setTargetProperties(originalProperties[_i], path);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
this._renderer.render(scene, { visualOnly: true });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
_processClick(i, scene, originalProperties, $e) {
|
|
121
|
+
i = scene._interactionsObj['click']
|
|
122
|
+
let multiSelectSet = new Set();
|
|
123
|
+
if (i.predicate[0].type == 'point') {
|
|
124
|
+
//continent done
|
|
125
|
+
//country - can leverage multi select done
|
|
126
|
+
if ($e.target.id.includes(i.target.type)) {
|
|
127
|
+
const _ = getPeers(i.target, scene).filter(e => e.id == $e.target.id);
|
|
128
|
+
if (_.length > 0) {
|
|
129
|
+
getPeers(i.target, scene).forEach((path, _i) => {
|
|
130
|
+
if (path.dataScope.getFieldValue(i.predicate[0].field) == _[0].dataScope.getFieldValue(i.predicate[0].field)) {
|
|
131
|
+
this.setTargetProperties(originalProperties[_i], path);
|
|
132
|
+
} else {
|
|
133
|
+
this.setTargetProperties(i.targetEval['false'], path);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
} else if (i.hitObject.type == 'legend' && i.hitObject.encoding.datatable._fieldSummaries[i.predicate[0].field].unique.includes($e.target.innerHTML)) {
|
|
138
|
+
getPeers(i.target, scene).forEach((path, _i) => {
|
|
139
|
+
if (path.dataScope.getFieldValue(i.predicate[0].field) == $e.target.innerHTML) {
|
|
140
|
+
this.setTargetProperties(originalProperties[_i], path);
|
|
141
|
+
} else {
|
|
142
|
+
this.setTargetProperties(i.targetEval['false'], path);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
} else {
|
|
146
|
+
getPeers(i.target, scene).forEach((path, _i) => {
|
|
147
|
+
this.setTargetProperties(originalProperties[_i], path);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
} else if (i.predicate[0].type == 'list') {
|
|
151
|
+
// countries done
|
|
152
|
+
// continents
|
|
153
|
+
if (i.predicate[0].multiByField) {
|
|
154
|
+
// select Multiple fields by continents for instance
|
|
155
|
+
if ($e.target.id.includes(i.target.type)) {
|
|
156
|
+
const _ = getPeers(i.target, scene).filter(e => e.id == $e.target.id);
|
|
157
|
+
if (_.length > 0) {
|
|
158
|
+
multiSelectSet.add(_[0].dataScope.getFieldValue(i.predicate[0].field));
|
|
159
|
+
getPeers(i.target, scene).forEach((path, _i) => {
|
|
160
|
+
if (multiSelectSet.has(path.dataScope.getFieldValue(i.predicate[0].field))) {
|
|
161
|
+
this.setTargetProperties(originalProperties[_i], path);
|
|
162
|
+
} else {
|
|
163
|
+
this.setTargetProperties(i.targetEval['false'], path);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
} else {
|
|
168
|
+
multiSelectSet.clear();
|
|
169
|
+
getPeers(i.target, scene).forEach((path, _i) => {
|
|
170
|
+
this.setTargetProperties(originalProperties[_i], path);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
if ($e.target.id.includes(i.target.type)) {
|
|
175
|
+
if (multiSelectSet.has($e.target.id)) {
|
|
176
|
+
multiSelectSet.delete($e.target.id); // deselect
|
|
177
|
+
} else {
|
|
178
|
+
multiSelectSet.add($e.target.id);
|
|
179
|
+
}
|
|
180
|
+
getPeers(i.target, scene).forEach((path, _i) => {
|
|
181
|
+
if (multiSelectSet.has(path.id)) {
|
|
182
|
+
this.setTargetProperties(originalProperties[_i], path);
|
|
183
|
+
} else {
|
|
184
|
+
this.setTargetProperties(i.targetEval['false'], path);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
} else {
|
|
188
|
+
multiSelectSet.clear();
|
|
189
|
+
getPeers(i.target, scene).forEach((path, _i) => {
|
|
190
|
+
this.setTargetProperties(originalProperties[_i], path);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
this._renderer.render(scene, { visualOnly: true });
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
evaluatePredicate(i, path, _range) {
|
|
199
|
+
if (i.predicate.type == 'range') {
|
|
200
|
+
return path.dataScope.getFieldValue(i.predicate.field) <= _[0] && path.dataScope.getFieldValue(i.predicate.field) >= _[1]
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
setTargetProperties(obj, path) {
|
|
205
|
+
Object.keys(obj).forEach(prop => {
|
|
206
|
+
try {
|
|
207
|
+
path[prop] = obj[prop];
|
|
208
|
+
} catch (error) {
|
|
209
|
+
console.log('Property not found');
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
_getSelection(e, selDef, listener, item) {
|
|
215
|
+
let selection = {};
|
|
216
|
+
if (item) {
|
|
217
|
+
selection.item = item;
|
|
218
|
+
} else if (selDef.item) {
|
|
219
|
+
//TODO
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
let field = selDef.field ? selDef.field : atlas_rowId;
|
|
223
|
+
if (selection.item) {
|
|
224
|
+
selection.predicate = { "field": field, "value": selection.item.dataScope.getFieldValue(field) };
|
|
225
|
+
} else {
|
|
226
|
+
//from axis
|
|
227
|
+
}
|
|
228
|
+
return selection;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
addGlobalPredicate(scene, p) {
|
|
232
|
+
if (!(scene.id in this._globalPredicates)) {
|
|
233
|
+
this._globalPredicates[scene.id] = {};
|
|
234
|
+
}
|
|
235
|
+
this._globalPredicates[scene.id][p.field] = p;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
getGlobalPredicates(scene) {
|
|
239
|
+
return (scene.id in this._globalPredicates) ? Object.values(this._globalPredicates[scene.id]) : [];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import {ItemType, Style2SVG} from "../util/Constants";
|
|
2
|
+
import * as d3 from 'd3';
|
|
3
|
+
import SVGInteractionHandler from "./SVGInteractionHandler";
|
|
4
|
+
|
|
5
|
+
export default class SVGRenderer {
|
|
6
|
+
|
|
7
|
+
constructor(svgId) {
|
|
8
|
+
this._svgId = svgId;
|
|
9
|
+
this._compMap = {};
|
|
10
|
+
this._decoMap = {};
|
|
11
|
+
this._interactionHandler = new SVGInteractionHandler(this);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param {*} scene
|
|
17
|
+
* @param {*} supported keys for params:
|
|
18
|
+
* flatten (do not organize elements in scene graph hierarchy)
|
|
19
|
+
* collectionBounds (draw collection borders)
|
|
20
|
+
*/
|
|
21
|
+
render(scene, params) {
|
|
22
|
+
let args = params ? params : {};
|
|
23
|
+
for (let k in this._decoMap) {
|
|
24
|
+
this._decoMap[k].remove();
|
|
25
|
+
delete this._decoMap[k];
|
|
26
|
+
}
|
|
27
|
+
this._removed = {};
|
|
28
|
+
for (let k in this._compMap) {
|
|
29
|
+
this._removed[k] = 1;
|
|
30
|
+
}
|
|
31
|
+
this._renderItem(scene, args);
|
|
32
|
+
for (let k in this._removed) {
|
|
33
|
+
this._compMap[k].remove();
|
|
34
|
+
delete this._compMap[k];
|
|
35
|
+
}
|
|
36
|
+
if (!("visualOnly" in args)) {
|
|
37
|
+
for (let i of scene._interactions)
|
|
38
|
+
this._interactionHandler.processInteraction(i, scene);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
clear() {
|
|
43
|
+
let svg = document.getElementById(this._svgId);
|
|
44
|
+
while (svg.firstChild) {
|
|
45
|
+
svg.firstChild.remove();
|
|
46
|
+
}
|
|
47
|
+
this._compMap = {};
|
|
48
|
+
this._decoMap = {};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
_renderItem(c, args) {
|
|
52
|
+
let cid = c.id,
|
|
53
|
+
parent = c.parent;
|
|
54
|
+
|
|
55
|
+
let svgParent;
|
|
56
|
+
if (parent && parent.id && parent.id in this._compMap && !args.flatten) {
|
|
57
|
+
svgParent = d3.select("#"+this._svgId).select("#"+parent.id);
|
|
58
|
+
} else {
|
|
59
|
+
svgParent = d3.select("#"+this._svgId);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!(cid in this._compMap)) {
|
|
63
|
+
//TODO: what if the parent is not rendered? What if the hierarchy has changed?
|
|
64
|
+
this._compMap[cid] = svgParent.append(this._getSVGElementType(c));
|
|
65
|
+
} else {
|
|
66
|
+
delete this._removed[cid];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (c.type == ItemType.Gridlines) {
|
|
70
|
+
this._compMap[cid].lower();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let el = this._compMap[cid];
|
|
74
|
+
|
|
75
|
+
el.attr("id", cid);
|
|
76
|
+
if (c.classId)
|
|
77
|
+
el.attr("class", c.classId);
|
|
78
|
+
|
|
79
|
+
if (c.type == ItemType.Scene) {
|
|
80
|
+
d3.select("#"+this._svgId).style("background", c.fillColor ? c.fillColor : "#fff");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// if (c.type == "vertex") {
|
|
84
|
+
// //TODO: render vertices
|
|
85
|
+
// return;
|
|
86
|
+
// }
|
|
87
|
+
|
|
88
|
+
let pathTypes = [ItemType.Path, ItemType.Polygon, ItemType.Link, ItemType.Pie, ItemType.Line, ItemType.Area, ItemType.Ring, ItemType.Arc];
|
|
89
|
+
if (pathTypes.indexOf(c.type) >= 0) {
|
|
90
|
+
el.attr("d", c.getSVGPathData());
|
|
91
|
+
if (!c.closed)
|
|
92
|
+
el.style("fill", "none");
|
|
93
|
+
if (cid.indexOf("axis") == 0) {
|
|
94
|
+
el.style("shape-rendering", "crispEdges");
|
|
95
|
+
}
|
|
96
|
+
// } else if (c.type == ItemType.Line) {
|
|
97
|
+
// el.attr("x1", c.vertices[0].x);
|
|
98
|
+
// el.attr("y1", c.vertices[0].y);
|
|
99
|
+
// el.attr("x2", c.vertices[1].x);
|
|
100
|
+
// el.attr("y2", c.vertices[1].y);
|
|
101
|
+
// if (cid.indexOf("axis") == 0) {
|
|
102
|
+
// el.style("shape-rendering", "crispEdges");
|
|
103
|
+
// }
|
|
104
|
+
} else if (c.type == ItemType.Circle) {
|
|
105
|
+
el.attr("cx", c.x);
|
|
106
|
+
el.attr("cy", c.y);
|
|
107
|
+
el.attr("r", c.radius);
|
|
108
|
+
} else if (c.type == ItemType.Rect) {
|
|
109
|
+
//do not use c.left, c.top, c.width, c.height as the rectangle may be flipped
|
|
110
|
+
//use c.bounds
|
|
111
|
+
let b = c.bounds;
|
|
112
|
+
el.attr("x", b.left).attr("y", b.top).attr("width", b.width).attr("height", b.height);
|
|
113
|
+
} else if (c.type == ItemType.PointText) {
|
|
114
|
+
el.attr("text-anchor", this._getTextAnchor(c.anchor[0]))
|
|
115
|
+
.attr("alignment-baseline", this._getTextAnchor(c.anchor[1]))
|
|
116
|
+
.attr("dominant-baseline", this._getTextAnchor(c.anchor[1]))
|
|
117
|
+
.text(c.text)
|
|
118
|
+
.attr("x", c.x).attr("y", c.y);
|
|
119
|
+
} else if (c.type == ItemType.Image) {
|
|
120
|
+
el.attr("href", c.src).attr("x", c.x).attr("y", c.y).attr("width", c.width).attr("height", c.height);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// for (let a in c.attrs) {
|
|
124
|
+
// el.attr(Attr2SVG[a], c.attrs[a]);
|
|
125
|
+
// }
|
|
126
|
+
|
|
127
|
+
for (let s in c.styles) {
|
|
128
|
+
if (c.styles[s] === undefined)
|
|
129
|
+
continue;
|
|
130
|
+
if (s.indexOf("Color") > 0 && c.styles[s].type == ItemType.LinearGradient) {
|
|
131
|
+
if (d3.select("#"+this._svgId).select("defs").empty())
|
|
132
|
+
d3.select("#"+this._svgId).append("defs");
|
|
133
|
+
let defs = d3.select("defs"), gradient = c.styles[s];
|
|
134
|
+
if (defs.select("#" + gradient.id).empty()) {
|
|
135
|
+
let grad = defs.append("linearGradient").attr("id", gradient.id);
|
|
136
|
+
grad.attr("x1", gradient.x1+"%").attr("x2", gradient.x2+"%").attr("y1", gradient.y1+"%").attr("y2", gradient.y2+"%");
|
|
137
|
+
for (let stop of gradient.stops)
|
|
138
|
+
grad.append("stop").attr("offset", stop.offset+"%").style("stop-color", stop.color).style("stop-opacity", stop.opacity);
|
|
139
|
+
}
|
|
140
|
+
el.style(Style2SVG[s], "url(#" + gradient.id + ")");
|
|
141
|
+
} else {
|
|
142
|
+
el.style(Style2SVG[s], c.styles[s]);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (c._rotate)
|
|
148
|
+
el.attr("transform", "rotate(" + c._rotate.join(" ") + ")");
|
|
149
|
+
|
|
150
|
+
// render vertices if shape is defined
|
|
151
|
+
if (c.vertices) {
|
|
152
|
+
// let shapes = c.vertices.map(d => d.shape).filter(d => d !== undefined);
|
|
153
|
+
// if (shapes.length > 0)
|
|
154
|
+
this._renderVertices(c, args);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// render scene bound
|
|
158
|
+
if (c.type == ItemType.Collection && args && args["collectionBounds"]) {
|
|
159
|
+
let b = c.bounds;
|
|
160
|
+
if (c.layout && c.layout.type == "grid") {
|
|
161
|
+
this._renderLayout(c);
|
|
162
|
+
} else {
|
|
163
|
+
if (!(c.id in this._decoMap)) {
|
|
164
|
+
this._decoMap[c.id] = d3.select("#"+this._svgId).append("rect").attr("class", "deco");
|
|
165
|
+
}
|
|
166
|
+
this._decoMap[c.id].attr("x", b.left).attr("y", b.top)
|
|
167
|
+
.attr("width", b.width).attr("height", b.height).attr("fill", "none")
|
|
168
|
+
.attr("stroke", "#1ecb40").attr("stroke-width", "2px")
|
|
169
|
+
.attr("stroke-dasharray", "5,5");
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
//render text/axis bound
|
|
174
|
+
// if (c.type == ItemType.PointText || c.type == ItemType.Axis) {
|
|
175
|
+
// let id = c.id + "-box";
|
|
176
|
+
// let b = c.bounds;
|
|
177
|
+
// if (!(id in this._decoMap)) {
|
|
178
|
+
// this._decoMap[id] = d3.select("#"+this._svgId).append("rect");
|
|
179
|
+
// }
|
|
180
|
+
// this._decoMap[id].attr("x", b.left).attr("y", b.top)
|
|
181
|
+
// .attr("width", b.width).attr("height", b.height).attr("fill", "none")
|
|
182
|
+
// .attr("stroke", "#1ecb40").attr("stroke-width", "1px")
|
|
183
|
+
// .attr("stroke-dasharray", "5,5");
|
|
184
|
+
// }
|
|
185
|
+
|
|
186
|
+
if (c.children) {
|
|
187
|
+
for (let child of c.children) {
|
|
188
|
+
this._renderItem(child, args);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
_renderVertices(c, args) {
|
|
195
|
+
let id = c.id+"-vertices";
|
|
196
|
+
if (!(id in this._compMap) && !args.flatten) {
|
|
197
|
+
let parent = c.parent,
|
|
198
|
+
pid = parent ? parent.id : this._svgId;
|
|
199
|
+
this._compMap[id] = d3.select("#"+pid).append("g").attr("id", id);
|
|
200
|
+
} else {
|
|
201
|
+
delete this._removed[id];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (!args.flatten) {
|
|
205
|
+
let shapes = c.vertices.map(d => d.shape).filter(d => d !== undefined);
|
|
206
|
+
if (shapes.length === 0) {
|
|
207
|
+
this._compMap[id].style("visible", "hidden");
|
|
208
|
+
return;
|
|
209
|
+
} else {
|
|
210
|
+
this._compMap[id].style("visible", "visible");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
let vertices = c.vertices.filter(d => d.shape !== undefined),
|
|
215
|
+
svgParent = args.flatten ? d3.select("#"+this._svgId) : d3.select("#"+id);
|
|
216
|
+
for (let v of vertices) {
|
|
217
|
+
let vid = id+"-"+v.id;
|
|
218
|
+
if (!(vid in this._compMap)) {
|
|
219
|
+
this._compMap[vid] = svgParent.append(v.shape).attr("id", vid);
|
|
220
|
+
} else if (v.shape !== this._compMap[vid].node().tagName) {
|
|
221
|
+
this._compMap[vid].remove();
|
|
222
|
+
this._compMap[vid] = svgParent.append(v.shape).attr("id", vid);
|
|
223
|
+
delete this._removed[vid];
|
|
224
|
+
} else {
|
|
225
|
+
delete this._removed[vid];
|
|
226
|
+
}
|
|
227
|
+
if (v.shape == "rect") {
|
|
228
|
+
d3.select("#"+vid).attr("x", v.x - v.width/2).attr("y", v.y - v.height/2)
|
|
229
|
+
.attr("width", v.width).attr("height", v.height);
|
|
230
|
+
} else if (v.shape == "circle") {
|
|
231
|
+
d3.select("#"+vid).attr("cx", v.x).attr("cy", v.y).attr("r", v.radius);
|
|
232
|
+
}
|
|
233
|
+
d3.select("#"+vid).style("fill", v.fillColor).style("opacity", v.opacity)
|
|
234
|
+
.style("stroke-width", v.strokeWidth).style("stroke", v.strokeColor);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
_renderLayout(c) {
|
|
239
|
+
let gridId = c.id+"-grid";
|
|
240
|
+
if (!(gridId in this._decoMap)) {
|
|
241
|
+
this._decoMap[gridId] = d3.select("#"+this._svgId).append("g")
|
|
242
|
+
.attr("id", gridId).attr("class", "deco");
|
|
243
|
+
}
|
|
244
|
+
let cellBounds = c.layout.cellBounds, rowGap = c.layout.rowGap;
|
|
245
|
+
this._decoMap[gridId].selectAll("rect").remove();
|
|
246
|
+
this._decoMap[gridId].selectAll("rect").data(cellBounds.slice(0, cellBounds.length -1))
|
|
247
|
+
.enter().append("rect").attr("x", d => d.left).attr("y", d => d.bottom)
|
|
248
|
+
.attr("width", d => d.width).attr("height", rowGap)
|
|
249
|
+
.style("fill", "pink").style("opacity", 0.5)
|
|
250
|
+
;
|
|
251
|
+
for (let cb of cellBounds) {
|
|
252
|
+
this._decoMap[gridId].append("rect").attr("x", cb.left).attr("y", cb.top)
|
|
253
|
+
.attr("width", cb.width).attr("height", cb.height)
|
|
254
|
+
.attr("stroke", "blue").attr("stroke-width", "1px")
|
|
255
|
+
.attr("stroke-dasharray", "5,5").attr("fill", "none");
|
|
256
|
+
}
|
|
257
|
+
// let left = Math.min(...cellBounds.map(d => d.left)),
|
|
258
|
+
// top = Math.min(...cellBounds.map(d => d.top))
|
|
259
|
+
// this._decoMap[gridId].append("rect").attr("x", left).attr("y", top)
|
|
260
|
+
// .attr("width", c.bounds.width).attr("height", c.bounds.height)
|
|
261
|
+
// .attr("stroke", "blue").attr("stroke-width", "1px")
|
|
262
|
+
// .attr("stroke-dasharray", "5,5").attr("fill", "none");
|
|
263
|
+
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
_getTextAnchor(anchor) {
|
|
267
|
+
switch(anchor) {
|
|
268
|
+
case "top":
|
|
269
|
+
return "text-before-edge";
|
|
270
|
+
//return "hanging";
|
|
271
|
+
case "bottom":
|
|
272
|
+
//return "text-after-edge";
|
|
273
|
+
return "auto";
|
|
274
|
+
case "left":
|
|
275
|
+
return "start";
|
|
276
|
+
case "right":
|
|
277
|
+
return "end";
|
|
278
|
+
case "center":
|
|
279
|
+
return "middle";
|
|
280
|
+
case "middle":
|
|
281
|
+
return "middle";
|
|
282
|
+
default:
|
|
283
|
+
return anchor;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
_getSVGElementType(cpnt) {
|
|
288
|
+
switch (cpnt.type) {
|
|
289
|
+
case ItemType.Rect:
|
|
290
|
+
return "rect";
|
|
291
|
+
case ItemType.Collection:
|
|
292
|
+
case ItemType.Group:
|
|
293
|
+
case ItemType.Glyph:
|
|
294
|
+
case ItemType.Scene:
|
|
295
|
+
case ItemType.Axis:
|
|
296
|
+
case ItemType.Legend:
|
|
297
|
+
case ItemType.Gridlines:
|
|
298
|
+
return "g";
|
|
299
|
+
case ItemType.Area:
|
|
300
|
+
case ItemType.Path:
|
|
301
|
+
case ItemType.Polygon:
|
|
302
|
+
case ItemType.Ring:
|
|
303
|
+
case ItemType.Pie:
|
|
304
|
+
case ItemType.Arc:
|
|
305
|
+
case ItemType.Link:
|
|
306
|
+
case ItemType.Line:
|
|
307
|
+
return "path";
|
|
308
|
+
case ItemType.Circle:
|
|
309
|
+
return "circle";
|
|
310
|
+
//return "line";
|
|
311
|
+
case ItemType.PointText:
|
|
312
|
+
return "text";
|
|
313
|
+
case "vertex":
|
|
314
|
+
if (cpnt.shape == "circle")
|
|
315
|
+
return "circle";
|
|
316
|
+
else if (cpnt.shape == "rect")
|
|
317
|
+
return "rect";
|
|
318
|
+
else throw "argument exception";
|
|
319
|
+
case "image":
|
|
320
|
+
return "image";
|
|
321
|
+
default:
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|