diff --git a/v3/src/components/data-display/models/data-configuration-model.ts b/v3/src/components/data-display/models/data-configuration-model.ts index fc939e4f79..7878483bc5 100644 --- a/v3/src/components/data-display/models/data-configuration-model.ts +++ b/v3/src/components/data-display/models/data-configuration-model.ts @@ -25,7 +25,7 @@ import {getQuantileScale, missingColor, parseColor} from "../../../utilities/col import { numericSortComparator } from "../../../utilities/data-utils" import {GraphPlace} from "../../axis-graph-shared" import {CaseData} from "../d3-types" -import {AttrRole, TipAttrRoles, graphPlaceToAttrRole} from "../data-display-types" +import {AttrRole, GraphAttrRole, TipAttrRoles, graphPlaceToAttrRole} from "../data-display-types" export const AttributeDescription = types .model('AttributeDescription', { @@ -43,6 +43,8 @@ export type RoleAttrIDPair = { role: AttrRole, attributeID: string } export interface IAttributeDescriptionSnapshot extends SnapshotIn { } + +export type GraphAttributeDescriptionsMapSnapshot = Partial> export type AttributeDescriptionsMapSnapshot = Partial> export const kUnknownDataConfigurationType = "unknownDataConfigurationType" diff --git a/v3/src/components/graph/adornments/adornment-models.ts b/v3/src/components/graph/adornments/adornment-models.ts index c70aa0b735..ee94abbce9 100644 --- a/v3/src/components/graph/adornments/adornment-models.ts +++ b/v3/src/components/graph/adornments/adornment-models.ts @@ -2,7 +2,7 @@ Adornment models are strictly MST. They keep track of the user modifications of the defaults. */ -import {Instance, types} from "mobx-state-tree" +import {Instance, SnapshotIn, types} from "mobx-state-tree" import { IAxisModel } from "../../axis/models/axis-model" import {safeDomIdentifier, typedId} from "../../../utilities/js-utils" import {Point} from "../../data-display/data-display-types" @@ -27,6 +27,8 @@ export const PointModel = types.model("Point", { } } })) +export interface IPointModelSnapshot extends SnapshotIn {} + export const kInfinitePoint = {x:NaN, y:NaN} export interface IUpdateCategoriesOptions { diff --git a/v3/src/components/graph/adornments/adornment-types.ts b/v3/src/components/graph/adornments/adornment-types.ts index e600673f0c..11511e8a92 100644 --- a/v3/src/components/graph/adornments/adornment-types.ts +++ b/v3/src/components/graph/adornments/adornment-types.ts @@ -12,7 +12,8 @@ import { IStandardDeviationAdornmentModel, StandardDeviationAdornmentModel } from "./univariate-measures/standard-deviation/standard-deviation-adornment-model" import { IStandardErrorAdornmentModel, StandardErrorAdornmentModel } from "./univariate-measures/standard-error/standard-error-adornment-model" -import { NormalCurveAdornmentModel } from "./univariate-measures/normal-curve/normal-curve-adornment-model" +import { INormalCurveAdornmentModel, NormalCurveAdornmentModel } + from "./univariate-measures/normal-curve/normal-curve-adornment-model" import { IMeanAbsoluteDeviationAdornmentModel, MeanAbsoluteDeviationAdornmentModel } from "./univariate-measures/mean-absolute-deviation/mean-absolute-deviation-adornment-model" import { BoxPlotAdornmentModel, IBoxPlotAdornmentModel } from "./univariate-measures/box-plot/box-plot-adornment-model" @@ -52,8 +53,9 @@ export const AdornmentModelUnion = types.union({ dispatcher: adornmentTypeDispat StandardDeviationAdornmentModel, StandardErrorAdornmentModel, UnknownAdornmentModel) export type IAdornmentModelUnion = IBoxPlotAdornmentModel | ICountAdornmentModel | ILSRLAdornmentModel | IMeanAdornmentModel | IMeanAbsoluteDeviationAdornmentModel | IMedianAdornmentModel | IMovableValueAdornmentModel | - IMovableLineAdornmentModel | IMovablePointAdornmentModel | IPlottedFunctionAdornmentModel | - IPlottedValueAdornmentModel | IStandardDeviationAdornmentModel | IStandardErrorAdornmentModel | IUnknownAdornmentModel + IMovableLineAdornmentModel | IMovablePointAdornmentModel | INormalCurveAdornmentModel | + IPlottedFunctionAdornmentModel | IPlottedValueAdornmentModel | + IStandardDeviationAdornmentModel | IStandardErrorAdornmentModel | IUnknownAdornmentModel export const ParentAdornmentTypes = ["Univariate Measure"] as const export type ParentAdornmentType = typeof ParentAdornmentTypes[number] diff --git a/v3/src/components/graph/adornments/adornment-utils.ts b/v3/src/components/graph/adornments/adornment-utils.ts index 6bfc58980b..d19b13fff8 100644 --- a/v3/src/components/graph/adornments/adornment-utils.ts +++ b/v3/src/components/graph/adornments/adornment-utils.ts @@ -7,9 +7,9 @@ export function getAxisDomains(xAxis?: IBaseNumericAxisModel, yAxis?: IBaseNumer return { xDomain, yDomain } } -export const updateCellKey = (cellKey: Record, attrId: string, cat: string) => { +export const updateCellKey = (cellKey: Record, attrId: string | undefined, cat: string) => { const newCellKey = { ...cellKey } - if (cat) { + if (attrId && cat) { const propertyAlreadyPresent = Object.prototype.hasOwnProperty.call(newCellKey, attrId) if (propertyAlreadyPresent && newCellKey[attrId] !== cat) { // When the same attribute appears on multiple axes or splits, we avoid overwriting the existing key's diff --git a/v3/src/components/graph/adornments/count/count-adornment-model.ts b/v3/src/components/graph/adornments/count/count-adornment-model.ts index c2b48ec96b..688cc9c2fe 100644 --- a/v3/src/components/graph/adornments/count/count-adornment-model.ts +++ b/v3/src/components/graph/adornments/count/count-adornment-model.ts @@ -1,4 +1,4 @@ -import { Instance, types } from "mobx-state-tree" +import { Instance, SnapshotIn, types } from "mobx-state-tree" import { AdornmentModel, IAdornmentModel } from "../adornment-models" import { kCountType } from "./count-adornment-types" import {IGraphDataConfigurationModel} from "../../models/graph-data-configuration-model" @@ -63,7 +63,7 @@ export const CountAdornmentModel = AdornmentModel } else { scaleCopy.range([plotHeight, 0]) } - + for (let i = 0; i < subPlotRegionBoundaries.length - 1; i++) { const lowerBoundary = subPlotRegionBoundaries[i] const upperBoundary = subPlotRegionBoundaries[i + 1] @@ -79,7 +79,7 @@ export const CountAdornmentModel = AdornmentModel prevHeight += height counts.push({ bottomOffset, height, leftOffset, count, width }) } - + return counts } })) @@ -97,6 +97,7 @@ export const CountAdornmentModel = AdornmentModel } })) +export interface ICountAdornmentModelSnapshot extends SnapshotIn {} export interface ICountAdornmentModel extends Instance {} export function isCountAdornment(adornment: IAdornmentModel): adornment is ICountAdornmentModel { return adornment.type === kCountType diff --git a/v3/src/components/graph/adornments/lsrl/lsrl-adornment-model.ts b/v3/src/components/graph/adornments/lsrl/lsrl-adornment-model.ts index 9f8667fa49..018f811c45 100644 --- a/v3/src/components/graph/adornments/lsrl/lsrl-adornment-model.ts +++ b/v3/src/components/graph/adornments/lsrl/lsrl-adornment-model.ts @@ -1,4 +1,4 @@ -import { Instance, types } from "mobx-state-tree" +import { Instance, SnapshotIn, types } from "mobx-state-tree" import { Point } from "../../../data-display/data-display-types" import { dataDisplayGetNumericValue } from "../../../data-display/data-display-value-utils" import { AdornmentModel, IAdornmentModel, IUpdateCategoriesOptions, PointModel } from "../adornment-models" @@ -62,6 +62,7 @@ export const LSRLInstance = types.model("LSRLInstance", { } })) + export const LSRLAdornmentModel = AdornmentModel .named("LSRLAdornmentModel") .props({ @@ -224,7 +225,9 @@ export const LSRLAdornmentModel = AdornmentModel } })) +export interface ILSRLInstanceSnapshot extends SnapshotIn {} export interface ILSRLInstance extends Instance {} +export interface ILSRLAdornmentModelSnapshot extends SnapshotIn {} export interface ILSRLAdornmentModel extends Instance {} export function isLSRLAdornment(adornment: IAdornmentModel): adornment is ILSRLAdornmentModel { return adornment.type === kLSRLType diff --git a/v3/src/components/graph/adornments/movable-line/movable-line-adornment-model.ts b/v3/src/components/graph/adornments/movable-line/movable-line-adornment-model.ts index 175797fc15..eb1df3c328 100644 --- a/v3/src/components/graph/adornments/movable-line/movable-line-adornment-model.ts +++ b/v3/src/components/graph/adornments/movable-line/movable-line-adornment-model.ts @@ -1,4 +1,4 @@ -import { Instance, types } from "mobx-state-tree" +import { Instance, SnapshotIn, types } from "mobx-state-tree" import { Point } from "../../../data-display/data-display-types" import { AdornmentModel, IAdornmentModel, IUpdateCategoriesOptions, PointModel, kInfinitePoint } from "../adornment-models" @@ -94,7 +94,9 @@ export const MovableLineAdornmentModel = AdornmentModel } })) +export interface IMovableLineInstanceSnapshot extends SnapshotIn {} export interface IMovableLineInstance extends Instance {} +export interface IMovableLineAdornmentModelSnapshot extends SnapshotIn {} export interface IMovableLineAdornmentModel extends Instance {} export function isMovableLineAdornment(adornment: IAdornmentModel): adornment is IMovableLineAdornmentModel { return adornment.type === kMovableLineType diff --git a/v3/src/components/graph/adornments/movable-point/movable-point-adornment-model.ts b/v3/src/components/graph/adornments/movable-point/movable-point-adornment-model.ts index a553cc280c..9e948d86cc 100644 --- a/v3/src/components/graph/adornments/movable-point/movable-point-adornment-model.ts +++ b/v3/src/components/graph/adornments/movable-point/movable-point-adornment-model.ts @@ -1,4 +1,4 @@ -import { Instance, types } from "mobx-state-tree" +import { Instance, SnapshotIn, types } from "mobx-state-tree" import { Point } from "../../../data-display/data-display-types" import { AdornmentModel, IAdornmentModel, IUpdateCategoriesOptions, PointModel } from "../adornment-models" import { IAxisModel, isNumericAxisModel } from "../../../axis/models/axis-model" @@ -39,6 +39,7 @@ export const MovablePointAdornmentModel = AdornmentModel }) } })) +export interface IMovablePointAdornmentModelSnapshot extends SnapshotIn {} export interface IMovablePointAdornmentModel extends Instance {} export function isMovablePointAdornment(adornment: IAdornmentModel): adornment is IMovablePointAdornmentModel { return adornment.type === kMovablePointType diff --git a/v3/src/components/graph/adornments/movable-value/movable-value-adornment-model.ts b/v3/src/components/graph/adornments/movable-value/movable-value-adornment-model.ts index 8e5dae1274..6d0b6934ac 100644 --- a/v3/src/components/graph/adornments/movable-value/movable-value-adornment-model.ts +++ b/v3/src/components/graph/adornments/movable-value/movable-value-adornment-model.ts @@ -1,4 +1,4 @@ -import { Instance, types } from "mobx-state-tree" +import { Instance, SnapshotIn, types } from "mobx-state-tree" import { AdornmentModel, IAdornmentModel, IUpdateCategoriesOptions } from "../adornment-models" import { kMovableValueType } from "./movable-value-adornment-types" import { IBaseNumericAxisModel } from "../../../axis/models/axis-model" @@ -140,6 +140,7 @@ export const MovableValueAdornmentModel = AdornmentModel } })) +export interface IMovableValueAdornmentModelSnapshot extends SnapshotIn {} export interface IMovableValueAdornmentModel extends Instance {} export function isMovableValueAdornment(adornment: IAdornmentModel): adornment is IMovableValueAdornmentModel { return adornment.type === kMovableValueType diff --git a/v3/src/components/graph/adornments/plotted-function/plotted-function-adornment-model.ts b/v3/src/components/graph/adornments/plotted-function/plotted-function-adornment-model.ts index a67da0baeb..203dd12646 100644 --- a/v3/src/components/graph/adornments/plotted-function/plotted-function-adornment-model.ts +++ b/v3/src/components/graph/adornments/plotted-function/plotted-function-adornment-model.ts @@ -1,4 +1,4 @@ -import { Instance, types } from "mobx-state-tree" +import { Instance, SnapshotIn, types } from "mobx-state-tree" import { AdornmentModel, IAdornmentModel } from "../adornment-models" import { kPlottedFunctionType, kPlottedFunctionValueTitleKey, FormulaFn } from "./plotted-function-adornment-types" import { Formula } from "../../../../models/formula/formula" @@ -50,6 +50,7 @@ export const PlottedFunctionAdornmentModel = AdornmentModel } })) +export interface IPlottedFunctionAdornmentModelSnapshot extends SnapshotIn {} export interface IPlottedFunctionAdornmentModel extends Instance {} export function isPlottedFunctionAdornment(adornment: IAdornmentModel): adornment is IPlottedFunctionAdornmentModel { return adornment.type === kPlottedFunctionType diff --git a/v3/src/components/graph/adornments/univariate-measures/box-plot/box-plot-adornment-model.ts b/v3/src/components/graph/adornments/univariate-measures/box-plot/box-plot-adornment-model.ts index 3a03f0da93..e7a7da47ed 100644 --- a/v3/src/components/graph/adornments/univariate-measures/box-plot/box-plot-adornment-model.ts +++ b/v3/src/components/graph/adornments/univariate-measures/box-plot/box-plot-adornment-model.ts @@ -1,4 +1,4 @@ -import { Instance, types } from "mobx-state-tree" +import { Instance, SnapshotIn, types } from "mobx-state-tree" import { median } from "mathjs" import { quantileOfSortedArray } from "../../../../../utilities/math-utils" import { UnivariateMeasureAdornmentModel } from "../univariate-measure-adornment-model" @@ -114,6 +114,7 @@ export const BoxPlotAdornmentModel = UnivariateMeasureAdornmentModel } })) +export interface IBoxPlotAdornmentModelSnapshot extends SnapshotIn {} export interface IBoxPlotAdornmentModel extends Instance {} export function isBoxPlotAdornment(adornment: IAdornmentModel): adornment is IBoxPlotAdornmentModel { return adornment.type === kBoxPlotType diff --git a/v3/src/components/graph/adornments/univariate-measures/mean-absolute-deviation/mean-absolute-deviation-adornment-model.ts b/v3/src/components/graph/adornments/univariate-measures/mean-absolute-deviation/mean-absolute-deviation-adornment-model.ts index d37ed2955a..255840a4da 100644 --- a/v3/src/components/graph/adornments/univariate-measures/mean-absolute-deviation/mean-absolute-deviation-adornment-model.ts +++ b/v3/src/components/graph/adornments/univariate-measures/mean-absolute-deviation/mean-absolute-deviation-adornment-model.ts @@ -1,4 +1,4 @@ -import { Instance, types } from "mobx-state-tree" +import { Instance, SnapshotIn, types } from "mobx-state-tree" import { mean } from "mathjs" import {IGraphDataConfigurationModel} from "../../../models/graph-data-configuration-model" import { @@ -34,6 +34,8 @@ export const MeanAbsoluteDeviationAdornmentModel = UnivariateMeasureAdornmentMod } })) +export interface IMeanAbsoluteDeviationAdornmentModelSnapshot + extends SnapshotIn {} export interface IMeanAbsoluteDeviationAdornmentModel extends Instance {} export function isMeanAbsoluteDeviationAdornment(adornment: IUnivariateMeasureAdornmentModel): adornment is IMeanAbsoluteDeviationAdornmentModel { diff --git a/v3/src/components/graph/adornments/univariate-measures/mean/mean-adornment-model.ts b/v3/src/components/graph/adornments/univariate-measures/mean/mean-adornment-model.ts index b8f0399385..1112a3cfb7 100644 --- a/v3/src/components/graph/adornments/univariate-measures/mean/mean-adornment-model.ts +++ b/v3/src/components/graph/adornments/univariate-measures/mean/mean-adornment-model.ts @@ -1,4 +1,4 @@ -import { Instance, types } from "mobx-state-tree" +import { Instance, SnapshotIn, types } from "mobx-state-tree" import { mean } from "mathjs" import { UnivariateMeasureAdornmentModel } from "../univariate-measure-adornment-model" import { kMeanType, kMeanValueTitleKey } from "./mean-adornment-types" @@ -19,6 +19,7 @@ export const MeanAdornmentModel = UnivariateMeasureAdornmentModel } })) +export interface IMeanAdornmentModelSnapshot extends SnapshotIn {} export interface IMeanAdornmentModel extends Instance {} export function isMeanAdornment(adornment: IAdornmentModel): adornment is IMeanAdornmentModel { return adornment.type === kMeanType diff --git a/v3/src/components/graph/adornments/univariate-measures/median/median-adornment-model.ts b/v3/src/components/graph/adornments/univariate-measures/median/median-adornment-model.ts index 0f7decfe87..c09ff33e74 100644 --- a/v3/src/components/graph/adornments/univariate-measures/median/median-adornment-model.ts +++ b/v3/src/components/graph/adornments/univariate-measures/median/median-adornment-model.ts @@ -1,4 +1,4 @@ -import { Instance, types } from "mobx-state-tree" +import { Instance, SnapshotIn, types } from "mobx-state-tree" import { median } from "mathjs" import {IGraphDataConfigurationModel} from "../../../models/graph-data-configuration-model" import { UnivariateMeasureAdornmentModel } from "../univariate-measure-adornment-model" @@ -19,6 +19,7 @@ export const MedianAdornmentModel = UnivariateMeasureAdornmentModel } })) +export interface IMedianAdornmentModelSnapshot extends SnapshotIn {} export interface IMedianAdornmentModel extends Instance {} export function isMedianAdornment(adornment: IAdornmentModel): adornment is IMedianAdornmentModel { return adornment.type === kMedianType diff --git a/v3/src/components/graph/adornments/univariate-measures/normal-curve/normal-curve-adornment-model.ts b/v3/src/components/graph/adornments/univariate-measures/normal-curve/normal-curve-adornment-model.ts index 2b4d094476..43d0c6ee49 100644 --- a/v3/src/components/graph/adornments/univariate-measures/normal-curve/normal-curve-adornment-model.ts +++ b/v3/src/components/graph/adornments/univariate-measures/normal-curve/normal-curve-adornment-model.ts @@ -1,4 +1,4 @@ -import { Instance, types } from "mobx-state-tree" +import { Instance, SnapshotIn, types } from "mobx-state-tree" import { mean, std } from "mathjs" import {IGraphDataConfigurationModel} from "../../../models/graph-data-configuration-model" import { UnivariateMeasureAdornmentModel, IUnivariateMeasureAdornmentModel } @@ -70,6 +70,7 @@ export const NormalCurveAdornmentModel = UnivariateMeasureAdornmentModel }, })) +export interface INormalCurveAdornmentModelSnapshot extends SnapshotIn {} export interface INormalCurveAdornmentModel extends Instance {} export function isNormalCurveAdornment(adornment: IUnivariateMeasureAdornmentModel): adornment is INormalCurveAdornmentModel { diff --git a/v3/src/components/graph/adornments/univariate-measures/plotted-value/plotted-value-adornment-model.ts b/v3/src/components/graph/adornments/univariate-measures/plotted-value/plotted-value-adornment-model.ts index 1beda18341..ce591d8323 100644 --- a/v3/src/components/graph/adornments/univariate-measures/plotted-value/plotted-value-adornment-model.ts +++ b/v3/src/components/graph/adornments/univariate-measures/plotted-value/plotted-value-adornment-model.ts @@ -1,4 +1,4 @@ -import { Instance, types } from "mobx-state-tree" +import { Instance, SnapshotIn, types } from "mobx-state-tree" import { IAdornmentModel } from "../../adornment-models" import { kPlottedValueType, kPlottedValueValueTitleKey } from "./plotted-value-adornment-types" import { UnivariateMeasureAdornmentModel } from "../univariate-measure-adornment-model" @@ -32,6 +32,7 @@ export const PlottedValueAdornmentModel = UnivariateMeasureAdornmentModel } })) +export interface IPlottedValueAdornmentModelSnapshot extends SnapshotIn {} export interface IPlottedValueAdornmentModel extends Instance {} export function isPlottedValueAdornment(adornment: IAdornmentModel): adornment is IPlottedValueAdornmentModel { return adornment.type === kPlottedValueType diff --git a/v3/src/components/graph/adornments/univariate-measures/standard-deviation/standard-deviation-adornment-model.ts b/v3/src/components/graph/adornments/univariate-measures/standard-deviation/standard-deviation-adornment-model.ts index 17b936ddce..c497f9b95a 100644 --- a/v3/src/components/graph/adornments/univariate-measures/standard-deviation/standard-deviation-adornment-model.ts +++ b/v3/src/components/graph/adornments/univariate-measures/standard-deviation/standard-deviation-adornment-model.ts @@ -1,4 +1,4 @@ -import { Instance, types } from "mobx-state-tree" +import { Instance, SnapshotIn, types } from "mobx-state-tree" import { mean, std } from "mathjs" import {IGraphDataConfigurationModel} from "../../../models/graph-data-configuration-model" import { @@ -36,6 +36,7 @@ export const StandardDeviationAdornmentModel = UnivariateMeasureAdornmentModel } })) +export interface IStandardDeviationAdornmentModelSnapshot extends SnapshotIn {} export interface IStandardDeviationAdornmentModel extends Instance {} export function isStandardDeviationAdornment(adornment: IUnivariateMeasureAdornmentModel): adornment is IStandardDeviationAdornmentModel { diff --git a/v3/src/components/graph/adornments/univariate-measures/standard-error/standard-error-adornment-model.ts b/v3/src/components/graph/adornments/univariate-measures/standard-error/standard-error-adornment-model.ts index f3f1dbd17f..b8de15744e 100644 --- a/v3/src/components/graph/adornments/univariate-measures/standard-error/standard-error-adornment-model.ts +++ b/v3/src/components/graph/adornments/univariate-measures/standard-error/standard-error-adornment-model.ts @@ -1,4 +1,4 @@ -import { Instance, types } from "mobx-state-tree" +import { Instance, SnapshotIn, types } from "mobx-state-tree" import { mean, std } from "mathjs" import {IGraphDataConfigurationModel} from "../../../models/graph-data-configuration-model" import { IAdornmentModel } from "../../adornment-models" @@ -56,6 +56,7 @@ export const StandardErrorAdornmentModel = UnivariateMeasureAdornmentModel } })) +export interface IStandardErrorAdornmentModelSnapshot extends SnapshotIn {} export interface IStandardErrorAdornmentModel extends Instance {} export function isStandardErrorAdornment(adornment: IAdornmentModel | undefined): adornment is IStandardErrorAdornmentModel { diff --git a/v3/src/components/graph/adornments/univariate-measures/univariate-measure-adornment-model.ts b/v3/src/components/graph/adornments/univariate-measures/univariate-measure-adornment-model.ts index 7f111ae98d..99ca7a1609 100644 --- a/v3/src/components/graph/adornments/univariate-measures/univariate-measure-adornment-model.ts +++ b/v3/src/components/graph/adornments/univariate-measures/univariate-measure-adornment-model.ts @@ -1,4 +1,4 @@ -import { Instance, types } from "mobx-state-tree" +import { Instance, SnapshotIn, types } from "mobx-state-tree" import { Point } from "../../../data-display/data-display-types" import { AdornmentModel, IAdornmentModel, IUpdateCategoriesOptions, PointModel } from "../adornment-models" import { IDataConfigurationModel } from "../../../data-display/models/data-configuration-model" @@ -126,6 +126,7 @@ export const UnivariateMeasureAdornmentModel = AdornmentModel } })) +export interface IMeasureInstanceSnapshot extends SnapshotIn {} export interface IMeasureInstance extends Instance {} export interface IUnivariateMeasureAdornmentModel extends Instance {} export function isUnivariateMeasureAdornment(adornment: IAdornmentModel): diff --git a/v3/src/components/graph/adornments/v2-adornment-importer.test.ts b/v3/src/components/graph/adornments/v2-adornment-importer.test.ts index 090a7412a6..2d1afa07d8 100644 --- a/v3/src/components/graph/adornments/v2-adornment-importer.test.ts +++ b/v3/src/components/graph/adornments/v2-adornment-importer.test.ts @@ -2,19 +2,18 @@ import { CodapV2Document } from "../../../v2/codap-v2-document" import { ICodapV2DocumentJson, ICodapV2GraphStorage } from "../../../v2/codap-v2-types" import { v2AdornmentImporter } from "./v2-adornment-importer" import { ICountAdornmentModel } from "./count/count-adornment-model" -import { IMeanAdornmentModel } from "./univariate-measures/mean/mean-adornment-model" -import { IMedianAdornmentModel } from "./univariate-measures/median/median-adornment-model" -import { IStandardDeviationAdornmentModel } +import { IMeanAdornmentModelSnapshot } from "./univariate-measures/mean/mean-adornment-model" +import { IMedianAdornmentModelSnapshot } from "./univariate-measures/median/median-adornment-model" +import { IStandardDeviationAdornmentModelSnapshot } from "./univariate-measures/standard-deviation/standard-deviation-adornment-model" -import { IMeanAbsoluteDeviationAdornmentModel } +import { IMeanAbsoluteDeviationAdornmentModelSnapshot } from "./univariate-measures/mean-absolute-deviation/mean-absolute-deviation-adornment-model" -import { IBoxPlotAdornmentModel } from "./univariate-measures/box-plot/box-plot-adornment-model" -import { IPlottedValueAdornmentModel } from "./univariate-measures/plotted-value/plotted-value-adornment-model" -import { IMovableValueAdornmentModel } from "./movable-value/movable-value-adornment-model" -import { IMovablePointAdornmentModel } from "./movable-point/movable-point-adornment-model" -import { IMovableLineAdornmentModel } from "./movable-line/movable-line-adornment-model" -import { ILSRLAdornmentModel } from "./lsrl/lsrl-adornment-model" -import { IPlottedFunctionAdornmentModel } from "./plotted-function/plotted-function-adornment-model" +import { IBoxPlotAdornmentModelSnapshot } from "./univariate-measures/box-plot/box-plot-adornment-model" +import { IPlottedValueAdornmentModelSnapshot } from "./univariate-measures/plotted-value/plotted-value-adornment-model" +import { IMovableValueAdornmentModelSnapshot } from "./movable-value/movable-value-adornment-model" +import { IMovablePointAdornmentModelSnapshot } from "./movable-point/movable-point-adornment-model" +import { ILSRLAdornmentModelSnapshot } from "./lsrl/lsrl-adornment-model" +import { IPlottedFunctionAdornmentModelSnapshot } from "./plotted-function/plotted-function-adornment-model" const fs = require("fs") const path = require("path") @@ -88,26 +87,27 @@ describe("V2AdornmentImporter", () => { }) expect(adornmentStore).toBeDefined() expect(adornmentStore.showMeasureLabels).toBe(true) - expect(adornmentStore.adornments.length).toBe(10) - const meanAdornment = adornmentStore.adornments.find(a=> a.type === "Mean") as IMeanAdornmentModel + expect(adornmentStore.adornments.length).toBe(9) + const meanAdornment = adornmentStore.adornments.find(a=> a.type === "Mean") as IMeanAdornmentModelSnapshot expect(meanAdornment).toBeDefined() expect(meanAdornment.id).toBeDefined() expect(meanAdornment.isVisible).toBe(true) - const medianAdornment = adornmentStore.adornments.find(a => a.type === "Median") as IMedianAdornmentModel + const medianAdornment = adornmentStore.adornments.find(a => a.type === "Median") as IMedianAdornmentModelSnapshot expect(medianAdornment).toBeDefined() expect(medianAdornment.id).toBeDefined() expect(medianAdornment.isVisible).toBe(true) const stDevAdornment = - adornmentStore.adornments.find(a => a.type === "Standard Deviation") as IStandardDeviationAdornmentModel + adornmentStore.adornments.find(a => a.type === "Standard Deviation") as IStandardDeviationAdornmentModelSnapshot expect(stDevAdornment).toBeDefined() expect(stDevAdornment.id).toBeDefined() expect(stDevAdornment.isVisible).toBe(true) - const madAdornment = - adornmentStore.adornments.find(a => a.type === "Mean Absolute Deviation") as IMeanAbsoluteDeviationAdornmentModel + const madAdornment = adornmentStore.adornments + .find(a => a.type === "Mean Absolute Deviation") as IMeanAbsoluteDeviationAdornmentModelSnapshot expect(madAdornment).toBeDefined() expect(madAdornment?.id).toBeDefined() expect(madAdornment?.isVisible).toBe(true) - const boxPlotAdornment = adornmentStore.adornments.find(a => a.type === "Box Plot") as IBoxPlotAdornmentModel + const boxPlotAdornment = adornmentStore.adornments + .find(a => a.type === "Box Plot") as IBoxPlotAdornmentModelSnapshot expect(boxPlotAdornment).toBeDefined() expect(boxPlotAdornment.id).toBeDefined() expect(boxPlotAdornment.isVisible).toBe(true) @@ -124,13 +124,13 @@ describe("V2AdornmentImporter", () => { expect(adornmentStore).toBeDefined() expect(adornmentStore.adornments.length).toBe(3) const plottedValuesAdornment = - adornmentStore.adornments.find(a => a.type === "Plotted Value") as IPlottedValueAdornmentModel + adornmentStore.adornments.find(a => a.type === "Plotted Value") as IPlottedValueAdornmentModelSnapshot expect(plottedValuesAdornment).toBeDefined() expect(plottedValuesAdornment.id).toBeDefined() expect(plottedValuesAdornment.isVisible).toBe(true) - expect(plottedValuesAdornment.formula.display).toBe("60") + expect(plottedValuesAdornment.formula?.display).toBe("60") const movableValuesAdornment = - adornmentStore.adornments.find(a => a.type === "Movable Value") as IMovableValueAdornmentModel + adornmentStore.adornments.find(a => a.type === "Movable Value") as IMovableValueAdornmentModelSnapshot expect(movableValuesAdornment).toBeDefined() expect(movableValuesAdornment.id).toBeDefined() expect(movableValuesAdornment.isVisible).toBe(true) @@ -147,16 +147,16 @@ describe("V2AdornmentImporter", () => { expect(adornmentStore.interceptLocked).toBe(true) expect(adornmentStore.adornments.length).toBe(4) const movablePointAdornment = - adornmentStore.adornments.find(a => a.type === "Movable Point") as IMovablePointAdornmentModel + adornmentStore.adornments.find(a => a.type === "Movable Point") as IMovablePointAdornmentModelSnapshot expect(movablePointAdornment).toBeDefined() expect(movablePointAdornment.id).toBeDefined() expect(movablePointAdornment.isVisible).toBe(true) const movableLineAdornment = - adornmentStore.adornments.find(a => a.type === "Movable Line") as IMovableLineAdornmentModel + adornmentStore.adornments.find(a => a.type === "Movable Line") as IMovablePointAdornmentModelSnapshot expect(movableLineAdornment).toBeDefined() expect(movableLineAdornment.id).toBeDefined() expect(movableLineAdornment.isVisible).toBe(true) - const lsrlAdornment = adornmentStore.adornments.find(a => a.type === "LSRL") as ILSRLAdornmentModel + const lsrlAdornment = adornmentStore.adornments.find(a => a.type === "LSRL") as ILSRLAdornmentModelSnapshot expect(lsrlAdornment).toBeDefined() expect(lsrlAdornment.id).toBeDefined() expect(lsrlAdornment.isVisible).toBe(true) @@ -172,10 +172,10 @@ describe("V2AdornmentImporter", () => { expect(adornmentStore).toBeDefined() expect(adornmentStore.adornments.length).toBe(2) const plottedFunctionAdornment = - adornmentStore.adornments.find(a => a.type === "Plotted Function") as IPlottedFunctionAdornmentModel + adornmentStore.adornments.find(a => a.type === "Plotted Function") as IPlottedFunctionAdornmentModelSnapshot expect(plottedFunctionAdornment).toBeDefined() expect(plottedFunctionAdornment.id).toBeDefined() expect(plottedFunctionAdornment.isVisible).toBe(true) - expect(plottedFunctionAdornment.formula.display).toBe("x*x") + expect(plottedFunctionAdornment.formula?.display).toBe("x*x") }) }) diff --git a/v3/src/components/graph/adornments/v2-adornment-importer.ts b/v3/src/components/graph/adornments/v2-adornment-importer.ts index ee533ad2a6..39a0fc6dba 100644 --- a/v3/src/components/graph/adornments/v2-adornment-importer.ts +++ b/v3/src/components/graph/adornments/v2-adornment-importer.ts @@ -1,4 +1,4 @@ -import { ICodapV2PlotStorage } from "../../../v2/codap-v2-types" +import { ICodapV2PlotModel, ICodapV2UnivariateAdornment } from "../../../v2/codap-v2-types" import { IAttribute } from "../../../models/data/attribute" import { typedId } from "../../../utilities/js-utils" import { updateCellKey } from "./adornment-utils" @@ -17,35 +17,58 @@ import { kPlottedValueType } from "./univariate-measures/plotted-value/plotted-v import { kStandardDeviationType } from "./univariate-measures/standard-deviation/standard-deviation-adornment-types" import { kStandardErrorType } from "./univariate-measures/standard-error/standard-error-adornment-types" import { kNormalCurveType } from "./univariate-measures/normal-curve/normal-curve-adornment-types" +import { ISharedDataSet } from "../../../models/shared/shared-data-set" +import { GraphAttributeDescriptionsMapSnapshot, IAttributeDescriptionSnapshot } + from "../../data-display/models/data-configuration-model" +import { IMovablePointAdornmentModelSnapshot } from "./movable-point/movable-point-adornment-model" +import { IPointModelSnapshot } from "./adornment-models" +import { IMeasureInstanceSnapshot } from "./univariate-measures/univariate-measure-adornment-model" +import { IMovableLineAdornmentModelSnapshot, IMovableLineInstanceSnapshot } + from "./movable-line/movable-line-adornment-model" +import { ILSRLAdornmentModelSnapshot, ILSRLInstanceSnapshot } from "./lsrl/lsrl-adornment-model" +import { IBoxPlotAdornmentModelSnapshot } from "./univariate-measures/box-plot/box-plot-adornment-model" +import { ICountAdornmentModelSnapshot } from "./count/count-adornment-model" +import { IMeanAdornmentModelSnapshot } from "./univariate-measures/mean/mean-adornment-model" +import { IMeanAbsoluteDeviationAdornmentModelSnapshot } + from "./univariate-measures/mean-absolute-deviation/mean-absolute-deviation-adornment-model" +import { IMedianAdornmentModelSnapshot } from "./univariate-measures/median/median-adornment-model" +import { IMovableValueAdornmentModelSnapshot } from "./movable-value/movable-value-adornment-model" +import { IPlottedFunctionAdornmentModelSnapshot } from "./plotted-function/plotted-function-adornment-model" +import { IPlottedValueAdornmentModelSnapshot } from "./univariate-measures/plotted-value/plotted-value-adornment-model" +import { IStandardDeviationAdornmentModelSnapshot } + from "./univariate-measures/standard-deviation/standard-deviation-adornment-model" +import { IStandardErrorAdornmentModelSnapshot } + from "./univariate-measures/standard-error/standard-error-adornment-model" +import { INormalCurveAdornmentModelSnapshot } from "./univariate-measures/normal-curve/normal-curve-adornment-model" interface IProps { - data?: Record - plotModels: Record - attributeDescriptions: Record - yAttributeDescriptions: Record + data?: ISharedDataSet + plotModels: ICodapV2PlotModel[] + attributeDescriptions: GraphAttributeDescriptionsMapSnapshot + yAttributeDescriptions: IAttributeDescriptionSnapshot[] } interface IInstanceKeyProps { index: number - xAttrId: string + xAttrId?: string xCats: string[] - yAttrId: string + yAttrId?: string yCats: string[] - topAttrId: string + topAttrId?: string topCats: string[] - rightAttrId: string + rightAttrId?: string rightCats: string[] } interface IInstanceKeysForAdornmentsProps { - data?: Record - attributeDescriptions: Record - yAttributeDescriptions: Record + data?: ISharedDataSet + attributeDescriptions: GraphAttributeDescriptionsMapSnapshot + yAttributeDescriptions: IAttributeDescriptionSnapshot[] } -const univariateMeasureInstances = (adornment: Record, instanceKeys?: string[]) => { - const equationCoords = adornment.equationCoordsArray[0] - const measures: Record = {} +const univariateMeasureInstances = (adornment: ICodapV2UnivariateAdornment, instanceKeys?: string[]) => { + const equationCoords = adornment.equationCoordsArray?.[0] + const measures: Record = {} instanceKeys?.forEach((key: string) => { const { proportionX, proportionY } = equationCoords ?? { proportionX: NaN, proportionY: NaN } const labelCoords = isFinite(proportionX) && isFinite(proportionY) @@ -94,7 +117,7 @@ const instanceKeysForAdornments = (props: IInstanceKeysForAdornmentsProps) => { const { attributeID: xAttrId, type: xAttrType } = attributeDescriptions.x ?? { attributeID: null, type: null } const { attributeID: topAttrId } = attributeDescriptions.topSplit ?? { attributeID: null } const { attributeID: rightAttrId } = attributeDescriptions.rightSplit ?? { attributeID: null } - const { attributeID: yAttrId, type: yAttrType } = yAttributeDescriptions.y ?? { attributeID: null } + const { attributeID: yAttrId, type: yAttrType } = yAttributeDescriptions[0] ?? { attributeID: null } const xAttr = data.dataSet.attributes.find((attr: IAttribute) => attr.id === xAttrId) const xCats = xAttr && xAttrType !== "numeric" ? [...new Set(xAttr.strValues)] as string[] : [""] const yAttr = data.dataSet.attributes.find((attr: IAttribute) => attr.id === yAttrId) @@ -128,21 +151,29 @@ const instanceKeysForAdornments = (props: IInstanceKeysForAdornmentsProps) => { return instanceKeys } +type ImportableAdornmentSnapshots = IBoxPlotAdornmentModelSnapshot | + ICountAdornmentModelSnapshot | ILSRLAdornmentModelSnapshot | IMeanAdornmentModelSnapshot | + IMeanAbsoluteDeviationAdornmentModelSnapshot | IMedianAdornmentModelSnapshot | + IMovableValueAdornmentModelSnapshot | IMovablePointAdornmentModelSnapshot | + IMovableLineAdornmentModelSnapshot | INormalCurveAdornmentModelSnapshot | + IPlottedFunctionAdornmentModelSnapshot | IPlottedValueAdornmentModelSnapshot | + IStandardDeviationAdornmentModelSnapshot | IStandardErrorAdornmentModelSnapshot + export const v2AdornmentImporter = ({data, plotModels, attributeDescriptions, yAttributeDescriptions}: IProps) => { const instanceKeys = instanceKeysForAdornments({data, attributeDescriptions, yAttributeDescriptions}) - const plotModelStorage = plotModels?.[0].plotModelStorage as ICodapV2PlotStorage + const plotModelStorage = plotModels?.[0].plotModelStorage const v2Adornments = plotModelStorage.adornments const showSquaresOfResiduals = plotModelStorage.areSquaresVisible const showMeasureLabels = plotModelStorage.showMeasureLabels let showConnectingLines = false - const v3Adornments = [] + const v3Adornments: ImportableAdornmentSnapshots[] = [] let interceptLocked = false // COUNT/PERCENT const countAdornment = v2Adornments?.plottedCount const percentTypeMap: Record = { 1: "cell", 2: "column", 3: "row" } if (countAdornment) { - const countAdornmentImport = { + const countAdornmentImport: ICountAdornmentModelSnapshot = { id: typedId("ADRN"), isVisible: countAdornment.isVisible, percentType: percentTypeMap[countAdornment.percentKind], @@ -162,11 +193,11 @@ export const v2AdornmentImporter = ({data, plotModels, attributeDescriptions, yA // MOVABLE POINT const movablePointAdornment = plotModelStorage.movablePointStorage if (movablePointAdornment) { - const points: Record = {} + const points: Record = {} instanceKeys?.forEach((key: string) => { points[key] = movablePointAdornment.coordinates }) - const movablePointAdornmentImport = { + const movablePointAdornmentImport: IMovablePointAdornmentModelSnapshot = { id: typedId("ADRN"), isVisible: movablePointAdornment.isVisible, points, @@ -179,7 +210,7 @@ export const v2AdornmentImporter = ({data, plotModels, attributeDescriptions, yA const movableLineAdornment = plotModelStorage.movableLineStorage if (movableLineAdornment) { const equationCoords = movableLineAdornment.equationCoords - const lines: Record = {} + const lines: Record = {} instanceKeys?.forEach((key: string) => { const lineInstance = { equationCoords: equationCoords ?? undefined, // The V2 default is null, but we want undefined @@ -188,7 +219,7 @@ export const v2AdornmentImporter = ({data, plotModels, attributeDescriptions, yA } lines[key] = lineInstance }) - const movableLineAdornmentImport = { + const movableLineAdornmentImport: IMovableLineAdornmentModelSnapshot = { id: typedId("ADRN"), isVisible: movableLineAdornment.isVisible, lines, @@ -199,16 +230,12 @@ export const v2AdornmentImporter = ({data, plotModels, attributeDescriptions, yA } // LSRL - interface ILSRLImportInstance { - equationCoords?: { x: number; y: number; } - } - const lsrlAdornment = plotModelStorage.multipleLSRLsStorage if (lsrlAdornment) { - const lines: Record = {} + const lines: Record = {} instanceKeys?.forEach((key: string) => { - const lsrlInstances: ILSRLImportInstance[] = [] - lsrlAdornment.lsrls.forEach(lsrl => { + const lsrlInstances: ILSRLInstanceSnapshot[] = [] + lsrlAdornment.lsrls.forEach((lsrl) => { const lsrlInstance = { equationCoords: lsrl.equationCoords ?? undefined // The V2 default is null, but we want undefined } @@ -216,7 +243,7 @@ export const v2AdornmentImporter = ({data, plotModels, attributeDescriptions, yA }) lines[key] = lsrlInstances }) - const lsrlAdornmentImport = { + const lsrlAdornmentImport: ILSRLAdornmentModelSnapshot = { id: typedId("ADRN"), isVisible: lsrlAdornment.isVisible, showConfidenceBands: lsrlAdornment.showConfidenceBands, @@ -231,7 +258,7 @@ export const v2AdornmentImporter = ({data, plotModels, attributeDescriptions, yA const meanAdornment = v2Adornments?.plottedMean if (meanAdornment) { const measures = univariateMeasureInstances(meanAdornment, instanceKeys) - const meanAdornmentImport = { + const meanAdornmentImport: IMeanAdornmentModelSnapshot = { id: typedId("ADRN"), isVisible: meanAdornment.isVisible, measures, @@ -244,7 +271,7 @@ export const v2AdornmentImporter = ({data, plotModels, attributeDescriptions, yA const medianAdornment = v2Adornments?.plottedMedian if (medianAdornment) { const measures = univariateMeasureInstances(medianAdornment, instanceKeys) - const medianAdornmentImport = { + const medianAdornmentImport: IMedianAdornmentModelSnapshot = { id: typedId("ADRN"), isVisible: medianAdornment.isVisible, measures, @@ -257,7 +284,7 @@ export const v2AdornmentImporter = ({data, plotModels, attributeDescriptions, yA const stDevAdornment = v2Adornments?.plottedStDev if (stDevAdornment) { const measures = univariateMeasureInstances(stDevAdornment, instanceKeys) - const stDevAdornmentImport = { + const stDevAdornmentImport: IStandardDeviationAdornmentModelSnapshot = { id: typedId("ADRN"), isVisible: stDevAdornment.isVisible, measures, @@ -267,14 +294,14 @@ export const v2AdornmentImporter = ({data, plotModels, attributeDescriptions, yA } // STANDARD ERROR - const stErrAdornment = v2Adornments?.plottedStDev + const stErrAdornment = v2Adornments?.plottedStErr if (stErrAdornment) { const measures = univariateMeasureInstances(stErrAdornment, instanceKeys) - const stErrAdornmentImport = { + const stErrAdornmentImport: IStandardErrorAdornmentModelSnapshot = { id: typedId("ADRN"), isVisible: stErrAdornment.isVisible, measures, - numStErrs: stErrAdornment.numberOfStdErrs, + _numStErrs: stErrAdornment.numberOfStdErrs, type: kStandardErrorType } v3Adornments.push(stErrAdornmentImport) @@ -284,7 +311,7 @@ export const v2AdornmentImporter = ({data, plotModels, attributeDescriptions, yA const madAdornment = v2Adornments?.plottedMad if (madAdornment) { const measures = univariateMeasureInstances(madAdornment, instanceKeys) - const madAdornmentImport = { + const madAdornmentImport: IMeanAbsoluteDeviationAdornmentModelSnapshot = { id: typedId("ADRN"), isVisible: madAdornment.isVisible, measures, @@ -297,7 +324,7 @@ export const v2AdornmentImporter = ({data, plotModels, attributeDescriptions, yA const boxPlotAdornment = v2Adornments?.plottedBoxPlot if (boxPlotAdornment) { const measures = univariateMeasureInstances(boxPlotAdornment, instanceKeys) - const boxPlotAdornmentImport = { + const boxPlotAdornmentImport: IBoxPlotAdornmentModelSnapshot = { id: typedId("ADRN"), isVisible: boxPlotAdornment.isVisible, measures, @@ -311,7 +338,7 @@ export const v2AdornmentImporter = ({data, plotModels, attributeDescriptions, yA const normalCurveAdornment = v2Adornments?.plottedNormal if (normalCurveAdornment) { const measures = univariateMeasureInstances(normalCurveAdornment, instanceKeys) - const normalCurveAdornmentImport = { + const normalCurveAdornmentImport: INormalCurveAdornmentModelSnapshot = { id: typedId("ADRN"), isVisible: normalCurveAdornment.isVisible, measures, @@ -323,16 +350,24 @@ export const v2AdornmentImporter = ({data, plotModels, attributeDescriptions, yA // MOVABLE VALUES const movableValuesAdornment = v2Adornments?.multipleMovableValues if (movableValuesAdornment) { - const values: Record = {} + const values: Record = {} instanceKeys?.forEach((key: string) => { const plotValues: number[] = [] - // ignoring legacy `values` for now - movableValuesAdornment.valueModels?.forEach((valueModel: Record) => { + + movableValuesAdornment.valueModels?.forEach((valueModel) => { plotValues.push(valueModel.values._main) }) + // Old files store the values in a value property with the form + // "values":[{"isVisible":true,"value":15}]}, + movableValuesAdornment.values?.forEach((value) => { + plotValues.push(value.value) + }) + + // TODO_V2_IMPORT: both valueModels and values might have `isVisible: false` + // we are currently just ignoring that values[key] = plotValues }) - const movableValuesAdornmentImport = { + const movableValuesAdornmentImport: IMovableValueAdornmentModelSnapshot = { id: typedId("ADRN"), isVisible: movableValuesAdornment.isVisible, type: kMovableValueType, @@ -349,7 +384,7 @@ export const v2AdornmentImporter = ({data, plotModels, attributeDescriptions, yA display: plottedValueAdornment.expression, canonical: plottedValueAdornment.expression } - const plottedValueAdornmentImport = { + const plottedValueAdornmentImport: IPlottedValueAdornmentModelSnapshot = { formula, id: typedId("ADRN"), isVisible: plottedValueAdornment.isVisible, @@ -366,7 +401,7 @@ export const v2AdornmentImporter = ({data, plotModels, attributeDescriptions, yA display: plottedFunctionAdornment.expression, canonical: plottedFunctionAdornment.expression } - const plottedFunctionAdornmentImport = { + const plottedFunctionAdornmentImport: IPlottedFunctionAdornmentModelSnapshot = { formula, id: typedId("ADRN"), isVisible: plottedFunctionAdornment.isVisible, diff --git a/v3/src/components/graph/v2-graph-importer.ts b/v3/src/components/graph/v2-graph-importer.ts index 5acd8505fe..2b81f3351a 100644 --- a/v3/src/components/graph/v2-graph-importer.ts +++ b/v3/src/components/graph/v2-graph-importer.ts @@ -8,7 +8,8 @@ import {PlotType} from "./graphing-types" import {IGraphContentModelSnapshot} from "./models/graph-content-model" import {kGraphDataConfigurationType} from "./models/graph-data-configuration-model" import {kGraphPointLayerType} from "./models/graph-point-layer-model" -import {IAttributeDescriptionSnapshot} from "../data-display/models/data-configuration-model" +import {GraphAttributeDescriptionsMapSnapshot, IAttributeDescriptionSnapshot} + from "../data-display/models/data-configuration-model" import {AxisPlace} from "../axis/axis-types" import {IAxisModelSnapshotUnion} from "../axis/models/axis-model" import {v2AdornmentImporter} from "./adornments/v2-adornment-importer" @@ -49,7 +50,7 @@ export function v2GraphImporter({v2Component, v2Document, sharedModelManager, in } const axes: Partial> = {} let primaryRole: PrimaryAttrRole | undefined - const _attributeDescriptions: Partial> = {} + const _attributeDescriptions: GraphAttributeDescriptionsMapSnapshot = {} const _yAttributeDescriptions: IAttributeDescriptionSnapshot[] = [] // configure attributes diff --git a/v3/src/v2/codap-v2-types.ts b/v3/src/v2/codap-v2-types.ts index b0b04640c2..4c134387a4 100644 --- a/v3/src/v2/codap-v2-types.ts +++ b/v3/src/v2/codap-v2-types.ts @@ -103,7 +103,7 @@ export interface ICodapV2DataContext { title: string collections: ICodapV2Collection[] description?: string - metadata?: ICodapV2DataContextMetadata, + metadata?: ICodapV2DataContextMetadata | null, // preventReorg: boolean // setAsideItems: this.get('dataSet').archiveSetAsideItems(), // contextStorage: this.contextStorage @@ -190,95 +190,76 @@ interface ICodapV2LegacyValueModel { value: number } +interface ICodapV2LegacyValueModel { + isVisible: boolean + value: number +} + interface ICodapV2ValueModel { isVisible: boolean enableMeasuresForSelection: boolean values: Record } -interface ICodapV2CountAdornment { +interface ICodapV2Adornment { isVisible: boolean - enableMeasuresForSelection: boolean + enableMeasuresForSelection?: boolean +} + +interface ICodapV2CountAdornment extends ICodapV2Adornment { isShowingCount: boolean isShowingPercent: boolean percentKind: number } -interface ICodapV2ConnectingLinesAdornment { - isVisible: boolean - enableMeasuresForSelection: boolean -} - -interface ICodapV2MovableValueAdornment { - isVisible: boolean - enableMeasuresForSelection: boolean +interface ICodapV2MovableValueAdornment extends ICodapV2Adornment { isShowingCount: boolean isShowingPercent: boolean - // some (older?) documents have `values`, e.g. 24cats.codap + // Older documents have this `values` property. It has been found in files + // generated by CODAPv2 from build 0552 to build 0573 values?: ICodapV2LegacyValueModel[] // more recent documents have `valueModels` ¯\_(ツ)_/¯ valueModels?: ICodapV2ValueModel[] } -interface ICodapV2MeanAdornment { - isVisible: boolean - enableMeasuresForSelection: boolean - equationCoordsArray: ICodapV2ProportionCoordinates[] +export interface ICodapV2UnivariateAdornment extends ICodapV2Adornment { + equationCoordsArray?: ICodapV2ProportionCoordinates[] } -interface ICodapV2MedianAdornment { - isVisible: boolean - enableMeasuresForSelection: boolean - equationCoordsArray: ICodapV2ProportionCoordinates[] +interface ICodapV2StErrAdornment extends ICodapV2UnivariateAdornment { + numberOfStdErrs: number } -interface ICodapV2StDevAdornment { - isVisible: boolean - enableMeasuresForSelection: boolean - equationCoordsArray: ICodapV2ProportionCoordinates[] -} - -interface ICodapV2StErrAdornment { - isVisible: boolean - enableMeasuresForSelection: boolean - equationCoordsArray: ICodapV2ProportionCoordinates[] - numStdErrs: number -} - -interface ICodapV2MadAdornment { - isVisible: boolean - enableMeasuresForSelection: boolean - equationCoordsArray: ICodapV2ProportionCoordinates[] -} - -interface ICodapV2BoxPlotAdornment { - isVisible: boolean - enableMeasuresForSelection: boolean - equationCoordsArray: ICodapV2ProportionCoordinates[] +interface ICodapV2BoxPlotAdornment extends ICodapV2UnivariateAdornment { showOutliers: boolean - showICI: boolean + // TODO_V2_IMPORT: this does not seem to be handled + showICI?: boolean } -interface ICodapV2PlottedFunctionAdornment { - isVisible: boolean - enableMeasuresForSelection: boolean +interface ICodapV2PlottedFunctionAdornment extends ICodapV2Adornment { adornmentKey: string expression: string } -interface ICodapV2PlottedValueAdornment { - isVisible: boolean - enableMeasuresForSelection: boolean +interface ICodapV2PlottedValueAdornment extends ICodapV2Adornment { adornmentKey: string expression: string } -type ICodapV2Adornment = ICodapV2CountAdornment | ICodapV2ConnectingLinesAdornment | ICodapV2MovableValueAdornment | - ICodapV2MeanAdornment | ICodapV2MedianAdornment | ICodapV2StDevAdornment | - ICodapV2StErrAdornment | ICodapV2MadAdornment | ICodapV2PlottedFunctionAdornment | - ICodapV2PlottedValueAdornment | ICodapV2BoxPlotAdornment -// TODO: fix adornments typing -type CodapV2AdornmentMap = Record +interface ICodapV2AdornmentMap { + connectingLine?: ICodapV2Adornment + multipleMovableValues?: ICodapV2MovableValueAdornment + plottedBoxPlot?: ICodapV2BoxPlotAdornment + plottedCount?: ICodapV2CountAdornment + plottedFunction?: ICodapV2PlottedFunctionAdornment + plottedMad?: ICodapV2UnivariateAdornment + plottedMean?: ICodapV2UnivariateAdornment + plottedMedian?: ICodapV2UnivariateAdornment + plottedNormal?: ICodapV2UnivariateAdornment + plottedStDev?: ICodapV2UnivariateAdornment + plottedStErr?: ICodapV2StErrAdornment + plottedValue?: ICodapV2PlottedValueAdornment +} interface ICodapV2MovablePointStorage { isVisible: boolean @@ -316,7 +297,7 @@ interface ICodapV2MultipleLSRLsStorage { export interface ICodapV2PlotStorage { verticalAxisIsY2: boolean - adornments?: CodapV2AdornmentMap + adornments?: ICodapV2AdornmentMap areSquaresVisible?: boolean isLSRLVisible?: boolean movableLineStorage?: ICodapV2MovableLineStorage @@ -343,11 +324,11 @@ export interface ICodapV2GraphStorage extends ICodapV2BaseComponentStorage { rightColl?: IGuidLink<"DG.Collection"> rightAttr?: IGuidLink<"DG.Attribute"> } - displayOnlySelected: boolean + displayOnlySelected?: boolean legendRole: number legendAttributeType: number - numberOfLegendQuantiles: number - legendQuantilesAreLocked: boolean + numberOfLegendQuantiles?: number + legendQuantilesAreLocked?: boolean pointColor: string strokeColor: string pointSizeMultiplier: 1 @@ -358,7 +339,7 @@ export interface ICodapV2GraphStorage extends ICodapV2BaseComponentStorage { plotBackgroundColor?: string | null plotBackgroundOpacity: number plotBackgroundImageLockInfo: any - plotBackgroundImage: string + plotBackgroundImage: string | null xRole: number xAttributeType: number yRole: number @@ -442,8 +423,8 @@ export interface ICodapV2BaseComponent { layout: { width: number height: number - left: number - top: number + left?: number + top?: number isVisible: boolean zIndex?: number }