The Spotfire Community is moving to TIBCOmmunity and this forum location has closed. During the transition, you can still search the old forums but posting has been disabled. We encourage you to pick up the discussion at the new Spotfire community on TIBCOmmunity.
July 2010 - Posts - Tip of the Week

Tip of the Week

July 2010 - Posts

  • Adding Instructional Help Files into your Analysis Files in TIBCO Spotfire Professional

    It is very important to add instructions in your Analysis files in order to explain to others how they should use it.  This can be done in a variety of ways. The most direct way is to add Text Areas that contain the necessary information.  The downside of this approach is it takes up a lot of real estate in the analysis file.  Another viable approach would be to add a button which will launch the instructions in a popup dialog.  We will first show you how to do this in TIBCO Spotfire Professional, and then in a future post we will show you how to do this so it works in TIBCO Spotfire Web Player.

    Once we are done, you will have a small Text Area with just one button. When the user clicks on that button, a window will open above Spotfire with the instructions. This can be developed to be one instruction set for the entire analysis or one for each page. See the image below for what the final version could look like.

     



    To start with, we need to figure out where the instructions will be stored. Given this is meant for people only using Spotfire Professional and not the Spotfire Web Player (we will discuss how to do this for a Web Player file in an upcoming post), we need to be consider a user may be working offline and not connected to the internet or the Spotfire server. If this is not a concern, you can code the instructions in an HTML page and post them on a web server.  


    Then we need to launch a .NET windows.form which contains a Web Browser. The following code will launch a Web Browser in a windows.form control and display www.server.com/instructions.html inside it.

    import clr
    clr.AddReference("System.Windows.Forms")
    from System.Windows.Forms import Form, DockStyle, WebBrowser

    f = Form()
    f.Text = 'Instructions'
    f.Width = 800
    f.Height = 600

    wb = WebBrowser()
    wb.Navigate("http://www.myserver.com/instructions.html")

    # Layout
    wb.Dock = DockStyle.Fill
    f.Controls.Add(wb)

    # Display the Control

    f.ShowDialog()

    Let’s assume you cannot simply point to a file on a web server and you would like to keep the intstructions directly inside the Analysis File.    The best way to do this would be to write the instructions to a string, which is then stored in a temporary file, and referenced in the WebBrowser control.


    import clr
    clr.AddReference("System.Windows.Forms")
    from System.IO import Path, File
    from System.Text import StringBuilder
    from System.Windows.Forms import Form, DockStyle, WebBrowser

    sb = StringBuilder()
    sb.Append("<h1>Instructions for this Analysis</h1>")
    sb.Append("<p>Here you need to check to see if blah blah blah</p>")
    sb.Append("<p>After that you need to check to see if blah blah blah</p>")

    tempfilename = Path.GetTempFileName()
    newHTMLFile = Path.ChangeExtension(tempfilename, ".html")
    tempfile = open(newHTMLFile, 'w+b')
    tempfile.write(sb.ToString())
    tempfile.close()

    f = Form()
    f.Text = 'Instructions'
    f.Width = 800
    f.Height = 600

    wb = WebBrowser()
    wb.Navigate(newHTMLFile)

    # Layout
    wb.Dock = DockStyle.Fill
    f.Controls.Add(wb)

    # Display the Control
    f.ShowDialog()

    #Must delete the temp files so they do not persist on the users’ computer
    File.Delete(newHTMLFile)
    File.Delete(tempfilename)      

    A third option would be to list the instructions in a Document Property rather than as a string inside the Script.  To do this, you can create a Document Property and then store the instructions in that. The value of the property is limited, but there is more characters allowed in the Description, so you can use that field to enter the instructions.

     


    Then in your script, instead of building a string to pass in the instructions to the Web Browser, we can reference the description of this property and pass that in. Assuming our property is called page1Instructions, we can use the following code to reference the Description of that property.

    strInstructions = Document.Data.Properties.GetProperty(DataPropertyClass.Document, "page1Instructions").Description

    The complete script for this third option is shown below:

    import clr
    clr.AddReference("System.Windows.Forms")
    from System.IO import Path, File
    from System.Windows.Forms import Form, DockStyle, WebBrowser
    from Spotfire.Dxp.Data import DataPropertyClass

    strInstructions = Document.Data.Properties.GetProperty(DataPropertyClass.Document, "page1Instructions").Description

    tempfilename = Path.GetTempFileName()
    newHTMLFile = Path.ChangeExtension(tempfilename, ".html")
    tempfile = open(newHTMLFile, 'w+b')
    tempfile.write(strInstructions)
    tempfile.close()

    f = Form()
    f.Text = 'Instructions'
    f.Width = 800
    f.Height = 600

    wb = WebBrowser()
    wb.Navigate(newHTMLFile)

    # Layout
    wb.Dock = DockStyle.Fill
    f.Controls.Add(wb)

    # Display the Control
    f.ShowDialog()

    #Must delete the temp files so they do not persist on the users’ computer
    File.Delete(newHTMLFile)
    File.Delete(tempfilename)       


    Yet another solution would be to add a description into each Visualization using its Properties dialog. Then have the Script loop through all Visualization’s on the page and append its Title and Description using the StringBuilder.


    Remember, this solution only works in Spotfire Professional and Spotfire Enterprise Player, it will not work in Spotfire Web Player since it’s a .NET windows control we are displaying.  We will show you in an upcoming post how to create similar instructional dialogs for your files that you will share over the Web Player. To learn more about Script Controls, consider taking SP232: Automation APIs using IronPython

  • Comparing Lists Using List Logic

    Suppose you use Spotfire to create a dashboard showing your customer's purchases every quarter. With every updated dashboard, you may want to see which customers are new in your top 10, which customers have dropped out of your top 10, and which customers continue to remain in your top 10.

    To start, you need to create a list from the top 10 customers.  In your dashboard inside TIBCO Spotfire Professional, mark the top 10 and then right click on a visualization and select “New List from Marked. . .”

     

     

     

    Then, when next quarter’s dashboard is ready, you can create a new list with the Top 10 Customers from that following the same steps as above:

     

     

    We can then analyze any of our top 10 lists using the List Logic capabilities.  For example, if we want to see who was in our top 10 in Q2 but not in Q1 we can by creating a new list which contains the customers from the Top 10 Q2 list who are not in the Top 10 Q1 list.

     

     

     

     

  • Filtering values to display in a Property Control list box

    There are many times when you want to use a Property Control to display a list of Columns, but only show a subset of Columns rather than all of them.  This could be because only certain columns are relevant for your analysis, or it could be because you have so many columns, it would be unusable to display them all.  If you want to limit columns based off what is relevant for your analysis, you could use something like the datatype and choose to display only columns with a given data type.


    You can do this when you create the Property Control by specifying the datatype you want to limit to in the ‘Selectable columns’ field shown below.


     

     

    In this case, we are choosing to only show columns where the datatype is a string.


    What if you wanted to allow the consumer to define what to show in the property control?  We can do this with a combination of Property Controls and Script Controls.  This can be very useful if you have a Data Table with too many columns to show in a Property Control.


    First, we create an Input field Property Control:

     

     
    This Property Control is going to let a consumer enter a search string to use for selecting what Columns to display.  


    Then we create a multi-select List Box Property Control. This will be the Property Control which displays all the Columns matching our search criteria. This Property Control  allows us to use properties to limit the values shown in the list,  as we saw earlier when we limited by showing only String Columns. So, we will create a new property called isIncluded, and only show Columns where isIncluded is true.  This is done by adding isIncluded:True into the ‘Selectable columns (limit through expression)’ field:


     

     

    We now need to create the isIncluded property. This can be created in a variety of places, but the easiest may be to go to Edit > Column Properties and create it there.
     


    Then we add a Script Control. The Script Control will read the search criteria from the input Property Control, use it to find matching Columns in the Data Table, and then set the isIncluded property on those Columns to True.

    The Script Control will take in the value from the input Property Control as the and call is pattern. It will then loop through each Column and use the Python regular expression object to search for a match with the Column name and the pattern. If there is a match, the isIncluded property is set to True, otherwise, False.


     

    The End Result

    Entering a search expression in the input field and then clicking the 'Filter Columns' button will display only matching Columns in the list box Property Control.  For the search expression , use the pipe character (|), to add multiple search criteria. Other syntax follows Python regular expression syntax.


     

     

    To learn more about Property Controls, please take either our Authoring Bootcamp  or our 3.1 Delta Training course. To learn more about Script Controls, please take either our Developer Bootcamp or our Automation APIs using IronPython course.

     

    Also, remember to sign up for our free Analytics in Action webinar series, run monthly.

  • Storing State in your Script Controls

    Using Script Controls can really increase the analytic power of your Spotfire files and make it easier for people to search for insight.  Since an entire script is wrapped in a single transaction, tasks like looping through filters will only update the document once at the end.  This means, to perform tasks where you want to update the document multiple times, the users must execute the script multiple times.  One problem with this is that scripts do not maintain state between uses.  To solve this , we will use a property to store our state.

    Consider the following example.  Assume we are analyzing Unemployment rates by County in the United States from 1999 – 2009. We can display this on a Map Chart as shown below.

     

    This is nice and very useful to visualize, but a consumer may not want to see the unemployment rates summed up for all 11 years, they may want to see how the rates change year from year instead.  Sure, they can use the filter panel to move the year filter one year at a time, but it would be nice to wrap this in a Script so the consumer just has to click a button. At the same time, we can also perform some helpful updates while we are in there.

     

    To start, create a Script Control in a Text Area.   The Script is going to pass in a visualization parameter that refers to the Map Chart.

    The script will retrieve the ‘Year’ Column Filter as an Item Filter and will move the Item Filter by one step. We need to use a property to store the current step so we can just increment it by one next time the Script is executed.

     

    Below is the full script:

     

    import Spotfire.Dxp.Application.Filters as filters

    from Spotfire.Dxp.Application.Filters import ItemFilter, FilterTypeIdentifiers

    from Spotfire.Dxp.Data import DataProperty, DataType, DataPropertyAttributes, DataPropertyClass

     

    myPanel = Document.ActivePageReference.FilterPanel

    myFilter= myPanel.TableGroups[0].GetFilter("Year")

     

    myFilter.FilterReference.TypeId = FilterTypeIdentifiers.ItemFilter

    itemFilter = myFilter.FilterReference.As[filters.ItemFilter]()

     

    whichCol = itemFilter.DataColumnReference

    if (whichCol.Properties.PropertyExists("CurrentStep") == False):

        myProp = DataProperty.CreateCustomPrototype("CurrentStep",0,DataType.Integer,DataPropertyAttributes.IsVisible|DataPropertyAttributes.IsEditable)

        Document.Data.Properties.AddProperty(DataPropertyClass.Column, myProp)

        whichCol.Properties.SetProperty("CurrentStep",0)

    else:

        whichVal = whichCol.Properties.GetProperty("CurrentStep")

        print whichVal

        print itemFilter.Values.Count

        if (whichVal == itemFilter.Values.Count):

                whichCol.Properties.SetProperty("CurrentStep",0)

        else:

            itemFilter.Value = itemFilter.Values.Item[whichVal]

            if (itemFilter.Value):

                            vis.Title = "Overall Unemployment by Country in " + itemFilter.Value

            else:

                            vis.Title = "Overall Unemployment by Country from 1999 to 2009"      

            whichCol.Properties.SetProperty("CurrentStep",whichVal+1)


     

     

    The end result? Consumers can click on the button and it will step through the Year filter so that they can see the unemployment rates for the given year one year at a time. In addition the title of the Map Chart is updated to include the year for the current step.

     

    Below is the result of the visualization and Filter Panel when the Script is executed to the point where the year column is 2007.

     

     

    For more information on Script Controls, consider taking our  blended training course dedicated to them.

  • Using Lists to Organize your Analytics Knowledge

    One of the new features of TIBCO Spotfire version 3.2 is called Lists.  Many of you who have been around since the DecisionSite days will find the functionality very similar to the Portfolio tool, with a few key additions. In an earlier post,  we discussed various methods for adding categories into our analysis.   With Lists, you have an additional method, which is very similar with tags, but also different in the following ways:

    •    You can add annotations, or knowledge,   on the items in your List to save and share the insights
    •    Your List exists in a separate file outside of your document and can be applied across many analysis sessions
    •    You can use some logical operations to easily search for and compare items in a List

    The best way to explain the capabilities above is with an example. Let’s assume we are looking at sales from a chain of stores.  We mayhave  identified during our analysis a couple of customers who we want to ‘watch’, either because they are big spenders and we want to make sure they continue to keep purchasing items, or maybe they return a lot of items, and  we want to monitor them moving forward.  Or maybe they are regular purchasers of a given brand.


    Just like with Tags, we can create a new list, called ‘Customers to Watch’, and can include the customers that fit into our criteria mentioned above.  The easiest way to accomplish this is by marking the customers and then selecting the ‘New List from Marked…’ command.



    When you have done this, you will see the Lists panel is updated with your new List.


     

     
    This List can then be exported into a TIBCO Spotfire Lists file (.lists).  The benefit of this is it can be applied to other documents you have which also contain information about customers.  


     
    Adding Knowledge into your Analysis
    In addition to the ability to use the Lists to classify your data, you can also add additional knowledge about your analysis. This concept is called Annotations. Let’s say we are interested in watching one of our customers more closely as a potential person to be our new spokesperson.  We can find the customer in the List and choose to add an annotation from the ‘List Item Properties’ dialog.


     


    When the analysis is opened later or when the List is used with another analysis file, we can search for the annotations and find the necessary customer id.  


     
    List Logic Operations
    In a future post, we will discuss the list logic capabilities for Lists, and walk through an example of how you can classify customers into different purchasing categories and then use the list logic capabilities to compare customers who fall into a specific purchasing habit (for example, those who purchase Brand A but never purchase Brand B or C).


Syndication

Other Spotfire Blogs

©Copyright 2000-2011 TIBCO Software Inc | Privacy Policy | Terms of Use I Blog I Contact Us I Content Center