Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions src/Components/Charts/Chart/Renderer/ChartLegendRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ private void UpdateHeightCollections(LegendOption legendOption, double rowCount,
{
int len = (int)(rowCount > 0 ? (rowCount - 1) : 0);

RowHeights?.Insert(len, Math.Max(len >= 0 && len < RowHeights.Count ? RowHeights[len] : 0, legendOption?.TextSize.Height ?? 0));
RowHeights?.Insert(len, Math.Max(len >= 0 && len < RowHeights.Count ? RowHeights[len] : 0, MaxItemHeight));

double columnHeightsValue = ComputeColumnHeightValue(legendOption!, columnCount, padding, firstLegend);
ColumnHeights?.Insert((int)columnCount, columnHeightsValue);
Expand All @@ -731,7 +731,7 @@ private void UpdateHeightCollections(LegendOption legendOption, double rowCount,
private double ComputeColumnHeightValue(LegendOption legendOption, double columnCount, double padding, bool firstLegend)
{
int colIndex = (int)columnCount;
double baseHeight = (colIndex >= 0 && colIndex < ColumnHeights?.Count ? ColumnHeights[colIndex] : 0) + (legendOption?.TextSize.Height ?? 0);
double baseHeight = (colIndex >= 0 && colIndex < ColumnHeights?.Count ? ColumnHeights[colIndex] : 0) + MaxItemHeight;
double additionalPadding = IsVertical
? (firstLegend || LegendCollection.IndexOf(legendOption ?? null!) == 0) ? padding : ItemPadding
: IsTopBottomVertical
Expand Down Expand Up @@ -765,18 +765,15 @@ private void CalculatePagingAndFinalBounds(double rowCount, int wrapTextCount, b
double padding = Legend?.Padding ?? 0;
double columnHeight = (ColumnHeights?.Count > 0 ? ColumnHeights.Max() : 0) + padding;

columnHeight = Math.Max(columnHeight + (wrapTextCount > 1 ? padding : 0), MaxItemHeight + padding + padding);
columnHeight = Math.Max(columnHeight + (wrapTextCount > 1 ? padding : 0), (MaxItemHeight + padding) + padding);
IsPaging = LegendBounds.Height < columnHeight && rowCount > 0;
rowCount = IsPaging ? rowCount : 1;

if (render)
{
SetBounds(Math.Max(rowWidth + padding, maximumWidth), columnHeight);

double rowsPerPageDenom = Math.Max(1.0, (double)RowCountPerPage - 1.0);
double linesPerPageDenom = Math.Max(0.0, Math.Ceiling((LegendBounds.Height - (Legend?.Padding ?? 0)) / _textHeight) + 1.0);

TotalPageCount = Math.Ceiling((rowCount / rowsPerPageDenom) + (wrapTextCount / linesPerPageDenom));
TotalPageCount = Math.Ceiling((rowCount / Math.Max(1, RowCountPerPage - 1)) + (wrapTextCount / Math.Max(0, Math.Ceiling((LegendBounds.Height - (Legend?.Padding ?? 0)) / _textHeight) + 1)));
}
else
{
Expand All @@ -796,11 +793,7 @@ private void FinalizeLegendLocation(Rect rect, Size availableSize)
GetLocation(rect ?? null!, availableSize ?? null!, LegendSettings.Margin, Owner?._margin ?? null!, LegendSettings.Border, LegendSettings.Location);
}

if (LegendSettings?.Position == LegendPosition.Custom)
{
double width = (availableSize?.Width ?? 0) - LegendSettings.Location.X - LegendSettings.Border.Width;
LegendBounds.Width = Math.Max(0, Math.Min(LegendBounds.Width, width));
}
LegendBounds.Width = LegendSettings?.Position == LegendPosition.Custom ? Math.Min(LegendBounds.Width, (availableSize?.Width ?? 0) - LegendSettings.Location.X - LegendSettings.Border.Width) : LegendBounds.Width;
}

/// <summary>
Expand Down