@hpcc-js/graph 3.6.5 → 3.7.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.
- package/LICENSE +43 -43
- package/README.md +256 -256
- package/dist/assets/dagre-B-z4SP0u.js.map +1 -1
- package/dist/assets/{graphviz-DQ0E8zfY.js.map → graphviz-DJ070oMZ.js.map} +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +13 -13
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +9 -9
- package/src/AdjacencyGraph.ts +224 -224
- package/src/Edge.css +23 -23
- package/src/Edge.ts +257 -257
- package/src/Graph.css +18 -18
- package/src/Graph.ts +1077 -1077
- package/src/GraphData.ts +187 -187
- package/src/GraphLayouts.ts +214 -214
- package/src/Sankey.css +45 -46
- package/src/Sankey.ts +304 -304
- package/src/Subgraph.css +10 -10
- package/src/Subgraph.ts +165 -165
- package/src/Vertex.css +3 -3
- package/src/Vertex.ts +282 -282
- package/src/__package__.ts +3 -3
- package/src/__tests__/data.ts +444 -444
- package/src/__tests__/index.ts +1 -1
- package/src/__tests__/test1.ts +18 -18
- package/src/__tests__/test2.ts +80 -80
- package/src/__tests__/test3.ts +46 -46
- package/src/__tests__/test4.ts +66 -66
- package/src/__tests__/test5.ts +85 -85
- package/src/common/graphT.css +38 -38
- package/src/common/graphT.ts +1363 -1363
- package/src/common/index.ts +3 -3
- package/src/common/layouts/circle.ts +37 -37
- package/src/common/layouts/dagre.ts +145 -145
- package/src/common/layouts/dagreWorker.ts +24 -24
- package/src/common/layouts/forceDirected.ts +117 -117
- package/src/common/layouts/forceDirectedWorker.ts +22 -22
- package/src/common/layouts/geoForceDirected.ts +112 -112
- package/src/common/layouts/graphviz.ts +137 -137
- package/src/common/layouts/graphvizWorker.ts +27 -27
- package/src/common/layouts/index.ts +7 -7
- package/src/common/layouts/layout.ts +147 -147
- package/src/common/layouts/null.ts +39 -39
- package/src/common/layouts/placeholders.ts +113 -113
- package/src/common/layouts/tree.ts +326 -326
- package/src/common/layouts/workers/dagre.ts +46 -46
- package/src/common/layouts/workers/dagreOptions.ts +35 -35
- package/src/common/layouts/workers/forceDirected.ts +38 -38
- package/src/common/layouts/workers/forceDirectedOptions.ts +30 -30
- package/src/common/layouts/workers/graphviz.ts +225 -225
- package/src/common/layouts/workers/graphvizOptions.ts +70 -70
- package/src/common/liteMap.ts +72 -72
- package/src/common/liteSVGZooom.ts +61 -61
- package/src/common/sankeyGraph.css +45 -45
- package/src/common/sankeyGraph.ts +345 -345
- package/src/html/annotation.ts +71 -71
- package/src/html/component.ts +18 -18
- package/src/html/edge.ts +15 -15
- package/src/html/graphHtml.ts +11 -11
- package/src/html/graphHtmlT.ts +117 -117
- package/src/html/icon.ts +64 -64
- package/src/html/image.ts +26 -26
- package/src/html/imageChar.ts +18 -18
- package/src/html/index.ts +8 -8
- package/src/html/intersection.ts +110 -110
- package/src/html/shape.ts +141 -141
- package/src/html/text.ts +59 -59
- package/src/html/textBox.ts +45 -45
- package/src/html/vertex.ts +67 -67
- package/src/index.ts +10 -10
- package/src/react/dataGraph.ts +345 -345
- package/src/react/graphReact.ts +177 -177
- package/src/react/graphReactT.ts +44 -44
- package/src/react/index.ts +4 -4
- package/src/react/subgraph.tsx +30 -30
- package/src/react/vertex.tsx +31 -31
package/src/Edge.ts
CHANGED
|
@@ -1,257 +1,257 @@
|
|
|
1
|
-
import { Platform, SVGWidget, TextBox, Widget } from "@hpcc-js/common";
|
|
2
|
-
import { curveBasis as d3CurveBasis, curveBundle as d3CurveBundle, curveCardinal as d3CurveCardinal, curveCatmullRom as d3CurveCatmullRom, curveLinear as d3CurveLinear, line as d3Line } from "d3-shape";
|
|
3
|
-
|
|
4
|
-
import "../src/Edge.css";
|
|
5
|
-
|
|
6
|
-
const Curve = {
|
|
7
|
-
basis: d3CurveBasis,
|
|
8
|
-
bundle: d3CurveBundle,
|
|
9
|
-
cardinal: d3CurveCardinal,
|
|
10
|
-
catmullRom: d3CurveCatmullRom,
|
|
11
|
-
linear: d3CurveLinear
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export class Edge extends SVGWidget {
|
|
15
|
-
protected _points: any[];
|
|
16
|
-
protected _weight: number;
|
|
17
|
-
protected _strokeDasharray: number[];
|
|
18
|
-
protected _hidden: boolean;
|
|
19
|
-
protected _textBox: TextBox;
|
|
20
|
-
protected _sourceVertex: Widget;
|
|
21
|
-
protected _targetVertex: Widget;
|
|
22
|
-
protected _elementPath;
|
|
23
|
-
protected _graphID;
|
|
24
|
-
|
|
25
|
-
constructor() {
|
|
26
|
-
super();
|
|
27
|
-
|
|
28
|
-
this._points = [];
|
|
29
|
-
this._weight = 100;
|
|
30
|
-
this._strokeDasharray = null;
|
|
31
|
-
this._hidden = false;
|
|
32
|
-
|
|
33
|
-
this._textBox = new TextBox()
|
|
34
|
-
.padding(0)
|
|
35
|
-
;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
graphID(_) {
|
|
39
|
-
if (!arguments.length) return this._graphID;
|
|
40
|
-
this._graphID = _;
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
sourceVertex(): Widget;
|
|
45
|
-
sourceVertex(_: Widget): this;
|
|
46
|
-
sourceVertex(_?: Widget): Widget | this {
|
|
47
|
-
if (!arguments.length) return this._sourceVertex;
|
|
48
|
-
this._sourceVertex = _;
|
|
49
|
-
return this;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
targetVertex(): Widget;
|
|
53
|
-
targetVertex(_: Widget): this;
|
|
54
|
-
targetVertex(_?: Widget): Widget | this {
|
|
55
|
-
if (!arguments.length) return this._targetVertex;
|
|
56
|
-
this._targetVertex = _;
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
weight(): number;
|
|
61
|
-
weight(_: number): this;
|
|
62
|
-
weight(_?: number): number | this {
|
|
63
|
-
if (!arguments.length) return this._weight;
|
|
64
|
-
this._weight = _;
|
|
65
|
-
return this;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
points(): any[];
|
|
69
|
-
points(_: any[], transitionDuration?, skipPushMarkers?): this;
|
|
70
|
-
points(_?: any[], transitionDuration?, skipPushMarkers?): any[] | this {
|
|
71
|
-
if (!arguments.length) return this._points;
|
|
72
|
-
this._points = _;
|
|
73
|
-
if (this._elementPath) {
|
|
74
|
-
this.update(null, this._element, transitionDuration, skipPushMarkers);
|
|
75
|
-
}
|
|
76
|
-
return this;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
hidden(_) {
|
|
80
|
-
if (!arguments.length) return this._hidden;
|
|
81
|
-
this._hidden = _;
|
|
82
|
-
return this;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
text(): string;
|
|
86
|
-
text(_: string): this;
|
|
87
|
-
text(_?: string): string | this {
|
|
88
|
-
if (!arguments.length) return this._textBox.text();
|
|
89
|
-
this._textBox.text(_);
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
enter(domNode, element) {
|
|
94
|
-
super.enter(domNode, element);
|
|
95
|
-
this._elementPath = element.append("path");
|
|
96
|
-
|
|
97
|
-
if (this._textBox.text()) {
|
|
98
|
-
this._textBox
|
|
99
|
-
.target(domNode)
|
|
100
|
-
.tooltip(this.tooltip())
|
|
101
|
-
.render()
|
|
102
|
-
;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
update(domNode, element, transitionDuration?, skipPushMarkers?) {
|
|
107
|
-
super.update(domNode, element);
|
|
108
|
-
|
|
109
|
-
const context = this;
|
|
110
|
-
if (Platform.svgMarkerGlitch && !skipPushMarkers) {
|
|
111
|
-
element.transition().duration((transitionDuration ? transitionDuration : 0) + 100)
|
|
112
|
-
.on("start", function () {
|
|
113
|
-
context._pushMarkers(element);
|
|
114
|
-
})
|
|
115
|
-
.on("end", function () {
|
|
116
|
-
context._popMarkers(element);
|
|
117
|
-
})
|
|
118
|
-
;
|
|
119
|
-
}
|
|
120
|
-
const points = context._calculateEdgePoints(this._sourceVertex, this._targetVertex, this._points);
|
|
121
|
-
const svgPoints = element.selectAll(".point2").data(this.showControlPoints() ? points : []);
|
|
122
|
-
svgPoints.enter().append("circle")
|
|
123
|
-
.attr("class", "point2")
|
|
124
|
-
.style("stroke", "red")
|
|
125
|
-
.merge(svgPoints)
|
|
126
|
-
.attr("cx", d => d.x)
|
|
127
|
-
.attr("cy", d => d.y)
|
|
128
|
-
.attr("r", 1)
|
|
129
|
-
;
|
|
130
|
-
svgPoints.exit().remove();
|
|
131
|
-
|
|
132
|
-
const line = d3Line()
|
|
133
|
-
.x(function (d: any) { return d.x; })
|
|
134
|
-
.y(function (d: any) { return d.y; })
|
|
135
|
-
// .tension(0.75)
|
|
136
|
-
.curve(Curve.basis)(points)
|
|
137
|
-
;
|
|
138
|
-
let pathElements = this._elementPath;
|
|
139
|
-
if (transitionDuration) {
|
|
140
|
-
pathElements = pathElements.transition().duration(transitionDuration);
|
|
141
|
-
}
|
|
142
|
-
pathElements
|
|
143
|
-
.attr("opacity", this._hidden ? 0 : 1)
|
|
144
|
-
.attr("marker-start", !(Platform.svgMarkerGlitch && skipPushMarkers) && this.sourceMarker_exists() ? "url(#" + this._graphID + "_" + this.sourceMarker() + "Foot)" : null)
|
|
145
|
-
.attr("marker-end", !(Platform.svgMarkerGlitch && skipPushMarkers) && this.targetMarker_exists() ? "url(#" + this._graphID + "_" + this.targetMarker() + "Head)" : null)
|
|
146
|
-
.attr("stroke", this.strokeColor_exists() ? this.strokeColor() : null)
|
|
147
|
-
.attr("stroke-dasharray", this.strokeDasharray_exists() ? this.strokeDasharray() : null)
|
|
148
|
-
.attr("d", line)
|
|
149
|
-
;
|
|
150
|
-
|
|
151
|
-
if (this._textBox.text()) {
|
|
152
|
-
this._textBox
|
|
153
|
-
.tooltip(this.tooltip())
|
|
154
|
-
.move(this._findMidPoint(points), transitionDuration)
|
|
155
|
-
;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
exit(domNode, element) {
|
|
160
|
-
if (this._textBox) {
|
|
161
|
-
this._textBox.target(null);
|
|
162
|
-
}
|
|
163
|
-
super.exit(domNode, element);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
_findMidPoint(points) {
|
|
167
|
-
const midIdx = points.length / 2;
|
|
168
|
-
if (points.length % 2) {
|
|
169
|
-
return points[Math.floor(midIdx)];
|
|
170
|
-
} else if (points.length) {
|
|
171
|
-
const p0 = points[midIdx - 1];
|
|
172
|
-
const p1 = points[midIdx];
|
|
173
|
-
return { x: (p0.x + p1.x) / 2, y: (p0.y + p1.y) / 2 };
|
|
174
|
-
}
|
|
175
|
-
return { x: 0, y: 0 };
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
_calculateEdgePoints(source, target, _points) {
|
|
179
|
-
if (!source || !target) {
|
|
180
|
-
return [{ x: 0, y: 0 }, { x: 0, y: 0 }];
|
|
181
|
-
}
|
|
182
|
-
let points = _points ? _points.filter(p => !source.contains(p) && !target.contains(p)) : [];
|
|
183
|
-
const p0 = points.length === 0 ? target.pos() : points[0];
|
|
184
|
-
const p1 = points.length === 0 ? source.pos() : points[points.length - 1];
|
|
185
|
-
|
|
186
|
-
points.unshift(source.intersection(source._pos, p0));
|
|
187
|
-
points.push(target.intersection(target._pos, p1));
|
|
188
|
-
if (!points[0]) {
|
|
189
|
-
points[0] = source._pos;
|
|
190
|
-
}
|
|
191
|
-
if (!points[points.length - 1]) {
|
|
192
|
-
points[points.length - 1] = target._pos;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if ((!_points || _points.length === 0) && points.length === 2 && points[0] && points[1]) {
|
|
196
|
-
const dx = points[0].x - points[1].x;
|
|
197
|
-
const dy = points[0].y - points[1].y;
|
|
198
|
-
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
199
|
-
if (dist) {
|
|
200
|
-
if (this.showArc()) {
|
|
201
|
-
const midX = (points[0].x + points[1].x) / 2 - dy * this.arcDepth() / 100;
|
|
202
|
-
const midY = (points[0].y + points[1].y) / 2 + dx * this.arcDepth() / 100;
|
|
203
|
-
points = [{ x: points[0].x, y: points[0].y }, { x: midX, y: midY }, { x: points[1].x, y: points[1].y }];
|
|
204
|
-
} else {
|
|
205
|
-
points = [{ x: points[0].x, y: points[0].y }, { x: points[1].x, y: points[1].y }];
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
return points;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
Edge.prototype._class += " graph_Edge";
|
|
213
|
-
|
|
214
|
-
export interface Edge {
|
|
215
|
-
arcDepth(): number;
|
|
216
|
-
arcDepth(_: number): this;
|
|
217
|
-
showControlPoints(): boolean;
|
|
218
|
-
showControlPoints(_: boolean): this;
|
|
219
|
-
showArc(): boolean;
|
|
220
|
-
showArc(_: boolean): this;
|
|
221
|
-
tooltip(): string;
|
|
222
|
-
tooltip(_: string): this;
|
|
223
|
-
|
|
224
|
-
sourceMarker(): string;
|
|
225
|
-
sourceMarker(_: string): this;
|
|
226
|
-
sourceMarker_exists: () => boolean;
|
|
227
|
-
targetMarker(): string;
|
|
228
|
-
targetMarker(_: string): this;
|
|
229
|
-
targetMarker_exists: () => boolean;
|
|
230
|
-
strokeDasharray(): string;
|
|
231
|
-
strokeDasharray(_: string): this;
|
|
232
|
-
strokeDasharray_exists: () => boolean;
|
|
233
|
-
strokeColor(): string;
|
|
234
|
-
strokeColor(_: string): this;
|
|
235
|
-
strokeColor_exists: () => boolean;
|
|
236
|
-
|
|
237
|
-
text_shape_colorFill(): string;
|
|
238
|
-
text_shape_colorFill(_: string): this;
|
|
239
|
-
text_shape_colorStroke(): string;
|
|
240
|
-
text_shape_colorStroke(_: string): this;
|
|
241
|
-
text_text_colorFill(): string;
|
|
242
|
-
text_text_colorFill(_: string): this;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
Edge.prototype.publish("arcDepth", 16, "number", "Arc Depth", null, { tags: ["Basic"] });
|
|
246
|
-
Edge.prototype.publish("showControlPoints", false, "boolean", "Show/Hide Control Points", null, { tags: ["Basic"] });
|
|
247
|
-
Edge.prototype.publish("showArc", true, "boolean", "Show/Hide Arc", null, { tags: ["Basic"] });
|
|
248
|
-
Edge.prototype.publish("tooltip", "", "string", "Tooltip", null, { tags: ["Private"] });
|
|
249
|
-
|
|
250
|
-
Edge.prototype.publish("sourceMarker", "circle", "set", "Source Marker", ["none", "circle"], { optional: true });
|
|
251
|
-
Edge.prototype.publish("targetMarker", "arrow", "set", "Source Marker", ["none", "arrow", "circle"], { optional: true });
|
|
252
|
-
Edge.prototype.publish("strokeDasharray", null, "string", "Stroke Dash Array", null, { optional: true });
|
|
253
|
-
Edge.prototype.publish("strokeColor", null, "html-color", "Stroke Color", null, { optional: true });
|
|
254
|
-
Edge.prototype.publish("textColor", null, "html-color", "Text Color", null, { optional: true });
|
|
255
|
-
Edge.prototype.publishProxy("text_shape_colorFill", "_textBox", "shape_colorFill");
|
|
256
|
-
Edge.prototype.publishProxy("text_shape_colorStroke", "_textBox", "shape_colorStroke");
|
|
257
|
-
Edge.prototype.publishProxy("text_text_colorFill", "_textBox", "text_colorFill");
|
|
1
|
+
import { Platform, SVGWidget, TextBox, Widget } from "@hpcc-js/common";
|
|
2
|
+
import { curveBasis as d3CurveBasis, curveBundle as d3CurveBundle, curveCardinal as d3CurveCardinal, curveCatmullRom as d3CurveCatmullRom, curveLinear as d3CurveLinear, line as d3Line } from "d3-shape";
|
|
3
|
+
|
|
4
|
+
import "../src/Edge.css";
|
|
5
|
+
|
|
6
|
+
const Curve = {
|
|
7
|
+
basis: d3CurveBasis,
|
|
8
|
+
bundle: d3CurveBundle,
|
|
9
|
+
cardinal: d3CurveCardinal,
|
|
10
|
+
catmullRom: d3CurveCatmullRom,
|
|
11
|
+
linear: d3CurveLinear
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export class Edge extends SVGWidget {
|
|
15
|
+
protected _points: any[];
|
|
16
|
+
protected _weight: number;
|
|
17
|
+
protected _strokeDasharray: number[];
|
|
18
|
+
protected _hidden: boolean;
|
|
19
|
+
protected _textBox: TextBox;
|
|
20
|
+
protected _sourceVertex: Widget;
|
|
21
|
+
protected _targetVertex: Widget;
|
|
22
|
+
protected _elementPath;
|
|
23
|
+
protected _graphID;
|
|
24
|
+
|
|
25
|
+
constructor() {
|
|
26
|
+
super();
|
|
27
|
+
|
|
28
|
+
this._points = [];
|
|
29
|
+
this._weight = 100;
|
|
30
|
+
this._strokeDasharray = null;
|
|
31
|
+
this._hidden = false;
|
|
32
|
+
|
|
33
|
+
this._textBox = new TextBox()
|
|
34
|
+
.padding(0)
|
|
35
|
+
;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
graphID(_) {
|
|
39
|
+
if (!arguments.length) return this._graphID;
|
|
40
|
+
this._graphID = _;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
sourceVertex(): Widget;
|
|
45
|
+
sourceVertex(_: Widget): this;
|
|
46
|
+
sourceVertex(_?: Widget): Widget | this {
|
|
47
|
+
if (!arguments.length) return this._sourceVertex;
|
|
48
|
+
this._sourceVertex = _;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
targetVertex(): Widget;
|
|
53
|
+
targetVertex(_: Widget): this;
|
|
54
|
+
targetVertex(_?: Widget): Widget | this {
|
|
55
|
+
if (!arguments.length) return this._targetVertex;
|
|
56
|
+
this._targetVertex = _;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
weight(): number;
|
|
61
|
+
weight(_: number): this;
|
|
62
|
+
weight(_?: number): number | this {
|
|
63
|
+
if (!arguments.length) return this._weight;
|
|
64
|
+
this._weight = _;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
points(): any[];
|
|
69
|
+
points(_: any[], transitionDuration?, skipPushMarkers?): this;
|
|
70
|
+
points(_?: any[], transitionDuration?, skipPushMarkers?): any[] | this {
|
|
71
|
+
if (!arguments.length) return this._points;
|
|
72
|
+
this._points = _;
|
|
73
|
+
if (this._elementPath) {
|
|
74
|
+
this.update(null, this._element, transitionDuration, skipPushMarkers);
|
|
75
|
+
}
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
hidden(_) {
|
|
80
|
+
if (!arguments.length) return this._hidden;
|
|
81
|
+
this._hidden = _;
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
text(): string;
|
|
86
|
+
text(_: string): this;
|
|
87
|
+
text(_?: string): string | this {
|
|
88
|
+
if (!arguments.length) return this._textBox.text();
|
|
89
|
+
this._textBox.text(_);
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
enter(domNode, element) {
|
|
94
|
+
super.enter(domNode, element);
|
|
95
|
+
this._elementPath = element.append("path");
|
|
96
|
+
|
|
97
|
+
if (this._textBox.text()) {
|
|
98
|
+
this._textBox
|
|
99
|
+
.target(domNode)
|
|
100
|
+
.tooltip(this.tooltip())
|
|
101
|
+
.render()
|
|
102
|
+
;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
update(domNode, element, transitionDuration?, skipPushMarkers?) {
|
|
107
|
+
super.update(domNode, element);
|
|
108
|
+
|
|
109
|
+
const context = this;
|
|
110
|
+
if (Platform.svgMarkerGlitch && !skipPushMarkers) {
|
|
111
|
+
element.transition().duration((transitionDuration ? transitionDuration : 0) + 100)
|
|
112
|
+
.on("start", function () {
|
|
113
|
+
context._pushMarkers(element);
|
|
114
|
+
})
|
|
115
|
+
.on("end", function () {
|
|
116
|
+
context._popMarkers(element);
|
|
117
|
+
})
|
|
118
|
+
;
|
|
119
|
+
}
|
|
120
|
+
const points = context._calculateEdgePoints(this._sourceVertex, this._targetVertex, this._points);
|
|
121
|
+
const svgPoints = element.selectAll(".point2").data(this.showControlPoints() ? points : []);
|
|
122
|
+
svgPoints.enter().append("circle")
|
|
123
|
+
.attr("class", "point2")
|
|
124
|
+
.style("stroke", "red")
|
|
125
|
+
.merge(svgPoints)
|
|
126
|
+
.attr("cx", d => d.x)
|
|
127
|
+
.attr("cy", d => d.y)
|
|
128
|
+
.attr("r", 1)
|
|
129
|
+
;
|
|
130
|
+
svgPoints.exit().remove();
|
|
131
|
+
|
|
132
|
+
const line = d3Line()
|
|
133
|
+
.x(function (d: any) { return d.x; })
|
|
134
|
+
.y(function (d: any) { return d.y; })
|
|
135
|
+
// .tension(0.75)
|
|
136
|
+
.curve(Curve.basis)(points)
|
|
137
|
+
;
|
|
138
|
+
let pathElements = this._elementPath;
|
|
139
|
+
if (transitionDuration) {
|
|
140
|
+
pathElements = pathElements.transition().duration(transitionDuration);
|
|
141
|
+
}
|
|
142
|
+
pathElements
|
|
143
|
+
.attr("opacity", this._hidden ? 0 : 1)
|
|
144
|
+
.attr("marker-start", !(Platform.svgMarkerGlitch && skipPushMarkers) && this.sourceMarker_exists() ? "url(#" + this._graphID + "_" + this.sourceMarker() + "Foot)" : null)
|
|
145
|
+
.attr("marker-end", !(Platform.svgMarkerGlitch && skipPushMarkers) && this.targetMarker_exists() ? "url(#" + this._graphID + "_" + this.targetMarker() + "Head)" : null)
|
|
146
|
+
.attr("stroke", this.strokeColor_exists() ? this.strokeColor() : null)
|
|
147
|
+
.attr("stroke-dasharray", this.strokeDasharray_exists() ? this.strokeDasharray() : null)
|
|
148
|
+
.attr("d", line)
|
|
149
|
+
;
|
|
150
|
+
|
|
151
|
+
if (this._textBox.text()) {
|
|
152
|
+
this._textBox
|
|
153
|
+
.tooltip(this.tooltip())
|
|
154
|
+
.move(this._findMidPoint(points), transitionDuration)
|
|
155
|
+
;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
exit(domNode, element) {
|
|
160
|
+
if (this._textBox) {
|
|
161
|
+
this._textBox.target(null);
|
|
162
|
+
}
|
|
163
|
+
super.exit(domNode, element);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
_findMidPoint(points) {
|
|
167
|
+
const midIdx = points.length / 2;
|
|
168
|
+
if (points.length % 2) {
|
|
169
|
+
return points[Math.floor(midIdx)];
|
|
170
|
+
} else if (points.length) {
|
|
171
|
+
const p0 = points[midIdx - 1];
|
|
172
|
+
const p1 = points[midIdx];
|
|
173
|
+
return { x: (p0.x + p1.x) / 2, y: (p0.y + p1.y) / 2 };
|
|
174
|
+
}
|
|
175
|
+
return { x: 0, y: 0 };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
_calculateEdgePoints(source, target, _points) {
|
|
179
|
+
if (!source || !target) {
|
|
180
|
+
return [{ x: 0, y: 0 }, { x: 0, y: 0 }];
|
|
181
|
+
}
|
|
182
|
+
let points = _points ? _points.filter(p => !source.contains(p) && !target.contains(p)) : [];
|
|
183
|
+
const p0 = points.length === 0 ? target.pos() : points[0];
|
|
184
|
+
const p1 = points.length === 0 ? source.pos() : points[points.length - 1];
|
|
185
|
+
|
|
186
|
+
points.unshift(source.intersection(source._pos, p0));
|
|
187
|
+
points.push(target.intersection(target._pos, p1));
|
|
188
|
+
if (!points[0]) {
|
|
189
|
+
points[0] = source._pos;
|
|
190
|
+
}
|
|
191
|
+
if (!points[points.length - 1]) {
|
|
192
|
+
points[points.length - 1] = target._pos;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if ((!_points || _points.length === 0) && points.length === 2 && points[0] && points[1]) {
|
|
196
|
+
const dx = points[0].x - points[1].x;
|
|
197
|
+
const dy = points[0].y - points[1].y;
|
|
198
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
199
|
+
if (dist) {
|
|
200
|
+
if (this.showArc()) {
|
|
201
|
+
const midX = (points[0].x + points[1].x) / 2 - dy * this.arcDepth() / 100;
|
|
202
|
+
const midY = (points[0].y + points[1].y) / 2 + dx * this.arcDepth() / 100;
|
|
203
|
+
points = [{ x: points[0].x, y: points[0].y }, { x: midX, y: midY }, { x: points[1].x, y: points[1].y }];
|
|
204
|
+
} else {
|
|
205
|
+
points = [{ x: points[0].x, y: points[0].y }, { x: points[1].x, y: points[1].y }];
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return points;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
Edge.prototype._class += " graph_Edge";
|
|
213
|
+
|
|
214
|
+
export interface Edge {
|
|
215
|
+
arcDepth(): number;
|
|
216
|
+
arcDepth(_: number): this;
|
|
217
|
+
showControlPoints(): boolean;
|
|
218
|
+
showControlPoints(_: boolean): this;
|
|
219
|
+
showArc(): boolean;
|
|
220
|
+
showArc(_: boolean): this;
|
|
221
|
+
tooltip(): string;
|
|
222
|
+
tooltip(_: string): this;
|
|
223
|
+
|
|
224
|
+
sourceMarker(): string;
|
|
225
|
+
sourceMarker(_: string): this;
|
|
226
|
+
sourceMarker_exists: () => boolean;
|
|
227
|
+
targetMarker(): string;
|
|
228
|
+
targetMarker(_: string): this;
|
|
229
|
+
targetMarker_exists: () => boolean;
|
|
230
|
+
strokeDasharray(): string;
|
|
231
|
+
strokeDasharray(_: string): this;
|
|
232
|
+
strokeDasharray_exists: () => boolean;
|
|
233
|
+
strokeColor(): string;
|
|
234
|
+
strokeColor(_: string): this;
|
|
235
|
+
strokeColor_exists: () => boolean;
|
|
236
|
+
|
|
237
|
+
text_shape_colorFill(): string;
|
|
238
|
+
text_shape_colorFill(_: string): this;
|
|
239
|
+
text_shape_colorStroke(): string;
|
|
240
|
+
text_shape_colorStroke(_: string): this;
|
|
241
|
+
text_text_colorFill(): string;
|
|
242
|
+
text_text_colorFill(_: string): this;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
Edge.prototype.publish("arcDepth", 16, "number", "Arc Depth", null, { tags: ["Basic"] });
|
|
246
|
+
Edge.prototype.publish("showControlPoints", false, "boolean", "Show/Hide Control Points", null, { tags: ["Basic"] });
|
|
247
|
+
Edge.prototype.publish("showArc", true, "boolean", "Show/Hide Arc", null, { tags: ["Basic"] });
|
|
248
|
+
Edge.prototype.publish("tooltip", "", "string", "Tooltip", null, { tags: ["Private"] });
|
|
249
|
+
|
|
250
|
+
Edge.prototype.publish("sourceMarker", "circle", "set", "Source Marker", ["none", "circle"], { optional: true });
|
|
251
|
+
Edge.prototype.publish("targetMarker", "arrow", "set", "Source Marker", ["none", "arrow", "circle"], { optional: true });
|
|
252
|
+
Edge.prototype.publish("strokeDasharray", null, "string", "Stroke Dash Array", null, { optional: true });
|
|
253
|
+
Edge.prototype.publish("strokeColor", null, "html-color", "Stroke Color", null, { optional: true });
|
|
254
|
+
Edge.prototype.publish("textColor", null, "html-color", "Text Color", null, { optional: true });
|
|
255
|
+
Edge.prototype.publishProxy("text_shape_colorFill", "_textBox", "shape_colorFill");
|
|
256
|
+
Edge.prototype.publishProxy("text_shape_colorStroke", "_textBox", "shape_colorStroke");
|
|
257
|
+
Edge.prototype.publishProxy("text_text_colorFill", "_textBox", "text_colorFill");
|
package/src/Graph.css
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
.graph_Graph .marker {
|
|
2
|
-
fill: #656565;
|
|
3
|
-
stroke: none;
|
|
4
|
-
stroke-width: 1.0px;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
.graph_Graph .zoom {
|
|
8
|
-
fill: none;
|
|
9
|
-
pointer-events: all;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
.graph_Graph .selectionBrush {
|
|
13
|
-
fill: none;
|
|
14
|
-
stroke: darkgray;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.graph_Graph .graphEdge.shortest-path .graph_Edge {
|
|
18
|
-
stroke:red;
|
|
1
|
+
.graph_Graph .marker {
|
|
2
|
+
fill: #656565;
|
|
3
|
+
stroke: none;
|
|
4
|
+
stroke-width: 1.0px;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.graph_Graph .zoom {
|
|
8
|
+
fill: none;
|
|
9
|
+
pointer-events: all;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.graph_Graph .selectionBrush {
|
|
13
|
+
fill: none;
|
|
14
|
+
stroke: darkgray;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.graph_Graph .graphEdge.shortest-path .graph_Edge {
|
|
18
|
+
stroke: red;
|
|
19
19
|
}
|