I think the behavior is happening because some code is iterating through some collection of nodes, in a particular order, assigning the Part.zOrder. As each assignment is made, the node is “moved” in the Layer.parts list’s sequence. As the node is “moved” in the list, it is only moved the minimal amount in order to satisfy the requirement imposed by the value of the Part.zOrder.
Imagine these nodes sorted by zOrder in the layer’s parts list:
So when moving the lightblue and orange nodes forward (i.e. more in front, or at higher indexes in the list, here shown towards the right), let’s say we move the lightblue node first by setting its zOrder to 7:
Then we move the orange node by setting its zOrder to 7:
The minimal move within the list is what is causing the changed paint order. But officially that is OK because GoJS does not guarantee the ordering of parts with the same value.
Parts that have zOrder that is NaN aren’t rearranged in the layer’s parts list, so they don’t happen to change apparent paint order until you remove them from the layer and then put them back in again.