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,52 +0,0 @@
1
- import { LayoutType } from "../util/Constants";
2
- import Layout from "./Layout";
3
- import * as d3 from "d3";
4
-
5
- export default class ForceLayout extends Layout {
6
-
7
- constructor(args) {
8
- super();
9
- this.type = LayoutType.Force;
10
- this._x = "x" in args ? args.x : 0;
11
- this._y = "y" in args ? args.y : 0;
12
- this._iterations = "iterations" in args ? args.iterations : 1;
13
- this._repulsion = "repulsion" in args ? args.repulsion : 30;
14
- this._attraction = "attraction" in args ? args.attraction : 1;
15
- this._linkDistance = "linkDistance" in args ? args.linkDistance : 30;
16
- }
17
-
18
- toJSON() {
19
- let json = {args: {}};
20
- json.type = this.type;
21
- json.args.x = this._x;
22
- json.args.y = this._y;
23
- json.args.iterations = this._iterations;
24
- return json;
25
- }
26
-
27
- run() {
28
- if (this.group == undefined)
29
- return;
30
- let graph = this.group.children[0].dataScope._dt.graph;
31
-
32
- if (graph) {
33
- let links = graph.links.map(d => ({ source: graph.getNode(d.source), target: graph.getNode(d.target) }));
34
- let simulation = d3.forceSimulation(graph.nodes)
35
- .force("charge", d3.forceManyBody().strength(-this._repulsion))
36
- .force("link", d3.forceLink(links).id(d => d.id).distance(this._linkDistance))
37
- .force("x", d3.forceX())
38
- .force("y", d3.forceY())
39
- .force("center", d3.forceCenter(this._x, this._y).strength(this._attraction))
40
- ;
41
- simulation.stop();
42
- simulation.tick(this._iterations);
43
-
44
- for (let i = 0; i < this.group.children.length; i++) {
45
- this.group.children[i].x = graph.nodes[i].x;
46
- this.group.children[i].y = graph.nodes[i].y;
47
- }
48
- this.group._updateBounds();
49
- this.group.getScene()._updateAncestorBounds(this.group);
50
- }
51
- }
52
- }
@@ -1,423 +0,0 @@
1
- import Rectangle from "../basic/Rectangle";
2
- import {Alignment, Errors, ItemType, LayoutType} from "../util/Constants";
3
- import { getPeers } from "../util/ItemUtil";
4
- import Layout from "./Layout";
5
-
6
- export default class GridLayout extends Layout {
7
-
8
- constructor(args) {
9
- super();
10
- this.type = "grid";
11
- this._numCols = args["numCols"];
12
- this._numRows = args["numRows"];
13
- this._dir = ("dir" in args) ? args["dir"] : [GridLayout.direction.Left2Right, GridLayout.direction.Top2Bottom];
14
- // this._hDir = ("hDir" in args) ? args["hDir"] : GridLayout.direction.Left2Right;
15
- // this._vDir = ("vDir" in args) ? args["vDir"] : GridLayout.direction.Top2Bottom;
16
- this._rowGap = "rowGap" in args && args["rowGap"] !== undefined ? args["rowGap"] : 5;
17
- this._colGap = "colGap" in args && args["colGap"] !== undefined ? args["colGap"] : 5;
18
- this._cellHorzAlignment = "horzCellAlignment" in args && this._validateCellAlignment("h", args["horzCellAlignment"]) ? args["horzCellAlignment"] : Alignment.Left;
19
- this._cellVertAlignment = "vertCellAlignment" in args && this._validateCellAlignment("v", args["vertCellAlignment"]) ? args["vertCellAlignment"] : Alignment.Bottom;
20
- if (!this._numCols && !this._numRows)
21
- this._numRows = 1;
22
- }
23
-
24
- _validateCellAlignment(orientation, v) {
25
- if (orientation === "h" && [Alignment.Left, Alignment.Center, Alignment.Right].indexOf(v) >= 0){
26
- return true;
27
- } else if (orientation === "v" && [Alignment.Top, Alignment.Middle, Alignment.Bottom].indexOf(v) >= 0){
28
- return true;
29
- }
30
- console.warn("Invalid alignment:", v);
31
- return false;
32
-
33
- }
34
-
35
- // toJSON() {
36
- // let json = {args: {}};
37
- // json.type = this.type;
38
- // json.args.numCols = this._numCols;
39
- // json.args.numRows = this._numRows;
40
- // json.args.colGap = this._colGap;
41
- // json.args.rowGap = this._rowGap;
42
- // json.args.horzCellAlignment = this._cellHorzAlignment;
43
- // json.args.vertCellAlignment = this._cellVertAlignment;
44
- // json.left = this._left;
45
- // json.top = this._top;
46
- // json.args.dir = this._dir;
47
- // return json;
48
- // }
49
-
50
- clone() {
51
- return new GridLayout({
52
- numCols: this._numCols,
53
- numRows: this._numRows,
54
- // hDir: this._hDir,
55
- // vDir: this._vDir,
56
- dir: this._dir,
57
- colGap: this._colGap,
58
- rowGap: this._rowGap
59
- });
60
- }
61
-
62
- get cellBounds() {
63
- let numCols, numRows, group = this.group, colGap = this._colGap, rowGap = this._rowGap;
64
- if (this._numRows) {
65
- numRows = this._numRows;
66
- numCols = Math.ceil(this.group.children.length/this._numRows);
67
- } else if (this._numCols) {
68
- numCols = this._numCols;
69
- numRows = Math.ceil(this.group.children.length/this._numCols);
70
- }
71
-
72
- let bounds = group.children.map(d => d.bounds);
73
- if (this._left === undefined) {
74
- let lefts = bounds.map(d => d.left),
75
- tops = bounds.map(d => d.top);
76
- this._left = Math.min(...lefts);
77
- this._top = Math.min(...tops);
78
- }
79
-
80
- let wds = bounds.map(d => d.width),
81
- hts = bounds.map(d => d.height),
82
- cellWidth = Math.max(...wds),
83
- cellHeight = Math.max(...hts);
84
-
85
- //cell size should be determined by the scale range extent if bound to data
86
- let leftOffset = 0; //, topOffset = 0;
87
-
88
- let xEncs = group.getInternalEncodings("x"),
89
- yEncs = group.getInternalEncodings("y"),
90
- wdEncs = group.getInternalEncodings("width"),
91
- htEncs = group.getInternalEncodings("height");
92
- if (xEncs.length > 0) {
93
- let xEnc = xEncs[xEncs.length -1];
94
- let cw = xEnc.scale.rangeExtent;
95
- leftOffset = xEnc.scale.range[0];
96
- // if (xEnc.scale.type === "point") {
97
- // //TODO: need to handle variable sizes
98
- // cw += xEnc.anyItem.bounds.width;
99
- // }
100
- cellWidth = Math.max(cw, cellWidth);
101
- } else if (wdEncs.length > 0 && wdEncs[wdEncs.length -1]._rectNegativeValues) { //width encoding with negative values
102
- cellWidth = wdEncs[wdEncs.length -1].scale.rangeExtent;
103
- leftOffset = wdEncs[wdEncs.length -1].scale.range[0];
104
- }
105
- if (yEncs.length > 0) {
106
- let yEnc = yEncs[yEncs.length -1];
107
- let ch = yEnc.scale.rangeExtent;
108
- // if (yEnc.scale.type === "point") {
109
- // //TODO: need to handle variable sizes
110
- // ch += yEnc.anyItem.bounds.height;
111
- // }
112
- cellHeight = Math.max(ch, cellHeight);
113
- } else if (htEncs.length > 0 && htEncs[htEncs.length -1]._rectNegativeValues) { //width encoding with negative values
114
- cellHeight = htEncs[htEncs.length -1].scale.rangeExtent;
115
- }
116
-
117
- let cb = [], cellCount = numRows * numCols;
118
-
119
- switch (this._dir[0]) {
120
- case GridLayout.direction.Left2Right:
121
- switch (this._dir[1]) {
122
- case GridLayout.direction.Top2Bottom:
123
- for (let i = 0; i < cellCount; i++) {
124
- cb.push(new Rectangle(this._left + (cellWidth + colGap) * (i%numCols) + leftOffset,
125
- this._top + (cellHeight + rowGap) * Math.floor(i/numCols), cellWidth, cellHeight));
126
- }
127
- break;
128
- // return group.children.map((d, i) => new Rectangle(this._left + (cellWidth + colGap) * (i%numCols) + leftOffset,
129
- // this._top + (cellHeight + rowGap) * Math.floor(i/numCols), cellWidth, cellHeight));
130
- case GridLayout.direction.Bottom2Top:
131
- for (let i = 0; i < cellCount; i++) {
132
- cb.push(new Rectangle(this._left + (cellWidth + colGap) * (i%numCols) + leftOffset,
133
- this._top + (this.numRows - 1 - Math.floor(i/numCols)) * (cellHeight + rowGap), cellWidth, cellHeight));
134
- }
135
- break;
136
- // return group.children.map((d, i) => new Rectangle(this._left + (cellWidth + colGap) * (i%numCols) + leftOffset,
137
- // this._top + (this.numRows - 1 - Math.floor(i/numCols)) * (cellHeight + rowGap), cellWidth, cellHeight));
138
- }
139
- break;
140
- case GridLayout.direction.Right2Left:
141
- switch (this._dir[1]) {
142
- case GridLayout.direction.Top2Bottom:
143
- for (let i = 0; i < cellCount; i++) {
144
- cb.push(new Rectangle(leftOffset + this._left + (numCols - 1) * (cellWidth + colGap) - (cellWidth + colGap) * (i%numCols),
145
- this._top + (cellHeight + rowGap) * Math.floor(i/numCols), cellWidth, cellHeight));
146
- }
147
- break;
148
- // return group.children.map((d, i) => new Rectangle(leftOffset + this._left + (numCols - 1) * (cellWidth + colGap) - (cellWidth + colGap) * (i%numCols),
149
- // this._top + (cellHeight + rowGap) * Math.floor(i/numCols), cellWidth, cellHeight));
150
- case GridLayout.direction.Bottom2Top: {
151
- for (let i = 0; i < cellCount; i++) {
152
- cb.push(new Rectangle(leftOffset + this._left + (numCols - 1 - i%numCols) * (cellWidth + colGap),
153
- this._top + (this.numRows - 1 - Math.floor(i/numCols)) * (cellHeight + rowGap), cellWidth, cellHeight));
154
- }
155
- break;
156
- // return group.children.map((d, i) => new Rectangle(leftOffset + this._left + (numCols - 1 - i%numCols) * (cellWidth + colGap),
157
- // this._top + (this.numRows - 1 - Math.floor(i/numCols)) * (cellHeight + rowGap), cellWidth, cellHeight));
158
- }
159
- }
160
- break;
161
- case GridLayout.direction.Top2Bottom:
162
- switch (this._dir[1]) {
163
- case GridLayout.direction.Left2Right:
164
- for (let i = 0; i < cellCount; i++) {
165
- cb.push(new Rectangle(leftOffset + this._left + (cellWidth + colGap) * Math.floor(i/this.numRows),
166
- this._top + (cellHeight + rowGap) * (i%this.numRows), cellWidth, cellHeight));
167
- }
168
- break;
169
- // return group.children.map((d, i) => new Rectangle(leftOffset + this._left + (cellWidth + colGap) * Math.floor(i/this.numRows),
170
- // this._top + (cellHeight + rowGap) * (i%this.numRows), cellWidth, cellHeight));
171
- case GridLayout.direction.Right2Left:
172
- for (let i = 0; i < cellCount; i++) {
173
- cb.push(new Rectangle(leftOffset + this._left + (cellWidth + colGap) * (this.numCols - 1) - (cellWidth + colGap) * Math.floor(i/this.numRows),
174
- this._top + (cellHeight + rowGap) * (i%this.numRows), cellWidth, cellHeight));
175
- }
176
- break;
177
- // return group.children.map((d, i) => new Rectangle(leftOffset + this._left + (cellWidth + colGap) * (this.numCols - 1) - (cellWidth + colGap) * Math.floor(i/this.numRows),
178
- // this._top + (cellHeight + rowGap) * (i%this.numRows), cellWidth, cellHeight));
179
- }
180
- break;
181
- case GridLayout.direction.Bottom2Top:
182
- switch (this._dir[1]) {
183
- case GridLayout.direction.Left2Right:
184
- for (let i = 0; i < cellCount; i++) {
185
- cb.push(new Rectangle(leftOffset + this._left + (cellWidth + colGap) * Math.floor(i/this.numRows),
186
- this._top + (cellHeight + rowGap) * (this.numRows - 1) - (cellHeight + rowGap) * (i%this.numRows), cellWidth, cellHeight));
187
- }
188
- break;
189
- // this._top + (cellHeight + rowGap) * (this.numRows - 1) - (cellHeight + rowGap) * (i%this.numRows), cellWidth, cellHeight)));
190
- // return group.children.map((d, i) => new Rectangle(leftOffset + this._left + (cellWidth + colGap) * Math.floor(i/this.numRows),
191
- // this._top + (cellHeight + rowGap) * (this.numRows - 1) - (cellHeight + rowGap) * (i%this.numRows), cellWidth, cellHeight));
192
- case GridLayout.direction.Right2Left:
193
- for (let i = 0; i < cellCount; i++) {
194
- cb.push(new Rectangle(leftOffset + this._left + (cellWidth + colGap) * (this.numCols - 1) - (cellWidth + colGap) * Math.floor(i/this.numRows),
195
- this._top + (cellHeight + rowGap) * (this.numRows - 1) - (cellHeight + rowGap) * (i%this.numRows), cellWidth, cellHeight));
196
- }
197
- break;
198
- // return group.children.map((d, i) => new Rectangle(leftOffset + this._left + (cellWidth + colGap) * (this.numCols - 1) - (cellWidth + colGap) * Math.floor(i/this.numRows),
199
- // this._top + (cellHeight + rowGap) * (this.numRows - 1) - (cellHeight + rowGap) * (i%this.numRows), cellWidth, cellHeight));
200
- }
201
- break;
202
- }
203
-
204
- return cb;
205
-
206
- // if (group.firstChild.type === ItemType.Glyph) {
207
- // let items = group.firstChild.children, xRanges = [], yRanges = [], minLefts = [], minTops = [], scn = group.getScene();
208
- // for (let itm of items) {
209
- // let xEnc = scn.positionBound(itm, "x"), wdEnc = scn.sizeBound(itm, "width"),
210
- // yEnc = scn.positionBound(itm, "y"), htEnc = scn.sizeBound(itm, "height"),
211
- // peers = getPeers(itm, scn);
212
- // xRanges.push(xEnc? xEnc.scale.rangeExtent : wdEnc && wdEnc._rectNegativeValues ? wdEnc.scale.rangeExtent : undefined);
213
- // yRanges.push(yEnc? yEnc.scale.rangeExtent : htEnc && htEnc._rectNegativeValues ? htEnc.scale.rangeExtent : undefined);
214
- // minLefts.push(Math.min(...peers.map(d => d.bounds.left)));
215
- // minTops.push(Math.min(...peers.map(d => d.bounds.top)));
216
- // }
217
- // let wds = [], hts = [];
218
- // for (let c of group.children) {
219
- // let xCoords = [], yCoords = [];
220
- // for (const [i, m] of c.children.entries()) {
221
- // xCoords.push( m.refBounds.left, m.refBounds.left + (xRanges[i] ? xRanges[i] : m.bounds.width));
222
- // yCoords.push( m.refBounds.top, m.refBounds.top + (yRanges[i] ? yRanges[i] : m.bounds.height));
223
- // }
224
- // wds.push(Math.max(...xCoords) - Math.min(...xCoords));
225
- // hts.push(Math.max(...yCoords) - Math.min(...yCoords));
226
- // }
227
- // cellWidth = Math.max(...wds);
228
- // cellHeight = Math.max(...hts);
229
- // } else
230
- // if (group.firstChild.type === ItemType.Collection && group.firstChild.layout && group.firstChild.layout.type === LayoutType.Grid) {
231
- // let cb = group.firstChild.layout.cellBounds[0];
232
- // cellWidth = (cb.width + group.firstChild.layout.colGap) * Math.max(...group.children.map(d => d.layout.numCols)) - group.firstChild.layout.colGap;
233
- // cellHeight = (cb.height + group.firstChild.layout.rowGap) * Math.max(...group.children.map(d => d.layout.numRows)) - group.firstChild.layout.rowGap;
234
- // } else {
235
- }
236
-
237
- run() {
238
- if (this.group == undefined|| !this.group.children || this.group.children.length === 0)
239
- return;
240
-
241
- let cellBounds = this.cellBounds;
242
-
243
- let xEncs = this.group.getInternalEncodings("x"),
244
- yEncs = this.group.getInternalEncodings("y"),
245
- wdEncs = this.group.getInternalEncodings("width"),
246
- htEncs = this.group.getInternalEncodings("height");
247
- for (let i = 0; i < this.group.children.length; i++) {
248
- let c = this.group.children[i];
249
- let gridBound = cellBounds[i];
250
-
251
- let dx = gridBound.x - c.bounds.x,
252
- dy = gridBound.y - c.bounds.y;
253
- c._doTranslate(dx, dy);
254
-
255
- //alignment in cell if c's position is not bound to data
256
- let cdx = 0, cdy = 0;
257
- if (xEncs.length == 0) {
258
- switch(this._cellHorzAlignment) {
259
- case Alignment.Left:
260
- cdx = gridBound.left - c.bounds.left;
261
- break;
262
- case Alignment.Center:
263
- cdx = gridBound.x - c.bounds.x;
264
- break;
265
- case Alignment.Right:
266
- cdx = gridBound.right - c.bounds.right;
267
- break;
268
- }
269
- }
270
-
271
- if (yEncs.length == 0) {
272
- switch(this._cellVertAlignment) {
273
- case Alignment.Top:
274
- cdy = gridBound.top - c.bounds.top;
275
- break;
276
- case Alignment.Middle:
277
- cdy = gridBound.y - c.bounds.y;
278
- break;
279
- case Alignment.Bottom:
280
- cdy = gridBound.bottom - c.bounds.bottom;
281
- break;
282
- default:
283
- break;
284
- }
285
- }
286
-
287
- c._doTranslate(cdx, cdy);
288
- }
289
-
290
- if (xEncs.length > 0) {
291
- //if childrens' position bound to data, compute position using the scale
292
- for (let enc of xEncs)
293
- enc._apply();
294
- } else if (wdEncs.length > 0) {
295
- let enc = wdEncs[wdEncs.length-1];
296
- if (enc._rectNegativeValues){
297
- enc._apply();
298
- }
299
- }
300
-
301
- if (yEncs.length > 0) {
302
- //yEncs[yEncs.length-1]._map();
303
- // yEncs[yEncs.length-1]._apply();
304
- for (let enc of yEncs)
305
- enc._apply();
306
- } else if (htEncs.length > 0) {
307
- let enc = htEncs[htEncs.length-1];
308
- if (enc._rectNegativeValues){
309
- enc._apply();
310
- }
311
- }
312
-
313
- this.group._updateBounds();
314
- }
315
-
316
- //TODO: add a corresponding scene level operation, automatically relayout
317
- set rowGap(g) {
318
- this._rowGap = g;
319
- this.run();
320
- this.group.getScene()._relayoutAncestors(this.group);
321
- }
322
-
323
- get rowGap() {
324
- return this._rowGap;
325
- }
326
-
327
- set colGap(g) {
328
- this._colGap = g;
329
- this.run();
330
- this.group.getScene()._relayoutAncestors(this.group);
331
- }
332
-
333
- get colGap() {
334
- return this._colGap;
335
- }
336
-
337
- set numCols(c) {
338
- if (c < 0 || c > this.group.children.length) {
339
- console.warn("Cannot set", c, "columns for", this.group.children.length, "items in grid");
340
- return;
341
- }
342
- this._numCols = c;
343
- this._numRows = Math.ceil(this.group.children.length/c);
344
- this.run();
345
- this.group.getScene()._relayoutAncestors(this.group);
346
- }
347
-
348
- get numCols() {
349
- if (this._numCols) {
350
- return this._numCols;
351
- } else if (this._numRows) {
352
- return Math.ceil(this.group.children.length/this._numRows);
353
- } else {
354
- return 0;
355
- }
356
- }
357
-
358
- set numRows(c) {
359
- if (c < 0 || c > this.group.children.length) {
360
- console.warn("Cannot set", c, "rows for", this.group.children.length, "items in grid");
361
- return;
362
- }
363
- this._numRows = c;
364
- this._numCols = Math.ceil(this.group.children.length/c);
365
- this.run();
366
- this.group.getScene()._relayoutAncestors(this.group);
367
- }
368
-
369
-
370
- get numRows() {
371
- if (this._numRows) {
372
- return this._numRows;
373
- } else if (this._numCols) {
374
- return Math.ceil(this.group.children.length/this._numCols);
375
- } else
376
- return 0;
377
- }
378
-
379
- set vertCellAlignment(v) {
380
- if (v != Alignment.Top && v != Alignment.Bottom && v != Alignment.Middle) {
381
- throw Errors.UNKOWN_ALIGNMENT;
382
- }
383
- this._cellVertAlignment = v;
384
- this.run();
385
- }
386
-
387
- get vertCellAlignment() {
388
- return this._cellVertAlignment;
389
- }
390
-
391
- set horzCellAlignment(h) {
392
- if (h != Alignment.Left && h != Alignment.Center && h != Alignment.Right) {
393
- throw Errors.UNKOWN_ALIGNMENT;
394
- }
395
- this._cellHorzAlignment = h;
396
- this.run();
397
- }
398
-
399
- get horzCellAlignment() {
400
- return this._cellHorzAlignment;
401
- }
402
-
403
- //accepts two formats: a two-element array, or a string
404
- set direction(d) {
405
- if (Array.isArray(d) && d.length === 2) {
406
- this._dir = d;
407
- } else {
408
- this._dir = d.split("_");
409
- }
410
- this.run();
411
- }
412
-
413
- get direction() {
414
- return this._dir.join("_");
415
- }
416
- }
417
-
418
- GridLayout.direction = {
419
- Left2Right: "l2r",
420
- Right2Left: "r2l",
421
- Top2Bottom: "t2b",
422
- Bottom2Top: "b2t"
423
- }
@@ -1,13 +0,0 @@
1
- import { ItemCounter } from "../util/ItemUtil";
2
-
3
- export default class Layout {
4
-
5
- constructor(){
6
- this.group = undefined;
7
- this.id = "layout" + ItemCounter["layout"]++;
8
- }
9
-
10
- run(){}
11
-
12
- clone(){}
13
- }
@@ -1,56 +0,0 @@
1
- import * as d3 from "d3";
2
- import Layout from "./Layout";
3
-
4
- export default class PackingLayout extends Layout {
5
-
6
- constructor(args) {
7
- super();
8
- this.type = "packing";
9
- this.x = "x" in args ? args.x : 400;
10
- this.y = "y" in args ? args.y : 400;
11
- this.width = args.width;
12
- this.height = args.height;
13
- }
14
-
15
- toJSON() {
16
- let json = {args: {}};
17
- json.type = this.type;
18
- json.args.x = this.x;
19
- json.args.y = this.y;
20
- json.args.width = this.width;
21
- json.args.height = this.height;
22
- return json;
23
- }
24
-
25
- clone() {
26
- return new PackingLayout({x: this.x, y: this.y, width: this.width, height: this.height});
27
- }
28
-
29
- run() {
30
- if (this.group == undefined)
31
- return;
32
- let nodes = this.group.children.map(d => ({"name": d.id, "radius": d.radius, "itm": d}));
33
-
34
- let area = nodes.reduce((total, current) => total + Math.pow(current.radius, 2), 0),
35
- s = Math.sqrt(area);
36
-
37
- if (this.width === undefined) {
38
- this.width = s;
39
- }
40
-
41
- if (this.height === undefined) {
42
- this.height = s;
43
- }
44
-
45
- let data = d3.hierarchy({name: "root", children: nodes}).sum(d => d.radius ? d.radius : 0).sort((a, b) => b.value - a.value);
46
- d3.pack().size([this.width, this.height]).radius(d => d.value)(data);
47
-
48
- for (let c of data.children) {
49
- let itm = c.data.itm;
50
- let dx = this.x - data.x + c.x - itm.x, dy = this.y - data.y + c.y - itm.y;
51
- itm._doTranslate(dx, dy);
52
- }
53
- this.group._updateBounds();
54
- }
55
-
56
- }