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

What is g? #3

Open
dawsbot opened this issue Oct 25, 2014 · 5 comments
Open

What is g? #3

dawsbot opened this issue Oct 25, 2014 · 5 comments

Comments

@dawsbot
Copy link

dawsbot commented Oct 25, 2014

What is g and why are we always appending to it? And @wannabeCitizen, if modularizing our code and having object names for our graph objects is a good thing, why does nobody do that in our examples and "e-book"?

@wannabeCitizen
Copy link

g is a group element that has to be the child of an svg.

Can you point me to specific code you think is non-modularized? I'm not
sure if we just have to different view of what that means or if I'm just
looking at different code than you.

On Sat, Oct 25, 2014 at 3:37 PM, Dawson Botsford [email protected]
wrote:

What is g and why are we always appending to it? And @wannabeCitizen
https://github.com/wannabeCitizen, if modularizing our code and having
object names for our graph objects is a good thing does nobody do that in
our examples?


Reply to this email directly or view it on GitHub
#3.

@dawsbot
Copy link
Author

dawsbot commented Oct 26, 2014

Shouldn't code like this have something like var circle = so that it can be referenced as circle in the future?

                   svg.selectAll("circle")
                       .data(dataset)
                       .transition()
                       .duration(1000)
                       .attr("cx", function(d) {
                            return xScale(d[0]);
                       })
                       .attr("cy", function(d) {
                            return yScale(d[1]);
                       });

Taken from https://github.com/dawsonbotsford/challenge-week-9/blob/master/checkpoint3.html

@wannabeCitizen
Copy link

Send me the link to where this code comes from.

On Sun, Oct 26, 2014 at 11:12 AM, Dawson Botsford [email protected]
wrote:

Shouldn't code like this have something like var circle = so that it can
be referenced as circle in the future?

               svg.selectAll("circle")
                   .data(dataset)
                   .transition()
                   .duration(1000)
                   .attr("cx", function(d) {
                        return xScale(d[0]);
                   })
                   .attr("cy", function(d) {
                        return yScale(d[1]);
                   });

Taken from https://github.com/dawsonbotsford/challenge-week-9/blob/master/checkpoint3.html


Reply to this email directly or view it on GitHub
#3 (comment)
.

@dawsbot
Copy link
Author

dawsbot commented Oct 26, 2014

@wannabeCitizen
Copy link

Okay so there is no need to modularize anything here, but all in all this
is always going to be a style choice like any other code.

They are using appending circles to the DOM then when they load their data,
a transform gets added to those elements. 'g' is being used in order to
group the y and x axes as separate entities they can work with rather than
accidentally grabbing the entire svg canvas.

On Sun, Oct 26, 2014 at 2:02 PM, Dawson Botsford [email protected]
wrote:

Originally from
https://github.com/alignedleft/d3-book/blob/master/chapter_09/20_axes_dynamic.html

Which was linked from the e-book page at
http://chimera.labs.oreilly.com/books/1230000000345/ch09.html#_updating_axes
half way down the page


Reply to this email directly or view it on GitHub
#3 (comment)
.

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

No branches or pull requests

2 participants