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,233 +0,0 @@
1
- import { CanvasProvider } from "../../render/CanvasRenderer";
2
- import { Style2SVG } from "../../render/SVGRenderer";
3
- import { generateUniqueID } from "../../util";
4
- import { ElementType } from "../../action/createElement";
5
- import LinearGradient from "../gradient/LinearGradient";
6
- import CircleMark from "./CircleMark";
7
-
8
-
9
-
10
- interface MarkJSON {
11
- type: keyof typeof ElementType;
12
- id: string;
13
- classId?: string;
14
- dataScope?: any; // Consider replacing 'any' with a more specific type if possible
15
- args: {
16
- [key: string]: any; // You might want to replace 'any' with more specific types based on your Style2SVG definition
17
- };
18
- }
19
-
20
-
21
- interface Bounds {
22
- contains: (px: number, py: number) => boolean;
23
- }
24
-
25
- export interface MarkArgs {
26
- type?: keyof typeof ElementType;
27
- id?: string;
28
- [key: string]: any; // Accommodate for other dynamic properties based on `Style2SVG`
29
- }
30
-
31
- export default class Mark {
32
- private _dataScope: any; // Define according to actual data scope object
33
- private _type: keyof typeof ElementType;
34
- private _id: string;
35
- private _classId?: string;
36
- private _bounds?: Bounds;
37
- private _styles: { [key: string]: any }; // Style definitions can vary
38
- private _strokeWidth: number; // Assuming strokeWidth is a number
39
-
40
- constructor(args: MarkArgs) {
41
- this._dataScope = undefined;
42
- this._type = "type" in args ? args.type! : ElementType.Mark; // Ensure ElementType.Mark is valid or use a valid default
43
- this._id = args.id ? args.id : this._type + generateUniqueID();
44
- this._classId = undefined;
45
- this._bounds = undefined;
46
- this._strokeWidth = 0; // Default value
47
- this._styles = {};
48
-
49
- // Initialize _styles based on args and Style2SVG mapping
50
- if (args !== undefined) {
51
- for (let s in Style2SVG) {
52
- if (s in args) {
53
- this._styles[s] = args[s];
54
- }
55
- }
56
- }
57
- }
58
-
59
- get strokeWidth(): number {
60
- return this._strokeWidth;
61
- }
62
-
63
- set strokeWidth(value: number) {
64
- this._strokeWidth = value;
65
- }
66
-
67
- get id(): string {
68
- return this._id;
69
- }
70
-
71
- set id(id: string) {
72
- // Assuming getScene is a method returning a scene object with _itemMap property
73
- // This part might need adjustment based on actual implementation of getScene
74
- const scene = this.getScene();
75
- if (scene) {
76
- delete scene._itemMap[this._id];
77
- this._id = id;
78
- scene._itemMap[id] = this;
79
- } else {
80
- this._id = id;
81
- }
82
- }
83
-
84
- get classId(): string | undefined {
85
- return this._classId;
86
- }
87
-
88
- set classId(cid: string | undefined) {
89
- this._classId = cid;
90
- }
91
-
92
- get bounds(): Bounds | undefined {
93
- return this._bounds;
94
- }
95
-
96
- set bounds(b: Bounds | undefined) {
97
- this._bounds = b;
98
- }
99
-
100
- get type(): keyof typeof ElementType {
101
- return this._type;
102
- }
103
-
104
- //TODO: implement winding contribution, see paper.js PathItem.Boolean.js
105
-
106
- initialContainsChecks(px: number, py: number): CanvasRenderingContext2D | undefined {
107
- if (!this._bounds) return undefined;
108
- if (!this._bounds.contains(px, py)) return undefined;
109
- const ctx = CanvasProvider.getContext();
110
- if (!ctx) return undefined; // Check if ctx is not null
111
- return ctx;
112
- }
113
- contains(px: number, py: number): boolean {
114
- const ctx = this.initialContainsChecks(px, py);
115
- if (typeof ctx === "undefined" || ctx === undefined) return false;
116
-
117
- switch (this.type) {
118
- case ElementType.Rect:
119
- case ElementType.PointText:
120
- return true;
121
- case ElementType.Circle: {
122
- throw new Error("Method not implemented.");
123
-
124
- }
125
- case ElementType.Path: {
126
- throw new Error("Method not implemented.");
127
- }
128
- case ElementType.Line: {
129
- let p = new Path2D(this.getSVGPathData());
130
- ctx.lineWidth = Math.max(this.strokeWidth, 2.5);
131
- ctx.stroke(p);
132
- return ctx.isPointInStroke(p, px, py);
133
- }
134
- default: {
135
- let p = new Path2D(this.getSVGPathData());
136
- return ctx.isPointInPath(p, px, py);
137
- }
138
- }
139
- }
140
-
141
- getSVGPathData(): string {
142
- throw new Error("Method not implemented.");
143
- }
144
-
145
-
146
- toJSON(): MarkJSON {
147
- const json: MarkJSON = {
148
- type: this._type,
149
- id: this._id,
150
- args: {}
151
- };
152
-
153
- if (this._classId) json.classId = this._classId;
154
- if (this._dataScope) json.dataScope = this._dataScope.toJSON(); // Assuming a toJSON method exists
155
-
156
- for (let s in this._styles) {
157
- const value = this._styles[s];
158
- json.args[s] = (value instanceof LinearGradient && value.toJSON) ? value.toJSON() : value;
159
- }
160
-
161
- // Optionally add other attributes to json.args as needed
162
-
163
- return json;
164
- }
165
-
166
- private getScene(): any {
167
- // Placeholder for actual getScene implementation
168
- }
169
-
170
-
171
- set dataScope(ds) {
172
- this._dataScope = ds;
173
- }
174
-
175
- get dataScope() {
176
- return this._dataScope;
177
- }
178
-
179
- // duplicate() {
180
- // //let scene = this.getScene();
181
- // let m = createMark({type: this.type});
182
- // this.copyPropertiesTo(m);
183
- // m._classId = this.classId;
184
- // if (this._dataScope) {
185
- // m._dataScope = this._dataScope.clone();
186
- // }
187
- // return m;
188
- // }
189
-
190
- // eslint-disable-next-line no-unused-vars
191
- _doTranslate(dx: number, dy: number): void {
192
- //child classes have their own implementations
193
- throw new Error("Method not implemented.");
194
- }
195
-
196
- get styles() {
197
- return this._styles;
198
- }
199
-
200
- set styles(value) {
201
- this._styles = value;
202
- }
203
-
204
- set visibility(v) {
205
- this.styles["visibility"] = v;
206
- }
207
-
208
- get visibility() {
209
- if (!this.styles["visibility"])
210
- return "visible";
211
- return this.styles["visibility"];
212
- }
213
-
214
- get opacity() {
215
- if (!("opacity" in this.styles))
216
- return 1;
217
- return this.styles["opacity"];
218
- }
219
-
220
- set opacity(c) {
221
- this.styles["opacity"] = c;
222
- }
223
-
224
- copyPropertiesTo(target: Mark): void {
225
- target.styles = Object.assign({}, this.styles);
226
- if (this._dataScope)
227
- target._dataScope = this._dataScope.clone();
228
- }
229
- }
230
-
231
- export function isMark(ele: any): ele is Mark {
232
- return ele instanceof Mark;
233
- }
@@ -1,483 +0,0 @@
1
- import Vertex from "./Vertex";
2
- import { ElementType } from "../../action/createElement";
3
- import Mark from "./Mark";
4
- import Segment from "./Segment";
5
- import { Rectangle } from "../../depgraph/variable/BoundsVar";
6
- import * as d3 from 'd3';
7
-
8
-
9
- export default class PathMark extends Mark {
10
-
11
- constructor(args) {
12
- super(args);
13
- this.type = "type" in args ? args.type : ElementType.Path;
14
-
15
- if (!("strokeColor" in this.styles))
16
- this.styles["strokeColor"] = "#ccc";
17
- if (!("strokeWidth" in this.styles))
18
- this.styles["strokeWidth"] = 1;
19
- if (!("strokeDash" in this.styles))
20
- this.styles["strokeDash"] = "none";
21
-
22
- this.vertices = [];
23
- this.vertexCounter = 0; //for assigning vertex ids
24
- this.segmentCounter = 0;
25
- this.segments = [];
26
-
27
- this.anchor = undefined;
28
-
29
- this.closed = false;
30
-
31
- this.curveMode = "linear";
32
-
33
- //when a path encodes data using its width or height, its geometric bounds may not be the same as its orginal bounds without encoding applied
34
- this.boundsOffsets = {top: 0, bottom: 0, left: 0, right: 0};
35
-
36
- this._vxShape = undefined;
37
- this._vxWidth = 0;
38
- this._vxHeight = 0;
39
- this._vxRadius = 0;
40
- this._vxFillColor = "#555555";
41
- this._vxStrokeColor = "#aaaaaa";
42
- this._vxStrokeWidth = 0;
43
- this._vxOpacity = 1;
44
-
45
- if (args !== undefined) {
46
- for (let vs of Vertex.styles){
47
- if (vs in args)
48
- this["_" + vs] = args[vs];
49
- }
50
-
51
- if ("vertices" in args) {
52
- this._setVertices(args["vertices"]);
53
- }
54
- }
55
- }
56
-
57
- toJSON() {
58
- let json = super.toJSON();
59
- json.type = this.type;
60
- json.id = this.id;
61
- switch (this.type) {
62
- case ElementType.Rect:
63
- json.args.width = this.width;
64
- json.args.height = this.height;
65
- json.args.top = this.top;
66
- json.args.left = this.left;
67
- break;
68
- case ElementType.Circle:
69
- json.args.x = this.x;
70
- json.args.y = this.y;
71
- json.args.radius = this.radius;
72
- break;
73
- case ElementType.Arc:
74
- case ElementType.Pie:
75
- json.args.x = this._x;
76
- json.args.y = this._y;
77
- json.args.innerRadius = this._innerRadius;
78
- json.args.outerRadius = this._outerRadius;
79
- json.args.startAngle = this._startAngle;
80
- json.args.endAngle = this._endAngle;
81
- break;
82
- case ElementType.Link:
83
- json.args.mode = this.mode;
84
- json.args.directed = this.directed;
85
- json.args.sourceAnchor = this.sourceAnchor;
86
- json.args.targetAnchor = this.targetAnchor;
87
- json.args.sourceOffset = this.sourceOffset;
88
- json.args.targetOffset = this.targetOffset;
89
- json.args.source = this.source.id;
90
- json.args.target = this.target.id;
91
- break;
92
- default:
93
- json.vertices = [];
94
- for (let v of this.vertices)
95
- json.vertices.push(v.toJSON());
96
- if (this.type === ElementType.Polygon) {
97
- json.args.x = this._x;
98
- json.args.y = this._y;
99
- json.args.radius = this._radius;
100
- } else if (this.type === ElementType.Area) {
101
- json.args.baseline = this._baseline;
102
- json.args.orientation = this._orientation;
103
- }
104
- break;
105
- }
106
-
107
- json.vertexCounter = this.vertexCounter;
108
- json.segmentCounter = this.segmentCounter;
109
- //do not save segments, anchor and closed for now
110
- json.curveMode = this.curveMode;
111
- if (this._bounds)
112
- json.bounds = this._bounds.toJSON();
113
- json.boundsOffsets = this.boundsOffsets;
114
- for (let s of Vertex.styles) {
115
- json.args[s] = this[s];
116
- }
117
- return json;
118
- }
119
-
120
- contains(px: number, py: number): boolean {
121
- const ctx = this.initialContainsChecks(px, py);
122
- if (typeof ctx === "undefined" || ctx === undefined) return false;
123
-
124
- let p = new Path2D(this.getSVGPathData());
125
- ctx.lineWidth = Math.max(this.strokeWidth, 2.5);
126
- ctx.stroke(p);
127
- if (pathMark.closed) {
128
- return ctx.isPointInPath(p, px, py);
129
- } else {
130
- return ctx.isPointInStroke(p, px, py);
131
- }
132
- }
133
-
134
- _setVertices(vertices) {
135
- let vertex;
136
- this.vertices = [];
137
- this.segments = [];
138
- for (let i = 0; i < vertices.length; i++) {
139
-
140
- if (i == vertices.length - 1 && vertices[i][0] === vertices[0][0] && vertices[i][1] === vertices[0][1] && this.type === ElementType.Path) {
141
- continue;
142
- }
143
-
144
- vertex = new Vertex(vertices[i][0], vertices[i][1], this, this.vertexCounter++);
145
-
146
- for (let vs of Vertex.styles){
147
- if (this[vs]){
148
- let temp = vs.replace("vx", "");
149
- vertex[temp[0].toLowerCase() + temp.slice(1)] = this[vs];
150
- }
151
- }
152
-
153
- this.vertices.push(vertex);
154
- if (i > 0)
155
- this.segments.push(new Segment(this.vertices[i-1], this.vertices[i], this, this.segmentCounter++));
156
- }
157
- //if the first vertex has the same position as the last, this path is closed
158
- let first = vertices[0], last = vertices[vertices.length - 1];
159
- if ((first[0] === last[0] && first[1] === last[1]) || this.type === ElementType.Rect) {
160
- this.closed = true;
161
- if (!("fillColor" in this.styles))
162
- this.styles["fillColor"] = "#fff";
163
- this.segments.push(new Segment(this.vertices[this.vertices.length-1], this.vertices[0], this, this.segmentCounter++));
164
- }
165
- }
166
-
167
- copyPropertiesTo(target) {
168
- target.attrs = Object.assign({}, this.attrs);
169
- target.styles = Object.assign({}, this.styles);
170
- for (let vs of Vertex.styles){
171
- if (this["_"+vs])
172
- target["_"+vs] = this["_"+vs];
173
- }
174
- if (this._dataScope)
175
- target._dataScope = this._dataScope.clone();
176
- target.closed = this.closed;
177
- target.curveMode = this.curveMode;
178
- target.vertices = [];
179
- target.segments = [];
180
- for (let v of this.vertices) {
181
- target.vertices.push(v._clone(target));
182
- }
183
- target.segmentCounter = 0;
184
- for (let i = 1; i < target.vertices.length; i++) {
185
- target.segments.push(new Segment(target.vertices[i-1], target.vertices[i], target, target.segmentCounter++));
186
- }
187
- if (target.closed)
188
- target.segments.push(new Segment(target.vertices[target.vertices.length-1], target.vertices[0], target, target.segmentCounter++));
189
- }
190
-
191
- /*
192
- * returns the bounds without incorporating transformations involving rotation
193
- */
194
- get bounds() {
195
- if (!this._bounds)
196
- this._updateBounds();
197
- return this._bounds;
198
- }
199
-
200
- /**
201
- * return the bounds as if the path does not encode data
202
- */
203
- get refBounds() {
204
- if (!this._bounds)
205
- this._updateBounds();
206
- let ht = (this._bounds.bottom + this.boundsOffsets.bottom) - (this._bounds.top - this.boundsOffsets.top),
207
- wd = this._bounds.right + this.boundsOffsets.right - (this._bounds.left - this.boundsOffsets.left);
208
- return new Rectangle(this._bounds.left - this.boundsOffsets.left, this._bounds.top - this.boundsOffsets.top, wd, ht);
209
- }
210
-
211
- get x() {
212
- return this.bounds.x;
213
- }
214
-
215
- get y() {
216
- return this.bounds.y;
217
- }
218
-
219
- get strokeColor() {
220
- return this.styles["strokeColor"];
221
- }
222
-
223
- set strokeColor(c) {
224
- this.styles["strokeColor"] = c;
225
- }
226
-
227
- get strokeWidth() {
228
- return this.styles["strokeWidth"];
229
- }
230
-
231
- set strokeWidth(c) {
232
- this.styles["strokeWidth"] = c;
233
- }
234
-
235
- get fillColor() {
236
- return this.styles["fillColor"];
237
- }
238
-
239
- set fillColor(c) {
240
- this.styles["fillColor"] = c;
241
- }
242
-
243
- get strokeDash() {
244
- return this.styles["strokeDash"];
245
- }
246
-
247
- set strokeDash(c) {
248
- this.styles["strokeDash"] = c;
249
- }
250
-
251
- _doTranslate(dx, dy) {
252
- for (let v of this.vertices) {
253
- v._doTranslate(dx, dy);
254
- }
255
- this._updateBounds();
256
- }
257
-
258
- //by default, with respect to the center of bounds
259
- resize(wd, ht, xRef, yRef) {
260
- let bounds = this.bounds, bWidth = bounds.width === 0 ? 1 : bounds.width, bHeight = bounds.height === 0 ? 1 : bounds.height;
261
- if (xRef === "right") {
262
- for (let v of this.vertices) {
263
- v.x = bounds.right - (wd/bWidth) * (bounds.right - v.x);
264
- }
265
- } else {
266
- for (let v of this.vertices) {
267
- v.x = bounds.left + (wd/bWidth) * (v.x - bounds.left);
268
- }
269
- }
270
- if (yRef === "top") {
271
- for (let v of this.vertices) {
272
- v.y = bounds.top + (ht/bHeight) * (v.y - bounds.top);
273
- }
274
- } else {
275
- for (let v of this.vertices) {
276
- v.y = bounds.bottom - (ht/bHeight) * (bounds.bottom - v.y);
277
- }
278
- }
279
- this._updateBounds();
280
- }
281
-
282
- _updateBounds() {
283
- let vx = this.vertices.map(d => d.x),
284
- vy = this.vertices.map(d => d.y);
285
-
286
- let left = Math.min(...vx), top = Math.min(...vy), right = Math.max(...vx), btm = Math.max(...vy);
287
-
288
- this._bounds = new Rectangle(left, top, right - left, btm - top);
289
- if (this.type === ElementType.Line || this.type === ElementType.Path) {
290
- let sw = this.styles["strokeWidth"] ? this.styles["strokeWidth"] : 1;
291
- if (left === right)
292
- this._bounds = new Rectangle(left - sw/2, top, right - left + sw, btm - top);
293
- else if (top === btm)
294
- this._bounds = new Rectangle(left, top - sw/2, right - left, btm - top + sw);
295
- }
296
- }
297
-
298
- addVertex(x, y, i) {
299
- let vertex = new Vertex(x, y, this, this.vertexCounter++);
300
- this.vertices.splice(i, 0, vertex);
301
- //TODO: handle segments
302
- }
303
-
304
- sortVertices(channel, descending) {
305
- this.vertices.sort((a,b) => a[channel] - b[channel]);
306
- if (descending)
307
- this.vertices.reverse();
308
- for (let i = 0; i < this.segments.length; i++) {
309
- let segment = this.segments[i];
310
- segment.vertex1 = this.vertices[i];
311
- segment.vertex2 = this.vertices[(i+1)%this.vertices.length];
312
- }
313
- }
314
-
315
- sortVerticesByData(field, descending, order) {
316
- let f;
317
- if (order)
318
- f = (a, b) => order.indexOf(a.dataScope.getFieldValue(field)) - order.indexOf(b.dataScope.getFieldValue(field));
319
- else
320
- f = (a, b) => (a.dataScope.getFieldValue(field) < b.dataScope.getFieldValue(field) ? -1 : 1 );
321
- this.vertices.sort(f);
322
- if (descending)
323
- this.vertices.reverse();
324
- for (let i = 0; i < this.segments.length; i++) {
325
- let segment = this.segments[i];
326
- segment.vertex1 = this.vertices[i];
327
- segment.vertex2 = this.vertices[(i+1)%this.vertices.length];
328
- }
329
- }
330
-
331
- getSVGPathData() {
332
- let p = d3.path();
333
- let curve = this._getD3CurveFunction(this.curveMode)(p);
334
- curve.lineStart();
335
- for (let vertex of this.vertices) {
336
- curve.point(vertex.x, vertex.y);
337
- }
338
- if (this.closed)
339
- curve.point(this.vertices[0].x, this.vertices[0].y);
340
- curve.lineEnd();
341
-
342
- return p._;
343
- }
344
-
345
- // toSVG() {
346
-
347
- // }
348
-
349
- // fromSVG() {
350
-
351
- // }
352
-
353
- get firstVertex() {
354
- return this.vertices[0];
355
- }
356
-
357
- get firstSegment() {
358
- return this.segments[0];
359
- }
360
-
361
- get lastVertex() {
362
- return this.vertices[this.vertices.length - 1];
363
- }
364
-
365
- get lastSegment() {
366
- return this.segments[this.segments.length - 1];
367
- }
368
-
369
- _getD3CurveFunction(v){
370
- switch(v) {
371
- case CurveMode.Natural:
372
- return d3.curveNatural;
373
- case CurveMode.Basis:
374
- return d3.curveBasis;
375
- case CurveMode.BumpX:
376
- return d3.curveBumpX;
377
- case CurveMode.BumpY:
378
- return d3.curveBumpY;
379
- case CurveMode.Linear:
380
- return d3.curveLinear;
381
- case CurveMode.Step:
382
- return d3.curveStep;
383
- case CurveMode.CatmullRom:
384
- return d3.curveCatmullRom;
385
- case CurveMode.Cardinal:
386
- return d3.curveCardinal;
387
- default:
388
- return d3.curveLinear;
389
- }
390
- }
391
-
392
- get vxShape(){
393
- return this._vxShape;
394
- }
395
-
396
- set vxShape(s){
397
- this._vxShape = s;
398
- for (let v of this.vertices)
399
- v.shape = s;
400
- }
401
-
402
- get vxWidth(){
403
- return this._vxWidth;
404
- }
405
-
406
- set vxWidth(s){
407
- this._vxWidth = s;
408
- for (let v of this.vertices)
409
- v.width = s;
410
- }
411
-
412
- get vxHeight(){
413
- return this._vxHeight;
414
- }
415
-
416
- set vxHeight(s){
417
- this._vxHeight = s;
418
- for (let v of this.vertices)
419
- v.height = s;
420
- }
421
-
422
- get vxRadius(){
423
- return this._vxRadius;
424
- }
425
-
426
- set vxRadius(s){
427
- this._vxRadius = s;
428
- for (let v of this.vertices)
429
- v.radius = s;
430
- }
431
-
432
- get vxFillColor(){
433
- return this._vxFillColor;
434
- }
435
-
436
- set vxFillColor(s){
437
- this._vxFillColor = s;
438
- for (let v of this.vertices)
439
- v.fillColor = s;
440
- }
441
-
442
- get vxStrokeColor(){
443
- return this._vxStrokeColor;
444
- }
445
-
446
- set vxStrokeColor(s){
447
- this._vxStrokeColor = s;
448
- for (let v of this.vertices)
449
- v.strokeColor = s;
450
- }
451
-
452
- get vxStrokeWidth(){
453
- return this._vxStrokeWidth;
454
- }
455
-
456
- set vxStrokeWidth(s){
457
- this._vxStrokeWidth = s;
458
- for (let v of this.vertices)
459
- v.strokeWidth = s;
460
- }
461
-
462
- get vxOpacity(){
463
- return this._vxOpacity;
464
- }
465
-
466
- set vxOpacity(s){
467
- this._vxOpacity = s;
468
- for (let v of this.vertices)
469
- v.opacity = s;
470
- }
471
-
472
- }
473
-
474
- export const CurveMode = {
475
- Natural: "natural",
476
- Basis: "basis",
477
- BumpX: "bumpX",
478
- BumpY: "bumpY",
479
- Linear: "linear",
480
- Step: "step",
481
- CatmullRom: "CatmullRom",
482
- Cardinal: "cardinal"
483
- }