sketchmark 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/ast/types.d.ts +1 -1
- package/dist/index.cjs +15 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +15 -17
- package/dist/index.js.map +1 -1
- package/dist/layout/index.d.ts.map +1 -1
- package/dist/renderer/roughChart.d.ts +1 -1
- package/dist/renderer/svg/index.d.ts.map +1 -1
- package/dist/scene/index.d.ts +1 -1
- package/dist/sketchmark.iife.js +15 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -848,7 +848,7 @@ function parse(src) {
|
|
|
848
848
|
kind: "chart",
|
|
849
849
|
id,
|
|
850
850
|
chartType: chartType.replace("-chart", ""),
|
|
851
|
-
|
|
851
|
+
label: props.label ?? props.title,
|
|
852
852
|
data: { headers, rows },
|
|
853
853
|
width: props.width ? parseFloat(props.width) : undefined,
|
|
854
854
|
height: props.height ? parseFloat(props.height) : undefined,
|
|
@@ -1340,7 +1340,7 @@ function buildSceneGraph(ast) {
|
|
|
1340
1340
|
return {
|
|
1341
1341
|
id: c.id,
|
|
1342
1342
|
chartType: c.chartType,
|
|
1343
|
-
|
|
1343
|
+
label: c.label,
|
|
1344
1344
|
data: c.data,
|
|
1345
1345
|
style: { ...ast.styles[c.id], ...themeStyle, ...c.style },
|
|
1346
1346
|
x: 0,
|
|
@@ -1538,9 +1538,8 @@ function sizeTable(t) {
|
|
|
1538
1538
|
const nData = rows.filter((r) => r.kind === "data").length;
|
|
1539
1539
|
t.h = labelH + nHeader * headerH + nData * rowH;
|
|
1540
1540
|
}
|
|
1541
|
-
function sizeChart(
|
|
1542
|
-
|
|
1543
|
-
c.h = c.h || 240;
|
|
1541
|
+
function sizeChart(_c) {
|
|
1542
|
+
// defaults already applied in buildSceneGraph
|
|
1544
1543
|
}
|
|
1545
1544
|
function sizeMarkdown(m) {
|
|
1546
1545
|
const pad = Number(m.style?.padding ?? 16);
|
|
@@ -2075,7 +2074,7 @@ const CHART_COLORS = [
|
|
|
2075
2074
|
'#7F77DD', '#D4537E', '#639922', '#E24B4A',
|
|
2076
2075
|
];
|
|
2077
2076
|
function chartLayout(c) {
|
|
2078
|
-
const titleH = c.
|
|
2077
|
+
const titleH = c.label ? 24 : 8;
|
|
2079
2078
|
const padL = 44, padR = 12, padB = 28, padT = 6;
|
|
2080
2079
|
const pw = c.w - padL - padR;
|
|
2081
2080
|
const ph = c.h - titleH - padT - padB;
|
|
@@ -2263,17 +2262,17 @@ function renderRoughChartSVG(rc, c, palette, isDark) {
|
|
|
2263
2262
|
...(s.strokeDash ? { strokeLineDash: s.strokeDash } : {}),
|
|
2264
2263
|
}));
|
|
2265
2264
|
// Title
|
|
2266
|
-
if (c.
|
|
2267
|
-
cg.appendChild(mkT(c.
|
|
2265
|
+
if (c.label) {
|
|
2266
|
+
cg.appendChild(mkT(c.label, c.x + c.w / 2, c.y + 14, cFontSize, cFontWeight, lc, 'middle', cFont));
|
|
2268
2267
|
}
|
|
2269
2268
|
const { px, py, pw, ph, cx, cy } = chartLayout(c);
|
|
2270
2269
|
// ── Pie / Donut ──────────────────────────────────────────
|
|
2271
2270
|
if (c.chartType === 'pie' || c.chartType === 'donut') {
|
|
2272
2271
|
const { segments, total } = parsePie(c.data);
|
|
2273
|
-
const r = Math.min(c.w * 0.38, (c.h - (c.
|
|
2272
|
+
const r = Math.min(c.w * 0.38, (c.h - (c.label ? 24 : 8)) * 0.44);
|
|
2274
2273
|
const ir = c.chartType === 'donut' ? r * 0.48 : 0;
|
|
2275
2274
|
const legendX = c.x + 8;
|
|
2276
|
-
const legendY = c.y + (c.
|
|
2275
|
+
const legendY = c.y + (c.label ? 28 : 12);
|
|
2277
2276
|
let angle = -Math.PI / 2;
|
|
2278
2277
|
for (const seg of segments) {
|
|
2279
2278
|
const sweep = (seg.value / total) * Math.PI * 2;
|
|
@@ -2311,7 +2310,7 @@ function renderRoughChartSVG(rc, c, palette, isDark) {
|
|
|
2311
2310
|
strokeWidth: 1.2,
|
|
2312
2311
|
}));
|
|
2313
2312
|
});
|
|
2314
|
-
legend(cg, pts.map(p => p.label), CHART_COLORS, c.x + 8, c.y + (c.
|
|
2313
|
+
legend(cg, pts.map(p => p.label), CHART_COLORS, c.x + 8, c.y + (c.label ? 28 : 12), lc, cFont);
|
|
2315
2314
|
return cg;
|
|
2316
2315
|
}
|
|
2317
2316
|
// ── Bar / Line / Area ─────────────────────────────────────
|
|
@@ -5562,7 +5561,6 @@ function renderToSVG(sg, container, options = {}) {
|
|
|
5562
5561
|
NoteL.appendChild(ng);
|
|
5563
5562
|
}
|
|
5564
5563
|
svg.appendChild(NoteL);
|
|
5565
|
-
markdownMap(sg);
|
|
5566
5564
|
const MDL = mkGroup('markdown-layer');
|
|
5567
5565
|
for (const m of sg.markdowns) {
|
|
5568
5566
|
const mg = mkGroup(`markdown-${m.id}`, 'mdg');
|
|
@@ -5758,23 +5756,23 @@ function drawRoughChartCanvas(rc, ctx, c, pal, R) {
|
|
|
5758
5756
|
...(s.strokeDash ? { strokeLineDash: s.strokeDash } : {}),
|
|
5759
5757
|
});
|
|
5760
5758
|
// Title
|
|
5761
|
-
if (c.
|
|
5759
|
+
if (c.label) {
|
|
5762
5760
|
ctx.save();
|
|
5763
5761
|
ctx.font = `${cFontWeight} ${cFontSize}px ${cFont}`;
|
|
5764
5762
|
ctx.fillStyle = lc;
|
|
5765
5763
|
ctx.textAlign = 'center';
|
|
5766
5764
|
ctx.textBaseline = 'middle';
|
|
5767
|
-
ctx.fillText(c.
|
|
5765
|
+
ctx.fillText(c.label, c.x + c.w / 2, c.y + 14);
|
|
5768
5766
|
ctx.restore();
|
|
5769
5767
|
}
|
|
5770
5768
|
const { px, py, pw, ph, cx, cy } = chartLayout(c);
|
|
5771
5769
|
// ── Pie / Donut ──────────────────────────────────────────
|
|
5772
5770
|
if (c.chartType === 'pie' || c.chartType === 'donut') {
|
|
5773
5771
|
const { segments, total } = parsePie(c.data);
|
|
5774
|
-
const r = Math.min(c.w * 0.38, (c.h - (c.
|
|
5772
|
+
const r = Math.min(c.w * 0.38, (c.h - (c.label ? 24 : 8)) * 0.44);
|
|
5775
5773
|
const ir = c.chartType === 'donut' ? r * 0.48 : 0;
|
|
5776
5774
|
const legendX = c.x + 8;
|
|
5777
|
-
const legendY = c.y + (c.
|
|
5775
|
+
const legendY = c.y + (c.label ? 28 : 12);
|
|
5778
5776
|
let angle = -Math.PI / 2;
|
|
5779
5777
|
segments.forEach((seg, i) => {
|
|
5780
5778
|
const sweep = (seg.value / total) * Math.PI * 2;
|
|
@@ -5802,7 +5800,7 @@ function drawRoughChartCanvas(rc, ctx, c, pal, R) {
|
|
|
5802
5800
|
strokeWidth: 1.2,
|
|
5803
5801
|
});
|
|
5804
5802
|
});
|
|
5805
|
-
drawLegend(ctx, pts.map(p => p.label), CHART_COLORS, c.x + 8, c.y + (c.
|
|
5803
|
+
drawLegend(ctx, pts.map(p => p.label), CHART_COLORS, c.x + 8, c.y + (c.label ? 28 : 12), lc, cFont);
|
|
5806
5804
|
ctx.globalAlpha = 1;
|
|
5807
5805
|
return;
|
|
5808
5806
|
}
|