d3 / d3-shape

Graphical primitives for visualization, such as lines and areas.
https://d3js.org/d3-shape
ISC License
2.48k stars 308 forks source link

d3-shape should return a good error when d3-path is not present #49

Closed llimllib closed 8 years ago

llimllib commented 8 years ago

Steps:

  1. Load up d3-shape in a webpage to test it
  2. Try something from the tests
  3. See an unuseful error message:
d3_shape.line().curve(d3_shape.basisOpen)([[0,0], [0,10]])
d3-shape.v0.2.js:1024 Uncaught TypeError: Cannot read property 'path' of undefined(…)

(It would also be awesome if there were bl.ocks samples for the images provided in the documentation, it seems quite hard to figure out how to generate them at the moment?)

mbostock commented 8 years ago

I agree that the documentation should be improved by adding (links to) more code examples.

Part of the issue is that D3 4.0 is not yet ready for release, and most of the existing “real-world” examples depend on other D3 features (such as selections and axes) that are not yet available in standalone modules. So some of the examples use the 3.x API which is similar but not identical.

I should create new, smaller examples that are better at demonstrating how to use d3-shape. They’d be less useful as visualizations without being able to use other D3 functionality, but they’d be better at demonstrating the d3-shape API.

FWIW, the curve viewer (currently a secret gist) is here:

http://bl.ocks.org/mbostock/4677815766e8404bee65

I’m not in favor of defending the code against missing dependencies. The correct usage is documented in the README, and this should be less of a problem in the future when there are more examples. In general, it just hurts my brain too much to try to anticipate all the ways the code can be misused and try to protect against it. I know this is a common case and so perhaps an exception could be made, but it’s not like the error is that obscure: the stack trace points you right to the line where d3_path is undefined, and that should be enough to go on.

So, I’m going to close this issue, but I’ll open a new one to cover the request for more self-contained examples.

llimllib commented 8 years ago

Thanks for reading it and coming up with the useful bit from it; I appreciate it.

I also modified your old spline viewer so I could play with these curves: http://bl.ocks.org/llimllib/115a23b78d1fae253bb8/bb4dba43022ebb920bcba4cc7cac1c36707e020d

mbostock commented 8 years ago

Nice.