Skip to content

Commit 87dac20

Browse files
Merge pull request #3 from serhiipylypchuk1991/sp-refactor
[dev] refactoring
2 parents a6b773b + 389b35b commit 87dac20

14 files changed

+181
-151
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![dhtmlx.com](https://img.shields.io/badge/made%20by-DHTMLX-blue)](https://dhtmlx.com/)
44

5-
![DHTMLX Diagram with Angular Demo](https://raw.githubusercontent.com/DHTMLX/angular-diagram-demo/master/diagram.png)
5+
![DHTMLX Diagram with Angular Demo](diagram_editor.png)
66

77
## How to start
88

diagram_editor.png

451 KB
Loading

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@angular/platform-browser": "^16.0.0",
2020
"@angular/platform-browser-dynamic": "^16.0.0",
2121
"@angular/router": "^16.0.0",
22-
"@dhx/trial-diagram": "^6.0.1",
22+
"@dhx/trial-diagram": "^6.0.5",
2323
"rxjs": "~7.8.0",
2424
"tslib": "^2.3.0",
2525
"zone.js": "~0.13.0"

src/app/app.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { Component } from "@angular/core";
22

33
@Component({
44
selector: "app-root",
5-
template: `<diagram />`,
5+
template: `<diagram-editor />`,
66
})
7+
78
export class AppComponent {
89
name = "";
910
}

src/app/app.module.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import { NgModule } from "@angular/core";
22
import { BrowserModule } from "@angular/platform-browser";
33

44
import { AppComponent } from "./app.component";
5-
import { DiagramComponent } from "./diagram/diagram.component";
5+
import { DiagramEditorComponent } from "./diagram-editor/diagram-editor.component";
66

77
@NgModule({
8-
declarations: [AppComponent, DiagramComponent],
8+
declarations: [AppComponent, DiagramEditorComponent],
99
imports: [BrowserModule],
10-
providers: [],
1110
bootstrap: [AppComponent],
1211
})
1312
export class AppModule {}

src/app/diagram-editor/data.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
export function getData() {
2+
return [
3+
{ id: 1, x: 880, y: 105, text: "Does user remember his password?", type: "process", lineHeight: 18, fontColor: "#fff", fill: "#3DA0E3", stroke: "#3DA0E3" },
4+
{ id: 2, x: 1080, y: 125, width: 50, "height": 50, text: "XOR", type: "circle", lineHeight: 18, fontColor: "#fff", fill: "#7D8495", stroke: "#7D8495" },
5+
{ id: 3, x: 1160, y: 40, text: "User forgets his password", type: "preparation", lineHeight: 18, fontColor: "#fff", fill: "#33B579", stroke: "#33B579" },
6+
{ id: 3.1, x: 1340, y: 40, text: "Send an E-mail with new password", type: "process", lineHeight: 18, fontColor: "#fff", fill: "#3DA0E3", stroke: "#3DA0E3" },
7+
{ id: 3.2, x: 1520, y: 40, text: "E-mail sent", type: "preparation", fontColor: "#fff", lineHeight: 18, fill: "#33B579", stroke: "#33B579" },
8+
{ id: 4, x: 1160, y: 180, text: "User remembers his password", type: "preparation", lineHeight: 18, fontColor: "#fff", fill: "#33B579", stroke: "#33B579" },
9+
{ id: 5, x: 1340, y: 180, text: "User types in login and password", type: "process", lineHeight: 18, fontColor: "#fff", fill: "#3DA0E3", stroke: "#3DA0E3" },
10+
{ id: 6, x: 1520, y: 180, text: "Data typed in", type: "preparation", fontColor: "#fff", lineHeight: 18, fill: "#33B579", stroke: "#33B579" },
11+
{ id: 7, x: 1700, y: 180, text: "Proof completion \n and correctness", type: "process", lineHeight: 18, fontColor: "#fff", fill: "#3DA0E3", stroke: "#3DA0E3" },
12+
{ id: 7.1, x: 1745, y: 600, width: 50, "height": 50, text: "XOR", type: "circle", lineHeight: 18, fontColor: "#fff", fill: "#7D8495", stroke: "#7D8495" },
13+
{ id: 7.2, x: 1880, y: 320, text: "User logged in", type: "preparation", lineHeight: 18, fontColor: "#fff", fill: "#33B579", stroke: "#33B579" },
14+
{ id: 7.3, x: 1880, y: 450, text: "Complete logging in", type: "process", lineHeight: 18, fontColor: "#fff", fill: "#3DA0E3", stroke: "#3DA0E3" },
15+
{ id: 7.4, x: 1880, y: 580, text: "Data is correct", type: "preparation", lineHeight: 18, fontColor: "#fff", fill: "#33B579", stroke: "#33B579" },
16+
{ id: 7.5, x: 1530, y: 580, text: "Data is not correct", type: "preparation", lineHeight: 18, fontColor: "#fff", fill: "#33B579", stroke: "#33B579" },
17+
{ id: 8, x: 1700, y: 40, text: "System", type: "subroutine", fontColor: "#fff", lineHeight: 18, fill: "#7E6BAD", stroke: "#7E6BAD" },
18+
{ id: 9, x: 1880, y: 180, text: "Database", type: "database", fontColor: "#fff", lineHeight: 18, fill: "#7E6BAD", stroke: "#7E6BAD" },
19+
{ id: 10, x: 0, y: 220, text: "Visitor enters the website", type: "preparation", lineHeight: 18, fontColor: "#fff", fill: "#33B579", stroke: "#33B579" },
20+
{ id: 11, x: 180, y: 220, text: "Logged in user?", type: "process", lineHeight: 18, fontColor: "#fff", fill: "#3DA0E3", stroke: "#3DA0E3" },
21+
{ id: 12, x: 365, y: 240, width: 50, "height": 50, text: "XOR", type: "circle", lineHeight: 18, fontColor: "#fff", fill: "#7D8495", stroke: "#7D8495" },
22+
{ id: 13, x: 320, y: 120, text: "User is logged in", type: "preparation", lineHeight: 18, fontColor: "#fff", fill: "#33B579", stroke: "#33B579" },
23+
{ id: 14, x: 320, y: 320, text: "User is not logged in", type: "preparation", lineHeight: 18, fontColor: "#fff", fill: "#33B579", stroke: "#33B579" },
24+
{ id: 15, x: 490, y: 320, text: "Registered user?", type: "process", lineHeight: 18, fontColor: "#fff", fill: "#3DA0E3", stroke: "#3DA0E3" },
25+
{ id: 16, x: 660, y: 340, width: 50, "height": 50, text: "XOR", type: "circle", lineHeight: 18, fontColor: "#fff", fill: "#7D8495", stroke: "#7D8495" },
26+
{ id: 17, x: 730, y: 240, text: "User is registered", type: "preparation", lineHeight: 18, fontColor: "#fff", fill: "#33B579", stroke: "#33B579" },
27+
{ id: 18, x: 730, y: 400, text: "User is not registered", type: "preparation", lineHeight: 18, fontColor: "#fff", fill: "#33B579", stroke: "#33B579" },
28+
{ id: 19, x: 905, y: 420, width: 50, "height": 50, text: "XOR", type: "circle", lineHeight: 18, fontColor: "#fff", fill: "#7D8495", stroke: "#7D8495" },
29+
{ id: 20, x: 860, y: 510, text: "User types in needed data", type: "process", lineHeight: 18, fontColor: "#fff", fill: "#3DA0E3", stroke: "#3DA0E3" },
30+
{ id: 21, x: 860, y: 640, text: "Data typed in", type: "preparation", lineHeight: 18, fontColor: "#fff", fill: "#33B579", stroke: "#33B579" },
31+
{ id: 22, x: 860, y: 770, text: "Proof completion \n and correctness", type: "process", lineHeight: 18, fontColor: "#fff", fill: "#3DA0E3", stroke: "#3DA0E3" },
32+
{ id: 23, x: 700, y: 770, text: "System", type: "subroutine", lineHeight: 18, fontColor: "#fff", fill: "#7E6BAD", stroke: "#7E6BAD" },
33+
{ id: 24, x: 860, y: 890, text: "Database", type: "database", lineHeight: 18, fontColor: "#fff", fill: "#7E6BAD", stroke: "#7E6BAD" },
34+
{ id: 25, x: 1065, y: 790, width: 50, "height": 50, text: "XOR", type: "circle", lineHeight: 18, fontColor: "#fff", fill: "#7D8495", stroke: "#7D8495" },
35+
{ id: 26, x: 1020, y: 640, text: "Data is not correct", type: "preparation", lineHeight: 18, fontColor: "#fff", fill: "#33B579", stroke: "#33B579" },
36+
{ id: 27, x: 1020, y: 890, text: "Data is correct", type: "preparation", lineHeight: 18, fontColor: "#fff", fill: "#33B579", stroke: "#33B579" },
37+
{ id: 28, x: 1245, y: 910, width: 50, "height": 50, text: "AND", type: "circle", lineHeight: 18, fontColor: "#fff", fill: "#7D8495", stroke: "#7D8495" },
38+
{ id: 29, x: 1200, y: 770, text: "Write account data into database", type: "process", lineHeight: 18, fontColor: "#fff", fill: "#3DA0E3", stroke: "#3DA0E3" },
39+
{ id: 29.1, x: 1380, y: 770, text: "Data writing done", type: "preparation", lineHeight: 18, fontColor: "#fff", fill: "#33B579", stroke: "#33B579" },
40+
{ id: 29.2, x: 1200, y: 640, text: "Database", type: "database", lineHeight: 18, fontColor: "#fff", fill: "#7E6BAD", stroke: "#7E6BAD" },
41+
{ id: 30, x: 1330, y: 890, text: "Send activation \n e-mail", type: "process", lineHeight: 18, fontColor: "#fff", fill: "#3DA0E3", stroke: "#3DA0E3" },
42+
{ id: 31, x: 1510, y: 890, text: "Activation e-mail sent", type: "preparation", lineHeight: 18, fontColor: "#fff", fill: "#33B579", stroke: "#33B579" },
43+
{ id: 32, x: 1690, y: 890, text: "User activates his account", type: "process", lineHeight: 18, fontColor: "#fff", fill: "#3DA0E3", stroke: "#3DA0E3" },
44+
{ id: 33, x: 1870, y: 889, text: "Account activated", type: "preparation", lineHeight: 18, fontColor: "#fff", fill: "#33B579", stroke: "#33B579" },
45+
46+
{ from: 1, to: 2, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
47+
{ from: 2, to: 3, type: "dash", toSide: "bottom", forwardArrow: "filled", stroke: "#7D8495" },
48+
{ from: 2, to: 7.5, type: "dash", fromSide: "bottom", toSide: "top", backArrow: "filled", stroke: "#7D8495" },
49+
{ from: 2, to: 3.2, type: "dash", fromSide: "top", toSide: "top", stroke: "#7D8495" },
50+
{ from: 3, to: 3.1, type: "line", forwardArrow: "filled", stroke: "#7D8495" },
51+
{ from: 3.1, to: 3.2, type: "line", forwardArrow: "filled", stroke: "#7D8495" },
52+
{ from: 2, to: 4, type: "dash", toSide: "top", forwardArrow: "filled", stroke: "#7D8495" },
53+
{ from: 4, to: 5, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
54+
{ from: 5, to: 6, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
55+
{ from: 6, to: 7, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
56+
{ from: 7, to: 7.1, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
57+
{ from: 7.1, to: 7.4, type: "dash", toSide: "left", stroke: "#7D8495" },
58+
{ from: 7.1, to: 7.5, type: "dash", toSide: "right", stroke: "#7D8495" },
59+
{ from: 7.2, to: 7.3, type: "dash", backArrow: "filled", stroke: "#7D8495" },
60+
{ from: 7.3, to: 7.4, type: "dash", backArrow: "filled", stroke: "#7D8495" },
61+
{ from: 7, to: 8, type: "dash", toSide: "bottom", forwardArrow: "filled", stroke: "#7D8495" },
62+
{ from: 7, to: 9, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
63+
{ from: 10, to: 11, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
64+
{ from: 11, to: 12, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
65+
{ from: 12, to: 13, type: "dash", forwardArrow: "filled", toSide: "bottom", stroke: "#7D8495" },
66+
{ from: 12, to: 14, type: "dash", forwardArrow: "filled", toSide: "top", stroke: "#7D8495" },
67+
{ from: 14, to: 15, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
68+
{ from: 15, to: 16, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
69+
{ from: 16, to: 17, type: "dash", forwardArrow: "filled", toSide: "bottom", stroke: "#7D8495" },
70+
{ from: 16, to: 33, type: "dash", backArrow: "filled", fromSide: "bottom", toSide: "bottom", stroke: "#7D8495" },
71+
{ from: 17, to: 1, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
72+
{ from: 17, to: 18, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
73+
{ from: 18, to: 19, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
74+
{ from: 19, to: 20, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
75+
{ from: 19, to: 26, type: "dash", backArrow: "filled", fromSide: "right", stroke: "#7D8495" },
76+
{ from: 20, to: 22, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
77+
{ from: 22, to: 23, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
78+
{ from: 22, to: 24, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
79+
{ from: 22, to: 25, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
80+
{ from: 25, to: 26, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
81+
{ from: 25, to: 27, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
82+
{ from: 27, to: 28, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
83+
{ from: 28, to: 29, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
84+
{ from: 29, to: 29.1, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
85+
{ from: 29, to: 29.2, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
86+
{ from: 28, to: 30, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
87+
{ from: 30, to: 31, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
88+
{ from: 31, to: 32, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
89+
{ from: 32, to: 33, type: "dash", forwardArrow: "filled", stroke: "#7D8495" }
90+
]
91+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* import Diagram styles */
2+
@import "../../../node_modules/@dhx/trial-diagram/codebase/diagram.min.css";
3+
4+
/* specify styles for initial page */
5+
html,
6+
body {
7+
margin: 0;
8+
padding: 0;
9+
height: 100%;
10+
}
11+
12+
/* specify styles for the Diagram Editor container */
13+
.widget {
14+
width: 100%;
15+
height: 100%;
16+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { DiagramEditor } from "@dhx/trial-diagram";
2+
import { IDefaultEditorConfig } from "@dhx/trial-diagram/codebase/types/ts-diagram-editor";
3+
import { getData } from "./data";
4+
5+
import {
6+
Component,
7+
ElementRef,
8+
OnInit,
9+
OnDestroy,
10+
ViewChild,
11+
ViewEncapsulation,
12+
} from "@angular/core";
13+
14+
@Component({
15+
encapsulation: ViewEncapsulation.None,
16+
selector: "diagram-editor",
17+
styleUrls: ["./diagram-editor.component.css"],
18+
template: `<div #container class="widget"></div>`,
19+
})
20+
21+
export class DiagramEditorComponent implements OnInit, OnDestroy {
22+
@ViewChild("container", { static: true }) editor_container!: ElementRef;
23+
24+
private _diagram_editor!: DiagramEditor;
25+
26+
ngOnInit() {
27+
const data = getData();
28+
this._diagram_editor = new DiagramEditor(this.editor_container.nativeElement, { type: "default" } as IDefaultEditorConfig);
29+
this._diagram_editor.parse(data);
30+
}
31+
32+
ngOnDestroy(): void {
33+
this._diagram_editor?.destructor();
34+
}
35+
}

0 commit comments

Comments
 (0)