Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
import { DiagramComponent } from './diagram.component';
---

<DiagramComponent client:only="angular" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
:host {
flex: 1;
display: flex;
}

.diagram {
flex: 1;
display: flex;
height: 20rem;
font-family: 'Poppins', sans-serif;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import '@angular/compiler';
import { Component } from '@angular/core';
import {
initializeModel,
NgDiagramComponent,
NgDiagramNodeTemplateMap,
provideNgDiagram,
type NgDiagramConfig,
} from 'ng-diagram';

import { NodeComponent } from './node/node.component';

enum NodeTemplateType {
CustomNodeType = 'customNodeType',
}

@Component({
imports: [NgDiagramComponent],
providers: [provideNgDiagram()],
template: `
<div class="not-content diagram">
<ng-diagram
[model]="model"
[config]="config"
[nodeTemplateMap]="nodeTemplateMap"
/>
</div>
`,
styleUrl: './diagram.component.scss',
})
export class DiagramComponent {
nodeTemplateMap = new NgDiagramNodeTemplateMap([
[NodeTemplateType.CustomNodeType, NodeComponent],
]);

config = {
zoom: {
max: 3,
},
} satisfies NgDiagramConfig;

model = initializeModel({
nodes: [
{
id: '1',
position: { x: 50, y: 20 },
type: 'customNodeType',
data: {
name: 'Node 1',
description:
'This is Node 1. This node is a custom node with a custom template.',
tooltip: 'Node 1 is a custom node',
status: 'Active',
},
},
{
id: '2',
position: { x: 400, y: 20 },
type: 'customNodeType',
data: {
name: 'Node 2',
description:
'This is Node 2. Initial status is red. This node is a custom node with a custom template.',
tooltip: 'Node 2 is a custom node',
status: 'Error',
},
},
],
edges: [],
metadata: { viewport: { x: 0, y: 0, scale: 1 } },
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<div class="node">
<div class="node-header">
<div>
{{ node().data.name }}
</div>
<div>
<mat-chip [style.backgroundColor]="nodeStatus()">
{{ this.node().data.status }}
</mat-chip>
</div>
</div>
<div class="node-body" title="{{ node().data.tooltip }}">
<mat-accordion>
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>Description</mat-panel-title>
</mat-expansion-panel-header>
<p>{{ node().data.description }}</p>
</mat-expansion-panel>
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>Options</mat-panel-title>
</mat-expansion-panel-header>
<form>
<mat-form-field>
<mat-select
(selectionChange)="onColorChange($event)"
[value]="this.node().data.status"
name="status"
>
<mat-option value="Active">Active</mat-option>
<mat-option value="Inactive">Inactive</mat-option>
<mat-option value="Error">Error</mat-option>
</mat-select>
</mat-form-field>
</form>
</mat-expansion-panel>
</mat-accordion>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
:host {
display: flex;
width: 100%;
height: 100%;
border-radius: 10px;
border: 1px solid var(--ngd-node-stroke-primary-default);
background-color: var(--ngd-node-bg-primary-default);

.node {
display: flex;
flex-direction: column;
padding: 12px;
border-radius: 10px;

&-header {
font-weight: bold;
margin-bottom: 10px;
display: flex;
justify-content: space-between;
vertical-align: middle;
align-items: center;
justify-items: center;

.mat-mdc-chip {
--mdc-chip-label-text-color: white !important;
}
}

&-body {
font-size: 12px;
cursor: help;

p {
width: 180px;
}

.mat-expansion-panel {
--mat-expansion-container-background-color: var(
--ngd-node-stroke-primary-default
);
--mat-expansion-header-text-color: var(--ngd-txt-primary-default);
--mat-expansion-container-text-color: var(--ngd-txt-primary-default);
--mat-expansion-header-indicator-color: var(--ngd-txt-primary-default);
}

form {
height: 50px;
margin-top: 8px;

.mat-mdc-form-field {
min-width: 120px;
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Component, computed, inject, input, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MatChipsModule } from '@angular/material/chips';
import { MatExpansionModule } from '@angular/material/expansion';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import {
NgDiagramModelService,
NgDiagramNodeRotateAdornmentComponent,
NgDiagramNodeSelectedDirective,
type NgDiagramNodeTemplate,
type Node,
} from 'ng-diagram';

export type NodeData = {
name: string;
status: string;
description: string;
tooltip: string;
};

@Component({
selector: 'node',
imports: [
NgDiagramNodeRotateAdornmentComponent,
MatSelectModule,
MatFormFieldModule,
FormsModule,
MatInputModule,
MatChipsModule,
MatExpansionModule,
],
hostDirectives: [
{ directive: NgDiagramNodeSelectedDirective, inputs: ['node'] },
],
templateUrl: './node.component.html',
styleUrls: ['./node.component.scss'],
})
export class NodeComponent implements NgDiagramNodeTemplate<NodeData> {
private readonly modelService = inject(NgDiagramModelService);
readonly panelOpenState = signal(false);
node = input.required<Node<NodeData>>();
nodeStatus = computed(() =>
this.node().data.status === 'Active'
? 'green'
: this.node().data.status === 'Error'
? 'red'
: 'orange'
);

onColorChange({ value }: any) {
this.modelService.updateNodeData(this.node().id, {
...this.node().data,
status: value,
});
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { Component, inject, input, model } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MatChipsModule } from '@angular/material/chips';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import {
NgDiagramNodeSelectedDirective,
NgDiagramPortComponent,
Expand All @@ -16,14 +11,7 @@ import { ContextMenuService } from '../menu/menu.service';

@Component({
selector: 'node',
imports: [
NgDiagramPortComponent,
MatSelectModule,
MatFormFieldModule,
FormsModule,
MatInputModule,
MatChipsModule,
],
imports: [NgDiagramPortComponent],
templateUrl: './node.component.html',
styleUrls: ['./node.component.scss'],
hostDirectives: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,33 @@
{{ node().data.name }}
</div>
<div>
<mat-chip>{{ selectedState }}</mat-chip>
<span
class="chip"
[style.backgroundColor]="
selectedState === 'Active'
? 'green'
: selectedState === 'Error'
? 'red'
: 'gray'
"
>{{ selectedState }}</span
>
</div>
</div>
<div class="node-body" title="{{ node().data.tooltip }}">
{{ node().data.description }}
<form>
<mat-form-field>
<mat-select [(ngModel)]="selectedState" name="state">
<mat-option value="Active">Active</mat-option>
<mat-option value="Inactive">Inactive</mat-option>
<mat-option value="Error">Error</mat-option>
</mat-select>
</mat-form-field>
<label for="state-select">State:</label>
<select
id="state-select"
[value]="selectedState"
name="state"
(change)="onStateChange($event)"
>
<option value="Active">Active</option>
<option value="Inactive">Inactive</option>
<option value="Error">Error</option>
</select>
</form>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@
align-items: center;
justify-items: center;

.mat-mdc-chip {
.chip {
display: inline-block;
font-size: 11px;
height: 20px;
padding: 0 8px;
border-radius: 10px;
color: white;
margin-bottom: 10px;
line-height: 20px;
}
}

Expand All @@ -40,23 +45,15 @@
height: 50px;
margin-top: 8px;

.mat-mdc-form-field {
select {
min-width: 120px;
padding: 4px 8px;
border-radius: 4px;
border: 1px solid #ccc;
font-size: 12px;
margin-left: 10px;
}
}
}

&-button {
margin-top: 8px;
padding: 4px 8px;
font-size: 12px;
border: 1px solid var(--ngd-node-stroke-primary-default);
border-radius: 4px;
cursor: pointer;

&:hover {
border-color: var(--ngd-node-stroke-primary-hover);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { Component, input, model } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MatChipsModule } from '@angular/material/chips';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import {
NgDiagramNodeResizeAdornmentComponent,
NgDiagramNodeRotateAdornmentComponent,
Expand All @@ -19,11 +14,6 @@ import {
NgDiagramNodeRotateAdornmentComponent,
NgDiagramPortComponent,
NgDiagramNodeResizeAdornmentComponent,
MatSelectModule,
MatFormFieldModule,
FormsModule,
MatInputModule,
MatChipsModule,
],
templateUrl: './node.component.html',
styleUrls: ['./node.component.scss'],
Expand All @@ -38,5 +28,10 @@ export class NodeComponent implements NgDiagramNodeTemplate {
text = model<string>('');
node = input.required<Node>();

selectedState: string = 'Active';
selectedState: string = 'Inactive';

onStateChange(event: Event) {
const selectElement = event.target as HTMLSelectElement;
this.selectedState = selectElement.value;
}
}
Loading