generated from allen-cell-animated/github-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: Toggle backdrop visibility #483
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3df96ff
feat: Added backdrop visibility config, on/off toggle in settings
ShrimpCryptid 731a07c
feat: Add onscreen toggle for backdrop
ShrimpCryptid 18c59a6
feat: Added custom icons for backdrop visibility
ShrimpCryptid 6ab9937
feat: Added link to viewer settings in backdrop tooltip
ShrimpCryptid 3de2e28
feat: Added backdrop visibility to URL
ShrimpCryptid 9dbadf9
refactor: Fixed linting, removed unused CSS variables
ShrimpCryptid b8c65aa
fix: Viewer will select the default backdrop for a dataset on load
ShrimpCryptid b9a6be6
refactor: Cleanup on SVG icons, changed link color and styling, comments
ShrimpCryptid e2911fd
fix: Backdrop visibility turns off when switching to datasets that do…
ShrimpCryptid 83146ff
refactor: Code cleanup
ShrimpCryptid a125c49
refactor: Code cleanup
ShrimpCryptid 1294332
Merge branch 'main' into feature/onscreen-backdrops-toggle
ShrimpCryptid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import styled, { css } from "styled-components"; | ||
|
||
/** | ||
* A button styled to remove default styles and visually resemble a link. | ||
* This ensures the button still follows accessibility semantics. | ||
*/ | ||
export const LinkStyleButton = styled.button<{ | ||
$color?: string; | ||
$hoverColor?: string; | ||
}>` | ||
margin: 0; | ||
padding: 0; | ||
width: auto; | ||
overflow: visible; | ||
background: transparent; | ||
line-height: normal; | ||
font: inherit; | ||
font-size: inherit; | ||
border: none; | ||
|
||
text-decoration: underline; | ||
|
||
${(props) => { | ||
return css` | ||
color: ${props.$color || "var(--color-text-link)"}; | ||
|
||
&:hover { | ||
color: ${props.$hoverColor || "var(--color-text-link-hover)"}; | ||
} | ||
|
||
&:focus-visible { | ||
box-shadow: 0 0 0 3px ${props.$color || "var(--color-text-link)"}; | ||
} | ||
`; | ||
}} | ||
`; |
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 |
---|---|---|
|
@@ -5,16 +5,17 @@ import styled from "styled-components"; | |
import { Color, ColorRepresentation, Vector2 } from "three"; | ||
import { clamp } from "three/src/math/MathUtils"; | ||
|
||
import { NoImageSVG } from "../assets"; | ||
import { ImagesIconSVG, ImagesSlashIconSVG, NoImageSVG } from "../assets"; | ||
import { ColorRamp, Dataset, Track } from "../colorizer"; | ||
import { LoadTroubleshooting, ViewerConfig } from "../colorizer/types"; | ||
import { LoadTroubleshooting, TabType, ViewerConfig } from "../colorizer/types"; | ||
import * as mathUtils from "../colorizer/utils/math_utils"; | ||
import { FlexColumn, FlexColumnAlignCenter, VisuallyHidden } from "../styles/utils"; | ||
|
||
import CanvasUIOverlay from "../colorizer/CanvasWithOverlay"; | ||
import Collection from "../colorizer/Collection"; | ||
import { AppThemeContext } from "./AppStyle"; | ||
import { AlertBannerProps } from "./Banner"; | ||
import { LinkStyleButton } from "./Buttons/LinkStyleButton"; | ||
import IconButton from "./IconButton"; | ||
import LoadingSpinner from "./LoadingSpinner"; | ||
|
||
|
@@ -30,19 +31,32 @@ const RIGHT_CLICK_BUTTON = 2; | |
const MAX_INVERSE_ZOOM = 2; // 0.5x zoom | ||
const MIN_INVERSE_ZOOM = 0.1; // 10x zoom | ||
|
||
function TooltipWithSubtext(props: TooltipProps & { title: ReactNode; subtext: ReactNode }): ReactElement { | ||
function TooltipWithSubtext( | ||
props: TooltipProps & { title: ReactNode; subtitle?: ReactNode; subtitleList?: ReactNode[] } | ||
): ReactElement { | ||
const divRef = useRef<HTMLDivElement>(null); | ||
return ( | ||
<Tooltip | ||
{...props} | ||
title={ | ||
<> | ||
<p style={{ margin: 0 }}>{props.title}</p> | ||
<p style={{ margin: 0, fontSize: "12px" }}>{props.subtext}</p> | ||
</> | ||
} | ||
> | ||
{props.children} | ||
</Tooltip> | ||
<div ref={divRef}> | ||
<Tooltip | ||
{...props} | ||
trigger={["hover", "focus"]} | ||
title={ | ||
<> | ||
<p style={{ margin: 0 }}>{props.title}</p> | ||
{props.subtitle && <p style={{ margin: 0, fontSize: "12px" }}>{props.subtitle}</p>} | ||
{props.subtitleList && | ||
props.subtitleList.map((text, i) => ( | ||
<p key={i} style={{ margin: 0, fontSize: "12px" }}> | ||
{text} | ||
</p> | ||
))} | ||
</> | ||
} | ||
getPopupContainer={() => divRef.current ?? document.body} | ||
> | ||
{props.children} | ||
</Tooltip> | ||
</div> | ||
); | ||
} | ||
|
||
|
@@ -84,6 +98,7 @@ type CanvasWrapperProps = { | |
/** Pan and zoom will be reset on collection change. */ | ||
collection: Collection | null; | ||
config: ViewerConfig; | ||
updateConfig: (settings: Partial<ViewerConfig>) => void; | ||
vectorData: Float32Array | null; | ||
|
||
loading: boolean; | ||
|
@@ -225,10 +240,22 @@ export default function CanvasWrapper(inputProps: CanvasWrapperProps): ReactElem | |
|
||
// Update backdrops | ||
useMemo(() => { | ||
canv.setBackdropKey(props.selectedBackdropKey); | ||
canv.setBackdropBrightness(props.config.backdropBrightness); | ||
canv.setBackdropSaturation(props.config.backdropSaturation); | ||
}, [props.selectedBackdropKey, props.config.backdropBrightness, props.config.backdropSaturation]); | ||
if (props.selectedBackdropKey !== null && props.config.backdropVisible) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a nice and important check to have! |
||
canv.setBackdropKey(props.selectedBackdropKey); | ||
canv.setBackdropBrightness(props.config.backdropBrightness); | ||
canv.setBackdropSaturation(props.config.backdropSaturation); | ||
canv.setObjectOpacity(props.config.objectOpacity); | ||
} else { | ||
canv.setBackdropKey(null); | ||
canv.setObjectOpacity(100); | ||
} | ||
}, [ | ||
props.selectedBackdropKey, | ||
props.config.backdropVisible, | ||
props.config.backdropBrightness, | ||
props.config.backdropSaturation, | ||
props.config.objectOpacity, | ||
]); | ||
|
||
// Update categorical colors | ||
useMemo(() => { | ||
|
@@ -246,10 +273,6 @@ export default function CanvasWrapper(inputProps: CanvasWrapperProps): ReactElem | |
canv.setOutlierDrawMode(settings.mode, settings.color); | ||
}, [props.config.outlierDrawSettings]); | ||
|
||
useMemo(() => { | ||
canv.setObjectOpacity(props.config.objectOpacity); | ||
}, [props.config.objectOpacity]); | ||
|
||
useMemo(() => { | ||
canv.setInRangeLUT(props.inRangeLUT); | ||
}, [props.inRangeLUT]); | ||
|
@@ -574,7 +597,33 @@ export default function CanvasWrapper(inputProps: CanvasWrapperProps): ReactElem | |
}, [props.dataset, canv]); | ||
|
||
// RENDERING ///////////////////////////////////////////////// | ||
|
||
canv.render(); | ||
|
||
const onViewerSettingsLinkClicked = (): void => { | ||
props.updateConfig({ openTab: TabType.SETTINGS }); | ||
}; | ||
|
||
const backdropTooltipContents: ReactNode[] = []; | ||
backdropTooltipContents.push( | ||
<span key="backdrop-name"> | ||
{props.selectedBackdropKey === null | ||
? "(No backdrops available)" | ||
: props.dataset?.getBackdropData().get(props.selectedBackdropKey)?.name} | ||
</span> | ||
); | ||
// Link to viewer settings | ||
backdropTooltipContents.push( | ||
<LinkStyleButton | ||
key="backdrop-viewer-settings-link" | ||
$color={theme.color.text.darkLink} | ||
$hoverColor={theme.color.text.darkLinkHover} | ||
onClick={onViewerSettingsLinkClicked} | ||
> | ||
{"Viewer settings > Backdrop"} <VisuallyHidden>(opens settings tab)</VisuallyHidden> | ||
</LinkStyleButton> | ||
); | ||
|
||
return ( | ||
<FlexColumnAlignCenter | ||
style={{ | ||
|
@@ -607,7 +656,7 @@ export default function CanvasWrapper(inputProps: CanvasWrapperProps): ReactElem | |
<VisuallyHidden>Reset view</VisuallyHidden> | ||
</IconButton> | ||
</Tooltip> | ||
<TooltipWithSubtext title={"Zoom in"} subtext="Ctrl + Scroll" placement="right" trigger={["hover", "focus"]}> | ||
<TooltipWithSubtext title={"Zoom in"} subtitle="Ctrl + Scroll" placement="right" trigger={["hover", "focus"]}> | ||
<IconButton | ||
type="link" | ||
onClick={() => { | ||
|
@@ -618,7 +667,7 @@ export default function CanvasWrapper(inputProps: CanvasWrapperProps): ReactElem | |
<VisuallyHidden>Zoom in</VisuallyHidden> | ||
</IconButton> | ||
</TooltipWithSubtext> | ||
<TooltipWithSubtext title={"Zoom out"} subtext="Ctrl + Scroll" placement="right" trigger={["hover", "focus"]}> | ||
<TooltipWithSubtext title={"Zoom out"} subtitle="Ctrl + Scroll" placement="right" trigger={["hover", "focus"]}> | ||
<IconButton | ||
type="link" | ||
onClick={() => { | ||
|
@@ -632,6 +681,23 @@ export default function CanvasWrapper(inputProps: CanvasWrapperProps): ReactElem | |
<VisuallyHidden>Zoom out</VisuallyHidden> | ||
</IconButton> | ||
</TooltipWithSubtext> | ||
<TooltipWithSubtext | ||
title={props.config.backdropVisible ? "Hide backdrop" : "Show backdrop"} | ||
placement="right" | ||
subtitleList={backdropTooltipContents} | ||
trigger={["hover", "focus"]} | ||
> | ||
<IconButton | ||
type={props.config.backdropVisible ? "primary" : "link"} | ||
onClick={() => { | ||
props.updateConfig({ backdropVisible: !props.config.backdropVisible }); | ||
}} | ||
disabled={props.selectedBackdropKey === null} | ||
> | ||
{props.config.backdropVisible ? <ImagesSlashIconSVG /> : <ImagesIconSVG />} | ||
<VisuallyHidden>{props.config.backdropVisible ? "Hide backdrop" : "Show backdrop"}</VisuallyHidden> | ||
</IconButton> | ||
</TooltipWithSubtext> | ||
</CanvasControlsContainer> | ||
</FlexColumnAlignCenter> | ||
); | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommend reviewing this with whitespace off!