Candlestick: Fix panel not rendering in candles-only mode (#68279)

This commit is contained in:
Leon Sorokin 2023-05-11 07:38:01 -05:00 committed by GitHub
parent 33ba5310ab
commit b96a2c1b62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View File

@ -5,7 +5,7 @@ import { DataFrame, TimeRange } from '@grafana/data';
import { withTheme2 } from '../../themes/ThemeContext';
import { GraphNG, GraphNGProps, PropDiffFn } from '../GraphNG/GraphNG';
import { PanelContext, PanelContextRoot } from '../PanelChrome/PanelContext';
import { PlotLegend } from '../uPlot/PlotLegend';
import { hasVisibleLegendSeries, PlotLegend } from '../uPlot/PlotLegend';
import { UPlotConfigBuilder } from '../uPlot/config/UPlotConfigBuilder';
import { preparePlotConfigBuilder } from './utils';
@ -39,8 +39,7 @@ export class UnthemedTimeSeries extends Component<TimeSeriesProps> {
renderLegend = (config: UPlotConfigBuilder) => {
const { legend, frames } = this.props;
//hides and shows the legend ON the uPlot graph
if (!config || (legend && !legend.showLegend)) {
if (!config || (legend && !legend.showLegend) || !hasVisibleLegendSeries(config, frames)) {
return null;
}

View File

@ -27,6 +27,29 @@ interface PlotLegendProps extends VizLegendOptions, Omit<VizLayoutLegendProps, '
config: UPlotConfigBuilder;
}
/**
* mostly duplicates logic in PlotLegend below :(
*
* @internal
*/
export function hasVisibleLegendSeries(config: UPlotConfigBuilder, data: DataFrame[]) {
return config.getSeries().some((s) => {
const fieldIndex = s.props.dataFrameFieldIndex;
if (!fieldIndex) {
return false;
}
const field = data[fieldIndex.frameIndex]?.fields[fieldIndex.fieldIndex];
if (!field || field.config.custom?.hideFrom?.legend) {
return false;
}
return true;
});
}
export const PlotLegend = React.memo(
({ data, config, placement, calcs, displayMode, ...vizLayoutLegendProps }: PlotLegendProps) => {
const theme = useTheme2();