total-diagram 0.9.6 → 0.9.8

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020-2023 Dariusz Dawidowski
3
+ Copyright (c) 2020-2024 Dariusz Dawidowski
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -8,7 +8,7 @@ Total Diagram
8
8
  Simple, powerful, extensible and fast JavaScript/ES8 diagram renderer for web browsers.
9
9
  </p>
10
10
  <p align="center">
11
- v0.9.6
11
+ v0.9.8
12
12
  </p>
13
13
 
14
14
  [![build](https://github.com/dariuszdawidowski/total-diagram/actions/workflows/build.yml/badge.svg)](https://github.com/dariuszdawidowski/total-diagram/actions/workflows/build.yml)
@@ -55,4 +55,5 @@ https://unpkg.com/total-diagram@latest/dist/total-diagram.js
55
55
 
56
56
  # Authors
57
57
 
58
- Dariusz Dawidowski
58
+ Dariusz Dawidowski\
59
+ Jagoda Dawidowska
@@ -0,0 +1,10 @@
1
+ describe('Fundamentals test', () => {
2
+ it('passes', () => {
3
+ // Open website
4
+ cy.visit('http://127.0.0.1:8080/examples/e2e.html')
5
+ // Two Nodes
6
+ cy.get('.total-diagram-node.node').should('have.length', 2)
7
+ // One links
8
+ cy.get('.link').should('have.length', 1)
9
+ })
10
+ })
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "Using fixtures to represent data",
3
+ "email": "hello@cypress.io",
4
+ "body": "Fixtures are a great way to mock data for responses to routes"
5
+ }
@@ -0,0 +1,25 @@
1
+ // ***********************************************
2
+ // This example commands.js shows you how to
3
+ // create various custom commands and overwrite
4
+ // existing commands.
5
+ //
6
+ // For more comprehensive examples of custom
7
+ // commands please read more here:
8
+ // https://on.cypress.io/custom-commands
9
+ // ***********************************************
10
+ //
11
+ //
12
+ // -- This is a parent command --
13
+ // Cypress.Commands.add('login', (email, password) => { ... })
14
+ //
15
+ //
16
+ // -- This is a child command --
17
+ // Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
18
+ //
19
+ //
20
+ // -- This is a dual command --
21
+ // Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
22
+ //
23
+ //
24
+ // -- This will overwrite an existing command --
25
+ // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
@@ -0,0 +1,20 @@
1
+ // ***********************************************************
2
+ // This example support/e2e.js is processed and
3
+ // loaded automatically before your test files.
4
+ //
5
+ // This is a great place to put global configuration and
6
+ // behavior that modifies Cypress.
7
+ //
8
+ // You can change the location of this file or turn off
9
+ // automatically serving support files with the
10
+ // 'supportFile' configuration option.
11
+ //
12
+ // You can read more here:
13
+ // https://on.cypress.io/configuration
14
+ // ***********************************************************
15
+
16
+ // Import commands.js using ES2015 syntax:
17
+ import './commands'
18
+
19
+ // Alternatively you can use CommonJS syntax:
20
+ // require('./commands')
@@ -0,0 +1,9 @@
1
+ const { defineConfig } = require("cypress");
2
+
3
+ module.exports = defineConfig({
4
+ e2e: {
5
+ setupNodeEvents(on, config) {
6
+ // implement node event listeners here
7
+ },
8
+ },
9
+ });
@@ -1,5 +1,6 @@
1
- class TotalDiagramNode{constructor(t={}){this.id="id"in t?t.id:crypto.randomUUID(),this.name="name"in t?t.name:null,this.transform={x:"x"in t?t.x:0,y:"y"in t?t.y:0,border:0,zindex:"zindex"in t?t.zindex:0,ox:0,oy:0,w:0,h:0,wmin:64,hmin:64,wmax:1024,hmax:1024,clear:()=>{this.transform.x=0,this.transform.y=0,this.transform.zindex=0,this.element.style.zIndex=0}},this.links={list:[],add:t=>{this.links.list.push(t)},del:t=>{const i=this.links.list.indexOf(t);-1!==i&&this.links.list.splice(i,1)},get:t=>"*"==t?this.links.list:"in"==t?this.links.list.filter((t=>t.end.id==this.id)):"out"==t?this.links.list.filter((t=>t.start.id==this.id)):"string"==typeof t?this.links.list.find((i=>i.id==t)):null,update:()=>{this.links.list.forEach((t=>t.update()))}},this.element=document.createElement("div"),this.element.classList.add("total-diagram-node"),this.element.style.zIndex=this.transform.zindex,this.element.dataset.id=this.id}destructor(){}awake(){}start(){}setSize(t){this.transform.w=t.width,this.transform.h=t.height,"minWidth"in t&&(this.transform.wmin=t.minWidth),"minHeight"in t&&(this.transform.hmin=t.minHeight),"maxWidth"in t&&(this.transform.wmax=t.maxWidth),"maxHeight"in t&&(this.transform.hmax=t.maxHeight),this.transform.border="border"in t?t.border:parseInt(getComputedStyle(this.element,null).getPropertyValue("border-left-width").replace("px",""))||0,this.setOrigin(),this.element.style.width=this.transform.w+"px",this.element.style.height=this.transform.h+"px"}getSize(){return{width:this.transform.w,height:this.transform.h,minWidth:this.transform.wmin,minHeight:this.transform.hmin,maxWidth:this.transform.wmax,maxHeight:this.transform.hmax}}setOrigin(){this.transform.ox=this.transform.w/2,this.transform.oy=this.transform.h/2}setPosition(t){this.transform.x=t.x,this.transform.y=t.y}getPosition(){return{x:this.transform.x,y:this.transform.y}}addPosition(t){this.transform.x+=t.x,this.transform.y+=t.y}subPosition(t){this.transform.x-=t.x,this.transform.y-=t.y}setStyle(t,i=null){null!==i&&(this.element.style[t]=i)}getStyle(t=null){return null!==t?this.element.style[t]:this.element.style}transparent(t){this.element.style.opacity=100==t?null:t/100}animated(t=!0){this.element.style.transition=t?"transform 0.5s ease-in-out":null}serialize(){return{id:this.id,type:this.constructor.name,x:this.transform.x,y:this.transform.y,w:this.transform.w,h:this.transform.h,zindex:this.transform.zindex}}setSortingZ(t){this.transform.zindex=t,this.element.style.zIndex=t}update(){this.element.style.transform=`translate(${this.transform.x-this.transform.ox}px, ${this.transform.y-this.transform.oy}px)`}}
1
+ class AnonymousTraversalSource{constructor(r){this.traversalSourceClass=r}static traversal(r){return new AnonymousTraversalSource(r||GraphTraversalSource)}withLists(r,s){return new this.traversalSourceClass(r,s)}}class GraphTraversalSource{constructor(r,s){this.vertices=r,this.edges=s}V(r=null){return new GraphTraversal(this.vertices,r)}E(r=null){return new GraphTraversal(this.edges,r)}}class GraphTraversal{constructor(r,s=null){if(this.result=null,null==s)this.result=r;else if("object"==typeof s){let t=s;for(;t.parentNode;)"classList"in t&&t.classList.contains("total-diagram-node")&&(this.result=r.find((r=>r.id==t.dataset.id))),t=t.parentNode}else"function"==typeof node?this.result=r.filter((r=>r instanceof node)):"string"==typeof s&&(this.result=r.find((r=>r.id==s)))}hasNext(){return null!=this.result&&"Array"!=this.result.constructor.name}next(){return this.result}toList(){return"Array"!=this.result.constructor.name?[this.result]:this.result}}
2
+ class TotalDiagramNode{constructor(t={}){this.id="id"in t?t.id:crypto.randomUUID(),this.name="name"in t?t.name:null,this.transform={x:"x"in t?t.x:0,y:"y"in t?t.y:0,border:0,zindex:"zindex"in t?t.zindex:0,ox:0,oy:0,w:0,h:0,wmin:64,hmin:64,wmax:1024,hmax:1024,clear:()=>{this.transform.x=0,this.transform.y=0,this.transform.zindex=0,this.element.style.zIndex=0}},this.links={list:[],add:t=>{-1===this.links.list.indexOf(t)&&this.links.list.push(t)},del:t=>{const i=this.links.list.indexOf(t);-1!==i&&this.links.list.splice(i,1)},get:t=>"*"==t?this.links.list:"in"==t?this.links.list.filter((t=>t.end.id==this.id)):"out"==t?this.links.list.filter((t=>t.start.id==this.id)):"string"==typeof t?this.links.list.find((i=>i.id==t)):null,update:()=>{this.links.list.forEach((t=>t.update()))}},this.element=document.createElement("div"),this.element.classList.add("total-diagram-node"),this.element.style.zIndex=this.transform.zindex,this.element.dataset.id=this.id}destructor(){}awake(){}start(){}setSize(t){"width"in t&&(this.transform.w=t.width),"height"in t&&(this.transform.h=t.height),"minWidth"in t&&(this.transform.wmin=t.minWidth),"minHeight"in t&&(this.transform.hmin=t.minHeight),"maxWidth"in t&&(this.transform.wmax=t.maxWidth),"maxHeight"in t&&(this.transform.hmax=t.maxHeight),"width"in t&&(this.transform.w<this.transform.wmin&&(this.transform.w=this.transform.wmin),this.transform.w>this.transform.wmax&&(this.transform.w=this.transform.wmax)),"height"in t&&(this.transform.h<this.transform.hmin&&(this.transform.h=this.transform.hmin),this.transform.h>this.transform.hmax&&(this.transform.h=this.transform.hmax)),this.transform.border="border"in t?t.border:parseInt(getComputedStyle(this.element,null).getPropertyValue("border-left-width").replace("px",""))||0,"width"in t&&"height"in t&&this.setOrigin(),"width"in t&&(this.element.style.width=this.transform.w+"px"),"height"in t&&(this.element.style.height=this.transform.h+"px")}getSize(){return{width:this.transform.w,height:this.transform.h,minWidth:this.transform.wmin,minHeight:this.transform.hmin,maxWidth:this.transform.wmax,maxHeight:this.transform.hmax,border:this.transform.border}}setOrigin(){this.transform.ox=this.transform.w/2,this.transform.oy=this.transform.h/2}setPosition(t){this.transform.x=t.x,this.transform.y=t.y}getPosition(){return{x:this.transform.x,y:this.transform.y}}addPosition(t){this.transform.x+=t.x,this.transform.y+=t.y}subPosition(t){this.transform.x-=t.x,this.transform.y-=t.y}setStyle(t,i=null){null!==i&&(this.element.style[t]=i)}getStyle(t=null){return null!==t?this.element.style[t]:this.element.style}transparent(t){this.element.style.opacity=100==t?null:t/100}animated(t=!0){this.element.style.transition=t?"transform 0.5s ease-in-out":null}serialize(){return{id:this.id,type:this.constructor.name,x:this.transform.x,y:this.transform.y,w:this.transform.w,h:this.transform.h,zindex:this.transform.zindex}}setSortingZ(t){this.transform.zindex=t,this.element.style.zIndex=t}update(){this.element.style.transform=`translate(${this.transform.x-this.transform.ox-this.transform.border}px, ${this.transform.y-this.transform.oy-this.transform.border}px)`}}
2
3
  class TotalDiagramNodesManager{constructor(){this.render=null,this.list=[]}add(t){this.list.push(t),this.render.board.append(t.element),t.awake();const e=new CustomEvent("broadcast:addnode",{detail:t});this.render.container.dispatchEvent(e)}del(t){if("*"!=t){const e=t.links.get("*");for(;e.length;){const t=e.pop();this.render.links.del(t)}t.destructor(),t.element.remove();const s=this.list.indexOf(t);-1!==s&&this.list.splice(s,1);const n=new CustomEvent("broadcast:delnode",{detail:t});this.render.container.dispatchEvent(n)}else if("*"==t){this.list.forEach((t=>{t.destructor(),t.element.remove()})),this.list.length=0;const t=new CustomEvent("broadcast:delnodes",{detail:"*"});this.render.container.dispatchEvent(t)}}get(t){if("*"==t)return this.list;if(null!=t&&"object"==typeof t){let e=t;for(;e.parentNode;){if("classList"in e&&e.classList.contains("total-diagram-node"))return this.get(e.dataset.id);e=e.parentNode}}else{if("function"==typeof t)return this.list.filter((e=>e instanceof t));if("string"==typeof t)return this.list.find((e=>e.id==t))}return null}}
3
4
  class TotalDiagramLink{constructor(t){this.id="id"in t?t.id:crypto.randomUUID(),this.start=t.start,this.start.links.add(this),this.end=t.end,this.end.links.add(this),this.element=document.createElementNS("http://www.w3.org/2000/svg","svg"),this.element.classList.add("link"),this.element.dataset.id=this.id}destructor(){this.start&&this.start.links.del(this),this.end&&this.end.links.del(this)}serialize(){return{id:this.id,type:this.constructor.name,start:this.start.id,end:this.end.id}}transparent(t){this.element.style.opacity=100==t?null:t/100}update(){}}
4
5
  class TotalDiagramLinksManager{constructor(){this.render=null,this.list=[]}add(t){if(!t.start||!t.end)return null;this.list.push(t),this.render.board.append(t.element);const e=new CustomEvent("broadcast:addlink",{detail:t});this.render.container.dispatchEvent(e)}del(t){if("*"!=t){t.destructor(),t.element.remove();const e=this.list.indexOf(t);-1!==e&&this.list.splice(e,1);const n=new CustomEvent("broadcast:dellink",{detail:t});this.render.container.dispatchEvent(n)}else{this.list.forEach((t=>{t.destructor(),t.element.remove()})),this.list.length=0;const t=new CustomEvent("broadcast:delnodes",{detail:"*"});this.render.container.dispatchEvent(t)}}get(t,e=null){if("*"==t)return this.list;if(e){for(const n of t.links.get("*"))for(const t of e.links.get("*"))if(n.id==t.id)return n;return null}return"string"==typeof t?this.list.find((e=>e.element.dataset.id==t)):"function"==typeof t?this.list.filter((e=>e instanceof t)):"object"==typeof t&&"dataset"in t?this.get(t.dataset.id):null}}
5
- class TotalDiagramRenderHTML5{constructor(t){this.container=t.container,this.board=document.createElement("div"),this.board.id="total-diagram-attach",this.board.style.transformOrigin="0px 0px",this.board.style.width=0,this.board.style.height=0,this.board.style.overflow="visible",this.container.appendChild(this.board),this.size=this.container.getBoundingClientRect(),this.size.center={x:this.size.width/2,y:this.size.height/2},this.margin={left:this.size.left-document.documentElement.scrollLeft,top:this.size.top-document.documentElement.scrollTop},this.offset={x:0,y:0,z:1},window.addEventListener("resize",(()=>{this.size=this.container.getBoundingClientRect(),this.size.center={x:this.size.width/2,y:this.size.height/2}})),this.nodes=t.nodes,this.nodes.render=this,this.links=t.links,this.links.render=this}pan(t,s){this.offset.x+=t,this.offset.y+=s,this.update()}zoom(t,s,e,i){let h=this.offset.z;this.offset.z=(this.offset.z-e/i*this.offset.z).clamp(.1,3),h=this.offset.z/h;const o=this.board.getBoundingClientRect(),n=o.width/2+o.left-t,f=o.height/2+o.top-s;this.offset.x+=n*h-n,this.offset.y+=f*h-f,this.update()}pinchZoom(t,s,e,i,h){let o=this.offset.z;this.offset.z=(this.offset.z*h).clamp(.1,3),o=this.offset.z/o;const n=this.board.getBoundingClientRect(),f=n.width/2+n.left-(t+e)/2,r=n.height/2+n.top-(s+i)/2;this.offset.x+=f*o-f,this.offset.y+=r*o-r,this.update()}screen2World(t){return{x:Math.round((t.x-this.offset.x)/this.offset.z-this.margin.left),y:Math.round((t.y-this.offset.y)/this.offset.z-this.margin.top)}}world2Screen(t){return{x:Math.round(this.offset.x+t.x*this.offset.z-this.margin.left),y:Math.round(this.offset.y+t.y*this.offset.z-this.margin.top)}}center(t={x:0,y:0},s="none",e="hard",i=null){"smooth"==e&&(this.board.style.transition="transform 1s",setInterval((()=>{this.board.style.removeProperty("transition")}),1e3)),"reset"==s?this.offset.z=1:"focus"==s&&(this.offset.z=this.size.height/(i.height+i.margin)),this.offset.x=-t.x*this.offset.z+this.size.center.x,this.offset.y=-t.y*this.offset.z+this.size.center.y,this.update()}centerZoom(){this.offset.z=1,this.update()}clear(){this.board.innerHTML="",this.links.del("*"),this.nodes.del("*")}update(){this.board.style.transform=`translate(${this.offset.x}px, ${this.offset.y}px) scale(${this.offset.z})`}redraw(){this.container.style.display="none";this.container.offsetHeight;this.container.style.display="block"}}
6
+ class TotalDiagramRenderHTML5{constructor(t){this.container=t.container,this.board=document.createElement("div"),this.board.id="total-diagram-attach",this.board.style.transformOrigin="0px 0px",this.board.style.width=0,this.board.style.height=0,this.board.style.overflow="visible",this.container.appendChild(this.board),this.size=this.container.getBoundingClientRect(),this.size.center={x:this.size.width/2,y:this.size.height/2},this.margin={left:this.size.left-document.documentElement.scrollLeft,top:this.size.top-document.documentElement.scrollTop},this.offset={x:0,y:0,z:1,delta:{x:0,y:0,length:function(){return Math.sqrt(this.x**2+this.y**2)}},timestamp:0,speed:0,add:function(t,s){this.delta.x=t,this.delta.y=s,this.x+=t,this.y+=s,this.calcSpeed()},calcSpeed:function(t=4e3){const s=Date.now();0==this.timestamp&&(this.timestamp=s);const e=s-this.timestamp;this.timestamp=s,this.speed=(this.speed+Math.min(t,this.delta.length()/(e/1e3)))/2}},window.addEventListener("resize",(()=>{this.size=this.container.getBoundingClientRect(),this.size.center={x:this.size.width/2,y:this.size.height/2}})),this.nodes=t.nodes,this.nodes.render=this,this.links=t.links,this.links.render=this;const s=AnonymousTraversalSource.traversal;this.g=s().withLists(this.nodes.list,this.links.list)}pan(t,s){this.offset.add(t,s),this.update()}damp(t=.97,s=300){this.offset.calcSpeed();const e=()=>{this.offset.delta.x*=t,this.offset.delta.y*=t,this.offset.x+=this.offset.delta.x/window.devicePixelRatio,this.offset.y+=this.offset.delta.y/window.devicePixelRatio,this.update(),(Math.abs(this.offset.delta.x)>.1||Math.abs(this.offset.delta.y)>.1)&&requestAnimationFrame(e)};this.offset.speed>s&&e()}zoom(t,s,e,i){this.offset.delta.x=0,this.offset.delta.y=0;let h=this.offset.z;this.offset.z=Math.max(.1,Math.min(3,this.offset.z-e/i*this.offset.z)),h=this.offset.z/h;const o=this.board.getBoundingClientRect(),n=o.width/2+o.left-t,f=o.height/2+o.top-s;this.offset.x+=n*h-n,this.offset.y+=f*h-f,this.update()}pinchZoom(t,s,e,i,h){let o=this.offset.z;this.offset.z=Math.max(.1,Math.min(3,this.offset.z*h)),o=this.offset.z/o;const n=this.board.getBoundingClientRect(),f=n.width/2+n.left-(t+e)/2,a=n.height/2+n.top-(s+i)/2;this.offset.x+=f*o-f,this.offset.y+=a*o-a,this.update()}screen2World(t){return{x:Math.round((t.x-this.offset.x)/this.offset.z-this.margin.left),y:Math.round((t.y-this.offset.y)/this.offset.z-this.margin.top)}}world2Screen(t){return{x:Math.round(this.offset.x+t.x*this.offset.z-this.margin.left),y:Math.round(this.offset.y+t.y*this.offset.z-this.margin.top)}}center(t={x:0,y:0},s="none",e="hard",i=null){"smooth"==e&&(this.board.style.transition="transform 1s",setInterval((()=>{this.board.style.removeProperty("transition")}),1e3)),"reset"==s?this.offset.z=1:"focus"==s&&(this.offset.z=this.size.height/(i.height+i.margin)),this.offset.x=-t.x*this.offset.z+this.size.center.x,this.offset.y=-t.y*this.offset.z+this.size.center.y,this.update()}centerZoom(){this.offset.z=1,this.update()}focusBounds(){const t=this.getBounds(this.nodes.get("*").filter((t=>t.parent==this.nodes.parent))),s={x:this.size.width/t.width,y:this.size.height/t.height,avg:function(){return(this.x+this.y)/2}};this.offset.z=t.isZero()?1:Math.min(Math.max(s.avg(),.3),1),this.offset.x=-t.x*this.offset.z+this.size.center.x,this.offset.y=-t.y*this.offset.z+this.size.center.y,this.update()}getBounds(t){const s={left:1/0,right:-1/0,top:1/0,bottom:-1/0,x:0,y:0,width:0,height:0,isZero:function(){for(let t in this)if("isZero"!==t&&Math.abs(this[t])>Number.EPSILON)return!1;return!0}};return t.forEach((t=>{s.left=Math.min(t.transform.x-t.transform.w/2,s.left),s.top=Math.min(t.transform.y-t.transform.h/2,s.top),s.right=Math.max(t.transform.x+t.transform.w/2,s.right),s.bottom=Math.max(t.transform.y+t.transform.h/2,s.bottom)})),s.width=s.right-s.left,s.height=s.bottom-s.top,s.x=s.left+s.width/2,s.y=s.top+s.height/2,s}clear(){this.board.innerHTML="",this.links.del("*"),this.nodes.del("*")}update(){this.board.style.transform=`translate(${this.offset.x}px, ${this.offset.y}px) scale(${this.offset.z})`}redraw(){this.container.style.display="none";this.container.offsetHeight;this.container.style.display="block"}}
@@ -72,6 +72,7 @@
72
72
  </div>
73
73
 
74
74
  <!-- Total Diagram library -->
75
+ <script type="text/javascript" src="../gremlin.js"></script>
75
76
  <script type="text/javascript" src="../render-node.js"></script>
76
77
  <script type="text/javascript" src="../render-link.js"></script>
77
78
  <script type="text/javascript" src="../manager-nodes.js"></script>
@@ -105,6 +105,7 @@
105
105
  </div>
106
106
 
107
107
  <!-- Total Diagram library -->
108
+ <script type="text/javascript" src="../gremlin.js"></script>
108
109
  <script type="text/javascript" src="../render-node.js"></script>
109
110
  <script type="text/javascript" src="../render-link.js"></script>
110
111
  <script type="text/javascript" src="../manager-nodes.js"></script>
@@ -114,6 +114,7 @@
114
114
  </div>
115
115
 
116
116
  <!-- Total Diagram library -->
117
+ <script type="text/javascript" src="../gremlin.js"></script>
117
118
  <script type="text/javascript" src="../render-node.js"></script>
118
119
  <script type="text/javascript" src="../render-link.js"></script>
119
120
  <script type="text/javascript" src="../manager-nodes.js"></script>
@@ -0,0 +1,349 @@
1
+ <!doctype html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta charset="utf-8">
6
+ <title>Total Diagram Demo</title>
7
+ <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
8
+ <meta http-equiv="Pragma" content="no-cache">
9
+ <meta http-equiv="Expires" content="0">
10
+ <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
11
+ <style>
12
+
13
+ html, body {
14
+ width: 100%;
15
+ height: 100%;
16
+ margin: 0;
17
+ }
18
+
19
+ #container {
20
+ position: relative;
21
+ margin: 0 auto;
22
+ display: block;
23
+ background-color: #060531;
24
+ width: 100%;
25
+ min-width: 640px;
26
+ height: 100%;
27
+ min-height: 480px;
28
+ -webkit-touch-callout: none;
29
+ -webkit-user-select: none;
30
+ -khtml-user-select: none;
31
+ -moz-user-select: none;
32
+ -ms-user-select: none;
33
+ user-select: none;
34
+ touch-action: none;
35
+ overflow: hidden;
36
+ font-family: Arial, sans-serif;
37
+ }
38
+
39
+ h3, p {
40
+ color: white;
41
+ text-align: center;
42
+ }
43
+
44
+ .node {
45
+ display: flex;
46
+ flex-direction: column;
47
+ position: absolute;
48
+ background-color: white;
49
+ border-radius: 8px;
50
+ border-bottom: 10px solid #f19331;
51
+ }
52
+
53
+ .node .titlebar {
54
+ color: white;
55
+ background-color: #f19331;
56
+ width: 100%;
57
+ height: 35px;
58
+ line-height: 35px;
59
+ text-align: center;
60
+ font-size: 16px;
61
+ font-weight: bold;
62
+ border-radius: 8px 8px 0 0;
63
+ }
64
+
65
+ .node .header {
66
+ color: #222;
67
+ text-align: left;
68
+ font-size: 14px;
69
+ margin: 12px 16px;
70
+ font-weight: bold;
71
+ }
72
+
73
+ .node .option {
74
+ color: #222;
75
+ background-color: #fff5f5;
76
+ text-align: left;
77
+ font-size: 14px;
78
+ margin: 8px 16px 0 16px;
79
+ padding: 10px;
80
+ border-radius: 8px;
81
+ }
82
+
83
+ .socket {
84
+ position: absolute;
85
+ width: 8px;
86
+ height: 8px;
87
+ background-color: #fff5f5;
88
+ border: 2px solid #f19331;
89
+ border-radius: 50%;
90
+ }
91
+
92
+ .link {
93
+ position: absolute;
94
+ left: 0;
95
+ top: 0;
96
+ overflow: visible;
97
+ z-index: -1;
98
+ }
99
+
100
+ .link path {
101
+ pointer-events: none;
102
+ fill: none;
103
+ stroke: #e88f56;
104
+ stroke-width: 2;
105
+ }
106
+
107
+ </style>
108
+ </head>
109
+ <body>
110
+ <!-- Main diagram container -->
111
+ <div id="container">
112
+ <h3>4: Navigation demo</h3>
113
+ <p>How to navigate (pan and zoom) using mouse.</p>
114
+ </div>
115
+
116
+ <!-- Total Diagram library -->
117
+ <script type="text/javascript" src="../gremlin.js"></script>
118
+ <script type="text/javascript" src="../render-node.js"></script>
119
+ <script type="text/javascript" src="../render-link.js"></script>
120
+ <script type="text/javascript" src="../manager-nodes.js"></script>
121
+ <script type="text/javascript" src="../manager-links.js"></script>
122
+ <script type="text/javascript" src="../render.js"></script>
123
+
124
+ <script>
125
+
126
+ // Socket definition
127
+
128
+ class SocketPoint {
129
+
130
+ constructor(args) {
131
+
132
+ // Store parent
133
+ this.parent = args.parent;
134
+
135
+ // Main element
136
+ this.element = document.createElement('div');
137
+ this.element.classList.add('socket');
138
+ args.parent.element.append(this.element);
139
+
140
+ // Position
141
+ this.position = args.pos;
142
+ if ('top' in args.pos) this.element.style.top = args.pos.top + 'px';
143
+ if ('left' in args.pos) this.element.style.left = args.pos.left + 'px';
144
+ if ('right' in args.pos) this.element.style.right = args.pos.right + 'px';
145
+
146
+ }
147
+
148
+ getWorldPosition() {
149
+ let x = 0;
150
+ let y = this.parent.transform.y - (this.parent.transform.h / 2) + this.position.top + 5;
151
+ if ('left' in this.position) {
152
+ x = this.parent.transform.x - (this.parent.transform.w / 2) + this.position.left + 5;
153
+ }
154
+ else if ('right' in this.position) {
155
+ x = this.parent.transform.x + (this.parent.transform.w / 2) + this.position.right + 5;
156
+ }
157
+ return {x, y};
158
+ }
159
+
160
+ }
161
+
162
+ // More advanced node definition
163
+
164
+ class NodeMoreAdvanced extends TotalDiagramNode {
165
+
166
+ constructor(args) {
167
+ super(args);
168
+
169
+ // Class
170
+ this.element.classList.add('node');
171
+
172
+ // Title bar
173
+ this.titlebar = document.createElement('div');
174
+ this.titlebar.classList.add('titlebar');
175
+ this.titlebar.innerText = args.title || 'Node';
176
+ this.element.append(this.titlebar);
177
+
178
+ // Header
179
+ this.header = document.createElement('div');
180
+ this.header.classList.add('header');
181
+ this.header.innerText = args.header || 'Header';
182
+ this.element.append(this.header);
183
+
184
+ // Options
185
+ if ('options' in args) {
186
+ args.options.forEach(text => {
187
+ const option = document.createElement('div');
188
+ option.classList.add('option');
189
+ option.innerHTML = text;
190
+ this.element.append(option);
191
+ });
192
+ }
193
+
194
+ // Sockets
195
+ this.socketIn = new SocketPoint({
196
+ parent: this,
197
+ pos: {left: -5, top: 11}
198
+ });
199
+ this.socketOut = new SocketPoint({
200
+ parent: this,
201
+ pos: {right: -5, top: 11}
202
+ });
203
+
204
+ // Size
205
+ this.setSize({width: 200, height: 300});
206
+
207
+ // Update
208
+ this.update();
209
+ }
210
+ }
211
+
212
+ // Bezier curve link definition
213
+
214
+ class LinkBezier extends TotalDiagramLink {
215
+
216
+ constructor(args) {
217
+ super(args);
218
+
219
+ // SVG DOM element
220
+ this.path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
221
+ this.element.appendChild(this.path);
222
+
223
+ // Curvature
224
+ this.curvature = 0.5;
225
+
226
+ // Update
227
+ this.update();
228
+ }
229
+
230
+ update() {
231
+
232
+ // Start & end position
233
+ const startPos = this.start.socketOut.getWorldPosition();
234
+ const endPos = this.end.socketIn.getWorldPosition();
235
+ let x1 = 0;
236
+ let y1 = 0;
237
+ let x2 = 0;
238
+ let y2 = 0;
239
+
240
+ // Left -> right
241
+ if (this.start.transform.x <= this.end.transform.x) {
242
+ x1 = startPos.x;
243
+ y1 = startPos.y;
244
+ x2 = endPos.x;
245
+ y2 = endPos.y;
246
+ }
247
+
248
+ // Right -> left
249
+ else {
250
+ x1 = endPos.x;
251
+ y1 = endPos.y;
252
+ x2 = startPos.x;
253
+ y2 = startPos.y;
254
+ }
255
+
256
+ // Calculate & render
257
+ const hx1 = x1 + Math.abs(x2 - x1) * this.curvature;
258
+ const hx2 = x2 - Math.abs(x2 - x1) * this.curvature;
259
+ const angle = Math.atan2(y2 - y1, ((x2 + hx2) / 2) - ((x1 + hx1) / 2));
260
+ this.path.setAttribute('d', `M ${x1} ${y1} C ${hx1} ${y1} ${hx2} ${y2} ${x2} ${y2}`);
261
+ }
262
+
263
+ }
264
+
265
+
266
+ function initEvents(render) {
267
+ const container = document.querySelector('#container');
268
+ let state = 0;
269
+
270
+ container.addEventListener('mousedown', (event) => {
271
+ state = 1;
272
+ });
273
+
274
+ container.addEventListener('mousemove', (event) => {
275
+ if (state == 1) {
276
+ render.pan(event.movementX, event.movementY);
277
+ }
278
+ });
279
+
280
+ container.addEventListener('mouseup', (event) => {
281
+ render.damp();
282
+ state = 0;
283
+ });
284
+
285
+ container.addEventListener('mousewheel', (event) => {
286
+ event.preventDefault();
287
+ render.zoom(event.pageX, event.pageY, event.deltaY, 1000);
288
+ });
289
+
290
+ }
291
+
292
+ // Start
293
+
294
+ window.onload = function() {
295
+
296
+ // Create managers
297
+ const render = new TotalDiagramRenderHTML5({
298
+ container: document.getElementById('container'),
299
+ nodes: new TotalDiagramNodesManager(),
300
+ links: new TotalDiagramLinksManager()
301
+ });
302
+
303
+ initEvents(render);
304
+
305
+ // Create first node
306
+ const node1 = new NodeMoreAdvanced({
307
+ title: 'Node #1',
308
+ header: 'Options for node 1:',
309
+ options: [
310
+ '<b>Option 1:</b> Hello',
311
+ '<b>Option 2:</b> World',
312
+ '<b>Option 3:</b> Lorem',
313
+ '<b>Option 4:</b> Ipsum'
314
+ ],
315
+ x: -200,
316
+ y: -50
317
+ });
318
+ render.nodes.add(node1);
319
+
320
+ // Create second node
321
+ const node2 = new NodeMoreAdvanced({
322
+ title: 'Node #2',
323
+ header: 'Options for node 2:',
324
+ options: [
325
+ '<b>Option 1:</b> Hello',
326
+ '<b>Option 2:</b> World',
327
+ '<b>Option 3:</b> Lorem',
328
+ '<b>Option 4:</b> Ipsum'
329
+ ],
330
+ x: 200,
331
+ y: 50
332
+ });
333
+ render.nodes.add(node2);
334
+
335
+ // Create link between them
336
+ const link1 = new LinkBezier({
337
+ start: node1,
338
+ end: node2
339
+ });
340
+ render.links.add(link1);
341
+
342
+ // Move to view central 0,0
343
+ render.center();
344
+
345
+ };
346
+ </script>
347
+
348
+ </body>
349
+ </html>