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

Including d3-fetch.v1.js causes d3.svg to be undefined in nv.d3.js #37

Closed
JetForMe opened this issue Mar 25, 2020 · 8 comments
Closed

Comments

@JetForMe
Copy link

By process of elimination, I've determined that an error in I get while running the NVD3 lineChart() example comes from including d3-fetch.v1.js in the same HTML file. The error reported by Safari is "TypeError: d3.svg.axis is not a function. (In 'd3.svg.axis()', 'd3.svg.axis' is undefined)".

This goes away if I don't include d3-fetch, but I need that for…fetching data.

@mbostock
Copy link
Member

Sounds like both d3-fetch and NVD3 define d3.svg, so you won’t be able to use them together. Sorry!

@gordonwoodhull
Copy link

Generally, you can't include d3@3 and d3@4+ in the same HTML file.

I needed to load d3v4-force into a d3@3 project and I had luck using rollup to produce a bundle that exposed the d3@4 code as d3v4 instead of d3.

https://github.com/dc-js/dc.graph.js/blob/develop/d3v4-force.rollup.config.js

(Doing a sed search-and-replace also worked, but this is more elegant.)

@JetForMe
Copy link
Author

Sounds like both d3-fetch and NVD3 define d3.svg, so you won’t be able to use them together. Sorry!

Why does something designed for fetching data define d3.svg?

Generally, you can't include d3@3 and d3@4+ in the same HTML file.

I was aware the NVD3 couldn't use d3 v4, but I thought I was avoiding that, following their examples. I'm not using node, so I'm not sure how to incorporate your solution.

@JetForMe
Copy link
Author

Oh I see, you parse SVG. I think I'll just modify my copy to change the definition.

@JetForMe
Copy link
Author

Or maybe you could make everything live under d3.fetch?

@mbostock
Copy link
Member

Sorry, but I’m not going to rename this method. The d3.svg namespace was removed from D3 in 4.0 which was released in 2016. This module added a new d3.svg method (parallel to d3.xml, d3.text, d3.json, etc.) in 2018.

@gordonwoodhull
Copy link

gordonwoodhull commented Mar 25, 2020

d3-fetch is circa d3@5 so it’s not compatible with d3@3 used by NVD3.

My rollup solution has nothing to do with Node. It’s just a way to bundle individual D3 ES6 modules to replaced3-fetch.v1.js with something that don’t write to the global d3 namespace.

It’s basically the same way the official D3 bundles are created.

@JetForMe
Copy link
Author

Ah I see. Well, I did search and replace, which worked, but then couldn't get NVD3 to do what I wanted, to I switched to C3.

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

No branches or pull requests

3 participants