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,241 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,325 +0,0 @@
|
|
|
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
|
-
}
|