Actions can be defined on all dynamic items in a graphical table or in a text area. Below is an example of what you can do by setting up an IronPython script action on two dynamic items of the type calculated value in a graphical table.
Configure Details Visualization Example
This example uses a fictive data table containing sales and cost for a number of products in the different states of USA. The graphical table has been set up to show all states on the Rows axis and two dynamic items of the type calculated value have been added, displaying the sum of sales and the sum of cost, respectively:
Another visualization, a line chart, has been set up to show either the sum of sales or the sum of cost for the marked state in the graphical table over the time, thus displaying the details behind the total sum for each state. In contrast to a standard details visualization controlled by the marking, this visualization will display different data depending on which cell you click on; clicking in the Sales column will show the sales for that state and clicking in the cost column will show the cost.
This is done using an action script on the columns in the graphical table which sets what to show on the Y-axis and automatically limits the line chart by a boolean expression set to display data for the state of the clicked row in the graphical table only. The title of the details visualization is also updated by the script:
To add the action to the graphical table columns:
Open the Calculated Value Settings dialog for the first column and go to the Actions page.
Select the Perform action on click check box.
Click on Settings....
Response: The Action Settings dialog is displayed, providing you with the same options as when inserting action controls in the text area.
Go to the Script page.
Click New....
Type a Script name (for example, "Configure Details Visualization").
Type a Description (for example, "Configures a visualization to show details of a graphical table cell.")
Copy the script below and paste it into the Script field.
Comment: Note that the example script assumes that a column called "State" is available in the data table.
Click Add....
Type the Name detailsVis, as expected by the script.
Let the Type be a Visualization and select the line chart to use as the details visualization from the list.
Click OK in all dialogs to close them.
Add the defined script to the other column as well, to be able to show either Sales or Cost details in the line chart.
Script:
# This script is intended to be run as an action on a
# Calculated Value miniature visualization in a graphical
# table.
#
# It expects one Visualization argument, detailsVis, and
# it configures the specified visualization to show details
# for the clicked cell.
#
# When executed as an action in a graphical table,
# the variable Context is bound to an instance of
# MiniatureVisualizationActionContext (see API documentation).
from Spotfire.Dxp.Application.Visuals import VisualContent
# This script assumes that the row axis of the Graphical Table
# is configured with one column: State.
#
# Get the miniature visualization and the value of the row
# axis hierarchy (the state column) for the clicked cell:
clickedMiniVis = Context.Visualization
state = Context.HierarchyPathValues[0]
# Get the content of the visual that shall be configured to
# show details. Use the most general type so that the script
# works for all VisualContent classes that have a Y-axis
# property. This works well for a Line Chart, for instance.
vc = detailsVis.As[VisualContent]()
# Configure the Title and YAxis of the details visualization:
vc.YAxis.Expression = clickedMiniVis.ValueAxis.Expression
detailsVis.Title = clickedMiniVis.Title + " for " + state
# Limit the data of the details visualization to only use
# data for the selected state:
vc.Data.WhereClauseExpression = "State = \"" + state + "\""
See also: