hongji.li
2023-11-11 df5a7e1ad6835e78b2f9eb7428817b0c23b116bc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Quintiq file version 2.0
#parent: #root
Method AdjustTrees () id:Method_FormSupplyChainVisualization_AdjustTrees
{
  #keys: '[132894.0.984127057]'
  Body:
  [*
    // Adjust trees position, this is the last step of populate Y position
    // If downstream tree taller, we adjust upstream tree, vice versa
    scvConfig := DataHolderSCVConfiguration.Data();
    
    root := select( scvConfig, SCVNode, node,
                    node.IsRoot() );
    
    // To adjust the tree Y position, we pre-compute the root node position
    // from upstream and downstream, whoever is at the higher position, needs
    // to adjust its side lower 
    this.AdjusNodeYPos( root, true /*isupstream*/ ); 
    upStreamY := root.Y();
    this.AdjusNodeYPos( root, false /*isupstream*/ );
    downStreamY := root.Y();
    
    offset := upStreamY - downStreamY;
    isupstream := false;
    
    // If upStream is higher, move it down
    // vice versa
    if( offset < 0 )
    {
      isupstream := true;
    }
    
    // Adjust the whole side of the tree
    traverse( scvConfig, SCVNode, node,
              node.IsUpstream() = isupstream )
    {
      node.Y( node.Y() + abs( offset ) );
    }
    
    root.Y( ifexpr( offset < 0, downStreamY, upStreamY ) );
  *]
}