Skip to content

Commit

Permalink
Fix some legend rendering issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
pkindruk committed Dec 17, 2022
1 parent 5e6b30f commit 4f62876
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/LiveChartsCore/Chart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ protected void DrawLegend(IChartSeries<TDrawingContext>[] seriesInLegend)
if (LegendPosition is LegendPosition.Top or LegendPosition.Bottom)
ControlSize = new(ControlSize.Width, ControlSize.Height - imageLegend.Size.Height);

// reset for cases when legend is hidden or changes postion
Canvas.StartPoint = new LvcPoint(0, 0);

Legend.Draw(this);

PreviousLegendPosition = LegendPosition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,19 @@ private void BuildLayout(Chart<SkiaSharpDrawingContext> chart)
_stackPanel ??= new StackPanel<RoundedRectangleGeometry, SkiaSharpDrawingContext>
{
Padding = new Padding(0),
Orientation = _orientation,
HorizontalAlignment = Align.Start,
VerticalAlignment = Align.Middle,
BackgroundPaint = BackgroundPaint
};

_stackPanel.Orientation = _orientation;
_stackPanel.BackgroundPaint = BackgroundPaint;

_toRemoveSeries = new List<VisualElement<SkiaSharpDrawingContext>>(_stackPanel.Children);

foreach (var series in chart.ChartSeries)
{
if (!series.IsVisibleAtLegend) continue;

var seriesMiniatureVisual = GetSeriesVisual(series);
_ = _toRemoveSeries.Remove(seriesMiniatureVisual);
}
Expand Down

0 comments on commit 4f62876

Please sign in to comment.