如何在cytoscape.js 2.6版本中添加自定义布局

磁石4000

API文档(http://js.cytoscape.org/#extensions/api)指出cytoscape( type, name, extension )谁应该注册扩展。它在中起作用,v2.4但在中不再起作用v2.6现在正确的方法是什么?

编辑:这是我的工作

;(function($$){ 'use strict';

  var defaults = {
    fit: true, // whether to fit the viewport to the graph
    padding: 30, // the padding on fit
    startAngle: 3/2 * Math.PI, // the position of the first node
    counterclockwise: false, // whether the layout should go counterclockwise/anticlockwise (true) or clockwise (false)
    minNodeSpacing: 10, // min spacing between outside of nodes (used for radius adjustment)
    boundingBox: undefined, // constrain layout bounds; { x1, y1, x2, y2 } or { x1, y1, w, h }
    avoidOverlap: true, // prevents node overlap, may overflow boundingBox if not enough space
    height: undefined, // height of layout area (overrides container height)
    width: undefined, // width of layout area (overrides container width)
    concentric: function(node){ // returns numeric value for each node, placing higher nodes in levels towards the centre
      return node.degree();
    },
    levelWidth: function(nodes){ // the variation of concentric values in each level
      return nodes.maxDegree() / 4;
    },
    animate: false, // whether to transition the node positions
    animationDuration: 500, // duration of animation in ms if enabled
    ready: undefined, // callback on layoutready
    stop: undefined // callback on layoutstop
  };

  function ConcentricLayout( options ){
    console.log('INIT');
    this.options = $$.util.extend({}, defaults, options);
  }

  ConcentricLayout.prototype.run = function(){
    console.log('RUNNING');
    // Run code
  };

  $$('layout', 'customconcentric', ConcentricLayout);

})( cytoscape );

以及我如何使用它

var cy = cytoscape({
    container: document.getElementById('cy'),

    boxSelectionEnabled: false,
    autounselectify: true,

    elements: p,

    layout: {
        name: 'null',
        stop: function() {
            cy.elements('node.group').forEach(function( ele ){
                var eles = ele.children();
                eles.layout({
                    name: 'customgrid',
                    fit: false,
                    avoidOverlapPadding: 0,
                    columns: 2
                });
            });
            cy.elements('node.machine').forEach(function( ele ){
                var elesleft = ele.children('node.mod');
                var elesright = ele.children('node.group');
                var descendants = elesright.descendants();
                if (elesleft.length > 0) {
                    var relpos = getRelativePositions(descendants);
                    elesright.forEach(function( ele ){
                        ele.relativePosition('x', 200);
                    });
                    setRelativePositions(relpos, cy);
                    elesleft.layout({
                        name: 'customgrid',
                        fit: false,
                        avoidOverlapPadding: 0,
                        columns: 1
                    });
                }
            });
            cy.elements('node.machine, node.env').layout({
                name: 'customconcentric',
                fit: true
            });
        }
    }

});

在2.4.9中,我在浏览器的JavaScript控制台中看到了这一点。

cytoscape.layout.custom.js:41 INIT
cytoscape.layout.custom.js:46 RUNNING

对于2.6.2,什么也没有发生。

Maxkfranz

注册API很好。您所依赖的私有对象不可访问:

this.options = $$.util.extend({}, defaults, options);

如果您希望代码与较新版本兼容,请仅在文档中引用公共API:http : //js.cytoscape.org

使用适当的调试器,例如在Chrome中当您引用不存在的对象或导致异常时,调试器应向您显示一条错误消息。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档