Skip to content

Commit

Permalink
Merge pull request #821 from pkindruk/fix-legend
Browse files Browse the repository at this point in the history
Fix some legend rendering issues.
  • Loading branch information
beto-rodriguez authored Dec 18, 2022
2 parents 5e6b30f + 4f62876 commit bd04814
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 bd04814

Please sign in to comment.