Interface: ISelectionApi
Charting Library.ISelectionApi
Allows you to select entities (drawings and indicators) on the chart. Consider the following example:
var chart = tvWidget.activeChart();
// Prints all selection changes to the console
chart.selection().onChanged().subscribe(null, s => console.log(chart.selection().allSources()));
// Creates an indicator and saves its ID
var studyId = chart.createStudy("Moving Average", false, false, { length: 10 });
// Adds the indicator to the selection ([<id>] is printed to the console)
chart.selection().add(studyId);
// Clears the selection ([] is printed to the console)
chart.selection().clear();
Multiple Selection
Multiple selection has the following specifics:
- Either indicators or drawings can be selected at the same time.
- If you add an indicator to the selection, other entities are removed from it.
- Adding an array of objects to the selection works the same as adding these objects one by one.
Methods
add
▸ add(entities
): void
Add entity / entities to selection
Parameters
Name | Type | Description |
---|---|---|
entities | EntityId | EntityId [] | entities to be added to selection |
Returns
void
allSources
▸ allSources(): EntityId
[]
Returns all the entities in the selection
Returns
EntityId
[]
canBeAddedToSelection
▸ canBeAddedToSelection(entity
): boolean
Whether the entity can be added to the selection
Parameters
Name | Type | Description |
---|---|---|
entity | EntityId | entity to be checked |
Returns
boolean
true
when entity can be added to the selection
clear
▸ clear(): void
Clear selection
Returns
void
contains
▸ contains(entity
): boolean
Does the selection contain the entity
Parameters
Name | Type | Description |
---|---|---|
entity | EntityId | entity to be checked |
Returns
boolean
true
when entity is in the selection
isEmpty
▸ isEmpty(): boolean
Is the selection empty
Returns
boolean
true
when empty
onChanged
▸ onChanged(): ISubscription
<() => void
>
Subscription for selection changes.
Returns
ISubscription
<() => void
>
remove
▸ remove(entities
): void
Remove entities from the selection
Parameters
Name | Type | Description |
---|---|---|
entities | EntityId [] | entities to be removed from the selection |
Returns
void
set
▸ set(entities
): void
Set entity / entities as the selection
Parameters
Name | Type | Description |
---|---|---|
entities | EntityId | EntityId [] | entities to be selected |
Returns
void