问题
This is my first post here, so please forgive me if I fail at etiquette somewhere along the way.
I am working on a POC dealing with animating a visualization within Tibco Spotfire 7.0 which will allow a user to see changes in data over time by iterating through a set of filters or by iterating through alterations to the data based on a pre-determined set of conditions. TIBCOmmunity already defines a custom tool for this purpose http://tibcoanalytics.com/spotfire/archive/totw/2011-01-16.html. However, it is my task to show that this can be done within an Iron Python script. The POC is rather simple in concept, I need an Action Control to move a point on a scatter plot around in a circle. Below is the Python I'm working with so far. The issue I am having is forcing Spotfire to update/refresh the visualization inside the loop. Help?
import time
import math
R = Rad; #parameter containing the radius of the circle
x_0 = xc; #parameter containing the center x coord
y_0 = yc; #parameter containing the center y coord
t=0.00
while t<(2*math.pi):
x = R*(math.cos(t)) + x_0;
y = R*(math.sin(t)) + y_0;
t+=0.01
Document.Properties['xc'] = x
Document.Properties['yc'] = y
#code to force the visualization/document to refresh/update goes here
time.sleep(1/360)
回答1:
this does not directly answer your question but provides you with a method of creating a timer that can interact with document properties. sorry that I don't have time to provide an explicit answer. as such feel free not to mark it accepted -- maybe someone else has a better one.
the reason that your code doesn't work is because the IronPython engine locks Spotfire until execution is completed. you're not far off in assuming that the visualization doesn't update: in fact the entire application doesn't update! you can test this as I mentioned in my comment by setting the sleep value to 1 second.
I created this DXP some time ago to illustrate how to allow IronPython and Javascript code to interact with each other inside of textareas. the IP->JS page should give you some clues on how to build your animation solution.
what's going on behind the scenes here:
- a Spotfire Property Control (Input area) inside of a
<div>
allows the user to enter text - a Javascript function called
update
runs periodically:var timer = setInterval(update, 1000);
- the
update
function uses JQuery to access the input area via its parent<div>
:var text_in = $("#input_container").text();
update
finally replaces the text in an "output" container<div>
with the modified text:$("#output_container").html(rainbowize(text_in));
you can modify this example to use JQuery to output to a document property-linked input area. in other words, use the Javascript timer setInterval()
instead of time.sleep()
.
I hope I've done a decent job of explaining that. let me know if it was unclear :)
来源:https://stackoverflow.com/questions/32487595/animating-data-changes-in-tibco-spotfire