total-diagram 0.9.2 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -5
- package/build.js +14 -4
- package/{demo.html → examples/1_basic.html} +5 -5
- package/{links.js → manager-links.js} +7 -7
- package/{nodes.js → manager-nodes.js} +7 -7
- package/package.json +3 -3
- package/{node.js → render-node.js} +4 -2
- package/render.js +17 -6
- package/total-diagram.js.ejs +4 -4
- /package/{link.js → render-link.js} +0 -0
package/README.md
CHANGED
|
@@ -6,19 +6,21 @@ Total Diagram
|
|
|
6
6
|
</h1>
|
|
7
7
|
<p align="center">
|
|
8
8
|
Simple, powerful, extensible and fast JavaScript/ES8 diagram renderer for web browsers.
|
|
9
|
-
|
|
9
|
+
</p>
|
|
10
10
|
<p align="center">
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
v0.9.4
|
|
12
|
+
</p>
|
|
13
13
|
|
|
14
14
|
[](https://github.com/dariuszdawidowski/total-diagram/actions/workflows/build.yml)
|
|
15
|
+
[](https://www.npmjs.com/package/total-diagram)
|
|
15
16
|
[](./LICENSE)
|
|
16
17
|
|
|
17
18
|
# About
|
|
18
19
|
|
|
19
20
|
A library for rendering diagrams consisting of nodes and links.
|
|
20
21
|
Designed for simplicity, it can be the basis for creating a diagramming application or data representation on a website.
|
|
21
|
-
|
|
22
|
+
|
|
23
|
+
For more details look into 'examples/' directory. You can find self-explanatory tutorials there.
|
|
22
24
|
|
|
23
25
|
# Features
|
|
24
26
|
|
|
@@ -31,4 +33,12 @@ For more details look into self-explanatory demo.html.
|
|
|
31
33
|
npm install
|
|
32
34
|
npm run build
|
|
33
35
|
```
|
|
34
|
-
Note: This is browser-centric vanilla JavaScript library, npm is only used to minify and bundle files
|
|
36
|
+
Note: This is browser-centric vanilla JavaScript library, npm is only used to minify and bundle files.
|
|
37
|
+
|
|
38
|
+
# Load from CDN
|
|
39
|
+
|
|
40
|
+
https://unpkg.com/total-diagram@latest/dist/total-diagram.js
|
|
41
|
+
|
|
42
|
+
# Authors
|
|
43
|
+
|
|
44
|
+
Dariusz Dawidowski
|
package/build.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Build script
|
|
2
|
+
* Build script v6-custom
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
const files = [
|
|
6
|
+
{ src: 'total-diagram.js.ejs', dst: 'total-diagram.js' },
|
|
7
|
+
];
|
|
8
|
+
|
|
5
9
|
const fs = require('fs');
|
|
6
|
-
const ejs = require('ejs');
|
|
7
10
|
const { readFile } = require('fs').promises;
|
|
11
|
+
const ejs = require('ejs');
|
|
8
12
|
const { minify } = require('terser');
|
|
9
13
|
|
|
10
14
|
const minjs = async (filePath) => {
|
|
@@ -19,5 +23,11 @@ const minjs = async (filePath) => {
|
|
|
19
23
|
}
|
|
20
24
|
};
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
if (!fs.existsSync('dist')) fs.mkdirSync('dist');
|
|
27
|
+
|
|
28
|
+
files.forEach((file) => {
|
|
29
|
+
|
|
30
|
+
ejs.render(fs.readFileSync(file.src, 'utf8'), { minjs }, {async: true})
|
|
31
|
+
.then(output => fs.writeFileSync('dist/' + file.dst, output, 'utf8'));
|
|
32
|
+
|
|
33
|
+
});
|
|
@@ -63,11 +63,11 @@
|
|
|
63
63
|
<div id="container"></div>
|
|
64
64
|
|
|
65
65
|
<!-- Total Diagram library -->
|
|
66
|
-
<script type="text/javascript" src="node.js"></script>
|
|
67
|
-
<script type="text/javascript" src="link.js"></script>
|
|
68
|
-
<script type="text/javascript" src="nodes.js"></script>
|
|
69
|
-
<script type="text/javascript" src="links.js"></script>
|
|
70
|
-
<script type="text/javascript" src="render.js"></script>
|
|
66
|
+
<script type="text/javascript" src="../render-node.js"></script>
|
|
67
|
+
<script type="text/javascript" src="../render-link.js"></script>
|
|
68
|
+
<script type="text/javascript" src="../manager-nodes.js"></script>
|
|
69
|
+
<script type="text/javascript" src="../manager-links.js"></script>
|
|
70
|
+
<script type="text/javascript" src="../render.js"></script>
|
|
71
71
|
|
|
72
72
|
<script>
|
|
73
73
|
|
|
@@ -71,21 +71,21 @@ class TotalDiagramLinksManager {
|
|
|
71
71
|
* Get link(s)
|
|
72
72
|
*/
|
|
73
73
|
|
|
74
|
-
get(link
|
|
74
|
+
get(link, node2 = null) {
|
|
75
|
+
|
|
76
|
+
// All links
|
|
77
|
+
if (link == '*') return this.list;
|
|
75
78
|
|
|
76
79
|
// Find link betwen two nodes
|
|
77
|
-
if (node2) {
|
|
78
|
-
for (const link1 of link.links.get()) {
|
|
79
|
-
for (const link2 of node2.links.get()) {
|
|
80
|
+
else if (node2) {
|
|
81
|
+
for (const link1 of link.links.get('*')) {
|
|
82
|
+
for (const link2 of node2.links.get('*')) {
|
|
80
83
|
if (link1.id == link2.id) return link1;
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
86
|
return null;
|
|
84
87
|
}
|
|
85
88
|
|
|
86
|
-
// All links
|
|
87
|
-
else if (link === 0) return this.list;
|
|
88
|
-
|
|
89
89
|
// Find one link by giving ID
|
|
90
90
|
else if (typeof(link) == 'string') return this.list.find(n => n.element.dataset.id == link);
|
|
91
91
|
|
|
@@ -50,8 +50,8 @@ class TotalDiagramNodesManager {
|
|
|
50
50
|
// Single node
|
|
51
51
|
if (node != '*') {
|
|
52
52
|
|
|
53
|
-
// First delete associated links
|
|
54
|
-
let linksToDelete = node.links.get()
|
|
53
|
+
// First delete associated links
|
|
54
|
+
let linksToDelete = node.links.get('*');
|
|
55
55
|
while (linksToDelete.length) {
|
|
56
56
|
const link = linksToDelete.pop();
|
|
57
57
|
this.render.links.del(link);
|
|
@@ -79,10 +79,13 @@ class TotalDiagramNodesManager {
|
|
|
79
79
|
* Get nodes from scene
|
|
80
80
|
*/
|
|
81
81
|
|
|
82
|
-
get(node
|
|
82
|
+
get(node) {
|
|
83
|
+
|
|
84
|
+
// All nodes
|
|
85
|
+
if (node == '*') return this.list;
|
|
83
86
|
|
|
84
87
|
// Find one node by giving DOM element
|
|
85
|
-
if (node != null && typeof(node) == 'object') {
|
|
88
|
+
else if (node != null && typeof(node) == 'object') {
|
|
86
89
|
// Traverse DOM
|
|
87
90
|
let target = node;
|
|
88
91
|
while (target.parentNode) {
|
|
@@ -94,9 +97,6 @@ class TotalDiagramNodesManager {
|
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
99
|
|
|
97
|
-
// All nodes
|
|
98
|
-
else if (node === 0) return this.list;
|
|
99
|
-
|
|
100
100
|
// Find all nodes type by giving class
|
|
101
101
|
else if (typeof(node) == 'function') return this.list.filter(n => n instanceof node);
|
|
102
102
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "total-diagram",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"description": "Simple, powerful, extensible and fast JavaScript/ES8 diagram renderer for web browsers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"start": "npm-run-all build"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"ejs": "^3.1.9",
|
|
13
|
-
"fs": "^0.0.1-security",
|
|
14
12
|
"npm-run-all": "^4.1.5",
|
|
13
|
+
"fs": "^0.0.1-security",
|
|
14
|
+
"ejs": "^3.1.9",
|
|
15
15
|
"terser": "^5.17.3"
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -79,9 +79,10 @@ class TotalDiagramNode {
|
|
|
79
79
|
},
|
|
80
80
|
|
|
81
81
|
// Get assigned link
|
|
82
|
-
get: (id
|
|
82
|
+
get: (id) => {
|
|
83
|
+
|
|
83
84
|
// All links
|
|
84
|
-
if (id
|
|
85
|
+
if (id == '*') return this.links.list;
|
|
85
86
|
|
|
86
87
|
// Find one link by ID
|
|
87
88
|
else if (typeof(id) == 'string') {
|
|
@@ -145,6 +146,7 @@ class TotalDiagramNode {
|
|
|
145
146
|
if ('maxWidth' in size) this.transform.wmax = size.maxWidth;
|
|
146
147
|
if ('maxHeight' in size) this.transform.hmax = size.maxHeight;
|
|
147
148
|
if ('border' in size) this.transform.border = size.border;
|
|
149
|
+
else this.transform.border = parseInt(getComputedStyle(this.element, null).getPropertyValue('border-left-width').replace('px', '')) || 0;
|
|
148
150
|
this.setOrigin();
|
|
149
151
|
this.element.style.width = this.transform.w + 'px';
|
|
150
152
|
this.element.style.height = this.transform.h + 'px';
|
package/render.js
CHANGED
|
@@ -64,6 +64,8 @@ class TotalDiagramRenderHTML5 {
|
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* Perform pan
|
|
67
|
+
* @param deltaX: change x
|
|
68
|
+
* @param deltaY: change y
|
|
67
69
|
*/
|
|
68
70
|
|
|
69
71
|
pan(deltaX, deltaY) {
|
|
@@ -74,6 +76,10 @@ class TotalDiagramRenderHTML5 {
|
|
|
74
76
|
|
|
75
77
|
/**
|
|
76
78
|
* Perform zoom
|
|
79
|
+
* @param x: x position
|
|
80
|
+
* @param y: y position
|
|
81
|
+
* @param deltaZ: zoom change
|
|
82
|
+
* @param factorZ: multplier
|
|
77
83
|
*/
|
|
78
84
|
|
|
79
85
|
zoom(x, y, deltaZ, factorZ) {
|
|
@@ -92,6 +98,11 @@ class TotalDiagramRenderHTML5 {
|
|
|
92
98
|
|
|
93
99
|
/**
|
|
94
100
|
* Perform mobile zoom
|
|
101
|
+
* @param x1: finger 1 x position
|
|
102
|
+
* @param y1: finger 1 y position
|
|
103
|
+
* @param x2: finger 2 x position
|
|
104
|
+
* @param y2: finger 2 y position
|
|
105
|
+
* @param deltaZ: zoom change
|
|
95
106
|
*/
|
|
96
107
|
|
|
97
108
|
pinchZoom(x1, y1, x2, y2, deltaZ) {
|
|
@@ -110,7 +121,7 @@ class TotalDiagramRenderHTML5 {
|
|
|
110
121
|
|
|
111
122
|
/**
|
|
112
123
|
* Convert window coordinates to world
|
|
113
|
-
* {x:
|
|
124
|
+
* @param coords {x: <Number>, y: <Number>}
|
|
114
125
|
*/
|
|
115
126
|
|
|
116
127
|
screen2World(coords) {
|
|
@@ -122,7 +133,7 @@ class TotalDiagramRenderHTML5 {
|
|
|
122
133
|
|
|
123
134
|
/**
|
|
124
135
|
* Convert world coordinates to window
|
|
125
|
-
* {x:
|
|
136
|
+
* @param coords {x: <Number>, y: <Number>}
|
|
126
137
|
*/
|
|
127
138
|
|
|
128
139
|
world2Screen(coords) {
|
|
@@ -134,9 +145,9 @@ class TotalDiagramRenderHTML5 {
|
|
|
134
145
|
|
|
135
146
|
/**
|
|
136
147
|
* Reset to origin
|
|
137
|
-
* z: 'none' (don't zoom) | 'reset': standard zoom | 'focus': zoom to node size
|
|
138
|
-
* animation: 'hard' | 'smooth'
|
|
139
|
-
* rect: {width, height: dimensions of the focus target}
|
|
148
|
+
* @param z: 'none' (don't zoom) | 'reset': standard zoom | 'focus': zoom to node size
|
|
149
|
+
* @param animation: 'hard' | 'smooth'
|
|
150
|
+
* @param rect: {width, height: dimensions of the focus target}
|
|
140
151
|
*/
|
|
141
152
|
|
|
142
153
|
center(coords = {x: 0, y: 0}, z = 'none', animation = 'hard', rect = null) {
|
|
@@ -178,11 +189,11 @@ class TotalDiagramRenderHTML5 {
|
|
|
178
189
|
|
|
179
190
|
/**
|
|
180
191
|
* Render update
|
|
192
|
+
* Note: use 'transform' since PYQt6 doesn't support separate 'translate' and 'scale' yet
|
|
181
193
|
*/
|
|
182
194
|
|
|
183
195
|
update() {
|
|
184
196
|
// Calculate board's position
|
|
185
|
-
// Note: using 'transform' since PYQt6 doesn't support new css 'translate' and 'scale' yet
|
|
186
197
|
this.board.style.transform = `translate(${this.offset.x}px, ${this.offset.y}px) scale(${this.offset.z})`;
|
|
187
198
|
}
|
|
188
199
|
|
package/total-diagram.js.ejs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
<%- await minjs('node.js') %>
|
|
2
|
-
<%- await minjs('nodes.js') %>
|
|
3
|
-
<%- await minjs('link.js') %>
|
|
4
|
-
<%- await minjs('links.js') %>
|
|
1
|
+
<%- await minjs('render-node.js') %>
|
|
2
|
+
<%- await minjs('manager-nodes.js') %>
|
|
3
|
+
<%- await minjs('render-link.js') %>
|
|
4
|
+
<%- await minjs('manager-links.js') %>
|
|
5
5
|
<%- await minjs('render.js') %>
|
|
File without changes
|