Author: clopes
Date: 2011-09-01 12:42:44 -0700 (Thu, 01 Sep 2011)
New Revision: 26681
Modified:
cytoscapeweb/trunk/cytoscapeweb/default.properties
cytoscapeweb/trunk/cytoscapeweb/html-template/js/tests.js
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/GraphProxy.as
Log:
Fixed issue #2576: When adding field, default value null is replaced by 0
Modified: cytoscapeweb/trunk/cytoscapeweb/default.properties
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/default.properties 2011-09-01 19:41:51 UTC
(rev 26680)
+++ cytoscapeweb/trunk/cytoscapeweb/default.properties 2011-09-01 19:42:44 UTC
(rev 26681)
@@ -1,3 +1,3 @@
-build.version=0.7.4
+build.version=0.7.5
FLEX_HOME=/Applications/Adobe Flex Builder 3 Plug-in/sdks/3.2.0/
\ No newline at end of file
Modified: cytoscapeweb/trunk/cytoscapeweb/html-template/js/tests.js
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/html-template/js/tests.js 2011-09-01
19:41:51 UTC (rev 26680)
+++ cytoscapeweb/trunk/cytoscapeweb/html-template/js/tests.js 2011-09-01
19:42:44 UTC (rev 26681)
@@ -902,8 +902,16 @@
same(Math.round(n.y), 45, "New node - y");
ok(n.size > style.nodes.size.continuousMapper.minValue + n.borderWidth,
"Node size updated");
same(vis.nodes().length, ++count, "New nodes length");
+ });
+
+ test("Add Node: accepts null number attribute", function() {
+ vis.addDataField("nodes", { name: "null_number_attr", type: "number"
});
- // TODO: test duplicate ID (FireFox does not catch Flash exceptions...)
+ var n = vis.addNode({ label: "New Node - null number",
null_number_attr: null });
+ same(n.data.null_number_attr, null, "New node added: 'null_number_attr'
still null");
+
+ vis.removeElements([n], true);
+ vis.removeDataField("nodes", "null_number_attr");
});
test("Add Edge", function() {
@@ -930,6 +938,18 @@
same(vis.edges().length, ++count, "New edges length");
});
+ test("Add Edge: accepts null number attribute", function() {
+ vis.addDataField("edges", { name: "null_number_attr", type: "number"
});
+
+ var nodes = vis.nodes();
+ var src = nodes[0], tgt = nodes[3];
+ var e = vis.addEdge({ source: src.data.id, target: tgt.data.id,
null_number_attr: null });
+ same(e.data.null_number_attr, null, "New edge added: 'null_number_attr'
still null");
+
+ vis.removeElements([e], true);
+ vis.removeDataField("edges", "null_number_attr");
+ });
+
test("Remove Edges", function() {
var nodes = vis.nodes(), edges = vis.edges();
var original = edges;
@@ -1180,15 +1200,23 @@
});
// 2: Add new field to nodes only:
- vis.addDataField("nodes", { name: "new_node_attr_1", type: "number",
defValue: " 0.234" /*Should convert string to number*/ })
- .addDataField("nodes", { name: "new_node_attr_2", type: "boolean" })
- .addDataField("nodes", { name: "new_node_attr_3", type: "int" });
+ vis.addDataField("nodes", { name: "new_node_attr_1", type: "number",
defValue: 0.234 })
+ .addDataField("nodes", { name: "new_node_attr_2", type: "number" })
+ .addDataField("nodes", { name: "new_node_attr_3", type: "boolean",
defValue: true })
+ .addDataField("nodes", { name: "new_node_attr_4", type: "boolean",
defValue: null })
+ .addDataField("nodes", { name: "new_node_attr_5", type: "int" })
+ .addDataField("nodes", { name: "new_node_attr_6", type: "string",
defValue: "DEF_VAL" })
+ .addDataField("nodes", { name: "new_node_attr_7", type: "string" });
nodes = vis.nodes();
$.each(nodes, function(i, el) {
same(el.data["new_node_attr_1"], 0.234, "New field [number]
added to nodes ("+el.data.id+")");
- same(el.data["new_node_attr_2"], false, "New field [boolean]
added to nodes ("+el.data.id+")");
- same(el.data["new_node_attr_3"], 0, "New field [int] added to
nodes ("+el.data.id+")");
+ same(el.data["new_node_attr_2"], null, "New field [number]
added to nodes ("+el.data.id+")");
+ same(el.data["new_node_attr_3"], true, "New field [boolean]
added to nodes ("+el.data.id+")");
+ same(el.data["new_node_attr_4"], false, "New field [boolean]
added to nodes ("+el.data.id+")");
+ same(el.data["new_node_attr_5"], 0, "New field [int] added to
nodes ("+el.data.id+")");
+ same(el.data["new_node_attr_6"], "DEF_VAL", "New field [string]
added to nodes ("+el.data.id+")");
+ same(el.data["new_node_attr_7"], null, "New field [string]
added to nodes ("+el.data.id+")");
});
edges = vis.edges();
$.each(edges, function(i, el) {
Modified:
cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/GraphProxy.as
===================================================================
--- cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/GraphProxy.as
2011-09-01 19:41:51 UTC (rev 26680)
+++ cytoscapeweb/trunk/cytoscapeweb/src/org/cytoscapeweb/model/GraphProxy.as
2011-09-01 19:42:44 UTC (rev 26681)
@@ -345,15 +345,22 @@
if (schema.getFieldById(name) == null) {
// This field is not duplicated...
- var v:*;
+ if (defValue == null) {
+ switch (type) {
+ case DataUtil.BOOLEAN: defValue = false; break;
+ case DataUtil.INT: defValue = 0; break;
+ default: defValue = null;
+ }
+ } else {
+ try {
+ defValue =
ExternalObjectConverter.normalizeDataValue(defValue, type, null);
+ } catch (err:Error) {
+ throw new CWError("Cannot add data field
'"+name+"':" + err.message,
+
ErrorCodes.INVALID_DATA_CONVERSION);
+ }
+ }
- if (!(defValue == null && type === DataUtil.STRING))
- v = DataUtil.parseValue(defValue, type);
-
- if (isNaN(v) && (type === DataUtil.INT || type ===
DataUtil.NUMBER))
- throw new Error("Attempt to convert default value
'"+defValue+"' to NUMBER while creating data field");
-
- var field:DataField = new DataField(name, type, v);
+ var field:DataField = new DataField(name, type, defValue);
schema.addField(field);
added = true;
@@ -362,6 +369,9 @@
for each (var ds:DataSprite in items) {
ds.data[field.name] = field.defaultValue;
}
+ } else {
+ throw new CWError("Cannot add data field '"+name+"':
data field name already existis",
+ ErrorCodes.INVALID_DATA_CONVERSION);
}
}
@@ -891,8 +901,13 @@
v = data[k];
f = schema.getFieldById(k);
+ if (f == null) {
+ throw new CWError("Undefined data field: '"+k+"'",
+ ErrorCodes.INVALID_DATA_CONVERSION);
+ }
+
try {
- v = ExternalObjectConverter.normalizeDataValue(v, f.type);
+ v = ExternalObjectConverter.normalizeDataValue(v, f.type,
f.defaultValue);
} catch (err:Error) {
throw new CWError("Invalid data value ('"+k+"'):
"+err.message,
ErrorCodes.INVALID_DATA_CONVERSION);
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.