From 637d06d6c5ac02f309c1c5c8efcf33204d1f369d Mon Sep 17 00:00:00 2001 From: txlabs Date: Sun, 20 Jun 2021 23:29:29 +0100 Subject: [PATCH] Readme.md fixes and styles --- LICENSE | 17 ++++ README.md | 129 +++++++++++++++++++++++++++-- src/components/Edge.vue | 16 ++-- src/components/Markers.vue | 4 +- src/demo/Benchmark.vue | 99 ++++++++++++++++++++++ src/demo/Demo.vue | 22 +++-- src/demo/{Groups.vue => Ports.vue} | 0 7 files changed, 263 insertions(+), 24 deletions(-) create mode 100644 LICENSE create mode 100644 src/demo/Benchmark.vue rename src/demo/{Groups.vue => Ports.vue} (100%) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..969d061 --- /dev/null +++ b/LICENSE @@ -0,0 +1,17 @@ +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 2829e86..b1f120f 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,8 @@ -------- - # vnodes Vue bare components to create svg interactive graphs, diagrams or node visual tools. -### Demo +### Demo https://txlabs.github.io/vnodes/ @@ -25,8 +23,8 @@ https://txlabs.github.io/vnodes/ import { Screen, Node, Edge, graph } from 'vnodes' export default { components: { - Screen, - Node, + Screen, + Node, Edge } data () { @@ -45,7 +43,120 @@ export default { ## Components -- Screen - svg wrapper with zoom, panning and others -- Node - svg element that contain html -- Edge - connect nodes using svg lines -- Group - surround nodes with a container +Vnodes components are independent and can be used anywhere in your project. + +### Screen + +Svg wrapper with zoom, panning and other features. + +```html + + + +``` + +### Node + +Html wrapper for svg with additional features like, dragging and fitting contents. + + +```html + + +

My First Node!

+ + +``` + +### Edge + +Connects nodes using svg lines + +```html + +``` + +Edges data require node references `{ from: String|Object, to: String:Object }`, if nodes are refered by id(String) edges must also include an array with those `nodes` as property. + + +Edges can take **anchor** information to offset their position relative to a node, + +```html + +``` + anchors format can be: + +* String `'center', 'left', 'right', 'top', 'top-left', 'top-right', 'bottom', 'bottom-left', 'bottom-right', 'cirlce', 'rect'` + +* Object `{ x?:Number | String, y?: Number | String, align?: String, snap?: String }` + +Examples of valid anchor values: + +```js +null +{ x: 0, y: 0} // snaps to top left corner +{ x: 10, y: 0 } // offsets x,y by 10 pixels +{ x: '50%', '50%' } // snaps to center +{ x: '50%', '50%', snap: 'rect' } // offsets around node rectangle +{ align: 'bottom-right' } // same as { x: '100%', y: '100% } +'center' // same as { x: '50%', y: '50%' } +'top-left' // same as { x: 0, y: 0 } +'circle' // offsets to circle with radius node.width/2 +'rect' // offsets around node rectangle +``` + +### Group + +Surround nodes with a visible container, allows dragging multiple nodes, + +```html + +

Group Label

+
+``` + + +### Port + +Helper component to offset an edge anchor to a specific position inside the html of a node. + +### graph + +Graph utils that can be used to store edges and nodes. +Contains utility methods to build graphs, position nodes remove and create nodes, edges etc. + +## Styling + +The simplest way to style nodes / edges is using CSS + +### Markers + +TODO + +```css + +``` \ No newline at end of file diff --git a/src/components/Edge.vue b/src/components/Edge.vue index efe142b..a11644f 100644 --- a/src/components/Edge.vue +++ b/src/components/Edge.vue @@ -14,12 +14,15 @@ export default { }, nodes: { // graph nodes reference type: Array, - required: true } }, computed: { - fromNode: vm => vm.nodes.find(n => n.id === vm.data.from), - toNode: vm => vm.nodes.find(n => n.id === vm.data.to), + fromNode: vm => typeof vm.data.from === 'string' + ? vm.nodes.find(n => n.id === vm.data.from) + : vm.data.from, + toNode: vm => typeof vm.data.to === 'string' + ? vm.nodes.find(n => n.id === vm.data.to) + : vm.data.to, fromAnchor: vm => vm.parseAnchor(vm.data.fromAnchor, vm.fromNode), toAnchor: vm => vm.parseAnchor(vm.data.toAnchor, vm.toNode), @@ -29,7 +32,7 @@ export default { let x2 = this.toNode.x + (this.toAnchor.x || 0) let y2 = this.toNode.y + (this.toAnchor.y || 0) - if (this.fromAnchor.snap) { + if (this.fromAnchor?.snap) { if (this.fromAnchor.snap === 'circle') { const radius = Math.max(this.fromNode.width, this.fromNode.height) / 2 const vec = new Victor(x2 - x1, y2 - y1).normalize() @@ -44,7 +47,7 @@ export default { } } } - if (this.toAnchor.snap) { + if (this.toAnchor?.snap) { if (this.toAnchor.snap === 'circle') { const radius = Math.max(this.toNode.width, this.toNode.height) / 2 const vec = new Victor(x2 - x1, y2 - y1).normalize() @@ -95,6 +98,7 @@ export default { * } */ parseAnchor(anchor, node) { + if (!anchor) return { x: 0, y: 0 } let snap = anchor.snap let align = anchor.align let pos = { x: anchor.x || 0, y: anchor.y || 0 } @@ -162,7 +166,7 @@ export default { \ No newline at end of file diff --git a/src/demo/Demo.vue b/src/demo/Demo.vue index f48fc7a..b4fa9c0 100644 --- a/src/demo/Demo.vue +++ b/src/demo/Demo.vue @@ -1,28 +1,36 @@ diff --git a/src/demo/Groups.vue b/src/demo/Ports.vue similarity index 100% rename from src/demo/Groups.vue rename to src/demo/Ports.vue