mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 12:44:10 -06:00
Candlestick: Fix panel not rendering in candles-only mode (#68279)
This commit is contained in:
parent
33ba5310ab
commit
b96a2c1b62
@ -5,7 +5,7 @@ import { DataFrame, TimeRange } from '@grafana/data';
|
|||||||
import { withTheme2 } from '../../themes/ThemeContext';
|
import { withTheme2 } from '../../themes/ThemeContext';
|
||||||
import { GraphNG, GraphNGProps, PropDiffFn } from '../GraphNG/GraphNG';
|
import { GraphNG, GraphNGProps, PropDiffFn } from '../GraphNG/GraphNG';
|
||||||
import { PanelContext, PanelContextRoot } from '../PanelChrome/PanelContext';
|
import { PanelContext, PanelContextRoot } from '../PanelChrome/PanelContext';
|
||||||
import { PlotLegend } from '../uPlot/PlotLegend';
|
import { hasVisibleLegendSeries, PlotLegend } from '../uPlot/PlotLegend';
|
||||||
import { UPlotConfigBuilder } from '../uPlot/config/UPlotConfigBuilder';
|
import { UPlotConfigBuilder } from '../uPlot/config/UPlotConfigBuilder';
|
||||||
|
|
||||||
import { preparePlotConfigBuilder } from './utils';
|
import { preparePlotConfigBuilder } from './utils';
|
||||||
@ -39,8 +39,7 @@ export class UnthemedTimeSeries extends Component<TimeSeriesProps> {
|
|||||||
renderLegend = (config: UPlotConfigBuilder) => {
|
renderLegend = (config: UPlotConfigBuilder) => {
|
||||||
const { legend, frames } = this.props;
|
const { legend, frames } = this.props;
|
||||||
|
|
||||||
//hides and shows the legend ON the uPlot graph
|
if (!config || (legend && !legend.showLegend) || !hasVisibleLegendSeries(config, frames)) {
|
||||||
if (!config || (legend && !legend.showLegend)) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,29 @@ interface PlotLegendProps extends VizLegendOptions, Omit<VizLayoutLegendProps, '
|
|||||||
config: UPlotConfigBuilder;
|
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(
|
export const PlotLegend = React.memo(
|
||||||
({ data, config, placement, calcs, displayMode, ...vizLayoutLegendProps }: PlotLegendProps) => {
|
({ data, config, placement, calcs, displayMode, ...vizLayoutLegendProps }: PlotLegendProps) => {
|
||||||
const theme = useTheme2();
|
const theme = useTheme2();
|
||||||
|
Loading…
Reference in New Issue
Block a user