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

fix(#6812): Align Plot and Plan X-Axes in Time Strips #7744

Merged
merged 26 commits into from
Jul 22, 2024
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5aa6a03
DRAFT - alignment for axes
shefalijoshi Jun 8, 2024
b240519
Use alignmentContext to manage tick widths instead of passing around …
shefalijoshi Jun 11, 2024
eff6398
Merge branch 'master' of https://github.com/nasa/openmct into alignme…
shefalijoshi Jun 11, 2024
c14960f
Remove log statements
shefalijoshi Jun 11, 2024
d2f7458
Add ability to remove alignment widths for a given y axis
shefalijoshi Jun 18, 2024
7e28e18
Fix computation of left margin and width of plan when in the timestrip
shefalijoshi Jun 20, 2024
2167eef
Remove excess padding when there is no left y axis
shefalijoshi Jun 20, 2024
bea3a92
Use alignment composable to adjust left margin and width of time syst…
shefalijoshi Jun 20, 2024
7ab7dc3
Fix now marker visibility
shefalijoshi Jun 20, 2024
8e15ba2
refactor: use built in `Map()` data structure
ozyx Jun 24, 2024
ae90491
refactor: improve readability and conciseness
ozyx Jun 24, 2024
ee1a322
docs: improve jsdocs
ozyx Jun 24, 2024
8f5e2ed
refactor: move jsdoc typedefs to bottom of file
ozyx Jun 24, 2024
78e5ec9
refactor: axis to use vue reactivity
ozyx Jun 25, 2024
81e66fc
fix: return alignment as an object of refs
ozyx Jun 26, 2024
63ac403
alignmentMap needs to be shared state, move it out of the useAlignmen…
shefalijoshi Jun 26, 2024
a096829
Merge branch 'alignment-composable' of https://github.com/nasa/openmc…
shefalijoshi Jun 26, 2024
8288570
Fix now marker offset
shefalijoshi Jul 1, 2024
c76c339
Merge branch 'master' of https://github.com/nasa/openmct into alignme…
shefalijoshi Jul 2, 2024
2029b93
Add new visual test for time strips
shefalijoshi Jul 5, 2024
5b51761
Merge branch 'master' of https://github.com/nasa/openmct into alignme…
unlikelyzero Jul 17, 2024
7b13022
update with animation stabilization
unlikelyzero Jul 17, 2024
467d5c8
Fix failing test due to changed injected property (path -> objectPath)
shefalijoshi Jul 22, 2024
68fdd6d
change injected property from path to objectPath
shefalijoshi Jul 22, 2024
99c1657
Fix spelling
shefalijoshi Jul 22, 2024
548533f
Remove unused arguments to function call
shefalijoshi Jul 22, 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
69 changes: 22 additions & 47 deletions src/ui/composables/alignmentContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*****************************************************************************/
/* eslint-disable func-style */

import { ref } from 'vue';
import { reactive } from 'vue';

/**
* Manages alignment for multiple y axes given an object path
Expand All @@ -36,32 +36,20 @@ const alignmentMap = new Map();
export function useAlignment(targetObject, path, openmct) {
const getAlignmentKeyForPath = () => {
const keys = Array.from(alignmentMap.keys());
if (!keys.length) {
return;
}
return (
path
//get just the identifiers
.map((domainObject) => {
return openmct.objects.makeKeyString(domainObject.identifier);
})
.reverse()
// find a match
.find((keyString) => {
return keys.includes(keyString);
})
);
return path
.map((domainObject) => openmct.objects.makeKeyString(domainObject.identifier))
.reverse()
.find((keyString) => keys.includes(keyString));
};

// Use the furthest ancestor's alignment if it exists, otherwise, use your own
let alignmentKey = getAlignmentKeyForPath(path);
let alignmentKey =
getAlignmentKeyForPath() || openmct.objects.makeKeyString(targetObject.identifier);

if (!alignmentKey) {
const targetObjectKey = openmct.objects.makeKeyString(targetObject.identifier);
alignmentKey = targetObjectKey;
if (!alignmentMap.has(alignmentKey)) {
alignmentMap.set(
targetObjectKey,
ref({
alignmentKey,
reactive({
leftWidth: 0,
rightWidth: 0,
multiple: false,
Expand All @@ -70,45 +58,34 @@ export function useAlignment(targetObject, path, openmct) {
);
}

// reset any alignment data for the given key
// Reset any alignment data for the given key
const resetAlignment = () => {
const key = getAlignmentKeyForPath(path);
const key = getAlignmentKeyForPath();
if (key && alignmentMap.has(key)) {
alignmentMap.delete(key);
}
};

// Given the axes ids and widths, calculate the max left and right widths and whether or not multiple left axes exist
const processAlignment = () => {
const alignment = alignmentMap.get(alignmentKey).value;
const alignment = alignmentMap.get(alignmentKey);
const axesKeys = Object.keys(alignment.axes);
const leftAxes = axesKeys.filter((axis) => axis <= 2);
const rightAxes = axesKeys.filter((axis) => axis > 2);
// Get width of left Y axis
let leftWidth = 0;
leftAxes.forEach((leftAxis) => {
leftWidth = leftWidth + alignment.axes[leftAxis];
});
alignment.leftWidth = leftWidth;

// Get width of right Y axis
let rightWidth = 0;
rightAxes.forEach((rightAxis) => {
rightWidth = rightWidth + alignment.axes[rightAxis];
});
alignment.rightWidth = rightWidth;

alignment.leftWidth = leftAxes.reduce((sum, axis) => sum + alignment.axes[axis], 0);
alignment.rightWidth = rightAxes.reduce((sum, axis) => sum + alignment.axes[axis], 0);
alignment.multiple = leftAxes.length > 1;
};

/**
* Unregister y-axis from width calculations
* @param {Object: yAxisId, updateObjectPath} the last known width of the y-axis, yAxisId of the tick bar, path of the axis being updated
* @param {Object} param0 - The object containing yAxisId, updateObjectPath, and type.
*/
const remove = ({ yAxisId, updateObjectPath, type } = {}) => {
const remove = ({ yAxisId, updateObjectPath } = {}) => {
const key = getAlignmentKeyForPath(updateObjectPath);

Check warning

Code scanning / CodeQL

Superfluous trailing arguments Warning

Superfluous argument passed to function getAlignmentKeyForPath.
if (key) {
const alignment = alignmentMap.get(alignmentKey).value;
const alignment = alignmentMap.get(alignmentKey);
if (alignment.axes[yAxisId] !== undefined) {
delete alignment.axes[yAxisId];
}
Expand All @@ -118,15 +95,13 @@ export function useAlignment(targetObject, path, openmct) {

/**
* Update widths of a y axis given the id and path. The path is used to determine which ancestor should hold the alignment
* @param {Object: width, yAxisId, updateObjectPath} the width of the y-axis, yAxisId of the tick bar, path of the axis being updated
* @param {Object} param0 - The object containing width, yAxisId, updateObjectPath, and type.
*/
const update = ({ width, yAxisId, updateObjectPath, type } = {}) => {
const update = ({ width, yAxisId, updateObjectPath } = {}) => {
const key = getAlignmentKeyForPath(updateObjectPath);

Check warning

Code scanning / CodeQL

Superfluous trailing arguments Warning

Superfluous argument passed to function getAlignmentKeyForPath.
if (key) {
const alignment = alignmentMap.get(alignmentKey).value;
if (alignment.axes[yAxisId] === undefined) {
alignment.axes[yAxisId] = width;
} else if (width > alignment.axes[yAxisId]) {
const alignment = alignmentMap.get(alignmentKey);
if (alignment.axes[yAxisId] === undefined || width > alignment.axes[yAxisId]) {
alignment.axes[yAxisId] = width;
}
processAlignment();
Expand Down