Merged
Conversation
When dates are stored as UTC (common for APIs and CSVs with autoType), the existing `time` scale renders them in the local timezone, causing visible shifts — e.g. midnight UTC appears as 01:00 BST. This adds explicit `type: 'utc'` support using d3's scaleUtc and UTC-aware intervals/formatting, fixing tick alignment for UTC data. Closes #120, closes #214 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
✅ Deploy Preview for svelteplot ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
|
Thanks for adding new features! One important thing missing here is documentation. The scales page should ideally mention the |
Collaborator
Author
Fair point. I will add that as soon as I am able. |
Fix intro text that incorrectly stated SveltePlot defaults to UTC (it defaults to `time`), and add a new UTC scale subsection with a side-by-side comparison example showing the difference between `time` and `utc` scale types. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Resolve conflict in autoTimeFormat.ts: keep utc parameter support from feature branch and formatter variable naming from main. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
@ljodea I tweaked your example a bit so that it also shows a difference for me (assuming it looked different for you). I'm on UTC+1 so an intra-day axis range is a safer choice
|
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
type: 'utc'support for x/y scales, fixing timezone-shifted tick rendering when dates are stored as UTC (common for APIs, CSVs withautoType)scaleUtcand UTC-aware intervals/formatting (timeZone: 'UTC'inIntl.DateTimeFormat)isTemporalScale()helper to eliminate=== 'time'checks across 8 call sites, covering both'time'and'utc'Usage
What changed
src/lib/types/scale.ts'utc'toScaleTypeunionsrc/lib/helpers/typeChecks.tsisTemporalScale()helpersrc/lib/constants.ts'utc'toVALID_SCALE_TYPES.xand.ysrc/lib/helpers/autoScales.tsscaleUtc, add to map, update nice conditionsrc/lib/helpers/autoTicks.tsscaleType === 'utc'src/lib/helpers/autoTimeFormat.tstimeZone: 'UTC'for UTC scalessrc/lib/marks/AxisX.svelte'utc'type in tick formattingsrc/lib/marks/AxisY.svelte'utc'type in tick formattingsrc/lib/helpers/scales.tssrc/lib/marks/helpers/Regression.svelteNot changed (and why)
inferScaleType()— Keeps returning'time'for dates. UTC must be explicit (type: 'utc'). No breaking change.shift.ts,group.ts,bin.ts— Use numeric intervals ormaybeTimeIntervalfor relative shifts. Separate concern.Test plan
VALID_SCALE_TYPES.x/yinclude'utc'isTemporalScale()returns correct values for'time','utc','linear','band'inferScaleTypereturns'time'(not'utc') for date values — regression checkmaybeInterval('month', 'utc')returns UTC interval (checked viaintervalTypesymbol)autoTimeFormatwith UTC scale formats dates in UTC timezone<Plot x={{ type: 'utc' }}>with<AxisX>produces visible tick labels'3 months') render correctlysvelte-checkclean,prettiercleanCloses #120, closes #214
🤖 Generated with Claude Code