Длина края макета Cytoscape Cola.js = визуализация корпуса текста

Я хочу установить длину ребра с весом в моем data.json.

Как и в демонстрации cytoscape-spread, длина ребра должна быть больше в зависимости от веса.

"data" : {
    "id" : "1965",
    "source" : "108",
    "target" : "149",
    "shared_name" : "A (interacts with) B",
    "shared_interaction" : "interacts with",
    "name" : "A (interacts with) B",
    "interaction" : "interacts with",
    "SUID" : 1965,
    "weight" : 342,
    "selected" : false
  },
  "selected" : false

Взвешивание — это подсчет того, как часто A и B стоят вместе в моем текстовом корпусе.

Я пробовал разные макеты, но не знаю, как я могу изменить положение, чтобы наибольший вес имел кратчайшее расстояние.

На данный момент я пытаюсь использовать макет "cose" и установить IdealEdgeLength: function( edge ){ return edge.data('weight');

  var options = {
  name: 'cose',

  // Called on `layoutready`
  ready: function(){},

  // Called on `layoutstop`
  stop: function(){},

  // Whether to animate while running the layout
  animate: true,


  // Whether to fit the network view after when done
  fit: true,

  // Padding on fit
  padding: 30,

  // Constrain layout bounds; { x1, y1, x2, y2 } or { x1, y1, w, h }
  boundingBox: undefined,

  // Randomize the initial positions of the nodes (true) or use existing positions (false)
  randomize: false,


  // Ideal edge (non nested) length
  idealEdgeLength: function( edge ){ return edge.data('weight'); },


};

cy.layout( options );

И cola.js edgeLength:

 name: 'cola',
            animate: true, // whether to show the layout as it's running
            refresh: 1, // number of ticks per frame; higher is faster but more jerky
            maxSimulationTime: 4000, // max length in ms to run the layout
            ungrabifyWhileSimulating: false, // so you can't drag nodes during layout
            fit: true, // on every layout reposition of nodes, fit the viewport
            padding: 0, // padding around the simulation
            boundingBox: undefined, // constrain layout bounds; { x1, y1, x2, y2 } or { x1, y1, w, h }

            // layout event callbacks
            ready: function(){}, // on layoutready
            stop: function(){}, // on layoutstop

            // positioning options
            randomize: false, // use random node positions at beginning of layout
            avoidOverlap: true, // if true, prevents overlap of node bounding boxes
            handleDisconnected: true, // if true, avoids disconnected components from overlapping
            nodeSpacing: function( node ){ return 10; }, // extra spacing around nodes
            flow: undefined, // use DAG/tree flow layout if specified, e.g. { axis: 'y', minSeparation: 30 }
            alignment: undefined, // relative alignment constraints on nodes, e.g. function( node ){ return { x: 0, y: 1 } }

            // different methods of specifying edge length
            // each can be a constant numerical value or a function like `function( edge ){ return 2; }`
            edgeLength: function( edge ){var len = parseInt(edge.data('weight')); return len; }, // sets edge length directly in simulation
            edgeSymDiffLength: undefined, // symmetric diff edge length in simulation
            edgeJaccardLength: undefined, // jaccard edge length in simulation

            // iterations of cola algorithm; uses default values on undefined
            unconstrIter: undefined, // unconstrained initial layout iterations
            userConstIter: undefined, // initial layout iterations with user-specified constraints
            allConstIter: undefined, // initial layout iterations with all constraints including non-overlap

            // infinite layout options
            infinite: false // overrides all other options for a forces-all-the-time mode

person ma-jo-ne    schedule 05.03.2017    source источник


Ответы (1)


Если вы хотите, чтобы узлы были сближены, если вес ребра высок, тогда длина ребра должна быть обратно пропорциональна весу, например. k / edge.data('weight') для некоторой константы k. Вам придется поэкспериментировать, чтобы найти, какое значение k лучше всего подходит для ваших данных.

Для примера взгляните на демо-источник Cola. Он использует именно этот подход, и ползунок просто меняет значение k.

http://js.cytoscape.org/demos/2ebdc40f1c2540de6cf0/

person maxkfranz    schedule 09.03.2017