Skip to content
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

Add a tooltip to plots with long titles that are cut by Vega #4840

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions webview/src/plots/components/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2637,6 +2637,78 @@ describe('App', () => {
expect(clickEvent.stopPropagation).toHaveBeenCalledTimes(1)
})

it('should have a tooltip on the plot if the title is cut', () => {
const title = 'Plot with a long title'
renderAppWithOptionalData({
template: {
...templatePlotsFixture,
plots: [
{
entries: [
{
...templatePlotsFixture.plots[0].entries[0],
content: {
...templatePlotsFixture.plots[0].entries[0].content,
title: '… with a long title'
} as unknown as VisualizationSpec,
id: title
}
],
group: TemplatePlotGroup.SINGLE_VIEW
}
]
}
})

expect(screen.queryByText(title)).not.toBeInTheDocument()

const plot = within(screen.getByTestId(`plot_${title}`)).getAllByRole(
'button'
)[0]
fireEvent.mouseEnter(plot, {
bubbles: true,
cancelable: true
})

expect(screen.getByText(title)).toBeInTheDocument()
})

it('should not have a tooltip on the plot if the title is not cut', () => {
const title = 'Short title'
renderAppWithOptionalData({
template: {
...templatePlotsFixture,
plots: [
{
entries: [
{
...templatePlotsFixture.plots[0].entries[0],
content: {
...templatePlotsFixture.plots[0].entries[0].content,
title
} as unknown as VisualizationSpec,
id: title
}
],
group: TemplatePlotGroup.SINGLE_VIEW
}
]
}
})

expect(screen.queryByText(title)).not.toBeInTheDocument()

const plot = within(screen.getByTestId(`plot_${title}`)).getAllByRole(
'button'
)[0]
fireEvent.mouseEnter(plot, {
bubbles: true,
cancelable: true
})

expect(screen.queryByText(title)).not.toBeInTheDocument()
})

describe('Smooth Plots', () => {
const waitSetValuePostMessage = (value: number) =>
waitFor(
Expand Down
69 changes: 36 additions & 33 deletions webview/src/plots/components/ZoomablePlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { useEffect, useRef } from 'react'
import { useDispatch } from 'react-redux'
import { VisualizationSpec } from 'react-vega'
import VegaLite, { VegaLiteProps } from 'react-vega/lib/VegaLite'
import { ZoomablePlotWrapper } from './ZoomablePlotWrapper'
import { TemplateVegaLite } from './templatePlots/TemplateVegaLite'
import { setZoomedInPlot } from './webviewSlice'
import styles from './styles.module.scss'
Expand Down Expand Up @@ -77,39 +78,41 @@ export const ZoomablePlot: React.FC<ZoomablePlotProps> = ({
}

return (
<button
className={styles.zoomablePlot}
onClick={() => handleOnClick()}
aria-label="Open Plot in Popup"
>
<GripIcon className={styles.plotGripIcon} />
<span
className={styles.plotActions}
onClick={event => {
event.stopPropagation()
handleOnClick(true)
}}
onKeyDown={event => {
if (event.key === 'Enter') {
handleOnClick(true)
}
}}
role="button"
tabIndex={0}
aria-label="See Plot Export Options"
<ZoomablePlotWrapper id={id} title={plotProps.spec.title?.toString()}>
<button
className={styles.zoomablePlot}
onClick={() => handleOnClick()}
aria-label="Open Plot in Popup"
>
<Ellipsis />
</span>
{currentPlotProps.current &&
(isTemplatePlot ? (
<TemplateVegaLite
vegaLiteProps={plotProps}
id={id}
onNewView={onNewView}
/>
) : (
<VegaLite {...plotProps} onNewView={onNewView} />
))}
</button>
<GripIcon className={styles.plotGripIcon} />
<span
className={styles.plotActions}
onClick={event => {
event.stopPropagation()
handleOnClick(true)
}}
onKeyDown={event => {
if (event.key === 'Enter') {
handleOnClick(true)
}
}}
role="button"
tabIndex={0}
aria-label="See Plot Export Options"
>
<Ellipsis />
</span>
{currentPlotProps.current &&
(isTemplatePlot ? (
<TemplateVegaLite
vegaLiteProps={plotProps}
id={id}
onNewView={onNewView}
/>
) : (
<VegaLite {...plotProps} onNewView={onNewView} />
))}
</button>
</ZoomablePlotWrapper>
)
}
21 changes: 21 additions & 0 deletions webview/src/plots/components/ZoomablePlotWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React, { ReactElement, PropsWithChildren } from 'react'
import Tooltip from '../../shared/components/tooltip/Tooltip'

interface ZoomablePlotWrapperProps {
title?: string
id: string
}

export const ZoomablePlotWrapper: React.FC<
PropsWithChildren<ZoomablePlotWrapperProps>
> = ({ title, id, children }) => {
const isTitleCut = title?.indexOf('…') === 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL we aren't doing this in code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no wait.... we are doing this in code but you can bypass because the id is the title, got it


return isTitleCut ? (
<Tooltip content={id} placement="top" interactive>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please confirm that having a tooltip in place does not break the ability to zoom the plot 🙏🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not prevent from zooming the plot. There should also be a tooltip on the zoomed plot though. I'll add one there as well.

{children as ReactElement}
</Tooltip>
sroy3 marked this conversation as resolved.
Show resolved Hide resolved
) : (
children
)
}
Loading