Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix vertical legend position for cartesian charts (#62602)

Anton Kulyk69d55d3b8417
diff --git a/frontend/src/metabase/visualizations/components/legend/LegendLayout.jsx b/frontend/src/metabase/visualizations/components/legend/LegendLayout.jsx
index e18fb855708..c664d92ec0a 100644
--- a/frontend/src/metabase/visualizations/components/legend/LegendLayout.jsx
+++ b/frontend/src/metabase/visualizations/components/legend/LegendLayout.jsx
@@ -55,38 +55,41 @@ export const LegendLayout = ({
const minYLabels = items.length > maxYItems ? maxYLabels : items.length;
const isNarrow = width < MIN_LEGEND_WIDTH;
+
const isVertical = maxXItems < items.length;
+ const isHorizontal = !isVertical;
+
const isVisible = hasLegend && !(isVertical && isNarrow);
const visibleLength = isVertical ? minYLabels : items.length;
+ const legend = (
+ <LegendContainer isVertical={isVertical} isQueryBuilder={isQueryBuilder}>
+ <Legend
+ items={items}
+ hovered={hovered}
+ visibleLength={visibleLength}
+ isVertical={isVertical}
+ onHoverChange={onHoverChange}
+ onSelectSeries={onSelectSeries}
+ onToggleSeriesVisibility={onToggleSeriesVisibility}
+ isReversed={isReversed}
+ />
+ {!isVertical && actionButtons && (
+ <LegendActions>{actionButtons}</LegendActions>
+ )}
+ </LegendContainer>
+ );
+
return (
<LegendLayoutRoot className={className} isVertical={isVertical}>
+ {isVisible && isHorizontal && legend}
<MainContainer>
{isVertical && actionButtons && (
<LegendActions>{actionButtons}</LegendActions>
)}
{hasDimensions && <ChartContainer>{children}</ChartContainer>}
</MainContainer>
- {isVisible && (
- <LegendContainer
- isVertical={isVertical}
- isQueryBuilder={isQueryBuilder}
- >
- <Legend
- items={items}
- hovered={hovered}
- visibleLength={visibleLength}
- isVertical={isVertical}
- onHoverChange={onHoverChange}
- onSelectSeries={onSelectSeries}
- onToggleSeriesVisibility={onToggleSeriesVisibility}
- isReversed={isReversed}
- />
- {!isVertical && actionButtons && (
- <LegendActions>{actionButtons}</LegendActions>
- )}
- </LegendContainer>
- )}
+ {isVisible && isVertical && legend}
</LegendLayoutRoot>
);
};