Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It sounds like you need to write a web service in Python that consumes and returns <a href="http://www.json.org/" rel="noreferrer">JSON</a>. I'm not sure if the data is originating on the client or the server, so for this example, I'm assuming it comes from the client.</p> <ol> <li>POST your graph data in JSON format to your webservice</li> <li>Do processing server-side</li> <li>return JSON representing the results of the processing to the client</li> <li>Render it with d3.js</li> <li>User interaction on the client creates a new or modified data structure</li> <li>Go back to step 1</li> </ol> <p>Maybe your server-side web service method looks like this (this is pseudo-code based on <a href="http://webpy.org/" rel="noreferrer">web.py</a>):</p> <pre><code>import simplejson class ml(object): def POST(self,data=None): # turn the JSON string into a Python data structure d = simplejson.loads(data) # do stuff results = alter_data(d) web.header('Content-Type','application/json') # send JSON back to the client return simplejson.dumps(results) </code></pre> <p>And your client-side code might look something like this (again, just a rough sketch). This example assumes that you're using jQuery to do your AJAX stuff.</p> <pre><code>function render(data,textStatus) { d3 .select('svg') .selectAll('circle') .data(data) .enter() .append('circle') .on('click',function() { $.getJSON( 'your_webservice_url', // POST an updated data structure to your service { 'data' : alter_data(data) }, // Call the render method again when new data is received render); }); } </code></pre> <p>d3.js' <a href="https://github.com/mbostock/d3/wiki/Selections#wiki-enter" rel="noreferrer"><code>enter</code></a> and <a href="https://github.com/mbostock/d3/wiki/Selections#wiki-exit" rel="noreferrer"><code>exit</code></a> methods make updating the visual representation of your data very easy. I recommend reading the documentation for those.</p> <p><a href="http://mbostock.github.com/d3/ex/force.html" rel="noreferrer">This example</a> might give you some ideas about how to represent your graph data with JSON, and how to render it.</p> <p>Check out the <a href="https://github.com/mbostock/d3/wiki/Selections#wiki-on" rel="noreferrer"><code>on</code></a> method for an idea about how to trigger a POST to your web service when a node is clicked.</p> <p>I'm going to skip the really specific stuff, like displaying text with d3.js. I'm sure you can figure out how to do that by perusing the <a href="https://github.com/mbostock/d3/wiki" rel="noreferrer">d3.js documentation</a>.</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