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.
Files changed (156) hide show
  1. package/dist/mascot-esm.js +186 -0
  2. package/package.json +3 -6
  3. package/dist/mascot-es.js +0 -27745
  4. package/dist/mascot-min.js +0 -186
  5. package/dist/mascot-umd.js +0 -27781
  6. package/js/depGraphVis.js +0 -66
  7. package/src-new-ts/action/createElement.ts +0 -91
  8. package/src-new-ts/action/encode.js +0 -20
  9. package/src-new-ts/action/repeat.js +0 -128
  10. package/src-new-ts/action/traverseScene.js +0 -41
  11. package/src-new-ts/data/Network.js +0 -2
  12. package/src-new-ts/data/Scope.js +0 -135
  13. package/src-new-ts/data/Table.js +0 -263
  14. package/src-new-ts/data/Tree.js +0 -3
  15. package/src-new-ts/data/field.ts +0 -115
  16. package/src-new-ts/data/import.ts +0 -96
  17. package/src-new-ts/data/predicate.ts +0 -82
  18. package/src-new-ts/depgraph/DepGraph.js +0 -178
  19. package/src-new-ts/depgraph/Edge.js +0 -9
  20. package/src-new-ts/depgraph/SceneGraph2DepGraph.js +0 -110
  21. package/src-new-ts/depgraph/Signal.js +0 -12
  22. package/src-new-ts/depgraph/operator/BoundsEvaluator.js +0 -30
  23. package/src-new-ts/depgraph/operator/Dataflow.js +0 -41
  24. package/src-new-ts/depgraph/operator/DomainBuilder.js +0 -50
  25. package/src-new-ts/depgraph/updateDepGraph.js +0 -45
  26. package/src-new-ts/depgraph/variable/BoundsVar.js +0 -81
  27. package/src-new-ts/depgraph/variable/ChannelVar.js +0 -17
  28. package/src-new-ts/depgraph/variable/DataScopeVar.js +0 -12
  29. package/src-new-ts/depgraph/variable/DomainVar.js +0 -15
  30. package/src-new-ts/depgraph/variable/FieldVar.js +0 -17
  31. package/src-new-ts/depgraph/variable/LayoutParameter.js +0 -8
  32. package/src-new-ts/depgraph/variable/ScaleVar.js +0 -13
  33. package/src-new-ts/depgraph/variable/Variable.js +0 -39
  34. package/src-new-ts/element/gradient/LinearGradient.js +0 -37
  35. package/src-new-ts/element/group/Collection.js +0 -109
  36. package/src-new-ts/element/group/Group.js +0 -307
  37. package/src-new-ts/element/group/Scene.js +0 -98
  38. package/src-new-ts/element/mark/CircleMark.ts +0 -85
  39. package/src-new-ts/element/mark/Mark.ts +0 -233
  40. package/src-new-ts/element/mark/PathMark.js +0 -483
  41. package/src-new-ts/element/mark/Segment.js +0 -29
  42. package/src-new-ts/element/mark/Vertex.js +0 -118
  43. package/src-new-ts/encode/Scale.ts +0 -115
  44. package/src-new-ts/index.ts +0 -19
  45. package/src-new-ts/layout/Layout.ts +0 -3
  46. package/src-new-ts/render/CanvasRenderer.ts +0 -24
  47. package/src-new-ts/render/SVGRenderer.js +0 -316
  48. package/src-new-ts/util.ts +0 -3
  49. package/src-old/action/Classify.js +0 -53
  50. package/src-old/action/Densify.js +0 -199
  51. package/src-old/action/Partition.js +0 -531
  52. package/src-old/action/Repeat.js +0 -106
  53. package/src-old/action/Repopulate.js +0 -44
  54. package/src-old/action/Stratify.js +0 -156
  55. package/src-old/basic/Gradient.js +0 -37
  56. package/src-old/basic/Point.js +0 -51
  57. package/src-old/basic/Rectangle.js +0 -63
  58. package/src-old/bind/bindToAngle.js +0 -56
  59. package/src-old/bind/bindToAreaMark.js +0 -360
  60. package/src-old/bind/bindToColor.js +0 -114
  61. package/src-old/bind/bindToLink.js +0 -81
  62. package/src-old/bind/bindToPosition.js +0 -283
  63. package/src-old/bind/bindToRadialDistance.js +0 -62
  64. package/src-old/bind/bindToSize.js +0 -235
  65. package/src-old/bind/bindToText.js +0 -60
  66. package/src-old/bind/bindToThickness.js +0 -100
  67. package/src-old/constraint/AffixConstraint.js +0 -129
  68. package/src-old/constraint/AlignConstraint.js +0 -58
  69. package/src-old/core/Encoding.js +0 -336
  70. package/src-old/core/Scale.js +0 -322
  71. package/src-old/core/SceneLoader.js +0 -290
  72. package/src-old/core/SceneValidator.js +0 -232
  73. package/src-old/core/SpecExecutor.js +0 -113
  74. package/src-old/core/SpecGenerator.js +0 -350
  75. package/src-old/data/DataImporter.js +0 -64
  76. package/src-old/data/DataScope.js +0 -124
  77. package/src-old/data/DataTable.js +0 -338
  78. package/src-old/data/Network.js +0 -106
  79. package/src-old/data/Tree.js +0 -251
  80. package/src-old/data/transform/Bin.js +0 -46
  81. package/src-old/data/transform/Filter.js +0 -48
  82. package/src-old/data/transform/Groupby.js +0 -18
  83. package/src-old/data/transform/KDE.js +0 -58
  84. package/src-old/data/transform/Sort.js +0 -14
  85. package/src-old/data/transform/Split.js +0 -5
  86. package/src-old/data/transform/partition.js +0 -46
  87. package/src-old/history/UndoRedoStack +0 -0
  88. package/src-old/index.js +0 -271
  89. package/src-old/indexSVG.js +0 -259
  90. package/src-old/interaction/Interaction.js +0 -91
  91. package/src-old/interaction/MouseEvent.js +0 -8
  92. package/src-old/interaction/Selection.js +0 -9
  93. package/src-old/interaction/brush.js +0 -362
  94. package/src-old/item/Segment.js +0 -29
  95. package/src-old/item/Vertex.js +0 -118
  96. package/src-old/item/composite/Collection.js +0 -106
  97. package/src-old/item/composite/Glyph.js +0 -19
  98. package/src-old/item/composite/Group.js +0 -310
  99. package/src-old/item/composite/Scene.js +0 -1251
  100. package/src-old/item/mark/ArcPath.js +0 -181
  101. package/src-old/item/mark/AreaPath.js +0 -78
  102. package/src-old/item/mark/CirclePath.js +0 -102
  103. package/src-old/item/mark/EllipsePath.js +0 -5
  104. package/src-old/item/mark/Image.js +0 -101
  105. package/src-old/item/mark/LinkPath.js +0 -118
  106. package/src-old/item/mark/Mark.js +0 -163
  107. package/src-old/item/mark/Path.js +0 -494
  108. package/src-old/item/mark/PointText.js +0 -201
  109. package/src-old/item/mark/PolygonPath.js +0 -64
  110. package/src-old/item/mark/RectPath.js +0 -88
  111. package/src-old/item/mark/RingPath.js +0 -92
  112. package/src-old/item/refs/Axis.js +0 -362
  113. package/src-old/item/refs/EncodingAxis.js +0 -515
  114. package/src-old/item/refs/Gridlines.js +0 -144
  115. package/src-old/item/refs/LayoutAxis.js +0 -316
  116. package/src-old/item/refs/Legend.js +0 -273
  117. package/src-old/layout/Circular.js +0 -95
  118. package/src-old/layout/Force.js +0 -52
  119. package/src-old/layout/Grid.js +0 -423
  120. package/src-old/layout/Layout.js +0 -13
  121. package/src-old/layout/Packing.js +0 -56
  122. package/src-old/layout/Stack.js +0 -264
  123. package/src-old/layout/Strata.js +0 -88
  124. package/src-old/layout/Sugiyama.js +0 -59
  125. package/src-old/layout/TidyTree.js +0 -105
  126. package/src-old/layout/Treemap.js +0 -87
  127. package/src-old/renderer/SVGInteractionHandler.js +0 -241
  128. package/src-old/renderer/SVGRenderer.js +0 -325
  129. package/src-old/renderer/WebGLRenderer.js +0 -1097
  130. package/src-old/renderer/WebGLRenderer2.js +0 -249
  131. package/src-old/renderer/threejs/Line2.js +0 -18
  132. package/src-old/renderer/threejs/LineGeometry.js +0 -77
  133. package/src-old/renderer/threejs/LineMaterial.js +0 -605
  134. package/src-old/renderer/threejs/LineSegments2.js +0 -281
  135. package/src-old/renderer/threejs/LineSegmentsGeometry.js +0 -226
  136. package/src-old/renderer/threejs/Wireframe.js +0 -51
  137. package/src-old/renderer/threejs/WireframeGeometry2.js +0 -16
  138. package/src-old/scale/areaSize.js +0 -0
  139. package/src-old/scale/domain.js +0 -38
  140. package/src-old/util/Constants.js +0 -180
  141. package/src-old/util/DataUtil.js +0 -35
  142. package/src-old/util/ItemUtil.js +0 -586
  143. package/src-old/util/Numerical.js +0 -33
  144. package/tests/demo-tests/README.md +0 -80
  145. package/tests/demo-tests/SVG2PNG.js +0 -56
  146. package/tests/demo-tests/demos2CanvasPNGs.js +0 -69
  147. package/tests/demo-tests/demos2ScenesSVGs.js +0 -100
  148. package/tests/demo-tests/pathElementWorker.js +0 -91
  149. package/tests/demo-tests/pixelTest.js +0 -62
  150. package/tests/demo-tests/renderDemos.html +0 -132
  151. package/tests/demo-tests/serializationTest.js +0 -36
  152. package/tests/demo-tests/serializeDemos.html +0 -134
  153. package/tests/unit-tests/README.md +0 -4
  154. package/tests/unit-tests/jasmine-browser.json +0 -21
  155. package/tests/unit-tests/jasmine.json +0 -14
  156. package/tests/unit-tests/testSpec.js +0 -274
@@ -1,360 +0,0 @@
1
- import {getParents, getPeers, getClosestLayout, getCellBoundsInLayout, CheckAreaOrien} from "../util/ItemUtil";
2
- import {DataType, Alignment, LayoutType} from "../util/Constants";
3
- import {Orientation} from "../util/Constants";
4
- import Scale from "../core/Scale";
5
- import LinearGradient from "../basic/Gradient";
6
-
7
- export function bindToAreaMark(encoding){
8
-
9
- encoding._query = function() {
10
- this.data = [];
11
- // store area peers
12
- this.areas = getPeers(this.items[0], this.scene);
13
- let areaNum = this.areas.length;
14
- this.areaNum = areaNum;
15
- // this.items are all the areas, we need to keep them for saving to json
16
- // here we populate the vertices to be used for binding
17
- this._vertices = [];
18
- this.indicator = [];
19
- for (let area of this.areas) {
20
- for (let i=0; i < area.vertices.length; i++) {
21
- this._vertices.push(area.vertices[i]);
22
- if (i < area.vertices.length / 2) {
23
- this.indicator.push(1);
24
- } else {
25
- this.indicator.push(0);
26
- }
27
- }
28
- }
29
- let field = this.field, items = this._vertices;
30
- let dataScopes = items.map(d => d.dataScope);
31
- // ((this.anyItem.type == "vertex" || this.anyItem.type == "segment") && !this.anyItem.dataScope) ?
32
- // items.map(d => d.parent.dataScope) : items.map(d => d.dataScope);
33
- switch (this.datatable.getFieldType(field)) {
34
- case DataType.Boolean:
35
- break;
36
-
37
- case DataType.Date:
38
- this.data = dataScopes.map(d => d.getFieldValue(field));
39
- break;
40
-
41
- case DataType.String:
42
- this.data = dataScopes.map((d, i) => this.indicator[i] == 0 ? 0 : d.aggregateNumericalField(field, this.aggregator));
43
- break;
44
-
45
- default: //integer or number
46
- if (this.channel == "x" || this.channel == "y") {
47
- this.data = dataScopes.map(d => d._field2value[field]);
48
- } else {
49
- this.data = dataScopes.map((d, i) => this.indicator[i] == 0 ? 0 : d.aggregateNumericalField(field, this.aggregator));
50
- }
51
- break;
52
- }
53
- }
54
-
55
- encoding._map = function() {
56
- if (this.channel === "fillGradient")
57
- this._mapToGradient();
58
- else if (this.channel == "width" || this.channel == "height")
59
- this._mapToSize();
60
- }
61
-
62
- encoding._mapToGradient = function() {
63
- if (this.scale) {
64
- if (!this._mapping) {
65
- let values = this.scale.domain.concat(this.data);
66
- this.scale.domain = [Math.min(...values), Math.max(...values)];
67
- }
68
- } else {
69
- if (this._mapping) {
70
- this.scale = new Scale("linear", this._mapping);
71
- } else {
72
- let min = Math.min(...this.data), max = Math.max(...this.data),
73
- abs = Math.max(Math.abs(min), Math.abs(max)), scheme;
74
- if (min < 0 && max > 0) {
75
- scheme = "interpolatePuOr";
76
- min = -abs;
77
- max = abs;
78
- this.scale = new Scale("divergingColor", this._scheme ? this._scheme: scheme);
79
- } else {
80
- scheme = "interpolateTurbo";
81
- this.scale = new Scale("sequentialColor", this._scheme ? this._scheme: scheme);
82
- }
83
- this.scale.domain = [min, max];
84
- }
85
- }
86
- this.scale._addEncoding(this);
87
- }
88
-
89
- encoding._mapToSize = function() {
90
- let fieldType = this.datatable.getFieldType(this.field);
91
-
92
- let scale, min, max;
93
- switch (fieldType) {
94
- case DataType.Boolean:
95
- break;
96
-
97
- case DataType.Date:
98
- scale = new Scale("time");
99
- min = Math.min(...this.data);
100
- max = Math.max(...this.data);
101
- scale.domain = [min, max];
102
- break;
103
-
104
- case DataType.String:
105
- scale = new Scale("linear");
106
- min = Math.min(...this.data);
107
- max = Math.max(...this.data);
108
- scale.domain = (this._includeZero || min < 0)? [0, max] : [min, max];
109
- break;
110
-
111
- default: //integer or number
112
- scale = new Scale("linear");
113
- min = Math.min(...this.data);
114
- max = Math.max(...this.data);
115
- //scale.domain = (this._includeZero || min < 0)? [0, max] : [min, max];
116
- scale.domain = (min < 0)? [0, max] : [min, max];
117
- break;
118
- }
119
-
120
- //to be used for determining the range of scale
121
- //TODO: need to update cellBounds dynamically for _map() and _apply()
122
- let orientation = CheckAreaOrien(this.areas[0]);
123
- let extent;
124
- let layout = getClosestLayout(this.anyItem);
125
- if (layout) {
126
- let cellBounds = layout.cellBounds;
127
- if (this.channel == "width" || this.channel == "height") {
128
- extent = orientation == Orientation.Vertical ? cellBounds[0].width : cellBounds[0].height;
129
- } else {
130
- extent = orientation == Orientation.Vertical ? cellBounds[0].height : cellBounds[0].width;
131
- }
132
- // if (layout.type === LayoutType.Stack) {
133
- // if (orientation === Orientation.Horizontal && this.channel === "height")
134
- // extent /= this.areas.length;
135
- // else if (orientation === Orientation.Vertical && this.channel === "width")
136
- // extent /= this.areas.length;
137
- // }
138
- } else {
139
- //if (this.channel == "width" || this.channel == "x") {
140
- if (this.channel == "width") {
141
- // let pos = this._vertices.map(d => d.x);
142
- // extent = Math.max(...pos) - Math.min(...pos);
143
- extent = Math.max(...this.areas.map(d => d.bounds.width));
144
- } else {
145
- // let pos = this._vertices.map(d => d.y);
146
- // extent = Math.max(...pos) - Math.min(...pos);
147
- extent = Math.max(...this.areas.map(d => d.bounds.height));
148
- }
149
- }
150
-
151
- if (this.rangeExtent)
152
- extent = this.rangeExtent;
153
-
154
- if (min < 0) {
155
- scale._scale.domain([min, max]);
156
- //TODO: need to adjust according to scale type
157
- scale._setRange([0, extent]);
158
- } else {
159
- scale._setRange([0, extent]);
160
- }
161
-
162
- if (this.scale) {
163
- this.scale._merge(scale);
164
- } else {
165
- this.scale = scale;
166
- }
167
-
168
- this.scale._addEncoding(this);
169
- }
170
-
171
- encoding._apply = function() {
172
- if (this.channel === "fillGradient")
173
- this._applyToGradient();
174
- else if (this.channel == "width" || this.channel == "height")
175
- this._applyToSize();
176
- }
177
-
178
- encoding._applyToGradient = function() {
179
- let dIdx = 0;
180
- for (let area of this.areas) {
181
- let data = this.data.slice(dIdx, dIdx + area.vertices.length),
182
- min = Math.min(...data),
183
- max = Math.max(...data);
184
- let fill = area.orientation === "horizontal" ? new LinearGradient({x1: 0, y1: 100, x2: 0, y2: 0}) : new LinearGradient({x1: 0, y1: 0, x2: 100, y2: 0});
185
- fill.addStop(0, this.scale.map(min), 1.0);
186
- if (this._mapping) {
187
- let vals = Object.keys(this._mapping).map(d => parseFloat(d)).sort();
188
- for (let v of vals) {
189
- if (v > min && v < max) {
190
- fill.addStop(100*(v-min)/(max-min), this.scale.map(v), 1.0);
191
- }
192
- }
193
- } else if (this.scale.type === "divergingColor") {
194
- fill.addStop(100*(-min)/(max-min), this.scale.map(0), 1.0);
195
- }
196
- fill.addStop(100, this.scale.map(max), 1.0);
197
- area.fillColor = fill;
198
- dIdx += area.vertices.length;
199
- }
200
- }
201
-
202
- encoding._applyToSize = function() {
203
- let items = [], channel = this.channel;
204
- for (let enc of this.scale.encodings)
205
- items = items.concat(enc.items);
206
- let ao = this.areas[0].orientation;
207
- if (channel === "width" || channel === "height") {
208
- if (this.data.find(d => d < 0) != undefined)
209
- this.areas.forEach(d => d._areaNegativeValues = true);
210
- else
211
- this.areas.forEach(d => d._areaNegativeValues = false);
212
- let closestLayout = getClosestLayout(this.areas[0]);
213
- if (closestLayout) {
214
- let vidx = 0, cellBounds = this.areas.map(d => getCellBoundsInLayout(d)), layouts = this.areas.map(d => getClosestLayout(d));
215
- for (let [aidx, area] of this.areas.entries()) {
216
- let cb = cellBounds[aidx], layout = layouts[aidx];
217
- // let cb = getCellBoundsInLayout(area),
218
- // layout = getClosestLayout(area);
219
- for (let i = 0; i < area.vertices.length; i++) {
220
- let v = this._vertices[i + vidx],
221
- dx, dy;
222
- if (ao === Orientation.Horizontal) {
223
- dx = 0;
224
- if (layout.type === LayoutType.Stack) {
225
- dy = cb.bottom - this.scale.map(this.data[i + vidx]) - v.y;
226
- } else if (layout.type === LayoutType.Grid) {
227
- let baseline = area.baseline;
228
- switch (baseline) {
229
- case "top":
230
- dy = cb.top + this.scale.map(this.data[i + vidx]) - v.y;
231
- break;
232
- case "bottom":
233
- dy = cb.bottom - this.scale.map(this.data[i + vidx]) - v.y;
234
- break;
235
- case "middle": {
236
- let j = area.vertices.length - 1 - i,
237
- dist = Math.abs(this.scale.map(this.data[i + vidx]) - this.scale.map(this.data[j + vidx]));
238
- dy = this.indicator[i + vidx] ? cb.middle - dist/2 - v.y : cb.middle + dist/2 - v.y;
239
- break;
240
- }
241
- }
242
- } else {
243
- dy = 0;
244
- }
245
- } else {
246
- dy = 0;
247
- if (layout.type === LayoutType.Stack) {
248
- dx = cb.left + this.scale.map(this.data[i + vidx]) - v.x;
249
- } else if (layout.type === LayoutType.Grid) {
250
- let baseline = area.baseline;
251
- switch (baseline) {
252
- case "left":
253
- dx = cb.left + this.scale.map(this.data[i + vidx]) - v.x;
254
- break;
255
- case "right":
256
- dx = cb.right - this.scale.map(this.data[i + vidx]) - v.x;
257
- break;
258
- case "center": {
259
- let j = area.vertices.length - 1 - i,
260
- dist = Math.abs(this.scale.map(this.data[i + vidx]) - this.scale.map(this.data[j + vidx]));
261
- dx = this.indicator[i + vidx] ? cb.center - dist/2 - v.x : cb.center + dist/2 - v.x;
262
- break;
263
- }
264
- }
265
- } else {
266
- dx = 0;
267
- }
268
- }
269
- v._doTranslate(dx, dy);
270
- }
271
- vidx += area.vertices.length;
272
- }
273
- } else {
274
- let baseline_check = this.areas[0].baseline == "center" || this.areas[0].baseline == "middle";
275
- //let marks = getParents(this._vertices);
276
- //let offset = ao == Orientation.Vertical ? this.areas[0].baseline !== Alignment.Right ? Math.min(...marks.map(d => d.bounds.left)) : Math.max(...marks.map(d => d.bounds.right)) : this.areas[0].baseline != Alignment.Top ? Math.max(...marks.map(d => d.bounds.bottom)) : Math.min(...marks.map(d => d.bounds.top));
277
-
278
- let dIdx = 0, minSide = ao == Orientation.Vertical ? "left" : "bottom", maxSide = ao == ao == Orientation.Vertical ? "right" : "top";
279
- for (let area of this.areas) {
280
- for (let i = dIdx; i < dIdx + area.vertices.length; i++) {
281
- let peer = this._vertices[i];
282
- let offset = ao == Orientation.Vertical ? area.baseline !== Alignment.Right ? area.bounds.left - area.boundsOffsets.left : area.bounds.right + area.boundsOffsets.right:
283
- area.baseline != Alignment.Top ? area.bounds.bottom + area.boundsOffsets.bottom: area.bounds.top - area.boundsOffsets.top;
284
- let dx = ao == Orientation.Vertical ? area.baseline !== Alignment.Right ? offset + this.scale.map(this.data[i]) - peer.x
285
- : offset - this.scale.map(this.data[i]) - peer.x : 0,
286
- dy = ao == Orientation.Vertical ? 0 : area.baseline != Alignment.Top ? offset - this.scale.map(this.data[i]) - peer.y
287
- : offset + this.scale.map(this.data[i]) - peer.y;
288
- peer._doTranslate(dx, dy);
289
- }
290
- let data = this.data.slice(dIdx, dIdx + area.vertices.length),
291
- min = Math.min(...data),
292
- max = Math.max(...data);
293
- //record coordinate corresponding to zero value if the area has both +ve and -ve values
294
- //TODO: need to handle the case where the areas are inside a layout
295
- if (area._areaNegativeValues)
296
- area._areaZeroCoord = ao == Orientation.Vertical ? area.bounds.left - area.boundsOffsets.left + this.scale.map(0) :
297
- area.bounds.bottom + area.boundsOffsets.bottom - this.scale.map(0);
298
- area.boundsOffsets[maxSide] = this.scale.map(Math.max(...this.data)) - this.scale.map(max);
299
- area.boundsOffsets[minSide] = this.scale.map(min) - this.scale.map(Math.min(...this.data));
300
- dIdx += area.vertices.length;
301
- }
302
-
303
- if (baseline_check == true) {
304
- //TODO: handle cases where each area have different number of vertices
305
- let VNum = this._vertices.length / this.areaNum;
306
- let marks = getParents(this._vertices);
307
- let offset = ao == Orientation.Vertical ? Math.min(...marks.map(d => d.bounds.x)) : Math.max(...marks.map(d => d.bounds.y));
308
- for (let j = 0; j < this.areaNum; j++) {
309
- for (let i = 0; i < VNum / 2; i++) {
310
- let Vid1 = j * VNum + i, Vid2 = (j + 1) * VNum - i - 1;
311
- let peer1 = this._vertices[Vid1], peer2 = this._vertices[Vid2];
312
- let height = ao == Orientation.Vertical ? peer1.x-peer2.x : peer2.y-peer1.y;
313
- let dx1 = ao == Orientation.Vertical ? offset + height / 2 - peer1.x : 0,
314
- dy1 = ao == Orientation.Vertical ? 0 : offset + height / 2 - peer1.y;
315
- let dx2 = ao == Orientation.Vertical ? offset - height / 2 - peer2.x : 0,
316
- dy2 = ao == Orientation.Vertical ? 0 : offset - height / 2 - peer2.y;
317
- peer1._doTranslate(dx1, dy1);
318
- peer2._doTranslate(dx2, dy2);
319
- }
320
- }
321
- }
322
- }
323
- }
324
-
325
- // else { //x or y
326
- // let layout = getClosestLayout(this.anyItem);
327
- // if (layout) {
328
- // let marks = getParents(this._vertices);
329
- // if (this.scale.offset === undefined)
330
- // this.scale.offset = ao == Orientation.Horizontal ? Math.min(...marks.map(d => d.bounds.left)) : Math.max(...marks.map(d => d.bounds.top));
331
- // for (let i = 0; i < this._vertices.length; i++) {
332
- // let peer = this._vertices[i], perrCb = getCellBoundsInLayout(peer);
333
- // let dx = ao == Orientation.Vertical ? 0 : perrCb.left + this.scale.map(this.data[i]) - peer.x,
334
- // dy = ao == Orientation.Vertical ? perrCb.bottom - this.scale.map(this.data[i]) - peer.y : 0;
335
- // peer._doTranslate(dx, dy);
336
- // }
337
- // } else {
338
- // let marks = getParents(this._vertices);
339
- // if (this.scale.offset === undefined)
340
- // this.scale.offset = ao == Orientation.Horizontal ? Math.min(...marks.map(d => d.bounds.left)) : Math.max(...marks.map(d => d.bounds.top));
341
- // for (let i = 0; i < this._vertices.length; i++) {
342
- // let peer = this._vertices[i];
343
- // let dx = ao == Orientation.Horizontal ? this.scale.offset + this.scale.map(this.data[i]) - peer.x : 0,
344
- // dy = ao == Orientation.Horizontal ? 0 : this.scale.offset + this.scale.rangeExtent - this.scale.map(this.data[i]) - peer.y;
345
- // peer._doTranslate(dx, dy);
346
- // }
347
- // }
348
- // }
349
-
350
- for (let area of this.areas) {
351
- area._updateBounds()
352
- }
353
- if (channel == "width" || channel == "height") {
354
- this.scene._relayoutAncestors(this.areas[0], this.areas);
355
- }
356
- }
357
-
358
- encoding.run();
359
- return encoding;
360
- }
@@ -1,114 +0,0 @@
1
- import Scale from "../core/Scale";
2
- import {categoricalColorSchemes, DataType, divergingColorSchemes, sequentialColorSchemes} from "../util/Constants";
3
-
4
- export function bindToColor(encoding){
5
-
6
- encoding._query = function() {
7
- this.data = [];
8
-
9
- let field = this.field, items = this.items;
10
- let dataScopes = ((this.anyItem.type == "vertex" || this.anyItem.type == "segment") && !this.anyItem.dataScope) ?
11
- items.map(d => d.parent.dataScope) : items.map(d => d.dataScope);
12
-
13
- switch (this.datatable.getFieldType(field)) {
14
- case DataType.Boolean:
15
- this.data = [true, false];
16
- break;
17
-
18
- case DataType.Date:
19
- this.data = dataScopes.map(d => d.getFieldValue(field));
20
- break;
21
-
22
- case DataType.String:
23
- try {
24
- this.data = dataScopes.map(d => d.getFieldValue(field));
25
- } catch (error) {
26
- throw new Error("Cannot bind " + this.channel + " to " + field + " : " + error);
27
- }
28
- break;
29
-
30
- default: //integer or number
31
- this.data = dataScopes.map(d => d.aggregateNumericalField(field, this.aggregator));
32
- break;
33
- }
34
- }
35
-
36
- encoding._map = function() {
37
- switch (this.datatable.getFieldType(this.field)) {
38
- case DataType.Boolean:
39
- if (!this.scale) {
40
- this.scale = new Scale("ordinalColor");
41
- this.scale.domain = this.data;
42
- if (this._mapping) {
43
- let range = this.scale.domain.map(d => d in this._mapping ? this._mapping[d] : "black");
44
- this.scale._scale.range(range);
45
- }
46
- }
47
- break;
48
- case DataType.String:
49
- if (this.scale) {
50
- this.scale.domain = Array.from(new Set(this.scale.domain.concat(this.data)));
51
- } else {
52
- let args = {scheme: "schemeCategory10"};
53
- if (this._scheme) {
54
- if (categoricalColorSchemes.indexOf(this._scheme) >= 0) {
55
- args.scheme = this._scheme;
56
- } else if (divergingColorSchemes.indexOf(this._scheme) >= 0 || sequentialColorSchemes.indexOf(this._scheme) >= 0) {
57
- args.scheme = this._scheme;
58
- args.size = this.data.length;
59
- }
60
- }
61
- this.scale = new Scale("ordinalColor", args);
62
- this.scale.domain = this.data;
63
- if (this._mapping) {
64
- let range = this.scale.domain.map(d => d in this._mapping ? this._mapping[d] : "black");
65
- this.scale._scale.range(range);
66
- }
67
- }
68
- break;
69
-
70
- default: //number or date
71
- if (this.scale) {
72
- if (!this._mapping) {
73
- let values = this.scale.domain.concat(this.data);
74
- this.scale.domain = [Math.min(...values), Math.max(...values)];
75
- }
76
- } else {
77
- if (this._mapping) {
78
- this.scale = new Scale("linear", this._mapping);
79
- } else {
80
- let min = Math.min(...this.data), max = Math.max(...this.data),
81
- abs = Math.max(Math.abs(min), Math.abs(max)), scheme;
82
- if (min < 0 && max > 0) {
83
- scheme = "interpolatePuOr";
84
- min = -abs;
85
- max = abs;
86
- this.scale = new Scale("divergingColor", this._scheme ? this._scheme: scheme);
87
- } else {
88
- scheme = "interpolateTurbo";
89
- this.scale = new Scale("sequentialColor", this._scheme ? this._scheme: scheme);
90
- }
91
- this.scale.domain = [min, max];
92
- }
93
- }
94
- break;
95
- }
96
- this.scale._addEncoding(this);
97
- }
98
-
99
- encoding._apply = function() {
100
- for (let i = 0; i < this.items.length; i++) {
101
- let peer = this.items[i], value = this.scale.map(this.data[i]);
102
- if (peer.type == "vertex" || peer.type == "segment")
103
- peer[this.channel] = value;
104
- else
105
- peer.styles[this.channel] = value;
106
- if (peer.vertices && this.channel == "strokeColor") {
107
- peer.vertices.forEach(d => d.fillColor = value);
108
- }
109
- }
110
- }
111
-
112
- encoding.run();
113
- return encoding;
114
- }
@@ -1,81 +0,0 @@
1
- import Scale from "../core/Scale";
2
- import DataScope from "../data/DataScope";
3
- import { ItemType, nodeId } from "../util/Constants";
4
-
5
- export function bindToLink(encoding){
6
-
7
- encoding._query = function() {
8
- let field = this.field, channel = this.channel, items = this.items;
9
- let dataScopes = items.map(d => d.dataScope);
10
-
11
- // if (channel == "source" || channel == "target") {
12
- // //data are marks in the scene representing the nodes
13
- // let nodeIds = dataScopes.map(d => d.getFieldValue(field));
14
- // let scene = this.scene;
15
- // this.data = [];
16
- // for (let id of nodeIds) {
17
- // let r = scene.find([{field: nodeId, value: id}]);
18
- // //since we assign data scopes to collections when repeating, need to filter out collections
19
- // r = r.filter(d => d.type !== ItemType.Collection);
20
- // this.data.push(r[0]);
21
- // }
22
- // } else
23
- if (channel == "strokeWidth") {
24
- if (this.datatable.hasField(field)) {
25
- this.data = dataScopes.map(d => d.getFieldValue(field));
26
- } else if (field.startsWith("parent.") || field.startsWith("child.")) {
27
- let dt = this.datatable.tree.nodeTable;
28
- let s = field.split(".")[0], f = field.split(".")[1];
29
- let nodeIds = dataScopes.map(d => d.getFieldValue(s));
30
- this.data = nodeIds.map(d => (new DataScope(dt)).cross(nodeId, d).getFieldValue(f));
31
- }
32
- }
33
- }
34
-
35
- encoding._map = function() {
36
- let channel = this.channel, items = this.items;
37
- let scale;
38
- if (channel == "strokeWidth") {
39
- scale = new Scale(this.scaleType);
40
- scale.domain = [0, Math.max(...this.data)];
41
- let min, max;
42
- min = 1;
43
- max = Math.max(...(items.map(d => parseFloat(d.styles.strokeWidth))));
44
- if (max == min)
45
- max = min + 5;
46
- if (this.rangeExtent)
47
- max = min + this.rangeExtent;
48
- if (this.range) {
49
- min = this.range[0];
50
- max = this.range[1];
51
- }
52
- scale._setRange([min, max]);
53
-
54
- if (this.scale){
55
- //TODO
56
- } else {
57
- this.scale = scale;
58
- }
59
- this.scale._addEncoding(this);
60
- }
61
-
62
- }
63
-
64
- encoding._apply = function() {
65
- let channel = this.channel;
66
- // if (channel == "source" || channel == "target") {
67
- // for (let i = 0; i < this.data.length; i++) {
68
- // this.items[i][this.channel] = this.data[i];
69
- // this.items[i]._updateBounds();
70
- // }
71
- // } else
72
- if (channel == "strokeWidth") {
73
- for (let i = 0; i < this.data.length; i++) {
74
- this.items[i].styles.strokeWidth = this.scale.map(this.data[i]);
75
- }
76
- }
77
- }
78
-
79
- encoding.run();
80
- return encoding;
81
- }