[v10.0.x] Candlestick: Fix panel not rendering in candles-only mode (#68307)

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

(cherry picked from commit b96a2c1b62)

Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2023-05-11 12:49:48 +00:00
committed by GitHub
co-authored by Leon Sorokin
parent 14be55f682
commit 2ee5a009cd
2 changed files with 25 additions and 3 deletions
@@ -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;
}
@@ -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();