diff --git a/src/opts.js b/src/opts.js index 84349e5e..dedadbf3 100644 --- a/src/opts.js +++ b/src/opts.js @@ -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, @@ -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]); @@ -700,4 +698,4 @@ export const xScaleOpts = { export const yScaleOpts = assign({}, xScaleOpts, { time: false, ori: 1, -}); \ No newline at end of file +}); diff --git a/src/uPlot.js b/src/uPlot.js index 75c74e8d..b2e4aa1d 100644 --- a/src/uPlot.js +++ b/src/uPlot.js @@ -135,9 +135,6 @@ import { clampScale, - timeIncrsMs, - timeIncrsS, - wholeIncrs, numIncrs, timeAxisVal, @@ -152,21 +149,17 @@ import { timeSeriesLabel, numSeriesLabel, - timeAxisSplitsMs, - timeAxisSplitsS, - numAxisSplits, logAxisSplits, asinhAxisSplits, timeAxisStamps, - _timeAxisStampsMs, - _timeAxisStampsS, - timeSeriesStamp, _timeSeriesStamp, + genTimeStuffs, + legendOpts, } from './opts'; @@ -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));