ztd-charts-cli 0.7.0 → 0.8.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.
Files changed (54) hide show
  1. package/README.md +1 -1
  2. package/dist/api.d.ts +11 -1
  3. package/dist/api.js +5 -1
  4. package/dist/{chunk-4WXNLD5P.js → chunk-FB5WHEJX.js} +38 -15
  5. package/dist/cli.js +5 -4
  6. package/dist/client/NOTICE.md +39 -0
  7. package/dist/client/area.js +10 -10
  8. package/dist/client/bar.js +10 -10
  9. package/dist/client/barRace.js +28 -0
  10. package/dist/client/beeswarm.js +10 -10
  11. package/dist/client/box.js +10 -10
  12. package/dist/client/bubble.js +10 -10
  13. package/dist/client/bullet.js +9 -9
  14. package/dist/client/bump.js +10 -10
  15. package/dist/client/calendar.js +9 -9
  16. package/dist/client/candlestick.js +9 -9
  17. package/dist/client/chord.js +10 -10
  18. package/dist/client/choropleth.js +28 -0
  19. package/dist/client/donut.js +10 -10
  20. package/dist/client/dumbbell.js +9 -9
  21. package/dist/client/flowMap.js +28 -0
  22. package/dist/client/funnel.js +10 -10
  23. package/dist/client/gauge.js +10 -10
  24. package/dist/client/geo-kr-sido.js +1 -0
  25. package/dist/client/geo-us-states.js +1 -0
  26. package/dist/client/geo-world.js +1 -0
  27. package/dist/client/heatmap.js +9 -9
  28. package/dist/client/histogram.js +6 -6
  29. package/dist/client/line.js +10 -10
  30. package/dist/client/lollipop.js +10 -10
  31. package/dist/client/marimekko.js +6 -6
  32. package/dist/client/network.js +28 -0
  33. package/dist/client/parallel.js +9 -9
  34. package/dist/client/pareto.js +10 -10
  35. package/dist/client/pie.js +10 -10
  36. package/dist/client/radar.js +10 -10
  37. package/dist/client/radialBar.js +10 -10
  38. package/dist/client/ridgeline.js +10 -10
  39. package/dist/client/sankey.js +10 -10
  40. package/dist/client/scatter.js +10 -10
  41. package/dist/client/segmented.js +9 -9
  42. package/dist/client/skyline.js +10 -10
  43. package/dist/client/slope.js +10 -10
  44. package/dist/client/sparkline.js +10 -10
  45. package/dist/client/stream.js +10 -10
  46. package/dist/client/sunburst.js +9 -9
  47. package/dist/client/symbolMap.js +28 -0
  48. package/dist/client/tileMap.js +10 -10
  49. package/dist/client/timeline.js +28 -0
  50. package/dist/client/tree.js +28 -0
  51. package/dist/client/treemap.js +9 -9
  52. package/dist/client/waffle.js +9 -9
  53. package/dist/client/waterfall.js +10 -10
  54. package/package.json +2 -2
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ztd-charts-cli
2
2
 
3
- `ztd-charts`: the list of all 37 charts, JSON Schema, spec validation, SVG/PNG/HTML rendering, starter files, and chart suggestions from your data.
3
+ `ztd-charts`: the list of all 44 charts, JSON Schema, spec validation, SVG/PNG/HTML rendering, starter files, and chart suggestions from your data.
4
4
 
5
5
  [Website](https://charts.ztd.app) · [Gallery](https://charts.ztd.app/docs/) · [GitHub](https://github.com/Junhan2/ztd-charts)
6
6
 
package/dist/api.d.ts CHANGED
@@ -137,6 +137,16 @@ declare function svgToPng(svg: string, opts?: {
137
137
  png: Buffer;
138
138
  notes?: string[];
139
139
  }>;
140
+ /**
141
+ * PNG 한 장의 최대 픽셀 수. 10,000 × 5,000px 또는 2400 × 1000px 차트의 배율 4(약 3,800만)까지 그대로이고, 비트맵은 4바이트씩이라 약 200MB가 상한이에요
142
+ */
143
+ declare const PNG_MAX_PIXELS = 50000000;
144
+ /**
145
+ * PNG 배율. 실제로 그릴 SVG의 바깥 <svg> 크기 × 배율²이 PNG_MAX_PIXELS를 넘으면 넘지 않게 배율을 낮춰요(비트맵을 잡기 전에 정해요).
146
+ * 크기는 줄이지 않은 그대로 재요(작은 여러 개, 긴 범례처럼 차트 한 변 한도보다 큰 문서도 있어요).
147
+ * 바깥 <svg>에 픽셀 폭과 높이가 없거나 0 이하, 유한하지 않으면 null이라 그리지 않아요(한도를 증명할 수 없어서)
148
+ */
149
+ declare function pngZoom(svg: string, scale: number): number | null;
140
150
  /** http(s) 주소인지. loadRows, CLI suggest, MCP suggest_chart가 같은 규칙(대소문자 무시)을 써요 */
141
151
  declare function isHttpUrl(source: string): boolean;
142
152
  /** 파일 경로나 URL, CSV/JSON 문자열을 행 배열로 */
@@ -150,5 +160,5 @@ declare function suggest(rows: Record<string, unknown>[], opts?: {
150
160
  suggestions: Suggestion[];
151
161
  };
152
162
 
153
- export { FETCH_TIMEOUT_MS, MAX_FETCH_BYTES, fetchUrl, findFonts, getChartInfo, getChartSchema, isHttpUrl, listCharts, loadRows, reactSnippet, render, resolveType, specSnippet, stripEmoji, suggest, summarize, svgToPng, validate };
163
+ export { FETCH_TIMEOUT_MS, MAX_FETCH_BYTES, PNG_MAX_PIXELS, fetchUrl, findFonts, getChartInfo, getChartSchema, isHttpUrl, listCharts, loadRows, pngZoom, reactSnippet, render, resolveType, specSnippet, stripEmoji, suggest, summarize, svgToPng, validate };
154
164
  export type { ChartSummary, FetchOptions, RenderOptions, RenderResult };
package/dist/api.js CHANGED
@@ -2,6 +2,7 @@ import {
2
2
  CHARTS,
3
3
  FETCH_TIMEOUT_MS,
4
4
  MAX_FETCH_BYTES,
5
+ PNG_MAX_PIXELS,
5
6
  fetchUrl,
6
7
  findFonts,
7
8
  getChartInfo,
@@ -9,6 +10,7 @@ import {
9
10
  isHttpUrl,
10
11
  listCharts,
11
12
  loadRows,
13
+ pngZoom,
12
14
  reactSnippet,
13
15
  render,
14
16
  resolveType,
@@ -18,11 +20,12 @@ import {
18
20
  summarize,
19
21
  svgToPng,
20
22
  validate
21
- } from "./chunk-4WXNLD5P.js";
23
+ } from "./chunk-FB5WHEJX.js";
22
24
  export {
23
25
  CHARTS,
24
26
  FETCH_TIMEOUT_MS,
25
27
  MAX_FETCH_BYTES,
28
+ PNG_MAX_PIXELS,
26
29
  fetchUrl,
27
30
  findFonts,
28
31
  getChartInfo,
@@ -30,6 +33,7 @@ export {
30
33
  isHttpUrl,
31
34
  listCharts,
32
35
  loadRows,
36
+ pngZoom,
33
37
  reactSnippet,
34
38
  render,
35
39
  resolveType,
@@ -5,14 +5,14 @@ import { dirname, join, resolve } from "path";
5
5
  import { fileURLToPath } from "url";
6
6
  import { CHARTS, commonOptionsIn, downloadFields, FACET_TYPES, findGroup, findLevel, getChartDef, localizeDef, schemaForIn, specLocale, specSchemaIn, specTemplate, suggestCharts, validateSpec, variantsIn, TYPE_ALIASES } from "ztd-charts/spec";
7
7
  import { inlineRows, normalizeData, parseCSV } from "ztd-charts/spec";
8
- import { langOf, renderSpecToHTML, renderSpecToSVG, resolveDef, resolveSpecData } from "ztd-charts/server";
8
+ import { langOf, mapExportName, renderSpecToHTML, renderSpecToSVG, resolveDef, resolveSpecData, specMapName } from "ztd-charts/server";
9
9
 
10
10
  // src/messages.ts
11
11
  import { plural } from "ztd-charts/server";
12
- var VERSION = "0.7.0";
12
+ var VERSION = "0.8.0";
13
13
  var SCHEMA_URL = "https://unpkg.com/ztd-charts/schema/chart-spec.schema.json";
14
14
  var en = {
15
- help: `ztd-charts ${VERSION} CLI for 37 React chart types
15
+ help: `ztd-charts ${VERSION} CLI for 44 React chart types
16
16
 
17
17
  Usage
18
18
  ztd-charts list [--group proportion] [--level basic] [--json]
@@ -66,6 +66,7 @@ ${n} charts. Details: ztd-charts info <type>`,
66
66
  noVariants: (type) => `${type} has no named variants`,
67
67
  saved: (p) => `Saved: ${p}`,
68
68
  emojiRemoved: (n) => `Removed ${n} emoji from the PNG text because PNG has no emoji font. SVG and HTML keep them`,
69
+ pngNoSize: "Couldn't read a width and height in pixels on the outer <svg>, so the PNG was not drawn",
69
70
  valid: (file, type, warnings) => `\u2713 ${file}: valid ${type} spec${warnings ? ` (${plural(warnings, "warning")})` : ""}`,
70
71
  skipped: (p) => `Skipped (already exists): ${p}`,
71
72
  created: (p) => `Created: ${p}`,
@@ -103,7 +104,7 @@ ${n} charts. Details: ztd-charts info <type>`,
103
104
  })
104
105
  };
105
106
  var ko = {
106
- help: `ztd-charts ${VERSION} React \uCC28\uD2B8 37\uC885\uC744 \uC704\uD55C CLI
107
+ help: `ztd-charts ${VERSION} React \uCC28\uD2B8 44\uC885\uC744 \uC704\uD55C CLI
107
108
 
108
109
  \uC0AC\uC6A9\uBC95
109
110
  ztd-charts list [--group \uBE44\uC728] [--level \uAE30\uBCF8] [--json]
@@ -155,6 +156,7 @@ ${n}\uC885. \uC790\uC138\uD788: ztd-charts info <type>`,
155
156
  noVariants: (type) => `${type}\uC5D0\uB294 \uC774\uB984 \uBD99\uC740 \uBCC0\uD615\uC774 \uC5C6\uC5B4\uC694`,
156
157
  saved: (p) => `\uC800\uC7A5: ${p}`,
157
158
  emojiRemoved: (n) => `PNG\uC5D0\uB294 \uC774\uBAA8\uC9C0 \uAE00\uAF34\uC774 \uC5C6\uC5B4\uC11C \uAE00\uC790\uC5D0\uC11C \uC774\uBAA8\uC9C0 ${n}\uAC1C\uB97C \uBE90\uC5B4\uC694. SVG\uC640 HTML\uC5D0\uB294 \uADF8\uB300\uB85C \uC788\uC5B4\uC694`,
159
+ pngNoSize: "\uBC14\uAE65 <svg>\uC5D0\uC11C \uD53D\uC140 \uD3ED\uACFC \uB192\uC774\uB97C \uC77D\uC9C0 \uBABB\uD574\uC11C PNG\uB97C \uADF8\uB9AC\uC9C0 \uC54A\uC558\uC5B4\uC694",
158
160
  valid: (file, type, warnings) => `\u2713 ${file}: \uC62C\uBC14\uB978 ${type} \uC2A4\uD399${warnings ? `(\uACBD\uACE0 ${warnings}\uAC1C)` : ""}`,
159
161
  skipped: (p) => `\uAC74\uB108\uB700(\uC774\uBBF8 \uC788\uC74C): ${p}`,
160
162
  created: (p) => `\uB9CC\uB4E6: ${p}`,
@@ -309,11 +311,13 @@ function reactSnippet(spec, opts = {}) {
309
311
  }
310
312
  const template = specTemplate(spec);
311
313
  const tipLocale = specLocale(spec);
314
+ const geo = specMapName(spec);
312
315
  for (const [k, v] of Object.entries(spec.options ?? {})) {
313
- if (!JSX_NAME.test(k)) continue;
316
+ if (!JSX_NAME.test(k) || geo && k === "map") continue;
314
317
  if (k === "tooltip" && template) props.push(`tooltip={templateTooltip(${JSON.stringify(template)}${tipLocale ? `, ${JSON.stringify(tipLocale)}` : ""})}`);
315
318
  else props.push(`${k}=${jsxValue(v)}`);
316
319
  }
320
+ if (geo) props.push(`map={${mapExportName(geo)}}`);
317
321
  const facet = spec.facet && typeof spec.facet.by === "string" && FACET_TYPES.includes(def.type) && !(def.type === "bar" && spec.options?.layout === "diverging") ? spec.facet : void 0;
318
322
  const chartEl = facet ? facetElement(def.component, def.type, facet, props) : `<${def.component} ${props.join(" ")} />`;
319
323
  const card = spec.card;
@@ -338,8 +342,10 @@ function reactSnippet(spec, opts = {}) {
338
342
  ${chartEl}
339
343
  </ChartCard>`;
340
344
  }
345
+ const geoLine = geo ? `import { ${mapExportName(geo)} } from "ztd-charts/geo/${geo}";
346
+ ` : "";
341
347
  return `import { ${imports} } from "ztd-charts";
342
-
348
+ ${geoLine}
343
349
  ${dataLine}export function ${def.component}Example() {
344
350
  return (
345
351
  ${body}
@@ -348,8 +354,15 @@ ${dataLine}export function ${def.component}Example() {
348
354
  `;
349
355
  }
350
356
  function specSnippet(spec) {
351
- return `import { Chart, type ChartSpec } from "ztd-charts";
357
+ const geo = specMapName(spec);
358
+ const name = geo && mapExportName(geo);
359
+ const head = geo ? `import { Chart, registerMap, type ChartSpec } from "ztd-charts";
360
+ import { ${name} } from "ztd-charts/geo/${geo}";
352
361
 
362
+ registerMap(${name});
363
+ ` : `import { Chart, type ChartSpec } from "ztd-charts";
364
+ `;
365
+ return `${head}
353
366
  const spec: ChartSpec = ${JSON.stringify({ ...spec, data: Array.isArray(spec.data) ? spec.data.slice(0, 8) : spec.data }, null, 2)};
354
367
 
355
368
  export function SpecChart() {
@@ -386,13 +399,11 @@ function stripEmoji(svg) {
386
399
  });
387
400
  return { svg: out, removed };
388
401
  }
389
- function clientScript(type) {
402
+ function clientScript(type, map) {
390
403
  const here = dirname(fileURLToPath(import.meta.url));
391
404
  for (const dir of [join(here, "client"), join(here, "../dist/client")]) {
392
- const react = join(dir, "react.js");
393
- const chart = join(dir, `${type}.js`);
394
- if (existsSync(react) && existsSync(chart)) return `${readFileSync(react, "utf8")}
395
- ${readFileSync(chart, "utf8")}`;
405
+ const files = [join(dir, "react.js"), ...map ? [join(dir, `geo-${map}.js`)] : [], join(dir, `${type}.js`)];
406
+ if (files.every((f) => existsSync(f))) return files.map((f) => readFileSync(f, "utf8")).join("\n");
396
407
  }
397
408
  return null;
398
409
  }
@@ -455,8 +466,8 @@ async function render(input, opts = {}) {
455
466
  }
456
467
  const format = opts.format ?? "svg";
457
468
  if (format === "html") {
458
- const type = opts.interactive ? resolveDef(spec.type, spec.encoding)?.type : void 0;
459
- const script = type ? clientScript(type) : null;
469
+ const type = opts.interactive ? resolveDef(spec.type, spec.encoding, spec.options)?.type : void 0;
470
+ const script = type ? clientScript(type, specMapName(spec)) : null;
460
471
  const html = renderSpecToHTML(spec, { width: opts.width, height: opts.height, theme: opts.theme, frame: opts.frame, interactive: script ? { script } : false, locale });
461
472
  return { format, html };
462
473
  }
@@ -471,9 +482,19 @@ async function svgToPng(svg, opts = {}) {
471
482
  const { Resvg } = await import("@resvg/resvg-js");
472
483
  const fontFiles = findFonts(opts.fonts);
473
484
  const plain = stripEmoji(svg);
474
- const r = new Resvg(plain.svg, { fitTo: { mode: "zoom", value: opts.scale ?? 2 }, font: { fontFiles, loadSystemFonts: true, defaultFontFamily: fontFiles.length ? "Pretendard" : "sans-serif" } });
485
+ const zoom = pngZoom(svg, opts.scale ?? 2);
486
+ if (zoom === null) throw new Error(CLI_TEXT[langOf(opts.locale)].pngNoSize);
487
+ const r = new Resvg(plain.svg, { fitTo: { mode: "zoom", value: zoom }, font: { fontFiles, loadSystemFonts: true, defaultFontFamily: fontFiles.length ? "Pretendard" : "sans-serif" } });
475
488
  return { png: Buffer.from(r.render().asPng()), ...plain.removed ? { notes: [CLI_TEXT[langOf(opts.locale)].emojiRemoved(plain.removed)] } : {} };
476
489
  }
490
+ var PNG_MAX_PIXELS = 5e7;
491
+ function pngZoom(svg, scale) {
492
+ const tag = /<svg\b[^>]*>/.exec(svg)?.[0] ?? "";
493
+ const w = Number(/\swidth="([\d.]+)"/.exec(tag)?.[1]);
494
+ const h = Number(/\sheight="([\d.]+)"/.exec(tag)?.[1]);
495
+ if (!(w > 0 && h > 0 && Number.isFinite(w) && Number.isFinite(h))) return null;
496
+ return Math.min(scale, Math.sqrt(PNG_MAX_PIXELS / (w * h)));
497
+ }
477
498
  function isHttpUrl(source) {
478
499
  return /^https?:\/\//i.test(source);
479
500
  }
@@ -510,6 +531,8 @@ export {
510
531
  fetchUrl,
511
532
  render,
512
533
  svgToPng,
534
+ PNG_MAX_PIXELS,
535
+ pngZoom,
513
536
  isHttpUrl,
514
537
  loadRows,
515
538
  suggest
package/dist/cli.js CHANGED
@@ -13,13 +13,13 @@ import {
13
13
  resolveType,
14
14
  suggest,
15
15
  validate
16
- } from "./chunk-4WXNLD5P.js";
16
+ } from "./chunk-FB5WHEJX.js";
17
17
 
18
18
  // src/cli.ts
19
19
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
20
20
  import { basename, dirname, extname, join, resolve } from "path";
21
21
  import { parseArgs } from "util";
22
- import { COMMON_OPTIONS, findGroup, findLevel, formatIssues, GROUPS, LEVELS, localizeDef, variantSpec, variantsIn } from "ztd-charts/spec";
22
+ import { capChartSize, COMMON_OPTIONS, findGroup, findLevel, formatIssues, GROUPS, LEVELS, localizeDef, variantSpec, variantsIn } from "ztd-charts/spec";
23
23
  import { langOf } from "ztd-charts/server";
24
24
  var t = CLI_TEXT.en;
25
25
  function fail(msg, code = 1) {
@@ -189,8 +189,9 @@ ${info.react}`);
189
189
  const scale = numberFlag(f, "scale");
190
190
  const res = await render(spec, {
191
191
  format,
192
- width: numberFlag(f, "width"),
193
- height: numberFlag(f, "height"),
192
+ // 한 변은 MAX_CHART_SIZE(10,000px)까지. 넘으면 줄여서 그려요
193
+ width: capChartSize(numberFlag(f, "width")),
194
+ height: capChartSize(numberFlag(f, "height")),
194
195
  theme,
195
196
  scale,
196
197
  frame: f["no-frame"] ? false : f.frame ? true : void 0,
@@ -0,0 +1,39 @@
1
+ # Third-party data in ztd-charts
2
+
3
+ The library code is MIT (see LICENSE). The built-in map boundaries under `src/geo/maps/` (shipped as the entry points `ztd-charts/geo/world`, `ztd-charts/geo/us-states` and `ztd-charts/geo/kr-sido`) are derived from the public data below. `scripts/build-geo.mjs` rebuilds them from pinned source files whose SHA-256 sums are in `scripts/geo-sources.json`.
4
+
5
+ ## Borders
6
+
7
+ World borders follow Natural Earth, which shows de facto boundaries: the line of actual control, not any one country's claim. Disputed areas are drawn as Natural Earth draws them at 1:110m. If you need different borders, pass your own GeoJSON FeatureCollection as `options.map` (or the `map` prop); it replaces the built-in map entirely.
8
+
9
+ ## world (`ztd-charts/geo/world`)
10
+
11
+ - Source: Natural Earth 1:110m Cultural Vectors, Admin 0 Countries, as packaged in world-atlas 2.0.2 (`countries-110m.json`), https://github.com/topojson/world-atlas
12
+ - Natural Earth data is in the public domain: https://www.naturalearthdata.com/about/terms-of-use/
13
+ - world-atlas is distributed under the ISC licence:
14
+
15
+ > Copyright 2013-2019 Michael Bostock
16
+ >
17
+ > Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
18
+ >
19
+ > THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20
+
21
+ - Changes: coordinates requantised to 0.01°, re-encoded. Country codes (ISO 3166-1 alpha-2, alpha-3, numeric), English display names (CLDR, through `Intl.DisplayNames`, with a few edits) and the continent table (UN M49 regions) were added by ztd-charts.
22
+
23
+ ## us-states (`ztd-charts/geo/us-states`)
24
+
25
+ - Source: US Census Bureau cartographic boundary files (state level, 1:10m), as packaged in us-atlas 3.0.1 (`states-10m.json`), https://github.com/topojson/us-atlas
26
+ - US Census Bureau data is a work of the US federal government and in the public domain.
27
+ - us-atlas is distributed under the ISC licence, with the same text as world-atlas above (Copyright 2013-2019 Michael Bostock).
28
+ - Changes: territories left out (50 states and DC kept), lines simplified (Douglas-Peucker, 0.03°), coordinates requantised to 0.01°, re-encoded.
29
+
30
+ ## kr-sido (`ztd-charts/geo/kr-sido`)
31
+
32
+ - Source: geoBoundaries gbOpen KOR ADM1 (release 9469f09, built from Natural Earth), https://www.geoboundaries.org/
33
+ - Licence stated by geoBoundaries for this boundary: public domain (Natural Earth terms of use).
34
+ - Changes: Gwangju (KR-29) and Jeollanam-do (KR-46) merged into one region, Jeonnam-Gwangju (전남광주통합특별시), which they became on 2026-07-01; lines simplified (Douglas-Peucker, 0.004°), coordinates requantised to 0.001°, re-encoded. Ulleungdo comes from the source and is kept.
35
+ - Dokdo: geoBoundaries KOR ADM1 has no polygon for it, so it is added to Gyeongsangbuk-do (it belongs to Ulleung-gun) from Natural Earth 1:10m Physical Vectors, Minor Islands (`ne_10m_minor_islands.geojson`, natural-earth-vector v5.1.2, public domain): the island whose centre is at about 131.86° E, 37.24° N. It is kept unsimplified. At most sizes it is drawn as a small speck, since the map draws any island smaller than 1px as a 1.6px square.
36
+
37
+ ## Tile layouts
38
+
39
+ The tile grid layouts (`us-states`, `kr-sido`, `kr-sido-2025` in `src/data/`) were arranged by ztd-charts for this library and are covered by its MIT licence.