Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 092dc80

Browse files
BoykoAlexghillert
authored andcommitted
gh-865 Specialize "smooth" connectors for horizontal and vertical
* Make adjustments to fitToPage() and layout
1 parent bb832c7 commit 092dc80

File tree

13 files changed

+114
-26
lines changed

13 files changed

+114
-26
lines changed

ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"web-animations-js": "2.3.1",
5050
"stompjs": "2.3.3",
5151
"jshint": "2.9.5",
52-
"spring-flo": "0.8.0",
52+
"spring-flo": "git://github.com/spring-projects/spring-flo#bc0eeb08c0e5121cd62bf2759009f54fe8317379",
5353
"ng-busy": "1.4.4",
5454
"rxjs-compat": "^6.2.1",
5555
"uuid": "3.3.2"
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { dia } from 'jointjs';
2+
import * as _joint from 'jointjs';
3+
const joint: any = _joint;
4+
const g = joint.g;
5+
const V = joint.V;
6+
7+
joint.connectors.smoothHorizontal = function(sourcePoint, targetPoint, route, opt) {
8+
9+
const raw = opt && opt.raw;
10+
let path;
11+
12+
if (route && route.length !== 0) {
13+
14+
const points = [sourcePoint].concat(route).concat([targetPoint]);
15+
const curves = g.Curve.throughPoints(points);
16+
17+
path = new g.Path(curves);
18+
19+
} else {
20+
// if we have no route, use a default cubic bezier curve
21+
// cubic bezier requires two control points
22+
// the control points have `x` midway between source and target
23+
// this produces an S-like curve
24+
25+
path = new g.Path();
26+
27+
let segment;
28+
29+
segment = g.Path.createSegment('M', sourcePoint);
30+
path.appendSegment(segment);
31+
32+
const controlPointX = (sourcePoint.x + targetPoint.x) / 2;
33+
34+
segment = g.Path.createSegment('C', controlPointX, sourcePoint.y, controlPointX, targetPoint.y, targetPoint.x, targetPoint.y);
35+
path.appendSegment(segment);
36+
}
37+
38+
return (raw) ? path : path.serialize();
39+
};
40+
41+
joint.connectors.smoothVertical = function(sourcePoint, targetPoint, route, opt) {
42+
43+
const raw = opt && opt.raw;
44+
let path;
45+
46+
if (route && route.length !== 0) {
47+
48+
const points = [sourcePoint].concat(route).concat([targetPoint]);
49+
const curves = g.Curve.throughPoints(points);
50+
51+
path = new g.Path(curves);
52+
53+
} else {
54+
// if we have no route, use a default cubic bezier curve
55+
// cubic bezier requires two control points
56+
// the control points have `x` midway between source and target
57+
// this produces an S-like curve
58+
59+
path = new g.Path();
60+
61+
let segment;
62+
63+
segment = g.Path.createSegment('M', sourcePoint);
64+
path.appendSegment(segment);
65+
66+
const controlPointY = (sourcePoint.y + targetPoint.y) / 2;
67+
68+
segment = g.Path.createSegment('C', sourcePoint.x, controlPointY, targetPoint.x, controlPointY, targetPoint.x, targetPoint.y);
69+
path.appendSegment(segment);
70+
}
71+
72+
return (raw) ? path : path.serialize();
73+
};
74+
75+
export function centerGraphHorizontallyOnPaper(paper: dia.Paper) {
76+
const currentTranslate = paper.translate();
77+
const box = /*V(paper.viewport).getBBox()*/paper.getContentBBox();
78+
const tx = (paper.$el.innerWidth() - box.width) / 2;
79+
paper.translate(tx, currentTranslate.ty);
80+
}
81+
82+

ui/src/app/streams/components/flo/render.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class RenderService implements Flo.Renderer {
5858
}
5959

6060
initializeNewLink(link: dia.Link, viewerDescriptor: Flo.ViewerDescriptor) {
61-
link.set('smooth', true);
61+
link.set('connector/name', 'smoothHorizontal');
6262
link.attr('metadata/metadata/unselectable', true);
6363
}
6464

ui/src/app/streams/components/flo/support/layout.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function layout(paper: dia.Paper) {
77

88
let gridSize = paper.options.gridSize;
99
if (gridSize <= 1) {
10-
gridSize = IMAGE_H;
10+
gridSize = IMAGE_H / 2;
1111
}
1212

1313
const g = new dagre.graphlib.Graph();
@@ -25,8 +25,6 @@ export function layout(paper: dia.Paper) {
2525
});
2626

2727
g.graph().rankdir = 'LR';
28-
g.graph().marginx = gridSize;
29-
g.graph().marginy = gridSize;
3028
g.graph().nodesep = 2 * gridSize;
3129
g.graph().ranksep = 2 * gridSize;
3230
g.graph().edgesep = gridSize;

ui/src/app/streams/components/flo/support/shapes.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const joint: any = _joint;
33

44
// Load changes into joint object
55
import 'spring-flo';
6+
import '../../../../shared/flo/support/shared-shapes';
67

78
export const IMAGE_W = 120;
89
export const IMAGE_H = 40;
@@ -221,8 +222,10 @@ joint.shapes.flo.LinkDataflow = joint.dia.Link.extend({
221222
options: {
222223
linkToolsOffset: 1000,
223224
},
224-
smooth: true,
225-
// router: { name: 'metro' },
225+
connector: {
226+
name: 'smoothHorizontal'
227+
},
228+
// router: { name: 'metro' },
226229
attrs: {
227230
'.connection': { stroke: '#34302d', 'stroke-width': 2 },
228231
'.connection-wrap': { display: 'none' },
@@ -269,3 +272,5 @@ joint.shapes.flo.InstanceDot = joint.shapes.basic.Generic.extend({
269272

270273

271274

275+
276+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<app-graph-view [dsl]="dsl" [ngClass]="status ? status : 'undeployed'" (floApi)="setEditorContext($event)" [metamodel]="metamodel" [renderer]="renderer"></app-graph-view>
1+
<app-graph-view [dsl]="dsl" [ngClass]="status ? status : 'undeployed'" (floApi)="setEditorContext($event)" [metamodel]="metamodel" [renderer]="renderer" [paperPadding]="40"></app-graph-view>

ui/src/app/streams/stream-create/stream-create.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ <h1 class="no-user-selection">Create a stream</h1>
99

1010
<div id="flo-container" class="stream-editor">
1111
<flo-editor (floApi)="setEditorContext($event)" [metamodel]="metamodelService" [renderer]="renderService"
12-
[editor]="editorService" [paletteSize]="paletteSize" [(dsl)]="dsl" [paperPadding]="20"
12+
[editor]="editorService" [paletteSize]="paletteSize" [(dsl)]="dsl" [paperPadding]="40"
1313
(contentValidated)="contentValidated=$event" (validationMarkers)="validationMarkers = $event">
1414

1515
<button (click)="createStreamDefs()" class="btn btn-default" type="button" [disabled]="isCreateStreamsDisabled">Create Stream</button>

ui/src/app/streams/stream/graph/stream-graph.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div>
22

3-
<app-graph-view [dsl]="dsl" [paperPadding]="20" class="stream-details"
3+
<app-graph-view [dsl]="dsl" [paperPadding]="40" class="stream-details"
44
[metamodel]="metamodelService"
55
[renderer]="renderService">
66
</app-graph-view>

ui/src/app/tasks/components/flo/editor.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as _joint from 'jointjs';
77
import { TaskPropertiesDialogComponent } from './properties/task-properties-dialog-component';
88
import { TaskGraphPropertiesSource } from './properties/task-properties-source';
99
import { Utils} from '../../../shared/flo/support/utils';
10+
import { arrangeAll } from './support/layout';
1011

1112
const joint: any = _joint;
1213

@@ -75,7 +76,7 @@ export class EditorService implements Flo.Editor {
7576
editorContext.getGraph().clear();
7677
editorContext.createNode(data.get(CONTROL_GROUP_TYPE).get(START_NODE_TYPE));
7778
editorContext.createNode(data.get(CONTROL_GROUP_TYPE).get(END_NODE_TYPE));
78-
editorContext.performLayout();
79+
arrangeAll(editorContext);
7980
}
8081

8182
validateLink(flo: Flo.EditorContext, cellViewS: dia.ElementView, magnetS: SVGElement, cellViewT: dia.ElementView,

ui/src/app/tasks/components/flo/metamodel.service.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { AppMetadata } from '../../../shared/flo/support/app-metadata';
99

1010
import * as _joint from 'jointjs';
1111
import { LoggerService } from '../../../shared/services/logger.service';
12+
import { arrangeAll } from './support/layout';
1213

1314
const joint: any = _joint;
1415

@@ -302,16 +303,7 @@ export class MetamodelService implements Flo.Metamodel {
302303
flo.performLayout();
303304

304305
// Graph is empty? Ensure there are at least start and end nodes created!
305-
const promise = nodesIndex.length ? flo.performLayout() : flo.clearGraph();
306-
307-
if (promise && promise.then && promise.then.call) {
308-
promise.then(function () {
309-
flo.fitToPage();
310-
});
311-
} else {
312-
flo.fitToPage();
313-
}
314-
306+
nodesIndex.length ? arrangeAll(flo) : flo.clearGraph();
315307
}
316308

317309
clearCachedData() {

0 commit comments

Comments
 (0)