diff --git a/src/panel/graph_panel/controllers/analytic_controller.ts b/src/panel/graph_panel/controllers/analytic_controller.ts index 311fbf9..93e2c97 100644 --- a/src/panel/graph_panel/controllers/analytic_controller.ts +++ b/src/panel/graph_panel/controllers/analytic_controller.ts @@ -505,12 +505,16 @@ export class AnalyticController { async getHSR(from: number, to: number): Promise { // Returns HSR (Hastic Signal Representation) for analytic unit in "Inspect" mode - // Returns null when there is no analytic units in "Inspect" mode + // Returns null when there are no analytic units in "Inspect" mode + // or if there is no response from server if(this.inspectedAnalyticUnit === null) { return null; } const hsr = await this._analyticService.getHSR(this.inspectedAnalyticUnit.id, from, to); + if(hsr === null) { + return null; + } const datapoints = hsr.values.map(value => value.reverse() as [number, number]); return { target: 'HSR', datapoints }; } diff --git a/src/panel/graph_panel/graph_ctrl.ts b/src/panel/graph_panel/graph_ctrl.ts index 8ef5d9b..4b7fc16 100644 --- a/src/panel/graph_panel/graph_ctrl.ts +++ b/src/panel/graph_panel/graph_ctrl.ts @@ -398,6 +398,13 @@ class GraphCtrl extends MetricsPanelCtrl { }; break; } + const from = _.find(series.datapoints, datapoint => datapoint[0] !== null); + const to = _.findLast(series.datapoints, datapoint => datapoint[0] !== null); + + this._dataTimerange = {}; + if(from !== undefined && to !== undefined) { + this._dataTimerange = { from: from[1], to: to[1] }; + } } } @@ -410,11 +417,11 @@ class GraphCtrl extends MetricsPanelCtrl { await Promise.all(loadTasks); // this.annotations = results[0].annotations; - this.render(this.seriesList); - this.analyticsController.fetchAnalyticUnitsDetections( + await this.analyticsController.fetchAnalyticUnitsDetections( this._dataTimerange.from, this._dataTimerange.to ); + this.render(this.seriesList); } this.loading = false; @@ -426,14 +433,6 @@ class GraphCtrl extends MetricsPanelCtrl { } for(let series of this.seriesList) { - const from = _.find(series.datapoints, datapoint => datapoint[0] !== null); - const to = _.findLast(series.datapoints, datapoint => datapoint[0] !== null); - - this._dataTimerange = {}; - if(from !== undefined && to !== undefined) { - this._dataTimerange = { from: from[1], to: to[1] }; - } - if (series.unit) { this.panel.yaxes[series.yaxis - 1].format = series.unit; } diff --git a/src/panel/graph_panel/services/analytic_service.ts b/src/panel/graph_panel/services/analytic_service.ts index 2935efa..3b87ac3 100644 --- a/src/panel/graph_panel/services/analytic_service.ts +++ b/src/panel/graph_panel/services/analytic_service.ts @@ -203,8 +203,11 @@ export class AnalyticService { async getHSR(analyticUnitId: AnalyticUnitId, from: number, to: number): Promise<{ values: [number, number][]; columns: string[]; - }> { + } | null> { const data = await this.get('/query', { analyticUnitId, from, to }); + if(data === undefined) { + return null; + } return data.results; }