How to Set the Layout of the Visualizations on a Page in TIBCO Spotfire® using IronPython
Last updated:
6:36am Jun 25, 2018
Back to main IronPython scripting page

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.

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

Attachments

AttachmentSize
Binary Data layoutdefinitionexample.dxp482.1 KB

Feedback (1)

Thank you very much for the Example !

Hector Martinez 9:35pm May. 24, 2017