Skip to content

Commit

Permalink
Fix Graph Display Without Recent Devicestatus (#5409)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcunningh authored and sulkaharo committed Jan 6, 2020
1 parent df03577 commit 60be07c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
27 changes: 21 additions & 6 deletions lib/client/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function init (client, d3, $) {
chart.createAdjustedRange = function() {
var adjustedRange = chart.createBrushedRange();

adjustedRange[1] = new Date(adjustedRange[1].getTime() + client.forecastTime);
adjustedRange[1] = new Date(Math.max(adjustedRange[1].getTime(), client.forecastTime));

return adjustedRange;
}
Expand Down Expand Up @@ -609,6 +609,8 @@ function init (client, d3, $) {
var currentBrushExtent = scrollBrushExtent;
var currentRange = scrollRange;

chart.setForecastTime();

chart.xScale.domain(currentRange);

focusYDomain = dynamicDomainOrElse(focusYDomain);
Expand Down Expand Up @@ -663,6 +665,10 @@ function init (client, d3, $) {
renderer.addTreatmentProfiles(client);
renderer.drawTreatments(client);


// console.log('Redrawing brush due to update: ', currentBrushExtent);

chart.theBrush.call(chart.brush.move, currentBrushExtent.map(chart.xScale2));
}

chart.scroll = function scroll (nowDate) {
Expand Down Expand Up @@ -704,21 +710,30 @@ function init (client, d3, $) {
if (client.sbx.pluginBase.forecastPoints) {
var shownForecastPoints = chart.getForecastData();

var focusHoursAheadMills = chart.getMaxForecastMills();
// Get maximum time we will allow projected forward in time
// based on the number of hours the user has selected to show.
var maxForecastMills = chart.getMaxForecastMills();

var selectedRange = chart.createBrushedRange();
var to = selectedRange[1].getTime();
var maxForecastMills = to + times.mins(30).msecs;

// Default min forecast projection times to the default amount of time to forecast
var minForecastMills = to + client.defaultForecastTime;
var availForecastMills = 0;

// Determine what the maximum forecast time is that is available in the forecast data
if (shownForecastPoints.length > 0) {
maxForecastMills = _.max(_.map(shownForecastPoints, function(point) { return point.mills }));
availForecastMills = _.max(_.map(shownForecastPoints, function(point) { return point.mills }));
}

maxForecastMills = Math.min(focusHoursAheadMills, maxForecastMills);
// Limit the amount shown to the maximum time allowed to be projected forward based
// on the number of hours the user has selected to show
var forecastMills = Math.min(availForecastMills, maxForecastMills);

var lastSGVMills = client.sbx.lastSGVMills();

client.forecastTime = ((maxForecastMills > 0) && lastSGVMills) ? maxForecastMills - lastSGVMills : client.defaultForecastTime;
// Don't allow the forecast time to go below the minimum forecast time
client.forecastTime = Math.max(forecastMills, minForecastMills);
}
};

Expand Down
3 changes: 2 additions & 1 deletion lib/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ client.load = function load (serverSettings, callback) {

client.now = Date.now();
client.ddata = require('../data/ddata')();
client.forecastTime = client.defaultForecastTime = times.mins(30).msecs;
client.defaultForecastTime = times.mins(30).msecs;
client.forecastTime = client.now + client.defaultForecastTime;
client.entries = [];
client.ticks = require('./ticks');

Expand Down

0 comments on commit 60be07c

Please sign in to comment.