TK.Chart

new Chart(optionsopt)

TK.Chart is an SVG image containing one or more Graphs. TK.Chart extends TK.Widget and contains a TK.Grid and two TK.Ranges.

Parameters:
Name Type Attributes Default Description
options Object <optional>
{ }

An object containing initial options.

Properties:
Name Type Attributes Default Description
options.title String | Boolean <optional>
""

A title for the Chart. Set to false to remove the title from the DOM.

options.title_position String <optional>
"top-right"

Position of the title inside of the chart. Possible values are "top-left", "top", "top-right", "left", "center", "right", "bottom-left", "bottom" and "bottom-right".

options.key Boolean | String <optional>
false

If set to a string a key is rendered into the chart at the given position. The key will detail names and colors of the graphs inside of this chart. Possible values are "top-left", "top-right", "bottom-left" and "bottom-right". Set to false to remove the key from the DOM.

options.key_size Object <optional>
{x:20,y:10}

Size of the colored rectangles inside of the key describing individual graphs.

options.grid_x Array.<Object> <optional>
[]

An array containing objects with the following optional members to draw the grid:

Name Type Attributes Description
pos Number <optional>

The value where to draw grid line and corresponding label.

color String <optional>

A valid CSS color string to colorize the elements.

class String <optional>

A class name for the elements.

label String <optional>

A label string.

options.grid_y Array.<Object> <optional>
[]

An array containing objects with the following optional members to draw the grid:

Name Type Attributes Description
pos Number <optional>

The value where to draw grid line and corresponding label.

color String <optional>

A valid CSS color string to colorize the elements.

class String <optional>

A class name for the elements.

label String <optional>

A label string.

options.show_grid Boolean <optional>
true

Set to false to hide the grid.

options.range_x function | Object <optional>
{}

Either a function returning a TK.Range or an object containing options for a new TK.Range.

options.range_y function | Object <optional>
{}

Either a function returning a TK.Range or an object containing options for a new TK.Range.

options.range_z Object | function <optional>
{ scale: "linear", min: 0, max: 1 }

Either a function returning a TK.Range or an object containing options for a new TK.Range.

options.importance_label Number <optional>
4

Multiplicator of square pixels on hit testing labels to gain importance.

options.importance_handle Number <optional>
1

Multiplicator of square pixels on hit testing handles to gain importance.

options.importance_border Number <optional>
50

Multiplicator of square pixels on hit testing borders to gain importance.

options.handles Array.<Object> <optional>
[]

An array of options for creating TK.ResponseHandle on init.

options.show_handles Boolean <optional>
true

Show or hide all handles.

Source:

Extends

Members

_graphs :SVGGroup

The SVG group containing all graphs. Has class toolkit-graphs.

Source:

_handles :SVGGroup

The SVG group containing all handles. Has class toolkit-response-handles.

Source:

_handles :SVGGroup

The SVG group containing all handles. Has class toolkit-handles.

Source:

_key :SVGGroup

The SVG group containing all descriptions. Has class toolkit-key.

Source:

_key_background :SVGRect

The SVG rectangle of the key. Has class toolkit-background.

Source:

_title :SVGText

The title of the chart. Has class toolkit-title.

Source:

element :HTMLDivElement

The main DIV container. Has class toolkit-chart.

Source:

graphs :Array

An array containing all SVG paths acting as graphs.

Source:

grid :TK.Grid

The grid element of the chart. Has class toolkit-grid.

Source:

handles :Array

An array containing all TK.ResponseHandle instances.

Source:

range_x :TK.Range

The TK.Range for the x axis.

Source:

range_y :TK.Range

The TK.Range for the y axis.

Source:

Methods

add_graph(graph) → {Object}

Add a graph to the chart.

Parameters:
Name Type Description
graph Object

The graph to add. This can be either an instance of TK.Graph or an object of options to TK.Graph.

Source:
Fires:
Returns:

The instance of TK.Graph.

Type
Object

add_handle(optionsopt, typeopt)

Add a new handle to the widget. Options is an object containing options for the TK.ResponseHandle.

Parameters:
Name Type Attributes Default Description
options Object <optional>
{ }

An object containing initial options. - The options for the TK.ResponseHandle.

type Object <optional>
TK.ResponseHandle

A widget class to be used as the new handle.

Source:
Fires:

add_handles(options, typeopt)

Add multiple new TK.ResponseHandle to the widget. Options is an array of objects containing options for the new instances of TK.ResponseHandle.

Parameters:
Name Type Attributes Default Description
options Array.<Object>

An array of options objects for the TK.ResponseHandle.

type Object <optional>
TK.ResponseHandle

A widget class to be used for the new handles.

Source:

empty()

Remove all graphs from the chart.

Source:
Fires:

remove_graph(graph)

Remove a graph from the chart.

Parameters:
Name Type Description
graph TK.Graph

The TK.Graph to remove.

Source:
Fires:

remove_handle(handle)

Remove a handle from the widget.

Parameters:
Name Type Description
handle TK.ResponseHandle

The TK.ResponseHandle to remove.

Source:
Fires:

remove_handles(handles)

Remove multiple or all TK.ResponseHandle from the widget.

Parameters:
Name Type Description
handles Array.<TK.ResponseHandle>

An array of TK.ResponseHandle instances. If the argument reveals to false, all handles are removed from the widget.

Source:

Methods inherited from TK.Widget

add_child(child)

Registers a widget as a child widget. This method is used to build up the widget tree. It does not modify the DOM tree.

add_children(a)

Registers an array of widgets as children.

all_children()

Returns an array of all children.

enable_draw()

Schedules this widget for drawing.

force_hide()

This is an alias for hide, which may be overloaded. See TK.Container for an example.

force_show()

This is an alias for hide, which may be overloaded. See TK.Container for an example.

get_style()

Returns the computed style of this widgets DOM element.

hidden()

Returns the current hidden status.

hide()

Make the widget hidden. This does not modify the DOM, instead it will stop rendering this widget. Options changed after calling hide will only be rendered (i.e. applied to the DOM) when the widget is made visible again using TK.Widget#show.

remove_child(child)

Removes a child widget. Note that this method only modifies the widget tree and does not change the DOM.

remove_children(a)

Removes an array of children.

set(key, value)

Sets an option.

set_style()

Sets a CSS style property in this widgets DOM element.

show()

Make the widget visible. This does not modify the DOM, instead it will only schedule the widget for rendering.

toggle_hidden()

TK.Toggle the hidden status. This is equivalent to calling hide() or show(), depending on the current hidden status of this widget.

visible_children()

Returns an array of all visible children.

widgetize()

Set the DOM elements of this widgets. This method is usually only used internally. Basically it means to add the id from options and set a basic CSS class. If delegate is true, basic events will be delegated from the element to the widget instance if classify is true, CSS functions will be bound to the widget instance.

Methods inherited from TK.Base

add_event(event, func, prevent, stop)

Register an event handler.

add_events(events, func)

Add multiple event handlers at once, either as dedicated event handlers or a list of event descriptors with a single handler function.

delegate_events(element) → {HTMLElement}

Delegates all occuring DOM events of a specific DOM node to the widget. This way the widget fires e.g. a click event if someone clicks on the given DOM node.

destroy()

Destroys all event handlers and the options object.

fire_event(event, …args)

Fires an event.

fire_events(events)

Fires several events.

get(key)

Get the value of an option.

has_event_listeners(event) → {boolean}

Test if the event descriptor has some handler functions in the queue.

remove_event(event, fun)

Removes the given function from the event queue. If it is a native DOM event, it removes the DOM event listener as well.

remove_events(events, func)

Remove multiple event handlers at once, either as dedicated event handlers or a list of event descriptors with a single handler function.

set_options(optionsopt)

Merges a new options object into the existing one, including deep copies of objects. If an option key begins with the string "on" it is considered as event handler. In this case the value should be the handler function for the event with the corresponding name without the first "on" characters.

userset(key, value)

Sets an option by user interaction. Emits the userset event. The userset event can be cancelled (if an event handler returns false), in which case the option is not set. Returns true if the option was set, false otherwise. If the option was set, it will emit a useraction event.

Events

emptied

Is fired when all graphs are removed from the chart.

Source:

emptied

Is fired when all handles are removed.

Source:

graphadded

Is fired when a graph was added. Arguments are the graph and its position in the array.

Parameters:
Name Type Description
graph TK.Graph

The TK.Graph which was added.

id int

The ID of the added TK.Graph.

Source:

graphremoved

Is fired when a graph was removed. Arguments are the graph and its position in the array.

Parameters:
Name Type Description
graph TK.Graph

The TK.Graph which was removed.

id int

The ID of the removed TK.Graph.

Source:

handleadded

Is fired when a new handle was added.

Parameters:
Name Type Description
handle TK.ResponseHandle

The TK.ResponseHandle which was added.

Source:

handleremoved

Is fired when a handle was removed.

Source:

Events inherited from TK.Widget

GenericDOMEvents

Generic DOM events. Please refer to W3Schools for further details.

classified

Is fired when a widget is classified.

destroy

Is fired when a widget is destroyed.

doubleclick

Is fired after a double click appeared. Set dblclick to 0 to disable click event handling.

hide

The hide event is emitted when a widget is hidden and is not rendered anymore. This happens both with browser visibility changes and also internally when using layout widgets such as TK.Pager.

initialized

Is fired when a widget is initialized.

redraw

Is fired when a redraw is executed.

resize

The resize event is emitted whenever a widget is being resized. This event can be used to e.g. measure its new size. Note that some widgets do internal adjustments after the resize event. If that is relevant, the TK.Widget#resized event can be used, instead.

resized

The resized event is emitted after each rendering frame, which was triggered by a resize event.

set

The set event is emitted when an option was set using the TK.Widget#set method. The arguments are the option name and its new value.

Note that this happens both for user interaction and programmatical option changes.

show

The show event is emitted when a widget is shown and is being rendered. This is the counterpart to TK.Widget#hide.

stylized

Is fired when a widget is stylized.

visibility

Is fired when the visibility state changes. The first argument is the visibility state, which is either true or false.

widgetize

Is fired when a widget is widgetized.

Events inherited from TK.Base

delegated

Is fired when an element is delegated.

set_[option]

Is fired when an option is set.