Fix now marker for time system axis in timestrips and plans (#5911)

* Ensure the now marker spans the height of the plan.
* Set height for timestrip for the now marker
* Fix linting issues
* Fix failing test
This commit is contained in:
Shefali Joshi 2022-10-31 16:56:52 -07:00 committed by GitHub
parent 015c764ab3
commit 4697352f60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 17 deletions

View File

@ -129,11 +129,13 @@ export default {
this.timeContext.on("timeSystem", this.setScaleAndPlotActivities); this.timeContext.on("timeSystem", this.setScaleAndPlotActivities);
this.timeContext.on("bounds", this.updateViewBounds); this.timeContext.on("bounds", this.updateViewBounds);
this.timeContext.on("clock", this.updateBounds);
}, },
stopFollowingTimeContext() { stopFollowingTimeContext() {
if (this.timeContext) { if (this.timeContext) {
this.timeContext.off("timeSystem", this.setScaleAndPlotActivities); this.timeContext.off("timeSystem", this.setScaleAndPlotActivities);
this.timeContext.off("bounds", this.updateViewBounds); this.timeContext.off("bounds", this.updateViewBounds);
this.timeContext.off("clock", this.updateBounds);
} }
}, },
observeForChanges(mutatedObject) { observeForChanges(mutatedObject) {
@ -142,10 +144,15 @@ export default {
}, },
resize() { resize() {
let clientWidth = this.getClientWidth(); let clientWidth = this.getClientWidth();
let clientHeight = this.getClientHeight();
if (clientWidth !== this.width) { if (clientWidth !== this.width) {
this.setDimensions(); this.setDimensions();
this.updateViewBounds(); this.updateViewBounds();
} }
if (clientHeight !== this.height) {
this.setDimensions();
}
}, },
getClientWidth() { getClientWidth() {
let clientWidth = this.$refs.plan.clientWidth; let clientWidth = this.$refs.plan.clientWidth;
@ -160,9 +167,27 @@ export default {
return clientWidth - 200; return clientWidth - 200;
}, },
getClientHeight() {
let clientHeight = this.$refs.plan.clientHeight;
if (!clientHeight) {
//this is a hack - need a better way to find the parent of this component
let parent = this.openmct.layout.$refs.browseObject.$el;
if (parent) {
clientHeight = parent.getBoundingClientRect().height;
}
}
return clientHeight;
},
getPlanData(domainObject) { getPlanData(domainObject) {
this.planData = getValidatedData(domainObject); this.planData = getValidatedData(domainObject);
}, },
updateBounds(clock) {
if (clock === undefined) {
this.viewBounds = Object.create(this.timeContext.bounds());
}
},
updateViewBounds(bounds) { updateViewBounds(bounds) {
if (bounds) { if (bounds) {
this.viewBounds = Object.create(bounds); this.viewBounds = Object.create(bounds);
@ -191,10 +216,8 @@ export default {
activities.forEach(activity => activity.remove()); activities.forEach(activity => activity.remove());
}, },
setDimensions() { setDimensions() {
const planHolder = this.$refs.plan;
this.width = this.getClientWidth(); this.width = this.getClientWidth();
this.height = this.getClientHeight();
this.height = Math.round(planHolder.getBoundingClientRect().height);
}, },
setScale(timeSystem) { setScale(timeSystem) {
if (!this.width) { if (!this.width) {

View File

@ -124,12 +124,10 @@ export default {
}; };
this.items.push(item); this.items.push(item);
this.updateContentHeight();
}, },
removeItem(identifier) { removeItem(identifier) {
let index = this.items.findIndex(item => this.openmct.objects.areIdsEqual(identifier, item.domainObject.identifier)); let index = this.items.findIndex(item => this.openmct.objects.areIdsEqual(identifier, item.domainObject.identifier));
this.items.splice(index, 1); this.items.splice(index, 1);
this.updateContentHeight();
}, },
reorder(reorderPlan) { reorder(reorderPlan) {
let oldItems = this.items.slice(); let oldItems = this.items.slice();
@ -138,7 +136,23 @@ export default {
}); });
}, },
updateContentHeight() { updateContentHeight() {
this.height = Math.round(this.$refs.contentHolder.getBoundingClientRect().height); const clientHeight = this.getClientHeight();
if (this.height !== clientHeight) {
this.height = clientHeight;
}
},
getClientHeight() {
let clientHeight = this.$refs.contentHolder.getBoundingClientRect().height;
if (!clientHeight) {
//this is a hack - need a better way to find the parent of this component
let parent = this.openmct.layout.$refs.browseObject.$el;
if (parent) {
clientHeight = parent.getBoundingClientRect().height;
}
}
return clientHeight;
}, },
getTimeSystems() { getTimeSystems() {
const timeSystems = this.openmct.time.getAllTimeSystems(); const timeSystems = this.openmct.time.getAllTimeSystems();
@ -155,7 +169,9 @@ export default {
//TODO: Some kind of translation via an offset? of current bounds to target timeSystem //TODO: Some kind of translation via an offset? of current bounds to target timeSystem
return currentBounds; return currentBounds;
}, },
updateViewBounds(bounds) { updateViewBounds() {
const bounds = this.timeContext.bounds();
this.updateContentHeight();
let currentTimeSystem = this.timeSystems.find(item => item.timeSystem.key === this.openmct.time.timeSystem().key); let currentTimeSystem = this.timeSystems.find(item => item.timeSystem.key === this.openmct.time.timeSystem().key);
if (currentTimeSystem) { if (currentTimeSystem) {
currentTimeSystem.bounds = bounds; currentTimeSystem.bounds = bounds;
@ -166,12 +182,14 @@ export default {
this.timeContext = this.openmct.time.getContextForView(this.objectPath); this.timeContext = this.openmct.time.getContextForView(this.objectPath);
this.getTimeSystems(); this.getTimeSystems();
this.updateViewBounds(this.timeContext.bounds()); this.updateViewBounds();
this.timeContext.on('bounds', this.updateViewBounds); this.timeContext.on('bounds', this.updateViewBounds);
this.timeContext.on('clock', this.updateViewBounds);
}, },
stopFollowingTimeContext() { stopFollowingTimeContext() {
if (this.timeContext) { if (this.timeContext) {
this.timeContext.off('bounds', this.updateViewBounds); this.timeContext.off('bounds', this.updateViewBounds);
this.timeContext.off('clock', this.updateViewBounds);
} }
} }
} }

View File

@ -27,6 +27,7 @@ import EventEmitter from "EventEmitter";
describe('the plugin', function () { describe('the plugin', function () {
let objectDef; let objectDef;
let appHolder;
let element; let element;
let child; let child;
let openmct; let openmct;
@ -92,6 +93,10 @@ describe('the plugin', function () {
}; };
beforeEach((done) => { beforeEach((done) => {
appHolder = document.createElement('div');
appHolder.style.width = '640px';
appHolder.style.height = '480px';
mockObjectPath = [ mockObjectPath = [
{ {
name: 'mock folder', name: 'mock folder',
@ -133,7 +138,7 @@ describe('the plugin', function () {
element.appendChild(child); element.appendChild(child);
openmct.on('start', done); openmct.on('start', done);
openmct.startHeadless(); openmct.start(appHolder);
}); });
afterEach(() => { afterEach(() => {
@ -167,7 +172,7 @@ describe('the plugin', function () {
const applicableViews = openmct.objectViews.get(testViewObject, mockObjectPath); const applicableViews = openmct.objectViews.get(testViewObject, mockObjectPath);
timelineView = applicableViews.find((viewProvider) => viewProvider.key === 'time-strip.view'); timelineView = applicableViews.find((viewProvider) => viewProvider.key === 'time-strip.view');
let view = timelineView.view(testViewObject, element); let view = timelineView.view(testViewObject, mockObjectPath);
view.show(child, true); view.show(child, true);
return Vue.nextTick(); return Vue.nextTick();
@ -245,7 +250,7 @@ describe('the plugin', function () {
beforeEach(done => { beforeEach(done => {
const applicableViews = openmct.objectViews.get(testViewObject, mockObjectPath); const applicableViews = openmct.objectViews.get(testViewObject, mockObjectPath);
timelineView = applicableViews.find((viewProvider) => viewProvider.key === 'time-strip.view'); timelineView = applicableViews.find((viewProvider) => viewProvider.key === 'time-strip.view');
let view = timelineView.view(testViewObject, element); let view = timelineView.view(testViewObject, mockObjectPath);
view.show(child, true); view.show(child, true);
Vue.nextTick(done); Vue.nextTick(done);
@ -281,7 +286,7 @@ describe('the plugin', function () {
beforeEach((done) => { beforeEach((done) => {
const applicableViews = openmct.objectViews.get(testViewObject2, mockObjectPath); const applicableViews = openmct.objectViews.get(testViewObject2, mockObjectPath);
timelineView = applicableViews.find((viewProvider) => viewProvider.key === 'time-strip.view'); timelineView = applicableViews.find((viewProvider) => viewProvider.key === 'time-strip.view');
let view = timelineView.view(testViewObject2, element); let view = timelineView.view(testViewObject2, mockObjectPath);
view.show(child, true); view.show(child, true);
Vue.nextTick(done); Vue.nextTick(done);

View File

@ -94,15 +94,13 @@ export default {
if (this.openmct.time.clock() === undefined) { if (this.openmct.time.clock() === undefined) {
let nowMarker = document.querySelector('.nowMarker'); let nowMarker = document.querySelector('.nowMarker');
if (nowMarker) { if (nowMarker) {
nowMarker.parentNode.removeChild(nowMarker); nowMarker.classList.add('hidden');
} }
} else { } else {
let nowMarker = document.querySelector('.nowMarker'); let nowMarker = document.querySelector('.nowMarker');
if (nowMarker) { if (nowMarker) {
const svgEl = d3Selection.select(this.svgElement).node(); nowMarker.classList.remove('hidden');
let height = svgEl.style('height').replace('px', ''); nowMarker.style.height = this.contentHeight + 'px';
height = Number(height) + this.contentHeight;
nowMarker.style.height = height + 'px';
const now = this.xScale(Date.now()); const now = this.xScale(Date.now());
nowMarker.style.left = now + this.offset + 'px'; nowMarker.style.left = now + this.offset + 'px';
} }

View File

@ -32,6 +32,10 @@
z-index: 10; z-index: 10;
background: gray; background: gray;
&.hidden {
display: none;
}
& .icon-arrow-down { & .icon-arrow-down {
font-size: large; font-size: large;
position: absolute; position: absolute;