diff --git a/src/api/annotation/AnnotationAPI.js b/src/api/annotation/AnnotationAPI.js index 3ca5889b1b..f6da19d2b9 100644 --- a/src/api/annotation/AnnotationAPI.js +++ b/src/api/annotation/AnnotationAPI.js @@ -95,6 +95,7 @@ export default class AnnotationAPI extends EventEmitter { this.availableTags = {}; this.namespaceToSaveAnnotations = ''; this.#targetComparatorMap = new Map(); + this.annotatableTypes = []; this.ANNOTATION_TYPES = ANNOTATION_TYPES; this.ANNOTATION_TYPE = ANNOTATION_TYPE; @@ -115,6 +116,17 @@ export default class AnnotationAPI extends EventEmitter { domainObject.annotationType = domainObject.annotationType || 'plotspatial'; } }); + + this.openmct.on('start', () => { + const types = this.openmct.types.getTypes(); + const typeKeys = Object.keys(types); + + typeKeys.forEach((key) => { + if (types[key].definition.annotatable) { + this.annotatableTypes.push(key); + } + }); + }); } /** * Creates an annotation on a given domain object (e.g., a plot) and a set of targets (e.g., telemetry objects) @@ -582,4 +594,14 @@ export default class AnnotationAPI extends EventEmitter { _.isEqual(targets, otherTargets) ); } + + /** + * Checks if the given type is annotatable + * @param {string} type The type to check + * @returns {boolean} Returns true if the type is annotatable + */ + isAnnotatableType(type) { + console.log('type', type, this.annotatableTypes); + return this.annotatableTypes.some((annotatableType) => annotatableType === type); + } } diff --git a/src/api/types/TypeRegistry.js b/src/api/types/TypeRegistry.js index 1dac938fb4..4ed36a2f1a 100644 --- a/src/api/types/TypeRegistry.js +++ b/src/api/types/TypeRegistry.js @@ -94,7 +94,7 @@ export default class TypeRegistry { * @returns {Type[]} all registered types */ getTypes() { - return Object.values(this.types); + return this.types; } /** * Import legacy types. diff --git a/src/plugins/charts/scatter/plugin.js b/src/plugins/charts/scatter/plugin.js index 16198a250f..b8a74f5c61 100644 --- a/src/plugins/charts/scatter/plugin.js +++ b/src/plugins/charts/scatter/plugin.js @@ -40,6 +40,7 @@ export default function () { cssClass: 'icon-plot-scatter', description: 'View data as a scatter plot.', creatable: true, + annotatable: true, initialize: function (domainObject) { domainObject.composition = []; domainObject.configuration = { diff --git a/src/plugins/gauge/GaugeCompositionPolicy.js b/src/plugins/gauge/GaugeCompositionPolicy.js index d334c4f62c..070cdc1dea 100644 --- a/src/plugins/gauge/GaugeCompositionPolicy.js +++ b/src/plugins/gauge/GaugeCompositionPolicy.js @@ -21,28 +21,10 @@ *****************************************************************************/ export default function GaugeCompositionPolicy(openmct) { - function hasNumericTelemetry(domainObject) { - const hasTelemetry = openmct.telemetry.isTelemetryObject(domainObject); - if (!hasTelemetry) { - return false; - } - - const metadata = openmct.telemetry.getMetadata(domainObject); - - return metadata.values().length > 0 && hasDomainAndRange(metadata); - } - - function hasDomainAndRange(metadata) { - return ( - metadata.valuesForHints(['range']).length > 0 && - metadata.valuesForHints(['domain']).length > 0 - ); - } - return { allow: function (parent, child) { if (parent.type === 'gauge') { - return hasNumericTelemetry(child); + return openmct.telemetry.hasNumericTelemetry(child); } return true; diff --git a/src/plugins/inspectorViews/annotations/AnnotationsViewProvider.js b/src/plugins/inspectorViews/annotations/AnnotationsViewProvider.js index bfc477d7c7..970f3ee79a 100644 --- a/src/plugins/inspectorViews/annotations/AnnotationsViewProvider.js +++ b/src/plugins/inspectorViews/annotations/AnnotationsViewProvider.js @@ -63,6 +63,14 @@ export default function AnnotationsViewProvider(openmct) { ); _destroy = destroy; }, + showTab: function () { + const isAnnotatableType = openmct.annotation.isAnnotatableType(domainObject.type); + const metadata = openmct.telemetry.getMetadata(domainObject); + const hasImagery = metadata?.valuesForHints(['image']).length > 0; + const hasNumericTelemetry = openmct.telemetry.hasNumericTelemetry(domainObject); + + return isAnnotatableType || hasImagery || hasNumericTelemetry; + }, priority: function () { return openmct.priority.DEFAULT; }, diff --git a/src/plugins/plot/PlotViewProvider.js b/src/plugins/plot/PlotViewProvider.js index 7645a1881e..425e495aa9 100644 --- a/src/plugins/plot/PlotViewProvider.js +++ b/src/plugins/plot/PlotViewProvider.js @@ -25,27 +25,6 @@ import mount from 'utils/mount'; import Plot from './PlotView.vue'; export default function PlotViewProvider(openmct) { - function hasNumericTelemetry(domainObject) { - if (!Object.prototype.hasOwnProperty.call(domainObject, 'telemetry')) { - return false; - } - - let metadata = openmct.telemetry.getMetadata(domainObject); - - return metadata.values().length > 0 && hasDomainAndNumericRange(metadata); - } - - function hasDomainAndNumericRange(metadata) { - const rangeValues = metadata.valuesForHints(['range']); - const domains = metadata.valuesForHints(['domain']); - - return ( - domains.length > 0 && - rangeValues.length > 0 && - !rangeValues.every((value) => value.format === 'string') - ); - } - function isCompactView(objectPath) { let isChildOfTimeStrip = objectPath.find((object) => object.type === 'time-strip'); @@ -57,7 +36,7 @@ export default function PlotViewProvider(openmct) { name: 'Plot', cssClass: 'icon-telemetry', canView(domainObject, objectPath) { - return hasNumericTelemetry(domainObject); + return openmct.telemetry.hasNumericTelemetry(domainObject); }, view: function (domainObject, objectPath) { diff --git a/src/plugins/plot/overlayPlot/OverlayPlotCompositionPolicy.js b/src/plugins/plot/overlayPlot/OverlayPlotCompositionPolicy.js index ca5185e8b0..6178caebee 100644 --- a/src/plugins/plot/overlayPlot/OverlayPlotCompositionPolicy.js +++ b/src/plugins/plot/overlayPlot/OverlayPlotCompositionPolicy.js @@ -1,25 +1,10 @@ export default function OverlayPlotCompositionPolicy(openmct) { - function hasNumericTelemetry(domainObject) { - const hasTelemetry = openmct.telemetry.isTelemetryObject(domainObject); - if (!hasTelemetry) { - return false; - } - - let metadata = openmct.telemetry.getMetadata(domainObject); - - return metadata.values().length > 0 && hasDomainAndRange(metadata); - } - - function hasDomainAndRange(metadata) { - return ( - metadata.valuesForHints(['range']).length > 0 && - metadata.valuesForHints(['domain']).length > 0 - ); - } - return { allow: function (parent, child) { - if (parent.type === 'telemetry.plot.overlay' && hasNumericTelemetry(child) === false) { + if ( + parent.type === 'telemetry.plot.overlay' && + !openmct.telemetry.hasNumericTelemetry(child) + ) { return false; } diff --git a/src/plugins/timeline/TimelineCompositionPolicy.js b/src/plugins/timeline/TimelineCompositionPolicy.js index 150f46217a..c03b21467c 100644 --- a/src/plugins/timeline/TimelineCompositionPolicy.js +++ b/src/plugins/timeline/TimelineCompositionPolicy.js @@ -23,22 +23,6 @@ const ALLOWED_TYPES = ['telemetry.plot.overlay', 'telemetry.plot.stacked', 'plan', 'gantt-chart']; const DISALLOWED_TYPES = ['telemetry.plot.bar-graph', 'telemetry.plot.scatter-plot']; export default function TimelineCompositionPolicy(openmct) { - function hasNumericTelemetry(domainObject, metadata) { - const hasTelemetry = openmct.telemetry.isTelemetryObject(domainObject); - if (!hasTelemetry || !metadata) { - return false; - } - - return metadata.values().length > 0 && hasDomainAndRange(metadata); - } - - function hasDomainAndRange(metadata) { - return ( - metadata.valuesForHints(['range']).length > 0 && - metadata.valuesForHints(['domain']).length > 0 - ); - } - function hasImageTelemetry(domainObject, metadata) { if (!metadata) { return false; @@ -54,7 +38,7 @@ export default function TimelineCompositionPolicy(openmct) { if ( !DISALLOWED_TYPES.includes(child.type) && - (hasNumericTelemetry(child, metadata) || + (openmct.telemetry.hasNumericTelemetry(child) || hasImageTelemetry(child, metadata) || ALLOWED_TYPES.includes(child.type)) ) {