Comments (2)
Fixed. Changed to
if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
from d3.
I think this is still problematic. The code snippet found here: https://github.com/mbostock/d3/wiki/Selections#wiki-data has nested data. In trying to call select
on a single td, its data (a single number) gets overwritten by its parent td's data (an array of numbers). My workaround for now, has been to do selectAll
and then filter
to reduce the size of the selection to the element I care about. The issue is demonstrated in this fiddle: http://jsfiddle.net/FUJa6/1/
I feel as though the fix is more confusing than the original implementation. It is also strange that select
modifies __data__
, while selectAll
does not.
Fix 1
It seems like in most cases, if a child node already has data, you would not want it to inherit its parent's data. To fix the boolean/null problem, we could do:
if (subnode && !("__data__" in subnode)) subnode.__data__ = node.__data__;
Fix 2
A second alternative would be to consider the 'freshest' data; whichever data is newest should win. __data__
could be augmented with a global counter that tracks when the data was set. If both the subnode and node have data, the data with a higher counter would win. This seems overly complex, and I can't think of a good example of when this scenario arises.
Fix 3
To get rid of any ambiguities, I think it is cleaner to never inherit data from the parent. select
is then non-volatile. In the cases that you do want to use the parent data, you can use each
, to create a closure. For example, instead of:
d3.selectAll('div').data(divData);
d3.selectAll('div').selectAll('p').text(function(d){ return d;});
you would do:
d3.selectAll('div').data(divData);
d3.selectAll('div').each(function(divData){
d3.select(this).selectAll('p').text(divData);
});
from d3.
Related Issues (20)
- #How to remove spaces between bar in d3.js grouped bar chart.
- d3 hierarchy: node visibility parameter to control either to show node in visualization or hide it.
- the wrong parameter name at Binning data of d3-array documentation HOT 5
- Upgrading from v3 to v7 requires additional renders for my custom gauge
- Making a non-contiguous piechart
- Transition to pie chart with 2 slices crashes HOT 1
- Adding a link towards DefinitelyTyped HOT 1
- Realtime line chart
- setting overflow direction in css causes Y-axis labels to clip the cartesian line
- How to align nodes horizontally (sequence way)
- D3-Brush not working with Angular 17
- Add Repobeats (metrics) to README HOT 1
- Custom error handling.
- d3.pointer()
- [Request] How do I put values on top of the bar chart ?
- Firefox error when calling d3.pointer inside of 'zoom' event handler
- Hover doesn't apply styles in Firefox if d3.select.raise is used.
- D3 Ported to Dart
- rollup -c fails. es6 bundle
- Query on how to build Custom Scale
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3.