plotagents 0.5.0 → 0.7.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.
- package/AGENTS.md +24 -4
- package/README.md +26 -14
- package/bin/plotagents.js +38 -14
- package/dist/plotagents-geo.js +1 -1
- package/dist/plotagents.js +4294 -637
- package/docs/api.md +23 -5
- package/docs/charts.md +143 -9
- package/docs/colorscales.md +46 -0
- package/docs/dashboards.md +79 -0
- package/docs/getting-started.md +6 -2
- package/docs/themes.md +39 -9
- package/index.d.ts +188 -17
- package/package.json +9 -3
- package/schema.json +1025 -46
- package/src/axes.js +11 -3
- package/src/charts/bar.js +28 -17
- package/src/charts/categorical.js +31 -7
- package/src/charts/chord.js +3 -3
- package/src/charts/choropleth.js +284 -36
- package/src/charts/dist.js +37 -20
- package/src/charts/donut.js +1 -1
- package/src/charts/gantt.js +460 -0
- package/src/charts/heatmap.js +2 -2
- package/src/charts/kpi.js +9 -6
- package/src/charts/line.js +173 -41
- package/src/charts/network.js +552 -189
- package/src/charts/pointmap.js +599 -0
- package/src/charts/radar.js +7 -1
- package/src/charts/regplot.js +7 -1
- package/src/charts/sankey.js +41 -5
- package/src/charts/scatter.js +100 -22
- package/src/charts/sunburst.js +5 -4
- package/src/charts/treemap.js +10 -7
- package/src/charts/wordcloud.js +163 -0
- package/src/colorscales.js +182 -0
- package/src/dashboard.js +438 -0
- package/src/dashed.js +1 -1
- package/src/data.js +2 -2
- package/src/format.js +46 -14
- package/src/frame.js +95 -26
- package/src/geo/projection.js +74 -9
- package/src/geo/registry.js +87 -8
- package/src/index.js +76 -11
- package/src/infer.js +10 -1
- package/src/interact.js +157 -36
- package/src/lint.js +289 -9
- package/src/runtime.js +209 -97
- package/src/scale.js +80 -10
- package/src/schema.js +187 -31
- package/src/stats.js +71 -14
- package/src/theme.js +101 -14
package/AGENTS.md
CHANGED
|
@@ -24,6 +24,7 @@ const svg = plot({ type, data, x, y, series, title, subtitle, source });
|
|
|
24
24
|
| Count rows per category | `countplot` | `x` |
|
|
25
25
|
| Mean per category with a CI | `barplot` or `point` | `x`, `y`, `hue?` |
|
|
26
26
|
| Change over time | `line` | `x` date (`"2024-03"`) or year, `y`, `series?`; `ci: true` with several observations per x |
|
|
27
|
+
| A project plan or schedule | `gantt` | `task`, `start`, `end` (or `duration`), `group?`, `progress?`, `dependsOn?`, `today?`, `collapsed?` |
|
|
27
28
|
| Volume over time | `area` | like `line`; stacks with `series` |
|
|
28
29
|
| Measures on different scales | `line` + `index: true`, or `facet` | **there is no dual axis** |
|
|
29
30
|
| Exponential growth | `line` + `yScale: "log"` | |
|
|
@@ -35,28 +36,37 @@ const svg = plot({ type, data, x, y, series, title, subtitle, source });
|
|
|
35
36
|
| Hierarchical part-to-whole | `treemap` or `sunburst` | `path: [level1, level2, …]`, `value` |
|
|
36
37
|
| Part-to-whole, ≤ 6 parts | `donut` / `pie` | `label`, `value`; `half: true` for a semicircle |
|
|
37
38
|
| Magnitude on a grid | `heatmap` | `x`, `y`, `value` |
|
|
38
|
-
| A value per region, state or country | `choropleth` (`symbolmap` for totals) | `geo: "chile" \| "usa" \| "world"
|
|
39
|
-
|
|
|
39
|
+
| A value per region, state or country | `choropleth` (`symbolmap` for totals) | `geo: "chile" \| "usa" \| "world"` or any GeoJSON/TopoJSON object, `key`, `value` (text → one color per category) |
|
|
40
|
+
| Dots at real places on a street map | `pointmap` | `lon`, `lat` (auto-detected), `size?`, `hue?`, `value?`, `label?`; `tiles: "osm"` (default) / `"esri-gray"` / `"esri-dark"`, or carto-* / mapbox-* with `tilesKey` |
|
|
41
|
+
| Who is connected to whom | `network` | edges `from`, `to`, `value?`; `nodes?` with `group`; `layout?` |
|
|
40
42
|
| Exchanges between a few groups | `chord` | `from`, `to`, `value` |
|
|
41
43
|
| Age structure | `pyramid` | `age`, `sex`, `value` |
|
|
42
44
|
| A process with decisions | `flowchart` | `nodes` (`type`, `lane`), `edges` (`label`) |
|
|
43
45
|
| Flows between stages | `sankey` | `from`, `to`, `value` |
|
|
44
46
|
| One or more numbers | `kpi` | `items: [{ label, value, delta, period, trend, target, good }]` |
|
|
47
|
+
| What comes up most in text | `wordcloud` | `text` (field or raw text), `value?`, `series?`; prefer `bar` + `top` to compare exactly |
|
|
45
48
|
|
|
46
49
|
seaborn names work (`histplot`, `kdeplot`, `boxplot`, `violinplot`, `lmplot`, `stripplot`, `swarmplot`, `pointplot`), and `hue` is an alias of `series`. Leave `type` out to infer it from the data.
|
|
47
50
|
|
|
48
51
|
## Most useful options
|
|
49
52
|
|
|
50
|
-
- `highlight: "Ñuble"`: emphasize one category or series and mute the rest.
|
|
53
|
+
- `highlight: "Ñuble"`: emphasize one category or series and mute the rest. `exclude: ["Maule"]` drops entries and recomputes the chart; colors stay put.
|
|
54
|
+
- `legend: "top" | "bottom" | "left" | "right" | false`: where the legend goes (top by default).
|
|
55
|
+
- `colorScale: "viridis"`: any matplotlib colormap for heatmaps, maps and treemaps by change (`"RdBu"` diverges around 0; `_r` reverses; or a list of colors). `palette: "tab10"` for categories.
|
|
51
56
|
- `dashed` for what is not a firm number (estimates, projections, provisional figures): a name, a list, or a data field (`dashed: "provisional"`). Shapes keep their color, with a hatched fill and a dashed outline. On a time axis, `dashedFrom: 2025` dashes lines, areas and columns from that year on. **Always set `dashedLabel`** ("Projection", "Preliminary") so readers know what the hatching means.
|
|
52
57
|
- `facet: "region"` (+ `columns`): one panel per value, on a shared scale.
|
|
53
|
-
- `time: "year"`: one period at a time (the latest) with % change vs the previous one
|
|
58
|
+
- `time: "year"`: one period at a time (the latest) with % change vs the previous one. Time controls are **off by default**: add `slider: true` only when the person asks to move through periods (buttons for ≤ 8 periods, a minimal slider otherwise; `"buttons"` / `"slider"` force one, `play: false` hides play). Treemaps can be colored by change with `colorBy: "change"`.
|
|
54
59
|
- `refLines: [{ y: 600, label: "Target" }]` and `annotations: [{ x: "2024-01", label: "New branch" }]`.
|
|
55
60
|
- `format: "percent" | "currency" | "compact" | "integer"` or `{ prefix, suffix, decimals }`.
|
|
56
61
|
- `xScale` / `yScale: "log"`.
|
|
57
62
|
- `theme: "noche"` or a JSON object (`{ extends, categorical, type, marks, font }`); `palette: [...]` for your own colors.
|
|
58
63
|
- `font: "Poppins"` and `textScale: 1.5` (presentation mode); `configure({ font, textScale })` sets them for every chart.
|
|
59
64
|
- `network` + `focus: "node id"`: center a node and highlight its neighbors.
|
|
65
|
+
- Your own map: `geo: <GeoJSON or TopoJSON>`; the matching property is found for you (`featureKey` to force it). Add `markers: [{ lon, lat, label }]`, `layers: [{ geo, label }]` for rivers or routes, and `fitTo: ["Biobío"]` or a `[lonMin, latMin, lonMax, latMax]` box to zoom.
|
|
66
|
+
- `gantt`: day `end` dates are inclusive; a row without `end` is a milestone. Always set `today` on a live plan. `collapsed: ["Phase 2"]` (or `true`) folds phases into one summary bar; in the browser a click on a phase toggles it.
|
|
67
|
+
- `network` + `layout: "force" | "circular" | "radial" | "concentric" | "clusters" | "tree" | "grid"` picks the placement; `curveness: 0` straightens edges.
|
|
68
|
+
- `pointmap` draws on OpenStreetMap tiles by default (`tiles: "esri-gray"`, `"mapbox-light"` + `tilesKey`, or your own `{ url, attribution }`). Tiles load only when the SVG is inline or in `toHTML`, not inside `<img>`.
|
|
69
|
+
- Your own look for every chart: `registerTheme("acme", { background, text, grid: { color, dash }, categorical: "tab10", font })` then `configure({ theme: "acme" })`.
|
|
60
70
|
- `geo: "usa"`: states match by postal code ("TX"), English or Spanish name, or FIPS ("48"). Alaska and Hawaii are insets; Puerto Rico appears only when your data has it. In the browser, maps zoom on click, Ctrl/⌘ + scroll or pinch.
|
|
61
71
|
|
|
62
72
|
## Mistakes the library already handles
|
|
@@ -69,6 +79,16 @@ seaborn names work (`histplot`, `kdeplot`, `boxplot`, `violinplot`, `lmplot`, `s
|
|
|
69
79
|
- Numbers as text ("1.234,5", "12%", "$ 3.000") → parsed automatically.
|
|
70
80
|
- Tens of thousands of points → drawn as batched paths, still fast.
|
|
71
81
|
|
|
82
|
+
## Dashboards
|
|
83
|
+
|
|
84
|
+
When someone asks for a dashboard, call `safeDashboard({ title, subtitle, source, data, kpis, charts, filters })` (tool: `toolDefinition({ kind: 'dashboard' })`). Layout, widths, shared colors and filters are decided for you:
|
|
85
|
+
|
|
86
|
+
- `title` is the **question** the dashboard answers; every chart still gets its finding as title.
|
|
87
|
+
- At most **5 KPIs**, computed from `data` when possible: `{ label, field, agg: "sum", compare: { field: "year", current: 2025, previous: 2024 }, trendBy: "month" }`.
|
|
88
|
+
- **4–6 charts**. The first time series (or the one with `primary: true`) goes full width; the rest fill balanced rows.
|
|
89
|
+
- `filters: ["region", "channel"]` become buttons that filter every chart and KPI.
|
|
90
|
+
- No more than one donut; one `source` for the page.
|
|
91
|
+
|
|
72
92
|
## Outputs
|
|
73
93
|
|
|
74
94
|
- `plot(spec)` → SVG string. Drop it into HTML, Markdown, an `.svg` file or a PDF.
|
package/README.md
CHANGED
|
@@ -4,14 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
**[Documentation, live examples and playground →](https://carlosnavarrete.cl/plotagents/)**
|
|
6
6
|
|
|
7
|
-
Data and field names go in; an accessible SVG comes out, with careful typography, colorblind-safe colors and tooltips.
|
|
7
|
+
Data and field names go in; an accessible SVG comes out, with careful typography, colorblind-safe colors and tooltips. 34 chart types: the ones people reach for in seaborn, multi-level treemaps and sunbursts, choropleth maps of Chile, the United States and the world, networks, chord diagrams, population pyramids, flow charts and Gantt charts, plus word clouds, a dashboard builder with best-practice layouts, opt-in time controls, small multiples and fully JSON-configurable themes. Zero dependencies. Runs in Node, Deno, Bun and the browser.
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install
|
|
10
|
+
npm install plotagents
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
plotagents is not on the npm registry yet, so install it from GitHub for now; `npm install plotagents` will work once it is published.
|
|
14
|
-
|
|
15
13
|
```js
|
|
16
14
|
import { plot } from 'plotagents';
|
|
17
15
|
|
|
@@ -42,11 +40,12 @@ Agents are good at data and bad at charts: dual axes, 12-slice pies, titles that
|
|
|
42
40
|
- **One axis.** There is no dual axis; `index: true` rebases series to 100 and `facet` draws panels on a shared scale.
|
|
43
41
|
- **Labels at the end of every line**, always. When they collide they are spread apart and joined to their point by a thin leader line; a legend appears only when needed.
|
|
44
42
|
- **Every pixel for the data.** The y axis sits inside the plot on its gridline; margins and type scale down on phones; treemaps, sunbursts, horizontal bars, heatmaps and KPI tiles size their own height.
|
|
45
|
-
- **Color follows the entity.** Eight validated colors in a fixed order; "Copper" keeps its color when you filter, drill down or move
|
|
46
|
-
- **Legend and chart are connected.** Hover a legend key to light up its marks, click to pin
|
|
43
|
+
- **Color follows the entity.** Eight validated colors in a fixed order; "Copper" keeps its color when you filter, drill down or move through periods. One solid color per category.
|
|
44
|
+
- **Legend and chart are connected.** Hover a legend key to light up its marks, click to pin, shift + click to drop that entry (axes and shares recompute, colors stay put). In treemaps a click zooms the whole plot to the category. The legend goes top by default, or `legend: "bottom" | "left" | "right"`.
|
|
45
|
+
- **Tooltips that never cover the title.** They sit next to the hovered mark, stay inside the chart, and their header wears the mark's color with white or dark text picked by contrast. Arrow keys walk through the data.
|
|
47
46
|
- **Estimates look like estimates.** `dashed` hatches the shapes that are projections or provisional figures (same color, striped fill, dashed outline) and `dashedFrom: 2025` turns lines, areas and columns dashed from that point on, over a soft labeled band. The legend says what the hatching means; hovering it lights up just those shapes.
|
|
48
|
-
- **Maps you can explore.** Click a state or region to zoom to it, Ctrl/⌘ + scroll or pinch to zoom, drag to pan; +/−/reset buttons for the keyboard. Hovering outlines the shape instead of dimming the map, and each color class in the legend lights up its regions.
|
|
49
|
-
- **Networks you can explore.** Click a node and it glides to the center with its connections highlighted; click again or press Esc to go back.
|
|
47
|
+
- **Maps you can explore.** Click a state or region to zoom to it, Ctrl/⌘ + scroll or pinch to zoom, drag to pan; +/−/reset buttons for the keyboard. Hovering outlines the shape instead of dimming the map, and each color class in the legend lights up its regions. Moving through years, colors glide from one to the next.
|
|
48
|
+
- **Networks you can explore.** Curved edges in the source node's color, sized nodes and labels that never pile up. Pick the placement with `layout` (force, circular, radial, concentric, clusters, tree, grid). Click a node and it glides to the center with its connections highlighted; click again or press Esc to go back.
|
|
50
49
|
- **Thin marks, quiet grid.** 4 px rounded data ends, 2.25 px lines, 2 px surface gaps instead of borders.
|
|
51
50
|
- **Locale-aware numbers.** Spanish (Chile) by default: `1.234,5`, `56,1%`, `$18.500`. `locale: 'en'` gives `1,234.5`.
|
|
52
51
|
|
|
@@ -60,11 +59,14 @@ Agents are good at data and bad at charts: dual axes, 12-slice pies, titles that
|
|
|
60
59
|
| Profiles | `radar` (`spider`) |
|
|
61
60
|
| Distributions | `hist` (`histplot`), `kde` (`kdeplot`), `ecdf`, `box` (`boxplot`), `violin`, `strip`, `swarm` (`beeswarm`), `point` (`pointplot`) |
|
|
62
61
|
| Part-to-whole | `treemap` (any depth, with % change over time), `sunburst`, `donut`, `pie` |
|
|
63
|
-
| Maps | `choropleth` (Chile by region, US by state, world by country,
|
|
62
|
+
| Maps | `choropleth` (Chile by region, US by state, world by country, or your own GeoJSON / TopoJSON with markers, layers and framing), `symbolmap`, `pointmap` (lat/lon dots over OpenStreetMap or Mapbox tiles) |
|
|
63
|
+
| Projects | `gantt` (`timeline`, `roadmap`): phases that fold and unfold, progress, milestones, dependencies and a today line |
|
|
64
64
|
| Networks and flows | `network`, `chord`, `sankey`, `flowchart` (with swimlanes) |
|
|
65
65
|
| Populations | `pyramid` |
|
|
66
66
|
| Grids | `heatmap` |
|
|
67
67
|
| Numbers | `kpi` |
|
|
68
|
+
| Text | `wordcloud` (words sized by frequency, or raw text to count) |
|
|
69
|
+
| Dashboards | `dashboard({ title, kpis, charts, filters })`: a whole HTML dashboard with best-practice layout ([guide](docs/dashboards.md)) |
|
|
68
70
|
|
|
69
71
|
Leave `type` out and it is inferred: dates → `line`, two measures → `scatter`, `source`/`target` → `sankey`, `path` → `treemap`, categories → `bar`. Every option is documented in [`docs/charts.md`](docs/charts.md).
|
|
70
72
|
|
|
@@ -78,11 +80,12 @@ Leave `type` out and it is inferred: dates → `line`, two measures → `scatter
|
|
|
78
80
|
## Time, panels and drill-down
|
|
79
81
|
|
|
80
82
|
```js
|
|
81
|
-
// One period at a time
|
|
82
|
-
|
|
83
|
+
// One period at a time (the latest). Controls are opt-in: `slider: true` adds
|
|
84
|
+
// period buttons (few periods) or a minimal slider (many), with a play button.
|
|
85
|
+
plot({ type: 'treemap', data, path: ['sector', 'product'], value: 'value', time: 'year', slider: true });
|
|
83
86
|
|
|
84
|
-
// Time series:
|
|
85
|
-
render('#chart', { type: 'line', data, x: 'month', y: 'sales', series: 'region' });
|
|
87
|
+
// Time series: `slider: true` adds a two-handle range in the browser.
|
|
88
|
+
render('#chart', { type: 'line', data, x: 'month', y: 'sales', series: 'region', slider: true });
|
|
86
89
|
|
|
87
90
|
// Small multiples (seaborn's col / col_wrap) with shared scales and colors.
|
|
88
91
|
plot({ type: 'area', data, x: 'month', y: 'sales', facet: 'region', columns: 3 });
|
|
@@ -125,6 +128,15 @@ plot({
|
|
|
125
128
|
});
|
|
126
129
|
```
|
|
127
130
|
|
|
131
|
+
Register it once and every chart uses it; the default look never changes unless you ask:
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
registerTheme('acme', { background: '#FFF', text: '#111827', grid: { color: '#EEF0F4', dash: '2 3' }, categorical: 'tab10', font: 'Inter' });
|
|
135
|
+
configure({ theme: 'acme' });
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Every matplotlib colormap works by name for heatmaps, maps and treemaps by change: `colorScale: 'viridis'`, `'RdBu_r'`, or your own list of colors ([color scales](docs/colorscales.md)).
|
|
139
|
+
|
|
128
140
|
`validatePalette(colors)` checks a custom palette with the same tests the built-in one passed (lightness band, chroma floor, colorblind separation, normal-vision separation), and `lint` runs it for you.
|
|
129
141
|
|
|
130
142
|
## SVG, not Canvas
|
|
@@ -149,7 +161,7 @@ import { plot, safePlot, lint, describe, render, toHTML, schema, toolDefinition,
|
|
|
149
161
|
| `safePlot(spec)` | `{ ok, svg, description, errors, warnings, suggestions }`. Never throws. |
|
|
150
162
|
| `lint(spec)` | Review of the spec without drawing: errors and design suggestions. |
|
|
151
163
|
| `describe(spec)` | Alt text ("Highest: Biobío with 1,240 (30%)…"). |
|
|
152
|
-
| `render(el, spec)` | Browser: tooltips, responsive width, time
|
|
164
|
+
| `render(el, spec)` | Browser: tooltips, responsive width, drill-down, and time controls when the spec asks for them. |
|
|
153
165
|
| `toHTML(specs)` | A self-contained, interactive HTML page in one file. |
|
|
154
166
|
| `schema` / `toolDefinition({ flavor })` | JSON Schema of the spec and a tool definition for Claude (`anthropic`) or OpenAI (`openai`). |
|
|
155
167
|
| `validatePalette(colors, opts)` | `{ ok, checks }`. |
|
package/bin/plotagents.js
CHANGED
|
@@ -1,48 +1,72 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// CLI: plotagents spec.json [-o salida.svg|.html] [--lint] [--schema] [--tool]
|
|
2
|
+
// CLI: plotagents spec.json [-o salida.svg|.html] [--lint] [--schema] [--tool [openai] [dashboard]]
|
|
3
3
|
// cat spec.json | plotagents > grafico.svg
|
|
4
|
+
// A spec with a `charts` list is a dashboard: it renders to a self-contained HTML page.
|
|
4
5
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
5
|
-
import { plot, toHTML, lint, schema, toolDefinition, describe } from '../src/index.js';
|
|
6
|
+
import { plot, toHTML, lint, schema, toolDefinition, describe, dashboard, lintDashboard, dashboardSchema } from '../src/index.js';
|
|
7
|
+
|
|
8
|
+
// `plotagents … | head` closes the pipe early: exit quietly instead of crashing.
|
|
9
|
+
for (const stream of [process.stdout, process.stderr]) {
|
|
10
|
+
stream.on('error', (e) => { if (e && e.code === 'EPIPE') process.exit(0); throw e; });
|
|
11
|
+
}
|
|
6
12
|
|
|
7
13
|
const args = process.argv.slice(2);
|
|
8
14
|
const flag = (f) => args.includes(f);
|
|
9
15
|
const opt = (f) => { const i = args.indexOf(f); return i >= 0 ? args[i + 1] : undefined; };
|
|
10
|
-
const
|
|
16
|
+
const VALUE_FLAGS = new Set(['-o', '--out', '--tool']);
|
|
17
|
+
const TOOL_ARGS = new Set(['openai', 'anthropic', 'dashboard', 'chart']);
|
|
18
|
+
const input = args.find((a, i) => !a.startsWith('-') && !VALUE_FLAGS.has(args[i - 1]) && !(TOOL_ARGS.has(a) && args.slice(0, i).includes('--tool')));
|
|
19
|
+
const print = (s) => process.stdout.write(s.endsWith('\n') ? s : s + '\n');
|
|
11
20
|
|
|
12
21
|
if (flag('-h') || flag('--help')) {
|
|
13
|
-
|
|
22
|
+
print(`plotagents — gráficos bellos desde un spec JSON
|
|
14
23
|
|
|
15
24
|
Uso:
|
|
16
25
|
plotagents spec.json SVG a la salida estándar
|
|
17
26
|
plotagents spec.json -o grafico.svg guarda SVG
|
|
18
27
|
plotagents spec.json -o reporte.html página HTML interactiva (acepta un arreglo de specs)
|
|
28
|
+
plotagents tablero.json -o tablero.html dashboard (un spec con \`charts: [...]\`)
|
|
19
29
|
plotagents spec.json --lint revisa el spec y sugiere mejoras (JSON)
|
|
20
30
|
plotagents spec.json --describe descripción en texto del gráfico
|
|
21
|
-
plotagents --schema
|
|
22
|
-
plotagents --tool [openai]
|
|
31
|
+
plotagents --schema [dashboard] JSON Schema del spec (o del dashboard)
|
|
32
|
+
plotagents --tool [openai] [dashboard] definición de herramienta para agentes
|
|
23
33
|
cat spec.json | plotagents también lee de stdin`);
|
|
24
34
|
process.exit(0);
|
|
25
35
|
}
|
|
26
|
-
|
|
27
|
-
|
|
36
|
+
// Tool and schema flags accept "openai" and/or "dashboard" in any order after the flag.
|
|
37
|
+
const after = (f) => { const i = args.indexOf(f); return i >= 0 ? args.slice(i + 1).filter((a) => TOOL_ARGS.has(a)) : []; };
|
|
38
|
+
if (flag('--schema')) { print(JSON.stringify(after('--schema').includes('dashboard') ? dashboardSchema : schema, null, 2)); process.exit(0); }
|
|
39
|
+
if (flag('--tool')) {
|
|
40
|
+
const t = after('--tool');
|
|
41
|
+
print(JSON.stringify(toolDefinition({ flavor: t.includes('openai') ? 'openai' : 'anthropic', kind: t.includes('dashboard') ? 'dashboard' : 'chart' }), null, 2));
|
|
42
|
+
process.exit(0);
|
|
43
|
+
}
|
|
28
44
|
|
|
29
45
|
let raw;
|
|
30
46
|
try { raw = input ? readFileSync(input, 'utf8') : readFileSync(0, 'utf8'); } catch (e) { console.error('No pude leer el spec:', e.message); process.exit(2); }
|
|
31
47
|
let spec;
|
|
32
48
|
try { spec = JSON.parse(raw); } catch (e) { console.error('El spec no es JSON válido:', e.message); process.exit(2); }
|
|
33
49
|
|
|
50
|
+
const isDashboard = (s) => !!s && typeof s === 'object' && !Array.isArray(s) && Array.isArray(s.charts);
|
|
51
|
+
|
|
34
52
|
if (flag('--lint')) {
|
|
35
53
|
const list = Array.isArray(spec) ? spec : [spec];
|
|
36
|
-
const out = list.map(lint);
|
|
37
|
-
|
|
54
|
+
const out = list.map((s) => (isDashboard(s) ? lintDashboard(s) : lint(s)));
|
|
55
|
+
print(JSON.stringify(Array.isArray(spec) ? out : out[0], null, 2));
|
|
38
56
|
process.exit(out.every((r) => r.ok) ? 0 : 1);
|
|
39
57
|
}
|
|
40
58
|
try {
|
|
41
|
-
if (flag('--describe')) { console.log((Array.isArray(spec) ? spec : [spec]).map(describe).join('\n')); process.exit(0); }
|
|
42
59
|
const outFile = opt('-o') ?? opt('--out');
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
60
|
+
if (isDashboard(spec)) {
|
|
61
|
+
if (flag('--describe')) { print([spec.title, ...spec.charts.map((c) => { try { return describe({ data: spec.data, ...c }); } catch (e) { return e.message.split('\n')[0]; } })].filter(Boolean).join('\n')); process.exit(0); }
|
|
62
|
+
const html = dashboard(spec);
|
|
63
|
+
if (outFile) { writeFileSync(outFile, html); console.error(`✓ ${outFile}`); } else process.stdout.write(html);
|
|
64
|
+
} else {
|
|
65
|
+
if (flag('--describe')) { print((Array.isArray(spec) ? spec : [spec]).map(describe).join('\n')); process.exit(0); }
|
|
66
|
+
const html = (outFile && outFile.endsWith('.html')) || flag('--html') || Array.isArray(spec);
|
|
67
|
+
const result = html ? toHTML(spec, { title: (Array.isArray(spec) ? spec[0] : spec).title || 'plotagents' }) : plot(spec);
|
|
68
|
+
if (outFile) { writeFileSync(outFile, result); console.error(`✓ ${outFile}`); } else process.stdout.write(result);
|
|
69
|
+
}
|
|
46
70
|
} catch (e) {
|
|
47
71
|
console.error(e.message);
|
|
48
72
|
process.exit(1);
|
package/dist/plotagents-geo.js
CHANGED