2013-04-20 11 views
9

Sigma.js elenca diversi examples sul proprio GitHub, ma non è chiaro da loro cosa è necessario per caricare un plugin.Come faccio a "collegare" i plugin per sigma.js?

Ho provato semplicemente a includere un tag <script> che punta al file JavaScript del plugin ma che non ha funzionato. Come posso importare/utilizzare/copypaste il plugin sul mio sito?

+0

Forse avrei dovuto dire che mentre mi trovo a mio agio con Python, javascript non è quello che chiameresti il ​​mio forte. – Tuomas

+0

Lo capisco correttamente, i plugin sono solo file javascript. Penserei che tu dovessi scaricare un plugin e "riferimento" nel tuo file html. come in "script type =" text/javascript "src = ...." – user1043144

+0

No, scusate, ci ho provato ma non ha funzionato così. Gli esempi elencati sul sito sigma.js sembrano avere altre cose in loro così come la reale funzionalità del plugin. – Tuomas

risposta

7

In primo luogo, include i sigma-file necessari:

<script src="sigma/sigma.concat.js"></script> 
<script src="sigma/plugins/sigma.parseGexf.js"></script> 
<script src="sigma/plugins/sigma.forceatlas2.js"></script> 

Quindi avviare lo script;

<script type="text/javascript"> 
function init() { 
    // Instanciate sigma.js and customize rendering : 
    sigInst = sigma.init(document.getElementById('graph')).drawingProperties({ 
    defaultLabelColor: '#fff', 
    defaultLabelSize: 14, 
    defaultLabelBGColor: '#fff', 
    defaultLabelHoverColor: '#000', 
    labelThreshold: 6, 
    defaultEdgeType: 'curve' 

    }).graphProperties({ 
    minNodeSize: 2, 
    maxNodeSize: 5, 
    minEdgeSize: 1, 
    maxEdgeSize: 1 

    }).mouseProperties({ 
    maxRatio: 32 
    }); 

    // Parse a GEXF encoded file to fill the graph 
    // (requires "sigma.parseGexf.js" to be included) 
    sigInst.parseGexf('getgefx.php'); 


    sigInst.bind('downnodes',function(event){ 
    var nodes = event.content; 
    var neighbors = {}; 
    sigInst.iterEdges(function(e){ 
     if(nodes.indexOf(e.source)>=0 || nodes.indexOf(e.target)>=0){ 
     neighbors[e.source] = 1; 
     neighbors[e.target] = 1; 

     } 
    }).iterNodes(function(n){ 
     if(!neighbors[n.id]){ 
     n.attr['temphidden'] = 1; 
     n.attr['oldcolor'] = n.color; 
     // var c = sigma.tools.getRGB(n.color); 
     n.color = "#eee"; // #ccc"; 

     // n.color = "rgba("+c['r']+","+c['g']+","+c['b']+",0.2)"; 
     } 
    }).draw(2,2,2); 
    }).bind('upnodes',function(){ 
    sigInst.iterNodes(function(n){ 
     if(n.attr['temphidden'] == 1) { 
      n.color = n.attr['oldcolor']; 
      n.attr['temphidden'] = 0; 
     } 

    }).draw(2,2,2); 
    }); 
    // Draw the graph : 
    sigInst.draw(2,2,2); 
    sigInst.startForceAtlas2(); 
    var isRunning = true; 
    document.getElementById('stop-layout').addEventListener('click',function(){ 
    if(isRunning){ 
     isRunning = false; 
     sigInst.stopForceAtlas2(); 
     document.getElementById('stop-layout').childNodes[0].nodeValue = 'Start Layout'; 
    }else{ 
     isRunning = true; 
     sigInst.startForceAtlas2(); 
     document.getElementById('stop-layout').childNodes[0].nodeValue = 'Stop Layout'; 
    } 
    },true); 

} 

if (document.addEventListener) { 
    document.addEventListener("DOMContentLoaded", init, false); 
} else { 
    window.onload = init; 
} 
</script> 
Problemi correlati