🏠 back to Observable

Porting Brush and zoom II to observable


#1

Hi,

I’m really not good in javascript but I’m trying to port Brush & Zoom II from bl.ocks to observablehq (my attempt) as to learn about brush and zoom.

The problem is that I don’t get quite get all the original code although I made progress since this morning (about 7 hours ago) and some doc reading (w3, d3, moz://a).

Comments would be welcome.
Thank you.


#2

Hi, here’s a fork that works:

The main change that I made was to move some of the code into the svg cell. Note that each cell defines its own function scope, so the only variables defined in a cell that you can access from other cells are the ones that you output with a return or yield statement.

Hope that helps!


#3

Thank you Bryan.
It helps seen it work, Although I don’t understand why I didn’t get it right when I first tried copying the whole block in one cell.

I also finished reading https://beta.observablehq.com/@mbostock/how-observable-runs and scope thing in Observable gets clearer.

(edit:
for good practices while porting code check https://beta.observablehq.com/@tmcw/observable-anti-patterns-and-code-smells)