Skip to content

Commit 7352583

Browse files
Merge pull request #50 from DHTMLX/next
[update] Installing via npm and yarn (Diagram Editor). Integration guides
2 parents 6bee2c1 + ca50e1a commit 7352583

File tree

7 files changed

+981
-33
lines changed

7 files changed

+981
-33
lines changed

Diff for: docs/assets/trial_diagram.png

542 KB
Loading

Diff for: docs/guides/diagram_editor/initialization.md

+28-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
22
sidebar_label: Initialization
3-
title: Editor initialization
3+
title: Diagram Editor initialization
44
description: You can learn how to start with Diagram Editor in the documentation of the DHTMLX JavaScript Diagram library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX Diagram.
55
---
66

7-
# Editor initialization
7+
# Diagram Editor initialization
88

9-
This article covers the process of displaying a Diagram editor on a page. In order to initialize the editor, you need to include source files specific for Editor and use the `DiagramEditor` instance. In all other aspects the initialization stage is the same as for the Diagram component:
9+
This article covers the process of displaying a Diagram Editor on a page. In order to initialize the editor, you need to include source files specific for Editor and use the `DiagramEditor` instance. In all other aspects the initialization stage is the same as for the Diagram component:
1010

1111
- [Download the DHTMLX Diagram package](https://dhtmlx.com/docs/products/dhtmlxDiagram/download.shtml) and unpack it into a folder of your project
1212
- [Include the source files on a page](#including-required-code-files)
13-
- [Initialize the Editor with the object constructor](#initializing-editor)
14-
- [Load data into the Editor](#loading-data-into-editor)
13+
- [Initialize Diagram Editor with the object constructor](#initializing-diagram-editor)
14+
- [Load data into the Diagram Editor](#loading-data-into-diagram-editor)
1515

1616
~~~html
1717
<!DOCTYPE html>
@@ -34,7 +34,7 @@ This article covers the process of displaying a Diagram editor on a page. In ord
3434
// more objects
3535
];
3636
37-
// creating Editor
37+
// creating Diagram Editor
3838
const editor = new dhx.DiagramEditor("editor_container", {
3939
// config options
4040
});
@@ -48,7 +48,7 @@ This article covers the process of displaying a Diagram editor on a page. In ord
4848

4949
## Including required code files
5050

51-
To create Editor, you need to include 2 source files on your page:
51+
To create Diagram Editor, you need to include 2 source files on your page:
5252

5353
- **diagramWithEditor.js**
5454
- **diagramWithEditor.css**
@@ -60,15 +60,31 @@ Make sure that you set correct relative paths to these files:
6060
<link rel="stylesheet" href="../codebase/diagramWithEditor.css">
6161
~~~
6262

63-
## Initializing Editor
63+
### Installing Diagram Editor via npm and yarn
64+
65+
You can import JavaScript Diagram Editor into your project using the `yarn` or `npm` package manager.
66+
67+
#### Installing trial Diagram Editor via npm and yarn
68+
69+
:::info
70+
If you want to use the trial version of Diagram Editor, download the [**trial Diagram package**](https://dhtmlx.com/docs/products/dhtmlxDiagram/download.shtml) and follow the steps mentioned in the *README* file. Note that the trial Diagram Editor is available 30 days only.
71+
:::
72+
73+
#### Installing PRO Diagram Editor via npm and yarn
74+
75+
:::info
76+
If you already have Diagram Editor under the proprietary license, send your **license number** to the *[email protected]* email to receive a login and a password for a private **npm** as well as a detailed guide on how to install Diagram Editor. Note that a private **npm** is available before the expiration of the proprietary Diagram Editor license.
77+
:::
78+
79+
## Initializing Diagram Editor
6480

6581
You can initialize a Diagram Editor in a container, in the document body, or in a layout cell.
6682

6783
### Initialization in a container
6884

69-
To initialize an editor in a container, use the `dhx.DiagramEditor` constructor and pass the following two parameters to the constructor function:
85+
To initialize Diagram Editor in a container, use the `dhx.DiagramEditor` constructor and pass the following two parameters to the constructor function:
7086

71-
- a container to place an Editor into, let's give it the *"editor_container"* id:
87+
- a container to place Diagram Editor into, let's give it the *"editor_container"* id:
7288

7389
~~~html title="index.html"
7490
<div id="editor_container"></div>
@@ -84,7 +100,7 @@ const editor = new dhx.DiagramEditor("editor_container", {
84100

85101
### Initialization in the document body
86102

87-
It is also possible to skip setting a container for Editor and to add it right into the document's body:
103+
It is also possible to skip setting a container for Diagram Editor and to add it right into the document's body:
88104

89105
~~~jsx
90106
const editor = new dhx.DiagramEditor(document.body, {
@@ -127,7 +143,7 @@ const editor = new dhx.DiagramEditor("editor_container", {
127143

128144
Check [the full list of configuration properties of Editor](/api/diagram_editor/editor/config/overview/).
129145

130-
## Loading data into Editor
146+
## Loading data into Diagram Editor
131147

132148
It is possible to load an [appropriate data set](../../../guides/loading_data/#preparing-data-to-load) into the editor via the [parse()](../../../api/diagram_editor/editor/methods/parse_method/) method of the editor.
133149

Diff for: docs/guides/integrations/angular_integration.md

+255-6
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,264 @@ description: You can learn about the Integration with Angular in the documentati
66

77
# Integration with Angular
88

9-
DHTMLX Diagram can be easily integrated into an application created with the Angular framework.
9+
:::tip
10+
You should be familiar with the basic concepts and patterns of **Angular** to use this documentation. To refresh your knowledge, please refer to the [**Angular documentation**](https://angular.io/docs).
11+
:::
12+
13+
DHTMLX Diagram Editor is compatible with **Angular**. We have prepared code examples on how to use DHTMLX Diagram Editor with **Angular**. For more information, refer to the corresponding [**Example on GitHub**](https://github.com/DHTMLX/angular-diagram-demo).
14+
15+
## Creating a project
16+
17+
:::info
18+
Before you start to create a new project, install [**Angular CLI**](https://angular.io/cli) and [**Node.js**](https://nodejs.org/en/).
19+
:::
20+
21+
Create a new **my-angular-diagram-app** project using Angular CLI. Run the following command for this purpose:
22+
23+
~~~json
24+
ng new my-angular-diagram-app
25+
~~~
1026

1127
:::note
12-
View the [DHTMLX Diagram + Angular](https://github.com/DHTMLX/angular-diagram-demo) demo on GitHub.
28+
If you want to follow this guide, disable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering) when creating new Angular app!
1329
:::
1430

15-
You can clone or download it, and use it for your projects. To run the demo, follow the instructions given in the README file.
31+
The command above installs all the necessary tools, so you don't need to run any additional commands.
32+
33+
### Installation of dependencies
34+
35+
After that, go to the app directory:
36+
37+
~~~json
38+
cd my-angular-diagram-app
39+
~~~
40+
41+
Install dependencies and start the dev server. For this, use the [**yarn**](https://yarnpkg.com/) package manager:
42+
43+
~~~json
44+
yarn
45+
yarn start
46+
~~~
47+
48+
The app should run on a localhost (for instance `http://localhost:3000`).
49+
50+
## Creating Diagram Editor
51+
52+
Now you should get the DHTMLX Diagram Editor source code. First of all, stop the app and proceed with installing the Diagram Editor package.
53+
54+
### Step 1. Package installation
55+
56+
Download the [**trial Diagram package**](/guides/diagram_editor/initialization/#installing-diagram-editor-via-npm-and-yarn) and follow steps mentioned in the README file. Note that trial Diagram Editor is available 30 days only.
57+
58+
### Step 2. Component creation
59+
60+
Now you need to create an Angular component, to add Diagram Editor into the application. Create the **diagram-editor** folder in the **src/app/** directory, add a new file into it and name it **diagram-editor.component.ts**. Then complete the steps described below.
61+
62+
#### Import source files
63+
64+
Open the file and import Diagram Editor source files. Note that:
65+
66+
- if you use PRO version and install the Diagram Editor package from a local folder, the imported path looks like this:
67+
68+
~~~jsx
69+
import { DiagramEditor } from 'dhx-diagram-package';
70+
~~~
71+
72+
- if you use the trial version of Diagram, specify the following path:
73+
74+
~~~jsx
75+
import { DiagramEditor } from '@dhx/trial-diagram';
76+
~~~
77+
78+
In this tutorial you can see how to configure the **trial** version of Diagram.
79+
80+
#### Set the container and initialize Diagram Editor
81+
82+
To display Diagram Editor on the page, you need to set the container to render the component inside and initialize Diagram Editor using the corresponding constructor:
83+
84+
~~~jsx {1,9,13-14,19-20} title="diagram-editor.component.ts"
85+
import { DiagramEditor } from "@dhx/trial-diagram";
86+
import { IDefaultEditorConfig } from "@dhx/trial-diagram/codebase/types/ts-diagram-editor";
87+
import { Component, ElementRef, OnInit, ViewChild, OnDestroy, ViewEncapsulation } from '@angular/core';
88+
89+
@Component({
90+
encapsulation: ViewEncapsulation.None,
91+
selector: 'diagram-editor', // a template name used in the "app.component.ts" file as <diagram-editor/>
92+
styleUrls: ['./diagram-editor.component.css'], // include a css file
93+
template: `<div #container class = "widget"></div>`
94+
})
95+
96+
export class DiagramEditorComponent implements OnInit, OnDestroy {
97+
// initialize container for Diagram Editor
98+
@ViewChild('container', { static: true }) editor_container!: ElementRef;
99+
100+
private _diagram_editor!: DiagramEditor;
101+
102+
ngOnInit() {
103+
// initialize the Diagram Editor component
104+
this._diagram_editor = new DiagramEditor( this.editor_container.nativeElement, { type: "default" } as IDefaultEditorConfig);
105+
}
106+
107+
ngOnDestroy() {
108+
this._diagram_editor.destructor(); // destruct Diagram Editor
109+
}
110+
}
111+
~~~
112+
113+
#### Adding styles
114+
115+
To display Diagram Editor correctly, you need to provide the corresponding styles. For this purpose, you can create the **diagram-editor.component.css** file in the **src/app/diagram-editor/** directory and specify important styles for Diagram Editor and its container:
116+
117+
~~~css title="diagram-editor.component.css"
118+
/* import Diagram Editor styles */
119+
@import "@dhx/trial-diagram/codebase/diagram.min.css";
120+
121+
/* specify styles for initial page */
122+
html,
123+
body {
124+
height: 100%;
125+
padding: 0;
126+
margin: 0;
127+
}
128+
129+
/* specify styles for the Diagram Editor container */
130+
.widget {
131+
height: 100%;
132+
width: 100%;
133+
}
134+
~~~
135+
136+
#### Loading data
137+
138+
To add data into Diagram Editor, you need to provide a [**data set**](https://github.com/DHTMLX/angular-diagram-demo/blob/master/src/app/diagram/data.ts). You can create the **data.ts** file in the **src/app/diagram-editor/** directory and add some data into it:
139+
140+
~~~jsx title="data.ts"
141+
export function getData() {
142+
return [
143+
{ id: 1, x: 880, y: 105, text: "Does user remember his password?", type: "process", lineHeight: 18, fontColor: "#fff", fill: "#3DA0E3", stroke: "#3DA0E3" },
144+
{ id: 2, x: 1080, y: 125, width: 50, "height": 50, text: "XOR", type: "circle", lineHeight: 18, fontColor: "#fff", fill: "#7D8495", stroke: "#7D8495" },
145+
{ id: 3, x: 1160, y: 40, text: "User forgets his password", type: "preparation", lineHeight: 18, fontColor: "#fff", fill: "#33B579", stroke: "#33B579" },
146+
{ 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" },
147+
{ id: 3.2, x: 1520, y: 40, text: "E-mail sent", type: "preparation", fontColor: "#fff", lineHeight: 18, fill: "#33B579", stroke: "#33B579" },
148+
{ id: 4, x: 1160, y: 180, text: "User remembers his password", type: "preparation", lineHeight: 18, fontColor: "#fff", fill: "#33B579", stroke: "#33B579" },
149+
{ id: 5, x: 1340, y: 180, text: "User types in login and password", type: "process", lineHeight: 18, fontColor: "#fff", fill: "#3DA0E3", stroke: "#3DA0E3" },
150+
// other data
151+
152+
{ from: 1, to: 2, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
153+
{ from: 2, to: 3, type: "dash", toSide: "bottom", forwardArrow: "filled", stroke: "#7D8495" },
154+
{ from: 2, to: 7.5, type: "dash", fromSide: "bottom", toSide: "top", backArrow: "filled", stroke: "#7D8495" },
155+
{ from: 2, to: 3.2, type: "dash", fromSide: "top", toSide: "top", stroke: "#7D8495" },
156+
{ from: 3, to: 3.1, type: "line", forwardArrow: "filled", stroke: "#7D8495" },
157+
{ from: 3.1, to: 3.2, type: "line", forwardArrow: "filled", stroke: "#7D8495" },
158+
{ from: 2, to: 4, type: "dash", toSide: "top", forwardArrow: "filled", stroke: "#7D8495" },
159+
{ from: 4, to: 5, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
160+
{ from: 5, to: 6, type: "dash", forwardArrow: "filled", stroke: "#7D8495" },
161+
// other data
162+
]
163+
}
164+
~~~
165+
166+
Then open the ***diagram-editor.component.ts*** file. Import the file with data and apply it using the [`parse()`](api/diagram_editor/editor/methods/parse_method.md) method within the `ngOnInit()` method, as shown below.
167+
168+
~~~jsx {3,19,22} title="diagram-editor.component.ts"
169+
import { DiagramEditor } from "@dhx/trial-diagram";
170+
import { IDefaultEditorConfig } from "@dhx/trial-diagram/codebase/types/ts-diagram-editor";
171+
import { getData } from "./data"; // import data
172+
import { Component, ElementRef, OnInit, ViewChild, OnDestroy, ViewEncapsulation } from '@angular/core';
173+
174+
@Component({
175+
encapsulation: ViewEncapsulation.None,
176+
selector: 'diagram-editor',
177+
styleUrls: ['./diagram-editor.component.css'],
178+
template: `<div #container class = "widget"></div>`
179+
})
180+
181+
export class DiagramEditorComponent implements OnInit, OnDestroy {
182+
@ViewChild('container', { static: true }) editor_container!: ElementRef;
183+
184+
private _diagram_editor!: DiagramEditor;
185+
186+
ngOnInit() {
187+
const data = getData(); // initialize data property
188+
this._diagram_editor = new DiagramEditor( this.editor_container.nativeElement, { type: "default" } as IDefaultEditorConfig);
189+
190+
this._diagram_editor.parse(data);
191+
}
192+
193+
ngOnDestroy() {
194+
this._diagram_editor.destructor();
195+
}
196+
}
197+
~~~
198+
199+
Now the Diagram Editor component is ready to use. When the element will be added to the page, it will initialize the Diagram Editor with data. You can provide necessary configuration settings as well. Visit our [Diagram Editor API docs](/category/diagram-editor-api/) to check the full list of available properties.
200+
201+
#### Handling events
202+
203+
When a user makes some action in the Diagram Editor, it invokes an event. You can use these events to detect the action and run the desired code for it. See the [full list of events](api/diagram_editor/editor/events/overview.md).
204+
205+
Open the **diagram-editor.component.ts** file and complete the `ngOnInit()` method as in:
206+
207+
~~~jsx {5-7} title="diagram-editor.component.ts"
208+
// ...
209+
ngOnInit() {
210+
this._diagram_editor = new DiagramEditor(this.editor_container.nativeElement, { type: "default" } as IDefaultEditorConfig);
211+
212+
this._diagram_editor.events.on("zoomIn", (step) => {
213+
console.log("The diagram in the editor is zoomed in. The step is" + step);
214+
});
215+
}
216+
217+
ngOnDestroy() {
218+
this._diagram_editor.destructor();
219+
}
220+
~~~
221+
222+
### Step 3. Adding Diagram Editor into the app
223+
224+
To add the ***DiagramEditorComponent*** into the app, open the ***src/app/app.component.ts*** file and replace the default code with the following one:
225+
226+
~~~jsx {5} title="app.component.ts"
227+
import { Component } from "@angular/core";
228+
229+
@Component({
230+
selector: "app-root",
231+
template: `<diagram-editor/>` // a template created in the "diagram-editor.component.ts" file
232+
})
233+
export class AppComponent {
234+
name = "";
235+
}
236+
~~~
237+
238+
Then create the ***app.module.ts*** file in the ***src/app/*** directory and specify the *DiagramEditorComponent* as shown below:
239+
240+
~~~jsx {4-5,8} title="app.module.ts"
241+
import { NgModule } from "@angular/core";
242+
import { BrowserModule } from "@angular/platform-browser";
243+
244+
import { AppComponent } from "./app.component";
245+
import { DiagramEditorComponent } from "./diagram-editor/diagram-editor.component";
246+
247+
@NgModule({
248+
declarations: [AppComponent, DiagramEditorComponent],
249+
imports: [BrowserModule],
250+
bootstrap: [AppComponent]
251+
})
252+
export class AppModule {}
253+
~~~
254+
255+
The last step is to open the ***src/main.ts*** file and replace the existing code with the following one:
256+
257+
~~~jsx title="main.ts"
258+
import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
259+
import { AppModule } from "./app/app.module";
260+
platformBrowserDynamic()
261+
.bootstrapModule(AppModule)
262+
.catch((err) => console.error(err));
263+
~~~
264+
265+
After that, you can start the app to see Diagram Editor loaded with data on a page.
16266

17-
If you use some other frameworks, check the available examples below:
267+
![Diagram Editor initialization](../../assets/trial_diagram.png)
18268

19-
- [Integration with React](/guides/integrations/react_integration/)
20-
- [Integration with Vue.js](/guides/integrations/vue_integration/)
269+
Now you know how to integrate DHTMLX Diagram Editor with Angular. You can customize the code according to your specific requirements. The final example you can find on [**GitHub**](https://github.com/DHTMLX/angular-diagram-demo).

0 commit comments

Comments
 (0)