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

Handling default attributes for node/edge/graph statements #55

Merged
merged 3 commits into from
Feb 18, 2013

Conversation

ress
Copy link
Contributor

@ress ress commented Feb 18, 2013

I saw this was a feature request for dig.js and implemented it for dagre.

Default attributes apply to all statements following them:
digraph G {
n0 [label="colorless node"]
node [color=green font=Helvetica];
n1 [label="green node"]; /* color=green and font"Helvetica are added automatically */
}

Multiple default attribute statements are merged, and newer attributes have
precedence over older attributes:
digraph G {
node [color=green font=Helvetica];
node [color=yellow];
n0 [label="yellow node"]; /* font=Helvetica is added automatically */
}

Default attributes apply to all statements following them:
  digraph G {
    n0 [label="colorless node"]
    node [color=green font=Helvetica];
    n1 [label="green node"]; /* color=green and font"Helvetica are added automatically */
  }

Multiple default attribute statements are merged, and newer attributes have
precedence over older attributes:
  digraph G {
    node [color=green font=Helvetica];
    node [color=yellow];
    n0 [label="yellow node"]; /* font=Helvetica is added automatically */
  }
@ress ress closed this Feb 18, 2013
@ress ress reopened this Feb 18, 2013
@ress
Copy link
Contributor Author

ress commented Feb 18, 2013

Fixed a bug in my initial commit. Works well now and includes test cases.

@cpettitt cpettitt merged commit a35c5bc into dagrejs:master Feb 18, 2013
@cpettitt
Copy link
Collaborator

Thanks for adding this feature! I've changed the behavior slightly for how we handle nodes. If this is the first time we encounter the node (explicit node statement or implicit via edge statement) we try to apply the default attributes. Otherwise we only attributes that were explicitly defined in the statement. I believe this is consistent with how graphviz handles attributes.

@ress
Copy link
Contributor Author

ress commented Feb 18, 2013

That change makes sense, and also makes the code simpler. Thanks for merging!

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

Successfully merging this pull request may close these issues.

None yet

2 participants