P..S. The above uses the approach of the generic.json files. Refer to: http://web2py.com/books/default/chapter/29/10/services?search=serializers and the generic.json code.
On Thursday, June 12, 2014 8:20:04 AM UTC+10, Andrew W wrote: > > This may not be the crucial hint, but I noticed that your flare is a list > (array). If you checkout the structure at: > https://github.com/mbostock/d3/wiki/Cluster-Layout you see that its a > dict (or object). > > Try removing the [] around your flare definition. > > Secondly: Where I have used XML(json... in the controller it has been > to produce a standaoone .json output from web2py, I then create an > independent view that then uses the d3.json function to read the json > output. That is the approach that mostly matches the majority of d3 > examples. This works if you want to separate your data sources (thinking > independent data api) from your presentation views. > > The other approach is to use the variables, which you've done. There may > be more than one way to do this but this has worked for me: > 1. Change your flare definition to be a dict. remove the [] > 2. Change your controller output to be return locals(). > 3. In your view , in the <script> add: > {{from gluon.serializers import json}} > var flare = {{=XML(json(flare))}} > > > > > > > > I think web2py is a good data provider for d3 apps > > On Thursday, June 12, 2014 2:49:32 AM UTC+10, Richard wrote: >> >> Andrew, >> >> When I respond with flare=flare I get the & issue, solved by XML() >> >> Uncaught SyntaxError: Unexpected token & >> >> My script starts with: >> >> <script> >> >> var width = 960, >> height = 2200; >> >> var cluster = d3.layout.cluster() >> .size([height, width - 160]); >> >> var diagonal = d3.svg.diagonal() >> .projection(function(d) { return [d.y, d.x]; }); >> >> var svg = d3.select("body").append("svg") >> .attr("width", width) >> .attr("height", height) >> .append("g") >> .attr("transform", "translate(40,0)"); >> >> var flare = {{=flare}} ; >> >> var nodes = cluster.nodes( flare ), >> links = cluster.links(nodes); >> >> var link = svg.selectAll(".link") >> .data(links) >> .enter().append("path") >> .attr("class", "link") >> .attr("d", diagonal); >> >> Hope you can give me a crucial hint. >> >> >> On Wednesday, June 11, 2014 5:49:13 PM UTC+2, Andrew W wrote: >>> >>> What else is in your view? Is the code inside a <script>? >>> What if you just returned dict( flare=flare) in your controller? >>> >> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

