Last updated

API / geotoolkit / data / CalculatedDataSeries / CalculatedDataSeries

Class: CalculatedDataSeries<T>

data.CalculatedDataSeries.CalculatedDataSeries

Read-only data series view which calculates values, depending on other series

Example

// using callback
const ds1 = new NumericalDataSeries({'data': [1, 4, 6, 7]}).setName('alfa');
const ds2 = new NumericalDataSeries({'data': [1, 4, 6, 7]}).setName('beta');

const calcds = new CalculatedDataSeries({
'name': 'calculated',
'sources': [ds1, ds2],
'formula': (val) => val('alfa') + val('beta')
});

Example

// using string
const ds1 = new NumericalDataSeries({'data': [1, 4, 6, 7]}).setName('alfa');
const ds2 = new NumericalDataSeries({'data': [1, 4, 6, 7]}).setName('beta');

const calcds = new CalculatedDataSeries({
'name': 'calculated',
'sources': [ds1, ds2],
'formula': '2 * alfa + beta'
});

Type parameters

NameType
Tany

Hierarchy

Table of contents

Constructors
Methods
Css Properties
Name Type Description
idnumber | stringUnique id of the data series
namestringName
typestringType
unitstringUnit of the data series
uristringUnique resource identifier

Contents

Constructors

new CalculatedDataSeries&lt;T&amp;gt;(options)

new CalculatedDataSeries<T>(options?)

Type parameters

NameType
Tany

Parameters

Name Type
Optional optionsOptions<T>

Overrides

DataSeries&lt;T&amp;gt;.constructor

Methods

addChild

addChild(data): CalculatedDataSeries<T>

Add a child object

Parameters

Name Type Description
dataDataObject | DataObject[]the child data to be added

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.addChild


addProperties

addProperties(properties): CalculatedDataSeries<T>

Add additional properties

Parameters

Name Type Description
propertiesRecord<string, any>additional properties of the dataobject

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.addProperties


addValue

addValue(value): CalculatedDataSeries<T>

Does nothing

Parameters

Name Type Description
valueTa new value

Returns

CalculatedDataSeries<T>

this

Overrides

DataSeries.addValue


addValues

addValues(array): CalculatedDataSeries<T>

Does nothing

Parameters

Name Type Description
arrayT[]an array of values

Returns

CalculatedDataSeries<T>

this

Overrides

DataSeries.addValues


calculate

calculate(name): any

Run function. See available formulas list by DataSeries.getFormulas

Parameters

Name Type Description
namestringname

Returns

any

Inherited from

DataSeries.calculate


clearChildren

clearChildren(): CalculatedDataSeries<T>

Remove all child data

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.clearChildren


clearValues

clearValues(): CalculatedDataSeries<T>

Does nothing

Returns

CalculatedDataSeries<T>

this

Overrides

DataSeries.clearValues


clone

clone(copyData?): DataObject

All subclasses should override copyConstructor or provide custom implementation for this method

Parameters

Name Type Description
Optional copyDatabooleanflag to copy data

Returns

DataObject

clone

Inherited from

DataSeries.clone


convertValues

Protected convertValues<U>(values, fromUnit?, toUnit?): U

Converts values from one unit to another specified unit.

Type parameters

Name
U

Parameters

Name Type Description
valuesUarray of values or a single value
Optional fromUnitstring | AbstractUnitthe original unit of the value(s)
Optional toUnitstring | AbstractUnitthe unit to convert the value(s) to

Returns

U

Inherited from

DataSeries.convertValues


copyConstructor

Protected copyConstructor(src, copyData?): CalculatedDataSeries<T>

Copy constructor function.
Function used as part of the cloning mechanism.
Implementations should copy the given instance state to this instance.

Parameters

Name Type Description
srcCalculatedDataSeries<T>Source to copy from
Optional copyDatabooleancopy data

Returns

CalculatedDataSeries<T>

Overrides

DataSeries.copyConstructor


dispose

dispose(): void

Dispose data object and all children. Clear all listeners

Returns

void

Inherited from

DataSeries.dispose


getChild

getChild(i): DataObject

Return data by index

Parameters

Name Type Description
inumberindex of the data

Returns

DataObject

child

Inherited from

DataSeries.getChild


getChildren

getChildren(filter?): Iterator<DataObject>

Return iterator by child data objects

Parameters

Name Type Description
Optional filter(data: DataObject) => booleana filter function. Returns all child data objects if the value is null.

Returns

Iterator<DataObject>

Inherited from

DataSeries.getChildren


getChildrenCount

getChildrenCount(): number

Return number of child data

Returns

number

Inherited from

DataSeries.getChildrenCount


getClassName

getClassName(): string

Returns

string

Inherited from

DataSeries.getClassName


getDataOrder

getDataOrder(): Order

Returns data ordering of the data series.

Returns

Order

Inherited from

DataSeries.getDataOrder


getId

getId(): string | number

Returns the identifier of the data series.

Returns

string | number

Inherited from

DataSeries.getId


getLength

getLength(): number

Returns the number of values in the data series.

Returns

number

Inherited from

DataSeries.getLength


getName

getName(): string

Returns data object name

Returns

string

Inherited from

DataSeries.getName


getParent

getParent(): DataObject

Gets parent data item

Returns

DataObject

Inherited from

DataSeries.getParent


getProperties

getProperties(): OptionsOut

Gets all the properties pertaining to this object

Returns

OptionsOut

JSON options object

Inherited from

DataSeries.getProperties


getProperty

getProperty(name): any

Gets property by name

Parameters

Name Type Description
namestringproperty name

Returns

any

Inherited from

DataSeries.getProperty


getTimeStamp

Protected getTimeStamp(): number

Returns the timestamp of the data series.

Returns

number

Inherited from

DataSeries.getTimeStamp


getType

getType(): string

Returns data type

Returns

string

Inherited from

DataSeries.getType


getUnit

getUnit(): AbstractUnit

Returns unit of the data series.

Returns

AbstractUnit

unit

Inherited from

DataSeries.getUnit


getUri

getUri(): string

Returns unique resource identifier

Returns

string

Inherited from

DataSeries.getUri


getValue

getValue(index): T

Returns the value at given index.

Parameters

Name Type Description
indexnumberthe index should be a number greater than or equal to zero, and less than the number of values as returned by getLength() method.

Returns

T

Inherited from

DataSeries.getValue


hasEventListener

hasEventListener(type, callback?): boolean

Check if a list of event listeners for this type contains this listener

Parameters

Name Type Description
typestringtype of event or property
Optional callbackFunctionto be called, if null, check if any callback is registered

Returns

boolean

Inherited from

DataSeries.hasEventListener


hasProperty

hasProperty(name): boolean

Returns whether data object contains specific property

Parameters

Name Type Description
namestringproperty name

Returns

boolean

Inherited from

DataSeries.hasProperty


indexOfChild

indexOfChild(data): number

Return index of child data ( index of the specified child or -1 if data is not found)

Parameters

Name Type Description
dataDataObjectdata object to check index

Returns

number

Inherited from

DataSeries.indexOfChild


insertChild

insertChild(index, item, silent?): CalculatedDataSeries<T>

Insert item by index

Parameters

Name Type Description
indexnumberspecified index
itemDataObjectnode
Optional silentbooleanwill not fire any events if true

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.insertChild


insertValue

insertValue(index, value): CalculatedDataSeries<T>

Does nothing

Parameters

Name Type Description
indexnumberthe index number where to insert the value.
valueTthe value to insert

Returns

CalculatedDataSeries<T>

this

Overrides

DataSeries.insertValue


insertValues

insertValues(index, array): CalculatedDataSeries<T>

Does nothing

Parameters

Name Type Description
indexnumberthe index number where to insert the values. Values will be added starting at the index number.
arrayT[]the array of values to insert

Returns

CalculatedDataSeries<T>

this

Overrides

DataSeries.insertValues


isDisposed

isDisposed(): boolean

Returns whether this object has been disposed

Returns

boolean

Inherited from

DataSeries.isDisposed


isReadOnly

isReadOnly(): boolean

Returns true

Returns

boolean

true

Overrides

DataSeries.isReadOnly


isSilent

isSilent(): boolean

Return true if the event dispatcher doesn't notify any events

Returns

boolean

Inherited from

DataSeries.isSilent


notify

notify<E>(type, source, args?): CalculatedDataSeries<T>

Notify listeners

Type parameters

NameType
Eextends string

Parameters

Name Type Description
typeEevent types
sourceAbstractDataSeries<any>of the event
Optional argsEventMap[E]arguments of the event

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.notify


off

off<E>(type?, callback?): CalculatedDataSeries<T>

Detach listener on event. Calling .off() with no arguments removes all attached listeners. Calling .off(type) with no callback removes all attached listeners for specific type.

Type parameters

NameType
Eextends string

Parameters

Name Type Description
Optional typeEtype of the event
Optional callback(eventType: E, sender: CalculatedDataSeries<T>, args: EventMap[E]) => voidfunction to be called

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.off


on

on<E>(type, callback): CalculatedDataSeries<T>

Attach listener on event that will be called whenever the specified event is delivered to the target

If the callback function is already in the list of event listeners for this target, the function is not added a second time.

If a particular anonymous function is in the list of event listeners registered for a certain target, and then later in the code, an identical anonymous function is given in an "on" call, the second function will also be added to the list of event listeners for that target.

Type parameters

NameType
Eextends string

Parameters

Name Type Description
typeEtype of event or property
callback(eventType: E, sender: CalculatedDataSeries<T>, args: EventMap[E]) => voidto be called

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.on


onPropertyChanged

onPropertyChanged(prop): CalculatedDataSeries<T>

This method is called if property bag is changed using setProperty method

Parameters

Name Type Description
propObjectproperty
prop.namestring
prop.valueany

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.onPropertyChanged


query

query(): QueryBuilder<any>

Query data item and child items by different conditions

Example

// Select by function
import {DataObject} from '@int/geotoolkit/data/DataObject';

const dataobject = new DataObject({'name': 'test', 'uri': 'testuri', 'type': 'testtype'});
const item1 = new DataObject({'name': 'item1', 'uri': 'item1', 'type': 'test'});
const item2 = new DataObject({'name': 'item2', 'uri': 'item2', 'type': 'test'});
dataobject.addChild([item1, item2]);
const item5 = new DataObject({'name': 'item5', 'uri': 'item5', 'type': 'test'});
item2.addChild(item5);
let founditem = null;
dataobject.query()
.where( (item: DataObject) => item.getParent() === dataobject)
.where( (item: DataObject) => item.getUri() === 'item2')
.select((item: DataObject) => {
founditem = item;
});

Example

// Select by expression
dataobject.query()
.where( 'item => uri(item) == "item5"')
.select((item: DataObject) => {
founditem = item;
});

Returns

QueryBuilder<any>

query object which has methods 'where' tp specify conditions, 'select' to run query, 'selectToArray' select results to array Expressions syntax: "item => expression", where expression:

  • logical and arithmetic operators
  • embedded functions: name(item) - gets name of the data object url(item) - gets url of the data object type(item) - gets type of the data object

Inherited from

DataSeries.query


removeChild

removeChild(data, silent?): CalculatedDataSeries<T>

Remove child data object

Parameters

Name Type Description
dataDataObjectdata object to be removed
Optional silentbooleanwill not fire any events if true

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.removeChild


removeValues

removeValues(index, count?): CalculatedDataSeries<T>

Does nothing

Parameters

Name Type Description
indexnumberthe index number where to start removing the values
Optional countnumberthe amount of values to remove

Returns

CalculatedDataSeries<T>

this

Overrides

DataSeries.removeValues


reverseValues

reverseValues(): CalculatedDataSeries<T>

Reverse values

Returns

CalculatedDataSeries<T>

Inherited from

DataSeries.reverseValues


set

set(index, item): DataObject

Sets item by index

Parameters

Name Type Description
indexnumberindex of the item
itemDataObjectnode

Returns

DataObject

Inherited from

DataSeries.set


setFormula

setFormula(formula?): CalculatedDataSeries<T>

Set formula. String version supports Math functions such as cos, sin, sqrt etc.

Example

const ds1 = new NumericalDataSeries({'data': [1.1, 1.4, 1.6, 1.7]}).setName('alfa');

const calcds = new CalculatedDataSeries({
'name': 'calculated',
'sources': [ds1]
});
calcds.setFormula('round(alfa)');

Parameters

Name Type Description
Optional formulastring | FormulaCallback<T>callback or string to calculate values of the series

Returns

CalculatedDataSeries<T>


setId

setId(id): CalculatedDataSeries<T>

Sets the identifier of the data series.

Parameters

Name Type Description
idstring | numbera new identifier

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.setId


setName

setName(name): CalculatedDataSeries<T>

Sets data object name

Parameters

Name Type Description
namestringdata object name

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.setName


setParent

setParent(parent): CalculatedDataSeries<T>

Sets parent data item

Parameters

Name Type Description
parentDataObjectparent data item

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.setParent


setProperties

setProperties(properties?): CalculatedDataSeries<T>

Sets all the properties pertaining to this object

Parameters

Name Type Description
Optional propertiesOptions<any>JSON options object

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.setProperties


setProperty

setProperty(name, value): CalculatedDataSeries<T>

Sets property by name

Parameters

Name Type Description
namestringproperty name
valueanyproperty value

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.setProperty


setSilent

setSilent(bool): CalculatedDataSeries<T>

Set silent mode

Parameters

Name Type Description
boolbooleanflag to enable silent mode

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.setSilent


setSources

setSources(sources?): CalculatedDataSeries<T>

Set sources

Parameters

Name Type Description
Optional sourcesAbstractDataSeries<T>[]set of sources to be used by function

Returns

CalculatedDataSeries<T>

this


setType

setType(type): CalculatedDataSeries<T>

Sets data object type

Parameters

Name Type Description
typestringdata type

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.setType


setUnit

setUnit(unit?): CalculatedDataSeries<T>

Sets unit of the data series.

Parameters

Name Type Description
Optional unitstring | AbstractUnitunit to be set

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.setUnit


setUri

setUri(uri): CalculatedDataSeries<T>

Sets unique resource identifier

Parameters

Name Type Description
uristringunique identifier

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.setUri


setValue

setValue(index, value): CalculatedDataSeries<T>

Does nothing

Parameters

Name Type Description
indexnumberthe index should be a number greater than or equal to zero, and less than the number of values as returned by getLength() method.
valueTvalue to set

Returns

CalculatedDataSeries<T>

this

Overrides

DataSeries.setValue


setValues

setValues(array, copy?): CalculatedDataSeries<T>

Does nothing

Parameters

Name Type Description
arrayT[]an array of values to set
Optional copybooleanmake a deep copy of the values

Returns

CalculatedDataSeries<T>

this

Overrides

DataSeries.setValues


toArray

toArray(copy?, unit?): T[]

Returns an array of objects in the data series.

Parameters

Name Type Description
Optional copybooleanwhether creating a copy of data
Optional unitstring | AbstractUnitunit optional output unit to convert the data to. if not specified, data will not be converted

Returns

T[]

Overrides

DataSeries.toArray


update

update(args?): CalculatedDataSeries<T>

Notifies the data series has been updated. The timestamp will be updated and Events.Updated event will be fired.

Fires

Events.Updated

Parameters

Name Type Description
Optional argsObjectevent args
args.countnumber
args.indexnumber
args.typeStateChanges

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.update


updateTimeStamp

Protected updateTimeStamp(): CalculatedDataSeries<T>

Updates timestamp of the data series.

Returns

CalculatedDataSeries<T>

Inherited from

DataSeries.updateTimeStamp


updating

updating(args?): CalculatedDataSeries<T>

Notifies the data series has been started updating. The Events.Updating event will be fired.

Fires

Events.Updating

Parameters

Name Type Description
Optional argsObjectevent args
args.countnumber
args.indexnumber
args.typeStateChanges

Returns

CalculatedDataSeries<T>

this

Inherited from

DataSeries.updating


getClassName

Static getClassName(): string

Returns

string

Inherited from

DataSeries.getClassName


getFormulaDescription

Static getFormulaDescription(name?): string

Get formula's description

Parameters

Name Type Description
Optional namestringname of function

Returns

string

Inherited from

DataSeries.getFormulaDescription


getFormulas

Static getFormulas(): string[]

List formulas

Returns

string[]

Inherited from

DataSeries.getFormulas


setFormula

Static setFormula(name, func?, desc?): void

Set function which can be used to calculate some value (e.g. sum, avg etc.)

Example

DataSeries.setFormula('concat', (series) => {
return series.toArray().join(' ');
});
const series = new DataSeries({
'type': 'string',
'data': ['just', 'some', 'text']
});
console.log(series.calculate('concat')); // 'just some text'

Parameters

Name Type Description
namestring | FormulaDescriptionname of function or parameters object
Optional funcFormulahandler, use null to unset
Optional descstringdescription

Returns

void

Inherited from

DataSeries.setFormula