Comments (5)
You can do this (w/ slightly different syntax) in 3 by modifying the selection prototype - see jetpack and starterkit
from d3-selection.
Okay, so that rolls .classed
into .append
but you still have to specify things twice for an enter selection. So those libraries don't really address the problem.
from d3-selection.
Hmm, I suppose you'd have a bit of a problem for union selectors like "div.a, span.b"
. I don't think this is a dealbreaker, though. You'd take the last one and most of the time the user would override it. I still would like Mike to weigh in.
from d3-selection.
I typically just select by class and not element:
selection.selectAll(".foo")
.data(data)
.enter().append("div")
.class("foo", true);
Sometimes I’ll do things like select based on the presence of an attribute but then compute its value dynamically:
selection.selectAll("[foo]")
.data(data)
.enter().append("div")
.attr("foo", function(d, i) { return …; });
So, yes, typically the selector used to create a selection implies certain things on entering elements, but not always enough to enforce those things automatically. It would be possible to capture the selector used to create a selection (when a selector is used—note that you can also pass a function to selection.select and selection.selectAll), and then modify enter.select / enter.append to try to enforce what’s implied by the selector.
But, it’s not trivial to enforce that the selector matches materialized elements in general. For example, you presumably wouldn’t be able to enforce a selector like ":nth-child(2)", and in an attribute existence selector (like "[foo]") you’d have to define a default value for that attribute, which might be pointless if you were going to subsequently give it an explicit value later anyway.
Given the difficulty of supporting this in the general case, and the undesirability of having it just work in a few special cases, I prefer having a little redundancy. Or just a little syntactic sugar for convenience as an optional feature, like in d3-jetpack.
from d3-selection.
Okay, thanks for the explanation.
from d3-selection.
Related Issues (20)
- How to add passive listener into zoom event? HOT 1
- Proposal: add sample code for transitions into README docs HOT 1
- How to report type issues HOT 1
- d3.style('padding') or d3.style('margin') returned empty string only in firefox HOT 2
- Adopt InternMap for selection.data
- Stash the key used by the previous data-join HOT 2
- Raise an error when passing a `selection.data()` key that does not evaluate to a string. HOT 1
- Selection.one HOT 11
- Please provide your artifact as transpiled (CJS) code. HOT 3
- Enable the use of d3.join() without implicit d3.order() call HOT 3
- selection.appendAll HOT 3
- Is anyone working on D3.ts ? HOT 1
- chaining multiple transform styles to an element do not all get applied to the element HOT 1
- Proposal: Memoization Utility HOT 3
- Error: path attribute d expected number, on value with scientific notation HOT 2
- Chaining select has a side-effect on data HOT 1
- `pointer.js` function is not available for import through `d3-selection` HOT 8
- .attr on null selection should not error HOT 3
- Missing null check HOT 1
- Cannot import {pointer} function as it is not available to import HOT 4
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-selection.