sketchmark 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,
@@ -2077,7 +2077,7 @@ const CHART_COLORS = [
2077
2077
  '#7F77DD', '#D4537E', '#639922', '#E24B4A',
2078
2078
  ];
2079
2079
  function chartLayout(c) {
2080
- const titleH = c.title ? 24 : 8;
2080
+ const titleH = c.label ? 24 : 8;
2081
2081
  const padL = 44, padR = 12, padB = 28, padT = 6;
2082
2082
  const pw = c.w - padL - padR;
2083
2083
  const ph = c.h - titleH - padT - padB;
@@ -2265,17 +2265,17 @@ function renderRoughChartSVG(rc, c, palette, isDark) {
2265
2265
  ...(s.strokeDash ? { strokeLineDash: s.strokeDash } : {}),
2266
2266
  }));
2267
2267
  // Title
2268
- if (c.title) {
2269
- cg.appendChild(mkT(c.title, c.x + c.w / 2, c.y + 14, cFontSize, cFontWeight, lc, 'middle', cFont));
2268
+ if (c.label) {
2269
+ cg.appendChild(mkT(c.label, c.x + c.w / 2, c.y + 14, cFontSize, cFontWeight, lc, 'middle', cFont));
2270
2270
  }
2271
2271
  const { px, py, pw, ph, cx, cy } = chartLayout(c);
2272
2272
  // ── Pie / Donut ──────────────────────────────────────────
2273
2273
  if (c.chartType === 'pie' || c.chartType === 'donut') {
2274
2274
  const { segments, total } = parsePie(c.data);
2275
- const r = Math.min(c.w * 0.38, (c.h - (c.title ? 24 : 8)) * 0.44);
2275
+ const r = Math.min(c.w * 0.38, (c.h - (c.label ? 24 : 8)) * 0.44);
2276
2276
  const ir = c.chartType === 'donut' ? r * 0.48 : 0;
2277
2277
  const legendX = c.x + 8;
2278
- const legendY = c.y + (c.title ? 28 : 12);
2278
+ const legendY = c.y + (c.label ? 28 : 12);
2279
2279
  let angle = -Math.PI / 2;
2280
2280
  for (const seg of segments) {
2281
2281
  const sweep = (seg.value / total) * Math.PI * 2;
@@ -2313,7 +2313,7 @@ function renderRoughChartSVG(rc, c, palette, isDark) {
2313
2313
  strokeWidth: 1.2,
2314
2314
  }));
2315
2315
  });
2316
- legend(cg, pts.map(p => p.label), CHART_COLORS, c.x + 8, c.y + (c.title ? 28 : 12), lc, cFont);
2316
+ legend(cg, pts.map(p => p.label), CHART_COLORS, c.x + 8, c.y + (c.label ? 28 : 12), lc, cFont);
2317
2317
  return cg;
2318
2318
  }
2319
2319
  // ── Bar / Line / Area ─────────────────────────────────────
@@ -5760,23 +5760,23 @@ function drawRoughChartCanvas(rc, ctx, c, pal, R) {
5760
5760
  ...(s.strokeDash ? { strokeLineDash: s.strokeDash } : {}),
5761
5761
  });
5762
5762
  // Title
5763
- if (c.title) {
5763
+ if (c.label) {
5764
5764
  ctx.save();
5765
5765
  ctx.font = `${cFontWeight} ${cFontSize}px ${cFont}`;
5766
5766
  ctx.fillStyle = lc;
5767
5767
  ctx.textAlign = 'center';
5768
5768
  ctx.textBaseline = 'middle';
5769
- ctx.fillText(c.title, c.x + c.w / 2, c.y + 14);
5769
+ ctx.fillText(c.label, c.x + c.w / 2, c.y + 14);
5770
5770
  ctx.restore();
5771
5771
  }
5772
5772
  const { px, py, pw, ph, cx, cy } = chartLayout(c);
5773
5773
  // ── Pie / Donut ──────────────────────────────────────────
5774
5774
  if (c.chartType === 'pie' || c.chartType === 'donut') {
5775
5775
  const { segments, total } = parsePie(c.data);
5776
- const r = Math.min(c.w * 0.38, (c.h - (c.title ? 24 : 8)) * 0.44);
5776
+ const r = Math.min(c.w * 0.38, (c.h - (c.label ? 24 : 8)) * 0.44);
5777
5777
  const ir = c.chartType === 'donut' ? r * 0.48 : 0;
5778
5778
  const legendX = c.x + 8;
5779
- const legendY = c.y + (c.title ? 28 : 12);
5779
+ const legendY = c.y + (c.label ? 28 : 12);
5780
5780
  let angle = -Math.PI / 2;
5781
5781
  segments.forEach((seg, i) => {
5782
5782
  const sweep = (seg.value / total) * Math.PI * 2;
@@ -5804,7 +5804,7 @@ function drawRoughChartCanvas(rc, ctx, c, pal, R) {
5804
5804
  strokeWidth: 1.2,
5805
5805
  });
5806
5806
  });
5807
- drawLegend(ctx, pts.map(p => p.label), CHART_COLORS, c.x + 8, c.y + (c.title ? 28 : 12), lc, cFont);
5807
+ drawLegend(ctx, pts.map(p => p.label), CHART_COLORS, c.x + 8, c.y + (c.label ? 28 : 12), lc, cFont);
5808
5808
  ctx.globalAlpha = 1;
5809
5809
  return;
5810
5810
  }