# Confused by subgraph results

**URL:** <https://forum.graphviz.org/t/confused-by-subgraph-results/887>\
**Category:** Uncategorized\
**Created:** [October 22, 2021, 10:20pm UTC](https://forum.graphviz.org/t/confused-by-subgraph-results/887 "2021-10-22T22:20:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [October 22, 2021, 10:20pm UTC](https://forum.graphviz.org/t/confused-by-subgraph-results/887/1 "2021-10-22T22:20:44Z")

</div>

It appears that only one subgraph’s attributes can apply to a node (object), even if subsequent subgraphs (try to) apply different attributes.  
e.g. why is node _a_ not colored _green_?

```auto
  node [shape=circle style=filled color=lightblue]

  { node [color=pink]
    c f i p
  }
  {
    node [shape=square] // why not c ?
    a b c
  }
  { node [color=green] // why not a ?
    a d g
  }
  {
    node [shape=triangle] // why not d & f ?
    d e f
  }
  {
    node [shape=pentagon] // why not g & i ?
    g h i
  }
}    

```

Giving:

 ![semanticTest3](https://global.discourse-cdn.com/graphviz/original/1X/dc2d8b5c04108018f12221d13098936b382a442c.png)

---

<div class="post-metadata">

**Author:** ![scnorth](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/scnorth/32/89_2.png) [@scnorth](https://forum.graphviz.org/u/scnorth)\
**Post date:** [October 23, 2021, 1:11pm UTC](https://forum.graphviz.org/t/confused-by-subgraph-results/887/2 "2021-10-23T13:11:22Z")

</div>

It works that way because objects get the default attributes of the enclosing graph/subgraph at the point where they are created. If they are already created, they are not changed.

On a related topic, over the years we have wanted to implement graph object classes but we never worked out the details of how the library API would work, or how we would handle I/O (specifically graph writing) since we do not preserve the graph parse tree but basically reconstruct it based on the semantics of API calls.

Hope this makes some sense. Sorry.

---

<div class="post-metadata">

**Author:** ![smattr](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/smattr/32/85_2.png) [@smattr](https://forum.graphviz.org/u/smattr)\
**Post date:** [October 24, 2021, 12:16am UTC](https://forum.graphviz.org/t/confused-by-subgraph-results/887/3 "2021-10-24T00:16:54Z")

</div>

Assigning attributes at the point at which a node is parsed/created is essentially consistent with how cluster assignment works too, right?

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [October 25, 2021, 8:33pm UTC](https://forum.graphviz.org/t/confused-by-subgraph-results/887/4 "2021-10-25T20:33:22Z")

</div>

Ahh, got it. Thanks.
