我有一点Neo图:
match (f) optional match (f)-[r]-() delete f, r;
merge (DMSrc:DMSys { Org: 'UNK-1', System: 'UNK' }) merge (DMDst:DMSys { Organization: 'UNK-0', System: 'Peoplesoft' }) merge (f:DMFile { Name: 'BAL'}) merge (DMSrc)-[:Provides]->(f)-[:Receives]->(DMDst);
merge (DMSrc:DMSys { Org: 'UNK-2', System: 'Oracle GL' }) merge (DMDst:DMSys { Organization: 'UNK-0', System: 'Peoplesoft' }) merge (f:DMFile { Name: 'BAL'}) merge (DMSrc)-[:Provides]->(f)-[:Receives]->(DMDst);
merge (DMSrc:DMSys { Org: 'X&X', System: 'Classic' }) merge (DMDst:DMSys { Organization: 'UNK-0', System: 'Peoplesoft' }) merge (f:DMFile { Name: 'BAL'}) merge (DMSrc)-[:Provides]->(f)-[:Receives]->(DMDst);
merge (DMSrc:DMSys { Org: 'UNK-3', System: 'Classic' }) merge (DMDst:DMSys { Organization: 'UNK-0', System: 'Peoplesoft' }) merge (f:DMFile { Name: 'BAL'}) merge (DMSrc)-[:Provides]->(f)-[:Receives]->(DMDst);
merge (DMSrc:DMSys { Org: 'UNK-4', System: 'Sun System' }) merge (DMDst:DMSys { Organization: 'UNK-0', System: 'Peoplesoft' }) merge (f:DMFile { Name: 'BAL'}) merge (DMSrc)-[:Provides]->(f)-[:Receives]->(DMDst);
merge (DMSrc:DMSys { Org: 'UNK-5', System: 'Oracle GL' }) merge (DMDst:DMSys { Organization: 'UNK-0', System: 'Peoplesoft' }) merge (f:DMFile { Name: 'BAL'}) merge (DMSrc)-[:Provides]->(f)-[:Receives]->(DMDst);
merge (DMSrc:DMSys { Org: 'UNK-6', System: 'Oracle GL' }) merge (DMDst:DMSys { Organization: 'UNK-0', System: 'Peoplesoft' }) merge (f:DMFile { Name: 'BAL'}) merge (DMSrc)-[:Provides]->(f)-[:Receives]->(DMDst);
merge (DMSrc:DMSys { Org: 'UNK-7', System: 'Direct (No Interface)' }) merge (DMDst:DMSys { Organization: 'UNK-0', System: 'Peoplesoft' }) merge (f:DMFile { Name: 'BAL'}) merge (DMSrc)-[:Provides]->(f)-[:Receives]->(DMDst);
我试图生成一个图表,其中节点使用数据属性(Neo中的节点属性)' System'但我无法使其工作。这是代码:
var neo = {
url: 'http://localhost:7474',
user: 'neo4j',
password: '***'
};
sigma.neo4j.cypher(neo,
'MATCH (n) OPTIONAL MATCH (n)-[r]->(m) RETURN n,r,m LIMIT 100',
{ container: 'graph' },
function (s) {
sigma.plugins.killDesign(s);
var design = sigma.plugins.design(s);
design.setStyles({
nodes: {
label: { by: 'neo4j_data.System' }
}
});
design.apply();
}
);
您注意到,与 data.something 的文档中的示例引用不同,我使用 neo4j_data.something ,因为我已经从调试中找到了对于从Neo4j中检索到的图形,这是节点属性似乎所在的位置。
显然应该访问此数据的位置是applyStyle
中定义的sigma.plugins.design.js
方法,特别是第534行,我在下面引用:
if (!(visualVar in self.originalVisualVariable[item.id])) {
// non-writable property
Object.defineProperty(self.originalVisualVariable[item.id], visualVar, {
enumerable: true,
value: item[visualVar]
});
}
可以看到标签的值(visualVar当前设置为"标签")设置为item[visualVar]
...但是item
包含:
{
Object
cam0:size: 8
cam0:x: 656.8832126805254
cam0:y: 191.29239469613498
color: "#000000"
id: "0"
label: "0"
neo4j_data: {
Org: "UNK-1"
System: "UNK"
}
neo4j_labels: Array[1]
read_cam0:size: 8
read_cam0:x: 61.38321268052541
read_cam0:y: 91.79239469613499
size: 1
x: 0.8536414597183466
y: 0.980357211548835
__proto__: Object
}
从中可以看出,虽然有一个属性item.label
,它应该真正做的是检索item.neo4j_data.System
。
我误解了这个,或者它应该如何运作?
TIA - e
答案 0 :(得分:1)
我错误地提取了节点属性的代码。后来有这个片段:
var newVal = o.styles[visualVar](item);
引用此(在update
方法中):
case 'label':
self.idx[key][val].styles.label = function(item) {
return format(byFn(item, key));
};
break;
其中:
format = that.mappings.label.format || function(item) {
return item.label;
};
byFn: function(item, key) { return strToObjectRef(item, key); };
function strToObjectRef(obj, str) {
// http://stackoverflow.com/a/6393943
return str.split('.').reduce(function(obj, i) { return obj[i] }, obj);
}
...在查看byFn
的输出时,我们发现它不是一个对象,它是一个字符串!因此默认format
方法中的取消引用失败。
因此声明我的风格使其有效:
design.setStyles({
nodes: {
label: {
by: 'neo4j_data.System',
format: function(item) { return item; }
}
}
});
所以这里的教训是使用Neo4j时需要format
方法
*更新I *
重新定义format
方法的代码补丁将解决此问题:
format = that.mappings.label.format || function(item) {
return typeof item === 'string' ? item : item.label;
};