/swift-charts-skills:swift-charts-dynamic-maskingfrom swift-charts-skills
Use this skill when a Swift Charts chart should show part of its data at full strength and the rest dimmed or hidden: the TradingView-style scrub that keeps everything left of the finger bright, a selected range highlighted, actual versus forecast drawn from one line, a reveal up to a date. Also use it for the parts that effect is built from — chartXSelection and snapping its value, RuleMark and annotation for the selection, ChartContent.mask with RectangleMark, layered LinePlot / AreaPlot or LineMark copies and their series — and for the bugs they cause: a diagonal line joining the end of a chart back to its start, half-cut first and last points, a chart that rescales while dragging, a tooltip naming the wrong day, data filtered on every drag. iOS 16 to the current SDK. Not for picking a chart type, axis or legend styling, pie charts, Chart3D, scrolling charts, or charts drawn without Swift Charts.
Ships in swift-charts-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Never change the data to show part of it. Plot complete copies of the same data and change only what a mask reveals and how opaque each copy is. The selection then moves one rectangle edge and one opacity; the marks, the scales and the chart's geometry stay put.
Anton Gubarenko's article SwiftUI Charts: Dynamic Masking builds this effect
step by step (references/sources.md).
This skill keeps its composition, changes the parts the repository's probe
found drawing wrong, and grounds every rule in Apple's sessions, the documentation,
the SDK, or that measurement.
references/masking-code.mdreferences/measured-behavior.mdreferences/api-availability.mdreferences/selection-state-matrix.mdreferences/recommendation-format.mdreferences/sources.mdreferences/recommendation-format.md).
"Make the chart do the TradingView thing" before a plan exists is a request for the plan.LinePlot and AreaPlot need iOS 18, chartXSelection iOS 17;
below that there is a marks-and-overlay version, not a guess.measured-behavior.md.
Anything else is labelled inference.Bottom to top, in declaration order:
| Layer | Data | series: | Mask | Opacity | VoiceOver |
|---|---|---|---|---|---|
| Dimmed line | all | "Dimmed" | none | 0 with no selection, about 0.25 with one | hidden |
| Area | all | — | active region | about 0.3 | hidden |
| Active line | all | "Active" | active region | 1 | reads this copy |
| Rule and annotation | the matched element | — | none | — | — |
CHART007).series:.
Marks with the same series are drawn as one line (LineMark documentation),
and two copies without a series are one series:
Swift Charts joins the end of the first back to the start of the second.
A different constant color does not separate them
(Measured §1; scanner CHART001).
The same goes for any two line plots in a chart, whatever their data:
a solid half and a dashed half without series drew as one solid line
(Measured §1; CHART010)..accessibilityHidden(true)
(inference — VoiceOver output was not measured; CHART006).zIndex layering (WWDC24 10155, 11:34 and 11:45).
The selection talk keeps its RuleMark behind the lines with a negative zIndex
(WWDC23 10037, 6:09; zIndex is iOS 17).ChartContent.mask(content:) takes chart content (iOS 16),
so the mask is drawn in data space: RectangleMark(xStart:xEnd:) with no y
spans the plot's full height.
No pixel conversion, no GeometryReader.RectangleMark, not RectanglePlot(data, …).
A plot with constant bounds draws one identical rectangle per element;
the masked pixels are the same (Measured §2; CHART004).CHART003).
Pad the x domain in data units (half the spacing between points)
and mask from domain.lowerBound to the selection,
or to domain.upperBound when nothing is selected:
0 px differ from the unmasked chart..plotDimension(startPadding:endPadding:)) with a mask that starts
well before the data also works, but only because the domain is explicit.LinearGradient has two stops at the cutoff's position between
the first and the last point.
Stops placed by position land on their points (Measured §5);
the hard stop itself is inference, not measured.
A gradient cannot change dash, width or symbols past the cutoff — that needs masks.chartXSelection(value:) (iOS 17) recognizes the gesture and writes the
selected x value to a binding;
chartOverlay with a gesture is the older route (WWDC23 10037, 5:26 and 5:34).
On macOS the default selection gesture is hover (6:59):
the dimming follows the pointer with no click.
What the binding holds after the finger lifts was not measured here and the talk
does not say; verify it (state S8) before promising either behavior.RuleMark at a raw value past the data widens an automatic domain,
so the whole chart rescales mid-drag (Measured §3; CHART005).
Give the chart an explicit chartXScale(domain:) either way.CHART008).RuleMark (6:03) with an annotation
(6:16) whose overflowResolution fits x to the chart and disables y,
so it can sit above the plot (6:32–6:48; iOS 17).chartXSelection(range:) — two fingers on iOS, a drag on macOS
(7:07–7:18). Snap both ends; the mask runs from one to the other.DragGesture in chartOverlay,
subtracting the plot frame's origin before proxy.value(atX:)
(WWDC22 10137, 19:17–20:47).
plotAreaFrame is deprecated from iOS 17 in favor of plotFrame;
at an iOS 16 deployment target it compiles without a warning,
and from iOS 17 the compiler warns (checked with swiftc -typecheck).CHART002):
it rebuilds every mark per drag event and, with an automatic domain,
rescales the chart as the slice shrinks.LinePlot and AreaPlot take the whole collection
and key paths (WWDC24 10155, 0:51 and 10:21) and suit this effect,
whose copies are uniformly styled.
Constant plot arguments such as series: .value("Layer", "Dimmed") are iOS 18 too.ForEach with LineMark(x:y:series:) and AreaMark,
each ForEach masked as a whole.
Rendered on macOS, it looked the same as the plot version
(compared by eye, not by the committed probe).references/masking-code.md has each one compiled:
Preflight.
xcodebuild -version; the app's deployment target
(the scan reports ios_deployment_targets); the project's own agent
instructions (AGENTS.md, CLAUDE.md).
Report the toolchain in the plan.
Where xcodebuild cannot run (a sandbox that blocks its cache),
xcrun --sdk iphoneos --show-sdk-version and the header of charts_sdk_check.py
still name the SDK — report those, and say xcodebuild was unavailable.
Scan and check:
python3 scripts/charts_scan.py <project-root> --format json > "$TMPDIR/charts-scan.json"
python3 scripts/charts_scan.py <project-root> --format markdown
python3 scripts/charts_sdk_check.py # iOS floor of every API below
The scan skips dependencies and hidden directories. Its matches are heuristics: read the chart before a finding becomes an item.
Plan with references/recommendation-format.md:
correctness first (CHART001, 003, 005, 007, 008, 010),
then the technique itself (replace slicing or a hand-rolled gesture),
then polish (CHART004, 006, gradients, the popover).
Mark anything above the deployment target with the gate it needs,
or plan the marks-and-overlay version.
Ask which item IDs to apply.
charts_scan.py; the resolved findings should be gone.references/selection-state-matrix.md that the change touches.
Give the chart an initialSelection parameter
(references/masking-code.md › Pinning a state)
so previews and snapshot tests can render each state without a gesture.
States not rendered are reported as not verified.Chart view with a SwiftUI .mask or .clipShape:
that masks axes and gridlines too, and needs plot coordinates the chart
already has (inference).LinePlot, AreaPlot or constant PlottableProjection values
below iOS 18, or chartXSelection below iOS 17, without an if #available gate.evals/evals.json (opens in a new tab)evals/files/ActivityTrend/ActivityTrend.xcodeproj/project.pbxproj (opens in a new tab)evals/files/ActivityTrend/ActivityTrend/TrendChart.swift (opens in a new tab)evals/files/Forecast/Forecast.xcodeproj/project.pbxproj (opens in a new tab)evals/files/Forecast/Forecast/BalanceChart.swift (opens in a new tab)evals/files/SleepChart/Package.swift (opens in a new tab)evals/files/SleepChart/Sources/SleepChart/SleepHistory.swift (opens in a new tab)evals/files/StepsScrubber/StepsScrubber.xcodeproj/project.pbxproj (opens in a new tab)evals/files/StepsScrubber/StepsScrubber/StepsChart.swift (opens in a new tab)evals/files/TooltipDay/TooltipDay.xcodeproj/project.pbxproj (opens in a new tab)evals/files/TooltipDay/TooltipDay/MoodChart.swift (opens in a new tab)evals/trigger-evals.json (opens in a new tab)references/api-availability.md (opens in a new tab)references/masking-code.md (opens in a new tab)references/measured-behavior.md (opens in a new tab)references/recommendation-format.md (opens in a new tab)references/selection-state-matrix.md (opens in a new tab)references/sources.md (opens in a new tab)scripts/charts_scan.py (opens in a new tab)scripts/charts_sdk_check.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub alexey1312/swift-charts-agent-skill --plugin swift-charts-skills2 skills in this plugin