Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timelist centering algorithm change and duration formatting change #7194

Merged
merged 25 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d2df694
Change the centering algorithm for timelist
shefalijoshi Nov 1, 2023
c5713f3
test: add time list countdown and countup test
ozyx Nov 7, 2023
cc824e0
test: respond to comments
ozyx Nov 8, 2023
755054e
chore: lint fix
ozyx Nov 8, 2023
c13b375
fix: lint errors and visual suite failures
ozyx Nov 8, 2023
cc7223b
Change parameters to options object
shefalijoshi Nov 20, 2023
2bb696a
Fix regression with auto scroll. Improve code readability
shefalijoshi Nov 20, 2023
3e47056
Merge branch 'master' into timelist-7130-7161
shefalijoshi Nov 20, 2023
e591933
Merge branch 'master' into timelist-7130-7161
shefalijoshi Nov 27, 2023
c467e85
Merge branch 'master' into timelist-7130-7161
shefalijoshi Dec 5, 2023
0c77e99
Add defaults for getPreciseDuration options object
shefalijoshi Dec 5, 2023
6382172
Merge branch 'timelist-7130-7161' of https://github.com/nasa/openmct …
shefalijoshi Dec 5, 2023
a99e522
Defaults for options
shefalijoshi Dec 5, 2023
031799a
Merge branch 'master' into timelist-7130-7161
shefalijoshi Dec 5, 2023
3411565
Merge branch 'master' into timelist-7130-7161
shefalijoshi Dec 11, 2023
f309749
Add missing await
shefalijoshi Dec 11, 2023
ef6b39d
Merge branch 'timelist-7130-7161' of https://github.com/nasa/openmct …
shefalijoshi Dec 11, 2023
6ba1052
Merge branch 'master' into timelist-7130-7161
shefalijoshi Dec 13, 2023
5bf252a
Merge branch 'master' of https://github.com/nasa/openmct into timelis…
shefalijoshi Jan 3, 2024
c79741b
Merge branch 'timelist-7130-7161' of https://github.com/nasa/openmct …
shefalijoshi Jan 3, 2024
69a6e2f
Fix imports for ESM
shefalijoshi Jan 3, 2024
75ba7f9
Fix json import
shefalijoshi Jan 3, 2024
1327b88
Fix broken test
shefalijoshi Jan 3, 2024
cdc3b9a
Merge branch 'master' into timelist-7130-7161
shefalijoshi Jan 4, 2024
c9000cf
Merge branch 'master' into timelist-7130-7161
shefalijoshi Jan 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 50 additions & 33 deletions src/plugins/timelist/TimelistComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ const headerItems = [
format: function (value) {
let result;
if (value < 0) {
result = `+${getPreciseDuration(Math.abs(value), true)}`;
result = `+${getPreciseDuration(Math.abs(value), true, true)}`;
} else if (value > 0) {
result = `-${getPreciseDuration(value, true)}`;
result = `-${getPreciseDuration(value, true, true)}`;
} else {
result = 'Now';
}
Expand Down Expand Up @@ -350,8 +350,10 @@ export default {
},
applyStyles(activities) {
let firstCurrentActivityIndex = -1;
let activityClosestToNowIndex = -1;
let firstFutureActivityIndex = -1;
let currentActivitiesCount = 0;
let pastActivitiesCount = 0;
let futureActivitiesCount = 0;
const styledActivities = activities.map((activity, index) => {
if (this.timestamp >= activity.start && this.timestamp <= activity.end) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's extract this condition to a boolean returning function for readability

activity.cssClass = CURRENT_CSS_SUFFIX;
Expand All @@ -363,11 +365,13 @@ export default {
} else if (this.timestamp < activity.start) {
activity.cssClass = FUTURE_CSS_SUFFIX;
//the index of the first activity that's greater than the current timestamp
if (activityClosestToNowIndex < 0) {
activityClosestToNowIndex = index;
if (firstFutureActivityIndex < 0) {
firstFutureActivityIndex = index;
}
futureActivitiesCount = futureActivitiesCount + 1;
} else {
activity.cssClass = PAST_CSS_SUFFIX;
pastActivitiesCount = pastActivitiesCount + 1;
}

if (!activity.key) {
Expand All @@ -384,9 +388,14 @@ export default {
return activity;
});

this.activityClosestToNowIndex = activityClosestToNowIndex;
this.firstCurrentActivityIndex = firstCurrentActivityIndex;
if (firstCurrentActivityIndex > -1) {
this.firstCurrentOrFutureActivityIndex = firstCurrentActivityIndex;
} else if (firstFutureActivityIndex > -1) {
this.firstCurrentOrFutureActivityIndex = firstFutureActivityIndex;
}
this.currentActivitiesCount = currentActivitiesCount;
this.pastActivitiesCount = pastActivitiesCount;
this.futureActivitiesCount = futureActivitiesCount;

return styledActivities;
},
Expand All @@ -401,9 +410,10 @@ export default {
return;
}

this.firstCurrentActivityIndex = -1;
this.activityClosestToNowIndex = -1;
this.firstCurrentOrFutureActivityIndex = -1;
this.pastActivitiesCount = 0;
this.currentActivitiesCount = 0;
this.futureActivitiesCount = 0;
this.$el.parentElement?.scrollTo({ top: 0 });
this.autoScrolled = false;
},
Expand All @@ -413,40 +423,47 @@ export default {
return;
}

const row = this.$el.querySelector('.js-list-item');
if (row && this.firstCurrentActivityIndex > -1) {
// scroll to somewhere mid-way of the current activities
const ROW_HEIGHT = row.getBoundingClientRect().height;
// See #7167 for scrolling algorithm
const scrollTop = this.calculateScrollOffset();

if (this.canAutoScroll() === false) {
return;
}

const scrollOffset =
this.currentActivitiesCount > 0 ? Math.floor(this.currentActivitiesCount / 2) : 0;
if (scrollTop === undefined) {
this.resetScroll();
} else {
this.$el.parentElement?.scrollTo({
top: ROW_HEIGHT * (this.firstCurrentActivityIndex + scrollOffset),
top: scrollTop,
behavior: 'smooth'
});
this.autoScrolled = false;
} else if (row && this.activityClosestToNowIndex > -1) {
// scroll to somewhere close to 'now'
}
},
calculateScrollOffset() {
let scrollTop;

//No scrolling necessary if no past events are present
if (this.pastActivitiesCount > 0) {
const row = this.$el.querySelector('.js-list-item');
const ROW_HEIGHT = row.getBoundingClientRect().height;

if (this.canAutoScroll() === false) {
return;
}
const maxViewableActivities =
Math.floor(this.$el.parentElement.getBoundingClientRect().height / ROW_HEIGHT) - 1;

this.$el.parentElement.scrollTo({
top: ROW_HEIGHT * (this.activityClosestToNowIndex - 1),
behavior: 'smooth'
});
this.autoScrolled = false;
} else {
// scroll to the top
this.resetScroll();
const currentAndFutureActivities = this.currentActivitiesCount + this.futureActivitiesCount;

//If there is more viewable area than all current and future activities combined, then show some past events
const numberOfPastEventsToShow = maxViewableActivities - currentAndFutureActivities;
if (numberOfPastEventsToShow > 0) {
//some past events can be shown - get that scroll index
if (this.pastActivitiesCount > numberOfPastEventsToShow) {
scrollTop =
ROW_HEIGHT * (this.firstCurrentOrFutureActivityIndex + numberOfPastEventsToShow);
}
} else {
// only show current and future events
scrollTop = ROW_HEIGHT * this.firstCurrentOrFutureActivityIndex;
}
}

return scrollTop;
},
deferAutoScroll() {
//if this is not a user-triggered event, don't defer auto scrolling
Expand Down
23 changes: 20 additions & 3 deletions src/utils/duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,33 @@ export function millisecondsToDHMS(numericDuration) {
return `${dhms ? '+' : ''} ${dhms}`;
}

export function getPreciseDuration(value, excludeMilliSeconds) {
export function getPreciseDuration(value, excludeMilliSeconds, useDayFormat) {
let preciseDuration;
const ms = value || 0;

const duration = [
toDoubleDigits(Math.floor(normalizeAge(ms / ONE_DAY))),
Math.floor(normalizeAge(ms / ONE_DAY)),
toDoubleDigits(Math.floor(normalizeAge((ms % ONE_DAY) / ONE_HOUR))),
toDoubleDigits(Math.floor(normalizeAge((ms % ONE_HOUR) / ONE_MINUTE))),
toDoubleDigits(Math.floor(normalizeAge((ms % ONE_MINUTE) / ONE_SECOND)))
];
if (!excludeMilliSeconds) {
duration.push(toTripleDigits(Math.floor(normalizeAge(ms % ONE_SECOND))));
}
return duration.join(':');

if (useDayFormat) {
// Format days as XD
const days = duration.shift();
if (days > 0) {
preciseDuration = `${days}D ${duration.join(':')}`;
} else {
preciseDuration = duration.join(':');
}
} else {
const days = toDoubleDigits(duration.shift());
duration.unshift(days);
preciseDuration = duration.join(':');
}

return preciseDuration;
}