Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>vis.render()</code> is currently being called before you get the data. There may be other issues too, but it needs to be after <code>getNet()</code>.</p> <hr> <p><strong>EDIT 1:</strong></p> <p><code>vis.render()</code> is now after <code>getNet()</code>. I've put the protovis force layout creation code inside a function so that I can control when it executes, and made the <code>vis</code> and <code>followers</code> variables visible to both the initialization code and the <code>createLayout</code> code.</p> <p>Protovis, particularly the force layout, is very unforgiving about errors - e.g. wrong structure or count of elements for nodes/links datastructure, and does not tell you what is going on, so in developing it is best to first use static data that you know is of the right kind, and then later replace with dynamically created data.</p> <p>One part of the problem you were having is that using <code>type="text/javascript+protovis"</code> invokes javascript rewriting by protovis. The code below uses <code>type="text/javascript"</code> and has the extra <code>{}</code>s and <code>return</code>s that using <code>+protovis</code> saves. This allows <code>getJSON()</code> and protovis to coexist in Chrome browser, without <code>getNet()</code> being called repeatedly.</p> <pre><code>&lt;html&gt;&lt;head&gt;&lt;title&gt;&lt;/title&gt; &lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="protovis-d3.2.js"&gt;&lt;/script&gt; &lt;body&gt; &lt;div id="center"&gt;&lt;div id="fig"&gt; &lt;script type="text/javascript"&gt; var vis; var followers={}; function createLayout(){ var w = document.body.clientWidth, h = document.body.clientHeight, colors = pv.Colors.category19(); vis = new pv.Panel() .width(w) .height(h) .fillStyle("white") .event("mousedown", pv.Behavior.pan()) .event("mousewheel", pv.Behavior.zoom()); var force = vis.add(pv.Layout.Force) .nodes(followers.nodes) .links(followers.links); force.link.add(pv.Line); force.node.add(pv.Dot) .size(function(d){ return (d.linkDegree + 4) * Math.pow(this.scale, -1.5);}) .fillStyle(function(d){ return d.fix ? "brown" : colors(d.group);}) .strokeStyle(function(){ return this.fillStyle().darker();}) .lineWidth(1) .title(function(d){return d.nodeName;}) .event("mousedown", pv.Behavior.drag()) .event("drag", force); //comment out the next line to remove labels //.anchor("center").add(pv.Label).textAlign("center").text(function(n) n.nodeName) vis.render(); } function getNet(){ // OK to have a getJSON function here. followers={nodes:[{nodeName:'mweller', group:6}, {nodeName:'mhawksey', group:6}, {nodeName:'garethm', group:6}, {nodeName:'gconole', group:6}, {nodeName:'ambrouk', group:6} ], links:[ {source:0, target:1, value:1}, {source:1, target:2, value:1}, {source:1, target:4, value:1}, {source:2, target:3, value:1}, {source:2, target:4, value:1}, {source:3, target:4, value:1}]}; } $(document).ready(function() { getNet(); createLayout(); }) &lt;/script&gt; &lt;/head&gt; &lt;/div&gt;&lt;/div&gt; &lt;/body&gt;&lt;/html&gt; </code></pre> <p><strong>EDIT 2:</strong></p> <p>In case you are interested in digging a bit deeper, the problem comes from this code in protovis:</p> <pre><code>pv.listen(window, "load", function() { pv.$ = {i:0, x:document.getElementsByTagName("script")}; for (; pv.$.i &lt; pv.$.x.length; pv.$.i++) { pv.$.s = pv.$.x[pv.$.i]; if (pv.$.s.type == "text/javascript+protovis") { try { window.eval(pv.parse(pv.$.s.text)); } catch (e) { pv.error(e); } } } delete pv.$; }); </code></pre> <p>The technique I've used to use <code>"text/javascript"</code> and avoid using <code>"text/javascript+protovis"</code> both solves your problem AND makes it easier to debug code using protovis in Firefox.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload