Enhancing a Package: Displaying Charts
Follow these steps to add charts to a Package.
In the previous article, we allowed our model to vary with time. Now we will add the ability to graphically visualize the model outputs using charts.
Note
The final materials for this article can be downloaded using the following links:
Step 1 - Add Charts to the XML Configuration File
Transformers
First, we must include a new Transformer within the Primary Transformer in the XML configuration file called corestime_Runtime. This Transformer uses the Runtime Transformer from the corestime built-in SyncroSim core to store chart information. The <include> tag tells the Package loader to reference Transformers in other Packages.
<!--Primary Transformer-->
<transformer
name="Primary"
isPrimary="True"
programName="Rscript"
programArguments="model.R">
<!--Chart Transformer-->
<include>
<transformer name="corestime_Runtime"/>
</include>
<datafeeds>
Datafeeds and Datasheets
We must add an Iteration column to the OutputDatafeed. Although we will not be using iterations in this tutorial, this column is required by the built-in charting software. We will revisit setting iterations for modelling uncertainty in the next article. This column also has a new attribute called isOptional. By default, all columns after ScenarioID are displayed in the SyncroSim Windows Interface. When isOptional is set to "True", the column is hidden unless manually inserted by the user.
<!--Model Output-->
<datafeed name="OutputDatafeed" displayName="Outputs" dataScope="Scenario">
<datasheets>
<datasheet name="OutputDatasheet">
<columns>
<column name="OutputDatasheetID" dataType="Integer" isPrimary="True"/>
<column name="ScenarioID" dataType="Integer"/>
<column name="Iteration" dataType="Integer" isOptional="True"/>
<column name="Timestep" dataType="Integer"/>
<column name="y" dataType="Double" displayName="Value for y"/>
</columns>
</datasheet>
</datasheets>
</datafeed>
Layouts
Next, we need to add two new layouts to the configuration file. The first layout, named coreforms_ResultTransformers, creates the result panel in the bottom left-hand corner of the SyncroSim Windows Interface. The second layout, named corestimeforms_Charts indicates which data from the specified datasheets will be used in this chart display. This data will show up in the left-hand criteria window when creating a new chart. This second new layout also contains an attribute called configurationSheet, which is set to the RunControl datafeed. This attribute ensures the charting software recognizes the Timestep column in the RunControl datafeed and adds plotting functionality based on this column.
<layouts>
<!--Results Transformer Layout-->
<layout name="coreforms_ResultTransformers">
<item name="corestime_ChartTransformer"/>
</layout>
<!--Library Datafeeds Layout-->
<layout name="coreforms_LibraryDatafeeds">
<item name="core_Rconfig"/>
</layout>
<!--Scenario Datafeeds Layout-->
<layout name="coreforms_ScenarioDatafeeds">
<item name="RunControl"/>
<item name="InputDatafeed"/>
<item name="OutputDatafeed"/>
</layout>
<!--Charts Layout-->
<layout name="corestimeforms_Charts" configurationSheet="RunControl">
<item name="y" displayName="y" dataSheet="OutputDatasheet" column="y"/>
</layout>
</layouts>
Step 2 - Rebuild the Package
Use the Package Manager to rebuild the Package using the new package.xml and model.R files shown above (see Step 4 in the Building a Package article).
Step 3 - Set Model Inputs
- Start SyncroSim.
- Create a new library based on the helloworldEnhanced Package.
- Create a new Scenario - Right-click in the Library Explorer and select New > Scenario from the context menu. Rename this scenario to Timesteps Added.
- Edit the Scenario Run Control - Within the Timesteps Added Scenario, navigate to the Run Control tab. Set the Minimum Timestep and Maximum Timestep values for your model.
- Edit the Scenario Inputs - Re-enter the values for m and b.
Step 4 - Run the Model
Right-click on this Timesteps Added Scenario again in the Library Explorer and select Run to run this Scenario.
Step 5 - View the Results
- Once the run is complete, return to the Library Explorer. Expand the node beside the Timesteps Added scenario to reveal a Results folder containing your results, then expand the node beside the Results folder to show the newly generated date/time stamped Results Scenario. Each Results Scenario contains a read-only snapshot copy of all your inputs at the time of your run, along with values for your model generated outputs.
- Right-click on this Results Scenario and select Properties to view the details of this Results Scenario; you will find your calculated outputs at each timestep under the Outputs tab.
- In the bottom left-hand corner, a Results Viewer should now be visible with a Charts tab. Within this viewer, click on the Create a new chart button.
- Fill in a name, select the y variable from the left panel, and click Apply to graphically view the change in y over time. To make further modifications to your chart, such as adding X and Y axes, see the Customizing a Chart tutorial.