@seanyeh77/ui 0.7.0 → 0.8.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/dist/bundle.js +7 -7
- package/dist/bundle.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +401 -253
- package/dist/index.js.map +1 -1
- package/docs/DataTable.md +2 -1
- package/docs/LayerGraph.md +3 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2928,7 +2928,7 @@ function DataTable(p) {
|
|
|
2928
2928
|
const [q, setQ] = React.useState(() => fromUrl().q);
|
|
2929
2929
|
const [values, setValues] = React.useState(() => fromUrl().values);
|
|
2930
2930
|
const [view, setView] = React.useState(p.views?.[0]?.id ?? null);
|
|
2931
|
-
const [
|
|
2931
|
+
const [toggled, setToggled] = React.useState({});
|
|
2932
2932
|
const [sel, setSel] = React.useState({});
|
|
2933
2933
|
const [sumVal, setSumVal] = React.useState("all");
|
|
2934
2934
|
const [resetKey, setResetKey] = React.useState(p.resetKey);
|
|
@@ -2944,6 +2944,7 @@ function DataTable(p) {
|
|
|
2944
2944
|
key: null,
|
|
2945
2945
|
dir: "desc"
|
|
2946
2946
|
});
|
|
2947
|
+
setToggled({});
|
|
2947
2948
|
}
|
|
2948
2949
|
const valuesKey = JSON.stringify(values);
|
|
2949
2950
|
React.useEffect(() => {
|
|
@@ -2951,7 +2952,11 @@ function DataTable(p) {
|
|
|
2951
2952
|
}, [valuesKey, q]);
|
|
2952
2953
|
devWarn(cols.some((c) => c.format === "percent" && !c.unit), "DataTable", "format: 'percent' sets 1 decimal and shows no % sign; add unit: '%' to that column.");
|
|
2953
2954
|
devWarn(rows.length > 1 && rows.every((r) => get(r, "id") == null) && selectable, "DataTable", "rows have no id, so a selection follows the position, not the row. Add an id to each row.");
|
|
2954
|
-
|
|
2955
|
+
devWarn(!!cols[0]?.hidden, "DataTable", "the first column is always shown, so its hidden: true does nothing. Move the column, or drop hidden.");
|
|
2956
|
+
devWarn((p.columnMenu === false || cols.length <= 2) && cols.some((c, i) => i > 0 && c.hidden), "DataTable", "a column has hidden: true but there is no 「欄位」 menu (columnMenu is false, or the table has 2 columns or fewer), so nobody can turn it on. Turn the menu on, or leave the column out.");
|
|
2957
|
+
const hidden = {};
|
|
2958
|
+
cols.forEach((c, i) => hidden[c.key] = i > 0 && (toggled[c.key] ?? !!c.hidden));
|
|
2959
|
+
const shownCols = cols.filter((c) => !hidden[c.key]);
|
|
2955
2960
|
const { ref: scrollRef, more: scrollMore, overflows, scrolled, onScroll } = useScrollHint();
|
|
2956
2961
|
const bodyRef = React.useRef(null);
|
|
2957
2962
|
const rowEls = React.useRef({});
|
|
@@ -3347,8 +3352,8 @@ function DataTable(p) {
|
|
|
3347
3352
|
p.columnMenu !== false && cols.length > 2 ? /* @__PURE__ */ jsx(ColumnMenu, {
|
|
3348
3353
|
cols,
|
|
3349
3354
|
hidden,
|
|
3350
|
-
onToggle: (k) =>
|
|
3351
|
-
...
|
|
3355
|
+
onToggle: (k) => setToggled({
|
|
3356
|
+
...toggled,
|
|
3352
3357
|
[k]: !hidden[k]
|
|
3353
3358
|
})
|
|
3354
3359
|
}) : null
|
|
@@ -4141,6 +4146,50 @@ function labelWidth(text) {
|
|
|
4141
4146
|
return w + c.measureText(t[0] === "`" ? t.slice(1, -1) : t).width;
|
|
4142
4147
|
}, 0);
|
|
4143
4148
|
}
|
|
4149
|
+
const GROW = 24;
|
|
4150
|
+
const GROW_MAX = 144;
|
|
4151
|
+
/** The label on 1 line, then wrapped onto 2, 3 and 4 lines as evenly as it goes. Breaks between Chinese characters
|
|
4152
|
+
* and at spaces; never inside `code`, a word or a number, between a number and the word after it, before a closing
|
|
4153
|
+
* mark or after an opening one. */
|
|
4154
|
+
function wraps(text) {
|
|
4155
|
+
const atoms = [];
|
|
4156
|
+
for (const t of text.match(/`[^`]+`|[A-Za-z0-9_./:#@-]+|\s+|[\s\S]/gu) ?? []) {
|
|
4157
|
+
const prev = atoms[atoms.length - 1];
|
|
4158
|
+
const unit = /\d\s*$/.test(prev ?? "") && !/^[A-Za-z0-9_]/.test(t);
|
|
4159
|
+
if (prev != null && (unit || /^[)」』、,。:;!?)\]]/.test(t) || /[(「『([]$/.test(prev))) atoms[atoms.length - 1] = prev + t;
|
|
4160
|
+
else atoms.push(t);
|
|
4161
|
+
}
|
|
4162
|
+
const fill = (max) => {
|
|
4163
|
+
const lines = [];
|
|
4164
|
+
let cur = "";
|
|
4165
|
+
for (const a of atoms) {
|
|
4166
|
+
if (/^\s+$/.test(a)) {
|
|
4167
|
+
if (cur) cur += a;
|
|
4168
|
+
continue;
|
|
4169
|
+
}
|
|
4170
|
+
if (cur && labelWidth(cur.trimEnd() + a) > max) {
|
|
4171
|
+
lines.push(cur.trimEnd());
|
|
4172
|
+
cur = a;
|
|
4173
|
+
} else cur += a;
|
|
4174
|
+
}
|
|
4175
|
+
if (cur.trim()) lines.push(cur.trimEnd());
|
|
4176
|
+
return lines;
|
|
4177
|
+
};
|
|
4178
|
+
const full = labelWidth(text);
|
|
4179
|
+
const out = [[text]];
|
|
4180
|
+
for (let n = 2; n <= 4; n++) {
|
|
4181
|
+
let lo = Math.max(...atoms.filter((a) => a.trim()).map(labelWidth)) - 1;
|
|
4182
|
+
let hi = full;
|
|
4183
|
+
while (hi - lo > 1) {
|
|
4184
|
+
const mid = (lo + hi) / 2;
|
|
4185
|
+
if (fill(mid).length <= n) hi = mid;
|
|
4186
|
+
else lo = mid;
|
|
4187
|
+
}
|
|
4188
|
+
const lines = fill(hi);
|
|
4189
|
+
if (lines.length > out[out.length - 1].length) out.push(lines);
|
|
4190
|
+
}
|
|
4191
|
+
return out;
|
|
4192
|
+
}
|
|
4144
4193
|
function labelParts(text) {
|
|
4145
4194
|
return text.split(SPLIT).filter(Boolean).map((t, i) => t[0] === "`" || /^\d/.test(t) ? /* @__PURE__ */ jsx("span", {
|
|
4146
4195
|
className: "ui-lg-code",
|
|
@@ -4199,7 +4248,8 @@ function LayerGraph(p) {
|
|
|
4199
4248
|
const layers = [...byLayer.keys()].sort((a, b) => a - b);
|
|
4200
4249
|
const cols = Math.max(1, ...layers.map((l) => byLayer.get(l)?.length ?? 0));
|
|
4201
4250
|
let W = 32 + cols * NW + (cols - 1) * COL;
|
|
4202
|
-
const
|
|
4251
|
+
const gaps = layers.map(() => GAP);
|
|
4252
|
+
let H = 0;
|
|
4203
4253
|
const pos = {};
|
|
4204
4254
|
const layerIndex = {};
|
|
4205
4255
|
layers.forEach((l, k) => {
|
|
@@ -4208,11 +4258,16 @@ function LayerGraph(p) {
|
|
|
4208
4258
|
row.forEach((n, i) => {
|
|
4209
4259
|
pos[n.id] = {
|
|
4210
4260
|
x: off + i * (NW + COL),
|
|
4211
|
-
y:
|
|
4261
|
+
y: 0
|
|
4212
4262
|
};
|
|
4213
4263
|
layerIndex[n.id] = k;
|
|
4214
4264
|
});
|
|
4215
4265
|
});
|
|
4266
|
+
const rowTop = (k) => PAD + k * NH + gaps.slice(0, k).reduce((a, b) => a + b, 0);
|
|
4267
|
+
const placeRows = () => {
|
|
4268
|
+
for (const id in pos) pos[id].y = rowTop(layerIndex[id]);
|
|
4269
|
+
H = rowTop(layers.length - 1) + NH + PAD;
|
|
4270
|
+
};
|
|
4216
4271
|
const maxSize = Math.max(1, ...main.map((n) => sizeOf(n) || 0));
|
|
4217
4272
|
const maxCount = Math.max(1, ...edges.map((e) => e.count || 0));
|
|
4218
4273
|
const isUp = (e) => !!pos[e.from] && !!pos[e.to] && layerIndex[e.to] < layerIndex[e.from];
|
|
@@ -4296,277 +4351,370 @@ function LayerGraph(p) {
|
|
|
4296
4351
|
if (next && sel != null) p.onSelect?.(null);
|
|
4297
4352
|
pickEdge?.(next);
|
|
4298
4353
|
};
|
|
4299
|
-
const
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
const
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
y0
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
y1
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
[
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4354
|
+
const draw = () => {
|
|
4355
|
+
const paths = [];
|
|
4356
|
+
const labels = [];
|
|
4357
|
+
const need = /* @__PURE__ */ new Set();
|
|
4358
|
+
const marks = [];
|
|
4359
|
+
const runs = [];
|
|
4360
|
+
const segs = [];
|
|
4361
|
+
const arrows = [];
|
|
4362
|
+
const hitPaths = [];
|
|
4363
|
+
edges.forEach((e, idx) => {
|
|
4364
|
+
const a = pos[e.from];
|
|
4365
|
+
const b = pos[e.to];
|
|
4366
|
+
if (!a || !b) return;
|
|
4367
|
+
const r = related(e);
|
|
4368
|
+
const dim = focus && !r;
|
|
4369
|
+
const picked = e === selEdge;
|
|
4370
|
+
const hovered = !!pickEdge && hover === edgeId(e) && !r;
|
|
4371
|
+
const up = isUp(e);
|
|
4372
|
+
let pts;
|
|
4373
|
+
let tx;
|
|
4374
|
+
let ty;
|
|
4375
|
+
let arrow;
|
|
4376
|
+
let inn = 1;
|
|
4377
|
+
if (up) {
|
|
4378
|
+
const lx = laneX(e);
|
|
4379
|
+
const L = onLeft(e);
|
|
4380
|
+
const si = upOut[e.from].indexOf(e);
|
|
4381
|
+
const sn = upOut[e.from].length;
|
|
4382
|
+
const ti = upIn[e.to].indexOf(e);
|
|
4383
|
+
const tn = upIn[e.to].length;
|
|
4384
|
+
const start = [];
|
|
4385
|
+
let y0;
|
|
4386
|
+
if (L ? leftmost(e.from) : rightmost(e.from)) {
|
|
4387
|
+
y0 = Math.round(a.y + NH / 2 + (si - (sn - 1) / 2) * 10);
|
|
4388
|
+
start.push([L ? a.x : a.x + NW, y0], [lx, y0]);
|
|
4389
|
+
} else {
|
|
4390
|
+
const px = L ? a.x + 20 + si * 10 : a.x + NW - 20 - si * 10;
|
|
4391
|
+
y0 = a.y - 12 - si * 6;
|
|
4392
|
+
start.push([px, a.y], [px, y0], [lx, y0]);
|
|
4393
|
+
}
|
|
4394
|
+
let y1;
|
|
4395
|
+
if (L || rightmost(e.to)) {
|
|
4396
|
+
y1 = Math.round(b.y + NH / 2 + (ti - (tn - 1) / 2) * 10);
|
|
4397
|
+
tx = L ? b.x : b.x + NW;
|
|
4398
|
+
ty = y1;
|
|
4399
|
+
const back = L ? tx - 9 : tx + 9;
|
|
4400
|
+
pts = [
|
|
4401
|
+
...start,
|
|
4402
|
+
[lx, y1],
|
|
4403
|
+
[back, y1]
|
|
4404
|
+
];
|
|
4405
|
+
arrow = `M${back} ${ty - 5} L${back} ${ty + 5} L${tx} ${ty} Z`;
|
|
4406
|
+
arrows.push([
|
|
4407
|
+
Math.min(tx, back),
|
|
4408
|
+
Math.max(tx, back),
|
|
4409
|
+
ty - 5,
|
|
4410
|
+
ty + 5
|
|
4411
|
+
]);
|
|
4412
|
+
runs.push([
|
|
4413
|
+
Math.min(tx, lx),
|
|
4414
|
+
Math.max(tx, lx),
|
|
4415
|
+
y1 - 3,
|
|
4416
|
+
y1 + 3
|
|
4417
|
+
]);
|
|
4418
|
+
} else {
|
|
4419
|
+
tx = b.x + NW - 20 - ti * 10;
|
|
4420
|
+
y1 = b.y + NH + 12 + ti * 6;
|
|
4421
|
+
ty = b.y + NH;
|
|
4422
|
+
pts = [
|
|
4423
|
+
...start,
|
|
4424
|
+
[lx, y1],
|
|
4425
|
+
[tx, y1],
|
|
4426
|
+
[tx, ty + 9]
|
|
4427
|
+
];
|
|
4428
|
+
arrow = `M${tx - 5} ${ty + 9} L${tx + 5} ${ty + 9} L${tx} ${ty} Z`;
|
|
4429
|
+
arrows.push([
|
|
4430
|
+
tx - 5,
|
|
4431
|
+
tx + 5,
|
|
4432
|
+
ty,
|
|
4433
|
+
ty + 9
|
|
4434
|
+
]);
|
|
4435
|
+
runs.push([
|
|
4436
|
+
tx,
|
|
4437
|
+
lx,
|
|
4438
|
+
y1 - 3,
|
|
4439
|
+
y1 + 3
|
|
4440
|
+
]);
|
|
4441
|
+
}
|
|
4442
|
+
const sx0 = start[start.length - 2][0];
|
|
4355
4443
|
runs.push([
|
|
4356
|
-
Math.min(
|
|
4357
|
-
Math.max(
|
|
4358
|
-
|
|
4359
|
-
|
|
4444
|
+
Math.min(sx0, lx),
|
|
4445
|
+
Math.max(sx0, lx),
|
|
4446
|
+
y0 - 3,
|
|
4447
|
+
y0 + 3
|
|
4360
4448
|
]);
|
|
4449
|
+
if (e.inferred || r) {
|
|
4450
|
+
const text = e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e);
|
|
4451
|
+
marks.push({
|
|
4452
|
+
idx,
|
|
4453
|
+
e,
|
|
4454
|
+
text,
|
|
4455
|
+
tx: L ? upLabelX : upLabelEndL,
|
|
4456
|
+
ty: Math.round((y0 + y1) / 2),
|
|
4457
|
+
left: !L,
|
|
4458
|
+
r,
|
|
4459
|
+
dim,
|
|
4460
|
+
up: true
|
|
4461
|
+
});
|
|
4462
|
+
}
|
|
4361
4463
|
} else {
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4464
|
+
const oi = outs[e.from].indexOf(e);
|
|
4465
|
+
const on = outs[e.from].length;
|
|
4466
|
+
const ii = ins[e.to].indexOf(e);
|
|
4467
|
+
inn = ins[e.to].length;
|
|
4468
|
+
const sx = Math.round(a.x + NW * (oi + 1) / (on + 1));
|
|
4469
|
+
const sy = a.y + NH;
|
|
4470
|
+
tx = Math.round(b.x + NW * (ii + 1) / (inn + 1));
|
|
4471
|
+
ty = b.y;
|
|
4472
|
+
const off = (oi - (on - 1) / 2) * 6;
|
|
4473
|
+
const y1 = sy + gaps[layerIndex[e.from]] / 2 + off;
|
|
4474
|
+
if (layerIndex[e.to] - layerIndex[e.from] > 1) {
|
|
4475
|
+
const next = (byLayer.get(layers[layerIndex[e.from] + 1]) ?? []).map((n) => pos[n.id]);
|
|
4476
|
+
const mid = (sx + tx) / 2;
|
|
4477
|
+
const chans = [next[0].x - COL / 2, ...next.map((q) => q.x + NW + COL / 2)].map((c) => Math.max(PAD / 2, Math.min(W - PAD / 2, c)));
|
|
4478
|
+
const chx = chans.reduce((best, c) => Math.abs(c - mid) < Math.abs(best - mid) ? c : best, chans[0]) + off;
|
|
4479
|
+
const y2 = ty - gaps[layerIndex[e.to] - 1] / 2 + off;
|
|
4480
|
+
pts = [
|
|
4481
|
+
[sx, sy],
|
|
4482
|
+
[sx, y1],
|
|
4483
|
+
[chx, y1],
|
|
4484
|
+
[chx, y2],
|
|
4485
|
+
[tx, y2],
|
|
4486
|
+
[tx, ty - 8]
|
|
4487
|
+
];
|
|
4488
|
+
} else pts = [
|
|
4489
|
+
[sx, sy],
|
|
4490
|
+
[sx, y1],
|
|
4368
4491
|
[tx, y1],
|
|
4369
|
-
[tx, ty
|
|
4492
|
+
[tx, ty - 8]
|
|
4370
4493
|
];
|
|
4371
|
-
arrow = `M${tx - 5} ${ty
|
|
4494
|
+
arrow = `M${tx - 5} ${ty - 9} L${tx + 5} ${ty - 9} L${tx} ${ty} Z`;
|
|
4372
4495
|
arrows.push([
|
|
4373
4496
|
tx - 5,
|
|
4374
4497
|
tx + 5,
|
|
4375
|
-
ty,
|
|
4376
|
-
ty
|
|
4377
|
-
]);
|
|
4378
|
-
runs.push([
|
|
4379
|
-
tx,
|
|
4380
|
-
lx,
|
|
4381
|
-
y1 - 3,
|
|
4382
|
-
y1 + 3
|
|
4498
|
+
ty - 9,
|
|
4499
|
+
ty
|
|
4383
4500
|
]);
|
|
4384
4501
|
}
|
|
4385
|
-
const
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4502
|
+
const w = (e.inferred ? 1.5 : 1.5 + 5.5 * ((e.count || 0) / maxCount)) + (picked ? 1.5 : 0) + (hovered ? 2 : 0);
|
|
4503
|
+
const cpts = clean(pts);
|
|
4504
|
+
for (let k = 1; k < cpts.length; k++) {
|
|
4505
|
+
const [ax, ay] = cpts[k - 1];
|
|
4506
|
+
const [bx, by] = cpts[k];
|
|
4507
|
+
segs.push({
|
|
4508
|
+
idx,
|
|
4509
|
+
box: [
|
|
4510
|
+
Math.min(ax, bx) - 3,
|
|
4511
|
+
Math.max(ax, bx) + 3,
|
|
4512
|
+
Math.min(ay, by) - 3,
|
|
4513
|
+
Math.max(ay, by) + 3
|
|
4514
|
+
]
|
|
4515
|
+
});
|
|
4516
|
+
}
|
|
4517
|
+
const d = route(cpts, 10);
|
|
4518
|
+
paths.push(/* @__PURE__ */ jsx("path", {
|
|
4519
|
+
className: cx("ui-lg-edge", e.inferred && "is-inferred", r && "is-related", dim && "is-dim", hovered && "is-hover"),
|
|
4520
|
+
d,
|
|
4521
|
+
strokeWidth: w
|
|
4522
|
+
}, "p" + idx));
|
|
4523
|
+
if (pickEdge) hitPaths.push(/* @__PURE__ */ jsx("path", {
|
|
4524
|
+
className: "ui-lg-hit",
|
|
4525
|
+
"data-edge": edgeId(e),
|
|
4526
|
+
d,
|
|
4527
|
+
role: "button",
|
|
4528
|
+
tabIndex: 0,
|
|
4529
|
+
"aria-label": `${nameOf(e.from)} → ${nameOf(e.to)},${(e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e)).replace(/`/g, "")}`,
|
|
4530
|
+
"aria-pressed": picked,
|
|
4531
|
+
onClick: (ev) => {
|
|
4532
|
+
ev.stopPropagation();
|
|
4533
|
+
choose(e);
|
|
4534
|
+
},
|
|
4535
|
+
onPointerEnter: () => setHover(edgeId(e)),
|
|
4536
|
+
onPointerLeave: () => setHover(null),
|
|
4537
|
+
onKeyDown: (ev) => {
|
|
4538
|
+
if (ev.key === "Enter" || ev.key === " ") {
|
|
4539
|
+
ev.preventDefault();
|
|
4540
|
+
choose(e);
|
|
4541
|
+
} else if (ev.key === "Escape" && picked) pickEdge(null);
|
|
4542
|
+
}
|
|
4543
|
+
}, "h" + idx));
|
|
4544
|
+
paths.push(/* @__PURE__ */ jsx("path", {
|
|
4545
|
+
className: cx("ui-lg-arrow", r && "is-related", dim && "is-dim"),
|
|
4546
|
+
d: arrow
|
|
4547
|
+
}, "a" + idx));
|
|
4548
|
+
if (!up && (e.inferred || r)) {
|
|
4393
4549
|
const text = e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e);
|
|
4394
4550
|
marks.push({
|
|
4395
4551
|
idx,
|
|
4396
4552
|
e,
|
|
4397
4553
|
text,
|
|
4398
|
-
tx
|
|
4399
|
-
ty
|
|
4400
|
-
left:
|
|
4554
|
+
tx,
|
|
4555
|
+
ty,
|
|
4556
|
+
left: inn > 1 && tx < b.x + NW / 2,
|
|
4401
4557
|
r,
|
|
4402
|
-
dim
|
|
4403
|
-
up: true
|
|
4558
|
+
dim
|
|
4404
4559
|
});
|
|
4405
4560
|
}
|
|
4406
|
-
}
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
const y2 = ty - GAP / 2 + off;
|
|
4423
|
-
pts = [
|
|
4424
|
-
[sx, sy],
|
|
4425
|
-
[sx, y1],
|
|
4426
|
-
[chx, y1],
|
|
4427
|
-
[chx, y2],
|
|
4428
|
-
[tx, y2],
|
|
4429
|
-
[tx, ty - 8]
|
|
4430
|
-
];
|
|
4431
|
-
} else pts = [
|
|
4432
|
-
[sx, sy],
|
|
4433
|
-
[sx, y1],
|
|
4434
|
-
[tx, y1],
|
|
4435
|
-
[tx, ty - 8]
|
|
4436
|
-
];
|
|
4437
|
-
arrow = `M${tx - 5} ${ty - 9} L${tx + 5} ${ty - 9} L${tx} ${ty} Z`;
|
|
4438
|
-
arrows.push([
|
|
4439
|
-
tx - 5,
|
|
4440
|
-
tx + 5,
|
|
4441
|
-
ty - 9,
|
|
4442
|
-
ty
|
|
4443
|
-
]);
|
|
4444
|
-
}
|
|
4445
|
-
const w = (e.inferred ? 1.5 : 1.5 + 5.5 * ((e.count || 0) / maxCount)) + (picked ? 1.5 : 0) + (hovered ? 2 : 0);
|
|
4446
|
-
const cpts = clean(pts);
|
|
4447
|
-
for (let k = 1; k < cpts.length; k++) {
|
|
4448
|
-
const [ax, ay] = cpts[k - 1];
|
|
4449
|
-
const [bx, by] = cpts[k];
|
|
4450
|
-
segs.push({
|
|
4451
|
-
idx,
|
|
4452
|
-
box: [
|
|
4453
|
-
Math.min(ax, bx) - 3,
|
|
4454
|
-
Math.max(ax, bx) + 3,
|
|
4455
|
-
Math.min(ay, by) - 3,
|
|
4456
|
-
Math.max(ay, by) + 3
|
|
4457
|
-
]
|
|
4458
|
-
});
|
|
4459
|
-
}
|
|
4460
|
-
const d = route(cpts, 10);
|
|
4461
|
-
paths.push(/* @__PURE__ */ jsx("path", {
|
|
4462
|
-
className: cx("ui-lg-edge", e.inferred && "is-inferred", r && "is-related", dim && "is-dim", hovered && "is-hover"),
|
|
4463
|
-
d,
|
|
4464
|
-
strokeWidth: w
|
|
4465
|
-
}, "p" + idx));
|
|
4466
|
-
if (pickEdge) hitPaths.push(/* @__PURE__ */ jsx("path", {
|
|
4467
|
-
className: "ui-lg-hit",
|
|
4468
|
-
"data-edge": edgeId(e),
|
|
4469
|
-
d,
|
|
4470
|
-
role: "button",
|
|
4471
|
-
tabIndex: 0,
|
|
4472
|
-
"aria-label": `${nameOf(e.from)} → ${nameOf(e.to)},${(e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e)).replace(/`/g, "")}`,
|
|
4473
|
-
"aria-pressed": picked,
|
|
4474
|
-
onClick: (ev) => {
|
|
4475
|
-
ev.stopPropagation();
|
|
4476
|
-
choose(e);
|
|
4561
|
+
});
|
|
4562
|
+
const placed = [...arrows, ...runs];
|
|
4563
|
+
const boxRects = main.map((n) => [
|
|
4564
|
+
pos[n.id].x,
|
|
4565
|
+
pos[n.id].x + NW,
|
|
4566
|
+
pos[n.id].y,
|
|
4567
|
+
pos[n.id].y + NH
|
|
4568
|
+
]);
|
|
4569
|
+
const hits = (x0, x1, y0, y1) => placed.some((q) => x0 < q[1] + (q[4] || 0) && q[0] < x1 + (q[4] || 0) && y0 < q[3] && q[2] < y1);
|
|
4570
|
+
const cross = (q, x0, lw, y0, y1) => x0 < q[1] - 1 && q[0] + 1 < x0 + lw && y0 < q[3] - 1 && q[2] + 1 < y1;
|
|
4571
|
+
const labelEl = (m, x0, top, lines = [m.text]) => /* @__PURE__ */ jsx("span", {
|
|
4572
|
+
"aria-hidden": pickEdge ? true : void 0,
|
|
4573
|
+
className: cx("ui-lg-label", pickEdge && "is-clickable", pickEdge && hover === edgeId(m.e) && "is-hover", m.r && "is-related", m.dim && "is-dim"),
|
|
4574
|
+
style: {
|
|
4575
|
+
left: x0,
|
|
4576
|
+
top
|
|
4477
4577
|
},
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
style: {
|
|
4517
|
-
left: x0,
|
|
4518
|
-
top
|
|
4519
|
-
},
|
|
4520
|
-
onClick: pickEdge ? (ev) => {
|
|
4521
|
-
ev.stopPropagation();
|
|
4522
|
-
choose(m.e);
|
|
4523
|
-
} : void 0,
|
|
4524
|
-
onPointerEnter: pickEdge ? () => setHover(edgeId(m.e)) : void 0,
|
|
4525
|
-
onPointerLeave: pickEdge ? () => setHover(null) : void 0,
|
|
4526
|
-
children: labelParts(m.text)
|
|
4527
|
-
}, "l" + m.idx);
|
|
4528
|
-
marks.sort((m, n) => m.ty - n.ty || m.tx - n.tx).forEach((m) => {
|
|
4529
|
-
const w = Math.ceil(labelWidth(m.text));
|
|
4530
|
-
if (m.up) {
|
|
4531
|
-
const x0 = Math.max(PAD / 2, Math.min(W - PAD / 2 - w, m.left ? m.tx - w : m.tx));
|
|
4532
|
-
const over = (q, y0, y1) => x0 < q[1] + 4 && q[0] < x0 + w + 4 && y0 < q[3] + 4 && q[2] < y1 + 4;
|
|
4533
|
-
const blocked = (y0, y1) => hits(x0, x0 + w, y0, y1) || boxRects.some((q) => over(q, y0, y1));
|
|
4534
|
-
const crosses = (y0, y1) => segs.some((g) => g.idx !== m.idx && over(g.box, y0, y1));
|
|
4535
|
-
const start = Math.max(10, Math.min(H - 10, m.ty));
|
|
4536
|
-
const find = (bad) => {
|
|
4537
|
-
for (let k = 0; k <= 16; k++) for (const dir of k ? [-1, 1] : [0]) {
|
|
4538
|
-
const t = start + dir * k * 18;
|
|
4539
|
-
if (t >= 10 && t <= H - 10 && !bad(t - 8, t + 8)) return t;
|
|
4578
|
+
onClick: pickEdge ? (ev) => {
|
|
4579
|
+
ev.stopPropagation();
|
|
4580
|
+
choose(m.e);
|
|
4581
|
+
} : void 0,
|
|
4582
|
+
onPointerEnter: pickEdge ? () => setHover(edgeId(m.e)) : void 0,
|
|
4583
|
+
onPointerLeave: pickEdge ? () => setHover(null) : void 0,
|
|
4584
|
+
children: lines.map((t, i) => /* @__PURE__ */ jsxs(React.Fragment, { children: [i ? /* @__PURE__ */ jsx("br", {}) : null, labelParts(t)] }, i))
|
|
4585
|
+
}, "l" + m.idx);
|
|
4586
|
+
marks.sort((m, n) => Number(!!m.up) - Number(!!n.up) || m.ty - n.ty || m.tx - n.tx).forEach((m) => {
|
|
4587
|
+
const w = Math.ceil(labelWidth(m.text));
|
|
4588
|
+
if (m.up) {
|
|
4589
|
+
const x0Of = (lw) => Math.max(PAD / 2, Math.min(W - PAD / 2 - lw, m.left ? m.tx - lw : m.tx));
|
|
4590
|
+
const start0 = Math.max(10, Math.min(H - 10, m.ty));
|
|
4591
|
+
const find = (x0, lw, lh, withLines) => {
|
|
4592
|
+
const over = (q, y0, y1) => x0 < q[1] + 4 && q[0] < x0 + lw + 4 && y0 < q[3] + 4 && q[2] < y1 + 4;
|
|
4593
|
+
const bad = (y0, y1) => hits(x0, x0 + lw, y0 - 4, y1 + 4) || boxRects.some((q) => over(q, y0, y1)) || withLines && segs.some((g) => g.idx === m.idx ? cross(g.box, x0, lw, y0, y1) : over(g.box, y0, y1));
|
|
4594
|
+
for (let k = 0; k <= 16; k++) for (const dir of k ? [-1, 1] : [0]) {
|
|
4595
|
+
const t = start0 + dir * k * 18;
|
|
4596
|
+
if (t - lh / 2 >= 2 && t + lh / 2 <= H - 2 && !bad(t - lh / 2, t + lh / 2)) return t;
|
|
4597
|
+
}
|
|
4598
|
+
return null;
|
|
4599
|
+
};
|
|
4600
|
+
let spot = null;
|
|
4601
|
+
for (const lines of wraps(m.text)) {
|
|
4602
|
+
const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
|
|
4603
|
+
const lh = lines.length * 16;
|
|
4604
|
+
const x0 = x0Of(lw);
|
|
4605
|
+
const top = find(x0, lw, lh, true);
|
|
4606
|
+
if (top != null) {
|
|
4607
|
+
spot = {
|
|
4608
|
+
x0,
|
|
4609
|
+
top,
|
|
4610
|
+
lw,
|
|
4611
|
+
lh,
|
|
4612
|
+
lines
|
|
4613
|
+
};
|
|
4614
|
+
break;
|
|
4615
|
+
}
|
|
4540
4616
|
}
|
|
4541
|
-
|
|
4617
|
+
if (!spot) {
|
|
4618
|
+
const g = Math.max(0, Math.min(layers.length - 2, layers.findIndex((_, k) => k < layers.length - 1 && m.ty < rowTop(k + 1))));
|
|
4619
|
+
need.add(g);
|
|
4620
|
+
const x0 = x0Of(w);
|
|
4621
|
+
spot = {
|
|
4622
|
+
x0,
|
|
4623
|
+
top: find(x0, w, 16, false) ?? start0,
|
|
4624
|
+
lw: w,
|
|
4625
|
+
lh: 16,
|
|
4626
|
+
lines: [m.text]
|
|
4627
|
+
};
|
|
4628
|
+
}
|
|
4629
|
+
placed.push([
|
|
4630
|
+
spot.x0,
|
|
4631
|
+
spot.x0 + spot.lw,
|
|
4632
|
+
spot.top - spot.lh / 2 - 4,
|
|
4633
|
+
spot.top + spot.lh / 2 + 4,
|
|
4634
|
+
6
|
|
4635
|
+
]);
|
|
4636
|
+
labels.push(labelEl(m, spot.x0, spot.top, spot.lines));
|
|
4637
|
+
return;
|
|
4638
|
+
}
|
|
4639
|
+
const g = layerIndex[m.e.to] - 1;
|
|
4640
|
+
const sideOf = (lw) => {
|
|
4641
|
+
let left = m.left;
|
|
4642
|
+
if (left && m.tx - 8 - lw < 0) left = false;
|
|
4643
|
+
else if (!left && m.tx + 8 + lw > W) left = m.tx - 8 - lw >= 0;
|
|
4644
|
+
return left;
|
|
4645
|
+
};
|
|
4646
|
+
const at = (left, lw) => left ? m.tx - 8 - lw : Math.min(m.tx + 8, W - lw);
|
|
4647
|
+
const clear = (x0, lw, y0, y1) => {
|
|
4648
|
+
const over = (q) => x0 < q[1] + 2 && q[0] < x0 + lw + 2 && y0 < q[3] + 2 && q[2] < y1 + 2;
|
|
4649
|
+
return !hits(x0, x0 + lw, y0, y1) && !boxRects.some(over) && !segs.some((sg) => sg.idx === m.idx ? cross(sg.box, x0, lw, y0, y1) : over(sg.box));
|
|
4542
4650
|
};
|
|
4543
|
-
|
|
4651
|
+
let spot = null;
|
|
4652
|
+
for (const lines of wraps(m.text)) {
|
|
4653
|
+
const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
|
|
4654
|
+
const lh = lines.length * 16;
|
|
4655
|
+
const pref = sideOf(lw);
|
|
4656
|
+
for (const left of [pref, !pref]) {
|
|
4657
|
+
const x0 = at(left, lw);
|
|
4658
|
+
if (x0 < 0 || x0 + lw > W) continue;
|
|
4659
|
+
for (let k = 0; k < 8 && !spot; k++) {
|
|
4660
|
+
const top = m.ty - 8 - lh / 2 - k * 18;
|
|
4661
|
+
if (top - lh / 2 < 2) break;
|
|
4662
|
+
if (clear(x0, lw, top - lh / 2, top + lh / 2)) spot = {
|
|
4663
|
+
x0,
|
|
4664
|
+
top,
|
|
4665
|
+
lw,
|
|
4666
|
+
lh,
|
|
4667
|
+
lines
|
|
4668
|
+
};
|
|
4669
|
+
}
|
|
4670
|
+
if (spot) break;
|
|
4671
|
+
}
|
|
4672
|
+
if (spot) break;
|
|
4673
|
+
}
|
|
4674
|
+
if (!spot) {
|
|
4675
|
+
if (g >= 0) need.add(g);
|
|
4676
|
+
const x0 = at(sideOf(w), w);
|
|
4677
|
+
let top = m.ty - 16;
|
|
4678
|
+
for (let k = 0; k < 8 && hits(x0, x0 + w, top - 8, top + 8); k++) top -= 18;
|
|
4679
|
+
spot = {
|
|
4680
|
+
x0,
|
|
4681
|
+
top,
|
|
4682
|
+
lw: w,
|
|
4683
|
+
lh: 16,
|
|
4684
|
+
lines: [m.text]
|
|
4685
|
+
};
|
|
4686
|
+
}
|
|
4544
4687
|
placed.push([
|
|
4545
|
-
x0,
|
|
4546
|
-
x0 +
|
|
4547
|
-
top -
|
|
4548
|
-
top +
|
|
4688
|
+
spot.x0,
|
|
4689
|
+
spot.x0 + spot.lw,
|
|
4690
|
+
spot.top - spot.lh / 2,
|
|
4691
|
+
spot.top + spot.lh / 2,
|
|
4549
4692
|
6
|
|
4550
4693
|
]);
|
|
4551
|
-
labels.push(labelEl(m, x0, top));
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4694
|
+
labels.push(labelEl(m, spot.x0, spot.top, spot.lines));
|
|
4695
|
+
});
|
|
4696
|
+
return {
|
|
4697
|
+
paths,
|
|
4698
|
+
labels,
|
|
4699
|
+
hitPaths,
|
|
4700
|
+
need
|
|
4701
|
+
};
|
|
4702
|
+
};
|
|
4703
|
+
placeRows();
|
|
4704
|
+
let drawn = draw();
|
|
4705
|
+
const grows = () => [...drawn.need].filter((g) => gaps[g] < 200);
|
|
4706
|
+
for (let k = 0; k < GROW_MAX / GROW && grows().length; k++) {
|
|
4707
|
+
for (const g of grows()) gaps[g] = Math.min(200, gaps[g] + GROW);
|
|
4708
|
+
placeRows();
|
|
4709
|
+
drawn = draw();
|
|
4710
|
+
}
|
|
4711
|
+
const stuck = [...drawn.need].filter((g) => gaps[g] >= 200);
|
|
4712
|
+
if (stuck.length) {
|
|
4713
|
+
for (const g of stuck) gaps[g] = GAP;
|
|
4714
|
+
placeRows();
|
|
4715
|
+
drawn = draw();
|
|
4716
|
+
}
|
|
4717
|
+
const { paths, labels, hitPaths } = drawn;
|
|
4570
4718
|
const sizeText = p.sizeLabel ?? tr("{n} 個項目");
|
|
4571
4719
|
const useText = p.useLabel ?? tr("使用 {n} 次");
|
|
4572
4720
|
const nodes = main.map((n) => {
|