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

WIP: Rework timeStuffs to allow time formats to be specified #517

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions src/opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,24 @@ export const wholeIncrs = oneIncrs.filter(onlyWhole);

export const numIncrs = decIncrs.concat(oneIncrs);

const NL = "\n";
export const NL = "\n";

const yyyy = "{YYYY}";
const NLyyyy = NL + yyyy;
const md = "{M}/{D}";
const NLmd = NL + md;
const NLmdyy = NLmd + "/{YY}";
const _ = null;

const aa = "{aa}";
const hmm = "{h}:{mm}";
const hmmaa = hmm + aa;
const NLhmmaa = NL + hmmaa;
const ss = ":{ss}";
export function genTimeStuffs(ms, opts) {
opts = opts || {};
const yyyy = opts.YYYY || "{YYYY}";
const NLyyyy = opts.NLyyyy || NL + yyyy;
const md = opts.md || "{M}/{D}";
const NLmd = opts.NLmd || NL + md;
const NLmdyy = opts.NLmdyy || NLmd + "/{YY}";

const _ = null;
const aa = opts.aa || "{aa}";
const hmm = opts.hmm || "{h}:{mm}";
const hmmaa = opts.hmmaa || hmm + aa;
const NLhmmaa = opts.NLhmmaa || NL + hmmaa;
const ss = opts.ss || ":{ss}";

function genTimeStuffs(ms) {
let s = ms * 1e3,
m = s * 60,
h = m * 60,
Expand Down Expand Up @@ -243,9 +244,6 @@ function genTimeStuffs(ms) {
];
}

export const [ timeIncrsMs, _timeAxisStampsMs, timeAxisSplitsMs ] = FEAT_TIME && genTimeStuffs(1);
export const [ timeIncrsS, _timeAxisStampsS, timeAxisSplitsS ] = FEAT_TIME && genTimeStuffs(1e-3);

// base 2
const binIncrs = genIncrs(2, -53, 53, [1]);

Expand Down Expand Up @@ -700,4 +698,4 @@ export const xScaleOpts = {
export const yScaleOpts = assign({}, xScaleOpts, {
time: false,
ori: 1,
});
});
14 changes: 5 additions & 9 deletions src/uPlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ import {

clampScale,

timeIncrsMs,
timeIncrsS,

wholeIncrs,
numIncrs,
timeAxisVal,
Expand All @@ -152,21 +149,17 @@ import {
timeSeriesLabel,
numSeriesLabel,

timeAxisSplitsMs,
timeAxisSplitsS,

numAxisSplits,
logAxisSplits,
asinhAxisSplits,

timeAxisStamps,

_timeAxisStampsMs,
_timeAxisStampsS,

timeSeriesStamp,
_timeSeriesStamp,

genTimeStuffs,

legendOpts,
} from './opts';

Expand Down Expand Up @@ -460,6 +453,9 @@ export default function uPlot(opts, data, then) {
const _tzDate = FEAT_TIME && (opts.tzDate || (ts => new Date(round(ts / ms))));
const _fmtDate = FEAT_TIME && (opts.fmtDate || fmtDate);

const [ timeIncrsMs, _timeAxisStampsMs, timeAxisSplitsMs ] = FEAT_TIME && genTimeStuffs(1, opts.timeFormats);
const [ timeIncrsS, _timeAxisStampsS, timeAxisSplitsS ] = FEAT_TIME && genTimeStuffs(1e-3, opts.timeFormats);

const _timeAxisSplits = FEAT_TIME && (ms == 1 ? timeAxisSplitsMs(_tzDate) : timeAxisSplitsS(_tzDate));
const _timeAxisVals = FEAT_TIME && timeAxisVals(_tzDate, timeAxisStamps((ms == 1 ? _timeAxisStampsMs : _timeAxisStampsS), _fmtDate));
const _timeSeriesVal = FEAT_TIME && timeSeriesVal(_tzDate, timeSeriesStamp(_timeSeriesStamp, _fmtDate));
Expand Down