This article provides steps, using IronPython, to work with zoom sliders, scrollbars and other elements of Spotfire® visualizations. Here is a collection of scripts in that category.
Introduction
Using IronPython, we can work with zoom sliders, scrollbars, and other elements of Spotfire® visualizations. Here is a collection of scripts in that category.
Reset All Zoom Sliders on the Active Page
This script resets all zoom sliders on the active page. It has two optional parameters:
- resetX - Boolean - controls the resetting of the X-Axis zoom slider
- resetY - Boolean - controls the resetting of the Y-Axis zoom slider
The script shows some interesting tips:
- You can check if a variable is present by using vars().has_key('variableName')
- You can typecast a visualization to a specific type
- You can check the type of visualization - remember that each visualization is a "descendent' of the Visual class
from Spotfire.Dxp.Application.Visuals import * # set resetX, resetY to defaults if they have not already been set if not vars().has_key('resetX'): resetX = True if not vars().has_key('resetY'): resetY = True typedVisualisation = None for vis in Application.Document.ActivePageReference.Visuals: # depending on the type of visualisation passed, cast it to the appropriate type # if it is a visualisation which cannot have a zoom slider, it is ignored if vis.TypeId.Name=="Spotfire.ScatterPlot": typedVisualisation = vis.As[ScatterPlot]() elif vis.TypeId.Name=="Spotfire.BarChart": typedVisualisation = vis.As[BarChart]() elif vis.TypeId.Name=="Spotfire.LineChart": typedVisualisation = vis.As[LineChart]() elif vis.TypeId.Name=="Spotfire.CombinationChart": typedVisualisation = vis.As[CombinationChart]() # if the visualization was a compatible one, reset the sliders if typedVisualisation is not None: if resetX: typedVisualisation.XAxis.ZoomRange = AxisRange.DefaultRange if resetY: typedVisualisation.YAxis.ZoomRange = AxisRange.DefaultRange typedVisualisation = None
Toggle All Zoom Sliders on the Active Page
This script toggles the zoom sliders on all applicable visualizations.
# # Toggle All Zoom Sliders # Andrew Berridge, TIBCO Software, November 2011 # # This script toggles on/off all zoom sliders on the current page. Zoom sliders # are not available on all visualisations, so this script just affects the visualisations # that support zoom sliders from Spotfire.Dxp.Application.Visuals import VisualContent from Spotfire.Dxp.Application.Visuals import AxisRange from Spotfire.Dxp.Application.AnalyticItems import BookmarkManager from Spotfire.Dxp.Application.AnalyticItems import Bookmark from Spotfire.Dxp.Application import BookmarkComponentFlags for vis in Application.Document.ActivePageReference.Visuals: try: plot=vis.As[VisualContent]() plot.XAxis.ManualZoom=not (plot.XAxis.ManualZoom) except: print "no X axis" try: plot.YAxis.ManualZoom=not (plot.YAxis.ManualZoom) except: print "no Y axis"
Check the Position of Scroll Bars in all Cross Table Plots
This script is useful for checking the position of all the scroll bars in all the cross-table plots in an analysis file. There's no (easy) way to reset the scroll bars, but you can at least check that they are at the top-left position before publishing the analysis.
from Spotfire.Dxp.Application.Visuals import * from Spotfire.Dxp.Application.Visuals import VisualTypeIdentifiers, VisualContent def checkScrollBars(): #Check scroll bar positions for p in Document.Pages: for vis in p.Visuals: if vis.TypeId.Name == 'Spotfire.Table' or vis.TypeId.Name == 'Spotfire.CrossTable' : vc = vis.As[VisualContent]() layout = vc.CreateLayout() if layout.ScrollPosition.X != 0 or layout.ScrollPosition.Y != 0: print ' Warning: The scroll bars for "' + vc.Title + '" on the page "' + p.Title + '" are not in the correct position.' print 'Completed checkScrollbars()' checkScrollBars()
Recommended Comments
There are no comments to display.