From b712fc598a31104c3e1c18fe4210524c247f1dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Ni=C8=9Bu?= Date: Sat, 28 May 2016 22:31:47 +0300 Subject: [PATCH 1/4] Add edge weight --- addon/components/visjs-edge.js | 13 +++++++++++++ addon/components/visjs-network.js | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/addon/components/visjs-edge.js b/addon/components/visjs-edge.js index 144c93d..1c38fcb 100644 --- a/addon/components/visjs-edge.js +++ b/addon/components/visjs-edge.js @@ -24,6 +24,19 @@ export default VisJsChild.extend({ return `${this.get('from')}-${this.get('to')}`; }), + /** + * @public + * + * If set this defines edge's weight (thickness). + * @type {Int} + */ + value: undefined, + + valueChanged: Ember.observer('value', function() { + let container = this.get('containerLayer'); + container.updateEdgeValue(this.get('eId'), this.get('value')); + }), + arrowChanged: Ember.observer('arrows', function() { let container = this.get('containerLayer'); container.updateEdgeArrow(this.get('eId'), this.get('arrows')); diff --git a/addon/components/visjs-network.js b/addon/components/visjs-network.js index 8714829..4b04bf5 100644 --- a/addon/components/visjs-network.js +++ b/addon/components/visjs-network.js @@ -186,6 +186,10 @@ export default Ember.Component.extend(ContainerMixin, { simplifiedEdge.arrows = edge.get('arrows'); } + if (edge.get('value')) { + simplifiedEdge.value = edge.get('value'); + } + edges.add(simplifiedEdge); }, From 3cf5357b12a6ecc58cd1a3185b45c031938dcb13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Ni=C8=9Bu?= Date: Sun, 29 May 2016 01:29:43 +0300 Subject: [PATCH 2/4] Options for defining node size and edge color --- addon/components/visjs-edge.js | 13 +++++++++++++ addon/components/visjs-network.js | 8 ++++++++ addon/components/visjs-node.js | 13 +++++++++++++ 3 files changed, 34 insertions(+) diff --git a/addon/components/visjs-edge.js b/addon/components/visjs-edge.js index 1c38fcb..207e804 100644 --- a/addon/components/visjs-edge.js +++ b/addon/components/visjs-edge.js @@ -37,6 +37,19 @@ export default VisJsChild.extend({ container.updateEdgeValue(this.get('eId'), this.get('value')); }), + /** + * @public + * + * If set this defines edge's color + * @type {Int} + */ + color: undefined, + + colorChanged: Ember.observer('color', function() { + let container = this.get('containerLayer'); + container.updateEdgeColor(this.get('eId'), this.get('color')); + }), + arrowChanged: Ember.observer('arrows', function() { let container = this.get('containerLayer'); container.updateEdgeArrow(this.get('eId'), this.get('arrows')); diff --git a/addon/components/visjs-network.js b/addon/components/visjs-network.js index 4b04bf5..3951bd7 100644 --- a/addon/components/visjs-network.js +++ b/addon/components/visjs-network.js @@ -170,6 +170,10 @@ export default Ember.Component.extend(ContainerMixin, { simplifiedNode.y = node.get('posY'); } + if (node.get('value')) { + simplifiedNode.value = node.get('value'); + } + if (node.get('image')) { simplifiedNode.shape = 'image'; simplifiedNode.image = node.get('image'); @@ -190,6 +194,10 @@ export default Ember.Component.extend(ContainerMixin, { simplifiedEdge.value = edge.get('value'); } + if (edge.get('color')) { + simplifiedEdge.color = edge.get('color'); + } + edges.add(simplifiedEdge); }, diff --git a/addon/components/visjs-node.js b/addon/components/visjs-node.js index 1e3d64f..feea9f5 100644 --- a/addon/components/visjs-node.js +++ b/addon/components/visjs-node.js @@ -54,4 +54,17 @@ export default VisJsChild.extend({ container.updateNodeImage(this.get('nId'), this.get('image')); }) + /** + * @public + * + * If set, a value would be set to alter node's size + * @type {Number} + */ + value: false, + + valueChanged: Ember.observer('value', function() { + let container = this.get('containerLayer'); + container.updateNodeValue(this.get('nId'), this.get('value')); + }) + }); From 27e9e024dbb3ab169d382d71f5362b53327a8664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Ni=C8=9Bu?= Date: Sun, 29 May 2016 11:53:58 +0300 Subject: [PATCH 3/4] Attempt DataSet creation from given array(s) --- addon/components/visjs-network.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/addon/components/visjs-network.js b/addon/components/visjs-network.js index 3951bd7..6070189 100644 --- a/addon/components/visjs-network.js +++ b/addon/components/visjs-network.js @@ -15,8 +15,17 @@ export default Ember.Component.extend(ContainerMixin, { init() { this._super(...arguments); - this.set('nodes', new vis.DataSet([])); - this.set('edges', new vis.DataSet([])); + if(this.get('nodesSet') || this.get('nodesSet').size === 0) { + this.set('nodes', new vis.DataSet([])); + } else { + this.set('nodes', new vis.DataSet(this.get('nodesSet'))); + } + + if(this.get('edgesSet') || this.get('edgesSet').size === 0) { + this.set('edges', new vis.DataSet([])); + } else { + this.set('edges', new vis.DataSet(this.get('edgesSet'))); + } }, didInsertElement() { @@ -170,7 +179,7 @@ export default Ember.Component.extend(ContainerMixin, { simplifiedNode.y = node.get('posY'); } - if (node.get('value')) { + if (node.get('value') || node.get('value') === 0) { simplifiedNode.value = node.get('value'); } From 0d9da32745c803cb92b450e27d3d315dd059b595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Ni=C8=9Bu?= Date: Sun, 29 May 2016 12:48:28 +0300 Subject: [PATCH 4/4] Enable providing array of nodes and edges as component parameters --- addon/components/visjs-network.js | 20 +++++++++----------- addon/components/visjs-node.js | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/addon/components/visjs-network.js b/addon/components/visjs-network.js index 6070189..6c32b45 100644 --- a/addon/components/visjs-network.js +++ b/addon/components/visjs-network.js @@ -15,17 +15,8 @@ export default Ember.Component.extend(ContainerMixin, { init() { this._super(...arguments); - if(this.get('nodesSet') || this.get('nodesSet').size === 0) { - this.set('nodes', new vis.DataSet([])); - } else { - this.set('nodes', new vis.DataSet(this.get('nodesSet'))); - } - - if(this.get('edgesSet') || this.get('edgesSet').size === 0) { - this.set('edges', new vis.DataSet([])); - } else { - this.set('edges', new vis.DataSet(this.get('edgesSet'))); - } + this.set('nodes', new vis.DataSet([])); + this.set('edges', new vis.DataSet(this.get('edgesSet'))); }, didInsertElement() { @@ -41,6 +32,13 @@ export default Ember.Component.extend(ContainerMixin, { options ); + if(this.get('nodesSet') && this.get('edgesSet')) { + network.setData({ + nodes: this.get('nodesSet'), + edges: this.get('edgesSet') + }); + } + let _this = this; network.on('selectNode', (e) => { diff --git a/addon/components/visjs-node.js b/addon/components/visjs-node.js index feea9f5..91dbc14 100644 --- a/addon/components/visjs-node.js +++ b/addon/components/visjs-node.js @@ -52,7 +52,7 @@ export default VisJsChild.extend({ imageChanged: Ember.observer('image', function() { let container = this.get('containerLayer'); container.updateNodeImage(this.get('nId'), this.get('image')); - }) + }), /** * @public