-
Notifications
You must be signed in to change notification settings - Fork 22.9k
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
4.0 attr
not support object as parameter
#2793
Comments
attr
not support object as parameter
In D3 4.0, multi-value map support has moved to the d3-selection-multi repository as an optional plugin, using distinct names (e.g., selection.attrs instead of selection.attr) to avoid ambiguity. |
What's the proper way to require this plugin (or any plugin) if we're not exposing d3 globally? I upgraded to v4 (d3@4.0.0-rc.2) and
works fine for the base functionality, but I use the attr({...}) syntax frequently and I haven't been able to get it to work again. I would expect something like this:
however this fails. I know I'm probably missing something silly here but from reading the docs and using other libs like leaflet, this was my best guess as to how I could get it working (although leaflet does expose itself globally). Using leaflet plugins through npm and
My only other guess would be that maybe I need to use rollup and make a custom build? |
It might depend on how your bundler is configured. If your bundler isn’t observing the jsnext:main defined in the d3 package.json, then it’s possible that you are importing the generated UMD bundle (see build/d3.js). If that’s the case, then the imported One way to avoid this problem is to use the modules directly and avoid the default bundle: import * as d3_selection from "d3-selection";
import "d3-selection-multi"; // modifies d3_selection.selection.prototype If you’re using var d3 = require("d3");
require("d3-selection-multi"); // modifies d3.selection.prototype That’s because there’s a special d3.node.js bundle that uses As you guessed, another solution is to create your own custom bundle and then require that as |
Thanks for the quick response! I'll keep playing around with it (I'm using Webpack btw)... |
I'm migrating several components to v4 and I just got hit by this breaking change. Too bad that it's not listed in https://github.com/d3/d3/blob/master/CHANGES.md |
@ValentinH It is listed there, in the last paragraph of the Selections section, quoted here:
|
OK, sorry for that. I didn't read until the end of the section and was searching for the Just to understand, is extracting those multi-value methods in a separate repository showing that the "recommended" way is to chain single methods? |
Yes, d3-selection-multi is available but not recommended by default. |
@mbostock, would you please help us understand why |
Summary: In the graph dashboard, we attempt to set the size of the download canvas according to the scene size. However, the syntax that we use to do this is no longer supported by d3v4 ([source]), and so this ends up doing nothing. Simply changing the syntax fixes the bug. Fixes #88. [source]: d3/d3#2793 Test Plan: Launch the graph explorer, and click "Download PNG" at left. Before this patch, this always resulted in a 300×150 px image. Now, it results in an image whose size is properly determined by the contents of the graph. wchargin-branch: fix-graph-png-size
Summary: In the graph dashboard, we attempt to set the size of the download canvas according to the scene size. However, the syntax that we use to do this is no longer supported by d3v4 ([source]), and so this ends up doing nothing. Simply changing the syntax fixes the bug. Fixes #88. [source]: d3/d3#2793 Test Plan: Launch the graph explorer, and click "Download PNG" at left. Before this patch, this always resulted in a 300×150 px image. Now, it results in an image whose size is properly determined by the contents of the graph. wchargin-branch: fix-graph-png-size
In 3.X, we can use syntax like:
But now, it's not work and no error prompt.
Need change it to
What's the reason the syntax changed?
Thanks in advance.
The text was updated successfully, but these errors were encountered: