From a205dad5217405592bdf67d6c769a3694d6a343c Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Tue, 18 Nov 2014 23:35:51 +0200 Subject: model/core: create_node + spelling Tried using it, fixed spelling and added node creator that doesn't override id. Failed to use it - d3 doesn't like objects. Need to figure that out. --- src/model/core.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src/model/core.js') diff --git a/src/model/core.js b/src/model/core.js index 43a87b5d..b1758cd1 100644 --- a/src/model/core.js +++ b/src/model/core.js @@ -19,14 +19,23 @@ define([], function() { function Node() { } + Node.prototype.selected = function() { + return this.state == 'chosen' || this.state == 'enter' || this.state == 'exit'; + } + function create_node__set_random_id(node_spec) { + if (node_spec.id) { + console.log('create_node__set_random_id: bug: given id'); + } + node_spec.id = random_id(); + return create_node(node_spec); + } + + function create_node(node_spec) { if (undefined == node_spec) { node_spec = {}; } - var ret = new Node(); - ret.id = random_id(); - ret.name = node_spec.name; ret.type = node_spec.type; ret.state = node_spec.state; @@ -35,6 +44,9 @@ define([], function() { ret.start = node_spec.start; ret.end = node_spec.end; + ret.x = node_spec.x; + ret.y = node_spec.y; + console.log(ret); return ret; } @@ -45,13 +57,13 @@ define([], function() { } /** - * determine if nodes are equal by ID + * determine if nodes are equal by name * * @param other_node * @returns {Boolean} */ - Node.prototype.equlas_by_id = function(other) { - ret = this.id.toLowerCase() == other.id.toLowerCase(); + Node.prototype.equal_by_name = function(other) { + ret = this.name.toLowerCase() == other.name.toLowerCase(); if (false == ret) { console.debug(this.id + ' != ' + other.id); } @@ -68,12 +80,13 @@ define([], function() { * @param other_node * @returns {Boolean} */ - Link.prototype.equlas_by_id = function(other) { + Link.prototype.equal_by_id = function(other) { return this.id.toLowerCase() == other.id.toLowerCase(); } return { random_node_name : random_node_name, + create_node: create_node, create_node__set_random_id : create_node__set_random_id, create_link__set_random_id : create_link__set_random_id, }; -- cgit v1.3.1