Skip to content

Commit

Permalink
Merge pull request #1658 from concord-consortium/188618233-adornments…
Browse files Browse the repository at this point in the history
…-import-types

improve adornment v2 importer typing
  • Loading branch information
scytacki authored Dec 2, 2024
2 parents f58123d + 72d1c32 commit 03d39d7
Show file tree
Hide file tree
Showing 23 changed files with 203 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand All @@ -43,6 +43,8 @@ export type RoleAttrIDPair = { role: AttrRole, attributeID: string }

export interface IAttributeDescriptionSnapshot extends SnapshotIn<typeof AttributeDescription> {
}

export type GraphAttributeDescriptionsMapSnapshot = Partial<Record<GraphAttrRole, IAttributeDescriptionSnapshot>>
export type AttributeDescriptionsMapSnapshot = Partial<Record<AttrRole, IAttributeDescriptionSnapshot>>

export const kUnknownDataConfigurationType = "unknownDataConfigurationType"
Expand Down
4 changes: 3 additions & 1 deletion v3/src/components/graph/adornments/adornment-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -27,6 +27,8 @@ export const PointModel = types.model("Point", {
}
}
}))
export interface IPointModelSnapshot extends SnapshotIn<typeof PointModel> {}

export const kInfinitePoint = {x:NaN, y:NaN}

export interface IUpdateCategoriesOptions {
Expand Down
8 changes: 5 additions & 3 deletions v3/src/components/graph/adornments/adornment-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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]
4 changes: 2 additions & 2 deletions v3/src/components/graph/adornments/adornment-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export function getAxisDomains(xAxis?: IBaseNumericAxisModel, yAxis?: IBaseNumer
return { xDomain, yDomain }
}

export const updateCellKey = (cellKey: Record<string, string>, attrId: string, cat: string) => {
export const updateCellKey = (cellKey: Record<string, string>, 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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]
Expand All @@ -79,7 +79,7 @@ export const CountAdornmentModel = AdornmentModel
prevHeight += height
counts.push({ bottomOffset, height, leftOffset, count, width })
}

return counts
}
}))
Expand All @@ -97,6 +97,7 @@ export const CountAdornmentModel = AdornmentModel
}
}))

export interface ICountAdornmentModelSnapshot extends SnapshotIn<typeof CountAdornmentModel> {}
export interface ICountAdornmentModel extends Instance<typeof CountAdornmentModel> {}
export function isCountAdornment(adornment: IAdornmentModel): adornment is ICountAdornmentModel {
return adornment.type === kCountType
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -62,6 +62,7 @@ export const LSRLInstance = types.model("LSRLInstance", {
}
}))


export const LSRLAdornmentModel = AdornmentModel
.named("LSRLAdornmentModel")
.props({
Expand Down Expand Up @@ -224,7 +225,9 @@ export const LSRLAdornmentModel = AdornmentModel
}
}))

export interface ILSRLInstanceSnapshot extends SnapshotIn<typeof LSRLInstance> {}
export interface ILSRLInstance extends Instance<typeof LSRLInstance> {}
export interface ILSRLAdornmentModelSnapshot extends SnapshotIn<typeof LSRLAdornmentModel> {}
export interface ILSRLAdornmentModel extends Instance<typeof LSRLAdornmentModel> {}
export function isLSRLAdornment(adornment: IAdornmentModel): adornment is ILSRLAdornmentModel {
return adornment.type === kLSRLType
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -94,7 +94,9 @@ export const MovableLineAdornmentModel = AdornmentModel
}
}))

export interface IMovableLineInstanceSnapshot extends SnapshotIn<typeof MovableLineInstance> {}
export interface IMovableLineInstance extends Instance<typeof MovableLineInstance> {}
export interface IMovableLineAdornmentModelSnapshot extends SnapshotIn<typeof MovableLineAdornmentModel> {}
export interface IMovableLineAdornmentModel extends Instance<typeof MovableLineAdornmentModel> {}
export function isMovableLineAdornment(adornment: IAdornmentModel): adornment is IMovableLineAdornmentModel {
return adornment.type === kMovableLineType
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -39,6 +39,7 @@ export const MovablePointAdornmentModel = AdornmentModel
})
}
}))
export interface IMovablePointAdornmentModelSnapshot extends SnapshotIn<typeof MovablePointAdornmentModel> {}
export interface IMovablePointAdornmentModel extends Instance<typeof MovablePointAdornmentModel> {}
export function isMovablePointAdornment(adornment: IAdornmentModel): adornment is IMovablePointAdornmentModel {
return adornment.type === kMovablePointType
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -140,6 +140,7 @@ export const MovableValueAdornmentModel = AdornmentModel
}
}))

export interface IMovableValueAdornmentModelSnapshot extends SnapshotIn<typeof MovableValueAdornmentModel> {}
export interface IMovableValueAdornmentModel extends Instance<typeof MovableValueAdornmentModel> {}
export function isMovableValueAdornment(adornment: IAdornmentModel): adornment is IMovableValueAdornmentModel {
return adornment.type === kMovableValueType
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -50,6 +50,7 @@ export const PlottedFunctionAdornmentModel = AdornmentModel
}
}))

export interface IPlottedFunctionAdornmentModelSnapshot extends SnapshotIn<typeof PlottedFunctionAdornmentModel> {}
export interface IPlottedFunctionAdornmentModel extends Instance<typeof PlottedFunctionAdornmentModel> {}
export function isPlottedFunctionAdornment(adornment: IAdornmentModel): adornment is IPlottedFunctionAdornmentModel {
return adornment.type === kPlottedFunctionType
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -114,6 +114,7 @@ export const BoxPlotAdornmentModel = UnivariateMeasureAdornmentModel
}
}))

export interface IBoxPlotAdornmentModelSnapshot extends SnapshotIn<typeof BoxPlotAdornmentModel> {}
export interface IBoxPlotAdornmentModel extends Instance<typeof BoxPlotAdornmentModel> {}
export function isBoxPlotAdornment(adornment: IAdornmentModel): adornment is IBoxPlotAdornmentModel {
return adornment.type === kBoxPlotType
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -34,6 +34,8 @@ export const MeanAbsoluteDeviationAdornmentModel = UnivariateMeasureAdornmentMod
}
}))

export interface IMeanAbsoluteDeviationAdornmentModelSnapshot
extends SnapshotIn<typeof MeanAbsoluteDeviationAdornmentModel> {}
export interface IMeanAbsoluteDeviationAdornmentModel extends Instance<typeof MeanAbsoluteDeviationAdornmentModel> {}
export function isMeanAbsoluteDeviationAdornment(adornment: IUnivariateMeasureAdornmentModel):
adornment is IMeanAbsoluteDeviationAdornmentModel {
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -19,6 +19,7 @@ export const MeanAdornmentModel = UnivariateMeasureAdornmentModel
}
}))

export interface IMeanAdornmentModelSnapshot extends SnapshotIn<typeof MeanAdornmentModel> {}
export interface IMeanAdornmentModel extends Instance<typeof MeanAdornmentModel> {}
export function isMeanAdornment(adornment: IAdornmentModel): adornment is IMeanAdornmentModel {
return adornment.type === kMeanType
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -19,6 +19,7 @@ export const MedianAdornmentModel = UnivariateMeasureAdornmentModel
}
}))

export interface IMedianAdornmentModelSnapshot extends SnapshotIn<typeof MedianAdornmentModel> {}
export interface IMedianAdornmentModel extends Instance<typeof MedianAdornmentModel> {}
export function isMedianAdornment(adornment: IAdornmentModel): adornment is IMedianAdornmentModel {
return adornment.type === kMedianType
Expand Down
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down Expand Up @@ -70,6 +70,7 @@ export const NormalCurveAdornmentModel = UnivariateMeasureAdornmentModel
},
}))

export interface INormalCurveAdornmentModelSnapshot extends SnapshotIn<typeof NormalCurveAdornmentModel> {}
export interface INormalCurveAdornmentModel extends Instance<typeof NormalCurveAdornmentModel> {}
export function isNormalCurveAdornment(adornment: IUnivariateMeasureAdornmentModel):
adornment is INormalCurveAdornmentModel {
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -32,6 +32,7 @@ export const PlottedValueAdornmentModel = UnivariateMeasureAdornmentModel
}
}))

export interface IPlottedValueAdornmentModelSnapshot extends SnapshotIn<typeof PlottedValueAdornmentModel> {}
export interface IPlottedValueAdornmentModel extends Instance<typeof PlottedValueAdornmentModel> {}
export function isPlottedValueAdornment(adornment: IAdornmentModel): adornment is IPlottedValueAdornmentModel {
return adornment.type === kPlottedValueType
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -36,6 +36,7 @@ export const StandardDeviationAdornmentModel = UnivariateMeasureAdornmentModel
}
}))

export interface IStandardDeviationAdornmentModelSnapshot extends SnapshotIn<typeof StandardDeviationAdornmentModel> {}
export interface IStandardDeviationAdornmentModel extends Instance<typeof StandardDeviationAdornmentModel> {}
export function isStandardDeviationAdornment(adornment: IUnivariateMeasureAdornmentModel):
adornment is IStandardDeviationAdornmentModel {
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -56,6 +56,7 @@ export const StandardErrorAdornmentModel = UnivariateMeasureAdornmentModel
}
}))

export interface IStandardErrorAdornmentModelSnapshot extends SnapshotIn<typeof StandardErrorAdornmentModel> {}
export interface IStandardErrorAdornmentModel extends Instance<typeof StandardErrorAdornmentModel> {}
export function isStandardErrorAdornment(adornment: IAdornmentModel | undefined):
adornment is IStandardErrorAdornmentModel {
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -126,6 +126,7 @@ export const UnivariateMeasureAdornmentModel = AdornmentModel
}
}))

export interface IMeasureInstanceSnapshot extends SnapshotIn<typeof MeasureInstance> {}
export interface IMeasureInstance extends Instance<typeof MeasureInstance> {}
export interface IUnivariateMeasureAdornmentModel extends Instance<typeof UnivariateMeasureAdornmentModel> {}
export function isUnivariateMeasureAdornment(adornment: IAdornmentModel):
Expand Down
Loading

0 comments on commit 03d39d7

Please sign in to comment.