Jump to content
We've recently updated our Privacy Statement, available here. ×
  • How to Set the Layout of the Visualizations on a Page in Spotfire® using IronPython


    Introduction

    With new the capabilities in the LayoutDefinition API, introduced in Spotfire 7.8, it is possible to specify proportions (vertically or horizontally) to get full control over the layout of the visualizations on a page. This makes it possible to get the same kind of layout that is possible to achieve by manually arranging visuals on a page.

    The feature may be useful, for example, when automating dashboard creation, building tools similar to data relationship tool that creates new pages with many visualizations or when there is a need to have a set of pre-defined layouts.

    converted-file.thumb.png.ad690a24d9ac16ce6cc0c5d73f3e6834.png

    To capture the current layout of an existing page, use the GetVisualBounds method.

    Code sample

    The layout in the image above is achived by running the following script

    # Copyright © 2017. TIBCO Software Inc.  Licensed under TIBCO BSD-style license.
    
    from Spotfire.Dxp.Application.Layout import LayoutDefinition
    
    page = Document.ActivePageReference
    activeVisual = page.ActiveVisualReference
    layout = LayoutDefinition()
    layout.BeginSideBySideSection()
    layout.Add(activeVisual, 70)
    layout.BeginStackedSection(30)
    for visual in page.Visuals:
    	if visual != activeVisual:
    		layout.Add(visual)
    layout.EndSection()
    layout.EndSection()
    page.ApplyLayout(layout)
     

    The extended sample below (also in the attached .dxp file) shows and extended version of the previous script. It uses a text area with an action control to trigger the layout script. The text area is always placed on top on the page, and a document property controls by index which of the visualizations that is the main visualization and placed in the larger section in the layout. Each time the action control button is clicked, the next visualization on the page will be the main visualization.

    # Copyright © 2017. TIBCO Software Inc.  Licensed under TIBCO BSD-style license.
    
    from Spotfire.Dxp.Application.Layout import LayoutDefinition
    
    page = Document.ActivePageReference
    mainVisualIndex = Document.Properties["mainVisualIndex"]
    
    visuals = []
    for visual in page.Visuals:
    	if visual != inputTextArea:
    		visuals.append(visual)
    
    mainVisualIndex = mainVisualIndex % (len(visuals))
    Document.Properties["mainVisualIndex"] = mainVisualIndex + 1
    
    layout = LayoutDefinition()
    layout.BeginStackedSection();
    layout.Add(inputTextArea, 10)
    layout.BeginSideBySideSection(90)
    layout.Add(visuals[mainVisualIndex], 70)
    layout.BeginStackedSection(30)
    for index in range(len(visuals)):
    	if index != mainVisualIndex:
    		layout.Add(visuals[index])
    layout.EndSection()
    layout.EndSection()
    layout.EndSection()
    page.ApplyLayout(layout)
      

    References

    Other Examples

    License:  TIBCO BSD-Style License

    Back to IronPython Scripting in Spotfire Examples

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...