Search

KeyLines

The KeyLines namespace contains functions for loading charts and time bars into your webpage.

The components object has all the current components loaded by the KeyLines wrapper. Components are accessed via their DOM id:

KeyLines.components['canvasID'].zoom('in');

Components are not created directly, but via KeyLines.create().

Returns object

An object whose properties contain the individual component elements.

Allows asynchronous functions to be used with callbacks. This function is for backwards compatibility only.

Returns KeyLines

A KeyLines object whose asynchronous functions can be handled with callbacks, or with both callbacks and promises simultaneously.

Calculates the coordinates of events relative to their target.

Parameters

evt
required
Event

A DOM or jQuery event.

Returns object

An object containing the relative position coordinates.

x

required
number

The horizontal coordinate.

y

required
number

The vertical coordinate.

Sets the value of the crossorigin HTML attribute whenever KeyLines is trying to load an image from a third-party domain.

The function takes a callback function that should return the value of the HTML attribute as a string depending on your criterion. If corsAdapter() is not set or if the callback returns undefined, the crossorigin attribute defaults to 'anonymous'.

KeyLines.corsAdapter((url) => {
  if (url.startsWith('https://keylines.io/')) {
    return 'use-credentials';
  } else {
    return 'anonymous'
  }
});

Parameters

adapter
required
(url: string) => string

A callback function which takes a URL of the CORS image as an argument and returns the value of the crossorigin HTML attribute as a string.

Returns void

Not used.

Creates KeyLines components in your web page.

The create() function is asynchronous, and so returns a promise. If an error occurs, the error catch function will be called, passing the error parameter to it. Otherwise, the success function will be called with the result object as the new component or array of components.

// Load a single chart
KeyLines.create({ container: 'div1' })
  .then((result) => {
    chart = result;
  })
  .catch((err) => {
    // handle the error here
});
// Load two KeyLines components with a specific id
KeyLines.create([
    { container: 'chartDiv', type:'chart' },
    { container: 'timebarDiv', type:'timebar' }
])
  .then((result) => {
    [chart, timebar] = result;
})
  .catch((err) => {
    // handle the error here
});

Parameters

component
required
Component Object

A definition object describing the component to create, or an array of definition objects.

null | string | HTMLElement

The DOM element or id where you want to insert the component. If set to null, the created component will be detached from any DOM element. Note that the KeyLines component will not render if the container's css style property has display: none, width = 0 or height = 0.

string

The id of the component. If not set, one will automatically be assigned.

The chart or time bar options for the new component (optional).

"chart" | "timebar" default: 'chart'

The type of component to create.

Returns Promise

A Promise that resolves to a reference for the KeyLines component.

Checks whether the current browser can show elements full screen.

To view the current state of browser support for the Fullscreen API with desktop and mobile devices, see Can I use Fullscreen API.

Use the toggleFullScreen() call to make an element full screen.

Returns boolean

If true, the current browser can show elements full screen.

A helper to find the right Unicode character to use for the icon based on the class name:

let data = { id: 'user', type: 'node', fi: { t: KeyLines.getFontIcon('fas fa-user') } };   // retrieves the Unicode position

The getfontIcon() function is deprecated as you can set font icons directly:

let data = { id: 'user', type: 'node', fi: { t: 'fas fa-user' } };

This applies to both the t option on the fi property to set an icon, and the imageAlignment option to scale and position it.

See the Font Icons documentation for details.

Parameters

classes
required
string

The class names required to get the font icon.

Returns number

The reference for the font icon.

The Graph engine can be used to perform traversals or other graph computations within a separate context from the chart. For more information see The Graph Engine.

Parameters

Options for the graph engine.

boolean default: false

If true, links from a node to itself can be loaded into the graph engine. If false, self links are not loaded into the graph engine.

Returns Graph

A new instance of the graph engine used by KeyLines.

The info function returns an object containing useful information about how KeyLines is set up in your environment, including the KeyLines version number.

Returns object

An object containing KeyLines information.

Defines which runtime KeyLines will use when calling KeyLines.create().

Parameters

value
required
"auto" | "canvas" | "webgl"

The mode to use. Can be one of the following values:

  • 'auto': (default) KeyLines determines which runtime is available. Defaults to WebGL if supported.
  • 'webgl': Use WebGL Canvas. If WebGL isn't available, use HTML5 Canvas instead.
  • 'canvas': Use HTML5 Canvas.

Returns string

The current mode.

Tells KeyLines where it can find various resources on your server. This function must be called before the KeyLines.create() function.

When many chart items use images from the same directory, the images path can be used to save repeated use of the directory path within the chart object.

By default the full path to images must be passed in the u parameter of nodes, e.g.,

const item = { t: 'label', u: '/path/to/very/deep/directory/person.png' };

Alternatively, using the images path:

// in the initialization code put this:
KeyLines.paths({ images: '/path/to/very/deep/directory/' });
// and in the item creation
const item = { t: 'label', u: 'person.png' };

The images path is also used for glyph images, the logo and the background watermark.

The images path must have a trailing slash (/) character.

Parameters

value
required

An object specifying the path to the image resources.

string

The path to use for images.

Returns object

An object containing the current path settings.

Allows any given HTMLElement to be put in Full Screen mode, using the browser's full screen API.

Usually a containing div is made full screen, rather than the KeyLines component itself. You should change the sizes of any parts of the page in the handler function – this receives a boolean parameter which is true if new status is full screen, or false if not.

Note that this function does not support Promises.

Parameters

element
required
HTMLElement

The element to be put in full screen. Cannot be null.

Function

A callback function which will be called once the operation is complete.

Returns void

Checks if the current device supports WebGL and meets the minimum requirements.

Returns boolean

True when the device supports WebGL.

Terms of use

These terms do not alter or supersede any existing agreements between you (or your employer) and us.

By accessing or using any Content you agree to be bound by these Terms of Use. Please review these terms carefully before using the website.

The contents of this website, including but not limited to any text, code samples, API references, schemas, interactive tools, and other materials (collectively, the 'Content'), are made available for informational and internal evaluation purposes only. All intellectual property rights in the Content are reserved. No licence is granted to use the Content for any commercial purpose, or to copy, distribute, modify, reverse-engineer, or incorporate any part of the Content into any product or service, without our prior written consent.

This Content is provided “as is” and “as available,” without any representations, warranties, or guarantees of any kind, whether express or implied, including but not limited to implied warranties of merchantability, fitness for a particular purpose, non-infringement, or accuracy. To the fullest extent permitted by applicable law, we expressly exclude and disclaim all implied warranties, conditions, and other terms that might otherwise be implied.

We disclaim all liability for any loss or damage, whether direct, indirect, incidental, consequential, or otherwise, arising from any reliance placed on the Content or from your use of it, to the fullest extent permitted by applicable law. By continuing to access or use the Content, you acknowledge and agree to these terms.