mascot-vis 3.0.0 → 3.0.1

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.
Files changed (152) hide show
  1. package/package.json +1 -2
  2. package/js/depGraphVis.js +0 -66
  3. package/src-new-ts/action/createElement.ts +0 -91
  4. package/src-new-ts/action/encode.js +0 -20
  5. package/src-new-ts/action/repeat.js +0 -128
  6. package/src-new-ts/action/traverseScene.js +0 -41
  7. package/src-new-ts/data/Network.js +0 -2
  8. package/src-new-ts/data/Scope.js +0 -135
  9. package/src-new-ts/data/Table.js +0 -263
  10. package/src-new-ts/data/Tree.js +0 -3
  11. package/src-new-ts/data/field.ts +0 -115
  12. package/src-new-ts/data/import.ts +0 -96
  13. package/src-new-ts/data/predicate.ts +0 -82
  14. package/src-new-ts/depgraph/DepGraph.js +0 -178
  15. package/src-new-ts/depgraph/Edge.js +0 -9
  16. package/src-new-ts/depgraph/SceneGraph2DepGraph.js +0 -110
  17. package/src-new-ts/depgraph/Signal.js +0 -12
  18. package/src-new-ts/depgraph/operator/BoundsEvaluator.js +0 -30
  19. package/src-new-ts/depgraph/operator/Dataflow.js +0 -41
  20. package/src-new-ts/depgraph/operator/DomainBuilder.js +0 -50
  21. package/src-new-ts/depgraph/updateDepGraph.js +0 -45
  22. package/src-new-ts/depgraph/variable/BoundsVar.js +0 -81
  23. package/src-new-ts/depgraph/variable/ChannelVar.js +0 -17
  24. package/src-new-ts/depgraph/variable/DataScopeVar.js +0 -12
  25. package/src-new-ts/depgraph/variable/DomainVar.js +0 -15
  26. package/src-new-ts/depgraph/variable/FieldVar.js +0 -17
  27. package/src-new-ts/depgraph/variable/LayoutParameter.js +0 -8
  28. package/src-new-ts/depgraph/variable/ScaleVar.js +0 -13
  29. package/src-new-ts/depgraph/variable/Variable.js +0 -39
  30. package/src-new-ts/element/gradient/LinearGradient.js +0 -37
  31. package/src-new-ts/element/group/Collection.js +0 -109
  32. package/src-new-ts/element/group/Group.js +0 -307
  33. package/src-new-ts/element/group/Scene.js +0 -98
  34. package/src-new-ts/element/mark/CircleMark.ts +0 -85
  35. package/src-new-ts/element/mark/Mark.ts +0 -233
  36. package/src-new-ts/element/mark/PathMark.js +0 -483
  37. package/src-new-ts/element/mark/Segment.js +0 -29
  38. package/src-new-ts/element/mark/Vertex.js +0 -118
  39. package/src-new-ts/encode/Scale.ts +0 -115
  40. package/src-new-ts/index.ts +0 -19
  41. package/src-new-ts/layout/Layout.ts +0 -3
  42. package/src-new-ts/render/CanvasRenderer.ts +0 -24
  43. package/src-new-ts/render/SVGRenderer.js +0 -316
  44. package/src-new-ts/util.ts +0 -3
  45. package/src-old/action/Classify.js +0 -53
  46. package/src-old/action/Densify.js +0 -199
  47. package/src-old/action/Partition.js +0 -531
  48. package/src-old/action/Repeat.js +0 -106
  49. package/src-old/action/Repopulate.js +0 -44
  50. package/src-old/action/Stratify.js +0 -156
  51. package/src-old/basic/Gradient.js +0 -37
  52. package/src-old/basic/Point.js +0 -51
  53. package/src-old/basic/Rectangle.js +0 -63
  54. package/src-old/bind/bindToAngle.js +0 -56
  55. package/src-old/bind/bindToAreaMark.js +0 -360
  56. package/src-old/bind/bindToColor.js +0 -114
  57. package/src-old/bind/bindToLink.js +0 -81
  58. package/src-old/bind/bindToPosition.js +0 -283
  59. package/src-old/bind/bindToRadialDistance.js +0 -62
  60. package/src-old/bind/bindToSize.js +0 -235
  61. package/src-old/bind/bindToText.js +0 -60
  62. package/src-old/bind/bindToThickness.js +0 -100
  63. package/src-old/constraint/AffixConstraint.js +0 -129
  64. package/src-old/constraint/AlignConstraint.js +0 -58
  65. package/src-old/core/Encoding.js +0 -336
  66. package/src-old/core/Scale.js +0 -322
  67. package/src-old/core/SceneLoader.js +0 -290
  68. package/src-old/core/SceneValidator.js +0 -232
  69. package/src-old/core/SpecExecutor.js +0 -113
  70. package/src-old/core/SpecGenerator.js +0 -350
  71. package/src-old/data/DataImporter.js +0 -64
  72. package/src-old/data/DataScope.js +0 -124
  73. package/src-old/data/DataTable.js +0 -338
  74. package/src-old/data/Network.js +0 -106
  75. package/src-old/data/Tree.js +0 -251
  76. package/src-old/data/transform/Bin.js +0 -46
  77. package/src-old/data/transform/Filter.js +0 -48
  78. package/src-old/data/transform/Groupby.js +0 -18
  79. package/src-old/data/transform/KDE.js +0 -58
  80. package/src-old/data/transform/Sort.js +0 -14
  81. package/src-old/data/transform/Split.js +0 -5
  82. package/src-old/data/transform/partition.js +0 -46
  83. package/src-old/history/UndoRedoStack +0 -0
  84. package/src-old/index.js +0 -271
  85. package/src-old/indexSVG.js +0 -259
  86. package/src-old/interaction/Interaction.js +0 -91
  87. package/src-old/interaction/MouseEvent.js +0 -8
  88. package/src-old/interaction/Selection.js +0 -9
  89. package/src-old/interaction/brush.js +0 -362
  90. package/src-old/item/Segment.js +0 -29
  91. package/src-old/item/Vertex.js +0 -118
  92. package/src-old/item/composite/Collection.js +0 -106
  93. package/src-old/item/composite/Glyph.js +0 -19
  94. package/src-old/item/composite/Group.js +0 -310
  95. package/src-old/item/composite/Scene.js +0 -1251
  96. package/src-old/item/mark/ArcPath.js +0 -181
  97. package/src-old/item/mark/AreaPath.js +0 -78
  98. package/src-old/item/mark/CirclePath.js +0 -102
  99. package/src-old/item/mark/EllipsePath.js +0 -5
  100. package/src-old/item/mark/Image.js +0 -101
  101. package/src-old/item/mark/LinkPath.js +0 -118
  102. package/src-old/item/mark/Mark.js +0 -163
  103. package/src-old/item/mark/Path.js +0 -494
  104. package/src-old/item/mark/PointText.js +0 -201
  105. package/src-old/item/mark/PolygonPath.js +0 -64
  106. package/src-old/item/mark/RectPath.js +0 -88
  107. package/src-old/item/mark/RingPath.js +0 -92
  108. package/src-old/item/refs/Axis.js +0 -362
  109. package/src-old/item/refs/EncodingAxis.js +0 -515
  110. package/src-old/item/refs/Gridlines.js +0 -144
  111. package/src-old/item/refs/LayoutAxis.js +0 -316
  112. package/src-old/item/refs/Legend.js +0 -273
  113. package/src-old/layout/Circular.js +0 -95
  114. package/src-old/layout/Force.js +0 -52
  115. package/src-old/layout/Grid.js +0 -423
  116. package/src-old/layout/Layout.js +0 -13
  117. package/src-old/layout/Packing.js +0 -56
  118. package/src-old/layout/Stack.js +0 -264
  119. package/src-old/layout/Strata.js +0 -88
  120. package/src-old/layout/Sugiyama.js +0 -59
  121. package/src-old/layout/TidyTree.js +0 -105
  122. package/src-old/layout/Treemap.js +0 -87
  123. package/src-old/renderer/SVGInteractionHandler.js +0 -241
  124. package/src-old/renderer/SVGRenderer.js +0 -325
  125. package/src-old/renderer/WebGLRenderer.js +0 -1097
  126. package/src-old/renderer/WebGLRenderer2.js +0 -249
  127. package/src-old/renderer/threejs/Line2.js +0 -18
  128. package/src-old/renderer/threejs/LineGeometry.js +0 -77
  129. package/src-old/renderer/threejs/LineMaterial.js +0 -605
  130. package/src-old/renderer/threejs/LineSegments2.js +0 -281
  131. package/src-old/renderer/threejs/LineSegmentsGeometry.js +0 -226
  132. package/src-old/renderer/threejs/Wireframe.js +0 -51
  133. package/src-old/renderer/threejs/WireframeGeometry2.js +0 -16
  134. package/src-old/scale/areaSize.js +0 -0
  135. package/src-old/scale/domain.js +0 -38
  136. package/src-old/util/Constants.js +0 -180
  137. package/src-old/util/DataUtil.js +0 -35
  138. package/src-old/util/ItemUtil.js +0 -586
  139. package/src-old/util/Numerical.js +0 -33
  140. package/tests/demo-tests/README.md +0 -80
  141. package/tests/demo-tests/SVG2PNG.js +0 -56
  142. package/tests/demo-tests/demos2CanvasPNGs.js +0 -69
  143. package/tests/demo-tests/demos2ScenesSVGs.js +0 -100
  144. package/tests/demo-tests/pathElementWorker.js +0 -91
  145. package/tests/demo-tests/pixelTest.js +0 -62
  146. package/tests/demo-tests/renderDemos.html +0 -132
  147. package/tests/demo-tests/serializationTest.js +0 -36
  148. package/tests/demo-tests/serializeDemos.html +0 -134
  149. package/tests/unit-tests/README.md +0 -4
  150. package/tests/unit-tests/jasmine-browser.json +0 -21
  151. package/tests/unit-tests/jasmine.json +0 -14
  152. package/tests/unit-tests/testSpec.js +0 -274
@@ -1,322 +0,0 @@
1
- import * as d3 from 'd3';
2
- import { Errors, ScaleType, Warnings } from '../util/Constants';
3
- import { ItemCounter } from '../util/ItemUtil';
4
- import SceneValidator from './SceneValidator';
5
-
6
-
7
- export default class Scale {
8
-
9
- constructor(type, args) {
10
- if (ScaleType.indexOf(type) < 0) {
11
- throw new Error(Errors.UNKOWNN_SCALE_TYPE + ": " + type);
12
- }
13
- this._type = type;
14
- //offset in terms of absolute coordinates on screen, this property is useful for reusing scales on items that are not in a layout
15
- this._offset = undefined;
16
- this.id = "scale" + ItemCounter["scale"]++;
17
- this._flipped = false;
18
- this._includeZero = false;
19
- switch (type) {
20
- case "linear":
21
- if (args) {
22
- //mapping
23
- let domain = Object.keys(args).map(d => parseFloat(d)).sort((a,b) => a - b),
24
- range = domain.map(d => args[d]);
25
- this._scale = d3.scaleLinear(domain, range);
26
- if ("clamp" in args)
27
- this._scale.clamp(args.clamp);
28
- this._mapping = args;
29
- } else {
30
- this._scale = d3.scaleLinear();
31
- }
32
- break;
33
- case "point":
34
- this._scale = d3.scalePoint();
35
- break;
36
- case "ordinal":
37
- this._scale = d3.scaleOrdinal();
38
- break;
39
- case "ordinalColor":
40
- this._scale = d3.scaleOrdinal(args? args.size ? d3[args.scheme][args.size] : d3[args.scheme] : d3.schemeCategory10);
41
- break;
42
- case "power":
43
- this._scale = d3.scalePow().exponent(2);
44
- break;
45
- case "sqrt":
46
- this._scale = d3.scalePow().exponent(0.5);
47
- break;
48
- case "log":
49
- this._scale = d3.scaleLog();
50
- break;
51
- case "identity":
52
- case "time":
53
- this._scale = d3.scaleTime();
54
- break;
55
- case "sequentialColor":
56
- case "divergingColor":
57
- if (args && typeof(args) == "string") {
58
- this._scale = d3.scaleSequential(d3[args]);
59
- this._scheme = args;
60
- }
61
- else
62
- this._scale = d3.scaleSequential();
63
- break;
64
- default:
65
- break;
66
- }
67
- this.encodings = [];
68
- }
69
-
70
- set scheme(s) {
71
- if (this._type.indexOf("Color") < 0 && this._type !== "linear") return;
72
- //TODO: need to verify the scheme is compatible with the data type and characteristics
73
- let scale = d3.scaleSequential(d3[s]), domain = this._scale.domain();
74
- if (Math.min(...domain) * Math.max(...domain) < 0) {
75
- let abs = Math.max(Math.abs(Math.min(...domain)), Math.abs(Math.max(...domain)));
76
- domain = [-abs, abs];
77
- }
78
- scale.domain(domain);
79
- this._scheme = s;
80
- this._scale = scale;
81
- if (this._type === "linear") {
82
- this._type = this._scale.domain()[0] * this._scale.domain()[1] < 0 ? "divergingColor" : "sequentialColor";
83
- if (this._mapping)
84
- this._mapping = undefined;
85
- }
86
- for (let enc of this.encodings) {
87
- if (enc._mapping)
88
- enc._mapping = undefined;
89
- enc._scheme = s;
90
- enc._apply();
91
- }
92
- }
93
-
94
- get scheme() {
95
- return this._scheme;
96
- }
97
-
98
- get type() {
99
- return this._type;
100
- }
101
-
102
- set type(t) {
103
- let scale;
104
- switch (t) {
105
- case "linear":
106
- scale = d3.scaleLinear();
107
- break;
108
- case "power":
109
- scale = d3.scalePow().exponent(2);
110
- break;
111
- case "sqrt":
112
- scale = d3.scalePow().exponent(0.5);
113
- break;
114
- case "log":
115
- scale = d3.scaleLog();
116
- break;
117
- default:
118
- break;
119
- }
120
- if (scale) {
121
- this._type = t;
122
- scale.domain(this._scale.domain()).range(this._scale.range());
123
- this._scale = scale;
124
- for (let enc of this.encodings) {
125
- //enc._map();
126
- enc._apply();
127
- }
128
- for (let enc of this.encodings) {
129
- enc.scene._updateAncestorBounds(enc.item, enc.items);
130
- }
131
- } else {
132
- console.warn(Warnings.UNSUPPORTED_SCALE_TYPE_CHANGE + t);
133
- }
134
- }
135
-
136
- toJSON() {
137
- let json = {};
138
- json.type = this.type;
139
- json.id = this.id;
140
- json.offset = this._offset;
141
- if (this._scheme)
142
- json.scheme = this._scheme;
143
- json.domain = this._scale.domain();
144
- json.range = this.range;
145
- json.clamp = this.clamp;
146
- json.isFlipped = this.isFlipped;
147
- json.includeZero = this.includeZero;
148
-
149
- if (this._mapping)
150
- json.mapping = this._mapping;
151
- if (this._baseItem)
152
- json.baseItem = this._baseItem.id;
153
- return json;
154
- }
155
-
156
- // static mergeDomain(d1, d2){
157
- // return [Math.min(d1[0], d2[0]), Math.max(d1[1], d2[1])];
158
- // }
159
-
160
- //the argument s will be discarded, this scale will kept being used
161
- //only internally used in encoding._map
162
- _merge(s) {
163
- if (this.type != s.type) {
164
- throw Errors.DIFFERENT_SCALE_TYPE;
165
- }
166
- //let scale;
167
- let newDomain, newRange;
168
- switch (this.type) {
169
- case "linear":
170
- case "time":
171
- newDomain = [Math.min(this.domain[0], s.domain[0]), Math.max(this.domain[1], s.domain[1])];
172
- newRange = [0, this.map(newDomain[1]) - this.map(newDomain[0])];
173
- break;
174
- case "point":
175
- case "ordinalColor":
176
- newDomain = [...new Set(this.domain.concat(s.domain))];
177
- //TODO: need to compute new range
178
- newRange = [];
179
- //scale = createScale("point");
180
- //scale.domain = [...new Set(this.domain.concat(s.domain))];
181
- break;
182
- default:
183
- console.log("TODO: merge scale type", this.type);
184
- break;
185
- }
186
- this._scale.domain(newDomain);
187
- this._scale.range(newRange);
188
- }
189
-
190
- get domain() {
191
- //TODO: this._scale.domain contains the true data domain values,
192
- //this getter returns a different domain depending on includeZero
193
- if (this._includeZero) {
194
- let d = this._scale.domain();
195
- return [0, d[1]];
196
- } else
197
- return this._scale.domain();
198
- }
199
-
200
- set domain(d) {
201
- this._scale.domain(d);
202
- for (let enc of this.encodings) {
203
- //enc._map();
204
- enc._apply();
205
- }
206
- }
207
-
208
- get range() {
209
- return this._scale.range();
210
- }
211
-
212
- //disable setting range directly because scale ranges are internally represented as [0, extent],
213
- //to support this, the argument should be in real screen coordinates and need to do internal conversion
214
- set range(r) {
215
- //TODO: check r is a two-element array
216
- this._scale.range(r);
217
- for (let enc of this.encodings) {
218
- //enc._map();
219
- enc._apply();
220
- }
221
-
222
- for (let enc of this.encodings) {
223
- enc.scene._updateAncestorBounds(enc.item, enc.items);
224
- }
225
- }
226
-
227
- _setRange(r) {
228
- //TODO: check r is a two-element array
229
- this._scale.range(r);
230
- SceneValidator.scaleRangeSet(this);
231
- }
232
-
233
- get clamp() {
234
- if (this.type == "linear")
235
- return this._scale.clamp();
236
- else
237
- return false;
238
- }
239
-
240
- set clamp(c) {
241
- if (this.type == "linear")
242
- this._scale.clamp(c);
243
- }
244
-
245
- set rangeExtent(e) {
246
- //TODO: check e is a valid number
247
- let r = this._scale.range();
248
- this._setRange([r[0], r[0] + e]);
249
- // if (r[0] < r[1])
250
- // this._setRange([r[0], r[0] + e]);
251
- // else
252
- // this._setRange([r[1] + e, r[1]]);
253
- }
254
-
255
- get rangeExtent() {
256
- let r = this._scale.range();
257
- return Math.abs(r[1] - r[0]);
258
- }
259
-
260
- _addEncoding(b) {
261
- if (this.encodings.indexOf(b) < 0)
262
- this.encodings.push(b);
263
- }
264
-
265
- map(d) {
266
- let s = this._scale.copy(), v;
267
- s.domain(this.domain);
268
- if (this._flipped) {
269
- s.range(this._scale.range().reverse());
270
- }
271
- v = s(d);
272
- if (typeof(v) === "number")
273
- return Math.round(v);
274
- else
275
- return v;
276
- }
277
-
278
- //TODO: handle flip
279
- invert(r) {
280
- return this._scale.invert(r);
281
- }
282
-
283
- get offset() {
284
- return this._offset;
285
- }
286
-
287
- set offset(s) {
288
- this._offset = s;
289
- for (let enc of this.encodings) {
290
- enc._apply();
291
- }
292
- }
293
-
294
- get isFlipped() {
295
- return this._flipped;
296
- }
297
-
298
- set isFlipped(f) {
299
- this._flipped = f;
300
- }
301
-
302
- get includeZero() {
303
- return this._includeZero;
304
- }
305
-
306
- set includeZero(i) {
307
- this._includeZero = i;
308
- SceneValidator.scaleDomainSet(this);
309
- }
310
-
311
- get mapping() {
312
- return this._mapping;
313
- }
314
-
315
- getEncodedChannels() {
316
- let channels = {};
317
- for (let enc of this.encodings) {
318
- channels[enc.channel] = true;
319
- }
320
- return Object.keys(channels);
321
- }
322
- }
@@ -1,290 +0,0 @@
1
- import Rectangle from "../basic/Rectangle";
2
- import AffixConstraint from "../constraint/AffixConstraint";
3
- import AlignConstraint from "../constraint/AlignConstraint";
4
- import DataScope from "../data/DataScope";
5
- import DataTable from "../data/DataTable";
6
- import Segment from "../item/Segment";
7
- import Vertex from "../item/Vertex";
8
- import { ItemType, LayoutType } from "../util/Constants";
9
- import { getLayout, isPath, ItemCounter } from "../util/ItemUtil";
10
- import Scale from "./Scale";
11
- import Scene from "../item/composite/Scene";
12
- import LinearGradient from "../basic/Gradient";
13
-
14
- export default class SceneLoader {
15
-
16
- constructor() {
17
- this.axes = {};
18
- this.legends = [];
19
- this.gridlines = [];
20
- this.scales = {};
21
- this.tables = {};
22
- }
23
-
24
- load(json) {
25
- //console.log("saved", json);
26
- let sceneArgs = {};
27
- if (json.fillColor)
28
- sceneArgs.fillColor = json.fillColor;
29
- if (json.itemCounter) {
30
- for (let t in json.itemCounter)
31
- ItemCounter[t] = json.itemCounter[t];
32
- }
33
- let scn = new Scene(sceneArgs);
34
- scn.id = json.id;
35
- scn.type = json.type;
36
- if (json.bounds)
37
- scn._bounds = new Rectangle(json.bounds.left, json.bounds.top, json.bounds.width, json.bounds.height);
38
-
39
- if (json.tables) {
40
- for (let t in json.tables) {
41
- this.tables[t] = new DataTable(json.tables[t].data, json.tables[t].url, json.tables[t].fieldTypes);
42
- this.tables[t].id = json.tables[t].id;
43
- }
44
- }
45
-
46
- for (let c of json.children) {
47
- this._processItem(scn, c, scn);
48
- }
49
-
50
- if (json.scales) {
51
- for (let s in json.scales)
52
- this._loadScale(json.scales[s], scn);
53
- }
54
-
55
- if (json.encodings) {
56
- for (let e of json.encodings) {
57
- this._loadEncoding(e, scn);
58
- }
59
- }
60
-
61
- if (json.constraints) {
62
- for (let c in json.constraints)
63
- this._loadConstraint(json.constraints[c], scn);
64
- }
65
-
66
- for (let a in this.axes) {
67
- this._createGuide(scn, this.axes[a]);
68
- }
69
-
70
- for (let l of this.legends) {
71
- this._createGuide(scn, l);
72
- }
73
-
74
- for (let l of this.gridlines) {
75
- this._createGuide(scn, l);
76
- }
77
-
78
- //console.log("loaded", scn);
79
- return scn;
80
- }
81
-
82
- _loadScale(s, scn) {
83
- let scale;
84
- // if (s.type === "sequentialColor" && s.scheme) {
85
- if (s.type.indexOf("Color") > 0 && s.scheme) {
86
- scale = new Scale(s.type, s.scheme);
87
- } else {
88
- scale = new Scale(s.type);
89
- scale.range = s.range;
90
- }
91
- scale.domain = s.type == "time" ? s.domain.map(d => new Date(d)) : s.domain;
92
- scale.id = s.id;
93
- if ("offset" in s)
94
- scale.offset = s.offset;
95
- scale.isFlipped = s.isFlipped;
96
- scale.clamp = s.clamp;
97
- scale._mapping = s.mapping;
98
- if ("includeZero" in s)
99
- scale.includeZero = s.includeZero;
100
- if ("baseItem" in s)
101
- scale._baseItem = scn.getItem(s.baseItem);
102
- this.scales[scale.id] = scale;
103
- //console.log(scale.domain, scale.range);
104
- }
105
-
106
- _loadEncoding(enc, scene) {
107
- if (enc.args.datatable)
108
- enc.args.datatable = this.tables[enc.args.datatable];
109
- if (enc.args.scale) {
110
- enc.args.scale = this.scales[enc.args.scale];
111
- }
112
- //let item = scene.getItem(enc.anyItem);
113
- let items = enc.items.map(d => scene.getItem(d));
114
- scene._doEncode(items, enc.args);
115
- scene._relayoutAncestors(items[0], items);
116
- }
117
-
118
- _createGuide(scene, guide) {
119
- switch (guide.type) {
120
- case ItemType.Axis:
121
- if (guide.args.item) {
122
- guide.args.item = scene.getItem(guide.args.item);
123
- }
124
- scene.axis(guide.channel, guide.field, guide.args);
125
- break;
126
- case ItemType.Legend:
127
- scene.legend(guide.channel, guide.field, guide.args);
128
- break;
129
- case ItemType.Gridlines:
130
- if (guide.args.item) {
131
- guide.args.item = scene.getItem(guide.args.item);
132
- }
133
- scene.gridlines(guide.channel, guide.field, guide.args);
134
- break;
135
- }
136
- }
137
-
138
- _processItem(parent, itm, scene) {
139
- switch (itm.type) {
140
- case ItemType.Axis: {
141
- let id = itm.classId ? itm.classId : itm.id;
142
- if (itm.args.tickValues && itm.args.isDate) {
143
- itm.args.tickValues = itm.args.tickValues.map(d => new Date(d));
144
- }
145
- this.axes[id] = itm;
146
- break;
147
- }
148
- case ItemType.Gridlines:
149
- if (itm.args.values && itm.args.isDate) {
150
- itm.args.values = itm.args.values.map(d => new Date(d));
151
- }
152
- this.gridlines.push(itm);
153
- break;
154
- case ItemType.Legend:
155
- this.legends.push(itm);
156
- break;
157
- case ItemType.Collection: {
158
- let coll = scene.collection();
159
- parent.addChild(coll);
160
- this._loadGroup(coll, itm, scene);
161
- break;
162
- }
163
- case ItemType.Group: {
164
- let g = scene.group();
165
- parent.addChild(g);
166
- this._loadGroup(g, itm, scene);
167
- break;
168
- }
169
- case ItemType.Glyph: {
170
- let glyph = scene.glyph();
171
- parent.addChild(glyph);
172
- this._loadGroup(glyph, itm, scene);
173
- break;
174
- }
175
- default:
176
- this._loadMark(parent, itm, scene);
177
- break;
178
- }
179
- }
180
-
181
- _loadConstraint(c, scene) {
182
- switch (c.type) {
183
- case "affixation": {
184
- let item = scene.getItem(c.item), baseItem = scene.getItem(c.baseItem);
185
- let cstr = new AffixConstraint(item, baseItem, scene, c.channel, c.itemAnchor, c.baseAnchor, c.offset);
186
- cstr.id = c.id;
187
- scene.constraints[c.id] = cstr;
188
- cstr.apply();
189
- return cstr;
190
- }
191
- case "alignment": {
192
- let items = c.items.map(d => scene.getItem(d));
193
- let cstr = new AlignConstraint(items, c.direction);
194
- cstr.id = c.id;
195
- scene.constraints[c.id] = cstr;
196
- cstr.apply();
197
- return cstr;
198
- }
199
- }
200
- }
201
-
202
- _loadDataScope(ds) {
203
- let scope = new DataScope(this.tables[ds.dt]);
204
- for (let f in ds.f2v) {
205
- scope._field2value[f] = ds.f2v[f];
206
- scope._updateTuples(f, ds.f2v[f]);
207
- }
208
- return scope;
209
- }
210
-
211
- _loadGroup(coll, itm, scene) {
212
- coll.id = itm.id;
213
- if (itm.classId)
214
- coll.classId = itm.classId;
215
- if (itm.dataScope)
216
- coll.dataScope = this._loadDataScope(itm.dataScope);
217
- if (itm.children) {
218
- for (let c of itm.children) {
219
- this._processItem(coll, c, scene);
220
- }
221
- }
222
- if (itm.layout) {
223
- let l = this._loadLayout(itm.layout);
224
- l.group = coll;
225
- coll._layout = l;
226
- }
227
- if (itm.bounds)
228
- coll._bounds = new Rectangle(itm.bounds.left, itm.bounds.top, itm.bounds.width, itm.bounds.height);
229
- }
230
-
231
- _loadMark(parent, itm, scene) {
232
- if (itm.args.fillColor && itm.args.fillColor.type === "LinearGradient") {
233
- let g = itm.args.fillColor;
234
- itm.args.fillColor = new LinearGradient(g);
235
- itm.args.fillColor.id = g.id;
236
- itm.args.fillColor._stops = g.stops;
237
- }
238
- if ("id" in itm)
239
- itm.args.id = itm.id;
240
- let mark = scene.mark(itm.type, itm.args);
241
- if (itm.classId)
242
- mark.classId = itm.classId;
243
- if (itm.dataScope)
244
- mark.dataScope = this._loadDataScope(itm.dataScope);
245
- if (itm.vertices) {
246
- const vertices = [];
247
- for (let d of itm.vertices) {
248
- const v = Vertex.fromJSON(d, mark);
249
- if (v.dataScope)
250
- v.dataScope = this._loadDataScope(v.dataScope);
251
- vertices.push(v);
252
- }
253
- mark.vertices = vertices;
254
- //TODO: modify instead of replace segments
255
- mark.segments = [];
256
- for (let i = 1; i < mark.vertices.length; i++)
257
- mark.segments.push(new Segment(mark.vertices[i-1], mark.vertices[i], mark, mark.segmentCounter++));
258
- }
259
- if (itm.bounds)
260
- mark._bounds = new Rectangle(itm.bounds.left, itm.bounds.top, itm.bounds.width, itm.bounds.height);
261
- if (itm.boundsOffsets)
262
- mark.boundsOffsets = itm.boundsOffsets;
263
- if (isPath(mark)) {
264
- mark.vertexCounter = itm.vertexCounter;
265
- mark.segmentCounter = itm.segmentCounter;
266
- mark.curveMode = itm.curveMode;
267
- } else if (itm.type === ItemType.Image) {
268
- mark.src = itm.src;
269
- mark.width = itm.width;
270
- mark.height = itm.height;
271
- mark.x = itm.x;
272
- mark.y = itm.y;
273
- }
274
- parent.addChild(mark);
275
- }
276
-
277
- _loadLayout(l) {
278
- let lo = getLayout(l.type, l.args);
279
- switch (l.type) {
280
- case LayoutType.Grid:
281
- lo._left = l.left;
282
- lo._top = l.top;
283
- break;
284
- default:
285
- break;
286
- }
287
- return lo;
288
- }
289
-
290
- }