[v10.0.x] Graph: Fix legend overlapping graph area (#68107)

Graph: Fix legend overlapping graph area (#67912)

use render callback instead of requestIdleTimeout

(cherry picked from commit 8e752439c6)

Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2023-05-09 19:45:16 +03:00
committed by GitHub
co-authored by Ashley Harrison
parent a39c486f31
commit fe9b529c25
2 changed files with 4 additions and 2 deletions
@@ -32,6 +32,7 @@ interface LegendDisplayProps {
alignAsTable?: boolean;
rightSide?: boolean;
sideWidth?: number;
renderCallback?: () => void;
}
interface LegendValuesProps {
@@ -176,6 +177,7 @@ export class GraphLegend extends PureComponent<GraphLegendProps, LegendState> {
avg,
current,
total,
renderCallback,
} = this.props;
const seriesValuesProps = { values, min, max, avg, current, total };
const hiddenSeries = this.state.hiddenSeries;
@@ -205,7 +207,7 @@ export class GraphLegend extends PureComponent<GraphLegendProps, LegendState> {
};
return (
<div className={`graph-legend-content ${legendClass}`} style={legendStyle}>
<div className={`graph-legend-content ${legendClass}`} ref={renderCallback} style={legendStyle}>
{this.props.alignAsTable ? <LegendTable {...legendProps} /> : <LegendSeriesList {...legendProps} />}
</div>
);
+1 -1
View File
@@ -155,13 +155,13 @@ class GraphElement {
onToggleSort: this.ctrl.onToggleSort,
onColorChange: this.ctrl.onColorChange,
onToggleAxis: this.ctrl.onToggleAxis,
renderCallback: this.renderPanel.bind(this),
};
const legendReactElem = React.createElement(LegendWithThemeProvider, legendProps);
// render callback isn't supported in react 18+, see: https://github.com/reactwg/react-18/discussions/5
this.legendElemRoot.render(legendReactElem);
requestIdleCallback(() => this.renderPanel());
}
onGraphHover(evt: LegacyGraphHoverEventPayload | DataHoverPayload) {