Skip to main content
RSS feed Subscribe to feed

 

How to Create a Visualization View

A visualization view handles user input and is responsible for drawing the visualization in the user interface.

Overview

This tutorial describes how to create a Visualization View for TIBCO Spotfire Professional. In Spotfire Professional, a visualization view is a Windows Forms Control. The view is typically implemented as a new class derived from UserControl External link. The class must have a constructor that takes the model object as the only parameter.

A minimal view for the simple visualization outlined in the How to Create a Visualization Model tutorial may look like this:

public class MyVisualizationFormsView : UserControl
{
    private MyVisualization model;
    private ExternalEventManager eventManager;

    public MyVisualizationFormsView(MyVisualization model)
    {
        this.model = model;

        // Use double buffering for flicker free rendering, and make sure
        // everything is redrawn in response to size changes.
        this.DoubleBuffered = true;
        this.SetStyle(ControlStyles.ResizeRedraw, true);

        // Listen to the render trigger.
        this.eventManager = new ExternalEventManager();
        eventManager.AddEventHandler(OnRenderTriggerFired, this.model.GetRenderTrigger());
    }

    private void OnRenderTriggerFired()
    {
        // Tell windows we want to redraw ourselves.
        this.Invalidate();
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);

        // Repaint using the model.
        e.Graphics.Clear(Color.White);
        this.model.Render(e.Graphics, this.ClientRectangle);
    }

    protected override void Dispose(bool disposing)
    {
        if(disposing && this.eventManager != null)
        {
            // Always dispose the event manager in order
            // to disconnect event handlers.
            this.eventManager.Dispose();
            this.eventManager = null;
        }
        base.Dispose(disposing);
    }
}

The view must be registered with the framework to be created. This is achieved by overriding the RegisterViews in the add-in:

public sealed class CustomVisualsFormsAddIn : AddIn
{
    protected override void RegisterViews(ViewRegistrar registrar)
    {
        registrar.Register(
            typeof(Control),
            typeof(MyVisualization),
            typeof(MyVisualizationFormsView));
    }
}

Running this example will produce a page similar to the following:

The visualization view in TIBCO Spotfire Professional

This view really does nothing more than render the visualization. It basically does the same thing as the built-in default view for a visualization. To make the view react to user input, override methods to handle mouse and keyboard input, drag and drop messages and so forth.

From 3.0 a number of components facilitate the implementation of convenient visualization features, with fully functional code examples available in the CustomScatterPlot example in the SDK:

  • The TitlebarExtension component enables you to add a menu a buttons to the visualization title bar.
  • The DropTargetPopup component and the DragDropHelper class helps you implement drag and drop between your view and the application.
  • The VisualizationContextMenu enables you to display a context menu with the same commands as the built in visualizations.
  • The BusyIndicator BusyIndicator can be used to indicate that you view is busy.