wiki-plugin-rcngraph 0.1.22 → 0.1.23
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/client/rcngraph.js +116 -4
- package/package.json +1 -1
- package/pages/about-rcngraph-plugin +16 -0
package/client/rcngraph.js
CHANGED
|
@@ -154,6 +154,80 @@
|
|
|
154
154
|
if (f.seen.has(id)) return 0.42
|
|
155
155
|
return f.click ? 0.3 : 0.13
|
|
156
156
|
}
|
|
157
|
+
// Whole or Step, item by item (Nov 17 2026), the same choice as the explorer's
|
|
158
|
+
// panes (tools/rcn-together.html). Step: a walk — this item's or one it
|
|
159
|
+
// follows — zooms the item to each step. Whole: the item shows the whole
|
|
160
|
+
// timeline, map or drawing and stays where you put it; steps light things in
|
|
161
|
+
// place, and you pan and zoom by hand. A click elsewhere still brings the item
|
|
162
|
+
// to what was clicked. ⤢ shows the whole thing again. Each kind of item
|
|
163
|
+
// (timeline, map, sketch) remembers its last choice in this browser.
|
|
164
|
+
const FRAME_KEY = 'rcnLineupFrame'
|
|
165
|
+
const frameSaved = () => { try { return JSON.parse(localStorage.getItem(FRAME_KEY)) || {} } catch (e) { return {} } }
|
|
166
|
+
R.frame = el => el.rcnFrame || (el.rcnFrame = frameSaved()[el.rcnKind] === 'whole' ? 'whole' : 'step')
|
|
167
|
+
R.whole = el => R.frame(el) === 'whole'
|
|
168
|
+
const frameHTML = fr => {
|
|
169
|
+
const b = 'font:inherit;font-size:12px;border:0;padding:2px 8px;cursor:pointer;'
|
|
170
|
+
const on = 'background:#4f46e5;color:#fff;', off = 'background:#fff;color:#334155;'
|
|
171
|
+
return `<button data-fr="whole" style="${b}${fr === 'whole' ? on : off}" title="Show the whole thing; a walk lights things where they are and leaves the view to you. Drag to pan, pinch or ⌘-scroll to zoom.">Whole</button>` +
|
|
172
|
+
`<button data-fr="step" style="${b}border-left:1px solid #cbd5e1;${fr === 'step' ? on : off}" title="Zoom in on each step of a walk">Step</button>` +
|
|
173
|
+
(fr === 'whole' ? `<button data-fr="fit" style="${b}border-left:1px solid #cbd5e1;${off}" title="Show the whole thing again">⤢</button>` : '')
|
|
174
|
+
}
|
|
175
|
+
// The switch, for an item's button row. kind: 'timeline' | 'map' | 'sketch'.
|
|
176
|
+
R.frameSwitch = kind => `<span class="rcn-frame" data-kind="${kind}" style="display:inline-flex;vertical-align:middle;border:1px solid #cbd5e1;border-radius:6px;overflow:hidden" role="group" aria-label="During a walk"></span>`
|
|
177
|
+
// Wire an item's switch. fn(frame, fit) redraws the item for the new choice.
|
|
178
|
+
R.bindFrame = function (el, kind, fn) {
|
|
179
|
+
el.rcnKind = kind
|
|
180
|
+
const draw = () => el.querySelectorAll('.rcn-frame').forEach(s => { s.innerHTML = frameHTML(R.frame(el)) })
|
|
181
|
+
draw()
|
|
182
|
+
if (el.rcnFrameBound) { el.rcnFrameFn = fn; return }
|
|
183
|
+
el.rcnFrameBound = true; el.rcnFrameFn = fn
|
|
184
|
+
el.addEventListener('click', e => {
|
|
185
|
+
const b = e.target.closest && e.target.closest('.rcn-frame button')
|
|
186
|
+
if (!b) return
|
|
187
|
+
e.stopPropagation()
|
|
188
|
+
const v = b.dataset.fr, was = R.frame(el)
|
|
189
|
+
if (v !== 'fit') {
|
|
190
|
+
el.rcnFrame = v
|
|
191
|
+
const s = frameSaved(); s[kind] = v
|
|
192
|
+
try { localStorage.setItem(FRAME_KEY, JSON.stringify(s)) } catch (err) {}
|
|
193
|
+
}
|
|
194
|
+
el.querySelectorAll('.rcn-frame').forEach(s => { s.innerHTML = frameHTML(R.frame(el)) })
|
|
195
|
+
if (v === 'fit' || v !== was) try { el.rcnFrameFn(R.frame(el), v === 'fit') } catch (err) { console.warn('rcn-frame:', err) }
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
// Hand pan and zoom on an element, for items without their own (the timeline
|
|
199
|
+
// and the drawing; the map has Leaflet's). Only while on() says so. Drag pans,
|
|
200
|
+
// pinch or ⌘/Ctrl-scroll zooms about the pointer, double-click shows the whole.
|
|
201
|
+
// A drag swallows the click that ends it, so it never counts as a click on a box.
|
|
202
|
+
// h: {on(), pan(dxPx, dyPx), zoom(factor, xPx, yPx), reset()}; positions are
|
|
203
|
+
// relative to the element's top-left corner.
|
|
204
|
+
R.handView = function (box, h) {
|
|
205
|
+
if (box.rcnHand) { box.rcnHand = h; return }
|
|
206
|
+
box.rcnHand = h
|
|
207
|
+
let drag = null, moved = false
|
|
208
|
+
box.addEventListener('pointerdown', e => {
|
|
209
|
+
if (!box.rcnHand.on() || e.button !== 0) return
|
|
210
|
+
drag = { x: e.clientX, y: e.clientY, id: e.pointerId }; moved = false
|
|
211
|
+
})
|
|
212
|
+
box.addEventListener('pointermove', e => {
|
|
213
|
+
if (!drag || e.pointerId !== drag.id) return
|
|
214
|
+
const dx = e.clientX - drag.x, dy = e.clientY - drag.y
|
|
215
|
+
if (!moved && Math.hypot(dx, dy) < 4) return
|
|
216
|
+
if (!moved) { moved = true; try { box.setPointerCapture(e.pointerId) } catch (err) {} box.style.cursor = 'grabbing' }
|
|
217
|
+
drag.x = e.clientX; drag.y = e.clientY
|
|
218
|
+
box.rcnHand.pan(dx, dy)
|
|
219
|
+
})
|
|
220
|
+
const up = () => { if (drag) { drag = null; box.style.cursor = '' } }
|
|
221
|
+
box.addEventListener('pointerup', up); box.addEventListener('pointercancel', up)
|
|
222
|
+
box.addEventListener('click', e => { if (moved) { moved = false; e.stopPropagation(); e.preventDefault() } }, true)
|
|
223
|
+
box.addEventListener('wheel', e => {
|
|
224
|
+
if (!box.rcnHand.on() || !(e.ctrlKey || e.metaKey)) return // a plain scroll still scrolls the wiki page
|
|
225
|
+
e.preventDefault()
|
|
226
|
+
const r = box.getBoundingClientRect()
|
|
227
|
+
box.rcnHand.zoom(Math.exp(-e.deltaY * (e.deltaMode ? 0.05 : 0.002) * (e.ctrlKey ? 10 : 1)), e.clientX - r.left, e.clientY - r.top) // a pinch arrives as ctrl+wheel in small steps
|
|
228
|
+
}, { passive: false })
|
|
229
|
+
box.addEventListener('dblclick', e => { if (box.rcnHand.on()) { e.preventDefault(); e.stopPropagation(); box.rcnHand.reset() } }, true)
|
|
230
|
+
}
|
|
157
231
|
// "⧉ Open together": the Time Place Causality Explorer on an item's set file
|
|
158
232
|
// (item.set). A bare file name lives in the site's /assets/NDC/ folder beside
|
|
159
233
|
// the explorer and the full tools; a full address may point anywhere, and the
|
|
@@ -331,15 +405,19 @@
|
|
|
331
405
|
}
|
|
332
406
|
|
|
333
407
|
// i === null: no walk, everything back to normal.
|
|
408
|
+
// Whole (the Whole / Step switch, rcn-lineup-follow): steps light boxes where they
|
|
409
|
+
// are; the view is the whole drawing or wherever you have dragged and zoomed it.
|
|
410
|
+
const isWhole = $item => !!(RL && RL.whole && RL.whole($item.get(0)))
|
|
334
411
|
function showWalkStep($item, g, walk, i) {
|
|
335
412
|
const svg = $item.find('svg').get(0)
|
|
336
413
|
if (!svg) return
|
|
414
|
+
const hold = isWhole($item)
|
|
337
415
|
svg.querySelectorAll('.rcn-walk-ring').forEach(el => el.remove())
|
|
338
416
|
$item.find('.graph-box').css('max-height', i === null ? '280px' : 'none')
|
|
339
417
|
if (i === null) {
|
|
340
418
|
g.nodes.forEach(n => { const el = groupFor(svg, 'node', n.id); if (el) el.style.opacity = '' })
|
|
341
419
|
g.edges.forEach(e => { const el = groupFor(svg, 'edge', e.id); if (el) el.style.opacity = '' })
|
|
342
|
-
walkZoom(svg, null)
|
|
420
|
+
if (!hold) walkZoom(svg, null)
|
|
343
421
|
return
|
|
344
422
|
}
|
|
345
423
|
const seen = { nodes: new Set(), edges: new Set() }
|
|
@@ -358,7 +436,7 @@
|
|
|
358
436
|
const el = groupFor(svg, 'edge', e.id)
|
|
359
437
|
if (el) el.style.opacity = op('edges', String(e.id))
|
|
360
438
|
})
|
|
361
|
-
walkZoom(svg, lit ? [...lit.nodes].map(id => groupFor(svg, 'node', id)).filter(Boolean) : null)
|
|
439
|
+
if (!hold) walkZoom(svg, lit ? [...lit.nodes].map(id => groupFor(svg, 'node', id)).filter(Boolean) : null)
|
|
362
440
|
}
|
|
363
441
|
|
|
364
442
|
// Voice and speed are the listener's: kept in this browser, the same keys the Graph Tool uses.
|
|
@@ -519,7 +597,7 @@
|
|
|
519
597
|
const op = id => RL.op(f, String(id))
|
|
520
598
|
g.nodes.forEach(n => { const el = groupFor(svg, 'node', n.id); if (el) el.style.opacity = String(op(n.id)) })
|
|
521
599
|
g.edges.forEach(e => { const el = groupFor(svg, 'edge', e.id); if (el) el.style.opacity = String(Math.min(op(e.src), op(e.tgt))) })
|
|
522
|
-
walkZoom(svg, [...f.lit].map(id => groupFor(svg, 'node', id)).filter(Boolean))
|
|
600
|
+
if (!isWhole($item) || f.click) walkZoom(svg, [...f.lit].map(id => groupFor(svg, 'node', id)).filter(Boolean)) // a click brings it into view even on Whole
|
|
523
601
|
}
|
|
524
602
|
|
|
525
603
|
function esc(s) { return String(s).replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c])) }
|
|
@@ -535,6 +613,7 @@
|
|
|
535
613
|
<div style="padding:6px 0 0;display:flex;gap:6px;justify-content:center;">
|
|
536
614
|
<button class="edit-graph" style="cursor:pointer;">Edit in Graph Tool ↗</button>
|
|
537
615
|
${RL ? RL.togetherButton(item) : ''}
|
|
616
|
+
${RL && RL.frameSwitch ? RL.frameSwitch('sketch') : ''}
|
|
538
617
|
</div>
|
|
539
618
|
${buildBar(item)}
|
|
540
619
|
${walkBar(item)}
|
|
@@ -745,7 +824,7 @@
|
|
|
745
824
|
})
|
|
746
825
|
$item.on('dblclick', e => {
|
|
747
826
|
// Stepping a build or a walk is quick clicking — never let it open the editor.
|
|
748
|
-
if ($(e.target).closest('.build-bar, .walk-bar').length) return
|
|
827
|
+
if ($(e.target).closest('.build-bar, .walk-bar, .rcn-frame').length) return
|
|
749
828
|
wiki.textEditor($item, item)
|
|
750
829
|
})
|
|
751
830
|
// Build playback. Namespaced and reset, because a save re-runs bind.
|
|
@@ -841,6 +920,39 @@
|
|
|
841
920
|
walkUI()
|
|
842
921
|
}
|
|
843
922
|
wk.end = walkEnd
|
|
923
|
+
// Whole / Step (rcn-lineup-follow). Whole and ⤢ show the whole drawing; Step
|
|
924
|
+
// frames what is lit now. In Whole the drawing is yours to pan and zoom.
|
|
925
|
+
if (RL && RL.bindFrame && $item.find('.graph-box svg').length) {
|
|
926
|
+
const svgNow = () => $item.find('.graph-box svg').get(0)
|
|
927
|
+
RL.bindFrame(elG, 'sketch', (fr, fit) => {
|
|
928
|
+
const g = graphModel(item), svg = svgNow()
|
|
929
|
+
if (!g || !svg) return
|
|
930
|
+
if (fr === 'whole' || fit) { walkZoom(svg, null); return }
|
|
931
|
+
if (wk.w !== null) showWalkStep($item, g, curWalk(), wk.i)
|
|
932
|
+
else if (elG.rcnFollow && elG.rcnFollow.lit) showFollow($item, g, elG.rcnFollow)
|
|
933
|
+
})
|
|
934
|
+
const vb = svg => (svg.getAttribute('viewBox') || svg.__fullViewBox || '0 0 1000 600').split(/[\s,]+/).map(Number)
|
|
935
|
+
const put = (svg, v) => { svg.__zoomId = (svg.__zoomId || 0) + 1; svg.setAttribute('viewBox', v.join(' ')) } // also stops a zoom still easing in
|
|
936
|
+
RL.handView($item.find('.graph-box').get(0), {
|
|
937
|
+
on: () => isWhole($item) && !!svgNow(),
|
|
938
|
+
pan: (dx, dy) => {
|
|
939
|
+
const svg = svgNow(), v = vb(svg), r = svg.getBoundingClientRect()
|
|
940
|
+
if (!svg.__fullViewBox) svg.__fullViewBox = v.join(' ')
|
|
941
|
+
const k = Math.max(v[2] / r.width, v[3] / r.height)
|
|
942
|
+
put(svg, [v[0] - dx * k, v[1] - dy * k, v[2], v[3]])
|
|
943
|
+
},
|
|
944
|
+
zoom: (f, x, y) => {
|
|
945
|
+
const svg = svgNow(), v = vb(svg), r = svg.getBoundingClientRect(), box = svg.parentNode.getBoundingClientRect()
|
|
946
|
+
if (!svg.__fullViewBox) svg.__fullViewBox = v.join(' ')
|
|
947
|
+
const full = svg.__fullViewBox.split(/[\s,]+/).map(Number)
|
|
948
|
+
const k = Math.max(v[2] / r.width, v[3] / r.height)
|
|
949
|
+
const px = v[0] + (x + box.left - r.left) * k, py = v[1] + (y + box.top - r.top) * k // the drawing's point under the pointer
|
|
950
|
+
const w = Math.max(full[2] / 20, Math.min(full[2] * 2, v[2] / f)), s = w / v[2]
|
|
951
|
+
put(svg, [px - (px - v[0]) * s, py - (py - v[1]) * s, w, v[3] * s])
|
|
952
|
+
},
|
|
953
|
+
reset: () => { const svg = svgNow(); if (svg) walkZoom(svg, null) }
|
|
954
|
+
})
|
|
955
|
+
}
|
|
844
956
|
// Follow the other timeline, map and drawing items in the lineup, and the full
|
|
845
957
|
// tools in other tabs. A walk played elsewhere stops this one (and a build);
|
|
846
958
|
// a click elsewhere is ignored while either is open. A box is lit by its own
|
package/package.json
CHANGED
|
@@ -41,6 +41,11 @@
|
|
|
41
41
|
"id": "eb1078f31385e806",
|
|
42
42
|
"text": "Opening the explorer. Give the item a set field naming a set file, for example \"set\": \"superior.set.json\", and it shows a ⧉ Open together button. The button opens the Time Place Causality Explorer, which puts the timeline, the map and the sketch side by side on one page. A bare file name means the site's /assets/NDC/ folder, where the explorer and the full tools sit; a full address can point to a set anywhere."
|
|
43
43
|
},
|
|
44
|
+
{
|
|
45
|
+
"type": "paragraph",
|
|
46
|
+
"id": "149c044870cee1eb",
|
|
47
|
+
"text": "Whole or Step. Beside the item's buttons, Whole · Step says what this drawing does while a walk plays, its own or one it follows. Step zooms in on what each step is about. Whole keeps the whole drawing, or wherever you have put it: each step lights its boxes where they are. In Whole, drag the drawing to move it, pinch or ⌘-scroll to zoom, and double-click (or ⤢) to see all of it again. A click on the timeline or the map beside it still brings the drawing to that box. You can switch at any time, in the middle of a walk too, and the choice is remembered in your browser. The Time Place Causality Explorer has the same switch on each of its panes."
|
|
48
|
+
},
|
|
44
49
|
{
|
|
45
50
|
"type": "rcngraph",
|
|
46
51
|
"id": "8d4e2a7f1c9b3065",
|
|
@@ -218,6 +223,17 @@
|
|
|
218
223
|
},
|
|
219
224
|
"after": "f2b474457cb3f7bd",
|
|
220
225
|
"date": 1794195627668
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
"type": "add",
|
|
229
|
+
"id": "149c044870cee1eb",
|
|
230
|
+
"item": {
|
|
231
|
+
"type": "paragraph",
|
|
232
|
+
"id": "149c044870cee1eb",
|
|
233
|
+
"text": "Whole or Step. Beside the item's buttons, Whole · Step says what this drawing does while a walk plays, its own or one it follows. Step zooms in on what each step is about. Whole keeps the whole drawing, or wherever you have put it: each step lights its boxes where they are. In Whole, drag the drawing to move it, pinch or ⌘-scroll to zoom, and double-click (or ⤢) to see all of it again. A click on the timeline or the map beside it still brings the drawing to that box. You can switch at any time, in the middle of a walk too, and the choice is remembered in your browser. The Time Place Causality Explorer has the same switch on each of its panes."
|
|
234
|
+
},
|
|
235
|
+
"after": "eb1078f31385e806",
|
|
236
|
+
"date": 1794945537905
|
|
221
237
|
}
|
|
222
238
|
]
|
|
223
239
|
}
|