JavaScript Conditionally build group in d3

I am trying to build a graph using the force layout in D3. I would like to build different looking nodes depending on the data. Currently all nodes have a category and a name. So I draw an svg:g consisting of two rect and two text elements.

My code currently looks something like this:

// nodes are in the form: { group: 'string', name: 'string2' }
this.node = this.node.data(this.node, function(d) { return d.id; });

var g = this.node.enter().
    append('svg:g').
    attr('transform', function(d) { return 'translate('+ d.x +','+ d.y +')'; });
g.append('svg:rect').attr('h', 20).attr('w', 100);
g.append('svg:rect').attr('y', 20).attr('h', 20).attr('w', 100);
g.append('svg:text').text(function(d) { d.group; });
g.append('svg:text').attr('y', 20).text(function(d) { d.name; });

If the node doesn't have a name, however, I'd like to supress the creation of the second rect and text. Logically, if it wasn't for the implicit iterator in d3 I'd be doing something like:

var g = this.node.enter().
    append('svg:g').
    attr('transform', function(d) { return 'translate('+ d.x +','+ d.y +')'; });
g.append('svg:rect').attr('h', 20).attr('w', 100);
g.append('svg:text').text(function(d) { d.group; });


// unfortunately 'd' isn't defined out here.
// EDIT: based on comment from the answer below; the conditional should
// be for the text and the related rectangle.
if(d.name) {
  g.append('svg:rect').attr('y', 20).attr('h', 20).attr('w', 100);
  g.append('svg:text').attr('y', 20).text(function(d) { d.name; });
}
Answer:1

I just trying to set default allow fullscreen for youtube api but i can't find that and i am new to javascript i tried so any many code but i didn't got.Actually i want to allow multiple youtube ...

I just trying to set default allow fullscreen for youtube api but i can't find that and i am new to javascript i tried so any many code but i didn't got.Actually i want to allow multiple youtube ...

  1. fullscreen youtube network
  2. fullscreen youtube video
  3. fullscreen youtube embed
  4. fullscreen youtube link
  5. fullscreen youtube partnership
  6. fullscreen youtube ipad
  7. fullscreen youtube stutter
  8. fullscreen youtube screen tearing
  9. fullscreen youtube thumbnail
  10. fullscreen youtube video embed
  11. fullscreen youtube taskbar visible
  12. fullscreen youtube video background css
  13. fullscreen youtube videos split diagonally
  14. fullscreen youtube video in powerpoint
  15. fullscreen youtube firefox
  16. fullscreen youtube not working
  17. fullscreen youtube partner
  18. fullscreen youtube video background html
  19. fullscreen youtube lag
  20. fullscreen youtube iframe

I am in my second semester at SCSU and currently taking an introductory course into Computer Science. We are going over the basics of HTML and Javascript. The latest lab I worked on was using a ...

I am in my second semester at SCSU and currently taking an introductory course into Computer Science. We are going over the basics of HTML and Javascript. The latest lab I worked on was using a ...

  1. javascript checking radio button value
  2. javascript checking radio button
  3. javascript checking if radio button is selected

I want to reset my form having id user_post. This form contains hidden fields also. I used this code to reset input form fields $('#user_post').each(function(){ this.reset(); }); My form given ...

I want to reset my form having id user_post. This form contains hidden fields also. I used this code to reset input form fields $('#user_post').each(function(){ this.reset(); }); My form given ...

  1. arena
  2. arena football
  3. arendelle
  4. arena stage
  5. arenado
  6. arenal volcano
  7. arena sports
  8. arent
  9. arenal costa rica
  10. arena theatre
  11. arena of valor
  12. arena stage dc
  13. arena sf
  14. arent fox
  15. arena ktown
  16. arenanet
  17. arenado trade
  18. arenacross
  19. arenal volcano national park
  20. arena theater

In my Node.js app I have a database layer that calls toString on input parameters that need to be passed to the database as a string (for example, numbers). The places where I pass parameters to the ...

In my Node.js app I have a database layer that calls toString on input parameters that need to be passed to the database as a string (for example, numbers). The places where I pass parameters to the ...

  1. calling tostring on string java
  2. calling tostring on string
  3. calling tostring on string c#
  4. avoid calling tostring() on string objects this is unnecessary
  5. avoid calling tostring() on string objects