Repository navigation
Skip drawing an axis chart that has no entries - #387
Merged
Merged
Conversation
AxisBasedChart.DrawContent only checked that Series and entries were
not null, so a chart given an empty list went on to take the Max of the
grouped entries and threw InvalidOperationException ("Sequence contains
no elements") on every draw. Line, bar and point charts all failed this
way, and the exception escapes the paint callback and crashes the app.
An empty chart now draws its background and nothing else.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A line, bar or point chart whose
Entriesis an empty list (rather thannull) threw on every draw.AxisBasedChart.DrawContentonly checkedSeries != null && entries != null, then laid out the chart withentries.GroupBy(x => x.Label).Max(g => g.Count()), andMaxthrowsInvalidOperationException("Sequence contains no elements") on an empty sequence. The exception escapes theSKCanvasViewpaint callback, so it takes the app down — seen in a shipping iOS app, where a chart was bound to data that could briefly be empty.DrawContentnow also requiresentries.Any(). An empty chart draws its background and nothing else, the same as a chart whose entries were never set.Verification
Headless draw onto a 300×100
SKBitmapagainst theMicrochartsproject:LineChart, 0 entriesInvalidOperationExceptionBarChart, 0 entriesInvalidOperationExceptionPointChart, 0 entriesInvalidOperationExceptionLineChart, 1 entrySources/Microcharts/Microcharts.csprojbuilds with no warnings.🤖 Generated with Claude Code