0

新しい cytoscape.js にカスタム マッパーを追加する方法はありますか?

data(nodeKey) があることは知っていますが、それは nodeKey の値を de novo で使用します。独自のマッピングを設定できますか?

ありがとう!

4

2 に答える 2

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」ノード属性の値が生成されます。

于 2013-08-21T21:14:21.720 に答える
0

カスタム マッパーは一般に高価すぎるため、Cytoscape.js ではサポートされていません。優れたパフォーマンスは、ライブラリの最重要要件の 1 つです。

探しているマッピングの種類を説明していただければ、現在の API で可能かもしれませんし、お客様のニーズに合ったものを見つけられるかもしれません。ありがとう!

于 2013-08-20T16:40:32.343 に答える