mascot-vis 2.0.0 → 3.0.0

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 (157) hide show
  1. package/README.md +4 -3
  2. package/dist/mascot-es.js +27745 -0
  3. package/dist/mascot-min.js +186 -199
  4. package/dist/mascot-umd.js +27781 -0
  5. package/js/depGraphVis.js +66 -0
  6. package/package.json +23 -15
  7. package/src-new-ts/action/createElement.ts +91 -0
  8. package/src-new-ts/action/encode.js +20 -0
  9. package/src-new-ts/action/repeat.js +128 -0
  10. package/src-new-ts/action/traverseScene.js +41 -0
  11. package/src-new-ts/data/Network.js +2 -0
  12. package/src-new-ts/data/Scope.js +135 -0
  13. package/src-new-ts/data/Table.js +263 -0
  14. package/src-new-ts/data/Tree.js +3 -0
  15. package/src-new-ts/data/field.ts +115 -0
  16. package/src-new-ts/data/import.ts +96 -0
  17. package/src-new-ts/data/predicate.ts +82 -0
  18. package/src-new-ts/depgraph/DepGraph.js +178 -0
  19. package/src-new-ts/depgraph/Edge.js +9 -0
  20. package/src-new-ts/depgraph/SceneGraph2DepGraph.js +110 -0
  21. package/src-new-ts/depgraph/Signal.js +12 -0
  22. package/src-new-ts/depgraph/operator/BoundsEvaluator.js +30 -0
  23. package/src-new-ts/depgraph/operator/Dataflow.js +41 -0
  24. package/src-new-ts/depgraph/operator/DomainBuilder.js +50 -0
  25. package/src-new-ts/depgraph/updateDepGraph.js +45 -0
  26. package/src-new-ts/depgraph/variable/BoundsVar.js +81 -0
  27. package/src-new-ts/depgraph/variable/ChannelVar.js +17 -0
  28. package/src-new-ts/depgraph/variable/DataScopeVar.js +12 -0
  29. package/src-new-ts/depgraph/variable/DomainVar.js +15 -0
  30. package/src-new-ts/depgraph/variable/FieldVar.js +17 -0
  31. package/src-new-ts/depgraph/variable/LayoutParameter.js +8 -0
  32. package/src-new-ts/depgraph/variable/ScaleVar.js +13 -0
  33. package/src-new-ts/depgraph/variable/Variable.js +39 -0
  34. package/src-new-ts/element/gradient/LinearGradient.js +37 -0
  35. package/src-new-ts/element/group/Collection.js +109 -0
  36. package/src-new-ts/element/group/Group.js +307 -0
  37. package/src-new-ts/element/group/Scene.js +98 -0
  38. package/src-new-ts/element/mark/CircleMark.ts +85 -0
  39. package/src-new-ts/element/mark/Mark.ts +233 -0
  40. package/src-new-ts/element/mark/PathMark.js +483 -0
  41. package/src-new-ts/element/mark/Segment.js +29 -0
  42. package/src-new-ts/element/mark/Vertex.js +118 -0
  43. package/src-new-ts/encode/Scale.ts +115 -0
  44. package/src-new-ts/index.ts +19 -0
  45. package/src-new-ts/layout/Layout.ts +3 -0
  46. package/src-new-ts/render/CanvasRenderer.ts +24 -0
  47. package/src-new-ts/render/SVGRenderer.js +316 -0
  48. package/src-new-ts/util.ts +3 -0
  49. package/src-old/action/Classify.js +53 -0
  50. package/src-old/action/Densify.js +199 -0
  51. package/src-old/action/Partition.js +531 -0
  52. package/src-old/action/Repeat.js +106 -0
  53. package/src-old/action/Repopulate.js +44 -0
  54. package/src-old/action/Stratify.js +156 -0
  55. package/src-old/basic/Gradient.js +37 -0
  56. package/src-old/basic/Point.js +51 -0
  57. package/src-old/basic/Rectangle.js +63 -0
  58. package/src-old/bind/bindToAngle.js +56 -0
  59. package/src-old/bind/bindToAreaMark.js +360 -0
  60. package/src-old/bind/bindToColor.js +114 -0
  61. package/src-old/bind/bindToLink.js +81 -0
  62. package/src-old/bind/bindToPosition.js +283 -0
  63. package/src-old/bind/bindToRadialDistance.js +62 -0
  64. package/src-old/bind/bindToSize.js +235 -0
  65. package/src-old/bind/bindToText.js +60 -0
  66. package/src-old/bind/bindToThickness.js +100 -0
  67. package/src-old/constraint/AffixConstraint.js +129 -0
  68. package/src-old/constraint/AlignConstraint.js +58 -0
  69. package/src-old/core/Encoding.js +336 -0
  70. package/src-old/core/Scale.js +322 -0
  71. package/src-old/core/SceneLoader.js +290 -0
  72. package/src-old/core/SceneValidator.js +232 -0
  73. package/src-old/core/SpecExecutor.js +113 -0
  74. package/src-old/core/SpecGenerator.js +350 -0
  75. package/src-old/data/DataImporter.js +64 -0
  76. package/src-old/data/DataScope.js +124 -0
  77. package/src-old/data/DataTable.js +338 -0
  78. package/src-old/data/Network.js +106 -0
  79. package/src-old/data/Tree.js +251 -0
  80. package/src-old/data/transform/Bin.js +46 -0
  81. package/src-old/data/transform/Filter.js +48 -0
  82. package/src-old/data/transform/Groupby.js +18 -0
  83. package/src-old/data/transform/KDE.js +58 -0
  84. package/src-old/data/transform/Sort.js +14 -0
  85. package/src-old/data/transform/Split.js +5 -0
  86. package/src-old/data/transform/partition.js +46 -0
  87. package/src-old/history/UndoRedoStack +0 -0
  88. package/src-old/index.js +271 -0
  89. package/src-old/indexSVG.js +259 -0
  90. package/src-old/interaction/Interaction.js +91 -0
  91. package/src-old/interaction/MouseEvent.js +8 -0
  92. package/src-old/interaction/Selection.js +9 -0
  93. package/src-old/interaction/brush.js +362 -0
  94. package/src-old/item/Segment.js +29 -0
  95. package/src-old/item/Vertex.js +118 -0
  96. package/src-old/item/composite/Collection.js +106 -0
  97. package/src-old/item/composite/Glyph.js +19 -0
  98. package/src-old/item/composite/Group.js +310 -0
  99. package/src-old/item/composite/Scene.js +1251 -0
  100. package/src-old/item/mark/ArcPath.js +181 -0
  101. package/src-old/item/mark/AreaPath.js +78 -0
  102. package/src-old/item/mark/CirclePath.js +102 -0
  103. package/src-old/item/mark/EllipsePath.js +5 -0
  104. package/src-old/item/mark/Image.js +101 -0
  105. package/src-old/item/mark/LinkPath.js +118 -0
  106. package/src-old/item/mark/Mark.js +163 -0
  107. package/src-old/item/mark/Path.js +494 -0
  108. package/src-old/item/mark/PointText.js +201 -0
  109. package/src-old/item/mark/PolygonPath.js +64 -0
  110. package/src-old/item/mark/RectPath.js +88 -0
  111. package/src-old/item/mark/RingPath.js +92 -0
  112. package/src-old/item/refs/Axis.js +362 -0
  113. package/src-old/item/refs/EncodingAxis.js +515 -0
  114. package/src-old/item/refs/Gridlines.js +144 -0
  115. package/src-old/item/refs/LayoutAxis.js +316 -0
  116. package/src-old/item/refs/Legend.js +273 -0
  117. package/src-old/layout/Circular.js +95 -0
  118. package/src-old/layout/Force.js +52 -0
  119. package/src-old/layout/Grid.js +423 -0
  120. package/src-old/layout/Layout.js +13 -0
  121. package/src-old/layout/Packing.js +56 -0
  122. package/src-old/layout/Stack.js +264 -0
  123. package/src-old/layout/Strata.js +88 -0
  124. package/src-old/layout/Sugiyama.js +59 -0
  125. package/src-old/layout/TidyTree.js +105 -0
  126. package/src-old/layout/Treemap.js +87 -0
  127. package/src-old/renderer/SVGInteractionHandler.js +241 -0
  128. package/src-old/renderer/SVGRenderer.js +325 -0
  129. package/src-old/renderer/WebGLRenderer.js +1097 -0
  130. package/src-old/renderer/WebGLRenderer2.js +249 -0
  131. package/src-old/renderer/threejs/Line2.js +18 -0
  132. package/src-old/renderer/threejs/LineGeometry.js +77 -0
  133. package/src-old/renderer/threejs/LineMaterial.js +605 -0
  134. package/src-old/renderer/threejs/LineSegments2.js +281 -0
  135. package/src-old/renderer/threejs/LineSegmentsGeometry.js +226 -0
  136. package/src-old/renderer/threejs/Wireframe.js +51 -0
  137. package/src-old/renderer/threejs/WireframeGeometry2.js +16 -0
  138. package/src-old/scale/areaSize.js +0 -0
  139. package/src-old/scale/domain.js +38 -0
  140. package/src-old/util/Constants.js +180 -0
  141. package/src-old/util/DataUtil.js +35 -0
  142. package/src-old/util/ItemUtil.js +586 -0
  143. package/src-old/util/Numerical.js +33 -0
  144. package/tests/demo-tests/README.md +80 -0
  145. package/tests/demo-tests/SVG2PNG.js +56 -0
  146. package/tests/demo-tests/demos2CanvasPNGs.js +69 -0
  147. package/tests/demo-tests/demos2ScenesSVGs.js +100 -0
  148. package/tests/demo-tests/pathElementWorker.js +91 -0
  149. package/tests/demo-tests/pixelTest.js +62 -0
  150. package/tests/demo-tests/renderDemos.html +132 -0
  151. package/tests/demo-tests/serializationTest.js +36 -0
  152. package/tests/demo-tests/serializeDemos.html +134 -0
  153. package/tests/unit-tests/README.md +4 -0
  154. package/tests/unit-tests/jasmine-browser.json +21 -0
  155. package/tests/unit-tests/jasmine.json +14 -0
  156. package/tests/unit-tests/testSpec.js +274 -0
  157. package/dist/mascot.js +0 -24446
@@ -0,0 +1,362 @@
1
+ export const Direction = {
2
+ North: 'N',
3
+ South: 'S',
4
+ East: 'E',
5
+ West: 'W',
6
+ NorthEast: 'NE',
7
+ NorthWest: 'NW',
8
+ SouthEast: 'SE',
9
+ SouthWest: 'SW',
10
+ Move: 'M'
11
+ }
12
+
13
+ export default class Brush {
14
+
15
+ // Resize Corners and handling Bounds
16
+
17
+ SVG = null;
18
+ drag = false;
19
+ selection = [];
20
+ mouseDown = false;
21
+ rectSvg = null;
22
+ bounds = null;
23
+ brushColor = '#9c3131';
24
+
25
+ dir = null;
26
+ bb = [];
27
+ mouseDownEvent = null;
28
+
29
+ constructor(id, brushColor, bounds = null) {
30
+ this.SVG = d3.select("#" + id).style('cursor', 'crosshair');
31
+ this.brushColor = brushColor;
32
+ if (bounds) {
33
+ this.bounds = bounds;
34
+ }
35
+ }
36
+
37
+ brush() {
38
+ document.addEventListener(
39
+ 'mousedown', ($e) => {
40
+ this.mouseDownEvent = $e;
41
+ if (!this.rectSvg) {
42
+ this.appendRectangles(this.brushColor);
43
+ }
44
+ if (this.bounds) {
45
+ if (!($e.layerX >= this.bounds.left && $e.layerX <= this.bounds.left + this.bounds.width
46
+ && $e.layerY >= this.bounds.top && $e.layerY <= this.bounds.top + this.bounds.height))
47
+ return;
48
+ }
49
+ this.drag = false;
50
+ this.mouseDown = true;
51
+ this.selection = [$e.layerX, $e.layerY];
52
+
53
+ let x = this.bb[0];
54
+ let y = this.bb[1];
55
+ let height = this.bb[2];
56
+ let width = this.bb[3];
57
+ if (this.selection[0] > x + 3 && this.selection[0] < x + width - 3 && (this.selection[1] >= y + height - 3 && this.selection[1] <= y + height + 3)) {
58
+ this.dir = Direction.South;
59
+ } else if (this.selection[0] > x + 3 && this.selection[0] < x + width - 3 && (this.selection[1] >= y - 3 && this.selection[1] <= y + 3)) {
60
+ this.dir = Direction.North;
61
+ } else if (this.selection[1] > y + 3 && this.selection[1] < y + height - 3 && (this.selection[0] >= x + width - 3 && this.selection[0] <= x + width + 3)) {
62
+ this.dir = Direction.East;
63
+ } else if (this.selection[1] > y + 3 && this.selection[1] < y + height - 3 && (this.selection[0] >= x - 3 && this.selection[0] <= x + 3)) {
64
+ this.dir = Direction.West;
65
+ } else if (this.selection[0] >= x - 3 && this.selection[0] <= x + 3 && this.selection[1] >= y - 3 && this.selection[1] <= y + 3) {
66
+ this.dir = Direction.NorthWest;
67
+ } else if (this.selection[0] >= x - 3 && this.selection[0] <= x + 3 && this.selection[1] >= y + height - 3 && this.selection[1] <= y + height + 3) {
68
+ this.dir = Direction.SouthWest;
69
+ } else if (this.selection[0] >= x + width - 3 && this.selection[0] <= x + width + 3 && this.selection[1] >= y - 3 && this.selection[1] <= y + 3) {
70
+ this.dir = Direction.NorthEast;
71
+ } else if (this.selection[0] >= x + width - 3 && this.selection[0] <= x + width + 3 && this.selection[1] >= y + height - 3 && this.selection[1] <= y + height + 3) {
72
+ this.dir = Direction.SouthEast;
73
+ } else if (this.selection[0] > x + 3 && this.selection[0] < x + width - 3 && this.selection[1] > y + 3 && this.selection[1] < y + height - 3) {
74
+ this.dir = Direction.Move;
75
+ } else {
76
+ this.dir = null;
77
+ this.updateRectangles(null, $e.layerX, $e.layerY, 0, 0);
78
+ }
79
+ });
80
+
81
+ document.addEventListener(
82
+ 'mousemove', ($e) => {
83
+ if (this.mouseDown) {
84
+ this.drag = true;
85
+ if (this.dir == Direction.North) {
86
+ if ($e.layerY > this.bb[1]) {
87
+ //pull down
88
+ if ($e.layerY <= this.bb[1] + this.bb[2])//When we are above bottom line of rect
89
+ this.updateRectangles(null, this.bb[0], $e.layerY, this.bb[3], this.bb[2] + this.bb[1] - $e.layerY);
90
+ else//When we go below bottom line of rect
91
+ this.updateRectangles(null, this.bb[0], this.bb[1] + this.bb[2], this.bb[3], $e.layerY - this.bb[1] - this.bb[2]);
92
+ } else {
93
+ // pull up
94
+ this.updateRectangles(null, this.bb[0], $e.layerY, this.bb[3], this.bb[2] + this.bb[1] - $e.layerY);
95
+ }
96
+ } else if (this.dir == Direction.South) {
97
+ if ($e.layerY > this.bb[1]) {
98
+ //pull down
99
+ this.updateRectangles(null, this.bb[0], this.bb[1], this.bb[3], $e.layerY - this.bb[1]);
100
+ } else {
101
+ // pull up
102
+ this.updateRectangles(null, this.bb[0], $e.layerY, this.bb[3], this.bb[1] - $e.layerY);
103
+ }
104
+ //x,y,height,width
105
+ } else if (this.dir == Direction.West) {
106
+ if ($e.layerX > this.bb[0]) {//Move Right
107
+ if ($e.layerX <= this.bb[0] + this.bb[3])// When we are to the left of rightmost border
108
+ this.updateRectangles(null, $e.layerX, this.bb[1], this.bb[3] - $e.layerX + this.bb[0], this.bb[2]);
109
+ else
110
+ this.updateRectangles(null, this.bb[0] + this.bb[3], this.bb[1], $e.layerX - this.bb[0] - this.bb[3], this.bb[2]);
111
+
112
+ } else {// Move Left
113
+ this.updateRectangles(null, $e.layerX, this.bb[1], this.bb[3] + this.bb[0] - $e.layerX, this.bb[2]);
114
+ }
115
+ } else if (this.dir == Direction.East) {
116
+ if ($e.layerX > this.bb[0]) {//Move Left
117
+ this.updateRectangles(null, this.bb[0], this.bb[1], $e.layerX - this.bb[0], this.bb[2]);
118
+ } else {
119
+ this.updateRectangles(null, $e.layerX, this.bb[1], this.bb[0] - $e.layerX, this.bb[2]);
120
+ }
121
+ }
122
+ else if (this.dir == Direction.NorthEast) {
123
+ }
124
+ else if (this.dir == Direction.NorthWest) {
125
+ }
126
+ else if (this.dir == Direction.SouthEast) {
127
+ //Done
128
+ if ($e.layerX > this.bb[0] && $e.layerY > this.bb[1]) {
129
+ //4
130
+ this.updateRectangles(null, this.bb[0], this.bb[1], $e.layerX - this.bb[0], $e.layerY - this.bb[1]);
131
+ } else if ($e.layerX > this.bb[0] && $e.layerY < this.bb[1]) {
132
+ //1
133
+ this.updateRectangles(null, this.bb[0], $e.layerY, $e.layerX - this.bb[0], this.bb[1] - $e.layerY);
134
+ } else if ($e.layerX < this.bb[0] && $e.layerY < this.bb[1]) {
135
+ //2
136
+ this.updateRectangles(null, $e.layerX, $e.layerY, this.bb[0] - $e.layerX, this.bb[1] - $e.layerY);
137
+ } else {
138
+ //3
139
+ this.updateRectangles(null, $e.layerX, this.bb[1], this.bb[0] - $e.layerX, $e.layerY - this.bb[1]);
140
+ }
141
+ }
142
+ else if (this.dir == Direction.SouthWest) {
143
+ }
144
+ else if (this.dir == Direction.Move) {
145
+ this.updateRectangles(null, this.bb[0] + $e.layerX - this.selection[0], this.bb[1] + $e.layerY - this.selection[1], this.bb[3], this.bb[2]);
146
+ this.bb[0] = this.bb[0] + $e.layerX - this.selection[0];
147
+ this.bb[1] = this.bb[1] + $e.layerY - this.selection[1];
148
+ this.selection = [$e.layerX, $e.layerY];
149
+ }
150
+ else {
151
+ let { __x, __y, __height, __width } = this.getRectCoordinates($e, this.selection);
152
+ this.updateRectangles(null, __x, __y, __width, __height);
153
+ }
154
+ }
155
+ });
156
+
157
+ document.addEventListener(
158
+ 'mouseup', ($e) => {
159
+ if (this.mouseDown) {
160
+ if (this.drag) {
161
+ console.log('Brush');
162
+ let bb = this.rectSvg._groups[0][0].getBoundingClientRect();
163
+ this.bb = [bb.x - 183, bb.y, bb.height, bb.width];
164
+ document.dispatchEvent(new CustomEvent('brush', {
165
+ 'detail': { selection: [[bb.x - 183, bb.y], [bb.x - 183 + bb.width, bb.y + bb.height]] },
166
+ }));
167
+ // Brush Update here
168
+ } else {
169
+ console.log('Click');
170
+ this.updateRectangles('none');
171
+ this.bb = [];
172
+ this.removeRectangles();
173
+ // Click Update here
174
+ document.dispatchEvent(new CustomEvent('brush', {
175
+ 'detail': { e: this.mouseDownEvent },
176
+ }));
177
+ }
178
+ this.selection = [];
179
+ this.dir = null;
180
+ this.mouseDown = false;
181
+ }
182
+ })
183
+ return 1;
184
+ }
185
+ removeRectangles() {
186
+ this.rectSvg = null;
187
+ d3.selectAll('.handle--selection').remove()
188
+ d3.selectAll('.handle--n').remove()
189
+ d3.selectAll('.handle--w').remove();
190
+ d3.selectAll('.handle--e').remove();
191
+ d3.selectAll('.handle--s').remove();
192
+ d3.selectAll('.handle--nw').remove();
193
+ d3.selectAll('.handle--ne').remove();
194
+ d3.selectAll('.handle--sw').remove();
195
+ d3.selectAll('.handle--se').remove();
196
+ d3.selectAll('.handle--overlay').remove();
197
+
198
+ }
199
+ appendRectangles(brushColor) {
200
+ this.SVG
201
+ .append('rect')
202
+ .attr("class", "handle--overlay")
203
+ .attr("x", "0")
204
+ .attr("x", "0")
205
+ .attr("height", this.SVG._groups[0][0].clientHeight)
206
+ .attr("width", this.SVG._groups[0][0].clientWidth)
207
+ .style('cursor', 'crosshair')
208
+ .style("opacity", '0')
209
+ this.rectSvg = this.SVG
210
+ .append('rect')
211
+ .attr("class", "handle--selection")
212
+ .style("fill", brushColor)
213
+ .style('cursor', 'move')
214
+ .style("opacity", '0.3')
215
+ .attr("display", "none");
216
+ this.SVG
217
+ .append('rect')
218
+ .attr("class", "handle--n")
219
+ .style('cursor', 'ns-resize')
220
+ .attr("display", "none")
221
+ .style("opacity", '0')
222
+ this.SVG
223
+ .append('rect')
224
+ .attr("class", "handle--w")
225
+ .style('cursor', 'ew-resize')
226
+ .attr("display", "none")
227
+ .style("opacity", '0')
228
+ this.SVG
229
+ .append('rect')
230
+ .attr("class", "handle--e")
231
+ .style('cursor', 'ew-resize')
232
+ .attr("display", "none")
233
+ .style("opacity", '0')
234
+ this.SVG
235
+ .append('rect')
236
+ .attr("class", "handle--s")
237
+ .style('cursor', 'ns-resize')
238
+ .attr("display", "none")
239
+ .style("opacity", '0')
240
+ this.SVG
241
+ .append('rect')
242
+ .attr("class", "handle--nw")
243
+ .style('cursor', 'nwse-resize')
244
+ .attr("display", "none")
245
+ .style("opacity", '0')
246
+ this.SVG
247
+ .append('rect')
248
+ .attr("class", "handle--ne")
249
+ .style('cursor', 'nesw-resize')
250
+ .attr("display", "none")
251
+ .style("opacity", '0')
252
+ this.SVG
253
+ .append('rect')
254
+ .attr("class", "handle--sw")
255
+ .style('cursor', 'nesw-resize')
256
+ .attr("display", "none")
257
+ .style("opacity", '0')
258
+ this.SVG
259
+ .append('rect')
260
+ .attr("class", "handle--se")
261
+ .style('cursor', 'nwse-resize')
262
+ .attr("display", "none")
263
+ .style("opacity", '0');
264
+ }
265
+ updateRectangles(display = null, __x = null, __y = null, __width = null, __height = null) {
266
+ d3.selectAll('.handle--selection').attr("display", display).attr("x", __x)
267
+ .attr("y", __y)
268
+ .attr("height", __height)
269
+ .attr("width", __width)
270
+ d3.selectAll('.handle--n').attr("display", display).attr("x", __x ? __x - 3 : __x)
271
+ .attr("y", __y ? __y - 3 : __y)
272
+ .attr("height", __height == 0 || __height ? 6 : __height)
273
+ .attr("width", __width == 0 || __width ? __width + 6 : __width)
274
+ d3.selectAll('.handle--w').attr("display", display).attr("x", __x ? __x - 3 : __x)
275
+ .attr("y", __y ? __y - 3 : __y)
276
+ .attr("height", __height == 0 || __height ? __height + 6 : __height)
277
+ .attr("width", __width == 0 || __width ? 6 : __width);
278
+ d3.selectAll('.handle--e').attr("display", display).attr("x", __x ? __x + __width - 3 : __x)
279
+ .attr("y", __y ? __y - 3 : __y)
280
+ .attr("height", __height == 0 || __height ? __height + 6 : __height)
281
+ .attr("width", __width == 0 || __width ? 6 : __width);
282
+ d3.selectAll('.handle--s').attr("display", display).attr("x", __x ? __x - 3 : __x)
283
+ .attr("y", __y ? __y + __height - 3 : __y)
284
+ .attr("height", __height == 0 || __height ? 6 : __height)
285
+ .attr("width", __width == 0 || __width ? __width + 6 : __width);
286
+ d3.selectAll('.handle--nw').attr("display", display).attr("x", __x ? __x - 3 : __x)
287
+ .attr("y", __y ? __y - 3 : __y)
288
+ .attr("height", __height == 0 || __height ? 6 : __height)
289
+ .attr("width", __width == 0 || __width ? 6 : __width);
290
+ d3.selectAll('.handle--ne').attr("display", display).attr("x", __x ? __x + __width - 3 : __x)
291
+ .attr("y", __y ? __y - 3 : __y)
292
+ .attr("height", __height == 0 || __height ? 6 : __height)
293
+ .attr("width", __width == 0 || __width ? 6 : __width);
294
+ d3.selectAll('.handle--sw').attr("display", display).attr("x", __x ? __x - 3 : __x)
295
+ .attr("y", __y ? __y + __height - 3 : __y)
296
+ .attr("height", __height == 0 || __height ? 6 : __height)
297
+ .attr("width", __width == 0 || __width ? 6 : __width);
298
+ d3.selectAll('.handle--se').attr("display", display).attr("x", __x ? __x + __width - 3 : __x)
299
+ .attr("y", __y ? __y + __height - 3 : __y)
300
+ .attr("height", __height == 0 || __height ? 6 : __height)
301
+ .attr("width", __width == 0 || __width ? 6 : __width);
302
+ }
303
+ getRectCoordinates($e, selection) {
304
+ let __x, __y, __width, __height = null;
305
+ if ($e.layerY - selection[1] < 0) {
306
+ if ($e.layerX - selection[0] > 0) {
307
+ // LB-RT x+y-
308
+ __x = selection[0];
309
+ __y = $e.layerY;
310
+ __height = selection[1] - $e.layerY;
311
+ __width = $e.layerX - selection[0];
312
+ } else {
313
+ // RB-LT x-y-
314
+ __x = $e.layerX;
315
+ __y = $e.layerY;
316
+ __height = selection[1] - $e.layerY;
317
+ __width = selection[0] - $e.layerX;
318
+
319
+ }
320
+ } else {
321
+ if ($e.layerX - selection[0] > 0) {
322
+ // LT-BR x+y+
323
+ __x = selection[0];
324
+ __y = selection[1];
325
+ __height = $e.layerY - selection[1];
326
+ __width = $e.layerX - selection[0];
327
+ } else {
328
+ // RT-LB x-y+
329
+ __x = $e.layerX;
330
+ __y = selection[1];
331
+ __height = $e.layerY - selection[1];
332
+ __width = selection[0] - $e.layerX;
333
+ }
334
+ }
335
+
336
+ if (this.bounds) {
337
+ // Bounded
338
+ if ($e.layerY - selection[1] > 0) {
339
+ if (__y + __height > this.bounds.top + this.bounds.height) {
340
+ __height = this.bounds.top + this.bounds.height - selection[1];
341
+ }
342
+ } else {
343
+ if (this.bounds.top + __height > selection[1]) {
344
+ __y = this.bounds.top;
345
+ __height = selection[1] - $e.layerY - (this.bounds.top + __height - selection[1]);
346
+ }
347
+ }
348
+
349
+ if ($e.layerX - selection[0] > 0) {
350
+ if (__x + __width > this.bounds.left + this.bounds.width) {
351
+ __width = this.bounds.left + this.bounds.width - selection[0];
352
+ }
353
+ } else {
354
+ if (this.bounds.left + __width > selection[0]) {
355
+ __x = this.bounds.left;
356
+ __width = selection[0] - $e.layerX - (this.bounds.left + __width - selection[0]);
357
+ }
358
+ }
359
+ }
360
+ return { __x, __y, __height, __width };
361
+ }
362
+ }
@@ -0,0 +1,29 @@
1
+ export default class Segment {
2
+
3
+ constructor(v1, v2, parentMark, id) {
4
+ this.type = "segment";
5
+ this._id = id;
6
+ this.vertex1 = v1;
7
+ this.vertex2 = v2;
8
+
9
+ this.dataScope = undefined;
10
+ this.parent = parentMark;
11
+ }
12
+
13
+ get id() {
14
+ return this.parent.id + "_s_" + this._id;
15
+ }
16
+
17
+ _doTranslate(dx, dy) {
18
+ this.vertex1._doTranslate(dx, dy);
19
+ this.vertex2._doTranslate(dx, dy);
20
+ }
21
+
22
+ get x() {
23
+ return (this.vertex1.x + this.vertex2.x)/2;
24
+ }
25
+
26
+ get y() {
27
+ return (this.vertex1.y + this.vertex2.y)/2;
28
+ }
29
+ }
@@ -0,0 +1,118 @@
1
+ // Based on path.Segment.js, as part of Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
2
+ // http://paperjs.org/
3
+ // Copyright (c) 2011 - 2019, Juerg Lehni & Jonathan Puckey
4
+ // http://scratchdisk.com/ & https://puckey.studio/
5
+ //
6
+ // Distributed under the MIT license. See LICENSE file for detail
7
+ //
8
+ // All rights reserved.
9
+
10
+ import Point from "../basic/Point"
11
+ import Rectangle from "../basic/Rectangle";
12
+
13
+ export default class Vertex {
14
+
15
+ //handles are relative to the point
16
+ constructor(point, parentMark, id) {
17
+ this.type = "vertex";
18
+ this._id = id;
19
+ this.x = point.x;
20
+ this.y = point.y;
21
+ this.dataScope = undefined;
22
+ this.parent = parentMark;
23
+
24
+ this.shape = undefined;
25
+ this.width = 0;
26
+ this.height = 0;
27
+ this.radius = 0;
28
+ this.fillColor = "#555";
29
+ this.opacity = 1;
30
+ this.strokeWidth = 0;
31
+ this.strokeColor = "#aaa";
32
+ this._polarAngle = undefined;
33
+ }
34
+
35
+ get bounds() {
36
+ switch(this.shape) {
37
+ case "rect":
38
+ return new Rectangle(this.x - this.width/2, this.y - this.height/2, this.width, this.height);
39
+ case "circle":
40
+ return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2);
41
+ default:
42
+ return new Rectangle(this.x - 0.5, this.y - 0.5, 1, 1);
43
+ }
44
+ }
45
+
46
+ get id() {
47
+ return this.parent.id + "_v_" + this._id;
48
+ }
49
+
50
+ toJSON() {
51
+ let json = {};
52
+ json.type = this.type;
53
+ json.id = this._id;
54
+ json.x = this.x;
55
+ json.y = this.y;
56
+ if (this.dataScope)
57
+ json.dataScope = this.dataScope.toJSON();
58
+ if (this._polarAngle !== undefined)
59
+ json.polarAngle = this._polarAngle;
60
+ json.shape = this.shape;
61
+ json.width = this.width;
62
+ json.height = this.height;
63
+ json.radius = this.radius;
64
+ json.fillColor = this.fillColor;
65
+ json.opacity = this.opacity;
66
+ json.strokeWidth = this.strokeWidth;
67
+ json.strokeColor = this.strokeColor;
68
+ return json;
69
+ }
70
+
71
+ static fromJSON(json, parent) {
72
+ let v = new Vertex(json, parent, json.id);
73
+ if (json.dataScope)
74
+ v.dataScope = json.dataScope;
75
+ if ("polarAngle" in json)
76
+ v.polarAngle = json.polarAngle;
77
+ v.shape = json.shape;
78
+ v.width = json.width;
79
+ v.height = json.height;
80
+ v.radius = json.radius;
81
+ v.fillColor = json.fillColor;
82
+ v.opacity = json.opacity;
83
+ v.strokeWidth = json.strokeWidth;
84
+ v.strokeColor = json.strokeColor;
85
+ return v;
86
+ }
87
+
88
+ _doTranslate(dx, dy) {
89
+ this.x += dx;
90
+ this.y += dy;
91
+ }
92
+
93
+ _clone(parent) {
94
+ let v = new Vertex(new Point(this.x, this.y), parent, this._id);
95
+ if (this.dataScope) {
96
+ v.dataScope = this.dataScope.clone();
97
+ }
98
+ v.shape = this.shape;
99
+ v.width = this.width;
100
+ v.height = this.height;
101
+ v.radius = this.radius;
102
+ v.fillColor = this.fillColor;
103
+ v.opacity = this.opacity;
104
+ v.strokeWidth = this.strokeWidth;
105
+ v.strokeColor = this.strokeColor;
106
+ return v;
107
+ }
108
+
109
+ set polarAngle(a) {
110
+ this._polarAngle = a;
111
+ }
112
+
113
+ get polarAngle() {
114
+ return this._polarAngle;
115
+ }
116
+ }
117
+
118
+ Vertex.styles = ["vxShape", "vxWidth", "vxHeight", "vxRadius", "vxFillColor", "vxStrokeColor", "vxStrokeWidth", "vxOpacity"];
@@ -0,0 +1,106 @@
1
+ import Group from "./Group";
2
+ import {atlas_rowId, DataType, ItemType} from "../../util/Constants";
3
+ import {CanvasProvider, ItemCounter} from "../../util/ItemUtil";
4
+
5
+ export default class Collection extends Group{
6
+
7
+ constructor() {
8
+ super();
9
+ this.type = ItemType.Collection;
10
+ this._id = this.type + ItemCounter[this.type]++;
11
+ this.classId = this.id;
12
+ this._childrenOrder = undefined;
13
+ }
14
+
15
+ get childrenOrder() {
16
+ if (!this._childrenOrder)
17
+ return {"field": "atlas_rowId", "direction": "asc"};
18
+ else
19
+ return this._childrenOrder;
20
+ }
21
+
22
+ set childrenOrder(o) {
23
+ if (!("field" in o) && !("direction" in o)) return;
24
+ let field = o.field;
25
+ if (!this.dataScope.dataTable.hasField(field)) {
26
+ console.warn("Cannot order collection children by an non-existent field", o.field);
27
+ return;
28
+ }
29
+ this._childrenOrder = o;
30
+ let f;
31
+ if (field === atlas_rowId) {
32
+ f = (a, b) => parseInt(a.dataScope.getFieldValue(field).substring(1)) - parseInt(b.dataScope.getFieldValue(field).substring(1));
33
+ } else {
34
+ let type = this.children[0].dataScope.getFieldType(field);
35
+ switch (type) {
36
+ case DataType.Date:
37
+ break;
38
+ case DataType.Number:
39
+ case DataType.Integer:
40
+ f = (a, b) => a.dataScope.aggregateNumericalField(field) - b.dataScope.aggregateNumericalField(field);
41
+ break;
42
+ case DataType.String:
43
+ if (o.ranking)
44
+ f = (a, b) => o.ranking.indexOf(a.dataScope.getFieldValue(field)) - o.ranking.indexOf(b.dataScope.getFieldValue(field));
45
+ else
46
+ f = (a, b) => (a.dataScope.getFieldValue(field) < b.dataScope.getFieldValue(field) ? -1 : 1 );
47
+ break;
48
+ }
49
+ }
50
+ this.children.sort(f);
51
+
52
+ if (o.direction == "desc")
53
+ this.children.reverse();
54
+ if (this.layout)
55
+ this.layout.run();
56
+ }
57
+
58
+ duplicate() {
59
+ let coll = this.getScene().collection();
60
+ for (let i = 0; i < this.children.length; i++) {
61
+ let c = this.children[i];
62
+ coll.addChild(c.duplicate());
63
+ }
64
+ coll.classId = this.classId;
65
+ this.parent.addChild(coll);
66
+ if (this._layout) {
67
+ let layout = this._layout.clone();
68
+ coll.layout = layout;
69
+ }
70
+ return coll;
71
+ }
72
+
73
+ contains(x, y) {
74
+ let irregular2Ds = [ItemType.Arc, ItemType.Pie, ItemType.Polygon, ItemType.Area];
75
+ if (irregular2Ds.indexOf(this.firstChild.type) >= 0) {
76
+ let svgData = this.getSVGPathData();
77
+ if (svgData !== "") {
78
+ let ctx = CanvasProvider.getContext(),
79
+ p = new Path2D(svgData);
80
+ ctx.lineWidth = Math.max(this.strokeWidth, 2.5);
81
+ ctx.stroke(p);
82
+ return ctx.isPointInPath(p, x, y);
83
+ }
84
+ }
85
+ if (!this._bounds) {
86
+ this._updateBounds();
87
+ }
88
+ return this._bounds.contains(x, y);
89
+ }
90
+
91
+ getSVGPathData() {
92
+ let d = "";
93
+ for (let i of this.children) {
94
+ if (i.getSVGPathData)
95
+ d += i.getSVGPathData();
96
+ else if (i.bounds) {
97
+ let b = i.bounds;
98
+ d += ["M", b.left, b.top].join(" ");
99
+ d += ["L", b.right, b.top].join(" ");
100
+ d += ["L", b.right, b.bottom].join(" ");
101
+ d += ["L", b.left, b.bottom, "Z"].join(" ");
102
+ }
103
+ }
104
+ return d;
105
+ }
106
+ }
@@ -0,0 +1,19 @@
1
+ import Group from "./Group";
2
+ import {ItemType} from "../../util/Constants";
3
+ import {ItemCounter} from "../../util/ItemUtil";
4
+
5
+ export default class Glyph extends Group {
6
+
7
+ constructor(args) {
8
+ super();
9
+ this.type = ItemType.Glyph;
10
+ this._id = this.type + ItemCounter[this.type]++;
11
+ if (args){
12
+ for (let a of args){
13
+ this.addChild(a);
14
+ }
15
+ }
16
+ }
17
+
18
+
19
+ }