IronPython to Reset Zoom Sliders

  • Are you tired of manually adjusting Spotfire zoom sliders?
  • Would you like a button or control that lets you reset the zoom sliders?
  • Would you like to learn a bit more about IronPython in Spotfire?

In 7.13, TIBCO added auto-zoom for zoom sliders so that when data changes (e.g, when filtering) and/or when sliders are at the end of their range, they adjust.  However, not all users are at 7.13.  Additionally, you might still want a button to reset zoom sliders.  This can easily be done with an IronPython script.

IronPython in a Screen Shot

IronPython Code in Copy/Paste Form

from Spotfire.Dxp.Application.Visuals import VisualContent
from Spotfire.Dxp.Data import Range

for rVis in Application.Document.ActivePageReference.Visuals:
print rVis.Title
if (rVis.Title).strip() == “Pumping Efficiency per Hierarchy”:
vc=rVis.As[VisualContent]()
vc.XAxis.ZoomRange = vc.XAxis.ZoomRange.DefaultRange
vc.YAxis.ZoomRange = vc.YAxis.ZoomRange.DefaultRange

for rVis in Application.Document.ActivePageReference.Visuals:
print rVis.Title
if (rVis.Title).strip() == “Pumping Efficiency per Well (or Pad)”:
vc=rVis.As[VisualContent]()
vc.XAxis.ZoomRange = vc.XAxis.ZoomRange.DefaultRange
vc.YAxis.ZoomRange = vc.YAxis.ZoomRange.DefaultRange

Notes About the Code

  1. You’ll notice this code snippet does not have any parameters.  The code knows which visualization to interact with based on the visualization title in the code.
  2. There is a line of code to reset the X-Axis and a line of code to reset the Y-Axis.  Remove one line of code if you only have zoom sliders on one axis.
  3. To reset the zoom slider on multiple visualizations, just copy and paste.

Steps to Implement

  1. Add a Text Area
  2. Right-click, select Edit HTML
  3. Click the insert Action Control button
  4. Type in a name for the button, such as “Reset Zoom Sliders”
  5. Click the Script button
  6. Name the script.  Note, you may want to use this script more than once in a project.  I recommend using one script per page, which means give it a name to distinguish it from others in the project.
  7. Copy and paste the script.
  8. Edit the visualization names.
  9. Add or subtract lines of code depending on whether the zoom slider is on the X or Y axis as noted above.
  10. Edit according to how many visualizations need to be reset as noted above.
  11. Click Run to test.

And you’re done!

Spotfire Version

Content created with Spotfire 7.12.

 

If You Liked This Post…

Check out this post on using IronPython to turn labels on and off.

 

 

 

Guest Spotfire blogger residing in Whitefish, MT.  Working for SM Energy’s Advanced Analytics and Emerging Technology team!

3 thoughts on “IronPython to Reset Zoom Sliders

  1. Hi Julie! Love your posts & have shared with several friends that are trying to get started in Spotfire.

    I used your code today to perfectly solve this issue with the resetting zoom sliders automatically. Thanks for sharing!

Leave a Comment

Your email address will not be published. Required fields are marked *