@slickfast/mcp 0.2.1 → 0.4.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/index.js +1114 -9
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -806,6 +806,18 @@ function renderKpi(spec) {
|
|
|
806
806
|
p.push(`<rect x="${cx}" y="124" width="${pillW}" height="24" rx="12" fill="${pillBg}"/>`);
|
|
807
807
|
p.push(`<text x="${r(cx + pillW / 2)}" y="140" text-anchor="middle" font-size="12.5" ${wAttr(spec, 700)} fill="${pillTx}">${esc(dText)}</text>`);
|
|
808
808
|
}
|
|
809
|
+
const spark = spec.sparkline;
|
|
810
|
+
if (Array.isArray(spark) && spark.length >= 2) {
|
|
811
|
+
const sv = spark.map((n) => Number(n) || 0);
|
|
812
|
+
const lo = Math.min(...sv), hi = Math.max(...sv), span = hi - lo;
|
|
813
|
+
const sx0 = cx, sx1 = W - 16, syTop = H - 30, syBot = H - 16;
|
|
814
|
+
const sxOf = (i) => sx0 + i / (sv.length - 1) * (sx1 - sx0);
|
|
815
|
+
const syOf = (v) => span === 0 ? (syTop + syBot) / 2 : syBot - (v - lo) / span * (syBot - syTop);
|
|
816
|
+
const sparkCol = good ? isDark ? "#6ee7b7" : "#059669" : bad ? isDark ? "#fca5a5" : "#dc2626" : accent;
|
|
817
|
+
const pts = sv.map((v, i) => `${r(sxOf(i))},${r(syOf(v))}`).join(" ");
|
|
818
|
+
p.push(`<polyline points="${pts}" fill="none" stroke="${sparkCol}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>`);
|
|
819
|
+
p.push(`<circle cx="${r(sxOf(sv.length - 1))}" cy="${r(syOf(sv[sv.length - 1]))}" r="2.6" fill="${sparkCol}"/>`);
|
|
820
|
+
}
|
|
809
821
|
} else {
|
|
810
822
|
const hasLabel = !!label;
|
|
811
823
|
const px = Math.round(W * 0.09);
|
|
@@ -1098,7 +1110,7 @@ function renderPie(spec) {
|
|
|
1098
1110
|
return p.join("\n");
|
|
1099
1111
|
}
|
|
1100
1112
|
function renderPieOfPie(spec) {
|
|
1101
|
-
const W = spec.width || 920, H = spec.height ||
|
|
1113
|
+
const W = spec.width || 920, H = spec.height || 460;
|
|
1102
1114
|
const bg = spec.background || "#ffffff";
|
|
1103
1115
|
const transparent = bg === "transparent" || bg === "none";
|
|
1104
1116
|
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
@@ -1108,6 +1120,8 @@ function renderPieOfPie(spec) {
|
|
|
1108
1120
|
const watermark = spec.watermark !== false;
|
|
1109
1121
|
const donut = spec.donut !== false;
|
|
1110
1122
|
const showValues = spec.showValues !== false;
|
|
1123
|
+
const pre = spec.valuePrefix || "";
|
|
1124
|
+
const u = spec.valueUnit ? " " + spec.valueUnit : "";
|
|
1111
1125
|
const titleCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1112
1126
|
const subCol = txt(spec, isDark ? "#cbd5e1" : "#475569");
|
|
1113
1127
|
const faint = isDark ? "#475569" : "#94a3b8";
|
|
@@ -1155,7 +1169,10 @@ function renderPieOfPie(spec) {
|
|
|
1155
1169
|
const topMain = title ? 40 : 16;
|
|
1156
1170
|
const perTitleH = 30;
|
|
1157
1171
|
const botPad = 16 + (watermark ? 6 : 0);
|
|
1158
|
-
|
|
1172
|
+
const lgRowH = 22;
|
|
1173
|
+
const maxRows = Math.max(...pies.map((pie) => pie.labels.length));
|
|
1174
|
+
const legendH = maxRows * lgRowH + 14;
|
|
1175
|
+
let R = Math.min((W - 2 * sidePad - (n - 1) * gap) / sumDiam, (H - topMain - perTitleH - botPad - legendH) / 2);
|
|
1159
1176
|
R = Math.max(20, R);
|
|
1160
1177
|
const cyAxis = topMain + perTitleH + R;
|
|
1161
1178
|
const cxs = [];
|
|
@@ -1201,8 +1218,8 @@ function renderPieOfPie(spec) {
|
|
|
1201
1218
|
if (showValues && frac >= 0.07) {
|
|
1202
1219
|
const mid = (a + a1) / 2;
|
|
1203
1220
|
const lr = innerR > 0 ? (rad + innerR) / 2 : rad * 0.62;
|
|
1204
|
-
const
|
|
1205
|
-
p.push(`<text x="${r(drawCx + lr * Math.cos(mid))}" y="${r(cyAxis + lr * Math.sin(mid) + 4)}" text-anchor="middle" font-size="${
|
|
1221
|
+
const lfs2 = Math.max(9, r(fs * Math.sqrt(fac(i))));
|
|
1222
|
+
p.push(`<text x="${r(drawCx + lr * Math.cos(mid))}" y="${r(cyAxis + lr * Math.sin(mid) + 4)}" text-anchor="middle" font-size="${lfs2}" ${wAttr(spec, 700)} fill="${spec.textColor || contrastColor(col)}">${Math.round(frac * 100)}%</text>`);
|
|
1206
1223
|
}
|
|
1207
1224
|
a = a1;
|
|
1208
1225
|
});
|
|
@@ -1213,6 +1230,19 @@ function renderPieOfPie(spec) {
|
|
|
1213
1230
|
p.push(`<text x="${r(cx)}" y="${r(sy)}" text-anchor="middle" font-size="${fs - 3}"${wOpt(spec)} fill="${accent}">\u21B3 ${esc(parentLabel)}</text>`);
|
|
1214
1231
|
}
|
|
1215
1232
|
});
|
|
1233
|
+
const legendTop = cyAxis + R + 16;
|
|
1234
|
+
const lfs = fs - 1;
|
|
1235
|
+
pies.forEach((pie, i) => {
|
|
1236
|
+
const len = (si) => (String(pie.labels[si]) + " \xB7 " + pre + fmt(pie.values[si]) + u).length;
|
|
1237
|
+
const blockW = 16 + Math.max(0, ...pie.labels.map((_, si) => len(si))) * lfs * 0.55;
|
|
1238
|
+
const lx = cxs[i] - blockW / 2;
|
|
1239
|
+
let ly = legendTop;
|
|
1240
|
+
pie.labels.forEach((lab, si) => {
|
|
1241
|
+
p.push(`<rect x="${r(lx)}" y="${r(ly - 9)}" width="10" height="10" rx="2.5" fill="${pie.colors[si]}"/>`);
|
|
1242
|
+
p.push(`<text x="${r(lx + 16)}" y="${r(ly)}" font-size="${lfs}"${wOpt(spec)} fill="${subCol}">${esc(lab)} \xB7 ${esc(pre + fmt(pie.values[si]) + u)}</text>`);
|
|
1243
|
+
ly += lgRowH;
|
|
1244
|
+
});
|
|
1245
|
+
});
|
|
1216
1246
|
if (title) p.push(`<text x="${r(W / 2)}" y="26" text-anchor="middle" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${titleCol}">${esc(title)}</text>`);
|
|
1217
1247
|
if (watermark) p.push(`<text x="${r(W - 8)}" y="${r(H - 8)}" text-anchor="end" font-size="10" fill="${faint}" opacity="0.7">slickfast.com</text>`);
|
|
1218
1248
|
p.push(`</svg>`);
|
|
@@ -1240,6 +1270,965 @@ function applyPreset(spec) {
|
|
|
1240
1270
|
if (!p) return spec;
|
|
1241
1271
|
return { ...spec, width: spec.width != null ? spec.width : p[0], height: spec.height != null ? spec.height : p[1] };
|
|
1242
1272
|
}
|
|
1273
|
+
function renderCards(spec) {
|
|
1274
|
+
const cards = Array.isArray(spec.cards) ? spec.cards : [];
|
|
1275
|
+
const n = Math.max(1, cards.length);
|
|
1276
|
+
const title = spec.title || "";
|
|
1277
|
+
const cols = Math.max(1, Math.min(spec.columns ? Number(spec.columns) : Math.min(n, 4), n));
|
|
1278
|
+
const rows = Math.ceil(n / cols);
|
|
1279
|
+
const PAD = 24, GAP = 18, CARD_W = 300, CARD_H = 148;
|
|
1280
|
+
const titleH = title ? 44 : 0;
|
|
1281
|
+
const W = spec.width || PAD * 2 + cols * CARD_W + (cols - 1) * GAP;
|
|
1282
|
+
const H = spec.height || PAD * 2 + titleH + rows * CARD_H + (rows - 1) * GAP;
|
|
1283
|
+
const bg = spec.background || "#ffffff";
|
|
1284
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
1285
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
1286
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
1287
|
+
const font = resolveFont(spec);
|
|
1288
|
+
const watermark = spec.watermark !== false;
|
|
1289
|
+
const palette = resolveFlatPalette(spec.palette || "Clean Corporate", Math.max(n, 3));
|
|
1290
|
+
const titleCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1291
|
+
const labelCol = txt(spec, isDark ? "#94a3b8" : "#64748b");
|
|
1292
|
+
const valueCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1293
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
1294
|
+
const surface = isDark ? "#1e293b" : "#ffffff";
|
|
1295
|
+
const border = isDark ? "#334155" : "#e2e8f0";
|
|
1296
|
+
const cellW = (W - PAD * 2 - GAP * (cols - 1)) / cols;
|
|
1297
|
+
const cellH = (H - PAD * 2 - titleH - GAP * (rows - 1)) / rows;
|
|
1298
|
+
const p = [];
|
|
1299
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
1300
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
1301
|
+
if (title) p.push(`<text x="${r(W / 2)}" y="33" text-anchor="middle" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${titleCol}">${esc(title)}</text>`);
|
|
1302
|
+
cards.forEach((c, i) => {
|
|
1303
|
+
const col = i % cols, row = Math.floor(i / cols);
|
|
1304
|
+
const x = PAD + col * (cellW + GAP);
|
|
1305
|
+
const y = PAD + titleH + row * (cellH + GAP);
|
|
1306
|
+
const accent = contrastFloor(palette[i % palette.length], bg, transparent);
|
|
1307
|
+
p.push(`<rect x="${r(x)}" y="${r(y)}" width="${r(cellW)}" height="${r(cellH)}" rx="14" fill="${transparent ? "none" : surface}" stroke="${border}" stroke-width="1"/>`);
|
|
1308
|
+
p.push(`<rect x="${r(x + cellW * 0.05)}" y="${r(y + cellH * 0.18)}" width="5" height="${r(cellH * 0.64)}" rx="2.5" fill="${accent}"/>`);
|
|
1309
|
+
const contentX = r(x + cellW * 0.115);
|
|
1310
|
+
const labelFs = fs + 1;
|
|
1311
|
+
const valFs = Math.max(20, Math.round(cellH * 0.235));
|
|
1312
|
+
const valueStr = (c.valuePrefix || "") + fmt(c.value) + (c.valueUnit ? " " + c.valueUnit : "");
|
|
1313
|
+
const cLabel = c.label || "";
|
|
1314
|
+
if (cLabel) p.push(`<text x="${contentX}" y="${r(y + cellH * 0.27)}" font-size="${labelFs}" ${wAttr(spec, 600)} fill="${labelCol}">${esc(cLabel)}</text>`);
|
|
1315
|
+
p.push(`<text x="${contentX}" y="${r(y + cellH * 0.58)}" font-size="${valFs}" ${wAttr(spec, 800)} fill="${valueCol}">${esc(valueStr)}</text>`);
|
|
1316
|
+
const hasDelta = c.delta !== void 0 && c.delta !== null;
|
|
1317
|
+
if (hasDelta) {
|
|
1318
|
+
const d = Number(c.delta) || 0;
|
|
1319
|
+
const goodDown = c.deltaGoodWhen === "down";
|
|
1320
|
+
const good = goodDown ? d < 0 : d > 0;
|
|
1321
|
+
const bad = goodDown ? d > 0 : d < 0;
|
|
1322
|
+
const arrow = d > 0 ? "\u25B2" : d < 0 ? "\u25BC" : "\u2013";
|
|
1323
|
+
const dText = arrow + " " + fmt(Math.abs(d)) + (c.deltaUnit || "%");
|
|
1324
|
+
const pillBg = good ? isDark ? "#064e3b" : "#ecfdf5" : bad ? isDark ? "#7f1d1d" : "#fef2f2" : isDark ? "#334155" : "#f1f5f9";
|
|
1325
|
+
const pillTx = good ? isDark ? "#6ee7b7" : "#059669" : bad ? isDark ? "#fca5a5" : "#dc2626" : labelCol;
|
|
1326
|
+
const pillFs = 12.5;
|
|
1327
|
+
const pillH = 24;
|
|
1328
|
+
const pillW = Math.round(dText.length * 7.3 + 18);
|
|
1329
|
+
const py = r(y + cellH * 0.7);
|
|
1330
|
+
p.push(`<rect x="${contentX}" y="${py}" width="${pillW}" height="${pillH}" rx="12" fill="${pillBg}"/>`);
|
|
1331
|
+
p.push(`<text x="${r(Number(contentX) + pillW / 2)}" y="${r(Number(py) + 16)}" text-anchor="middle" font-size="${pillFs}" ${wAttr(spec, 700)} fill="${pillTx}">${esc(dText)}</text>`);
|
|
1332
|
+
}
|
|
1333
|
+
});
|
|
1334
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
1335
|
+
p.push(`</svg>`);
|
|
1336
|
+
return p.join("\n");
|
|
1337
|
+
}
|
|
1338
|
+
function renderLayers(spec) {
|
|
1339
|
+
const layers = Array.isArray(spec.layers) ? spec.layers : [];
|
|
1340
|
+
const n = Math.max(1, layers.length);
|
|
1341
|
+
const title = spec.title || "";
|
|
1342
|
+
const bg = spec.background || "#ffffff";
|
|
1343
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
1344
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
1345
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
1346
|
+
const font = resolveFont(spec);
|
|
1347
|
+
const watermark = spec.watermark !== false;
|
|
1348
|
+
const palette = resolveFlatPalette(spec.palette || "Clean Corporate", Math.max(n, 3));
|
|
1349
|
+
const titleCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1350
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
1351
|
+
const PAD = 24, GAP = 10, BLOCK_H = 72;
|
|
1352
|
+
const topY = title ? 54 : 24;
|
|
1353
|
+
const W = spec.width || 600;
|
|
1354
|
+
const H = spec.height || topY + n * BLOCK_H + (n - 1) * GAP + 16;
|
|
1355
|
+
const blockW = W - PAD * 2;
|
|
1356
|
+
const blockH = (H - topY - 16 - GAP * (n - 1)) / n;
|
|
1357
|
+
const p = [];
|
|
1358
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
1359
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
1360
|
+
if (title) p.push(`<text x="${r(W / 2)}" y="33" text-anchor="middle" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${titleCol}">${esc(title)}</text>`);
|
|
1361
|
+
layers.forEach((layer, i) => {
|
|
1362
|
+
const y = topY + i * (blockH + GAP);
|
|
1363
|
+
const fill = palette[i % palette.length];
|
|
1364
|
+
const tc = spec.textColor || contrastColor(fill);
|
|
1365
|
+
const cx = r(W / 2);
|
|
1366
|
+
const lTitle = layer.title || "";
|
|
1367
|
+
const lSub = layer.subtitle || "";
|
|
1368
|
+
p.push(`<rect x="${PAD}" y="${r(y)}" width="${r(blockW)}" height="${r(blockH)}" rx="12" fill="${fill}"/>`);
|
|
1369
|
+
if (lSub) {
|
|
1370
|
+
p.push(`<text x="${cx}" y="${r(y + blockH / 2 - 2)}" text-anchor="middle" font-size="${fs + 4}" ${wAttr(spec, 700)} fill="${tc}">${esc(lTitle)}</text>`);
|
|
1371
|
+
p.push(`<text x="${cx}" y="${r(y + blockH / 2 + 16)}" text-anchor="middle" font-size="${fs}"${wOpt(spec)} fill="${tc}" opacity="0.85">${esc(lSub)}</text>`);
|
|
1372
|
+
} else {
|
|
1373
|
+
p.push(`<text x="${cx}" y="${r(y + blockH / 2 + fs / 2)}" text-anchor="middle" font-size="${fs + 4}" ${wAttr(spec, 700)} fill="${tc}">${esc(lTitle)}</text>`);
|
|
1374
|
+
}
|
|
1375
|
+
});
|
|
1376
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
1377
|
+
p.push(`</svg>`);
|
|
1378
|
+
return p.join("\n");
|
|
1379
|
+
}
|
|
1380
|
+
function renderProgress(spec) {
|
|
1381
|
+
const bars = Array.isArray(spec.bars) ? spec.bars : [];
|
|
1382
|
+
const n = Math.max(1, bars.length);
|
|
1383
|
+
const title = spec.title || "";
|
|
1384
|
+
const bg = spec.background || "#ffffff";
|
|
1385
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
1386
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
1387
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
1388
|
+
const font = resolveFont(spec);
|
|
1389
|
+
const watermark = spec.watermark !== false;
|
|
1390
|
+
const palette = resolveFlatPalette(spec.palette || "Clean Corporate", Math.max(n, 3));
|
|
1391
|
+
const titleCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1392
|
+
const labelCol = txt(spec, isDark ? "#cbd5e1" : "#475569");
|
|
1393
|
+
const valCol = txt(spec, isDark ? "#e2e8f0" : "#334155");
|
|
1394
|
+
const trackCol = isDark ? "#334155" : "#e2e8f0";
|
|
1395
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
1396
|
+
const PAD = 24, ROW_H = 46;
|
|
1397
|
+
const topY = title ? 54 : 24;
|
|
1398
|
+
const W = spec.width || 600;
|
|
1399
|
+
const H = spec.height || topY + n * ROW_H + 8;
|
|
1400
|
+
const trackW = W - PAD * 2;
|
|
1401
|
+
const p = [];
|
|
1402
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
1403
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
1404
|
+
if (title) p.push(`<text x="${r(W / 2)}" y="33" text-anchor="middle" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${titleCol}">${esc(title)}</text>`);
|
|
1405
|
+
bars.forEach((b, i) => {
|
|
1406
|
+
const ry = topY + i * ROW_H;
|
|
1407
|
+
const val = Number(b.value) || 0;
|
|
1408
|
+
const hasTarget = b.target !== void 0 && b.target !== null;
|
|
1409
|
+
const target = Number(b.target) || 0;
|
|
1410
|
+
const unit = b.valueUnit || "";
|
|
1411
|
+
const ratio = hasTarget ? target > 0 ? val / target : 0 : val / 100;
|
|
1412
|
+
const cl = Math.max(0, Math.min(1, ratio));
|
|
1413
|
+
const valStr = hasTarget ? `${fmt(val)} / ${fmt(target)}${unit ? " " + unit : ""}` : `${fmt(val)}${unit || "%"}`;
|
|
1414
|
+
const fill = palette[i % palette.length];
|
|
1415
|
+
const labelY = ry + 13, barY = ry + 22, barH = 14;
|
|
1416
|
+
p.push(`<text x="${PAD}" y="${r(labelY)}" font-size="${fs}" ${wAttr(spec, 600)} fill="${labelCol}">${esc(b.label || "")}</text>`);
|
|
1417
|
+
p.push(`<text x="${W - PAD}" y="${r(labelY)}" text-anchor="end" font-size="${fs}"${wOpt(spec)} fill="${valCol}">${esc(valStr)}</text>`);
|
|
1418
|
+
p.push(`<rect x="${PAD}" y="${r(barY)}" width="${r(trackW)}" height="${barH}" rx="7" fill="${trackCol}"/>`);
|
|
1419
|
+
if (cl > 0) p.push(`<rect x="${PAD}" y="${r(barY)}" width="${r(Math.max(barH, cl * trackW))}" height="${barH}" rx="7" fill="${fill}"/>`);
|
|
1420
|
+
});
|
|
1421
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
1422
|
+
p.push(`</svg>`);
|
|
1423
|
+
return p.join("\n");
|
|
1424
|
+
}
|
|
1425
|
+
function renderWaffle(spec) {
|
|
1426
|
+
const parts = Array.isArray(spec.parts) ? spec.parts : [];
|
|
1427
|
+
const title = spec.title || "";
|
|
1428
|
+
const bg = spec.background || "#ffffff";
|
|
1429
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
1430
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
1431
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
1432
|
+
const font = resolveFont(spec);
|
|
1433
|
+
const watermark = spec.watermark !== false;
|
|
1434
|
+
const palette = resolveFlatPalette(spec.palette || "Clean Corporate", Math.max(parts.length, 3));
|
|
1435
|
+
const titleCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1436
|
+
const legendCol = txt(spec, isDark ? "#cbd5e1" : "#475569");
|
|
1437
|
+
const trackCol = isDark ? "#334155" : "#e2e8f0";
|
|
1438
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
1439
|
+
const vals = parts.map((pt) => Math.max(0, Number(pt.value) || 0));
|
|
1440
|
+
const sum = vals.reduce((a, b) => a + b, 0);
|
|
1441
|
+
const scale = sum > 100 ? 100 / sum : 1;
|
|
1442
|
+
const exact = vals.map((v) => v * scale);
|
|
1443
|
+
const cells = exact.map(Math.floor);
|
|
1444
|
+
const targetFilled = Math.min(100, Math.round(sum));
|
|
1445
|
+
const rem = targetFilled - cells.reduce((a, b) => a + b, 0);
|
|
1446
|
+
const order = exact.map((v, i) => [i, v - Math.floor(v)]).sort((a, b) => b[1] - a[1]);
|
|
1447
|
+
for (let k = 0; k < rem && order.length; k++) cells[order[k % order.length][0]]++;
|
|
1448
|
+
const colors = [];
|
|
1449
|
+
parts.forEach((pt, i) => {
|
|
1450
|
+
const c = pt.color || palette[i % palette.length];
|
|
1451
|
+
for (let k = 0; k < cells[i]; k++) colors.push(c);
|
|
1452
|
+
});
|
|
1453
|
+
while (colors.length < 100) colors.push(trackCol);
|
|
1454
|
+
colors.length = 100;
|
|
1455
|
+
const PAD = 24, CELL = 26, GAP = 4;
|
|
1456
|
+
const topY = title ? 54 : 24;
|
|
1457
|
+
const gridSize = 10 * CELL + 9 * GAP;
|
|
1458
|
+
const gridX = PAD, gridY = topY;
|
|
1459
|
+
const legendX = gridX + gridSize + 28;
|
|
1460
|
+
const W = spec.width || 600;
|
|
1461
|
+
const H = spec.height || topY + gridSize + 16;
|
|
1462
|
+
const p = [];
|
|
1463
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
1464
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
1465
|
+
if (title) p.push(`<text x="${r(W / 2)}" y="33" text-anchor="middle" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${titleCol}">${esc(title)}</text>`);
|
|
1466
|
+
for (let k = 0; k < 100; k++) {
|
|
1467
|
+
const row = Math.floor(k / 10), col = k % 10;
|
|
1468
|
+
const x = gridX + col * (CELL + GAP), y = gridY + row * (CELL + GAP);
|
|
1469
|
+
p.push(`<rect x="${r(x)}" y="${r(y)}" width="${CELL}" height="${CELL}" rx="4" fill="${colors[k]}"/>`);
|
|
1470
|
+
}
|
|
1471
|
+
parts.forEach((pt, i) => {
|
|
1472
|
+
const ly = topY + 6 + i * 24;
|
|
1473
|
+
const c = pt.color || palette[i % palette.length];
|
|
1474
|
+
p.push(`<rect x="${legendX}" y="${r(ly)}" width="13" height="13" rx="3" fill="${c}"/>`);
|
|
1475
|
+
p.push(`<text x="${legendX + 20}" y="${r(ly + 11)}" font-size="${fs}"${wOpt(spec)} fill="${legendCol}">${esc((pt.label || "") + " " + fmt(vals[i]))}</text>`);
|
|
1476
|
+
});
|
|
1477
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
1478
|
+
p.push(`</svg>`);
|
|
1479
|
+
return p.join("\n");
|
|
1480
|
+
}
|
|
1481
|
+
function renderHeatmap(spec) {
|
|
1482
|
+
const rows = Array.isArray(spec.rows) ? spec.rows : [];
|
|
1483
|
+
const cols = Array.isArray(spec.columns) ? spec.columns : [];
|
|
1484
|
+
const values = Array.isArray(spec.values) ? spec.values : [];
|
|
1485
|
+
const nr = Math.max(1, rows.length), nc = Math.max(1, cols.length);
|
|
1486
|
+
const title = spec.title || "";
|
|
1487
|
+
const bg = spec.background || "#ffffff";
|
|
1488
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
1489
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
1490
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
1491
|
+
const font = resolveFont(spec);
|
|
1492
|
+
const watermark = spec.watermark !== false;
|
|
1493
|
+
const showValues = spec.showValues !== false;
|
|
1494
|
+
const palette = resolveFlatPalette(spec.palette || "Clean Corporate", 3);
|
|
1495
|
+
const baseHsl = hexToHsl(palette[0]);
|
|
1496
|
+
const titleCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1497
|
+
const labelCol = txt(spec, isDark ? "#cbd5e1" : "#475569");
|
|
1498
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
1499
|
+
let min = Infinity, max = -Infinity;
|
|
1500
|
+
values.forEach((rv) => (rv || []).forEach((v) => {
|
|
1501
|
+
const x = Number(v) || 0;
|
|
1502
|
+
if (x < min) min = x;
|
|
1503
|
+
if (x > max) max = x;
|
|
1504
|
+
}));
|
|
1505
|
+
if (!isFinite(min)) {
|
|
1506
|
+
min = 0;
|
|
1507
|
+
max = 1;
|
|
1508
|
+
}
|
|
1509
|
+
const span = max - min || 1;
|
|
1510
|
+
const cellColor = (v) => hslToHex(baseHsl.h, Math.max(35, baseHsl.s), Math.max(0, Math.min(100, 92 - (v - min) / span * 52)));
|
|
1511
|
+
const PAD = 24, LEFT = 84, COLH = 24, CELL_H = 44;
|
|
1512
|
+
const topY = title ? 54 : 24;
|
|
1513
|
+
const W = spec.width || 640;
|
|
1514
|
+
const H = spec.height || topY + COLH + nr * CELL_H + 16;
|
|
1515
|
+
const plotLeft = PAD + LEFT;
|
|
1516
|
+
const plotW = W - PAD - plotLeft;
|
|
1517
|
+
const cellW = plotW / nc;
|
|
1518
|
+
const gridTop = topY + COLH;
|
|
1519
|
+
const p = [];
|
|
1520
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
1521
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
1522
|
+
if (title) p.push(`<text x="${r(W / 2)}" y="33" text-anchor="middle" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${titleCol}">${esc(title)}</text>`);
|
|
1523
|
+
cols.forEach((c, ci) => p.push(`<text x="${r(plotLeft + ci * cellW + cellW / 2)}" y="${r(gridTop - 8)}" text-anchor="middle" font-size="${fs - 1}"${wOpt(spec)} fill="${labelCol}">${esc(c)}</text>`));
|
|
1524
|
+
rows.forEach((rw, ri) => {
|
|
1525
|
+
const y = gridTop + ri * CELL_H;
|
|
1526
|
+
p.push(`<text x="${plotLeft - 10}" y="${r(y + CELL_H / 2 + 4)}" text-anchor="end" font-size="${fs - 1}"${wOpt(spec)} fill="${labelCol}">${esc(rw)}</text>`);
|
|
1527
|
+
cols.forEach((c, ci) => {
|
|
1528
|
+
const v = Number((values[ri] || [])[ci]) || 0;
|
|
1529
|
+
const col = cellColor(v);
|
|
1530
|
+
const x = plotLeft + ci * cellW;
|
|
1531
|
+
p.push(`<rect x="${r(x + 1)}" y="${r(y + 1)}" width="${r(cellW - 2)}" height="${CELL_H - 2}" rx="4" fill="${col}"/>`);
|
|
1532
|
+
if (showValues) p.push(`<text x="${r(x + cellW / 2)}" y="${r(y + CELL_H / 2 + 4)}" text-anchor="middle" font-size="${fs - 1}"${wOpt(spec)} fill="${spec.textColor || contrastColor(col)}">${esc(fmt(v))}</text>`);
|
|
1533
|
+
});
|
|
1534
|
+
});
|
|
1535
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
1536
|
+
p.push(`</svg>`);
|
|
1537
|
+
return p.join("\n");
|
|
1538
|
+
}
|
|
1539
|
+
function trapezoidPath(cx, yTop, topW, yBot, botW) {
|
|
1540
|
+
return `M${r(cx - topW / 2)},${r(yTop)} L${r(cx + topW / 2)},${r(yTop)} L${r(cx + botW / 2)},${r(yBot)} L${r(cx - botW / 2)},${r(yBot)} Z`;
|
|
1541
|
+
}
|
|
1542
|
+
function renderFunnel(spec) {
|
|
1543
|
+
const stages = Array.isArray(spec.stages) ? spec.stages : [];
|
|
1544
|
+
const n = Math.max(1, stages.length);
|
|
1545
|
+
const title = spec.title || "";
|
|
1546
|
+
const bg = spec.background || "#ffffff";
|
|
1547
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
1548
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
1549
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
1550
|
+
const font = resolveFont(spec);
|
|
1551
|
+
const watermark = spec.watermark !== false;
|
|
1552
|
+
const palette = resolveFlatPalette(spec.palette || "Clean Corporate", Math.max(n, 3));
|
|
1553
|
+
const titleCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1554
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
1555
|
+
const u = spec.valueUnit ? " " + spec.valueUnit : "";
|
|
1556
|
+
const PAD = 24, GAP = 6, BAND_H = 64;
|
|
1557
|
+
const topY = title ? 54 : 24;
|
|
1558
|
+
const W = spec.width || 600;
|
|
1559
|
+
const H = spec.height || topY + n * BAND_H + (n - 1) * GAP + 16;
|
|
1560
|
+
const plotW = W - PAD * 2;
|
|
1561
|
+
const cx = W / 2;
|
|
1562
|
+
const vals = stages.map((s) => Math.max(0, Number(s.value) || 0));
|
|
1563
|
+
const maxV = Math.max(1, ...vals);
|
|
1564
|
+
const top = vals[0] || 0;
|
|
1565
|
+
const p = [];
|
|
1566
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
1567
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
1568
|
+
if (title) p.push(`<text x="${r(cx)}" y="33" text-anchor="middle" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${titleCol}">${esc(title)}</text>`);
|
|
1569
|
+
stages.forEach((s, i) => {
|
|
1570
|
+
const yTop = topY + i * (BAND_H + GAP), yBot = yTop + BAND_H;
|
|
1571
|
+
const wTop = vals[i] / maxV * plotW;
|
|
1572
|
+
const wBot = (i < n - 1 ? vals[i + 1] : vals[i]) / maxV * plotW;
|
|
1573
|
+
const fill = palette[i % palette.length];
|
|
1574
|
+
const tc = spec.textColor || contrastColor(fill);
|
|
1575
|
+
const my = (yTop + yBot) / 2;
|
|
1576
|
+
const pct = top > 0 ? Math.round(vals[i] / top * 100) : 0;
|
|
1577
|
+
p.push(`<path d="${trapezoidPath(cx, yTop, wTop, yBot, wBot)}" fill="${fill}"/>`);
|
|
1578
|
+
p.push(`<text x="${r(cx)}" y="${r(my - 2)}" text-anchor="middle" font-size="${fs + 1}" ${wAttr(spec, 700)} fill="${tc}">${esc(s.label || "")}</text>`);
|
|
1579
|
+
p.push(`<text x="${r(cx)}" y="${r(my + 15)}" text-anchor="middle" font-size="${fs - 1}"${wOpt(spec)} fill="${tc}">${esc(fmt(vals[i]) + u + " \xB7 " + pct + "%")}</text>`);
|
|
1580
|
+
});
|
|
1581
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
1582
|
+
p.push(`</svg>`);
|
|
1583
|
+
return p.join("\n");
|
|
1584
|
+
}
|
|
1585
|
+
function renderPyramid(spec) {
|
|
1586
|
+
const levels = Array.isArray(spec.levels) ? spec.levels : [];
|
|
1587
|
+
const n = Math.max(1, levels.length);
|
|
1588
|
+
const title = spec.title || "";
|
|
1589
|
+
const bg = spec.background || "#ffffff";
|
|
1590
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
1591
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
1592
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
1593
|
+
const font = resolveFont(spec);
|
|
1594
|
+
const watermark = spec.watermark !== false;
|
|
1595
|
+
const palette = resolveFlatPalette(spec.palette || "Clean Corporate", Math.max(n, 3));
|
|
1596
|
+
const titleCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1597
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
1598
|
+
const PAD = 24;
|
|
1599
|
+
const topY = title ? 54 : 24;
|
|
1600
|
+
const W = spec.width || 600;
|
|
1601
|
+
const totalH = spec.height ? spec.height - topY - 16 : 300;
|
|
1602
|
+
const H = spec.height || topY + totalH + 16;
|
|
1603
|
+
const baseW = W - PAD * 2;
|
|
1604
|
+
const apexY = topY, cx = W / 2, bandH = totalH / n;
|
|
1605
|
+
const widthAt = (y) => (y - apexY) / totalH * baseW;
|
|
1606
|
+
const p = [];
|
|
1607
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
1608
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
1609
|
+
if (title) p.push(`<text x="${r(cx)}" y="33" text-anchor="middle" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${titleCol}">${esc(title)}</text>`);
|
|
1610
|
+
levels.forEach((lv, i) => {
|
|
1611
|
+
const yTop = apexY + i * bandH, yBot = apexY + (i + 1) * bandH;
|
|
1612
|
+
const fill = palette[i % palette.length];
|
|
1613
|
+
const tc = spec.textColor || contrastColor(fill);
|
|
1614
|
+
const hasVal = lv.value !== void 0 && lv.value !== null;
|
|
1615
|
+
const lbl = (lv.title || lv.label || "") + (hasVal ? " \xB7 " + fmt(Number(lv.value) || 0) : "");
|
|
1616
|
+
p.push(`<path d="${trapezoidPath(cx, yTop, widthAt(yTop), yBot, widthAt(yBot))}" fill="${fill}"/>`);
|
|
1617
|
+
p.push(`<text x="${r(cx)}" y="${r((yTop + yBot) / 2 + 4)}" text-anchor="middle" font-size="${fs + 1}" ${wAttr(spec, 700)} fill="${tc}">${esc(lbl)}</text>`);
|
|
1618
|
+
});
|
|
1619
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
1620
|
+
p.push(`</svg>`);
|
|
1621
|
+
return p.join("\n");
|
|
1622
|
+
}
|
|
1623
|
+
function renderQuadrant(spec) {
|
|
1624
|
+
const items = Array.isArray(spec.items) ? spec.items : [];
|
|
1625
|
+
const title = spec.title || "";
|
|
1626
|
+
const bg = spec.background || "#ffffff";
|
|
1627
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
1628
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
1629
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
1630
|
+
const font = resolveFont(spec);
|
|
1631
|
+
const watermark = spec.watermark !== false;
|
|
1632
|
+
const palette = resolveFlatPalette(spec.palette || "Clean Corporate", Math.max(items.length, 3));
|
|
1633
|
+
const titleCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1634
|
+
const labelCol = txt(spec, isDark ? "#e2e8f0" : "#334155");
|
|
1635
|
+
const axisCol = txt(spec, isDark ? "#cbd5e1" : "#475569");
|
|
1636
|
+
const gridCol = isDark ? "#334155" : "#e2e8f0";
|
|
1637
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
1638
|
+
const clamp01 = (v) => Math.max(0, Math.min(1, Number(v) || 0));
|
|
1639
|
+
const PAD = 24;
|
|
1640
|
+
const topY = title ? 54 : 30;
|
|
1641
|
+
const W = spec.width || 560, H = spec.height || 540;
|
|
1642
|
+
const plotTop = topY + 18;
|
|
1643
|
+
const S = Math.min(W - PAD * 2, H - plotTop - 46);
|
|
1644
|
+
const plotX = (W - S) / 2, plotBottom = plotTop + S;
|
|
1645
|
+
const p = [];
|
|
1646
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
1647
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
1648
|
+
if (title) p.push(`<text x="${r(W / 2)}" y="33" text-anchor="middle" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${titleCol}">${esc(title)}</text>`);
|
|
1649
|
+
p.push(`<rect x="${r(plotX)}" y="${r(plotTop)}" width="${r(S)}" height="${r(S)}" rx="8" fill="none" stroke="${gridCol}" stroke-width="1"/>`);
|
|
1650
|
+
p.push(`<line x1="${r(plotX + S / 2)}" y1="${r(plotTop)}" x2="${r(plotX + S / 2)}" y2="${r(plotBottom)}" stroke="${gridCol}" stroke-width="1"/>`);
|
|
1651
|
+
p.push(`<line x1="${r(plotX)}" y1="${r(plotTop + S / 2)}" x2="${r(plotX + S)}" y2="${r(plotTop + S / 2)}" stroke="${gridCol}" stroke-width="1"/>`);
|
|
1652
|
+
if (spec.yAxis) p.push(`<text x="${r(plotX)}" y="${r(plotTop - 8)}" font-size="${fs}" ${wAttr(spec, 600)} fill="${axisCol}">${esc(spec.yAxis)} \u2192</text>`);
|
|
1653
|
+
if (spec.xAxis) p.push(`<text x="${r(W / 2)}" y="${r(plotBottom + 28)}" text-anchor="middle" font-size="${fs}" ${wAttr(spec, 600)} fill="${axisCol}">${esc(spec.xAxis)} \u2192</text>`);
|
|
1654
|
+
items.forEach((it, i) => {
|
|
1655
|
+
const x = plotX + clamp01(it.x) * S;
|
|
1656
|
+
const y = plotTop + (1 - clamp01(it.y)) * S;
|
|
1657
|
+
const c = palette[i % palette.length];
|
|
1658
|
+
const rightHalf = clamp01(it.x) > 0.82;
|
|
1659
|
+
p.push(`<circle cx="${r(x)}" cy="${r(y)}" r="6" fill="${c}"/>`);
|
|
1660
|
+
p.push(`<text x="${r(rightHalf ? x - 10 : x + 10)}" y="${r(y + 4)}" text-anchor="${rightHalf ? "end" : "start"}" font-size="${fs}"${wOpt(spec)} fill="${labelCol}">${esc(it.label || "")}</text>`);
|
|
1661
|
+
});
|
|
1662
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
1663
|
+
p.push(`</svg>`);
|
|
1664
|
+
return p.join("\n");
|
|
1665
|
+
}
|
|
1666
|
+
function renderTimeline(spec) {
|
|
1667
|
+
const events = Array.isArray(spec.events) ? spec.events : [];
|
|
1668
|
+
const n = Math.max(1, events.length);
|
|
1669
|
+
const title = spec.title || "";
|
|
1670
|
+
const bg = spec.background || "#ffffff";
|
|
1671
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
1672
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
1673
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
1674
|
+
const font = resolveFont(spec);
|
|
1675
|
+
const watermark = spec.watermark !== false;
|
|
1676
|
+
const palette = resolveFlatPalette(spec.palette || "Clean Corporate", Math.max(n, 3));
|
|
1677
|
+
const titleCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1678
|
+
const labelTextCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1679
|
+
const dateCol = txt(spec, isDark ? "#cbd5e1" : "#475569");
|
|
1680
|
+
const lineCol = isDark ? "#475569" : "#cbd5e1";
|
|
1681
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
1682
|
+
const haloCol = transparent ? "#ffffff" : bg;
|
|
1683
|
+
const PAD = 44;
|
|
1684
|
+
const topY = title ? 54 : 24;
|
|
1685
|
+
const W = spec.width || 720, H = spec.height || 220;
|
|
1686
|
+
const lineY = topY + (H - topY) / 2;
|
|
1687
|
+
const plotW = W - PAD * 2;
|
|
1688
|
+
const xOf = (i) => n === 1 ? W / 2 : PAD + i * (plotW / (n - 1));
|
|
1689
|
+
const p = [];
|
|
1690
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
1691
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
1692
|
+
if (title) p.push(`<text x="${r(W / 2)}" y="33" text-anchor="middle" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${titleCol}">${esc(title)}</text>`);
|
|
1693
|
+
p.push(`<line x1="${PAD}" y1="${r(lineY)}" x2="${W - PAD}" y2="${r(lineY)}" stroke="${lineCol}" stroke-width="2"/>`);
|
|
1694
|
+
events.forEach((e, i) => {
|
|
1695
|
+
const x = xOf(i), c = palette[i % palette.length];
|
|
1696
|
+
const above = i % 2 === 0;
|
|
1697
|
+
p.push(`<circle cx="${r(x)}" cy="${r(lineY)}" r="6" fill="${c}" stroke="${haloCol}" stroke-width="3"/>`);
|
|
1698
|
+
if (above) {
|
|
1699
|
+
p.push(`<text x="${r(x)}" y="${r(lineY - 28)}" text-anchor="middle" font-size="${fs + 1}" ${wAttr(spec, 700)} fill="${labelTextCol}">${esc(e.label || "")}</text>`);
|
|
1700
|
+
if (e.date) p.push(`<text x="${r(x)}" y="${r(lineY - 13)}" text-anchor="middle" font-size="${fs - 1}"${wOpt(spec)} fill="${dateCol}">${esc(e.date)}</text>`);
|
|
1701
|
+
} else {
|
|
1702
|
+
if (e.date) p.push(`<text x="${r(x)}" y="${r(lineY + 20)}" text-anchor="middle" font-size="${fs - 1}"${wOpt(spec)} fill="${dateCol}">${esc(e.date)}</text>`);
|
|
1703
|
+
p.push(`<text x="${r(x)}" y="${r(lineY + 37)}" text-anchor="middle" font-size="${fs + 1}" ${wAttr(spec, 700)} fill="${labelTextCol}">${esc(e.label || "")}</text>`);
|
|
1704
|
+
}
|
|
1705
|
+
});
|
|
1706
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
1707
|
+
p.push(`</svg>`);
|
|
1708
|
+
return p.join("\n");
|
|
1709
|
+
}
|
|
1710
|
+
function renderVenn(spec) {
|
|
1711
|
+
const sets = Array.isArray(spec.sets) ? spec.sets : [];
|
|
1712
|
+
const ns = sets.length;
|
|
1713
|
+
const title = spec.title || "";
|
|
1714
|
+
const bg = spec.background || "#ffffff";
|
|
1715
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
1716
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
1717
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
1718
|
+
const font = resolveFont(spec);
|
|
1719
|
+
const watermark = spec.watermark !== false;
|
|
1720
|
+
const palette = resolveFlatPalette(spec.palette || "Clean Corporate", Math.max(ns, 3));
|
|
1721
|
+
const titleCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1722
|
+
const textCol = txt(spec, isDark ? "#f1f5f9" : "#1a1a1a");
|
|
1723
|
+
const labelCol = txt(spec, isDark ? "#cbd5e1" : "#475569");
|
|
1724
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
1725
|
+
const topY = title ? 54 : 24;
|
|
1726
|
+
const W = spec.width || 600, H = spec.height || 460;
|
|
1727
|
+
const val = (i) => fmt(Number(sets[i] && sets[i].value) || 0);
|
|
1728
|
+
const p = [];
|
|
1729
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
1730
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
1731
|
+
if (title) p.push(`<text x="${r(W / 2)}" y="33" text-anchor="middle" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${titleCol}">${esc(title)}</text>`);
|
|
1732
|
+
if (ns <= 2) {
|
|
1733
|
+
const R = 120, cy = topY + 40 + R;
|
|
1734
|
+
const cx1 = W / 2 - (ns === 2 ? 70 : 0), cx2 = W / 2 + 70;
|
|
1735
|
+
p.push(`<circle cx="${r(cx1)}" cy="${r(cy)}" r="${R}" fill="${palette[0]}" fill-opacity="0.5"/>`);
|
|
1736
|
+
p.push(`<text x="${r(cx1)}" y="${r(cy - R - 12)}" text-anchor="middle" font-size="${fs + 1}" ${wAttr(spec, 700)} fill="${labelCol}">${esc(sets[0] && sets[0].label || "")}</text>`);
|
|
1737
|
+
if (ns === 2) {
|
|
1738
|
+
p.push(`<circle cx="${r(cx2)}" cy="${r(cy)}" r="${R}" fill="${palette[1]}" fill-opacity="0.5"/>`);
|
|
1739
|
+
p.push(`<text x="${r(cx2)}" y="${r(cy - R - 12)}" text-anchor="middle" font-size="${fs + 1}" ${wAttr(spec, 700)} fill="${labelCol}">${esc(sets[1] && sets[1].label || "")}</text>`);
|
|
1740
|
+
p.push(`<text x="${r(cx1 - R * 0.45)}" y="${r(cy + 4)}" text-anchor="middle" font-size="${fs + 2}" ${wAttr(spec, 700)} fill="${textCol}">${val(0)}</text>`);
|
|
1741
|
+
p.push(`<text x="${r(cx2 + R * 0.45)}" y="${r(cy + 4)}" text-anchor="middle" font-size="${fs + 2}" ${wAttr(spec, 700)} fill="${textCol}">${val(1)}</text>`);
|
|
1742
|
+
if (spec.overlap !== void 0 && spec.overlap !== null) p.push(`<text x="${r(W / 2)}" y="${r(cy + 4)}" text-anchor="middle" font-size="${fs + 2}" ${wAttr(spec, 700)} fill="${textCol}">${esc(fmt(Number(spec.overlap) || 0))}</text>`);
|
|
1743
|
+
} else if (ns === 1) {
|
|
1744
|
+
p.push(`<text x="${r(cx1)}" y="${r(cy + 4)}" text-anchor="middle" font-size="${fs + 2}" ${wAttr(spec, 700)} fill="${textCol}">${val(0)}</text>`);
|
|
1745
|
+
}
|
|
1746
|
+
} else {
|
|
1747
|
+
const R = 100, cx = W / 2, cyTop = topY + 28 + R * 0.6;
|
|
1748
|
+
const c = [[cx, cyTop], [cx - R * 0.78, cyTop + R * 0.98], [cx + R * 0.78, cyTop + R * 0.98]];
|
|
1749
|
+
for (let i = 0; i < 3; i++) p.push(`<circle cx="${r(c[i][0])}" cy="${r(c[i][1])}" r="${R}" fill="${palette[i]}" fill-opacity="0.45"/>`);
|
|
1750
|
+
p.push(`<text x="${r(c[0][0])}" y="${r(c[0][1] - R - 8)}" text-anchor="middle" font-size="${fs + 1}" ${wAttr(spec, 700)} fill="${labelCol}">${esc((sets[0].label || "") + " " + val(0))}</text>`);
|
|
1751
|
+
p.push(`<text x="${r(c[1][0] - R * 0.4)}" y="${r(c[1][1] + R + 18)}" text-anchor="middle" font-size="${fs + 1}" ${wAttr(spec, 700)} fill="${labelCol}">${esc((sets[1].label || "") + " " + val(1))}</text>`);
|
|
1752
|
+
p.push(`<text x="${r(c[2][0] + R * 0.4)}" y="${r(c[2][1] + R + 18)}" text-anchor="middle" font-size="${fs + 1}" ${wAttr(spec, 700)} fill="${labelCol}">${esc((sets[2].label || "") + " " + val(2))}</text>`);
|
|
1753
|
+
}
|
|
1754
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
1755
|
+
p.push(`</svg>`);
|
|
1756
|
+
return p.join("\n");
|
|
1757
|
+
}
|
|
1758
|
+
function glyphCheck(cx, cy, s, col) {
|
|
1759
|
+
return `<path d="M${r(cx - s * 0.5)},${r(cy + s * 0.02)} L${r(cx - s * 0.12)},${r(cy + s * 0.42)} L${r(cx + s * 0.55)},${r(cy - s * 0.45)}" fill="none" stroke="${col}" stroke-width="${r(s * 0.26)}" stroke-linecap="round" stroke-linejoin="round"/>`;
|
|
1760
|
+
}
|
|
1761
|
+
function glyphCross(cx, cy, s, col) {
|
|
1762
|
+
return `<path d="M${r(cx - s * 0.4)},${r(cy - s * 0.4)} L${r(cx + s * 0.4)},${r(cy + s * 0.4)} M${r(cx + s * 0.4)},${r(cy - s * 0.4)} L${r(cx - s * 0.4)},${r(cy + s * 0.4)}" fill="none" stroke="${col}" stroke-width="${r(s * 0.24)}" stroke-linecap="round"/>`;
|
|
1763
|
+
}
|
|
1764
|
+
function glyphDot(cx, cy, s, col) {
|
|
1765
|
+
return `<circle cx="${r(cx)}" cy="${r(cy)}" r="${r(s * 0.36)}" fill="${col}"/>`;
|
|
1766
|
+
}
|
|
1767
|
+
function glyphRing(cx, cy, s, col) {
|
|
1768
|
+
return `<circle cx="${r(cx)}" cy="${r(cy)}" r="${r(s * 0.4)}" fill="none" stroke="${col}" stroke-width="${r(s * 0.18)}"/>`;
|
|
1769
|
+
}
|
|
1770
|
+
function glyphDash(cx, cy, s, col) {
|
|
1771
|
+
return `<line x1="${r(cx - s * 0.4)}" y1="${r(cy)}" x2="${r(cx + s * 0.4)}" y2="${r(cy)}" stroke="${col}" stroke-width="${r(s * 0.2)}" stroke-linecap="round"/>`;
|
|
1772
|
+
}
|
|
1773
|
+
function personGlyph(cx, topY, h, col) {
|
|
1774
|
+
const headR = h * 0.22, headCy = topY + headR;
|
|
1775
|
+
const bodyTop = headCy + headR * 1.2, bodyW = h * 0.64, bodyBot = topY + h;
|
|
1776
|
+
return `<circle cx="${r(cx)}" cy="${r(headCy)}" r="${r(headR)}" fill="${col}"/><path d="M${r(cx - bodyW / 2)},${r(bodyBot)} Q${r(cx - bodyW / 2)},${r(bodyTop)} ${r(cx)},${r(bodyTop)} Q${r(cx + bodyW / 2)},${r(bodyTop)} ${r(cx + bodyW / 2)},${r(bodyBot)} Z" fill="${col}"/>`;
|
|
1777
|
+
}
|
|
1778
|
+
function statusCellSvg(val, cx, cy, s, fs, textCol) {
|
|
1779
|
+
if (val === true) return glyphCheck(cx, cy, s, "#059669");
|
|
1780
|
+
if (val === false) return glyphCross(cx, cy, s, "#94a3b8");
|
|
1781
|
+
const t = String(val == null ? "" : val).trim().toLowerCase();
|
|
1782
|
+
if (["yes", "y", "true", "\u2713", "done", "included"].includes(t)) return glyphCheck(cx, cy, s, "#059669");
|
|
1783
|
+
if (["no", "n", "false", "\u2717", "x"].includes(t)) return glyphCross(cx, cy, s, "#94a3b8");
|
|
1784
|
+
if (["partial", "~", "half", "some", "limited"].includes(t)) return glyphDot(cx, cy, s, "#d97706");
|
|
1785
|
+
if (["", "-", "\u2013", "na", "n/a"].includes(t)) return glyphDash(cx, cy, s, "#cbd5e1");
|
|
1786
|
+
return `<text x="${r(cx)}" y="${r(cy + fs * 0.35)}" text-anchor="middle" font-size="${fs}" fill="${textCol}">${esc(String(val))}</text>`;
|
|
1787
|
+
}
|
|
1788
|
+
function renderMatrix(spec) {
|
|
1789
|
+
const columns = Array.isArray(spec.columns) ? spec.columns : [];
|
|
1790
|
+
const rows = Array.isArray(spec.rows) ? spec.rows : [];
|
|
1791
|
+
const nc = Math.max(1, columns.length);
|
|
1792
|
+
const title = spec.title || "";
|
|
1793
|
+
const bg = spec.background || "#ffffff";
|
|
1794
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
1795
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
1796
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
1797
|
+
const font = resolveFont(spec);
|
|
1798
|
+
const watermark = spec.watermark !== false;
|
|
1799
|
+
const titleCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1800
|
+
const labelCol = txt(spec, isDark ? "#e2e8f0" : "#334155");
|
|
1801
|
+
const headCol = txt(spec, isDark ? "#cbd5e1" : "#475569");
|
|
1802
|
+
const lineCol = isDark ? "#334155" : "#e2e8f0";
|
|
1803
|
+
const zebra = isDark ? "#1e293b" : "#f8fafc";
|
|
1804
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
1805
|
+
const PAD = 24;
|
|
1806
|
+
const topY = title ? 54 : 24;
|
|
1807
|
+
const LEFTW = spec.labelWidth ? Number(spec.labelWidth) : 200;
|
|
1808
|
+
const HEAD = 38, ROWH = 40;
|
|
1809
|
+
const W = spec.width || 680;
|
|
1810
|
+
const H = spec.height || topY + HEAD + rows.length * ROWH + 16;
|
|
1811
|
+
const plotLeft = PAD + LEFTW;
|
|
1812
|
+
const cellW = (W - PAD - plotLeft) / nc;
|
|
1813
|
+
const p = [];
|
|
1814
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
1815
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
1816
|
+
if (title) p.push(`<text x="${r(W / 2)}" y="33" text-anchor="middle" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${titleCol}">${esc(title)}</text>`);
|
|
1817
|
+
columns.forEach((c, ci) => p.push(`<text x="${r(plotLeft + ci * cellW + cellW / 2)}" y="${r(topY + HEAD - 14)}" text-anchor="middle" font-size="${fs}" ${wAttr(spec, 700)} fill="${headCol}">${esc(c)}</text>`));
|
|
1818
|
+
p.push(`<line x1="${PAD}" y1="${r(topY + HEAD)}" x2="${W - PAD}" y2="${r(topY + HEAD)}" stroke="${lineCol}" stroke-width="1"/>`);
|
|
1819
|
+
rows.forEach((row, ri) => {
|
|
1820
|
+
const y = topY + HEAD + ri * ROWH;
|
|
1821
|
+
if (ri % 2 === 1) p.push(`<rect x="${PAD}" y="${r(y)}" width="${r(W - PAD * 2)}" height="${ROWH}" fill="${zebra}"/>`);
|
|
1822
|
+
p.push(`<text x="${PAD}" y="${r(y + ROWH / 2 + 4)}" font-size="${fs}"${wOpt(spec)} fill="${labelCol}">${esc(row.label || "")}</text>`);
|
|
1823
|
+
const cells = Array.isArray(row.cells) ? row.cells : [];
|
|
1824
|
+
columns.forEach((c, ci) => {
|
|
1825
|
+
p.push(statusCellSvg(cells[ci], plotLeft + ci * cellW + cellW / 2, y + ROWH / 2, fs * 0.85, fs, labelCol));
|
|
1826
|
+
});
|
|
1827
|
+
});
|
|
1828
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
1829
|
+
p.push(`</svg>`);
|
|
1830
|
+
return p.join("\n");
|
|
1831
|
+
}
|
|
1832
|
+
function renderChecklist(spec) {
|
|
1833
|
+
const items = Array.isArray(spec.items) ? spec.items : [];
|
|
1834
|
+
const n = Math.max(1, items.length);
|
|
1835
|
+
const title = spec.title || "";
|
|
1836
|
+
const bg = spec.background || "#ffffff";
|
|
1837
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
1838
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
1839
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
1840
|
+
const font = resolveFont(spec);
|
|
1841
|
+
const watermark = spec.watermark !== false;
|
|
1842
|
+
const titleCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1843
|
+
const labelCol = txt(spec, isDark ? "#e2e8f0" : "#334155");
|
|
1844
|
+
const doneCol = isDark ? "#64748b" : "#94a3b8";
|
|
1845
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
1846
|
+
const PAD = 24, ROWH = 38;
|
|
1847
|
+
const topY = title ? 54 : 24;
|
|
1848
|
+
const W = spec.width || 520;
|
|
1849
|
+
const H = spec.height || topY + n * ROWH + 12;
|
|
1850
|
+
const s = fs * 1, gx = PAD + 11;
|
|
1851
|
+
const p = [];
|
|
1852
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
1853
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
1854
|
+
if (title) p.push(`<text x="${PAD}" y="33" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${titleCol}">${esc(title)}</text>`);
|
|
1855
|
+
items.forEach((it, i) => {
|
|
1856
|
+
const cy = topY + i * ROWH + ROWH / 2;
|
|
1857
|
+
const st = String(it.status || "").trim().toLowerCase();
|
|
1858
|
+
let glyph, lc = labelCol;
|
|
1859
|
+
if (["done", "complete", "completed", "yes", "true"].includes(st)) {
|
|
1860
|
+
glyph = glyphCheck(gx, cy, s, "#059669");
|
|
1861
|
+
lc = doneCol;
|
|
1862
|
+
} else if (["blocked", "fail", "failed", "no", "cancelled"].includes(st)) {
|
|
1863
|
+
glyph = glyphCross(gx, cy, s, "#dc2626");
|
|
1864
|
+
} else if (["partial", "progress", "in progress", "wip", "doing"].includes(st)) {
|
|
1865
|
+
glyph = glyphDot(gx, cy, s, "#d97706");
|
|
1866
|
+
} else {
|
|
1867
|
+
glyph = glyphRing(gx, cy, s, "#cbd5e1");
|
|
1868
|
+
}
|
|
1869
|
+
p.push(glyph);
|
|
1870
|
+
p.push(`<text x="${r(gx + s + 14)}" y="${r(cy + fs * 0.35)}" font-size="${fs + 1}"${wOpt(spec)} fill="${lc}">${esc(it.label || "")}</text>`);
|
|
1871
|
+
});
|
|
1872
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
1873
|
+
p.push(`</svg>`);
|
|
1874
|
+
return p.join("\n");
|
|
1875
|
+
}
|
|
1876
|
+
function renderIconArray(spec) {
|
|
1877
|
+
const total = Math.max(1, Math.round(Number(spec.total) || 10));
|
|
1878
|
+
const filled = Math.max(0, Math.min(total, Math.round(Number(spec.filled) || 0)));
|
|
1879
|
+
const title = spec.title || "";
|
|
1880
|
+
const bg = spec.background || "#ffffff";
|
|
1881
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
1882
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
1883
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
1884
|
+
const font = resolveFont(spec);
|
|
1885
|
+
const watermark = spec.watermark !== false;
|
|
1886
|
+
const titleCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1887
|
+
const fillCol = resolveFlatPalette(spec.palette || "Clean Corporate", 1)[0];
|
|
1888
|
+
const emptyCol = isDark ? "#334155" : "#e2e8f0";
|
|
1889
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
1890
|
+
const PAD = 24, ICON = 30, GAP = 8;
|
|
1891
|
+
const topY = title ? 54 : 24;
|
|
1892
|
+
const perRow = Math.max(1, spec.perRow ? Number(spec.perRow) : Math.min(total, 10));
|
|
1893
|
+
const rowsN = Math.ceil(total / perRow);
|
|
1894
|
+
const W = spec.width || PAD * 2 + perRow * ICON + (perRow - 1) * GAP;
|
|
1895
|
+
const H = spec.height || topY + rowsN * (ICON + GAP) + 12;
|
|
1896
|
+
const p = [];
|
|
1897
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
1898
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
1899
|
+
if (title) p.push(`<text x="${PAD}" y="33" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${titleCol}">${esc(title)}</text>`);
|
|
1900
|
+
for (let k = 0; k < total; k++) {
|
|
1901
|
+
const row = Math.floor(k / perRow), col = k % perRow;
|
|
1902
|
+
const x = PAD + col * (ICON + GAP), y = topY + row * (ICON + GAP);
|
|
1903
|
+
p.push(personGlyph(x + ICON / 2, y, ICON, k < filled ? fillCol : emptyCol));
|
|
1904
|
+
}
|
|
1905
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
1906
|
+
p.push(`</svg>`);
|
|
1907
|
+
return p.join("\n");
|
|
1908
|
+
}
|
|
1909
|
+
function connectorLine(x1, x2, y, col) {
|
|
1910
|
+
const ah = 5;
|
|
1911
|
+
return `<line x1="${r(x1)}" y1="${r(y)}" x2="${r(x2 - ah)}" y2="${r(y)}" stroke="${col}" stroke-width="2"/><path d="M${r(x2 - ah - 1)},${r(y - ah)} L${r(x2)},${r(y)} L${r(x2 - ah - 1)},${r(y + ah)}" fill="none" stroke="${col}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>`;
|
|
1912
|
+
}
|
|
1913
|
+
function renderSteps(spec) {
|
|
1914
|
+
const steps = Array.isArray(spec.steps) ? spec.steps : [];
|
|
1915
|
+
const n = Math.max(1, steps.length);
|
|
1916
|
+
const title = spec.title || "";
|
|
1917
|
+
const bg = spec.background || "#ffffff";
|
|
1918
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
1919
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
1920
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
1921
|
+
const font = resolveFont(spec);
|
|
1922
|
+
const watermark = spec.watermark !== false;
|
|
1923
|
+
const palette = resolveFlatPalette(spec.palette || "Clean Corporate", Math.max(n, 3));
|
|
1924
|
+
const titleCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1925
|
+
const labelCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1926
|
+
const descCol = txt(spec, isDark ? "#cbd5e1" : "#475569");
|
|
1927
|
+
const connCol = isDark ? "#475569" : "#cbd5e1";
|
|
1928
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
1929
|
+
const PAD = 52, R = 22;
|
|
1930
|
+
const topY = title ? 54 : 24;
|
|
1931
|
+
const W = spec.width || 720;
|
|
1932
|
+
const H = spec.height || topY + 150;
|
|
1933
|
+
const cy = topY + 36 + R;
|
|
1934
|
+
const xOf = (i) => n === 1 ? W / 2 : PAD + R + i * ((W - 2 * (PAD + R)) / (n - 1));
|
|
1935
|
+
const p = [];
|
|
1936
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
1937
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
1938
|
+
if (title) p.push(`<text x="${r(W / 2)}" y="33" text-anchor="middle" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${titleCol}">${esc(title)}</text>`);
|
|
1939
|
+
for (let i = 0; i < n - 1; i++) p.push(connectorLine(xOf(i) + R + 6, xOf(i + 1) - R - 6, cy, connCol));
|
|
1940
|
+
steps.forEach((st, i) => {
|
|
1941
|
+
const x = xOf(i), fill = palette[i % palette.length], tc = spec.textColor || contrastColor(fill);
|
|
1942
|
+
p.push(`<circle cx="${r(x)}" cy="${r(cy)}" r="${R}" fill="${fill}"/>`);
|
|
1943
|
+
p.push(`<text x="${r(x)}" y="${r(cy + 5)}" text-anchor="middle" font-size="${fs + 3}" ${wAttr(spec, 800)} fill="${tc}">${i + 1}</text>`);
|
|
1944
|
+
p.push(`<text x="${r(x)}" y="${r(cy + R + 24)}" text-anchor="middle" font-size="${fs + 1}" ${wAttr(spec, 700)} fill="${labelCol}">${esc(st.label || "")}</text>`);
|
|
1945
|
+
if (st.description) p.push(`<text x="${r(x)}" y="${r(cy + R + 42)}" text-anchor="middle" font-size="${fs - 1}"${wOpt(spec)} fill="${descCol}">${esc(st.description)}</text>`);
|
|
1946
|
+
});
|
|
1947
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
1948
|
+
p.push(`</svg>`);
|
|
1949
|
+
return p.join("\n");
|
|
1950
|
+
}
|
|
1951
|
+
function renderTable(spec) {
|
|
1952
|
+
const columns = Array.isArray(spec.columns) ? spec.columns : [];
|
|
1953
|
+
const rows = Array.isArray(spec.rows) ? spec.rows : [];
|
|
1954
|
+
const nc = Math.max(1, columns.length);
|
|
1955
|
+
const title = spec.title || "";
|
|
1956
|
+
const bg = spec.background || "#ffffff";
|
|
1957
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
1958
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
1959
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
1960
|
+
const font = resolveFont(spec);
|
|
1961
|
+
const watermark = spec.watermark !== false;
|
|
1962
|
+
const titleCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
1963
|
+
const headCol = txt(spec, isDark ? "#cbd5e1" : "#475569");
|
|
1964
|
+
const cellCol = txt(spec, isDark ? "#e2e8f0" : "#334155");
|
|
1965
|
+
const lineCol = isDark ? "#334155" : "#e2e8f0";
|
|
1966
|
+
const zebra = isDark ? "#1e293b" : "#f8fafc";
|
|
1967
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
1968
|
+
const PAD = 24, HEAD = 38, ROWH = 36;
|
|
1969
|
+
const topY = title ? 54 : 24;
|
|
1970
|
+
const W = spec.width || 680;
|
|
1971
|
+
const H = spec.height || topY + HEAD + rows.length * ROWH + 16;
|
|
1972
|
+
const colW = (W - PAD * 2) / nc;
|
|
1973
|
+
const isNum = (v) => typeof v === "number" || typeof v === "string" && v.trim() !== "" && !isNaN(Number(v));
|
|
1974
|
+
const cellX = (ci, right) => right ? PAD + ci * colW + colW - 10 : PAD + ci * colW + 4;
|
|
1975
|
+
const p = [];
|
|
1976
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
1977
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
1978
|
+
if (title) p.push(`<text x="${r(W / 2)}" y="33" text-anchor="middle" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${titleCol}">${esc(title)}</text>`);
|
|
1979
|
+
columns.forEach((c, ci) => {
|
|
1980
|
+
const right = ci > 0;
|
|
1981
|
+
p.push(`<text x="${r(cellX(ci, right))}" y="${r(topY + HEAD - 14)}" ${right ? 'text-anchor="end" ' : ""}font-size="${fs}" ${wAttr(spec, 700)} fill="${headCol}">${esc(c)}</text>`);
|
|
1982
|
+
});
|
|
1983
|
+
p.push(`<line x1="${PAD}" y1="${r(topY + HEAD)}" x2="${W - PAD}" y2="${r(topY + HEAD)}" stroke="${lineCol}" stroke-width="1"/>`);
|
|
1984
|
+
rows.forEach((row, ri) => {
|
|
1985
|
+
const y = topY + HEAD + ri * ROWH;
|
|
1986
|
+
if (ri % 2 === 1) p.push(`<rect x="${PAD}" y="${r(y)}" width="${r(W - PAD * 2)}" height="${ROWH}" fill="${zebra}"/>`);
|
|
1987
|
+
const cells = Array.isArray(row) ? row : [];
|
|
1988
|
+
for (let ci = 0; ci < nc; ci++) {
|
|
1989
|
+
const v = cells[ci];
|
|
1990
|
+
if (v === void 0 || v === null || v === "") continue;
|
|
1991
|
+
const num = ci > 0 && isNum(v);
|
|
1992
|
+
const out = num ? fmt(Number(v)) : String(v);
|
|
1993
|
+
p.push(`<text x="${r(cellX(ci, num))}" y="${r(y + ROWH / 2 + 4)}" ${num ? 'text-anchor="end" ' : ""}font-size="${fs}"${wOpt(spec)} fill="${cellCol}">${esc(out)}</text>`);
|
|
1994
|
+
}
|
|
1995
|
+
});
|
|
1996
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
1997
|
+
p.push(`</svg>`);
|
|
1998
|
+
return p.join("\n");
|
|
1999
|
+
}
|
|
2000
|
+
function renderGauge(spec) {
|
|
2001
|
+
const value = Number(spec.value) || 0;
|
|
2002
|
+
const min = spec.min != null ? Number(spec.min) : 0;
|
|
2003
|
+
const max = spec.max != null ? Number(spec.max) : 100;
|
|
2004
|
+
const t = Math.max(0, Math.min(1, (value - min) / (max - min || 1)));
|
|
2005
|
+
const title = spec.title || "";
|
|
2006
|
+
const bg = spec.background || "#ffffff";
|
|
2007
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
2008
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
2009
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
2010
|
+
const font = resolveFont(spec);
|
|
2011
|
+
const watermark = spec.watermark !== false;
|
|
2012
|
+
const accent = contrastFloor(resolveFlatPalette(spec.palette || "Clean Corporate", 1)[0], bg, transparent);
|
|
2013
|
+
const track = isDark ? "#334155" : "#e2e8f0";
|
|
2014
|
+
const valueCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
2015
|
+
const labelCol = txt(spec, isDark ? "#cbd5e1" : "#475569");
|
|
2016
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
2017
|
+
const PAD = 24;
|
|
2018
|
+
const topY = title ? 50 : 20;
|
|
2019
|
+
const W = spec.width || 340, H = spec.height || 230;
|
|
2020
|
+
const rad = Math.min((W - PAD * 2) / 2, H - topY - 50);
|
|
2021
|
+
const cx = W / 2, cy = topY + rad + 6;
|
|
2022
|
+
const innerR = rad * 0.72;
|
|
2023
|
+
const u = spec.valueUnit ? " " + spec.valueUnit : "";
|
|
2024
|
+
const p = [];
|
|
2025
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
2026
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
2027
|
+
if (title) p.push(`<text x="${r(cx)}" y="33" text-anchor="middle" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${valueCol}">${esc(title)}</text>`);
|
|
2028
|
+
p.push(`<path d="${arcPath(cx, cy, rad, Math.PI, 2 * Math.PI, innerR)}" fill="${track}"/>`);
|
|
2029
|
+
if (t > 0) p.push(`<path d="${arcPath(cx, cy, rad, Math.PI, Math.PI + t * Math.PI, innerR)}" fill="${accent}"/>`);
|
|
2030
|
+
p.push(`<text x="${r(cx)}" y="${r(cy - 6)}" text-anchor="middle" font-size="${r(rad * 0.42)}" ${wAttr(spec, 800)} fill="${valueCol}">${esc(fmt(value) + u)}</text>`);
|
|
2031
|
+
if (spec.label) p.push(`<text x="${r(cx)}" y="${r(cy + 18)}" text-anchor="middle" font-size="${fs}"${wOpt(spec)} fill="${labelCol}">${esc(spec.label)}</text>`);
|
|
2032
|
+
p.push(`<text x="${r(cx - (rad + innerR) / 2)}" y="${r(cy + 16)}" text-anchor="middle" font-size="${fs - 2}" fill="${faint}">${esc(fmt(min))}</text>`);
|
|
2033
|
+
p.push(`<text x="${r(cx + (rad + innerR) / 2)}" y="${r(cy + 16)}" text-anchor="middle" font-size="${fs - 2}" fill="${faint}">${esc(fmt(max))}</text>`);
|
|
2034
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
2035
|
+
p.push(`</svg>`);
|
|
2036
|
+
return p.join("\n");
|
|
2037
|
+
}
|
|
2038
|
+
function renderBullet(spec) {
|
|
2039
|
+
const bars = Array.isArray(spec.bars) ? spec.bars : [];
|
|
2040
|
+
const n = Math.max(1, bars.length);
|
|
2041
|
+
const title = spec.title || "";
|
|
2042
|
+
const bg = spec.background || "#ffffff";
|
|
2043
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
2044
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
2045
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
2046
|
+
const font = resolveFont(spec);
|
|
2047
|
+
const watermark = spec.watermark !== false;
|
|
2048
|
+
const measureCol = contrastFloor(resolveFlatPalette(spec.palette || "Clean Corporate", 1)[0], bg, transparent);
|
|
2049
|
+
const labelCol = txt(spec, isDark ? "#cbd5e1" : "#475569");
|
|
2050
|
+
const valCol = txt(spec, isDark ? "#e2e8f0" : "#334155");
|
|
2051
|
+
const tickCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
2052
|
+
const bandCols = isDark ? ["#1e293b", "#334155", "#475569"] : ["#eef2f6", "#dbe2ea", "#c3cedb"];
|
|
2053
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
2054
|
+
const PAD = 24, ROW_H = 50;
|
|
2055
|
+
const topY = title ? 54 : 24;
|
|
2056
|
+
const W = spec.width || 600;
|
|
2057
|
+
const H = spec.height || topY + n * ROW_H + 8;
|
|
2058
|
+
const trackW = W - PAD * 2;
|
|
2059
|
+
const p = [];
|
|
2060
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
2061
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
2062
|
+
if (title) p.push(`<text x="${r(W / 2)}" y="33" text-anchor="middle" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${tickCol}">${esc(title)}</text>`);
|
|
2063
|
+
bars.forEach((b, i) => {
|
|
2064
|
+
const ry = topY + i * ROW_H;
|
|
2065
|
+
const val = Number(b.value) || 0, target = b.target != null ? Number(b.target) : null;
|
|
2066
|
+
const bands = Array.isArray(b.bands) ? b.bands.map(Number) : [];
|
|
2067
|
+
const max = b.max != null ? Number(b.max) : Math.max(val, target || 0, ...bands) * 1.1 || 1;
|
|
2068
|
+
const sx = (v) => PAD + Math.max(0, Math.min(1, v / max)) * trackW;
|
|
2069
|
+
const barY = ry + 22, barH = 16;
|
|
2070
|
+
p.push(`<text x="${PAD}" y="${r(ry + 13)}" font-size="${fs}" ${wAttr(spec, 600)} fill="${labelCol}">${esc(b.label || "")}</text>`);
|
|
2071
|
+
p.push(`<text x="${W - PAD}" y="${r(ry + 13)}" text-anchor="end" font-size="${fs}"${wOpt(spec)} fill="${valCol}">${esc(fmt(val))}${target != null ? " / " + esc(fmt(target)) : ""}</text>`);
|
|
2072
|
+
const edges = [0, ...bands, max];
|
|
2073
|
+
for (let k = 0; k < edges.length - 1; k++) {
|
|
2074
|
+
const x0 = sx(edges[k]), x1 = sx(edges[k + 1]);
|
|
2075
|
+
p.push(`<rect x="${r(x0)}" y="${r(barY)}" width="${r(Math.max(0, x1 - x0))}" height="${barH}" fill="${bandCols[Math.min(k, bandCols.length - 1)]}"/>`);
|
|
2076
|
+
}
|
|
2077
|
+
p.push(`<rect x="${PAD}" y="${r(barY + barH / 2 - 4)}" width="${r(sx(val) - PAD)}" height="8" rx="2" fill="${measureCol}"/>`);
|
|
2078
|
+
if (target != null) p.push(`<line x1="${r(sx(target))}" y1="${r(barY - 4)}" x2="${r(sx(target))}" y2="${r(barY + barH + 4)}" stroke="${tickCol}" stroke-width="2.5"/>`);
|
|
2079
|
+
});
|
|
2080
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
2081
|
+
p.push(`</svg>`);
|
|
2082
|
+
return p.join("\n");
|
|
2083
|
+
}
|
|
2084
|
+
function renderCalendar(spec) {
|
|
2085
|
+
const days = spec.days && typeof spec.days === "object" && !Array.isArray(spec.days) ? spec.days : {};
|
|
2086
|
+
const year = spec.year != null ? Number(spec.year) : 2025;
|
|
2087
|
+
const title = spec.title || "";
|
|
2088
|
+
const bg = spec.background || "#ffffff";
|
|
2089
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
2090
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
2091
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
2092
|
+
const font = resolveFont(spec);
|
|
2093
|
+
const watermark = spec.watermark !== false;
|
|
2094
|
+
const titleCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
2095
|
+
const labelCol = txt(spec, isDark ? "#cbd5e1" : "#64748b");
|
|
2096
|
+
const empty = isDark ? "#1e293b" : "#ebedf0";
|
|
2097
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
2098
|
+
const baseHsl = hexToHsl(resolveFlatPalette(spec.palette || "Clean Corporate", 1)[0]);
|
|
2099
|
+
const isLeap = year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
2100
|
+
const mdays = [31, isLeap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
2101
|
+
const totalDays = isLeap ? 366 : 365;
|
|
2102
|
+
const Y = year - 1, K = Y % 100, J = Math.floor(Y / 100);
|
|
2103
|
+
const h = (1 + Math.floor(13 * 14 / 5) + K + Math.floor(K / 4) + Math.floor(J / 4) + 5 * J) % 7;
|
|
2104
|
+
const startDow = (h + 6) % 7;
|
|
2105
|
+
const doyOfMonth = (mo) => {
|
|
2106
|
+
let d = 0;
|
|
2107
|
+
for (let i = 0; i < mo; i++) d += mdays[i];
|
|
2108
|
+
return d;
|
|
2109
|
+
};
|
|
2110
|
+
const valByDoy = {};
|
|
2111
|
+
let maxV = 0;
|
|
2112
|
+
for (const key in days) {
|
|
2113
|
+
const parts = String(key).split("-").map(Number);
|
|
2114
|
+
const mo = parts.length >= 3 ? parts[1] : parts[0];
|
|
2115
|
+
const da = parts.length >= 3 ? parts[2] : parts[1];
|
|
2116
|
+
if (!mo || !da) continue;
|
|
2117
|
+
const doy = doyOfMonth(mo - 1) + (da - 1);
|
|
2118
|
+
const v = Number(days[key]) || 0;
|
|
2119
|
+
valByDoy[doy] = v;
|
|
2120
|
+
if (v > maxV) maxV = v;
|
|
2121
|
+
}
|
|
2122
|
+
const cellColor = (v) => v <= 0 ? empty : hslToHex(baseHsl.h, Math.max(35, baseHsl.s), Math.max(0, Math.min(100, 86 - (maxV > 0 ? v / maxV : 0) * 50)));
|
|
2123
|
+
const PAD = 24, CELL = 11, GAP = 3, LEFTW = 30, TOPH = 18;
|
|
2124
|
+
const topY = title ? 50 : 20;
|
|
2125
|
+
const gridX = PAD + LEFTW, gridY = topY + TOPH;
|
|
2126
|
+
const weeks = Math.ceil((startDow + totalDays) / 7);
|
|
2127
|
+
const W = spec.width || gridX + weeks * (CELL + GAP) + PAD;
|
|
2128
|
+
const H = spec.height || gridY + 7 * (CELL + GAP) + 16;
|
|
2129
|
+
const p = [];
|
|
2130
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
2131
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
2132
|
+
if (title) p.push(`<text x="${PAD}" y="33" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${titleCol}">${esc(title)}</text>`);
|
|
2133
|
+
const MON = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
2134
|
+
for (let mo = 0; mo < 12; mo++) {
|
|
2135
|
+
const col = Math.floor((startDow + doyOfMonth(mo)) / 7);
|
|
2136
|
+
p.push(`<text x="${r(gridX + col * (CELL + GAP))}" y="${r(topY + TOPH - 6)}" font-size="${fs - 3}" fill="${labelCol}">${MON[mo]}</text>`);
|
|
2137
|
+
}
|
|
2138
|
+
[["Mon", 1], ["Wed", 3], ["Fri", 5]].forEach(([lbl, row]) => p.push(`<text x="${r(PAD)}" y="${r(gridY + row * (CELL + GAP) + CELL)}" font-size="${fs - 3}" fill="${labelCol}">${lbl}</text>`));
|
|
2139
|
+
for (let doy = 0; doy < totalDays; doy++) {
|
|
2140
|
+
const idx = startDow + doy, col = Math.floor(idx / 7), row = idx % 7;
|
|
2141
|
+
const x = gridX + col * (CELL + GAP), y = gridY + row * (CELL + GAP);
|
|
2142
|
+
p.push(`<rect x="${r(x)}" y="${r(y)}" width="${CELL}" height="${CELL}" rx="2" fill="${cellColor(valByDoy[doy] || 0)}"/>`);
|
|
2143
|
+
}
|
|
2144
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
2145
|
+
p.push(`</svg>`);
|
|
2146
|
+
return p.join("\n");
|
|
2147
|
+
}
|
|
2148
|
+
function renderLeaderboard(spec) {
|
|
2149
|
+
const raw = Array.isArray(spec.items) ? spec.items : [];
|
|
2150
|
+
const items = raw.map((it) => ({ label: it.label || "", value: Number(it.value) || 0 })).sort((a, b) => b.value - a.value);
|
|
2151
|
+
const n = Math.max(1, items.length);
|
|
2152
|
+
const title = spec.title || "";
|
|
2153
|
+
const bg = spec.background || "#ffffff";
|
|
2154
|
+
const transparent = bg === "transparent" || bg === "none";
|
|
2155
|
+
const isDark = !transparent && getLuminance(bg) < 0.35;
|
|
2156
|
+
const fs = spec.fontSize ? Number(spec.fontSize) : 13;
|
|
2157
|
+
const font = resolveFont(spec);
|
|
2158
|
+
const watermark = spec.watermark !== false;
|
|
2159
|
+
const palette = resolveFlatPalette(spec.palette || "Clean Corporate", Math.max(n, 3));
|
|
2160
|
+
const titleCol = txt(spec, isDark ? "#f1f5f9" : "#0f172a");
|
|
2161
|
+
const labelCol = txt(spec, isDark ? "#e2e8f0" : "#334155");
|
|
2162
|
+
const rankCol = isDark ? "#64748b" : "#94a3b8";
|
|
2163
|
+
const track = isDark ? "#1e293b" : "#f1f5f9";
|
|
2164
|
+
const valCol = txt(spec, isDark ? "#e2e8f0" : "#334155");
|
|
2165
|
+
const faint = isDark ? "#475569" : "#94a3b8";
|
|
2166
|
+
const u = spec.valueUnit ? " " + spec.valueUnit : "";
|
|
2167
|
+
const PAD = 24, ROW_H = 40, RANKW = 30, LABELW = 140, VALW = 70;
|
|
2168
|
+
const topY = title ? 54 : 24;
|
|
2169
|
+
const W = spec.width || 560;
|
|
2170
|
+
const H = spec.height || topY + n * ROW_H + 8;
|
|
2171
|
+
const barLeft = PAD + RANKW + LABELW, barRight = W - PAD - VALW;
|
|
2172
|
+
const maxV = Math.max(1, ...items.map((s) => s.value));
|
|
2173
|
+
const p = [];
|
|
2174
|
+
p.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" font-family="${esc(font)}">`);
|
|
2175
|
+
if (!transparent) p.push(`<rect x="0" y="0" width="${W}" height="${H}" fill="${bg}"/>`);
|
|
2176
|
+
if (title) p.push(`<text x="${r(W / 2)}" y="33" text-anchor="middle" font-size="${fs + 5}" ${wAttr(spec, 700)} fill="${titleCol}">${esc(title)}</text>`);
|
|
2177
|
+
items.forEach((it, i) => {
|
|
2178
|
+
const cy = topY + i * ROW_H + ROW_H / 2;
|
|
2179
|
+
const fill = palette[i % palette.length];
|
|
2180
|
+
const bw = it.value / maxV * (barRight - barLeft);
|
|
2181
|
+
p.push(`<text x="${PAD}" y="${r(cy + 5)}" font-size="${fs + 1}" ${wAttr(spec, 800)} fill="${rankCol}">${i + 1}</text>`);
|
|
2182
|
+
p.push(`<text x="${r(PAD + RANKW)}" y="${r(cy + 5)}" font-size="${fs}" ${wAttr(spec, 600)} fill="${labelCol}">${esc(it.label)}</text>`);
|
|
2183
|
+
p.push(`<rect x="${r(barLeft)}" y="${r(cy - 8)}" width="${r(barRight - barLeft)}" height="16" rx="8" fill="${track}"/>`);
|
|
2184
|
+
if (bw > 0) p.push(`<rect x="${r(barLeft)}" y="${r(cy - 8)}" width="${r(Math.max(16, bw))}" height="16" rx="8" fill="${fill}"/>`);
|
|
2185
|
+
p.push(`<text x="${W - PAD}" y="${r(cy + 5)}" text-anchor="end" font-size="${fs}" ${wAttr(spec, 700)} fill="${valCol}">${esc(fmt(it.value) + u)}</text>`);
|
|
2186
|
+
});
|
|
2187
|
+
if (watermark) p.push(`<text x="${W - 10}" y="${H - 9}" text-anchor="end" font-size="9" fill="${faint}" opacity="0.6">slickfast.com</text>`);
|
|
2188
|
+
p.push(`</svg>`);
|
|
2189
|
+
return p.join("\n");
|
|
2190
|
+
}
|
|
2191
|
+
var TYPES = [
|
|
2192
|
+
{ type: "bar", family: "comparison", needsData: true, summary: "vertical bar chart" },
|
|
2193
|
+
{ type: "grouped", family: "comparison", needsData: true, summary: "clustered bars (one per series per category)" },
|
|
2194
|
+
{ type: "stacked", family: "composition", needsData: true, summary: "stacked bars (segments within each bar)" },
|
|
2195
|
+
{ type: "stacked100", family: "composition", needsData: true, summary: "100% stacked bars (each bar = 100%)" },
|
|
2196
|
+
{ type: "stackedh", family: "composition", needsData: true, summary: "horizontal stacked bars" },
|
|
2197
|
+
{ type: "horizontal", family: "comparison", needsData: true, summary: "horizontal bars (single series)" },
|
|
2198
|
+
{ type: "lollipop", family: "comparison", needsData: true, summary: "lollipop chart" },
|
|
2199
|
+
{ type: "diverging", family: "deviation", needsData: true, summary: "diverging bars around a zero line" },
|
|
2200
|
+
{ type: "line", family: "trend", needsData: true, summary: "line chart" },
|
|
2201
|
+
{ type: "smooth", family: "trend", needsData: true, summary: "smooth (curved) line" },
|
|
2202
|
+
{ type: "area", family: "trend", needsData: true, summary: "area chart (filled line)" },
|
|
2203
|
+
{ type: "stepped", family: "trend", needsData: true, summary: "stepped line" },
|
|
2204
|
+
{ type: "stackedArea", family: "trend", needsData: true, summary: "stacked area bands" },
|
|
2205
|
+
{ type: "difference", family: "deviation", needsData: true, summary: "two lines with the gap shaded" },
|
|
2206
|
+
{ type: "slope", family: "change", needsData: true, summary: "slopegraph (first vs last value)" },
|
|
2207
|
+
{ type: "pie", family: "composition", needsData: true, summary: "pie chart" },
|
|
2208
|
+
{ type: "donut", family: "composition", needsData: true, summary: "donut (pie with a center hole + total)" },
|
|
2209
|
+
{ type: "pieofpie", family: "composition", needsData: false, dataKey: "pies", summary: "nested drill-down pies (pie-of-pie)" },
|
|
2210
|
+
{ type: "kpi", family: "single-value", needsData: false, summary: "single metric tile (label + value + delta)" },
|
|
2211
|
+
{ type: "cards", family: "layout", needsData: false, dataKey: "cards", summary: "a row/grid of stat cards (multi-KPI strip)" },
|
|
2212
|
+
{ type: "layers", family: "layout", needsData: false, dataKey: "layers", summary: "labeled box-stack / layer diagram (e.g. a tech stack)" },
|
|
2213
|
+
{ type: "progress", family: "layout", needsData: false, dataKey: "bars", summary: "labeled progress / bullet bars toward a target" },
|
|
2214
|
+
{ type: "waffle", family: "layout", needsData: false, dataKey: "parts", summary: "waffle / dot grid (10\xD710, part-of-whole)" },
|
|
2215
|
+
{ type: "heatmap", family: "layout", needsData: false, summary: "heatmap grid (rows \xD7 columns, value \u2192 color)" },
|
|
2216
|
+
{ type: "funnel", family: "layout", needsData: false, dataKey: "stages", summary: "funnel \u2014 stages narrowing top\u2192bottom" },
|
|
2217
|
+
{ type: "pyramid", family: "layout", needsData: false, dataKey: "levels", summary: "pyramid \u2014 hierarchy levels" },
|
|
2218
|
+
{ type: "quadrant", family: "layout", needsData: false, dataKey: "items", summary: "2\xD72 matrix \u2014 items placed by two axes" },
|
|
2219
|
+
{ type: "timeline", family: "layout", needsData: false, dataKey: "events", summary: "linear timeline \u2014 events along one line" },
|
|
2220
|
+
{ type: "venn", family: "layout", needsData: false, dataKey: "sets", summary: "venn \u2014 2\u20133 overlapping sets with counts" },
|
|
2221
|
+
{ type: "matrix", family: "layout", needsData: false, dataKey: "rows", summary: "comparison / feature matrix (\u2713/\u2717/dot cells)" },
|
|
2222
|
+
{ type: "checklist", family: "layout", needsData: false, dataKey: "items", summary: "checklist / status list (done/pending/blocked)" },
|
|
2223
|
+
{ type: "iconarray", family: "layout", needsData: false, summary: "icon array / pictogram (N icons, M filled)" },
|
|
2224
|
+
{ type: "steps", family: "layout", needsData: false, dataKey: "steps", summary: "step / process row (numbered linear flow)" },
|
|
2225
|
+
{ type: "table", family: "layout", needsData: false, dataKey: "rows", summary: "data table (rows \xD7 columns of text / values)" },
|
|
2226
|
+
{ type: "gauge", family: "layout", needsData: false, summary: "radial gauge / dial (single value on a scale)" },
|
|
2227
|
+
{ type: "bullet", family: "layout", needsData: false, dataKey: "bars", summary: "bullet graph (measure vs target on banded scale)" },
|
|
2228
|
+
{ type: "calendar", family: "layout", needsData: false, dataKey: "days", summary: "calendar heatmap (year contribution grid)" },
|
|
2229
|
+
{ type: "leaderboard", family: "layout", needsData: false, dataKey: "items", summary: "leaderboard (ranked rows: rank + bar + value)" }
|
|
2230
|
+
];
|
|
2231
|
+
var TYPE_NAMES = TYPES.map((t) => t.type);
|
|
1243
2232
|
function renderSpec(spec) {
|
|
1244
2233
|
spec = applyPreset(spec);
|
|
1245
2234
|
switch (spec.type) {
|
|
@@ -1276,6 +2265,44 @@ function renderSpec(spec) {
|
|
|
1276
2265
|
return renderPieOfPie(spec);
|
|
1277
2266
|
case "kpi":
|
|
1278
2267
|
return renderKpi(spec);
|
|
2268
|
+
case "cards":
|
|
2269
|
+
return renderCards(spec);
|
|
2270
|
+
case "layers":
|
|
2271
|
+
return renderLayers(spec);
|
|
2272
|
+
case "progress":
|
|
2273
|
+
return renderProgress(spec);
|
|
2274
|
+
case "waffle":
|
|
2275
|
+
return renderWaffle(spec);
|
|
2276
|
+
case "heatmap":
|
|
2277
|
+
return renderHeatmap(spec);
|
|
2278
|
+
case "funnel":
|
|
2279
|
+
return renderFunnel(spec);
|
|
2280
|
+
case "pyramid":
|
|
2281
|
+
return renderPyramid(spec);
|
|
2282
|
+
case "quadrant":
|
|
2283
|
+
return renderQuadrant(spec);
|
|
2284
|
+
case "timeline":
|
|
2285
|
+
return renderTimeline(spec);
|
|
2286
|
+
case "venn":
|
|
2287
|
+
return renderVenn(spec);
|
|
2288
|
+
case "matrix":
|
|
2289
|
+
return renderMatrix(spec);
|
|
2290
|
+
case "checklist":
|
|
2291
|
+
return renderChecklist(spec);
|
|
2292
|
+
case "iconarray":
|
|
2293
|
+
return renderIconArray(spec);
|
|
2294
|
+
case "steps":
|
|
2295
|
+
return renderSteps(spec);
|
|
2296
|
+
case "table":
|
|
2297
|
+
return renderTable(spec);
|
|
2298
|
+
case "gauge":
|
|
2299
|
+
return renderGauge(spec);
|
|
2300
|
+
case "bullet":
|
|
2301
|
+
return renderBullet(spec);
|
|
2302
|
+
case "calendar":
|
|
2303
|
+
return renderCalendar(spec);
|
|
2304
|
+
case "leaderboard":
|
|
2305
|
+
return renderLeaderboard(spec);
|
|
1279
2306
|
default:
|
|
1280
2307
|
throw new Error('render-core: unknown chart type "' + spec.type + '"');
|
|
1281
2308
|
}
|
|
@@ -1290,8 +2317,9 @@ function svgToPng(svg, opts = {}) {
|
|
|
1290
2317
|
}
|
|
1291
2318
|
|
|
1292
2319
|
// server.mjs
|
|
2320
|
+
var NO_DATA_TYPES = TYPES.filter((t) => !t.needsData).map((t) => t.type);
|
|
1293
2321
|
var here = dirname(fileURLToPath(import.meta.url));
|
|
1294
|
-
var CHART_SPEC_MD = true ? '# ChartSpec \u2014 the render-core contract (the API/MCP input)\n\nOne JSON object (a **spec**) goes in; one **SVG string** comes out, via\n`renderSpec(spec)`. This document is the contract an agent (or the MCP tool) follows\nto produce a chart. It is written agent-first: **a spec with only `type` + `data`\nrenders a complete, good-looking chart** \u2014 every other field is an optional override.\n\n```js\nimport { renderSpec } from \'./render-core.mjs\';\nconst svg = renderSpec({ type: \'bar\', data: { labels: [\'A\',\'B\',\'C\'], series: [{ values: [10, 20, 15] }] } });\n```\n\n## When to use this \u2014 and when to fall back\n\n**Prefer `render_chart` for any supported type** (see "Chart types" below) over\nhand-writing plotting code (matplotlib, plotly, chart.js). It\'s faster, deterministic,\nand good-looking with just `{type, data}`. Pass `outputPath` when the user wants the\nfile saved to disk.\n\n**Fall back to your own plotting only for what this engine does not do yet:**\n- **Chart types not listed below** \u2014 scatter, bubble, heatmap, treemap, radar, sankey,\n geographic maps, candlestick, gantt.\n- **Reference / target / threshold lines, log scales, secondary (dual) axes, and point\n annotations / callouts** \u2014 on the roadmap, not available today.\n- **Interactivity, animation, hover tooltips** \u2014 output is a static SVG/PNG.\n\n## Universal fields (every chart type honors these)\n\n| field | type | default | what it does |\n|---|---|---|---|\n| `type` | string | \u2014 (required) | which chart: `"bar"`, `"line"`, `"kpi"` (more coming) |\n| `title` | string | `""` | heading drawn at the top |\n| `width` | number | per type | SVG width in px |\n| `height` | number | per type | SVG height in px |\n| `preset` / `ratio` | string | \u2014 | aspect-ratio preset \u2192 sets width/height (explicit `width`/`height` win). `Share Card` 1.91:1 (1200\xD7630, link/OG cards), `Wide` 16:9 (1280\xD7720), `Square` 1:1 (1080\xD71080), `Portrait` 4:5 (1080\xD71350), `Tall` 9:16 (1080\xD71920), `Classic` 4:3 (1200\xD7900). `ratio` also accepts the bare ratio string (`"16:9"`, `"9:16"`, \u2026) |\n| `background` | string | `"#ffffff"` | any hex color, or `"transparent"` for no fill (overlays/exports) |\n| `palette` | string | `"Clean Corporate"` | named palette: `Clean Corporate`, `Pastel`, `Vibrant`, `Monochrome`, `Cyberpunk`, `Analogous Shift`. Pick **`Monochrome`** when the chart will be **printed in black & white / on a laser printer** \u2014 it\'s a single-hue grey ramp that stays legible without color (other palettes can render as indistinct greys when printed). |\n| `font` | string | `"Inter"` | a named font: `Inter`, `System`, `Serif`, `Mono`, `Rounded`, `Condensed` |\n| `fontFamily` | string | \u2014 | a raw CSS font stack (overrides `font`; full control / future custom fonts) |\n| `fontSize` | number | `13` | base text size; other text scales from it |\n| `textColor` | string | auto | force a color for the **neutral** text (title, axis, category, value, legend, pie slice labels). Omit it and the engine auto-picks black/white for contrast. Semantic colors (green \u25B2 / red \u25BC deltas & gaps) stay meaningful. |\n| `bold` | boolean | `false` | thicken every text element |\n| `fontWeight` | string | \u2014 | exact weight for all text (`"400"`\u2013`"900"` or `"bold"`); overrides `bold` |\n| `valueUnit` | string | `""` | appended to values, e.g. `"$"`, `"%"`, `"ms"` |\n| `showValues` | boolean | `true` | draw the numeric labels |\n| `watermark` | boolean | `true` | tasteful "slickfast.com" mark. **Set `false` for the chart sites / paid output.** |\n\n**Readability is automatic:** text colors are chosen from the background\'s luminance\n(via palette-core), so labels stay legible on light *or* dark backgrounds.\n\n## Data shape\n\n```json\n"data": {\n "labels": ["North", "South", "East"],\n "series": [\n { "name": "Revenue", "values": [420, 310, 530], "colors": ["#2563eb", "#7c3aed", "#059669"] }\n ]\n}\n```\n\n- `labels` \u2014 the categories (x-axis).\n- `series[].values` \u2014 the numbers, aligned to `labels`.\n- `series[].colors` \u2014 **optional** explicit per-item colors. If omitted, colors come\n from `palette`. (Used when a user has customized individual bars.)\n- `series[].name` \u2014 optional label for the series.\n\n## Chart types\n\n### `bar` \u2014 vertical bar chart\nDefault size `800 \xD7 450`. Uses `data.series[0]`. Each bar a palette color (or its\nexplicit `colors[i]`), top-rounded, with value + category labels and "nice" axis numbers.\n\n| extra field | type | default | does |\n|---|---|---|---|\n| `showTotal` | boolean | `true` | "Total: N" badge, top-right |\n\nMinimal: `{ "type": "bar", "data": { "labels": ["A","B"], "series": [{ "values": [10,20] }] } }`\n\n### `grouped` \u2014 clustered bar chart (one bar per series in each category)\nDefault size `800 \xD7 450`. The `data.labels` are the **groups** (categories); each\n`data.series` entry is a bar that repeats inside every group. **Color = series\nidentity:** one solid palette color per series (A=palette[0], B=palette[mid], extras\nspread), the same color in every group \u2014 never rainbow-within-a-series. A centered\nlegend names the series. Best read with \u2264 4 series.\n\nMinimal: `{ "type": "grouped", "data": { "labels": ["Q1","Q2"], "series": [{ "name":"2023","values":[42,55] }, { "name":"2024","values":[52,48] }] } }`\n\n### `stacked` \u2014 stacked bar chart (segments stack within each category)\nDefault size `800 \xD7 450`. Each `data.labels` entry is a bar; each `data.series` entry\nis a **segment** stacked inside every bar, with a distinct palette color used\nconsistently across all bars. Inside each segment, two labels: the **name pinned to the\ntop**, the **value to the bottom** (contrast-aware text \u2014 dark on light fills, white on\ndark). Thin segments hide the name but keep the value. Only the top segment\'s outer edge\nis rounded; joins stay flush. A centered legend names the segments.\n\nMinimal: `{ "type": "stacked", "data": { "labels": ["Q1","Q2"], "series": [{ "name":"Core","values":[30,35] }, { "name":"Add-ons","values":[18,20] }] } }`\n\n### `stacked100` \u2014 100% stacked bar (each bar normalized to 100%)\nSame as `stacked`, but every bar fills the full height and each segment shows its\n**share of that bar** as an integer percent. Percentages use largest-remainder\nrounding so every bar sums to **exactly 100** (never 99/101). Best for comparing\n*mix* across categories rather than absolute totals.\n\nMinimal: `{ "type": "stacked100", "data": { "labels": ["Q1","Q2"], "series": [{ "name":"Core","values":[30,35] }, { "name":"Add-ons","values":[18,20] }] } }`\n\n### `stackedh` \u2014 horizontal stacked bar\nSame data model as `stacked`, transposed: bars run left\u2192right, one row per\n`data.labels` entry, segments stack horizontally. The last segment rounds its right\nedge; joins stay flush. Segment name + value sit centered in each segment (value-only\nwhen narrow); a centered legend names the segments. Good when category labels are long.\n\nMinimal: `{ "type": "stackedh", "data": { "labels": ["Eng","Sales"], "series": [{ "name":"Salaries","values":[120,90] }, { "name":"Tools","values":[40,25] }] } }`\n\n### `horizontal` \u2014 horizontal bar (single series)\nDefault size `800 \xD7 450`. One row per `data.labels` entry; each bar its own palette\ncolor by index (or its explicit `colors[i]`), value at the bar end, "Total: N" badge\ntop-right. Best when labels are long or there are many categories.\n\nMinimal: `{ "type": "horizontal", "data": { "labels": ["US","India"], "series": [{ "values": [820,610] }] } }`\n\n### `diverging` \u2014 diverging bar (around a zero line)\nDefault size `800 \xD7 450`. **Two modes, chosen by series count:**\n- **Two series** \u2192 opposing bars: **Series A forced up, Series B forced down** (both\n abs-valued), one solid color each (A=palette[0], B=palette[mid]); a centered legend\n names both. Great for sentiment (agree/disagree), inflow/outflow.\n- **One series** \u2192 classic **signed** diverging: each value plotted by its own sign\n (**positive up, negative down**), a single color, a single-name legend, and signed\n value labels (e.g. `-3` below the zero line).\n\nThe zero line is emphasized; down-bar labels sit below their bars.\n\nMinimal (two-series): `{ "type": "diverging", "data": { "labels": ["A","B"], "series": [{ "name":"Agree","values":[62,48] }, { "name":"Disagree","values":[38,52] }] } }`\n\nMinimal (signed): `{ "type": "diverging", "data": { "labels": ["Q1","Q2","Q3"], "series": [{ "name":"Net flow","values":[5,-3,8] }] } }`\n\n### `lollipop` \u2014 lollipop chart (single series)\nDefault size `800 \xD7 450`. One stem + dot per `data.labels` entry, each its own palette\ncolor by index (or explicit `colors[i]`), value above the dot, category below, "Total: N"\nbadge top-right. A lighter-weight alternative to `bar` when the bars would feel heavy.\n\nMinimal: `{ "type": "lollipop", "data": { "labels": ["A","B","C"], "series": [{ "values": [78,64,52] }] } }`\n\n### `line` \u2014 line chart (single or multi-series)\nDefault size `800 \xD7 450`. One line per `data.series` entry, each a palette color\n(or its own `color`), with points and a centered legend when there\'s more than one\nseries. "Nice" axis numbers; points span edge-to-edge.\n\n| extra field | type | default | does |\n|---|---|---|---|\n| `curve` | string | `"straight"` | line shape: `"straight"`, `"smooth"` (curved), `"stepped"` |\n| `area` | boolean | `false` | fill the region under each line (translucent) |\n| `showPoints` | boolean | `true` | dots at each data point |\n| `showValues` | boolean | `false` | numbers above each point (off by default \u2014 lines get crowded) |\n| series `color` | string | palette | per-line color override |\n\n**Type shortcuts:** `type: "smooth"`, `"area"`, `"stepped"` map to `line` with the\nmatching option set \u2014 `{type:"area"}` \u2261 `{type:"line", area:true}`. Also:\n- `type: "stackedArea"` \u2014 every series stacks cumulatively, filled bands + legend.\n- `type: "difference"` \u2014 exactly two series; shades the gap between them and labels\n the gap value at each point (green where series 1 leads, red where it trails).\n- `type: "slope"` \u2014 a slopegraph: each series\' first vs last value, connected by a\n straight line, with the end value + change labeled (green up / red down).\n\nMinimal: `{ "type": "line", "data": { "labels": ["Jan","Feb","Mar"], "series": [{ "name": "Users", "values": [120,190,170] }] } }`\n\n### `pie` / `donut` \u2014 proportion of a whole\nDefault size `640 \xD7 420`. One series; each label+value is a slice, colored from the\npalette (or explicit `colors`). Percentage labels sit inside slices \u2265 6%; a legend\n(label \xB7 value) runs down the right. `donut` adds a center hole with the **total** in\nthe middle.\n\nMinimal: `{ "type": "pie", "data": { "labels": ["A","B","C"], "series": [{ "values": [45,30,25] }] } }`\n\n### `pieofpie` \u2014 nested drill-down pies (pie-of-pie, pie-of-pie-of-pie, N-tier)\nDefault size `920 \xD7 380`. A row of pies where each pie\'s **first slice (the "bridge")**\nexplodes toward the next pie and breaks down into it, joined by two connector lines.\n2 pies = pie-of-pie, 3 = pie-of-pie-of-pie, N supported; each pie is 75% the size of the\none before. Donut by default.\n\nUses **`pies`** (not `data`): an array of `{ title?, labels[], values[], colors?, palette? }`.\nSlice index 0 of each pie is the bridge into the next pie.\n\n| extra field | type | default | does |\n|---|---|---|---|\n| `pies` | array | \u2014 (required) | the pies; pie[i] slice 0 drills into pie[i+1] |\n| `donut` | boolean | `true` | center hole on each pie (`false` = solid pies) |\n| `cascade` | boolean | `true` | child pies shade from the parent bridge hue; `false` = flat palette per pie |\n| `palette` | string | `"Clean Corporate"` | a **nested theme** (below) \u2014 drives the whole cascade |\n\n**Nested themes** (premium color cascades, set via `palette`):\n- *Inspired tiers* (hand-tuned per-pie triads): `Analogous Shift` (showcase \u2014 a spectrum\n walk), `Retro Editorial`, `Classic Triadic`, `Sorbet Pastel`.\n- *Generative* (children derived from the root hue): `Modern Corporate`, `Nordic Earth`,\n `Cyberpunk Glow`, `Sequential Rainbow`, plus classics `Clean Corporate`, `Pastel`,\n `Vibrant`, `Monochrome`. (Authoring new ones: `palette-core/AUTHORING-PALETTES.md`.)\n\nMinimal: `{ "type": "pieofpie", "palette": "Analogous Shift", "pies": [ { "labels": ["Enterprise","SMB","Other"], "values": [60,30,10] }, { "labels": ["US","EU","APAC"], "values": [35,15,10] } ] }`\n\n### `kpi` \u2014 single metric tile (the exec-snapshot building block)\nDefault size `340 \xD7 180`. A card: label + big value + colored delta pill + palette accent.\n\n| extra field | type | default | does |\n|---|---|---|---|\n| `label` | string | `""` | the metric name (top) |\n| `value` | number | \u2014 | the big number |\n| `valuePrefix` | string | `""` | e.g. `"$"` before the value |\n| `delta` | number | none | the change; renders a pill \u2014 \u25B2 if positive, \u25BC if negative |\n| `deltaUnit` | string | `"%"` | unit on the delta |\n| `deltaGoodWhen` | string | `"up"` | which direction is GOOD (green). Set `"down"` for lower-is-better metrics (churn, latency, cost) \u2014 the arrow still shows real direction, only the color flips |\n\nMinimal: `{ "type": "kpi", "label": "MRR", "value": 128400, "valuePrefix": "$", "delta": 12.4 }`\n\n## What an agent can change (the levers)\n\n- **Fonts** \u2192 `fontFamily`, `fontSize`\n- **Colors** \u2192 `palette` (a named set) for the whole chart, or `data.series[].colors` for exact per-item control\n- **Background** \u2192 `background` (any hex, or `"transparent"`)\n- **Size / aspect** \u2192 `width`, `height`\n- **Branding** \u2192 `watermark` (off for the sites, on for free-tier API output)\n\n## Rules for the engine (and any agent generating specs)\n\n- **Deterministic:** the same spec always produces the exact same SVG bytes. No\n randomness, no time. Safe to cache and snapshot-test.\n- **Defaults are good:** never require a field that has a sensible default. Emit the\n smallest spec that expresses the intent; the engine makes it beautiful.\n- **Unknown `type` is an error** \u2014 only documented types render.\n\n## Roadmap\nMore chart types (line, area, stacked, pie, \u2026) register in `renderSpec`; each inherits\nevery universal field above and gets its own row here. This document becomes a formal\nJSON Schema when the MCP server is built, so the `render_chart` tool can validate specs\nand an LLM can read the field contract directly.\n' : readFileSync(join(here, "../../packages/render-core/SPEC.md"), "utf8");
|
|
2322
|
+
var CHART_SPEC_MD = true ? '# ChartSpec \u2014 the render-core contract (the API/MCP input)\n\nOne JSON object (a **spec**) goes in; one **SVG string** comes out, via\n`renderSpec(spec)`. This document is the contract an agent (or the MCP tool) follows\nto produce a chart. It is written agent-first: **a spec with only `type` + `data`\nrenders a complete, good-looking chart** \u2014 every other field is an optional override.\n\n```js\nimport { renderSpec } from \'./render-core.mjs\';\nconst svg = renderSpec({ type: \'bar\', data: { labels: [\'A\',\'B\',\'C\'], series: [{ values: [10, 20, 15] }] } });\n```\n\n## When to use this \u2014 and when to fall back\n\n**Prefer `render_chart` for any supported type** (see "Chart types" below) over\nhand-writing plotting code (matplotlib, plotly, chart.js). It\'s faster, deterministic,\nand good-looking with just `{type, data}`. Pass `outputPath` when the user wants the\nfile saved to disk.\n\n**Fall back to your own plotting only for what this engine does not do yet:**\n- **Chart types not listed below** \u2014 scatter, bubble, heatmap, treemap, radar, sankey,\n geographic maps, candlestick, gantt.\n- **Reference / target / threshold lines, log scales, secondary (dual) axes, and point\n annotations / callouts** \u2014 on the roadmap, not available today.\n- **Interactivity, animation, hover tooltips** \u2014 output is a static SVG/PNG.\n\n## Universal fields (every chart type honors these)\n\n| field | type | default | what it does |\n|---|---|---|---|\n| `type` | string | \u2014 (required) | which chart: `"bar"`, `"line"`, `"kpi"` (more coming) |\n| `title` | string | `""` | heading drawn at the top |\n| `width` | number | per type | SVG width in px |\n| `height` | number | per type | SVG height in px |\n| `preset` / `ratio` | string | \u2014 | aspect-ratio preset \u2192 sets width/height (explicit `width`/`height` win). `Share Card` 1.91:1 (1200\xD7630, link/OG cards), `Wide` 16:9 (1280\xD7720), `Square` 1:1 (1080\xD71080), `Portrait` 4:5 (1080\xD71350), `Tall` 9:16 (1080\xD71920), `Classic` 4:3 (1200\xD7900). `ratio` also accepts the bare ratio string (`"16:9"`, `"9:16"`, \u2026) |\n| `background` | string | `"#ffffff"` | any hex color, or `"transparent"` for no fill (overlays/exports) |\n| `palette` | string | `"Clean Corporate"` | named palette: `Clean Corporate`, `Pastel`, `Vibrant`, `Monochrome`, `Cyberpunk`, `Analogous Shift`. Pick **`Monochrome`** when the chart will be **printed in black & white / on a laser printer** \u2014 it\'s a single-hue grey ramp that stays legible without color (other palettes can render as indistinct greys when printed). |\n| `font` | string | `"Inter"` | a named font: `Inter`, `System`, `Serif`, `Mono`, `Rounded`, `Condensed` |\n| `fontFamily` | string | \u2014 | a raw CSS font stack (overrides `font`; full control / future custom fonts) |\n| `fontSize` | number | `13` | base text size; other text scales from it |\n| `textColor` | string | auto | force a color for the **neutral** text (title, axis, category, value, legend, pie slice labels). Omit it and the engine auto-picks black/white for contrast. Semantic colors (green \u25B2 / red \u25BC deltas & gaps) stay meaningful. |\n| `bold` | boolean | `false` | thicken every text element |\n| `fontWeight` | string | \u2014 | exact weight for all text (`"400"`\u2013`"900"` or `"bold"`); overrides `bold` |\n| `valueUnit` | string | `""` | appended to values, e.g. `"$"`, `"%"`, `"ms"` |\n| `showValues` | boolean | `true` | draw the numeric labels |\n| `watermark` | boolean | `true` | tasteful "slickfast.com" mark. **Set `false` for the chart sites / paid output.** |\n\n**Readability is automatic:** text colors are chosen from the background\'s luminance\n(via palette-core), so labels stay legible on light *or* dark backgrounds.\n\n## Data shape\n\n```json\n"data": {\n "labels": ["North", "South", "East"],\n "series": [\n { "name": "Revenue", "values": [420, 310, 530], "colors": ["#2563eb", "#7c3aed", "#059669"] }\n ]\n}\n```\n\n- `labels` \u2014 the categories (x-axis).\n- `series[].values` \u2014 the numbers, aligned to `labels`.\n- `series[].colors` \u2014 **optional** explicit per-item colors. If omitted, colors come\n from `palette`. (Used when a user has customized individual bars.)\n- `series[].name` \u2014 optional label for the series.\n\n## Chart types\n\n### `bar` \u2014 vertical bar chart\nDefault size `800 \xD7 450`. Uses `data.series[0]`. Each bar a palette color (or its\nexplicit `colors[i]`), top-rounded, with value + category labels and "nice" axis numbers.\n\n| extra field | type | default | does |\n|---|---|---|---|\n| `showTotal` | boolean | `true` | "Total: N" badge, top-right |\n\nMinimal: `{ "type": "bar", "data": { "labels": ["A","B"], "series": [{ "values": [10,20] }] } }`\n\n### `grouped` \u2014 clustered bar chart (one bar per series in each category)\nDefault size `800 \xD7 450`. The `data.labels` are the **groups** (categories); each\n`data.series` entry is a bar that repeats inside every group. **Color = series\nidentity:** one solid palette color per series (A=palette[0], B=palette[mid], extras\nspread), the same color in every group \u2014 never rainbow-within-a-series. A centered\nlegend names the series. Best read with \u2264 4 series.\n\nMinimal: `{ "type": "grouped", "data": { "labels": ["Q1","Q2"], "series": [{ "name":"2023","values":[42,55] }, { "name":"2024","values":[52,48] }] } }`\n\n### `stacked` \u2014 stacked bar chart (segments stack within each category)\nDefault size `800 \xD7 450`. Each `data.labels` entry is a bar; each `data.series` entry\nis a **segment** stacked inside every bar, with a distinct palette color used\nconsistently across all bars. Inside each segment, two labels: the **name pinned to the\ntop**, the **value to the bottom** (contrast-aware text \u2014 dark on light fills, white on\ndark). Thin segments hide the name but keep the value. Only the top segment\'s outer edge\nis rounded; joins stay flush. A centered legend names the segments.\n\nMinimal: `{ "type": "stacked", "data": { "labels": ["Q1","Q2"], "series": [{ "name":"Core","values":[30,35] }, { "name":"Add-ons","values":[18,20] }] } }`\n\n### `stacked100` \u2014 100% stacked bar (each bar normalized to 100%)\nSame as `stacked`, but every bar fills the full height and each segment shows its\n**share of that bar** as an integer percent. Percentages use largest-remainder\nrounding so every bar sums to **exactly 100** (never 99/101). Best for comparing\n*mix* across categories rather than absolute totals.\n\nMinimal: `{ "type": "stacked100", "data": { "labels": ["Q1","Q2"], "series": [{ "name":"Core","values":[30,35] }, { "name":"Add-ons","values":[18,20] }] } }`\n\n### `stackedh` \u2014 horizontal stacked bar\nSame data model as `stacked`, transposed: bars run left\u2192right, one row per\n`data.labels` entry, segments stack horizontally. The last segment rounds its right\nedge; joins stay flush. Segment name + value sit centered in each segment (value-only\nwhen narrow); a centered legend names the segments. Good when category labels are long.\n\nMinimal: `{ "type": "stackedh", "data": { "labels": ["Eng","Sales"], "series": [{ "name":"Salaries","values":[120,90] }, { "name":"Tools","values":[40,25] }] } }`\n\n### `horizontal` \u2014 horizontal bar (single series)\nDefault size `800 \xD7 450`. One row per `data.labels` entry; each bar its own palette\ncolor by index (or its explicit `colors[i]`), value at the bar end, "Total: N" badge\ntop-right. Best when labels are long or there are many categories.\n\nMinimal: `{ "type": "horizontal", "data": { "labels": ["US","India"], "series": [{ "values": [820,610] }] } }`\n\n### `diverging` \u2014 diverging bar (around a zero line)\nDefault size `800 \xD7 450`. **Two modes, chosen by series count:**\n- **Two series** \u2192 opposing bars: **Series A forced up, Series B forced down** (both\n abs-valued), one solid color each (A=palette[0], B=palette[mid]); a centered legend\n names both. Great for sentiment (agree/disagree), inflow/outflow.\n- **One series** \u2192 classic **signed** diverging: each value plotted by its own sign\n (**positive up, negative down**), a single color, a single-name legend, and signed\n value labels (e.g. `-3` below the zero line).\n\nThe zero line is emphasized; down-bar labels sit below their bars.\n\nMinimal (two-series): `{ "type": "diverging", "data": { "labels": ["A","B"], "series": [{ "name":"Agree","values":[62,48] }, { "name":"Disagree","values":[38,52] }] } }`\n\nMinimal (signed): `{ "type": "diverging", "data": { "labels": ["Q1","Q2","Q3"], "series": [{ "name":"Net flow","values":[5,-3,8] }] } }`\n\n### `lollipop` \u2014 lollipop chart (single series)\nDefault size `800 \xD7 450`. One stem + dot per `data.labels` entry, each its own palette\ncolor by index (or explicit `colors[i]`), value above the dot, category below, "Total: N"\nbadge top-right. A lighter-weight alternative to `bar` when the bars would feel heavy.\n\nMinimal: `{ "type": "lollipop", "data": { "labels": ["A","B","C"], "series": [{ "values": [78,64,52] }] } }`\n\n### `line` \u2014 line chart (single or multi-series)\nDefault size `800 \xD7 450`. One line per `data.series` entry, each a palette color\n(or its own `color`), with points and a centered legend when there\'s more than one\nseries. "Nice" axis numbers; points span edge-to-edge.\n\n| extra field | type | default | does |\n|---|---|---|---|\n| `curve` | string | `"straight"` | line shape: `"straight"`, `"smooth"` (curved), `"stepped"` |\n| `area` | boolean | `false` | fill the region under each line (translucent) |\n| `showPoints` | boolean | `true` | dots at each data point |\n| `showValues` | boolean | `false` | numbers above each point (off by default \u2014 lines get crowded) |\n| series `color` | string | palette | per-line color override |\n\n**Type shortcuts:** `type: "smooth"`, `"area"`, `"stepped"` map to `line` with the\nmatching option set \u2014 `{type:"area"}` \u2261 `{type:"line", area:true}`. Also:\n- `type: "stackedArea"` \u2014 every series stacks cumulatively, filled bands + legend.\n- `type: "difference"` \u2014 exactly two series; shades the gap between them and labels\n the gap value at each point (green where series 1 leads, red where it trails).\n- `type: "slope"` \u2014 a slopegraph: each series\' first vs last value, connected by a\n straight line, with the end value + change labeled (green up / red down).\n\nMinimal: `{ "type": "line", "data": { "labels": ["Jan","Feb","Mar"], "series": [{ "name": "Users", "values": [120,190,170] }] } }`\n\n### `pie` / `donut` \u2014 proportion of a whole\nDefault size `640 \xD7 420`. One series; each label+value is a slice, colored from the\npalette (or explicit `colors`). Percentage labels sit inside slices \u2265 6%; a legend\n(label \xB7 value) runs down the right. `donut` adds a center hole with the **total** in\nthe middle.\n\nMinimal: `{ "type": "pie", "data": { "labels": ["A","B","C"], "series": [{ "values": [45,30,25] }] } }`\n\n### `pieofpie` \u2014 nested drill-down pies (pie-of-pie, pie-of-pie-of-pie, N-tier)\nDefault size `920 \xD7 460`. A row of pies where each pie\'s **first slice (the "bridge")**\nexplodes toward the next pie and breaks down into it, joined by two connector lines.\n2 pies = pie-of-pie, 3 = pie-of-pie-of-pie, N supported; each pie is 75% the size of the\none before. Donut by default. Each pie gets a **`name \xB7 value` legend beneath it**\n(honoring `valuePrefix`/`valueUnit`) so slices are identifiable; the slices themselves\nkeep their `%` labels.\n\nUses **`pies`** (not `data`): an array of `{ title?, labels[], values[], colors?, palette? }`.\nSlice index 0 of each pie is the bridge into the next pie.\n\n| extra field | type | default | does |\n|---|---|---|---|\n| `pies` | array | \u2014 (required) | the pies; pie[i] slice 0 drills into pie[i+1] |\n| `donut` | boolean | `true` | center hole on each pie (`false` = solid pies) |\n| `cascade` | boolean | `true` | child pies shade from the parent bridge hue; `false` = flat palette per pie |\n| `palette` | string | `"Clean Corporate"` | a **nested theme** (below) \u2014 drives the whole cascade |\n\n**Nested themes** (premium color cascades, set via `palette`):\n- *Inspired tiers* (hand-tuned per-pie triads): `Analogous Shift` (showcase \u2014 a spectrum\n walk), `Retro Editorial`, `Classic Triadic`, `Sorbet Pastel`.\n- *Generative* (children derived from the root hue): `Modern Corporate`, `Nordic Earth`,\n `Cyberpunk Glow`, `Sequential Rainbow`, plus classics `Clean Corporate`, `Pastel`,\n `Vibrant`, `Monochrome`. (Authoring new ones: `palette-core/AUTHORING-PALETTES.md`.)\n\nMinimal: `{ "type": "pieofpie", "palette": "Analogous Shift", "pies": [ { "labels": ["Enterprise","SMB","Other"], "values": [60,30,10] }, { "labels": ["US","EU","APAC"], "values": [35,15,10] } ] }`\n\n### `kpi` \u2014 single metric tile (the exec-snapshot building block)\nDefault size `340 \xD7 180`. A card: label + big value + colored delta pill + palette accent.\n\n| extra field | type | default | does |\n|---|---|---|---|\n| `label` | string | `""` | the metric name (top) |\n| `value` | number | \u2014 | the big number |\n| `valuePrefix` | string | `""` | e.g. `"$"` before the value |\n| `delta` | number | none | the change; renders a pill \u2014 \u25B2 if positive, \u25BC if negative |\n| `deltaUnit` | string | `"%"` | unit on the delta |\n| `deltaGoodWhen` | string | `"up"` | which direction is GOOD (green). Set `"down"` for lower-is-better metrics (churn, latency, cost) \u2014 the arrow still shows real direction, only the color flips |\n| `sparkline` | number[] | none | a minimalist trend line along the bottom (e.g. the last N periods) \u2014 no axes/labels, colored to match the delta (green good / red bad). Needs \u2265 2 points; **landscape tile only**. Omit it and the tile is byte-identical. |\n\nMinimal: `{ "type": "kpi", "label": "MRR", "value": 128400, "valuePrefix": "$", "delta": 12.4 }`\n\nWith a sparkline: `{ "type": "kpi", "label": "MRR", "value": 128400, "valuePrefix": "$", "delta": 12.4, "sparkline": [98,104,101,112,118,121,128] }`\n\n### `cards` \u2014 a row/grid of stat cards (the multi-KPI dashboard strip)\nA set of KPI tiles in one image \u2014 for an exec snapshot of several metrics at once.\nUses its own **`cards`** array (not `data`): each entry is one card, reusing the **same\nfields as `kpi`**. Each card\'s accent cycles the palette by index; the delta pill follows\nthe same good/bad coloring (\u25B2/\u25BC shows real direction, color shows good-or-bad). Layout is a\n**bounded computed grid**: by default a single horizontal strip, wrapping to a grid once there\nare more than 4 cards. Size auto-fits the grid unless you set `width`/`height`.\n\n| field | type | default | does |\n|---|---|---|---|\n| `cards` | array | \u2014 (required) | the tiles; each: `label`, `value`, `valuePrefix`, `valueUnit`, `delta`, `deltaUnit`, `deltaGoodWhen` (same meaning as `kpi`) |\n| `columns` | number | min(cards, 4) | force the number of columns; cards wrap into rows |\n\nMinimal: `{ "type": "cards", "cards": [ { "label": "MRR", "value": 128400, "valuePrefix": "$", "delta": 12.4 }, { "label": "Active users", "value": 8210, "delta": 3.1 }, { "label": "Churn", "value": 2.4, "valueUnit": "%", "delta": 0.6, "deltaGoodWhen": "down" } ] }`\n\n### `layers` \u2014 labeled box-stack / layer diagram\nA vertical stack of labeled blocks \u2014 a structure/architecture picture (e.g. a tech\nstack, a hierarchy of tiers), **not** a stacked bar (no values, no axis). Uses its own\n**`layers`** array (not `data`): each entry is `{ title, subtitle? }`, drawn top\u2192bottom\nas an equal-height rounded block. Each block fills a distinct palette color, cycling the\npalette; the title (and optional subtitle) sit centered with **contrast-aware text**\n(dark on light fills, white on dark). Inherits every universal field.\n\n| field | type | default | does |\n|---|---|---|---|\n| `layers` | array | \u2014 (required) | the blocks, top to bottom; each: `title`, optional `subtitle` |\n\nMinimal: `{ "type": "layers", "layers": [ { "title": "Application", "subtitle": "React + TypeScript" }, { "title": "API", "subtitle": "Node + Hono" }, { "title": "Engine", "subtitle": "render-core (pure SVG)" }, { "title": "Infra", "subtitle": "Railway + Docker" } ] }`\n\n### `progress` \u2014 labeled progress / bullet bars\nLabeled horizontal bars filling toward a target \u2014 for "how far along" readouts. Uses\nits own **`bars`** array: each `{ label, value, target?, valueUnit? }`. The track end IS\nthe target, so the fill = `value / target`; the label shows `value / target`. With **no\n`target`**, `value` is read as a percent (0\u2013100) and the track end is 100%. Each bar a\npalette color by index. Inherits every universal field.\n\n| field | type | default | does |\n|---|---|---|---|\n| `bars` | array | \u2014 (required) | the bars; each: `label`, `value`, optional `target`, optional `valueUnit` |\n\nMinimal: `{ "type": "progress", "bars": [ { "label": "Q1 revenue", "value": 82, "target": 100 }, { "label": "Signups", "value": 1240, "target": 2000 }, { "label": "Uptime", "value": 99.2, "valueUnit": "%" } ] }`\n\n### `waffle` \u2014 waffle / dot grid\nA 10\xD710 grid of cells showing part-of-whole \u2014 friendlier than a pie for "% complete" or\na simple mix. Uses its own **`parts`** array `{ label, value, color? }`: parts fill the\n100 cells proportionally (largest-remainder rounding keeps the count exact). If the parts\nsum to **less than 100**, the remainder are **empty track cells** \u2014 so **one part** is a\n"% filled" gauge, and **several parts** is categorical part-to-whole. A `label \xB7 value`\nlegend sits beside the grid.\n\n| field | type | default | does |\n|---|---|---|---|\n| `parts` | array | \u2014 (required) | the filled groups; each: `label`, `value` (cell count), optional `color` |\n\nMinimal: `{ "type": "waffle", "parts": [ { "label": "Enterprise", "value": 45 }, { "label": "SMB", "value": 30 }, { "label": "Other", "value": 15 } ] }`\n\n### `heatmap` \u2014 colored grid (rows \xD7 columns)\nA grid of cells colored by value (light \u2192 dark on a single palette hue) \u2014 for "intensity\nacross two dimensions" (e.g. activity by day \xD7 hour). Uses its own 2D shape: **`rows`**\n(row labels), **`columns`** (column labels), and **`values`** \u2014 a matrix where\n`values[row][col]` is the cell value. Cell value text is contrast-aware; `showValues:false`\nhides the numbers.\n\n| field | type | default | does |\n|---|---|---|---|\n| `rows` | string[] | \u2014 (required) | row labels (one per matrix row) |\n| `columns` | string[] | \u2014 (required) | column labels (one per matrix column) |\n| `values` | number[][] | \u2014 (required) | the matrix, `values[row][col]` |\n\nMinimal: `{ "type": "heatmap", "rows": ["Mon","Tue","Wed"], "columns": ["9a","12p","3p","6p"], "values": [[2,5,8,3],[1,4,9,6],[0,3,7,2]] }`\n\n### `funnel` \u2014 stages narrowing top\u2192bottom\nA conversion/drop-off funnel. Uses its own **`stages`** array `{ label, value }`: each\nstage is a centered band whose width is proportional to its value, tapering into the\nnext. Each band shows the label, the value, and its **% of the top stage**. Palette\ncolor per stage; band text is contrast-aware.\n\n| field | type | default | does |\n|---|---|---|---|\n| `stages` | array | \u2014 (required) | the stages top\u2192bottom; each: `label`, `value` |\n\nMinimal: `{ "type": "funnel", "stages": [ { "label": "Visitors", "value": 12000 }, { "label": "Signups", "value": 4200 }, { "label": "Trials", "value": 1800 }, { "label": "Paid", "value": 640 } ] }`\n\n### `pyramid` \u2014 hierarchy levels\nA triangle (apex on top) split into equal-height bands \u2014 for layered hierarchies\n(Maslow-style, org tiers, strategy levels). Uses its own **`levels`** array\n`{ title, value? }` (`label` is accepted as an alias for `title`). Each level a palette\ncolor, label centered with contrast-aware text; `value` is shown beside the label if set.\n\n| field | type | default | does |\n|---|---|---|---|\n| `levels` | array | \u2014 (required) | the levels, apex\u2192base; each: `title`, optional `value` |\n\nMinimal: `{ "type": "pyramid", "levels": [ { "title": "Vision" }, { "title": "Strategy" }, { "title": "Execution" }, { "title": "Operations" } ] }`\n\n### `quadrant` \u2014 2\xD72 matrix\nItems placed by two dimensions (effort/impact, reach/ease, etc.). Uses its own **`items`**\narray `{ label, x, y }` with `x`/`y` in **0\u20131** (x left\u2192right, y bottom\u2192top), plus\n**`xAxis`** and **`yAxis`** labels. A square plot is split by a crosshair into four\nquadrants; each item is a labeled dot (palette color by index).\n\n| field | type | default | does |\n|---|---|---|---|\n| `items` | array | \u2014 (required) | the items; each: `label`, `x` (0\u20131), `y` (0\u20131) |\n| `xAxis` | string | `""` | horizontal axis label |\n| `yAxis` | string | `""` | vertical axis label |\n\nMinimal: `{ "type": "quadrant", "xAxis": "Effort", "yAxis": "Impact", "items": [ { "label": "Quick win", "x": 0.2, "y": 0.8 }, { "label": "Big bet", "x": 0.8, "y": 0.9 }, { "label": "Time sink", "x": 0.8, "y": 0.2 } ] }`\n\n### `timeline` \u2014 events along one line\nA linear timeline. Uses its own **`events`** array `{ date?, label }`: events sit evenly\nspaced along a horizontal line, the date by the line and the label **alternating\nabove/below** so they don\'t crowd. Keep labels short.\n\n| field | type | default | does |\n|---|---|---|---|\n| `events` | array | \u2014 (required) | the events in order; each: optional `date`, `label` |\n\nMinimal: `{ "type": "timeline", "events": [ { "date": "Q1", "label": "Launch" }, { "date": "Q2", "label": "Series A" }, { "date": "Q3", "label": "100k users" }, { "date": "Q4", "label": "Profitable" } ] }`\n\n### `venn` \u2014 2\u20133 overlapping sets\nOverlapping translucent circles for set relationships. Uses its own **`sets`** array\n`{ label, value }` (2 or 3 sets; fixed layout \u2014 2 side-by-side, 3 in a triangle) plus an\noptional **`overlap`** count (2-set), shown in the lens. Each circle is labeled with its\nvalue.\n\n| field | type | default | does |\n|---|---|---|---|\n| `sets` | array | \u2014 (required) | 2\u20133 sets; each: `label`, `value` |\n| `overlap` | number | \u2014 | (2 sets) the count shared by both, drawn in the overlap |\n\nMinimal: `{ "type": "venn", "sets": [ { "label": "Design", "value": 120 }, { "label": "Engineering", "value": 160 } ], "overlap": 40 }`\n\n### `matrix` \u2014 comparison / feature matrix\nA rows \xD7 columns table of \u2713/\u2717 (the pricing/feature-comparison look). Uses its own shape:\n**`columns`** (string[]) + **`rows`** `{ label, cells[] }` (one cell per column). Each cell is\na **boolean** or **status word** \u2192 a glyph (`true`/`"yes"` \u2713 green, `false`/`"no"` \u2717 grey,\n`"partial"` \u2022 amber, `""`/`"-"` dash), or any other string \u2192 rendered as **text** (e.g. a\nplan limit). Rows zebra-stripe for readability. `labelWidth` sets the row-label column width.\n\n| field | type | default | does |\n|---|---|---|---|\n| `columns` | string[] | \u2014 (required) | the column headers |\n| `rows` | array | \u2014 (required) | each: `label`, `cells[]` (boolean / status word / text, aligned to columns) |\n| `labelWidth` | number | `200` | px reserved for the row-label column |\n\nMinimal: `{ "type": "matrix", "columns": ["Free","Pro","Enterprise"], "rows": [ { "label": "SSO / SAML", "cells": [false,false,true] }, { "label": "API access", "cells": [false,true,true] }, { "label": "Priority support", "cells": [false,"partial",true] }, { "label": "Seats", "cells": ["1","10","Unlimited"] } ] }`\n\n### `checklist` \u2014 checklist / status list\nA vertical list of items each with a status glyph \u2014 for run-of-show / readiness lists. Uses\nits own **`items`** array `{ label, status }`: **`done`** \u2713 (green, label mutes), **`blocked`**\n\u2717 (red), **`partial`** \u2022 (amber), anything else (or `pending`) \u2192 an empty ring.\n\n| field | type | default | does |\n|---|---|---|---|\n| `items` | array | \u2014 (required) | each: `label`, `status` (`done`/`pending`/`blocked`/`partial`) |\n\nMinimal: `{ "type": "checklist", "title": "Launch checklist", "items": [ { "label": "Domain transferred", "status": "done" }, { "label": "API deployed", "status": "done" }, { "label": "Load testing", "status": "pending" }, { "label": "Billing live", "status": "blocked" } ] }`\n\n### `iconarray` \u2014 icon array / pictogram\n`total` person icons with the first `filled` colored and the rest faint \u2014 a friendly\npart-of-whole ("7 of 10 teams onboarded"). `perRow` controls wrapping.\n\n| field | type | default | does |\n|---|---|---|---|\n| `total` | number | `10` | total icons |\n| `filled` | number | `0` | how many are filled (the rest faint) |\n| `perRow` | number | `min(total,10)` | icons per row before wrapping |\n\nMinimal: `{ "type": "iconarray", "title": "Teams onboarded (7/10)", "total": 10, "filled": 7 }`\n\n### `steps` \u2014 step / process row\nNumbered nodes left\u2192right joined by connector arrows \u2014 a **linear** process flow (not a\nbranching graph). Uses its own **`steps`** array `{ label, description? }`: each step is a\nnumbered palette circle with its label (and optional description) beneath. Positions are\ncomputed directly; no graph layout.\n\n| field | type | default | does |\n|---|---|---|---|\n| `steps` | array | \u2014 (required) | the steps in order; each: `label`, optional `description` |\n\nMinimal: `{ "type": "steps", "steps": [ { "label": "Sign up" }, { "label": "Connect data" }, { "label": "Build chart" }, { "label": "Share" } ] }`\n\n### `table` \u2014 data table (rows \xD7 columns)\nA plain tabular grid of text/values (the general tabular type; `matrix` is the \u2713/\u2717 variant).\nUses its own shape: **`columns`** (string[] header) + **`rows`** (an array of **cell arrays**).\nNumbers right-align and format with thousands separators; text left-aligns. Header rule +\nzebra rows.\n\n| field | type | default | does |\n|---|---|---|---|\n| `columns` | string[] | \u2014 (required) | the header cells |\n| `rows` | array | \u2014 (required) | each row is an array of cells (string or number), aligned to columns |\n\nMinimal: `{ "type": "table", "columns": ["Region","Q1","Q2","Q3"], "rows": [ ["North",420,510,480], ["South",310,290,350], ["East",530,560,600] ] }`\n\n### `gauge` \u2014 radial dial (single value)\nA 180\xB0 dial showing one value on a `min`..`max` scale \u2014 for "how full / how far" readouts. The\narc band fills to the value; the number sits in the center with `min`/`max` at the ends.\n\n| field | type | default | does |\n|---|---|---|---|\n| `value` | number | \u2014 (required) | the value to show |\n| `min` | number | `0` | scale minimum |\n| `max` | number | `100` | scale maximum |\n| `label` | string | `""` | caption under the value |\n| `valueUnit` | string | `""` | appended to the value |\n\nMinimal: `{ "type": "gauge", "label": "CPU load", "value": 72, "valueUnit": "%" }`\n\n### `bullet` \u2014 bullet graph\nA compact measure-vs-target gauge (Stephen Few style): a thin measure bar over grey\nqualitative bands, with a target tick \u2014 richer than `progress`. Uses its own **`bars`** array\n`{ label, value, target, max, bands }`, where `bands` are the threshold edges (e.g. `[150,225]`)\nthat shade the background into qualitative ranges.\n\n| field | type | default | does |\n|---|---|---|---|\n| `bars` | array | \u2014 (required) | each: `label`, `value`, optional `target` (tick), `max` (scale), `bands` (range edges) |\n\nMinimal: `{ "type": "bullet", "bars": [ { "label": "Revenue", "value": 275, "target": 250, "max": 300, "bands": [150,225] }, { "label": "Profit", "value": 82, "target": 100, "max": 120, "bands": [60,90] } ] }`\n\n### `calendar` \u2014 calendar heatmap (year grid)\nA GitHub-style contribution grid: weeks across, days down, each day a cell colored light\u2192dark by\nvalue on one palette hue. Uses **`days`** \u2014 a map of `"YYYY-MM-DD" \u2192 value` \u2014 plus **`year`**.\nWeekday placement is computed arithmetically (no clock), so it\'s fully deterministic.\n\n| field | type | default | does |\n|---|---|---|---|\n| `days` | object | \u2014 (required) | `"YYYY-MM-DD"` \u2192 number (the value for that day) |\n| `year` | number | `2025` | which year the grid covers (sets leap year + start weekday) |\n\nMinimal: `{ "type": "calendar", "title": "Activity", "year": 2025, "days": { "2025-01-06": 3, "2025-03-14": 8, "2025-07-21": 5 } }`\n\n### `leaderboard` \u2014 ranked rows\nA ranked list: each row is rank # + label + a bar (\u221D value) + the value, **auto-sorted\ndescending**. Uses its own **`items`** array `{ label, value }`.\n\n| field | type | default | does |\n|---|---|---|---|\n| `items` | array | \u2014 (required) | each: `label`, `value` (sorted high\u2192low, numbered) |\n\nMinimal: `{ "type": "leaderboard", "title": "Top regions", "items": [ { "label": "North", "value": 530 }, { "label": "South", "value": 480 }, { "label": "East", "value": 610 }, { "label": "West", "value": 390 } ] }`\n\n## What an agent can change (the levers)\n\n- **Fonts** \u2192 `fontFamily`, `fontSize`\n- **Colors** \u2192 `palette` (a named set) for the whole chart, or `data.series[].colors` for exact per-item control\n- **Background** \u2192 `background` (any hex, or `"transparent"`)\n- **Size / aspect** \u2192 `width`, `height`\n- **Branding** \u2192 `watermark` (off for the sites, on for free-tier API output)\n\n## Rules for the engine (and any agent generating specs)\n\n- **Deterministic:** the same spec always produces the exact same SVG bytes. No\n randomness, no time. Safe to cache and snapshot-test.\n- **Defaults are good:** never require a field that has a sensible default. Emit the\n smallest spec that expresses the intent; the engine makes it beautiful.\n- **Unknown `type` is an error** \u2014 only documented types render.\n\n## Roadmap\nMore chart types (line, area, stacked, pie, \u2026) register in `renderSpec`; each inherits\nevery universal field above and gets its own row here. This document becomes a formal\nJSON Schema when the MCP server is built, so the `render_chart` tool can validate specs\nand an LLM can read the field contract directly.\n' : readFileSync(join(here, "../../packages/render-core/SPEC.md"), "utf8");
|
|
1295
2323
|
var seriesShape = z.object({
|
|
1296
2324
|
name: z.string().optional().describe("series label (legend)"),
|
|
1297
2325
|
values: z.array(z.number()).describe("the numbers, aligned to data.labels"),
|
|
@@ -1305,12 +2333,88 @@ var pieShape = z.object({
|
|
|
1305
2333
|
colors: z.array(z.string()).optional().describe("per-slice color overrides"),
|
|
1306
2334
|
palette: z.string().optional().describe("per-pie palette override (rare)")
|
|
1307
2335
|
});
|
|
2336
|
+
var cardShape = z.object({
|
|
2337
|
+
label: z.string().optional().describe("the metric name"),
|
|
2338
|
+
value: z.number().optional().describe("the big number"),
|
|
2339
|
+
valuePrefix: z.string().optional().describe('prefix before the value, e.g. "$"'),
|
|
2340
|
+
valueUnit: z.string().optional().describe('unit appended to the value, e.g. "%"'),
|
|
2341
|
+
delta: z.number().optional().describe("the change (\u25B2/\u25BC; green good / red bad)"),
|
|
2342
|
+
deltaUnit: z.string().optional().describe('delta unit, default "%"'),
|
|
2343
|
+
deltaGoodWhen: z.enum(["up", "down"]).optional().describe('which delta direction is GOOD (green); default "up"')
|
|
2344
|
+
});
|
|
1308
2345
|
var inputSchema = {
|
|
1309
|
-
type: z.enum(
|
|
2346
|
+
type: z.enum(TYPE_NAMES).describe("chart type"),
|
|
1310
2347
|
title: z.string().optional(),
|
|
1311
|
-
data: z.object({ labels: z.array(z.string()), series: z.array(seriesShape) }).optional().describe("categories + series; required for every type except
|
|
2348
|
+
data: z.object({ labels: z.array(z.string()), series: z.array(seriesShape) }).optional().describe("categories + series; required for every type except " + NO_DATA_TYPES.join(", ")),
|
|
1312
2349
|
pies: z.array(pieShape).optional().describe(`pieofpie ONLY: a list of pies; each pie's first slice ("bridge") drills down into the next. 2 pies = pie-of-pie, 3 = pie-of-pie-of-pie, N supported.`),
|
|
1313
2350
|
cascade: z.boolean().optional().describe("pieofpie: child pies shade from the parent bridge hue (default true); false = flat palette per pie"),
|
|
2351
|
+
cards: z.array(cardShape).optional().describe("cards ONLY: the stat tiles. Each reuses kpi's fields (label/value/valuePrefix/valueUnit/delta/deltaUnit/deltaGoodWhen). Default layout = a single horizontal strip, wrapping to a grid past 4."),
|
|
2352
|
+
columns: z.union([z.number(), z.array(z.string())]).optional().describe("cards: force the number of columns (a number; cards wrap into rows; default min(cards, 4)). heatmap: the column labels (an array of strings)."),
|
|
2353
|
+
layers: z.array(z.object({
|
|
2354
|
+
title: z.string().optional().describe("the block label"),
|
|
2355
|
+
subtitle: z.string().optional().describe("smaller text under the title")
|
|
2356
|
+
})).optional().describe("layers ONLY: the stacked labeled blocks, top to bottom (e.g. a tech stack). Each block fills a distinct palette color; text is contrast-aware."),
|
|
2357
|
+
bars: z.array(z.object({
|
|
2358
|
+
label: z.string().optional().describe("the bar label"),
|
|
2359
|
+
value: z.number().optional().describe("current value"),
|
|
2360
|
+
target: z.number().optional().describe("the target (progress: the track end; bullet: a tick)"),
|
|
2361
|
+
valueUnit: z.string().optional().describe("progress: unit appended to the value"),
|
|
2362
|
+
max: z.number().optional().describe("bullet: the scale max for this bar"),
|
|
2363
|
+
bands: z.array(z.number()).optional().describe("bullet: qualitative band thresholds, e.g. [150,225]")
|
|
2364
|
+
})).optional().describe("progress: labeled bars filling toward a target. bullet: measure vs target on a banded scale."),
|
|
2365
|
+
parts: z.array(z.object({
|
|
2366
|
+
label: z.string().optional().describe("the part label"),
|
|
2367
|
+
value: z.number().optional().describe("count of cells (parts fill a 10\xD710 grid out of 100; remainder = empty)"),
|
|
2368
|
+
color: z.string().optional().describe("explicit fill color for this part")
|
|
2369
|
+
})).optional().describe('waffle ONLY: the parts of a 10\xD710 dot grid. One part = a "% filled" gauge; many = categorical part-to-whole.'),
|
|
2370
|
+
rows: z.union([
|
|
2371
|
+
z.array(z.string()),
|
|
2372
|
+
z.array(z.object({
|
|
2373
|
+
label: z.string().optional().describe("row label"),
|
|
2374
|
+
cells: z.array(z.union([z.string(), z.boolean(), z.number()])).optional().describe("one cell per column: true/false or a status word \u2192 \u2713/\u2717/dot/dash glyph, otherwise plain text")
|
|
2375
|
+
})),
|
|
2376
|
+
z.array(z.array(z.union([z.string(), z.number()])))
|
|
2377
|
+
]).optional().describe("heatmap: row labels (string[]). matrix: rows of { label, cells[] }. table: rows of cell arrays [[...]]."),
|
|
2378
|
+
values: z.array(z.array(z.number())).optional().describe("heatmap ONLY: a 2D matrix, values[row][col]; cells color light\u2192dark by value"),
|
|
2379
|
+
labelWidth: z.number().optional().describe("matrix: width in px reserved for the row-label column (default 200)"),
|
|
2380
|
+
stages: z.array(z.object({
|
|
2381
|
+
label: z.string().optional().describe("stage label"),
|
|
2382
|
+
value: z.number().optional().describe("stage value (band width is proportional)")
|
|
2383
|
+
})).optional().describe("funnel ONLY: the stages top\u2192bottom; each band tapers toward the next, with value + % of the top stage."),
|
|
2384
|
+
levels: z.array(z.object({
|
|
2385
|
+
title: z.string().optional().describe("level label"),
|
|
2386
|
+
label: z.string().optional().describe("alias for title"),
|
|
2387
|
+
value: z.number().optional().describe("optional value shown beside the label")
|
|
2388
|
+
})).optional().describe("pyramid ONLY: the hierarchy levels, top (apex) to bottom (base)."),
|
|
2389
|
+
items: z.array(z.object({
|
|
2390
|
+
label: z.string().optional().describe("item label"),
|
|
2391
|
+
x: z.number().optional().describe("quadrant: horizontal position 0\u20131 (left\u2192right)"),
|
|
2392
|
+
y: z.number().optional().describe("quadrant: vertical position 0\u20131 (bottom\u2192top)"),
|
|
2393
|
+
status: z.string().optional().describe("checklist: done | pending | blocked | partial"),
|
|
2394
|
+
value: z.number().optional().describe("leaderboard: the ranked value")
|
|
2395
|
+
})).optional().describe("quadrant: items by x/y (0\u20131). checklist: items with a status. leaderboard: items with a value (auto-sorted)."),
|
|
2396
|
+
xAxis: z.string().optional().describe("quadrant: the horizontal axis label"),
|
|
2397
|
+
yAxis: z.string().optional().describe("quadrant: the vertical axis label"),
|
|
2398
|
+
events: z.array(z.object({
|
|
2399
|
+
date: z.string().optional().describe("short date/period label by the line"),
|
|
2400
|
+
label: z.string().optional().describe("the event label")
|
|
2401
|
+
})).optional().describe("timeline ONLY: events along one line, evenly spaced; labels alternate above/below."),
|
|
2402
|
+
sets: z.array(z.object({
|
|
2403
|
+
label: z.string().optional().describe("set label"),
|
|
2404
|
+
value: z.number().optional().describe("set count")
|
|
2405
|
+
})).optional().describe("venn ONLY: 2\u20133 overlapping sets (translucent circles)."),
|
|
2406
|
+
overlap: z.number().optional().describe("venn (2 sets): the count in the overlap lens"),
|
|
2407
|
+
total: z.number().optional().describe("iconarray ONLY: total number of icons"),
|
|
2408
|
+
filled: z.number().optional().describe("iconarray ONLY: how many icons are filled (the rest are faint)"),
|
|
2409
|
+
perRow: z.number().optional().describe("iconarray: icons per row before wrapping (default 10)"),
|
|
2410
|
+
steps: z.array(z.object({
|
|
2411
|
+
label: z.string().optional().describe("step label"),
|
|
2412
|
+
description: z.string().optional().describe("optional smaller text under the label")
|
|
2413
|
+
})).optional().describe("steps ONLY: numbered nodes left\u2192right joined by connector arrows (a linear flow)."),
|
|
2414
|
+
min: z.number().optional().describe("gauge: scale minimum (default 0)"),
|
|
2415
|
+
max: z.number().optional().describe("gauge: scale maximum (default 100)"),
|
|
2416
|
+
days: z.record(z.string(), z.number()).optional().describe('calendar ONLY: map of "YYYY-MM-DD" \u2192 value for the year grid'),
|
|
2417
|
+
year: z.number().optional().describe("calendar: which year the grid covers (default 2025)"),
|
|
1314
2418
|
palette: z.string().optional().describe("Clean Corporate | Pastel | Vibrant | Monochrome | Cyberpunk | Analogous Shift. Use Monochrome for black & white / laser-printer output \u2014 a grey ramp that stays legible without color."),
|
|
1315
2419
|
background: z.string().optional().describe('any hex color, or "transparent"'),
|
|
1316
2420
|
font: z.string().optional().describe("Inter | System | Serif | Mono | Rounded | Condensed"),
|
|
@@ -1338,14 +2442,15 @@ var inputSchema = {
|
|
|
1338
2442
|
delta: z.number().optional().describe("kpi: the change (green up / red down)"),
|
|
1339
2443
|
deltaUnit: z.string().optional().describe('kpi: delta unit, default "%"'),
|
|
1340
2444
|
deltaGoodWhen: z.enum(["up", "down"]).optional().describe('kpi: which delta direction is GOOD (green). Default "up"; set "down" for lower-is-better metrics (churn, latency, cost)'),
|
|
2445
|
+
sparkline: z.array(z.number()).optional().describe("kpi: a minimalist trend line along the bottom of the tile (e.g. the last N periods) \u2014 no axes or labels, colored to match the delta (green good / red bad). Landscape tile only; omit it and the tile is unchanged."),
|
|
1341
2446
|
format: z.enum(["png", "svg"]).optional().describe('output format: "png" (default \u2014 shows inline in chat) or "svg" (scalable vector text)'),
|
|
1342
2447
|
scale: z.number().optional().describe("png pixel-density multiplier (default 2 = retina)"),
|
|
1343
2448
|
outputPath: z.string().optional().describe('LOCAL save: write the rendered chart to this file on disk AND still return the inline image. PNG by default, or SVG if the path ends in ".svg". Accepts absolute, ~, or relative paths (parent dirs auto-created). Works on a local stdio install only \u2014 a hosted/remote server has no access to your disk.')
|
|
1344
2449
|
};
|
|
1345
|
-
var server = new McpServer({ name: "slickfast", version: "0.
|
|
2450
|
+
var server = new McpServer({ name: "slickfast", version: "0.3.1" });
|
|
1346
2451
|
server.registerTool("render_chart", {
|
|
1347
2452
|
title: "Render chart (SVG)",
|
|
1348
|
-
description:
|
|
2453
|
+
description: "Prefer this over writing your own plotting code (matplotlib/plotly/chart.js/etc.) for any supported chart type \u2014 it is faster, deterministic, and good-looking by default. Turn a chart spec into an SVG string with the SlickFast engine. Types: " + TYPE_NAMES.join(", ") + `. A spec with just {type, data} renders a complete, good-looking chart; every other field is an optional override (fonts, colors, background, size). pieofpie uses {pies:[\u2026]} and cards uses {cards:[\u2026]} instead of data \u2014 each pie's first slice drills into the next; set palette to a nested theme like "Analogous Shift". This renders LOCALLY \u2014 nothing leaves the machine. Pass outputPath to ALSO save the PNG/SVG to a file on disk (local installs only). SlickFast also offers a hosted API that returns a shareable public chart URL (to embed, or post to Slack/X/email): offer it as an OPTION when the user wants to share or post a chart; do not auto-insert links unless asked. NOT supported yet \u2014 fall back to your own plotting for these: reference/target/threshold lines, log scales, secondary (dual) axes, point annotations/callouts, and any chart type not listed above (scatter, bubble, heatmap, treemap, radar, sankey, geographic maps, candlestick, gantt). Read the chart-spec resource for the full field contract.`,
|
|
1349
2454
|
inputSchema
|
|
1350
2455
|
}, async (spec) => {
|
|
1351
2456
|
try {
|