Skip to content

Commit

Permalink
Update the types to match some docs in cfm-shared
Browse files Browse the repository at this point in the history
This are only the updates required to validate the first 20 or so files in cfm-shared.
Also this is ignoring properties that those files define but are not declared in the v2 types.
  • Loading branch information
scytacki committed Dec 2, 2024
1 parent acbae57 commit 97881bb
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export const v2AdornmentImporter = ({data, plotModels, attributeDescriptions, yA
const lines: Record<string, ILSRLInstanceSnapshot[]> = {}
instanceKeys?.forEach((key: string) => {
const lsrlInstances: ILSRLInstanceSnapshot[] = []
lsrlAdornment.lsrls.forEach((lsrl) => {
lsrlAdornment.lsrls?.forEach((lsrl) => {
const lsrlInstance = {
equationCoords: lsrl.equationCoords ?? undefined // The V2 default is null, but we want undefined
}
Expand Down
4 changes: 3 additions & 1 deletion v3/src/components/graph/v2-graph-importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function v2GraphImporter({v2Component, v2Document, sharedModelManager, in
pointColor, strokeColor, pointSizeMultiplier,
strokeSameAsFill, isTransparent,
plotBackgroundImageLockInfo,
/* The following are present in the componentStorage but not used in the V3 content model (yet):
/* TODO_V2_IMPORT: The following are present in the componentStorage but not used in the V3 content model (yet):
displayOnlySelected, legendRole, legendAttributeType, numberOfLegendQuantiles,
legendQuantilesAreLocked, plotBackgroundImage, transparency, strokeTransparency,
plotBackgroundOpacity,
Expand Down Expand Up @@ -65,6 +65,8 @@ export function v2GraphImporter({v2Component, v2Document, sharedModelManager, in
const v2AttrId = aLink.id,
attribute = v2Document.getV3Attribute(v2AttrId),
v3AttrId = attribute?.id ?? '',
// This approach of dynamic key computation bypasses the typing in ICodapV2GraphStorage,
// there might be a typescript approach which fixes this.
attrRoleKey = `${attrKey}Role` as keyof ICodapV2GraphStorage,
v2Role = v2Component.componentStorage[attrRoleKey],
attrTypeKey = `${attrKey}AttributeType` as keyof ICodapV2GraphStorage,
Expand Down
86 changes: 61 additions & 25 deletions v3/src/v2/codap-v2-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ export type AllowStringIds<T> = Omit<T, "guid" | "id"> & {

export interface ICodapV2Attribute {
guid: number
id: number
// A document generated by build 0512 did not have this id
// It is ignored by the import code, however it is used by
// `convertValuesToAttributeSnapshot` this usage seems incorrect
id?: number
name: string
type?: string | null
title?: string
Expand Down Expand Up @@ -80,7 +83,7 @@ export interface ICodapV2Collection {
}
name: string
parent?: number
title: string
title: string | null
type: "DG.Collection"
}
// when exporting a v3 collection to v2
Expand All @@ -97,7 +100,9 @@ export interface ICodapV2DataContext {
type: "DG.DataContext"
document?: number // id of containing document
guid: number
id: number
// This was not present in a file generated by 0512.
// It also seems to be be ignored by the import code
id?: number
flexibleGroupingChangeFlag: boolean
name: string
title: string
Expand Down Expand Up @@ -133,7 +138,14 @@ export interface ICodapV2BaseComponentStorage {
title?: string
name?: string
userSetTitle: boolean
cannotClose: boolean
// in a document saved by build 0441 this property didn't exist
// TODO_V2_IMPORT: this property seems to be ignored by the import code
// The v3 models do support it, but from what I can tell each component
// importer needs to read this property from componentStorage and then
// set it on the tile snapshot they pass to insertTile
// In the CFM shared files there are more than 20,000 examples of cannotClose: true
// and more 20,000 examples cannotClose: false
cannotClose?: boolean
}

export interface ICodapV2CalculatorStorage extends ICodapV2BaseComponentStorage {
Expand All @@ -150,7 +162,7 @@ export interface ICodapV2SliderStorage extends ICodapV2BaseComponentStorage {
animationMode: number
restrictToMultiplesOf: number | null
maxPerSecond: number | null
userTitle: boolean
userTitle?: boolean
}

export interface ICodapV2TableStorage extends ICodapV2BaseComponentStorage {
Expand All @@ -166,6 +178,13 @@ export interface ICodapV2TableStorage extends ICodapV2BaseComponentStorage {
title: string
}

export interface ICodapV2CaseCardStorage extends ICodapV2BaseComponentStorage {
_links_: {
context: IGuidLink<"DG.DataContextRecord">
}
title: string
}

export interface ICodapV2WebViewStorage extends ICodapV2BaseComponentStorage {
URL: string
}
Expand Down Expand Up @@ -286,13 +305,15 @@ interface ICodapV2LSRL {
showConfidenceBands: boolean
}

// In a doc generated by build 0441:
// enableMeasuresForSelection, showConfidenceBands, and lsrls were not defined
interface ICodapV2MultipleLSRLsStorage {
isVisible: boolean
enableMeasuresForSelection: boolean
enableMeasuresForSelection?: boolean
showSumSquares: boolean
isInterceptLocked: boolean
showConfidenceBands: boolean
lsrls: ICodapV2LSRL[]
showConfidenceBands?: boolean
lsrls?: ICodapV2LSRL[]
}

export interface ICodapV2PlotStorage {
Expand Down Expand Up @@ -331,25 +352,33 @@ export interface ICodapV2GraphStorage extends ICodapV2BaseComponentStorage {
legendQuantilesAreLocked?: boolean
pointColor: string
strokeColor: string
pointSizeMultiplier: 1
// This was constrained to 1 in the types before, but there are many v2 documents
// where this is not 1. Values seem to range from 0.5 to 3
pointSizeMultiplier: number
transparency: number
strokeTransparency: number
strokeSameAsFill: boolean
// This property was not defined in a document from build 0473
strokeSameAsFill?: boolean
isTransparent: boolean
plotBackgroundColor?: string | null
plotBackgroundOpacity: number
plotBackgroundImageLockInfo: any
plotBackgroundImage: string | null
plotBackgroundImageLockInfo?: any
plotBackgroundImage?: string | null
xRole: number
xAttributeType: number
yRole: number
yAttributeType: number
y2Role: number
y2AttributeType: number
topRole: number
topAttributeType: number
rightRole: number
rightAttributeType: number

// The right* and top* properties were not defined in a document from build 0473
topRole?: number
topAttributeType?: number
topAxisClass?: string
rightRole?: number
rightAttributeType?: number
rightAxisClass?: string

xAxisClass: string
xLowerBound?: number
xUpperBound?: number
Expand All @@ -359,8 +388,6 @@ export interface ICodapV2GraphStorage extends ICodapV2BaseComponentStorage {
y2AxisClass: string
y2LowerBound?: number
y2UpperBound?: number
topAxisClass: string
rightAxisClass: string
plotModels: ICodapV2PlotModel[]
}

Expand Down Expand Up @@ -405,7 +432,7 @@ export interface ICodapV2MapStorage extends ICodapV2BaseComponentStorage {
export interface ICodapV2GuideStorage extends ICodapV2BaseComponentStorage {
currentItemIndex?: number
isVisible?: boolean
items: Array<{ itemTitle: string, url: string }>
items: Array<{ itemTitle: string | null, url: string }>
}

export interface ICodapV2TextStorage extends ICodapV2BaseComponentStorage {
Expand All @@ -421,8 +448,9 @@ export interface ICodapV2BaseComponent {
id?: number
componentStorage: Record<string, any>
layout: {
width: number
height: number
// A GameView saved by build 0606 had no width or height
width?: number
height?: number
left?: number
top?: number
isVisible: boolean
Expand Down Expand Up @@ -450,6 +478,13 @@ export interface ICodapV2TableComponent extends ICodapV2BaseComponent {
}
export const isV2TableComponent = (component: ICodapV2BaseComponent): component is ICodapV2TableComponent =>
component.type === "DG.TableView"

// TODO_V2_IMPORT: handle importing case cards:
// https://www.pivotaltracker.com/story/show/188596023
export interface ICodapV2CaseCardComponent extends ICodapV2BaseComponent {
type: "DG.CaseCard"
componentStorage: ICodapV2CaseCardStorage
}
export interface ICodapV2WebViewComponent extends ICodapV2BaseComponent {
type: "DG.WebView"
componentStorage: ICodapV2WebViewStorage
Expand Down Expand Up @@ -491,15 +526,16 @@ export interface ICodapV2TextComponent extends ICodapV2BaseComponent {
export const isV2TextComponent = (component: ICodapV2BaseComponent): component is ICodapV2TextComponent =>
component.type === "DG.TextView"

export type CodapV2Component = ICodapV2CalculatorComponent | ICodapGameViewComponent | ICodapV2GraphComponent |
ICodapV2GuideComponent | ICodapV2MapComponent | ICodapV2SliderComponent |
ICodapV2TableComponent | ICodapV2TextComponent | ICodapV2WebViewComponent
export type CodapV2Component = ICodapV2CalculatorComponent | ICodapV2CaseCardComponent| ICodapGameViewComponent |
ICodapV2GraphComponent | ICodapV2GuideComponent | ICodapV2MapComponent |
ICodapV2SliderComponent | ICodapV2TableComponent | ICodapV2TextComponent |
ICodapV2WebViewComponent

export interface ICodapV2DocumentJson {
type?: string // "DG.Document"
id?: number
guid: number
name: string
name: string | null
appName: string // "DG"
appVersion: string
appBuildNum: string
Expand Down
2 changes: 1 addition & 1 deletion v3/src/v2/import-v2-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function importV2Document(v2Document: CodapV2Document) {
layout: { left = 0, top = 0, width, height: v2Height, isVisible, zIndex }, savedHeight
} = v2Component
const isHidden = isVisible === false
const v2Minimized = (!!savedHeight && savedHeight >= v2Height) || undefined
const v2Minimized = (!!savedHeight && v2Height != null && savedHeight >= v2Height) || undefined
const isMinimized = v2Minimized && !isHidden
const height = savedHeight && v2Minimized ? savedHeight : v2Height
// only apply imported width and height to resizable tiles
Expand Down

0 comments on commit 97881bb

Please sign in to comment.