Script Fragments
One other useful application for fragments is a common repository for Lua scripts. In the following example, I have created a fragment that contains a function that can be used to draw an arbitrary square on a plot. With the fragment included at the base level of the document, any of the scripts in the document gain the ability to call the drawSquare function and pass it a data series and the square properties. In this example, the button creates a square using the fragment:
document.xml
<!-- Section 1 --> <section name="section1"> <xyPlot name="myPlot" xmax="10" xmin="0" ymax="10" ymin="0" xauto="fixed" yauto="fixed"> <series name="Series" manual="true"></series> </xyPlot> <button name="myButton" content="Draw Square"> <onClick> drawSquare(myPlot.Series, 8, 8, 5, 5); </onClick> </button> </section>
fragment3.xml
<fragment xmlns="http://resources.qdexapps.com/schema/v1/QDocument.xsd"> <script> function drawSquare(series, width, height, x, y) series:Add(x - width/2, y + height/2); series:Add(x + width/2, y + height/2); series:Add(x + width/2, y - height/2); series:Add(x - width/2, y - height/2); series:Add(x - width/2, y + height/2); series:Update(); end </script> </fragment>
which generates the following plot when the button is pressed.