Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: export ticker #61

Open
jwhitaker-swiftnav opened this issue Jan 16, 2023 · 1 comment
Open

Request: export ticker #61

jwhitaker-swiftnav opened this issue Jan 16, 2023 · 1 comment

Comments

@jwhitaker-swiftnav
Copy link

Hey guys,
Thanks for maintaining this.

Is there any chance of exporting ticker() from src/ticks? There are a few projects around that try to use this machinery to build a timezone-aware scale (e.g. https://github.com/yamass/d3-luxon/blob/main/src/scale/scaleZoned.js) . Without ticker being exported, these have to reimplement it from scratch.
I'm aware that you probably don't want it part of your stable API, but even exporting it from the internal module in src would be appreciated so users can swim with sharks if they accept the risk.

Thanks again!
Jarrad

@reubano
Copy link

reubano commented Jan 26, 2023

Check out my solution...

https://github.com/nerevu/d3-time/tree/571601395045d81b70b9e7d9ceee1b67b95ea2bd

let utcIntervals = {
    "hour": d3.utcHour,
    "day": d3.utcDay,
    "week": d3.utcWeek,
    "month": d3.utcMonth,
}

let localIntervals = {
    "hour": d3.timeHour,
    "day": d3.timeDay,
    "week": d3.timeWeek,
    "month": d3.timeMonth,
}

function getTZIntervals(tz) {
    return {
        "hour": d3time.timezoneHour(tz),
        "day": d3time.timezoneDay(tz),
        "week": d3time.timezoneWeek(tz),
        "month": d3time.timezoneMonth(tz),
    }
}

var tz = "America/Chicago"
var bin = "hour"

if (tz.toLowerCase().endsWith("utc")) {
    var interval = utcIntervals[bin];
} else if (tz) {
    var interval = getTZIntervals(tz)[bin];
} else {
    var interval = localIntervals[bin];
}

var binned = interval(new Date());
var converted = d3time.convertDate(binned, tz);

I used my forked time lib to create a timezone aware scale for Plot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants