Fix bar chart rendering for single-value data series - #749
Open
LeSingh1 wants to merge 1 commit into
Open
Conversation
When a data series contains exactly one value, graphBounds() inferred xMin == xMax and yMin == yMax, producing a zero-area CGRect that collapses bar/line/scatter rendering (issue carekit-apple#575). Expand the inferred range so a single point has room to render: - x: pad by 0.5 on either side of the value - y: snap to 0 as the natural baseline when the value is positive (matching the documented workaround), to 0 as the top when negative, and pad symmetrically when the value is exactly 0 Multi-point series are unaffected (xMin < xMax and yMin < yMax remain the existing computation). Fixes carekit-apple#575
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
Fixes #575: a bar chart with a single data point (e.g.
OCKDataSeries(values: [132], title: "Steps")) renders nothing.Root cause
OCKMultiPlotable.graphBounds()inCareKitUI/CareKitUI/iOS/Charts/Protocols/OCKGraphable.swiftcomputes the chart's coordinate-space rect from the min/max of the data points. With one point,xMin == xMaxandyMin == yMax, so the returnedCGRecthas zero width and zero height.OCKBarLayer.makePaththen receives degenerate input from the cartesian conversion and draws nothing.Fix
In
graphBounds(), when an axis collapses to a single value, pad the inferred range so the rect has positive extent:0so a single value renders as a full-height bar from the natural baseline — this matches the workaround@erik-appledocumented in the issue (graphView.yMinimum = 0). For negative values, snap the upper bound to0. For exactly0, expand symmetrically.Multi-point series fall through unchanged (
xMin < xMaxandyMin < yMaxcontinue to use the existing computation).Test plan
swiftc -parse CareKitUI/CareKitUI/iOS/Charts/Protocols/OCKGraphable.swift(exit 0)OCKDataSeries(values: [132], title: "Steps")):graphBounds()→CGRect(x: 0, y: 132, w: 132, h: 0)(auto-scaling setsyMaximum = 132, thenyMin == yMax); height is0, bar layer produces no visible path.graphBounds()→CGRect(x: -0.5, y: 0, w: 1, h: 132). Bar centered at x=0, full height from y=0 to y=132.[10, 20, 30]): unchanged behavior (xMin=0, xMax=2, height>0, etc.). Both branches of theif xMin == xMaxandif yMin == yMaxguards are skipped.view.graphBounds().width > 0 && height > 0afterview.dataSeries = [OCKDataSeries(values: [132], title: "Steps")]would be a natural follow-up — I intentionally did not add an unbuilt test file to avoid manual.pbxprojedits I couldn't verify.Scope
Single-file change to
OCKGraphable.swift. No public API changes, no behavior change for existing multi-point charts.