
--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Thanks Shreeram I really appreciate the linkMy question is how much should I process the data before I import it into D3jsFor examplesay I want to create a graph similar to a word cloud where I need to know the word count of each wordI could get this number by array functions in PHP and then import the data into d3 but that would require a server it for each viewI thought it might be more dynamic and efficient if D3js could handle this type of stuff?How would you go about solving this problem?
Like anything else where you are making a decision between front- and back-end rendering, you have to consider the pros and cons, and what the marginal effect on the end user would be.
foo foo bar
If the corpus of words is small, just do it front-end if your backend doesn't care one way or the other.
Actually, the d3.nest operator is great for that kind of thing, if you did want to do it on the frontend:
Midway upon the journey of our life
... the rest of dante's _inferno_ ...
Thence we came forth to rebehold the stars.
... and some more books
and you wouldn't have the raw data around on the client for another reason (like showing it, searching it, or allowing links to it, or something), you'll be almost always better off doing that on the backend... instead of passing megabytes of data, you'd be passing only a few kilobytes. Under most conditions, this will be preferable. If they need the text anyway, d3 (or other libraries) can do a lot of the heavy lifting for you, leaving you with some data to put into d3.
As to how you represent the data: d3 really likes arrays. In fact, if you have something you want to do for each of the properties in an object, you'll have to turn it into an array, first with, for example, d3.entries. So, in the case of your example above, instead of passing:
{"data": {foo: 2, bar: 1}}
you may want to pass:
{"data": [{word: "foo", "count": 2}, {word: "bar", "count": 1}]}
But this it's so much longer! This is true, but will give you more options down the road: once you want to store more than a count, you'll need a different structure than a straight object/dictionary/hash/map.
However, if the overhead of the JSON "schema" is really big, and if your data really is rows of one table coming off of a database, sometimes CSV or TSV can be a great way to go, for which d3.csv works great... but make sure you are using a library to generate your CSV server-side, or you could get some surprises with newlines, quotes, etc.!
word,count
foo,2
bar,1