wiki-plugin-rcntimeline 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -66,7 +66,8 @@
66
66
  return y + (Date.UTC(y, mo, day) - a) / (b - a)
67
67
  }
68
68
  function fmt (y) {
69
- const yr = Math.floor(y), d = new Date(Date.UTC(yr, 0, 1) + (y - yr) * (Date.UTC(yr + 1, 0, 1) - Date.UTC(yr, 0, 1)))
69
+ const yr = Math.floor(y), ms = Date.UTC(yr, 0, 1) + (y - yr) * (Date.UTC(yr + 1, 0, 1) - Date.UTC(yr, 0, 1))
70
+ const d = new Date(Math.round(ms / 864e5) * 864e5) // to the nearest day, so Feb 1 never prints as Jan 31
70
71
  return MON_NAME[d.getUTCMonth()] + ' ' + d.getUTCDate() + ' ' + d.getUTCFullYear()
71
72
  }
72
73
  const relWords = r => Array.isArray(r) ? 'one of ' + r.join(', ') : (r || 'before')
@@ -158,11 +159,22 @@
158
159
  // A tick step that gives four to seven labels across the span.
159
160
  function ticks (lo, hi) {
160
161
  const span = hi - lo
161
- const steps = [1 / 12, 0.25, 0.5, 1, 2, 5, 10, 20, 25, 50, 100]
162
+ const D = 1 / 365.25, steps = [D, 2 * D, 7 * D, 14 * D, 1 / 12, 0.25, 0.5, 1, 2, 5, 10, 20, 25, 50, 100]
162
163
  const step = steps.find(s => span / s <= 7) || 100
163
164
  const out = []
165
+ if (step >= 1 / 12 && step < 1) { // months on real month starts, not twelfths of a year
166
+ const every = Math.round(step * 12)
167
+ for (let y = Math.floor(lo), mo = 0; y <= Math.ceil(hi); mo += every) {
168
+ if (mo >= 12) { y += Math.floor(mo / 12); mo %= 12 }
169
+ const t = frac(y, mo, 1)
170
+ if (t > hi + 1e-9) break
171
+ if (t >= lo - 1e-9) out.push({ t, label: fmt(t).replace(/ \d+ /, ' ') })
172
+ }
173
+ return out
174
+ }
164
175
  for (let t = Math.ceil(lo / step) * step; t <= hi + 1e-9; t += step) {
165
- out.push({ t, label: step >= 1 ? String(Math.round(t)) : fmt(t).replace(/ \d+ /, ' ') })
176
+ // years, or days and weeks as "Mon D"
177
+ out.push({ t, label: step >= 1 ? String(Math.round(t)) : step >= 1 / 12 ? fmt(t).replace(/ \d+ /, ' ') : fmt(t).replace(/ \d+$/, '') })
166
178
  }
167
179
  return out
168
180
  }
@@ -281,7 +293,8 @@
281
293
  const ivs = lit ? m.intervals.filter(v => lit.has(String(v.id))) : []
282
294
  if (!ivs.length) return null
283
295
  let lo = Math.min(...ivs.map(v => v.s - v.sf)), hi = Math.max(...ivs.map(v => v.e + v.ef))
284
- const span = Math.max(hi - lo, 3), mid = (lo + hi) / 2
296
+ // at least 3 years, unless the bars are much shorter: then zoom in to them, down to 2 days (same rule as the tool)
297
+ const ext = hi - lo, span = ext > 0 ? Math.max(ext, Math.min(3, 4 * ext), 2 / 365.25) : 3, mid = (lo + hi) / 2
285
298
  return { lo: mid - span * 0.62, hi: mid + span * 0.62 }
286
299
  }
287
300
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-rcntimeline",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Federated Wiki plugin: a small RCN timeline on a page — intervals with fuzzy edges, the links between them, a date axis; each bar opens its page",
5
5
  "keywords": ["wiki", "federated wiki", "plugin", "rcn", "timeline"],
6
6
  "author": "RCN Network <rcn@relocalizecreativity.net>",