Skip to content

Commit 15173f9

Browse files
committed
Grid paper.
1 parent fc748a7 commit 15173f9

6 files changed

Lines changed: 91 additions & 22 deletions

File tree

app/GridPaper.svg

Lines changed: 13 additions & 0 deletions
Loading

app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
height: 100%;
1212
padding: 0;
1313
margin: 0;
14-
background-color: #2e2e2e;
14+
background: #2e2e2e url("./GridPaper.svg");
1515
}
1616

1717
.flow-node-title {

app/scripts/core/FlowPortViewModel.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,15 @@ export class FlowPortViewModel implements IFlowPortViewModel {
4747
port:IPort;
4848

4949

50-
constructor(name, portType, viewModel, position) {
51-
this._name = name;
50+
/**
51+
*
52+
* @param propertyName {string} Sets the property name of the {@link IFlowNodeViewModel} which will be used to pass data from the source.
53+
* @param portType {PortType} The port type.
54+
* @param viewModel {IFlowNodeViewModel} The view-model of the node the port belongs to.
55+
* @param position {Point} The position of the port on the shape.
56+
*/
57+
constructor(propertyName, portType, viewModel, position) {
58+
this._name = propertyName;
5259
this._portType = portType;
5360
this._viewModel = viewModel;
5461
this._position = position;

app/scripts/core/Surface.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {ISurface} from './ISurface';
2-
import {BridgeCrossingStyle, BridgeManager, DefaultEdgePathCropper, Fill, GraphComponent, GraphEditorInputMode, GraphItemTypes, GraphObstacleProvider, HierarchicLayout, HierarchicNestingPolicy, IEdge, IGraph, INode, IPort, LayoutExecutor, License, ShapeNodeStyle, Size, TemplateNodeStyle} from 'yfiles';
2+
import {BridgeCrossingStyle, BridgeManager, DefaultEdgePathCropper, Fill, GraphComponent, GraphEditorInputMode, GraphItemTypes, GraphObstacleProvider, HierarchicLayout, HierarchicNestingPolicy, ICanvasObjectDescriptor, IEdge, IGraph, INode, IPort, LayoutExecutor, License, ShapeNodeStyle, Size, TemplateNodeStyle} from 'yfiles';
33
import {IFlowModel} from './IFlowModel';
44
import {IFlowPortViewModel} from './IFlowPortViewModel';
55
import {IFlowNodeModel} from './IFlowNodeModel';
@@ -10,6 +10,7 @@ import IFlowEdgeViewModel from './IFlowEdgeViewModel';
1010
import RoutingEdgeStyle from '../style/EdgeStyle';
1111
import PortCandidateProvider from '../style/PortCandidateProvider';
1212
import * as _ from 'lodash';
13+
import {BackGridStyle} from '../style/BackGridStyle';
1314

1415

1516
/**
@@ -107,6 +108,9 @@ export class Surface implements ISurface {
107108
// crop the edge path at the port and not at the node bounds
108109
DefaultEdgePathCropper.isInstance(this.graph);
109110

111+
// this.graphComponent.backgroundGroup.addChild(new BackGridStyle(),
112+
// ICanvasObjectDescriptor.VISUAL);
113+
110114
const decorator = this.graph.decorator;
111115
const pathCropper = new DefaultEdgePathCropper();
112116
pathCropper.cropAtPort = true;

app/scripts/style/BackGridStyle.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import {HtmlCanvasVisual, IRenderContext, Point} from 'yfiles';
2+
3+
export class BackGridStyle extends HtmlCanvasVisual {
4+
minorTickSpacing: number
5+
minorTickSize: number
6+
private scaleFactor: number;
7+
private majorTickSpacing: number;
8+
private labeledTickSpacing: number;
9+
private tickSpacingFactor: number;
10+
11+
constructor() {
12+
super();
13+
this.scaleFactor = 1;
14+
this.minorTickSpacing = 20;
15+
this.majorTickSpacing = 100;
16+
this.labeledTickSpacing = 200;
17+
this.tickSpacingFactor = 1;
18+
}
19+
20+
paint(renderContext: IRenderContext, ctx: CanvasRenderingContext2D): void {
21+
const canvas = renderContext.canvasComponent;
22+
const viewPoint = canvas.viewPoint;
23+
const viewPort = canvas.viewport;
24+
ctx.translate(viewPoint.x, viewPoint.y);
25+
26+
ctx.strokeStyle = '#000';
27+
ctx.fillStyle = '#000';
28+
29+
ctx.beginPath();
30+
31+
let tickNr = Math.floor(viewPort.x / this.minorTickSpacing);
32+
const worldX = tickNr * this.minorTickSpacing;
33+
let viewX = 0;//canvas.toViewCoordinates(new Point(worldX, 0)).x;
34+
35+
36+
while (viewX <= canvas.size.width + 10) {
37+
38+
39+
40+
if ((tickNr % this.tickSpacingFactor) === 0) {
41+
ctx.moveTo(viewX, 0);
42+
ctx.lineTo(viewX, canvas.size.height);
43+
}
44+
45+
viewX += (this.minorTickSpacing );
46+
}
47+
48+
ctx.stroke();
49+
}
50+
51+
}

app/scripts/style/PortCandidateProvider.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {BaseClass, DefaultPortCandidate, INode, IPortCandidate, IPortCandidateProvider, List, PortCandidateProviderBase} from 'yfiles';
1+
import {BaseClass, DefaultPortCandidate, IEnumerable, IInputModeContext, INode, IPortCandidate, IPortCandidateProvider, List, PortCandidateProviderBase} from 'yfiles';
22
import {FlowPortModel} from './FlowPortModel';
33
import {PortType} from '../core/PortType';
44
import {IFlowPortViewModel} from '../core/IFlowPortViewModel';
@@ -18,19 +18,12 @@ export default class PortCandidateProvider extends PortCandidateProviderBase {
1818
* @returns {IEnumerable.<IPortCandidate>}
1919
*/
2020
getAllSourcePortCandidates(context) {
21-
// create a port candidate at the right side of the node
21+
2222
const candidates = new List<IPortCandidate>();
23-
const found = this.node.ports.filter(p => p.tag && (p.tag as IFlowPortViewModel).portType == PortType.OUTPUT);
24-
if (found.size === 0) {
25-
return candidates;
26-
}
27-
// const defaultPortCandidate: IPortCandidate = new DefaultPortCandidate(
28-
// this.node,
29-
// found.first().locationParameter
30-
// );
31-
// candidates.add(defaultPortCandidate);
23+
// add all
3224
this.addExistingPorts(this.node, candidates);
33-
return candidates
25+
// but keep only the output
26+
return candidates.filter(p => p.port.tag && (p.port.tag as IFlowPortViewModel).portType == PortType.OUTPUT)
3427
}
3528

3629
/**
@@ -40,13 +33,10 @@ export default class PortCandidateProvider extends PortCandidateProviderBase {
4033
*/
4134
getAllTargetPortCandidates(context) {
4235
const candidates = new List<IPortCandidate>();
43-
const found = this.node.ports.filter(p => p.tag && (p.tag as IFlowPortViewModel).portType == PortType.INPUT);
44-
if (found.size === 0) {
45-
return candidates;
46-
}
47-
36+
// add all
4837
this.addExistingPorts(this.node, candidates);
49-
return candidates
38+
// but keep only the output
39+
return candidates.filter(p => p.port.tag && (p.port.tag as IFlowPortViewModel).portType == PortType.INPUT);
5040
}
5141

5242
/**
@@ -66,4 +56,8 @@ export default class PortCandidateProvider extends PortCandidateProviderBase {
6656
getTargetPortCandidates(context, source) {
6757
return this.getAllTargetPortCandidates(context)
6858
}
59+
60+
getPortCandidates(context: IInputModeContext): IEnumerable<IPortCandidate> {
61+
return undefined;
62+
}
6963
}

0 commit comments

Comments
 (0)