From f0de458e89c5ffb12bd28beffe015492298a9e48 Mon Sep 17 00:00:00 2001 From: Nate Lanza Date: Thu, 23 May 2024 18:31:31 -0600 Subject: [PATCH] Move AltText type to core; update provenance actions for alttext --- .gitignore | 1 + packages/core/src/types.ts | 47 +++++++++++++++++++++----- packages/upset/src/provenance/index.ts | 38 +++------------------ packages/upset/src/types.ts | 26 -------------- 4 files changed, 44 insertions(+), 68 deletions(-) diff --git a/.gitignore b/.gitignore index 193dd327..2f4cff2a 100644 --- a/.gitignore +++ b/.gitignore @@ -162,3 +162,4 @@ sketch /docs/ # End of https://www.toptal.com/developers/gitignore/api/react,node,joed +.turbo/cookies/0.cookie diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index dbef0474..466d0a05 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -18,11 +18,19 @@ export type Meta = { */ export type PlotInformation = { /** User-generated plot description */ - description: string; + description?: string; /** User-generated name to use for sets in the plot (ie "genres") */ - sets: string; + sets?: string; /** User-generated name for items in the dataset (ie "movies") */ - items: string; + items?: string; + /** User-defined plot title */ + title?: string; + /** User-defined plot caption (for sighted users) */ + caption?: string; + /** Short user-defined plot alttxt (replaces the autogenerated shortDescription) */ + userShortText?: string; + /** Long user-defined plot alttxt (replaces the autogenerated longDescription) */ + userLongText?: string; }; export type RowType = @@ -226,6 +234,32 @@ export type Plot = Scatterplot | Histogram; export type Bookmark = { id: string; label: string; size: number } +/** +* Represents the alternative text for an Upset plot. +*/ +export type AltText = { + /** + * The long description for the Upset plot. + */ + longDescription: string; + + /** + * The short description for the Upset plot. + */ + shortDescription: string; + + /** + * The technique description for the Upset plot. + */ + techniqueDescription: string; + + /** + * Optional warnings for the Upset plot. + * Not yet implemented by the API as of 4/22/24 + */ + warnings?: string; +} + export type UpsetConfig = { plotInformation: PlotInformation; horizontal: boolean; @@ -252,12 +286,7 @@ export type UpsetConfig = { }; allSets: Column[]; selected: Row | null; - /** User-defined plot title */ - title?: string; - /** User-defined plot caption (for sighted users) */ - caption?: string; - /** User-defined plot alttxt (replaces the autogenerated alttxt; for low-vision users) */ - userAltText?: string; + userAltText?: AltText; }; export type AccessibleDataEntry = { diff --git a/packages/upset/src/provenance/index.ts b/packages/upset/src/provenance/index.ts index 308683c2..dab0f67b 100644 --- a/packages/upset/src/provenance/index.ts +++ b/packages/upset/src/provenance/index.ts @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ import { - AggregateBy, Plot, PlotInformation, SortBy, SortByOrder, SortVisibleBy, UpsetConfig, DefaultConfig, Row + AggregateBy, Plot, PlotInformation, SortBy, SortByOrder, SortVisibleBy, UpsetConfig, DefaultConfig, Row, + AltText } from '@visdesignlab/upset2-core'; import { Registry, initializeTrrack } from '@trrack/core'; @@ -296,30 +297,9 @@ const setSelectedAction = registry.register( }, ); -/** - * Sets the plotInformation title string - */ -const setTitleAction = registry.register( - 'set-title', - (state: UpsetConfig, title) => { - state.title = title; - return state; - } -) - -/** - * Sets the plotInformation caption string - */ -const setCaptionAction = registry.register( - 'set-caption', - (state: UpsetConfig, caption) => { - state.caption = caption; - return state; - } -); - /** * Sets the alt text for the user + * @param {AltText} altText The alt text to set */ const setUserAltTextAction = registry.register( 'set-user-alt-text', @@ -385,16 +365,8 @@ export function getActions(provenance: UpsetProvenance) { 'Deselect intersection', setSelectedAction(intersection) ), - setTitle: (title: string | null) => provenance.apply( - title ? `Set title to "${title}"` : "Cleared title", - setTitleAction(title) - ), - setCaption: (caption: string | null) => provenance.apply( - caption ? `Set caption to "${caption}"` : "Cleared caption", - setCaptionAction(caption) - ), - setUserAltText: (altText: string | null) => provenance.apply( - altText ? `Set user alt text to "${altText}"` : "Cleared user alt text", + setUserAltText: (altText: AltText | null) => provenance.apply( + altText ? `Set user alt text` : "Cleared user alt text", setUserAltTextAction(altText) ), }; diff --git a/packages/upset/src/types.ts b/packages/upset/src/types.ts index 1820ebaa..85986b07 100644 --- a/packages/upset/src/types.ts +++ b/packages/upset/src/types.ts @@ -1,32 +1,6 @@ import { CoreUpsetData, UpsetConfig } from '@visdesignlab/upset2-core'; import { UpsetProvenance, UpsetActions } from './provenance'; -/** -* Represents the alternative text for an Upset plot. -*/ -export interface AltText { - /** - * The long description for the Upset plot. - */ - longDescription: string; - - /** - * The short description for the Upset plot. - */ - shortDescription: string; - - /** - * The technique description for the Upset plot. - */ - techniqueDescription: string; - - /** - * Optional warnings for the Upset plot. - * Not yet implemented by the API as of 4/22/24 - */ - warnings?: string; -} - export type ContextMenuItem = { /** * The label for the context menu item.