@x-cmd/draw 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/render/ladder.js +1 -19
- package/dist/specs/ladder.js +29 -36
- package/package.json +1 -1
package/dist/render/ladder.js
CHANGED
|
@@ -76,11 +76,9 @@ export function renderLadder(spec, o) {
|
|
|
76
76
|
const x = (v) => left + (v / xMax) * (right - left);
|
|
77
77
|
const bg = card(width, height);
|
|
78
78
|
const parts = [];
|
|
79
|
+
// 刻度:只留数字(背景网格线不要 ✓ —— 用户:「不需要背景网格线」✓)
|
|
79
80
|
for (const t of ticks) {
|
|
80
81
|
const gx = r2(x(t));
|
|
81
|
-
if (t > 0) {
|
|
82
|
-
parts.push(`<line x1="${gx}" y1="${r2(contentTop)}" x2="${gx}" y2="${r2(height - PAD - 26)}" stroke="var(--d-grid)" stroke-width="1"/>`);
|
|
83
|
-
}
|
|
84
82
|
parts.push(`<text x="${gx}" y="${r2(height - PAD - 26 + 16)}" text-anchor="middle" font-size="12" fill="var(--d-muted)" style="${TAB}">${fmtNum(t)}</text>`);
|
|
85
83
|
}
|
|
86
84
|
const yOf = (i) => contentTop + i * pitch + (pitch - barH) / 2;
|
|
@@ -162,22 +160,6 @@ export function renderButterflyLadder(spec, o) {
|
|
|
162
160
|
const rightMax = leftMax;
|
|
163
161
|
const bg = card(width, height);
|
|
164
162
|
const parts = [];
|
|
165
|
-
// 刻度:两侧同一套(共用一把标尺)
|
|
166
|
-
const grid = (max, dir) => {
|
|
167
|
-
if (max <= 0)
|
|
168
|
-
return;
|
|
169
|
-
const ticks = niceTicks(max, 4);
|
|
170
|
-
const tickMax = ticks[ticks.length - 1] || max;
|
|
171
|
-
for (const t of ticks) {
|
|
172
|
-
if (t === 0)
|
|
173
|
-
continue;
|
|
174
|
-
const dx = (t / tickMax) * half;
|
|
175
|
-
const x = dir < 0 ? centre - dx : centre + dx;
|
|
176
|
-
parts.push(`<line x1="${r2(x)}" y1="${r2(contentTop)}" x2="${r2(x)}" y2="${r2(height - PAD - 26)}" stroke="var(--d-grid)"/>`);
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
grid(leftMax, -1);
|
|
180
|
-
grid(rightMax, 1);
|
|
181
163
|
parts.push(`<line x1="${r2(centre)}" y1="${r2(contentTop)}" x2="${r2(centre)}" y2="${r2(height - PAD - 26)}" stroke="var(--d-border)"/>`);
|
|
182
164
|
const yOf = (i) => contentTop + i * pitch + (pitch - barH) / 2;
|
|
183
165
|
// 档位:两侧的行是配对的,档以左边为准
|
package/dist/specs/ladder.js
CHANGED
|
@@ -220,49 +220,42 @@ export function matchLadderRows(left, right, match = 'rank') {
|
|
|
220
220
|
all.sort((a, b) => b.item.value - a.item.value);
|
|
221
221
|
return all.map((x) => (x.side === 0 ? [x.item, undefined] : [undefined, x.item]));
|
|
222
222
|
}
|
|
223
|
-
//
|
|
223
|
+
// 匹配排序:**右边的卡自动抬升**,落到左边数值对得上的那一行 ✓
|
|
224
224
|
//
|
|
225
|
-
//
|
|
226
|
-
//
|
|
227
|
-
//
|
|
225
|
+
// 规则(定死的 ✓):对右边的一张卡 r,找**最后一个**满足 `left[n].value >= r.value`
|
|
226
|
+
// 的行 n ✓ —— 于是 `left[n] >= r > left[n+1]` ✓,右边的卡刚好夹在左右两行之间 ✓
|
|
227
|
+
// (比左边最强的还强 ⇒ 顶行 ✓)。
|
|
228
228
|
//
|
|
229
|
-
//
|
|
230
|
-
//
|
|
231
|
-
//
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
let best = -1;
|
|
239
|
-
let bestGap = Infinity;
|
|
229
|
+
// 右边自己**按强弱排** ✓ ⇒ 抬升之后**顺序不变** ✓(这是要保证的 ✓)。
|
|
230
|
+
// 抢到同一行 ⇒ 后一张往下顺延 ✓。
|
|
231
|
+
//
|
|
232
|
+
// 两边都会空出几行 ✓ —— 那些行是真的没有能对上的卡 ✓(缺位是信号 ✓)。
|
|
233
|
+
const rightSorted = [...right].filter((x) => !!x).sort((a, b) => b.value - a.value);
|
|
234
|
+
const place = new Map(); // 行号 → 右边那张卡 ✓
|
|
235
|
+
const taken = new Set();
|
|
236
|
+
for (const r of rightSorted) {
|
|
237
|
+
let target = -1;
|
|
240
238
|
for (let i = 0; i < left.length; i++) {
|
|
241
239
|
const l = left[i];
|
|
242
|
-
if (!l
|
|
240
|
+
if (!l)
|
|
243
241
|
continue;
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
if (best >= 0) {
|
|
251
|
-
taken.add(best);
|
|
252
|
-
placeAt.set(best, j);
|
|
242
|
+
if (l.value >= r.value)
|
|
243
|
+
target = i;
|
|
244
|
+
else
|
|
245
|
+
break; // 左边是降序 ✓ 后面的只会更弱 ✓
|
|
253
246
|
}
|
|
247
|
+
if (target < 0)
|
|
248
|
+
target = 0; // 比左边最强的还强 ⇒ 顶行 ✓
|
|
249
|
+
let row = target;
|
|
250
|
+
while (taken.has(row))
|
|
251
|
+
row++; // 抢同一行 ⇒ 往下顺延 ✓
|
|
252
|
+
taken.add(row);
|
|
253
|
+
place.set(row, r);
|
|
254
254
|
}
|
|
255
|
-
|
|
256
|
-
const n = Math.max(left.length,
|
|
255
|
+
const last = place.size ? Math.max(...place.keys()) + 1 : 0;
|
|
256
|
+
const n = Math.max(left.length, last);
|
|
257
257
|
const rows = [];
|
|
258
|
-
for (let i = 0; i < n; i++)
|
|
259
|
-
|
|
260
|
-
let r;
|
|
261
|
-
if (j !== undefined)
|
|
262
|
-
r = right[j];
|
|
263
|
-
else if (i < right.length && !taken.has(i) && ![...placeAt.values()].includes(i))
|
|
264
|
-
r = right[i];
|
|
265
|
-
rows.push([left[i], r]);
|
|
266
|
-
}
|
|
258
|
+
for (let i = 0; i < n; i++)
|
|
259
|
+
rows.push([left[i], place.get(i)]);
|
|
267
260
|
return rows;
|
|
268
261
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-cmd/draw",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "SVG chart rendering as a service, a library, and a CLI — pie/bar/hbar/line/area/radar/gauge/scatter/combo/sankey/qr, same params everywhere",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|