-
Notifications
You must be signed in to change notification settings - Fork 28
Do not mutate plot props when zooming #5066
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { PlotsSection } from 'dvc/src/plots/webview/contract' | ||
import { SpecWithTitles } from 'dvc/src/plots/vega/util' | ||
import React, { useEffect, useRef } from 'react' | ||
import React from 'react' | ||
import { useDispatch } from 'react-redux' | ||
import VegaLite, { VegaLiteProps } from 'react-vega/lib/VegaLite' | ||
import VegaLite from 'react-vega/lib/VegaLite' | ||
import { ZoomablePlotWrapper } from './ZoomablePlotWrapper' | ||
import { TemplateVegaLite } from './templatePlots/TemplateVegaLite' | ||
import { setZoomedInPlot } from './webviewSlice' | ||
import styles from './styles.module.scss' | ||
import { config } from './constants' | ||
import { createPlotProps } from './constants' | ||
import { changeDragAndDropMode } from './util' | ||
import { zoomPlot } from '../util/messages' | ||
import { useGetPlot } from '../hooks/useGetPlot' | ||
|
@@ -29,35 +29,13 @@ export const ZoomablePlot: React.FC<ZoomablePlotProps> = ({ | |
}) => { | ||
const { data, spec, isTemplatePlot } = useGetPlot(section, id) | ||
const dispatch = useDispatch() | ||
const currentPlotProps = useRef<VegaLiteProps>() | ||
|
||
const plotProps: VegaLiteProps = { | ||
actions: false, | ||
config, | ||
data, | ||
'data-testid': `${id}-vega`, | ||
renderer: 'svg', | ||
spec | ||
} as VegaLiteProps | ||
currentPlotProps.current = plotProps | ||
|
||
useEffect(() => { | ||
dispatch( | ||
setZoomedInPlot({ | ||
id, | ||
isTemplatePlot, | ||
plot: currentPlotProps.current, | ||
refresh: true | ||
}) | ||
) | ||
}, [data, spec, dispatch, id, isTemplatePlot]) | ||
const plotProps = createPlotProps(data, id, spec) | ||
|
||
const handleOnClick = (openActionsMenu?: boolean) => { | ||
zoomPlot() | ||
|
||
return dispatch( | ||
setZoomedInPlot({ id, isTemplatePlot, openActionsMenu, plot: plotProps }) | ||
) | ||
return dispatch(setZoomedInPlot({ id, isTemplatePlot, openActionsMenu })) | ||
} | ||
|
||
if (!data && !spec) { | ||
|
@@ -103,16 +81,15 @@ export const ZoomablePlot: React.FC<ZoomablePlotProps> = ({ | |
> | ||
<Ellipsis /> | ||
</span> | ||
{currentPlotProps.current && | ||
(isTemplatePlot ? ( | ||
<TemplateVegaLite | ||
vegaLiteProps={plotProps} | ||
id={id} | ||
onNewView={onNewView} | ||
/> | ||
) : ( | ||
<VegaLite {...plotProps} onNewView={onNewView} /> | ||
))} | ||
{isTemplatePlot ? ( | ||
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. Similar blocks of code found in 2 locations. Consider refactoring. |
||
<TemplateVegaLite | ||
vegaLiteProps={plotProps} | ||
id={id} | ||
onNewView={onNewView} | ||
/> | ||
) : ( | ||
<VegaLite {...plotProps} onNewView={onNewView} /> | ||
)} | ||
</button> | ||
</ZoomablePlotWrapper> | ||
) | ||
|
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. Using the full Vega API for signals and views (https://vega.github.io/vega/docs/api/view/#signals) to make things simpler |
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.
Not quite sure what is going on, but when I tested the smooth plots, the plots started behaving really weird:
Screen.Recording.2023-12-05.at.9.46.02.AM.mov
I doubled checked to make sure it wasn't happening on
main
andmain
is working correctly.