To update a document property, trigger an ironPython script when a calculated value executes based on marking or filtering and even pass the value to a javascript variable, the flow is:
Spotfire Expression ➭ r Input Variable ➭ r Output Variable ➭ Document Property ➭ Property Control ➭ Javascript Variable
The Data Function takes an expression through the input parameter 'a' and passes the value to 'b' which is then stored in a 'c' document property. When the document property changes, an iron python script executes which adds a space to a text area. This forces the text area to refresh, triggering its javascript that extracts the document property value from a label control. There are ways to avoid using the iron python and datafunciton all together by using a calculated value or any property control on a text area by using a javascript timer interval.
Spotfire Expression ➭ r Input Variable ➭ r Output Variable ➭ Document Property ➭ Property Control ➭ Javascript Variable
The Data Function takes an expression through the input parameter 'a' and passes the value to 'b' which is then stored in a 'c' document property. When the document property changes, an iron python script executes which adds a space to a text area. This forces the text area to refresh, triggering its javascript that extracts the document property value from a label control. There are ways to avoid using the iron python and datafunciton all together by using a calculated value or any property control on a text area by using a javascript timer interval.
- Go to Edit>Data Function Properties and Register a new simple TERR Data Function that takes an input and returns the same input. For example:
b <- a #pass the value of a to b - Run the function and set the input parameter 'a' as an Expression (limited by marking or current filtering) and the output parameter 'b' as a Document Property. Make sure the input handler expression is limited by the active filtering or marked rows. The function must be set to auto refresh and run locally.
- At this point, every time the number of filtered rows changes, the expression will send the result to the document property 'c', which now behaves like a Calculated Value with python capabilities. To demonstrate, add a Label Property Control on a Text Area to show the value of 'c'
- To pass this document property to a javascript variable, extract the value of the Label Property Control with Javascript. For example:
html:
<span id='d' style='border:1px solid black'><SpotfireControl id="77fa68f4471f48b2a51e0b2c9049f1d1" /></span>
javascript:
#extract doc prop 'c' from div 'd' and stores it in javascript varialbe 'e' and animates the div 'd' width to 'e' pixels
function refreshWidth(){ e=d.innerText $("#d").animate({width:e+"px"},500)}
//trigger refreshWidth refreshWidth() - Finally, to trigger this javascript every time the document property changes, add a python script to force refreshing the text area.
from Spotfire.Dxp.Application.Visuals import HtmlTextArea
textArea.As[HtmlTextArea]().HtmlContent += " "
As an alternative, use the refreshWidth Javascript function in a timer. Use either one, but not both!
setInterval(refreshWidth,500) //trigger every .5 sec)
3 comments:
Awesome article. Put this into practice today, and opens up some great possiblities. Thanks a million.
Thanks, very helpful and simple to setup
Hey Great Article,
Just wanted to know how can we modify this for multiple values?
You've set the value of a as an expression with count function.
What if i wanted to store all the marked values in a and then pass it to be which will be eventually set as a drop down document property?
Post a Comment