Skip to content

Commit

Permalink
docs: Added auto snap example
Browse files Browse the repository at this point in the history
  • Loading branch information
siarheihuzarevich committed Oct 2, 2024
1 parent 015865d commit 7e7e4f5
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 8 deletions.
19 changes: 19 additions & 0 deletions projects/f-examples/connections/auto-snap/auto-snap.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<f-flow fDraggable (fLoaded)="onLoaded()" (fCreateConnection)="addConnection($event)">
<f-canvas>
<f-connection-for-create></f-connection-for-create>
<f-snap-connection [fSnapThreshold]="100"></f-snap-connection>

@for (connection of connections; track connection.inputId) {
<f-connection [fReassignDisabled]="true"
[fOutputId]="connection.outputId" [fInputId]="connection.inputId">
</f-connection>
}

<div fNode fDragHandle [fNodePosition]="{ x: 0, y: 24 }" fNodeOutput fOutputConnectableSide="right">drag me</div>
<div fNode fDragHandle [fNodePosition]="{ x: 300, y: 24 }" fNodeInput fInputConnectableSide="left">to me</div>

</f-canvas>
</f-flow>
<div class="toolbar">
<button class="f-button" (click)="onDeleteConnections()">Delete Connections</button>
</div>
14 changes: 14 additions & 0 deletions projects/f-examples/connections/auto-snap/auto-snap.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@use "../../flow-common";

::ng-deep auto-snap {
@include flow-common.connection;
}

.f-node {
@include flow-common.node;
}

.toolbar {
@include flow-common.toolbar;
}

42 changes: 42 additions & 0 deletions projects/f-examples/connections/auto-snap/auto-snap.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ViewChild } from '@angular/core';
import { FCanvasComponent, FCreateConnectionEvent, FFlowModule } from '@foblex/flow';

@Component({
selector: 'auto-snap',
styleUrls: [ './auto-snap.component.scss' ],
templateUrl: './auto-snap.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
FFlowModule
]
})
export class AutoSnapComponent {

@ViewChild(FCanvasComponent, { static: true })
public fCanvas!: FCanvasComponent;

public connections: { outputId: string, inputId: string }[] = [];

constructor(
private changeDetectorRef: ChangeDetectorRef
) {
}

public addConnection(event: FCreateConnectionEvent): void {
if(!event.fInputId) {
return;
}
this.connections.push({ outputId: event.fOutputId, inputId: event.fInputId });
this.changeDetectorRef.detectChanges();
}

public onLoaded(): void {
this.fCanvas.resetScaleAndCenter(false);
}

public onDeleteConnections(): void {
this.connections = [];
this.changeDetectorRef.detectChanges();
}
}
17 changes: 17 additions & 0 deletions public/markdown/examples/auto-snap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Auto Snap

## Description

This guide shows how to create connections when a connection is dropped near a connector, providing a comprehensive approach to building interactive flow-based diagrams.

## Example

::: ng-component <auto-snap></auto-snap> [height]="600"
[component.html] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/projects/f-examples/connections/auto-snap/auto-snap.component.html
[component.ts] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/projects/f-examples/connections/auto-snap/auto-snap.component.ts
[component.scss] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/projects/f-examples/connections/auto-snap/auto-snap.component.scss
[common.scss] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/projects/f-examples/_flow-common.scss
:::



17 changes: 12 additions & 5 deletions public/markdown/examples/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function createEnvironment(): IDocsEnvironment {
{ tag: 'drag-to-reassign', component: import('../../../projects/f-examples/connections/drag-to-reassign/drag-to-reassign.component') },
{ tag: 'create-node-on-connection-drop', component: import('../../../projects/f-examples/connections/create-node-on-connection-drop/create-node-on-connection-drop.component') },
{ tag: 'remove-connection-on-drop', component: import('../../../projects/f-examples/connections/remove-connection-on-drop/remove-connection-on-drop.component') },
{ tag: 'auto-snap', component: import('../../../projects/f-examples/connections/auto-snap/auto-snap.component') },

{ tag: 'dagre-layout-example', component: import('../../../projects/f-examples/layouts/dagre-layout-example/dagre-layout-example.component') },
{ tag: 'elkjs-layout-example', component: import('../../../projects/f-examples/layouts/elkjs-layout-example/elkjs-layout-example.component') },
Expand Down Expand Up @@ -236,11 +237,17 @@ function connectionGroup(): INavigationGroup {
image_width: 791,
image_height: 600,
image_type: 'image/png',
}
// {
// link: 'proximity-connect',
// text: 'Proximity Connect',
// },
},
{
link: 'auto-snap',
text: 'Auto Snap',
description: 'Discover how to automatically snap connections to nodes. This example demonstrates how to snap connections to nodes automatically, providing a comprehensive guide to building interactive flow-based diagrams.',
image: './previews/examples/auto-snap.light.png',
image_dark: './previews/examples/auto-snap.dark.png',
image_width: 791,
image_height: 600,
image_type: 'image/png',
},
// {
// link: 'connection-types',
// text: 'Connection Types',
Expand Down
Binary file added public/previews/examples/auto-snap.dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/previews/examples/auto-snap.light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<router-outlet></router-outlet>
<!--<button class="take-screenshot" (click)="takeScreenshot()">-->
<!-- Take Screenshot-->
<!--</button>-->
<button class="take-screenshot" (click)="takeScreenshot()">
Take Screenshot
</button>

0 comments on commit 7e7e4f5

Please sign in to comment.