Jump to content
  • Automating Plot Setup for JSViz Using a Custom Tool in Spotfire®


    Sometimes it is beneficial to automate the creation of plots, and sometimes entire pages or sections of an analysis. As the JavaScript Visualization Framework (JSViz) does not perform any default rendering when created, it might be even more beneficial to do so with a JSViz setup.

    Table of Contents

    Prerequisites

    Custom Tool Implementation for Plot Creation

    This example uses an implementation of the CustomTool class. You can reference the JavaScript Visualization Framework Core project in the Spotfire installation's modules folder in the package builder and Visual Studio to be able to build the example tool.

    When adding HTML and JavaScript resources to the project in Visual Studio, you must set all included files to "Build Action Embedded Resource".

    The following example code does the following:

    1. Creates a plot and adds it to the Document.
    2. Creates URLReference objects with embedded content to the Document-wide JavaScript repository collection, if they are not already there.
    3. Adds the key (name)  of the JavaScript file to the plot.

    To avoid premature immediate update events firing before the plot is completely configured, the creation and configuration steps are wrapped in a transaction.

     C#  
     public class AddPlotTool : CustomTool<Document> 
     {
     	public AddPlotTool() : base("Add Plot")
        {
        }
        protected override void ExecuteCore(Document context) 	
        context.Transactions.ExecuteTransaction(delegate 
        {
        	var viz = context.ActivePageReference.Visuals.AddNew<JSVisualizationModel>();  			
            //Add the JavaScript files needed to create a doughnut chart to the plot 			
            AddJs(context, viz, "scripts.jQuery.js");
            AddJs(context, viz, "scripts.d3.v3.min.js");
            AddJs(context, viz, "scripts.JSViz.js");
            AddJs(context, viz, "scripts.DoughnutChart.js");
            viz.ApplyUserPreferences(); 			
            viz.AutoConfigure(); 		
         }
         );
      }
      private void AddJs(Document context, JSVisualizationModel viz, string name) 	
      { 		
      		// Get the common JavaScript file repository
            var repo = context.CustomNodes.AddNewIfNeeded<ContentRepository>();
            // Add  the JS File to the common repository  		
            if (!repo.ContainsKey(name)) 		
            { 			
            	// Read the content of the script folder
                var content = System.Text.Encoding.UTF8.GetString(GetEmbeddedResource("SpotfirePS.AddPlotTool_70." + name)); 			
                var urlReference = new UrlReference(name, null, content, ContentType.JS, true); 			
                repo[name] = urlReference; 		
             }
             // Add the file to be used in the plot (order sensitive) 		
             viz.UrlInclusions.Add(name);
        }  
        /// Helper methods here --- see zip file for details ///  
    } 
     

    When building this in your C# environment, you must link to the JSViz core package DLL, where the JSViz model API resides. After installing JSViz on your local Spotfire installation, the JSViz core DLL is found in the modules folder of your Spotfire installation. For example:

     C:\TIBCO Spotfire Analyst\Modules\JSViz Core Package_3.5.3.0\SpotfirePS.Framework.JSVisualization.dll 
     

    Now you can build your custom tool package .spk file using the Spotfire package builder. See "Extending Extensions" below for a more detailed description of how to set this up.

    Extending Extensions

    It is possible to extend custom extensions in Spotfire, but you must address a few quirks concerning the Spotfire build process in the package builder as well as the load order of custom functionality.

    Setting up Visual Studio

    To build the Visual Studio project, link to the appropriate DLL in Visual Studio - for the main tool project reference SpotfirePS.Framework.JSVisualization.dll.

    1. Install the JSViz .sdn in your Spotfire Analyst client by uploading it to the Spotfire Server deployment section, connecting your analyst, and downloading the update to your installed client. The new functionality is downloaded to your Spotfire installation's modules folder.
    2. Copy all of the JSViz* folders to your Visual Studio build folder
    3. Link to SpotfirePS.Framework.JSVisualization.dll from the JSViz Core* folder.

    It is possible to set up Visual Studio without copying the files, but it is recommended to do so because your installation folder can experience changes when the server administrator modifies the distribution on the server.

    Setting up the Package Builder

    For the package builder to be able to find all of the references the extension needs to find, all the JSViz* packages previously copied to the working directory (described earlier) must be added to the package builder configuration.

    1. Click Add and navigate to each JSViz* folder.
    2. Before clicking Add, clear the Source Folder check box, so the package builder can find and use the already existing modules.xml.
    3. After compiling your custom VS project, you can now add your new extension (leaving the Source Folder check box selected) to Package Builder.

    Advisable practices:

    • In the main project try to register JSViz, so that the configured visual will find the right type.
    • Name the Package Builder project extension that comes after "JSViz" alphabetically - this affects custom extension load order and the JSViz DLLs must be loaded dynamically before the configured visualization can be loaded. 

    Note: When you deploy to the server, you cannot use the Package Builder button Deploy to Server because the JSViz packages are already deployed. Use the file menu, or right-click to build only the two configured visual *.spk files.

    Attachments

    Download the Attachment from the resources.

    spotfireps.addplottool_70.zip


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...