Skip to content

Commit

Permalink
refactor(frontend): alternative view dimming implementation
Browse files Browse the repository at this point in the history
The previous one created glitches in Firefox, because the animation for the
background completed before that the SVG animation with the same duration due to
laggy SVG rendering.
  • Loading branch information
kris7t committed Oct 21, 2024
1 parent affb68f commit 154e174
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
21 changes: 0 additions & 21 deletions subprojects/frontend/src/ModelWorkArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ function ModelWorkArea({ touchesTop }: { touchesTop: boolean }): JSX.Element {
selectedGeneratedModel === undefined
? 0
: generatedModelNames.indexOf(selectedGeneratedModel) + 1;
const selectedGraph = generatedModel?.graph ?? graph;
const { dimView } = selectedGraph;

return (
<Stack direction="column" height="100%" width="100%" overflow="hidden">
Expand Down Expand Up @@ -202,25 +200,6 @@ function ModelWorkArea({ touchesTop }: { touchesTop: boolean }): JSX.Element {
overflow="hidden"
position="relative"
>
<Stack
key={(generatedModel?.graph ?? graph).name}
sx={(theme) => ({
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
backgroundColor: dimView
? theme.palette.outer.disabled
: 'transparent',
transition: theme.transitions.create('background-color', {
duration: theme.transitions.duration.short,
}),
'@media (prefers-reduced-motion: reduce)': {
backgroundColor: 'transparent',
},
})}
/>
{generatedModel === undefined ? (
<SplitGraphPane
graph={graph}
Expand Down
28 changes: 28 additions & 0 deletions subprojects/frontend/src/graph/GraphArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,33 @@ const SyncWarning = observer(function SyncWarning({
);
});

const Overlay = observer(function Overlay({
graph: { dimView },
}: {
graph: GraphStore;
}): JSX.Element {
return (
<Box
sx={(theme) => ({
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
pointerEvents: 'none',
backgroundColor: dimView ? theme.palette.outer.disabled : 'transparent',
mixBlendMode: theme.palette.mode === 'dark' ? 'lighten' : 'darken',
transition: theme.transitions.create('background-color', {
duration: theme.transitions.duration.short,
}),
'@media (prefers-reduced-motion: reduce)': {
backgroundColor: 'transparent',
},
})}
/>
);
});

export default function GraphArea({
graph,
}: {
Expand Down Expand Up @@ -99,6 +126,7 @@ export default function GraphArea({
/>
)}
</ZoomCanvas>
<Overlay graph={graph} />
<SyncWarning graph={graph} />
<VisibilityPanel graph={graph} dialog={dialog} />
<ExportPanel graph={graph} svgContainer={svgContainer} dialog={dialog} />
Expand Down
8 changes: 1 addition & 7 deletions subprojects/frontend/src/graph/GraphTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,12 @@ export default styled('div', {
strokeDasharray: 'none !important',
},
},
'.node-bg, .node-header': {
'.node-header': {
transition: args.theme.transitions.create('fill', {
duration: args.theme.transitions.duration.short,
}),
},
'&.dimmed svg': {
'.node .node-bg:not(.node-shadow)': {
fill: args.theme.palette.outer.disabled,
'@media (prefers-reduced-motion: reduce)': {
fill: args.theme.palette.background.default,
},
},
'.node-header': {
fill: saturate(
args.theme.palette.mode === 'dark'
Expand Down
12 changes: 11 additions & 1 deletion subprojects/frontend/src/table/TableArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ function TableArea({
graph: GraphStore;
touchesTop: boolean;
}): JSX.Element {
const { concretize, selectedSymbol, showComputed, semantics } = graph;
const { concretize, selectedSymbol, showComputed, semantics, dimView } =
graph;
const { nodes, partialInterpretation } = semantics;
const symbolName = selectedSymbol?.name;
const computedName = showComputed
Expand Down Expand Up @@ -185,6 +186,15 @@ function TableArea({
getRowId={(row) => row.nodes.join(',')}
sx={(theme) => ({
border: 'none',
backgroundColor: dimView
? theme.palette.outer.disabled
: 'transparent',
transition: theme.transitions.create('background-color', {
duration: theme.transitions.duration.short,
}),
'@media (prefers-reduced-motion: reduce)': {
backgroundColor: 'transparent',
},
'--DataGrid-rowBorderColor':
theme.palette.mode === 'dark'
? alpha(theme.palette.text.primary, 0.24)
Expand Down

0 comments on commit 154e174

Please sign in to comment.