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.
September 2011 - Posts - Tip of the Week

Tip of the Week

September 2011 - Posts

  • Dynamically Updating Fixed Values in a Drop-down list Property Control

    There are some situations where you will want to have a Drop-down list Property Control display fixed values. This is easily accomplished by using the ‘Fixed values’ option for setting the property value, and then entering your fixed values and their display names.

     

    In other situations, you may want those fixed values to update depending on certain conditions.  It could be that you only want to show some of them at any given point in time, or it could be that you want the values to completely change based off some other logic in your analysis file.  This can also be accomplished. It does require more work, but does not necessarily require a Script Control. We will learn how to do this in this tip.  NOTE: If you want the Property Control values to update dynamically but show values in a column (as opposed to fixed values), this can be accomplished another way. Please see this tip for how to do that. 


    Let’s assume for this example you will want to update fixed values displayed in one Property Control based off a selection in another Property Control. The first Property Control will display the following fixed values:


          “All time”, “Year”, “Quarter” and “Month”

    We then want to create a second Property Control. In that Property Control, the values should also be fixed values, but if the first Property Control has “All time” selected, the second Property Control should show all possible values. If the first Property Control  has “Year” selected, the second Property Control should show “Year”,”Quarter”, and “Month”. If the first Property Control has “Quarter” selected, the second Property Control should show “Quarter” and “Month”. Finally, if the first Property Control has “Month” selected, the second Property Control should only show “Month”. This type of scenario is good when you are trying to do complex calculations, like Year over Year or Year over Month, when only certain combinations are valid.

    To setup this second Property Control, we need to first create a calculated column. Ideally we would do this in a new data table, but it can be in the existing data table. Call the column PropertyControlValues, and use the following calculation, assuming ${dd1} is the name of the Property attached to your first Property Control you just created.

    Case when "${dd1}" = "All time" and RowId() = 1 then "All Time"
    when "${dd1}" = "All time" and RowId() = 2 then "Year"
    when "${dd1}" = "All time" and RowId() = 3 then "Quarter"
    when "${dd1}" = "All time" and RowId() = 4 then "Month"
    when "${dd1}" = "Year" and RowId() = 1 then "Year"
    when "${dd1}" = "Year" and RowId() = 2 then "Quarter"
    when "${dd1}" = "Year" and RowId() = 3 then "Month"
    when "${dd1}" = "Quarter" and RowId() = 2 then "Quarter"
    when "${dd1}" = "Quarter" and RowId() = 3 then "Month"
    when "${dd1}" = "Month" and RowId() = 3 then "Month"
    else
    null
    end

    When this is created, the calculated column will update when the Property Control is updated.
     

    Then you can create another Drop-down list Property Control. This one should display values using the ‘Unique values in column’ option and point to the calculated column that we just created.
    The end result is that the second Property Control will only display values that are valid based off the first Property Control.
     

    As another example suppose as part of our Guided Analysis, we want to update some attributes like what unit of measurement to use.  By changing the unit of measurement, we will have to apply a calculation to all our relevant data.  Suppose you have many different attributes you need to measure, like Temperature, Weight, Time, Distance, etc…  Rather than creating a unique drop down combination for each, you can use the approach in this tip to create one group of drop downs and then update the values accordingly.

    In the image below, the user has selected to update the temperature, so the second property control shows both ‘Fahrenheit’ and ‘Celsius’. 


     
    If the user has selected to update the weight, the second Property Control will show ‘Kilograms’ and ‘Pounds’.


    The expression used for this calculated column, assuming the first Property Control is called “whichMeasurement” is:

    Case when "${whichMeasurement}" = "temperature" and RowId() = 1 then "Celsius"
    when "${whichMeasurement}" = "temperature" and RowId() = 2 then "Fahrenheit"
    when "${whichMeasurement}" = "weight" and RowId() = 1 then "Pounds"
    when "${whichMeasurement}" = "weight" and RowId() = 2 then "Kilograms"
    else
    null
    end

    For more information on using Property Controls and other advanced techniques such as these, please consider registering for our Author Bootcamp

  • Displaying Images in a Label Property Control

    In last week’s post, we learned how to create custom Property Controls in the form of Radio Buttons and Checkboxes.  As it turns out, this solution works well using the Web Player from Internet Explorer, but the wingdings fonts do not display as they should in Firefox or Chrome.  To correct this, and to learn another nice feature, we will replace the wingding fonts with a graphic in the Label Property Control.  

    This can be accomplished out of the box using a Data Function, but that requires S+ or R and the TIBCO Spotfire Statistics Server. If you do not have those, or you just want to use something more lightweight, a script can be used. The code below can be used in a script control. It will take an image, specified via a  URL, and will place it in a Binary Document Property.  
     

    from System.Drawing import Image
    from System import Uri
    from System.Net import HttpWebRequest
    from Spotfire.Dxp.Data  import BinaryLargeObject

    uri = Uri("http://spotfire.tibco.com/community/Downloads/radioOn.png")
    request = HttpWebRequest.Create(uri)
    response = request.GetResponse()
    stream = response.GetResponseStream()
    blob = BinaryLargeObject.Create(stream)
    Document.Properties["testImage"] = blob

    If you then attach this Binary Property to a Label Property Control, the image will appear, and will work in the Web Player as well in all supported browsers. To see the same example as last week updated to work using this new approach, take a look at: http://spottrain.tibco.com/SpotfireWeb/ViewAnalysis.aspx?file=/kevin/TNA

    This opens the door for a new set of features, where you can rotate through images based off some logic. This can lead to a custom-traffic light visualization, Radio Button and Checkbox Property Controls, and other solutions where you need to rotate or display different images based off of data.

  • Creating Radio Button and Checkbox Property Controls

    This is the first post after the Tip of the Week blog’s summer hiatus.  We are back now and will start out with a series of tips related to using Text Areas to create Guided Analysis files. In this first tip back we will discuss how to create new Property Control types (radio buttons and check boxes) using a combination of Document Properties, Labels, and Scripts. While these are not truly built-in Property Controls, they do work and function properly.


    In this first example we will look at building a radio button. The first thing we need to do is create two new Document Properties. One will store the value of a radio button checked and one will store the value of a radio button unchecked.  The easiest way to accomplish this is to use the Wingdings 2 font and the following symbols as the values for the property: and .

     

    NOTE: you will not see the symbol right away when you enter it in the value section, this is OK.


    After you add the property for the radio button checked, add a similar one called radioUnchecked which shows the symbol of an unchecked radio button.


    The next step occurs in the Text Area where you want to use the radio buttons. In the location where you want each radio button displayed, you should add a Label Property Control.  In our example we will display two radio buttons in the group. One with the value yes, and one with the value no.  Each one will be on its own line, one after the other.  The screen shot below shows the Label Property Control we will add for the 'Yes' part of the radio group. The Label Property Control is attached to a new Document Property, called radioYes, which is of type string. We can leave the default value empty or we can use the unchecked radio symbol from before, :


    We then add another Label on the following line in the Text Area which will show the 'No' part of the radio button group.


     
    Finally we will add a script next to each label. For the first script, it will go next to the label for the 'Yes' part, and will display as a link with the display name ‘Yes’. The code is shown below:

    Document.Properties["radioYes"] = Document.Properties["radioChecked"]
    Document.Properties["radioNo"] = Document.Properties["radioUnchecked"]

    What this is doing is setting the  radioYes property (which is attached to the 'Yes' button’s Label) to be equal to the radioChecked property (which is where the radio checked symbol is stored). Then the code sets the radioNo property (which is attached to the 'No' button’s Label) to be equal to the radioUnchecked document property (which is where the radio unchecked symbol is stored).


     
    We can then add a second script with the display name No next to the No label.
     


    When this is all done, you have a working radio button group in your Text Area.


      
    Want to see it in action? Try it in our Training Needs Assessment Application at http://spottrain.tibco.com/SpotfireWeb/ViewAnalysis.aspx?file=kevin/TNA


    Using a similar approach, you can also create a checkbox group:


     

     

Syndication

Other Spotfire Blogs

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