Combining the SystemWeaver Script Language with the Path Query Language creates new possibilities for more complexity in your chart presentations. It allows you to navigate the selected structure to select items to be presented. This article presents some examples. 


Prerequisites


Charts are usually a very useful way to present complex data in an easy-to-read manner. Using the Script Language, you can present data from one item type at a time as shown in the below example.


Example Configuration

<Charts>

    <PieChart>

        <Slices>
            <Slice name="1" caption="Prio 1" color="blue"/>
            <Slice name="2" caption="Prio 2" color="red"/>
            <Slice name="3" caption="Prio 3" color="yellow"/>      
            <Slice name="unknown" caption="Unknown" color="green"/>
        </Slices>

        <Counter>
          <ForEachPart type="XESX">
            <DefObj>
                <ForEachPart type="EXAC">
                    <DefObj>
                        <ForEachPart type="IBAR">
                            <DefObj>
                                <ApplyItemTemplates/>
                             </DefObj>
                        </ForEachPart>
                    </DefObj>
                </ForEachPart>    
            </DefObj>
          </ForEachPart>
        </Counter>

    </PieChart>    

    <ItemTemplate type="RQ">
        <Choose>
            <When test="@PRIO = 1">
                <AddToSlice name="1"/>
            </When>
            <When test="@PRIO = 2">
                <AddToSlice name="2"/>
            </When>                
            <When test="@PRIO = 3">
                <AddToSlice name="3"/>
            </When>  
            <Otherwise>              
                <AddToSlice name="unknown"/>
            </Otherwise>        
        </Choose>  
    </ItemTemplate>

</Charts>


Example Result

The result should look similar to the example below.


This same chart can be configured using the Path Query Language as follows: 

<Charts>

    <PieChart>

        <Slices>
            <Slice name="1" caption="Prio 1" color="blue"/>
            <Slice name="2" caption="Prio 2" color="red"/>
            <Slice name="3" caption="Prio 3" color="yellow"/>      
            <Slice name="unknown" caption="Unknown" color="green"/>
        </Slices>

        <Counter>

          <ForEach select="/XESX/EXAC/IBAR">
               <ApplyItemTemplates/>
           </ForEach>

        </Counter>

    </PieChart>    

    <ItemTemplate type="RQ">
        <Choose>
            <When test="@PRIO = 1">
                <AddToSlice name="1"/>
            </When>
            <When test="@PRIO = 2">
                <AddToSlice name="2"/>
            </When>                
            <When test="@PRIO = 3">
                <AddToSlice name="3"/>
            </When>  
            <Otherwise>              
                <AddToSlice name="unknown"/>
            </Otherwise>        
        </Choose>  
    </ItemTemplate>

</Charts>


A Comment on the SystemWeaver Path Query Language

The Path Query Language is an immensely powerful tool when used correctly and it will, as seen above, make otherwise tedious tasks seem very simple in comparison to the conventional way of navigating large structures. However, although it is a powerful tool for navigation and for some logical operations, it is not the answer for all use cases. The <ItemTemplate> used in the previous example could be replaced with the Path Query Language operators, but this would make the code harder to read and, in some cases, harder to maintain. Many times it's preferable and easier to lift out functions and logic to make it the purpose of the code more clear. There are exceptions, of course, and in the above example only one item type is being evaluated. If there is more than one item type, then the script needs to be adapted to include either several <ItemTemplate> and/or to use the <ForEach> loop in an inventive manner depending on the situation.


Example Configuration

This example shows a chart displaying the counts of the different item types located below each Application Component.

<Charts>

    <PieChart>   
    
        <Slices>
            <Slice name="1" caption="SendSignal" color="blue"/>
            <Slice name="2" caption="RecSignal" color="red"/>
            <Slice name="3" caption="E2EFunction" color="yellow"/>      
            <Slice name="4" caption="Requirement" color="green"/>
        </Slices>   
        
        <Counter>  
        
          <ForEach select="/XESX/EXAC">
                <ForEach select="/ITOS">
                     <AddToSlice name="1"/>
                </ForEach>
                 <ForEach select="/ITIS">
                     <AddToSlice name="2"/>
                </ForEach>
                <ForEach select="/3E2F">
                     <AddToSlice name="3"/>
                </ForEach>
                <ForEach select="/IBAR">
                     <AddToSlice name="4"/>
                </ForEach>
          </ForEach> 
          
        </Counter>  
        
    </PieChart>    
    
</Charts>

Example Result

The result should look similar to the example below.