d3-selection: version 1.3.1 crash with d3-transition: transition is not a function
Hi.
After updating to version 1.3.1 im getting error that select(...).transition is not a function
I manage to narrow it down to be something in version 1.3.1.
Nothing has changed im my code only this update. any ideas?
Here is the code. (webpack with react and d3-pack)
const sortedData = this.sortData(this.props.data);
const dataSet = { children: sortedData };
const nodes = hierarchy(dataSet).sum(d => d[this.props.valueFieldName]);
const size = 800;
const bubbleSizeScale = scaleSqrt()
.domain([
this.props.minValue,
this.props.maxValue,
])
.range([this.props.minRaduis, this.props.maxRaduis]);
const bubbles = pack()
.size([size, size])
.radius(d => bubbleSizeScale(d.value))
.padding(this.props.bubblePadding);
const svg = d3Select('.container-124')
.attr('viewBox', `0 0 ${size} ${size}`)
.attr('width', size)
.attr('height', size)
.attr('class', 'bubble');
const self = this;
const node = svg.selectAll('.node')
// Render the data acourding to the node id and value
.data(bubbles(nodes).descendants(), d => `${d.data.id}-${d.data[this.props.valueFieldName]}`);
const bubbleContainer = node
.enter()
.filter(d => !d.children)
.append('g')
.style('cursor', 'pointer')
.attr('class', 'node')
.attr('id', d => `a${d.data.id}`)
.attr('transform', d => `translate(${d.x},${d.y})`);
bubbleContainer
.append('circle')
.enter();
svg.selectAll('circle')
.attr('r', 1);
bubbleContainer
.append('text')
.attr('dy', '7px')
.attr('class', 'bubble-text-title')
.style('text-anchor', 'middle')
.style('opacity', 0)
node.exit().remove();
svg.selectAll('.node')
.transition() //<-- Here it crashes.
.duration(500)
.attr('transform', d => `translate(${d.x},${d.y})`);
svg.selectAll('circle')
.transition()
.duration(200)
.attr('r', d => d.r);
// Wait for bubbles to render then show the text
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 4
- Comments: 28 (3 by maintainers)
Commits related to this issue
- Specifically import d3-transition After code splitting (PR #701) the `transition` prototype was, depending on the dataset, not set on `Selection()` objects. See https://github.com/d3/d3-selection/iss... — committed to nextstrain/auspice by jameshadfield 5 years ago
- Pin d3-selection to overcome https://github.com/d3/d3-selection/issues/185 — committed to ooni/api by hellais 5 years ago
- ➕ Add dagre-d3 Related https://github.com/d3/d3-selection/issues/185, need to change yarn.lock — committed to MadratJerry/Compilers-Playground by MadratJerry 5 years ago
As @edmorley mentioned, this was an issue due to multiple versions of d3-selection in the
yarn.lock.I had to add the following to my
package.json:Removed the
yarn.lockfile and then ranyarnSame here, and one solution could be as below:
I think it happened because
Selection.prototype.transition()was added ind3-transitionpackage, so we must import transition package. See the source code.We hit this issue too - I believe it occurs when multiple versions of
d3-selectionare listed inyarn.lock- which looking at the repo linked above was the case there too.In our case, this is caused by the
d3parent package (for d3 v4.x) having pinned to exact versions (egd3-selection@1.3.0), whereas the d3-* sub-packages tend to use version ranges (egd3-selection@1, which is equivalent to^1.0.0).For your case, I’m guessing the exact pinned version is coming from your
package.jsonand the stale version is due to not refreshing the lockfile?Thanks for taking the time to post a full example! I am able to reproduce the issue at hand.
From D3 Custom Bundle II:
I thought perhaps the same is true of Webpack and tried importing
selectionas well, like this:Unfortunately this does not resolve the issue, and
selection.transitionis still not defined.I can also confirm that
selection.transitionis also not defined after upgrading tod3-selectionv1.3.2, and is defined (desired behavior) after reverting tod3-selectionv1.3.0.FWIW, here’s the diff between 1.3.0 and 1.3.1.
I wonder if this may be related to adoption of terser.
fix this issue by register
d3.selection.prototypemanuallyI had the same issue. In my case, the solution was to simply use npm for package management, and it worked without pinning any version of the package. It seems to me it might be an issue with yarn itself (maybe a new update). Hopefully this solution is helpful to some extend.
I had the issue multiple times, and it is true that it is caused by the presence of multiple versions of d3-selection (also d3-transition?). I manually edited yarn.lock to consolidate multiple versions of d3-selection into one and it solved the issue.
What my yarn.lock entry for d3-selection looks like after my manual consolidation.