This article show how to perform "Filter To Marked Rows" in Spotfire® using IronPython scripting
Introduction
Marked items in a visualization can be used to filter to data when working with in-memory data tables. Make sure you have marked the items you want to filter to in the analysis. This example shows how the below manual steps may be automated using IronPython scripting.
Right-click in the visualization and select Marked Rows > Filter To.
Code sample
# Copyright © 2017. TIBCO Software Inc. Licensed under TIBCO BSD-style license. # This implementation would include adding a tagging column to your dataset: #1) Select View .. Tags and add a new tag collection named “Filtered To” #2) Add two new tags: “Yes” and “No” #3) Link the following script to an action control button named “ShowOnlySelected” from Spotfire.Dxp.Data import * table = Document.ActiveDataTableReference marking = Document.ActiveMarkingSelectionReference rowMask = marking.GetSelection(table) tagsColumn = table.Columns["Filtered to"].As[TagsColumn]() tagged = [] index = -1 cursor = DataValueCursor.CreateFormatted(table.Columns["Filtered to"]) for row in table.GetRows(cursor): index = index + 1 if cursor.CurrentValue == "Yes": print "index " + str(index) + " is tagged" if rowMask.AsIndexSet()[index] == True: print "this is tagged and selected! index:" + str(index) tagsColumn.Tag("No", rowMask) # switch else: if rowMask.AsIndexSet()[index] == True: print "this is NOT tagged BUT selected! index:" + str(index) tagsColumn.Tag("Yes", rowMask) #This would create a new tag column which will show up in the FilterPanel as well. #This script sets the rowvalues of the column #“Filtered to” to Yes or No. #So to remove all nonselected values from the user view you would add the following at the bottom of #the above script: import Spotfire.Dxp.Application.Filters as filters myPanel = Document.ActivePageReference.FilterPanel myFilter = myPanel.TableGroups[0].GetFilter("Filtered to") cbFilter = myFilter.FilterReference.As[filters.CheckBoxFilter]() cbFilter.Uncheck("No") #Note: #The above script assumes you select all table rows and tag them as "No" once. #To do this using a script you can use the following: rowCount = Document.ActiveDataTableReference.RowCount rowsToInclude = IndexSet(rowCount,True) allrows = RowSelection(rowsToInclude) cursor = DataValueCursor.CreateFormatted(table.Columns["Filtered to"]) for row in table.GetRows(cursor): tagsColumn.Tag("No", allrows) #or you could use “Untagged” as your "No" indicator in the first script. #So instead of unchecking "No" in the filter panel you would uncheck "Untagged".
References
License: TIBCO BSD-Style License
Back to IronPython Scripting in Spotfire Examples: https://community.spotfire.com/s/article/IronPython-Scripting-in-TIBCO-Spotfire
Recommended Comments
There are no comments to display.