-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #356 from visdesignlab/340-shortdesc
Show short description in alttxt pane by default
- Loading branch information
Showing
4 changed files
with
128 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Upset, getAltTextConfig } from '@visdesignlab/upset2-react'; | ||
import { AltText, Upset, getAltTextConfig } from '@visdesignlab/upset2-react'; | ||
import { UpsetConfig, getRows } from '@visdesignlab/upset2-core'; | ||
import { useRecoilValue, useRecoilState } from 'recoil'; | ||
import { encodedDataAtom } from '../atoms/dataAtom'; | ||
|
@@ -55,29 +55,30 @@ export const Body = ({ yOffset, data, config }: Props) => { | |
* If an error occurs during the generation, an error message is returned. | ||
* Alt text generation currently is not supported for aggregated plots | ||
* and an error message is returned if the plot is aggregated. | ||
* @throws Error with descriptive message if an error occurs while generating the alttxt | ||
* @returns A promise that resolves to the generated alt text. | ||
*/ | ||
async function generateAltText(): Promise<string> { | ||
async function generateAltText(): Promise<AltText> { | ||
const state = provObject.provenance.getState(); | ||
const config = getAltTextConfig(state, data, getRows(data, state)); | ||
|
||
if (config.firstAggregateBy !== "None") { | ||
return "Alt text generation is not yet supported for aggregated plots. To generate an alt text, set aggregation to 'None' in the left sidebar."; | ||
throw new Error("Alt text generation is not yet supported for aggregated plots. To generate an alt text, set aggregation to 'None' in the left sidebar."); | ||
} | ||
|
||
let response; | ||
try { | ||
response = await api.generateAltText(true, config); | ||
} catch (e: any) { | ||
if (e.response.status === 500) { | ||
return "Server error while generating alt text. Please try again later. If the issue persists, please contact an UpSet developer at [email protected]."; | ||
throw Error("Server error while generating alt text. Please try again later. If the issue persists, please contact an UpSet developer at [email protected]."); | ||
} else if (e.response.status === 400) { | ||
return "Error generating alt text. Contact an upset developer at [email protected]."; | ||
throw Error("Error generating alt text. Contact an upset developer at [email protected]."); | ||
} else { | ||
return "Unknown error while generating alt text: " + e.response.statusText + ". Please contact an UpSet developer at [email protected]."; | ||
throw Error("Unknown error while generating alt text: " + e.response.statusText + ". Please contact an UpSet developer at [email protected]."); | ||
} | ||
} | ||
return response.alttxt.longDescription; | ||
return response.alttxt; | ||
} | ||
|
||
if (data === null) return null; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters