4

d3.time.scaleには、マルチスケールの時間形式を使用するきちんとした時間フォーマッタがあります。マルチスケールの時間形式を指定する API またはその他の方法 (まだ) はありますか?

新しい を作成できることはわかっていますが、それはd3.time.formatマルチスケールではありません。

ありがとう。

4

2 に答える 2

10

The multi-scale time format isn’t exposed as a public API outside of the standard one returned by a d3.time.scale’s tickFormat method.

That said, the implementation itself is fairly simple, so you could create your own multi-scale time format without a lot of work. The multi-scale time format is simply an ordered array of time formats, each of which has an associated test function. The first test function that returns true determines which time format is used.

The time format used by d3.time.scale has the following formats (taken from time/scale.js), specified in reverse order:

  [".%L", function(d) { return d.getMilliseconds(); }],
  [":%S", function(d) { return d.getSeconds(); }],
  ["%I:%M", function(d) { return d.getMinutes(); }],
  ["%I %p", function(d) { return d.getHours(); }],
  ["%a %d", function(d) { return d.getDay() && d.getDate() != 1; }],
  ["%b %d", function(d) { return d.getDate() != 1; }],
  ["%B", function(d) { return d.getMonth(); }],
  ["%Y", d3_true]

So, for example, if the time has a non-zero milliseconds field, then the ".%L" format is used; otherwise, if it has a non-zero seconds field, then ":%S" is used; and so on.

于 2012-08-04T23:37:20.740 に答える