Search

Time Bar

Time bar functions allow you to get and set the time bar's range, and display a histogram with it. To obtain a time bar object to call these functions on, use KeyLines.create.

Removes all data from the time bar.

Returns void

Destroys the current instance of the time bar, freeing any allocated resources.

Note: This action cannot be undone. Create a new time bar instance with KeyLines.create() to access the timebar namespace.

timebar.destroy();

Returns void

Returns an array of the ids that have datetimes in the specified range. A datetime dt is in the specified range if it satisfies dt1 <= dt < dt2.

Parameters

dt1
required
number | Date

The start of the required range of datetimes. This is inclusive of the stated value.

dt2
required
number | Date

The end of the required range of datetimes. This is exclusive of the stated value.

Returns string[]

The ids that have datetimes in the specified range.

Determines whether the item has a datetime either within the time bar's time range, or which overlaps any part of a time period in the range. Note that the item must have been loaded into the time bar.

If the item does not have a datetime, or the item does not exist or overlap a time period in the time bar's loaded data, then inRange() will return false.

Parameters

item
required
TimeBarItem | string

The item or id to range test.

Returns boolean

True if the specified item exists in the time bar and has a datetime that's either within the time range, or which overlaps any part of a time period, false otherwise.

Replaces the time bar data with the new data specified.

The data argument is a JavaScript Object, not a JSON string. It should have the properties specified by the Time Bar Item Properties.

If the loaded data changes the current time range, the timebar.change() event is not fired. If you don't want the range to change, first set the maxRange time bar option to take account of the data you're about to load.

To fit the time bar to the data once it has been loaded, use returned promise:

timebar.load(data).then(() => {
  return timebar.zoom('fit', { animate: false });
});

Parameters

data
required

The data to load into the time bar.

items

required

The KeyLines time bar data format.

Returns Promise

A Promise.

Sets or gets a list of dates or time periods (with both start time and end time specified) which should be marked in a different colour in the histogram.

This example shows how to mark one time as well as a range of times:

const marks = [
  // mark 1 - single date
  new Date('26 Jul 2010 08:00:00'),
  // mark 2 - time period - both start and end time must be set
  {
    dt1: new Date('18 Jul 2010 14:00:00'),
    dt2: new Date('21 Jul 2010 14:00:00')
  }
];
timebar.mark(marks);

To clear all the marks pass an empty array as an argument.

Parameters

number | Date | TimePeriod | (number | Date | TimePeriod)[]

The timestamps to set marks on.

Returns (number | Date | TimePeriod)[]

The current mark list.

Inserts new data into the time bar, merging it with any existing time bar data.

Incoming items that exactly match existing items in the time bar are merged with them on a one-to-one basis.

Note that the items argument is a JavaScript object or array, not a JSON string. It should have the properties specified in the Time Bar Object Properties.

Parameters

items
required
TimeBarItem[] | object

The KeyLines time bar data object or array of items to merge into the existing time bar data.

Returns Promise

A Promise.

Detaches an event handler function for one or more events attached to the time bar using the on() function.

timebar.off('change', changeEventHandler);

If no handler is supplied, all handlers for the specified event are detached. If no event name is supplied, all event handlers for all events are detached.

Parameters

Time Bar Events

The name of the event to be detached from, e.g., 'click'. Use 'all' to detach from all events.

function

The event handler that was supplied to the on() call.

Returns void

Attaches an event handler function for one or more Time Bar Events to the time bar.

function changeEventHandler() {
  // respond to change event
}
timebar.on('change', changeEventHandler);

To detach event handlers, use off().

See Events Basics for more details.

Parameters

name
required
Time Bar Events

The name of the event to be attached to, e.g., 'click'. Use 'all' to listen to all events.

handler
required
function

The event handler to call when the event occurs.

Returns void

Sets or gets options for the time bar.

Note that using this promisified function as a getter still returns an object in a synchronous way. See Special Cases: getters and setters for more detail.

Parameters

val
required

The options to set for the time bar.

Returns object | Promise


Getter: The current time bar options. See Time Bar Options.


Setter: A Promise object.

Pans the time bar in the direction specified.

Parameters

"forward" | "back"

The direction to pan. Default is 'forward'.

Options controlling the pan operation.

boolean default: true

Whether the transition should be animated.

number default: 200

The length of the animation in milliseconds.

Returns Promise

A Promise.

Stops the continuous animation of the time bar range started by play().

Returns void

Starts a continuous animation of the time bar range. The speed of the animation can be set via the options function's playSpeed property.

Parameters

Options controlling the play operation.

boolean default: false

If true, the start of the range stays fixed and the end is extended.

Returns void

Sets or gets the time range of the time bar. If called without parameters, it returns the time range of the time bar without updating it.

Setting the time range causes different visual effects according to whether the sliders are fixed, free, or not present.

  • If the sliders are fixed then setting the time range moves and zooms the scale underneath the sliders.
  • If the sliders are free then the sliders themselves move to the time range specified and scale does not change.
  • If there are no sliders (sliders:'none') then the time range is displayed in the full width of the time bar.

Things to note:

  • There are minimum and maximum limits on the time range size, and the time range must either overlap or be adjacent to the time range of loaded data. The requested range may be adjusted to meet these constraints.
  • The range function returns a JavaScript Date object. For more details see Time Zones.
  • Using this promisified function as a getter still returns an object in a synchronous way. See Special Cases: getters and setters for more detail.

Parameters

dt1
required
number | Date

The new start time for the time range of the time bar. This is inclusive of the stated value.

dt2
required
number | Date

The new end time for the time range of the time bar. This is exclusive of the stated value.

Options controlling the operation.

boolean default: true

Whether the transition should be animated.

number default: 200

The length of the animation in milliseconds.

Returns object | Promise


Getter: An object with JavaScript Date objects.


Setter: A Promise object.

Items are in the range if their time dt satisfies dt1dt < dt2.

dt1

required
Date

The start time for the time range of the time bar, as a Date object.

dt2

required
Date

The end time for the time range of the time bar, as a Date object.

Removes item or items with the id(s) specified. Pass a single id to remove a single item, or an array of id strings to remove many items at once. Note that there is no event to detect items being removed from the time bar.

Parameters

id
required
string | string[]

The id string or array of id strings of items to remove.

Returns void

Sets or gets the time bar selection lines.

This example shows how to create multiple selection lines by passing an array:

const lines = [
  // selection 1 - blue colour
  { id: ['id1', 'id2'], index: 0, c: 'blue' },
  // selection 2 - default colour
  { id: ['id3', 'id4'], index: 1 }
];
timebar.selection(lines);

To clear all the selections pass an empty array as argument. To clear a specific selection pass a selection object with an empty array as the id and its index.

Things to note:

  • The maximum number of selection lines available is 3: any selection with an index greater than 2 will be ignored. The default colours for the selection lines are: 0: green; 1: orange; 2: dark red.
  • The selection lines use a different scale to the histogram bars. Selection lines are scaled depending on the values within the selection range.
  • Passing a smaller array in subsequent selection() calls will not clear all selection lines. To clear existing selection lines, pad the array with empty objects.

Parameters

lines
required

An array of selection lines to be drawn on the time bar, or an object if just one selection line.

string(Colour)

The colour for the selection line.

string | string[]

An id string or array of id strings.

number

The index for the selection line. This field can be omitted when a single selection is passed.

Returns string[][]

Array of the current selection lines. Each line is given by an array of the id strings in the selection.

Sets the location of the time bar in the DOM. Pass null as the argument to hide it completely.

Things to note:

  • You must specify the container parameter in KeyLines.create() to use setContainer.
  • While the container is set to null all drawing and animations are paused.
timebar.setContainer('timebarContainer');

Parameters

element
required
null | string | HTMLElement

The id string or DOM element of the parent container that the time bar should be appended to.

Returns void

Zooms the time bar in the manner specified.

Parameters

"fit" | "in" | "out"

How to zoom the time bar. The default is 'in'.

Options controlling the zoom operation.

boolean default: true

Whether the transition should be animated.

string | string[]

When running zoom('fit',...), the ids of items to include in the fit range. If not specified, all items are included.

number default: 200

The length of the animation in milliseconds.

Returns Promise

A Promise.

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.