Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grouping different bubble colors together #5

Open
lorenries opened this issue Mar 21, 2018 · 3 comments
Open

Grouping different bubble colors together #5

lorenries opened this issue Mar 21, 2018 · 3 comments

Comments

@lorenries
Copy link

Hi Jim, thanks for the excellent tutorial! I'm wondering if you have a suggestion for how you could group together different color bubbles (or categories), kind of like how the NYT does it here, and have them stay grouped together when the view separates out different years.

@vlandham
Copy link
Owner

Ah yes. its a great feature of that graphic - and one that is ignored in this tutorial.
I haven't tried, but I think this could be accomplished with an forceY to position nodes along the Y axis based on their category.

You might have to do some work with the initial positioning of the nodes (i.e. not random positions - but start those of the same category close to one another).

It also might take some tweaking to make this force play nice with the other forces, but this is the approach i would try!

@lorenries
Copy link
Author

Thank you! That ended up working well, especially with a linear scale for initial positioning. I ended up doing something like this:

var simulation = d3.forceSimulation()
  .force('y', d3.forceY(function(d) {
    var yScale = d3.scaleLinear().domain([1, numberOfCategories]).range([250,height-250]);
    return yScale(d.category)
  })

@vlandham
Copy link
Owner

vlandham commented Apr 2, 2018

very nice! thanks for posting your solution to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants