All, I am working through Elijah Meeks D3 in Action Second Edition examples, and I thought it would be neat to try to create some of the visualizations inside an observable notebook. As I am new to Observable I am having difficulty decomposing working code from my desktop into blocks of code in an observable notebook.
I figured this would be a good opportunity to learn observable better. If I publish my notebook would someone mind taking a look, and giving me some suggestions.
Youâre never calling the overallTeamViz function.
Iâve made some other changes which I cannot explain why they are necessary in this fork (comments added where I made changes) and now at least the circles render. I donât have more time right now. Maybe itâs a start anyway.
Your code is a little hard to follow because the indentation is not consistent. If you fix it, it will be easier for people to help out.
Youâre code is already quite good, but there are some key points to take note of:
In your soccerViz cell, the overallTeamViz function is currently never run. I suggest simply removing the surrounding function, letting the code run once, when the cell evaluates.
Instead of d3.select("svg"), you can just use svg, and write svg.append('g')... etc. The rest of that statement is correct, including the .data(data).enter().append('g')... stuff.
Instead of making a new selection like you do in var teamG = d3.selectAll("g.overallG"); (which I think should work too, BTW) â you may want to consider âsavingâ your previous selection like so:
After youâve applied the .enter() command, you have in your hands the selection of ânewly added elements corresponding to data pointsâ, i.e. your full selection in this case. Thus, teamG is not actually âa single <g> elementâ, but the whole selection of ânew single <g> elementsâ, if that makes sense to you?
Iâm not really sure what you want to do with your code, next. If you want to do something specific to every element (team) in this selection, you should do something like teamG.each(function (d, i) { var singleTeamG = d3.select(this) ... }). This singleTeamG then refers to just the one particular <g> in question instead of the entire previous selection.
Created a quick notebook to demonstrate how to translate that example to Observable, along with some references to the techniques/patterns required for translating the rest of D3 in Action:
Looks like a lot of folks are online this morning I can see other people also replyingâŚ
Hi all, I got the majority of this working, the only issue I am having is with the control panel. That is to say that I cannot get the control panel to be visible. I see the g, and the associated buttons in the DOM, but nothing is visible on the page. Any suggestions? I updated the notebook, so you can see the current version at the same link as before.
So question for you super smart observable users / creators. Is this the best way to author a notebook, as one block function, or should it be broken up into smaller more digestible / explainable components? What is the convention that we as a community are trying to go for here?
As for âthe best way to author a notebookâ, weâre still figuring it out, together.
But usually, lots of little cells, each responsible for one aspect of your program, is a nice way to go. That allows the reactivity of the system to really shine.