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 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 [title="..."] [width=N] [height=N] [theme=X]
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 title="Revenue Split" width=280 height=240
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 title="Monthly Revenue" width=340 height=240
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 title="Market Share" width=280 height=240
961
+ pie-chart share label="Market Share" width=280 height=240
962
962
  data
963
963
  [
964
964
  ["Product A", 42],
@@ -121,7 +121,7 @@ export interface ASTChart {
121
121
  kind: 'chart';
122
122
  id: string;
123
123
  chartType: 'bar' | 'line' | 'pie' | 'donut' | 'scatter' | 'area';
124
- title?: string;
124
+ label?: string;
125
125
  data: ASTChartData;
126
126
  width?: number;
127
127
  height?: number;
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
- title: props.title,
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
- title: c.title,
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(c) {
1544
- c.w = c.w || 320;
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.title ? 24 : 8;
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.title) {
2269
- cg.appendChild(mkT(c.title, c.x + c.w / 2, c.y + 14, cFontSize, cFontWeight, lc, 'middle', cFont));
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.title ? 24 : 8)) * 0.44);
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.title ? 28 : 12);
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.title ? 28 : 12), lc, cFont);
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.title) {
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.title, c.x + c.w / 2, c.y + 14);
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.title ? 24 : 8)) * 0.44);
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.title ? 28 : 12);
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.title ? 28 : 12), lc, cFont);
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
  }