Jump to content

IronPython scripting to apply coloring to crosstable cells by logic


achen1

Recommended Posts

Hello Spotfire team, 

I have a cross table visualization on Spotfire and I am trying to create an iron python script for a drop-down list property control that will apply a color filter on a column named "Norwood" in my visualization based on the logic 

if value in cell = "Runs" then color the cell red

if value in cell = "OOC" then color the cell orange

Ive been reading the spotfire API documentation for CrossTablePlot Class linked below but it is unclear to me how the Properties work

https://docs.tibco.com/pub/doc_remote/sfire_dev/area/doc/api/TIB_sfire-analyst_api/Index.aspx

Link to comment
Share on other sites

The drop down will have two string options, "1" or "0". This is allow users to turn on or off the coloring logic that will be applied to the column named "Norwood"

If user selects "1" then the color filtering will be applied 

If user selects "0" then the color filtering will be unapplied. 

I have started the Iron Python script (screenshot attached). 

Capture.PNG

Link to comment
Share on other sites

I would build two document color schemes (FilterOn and FilterOff). Your script can toggle between them.

Create the two document color schemes:

  • In the Cross Table properties > Colors page
    • Create a "FitlerOn" color scheme group
      • image.png.c9cc3761b39b89e5f523f8e6300b8b51.png
    • Save these settings using the Color Schemes button > Save As > Document Color Scheme...
      • image.png.7ea9c84e809e5d03e87dfc23a68f759b.png
      • Call this one FilterOn
    • Repeat the above steps for the FilterOff settings
    • Notice that both of the Document Color Schemes exist and can be selected
      • image.thumb.png.cb5a417a6b4dd0fc0d46c2a2fac983f3.png

I tried to modify your code to include the toggle between the two Document Color Schemes:

from Spotfire.Dxp.Application.Visuals import CrossTablePlot
page = Document.ActivePageReference

for vis in page.Visuals:  
  if str(vis.Title) == "Combined Alert Table":
    myCrossTable = vis.As[CrossTablePlot]()

    if Document.Properties["ColorSwitch"] == "1":
      for coloring in myCrossTable.Colorings:
        if coloring.DisplayName == 'FilterOff' or coloring.DisplayName == 'FilterOn':
          print("filer ON")
          coloring.Clear
          coloring.Apply("FilterOn")
          
      
    else: #ColorSwitch is not 1
      for coloring in myCrossTable.Colorings:
        if coloring.DisplayName == "FilterOff" or coloring.DisplayName == "FilterOn":
          print("filter OFF")
          coloring.Clear
          coloring.Apply("FilterOff")

There may be many different color scheme groupings in your chart (some dates, some numbers, etc.). I tried to use the coloring.DisplayName to identify the correct color scheme grouping to toggle.

Link to comment
Share on other sites

I was thinking of a different way to accomplish this. You can use a custom expression to toggle the color/logic on and off.

  1. Create a color scheme grouping
    1. I called my example "MyColumn"
      1. I included the column that contains the data like Runs, OOC, etc.
  2. Make sure you click on the "MyColumn" item in the color scheme groupings list and then enable the check box "color the grouping using anther expression"
  3. Edit the custom expression "Color Logic" and place the expression in
    1. First(
      Case DocumentProperty("ColorSwitch") 
        when "1" then //Turn On
          case [Value] 
            when "Runs" then "Red" 
            when "OOC" then "Orange"
            else "Other"
          end 
        when "0" then "Other" //Turn off
        else "Other"
      end
      )

       

  4. Set the color mode to Unique values and configure the Red, Orange, Other, and Empty colors accordingly

image.png.84bdd1d2556f1b7428632d113f5ab969.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...