I have a hierarchy widget that broadcasts an event with the node selected.
The hierarchy widget is something like this:
Group 1
- device 1
- device 2
- device 3
Group 2
- device 1
- device 2
- device 3
The chart will initially show timeseries data for devices in Group 1.
When Group 2 is selected, I want the chart to show timeseries for devices in Group 2.
So, my chart widget captures the event with the group id and then tries to define a new datasource and makes the subscription:
self.onInit = function() {
self.ctx.$scope.timeSeriesChartWidget.onInit();
let $scope = self.ctx.$scope;
self.ctx.broadcastService = $scope.$injector.get(self.ctx.servicesMap.get('broadcastService'));
self.ctx.broadcastService.on('change-graph', function(event, args) {
const receivedData = args[0];
const groupId = receivedData.groupId;
const groupName = receivedData.groupName;
console.log('PSI Line Chart received "change-graph" for Group:', groupName, 'ID:', groupId);
if (!groupId) {
console.warn('Received "change-graph" broadcast but groupId is undefined. Chart will not update.');
return;
}
const datasources = [
{
type: 'entity',
dataKeys: [
{
name: 'psi',
type: 'timeseries',
label: 'Pressure',
settings: {}
}
],
entityFilter: {
type: 'relationsQuery',
rootEntity: {
id: groupId,
entityType: 'ASSET'
},
direction: 'FROM',
maxLevel: 1,
fetchLastLevelOnly: false,
filters: [
{
relationType: "Contains",
entityTypes: [
"DEVICE"
]
}
]
}
}
];
const subscriptionOptions = {
type: 'timeseries', // Subscription type
singleEntity: false,
datasources: datasources, // Describes what data you want to subscribe
ignoreDataUpdateOnIntervalTick: true, //if true onDataUpdated will be triggered only when new data appears otherwise onDataUpdate will be triggered every second
useDashboardTimewindow: true,
callbacks: {
onDataUpdated: () => {
self.onDataUpdated();
},
},
};
self.ctx.subscriptionApi.createSubscription(subscriptionOptions, true).subscribe(
(subscription) => {
//Data is not available here! Code below just indicates where data will save.
self.ctx.defaultSubscription = subscription; //Saves subscription information into widget context
self.ctx.data = subscription.data; //Saves data into widget context
self.ctx.datasources = subscription.datasources; //Saves datasource into widget context
}
);
});
const defaultGrupo1Id = '0a2f8e60-6959-11f0-899a-b775ed58e7c9'; // Your actual Grupo 1 ID
self.ctx.broadcastService.broadcast('change-graph', {
groupId: defaultGrupo1Id,
groupName: 'Grupo 1'
});
};
The problem is that data is empty, so chart does not show lines.