4 ms·
How to utilize D3.js with Rails partials?
Hi HN,
I'm building a Rails app that needs some visualizations, but I have a problem. In the app, users have folders which contain entries that they create. When you visit the site (logged in), you are shown a list of all your folders, and clicking on one loads up a partial with all the submissions contained inside.
What I'd like to do is something different: When the user opens the folder, I'd like to load a partial with all the <svg> and <circle> HTML for D3, and size them based on the character count of each submission. However, I'm lost on how to do it and have been trying to get it working all day.
I have placed all the D3 code inside my show.html.erb file for the folder, which injects the partial into the body of the site. It doesn't work, and my D3 code needs to know which folder has been opened to load the correct JSON data; I'm using a d3.json call to get the JSON for the folder, which contains a sub-array for submissions.
Is my approach wrong? I'm sort of a Rails newbie, so I'm not sure how else to do this. Any help is greatly appreciated.
- jdc 13y agoThat sounds complicated. Why not just make an SVG partial that draws circles that accepts the quantity, sizes and positions as parameters?