Historical data
Using datalinks, any widget can expose its properties to other widgets. By reimplementing the readHistData
method of BaseWgt
, a widget can also provide access to the historical data of its properties.
TagMgr
is the standard widget for attaching device data via device slots, abstracting away direct API calls.
Additionally, data source widgets can provide access to historical data through other mechanisms. For example, the platform offers DatasourceWgt
for advanced aggregation queries and DatasourceGraphQLWgt
for accessing GraphQL APIs.
Widgets that support historical data views can use the Datalink::fetchHistoricalData
method as a convenient way to retrieve historical data for their linked properties, regardless of the data source.
The SDK example demonstrates how to:
- Expose a property that can be linked to a model property using a datalink.
- Fetch historical data whenever the time interval changes.
To achieve this, it:
- Overrides
BaseGraphicWgt::addDatalink
to obtain a reference to the source widget and property. - Overrides
BaseGraphicWgt::setPropertyValue
to trigger data fetching whenever the time interval changes. - Defines a
fetch
method to retrieve historical data through the datalink usingreadHistData
.
BaseGraphic Methods
BaseGraphicWgt::addDatalink
The method addDatalink
is called every time a datalink is added to the widget.
BaseGraphicWgt::setPropertyValue
The method setPropertyValue
is called every time a widget property is changed.
Example
// Override BaseGraphicWgt::addDatalink
public addDatalink( dataLink: IDataLinkConstructorArgs )
{
const newDatalink = super.addDatalink(dataLink);
switch( dataLink.tgtProp )
{
case "tagReference":
this.sourceDatalink = newDatalink;
break;
}
return newDatalink;
}
// Override BaseGraphicWgt::setPropertyValue
public setPropertyValue( { prop, value } )
{
super.setPropertyValue( { prop, value } );
switch ( prop )
{
case "from":
case "to":
this.fetchData();
break;
}
}
// Example methods to get historical data from cloud
private async fetch( from: number, to: number ): Promise<DataValue[]>
{
if ( !this.dataSource || !this.tagName )
return [];
// Here and example to request
const data = await this.sourceDatalink.fetchHistoricalData({
from, // Start date in milliseconds
to, // End date in milliseconds
});
return data;
}