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/README.md
CHANGED
|
@@ -375,7 +375,7 @@ note n3 label="Centered" text-align=center vertical-align=middle width=180 heigh
|
|
|
375
375
|
### Charts
|
|
376
376
|
|
|
377
377
|
```
|
|
378
|
-
bar-chart id [
|
|
378
|
+
bar-chart id [label="..."] [width=N] [height=N] [theme=X]
|
|
379
379
|
line-chart id ...
|
|
380
380
|
area-chart id ...
|
|
381
381
|
pie-chart id ...
|
|
@@ -392,7 +392,7 @@ data
|
|
|
392
392
|
|
|
393
393
|
**Pie / donut:**
|
|
394
394
|
```
|
|
395
|
-
pie-chart revenue
|
|
395
|
+
pie-chart revenue label="Revenue Split" width=280 height=240
|
|
396
396
|
data
|
|
397
397
|
[
|
|
398
398
|
["Product A", 42],
|
|
@@ -948,7 +948,7 @@ diagram
|
|
|
948
948
|
layout row
|
|
949
949
|
config gap=40
|
|
950
950
|
|
|
951
|
-
bar-chart revenue
|
|
951
|
+
bar-chart revenue label="Monthly Revenue" width=340 height=240
|
|
952
952
|
data
|
|
953
953
|
[
|
|
954
954
|
["Month", "2023", "2024"],
|
|
@@ -958,7 +958,7 @@ data
|
|
|
958
958
|
["Apr", 46000, 72000 ]
|
|
959
959
|
]
|
|
960
960
|
|
|
961
|
-
pie-chart share
|
|
961
|
+
pie-chart share label="Market Share" width=280 height=240
|
|
962
962
|
data
|
|
963
963
|
[
|
|
964
964
|
["Product A", 42],
|
package/dist/ast/types.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -850,7 +850,7 @@ function parse(src) {
|
|
|
850
850
|
kind: "chart",
|
|
851
851
|
id,
|
|
852
852
|
chartType: chartType.replace("-chart", ""),
|
|
853
|
-
|
|
853
|
+
label: props.label ?? props.title,
|
|
854
854
|
data: { headers, rows },
|
|
855
855
|
width: props.width ? parseFloat(props.width) : undefined,
|
|
856
856
|
height: props.height ? parseFloat(props.height) : undefined,
|
|
@@ -1342,7 +1342,7 @@ function buildSceneGraph(ast) {
|
|
|
1342
1342
|
return {
|
|
1343
1343
|
id: c.id,
|
|
1344
1344
|
chartType: c.chartType,
|
|
1345
|
-
|
|
1345
|
+
label: c.label,
|
|
1346
1346
|
data: c.data,
|
|
1347
1347
|
style: { ...ast.styles[c.id], ...themeStyle, ...c.style },
|
|
1348
1348
|
x: 0,
|
|
@@ -1540,9 +1540,8 @@ function sizeTable(t) {
|
|
|
1540
1540
|
const nData = rows.filter((r) => r.kind === "data").length;
|
|
1541
1541
|
t.h = labelH + nHeader * headerH + nData * rowH;
|
|
1542
1542
|
}
|
|
1543
|
-
function sizeChart(
|
|
1544
|
-
|
|
1545
|
-
c.h = c.h || 240;
|
|
1543
|
+
function sizeChart(_c) {
|
|
1544
|
+
// defaults already applied in buildSceneGraph
|
|
1546
1545
|
}
|
|
1547
1546
|
function sizeMarkdown(m) {
|
|
1548
1547
|
const pad = Number(m.style?.padding ?? 16);
|
|
@@ -2077,7 +2076,7 @@ const CHART_COLORS = [
|
|
|
2077
2076
|
'#7F77DD', '#D4537E', '#639922', '#E24B4A',
|
|
2078
2077
|
];
|
|
2079
2078
|
function chartLayout(c) {
|
|
2080
|
-
const titleH = c.
|
|
2079
|
+
const titleH = c.label ? 24 : 8;
|
|
2081
2080
|
const padL = 44, padR = 12, padB = 28, padT = 6;
|
|
2082
2081
|
const pw = c.w - padL - padR;
|
|
2083
2082
|
const ph = c.h - titleH - padT - padB;
|
|
@@ -2265,17 +2264,17 @@ function renderRoughChartSVG(rc, c, palette, isDark) {
|
|
|
2265
2264
|
...(s.strokeDash ? { strokeLineDash: s.strokeDash } : {}),
|
|
2266
2265
|
}));
|
|
2267
2266
|
// Title
|
|
2268
|
-
if (c.
|
|
2269
|
-
cg.appendChild(mkT(c.
|
|
2267
|
+
if (c.label) {
|
|
2268
|
+
cg.appendChild(mkT(c.label, c.x + c.w / 2, c.y + 14, cFontSize, cFontWeight, lc, 'middle', cFont));
|
|
2270
2269
|
}
|
|
2271
2270
|
const { px, py, pw, ph, cx, cy } = chartLayout(c);
|
|
2272
2271
|
// ── Pie / Donut ──────────────────────────────────────────
|
|
2273
2272
|
if (c.chartType === 'pie' || c.chartType === 'donut') {
|
|
2274
2273
|
const { segments, total } = parsePie(c.data);
|
|
2275
|
-
const r = Math.min(c.w * 0.38, (c.h - (c.
|
|
2274
|
+
const r = Math.min(c.w * 0.38, (c.h - (c.label ? 24 : 8)) * 0.44);
|
|
2276
2275
|
const ir = c.chartType === 'donut' ? r * 0.48 : 0;
|
|
2277
2276
|
const legendX = c.x + 8;
|
|
2278
|
-
const legendY = c.y + (c.
|
|
2277
|
+
const legendY = c.y + (c.label ? 28 : 12);
|
|
2279
2278
|
let angle = -Math.PI / 2;
|
|
2280
2279
|
for (const seg of segments) {
|
|
2281
2280
|
const sweep = (seg.value / total) * Math.PI * 2;
|
|
@@ -2313,7 +2312,7 @@ function renderRoughChartSVG(rc, c, palette, isDark) {
|
|
|
2313
2312
|
strokeWidth: 1.2,
|
|
2314
2313
|
}));
|
|
2315
2314
|
});
|
|
2316
|
-
legend(cg, pts.map(p => p.label), CHART_COLORS, c.x + 8, c.y + (c.
|
|
2315
|
+
legend(cg, pts.map(p => p.label), CHART_COLORS, c.x + 8, c.y + (c.label ? 28 : 12), lc, cFont);
|
|
2317
2316
|
return cg;
|
|
2318
2317
|
}
|
|
2319
2318
|
// ── Bar / Line / Area ─────────────────────────────────────
|
|
@@ -5564,7 +5563,6 @@ function renderToSVG(sg, container, options = {}) {
|
|
|
5564
5563
|
NoteL.appendChild(ng);
|
|
5565
5564
|
}
|
|
5566
5565
|
svg.appendChild(NoteL);
|
|
5567
|
-
markdownMap(sg);
|
|
5568
5566
|
const MDL = mkGroup('markdown-layer');
|
|
5569
5567
|
for (const m of sg.markdowns) {
|
|
5570
5568
|
const mg = mkGroup(`markdown-${m.id}`, 'mdg');
|
|
@@ -5760,23 +5758,23 @@ function drawRoughChartCanvas(rc, ctx, c, pal, R) {
|
|
|
5760
5758
|
...(s.strokeDash ? { strokeLineDash: s.strokeDash } : {}),
|
|
5761
5759
|
});
|
|
5762
5760
|
// Title
|
|
5763
|
-
if (c.
|
|
5761
|
+
if (c.label) {
|
|
5764
5762
|
ctx.save();
|
|
5765
5763
|
ctx.font = `${cFontWeight} ${cFontSize}px ${cFont}`;
|
|
5766
5764
|
ctx.fillStyle = lc;
|
|
5767
5765
|
ctx.textAlign = 'center';
|
|
5768
5766
|
ctx.textBaseline = 'middle';
|
|
5769
|
-
ctx.fillText(c.
|
|
5767
|
+
ctx.fillText(c.label, c.x + c.w / 2, c.y + 14);
|
|
5770
5768
|
ctx.restore();
|
|
5771
5769
|
}
|
|
5772
5770
|
const { px, py, pw, ph, cx, cy } = chartLayout(c);
|
|
5773
5771
|
// ── Pie / Donut ──────────────────────────────────────────
|
|
5774
5772
|
if (c.chartType === 'pie' || c.chartType === 'donut') {
|
|
5775
5773
|
const { segments, total } = parsePie(c.data);
|
|
5776
|
-
const r = Math.min(c.w * 0.38, (c.h - (c.
|
|
5774
|
+
const r = Math.min(c.w * 0.38, (c.h - (c.label ? 24 : 8)) * 0.44);
|
|
5777
5775
|
const ir = c.chartType === 'donut' ? r * 0.48 : 0;
|
|
5778
5776
|
const legendX = c.x + 8;
|
|
5779
|
-
const legendY = c.y + (c.
|
|
5777
|
+
const legendY = c.y + (c.label ? 28 : 12);
|
|
5780
5778
|
let angle = -Math.PI / 2;
|
|
5781
5779
|
segments.forEach((seg, i) => {
|
|
5782
5780
|
const sweep = (seg.value / total) * Math.PI * 2;
|
|
@@ -5804,7 +5802,7 @@ function drawRoughChartCanvas(rc, ctx, c, pal, R) {
|
|
|
5804
5802
|
strokeWidth: 1.2,
|
|
5805
5803
|
});
|
|
5806
5804
|
});
|
|
5807
|
-
drawLegend(ctx, pts.map(p => p.label), CHART_COLORS, c.x + 8, c.y + (c.
|
|
5805
|
+
drawLegend(ctx, pts.map(p => p.label), CHART_COLORS, c.x + 8, c.y + (c.label ? 28 : 12), lc, cFont);
|
|
5808
5806
|
ctx.globalAlpha = 1;
|
|
5809
5807
|
return;
|
|
5810
5808
|
}
|