How to set a default value for the edge attribute 'weight'

Hi,

Very new to Graphviz (and the forum software), so forgive if, after all my googling, I’ve overlooked something obvious.

At the very top of my digraph, before any nodes, edges, etc, are defined, I have put the following statement: edge [weight=9 style=dashed]. I imagine that by doing so I’m setting these attributes to default values, used throughout unless changed further in the instruction set. However, whilst the dashed style seems to then apply to all subsquent edges as I was expecting, the weight attribute does not. The ony way I’ve managed to have the weight attribute apply is to state it separately for every edge that that I define.

Thanks for reading and, in advance, for any pointers.

Please include a sample input file. Also, which engine (dot, neato, …)? and what version of Graphviz (dot -V)?
But yep, should work as you expected.

Thanks for getting back. Sorry for the ommissions. Here are answers to your Qs:
Engine is dot. At the cmd prompt, dot -V tells me: dot - graphviz version 3.0.0 (20220226.1711). And my input file is this:

digraph Q {

   //Define global defaults here. Some exmaples:
      // graph [splines=false]
      edge [style=dashed] //weight=9]

   //Nodes.
   "Start" [shape=oval, style=filled, color=blue]
   "Run XRef" [shape=rect]
   "InputFile.ahk" [shape=rect]
   "Tidy XRef ouput" [shape=rect]
   "Read XRef file to var" [shape=rect]
   "InputFile.xref" [shape=rect]
   "For each line in var" [shape=rect]
   "Last line in var?" 
      [shape=diamond margin=".001, .1"]
   "sWord = 1st word on line from col 1" [shape=rect]
   "Does sWord match my\nnaming convention?" 
      [shape=diamond, margin=".001, .05"]
   "Log that line from var" [shape=rect]
   "Prepare & write output" [shape=rect]
   "End" [shape=oval, style=filled, color=blue]

   //Ranks
   {rank=same "Run XRef" "InputFile.ahk"}
   {rank=same "InputFile.xref" "Read XRef file to var"}

   //Edges
   "Start" -> "Run XRef" -> "Tidy XRef ouput"
   -> "Read XRef file to var" -> "For each line in var"
   -> "Last line in var?":n 
   [weight=9]

   "InputFile.ahk" 
   -> "Run XRef"

   "InputFile.xref" 
   -> "Read XRef file to var"

   "Last line in var?":w 
   -> "Prepare & write output":n 
   [label=yes]

   "Prepare & write output" 
   -> "End":n

   "Last line in var?":s
   -> "sWord = 1st word on line from col 1":n 
   [label=no] 
   [weight=9]

   "sWord = 1st word on line from col 1":s 
   -> "Does sWord match my\nnaming convention?":n
   [weight=9]

   "Does sWord match my\nnaming convention?":s 
   -> "Log that line from var":n 
   [label=yes]
   [weight=9]

   "Log that line from var":e 
   -> "For each line in var":e 

   "Does sWord match my\nnaming convention?":e 
   -> "For each line in var":e 
   [label=no]
   }

This works as expected because weight is specified for each edge. If I comment-toggle all the weight instructions (I’m using “//” to comment out), this leaves only the top one (line 5) active. But then I no longer see the weight attribute being applied.

Hope this helps improve my question and thanks for taking a look - very much appreciated.

Hmmm, the input you provide does not have weight=9 applied to every edge, only about half.
For example "Log that line from var":e -> "For each line in var":e does not have a weight attribute.
I created two variants of your graph - one with a weight=9 global default and one with weight=9 applied to each edge. They produced (seemingly) identical results.
The Graphviz syntax & semantics are a bit “eclectic” (see Comma separated list of node IDs), could this be causing confusion?

p.s. If you are trying to vertically align your nodes, you might look at group (group | Graphviz), instead of weight

Ah, your reply gave me the clue. Firstly, yes I am trying to vertically align nodes. But by applying weight=9 to the last two edges in my example, Graphviz is trying to make them straighter (or an analogy might be that the edges are stiffer in a structural sense). If these last two edges are stiffer, then this competes with the ‘stiffness’ of edges above and I guess the algorithm deforms more edges to minimise overall deflection. So my global default setting of “weight=9” was indeed working, it was just producing results that I wasn’t expecting!! Thanks so much for the clue, I’ve a much better understanding of “weight” now.

Now to the potential gold in your reply - the use of the Group attribute to align nodes - this is exactly what I’m wanting to do! I’d not heard of the group attribute before. I’ve followed your link to the docs, read that but have to confess that I don’t fully understand how to use it. I’ll study it some more on some simple examples to see if I can figure it out. But that’ll have to be a little later now. If I have probs I’ll post in a new thread related to the Group Attribute.

Thanks very much for helping me along here.