You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guides/diagram_editor/initialization.md
+28-12
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,17 @@
1
1
---
2
2
sidebar_label: Initialization
3
-
title: Editor initialization
3
+
title: Diagram Editor initialization
4
4
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.
5
5
---
6
6
7
-
# Editor initialization
7
+
# Diagram Editor initialization
8
8
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:
10
10
11
11
-[Download the DHTMLX Diagram package](https://dhtmlx.com/docs/products/dhtmlxDiagram/download.shtml) and unpack it into a folder of your project
12
12
-[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)
15
15
16
16
~~~html
17
17
<!DOCTYPE html>
@@ -34,7 +34,7 @@ This article covers the process of displaying a Diagram editor on a page. In ord
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
64
80
65
81
You can initialize a Diagram Editor in a container, in the document body, or in a layout cell.
66
82
67
83
### Initialization in a container
68
84
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:
70
86
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:
72
88
73
89
~~~html title="index.html"
74
90
<divid="editor_container"></div>
@@ -84,7 +100,7 @@ const editor = new dhx.DiagramEditor("editor_container", {
84
100
85
101
### Initialization in the document body
86
102
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:
88
104
89
105
~~~jsx
90
106
consteditor=newdhx.DiagramEditor(document.body, {
@@ -127,7 +143,7 @@ const editor = new dhx.DiagramEditor("editor_container", {
127
143
128
144
Check [the full list of configuration properties of Editor](/api/diagram_editor/editor/config/overview/).
129
145
130
-
## Loading data into Editor
146
+
## Loading data into Diagram Editor
131
147
132
148
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.
Copy file name to clipboardExpand all lines: docs/guides/integrations/angular_integration.md
+255-6
Original file line number
Diff line number
Diff line change
@@ -6,15 +6,264 @@ description: You can learn about the Integration with Angular in the documentati
6
6
7
7
# Integration with Angular
8
8
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
+
~~~
10
26
11
27
:::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!
13
29
:::
14
30
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:
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:
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:
/* 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
+
exportfunctiongetData() {
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" },
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.
this._diagram_editor=newDiagramEditor( 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=newDiagramEditor(this.editor_container.nativeElement, { type:"default" } as IDefaultEditorConfig);
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
+
exportclassAppComponent {
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:
-[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