有没有办法将自定义映射器添加到新的cytoscape.js?
我知道有数据(nodeKey),但是它使用了nodeKey的值de novo。我可以设置自己的映射吗?
谢谢!
答案 0 :(得分:0)
自定义映射器通常过于昂贵,因此Cytoscape.js不支持它们。良好的性能是我们对图书馆的最高要求之一。
如果您要描述您正在寻找的那种映射,那么今天可能会使用API,或者我们可以根据您的需求开展工作。谢谢!
答案 1 :(得分:0)
这是我的自定义映射器:
/* Converts element attributes to their appropriate mapped values
* Any non-matching attributes will be matched to the "other" mapping
* if exists
* data: data
* elementType: nodes or edges
* attr: some key under data.nodes[i].data
* mapping: obj mapping oldVal: newVal for attr
* (toType): new values will be put into this attr, if attr
* shouldn't be touched
*/
function mapAttr(elementType, attr, mapping, toType){
for(var i=0; i < data[elementType].length; i++){
element = data[elementType][i]['data'][attr];
toType = toType ? toType : attr;
if( mapping[element] ){
data[elementType][i]['data'][toType] = mapping[element];
}else if(mapping['other']){
data[elementType][i]['data'][toType] = mapping['other'];
}
}
}
示例:
var nodeShapeMapper = {
Rearrangement: "hexagon",
Gene: "octagon",
Molecule: "triangle",
other: "ellipse"
};
mapAttr('nodes', 'ntype', nodeShapeMapper, 'shape');
根据nodeShapeMapper [ntype]
生成“shape”节点属性的值