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
Show file tree
Hide file tree
Changes from 4 commits
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
24 changes: 22 additions & 2 deletions src/plugins/plan/components/ActivityTimeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{{ heading }}
</template>
<template #object>
<svg :height="height" :width="width">
<svg :height="height" :width="svgWidth" :style="alignmentStyle">
<symbol id="activity-bar-bg" :height="rowHeight" width="2" preserveAspectRatio="none">
<rect x="0" y="0" width="100%" height="100%" fill="currentColor" />
<line
Expand Down Expand Up @@ -92,13 +92,17 @@
</template>

<script>
import { inject } from 'vue';

import SwimLane from '@/ui/components/swim-lane/SwimLane.vue';

import { useAlignment } from '../../../ui/composables/alignmentContext';
shefalijoshi marked this conversation as resolved.
Show resolved Hide resolved

export default {
components: {
SwimLane
},
inject: ['openmct', 'domainObject'],
inject: ['openmct', 'domainObject', 'path'],
props: {
activities: {
type: Array,
Expand Down Expand Up @@ -136,11 +140,27 @@ export default {
}
},
emits: ['activity-selected'],
setup() {
const domainObject = inject('domainObject');
const path = inject('path');
const openmct = inject('openmct');
const { alignment: alignmentData } = useAlignment(domainObject, path, openmct);

return { alignmentData };
},
data() {
return {
lineHeight: 10
};
},
computed: {
alignmentStyle() {
return { marginLeft: `${this.alignmentData.leftWidth + 20}px` };
},
svgWidth() {
return this.width - this.alignmentData.leftWidth - 20;
}
},
methods: {
setSelectionForActivity(activity, event) {
event.stopPropagation();
Expand Down
120 changes: 16 additions & 104 deletions src/plugins/plot/MctPlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,9 @@
v-for="(yAxis, index) in yAxesIds"
:id="yAxis.id"
:key="`yAxis-${yAxis.id}-${index}`"
:has-multiple-left-axes="hasMultipleLeftAxes"
:position="yAxis.id > 2 ? 'right' : 'left'"
:class="{ 'plot-yaxis-right': yAxis.id > 2 }"
:tick-width="yAxis.tickWidth"
:used-tick-width="plotFirstLeftTickWidth"
:plot-left-tick-width="yAxis.id > 2 ? yAxis.tickWidth : plotLeftTickWidth"
@y-key-changed="setYAxisKey"
@plot-y-tick-width="onYTickWidthChange"
@toggle-axis-visibility="toggleSeriesForYAxis"
/>
</div>
Expand All @@ -66,7 +61,6 @@
:axis-type="'yAxis'"
:position="'bottom'"
:axis-id="yAxis.id"
@plot-tick-width="onYTickWidthChange"
/>

<div
Expand Down Expand Up @@ -178,9 +172,10 @@
import Flatbush from 'flatbush';
import _ from 'lodash';
import { useEventBus } from 'utils/useEventBus';
import { toRaw } from 'vue';
import { inject, toRaw } from 'vue';

import { MODES } from '../../api/time/constants';
import { useAlignment } from '../../ui/composables/alignmentContext';
import TagEditorClassNames from '../inspectorViews/annotations/tags/TagEditorClassNames.js';
import XAxis from './axis/XAxis.vue';
import YAxis from './axis/YAxis.vue';
Expand Down Expand Up @@ -223,16 +218,6 @@
return false;
}
},
parentYTickWidth: {
type: Object,
default() {
return {
leftTickWidth: 0,
rightTickWidth: 0,
hasMultipleLeftAxes: false
};
}
},
limitLineLabels: {
type: Object,
default() {
Expand All @@ -252,15 +237,21 @@
'grid-lines',
'loading-complete',
'loading-updated',
'plot-y-tick-width',
'highlights',
'lock-highlight-point',
'status-updated'
],
setup() {
const { EventBus } = useEventBus();

const domainObject = inject('domainObject');
const path = inject('path');
const openmct = inject('openmct');
const { alignment: alignmentData } = useAlignment(domainObject, path, openmct);

return {
EventBus
EventBus,
alignmentData
};
},
data() {
Expand Down Expand Up @@ -292,28 +283,20 @@
},
computed: {
xAxisStyle() {
const rightAxis = this.yAxesIds.find((yAxis) => yAxis.id > 2);
const leftOffset = this.hasMultipleLeftAxes ? 2 * AXES_PADDING : AXES_PADDING;
const leftOffset = this.alignmentData.multiple ? 2 * AXES_PADDING : AXES_PADDING;
let style = {
left: `${this.plotLeftTickWidth + leftOffset}px`
left: `${this.alignmentData.leftWidth + leftOffset}px`
};
const parentRightAxisWidth = this.parentYTickWidth.rightTickWidth;

if (parentRightAxisWidth || rightAxis) {
style.right = `${(parentRightAxisWidth || rightAxis.tickWidth) + AXES_PADDING}px`;
if (this.alignmentData.rightWidth) {
style.right = `${this.alignmentData.rightWidth + AXES_PADDING}px`;

Check warning on line 292 in src/plugins/plot/MctPlot.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/plot/MctPlot.vue#L292

Added line #L292 was not covered by tests
}

return style;
},
yAxesIds() {
return this.yAxes.filter((yAxis) => yAxis.seriesCount > 0);
},
hasMultipleLeftAxes() {
return (
this.parentYTickWidth.hasMultipleLeftAxes ||
this.yAxes.filter((yAxis) => yAxis.seriesCount > 0 && yAxis.id <= 2).length > 1
);
},
isNestedWithinAStackedPlot() {
const isNavigatedObject = this.openmct.router.isNavigatedObject(
[this.domainObject].concat(this.path)
Expand All @@ -331,24 +314,6 @@
// only allow annotations viewing/editing if plot is paused or in fixed time mode
return this.isFrozen || !this.isRealTime;
},
plotFirstLeftTickWidth() {
const firstYAxis = this.yAxes.find((yAxis) => yAxis.id === 1);

return firstYAxis ? firstYAxis.tickWidth : 0;
},
plotLeftTickWidth() {
let leftTickWidth = 0;
this.yAxes.forEach((yAxis) => {
if (yAxis.id > 2) {
return;
}

leftTickWidth = leftTickWidth + yAxis.tickWidth;
});
const parentLeftTickWidth = this.parentYTickWidth.leftTickWidth;

return parentLeftTickWidth || leftTickWidth;
},
seriesDataLoaded() {
return this.pending === 0 && this.loaded;
}
Expand Down Expand Up @@ -381,17 +346,15 @@
this.yAxes = [
{
id: this.config.yAxis.id,
seriesCount: 0,
tickWidth: 0
seriesCount: 0
}
];
if (this.config.additionalYAxes) {
this.yAxes = this.yAxes.concat(
this.config.additionalYAxes.map((yAxis) => {
return {
id: yAxis.id,
seriesCount: 0,
tickWidth: 0
seriesCount: 0
};
})
);
Expand Down Expand Up @@ -605,14 +568,6 @@
updateTicksAndSeriesForYAxis(newAxisId, oldAxisId) {
this.updateAxisUsageCount(oldAxisId, -1);
this.updateAxisUsageCount(newAxisId, 1);

const foundYAxis = this.yAxes.find((yAxis) => yAxis.id === oldAxisId);
if (foundYAxis.seriesCount === 0) {
this.onYTickWidthChange({
width: foundYAxis.tickWidth,
yAxisId: foundYAxis.id
});
}
},

updateAxisUsageCount(yAxisId, updateCountBy) {
Expand Down Expand Up @@ -1019,49 +974,6 @@
}
},

/**
* Aggregate widths of all left and right y axes and send them up to any parent plots
* @param {Object} tickWidthWithYAxisId - the width and yAxisId of the tick bar
* @param fromDifferentObject
*/
onYTickWidthChange(tickWidthWithYAxisId, fromDifferentObject) {
const { width, yAxisId } = tickWidthWithYAxisId;
if (yAxisId) {
const index = this.yAxes.findIndex((yAxis) => yAxis.id === yAxisId);
if (fromDifferentObject) {
// Always accept tick width if it comes from a different object.
this.yAxes[index].tickWidth = width;
} else {
// Otherwise, only accept tick with if it's larger.
const newWidth = Math.max(width, this.yAxes[index].tickWidth);
if (width !== this.yAxes[index].tickWidth) {
this.yAxes[index].tickWidth = newWidth;
}
}

const id = this.openmct.objects.makeKeyString(this.domainObject.identifier);
const leftTickWidth = this.yAxes
.filter((yAxis) => yAxis.id < 3)
.reduce((previous, current) => {
return previous + current.tickWidth;
}, 0);
const rightTickWidth = this.yAxes
.filter((yAxis) => yAxis.id > 2)
.reduce((previous, current) => {
return previous + current.tickWidth;
}, 0);
this.$emit(
'plot-y-tick-width',
{
hasMultipleLeftAxes: this.hasMultipleLeftAxes,
leftTickWidth,
rightTickWidth
},
id
);
}
},

toggleSeriesForYAxis({ id, visible }) {
//if toggling to visible, re-fetch the data for the series that are part of this y Axis
if (visible === true) {
Expand Down
21 changes: 20 additions & 1 deletion src/plugins/plot/MctTicks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,17 @@
</template>

<script>
import { inject } from 'vue';

import { useAlignment } from '../../ui/composables/alignmentContext';
import configStore from './configuration/ConfigStore.js';
import eventHelpers from './lib/eventHelpers.js';
import { getFormattedTicks, getLogTicks, ticks } from './tickUtils.js';

const SECONDARY_TICK_NUMBER = 2;

export default {
inject: ['openmct', 'domainObject'],
inject: ['openmct', 'domainObject', 'path'],
shefalijoshi marked this conversation as resolved.
Show resolved Hide resolved
props: {
axisType: {
type: String,
Expand Down Expand Up @@ -111,6 +114,14 @@ export default {
}
},
emits: ['plot-tick-width'],
setup() {
const domainObject = inject('domainObject');
const path = inject('path');
const openmct = inject('openmct');
const { update: updateAlignment } = useAlignment(domainObject, path, openmct);

return { updateAlignment };
},
data() {
return {
ticks: []
Expand Down Expand Up @@ -279,6 +290,14 @@ export default {
width: tickWidth,
yAxisId: this.axisType === 'yAxis' ? this.axisId : ''
});
if (this.axisType === 'yAxis') {
this.updateAlignment({
width: tickWidth,
yAxisId: this.axisId,
updateObjectPath: this.path
});
}

this.shouldCheckWidth = false;
}
}
Expand Down
16 changes: 0 additions & 16 deletions src/plugins/plot/PlotView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@
:init-cursor-guide="cursorGuide"
:options="options"
:limit-line-labels="limitLineLabelsProp"
:parent-y-tick-width="parentYTickWidth"
:color-palette="colorPalette"
@loading-updated="loadingUpdated"
@status-updated="setStatus"
@config-loaded="updateReady"
@lock-highlight-point="lockHighlightPointUpdated"
@highlights="highlightsUpdated"
@plot-y-tick-width="onYTickWidthChange"
@cursor-guide="onCursorGuideChange"
@grid-lines="onGridLinesChange"
>
Expand Down Expand Up @@ -119,16 +117,6 @@ export default {
return undefined;
}
},
parentYTickWidth: {
type: Object,
default() {
return {
leftTickWidth: 0,
rightTickWidth: 0,
hasMultipleLeftAxes: false
};
}
},
hideLegend: {
type: Boolean,
default() {
Expand All @@ -142,7 +130,6 @@ export default {
'grid-lines',
'highlights',
'config-loaded',
'plot-y-tick-width',
'cursor-guide'
],
data() {
Expand Down Expand Up @@ -261,9 +248,6 @@ export default {
this.configReady = ready;
this.$emit('config-loaded', ...arguments);
},
onYTickWidthChange() {
this.$emit('plot-y-tick-width', ...arguments);
},
onCursorGuideChange() {
this.$emit('cursor-guide', ...arguments);
},
Expand Down
Loading
Loading