Type annotations (#4789)
* add some types to XAxisModel * some more type defs and small code tweaks while getting familiar with plots * more type annotations and a few small tweaks * more type annotations and small tweaks to make types show * add mocha types * Add karma and jasmine, too * further simplify plot canvas creation * further simplify plot canvas creation * update types, avoid runtime behavior in type definition that breaks SeriesCollection * undo the changes to MctChart, improve it later * lint fix Co-authored-by: unlikelyzero <jchill2@gmail.com> Co-authored-by: John Hill <john.c.hill@nasa.gov> Co-authored-by: Jamie V <jamie.j.vigliotta@nasa.gov>
This commit is contained in:
@@ -26,20 +26,30 @@ import SeriesCollection from "./SeriesCollection";
|
||||
import XAxisModel from "./XAxisModel";
|
||||
import YAxisModel from "./YAxisModel";
|
||||
import LegendModel from "./LegendModel";
|
||||
|
||||
/**
|
||||
* PlotConfiguration model stores the configuration of a plot and some
|
||||
* limited state. The indiidual parts of the plot configuration model
|
||||
* handle setting defaults and updating in response to various changes.
|
||||
*
|
||||
* @extends {Model<PlotConfigModelType, PlotConfigModelOptions>}
|
||||
*/
|
||||
export default class PlotConfigurationModel extends Model {
|
||||
/**
|
||||
* Initializes all sub models and then passes references to submodels
|
||||
* to those that need it.
|
||||
*
|
||||
* @override
|
||||
* @param {import('./Model').ModelOptions<PlotConfigModelType, PlotConfigModelOptions>} options
|
||||
*/
|
||||
initialize(options) {
|
||||
this.openmct = options.openmct;
|
||||
|
||||
// This is a type assertion for TypeScript, this error is never thrown in practice.
|
||||
if (!options.model) {
|
||||
throw new Error('Not a collection model.');
|
||||
}
|
||||
|
||||
this.xAxis = new XAxisModel({
|
||||
model: options.model.xAxis,
|
||||
plot: this,
|
||||
@@ -76,6 +86,8 @@ export default class PlotConfigurationModel extends Model {
|
||||
}
|
||||
/**
|
||||
* Retrieve the persisted series config for a given identifier.
|
||||
* @param {import('./PlotSeries').Identifier} identifier
|
||||
* @returns {import('./PlotSeries').PlotSeriesModelType=}
|
||||
*/
|
||||
getPersistedSeriesConfig(identifier) {
|
||||
const domainObject = this.get('domainObject');
|
||||
@@ -123,15 +135,48 @@ export default class PlotConfigurationModel extends Model {
|
||||
/**
|
||||
* Return defaults, which are extracted from the passed in domain
|
||||
* object.
|
||||
* @override
|
||||
* @param {import('./Model').ModelOptions<PlotConfigModelType, PlotConfigModelOptions>} options
|
||||
*/
|
||||
defaults(options) {
|
||||
defaultModel(options) {
|
||||
return {
|
||||
series: [],
|
||||
domainObject: options.domainObject,
|
||||
xAxis: {
|
||||
},
|
||||
yAxis: _.cloneDeep(_.get(options.domainObject, 'configuration.yAxis', {})),
|
||||
legend: _.cloneDeep(_.get(options.domainObject, 'configuration.legend', {}))
|
||||
xAxis: {},
|
||||
yAxis: _.cloneDeep(options.domainObject.configuration?.yAxis ?? {}),
|
||||
legend: _.cloneDeep(options.domainObject.configuration?.legend ?? {})
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/** @typedef {any} TODO */
|
||||
|
||||
/** @typedef {import('./PlotSeries').default} PlotSeries */
|
||||
|
||||
/**
|
||||
@typedef {{
|
||||
configuration: {
|
||||
series: import('./PlotSeries').PlotSeriesModelType[]
|
||||
}
|
||||
}} SomeDomainObject_NeedsName
|
||||
*/
|
||||
|
||||
/**
|
||||
@typedef {{
|
||||
xAxis: import('./XAxisModel').XAxisModelType
|
||||
yAxis: import('./YAxisModel').YAxisModelType
|
||||
legend: TODO
|
||||
series: PlotSeries[]
|
||||
domainObject: SomeDomainObject_NeedsName
|
||||
}} PlotConfigModelType
|
||||
*/
|
||||
|
||||
/** @typedef {TODO} SomeOtherDomainObject */
|
||||
|
||||
/**
|
||||
TODO: Is SomeOtherDomainObject the same domain object as with SomeDomainObject_NeedsName?
|
||||
@typedef {{
|
||||
plot: import('./PlotConfigurationModel').default
|
||||
domainObject: SomeOtherDomainObject
|
||||
}} PlotConfigModelOptions
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user