scripts/modifiedCerebralJSLayout.js
/**
         * @function runCerebral - draw lines and draw text
         * @param {boolean} moveNodes - determine if we should reposition nodes or not.
         */
@function runCerebral - draw lines and draw text
@param {boolean} moveNodes - determine if we should reposition nodes or not.
@function runCerebral - draw lines and draw text @param { boolean } moveNodes - determine if we should reposition nodes or not .
function runCerebral (moveNodes) {
            var nodes = {};
            var extractLayers = (options.layers.length <= 0);
            var auxColors = ['#058DC7', '#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4'];
            var n = cy.nodes();
            for (let i = 0; i < n.length; i++) {
                if (extractLayers && options.layers.indexOf(n[i].data(options.layer_attribute_name)) === -1) {
                    options.layers.push(n[i].data(options.layer_attribute_name));
                }
                if (options.colors[n[i].data(options.layer_attribute_name)] === undefined) {
                    let col;
                    if (options.layers.length - 1 < auxColors.length) {
                        col = auxColors[options.layers.indexOf(n[i].data(options.layer_attribute_name))];
                    }
                    else {
                        col = '#' + Math.floor(Math.random() * 16777215).toString(16);
                    }
                    options.colors[n[i].data(options.layer_attribute_name)] = col;
                }
                n[i].data('color', options.colors[n[i].data(options.layer_attribute_name)]);
            }
            for (let j = 0; j < options.layers.length; j++) {
                var nodesAux = cy.elements("node[" + options.layer_attribute_name + " = '" + options.layers[j] + "']");
                if (nodesAux.length > 0) {
                    nodes[options.layers[j]] = nodesAux;
                }
            }
            var height = 0;
            var heightAcum = 0;
            var numLines = Object.keys(nodes).length - 1;
            var room = 50;
            ctx.lineWidth = options.lineWidth;
            ctx.strokeStyle = options.strokeStyle;
            ctx.textBaseline = "middle";
            ctx.font = options.font;
            ctx.setLineDash([5, 10]); 
            for (let k = 0; k < options.layers.length; k++) {
                var nodesAuxInLayer = nodes[options.layers[k]];
                if (nodesAuxInLayer !== undefined && nodesAuxInLayer.length > 0) {
                    height = Math.ceil((container.clientHeight - (numLines * room)) / (totalNodes / nodesAuxInLayer.length));
                    var line = heightAcum + height + (room / 2);
                    if (k !== 11) { 
                        ctx.beginPath();
                        ctx.moveTo(0, line);
                        ctx.lineTo(canvas.width, line);
                        ctx.stroke();
                    }
                    ctx.fillStyle = options.colors[options.layers[k]];
                    var y = heightAcum + Math.ceil((height) / 2);
                    if (heightAcum === 0) {
                        y = line / 2;
                    }
                    ctx.textAlign="end";
                    ctx.fillText(options.layers[k], container.clientWidth - 10, y);
                    if (moveNodes){
                        nodesAuxInLayer.positions(function (element, j) { 
                            if (element.locked()) {
                                return false;
                            }
                            if (k === 11) { 
                                return {
                                    x: Math.round((Math.random() * width) + 5),
                                    y: Math.round((Math.random() * height) + heightAcum - 25) 
                                };
                            }
                            return {
                                x: Math.round((Math.random() * width) + 5),
                                y: Math.round((Math.random() * height) + heightAcum + 20)
                            };
                        });
                    }
                    heightAcum += height + room;
                }
            }
        }
function runCerebral ( moveNodes ) { var nodes = { } ; var extractLayers = ( options . layers . length <= 0 ) ; var auxColors = [ '#058DC7' , '#50B432' , '#ED561B' , '#DDDF00' , '#24CBE5' , '#64E572' , '#FF9655' , '#FFF263' , '#6AF9C4' ] ; var n = cy . nodes ( ) ; for ( let i = 0 ; i < n . length ; i ++ ) { if ( extractLayers && options . layers . indexOf ( n [ i ] . data ( options . layer_attribute_name ) ) === - 1 ) { options . layers . push ( n [ i ] . data ( options . layer_attribute_name ) ) ; } if ( options . colors [ n [ i ] . data ( options . layer_attribute_name ) ] === undefined ) { let col ; if ( options . layers . length - 1 < auxColors . length ) { col = auxColors [ options . layers . indexOf ( n [ i ] . data ( options . layer_attribute_name ) ) ] ; } else { col = '#' + Math . floor ( Math . random ( ) * 16777215 ) . toString ( 16 ) ; } options . colors [ n [ i ] . data ( options . layer_attribute_name ) ] = col ; } n [ i ] . data ( 'color' , options . colors [ n [ i ] . data ( options . layer_attribute_name ) ] ) ; } for ( let j = 0 ; j < options . layers . length ; j ++ ) { var nodesAux = cy . elements ( "node[" + options . layer_attribute_name + " = '" + options . layers [ j ] + "']" ) ; if ( nodesAux . length > 0 ) { nodes [ options . layers [ j ] ] = nodesAux ; } } var height = 0 ; var heightAcum = 0 ; var numLines = Object . keys ( nodes ) . length - 1 ; var room = 50 ; ctx . lineWidth = options . lineWidth ; ctx . strokeStyle = options . strokeStyle ; ctx . textBaseline = "middle" ; ctx . font = options . font ; ctx . setLineDash ( [ 5 , 10 ] ) ; for ( let k = 0 ; k < options . layers . length ; k ++ ) { var nodesAuxInLayer = nodes [ options . layers [ k ] ] ; if ( nodesAuxInLayer !== undefined && nodesAuxInLayer . length > 0 ) { height = Math . ceil ( ( container . clientHeight - ( numLines * room ) ) / ( totalNodes / nodesAuxInLayer . length ) ) ; var line = heightAcum + height + ( room / 2 ) ; if ( k !== 11 ) { ctx . beginPath ( ) ; ctx . moveTo ( 0 , line ) ; ctx . lineTo ( canvas . width , line ) ; ctx . stroke ( ) ; } ctx . fillStyle = options . colors [ options . layers [ k ] ] ; var y = heightAcum + Math . ceil ( ( height ) / 2 ) ; if ( heightAcum === 0 ) { y = line / 2 ; } ctx . textAlign = "end" ; ctx . fillText ( options . layers [ k ] , container . clientWidth - 10 , y ) ; if ( moveNodes ) { nodesAuxInLayer . positions ( function ( element , j ) { if ( element . locked ( ) ) { return false ; } if ( k === 11 ) { return { x : Math . round ( ( Math . random ( ) * width ) + 5 ) , y : Math . round ( ( Math . random ( ) * height ) + heightAcum - 25 ) } ; } return { x : Math . round ( ( Math . random ( ) * width ) + 5 ) , y : Math . round ( ( Math . random ( ) * height ) + heightAcum + 20 ) } ; } ) ; } heightAcum += height + room ; } } }
@function runCerebral - draw lines and draw text
 @param {boolean} moveNodes - determine if we should reposition nodes or not.
@function runCerebral - draw lines and draw text @param { boolean } moveNodes - determine if we should reposition nodes or not .
//If layers is not defined we'll extract underlayer data from elements. // var extractLayers = true; // if (options.layers.length > 0) { //     extractLayers = false; // } //make line dashed // if k is 11, do not draw the line, as this is the nucleus, we want to include this line with the DNA chromosomes at the bottom //NOTE: changed here from elements, j to elements, j, likely to cytoscapejs version update //i.e. nucleus //do not overlay over DNA nodes