新しい cytoscape.js にカスタム マッパーを追加する方法はありますか?
data(nodeKey) があることは知っていますが、それは nodeKey の値を de novo で使用します。独自のマッピングを設定できますか?
ありがとう!
新しい cytoscape.js にカスタム マッパーを追加する方法はありますか?
data(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[ntype] に従って「shape」ノード属性の値が生成されます。
カスタム マッパーは一般に高価すぎるため、Cytoscape.js ではサポートされていません。優れたパフォーマンスは、ライブラリの最重要要件の 1 つです。
探しているマッピングの種類を説明していただければ、現在の API で可能かもしれませんし、お客様のニーズに合ったものを見つけられるかもしれません。ありがとう!