-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Added connection type and custom connection type examples
- Loading branch information
1 parent
7e7e4f5
commit eb248c0
Showing
14 changed files
with
217 additions
and
5 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
projects/f-examples/connections/connection-types/connection-types.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<f-flow fDraggable (fLoaded)="onLoaded()"> | ||
<f-canvas> | ||
<f-connection [fReassignDisabled]="true" fType="straight" fOutputId="1" fInputId="2"> | ||
</f-connection> | ||
<div fNode fDragHandle [fNodePosition]="{ x: 0, y: 0 }" fNodeOutput fOutputId="1" fOutputConnectableSide="right"> | ||
I'm a node | ||
</div> | ||
<div fNode fDragHandle [fNodePosition]="{ x: 200, y: 50 }" fNodeInput fInputId="2" fInputConnectableSide="left"> | ||
I'm a node | ||
</div> | ||
|
||
<f-connection [fReassignDisabled]="true" fType="segment" fOutputId="3" fInputId="4"> | ||
</f-connection> | ||
<div fNode fDragHandle [fNodePosition]="{ x: 0, y: 150 }" fNodeOutput fOutputId="3" fOutputConnectableSide="right"> | ||
I'm a node | ||
</div> | ||
<div fNode fDragHandle [fNodePosition]="{ x: 200, y: 200 }" fNodeInput fInputId="4" fInputConnectableSide="left"> | ||
I'm a node | ||
</div> | ||
|
||
<f-connection [fReassignDisabled]="true" fType="bezier" fOutputId="5" fInputId="6"> | ||
</f-connection> | ||
<div fNode fDragHandle [fNodePosition]="{ x: 0, y: 300 }" fNodeOutput fOutputId="5" fOutputConnectableSide="right"> | ||
I'm a node | ||
</div> | ||
<div fNode fDragHandle [fNodePosition]="{ x: 200, y: 350 }" fNodeInput fInputId="6" fInputConnectableSide="left"> | ||
I'm a node | ||
</div> | ||
</f-canvas> | ||
</f-flow> |
9 changes: 9 additions & 0 deletions
9
projects/f-examples/connections/connection-types/connection-types.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@use "../../flow-common"; | ||
|
||
::ng-deep connection-types { | ||
@include flow-common.connection; | ||
} | ||
|
||
.f-node { | ||
@include flow-common.node; | ||
} |
22 changes: 22 additions & 0 deletions
22
projects/f-examples/connections/connection-types/connection-types.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ChangeDetectionStrategy, Component, ViewChild } from '@angular/core'; | ||
import { FCanvasComponent, FFlowModule } from '@foblex/flow'; | ||
|
||
@Component({ | ||
selector: 'connection-types', | ||
styleUrls: [ './connection-types.component.scss' ], | ||
templateUrl: './connection-types.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
standalone: true, | ||
imports: [ | ||
FFlowModule | ||
] | ||
}) | ||
export class ConnectionTypesComponent { | ||
|
||
@ViewChild(FCanvasComponent, { static: true }) | ||
public fCanvas!: FCanvasComponent; | ||
|
||
public onLoaded(): void { | ||
this.fCanvas.resetScaleAndCenter(false); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
projects/f-examples/connections/custom-connection-type/custom-connection-type.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<f-flow fDraggable (fLoaded)="onLoaded()"> | ||
<f-canvas> | ||
<f-connection [fReassignDisabled]="true" fType="offset_straight" fOutputId="1" fInputId="2"> | ||
</f-connection> | ||
<div fNode fDragHandle [fNodePosition]="{ x: 0, y: 0 }" fNodeOutput fOutputId="1" fOutputConnectableSide="right"> | ||
I'm a node | ||
</div> | ||
<div fNode fDragHandle [fNodePosition]="{ x: 200, y: 50 }" fNodeInput fInputId="2" fInputConnectableSide="left"> | ||
I'm a node | ||
</div> | ||
|
||
<f-connection [fReassignDisabled]="true" fType="circle" fOutputId="3" fInputId="4"> | ||
</f-connection> | ||
<div fNode fDragHandle [fNodePosition]="{ x: 0, y: 150 }" fNodeOutput fOutputId="3" fOutputConnectableSide="right"> | ||
I'm a node | ||
</div> | ||
<div fNode fDragHandle [fNodePosition]="{ x: 200, y: 200 }" fNodeInput fInputId="4" fInputConnectableSide="left"> | ||
I'm a node | ||
</div> | ||
</f-canvas> | ||
</f-flow> |
10 changes: 10 additions & 0 deletions
10
projects/f-examples/connections/custom-connection-type/custom-connection-type.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@use "../../flow-common"; | ||
|
||
::ng-deep custom-connection-type { | ||
@include flow-common.connection; | ||
} | ||
|
||
.f-node { | ||
@include flow-common.node; | ||
} | ||
|
68 changes: 68 additions & 0 deletions
68
projects/f-examples/connections/custom-connection-type/custom-connection-type.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { ChangeDetectionStrategy, Component, ViewChild } from '@angular/core'; | ||
import { | ||
F_CONNECTION_BUILDERS, | ||
FCanvasComponent, | ||
FFlowModule, | ||
IFConnectionBuilder, | ||
IFConnectionBuilderRequest, | ||
IFConnectionBuilderResponse | ||
} from '@foblex/flow'; | ||
import { IPoint, PointExtensions } from '@foblex/2d'; | ||
|
||
class OffsetStraightBuilder implements IFConnectionBuilder { | ||
|
||
public handle(request: IFConnectionBuilderRequest): IFConnectionBuilderResponse { | ||
const { source, target } = request; | ||
const path = `M ${ source.x } ${ source.y } L ${ source.x + 20 } ${ source.y } L ${ target.x - 20 } ${ target.y } L ${ target.x } ${ target.y }`; | ||
|
||
return { path, connectionCenter: { x: 0, y: 0 }, penultimatePoint: PointExtensions.initialize(target.x - 20, target.y) }; | ||
} | ||
} | ||
|
||
class CircleConnectionBuilder implements IFConnectionBuilder { | ||
|
||
public handle(request: IFConnectionBuilderRequest): IFConnectionBuilderResponse { | ||
const { source, target } = request; | ||
const d = this.getD(request); | ||
const path = `M ${ source.x } ${ source.y } S${ d.x } ${ d.y } ${ target.x } ${ target.y }`; | ||
return { path, connectionCenter: { x: 0, y: 0 }, penultimatePoint: d }; | ||
} | ||
|
||
private getD(request: IFConnectionBuilderRequest): IPoint { | ||
const offset: number = request.offset; | ||
const cx: number = (request.source.x + request.radius + request.target.x) / 2; | ||
const cy: number = (request.source.y + request.radius + request.target.y) / 2; | ||
const dx: number = cx + (offset * (request.source.y - request.target.y)) / Math.sqrt(Math.pow(request.source.x - request.target.x, 2) + Math.pow(request.source.y - request.target.y, 2)) || cx; | ||
const dy: number = cy - (offset * (request.source.x - request.target.x)) / Math.sqrt(Math.pow(request.source.x - request.target.x, 2) + Math.pow(request.source.y - request.target.y, 2)) || cy; | ||
|
||
return { x: dx, y: dy }; | ||
} | ||
} | ||
|
||
const connectionBuilders = { | ||
[ 'offset_straight' ]: new OffsetStraightBuilder(), | ||
[ 'circle' ]: new CircleConnectionBuilder() | ||
}; | ||
|
||
@Component({ | ||
selector: 'custom-connection-type', | ||
styleUrls: [ './custom-connection-type.component.scss' ], | ||
templateUrl: './custom-connection-type.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
standalone: true, | ||
providers: [ | ||
{ provide: F_CONNECTION_BUILDERS, useValue: connectionBuilders } | ||
], | ||
imports: [ | ||
FFlowModule | ||
] | ||
}) | ||
export class CustomConnectionTypeComponent { | ||
|
||
@ViewChild(FCanvasComponent, { static: true }) | ||
public fCanvas!: FCanvasComponent; | ||
|
||
public onLoaded(): void { | ||
this.fCanvas.resetScaleAndCenter(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Connection Types | ||
|
||
## Description | ||
|
||
This guide shows how to set up different connection types, allowing for different types of connections to be made between connectors. | ||
|
||
## Example | ||
|
||
::: ng-component <connection-types></connection-types> [height]="600" | ||
[component.html] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/projects/f-examples/connections/connection-types/connection-types.component.html | ||
[component.ts] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/projects/f-examples/connections/connection-types/connection-types.component.ts | ||
[component.scss] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/projects/f-examples/connections/connection-types/connection-types.component.scss | ||
[common.scss] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/projects/f-examples/_flow-common.scss | ||
::: | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Custom Connection Type | ||
|
||
## Description | ||
|
||
This guide shows how to create a custom connection type, allowing for a custom connection style to be applied to connections between connectors. | ||
|
||
## Example | ||
|
||
::: ng-component <custom-connection-type></custom-connection-type> [height]="600" | ||
[component.html] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/projects/f-examples/connections/custom-connection-type/custom-connection-type.component.html | ||
[component.ts] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/projects/f-examples/connections/custom-connection-type/custom-connection-type.component.ts | ||
[component.scss] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/projects/f-examples/connections/custom-connection-type/custom-connection-type.component.scss | ||
[common.scss] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/projects/f-examples/_flow-common.scss | ||
::: | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.