0

我有一个小的 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 中的节点属性)“系统”,但我无法让它工作。这是代码:

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 当前设置为“label”)被设置为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,但真正应该做的是retrieve item.neo4j_data.System

我是否误解了这一点,或者它应该如何工作?

TIA-e

4

1 回答 1

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方法

*更新我*

重新定义format方法的代码补丁将解决此问题:

format = that.mappings.label.format || function(item) {
              return typeof item === 'string' ? item : item.label;
            };
于 2015-06-27T01:06:15.907 回答