有没有办法将自定义映射器添加到新的cytoscape.js?如何在cytoscape.js中创建自定义样式映射?
我知道有数据(nodeKey),但是它使用nodeKey的de novo值。我可以设置我自己的地图吗?
谢谢!
有没有办法将自定义映射器添加到新的cytoscape.js?如何在cytoscape.js中创建自定义样式映射?
我知道有数据(nodeKey),但是它使用nodeKey的de novo值。我可以设置我自己的地图吗?
谢谢!
这是我的自定义映射器:
/* 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 [n型]
自定义映射器一般来说太贵,所以它们在Cytoscape.js中不受支持。良好的表现是我们对图书馆最重要的要求之一。
如果您要描述您正在寻找的那种映射,那么今天就可以使用API,或者我们可以开展一些满足您需求的工作。谢谢!
您好@maxkfranz为 “形状” 的节点属性值产生的,我'寻找一个简单的方法来绘制沿着'var = {a:“六边形”,b:“三角形”,c:“椭圆”}'线条的值,这些边缘包含'type =''有可能吗?离散地图以这种方式,还是我必须分别处理这些情况?谢谢! –
@JD。您不需要为离散映射使用映射器。 'data()'语法实际上只是Cytoscape Web的一个结果,但最好使用CSS样式(即在init中指定的样式表中)。您可以将元素添加到元素以轻松设置元素的样式,或者可以使用基于数据的更复杂的选择器。请参阅http://cytoscape.github.io/cytoscape.js/#core/initialisation和http://cytoscape.github.io/cytoscape.js/#selectors – maxkfranz