API Reference
Namespaces
Classes
Events
Global
Externals

Class: Context

CIQ.UI. Context


new Context(stx, topNode [, params])

UI context helper class.

Designed to be used as a helper method for the included WebComponents. A full tutorial on how to work with and customize the web components can be found here: Web Component Interface.

Parameters:
Name Type Argument Description
stx CIQ.ChartEngine

The chart object to associate with this UI context.

topNode HTMLElement

The top node of the DOM tree for this context. The top node should contain all of the UI elements associated with the chart engine.

params object <optional>

Context parameters.

Members


stx :CIQ.ChartEngine

The chart object to associate with this UI context.

Type:

topNode :HTMLElement

The top node of the DOM tree for this context.

Type:
  • HTMLElement

Methods


<abstract> changeSymbol(data [, cb])

Executes a symbol change request on the UI context.

You must create an implementation of this abstract method (see example below).

Parameters:
Name Type Argument Description
data object

A symbol data object acceptable by CIQ.ChartEngine#loadChart.

Properties
Name Type Description
symbol string

A financial instrument symbol.

cb function <optional>

A callback function to execute when the symbol change is complete.

Since:
  • 8.2.0 Added the cb parameter.

Example

Method Implementation

uiContext.changeSymbol = function (data, cb) {
    const { stx, loader } = uiContext;
    if (loader) loader.show();

    if (data.symbol == data.symbol.toLowerCase())
        data.symbol = data.symbol.toUpperCase(); // Set a pretty display version.

    // Reset comparisons -- remove this loop to transfer from symbol to symbol.
    for (let field in stx.chart.series) {
        // Keep studies.
        if (stxx.chart.series[field].parameters.bucket != "study" ) stx.removeSeries(field);
    }

    stx.loadChart(data, function(err) {
        if (err) {
            // Add 'symbol not found error' here if one needed.
            if (loader) loader.hide();
            return;
        }
        if (loader) loader.hide();
        CIQ.ChartEngine.restoreDrawings(stx, stx.chart.symbol);
    });

    if (cb) cb(stx);
};

isLegendKeyboardActive()

Checks the chart for a study legend or comparison search that is active and has keyboard navigation control.

Since:
  • 8.3.0

Returns:

true if a cq-study-legend component is both active and has keyboard navigation control; otherwise, false.

Type
boolean

setLookupDriver(driver)

Sets the lookup driver used by the cq-lookup web component.

The lookup driver searches for matching symbols as text is entered in the cq-lookup web component's input field.

Parameters:
Name Type Description
driver CIQ.ChartEngine.Driver.Lookup

Lookup driver for the cq-lookup web component.

Example
// Create a context object.
UIContext = new CIQ.UI.Context(stxx, document.querySelector("cq-context,[cq-context]"));

// Add a lookup driver to the context. The cq-lookup web component accesses the driver from the context.
UIContext.setLookupDriver(new CIQ.ChartEngine.Driver.Lookup.ChartIQ());

// Get a reference to the cq-lookup web component.
UIContext.UISymbolLookup = document.querySelector(".ciq-search cq-lookup");

// Set a callback on the cq-lookup web component.
UIContext.UISymbolLookup.setCallback(function(context, data) {
    context.changeSymbol(data);
});

advertiseAs(uiHelper, helperName)

Attaches a Helper to the context, so that it can be found later on.

Designed to be used as a helper method for the included WebComponents. A full tutorial on how to work with and customize the web components can be found here: Web Component Interface

Parameters:
Name Type Description
uiHelper CIQ.UI.Helper

A UI Helper to attach

helperName String

The helperName of the element. For instance "Loader"


isModal()

Checks if the context in modal mode.

Designed to be used as a helper method for the included WebComponents. A full tutorial on how to work with and customize the web components can be found here: Web Component Interface

Returns:

true if in modal mode

Type
Boolean

setLoader(loader)

Attaches a loader to a UI context.

Designed to be used as a helper method for the included WebComponents. A full tutorial on how to work with and customize the web components can be found here: Web Component Interface

Parameters:
Name Type Description
loader CIQ.UI.Loader

Loader instance