The Controller is the main class of the charting package. It is built upon the features offered by BG.charts.ChartSet and BG.charts.Data. It provides an abstraction layer that simplifies many of the common tasks encountered when displaying a chart and offers prebuilt implementations for various additional features such as:
Static
convertersadds a new BG.charts.ToolGenerator to the chartset generators always appear in the same chart as the timeseries they target
the specified type string is resolved via the internal generator registry
custom generators can be registered via BG.charts.utils.setGenerator
NOTE: generators can not be added to chartsets that do not currently contain a timeseries
Optional
input: null | stringoptional identifier of a timeseries
add an indicator
the provided type is resolved via the internal indicator registry
custom indicators can be registered via BG.charts.utils.setIndicator
adds a new BG.charts.TimeSeries
if no target parameter is specified, timeseries will be automatically added to the main chart
alternatively, you can specify true
to add it as a new chart, or pass a specific chart instance or id
if no targetScale parameter is specified, timeseries will automatically be added to the right scale
alternatively, you can specify true
to add it to a new scale, or pass a specific scale id
if scale id is invalid, right scale will be used
if no targetOrder parameter is specified, the timeseries will automatically be appended after the last object.
the provided identifier is resolved to a data loader class via the internal loader registry
custom loaders can be registered via BG.charts.utils.setLoader
identifiers are formatted like this: "Instrument(133962,4)", "CFD(CFD_GDAXI,mid)", "Portfolio(1234)"
if a timeseries matching the specified identifier already exists in the chart, it is added again with an automatically appended unique id; e.g. "Instrument(133962,4)#42"
add a new tool to the chart
this method has three modes; depending on the supplied parameters it will
a) initiate interactive placement of the specified tool (default behaviour, only first parameter required) b) initiate placement at a predefined point in a specific chart. If tool has more than one handle, additional handles will be placed interactively; if it has just one, placement is non-interactive. (first three parameters required, second parameter must be an instance of BG.charts.Point) c) place a tool directly without any interaction required; coordinates all handles must be specified (first three parameters required, last two parameters optional, second parameter must be an array of handles)
Handles are specified as an array of numbers, either in the format [timestamp, value], or [timestamp, offset, value].
The number and layout constraints of handles depends on the type of the tool being added.
Layout can be changed at a later time using BG.charts.Tool.setHandles
See the documentation of the respective tool class for detailed information.
the tool type is resolved via the internal tool registry (full list available via BG.charts.utils.list
)
additional custom tools can be registered via BG.charts.setTool
identifier of the tool to be added
Optional
handles: Point | number[][]Optional
target: null | number | BG.charts.ChartOptional
targetScale: null | number | boolean[not currently used, tools are always placed on the primary scale]
Optional
targetOrder: null | number | boolean[not currently used, tools are always appended at top most position]
clones the specified object
Note: Only TimeSeries, Indicators and Tools (not generated ones) can be cloned
cloned objects will inherit all properties from the original they will be placed directly "after" the original (e.g. in terms of position for charts, or visual order for other objects)
returns the cloned object if successful, null otherwise
deserializes a previously serialized chart from an object different aspects of deserialization can be controlled using the optional parameters
NOTE: If data is modified (e.g. changing span, interval, or timeseries') after deserialization and before the controller has finished loading, the viewport is NOT restored.
Optional
asTemplate: booleanif true, the currently active timeseries are kept, and only applicable settings are loaded from the config
Optional
restoreView: booleanif true, the position and bounds of the X- and Y-axis are restored automatically
Optional
keepTools: booleanif true, tools are restored if the config is loaded as a template
Optional
noNewQuotes: booleanif true, quotes that did not exist when the chart was stored are not loaded
deserializes a previously serialized object
the optional second and third parameter control where the deserialized object is placed or if options are applied to an existing object
otherwise:
NOTE: interactive placement using a point is only supported for tools. When deserializing other object types, the point parameter is simply ignored
NOTE: when deserializing timeseries, the relative
option is ignored; deserialization behaves the same way
as using addTimeseries; instead, deserialization uses the benchmarkMode
setting of the Controller.
NOTE: because this method is intended for being used by a user interface, objects are always appended at the end, and visual order index can not be specified directly; if you want to modify this, use ::moveObject or even better use the individual methods intended for programmatic placement (::addIndicator, ::addTool, ..., combined with ::set, ::moveObject, etc)
Optional
target: Optional
targetScale: null | number | booleanOptional
targetOrder: null | number | booleanOptional
point: null | PointOptional
asTemplate: booleanmust be called after willUpdateOptions
once all actions that might potentially changed values of any options are done
IMPORTANT: methods must be called in balance; e.g. for each call to willUpdateOptions
, you must call didUpdateOptions
exactly once.
enumerate all objects in the controllers hierarchy
The provided callback will be called with each object, its parent, and the depth in the hierarchy. The callback can return true at any time to cancel enumeration
the optional filter parameter can be used to filter by option values (null or empty object matches all)
the optional parent parameter can be used to limit the scope to only children of the specified object(s) (null matches descendants of controller, e.g. Charts)
the optional third parameter can include various flags to modify the query behaviour
returns a flat representation of all available config options in the form of a key-value-object optionally only values that are not read-only can be returned
IMPORTANT: this method will always convert I18NStrings to strings, so for displaying strings in a UI use individual calls to BG.charts.Object:get instead
Optional
readWriteOnly: booleandefault: true
Optional
modifiedOnly: booleandefault: true
Optional
nonEphemeralOnly: booleandefault: true
returns the categorization of the objects options can be used for displaying a more structured user interface
retrieve one object matching the specified filter
the optional parent parameter can be used to limit the scope to only children of the specified object(s) (null matches descendants of controller, e.g. Charts)
the optional index parameter can be used to specify which object should be retrieved if more than one object matches the filter and scope
the optional fourth parameter can include various flags to modify the query behaviour
retrieves a list of object specific actions provided by the specified object E.g. trend lines provide an action to convert themselves to channels.
If the optional menuId parameter is not specified, the returned actions are for the default "right click" contextmenu. Different objects can support additional menus with other actions; possible values will be provided for example as a parameter in the "contextMenu" event
Note: Non-object specific generic actions such as "clone", "delete" etc are NOT included in the returned list.
retrieves objects current index in charts visual order.
As charts scales are always first in the object hierarchy even though they technically appear as the top most drawing, they have negative order indices.
Therefore, the object that is drawn first is always at index zero.
if the requested object is not in the controllers hierarchy, method returns null
retrieve objects and return them in an array
the optional filter parameter can be used to filter by option values (null or empty object matches all)
the optional parent parameter can be used to limit the scope to only children of the specified object(s) (null matches descendants of controller, e.g. Charts)
the optional third parameter can include various flags to modify the query behaviour
retrieve the scale of the specified object (identified by numeric id, layer or identifier)
NOTE: result is always non-null, except if the specified object is not part of the controllers hierarchy
return an objects parent
if the optional filter is not specified, always returns the immediate parent. if the optional filter is specified, the parent is only returend if it matches the filter
via the optional flags the matching can be extended:
Optional
id: null | number | BG.charts.ObjectOptional
filter: { [key: string]: any }an optional filter to match against parent objects' options
Optional
flags: EQueryFlagsretrieves the safe area insets
move an object to another position. Position is defined as the tuple of [chart, scale, visual order]. All of these properties can be changed invididually, or at the same time. By specifying null or false for any of them, the property is kept (e.g. just changing scale, but not chart), or determined automatically (e.g. when not specifying a scale, but moving to a new chart)
Numeric target values are interpreted as a relative offset (e.g. +1 means one chart down) by default.
Alternatively absolute values can be used if EQueryFlags.ABSOLUTE_VALUES is set in flags
.
By default, objects are "merged" into the charts at the target position.
When EQueryFlags.UNMERGE is set in flags
, objects are instead moved
to newly created charts that are inserted at the target position.
This flag only works when target chart is specified numerically.
When moving charts the target must always be numeric, and the scale and unmerge parameters are ignored
chart object, or numerical offset from current position (automatically determined if null or 0)
id of target scale (automatically determined if null/false or not specified)
Optional
targetOrder: null | number | booleanvisual order in chart (automatically determined if null/false or not specified)
Optional
flags: EQueryFlagsoptional flags for modifying behaviour
life cycle method; called when the object should stop normal operation if objects have any pending subscriptions/requests, they should all be stopped here
the object is also responsible for clearing the loading flag from it's state if it is currently active failing to do so will trigger a fatal error
object might be started again afterwards (start) or destroyed (destroy) this is not known yet at this point
called after start or restart
redraw the chart
Optional
reason: ERedrawReasonchanges the main timeseries of the controller
selects specified object and enables edit mode
Currently only tools (instances of BG.charts.Tool) can be edited. For all other objects, this will basically just emit the objectSelected event.
You can specify an optional action to directly start moving a tool or one of it's handles
Valid values for action
parameter:
** move **: Move the whole tool ** handle **: Move an individual handle (handle index can be specified via optional third parameter)
serializes the currently displayed chart along with all objects contained within to an object the resulting object can be used with the deserialize function to restore the chart
depending on the current state of the controller, serialization might not always work (e.g. it is not a good idea to serialize during loading); therefore, it is adviced to use serialize inside of a try catch block
will set validate and then set the specified option(s) to the provided value(s) after validation
NOTE: if multiple options are used, will return false if at least one value is not valid values are applied individually however, so one option might be set even if the value for another is invalid
set the ActivityIndicator class responsible for rendering the loading animation
You can pass null to disable the loading animation
e.g. you could implement a html/css based loader controlled by the
optionChanged
event for the loading
option
specify a custom layout function to use instead of the default logic the provided callback is used everytime the controller wants to generate a new initial layout
to clear/unset a previously specified layout function, simply call this method with null
NOTE: if the callback "does nothing" the chart will simply show ALL available data NOTE: a new initial layout is only generated when timeseries data is initially loaded (data updates via push are not considered)
simple layouts (e.g. if you just want to focus on a specific area of the chart and do not care about plotarea width etc) can just apply the desired ranges to the X-Axis and scales directly within the callback; the callback should not return anything.
ADVANCED MODE: for more complex layouts depending on properties such as the bounds of an axis or the final size of a charts plotarea it is also possible to use multiple passes that are applied directly from within the rendering pass to make use of this advanced mode, the layout callback should return a multi-pass-layout callback (a function returning a boolean)
for every pass, the logic is as follows:
the multi-pass-layout-callback MUST return true if it modifies the layout. The above steps are then repeated until the callback returns false.
NOTE: it is possible to create an endless loop here; make sure the callback returns false at some point.
by default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default which helps finding memory leaks. Obviously not all Emitters should be limited to 10. This function allows that limit to be increased. Set to zero for unlimited.
style overwrites can be used to specify a set of selectors that always get applied on top of the style selected by setStyle
exemplary usecase: a frontend might want to enforce a specific font to make charts fit into it's UI
overwrites should be used with care; e.g. setting a fixed white background color could result in "invisible" lines, if the stylesheet uses black backgrounds and white lines...
the new style object or a path to a stylesheet
when using custom getters/setters (via _get/_set) in options, the values of options can change
without .set being called - or there might not even be a setter for readonly options;
for example, if the getter simply returns the value of a member variable
this variable could be modified directly.
In this case, events such as optionChanged
would not be fired, and listeners would not be informed about the change.
To account for such cases, the methods willUpdateOptions
and didUpdateOptions
should be called directly BEFORE and AFTER
actions that might potentially change values of options.
the correct events will then automatically be triggered when calling didUpdateOptions
.
if the options that could change are known, they can be supplied via the optional parameter. This provides a small performance gain in most situations.
IMPORTANT: methods must be called in balance; e.g. for each call to willUpdateOptions
, you must call didUpdateOptions
exactly once.
Optional
options: string | string[]zoom visible area to the specified span zooming based on time spans is only supported when using time based mergers
Optional
a: string | numberOptional
b: string | numberOptional
noConversion: booleando not convert numbers to indices
Static
getStatic
getUtility function to find out which tools may be pruned if a config is opened after a specific date Tools will only be pruned when the data sources use shifting histories (e.g. always the last 3 months), which causes the firstTimestamp in the config to no longer be available
Static
guardStatic
listenerStatic
peek"peek" into a serialized configuration or a serialized object to retrieve information about contained objects this can for example be used to load required plugins on demand before actually deserializing a chart
the output can be configured with the optional flags parameter; see BG.charts.Controller.EPeekFlags for details
Static
set
*Example of an options definition with the most common attributes: