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,283 +0,0 @@
1
- import {getParents, getClosestLayout, getCellBoundsInLayout, sameClass, getPeers, getCellIndexInLayout} from "../util/ItemUtil";
2
- import {DataType, ItemType, LayoutType} from "../util/Constants";
3
- import Scale from "../core/Scale";
4
-
5
- export function bindToPosition(encoding){
6
-
7
- encoding._query = function() {
8
- this.data = [];
9
-
10
- let field = this.field, items = this.items;
11
- let dataScopes = ((this.anyItem.type == "vertex" || this.anyItem.type == "segment") && !this.anyItem.dataScope) ?
12
- items.map(d => d.parent.dataScope) : items.map(d => d.dataScope);
13
-
14
- switch (this.datatable.getFieldType(field)) {
15
- case DataType.Boolean:
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
- let channel = this.channel, fieldType = this.datatable.getFieldType(this.field);
38
-
39
- //to be used for determining the range of scale
40
- //TODO: need to update cellBounds dynamically for _map() and _apply()
41
- let extent;
42
- let layout = getClosestLayout(this.anyItem);
43
- if (layout && layout.type == LayoutType.Grid) {
44
- let cellBounds = layout.cellBounds;
45
- extent = channel == "x" ? cellBounds[0].width : cellBounds[0].height;
46
- } else if (this.anyItem.type === "vertex" && this.anyItem.parent.type === ItemType.Area) {
47
- extent = channel == "x" ? this.anyItem.parent.bounds.width : this.anyItem.parent.bounds.height;
48
- } else {
49
- let pos = this.items.map(d => d[channel]);
50
- extent = Math.max(...pos) - Math.min(...pos);
51
- if (extent < 100) extent = 100;
52
- else if (extent > 500) extent = 500;
53
- }
54
-
55
- let min, max, domain, range;
56
- switch (fieldType) {
57
- case DataType.Boolean:
58
- break;
59
-
60
- case DataType.Date:
61
- min = Math.min(...this.data);
62
- max = Math.max(...this.data);
63
- domain = [min, max];
64
- if (this.scale) {
65
- // let domainValues = domain.concat(this.scale.domain);
66
- let domainValues = this.data;
67
- for (let enc of this.scale.encodings) {
68
- domainValues = domainValues.concat(enc.data);
69
- }
70
- domain = [Math.min(...domainValues), Math.max(...domainValues)];
71
- //extent = Math.abs(this.scale.map(domain[0]) - this.scale.map(domain[1]));
72
- range = this.scale.range;
73
- } else {
74
- this.scale = new Scale("time");
75
- this.scale.isFlipped = this._flipScale;
76
- range = [0, extent];
77
- this.scale._baseItem = this.anyItem;
78
- }
79
- break;
80
-
81
- case DataType.String:
82
- domain = Array.from(new Set(this.data));
83
- range = [0, extent];
84
- if (this.scale) {
85
- let od = this.scale.domain;
86
- //the following lines preserve the order of values in existing domain
87
- for (let d of domain) {
88
- if (od.indexOf(d) < 0)
89
- od.push(d);
90
- }
91
- domain = od;
92
- //domain = Array.from(new Set(domain.concat(this.scale.domain)));
93
- range = this.scale.range;
94
- } else {
95
- this.scale = new Scale("point");
96
- this.scale.isFlipped = this._flipScale;
97
- range = [0, extent];
98
- this.scale._baseItem = this.anyItem;
99
- }
100
- break;
101
-
102
- default: //integer or number
103
- min = Math.min(...this.data);
104
- max = Math.max(...this.data);
105
- domain = [min, max];
106
-
107
- if (this.scale) {
108
- //where zero is included depends on the existing scale
109
- let domainValues = this.data;
110
- for (let enc of this.scale.encodings) {
111
- domainValues = domainValues.concat(enc.data);
112
- }
113
- // let domainValues = domain.concat(this.scale._scale.domain());
114
- domain = [Math.min(...domainValues), Math.max(...domainValues)];
115
-
116
- range = this.scale.range;
117
- } else {
118
- this.scale = new Scale(this.scaleType);
119
- this.scale.isFlipped = this._flipScale;
120
- this.scale.includeZero = this._includeZero;
121
- range = [0, extent];
122
- //remember the item that was used to first create this scale,
123
- //so that when the scale is reused later, we can refer to the base item
124
- //to get absoluate positions
125
- this.scale._baseItem = this.anyItem;
126
- }
127
- if (domain[0] == domain[1])
128
- domain[1] = domain[0] * 1.1;
129
- break;
130
- }
131
-
132
- this.scale._scale.domain(domain);
133
- this.scale._setRange(range);
134
-
135
- //TODO: need to adjust according to scale type
136
- this.scale._addEncoding(this);
137
- }
138
-
139
- encoding._apply = function() {
140
- let items = [], channel = this.channel;
141
- //if the scale is shared across multiple encodings, need to find the offset based on all items using this scale
142
- //use case: box plot, where lines, rect segments and line vertices share the same scale
143
- for (let enc of this.scale.encodings)
144
- items = items.concat(enc.items);
145
- if (channel == "x") {
146
- //let layout = getClosestLayout(this.anyItem, "grid");
147
- //let layout = getTopLevelCollection(this.anyItem) ? getTopLevelCollection(this.anyItem).layout : getClosestLayout(this.anyItem);
148
- let layout = getClosestLayout(this.anyItem, "grid"), baseLayout = this.scale._baseItem ? getClosestLayout(this.scale._baseItem, "grid"): undefined;
149
- if (this.scale._baseItem && !sameClass(this.anyItem, this.scale._baseItem) && layout && baseLayout && layout.numRows === baseLayout.numRows && layout.numCols === baseLayout.numCols) {
150
- let tx = baseLayout.group.bounds.left - layout.group.bounds.left,
151
- ty = 0;
152
- layout.group.getScene().translate(layout.group, tx, ty);
153
- layout._colGap = baseLayout.colGap;
154
- let cellIndices = this.items.map(d => getCellIndexInLayout(d)),
155
- baseCellBounds = baseLayout.cellBounds;
156
- for (let i = 0; i < this.items.length; i++) {
157
- let itm = this.items[i];
158
- let dx = baseCellBounds[cellIndices[i]].left + this.scale.map(this.data[i]) - itm[channel],
159
- dy = 0;
160
- itm._doTranslate(dx, dy);
161
- if (itm.type == "vertex" || itm.type == "segment")
162
- itm.parent._updateBounds();
163
- }
164
- this.anyItem.parent.getScene()._updateAncestorBounds(this.anyItem, this.items);
165
- } else if (layout && layout.type == LayoutType.Grid){
166
- //do not use scale.offset, use cell bounds
167
- for (let i = 0; i < this.items.length; i++) {
168
- let itm = this.items[i], itmCb = getCellBoundsInLayout(itm);
169
- let dx = itmCb.left + this.scale.map(this.data[i]) - itm[channel],
170
- dy = 0;
171
- itm._doTranslate(dx, dy);
172
- if (itm.type == "vertex" || itm.type == "segment")
173
- itm.parent._updateBounds();
174
- }
175
- } else if (this.anyItem.type === "vertex" && this.anyItem.parent.type === ItemType.Area) {
176
- //this is to make sure that the encoding of vertex position is within the bounds of an area mark
177
- let marks = getParents(this.items);
178
- if (this.scale.offset === undefined)
179
- this.scale.offset = Math.min(...marks.map(d => d.bounds.left));
180
- for (let i = 0; i < this.items.length; i++) {
181
- let peer = this.items[i], parent = peer.parent;
182
- let dx = parent.bounds.left + this.scale.map(this.data[i]) - peer[channel],
183
- dy = 0;
184
- peer._doTranslate(dx, dy);
185
- peer.parent._updateBounds();
186
- }
187
- } else if (this.anyItem.type == "vertex" || this.anyItem.type == "segment") {
188
- //TODO: right now using the leftmost mark peer as the baseline, which will not work for cases like bullet chart
189
- //need to check if marks are part of a glyph, and use the leftmose glyph peer.
190
- let marks = getParents(this.items);
191
- if (this.scale.offset === undefined)
192
- this.scale.offset = Math.min(...marks.map(d => d.bounds.left));
193
- for (let i = 0; i < this.items.length; i++) {
194
- let peer = this.items[i];
195
- let dx = this.scale.offset + this.scale.map(this.data[i]) - peer[channel],
196
- dy = 0;
197
- peer._doTranslate(dx, dy);
198
- peer.parent._updateBounds();
199
- }
200
- } else {
201
- if (this.scale.offset === undefined)
202
- this.scale.offset = Math.min(...items.map(d => d[channel]));
203
- if (this.items[0].type === ItemType.PointText)
204
- this.items.forEach(d => d.horzAnchor = "center");
205
- for (let i = 0; i < this.items.length; i++) {
206
- let peer = this.items[i];
207
- let dx = this.scale.offset + this.scale.map(this.data[i]) - peer[channel],
208
- dy = 0;
209
- peer._doTranslate(dx, dy);
210
- }
211
- }
212
-
213
- } else {//channel y
214
- //let layout = getTopLevelCollection(this.anyItem) ? getTopLevelCollection(this.anyItem).layout : getClosestLayout(this.anyItem);
215
- let layout = getClosestLayout(this.anyItem, "grid"), baseLayout = this.scale._baseItem ? getClosestLayout(this.scale._baseItem, "grid"): undefined;
216
- if (this.scale._baseItem && !sameClass(this.anyItem, this.scale._baseItem) && layout && baseLayout && layout.numRows === baseLayout.numRows && layout.numCols === baseLayout.numCols) {
217
- //if (this.scale._baseItem && !sameClass(this.anyItem, this.scale._baseItem) && baseLayout && baseLayout.numRows === 1) {
218
- //let peers = getPeers(this.scale._baseItem, this.scale._baseItem.parent.getScene());
219
- let tx = 0,
220
- ty = baseLayout.group.bounds.top - layout.group.bounds.top;
221
- layout.group.getScene().translate(layout.group, tx, ty);
222
- layout._rowGap = baseLayout.rowGap;
223
- let cellIndices = this.items.map(d => getCellIndexInLayout(d)),
224
- baseCellBounds = baseLayout.cellBounds;
225
- for (let i = 0; i < this.items.length; i++) {
226
- let itm = this.items[i];
227
- let dx = 0,
228
- dy = baseCellBounds[cellIndices[i]].bottom - this.scale.map(this.data[i]) - itm[channel];
229
- itm._doTranslate(dx, dy);
230
- if (itm.type == "vertex" || itm.type == "segment")
231
- itm.parent._updateBounds();
232
- }
233
- this.anyItem.parent.getScene()._updateAncestorBounds(this.anyItem, this.items);
234
- } else if (layout && layout.type == LayoutType.Grid){
235
- let cellBounds = this.items.map(d => getCellBoundsInLayout(d));
236
- for (let i = 0; i < this.items.length; i++) {
237
- let itm = this.items[i];
238
- let dx = 0,
239
- dy = cellBounds[i].bottom - this.scale.map(this.data[i]) - itm[channel];
240
- itm._doTranslate(dx, dy);
241
- if (itm.type == "vertex" || itm.type == "segment")
242
- itm.parent._updateBounds();
243
- }
244
- } else if (this.anyItem.type === "vertex" && this.anyItem.parent.type === ItemType.Area) {
245
- if (this.scale.offset === undefined)
246
- this.scale.offset = Math.min(...this.items.map(d => d.y));
247
- for (let i = 0; i < this.items.length; i++) {
248
- let peer = this.items[i], parent = peer.parent;
249
- let dx = 0,
250
- dy = parent.bounds.top + this.scale.rangeExtent - this.scale.map(this.data[i]) - peer[channel];
251
- peer._doTranslate(dx, dy);
252
- peer.parent._updateBounds();
253
- }
254
- } else if (this.anyItem.type == "vertex" || this.anyItem.type == "segment") {
255
- if (this.scale.offset === undefined)
256
- this.scale.offset = Math.min(...this.items.map(d => d.y));
257
- for (let i = 0; i < this.items.length; i++) {
258
- let peer = this.items[i];
259
- let dx = 0,
260
- dy = this.scale.offset + this.scale.rangeExtent - this.scale.map(this.data[i]) - peer[channel];
261
- peer._doTranslate(dx, dy);
262
- peer.parent._updateBounds();
263
- }
264
- } else {
265
- if (this.scale.offset === undefined)
266
- this.scale.offset = Math.min(...items.map(d => d.bounds.y));
267
- if (this.items[0].type === ItemType.PointText)
268
- this.items.forEach(d => d.vertAnchor = "middle");
269
- for (let i = 0; i < this.items.length; i++) {
270
- let peer = this.items[i];
271
- let dx = 0,
272
- dy = this.scale.offset + this.scale.rangeExtent - this.scale.map(this.data[i]) - peer.refBounds[channel];
273
- peer._doTranslate(dx, dy);
274
- }
275
- }
276
- }
277
- }
278
-
279
- encoding.run();
280
- if (encoding.rangeExtent)
281
- encoding.scale.rangeExtent = encoding.rangeExtent;
282
- return encoding;
283
- }
@@ -1,62 +0,0 @@
1
- import Scale from "../core/Scale";
2
- import {DataType} from "../util/Constants";
3
- import {polar2Cartesian} from "../util/ItemUtil";
4
-
5
- export function bindToRadialDistance(encoding){
6
-
7
- encoding._query = function() {
8
- this.data = [];
9
-
10
- let field = this.field, items = this.items;
11
- let dataScopes = ((this.anyItem.type == "vertex" || this.anyItem.type == "segment") && !this.anyItem.dataScope) ?
12
- items.map(d => d.parent.dataScope) : items.map(d => d.dataScope);
13
-
14
- switch (this.datatable.getFieldType(field)) {
15
- case DataType.Boolean:
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
-
37
- encoding._map = function() {
38
- let data = this.data;
39
- if (!this.scale){
40
- this.scale = new Scale("linear");
41
- this.scale.domain = [0, Math.max(...data)];
42
- this.scale._setRange([0, this.anyItem.parent.radius]);
43
-
44
- }
45
- this.scale._addEncoding(this);
46
- }
47
-
48
- encoding._apply = function() {
49
- for (let i = 0; i < this.items.length; i++) {
50
- let peer = this.items[i], rd = this.scale.map(this.data[i]);
51
- let coords = polar2Cartesian(this.anyItem.parent.x, this.anyItem.parent.y, rd, peer.polarAngle);
52
- peer.x = coords[0];
53
- peer.y = coords[1];
54
- }
55
-
56
- //relayout if needed
57
- this.scene._relayoutAncestors(this.anyItem, this.items);
58
- }
59
-
60
- encoding.run();
61
- return encoding;
62
- }
@@ -1,235 +0,0 @@
1
- import Scale from "../core/Scale";
2
- import {DataType, ItemType, LayoutType} from "../util/Constants";
3
- import { uniqueNumbers } from "../util/DataUtil";
4
-
5
- export function bindToSize(encoding){
6
-
7
- encoding._query = function() {
8
- this.data = [];
9
- let field = this.field, items = this.items, aggregator = this.aggregator;
10
- switch (this.datatable.getFieldType(field)) {
11
- case DataType.Boolean:
12
- break;
13
-
14
- case DataType.Date:
15
- this.data = items.map(d => d.dataScope.getFieldValue(field));
16
- break;
17
-
18
- case DataType.String:
19
- break;
20
-
21
- default: //integer or number
22
- this.data = items.map(d => d.dataScope.aggregateNumericalField(field, aggregator));
23
- break;
24
- }
25
- }
26
-
27
- encoding._map = function() {
28
- let items = this.items, data = this.data, channel = this.channel, scale;
29
-
30
- scale = new Scale(this.scaleType);
31
-
32
- if (this.data.find(d => d < 0) != undefined && (channel == "width" || channel == "height") && items[0].type.indexOf("rect") == 0) {
33
- this._rectNegativeValues = true;
34
- scale.domain = [Math.min(...data), Math.max(...data)];
35
- if (channel == "width") {
36
- // let left = Math.min(...(items.map(d => d.bounds.left))),
37
- // right = Math.max(...(items.map(d => d.bounds.right)));
38
- // scale._setRange([0, right - left]);
39
-
40
- //TODO: check if item width has already been encoded with a different field
41
- //the code below assumes width hasn't been bound to data
42
- scale._setRange([0, this.rangeExtent ? this.rangeExtent : Math.max(...(items.map(d => d.width)))]);
43
- } else {
44
- // let top = Math.min(...(items.map(d => d.bounds.top))),
45
- // bottom = Math.max(...(items.map(d => d.bounds.bottom)));
46
- // scale._setRange([0, bottom - top]);
47
-
48
- //TODO: check if item height has already been encoded with a different field
49
- //the code below assumes height hasn't been bound to data
50
- scale._setRange([0, this.rangeExtent ? this.rangeExtent : Math.max(...(items.map(d => d.height)))]);
51
- }
52
- } else {
53
- scale.domain = [0, Math.max(...data)];
54
- let min, max;
55
- if (channel == "radius" || channel == "outerRadius" || channel == "innerRadius") {
56
- min = 0;
57
- max = Math.max(...(items.map(d => d[channel])));
58
- if (max < 20) max = 20;
59
- } else if (channel == "area") {
60
- min = 0;
61
- max = Math.max(...(items.map(d => d.bounds.width * d.bounds.height)));
62
- if (max < 400) max = 400;
63
- } else if (channel == "fontSize") {
64
- min = 2;
65
- max = Math.max(...(items.map(d => parseFloat(d.styles.fontSize))));
66
- } else if (channel == "strokeWidth") {
67
- min = 1;
68
- max = Math.max(...(items.map(d => parseFloat(d.styles.strokeWidth))));
69
- if (max == min)
70
- max = min + 5;
71
- } else {
72
- min = 0;
73
- max = Math.max(...(items.map(d => d.bounds[channel])));
74
- }
75
- if (this.rangeExtent)
76
- max = min + this.rangeExtent;
77
- if (this.range) {
78
- min = this.range[0];
79
- max = this.range[1];
80
- }
81
- scale._setRange([min, max]);
82
- }
83
-
84
- if (this.scale){
85
- // TODO
86
- } else {
87
- this.scale = scale;
88
- }
89
-
90
- this.scale._addEncoding(this);
91
- }
92
-
93
- encoding._apply = function() {
94
- if (this.channel == "radius" || this.channel == "outerRadius" || this.channel == "innerRadius") {
95
- for (let i = 0; i < this.items.length; i++) {
96
- let peer = this.items[i];
97
- peer[this.channel] = this.scale.map(this.data[i]);
98
- }
99
- this.scene._relayoutAncestors(this.anyItem, this.items);
100
- } else if (this._rectNegativeValues){
101
- let dMax = Math.max(...this.data), dMin = Math.min(...this.data),
102
- base = this.channel === "width" ? Math.min(...this.items.map(d => d.bounds.left)) :
103
- Math.min(...this.items.map(d => d.bounds.top)) + this.scale.rangeExtent,
104
- maxSide = this.channel === "width" ? "right" : "top",
105
- minSide = this.channel === "width" ? "left" : "bottom";
106
- for (let i = 0; i < this.items.length; i++) {
107
- let offset, peer = this.items[i];
108
- if (peer.parent && peer.parent.type === ItemType.Collection) {
109
- let pp = peer.parent.parent;
110
- if (pp.type === ItemType.Collection && pp.layout && pp.layout.type === LayoutType.Grid) {
111
- let idx = pp.children.indexOf(peer.parent);
112
- offset = pp.layout.cellBounds[idx][minSide];
113
- } else {
114
- offset = peer.parent.refBounds[minSide];
115
- }
116
- } else {
117
- offset = base;
118
- }
119
- if (this.channel === "width") {
120
- peer.leftSegment._doTranslate(offset + this.scale.map(0) - peer.leftSegment.vertex1.x, 0);
121
- peer.rightSegment._doTranslate(offset + this.scale.map(this.data[i]) - peer.rightSegment.vertex1.x, 0);
122
- } else {
123
- peer.topSegment._doTranslate(0, offset - this.scale.map(this.data[i]) - peer.topSegment.vertex1.y);
124
- peer.bottomSegment._doTranslate(0, offset - this.scale.map(0) - peer.bottomSegment.vertex1.y);
125
- }
126
-
127
- peer._updateBounds();
128
- if (this.data[i] > 0) {
129
- peer.boundsOffsets[maxSide] = this.scale.map(dMax) - this.scale.map(this.data[i]);
130
- peer.boundsOffsets[minSide] = this.scale.map(0) - this.scale.map(dMin);
131
- } else {
132
- peer.boundsOffsets[minSide] = this.scale.map(this.data[i]) - this.scale.map(dMin);
133
- peer.boundsOffsets[maxSide] = this.scale.map(dMax) - this.scale.map(0);
134
- }
135
- }
136
-
137
-
138
- // if (this.channel == "width") {
139
- // let base = Math.min(...this.items.map(d => d.bounds.left));
140
- // for (let i = 0; i < this.items.length; i++) {
141
- // let offset, peer = this.items[i], left = peer.leftSegment.vertex1.x, right = peer.rightSegment.vertex1.x;
142
- // if (peer.parent && peer.parent.type == ItemType.Collection) {
143
- // offset = peer.parent.bounds.left;
144
- // } else {
145
- // offset = base;
146
- // }
147
- // peer.rightSegment._doTranslate(offset + this.scale.map(this.data[i]) - right, 0);
148
- // peer.leftSegment._doTranslate(offset + this.scale.map(0) - left, 0);
149
- // peer._updateBounds();
150
- // if (this.data[i] > 0) {
151
- // peer.boundsOffsets.right = this.scale.map(dMax) - this.scale.map(this.data[i]);
152
- // peer.boundsOffsets.left = this.scale.map(0) - this.scale.map(dMin);
153
- // } else {
154
- // peer.boundsOffsets.left = this.scale.map(this.data[i]) - this.scale.map(dMin);
155
- // peer.boundsOffsets.right = this.scale.map(dMax) - this.scale.map(0);
156
- // }
157
- // }
158
- // } else if (this.channel == "height") {
159
- // for (let i = 0; i < this.items.length; i++) {
160
- // let offset, peer = this.items[i], top = peer.topSegment.vertex1.y, btm = peer.bottomSegment.vertex1.y;
161
- // if (peer.parent && peer.parent.type === ItemType.Collection) {
162
- // let pp = peer.parent.parent;
163
- // if (pp.type === ItemType.Collection && pp.layout && pp.layout.type === LayoutType.Grid) {
164
- // let idx = pp.children.indexOf(peer.parent);
165
- // offset = pp.layout.cellBounds[idx].bottom;
166
- // } else {
167
- // offset = peer.parent.refBounds.bottom;
168
- // }
169
- // } else {
170
- // let base = Math.min(...this.items.map(d => d.bounds.top)) + this.scale.rangeExtent;
171
- // offset = base;
172
- // }
173
- // peer.topSegment._doTranslate(0, offset - this.scale.map(this.data[i]) - top);
174
- // peer.bottomSegment._doTranslate(0, offset - this.scale.map(0) - btm);
175
- // peer._updateBounds();
176
- // if (this.data[i] > 0) {
177
- // peer.boundsOffsets.top = this.scale.map(dMax) - this.scale.map(this.data[i]);
178
- // peer.boundsOffsets.bottom = this.scale.map(0) - this.scale.map(dMin);
179
- // } else {
180
- // peer.boundsOffsets.bottom = this.scale.map(this.data[i]) - this.scale.map(dMin);
181
- // peer.boundsOffsets.top = this.scale.map(dMax) - this.scale.map(0);
182
- // }
183
- // }
184
- // }
185
- } else if (this.channel == "area") {
186
- for (let i = 0; i < this.items.length; i++) {
187
- let peer = this.items[i], s = Math.sqrt(this.scale.map(this.data[i]));
188
- peer.resize(s, s);
189
- }
190
- this.scene._relayoutAncestors(this.anyItem, this.items);
191
- } else if (this.channel == "fontSize") {
192
- for (let i = 0; i < this.items.length; i++) {
193
- let peer = this.items[i], s = this.scale.map(this.data[i]);
194
- peer.styles.fontSize = s+ "px";
195
- }
196
- this.scene._relayoutAncestors(this.anyItem, this.items);
197
- } else if (this.channel == "strokeWidth") {
198
- for (let i = 0; i < this.items.length; i++) {
199
- let peer = this.items[i], s = this.scale.map(this.data[i]);
200
- peer.styles.strokeWidth = s;
201
- }
202
- this.scene._relayoutAncestors(this.anyItem, this.items);
203
- } else {
204
- let xRef = 'left', yRef = 'bottom';
205
- //if glyph item, check alignment
206
- if (this.anyItem.parent && this.anyItem.parent.type == ItemType.Glyph) {
207
- let children = this.anyItem.parent.children;
208
- if (uniqueNumbers(children.map(d=>d.bounds.right)).length == 1)
209
- xRef = 'right';
210
- if (uniqueNumbers(children.map(d=>d.bounds.top)).length == 1)
211
- yRef = 'top';
212
- }
213
-
214
- if (this.anyItem.type === ItemType.Collection && this.anyItem.layout && this.anyItem.layout[this.channel]) {
215
- //for cases like treemap barchart, where the collection size is bound to data before dividing
216
- for (let i = 0; i < this.items.length; i++) {
217
- let peer = this.items[i], s = this.scale.map(this.data[i]);
218
- peer.layout[this.channel] = s;
219
- }
220
- } else {
221
- for (let i = 0; i < this.items.length; i++) {
222
- let peer = this.items[i], s = this.scale.map(this.data[i]);
223
- let wd = this.channel == "width" ? s : peer.bounds.width,
224
- ht = this.channel == "height" ? s : peer.bounds.height;
225
- peer.resize(wd, ht, xRef, yRef);
226
- }
227
- }
228
-
229
- this.scene._relayoutAncestors(this.anyItem, this.items);
230
- }
231
- }
232
-
233
- encoding.run();
234
- return encoding;
235
- }
@@ -1,60 +0,0 @@
1
- import {DataType} from "../util/Constants";
2
- import DataScope from "../data/DataScope";
3
- import { nodeId } from "../util/Constants";
4
- import Scale from "../core/Scale";
5
-
6
- export function bindToText(encoding){
7
-
8
- encoding._query = function() {
9
- this.data = [];
10
-
11
- let field, items = this.items, dt;
12
- if (this.field.startsWith("parent.") || this.field.startsWith("child.")) {
13
- dt = this.datatable.tree.nodeTable;
14
- field = this.field.split(".")[1];
15
- let s = this.field.split(".")[0];
16
- let nodeIds = items.map(d => d.dataScope).map(d => d.getFieldValue(s));
17
- if (dt.getFieldType(field) == DataType.Integer || dt.getFieldType(field) == DataType.Number)
18
- this.data = nodeIds.map(d => (new DataScope(dt)).cross(nodeId, d).aggregateNumericalField(field));
19
- else
20
- this.data = nodeIds.map(d => (new DataScope(dt)).cross(nodeId, d).getFieldValue(field));
21
- } else {
22
- dt = this.datatable;
23
- field = this.field;
24
- if (dt.getFieldType(field) == DataType.Integer || dt.getFieldType(field) == DataType.Number)
25
- this.data = items.map(d => d.dataScope.aggregateNumericalField(field, this.aggregator));
26
- else
27
- this.data = items.map(d => d.dataScope.getFieldValue(field));
28
- }
29
- }
30
-
31
- encoding._map = function() {
32
- if (this.scale) {
33
- } else {
34
- switch (this.datatable.getFieldType(this.field)) {
35
- case DataType.Boolean:
36
- break;
37
-
38
- case DataType.Date:
39
- break;
40
-
41
- case DataType.String:
42
- default: //integer or number
43
- this.scale = new Scale("ordinal");
44
- this.scale.domain = [...new Set(this.data)];
45
- this.scale._scale.range(this.scale.domain.map(d => d + ""));
46
- break;
47
- }
48
- }
49
- }
50
-
51
- encoding._apply = function() {
52
- for (let i = 0; i < this.items.length; i++) {
53
- let peer = this.items[i], value = this.scale.map(this.data[i]);
54
- peer.text = value;
55
- }
56
- }
57
-
58
- encoding.run();
59
- return encoding;
60
- }