Skip to content

Faceting title and empty data #262

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

Merged
merged 13 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
42 changes: 36 additions & 6 deletions src/plots/PlotlyPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export interface PlotProps<T> extends ColorPaletteAddon {
displayLibraryControls?: boolean;
/** show a loading... spinner in the middle of the container div */
showSpinner?: boolean;
/** Show an overlay with the words 'No Data' */
showNoDataOverlay?: boolean;
/** Options for customizing plot legend layout and appearance. */
legendOptions?: PlotLegendAddon;
/** legend title */
Expand Down Expand Up @@ -87,6 +89,7 @@ function PlotlyPlot<T>(
legendTitle,
spacingOptions,
showSpinner,
showNoDataOverlay,
// set default max number of characters (20) for legend ellipsis
maxLegendTextLength = DEFAULT_MAX_LEGEND_TEXT_LENGTH,
// expose data for applying legend ellipsis
Expand Down Expand Up @@ -144,12 +147,6 @@ function PlotlyPlot<T>(
) + '...'
: plotlyProps?.layout?.yaxis?.title,
},
title: {
text: title,
xref: 'paper',
x: 0,
xanchor: 'left', // left aligned to left edge (y-axis) of plot
},
showlegend: displayLegend ?? true,
margin: {
t: spacingOptions?.marginTop,
Expand Down Expand Up @@ -355,6 +352,39 @@ function PlotlyPlot<T>(
onUpdate={onUpdate}
onInitialized={sharedPlotCreation.run}
/>
{title && (
<div
style={{
position: 'absolute',
top: 31,
left: 80,
fontSize: 17,
}}
>
{title}
</div>
)}
{showNoDataOverlay && (
<div
style={{
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
backgroundColor: 'black',
opacity: '50%',
color: 'white',
fontSize: 32,
userSelect: 'none',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
>
No Data
</div>
)}
{showSpinner && <Spinner />}
</div>
</Suspense>
Expand Down
8 changes: 8 additions & 0 deletions src/stories/plots/Barplot.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Basic.args = {
independentAxisLabel: 'Animal',
legendTitle: 'Domesticated',
opacity: 0.75,
title: 'Awesomeness of animals stratified by domestication',
};

export const EmptyData = Template.bind({});
Expand All @@ -43,3 +44,10 @@ EmptyDataLoading.args = {
independentAxisLabel: 'Independent axis label',
showSpinner: true,
};

export const NoDataOverlay = Template.bind({});
NoDataOverlay.args = {
dependentAxisLabel: 'Dependent axis label',
independentAxisLabel: 'Independent axis label',
showNoDataOverlay: true,
};