wiki-plugin-rcntimeline 0.3.5 → 0.3.6
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.
- package/README.md +1 -0
- package/client/rcntimeline.js +58 -5
- package/package.json +19 -4
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ and restart the wiki. The Factory then offers **RCN Timeline**.
|
|
|
30
30
|
|
|
31
31
|
- `timeline` is the RCN Timeline's own export format, so a timeline saved from the tool drops straight in. Fields the plugin does not use (`coops`, say) are left alone.
|
|
32
32
|
- `page` names the wiki page a bar opens. A bar without one is not a link.
|
|
33
|
+
- `bands`, `band` and `sort` (optional): a timeline that names its story bands gets a **Rows: By band · By time** switch under the drawing. By band, each band's bars sit under its name; by time, one bar per row, earliest at the top. The file's `sort` is the default; the reader's choice is not saved.
|
|
33
34
|
- `rel` may be one relation (`meets`) or a list (`["before", "meets"]`, "one of"), drawn dashed. Lists are not built in the tool yet; the plugin accepts them so it will not break when they are.
|
|
34
35
|
- `text`: the first line is the caption; the rest lists the intervals and links in words, for search and for a wiki without this plugin.
|
|
35
36
|
- An item with no `timeline` — a fresh one from the Factory — is drawn from its text in the tool's own sentence form: `Label = Jan 2020 .. Jun 2021`, or `Label = 1970 .. 2026`.
|
package/client/rcntimeline.js
CHANGED
|
@@ -77,7 +77,9 @@
|
|
|
77
77
|
// The item's own intervals and links, as stored (or read from its text).
|
|
78
78
|
function rawOf (item) {
|
|
79
79
|
if (item.timeline && Array.isArray(item.timeline.intervals)) {
|
|
80
|
-
|
|
80
|
+
const t = item.timeline
|
|
81
|
+
return Object.assign({ intervals: t.intervals, links: t.links || [] },
|
|
82
|
+
Array.isArray(t.bands) && t.bands.length ? { bands: t.bands } : {}, t.sort ? { sort: t.sort } : {})
|
|
81
83
|
}
|
|
82
84
|
const ivs = []
|
|
83
85
|
String(item.text || '').split('\n').forEach((line, i) => {
|
|
@@ -134,10 +136,23 @@
|
|
|
134
136
|
return out
|
|
135
137
|
}
|
|
136
138
|
|
|
137
|
-
function model (item, $item) { return normalize(effective($item, item)) }
|
|
139
|
+
function model (item, $item) { return normalize(effective($item, item), rowsHow($item, item)) }
|
|
140
|
+
|
|
141
|
+
// How the rows are arranged: 'band' (story bands, each under its name — only
|
|
142
|
+
// when the timeline names bands), 'time' (one row per bar, earliest first), or
|
|
143
|
+
// null (the rows as the file has them). The reader's choice is kept on the
|
|
144
|
+
// item's element for this visit; the file's own "sort" is the default.
|
|
145
|
+
function rowsHow ($item, item) {
|
|
146
|
+
const t = item.timeline || {}, el = $item && $item.get(0)
|
|
147
|
+
const how = (el && el.rcntRows) || t.sort || null
|
|
148
|
+
return how === 'band' && !(Array.isArray(t.bands) && t.bands.length) ? null : how
|
|
149
|
+
}
|
|
138
150
|
|
|
139
151
|
// Dates as fractional years, lanes packed top to bottom.
|
|
140
|
-
|
|
152
|
+
// how 'time': one lane per bar in date order. how 'band': each band (in the
|
|
153
|
+
// file's order, then "Other") gets a heading lane with its name, then the rows
|
|
154
|
+
// its bars use, in their order. heads: [{lane, label}].
|
|
155
|
+
function normalize (raw, how) {
|
|
141
156
|
const ivs = raw.intervals, links = raw.links
|
|
142
157
|
const out = []
|
|
143
158
|
ivs.forEach((v, i) => {
|
|
@@ -150,10 +165,30 @@
|
|
|
150
165
|
color: v.color || PALETTE[i % PALETTE.length], row: v.row == null ? i : v.row
|
|
151
166
|
}))
|
|
152
167
|
})
|
|
168
|
+
if (how === 'time') {
|
|
169
|
+
out.slice().sort((a, b) => a.s - b.s || a.e - b.e).forEach((v, k) => { v.lane = k })
|
|
170
|
+
return { intervals: out, links, lanes: out.length, heads: [] }
|
|
171
|
+
}
|
|
172
|
+
if (how === 'band' && raw.bands && raw.bands.length) {
|
|
173
|
+
const ids = raw.bands.map(b => b.id), groups = raw.bands.map(b => ({ label: b.label || b.id, ivs: [] }))
|
|
174
|
+
const other = { label: 'Other', ivs: [] }
|
|
175
|
+
out.forEach(v => { const k = ids.indexOf(v.band); (k < 0 ? other : groups[k]).ivs.push(v) })
|
|
176
|
+
if (other.ivs.length) groups.push(other)
|
|
177
|
+
const heads = []
|
|
178
|
+
let lane = 0
|
|
179
|
+
groups.forEach(g => {
|
|
180
|
+
if (!g.ivs.length) return
|
|
181
|
+
heads.push({ lane: lane++, label: g.label })
|
|
182
|
+
const rows = Array.from(new Set(g.ivs.map(v => v.row))).sort((a, b) => a - b)
|
|
183
|
+
g.ivs.forEach(v => { v.lane = lane + rows.indexOf(v.row) })
|
|
184
|
+
lane += rows.length
|
|
185
|
+
})
|
|
186
|
+
return { intervals: out, links, lanes: lane, heads }
|
|
187
|
+
}
|
|
153
188
|
// Lanes in use, packed top to bottom in their original order.
|
|
154
189
|
const lanes = Array.from(new Set(out.map(v => v.row))).sort((a, b) => a - b)
|
|
155
190
|
out.forEach(v => { v.lane = lanes.indexOf(v.row) })
|
|
156
|
-
return { intervals: out, links, lanes: lanes.length }
|
|
191
|
+
return { intervals: out, links, lanes: lanes.length, heads: [] }
|
|
157
192
|
}
|
|
158
193
|
|
|
159
194
|
// A tick step that gives four to seven labels across the span.
|
|
@@ -213,6 +248,11 @@
|
|
|
213
248
|
parts.push(`<text x="${x(k.t) + 3}" y="${AXIS_H - 8}" font-size="10" fill="#94a3b8">${esc(k.label)}</text>`)
|
|
214
249
|
})
|
|
215
250
|
parts.push(`<line x1="0" y1="${AXIS_H - 4}" x2="${W}" y2="${AXIS_H - 4}" stroke="#e2e8f0"/>`)
|
|
251
|
+
// band names, on their own lane at the left edge
|
|
252
|
+
;(m.heads || []).forEach(h => {
|
|
253
|
+
parts.push(`<line x1="0" y1="${yMid(h.lane) + 7}" x2="${W}" y2="${yMid(h.lane) + 7}" stroke="#cbd5e1"/>`)
|
|
254
|
+
parts.push(`<text x="${PAD}" y="${yMid(h.lane) + 3}" font-size="10" font-weight="700" letter-spacing=".06em" fill="#475569">${esc(h.label.toUpperCase())}</text>`)
|
|
255
|
+
})
|
|
216
256
|
|
|
217
257
|
// bars: the fuzz shoulders fade in and out, the core is solid
|
|
218
258
|
m.intervals.forEach((v, i) => {
|
|
@@ -518,6 +558,16 @@
|
|
|
518
558
|
if (p && p.catch) p.catch(() => fin(false))
|
|
519
559
|
}
|
|
520
560
|
|
|
561
|
+
// Rows: By band | By time — only for a timeline that names story bands.
|
|
562
|
+
function rowsBar ($item, item) {
|
|
563
|
+
const t = item.timeline || {}
|
|
564
|
+
if (!(Array.isArray(t.bands) && t.bands.length)) return ''
|
|
565
|
+
const how = rowsHow($item, item) || 'file'
|
|
566
|
+
const b = (h, label, title) => `<button class="rcnt-rows" data-how="${h}" title="${title}" style="cursor:pointer;font-size:12px;padding:2px 8px;${how === h ? 'background:#dbeafe;color:#1d4ed8;font-weight:600;' : ''}">${label}</button>`
|
|
567
|
+
return `<div style="display:flex;gap:6px;align-items:center;justify-content:center;padding:6px 0 0;font-size:12px;color:#475569">Rows:
|
|
568
|
+
${b('band', 'By band', 'One band of rows per story, each under its name')}${b('time', 'By time', 'One row per bar, earliest at the top')}</div>`
|
|
569
|
+
}
|
|
570
|
+
|
|
521
571
|
function walkBar (item) {
|
|
522
572
|
const ws = walkList(item)
|
|
523
573
|
if (!ws.length) return ''
|
|
@@ -667,7 +717,7 @@
|
|
|
667
717
|
: 'Collected from ' + collect($item).length + ' timeline(s) to the left.'}</p>` : ''
|
|
668
718
|
$item.append(`<div style="background:#f5f5f5;padding:8px;">
|
|
669
719
|
<div class="rcnt-canvas" style="background:#fff;border:1px solid #ddd;overflow-x:auto"></div>
|
|
670
|
-
${walkBar(item)}
|
|
720
|
+
${rowsBar($item, item)}${walkBar(item)}
|
|
671
721
|
<p class="caption" style="margin:4px 0 0;">${cap}</p>${note}
|
|
672
722
|
<div style="padding:6px 0 0;text-align:center;">${controls}<button class="rcnt-open" style="cursor:pointer;">Open in RCN Timeline ↗</button></div></div>`)
|
|
673
723
|
// Width is known only once the item is in the page. A walk step draws just
|
|
@@ -695,6 +745,8 @@
|
|
|
695
745
|
links: raw.links
|
|
696
746
|
}
|
|
697
747
|
const doc = Object.assign({ name: caption(item) || 'Timeline' }, tl, walkList(item).length ? { walks: item.timeline.walks } : {})
|
|
748
|
+
// carry the file's own extras (story bands, sort, place/eip on the bars ride along already)
|
|
749
|
+
if (item.timeline && !lineupOn(item)) ['bands', 'sort', 'note'].forEach(k => { if (item.timeline[k] != null && doc[k] == null) doc[k] = item.timeline[k] })
|
|
698
750
|
const hash = '#tl=' + b64(JSON.stringify(doc))
|
|
699
751
|
// Open the window now, while the click still counts, and point it at the
|
|
700
752
|
// tool once we know which copy to use; otherwise popup blockers stop it.
|
|
@@ -826,6 +878,7 @@
|
|
|
826
878
|
bindWalk($item, item)
|
|
827
879
|
$item.on('click', '.rcnt-open', e => { e.stopPropagation(); openTool($item, item) })
|
|
828
880
|
$item.on('click', '.rcnt-refresh', e => { e.stopPropagation(); emit($item, item) })
|
|
881
|
+
$item.on('click', '.rcnt-rows', function (e) { e.stopPropagation(); $item.get(0).rcntRows = this.getAttribute('data-how'); emit($item, item) })
|
|
829
882
|
$item.on('click', '.rcnt-freeze', e => {
|
|
830
883
|
e.stopPropagation()
|
|
831
884
|
if (e.shiftKey) { if (item.frozen) { delete item.frozen; save($item, item) } return }
|
package/package.json
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wiki-plugin-rcntimeline",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
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
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"wiki",
|
|
7
|
+
"federated wiki",
|
|
8
|
+
"plugin",
|
|
9
|
+
"rcn",
|
|
10
|
+
"timeline"
|
|
11
|
+
],
|
|
6
12
|
"author": "RCN Network <rcn@relocalizecreativity.net>",
|
|
7
13
|
"license": "MIT",
|
|
8
14
|
"main": "index.js",
|
|
9
|
-
"files": [
|
|
10
|
-
|
|
15
|
+
"files": [
|
|
16
|
+
"client/rcntimeline.js",
|
|
17
|
+
"factory.json",
|
|
18
|
+
"index.js",
|
|
19
|
+
"pages",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/marpie1/rcn.git"
|
|
25
|
+
},
|
|
11
26
|
"homepage": "https://github.com/marpie1/rcn/tree/master/wiki-plugin-rcntimeline"
|
|
12
27
|
}
|