Class RenderBase

RenderBase serves as the base class for all custom visualizations. It provides a custom visualization with meta information, properties, nls support and a number of methods that can be overridden to implement rendering and hit testing. A minimal custom visualization would look like this:

import { RenderBase } from "@businessanalytics/customvis-lib"

class MyCustomVis extends RenderBase
{
    create( _node: HTMLElement ): void
    {
        _node.textContent = "Hello Custom Visualization";
    }
}

Hierarchy

  • RenderBase

Index

Properties

Protected meta

meta: MetaInfo

Object holding various meta information that controls how the visualization behaves. For instance, an attribute can be set that controls the default shape that is used for encoding categorical legend items. A good place to make changes to this meta information is in the create method of the visualization.

// Change the shape of all categorical legend items to 'rectangle'.
this.meta.legendShape = "rectangle";

// Limit the 'categories' slot to 250 tuples.
this.meta.slotLimits.set( "categories", 250 );

Protected properties

properties: Properties

The properties of the rendering service. Created at initialization time, this object will not change during the lifetime of the instance. Since VIPR handles locking of properties during rendering, we can safely pass this instance as part of UpdateInfo.

Properties are 'protected' to allow subclasses to access them in methods that don't have an UpdateInfo. An example is [[getEncodings]], where the renderer may need to return legend encodings based on certain property values. The general rule however is to access properties through UpdateInfo.props.

// Retrieve the background color of the visualization.
const bgColor = _info.props.get( "color.background" );

Methods

Protected create

  • create(_parent: HTMLElement): Element | void | Promise<Element | void>
  • Called during initialization of the visualization. This is, after the constructor, the very first method that is called on the visualization object.

    Parameters

    • _parent: HTMLElement

      HTML element used as entry point for the visualization.

    Returns Element | void | Promise<Element | void>

    An Element or a promise that resolves to an element. The element that is returned here will be passed to the update function as part of UpdateInfo. This element is considered the root element of the visualization. A void return value is also allowed (or a Promise that resolves with void). In that case, the root element of the visualization will be the _parent that was passed to create.

Protected getSlotForPalette

  • getSlotForPalette(_data: DataSet, _palette: string): string | null
  • Called for every palette that is not linked to a slot. Subclasses can override this method to dynamically link a palette to a slot.

    Parameters

    • _data: DataSet

      Actual data.

    • _palette: string

    Returns string | null

    The name of a slot that is supposed to be linked to the palette, or null if the palette remains unlinked.

Protected hitTest

  • Performs a hit test on a given position. The position is specified in both client coordinates and viewport coordinates. Client coordinates are relative to the upper left corner of the browser. Viewport coordinates are relative to the top left of the visualization. Subclasses can override this method to perform specific hit testing.

    Note: the default implementation checks if _elem.__data__ represents a DataPoint, Tuple or Segment. If this is the case, then _elem.__data__ is returned. This provides automatic hit testing for d3 visualizations when the node is bound to a DataPoint, Tuple or Segment.

    Parameters

    • _elem: Element | null

      Element that was found on on the hit test position. Can be null in case no element was found on the specified hit test position.

    • _client: Point

      Client coordinate of the hit test position.

    • _viewport: Point

      Viewport coordinate of the hit test position.

    Returns DataPoint | Tuple | Segment | null

    An DataPoint, Tuple or Segment element from the data model, or null if nothing was hit.

loadCss

  • loadCss(_url: string): void
  • Load a stylesheet by appending a style tag to the head of the HTML document.

    Parameters

    • _url: string

      Absolute or relative url of the stylesheet. If the url is relative, then it will be made absolute by calling toUrl. Relative means relative to the root of the visualization.

    Returns void

Protected nls

  • nls(_key: string): string
  • Returns a translated string given a key.

    Parameters

    • _key: string

      The key to lookup in the translation table.

    Returns string

    The translated string, or an empty string if the key is unknown.

toUrl

  • toUrl(_url: string): string
  • Returns an absolute Url based on a Url relative to the visualization. Can be used to create absolute references to e.g. static resources.

    Parameters

    • _url: string

      Path of the content relative to the root of the visualization.

    Returns string

    An absolute url.

    const img = this.toUrl( "./static/image.png" );

Protected update

  • Parameters

    • _info: UpdateInfo

      Info which can be used to render the visualization. Contains the root element in which rendering should take place, along with properties, locale info and data. During (async) rendering this info will not change.

    Returns void | Promise<void>

    Optionally a promise that resolves when rendering is complete. If no promise is returned, rendering is considered to have completed synchronously.

Protected updateLegend

  • Called when the host application requests information to update the legend. The default implementation creates the correct encodings needed for the host. Override this method only when you need to make modifications to the automatically created legend.

    Parameters

    • _data: DataSet

      The active data set.

    Returns Encoding[]

    A list of legend encodings.

    // Reverse the items in the categorical legend.
    updateLegend( _data: DataSet ) : Encoding[]
    {
        // Call base class implementation.
        encodings = super.updateLegend( _data );
    
        // Retrieve the first, categorical, encoding.
        const encoding = encodings[ 0 ] as CatEncoding;
    
        // Reverse the entries in the encoding.
        encoding.entries.reverse();
    }

Protected updateProperty

  • updateProperty(_name: string, _value: any): void
  • Called immediately if the host assigns a new value to a property. Also called at initialization time for each property in the bundle. Subclasses of Renderbase can override this method to process property changes. For instance, they can set the active state of properties based on the value of another property.

    Parameters

    • _name: string

      Name of the property that has changed.

    • _value: any

      New value of the property.

    Returns void