Image view should react to time conductor changes - 2712 (#2934)
Image view reacts to time conductor changes Fixes #2712 Co-authored-by: Andrew Henry <akhenry@gmail.com>
This commit is contained in:
@@ -52,6 +52,7 @@ define([
|
|||||||
return {
|
return {
|
||||||
name: name,
|
name: name,
|
||||||
utc: Math.floor(timestamp / 5000) * 5000,
|
utc: Math.floor(timestamp / 5000) * 5000,
|
||||||
|
local: Math.floor(timestamp / 5000) * 5000,
|
||||||
url: IMAGE_SAMPLES[Math.floor(timestamp / 5000) % IMAGE_SAMPLES.length]
|
url: IMAGE_SAMPLES[Math.floor(timestamp / 5000) % IMAGE_SAMPLES.length]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -78,7 +79,7 @@ define([
|
|||||||
},
|
},
|
||||||
request: function (domainObject, options) {
|
request: function (domainObject, options) {
|
||||||
var start = options.start;
|
var start = options.start;
|
||||||
var end = options.end;
|
var end = Math.min(options.end, Date.now());
|
||||||
var data = [];
|
var data = [];
|
||||||
while (start <= end && data.length < 5000) {
|
while (start <= end && data.length < 5000) {
|
||||||
data.push(pointForTimestamp(start, domainObject.name));
|
data.push(pointForTimestamp(start, domainObject.name));
|
||||||
@@ -118,6 +119,14 @@ define([
|
|||||||
name: 'Time',
|
name: 'Time',
|
||||||
key: 'utc',
|
key: 'utc',
|
||||||
format: 'utc',
|
format: 'utc',
|
||||||
|
hints: {
|
||||||
|
domain: 2
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Local Time',
|
||||||
|
key: 'local',
|
||||||
|
format: 'local-format',
|
||||||
hints: {
|
hints: {
|
||||||
domain: 1
|
domain: 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
autoScroll: true,
|
autoScroll: true,
|
||||||
date: '',
|
|
||||||
filters : {
|
filters : {
|
||||||
brightness: 100,
|
brightness: 100,
|
||||||
contrast: 100
|
contrast: 100
|
||||||
@@ -78,22 +77,39 @@ export default {
|
|||||||
imageHistory: [],
|
imageHistory: [],
|
||||||
imageUrl: '',
|
imageUrl: '',
|
||||||
isPaused: false,
|
isPaused: false,
|
||||||
|
metadata: {},
|
||||||
requestCount: 0,
|
requestCount: 0,
|
||||||
timeFormat: ''
|
timeFormat: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
// set
|
||||||
this.keystring = this.openmct.objects.makeKeyString(this.domainObject.identifier);
|
this.keystring = this.openmct.objects.makeKeyString(this.domainObject.identifier);
|
||||||
this.subscribe(this.domainObject);
|
this.metadata = this.openmct.telemetry.getMetadata(this.domainObject);
|
||||||
|
this.imageFormat = this.openmct.telemetry.getValueFormatter(this.metadata.valuesForHints(['image'])[0]);
|
||||||
|
// initialize
|
||||||
|
this.timeKey = this.openmct.time.timeSystem().key;
|
||||||
|
this.timeFormat = this.openmct.telemetry.getValueFormatter(this.metadata.value(this.timeKey));
|
||||||
|
// listen
|
||||||
|
this.openmct.time.on('bounds', this.boundsChange);
|
||||||
|
this.openmct.time.on('timeSystem', this.timeSystemChange);
|
||||||
|
// kickoff
|
||||||
|
this.subscribe();
|
||||||
|
this.requestHistory();
|
||||||
},
|
},
|
||||||
updated() {
|
updated() {
|
||||||
this.scrollToRight();
|
this.scrollToRight();
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.stopListening();
|
if (this.unsubscribe) {
|
||||||
|
this.unsubscribe();
|
||||||
|
delete this.unsubscribe;
|
||||||
|
}
|
||||||
|
this.openmct.time.off('bounds', this.boundsChange);
|
||||||
|
this.openmct.time.off('timeSystem', this.timeSystemChange);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
datumMatchesMostRecent(datum) {
|
datumIsNotValid(datum) {
|
||||||
if (this.imageHistory.length === 0) {
|
if (this.imageHistory.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -103,7 +119,14 @@ export default {
|
|||||||
const lastHistoryTime = this.timeFormat.format(this.imageHistory.slice(-1)[0]);
|
const lastHistoryTime = this.timeFormat.format(this.imageHistory.slice(-1)[0]);
|
||||||
const lastHistoryURL = this.imageFormat.format(this.imageHistory.slice(-1)[0]);
|
const lastHistoryURL = this.imageFormat.format(this.imageHistory.slice(-1)[0]);
|
||||||
|
|
||||||
return (datumTime === lastHistoryTime) && (datumURL === lastHistoryURL);
|
// datum is not valid if it matches the last datum in history,
|
||||||
|
// or it is before the last datum in the history
|
||||||
|
const datumTimeCheck = this.timeFormat.parse(datum);
|
||||||
|
const historyTimeCheck = this.timeFormat.parse(this.imageHistory.slice(-1)[0]);
|
||||||
|
const matchesLast = (datumTime === lastHistoryTime) && (datumURL === lastHistoryURL);
|
||||||
|
const isStale = datumTimeCheck < historyTimeCheck;
|
||||||
|
|
||||||
|
return matchesLast || isStale;
|
||||||
},
|
},
|
||||||
getImageUrl(datum) {
|
getImageUrl(datum) {
|
||||||
return datum ?
|
return datum ?
|
||||||
@@ -147,21 +170,6 @@ export default {
|
|||||||
|
|
||||||
return this.isPaused;
|
return this.isPaused;
|
||||||
},
|
},
|
||||||
requestHistory(bounds) {
|
|
||||||
this.requestCount++;
|
|
||||||
this.imageHistory = [];
|
|
||||||
const requestId = this.requestCount;
|
|
||||||
this.openmct.telemetry
|
|
||||||
.request(this.domainObject, bounds)
|
|
||||||
.then((values = []) => {
|
|
||||||
if (this.requestCount > requestId) {
|
|
||||||
return Promise.resolve('Stale request');
|
|
||||||
}
|
|
||||||
|
|
||||||
values.forEach(this.updateHistory);
|
|
||||||
this.updateValues(values[values.length - 1]);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
scrollToRight() {
|
scrollToRight() {
|
||||||
if (this.isPaused || !this.$refs.thumbsWrapper || !this.autoScroll) {
|
if (this.isPaused || !this.$refs.thumbsWrapper || !this.autoScroll) {
|
||||||
return;
|
return;
|
||||||
@@ -188,40 +196,56 @@ export default {
|
|||||||
image.selected = true;
|
image.selected = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
stopListening() {
|
boundsChange(bounds, isTick) {
|
||||||
if (this.unsubscribe) {
|
if(!isTick) {
|
||||||
this.unsubscribe();
|
this.requestHistory();
|
||||||
delete this.unsubscribe;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
subscribe(domainObject) {
|
requestHistory() {
|
||||||
this.date = ''
|
let bounds = this.openmct.time.bounds();
|
||||||
this.imageUrl = '';
|
this.requestCount++;
|
||||||
this.openmct.objects.get(this.keystring)
|
const requestId = this.requestCount;
|
||||||
.then((object) => {
|
this.imageHistory = [];
|
||||||
const metadata = this.openmct.telemetry.getMetadata(this.domainObject);
|
this.openmct.telemetry
|
||||||
this.timeKey = this.openmct.time.timeSystem().key;
|
.request(this.domainObject, bounds)
|
||||||
this.timeFormat = this.openmct.telemetry.getValueFormatter(metadata.value(this.timeKey));
|
.then((values = []) => {
|
||||||
this.imageFormat = this.openmct.telemetry.getValueFormatter(metadata.valuesForHints(['image'])[0]);
|
if (this.requestCount === requestId) {
|
||||||
this.unsubscribe = this.openmct.telemetry
|
values.forEach(this.updateHistory, false);
|
||||||
.subscribe(this.domainObject, (datum) => {
|
this.updateValues(values[values.length - 1]);
|
||||||
this.updateHistory(datum);
|
}
|
||||||
this.updateValues(datum);
|
});
|
||||||
});
|
},
|
||||||
|
timeSystemChange(system) {
|
||||||
|
// reset timesystem dependent variables
|
||||||
|
this.timeKey = system.key;
|
||||||
|
this.timeFormat = this.openmct.telemetry.getValueFormatter(this.metadata.value(this.timeKey));
|
||||||
|
},
|
||||||
|
subscribe() {
|
||||||
|
this.unsubscribe = this.openmct.telemetry
|
||||||
|
.subscribe(this.domainObject, (datum) => {
|
||||||
|
let parsedTimestamp = this.timeFormat.parse(datum[this.timeKey]),
|
||||||
|
bounds = this.openmct.time.bounds();
|
||||||
|
|
||||||
this.requestHistory(this.openmct.time.bounds());
|
if(parsedTimestamp >= bounds.start && parsedTimestamp <= bounds.end) {
|
||||||
|
this.updateHistory(datum);
|
||||||
|
this.updateValues(datum);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
unselectAllImages() {
|
unselectAllImages() {
|
||||||
this.imageHistory.forEach(image => image.selected = false);
|
this.imageHistory.forEach(image => image.selected = false);
|
||||||
},
|
},
|
||||||
updateHistory(datum) {
|
updateHistory(datum, updateValues = true) {
|
||||||
if (this.datumMatchesMostRecent(datum)) {
|
if (this.datumIsNotValid(datum)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const index = _.sortedIndexBy(this.imageHistory, datum, this.timeFormat.format.bind(this.timeFormat));
|
const index = _.sortedIndexBy(this.imageHistory, datum, this.timeFormat.format.bind(this.timeFormat));
|
||||||
this.imageHistory.splice(index, 0, datum);
|
this.imageHistory.splice(index, 0, datum);
|
||||||
|
|
||||||
|
if(updateValues) {
|
||||||
|
this.updateValues(datum);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
updateValues(datum) {
|
updateValues(datum) {
|
||||||
if (this.isPaused) {
|
if (this.isPaused) {
|
||||||
|
|||||||
Reference in New Issue
Block a user