@cardenelabs/dragon 0.41.1 → 0.42.0
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 +21 -1
- package/dist/cli.cjs +4094 -961
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +4094 -961
- package/dist/cli.js.map +1 -1
- package/dist/export.cjs +3681 -939
- package/dist/export.cjs.map +1 -1
- package/dist/export.d.cts +1 -1
- package/dist/export.d.ts +1 -1
- package/dist/export.js +3681 -939
- package/dist/export.js.map +1 -1
- package/dist/index.cjs +4016 -815
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +159 -3
- package/dist/index.d.ts +159 -3
- package/dist/index.js +4016 -815
- package/dist/index.js.map +1 -1
- package/dist/{ink-B_7OXxtb.d.cts → ink-B8EZL7JV.d.cts} +95 -3
- package/dist/{ink-B_7OXxtb.d.ts → ink-B8EZL7JV.d.ts} +95 -3
- package/dist/node.cjs +2461 -726
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +2461 -726
- package/dist/node.js.map +1 -1
- package/dist/player.global.js +2 -2
- package/package.json +1 -1
- package/src/field-messages.ts +12 -0
- package/src/figure-text.ts +26 -0
- package/src/index.ts +11 -1
- package/src/layout/scene.ts +23 -2
- package/src/layout/time.ts +680 -0
- package/src/look/values.ts +142 -2
- package/src/messages.ts +108 -5
- package/src/parser.ts +427 -6
- package/src/player.ts +48 -10
- package/src/printer.ts +63 -12
- package/src/render/icons.ts +2 -0
- package/src/render/parts.ts +29 -9
- package/src/render/svg.ts +129 -21
- package/src/render/time.ts +291 -0
- package/src/schema.ts +109 -10
- package/src/schemas/diagram.schema.json +224 -12
- package/src/schemas/validate-diagram.js +1 -1
- package/src/timeline.ts +147 -10
- package/src/words.ts +39 -6
package/src/render/svg.ts
CHANGED
|
@@ -4,16 +4,18 @@
|
|
|
4
4
|
* 動きは全て SVG の中の CSS の keyframes が回す。1 周の長さは `--T`、止める時刻は `--at`、
|
|
5
5
|
* 止めるか流すかは `--play` の変数で外から変えられる (頁に置く `player.ts` がこれを使う)。
|
|
6
6
|
* 色と字は値の表から CSS の変数として 1 度だけ書き、部品はその変数だけを読む。
|
|
7
|
+
* 止め絵を選ぶと (`still`)、最後の段の止め絵に全ての段の線の名前と箱の中の処理を出し、流れ全体を 1 枚で読ませる (#3200)。
|
|
7
8
|
*/
|
|
8
9
|
import { FIGURE_TEXT } from "../figure-text";
|
|
9
10
|
import { layoutArchitecture } from "../layout/architecture";
|
|
10
11
|
import { isGitLayout, layoutGit } from "../layout/git";
|
|
11
12
|
import { textWidth } from "../layout/measure";
|
|
12
|
-
import type { Layout, Rect, SceneLabel } from "../layout/scene";
|
|
13
|
+
import type { Layout, Rect, SceneField, SceneLabel } from "../layout/scene";
|
|
13
14
|
import { layoutSequence } from "../layout/sequence";
|
|
14
15
|
import { layoutState } from "../layout/state";
|
|
16
|
+
import { isTimeLayout, layoutTime } from "../layout/time";
|
|
15
17
|
import { FONTS } from "../look/fonts";
|
|
16
|
-
import { type ColorKey, EASE, FONT_VARS, LOOK, MOTION, type Palette, paletteVars, resolvePalette, type TextStyle, type Theme, TYPE } from "../look/values";
|
|
18
|
+
import { type ColorKey, type Colors, EASE, FONT_VARS, isColorName, isColorValue, LOOK, MOTION, type Palette, paletteVars, resolvePalette, type TextStyle, type Theme, TYPE } from "../look/values";
|
|
17
19
|
import { readDiagram } from "../version";
|
|
18
20
|
import type { Diagram, ViewMode } from "../schema";
|
|
19
21
|
import { buildTimeline, type LabelTime, type Span, type Timeline } from "../timeline";
|
|
@@ -35,21 +37,33 @@ import {
|
|
|
35
37
|
headCard,
|
|
36
38
|
label,
|
|
37
39
|
lifeline,
|
|
40
|
+
linkTo,
|
|
38
41
|
path,
|
|
39
42
|
side,
|
|
40
43
|
strip,
|
|
41
44
|
type SubChange,
|
|
42
45
|
} from "./parts";
|
|
43
46
|
import { drawGit } from "./git";
|
|
47
|
+
import { drawTime, meterField, sansOf, timeFocus } from "./time";
|
|
44
48
|
import { findOverlaps, type Ink, type Overlap, type Trace } from "./ink";
|
|
45
49
|
import { Motion } from "./motion";
|
|
46
50
|
|
|
47
51
|
export interface RenderOptions {
|
|
48
52
|
/** 色味の名前。書かないか知らない名前なら紙と墨 */
|
|
49
53
|
palette?: string;
|
|
54
|
+
/**
|
|
55
|
+
* `palette` の色味に重ねる色の値 (#3198)。鍵は色味が持つ色の変数の名前 (`bg`、`ink`、`c-green` など) で、値は描く `theme` の色になる。
|
|
56
|
+
* 渡さない色は色味の値のまま残る。色味に無い名前と、色の値として読めない値は、名前を挙げて描かずに断る
|
|
57
|
+
*/
|
|
58
|
+
colors?: Colors;
|
|
50
59
|
theme?: Theme;
|
|
51
60
|
/** 描く部品が出す字 (断りの文、全体図の札、読み上げの名前) の言葉。書かなければ日本語 (#3001) */
|
|
52
61
|
lang?: NotationLang;
|
|
62
|
+
/**
|
|
63
|
+
* 最後の段の止め絵に、全ての段の線の名前と箱の中の処理を最後の段と同じ濃さで出す (#3200)。途中の段の止め絵は今の段の名前だけを出す。
|
|
64
|
+
* 箱の下の 1 行に出す処理は、その箱で最後に起きた処理か書き換えの字を出す。違う段の名前が重なっても置き直さず、最後の段の重なり (`overlaps`) に出す
|
|
65
|
+
*/
|
|
66
|
+
still?: boolean;
|
|
53
67
|
}
|
|
54
68
|
|
|
55
69
|
export interface Rendered {
|
|
@@ -158,6 +172,45 @@ const PART_CSS = [
|
|
|
158
172
|
`.dg-git-n{${font(TYPE.gitNote)};fill:var(--ink2)}`,
|
|
159
173
|
`.dg-git-old{fill:var(--surf);stroke:var(--c);stroke-width:${S.gitOrphan};stroke-dasharray:3 3;stroke-opacity:.6}`,
|
|
160
174
|
`.dg-git-oldl{${font(TYPE.gitId)};fill:var(--ct);opacity:.55}`,
|
|
175
|
+
// 時間軸の図 (#3165)。和文を含む字は、末尾に j を付けた class で同じ大きさと太さの和文の字にする
|
|
176
|
+
`.dg-tm-ep{fill:color-mix(in srgb,var(--ink) ${X.timeShade}%,transparent)}`,
|
|
177
|
+
`.dg-tm-sep{stroke:var(--hair);stroke-width:${S.hair};stroke-dasharray:2 4}`,
|
|
178
|
+
`.dg-tm-hd{${font(TYPE.timeHead)};fill:var(--ink)}`,
|
|
179
|
+
`.dg-tm-hdj{${font(sansOf(TYPE.timeHead))}}`,
|
|
180
|
+
`.dg-tm-slot{fill:none;stroke:var(--line);stroke-width:${S.timeSlot};opacity:.55}`,
|
|
181
|
+
".dg-tm-m{fill:var(--c)}",
|
|
182
|
+
".dg-tm-x{fill:var(--c-slate)}",
|
|
183
|
+
`.dg-tm-fr{fill:none;stroke:var(--c-blue);stroke-width:${S.timeFrame};stroke-dasharray:3 2}`,
|
|
184
|
+
`.dg-tm-gd{fill:none;stroke:color-mix(in srgb,var(--c-blue) ${X.timeGuide}%,transparent);stroke-width:${S.hair};stroke-dasharray:2 3}`,
|
|
185
|
+
`.dg-tm-ax{fill:none;stroke:var(--line);stroke-width:${S.timeAxis}}`,
|
|
186
|
+
`.dg-tm-tk{${font(TYPE.timeTick)};fill:var(--mute)}`,
|
|
187
|
+
`.dg-tm-tkj{${font(sansOf(TYPE.timeTick))}}`,
|
|
188
|
+
`.dg-tm-en{${font(TYPE.timePeriod)};fill:var(--ink2)}`,
|
|
189
|
+
`.dg-tm-er{${font(TYPE.timeRange)};fill:var(--mute)}`,
|
|
190
|
+
`.dg-tm-erj{${font(sansOf(TYPE.timeRange))}}`,
|
|
191
|
+
`.dg-tm-rn{${font(TYPE.timeRow)};fill:var(--ink2)}`,
|
|
192
|
+
`.dg-tm-br{fill:none;stroke:var(--c);stroke-width:${S.timeSpan};stroke-linecap:round;stroke-linejoin:round}`,
|
|
193
|
+
`.dg-tm-bt{${font(TYPE.spanText)};fill:var(--ct)}`,
|
|
194
|
+
`.dg-tm-bx{fill:color-mix(in srgb,var(--c) ${X.timeSpan}%,transparent);stroke:var(--c);stroke-width:${S.timeSpan};stroke-dasharray:4 3}`,
|
|
195
|
+
`.dg-tm-con{fill:none;stroke:var(--line);stroke-width:${S.timeDrop};stroke-linecap:round;stroke-dasharray:0 3.5}`,
|
|
196
|
+
".dg-tm-pg{fill:var(--surf);stroke:var(--line);stroke-dasharray:2 2.5}",
|
|
197
|
+
`.dg-tm-pgl{fill:none;stroke:var(--mute);stroke-width:${S.timeFlag};stroke-linecap:round;stroke-linejoin:round}`,
|
|
198
|
+
`.dg-tm-pc{fill:var(--surf);stroke:var(--c);stroke-width:${S.timePoint}}`,
|
|
199
|
+
`.dg-tm-pcg{fill:none;stroke:var(--c);stroke-width:${S.timeFlag};stroke-linecap:round;stroke-linejoin:round}`,
|
|
200
|
+
`.dg-tm-pn{${font(TYPE.pointName)};fill:var(--ink)}`,
|
|
201
|
+
`.dg-tm-pnj{${font(sansOf(TYPE.pointName))}}`,
|
|
202
|
+
".dg-tm-pn-g{fill:var(--mute)}",
|
|
203
|
+
`.dg-tm-ps{${font(TYPE.pointState)};fill:var(--ct)}`,
|
|
204
|
+
`.dg-tm-ln{fill:none;stroke:var(--c);stroke-width:${S.edgeOn};stroke-linecap:round;stroke-dasharray:1 2}`,
|
|
205
|
+
`.dg-tm-nd{stroke:var(--ink);stroke-width:${S.timeNeedle};opacity:.55}`,
|
|
206
|
+
".dg-tm-nh{fill:var(--ink)}",
|
|
207
|
+
".dg-tm-ph{fill:none;stroke:var(--line);stroke-dasharray:3 3}",
|
|
208
|
+
`.dg-tm-ex{fill:color-mix(in srgb,var(--c-slate) ${X.timeEmpty}%,var(--surf));stroke:var(--c-slate);stroke-width:${S.timeFrame};stroke-dasharray:3 3}`,
|
|
209
|
+
`.dg-tm-ext{${font(TYPE.emptyText)};fill:var(--t-slate)}`,
|
|
210
|
+
".dg-tm-mt{fill:var(--hair)}",
|
|
211
|
+
".dg-tm-mf{fill:var(--c);transform-box:fill-box;transform-origin:0 50%}",
|
|
212
|
+
`.dg-tm-mk{stroke:var(--ink2);stroke-width:${S.timeMeter}}`,
|
|
213
|
+
`.dg-tm-ml{${font(TYPE.meterLine)};fill:var(--ink2)}`,
|
|
161
214
|
".dg-vp-bg{fill:var(--bg)}",
|
|
162
215
|
".dg-vp-frame{fill:none;stroke:var(--hair)}",
|
|
163
216
|
".dg-hd-bg{fill:var(--bg)}",
|
|
@@ -196,17 +249,22 @@ function involved(diagram: Diagram): Map<string, number[]> {
|
|
|
196
249
|
return new Map([...on].map(([id, steps]) => [id, [...steps].sort((a, b) => a - b)]));
|
|
197
250
|
}
|
|
198
251
|
|
|
199
|
-
/**
|
|
252
|
+
/**
|
|
253
|
+
* 箱の下の字の移り変わり。書き換えはそのまま残し、構成図の処理はその段の間だけ出して元へ戻す。
|
|
254
|
+
* 止め絵を選んだ図は、その箱で最後に起きたのが処理なら、最後の段で起きることが済んだ時にその処理を出し直して繰り返す前まで残す (#3200)
|
|
255
|
+
*/
|
|
200
256
|
function subChanges(diagram: Diagram, timeline: Timeline, actionsInBox: boolean): Map<string, SubChange[]> {
|
|
201
257
|
type Raw = { t: number; order: number; box: string; set?: string; act?: string | null };
|
|
202
258
|
const raw: Raw[] = [];
|
|
259
|
+
const { whole } = timeline;
|
|
203
260
|
let order = 0;
|
|
204
261
|
for (const time of timeline.events) {
|
|
205
262
|
const event = diagram.steps[time.step]?.events[time.event];
|
|
206
263
|
if (event?.type === "swap") raw.push({ t: time.at, order: order++, box: event.box, set: event.text });
|
|
207
264
|
if (actionsInBox && event?.type === "action") {
|
|
208
265
|
raw.push({ t: time.at, order: order++, box: event.box, act: event.label });
|
|
209
|
-
|
|
266
|
+
const end = (timeline.steps[time.step] as Span).end;
|
|
267
|
+
if (!whole || end <= whole.start) raw.push({ t: end, order: order++, box: event.box, act: null });
|
|
210
268
|
}
|
|
211
269
|
}
|
|
212
270
|
raw.sort((a, b) => a.t - b.t || a.order - b.order);
|
|
@@ -216,7 +274,10 @@ function subChanges(diagram: Diagram, timeline: Timeline, actionsInBox: boolean)
|
|
|
216
274
|
let acting: string | undefined;
|
|
217
275
|
let shown = base.join("|");
|
|
218
276
|
const list: SubChange[] = [];
|
|
219
|
-
|
|
277
|
+
const changes = raw.filter((r) => r.box === box.id);
|
|
278
|
+
const latest = [...changes].reverse().find((r) => r.set !== undefined || typeof r.act === "string");
|
|
279
|
+
if (whole && typeof latest?.act === "string") changes.push({ t: whole.start, order: order++, box: box.id, act: latest.act });
|
|
280
|
+
for (const change of changes) {
|
|
220
281
|
// 書き換えは、出ている処理の字も置き換える
|
|
221
282
|
if (change.set !== undefined) {
|
|
222
283
|
base = [change.set, "dg-ss-ok"];
|
|
@@ -261,18 +322,24 @@ export interface FollowFrame {
|
|
|
261
322
|
lang: NotationLang;
|
|
262
323
|
}
|
|
263
324
|
|
|
264
|
-
/**
|
|
325
|
+
/**
|
|
326
|
+
* 同じ線の同じ名前を後の段が置く時は、薄く残した名前をその段が始まるまでで消す (#3184)。
|
|
327
|
+
* 止め絵で全ての段の名前を出し直す間は、同じ所に出る後の段の名前に任せる (#3200)
|
|
328
|
+
*/
|
|
265
329
|
function fadeBefore(l: SceneLabel, time: LabelTime, steps: Span[]): LabelTime {
|
|
266
|
-
if (l.until === undefined
|
|
330
|
+
if (l.until === undefined) return time;
|
|
331
|
+
const { after, again: _again, ...rest } = time;
|
|
332
|
+
if (!after) return rest;
|
|
267
333
|
const cut = (steps[l.until] as Span).start;
|
|
268
|
-
const { after, ...rest } = time;
|
|
269
334
|
return cut > after.start ? { ...rest, after: { start: after.start, end: Math.min(after.end, cut) } } : rest;
|
|
270
335
|
}
|
|
271
336
|
|
|
272
337
|
/** 図を描く。`follow` を渡すと、寄って追う窓と隅の全体図で描く。`ink` を渡すと、描いた字の四角と見えている間をそこへ記録する (#3175)。 */
|
|
273
338
|
export function drawSvg(diagram: Diagram, layout: Layout, timeline: Timeline, palette: Palette, theme: Theme, follow?: FollowFrame, ink: Ink[] = [], traces: Trace[] = []): string {
|
|
274
|
-
//
|
|
275
|
-
|
|
339
|
+
// 札の言葉で全体図の地の幅が変わりうるので、同じ頁に置いた別の言葉の図と名前を分ける。
|
|
340
|
+
// 色は色味の名前でなく色の値から名前を作り、色の値を重ねた図 (#3198) と同じ色味の名前の図の変数の規則を分ける
|
|
341
|
+
const vars = paletteVars(palette, theme);
|
|
342
|
+
const id = nameOf(`${JSON.stringify(diagram)}|${vars}|${follow ? `${follow.width}|${follow.lang}` : ""}`);
|
|
276
343
|
const m = new Motion(`dg${id}`, timeline.total, timeline.last);
|
|
277
344
|
const ctx: Ctx = { m, t: timeline, sh: `filter="url(#dg-sh-${id})"`, end: (timeline.steps[timeline.steps.length - 1] as Span).end, ink, traces };
|
|
278
345
|
const on = involved(diagram);
|
|
@@ -290,7 +357,10 @@ export function drawSvg(diagram: Diagram, layout: Layout, timeline: Timeline, pa
|
|
|
290
357
|
// 状態遷移図は、段で変わった値を今の状態の色で描き、帯の通った状態の点を着いた時刻に塗る (#3171)
|
|
291
358
|
const isState = layout.kind === "state";
|
|
292
359
|
const arrivals = new Map((timeline.states ?? []).flatMap((s) => (s.lit[0] ? [[s.box, s.lit[0].start] as [string, number]] : [])));
|
|
293
|
-
|
|
360
|
+
// 時間軸の図の物差しの欄は、満ち具合の動きで棒を伸ばす (#3165)
|
|
361
|
+
const meters = new Map((timeline.meters ?? []).map((meter) => [meter.field, meter.keys]));
|
|
362
|
+
const gauge = (field: SceneField): string | undefined => (field.meter ? meterField({ ...field, meter: field.meter }, meters.get(field.name) ?? [[0, 0]], ctx) : undefined);
|
|
363
|
+
if (layout.strip) L.band.push(strip(layout.strip, fieldChanges(diagram, timeline, layout), ctx, isState, arrivals, gauge));
|
|
294
364
|
for (const line of layout.lifelines) L.base.push(lifeline(line.x, line.y1, line.y2));
|
|
295
365
|
// 枝分かれの図の線と commit と札は、枝分かれの図を描く部品が描く (#3164)
|
|
296
366
|
if (isGitLayout(layout)) {
|
|
@@ -300,21 +370,34 @@ export function drawSvg(diagram: Diagram, layout: Layout, timeline: Timeline, pa
|
|
|
300
370
|
L.node.push(git.commits);
|
|
301
371
|
L.top.push(git.tags);
|
|
302
372
|
}
|
|
373
|
+
// 時間軸の図の目盛りと印と拡大の帯の箱と節目は、時間軸の図を描く部品が描く (#3165)。拡大の帯の線は他の図と同じ線で描く
|
|
374
|
+
const timeLayout = isTimeLayout(layout) ? layout : undefined;
|
|
375
|
+
if (timeLayout) {
|
|
376
|
+
const drawn = drawTime(timeLayout, diagram, timeline, ctx, subs);
|
|
377
|
+
L.base.push(drawn.base);
|
|
378
|
+
L.lit.push(drawn.lit);
|
|
379
|
+
L.node.push(drawn.node);
|
|
380
|
+
L.top.push(drawn.top);
|
|
381
|
+
}
|
|
382
|
+
const wired = new Set((timeLayout?.wires ?? []).map((w) => `${w.step}/${w.event}`));
|
|
303
383
|
for (const e of layout.edges) {
|
|
304
384
|
const time = timeline.edges.find((t) => t.step === e.step && t.event === e.event);
|
|
305
|
-
if (!time) continue;
|
|
385
|
+
if (!time || (timeLayout && !wired.has(`${e.step}/${e.event}`))) continue;
|
|
306
386
|
const drawn = edge(e, time, ctx, isState);
|
|
307
387
|
L.base.push(drawn.base);
|
|
308
388
|
L.lit.push(drawn.lit);
|
|
309
389
|
}
|
|
310
390
|
const states = new Map((timeline.states ?? []).map((s) => [s.box, s]));
|
|
311
|
-
|
|
391
|
+
// 飛び先を持つ箱は、箱の札をその飛び先への link で包む (#3199)。時間軸の図の箱は時間軸の図を描く部品が包む
|
|
392
|
+
const links = new Map(diagram.boxes.flatMap((b) => (b.link === undefined ? [] : [[b.id, b.link] as [string, string]])));
|
|
393
|
+
const linked = (id: string, markup: string): string => linkTo(links.get(id), markup);
|
|
394
|
+
for (const box of timeLayout ? [] : layout.boxes) {
|
|
312
395
|
if (box.ghost) {
|
|
313
|
-
L.node.push(ghostCard(box, ink));
|
|
396
|
+
L.node.push(linked(box.id, ghostCard(box, ink)));
|
|
314
397
|
continue;
|
|
315
398
|
}
|
|
316
399
|
const state = states.get(box.id);
|
|
317
|
-
L.node.push(card(box, ctx, on.get(box.id) ?? [], subs.get(box.id) ?? [], isState ? (state?.lit ?? []) : undefined));
|
|
400
|
+
L.node.push(linked(box.id, card(box, ctx, on.get(box.id) ?? [], subs.get(box.id) ?? [], isState ? (state?.lit ?? []) : undefined)));
|
|
318
401
|
if (state?.done !== undefined) L.node.push(doneMark(box, state.done, ctx));
|
|
319
402
|
}
|
|
320
403
|
for (const b of layout.badges) L.badge.push(badge(b, ctx, isState));
|
|
@@ -322,9 +405,13 @@ export function drawSvg(diagram: Diagram, layout: Layout, timeline: Timeline, pa
|
|
|
322
405
|
const time = timeline.labels.find((t) => t.step === l.step && t.event === l.event);
|
|
323
406
|
if (time) L.top.push(label(l, fadeBefore(l, time, timeline.steps), ctx));
|
|
324
407
|
}
|
|
408
|
+
// 止め絵を選んだ図は、全ての段の名前を出す間にも処理の札を出す。その間に見えている札は繰り返す前まで延ばす (#3200)
|
|
409
|
+
const { whole } = timeline;
|
|
325
410
|
for (const a of layout.actions) {
|
|
326
411
|
const time = timeline.events.find((t) => t.step === a.step && t.event === a.event);
|
|
327
|
-
if (time)
|
|
412
|
+
if (!time) continue;
|
|
413
|
+
const until = (timeline.steps[a.step] as Span).end;
|
|
414
|
+
L.top.push(whole && until > whole.start ? action(a, time.at, whole.end, ctx) : action(a, time.at, until, ctx, whole));
|
|
328
415
|
}
|
|
329
416
|
for (const time of timeline.carriers) {
|
|
330
417
|
const e = layout.edges.find((x) => x.step === time.step && x.event === time.event);
|
|
@@ -337,9 +424,9 @@ export function drawSvg(diagram: Diagram, layout: Layout, timeline: Timeline, pa
|
|
|
337
424
|
const { near, far, nearY, farY } = LOOK.shadow;
|
|
338
425
|
const shadow = `<filter id="dg-sh-${id}" x="-20%" y="-30%" width="140%" height="180%"><feDropShadow dx="0" dy="${nearY}" stdDeviation="${near}" style="flood-color:var(--sh);flood-opacity:var(--shA)"/><feDropShadow dx="0" dy="${farY}" stdDeviation="${far}" style="flood-color:var(--sh);flood-opacity:var(--shB)"/></filter>`;
|
|
339
426
|
// 寄って追う時系列図は、頭の箱を窓の上端に貼る頭の列にも描く (#3118)。頭の列の箱はアイコンを外した 2 段 (#3120)。止めて見せる図では描かない
|
|
340
|
-
const heads = follow && layout.kind === "sequence" ? layout.boxes.map((box) => headCard(box, ctx, on.get(box.id) ?? [], subs.get(box.id) ?? [])).join("") : "";
|
|
427
|
+
const heads = follow && layout.kind === "sequence" ? layout.boxes.map((box) => linked(box.id, headCard(box, ctx, on.get(box.id) ?? [], subs.get(box.id) ?? []))).join("") : "";
|
|
341
428
|
const view = follow ? followView(layout, timeline, diagram, m, id, content, follow, heads) : { body: `<rect class="dg-bg" width="${layout.width}" height="${layout.height}" rx="${LOOK.region.radius}"/>${content}`, w: layout.width, h: layout.height };
|
|
342
|
-
const css = `.dg-${id}{${FONT_VARS};--T:${timeline.total}s;${
|
|
429
|
+
const css = `.dg-${id}{${FONT_VARS};--T:${timeline.total}s;${vars}}${PART_CSS}${m.frames.join("")}`;
|
|
343
430
|
return (
|
|
344
431
|
`<svg xmlns="http://www.w3.org/2000/svg" class="dg dg-${id}" viewBox="0 0 ${Math.ceil(view.w)} ${Math.ceil(view.h)}" width="${Math.ceil(view.w)}" height="${Math.ceil(view.h)}" role="img" aria-label="${esc(diagram.title)}" data-dragon="figure" data-view="${follow ? "follow" : "fixed"}">` +
|
|
345
432
|
`<style>${css}</style><defs>${shadow}</defs>${view.body}</svg>`
|
|
@@ -448,6 +535,12 @@ function followView(layout: Layout, timeline: Timeline, diagram: Diagram, m: Mot
|
|
|
448
535
|
let prev: [number, number] = [layout.width / 2, layout.height / 2];
|
|
449
536
|
// 頭の列の下の残りの窓の真ん中。窓の真ん中は、これより頭の列の高さの半分だけ上に在る
|
|
450
537
|
const middles = timeline.steps.map((_, s) => {
|
|
538
|
+
// 時間軸の図は、針と印の列を必ず窓に入れる (#3165)。番号の丸へ寄せ直すと、針が窓から外れるため
|
|
539
|
+
if (isTimeLayout(layout)) {
|
|
540
|
+
const f = timeFocus(layout, timeline, s, focusParts(layout, diagram, s), vw, below);
|
|
541
|
+
prev = [f.x + f.w / 2, f.y + f.h / 2];
|
|
542
|
+
return [clampX(prev[0]), clampY(prev[1])] as [number, number];
|
|
543
|
+
}
|
|
451
544
|
const f = focusOf(layout, diagram, s);
|
|
452
545
|
prev = f ? [f.x + f.w / 2, f.y + f.h / 2] : prev;
|
|
453
546
|
const at: [number, number] = [clampX(prev[0]), clampY(prev[1])];
|
|
@@ -513,6 +606,19 @@ function followView(layout: Layout, timeline: Timeline, diagram: Diagram, m: Mot
|
|
|
513
606
|
return { body, w: beside && !bare ? vw + M.inset + bgW : full, h: beside ? vh : bgY + bgH };
|
|
514
607
|
}
|
|
515
608
|
|
|
609
|
+
/**
|
|
610
|
+
* 描く色味。名前で選んだ色味の `theme` の色に `colors` の色を重ねる (#3198)。
|
|
611
|
+
* 色味に無い色の名前と、色の値として読めない値は、名前を全て挙げて描かずに断る
|
|
612
|
+
*/
|
|
613
|
+
export function paletteOf(options: RenderOptions, theme: Theme): Palette {
|
|
614
|
+
const palette = resolvePalette(options.palette);
|
|
615
|
+
if (!options.colors) return palette;
|
|
616
|
+
const words = FIGURE_TEXT[options.lang ?? "ja"];
|
|
617
|
+
const errors = Object.entries(options.colors).flatMap(([name, value]) => (!isColorName(name) ? [words.unknownColor(name)] : isColorValue(value) ? [] : [words.unreadableColor(name)]));
|
|
618
|
+
if (errors.length > 0) throw new Error(words.cannotDraw(errors.join(" / ")));
|
|
619
|
+
return { ...palette, [theme]: { ...palette[theme], ...options.colors } };
|
|
620
|
+
}
|
|
621
|
+
|
|
516
622
|
/** 原本の JSON から図を描く。原本が形に合わない時は、誤りの場所を添えて断る。 */
|
|
517
623
|
export function renderDiagram(input: unknown, options: RenderOptions = {}): Rendered {
|
|
518
624
|
const lang = options.lang ?? "ja";
|
|
@@ -526,8 +632,10 @@ export function renderDiagram(input: unknown, options: RenderOptions = {}): Rend
|
|
|
526
632
|
? layoutState(diagram, lang)
|
|
527
633
|
: diagram.kind === "git"
|
|
528
634
|
? layoutGit(diagram)
|
|
529
|
-
:
|
|
530
|
-
|
|
635
|
+
: diagram.kind === "time"
|
|
636
|
+
? layoutTime(diagram, lang)
|
|
637
|
+
: layoutArchitecture(diagram);
|
|
638
|
+
return renderLayout(diagram, layout, buildTimeline(diagram, options.still === true), options);
|
|
531
639
|
}
|
|
532
640
|
|
|
533
641
|
/**
|
|
@@ -535,8 +643,8 @@ export function renderDiagram(input: unknown, options: RenderOptions = {}): Rend
|
|
|
535
643
|
* 重なりは、字を描く部品が記録した字だけから数えるので、描く所が位置を決める字 (箱の名前) も対象に入る
|
|
536
644
|
*/
|
|
537
645
|
export function renderLayout(diagram: Diagram, layout: Layout, timeline: Timeline, options: RenderOptions = {}): Rendered {
|
|
538
|
-
const palette = resolvePalette(options.palette);
|
|
539
646
|
const theme: Theme = options.theme === "dark" ? "dark" : "light";
|
|
647
|
+
const palette = paletteOf(options, theme);
|
|
540
648
|
const ink: Ink[] = [];
|
|
541
649
|
const traces: Trace[] = [];
|
|
542
650
|
const svg = drawSvg(diagram, layout, timeline, palette, theme, undefined, ink, traces);
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 時間軸の図 (#3165) を描く部品。見本帳の試作 `docs/design/base/scenes/finality.js` の時間軸と拡大の帯と節目を写す。
|
|
3
|
+
*
|
|
4
|
+
* 印は枠を初めから見せ、針が目盛りを過ぎた時に塗る。拡大した目盛りの印は、その列で印の列と同じ名札の箱へ線が届いた時に塗る。
|
|
5
|
+
* 印の色を変える出来事は、その時刻に色を重ねる。空きの印は、針が過ぎた時に小さな点を出す。
|
|
6
|
+
* 拡大の帯の箱は列ごとに描き、印の列と同じ名札の箱は線が届くまで点線の枠で待ち、届いた時に弾んで出る。空きの目盛りの列では空きの枠を出す。
|
|
7
|
+
* 節目は点線の丸で待ち、状態を変えるたびに色の丸を弾ませて、状態の字を書き換える。節目どうしの線は引いた後も残す。
|
|
8
|
+
* 範囲の括弧は次の括弧が来る段まで、範囲の囲みは最後まで出す。拡大の枠と点線は、拡大した範囲を囲む範囲の囲みが出る時に消す。
|
|
9
|
+
* 針は時刻の表の針の動きを辿り、繰り返す前に左端へ戻る。
|
|
10
|
+
*/
|
|
11
|
+
import type { TimeBox, TimeLayout } from "../layout/time";
|
|
12
|
+
import { hasWide } from "../layout/measure";
|
|
13
|
+
import { EASE, LOOK, MOTION, type TextStyle, TYPE } from "../look/values";
|
|
14
|
+
import type { Diagram } from "../schema";
|
|
15
|
+
import type { Span, Timeline } from "../timeline";
|
|
16
|
+
import { ALWAYS, type Shown } from "./ink";
|
|
17
|
+
import { arrowHead, card, type Ctx, cs, esc, glyph, linkTo, pathOf, type SubChange, write } from "./parts";
|
|
18
|
+
|
|
19
|
+
const r1 = (v: number): number => Math.round(v * 100) / 100;
|
|
20
|
+
|
|
21
|
+
/** 和文を含む字に、同じ大きさと太さの和文の字の class を足す */
|
|
22
|
+
const ja = (cls: string, text: string): string => (hasWide(text) ? `${cls} ${cls}j` : cls);
|
|
23
|
+
|
|
24
|
+
/** 和文を含む字の、和文の字で描く時の字の形 */
|
|
25
|
+
export const sansOf = (t: TextStyle): TextStyle => ({ ...t, family: "sans" });
|
|
26
|
+
|
|
27
|
+
/** 真っ直ぐ進む動きの並びから、向きの変わらない間の点を除く。keyframes の数を減らすため */
|
|
28
|
+
export function simplify(keys: [number, number][]): [number, number][] {
|
|
29
|
+
const out: [number, number][] = [];
|
|
30
|
+
for (const key of keys) {
|
|
31
|
+
const a = out[out.length - 2];
|
|
32
|
+
const b = out[out.length - 1];
|
|
33
|
+
if (a && b) {
|
|
34
|
+
const s1 = b[0] === a[0] ? Number.NaN : (b[1] - a[1]) / (b[0] - a[0]);
|
|
35
|
+
const s2 = key[0] === b[0] ? Number.NaN : (key[1] - b[1]) / (key[0] - b[0]);
|
|
36
|
+
if (Number.isFinite(s1) && Number.isFinite(s2) && Math.abs(s1 - s2) < 1e-9) out[out.length - 1] = key;
|
|
37
|
+
else out.push(key);
|
|
38
|
+
} else out.push(key);
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 真っ直ぐ進む動き `keys` の、時刻 `t` の値 */
|
|
44
|
+
export function valueAt(keys: [number, number][], t: number): number {
|
|
45
|
+
const first = keys[0];
|
|
46
|
+
if (!first) return 0;
|
|
47
|
+
if (t <= first[0]) return first[1];
|
|
48
|
+
for (let k = 1; k < keys.length; k++) {
|
|
49
|
+
const [t1, v1] = keys[k] as [number, number];
|
|
50
|
+
const [t0, v0] = keys[k - 1] as [number, number];
|
|
51
|
+
if (t <= t1) return t1 === t0 ? v1 : v0 + ((v1 - v0) * (t - t0)) / (t1 - t0);
|
|
52
|
+
}
|
|
53
|
+
return (keys[keys.length - 1] as [number, number])[1];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function drawTime(layout: TimeLayout, diagram: Diagram, timeline: Timeline, ctx: Ctx, subs: Map<string, SubChange[]>): { base: string; lit: string; node: string; top: string } {
|
|
57
|
+
const { m, ink } = ctx;
|
|
58
|
+
const T = LOOK.time;
|
|
59
|
+
const { axis } = layout;
|
|
60
|
+
const passed = new Map((timeline.units ?? []).map((u) => [u.unit, u.passed]));
|
|
61
|
+
const at = (step: number, event: number): number | undefined => timeline.events.find((t) => t.step === step && t.event === event)?.at;
|
|
62
|
+
const drawnOf = (step: number, event: number): number | undefined => timeline.edges.find((t) => t.step === step && t.event === event)?.drawn;
|
|
63
|
+
const base: string[] = [];
|
|
64
|
+
const lit: string[] = [];
|
|
65
|
+
const node: string[] = [];
|
|
66
|
+
const top: string[] = [];
|
|
67
|
+
const rowsTop = Math.min(...layout.rows.map((r) => r.y));
|
|
68
|
+
const rowsBottom = Math.max(...layout.rows.map((r) => r.y + r.h));
|
|
69
|
+
|
|
70
|
+
// 拡大の帯の箱へ、線が初めて届く時刻
|
|
71
|
+
const arrivals = new Map<TimeBox, number>();
|
|
72
|
+
for (const w of layout.wires) {
|
|
73
|
+
const drawn = drawnOf(w.step, w.event);
|
|
74
|
+
if (drawn !== undefined) arrivals.set(w.to, Math.min(arrivals.get(w.to) ?? Number.POSITIVE_INFINITY, drawn));
|
|
75
|
+
}
|
|
76
|
+
/** 印の列 `row` の目盛り `u` の印を塗る時刻。同じ名札の箱へ線が届くか、針が目盛りを過ぎるか、早い方 */
|
|
77
|
+
const filled = (row: string, u: number): number | undefined => {
|
|
78
|
+
const box = layout.zoom?.columns.find((c) => c.unit === u)?.boxes.find((b) => b.id === row);
|
|
79
|
+
const times = [passed.get(u), box ? arrivals.get(box) : undefined].filter((t): t is number => t !== undefined);
|
|
80
|
+
return times.length > 0 ? Math.min(...times) : undefined;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// 区切りの地。1 つおきに薄く塗る
|
|
84
|
+
for (const p of layout.periods) if (p.index % 2 === 1) base.push(`<rect class="dg-tm-ep" x="${r1(p.x)}" y="${r1(rowsTop - T.shade)}" width="${r1(p.w)}" height="${r1(rowsBottom - rowsTop + T.shade * 2)}" rx="4"/>`);
|
|
85
|
+
|
|
86
|
+
// 拡大の帯の列の区切りと上の字と箱
|
|
87
|
+
if (layout.zoom) {
|
|
88
|
+
const z = layout.zoom;
|
|
89
|
+
z.columns.forEach((c, k) => {
|
|
90
|
+
if (k > 0) base.push(`<line class="dg-tm-sep" x1="${r1(c.x)}" y1="${r1(c.y + T.sep)}" x2="${r1(c.x)}" y2="${r1(c.y + c.h - T.sep)}"/>`);
|
|
91
|
+
base.push(write(ink, ja("dg-tm-hd", c.head), c.x + c.w / 2, z.headY, c.head, TYPE.timeHead, ALWAYS, "middle"));
|
|
92
|
+
for (const box of c.boxes) node.push(columnBox(box, c.unit));
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function columnBox(box: TimeBox, unit: number): string {
|
|
97
|
+
const on = [...new Set(layout.wires.filter((w) => w.from === box || w.to === box).map((w) => w.step))].sort((a, b) => a - b);
|
|
98
|
+
const frame = (cls: string): string => `<rect class="${cls}" x="${r1(box.x)}" y="${r1(box.y)}" width="${r1(box.w)}" height="${box.h}" rx="${LOOK.box.radius}"/>`;
|
|
99
|
+
if (box.empty) {
|
|
100
|
+
const shown = passed.get(unit);
|
|
101
|
+
const word = layout.zoom?.empty ?? "";
|
|
102
|
+
const mark = shown === undefined ? "" : `<g class="dg-a" style="${m.vis(shown)}">${frame("dg-tm-ex")}${write(ink, "dg-tm-ext", box.cx, box.cy + LOOK.baseline.mark, word, TYPE.emptyText, [[shown, Number.POSITIVE_INFINITY]], "middle")}</g>`;
|
|
103
|
+
return `<g data-empty="${esc(box.id)}">${frame("dg-tm-ph")}${mark}</g>`;
|
|
104
|
+
}
|
|
105
|
+
const drawn = linkTo(diagram.boxes.find((b) => b.id === box.id)?.link, card(box, ctx, on, subs.get(box.id) ?? []));
|
|
106
|
+
if (!box.row) return drawn;
|
|
107
|
+
// 印の列と同じ名札の箱は、線が届くまで点線の枠で待つ
|
|
108
|
+
const shown = filled(box.row, unit);
|
|
109
|
+
if (shown === undefined) return frame("dg-tm-ph");
|
|
110
|
+
return `<g class="dg-a" style="${m.until(shown)}">${frame("dg-tm-ph")}</g><g class="dg-popc dg-a" style="${m.pop(shown)}">${drawn}</g>`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 印。枠を初めから見せ、塗る時刻に塗り、色を変える出来事で色を重ねる
|
|
114
|
+
for (const row of layout.rows) {
|
|
115
|
+
const parts: string[] = [];
|
|
116
|
+
for (const mark of layout.marks.filter((x) => x.row === row.id)) {
|
|
117
|
+
const rect = (cls: string, extra = ""): string => `<rect class="${cls}" x="${r1(mark.x)}" y="${r1(mark.y)}" width="${r1(mark.w)}" height="${r1(mark.h)}" rx="${T.markRadius}"${extra}/>`;
|
|
118
|
+
parts.push(rect("dg-tm-slot"));
|
|
119
|
+
if (mark.empty) {
|
|
120
|
+
const shown = passed.get(mark.unit);
|
|
121
|
+
if (shown !== undefined) parts.push(`<circle class="dg-tm-x dg-a" cx="${r1(mark.x + mark.w / 2)}" cy="${r1(mark.y + mark.h / 2)}" r="${T.emptyR}" style="${m.vis(shown, m.last, { f: 0.2 })}"/>`);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const shown = filled(row.id, mark.unit);
|
|
125
|
+
if (shown !== undefined) parts.push(rect("dg-tm-m dg-a", ` style="${m.vis(shown, m.last, { f: 0.2 })}"`));
|
|
126
|
+
mark.colors.forEach((c, k) => {
|
|
127
|
+
const t = at(c.step, c.event);
|
|
128
|
+
if (t === undefined) return;
|
|
129
|
+
const next = mark.colors[k + 1];
|
|
130
|
+
const until = next ? at(next.step, next.event) : undefined;
|
|
131
|
+
parts.push(`<g style="${cs(c.color)}">${rect("dg-tm-m dg-a", ` style="${m.vis(t, until ?? m.last, { f: 0.35 })}"`)}</g>`);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
base.push(`<g data-row="${esc(row.id)}" style="${cs(row.color)}">${parts.join("")}</g>`);
|
|
135
|
+
base.push(write(ink, "dg-tm-rn", LOOK.margin + LOOK.region.inset, row.y + row.h / 2 + LOOK.baseline.mark, row.name, TYPE.timeRow));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 拡大した範囲の枠と点線。拡大した範囲に掛かる範囲の囲みが出る時に消す
|
|
139
|
+
if (layout.zoom) {
|
|
140
|
+
const z = layout.zoom;
|
|
141
|
+
const hide = layout.spans
|
|
142
|
+
.filter((s) => s.kind === "box" && s.from <= z.to && z.from <= s.to)
|
|
143
|
+
.map((s) => at(s.step, s.event))
|
|
144
|
+
.filter((t): t is number => t !== undefined)
|
|
145
|
+
.sort((a, b) => a - b)[0];
|
|
146
|
+
const guides = z.guides.map((g) => `<path class="dg-tm-gd" d="${pathOf(g)}"/>`).join("");
|
|
147
|
+
const lens = `<rect class="dg-tm-fr" x="${r1(z.frame.x)}" y="${r1(z.frame.y)}" width="${r1(z.frame.w)}" height="${r1(z.frame.h)}" rx="4"/>${guides}`;
|
|
148
|
+
base.push(hide === undefined ? lens : `<g class="dg-a" style="${m.until(hide)}">${lens}</g>`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// 時刻の目盛りの線と字と区切り
|
|
152
|
+
const x = (u: number): number => r1(axis.x + u * axis.unit);
|
|
153
|
+
const majors = layout.ticks.map((t) => `M ${x(t.at)} ${r1(axis.line - T.major / 2)} V ${r1(axis.line + T.major / 2)}`);
|
|
154
|
+
const minors = layout.minor.map((u) => `M ${x(u)} ${r1(axis.line - T.minor / 2)} V ${r1(axis.line + T.minor / 2)}`);
|
|
155
|
+
base.push(`<path class="dg-tm-ax" d="M ${x(0)} ${r1(axis.line)} H ${x(axis.count)} ${[...majors, ...minors].join(" ")}"/>`);
|
|
156
|
+
for (const t of layout.ticks) base.push(write(ink, ja("dg-tm-tk", t.text), t.left, t.y, t.text, TYPE.timeTick));
|
|
157
|
+
for (const p of layout.periods) {
|
|
158
|
+
base.push(write(ink, ja("dg-tm-en", p.name), p.x + p.w / 2, p.nameY, p.name, TYPE.timePeriod, ALWAYS, "middle"));
|
|
159
|
+
base.push(write(ink, ja("dg-tm-er", p.range), p.x + p.w / 2, p.rangeY, p.range, TYPE.timeRange, ALWAYS, "middle"));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// 範囲の括弧と囲み
|
|
163
|
+
for (const span of layout.spans) {
|
|
164
|
+
const a = at(span.step, span.event);
|
|
165
|
+
if (a === undefined) continue;
|
|
166
|
+
const until = span.until === undefined ? undefined : (timeline.steps[span.until] as Span).start;
|
|
167
|
+
const shown: Shown[] = [[a, until ?? Number.POSITIVE_INFINITY]];
|
|
168
|
+
const vis = until === undefined ? m.vis(a) : m.vis(a, until, { within: true });
|
|
169
|
+
if (span.kind === "bracket") {
|
|
170
|
+
const [x0, x1, y0, y1] = [r1(span.x + 1), r1(span.x + span.w - 1), r1(span.y), r1(span.y + span.h)];
|
|
171
|
+
const words = write(ink, ja("dg-tm-bt", span.text), span.textRect.x + span.textRect.w / 2, span.textY, span.text, TYPE.spanText, shown, "middle");
|
|
172
|
+
base.push(`<g class="dg-a" data-span="${span.step}" style="${cs(span.color)};${vis}"><path class="dg-tm-br" d="M ${x0} ${y0} L ${x0} ${y1} L ${x1} ${y1} L ${x1} ${y0}"/>${words}</g>`);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
base.push(`<g class="dg-a" data-span="${span.step}" style="${cs(span.color)};${vis}"><rect class="dg-tm-bx" x="${r1(span.x)}" y="${r1(span.y)}" width="${r1(span.w)}" height="${r1(span.h)}" rx="6"/></g>`);
|
|
176
|
+
const tag = span.textRect;
|
|
177
|
+
ink.push({ text: span.text, rect: tag, shown, boxed: true });
|
|
178
|
+
top.push(
|
|
179
|
+
`<g class="dg-tg dg-popc dg-a" style="${cs(span.color)};${until === undefined ? m.pop(a) : m.pop(a, until)}"><rect x="${r1(tag.x)}" y="${r1(tag.y)}" width="${r1(tag.w)}" height="${tag.h}" rx="${tag.h / 2}"/><text x="${r1(tag.x + tag.w / 2)}" y="${r1(span.textY)}" text-anchor="middle">${esc(span.text)}</text></g>`,
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// 節目。点線の丸で待ち、状態を変えるたびに色の丸を弾ませ、状態の字を書き換える
|
|
184
|
+
const P = T.point;
|
|
185
|
+
for (const point of layout.points) {
|
|
186
|
+
const { cx, cy, r } = point;
|
|
187
|
+
const times = point.changes.map((c) => at(c.step, c.event) ?? Number.POSITIVE_INFINITY);
|
|
188
|
+
const first = times[0];
|
|
189
|
+
base.push(`<path class="dg-tm-con" d="M ${r1(cx)} ${r1(rowsBottom + 3)} L ${r1(cx)} ${r1(cy - r - 2)}"/>`);
|
|
190
|
+
const tx = point.text.x;
|
|
191
|
+
const name = write(ink, ja("dg-tm-pn", point.id), tx, cy + P.nameY, point.id, TYPE.pointName);
|
|
192
|
+
const grey = name.replace(/class="([^"]*)"/u, 'class="$1 dg-tm-pn-g"');
|
|
193
|
+
const label = first === undefined || !Number.isFinite(first) ? grey : `<g class="dg-a" style="${m.until(first)}">${grey}</g><g class="dg-a" style="${m.vis(first)}">${name}</g>`;
|
|
194
|
+
const states = point.changes
|
|
195
|
+
.map((c, k) => {
|
|
196
|
+
const t = times[k] as number;
|
|
197
|
+
if (!Number.isFinite(t)) return "";
|
|
198
|
+
const next = times[k + 1];
|
|
199
|
+
const end = next !== undefined && Number.isFinite(next) ? next - MOTION.untilFade : undefined;
|
|
200
|
+
const words = write(ink, ja("dg-tm-ps", c.text), tx, cy + P.stateY, c.text, TYPE.pointState, [[t, end ?? Number.POSITIVE_INFINITY]]);
|
|
201
|
+
return `<g class="dg-a" style="${cs(c.color ?? "slate")};${end === undefined ? m.rise(t) : m.rise(t, end)}">${words}</g>`;
|
|
202
|
+
})
|
|
203
|
+
.join("");
|
|
204
|
+
const rings = point.changes
|
|
205
|
+
.map((c, k) => {
|
|
206
|
+
const t = times[k] as number;
|
|
207
|
+
if (!c.color || !Number.isFinite(t)) return "";
|
|
208
|
+
return `<g class="dg-popc dg-a" style="${cs(c.color)};${m.pop(t)}"><circle class="dg-tm-pc" cx="${r1(cx)}" cy="${r1(cy)}" r="${r + 0.5}"/>${glyph("flag", cx, cy, P.glyph, "dg-tm-pcg")}</g>`;
|
|
209
|
+
})
|
|
210
|
+
.join("");
|
|
211
|
+
node.push(`<g data-point="${esc(point.id)}"><circle class="dg-tm-pg" cx="${r1(cx)}" cy="${r1(cy)}" r="${r}"/>${glyph("flag", cx, cy, P.glyph, "dg-tm-pgl")}${rings}${label}${states}</g>`);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// 節目どうしの線。引いた後も残す
|
|
215
|
+
const wired = new Set(layout.wires.map((w) => `${w.step}/${w.event}`));
|
|
216
|
+
for (const e of layout.edges) {
|
|
217
|
+
if (wired.has(`${e.step}/${e.event}`)) continue;
|
|
218
|
+
const time = timeline.edges.find((t) => t.step === e.step && t.event === e.event);
|
|
219
|
+
if (!time) continue;
|
|
220
|
+
ctx.traces.push({ from: e.from, to: e.to, points: e.points, shown: [[time.start, Number.POSITIVE_INFINITY]] });
|
|
221
|
+
const kf = m.kf([
|
|
222
|
+
[0, { opacity: 0, "stroke-dashoffset": 1 }],
|
|
223
|
+
[time.start, { opacity: 0, "stroke-dashoffset": 1 }, EASE.inOut],
|
|
224
|
+
[time.start + 0.05, { opacity: 1 }],
|
|
225
|
+
[time.drawn, { "stroke-dashoffset": 0 }],
|
|
226
|
+
[m.last, { opacity: 1, "stroke-dashoffset": 0 }, EASE.inOut],
|
|
227
|
+
[m.total, { opacity: 0, "stroke-dashoffset": 0 }],
|
|
228
|
+
]);
|
|
229
|
+
const head = m.kf([
|
|
230
|
+
[0, { opacity: 0 }],
|
|
231
|
+
[time.drawn - 0.05, { opacity: 0 }],
|
|
232
|
+
[time.drawn, { opacity: 1 }],
|
|
233
|
+
[m.last, { opacity: 1 }, EASE.inOut],
|
|
234
|
+
[m.total, { opacity: 0 }],
|
|
235
|
+
]);
|
|
236
|
+
lit.push(`<g data-link="${esc(`${e.from}->${e.to}`)}" style="${cs(e.color)}"><path class="dg-tm-ln dg-a" pathLength="1" d="${pathOf(e.points)}" style="${kf}"/><path class="dg-eh-on dg-a" d="${arrowHead(e.points)}" style="${head}"/></g>`);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// 針。時刻の表の針の動きを辿り、繰り返す前に左端へ戻る
|
|
240
|
+
const keys = timeline.needle ?? [];
|
|
241
|
+
const moved = simplify(keys.filter(([t]) => t < m.total));
|
|
242
|
+
const end = moved[moved.length - 1]?.[1] ?? 0;
|
|
243
|
+
const path: [number, number, number][] = [...moved.map(([t, u]): [number, number, number] => [t, axis.x + u * axis.unit, 0]), [m.last, axis.x + end * axis.unit, 0], [m.total, axis.x, 0]];
|
|
244
|
+
const { y1, y2 } = layout.needle;
|
|
245
|
+
const N = T.needle;
|
|
246
|
+
top.push(
|
|
247
|
+
`<g class="dg-a" data-needle="" style="${m.move(path)}"><line class="dg-tm-nd" x1="0" y1="${r1(y1)}" x2="0" y2="${r1(y2)}"/><path class="dg-tm-nh" d="M ${-N.head * 0.75} ${r1(y1 - N.head)} L ${N.head * 0.75} ${r1(y1 - N.head)} L 0 ${r1(y1)} Z"/><circle class="dg-tm-nh" cy="${r1(axis.line)}" r="${N.dot}"/></g>`,
|
|
248
|
+
);
|
|
249
|
+
return { base: base.join(""), lit: lit.join(""), node: node.join(""), top: top.join("") };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** 中身の帯の物差しの欄 (#3165)。棒を満ち具合の動きで伸ばし、`line` の割合の所に線の印と字を置く */
|
|
253
|
+
export function meterField(field: { x: number; y: number; meter: { line: number; text: string; x: number; w: number } }, keys: [number, number][], ctx: Ctx): string {
|
|
254
|
+
const { m } = ctx;
|
|
255
|
+
const M = LOOK.time.meter;
|
|
256
|
+
const { x, w, line, text } = field.meter;
|
|
257
|
+
const y = field.y + M.y;
|
|
258
|
+
const kf = m.kf([
|
|
259
|
+
...simplify(keys).map(([t, v]): [number, Record<string, string>] => [t, { transform: `scaleX(${r1(v * 1000) / 1000})` }]),
|
|
260
|
+
[m.last, { transform: `scaleX(${r1(valueAt(keys, m.last) * 1000) / 1000})` }, EASE.inOut],
|
|
261
|
+
[m.total, { transform: "scaleX(0)" }],
|
|
262
|
+
]);
|
|
263
|
+
const lx = x + w * line;
|
|
264
|
+
return (
|
|
265
|
+
`<rect class="dg-tm-mt" x="${r1(x)}" y="${r1(y)}" width="${r1(w)}" height="${M.h}" rx="${M.h / 2}"/>` +
|
|
266
|
+
`<rect class="dg-tm-mf dg-a" x="${r1(x)}" y="${r1(y)}" width="${r1(w)}" height="${M.h}" rx="${M.h / 2}" style="${cs(M.color)};${kf}"/>` +
|
|
267
|
+
`<line class="dg-tm-mk" x1="${r1(lx)}" y1="${r1(y - M.mark)}" x2="${r1(lx)}" y2="${r1(y + M.h + M.mark)}"/>` +
|
|
268
|
+
write(ctx.ink, "dg-tm-ml", lx, field.y + M.textY, text, TYPE.meterLine, ALWAYS, "middle")
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** 時間軸の図で、寄って追う窓が段の終わりに見せる所。針と印の列を必ず入れ、段の番号と段で動く物を窓に収まる間だけ足す */
|
|
273
|
+
export function timeFocus(layout: TimeLayout, timeline: Timeline, step: number, parts: { x: number; y: number; w: number; h: number }[], vw: number, vh: number): { x: number; y: number; w: number; h: number } {
|
|
274
|
+
const span = timeline.steps[step] as Span;
|
|
275
|
+
const position = valueAt(timeline.needle ?? [], span.end - MOTION.still);
|
|
276
|
+
const nx = layout.axis.x + position * layout.axis.unit;
|
|
277
|
+
const top = Math.min(...layout.rows.map((r) => r.y));
|
|
278
|
+
const bottom = Math.max(...layout.rows.map((r) => r.y + r.h));
|
|
279
|
+
let held = { x: nx - 1, y: top, w: 2, h: bottom - top };
|
|
280
|
+
const badge = layout.badges.find((b) => b.step === step);
|
|
281
|
+
const near = (p: { x: number; y: number; w: number; h: number }): number => Math.hypot(Math.max(0, p.x - nx, nx - p.x - p.w), Math.max(0, p.y - top, top - p.y - p.h));
|
|
282
|
+
const extra = [...(badge ? [{ x: badge.x - LOOK.badge.r, y: badge.y - LOOK.badge.r, w: LOOK.badge.r * 2, h: LOOK.badge.r * 2 }] : []), ...[...parts].sort((a, b) => near(a) - near(b))];
|
|
283
|
+
for (const p of extra) {
|
|
284
|
+
const x = Math.min(held.x, p.x);
|
|
285
|
+
const y = Math.min(held.y, p.y);
|
|
286
|
+
const next = { x, y, w: Math.max(held.x + held.w, p.x + p.w) - x, h: Math.max(held.y + held.h, p.y + p.h) - y };
|
|
287
|
+
if (next.w <= vw && next.h <= vh) held = next;
|
|
288
|
+
}
|
|
289
|
+
return held;
|
|
290
|
+
}
|
|
291
|
+
|