Here is a code snippet for removing markings across visualizations/data tables within an analyses. This script will not reset the filters and only work on the marking. To illustrate this, I have constricted the date range for couple of date filters in the filter column.
I will now make some selections on the bar chart
To remove the markings without resetting the applied filters, we can execute the script through the button Reset Markings
Code snippet for reference:
# Import required libraries from Spotfire.Dxp.Data import * from Spotfire.Dxp.Application.Filters import * def resetMarking(): # Loop through each data table for dataTable in Document.Data.Tables: # Navigate through each marking in a given data table for marking in Document.Data.Markings: # Unmark the selection rows = RowSelection(IndexSet(dataTable.RowCount, False)) marking.SetSelection(rows, dataTable) # Call the function resetMarking()
Below is one more use of the snippet applied for multiple visualizations which use cascading markings.
When the analysis contains multiple markings, then visualizations using these multiple markings have to be set individually. Below I am removing the marking for a single data table.
Though we Unmark marking for a single visualization, the markings which have got applied through cascading are not reset in other visualizations. In the bottom visualization, the markings are not reset as it inherits markings from the center visualization.
In such cases, our script should do the job.
Below is a code snippet to pull data from a data table into Script context. The data from a particular column(s) could be used to perform validations or compared against values from other data tables.
from Spotfire.Dxp.Data import *tableName='SuperStore_Sample' columnToFetch='Order Date' activeTable=Document.Data.Tables[tableName] rowCount = activeTable.RowCount rowsToInclude = IndexSet(rowCount,True) cursor1 = DataValueCursor.CreateFormatted(activeTable.Columns[columnToFetch]) ctr1 = 0 for row in activeTable.GetRows(rowsToInclude,cursor1): rowIndex = row.Index val1 = cursor1.CurrentValue ctr1 = ctr1 + 1 if (ctr1 == 5): break
Further, we could push the data into an array for temporary storage and use as per requirement.
In some cases (for ex. Trellis view), to get more visualization space, we could simply hide the legend.
For this, on change of View Type (using a drop down property control – ViewType), I am invoking a script to show or hide the legend.
Below, creating the property control ViewType:
IronPython Code: from Spotfire.Dxp.Application import Visuals from Spotfire.Dxp.Application.Visuals import LineChart from Spotfire.Dxp.Application.Visuals import Legend for vis in Application.Document.ActivePageReference.Visuals: if vis.Title == "Sales - Trellis View": vis.As[LineChart]().Legend.Visible = False if vis.Title == "Sales - Full View": vis.As[LineChart]().Legend.Visible = True
IronPython Code to reset all applied visible filters:
import Spotfire.Dxp.Application.Filters as filters from Spotfire.Dxp.Application.Filters import * # Navigate through each page in the analyses for eachPage in Document.Pages: # Get the active data table in the current page activeTable = eachPage.ActiveDataTableReference # Get the set of all table groups in the current page tableGroup = eachPage.FilterPanel.TableGroups # Navigate through all the table groups in the filter panel of current page for t in tableGroup: # To filter on the active data table used in the filter panel if (t.Name == activeTable.Name): # In table group (data table), navigate through the filter groups for filterSubGroup in t.SubGroups: # Navigate through the filters in each filter group for filterHandle in filterSubGroup.FilterHandles: filterReference = filterHandle.FilterReference # Reset if the filter is visible if filterHandle.Visible==True: filterReference.Reset() print "Reset done for: " + eachPage.Title + '.' + t.Name + '.' + filterSubGroup.Name + '.' + filterReference.Name if filterHandle.Visible==False: print "Reset not done for: " + eachPage.Title + '.' + t.Name + '.' + filterSubGroup.Name + '.' + filterReference.Name
Please take note that this script can be used to not reset the hidden filters in the analyses. That is, this will reset all the visible filters which are part of filter groups across all the pages in the analyses.
Snapshot for indentation reference: