plotagents 0.0.0-stage → 0.5.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 +78 -0
- package/LICENSE +21 -0
- package/README.md +205 -2
- package/bin/plotagents.js +49 -0
- package/dist/plotagents-geo.js +79 -0
- package/dist/plotagents.js +7954 -0
- package/docs/api.md +154 -0
- package/docs/charts.md +218 -0
- package/docs/getting-started.md +138 -0
- package/docs/rendering.md +47 -0
- package/docs/themes.md +86 -0
- package/index.d.ts +213 -0
- package/package.json +74 -4
- package/schema.json +895 -0
- package/src/axes.js +144 -0
- package/src/charts/bar.js +339 -0
- package/src/charts/categorical.js +471 -0
- package/src/charts/chord.js +218 -0
- package/src/charts/choropleth.js +559 -0
- package/src/charts/dist.js +513 -0
- package/src/charts/donut.js +232 -0
- package/src/charts/flowchart.js +407 -0
- package/src/charts/heatmap.js +76 -0
- package/src/charts/kpi.js +97 -0
- package/src/charts/line.js +419 -0
- package/src/charts/network.js +344 -0
- package/src/charts/pyramid.js +177 -0
- package/src/charts/radar.js +152 -0
- package/src/charts/regplot.js +364 -0
- package/src/charts/sankey.js +133 -0
- package/src/charts/scatter.js +136 -0
- package/src/charts/sunburst.js +135 -0
- package/src/charts/treemap.js +194 -0
- package/src/context.js +10 -0
- package/src/dashed.js +90 -0
- package/src/data.js +137 -0
- package/src/facet.js +84 -0
- package/src/format.js +171 -0
- package/src/frame.js +157 -0
- package/src/geo/chile.js +7 -0
- package/src/geo/data/chile-regiones.js +12 -0
- package/src/geo/data/usa-estados.js +12 -0
- package/src/geo/data/world.js +12 -0
- package/src/geo/projection.js +152 -0
- package/src/geo/registry.js +31 -0
- package/src/geo/usa.js +8 -0
- package/src/geo/world.js +7 -0
- package/src/hierarchy.js +139 -0
- package/src/index.js +271 -0
- package/src/infer.js +49 -0
- package/src/interact.js +362 -0
- package/src/lint.js +137 -0
- package/src/palette.js +59 -0
- package/src/runtime.js +304 -0
- package/src/scale.js +171 -0
- package/src/schema.js +181 -0
- package/src/stats.js +246 -0
- package/src/svg.js +85 -0
- package/src/text.js +61 -0
- package/src/theme.js +224 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// plotagents type declarations.
|
|
2
|
+
|
|
3
|
+
export type ChartType =
|
|
4
|
+
| 'auto' | 'bar' | 'column' | 'count' | 'line' | 'area' | 'scatter' | 'bubble'
|
|
5
|
+
| 'regplot' | 'residplot' | 'jointplot' | 'hist' | 'kde' | 'ecdf'
|
|
6
|
+
| 'box' | 'violin' | 'strip' | 'swarm' | 'point' | 'radar'
|
|
7
|
+
| 'treemap' | 'sunburst' | 'donut' | 'pie' | 'heatmap' | 'sankey' | 'kpi'
|
|
8
|
+
// Aliases (seaborn and others)
|
|
9
|
+
| 'barplot' | 'countplot' | 'lineplot' | 'scatterplot' | 'histplot' | 'kdeplot' | 'ecdfplot'
|
|
10
|
+
| 'lmplot' | 'boxplot' | 'violinplot' | 'stripplot' | 'swarmplot' | 'beeswarm' | 'pointplot' | 'spider';
|
|
11
|
+
|
|
12
|
+
export type Row = Record<string, string | number | Date | null | undefined>;
|
|
13
|
+
|
|
14
|
+
export type Format =
|
|
15
|
+
| 'number' | 'compact' | 'percent' | 'currency' | 'integer'
|
|
16
|
+
| { type?: string; prefix?: string; suffix?: string; decimals?: number; currency?: string; scale?: number };
|
|
17
|
+
|
|
18
|
+
export interface KpiItem {
|
|
19
|
+
label: string;
|
|
20
|
+
value: number;
|
|
21
|
+
/** Relative change as a fraction (0.12 = +12%). */
|
|
22
|
+
delta?: number;
|
|
23
|
+
previous?: number;
|
|
24
|
+
period?: string;
|
|
25
|
+
good?: 'up' | 'down';
|
|
26
|
+
trend?: number[];
|
|
27
|
+
target?: number;
|
|
28
|
+
format?: Format;
|
|
29
|
+
display?: string;
|
|
30
|
+
note?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface RefLine { y?: number; x?: number; value?: number; label?: string; color?: string }
|
|
34
|
+
export interface Annotation { x: string | number | Date; label?: string }
|
|
35
|
+
|
|
36
|
+
export interface Theme {
|
|
37
|
+
name: string;
|
|
38
|
+
mode: 'light' | 'dark';
|
|
39
|
+
surface: string; ink: string; lede: string; muted: string;
|
|
40
|
+
grid: string; axis: string; tint: string; tint2: string; dim: string; other: string;
|
|
41
|
+
link: number;
|
|
42
|
+
categorical: string[]; sequential: string[]; diverging: string[];
|
|
43
|
+
status: { good: string; warning: string; critical: string };
|
|
44
|
+
font: { family: string; mono: string; import: string };
|
|
45
|
+
type: { title: number; subtitle: number; label: number; axis: number; legend: number; source: number; titleWeight: number };
|
|
46
|
+
marks: { barRadius: number; barMax: number; barMaxH: number; lineWidth: number; pointRadius: number; gap: number; ring: number; areaOpacity: number; bandOpacity: number; dotOpacity: number };
|
|
47
|
+
axes: { inside: boolean; grid: boolean };
|
|
48
|
+
layout: { padding: number; paddingSmall: number };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type DeepPartial<T> = { [K in keyof T]?: T[K] extends object ? (T[K] extends any[] ? T[K] | string : DeepPartial<T[K]>) : T[K] };
|
|
52
|
+
/** JSON theme: deep-merged over `extends` (default "papel"). */
|
|
53
|
+
export type ThemeInput = 'papel' | 'noche' | 'light' | 'dark' | (DeepPartial<Theme> & { extends?: 'papel' | 'noche' })
|
|
54
|
+
|
|
55
|
+
export interface Spec {
|
|
56
|
+
type?: ChartType;
|
|
57
|
+
data?: Row[] | Record<string, number>;
|
|
58
|
+
title?: string;
|
|
59
|
+
subtitle?: string;
|
|
60
|
+
source?: string;
|
|
61
|
+
x?: string;
|
|
62
|
+
y?: string | string[];
|
|
63
|
+
series?: string;
|
|
64
|
+
color?: string;
|
|
65
|
+
value?: string;
|
|
66
|
+
label?: string;
|
|
67
|
+
group?: string;
|
|
68
|
+
path?: string[];
|
|
69
|
+
size?: string;
|
|
70
|
+
from?: string;
|
|
71
|
+
to?: string;
|
|
72
|
+
items?: KpiItem[];
|
|
73
|
+
format?: Format;
|
|
74
|
+
xFormat?: Format;
|
|
75
|
+
yFormat?: Format;
|
|
76
|
+
stack?: boolean | 'percent';
|
|
77
|
+
horizontal?: boolean;
|
|
78
|
+
sort?: 'desc' | 'asc' | 'none' | 'alpha';
|
|
79
|
+
top?: number;
|
|
80
|
+
highlight?: string | string[];
|
|
81
|
+
/** Dashed shapes (hatched fill + dashed outline): names, a data field, { field, equals } or true. */
|
|
82
|
+
dashed?: string | string[] | boolean | { field: string; equals?: unknown };
|
|
83
|
+
/** line/area/bar on a time axis: dashed from this x on (a projection). */
|
|
84
|
+
dashedFrom?: string | number;
|
|
85
|
+
/** Meaning of the dashed shapes: legend, band label and tooltip. */
|
|
86
|
+
dashedLabel?: string | false;
|
|
87
|
+
labels?: boolean | 'auto' | number | string[];
|
|
88
|
+
labelsFor?: Record<string, string>;
|
|
89
|
+
refLines?: RefLine[];
|
|
90
|
+
annotations?: Annotation[];
|
|
91
|
+
index?: boolean;
|
|
92
|
+
curve?: 'linear' | 'smooth';
|
|
93
|
+
zero?: boolean;
|
|
94
|
+
points?: boolean;
|
|
95
|
+
xScale?: 'linear' | 'log';
|
|
96
|
+
yScale?: 'linear' | 'log';
|
|
97
|
+
trend?: boolean;
|
|
98
|
+
xLabel?: string;
|
|
99
|
+
yLabel?: string;
|
|
100
|
+
aggregate?: 'sum' | 'mean' | 'max' | 'min' | 'count' | 'last' | 'first';
|
|
101
|
+
colors?: Record<string, string>;
|
|
102
|
+
theme?: ThemeInput;
|
|
103
|
+
palette?: string | string[];
|
|
104
|
+
ramp?: string | string[];
|
|
105
|
+
hue?: string;
|
|
106
|
+
facet?: string;
|
|
107
|
+
col?: string;
|
|
108
|
+
sharey?: boolean;
|
|
109
|
+
sharex?: boolean;
|
|
110
|
+
panelHeight?: number;
|
|
111
|
+
time?: string;
|
|
112
|
+
timeValue?: string | number;
|
|
113
|
+
slider?: boolean;
|
|
114
|
+
play?: boolean;
|
|
115
|
+
compare?: 'previous' | 'first' | string | number | false;
|
|
116
|
+
compareData?: Row[];
|
|
117
|
+
colorBy?: 'group' | 'change' | 'label';
|
|
118
|
+
shade?: boolean;
|
|
119
|
+
change?: boolean;
|
|
120
|
+
playInterval?: number;
|
|
121
|
+
xRange?: [string | number, string | number];
|
|
122
|
+
xDomain?: [number, number];
|
|
123
|
+
yDomain?: [number, number];
|
|
124
|
+
ci?: boolean | number;
|
|
125
|
+
errorbar?: 'ci' | 'sd' | 'se' | 'pi' | 'none' | false;
|
|
126
|
+
estimator?: 'mean' | 'median' | 'sum' | 'count';
|
|
127
|
+
focus?: string | string[];
|
|
128
|
+
font?: string | { family: string; import?: string };
|
|
129
|
+
textScale?: number;
|
|
130
|
+
fontScale?: number;
|
|
131
|
+
labelScale?: number;
|
|
132
|
+
depth?: number;
|
|
133
|
+
half?: boolean;
|
|
134
|
+
bins?: number;
|
|
135
|
+
binWidth?: number;
|
|
136
|
+
stat?: 'count' | 'percent' | 'density' | 'probability';
|
|
137
|
+
kde?: boolean;
|
|
138
|
+
multiple?: 'layer' | 'stack' | 'dodge' | 'fill';
|
|
139
|
+
fill?: boolean;
|
|
140
|
+
order?: number | string[];
|
|
141
|
+
lowess?: boolean;
|
|
142
|
+
logx?: boolean;
|
|
143
|
+
annotate?: boolean;
|
|
144
|
+
kind?: 'scatter' | 'reg';
|
|
145
|
+
marginal?: 'hist' | 'kde';
|
|
146
|
+
inner?: 'box' | 'quartiles' | 'points' | 'none';
|
|
147
|
+
split?: boolean;
|
|
148
|
+
axis?: string;
|
|
149
|
+
axes?: string[];
|
|
150
|
+
normalize?: boolean;
|
|
151
|
+
legend?: boolean;
|
|
152
|
+
locale?: 'es' | 'en';
|
|
153
|
+
width?: number;
|
|
154
|
+
height?: number;
|
|
155
|
+
padding?: number;
|
|
156
|
+
fontFamily?: string;
|
|
157
|
+
fontImport?: boolean;
|
|
158
|
+
background?: boolean;
|
|
159
|
+
maxSlices?: number;
|
|
160
|
+
centerValue?: string;
|
|
161
|
+
centerLabel?: string;
|
|
162
|
+
midpoint?: number;
|
|
163
|
+
diverging?: boolean;
|
|
164
|
+
/** choropleth/symbolmap: "chile" (default), "usa", "world", a registered name or a GeoJSON FeatureCollection. */
|
|
165
|
+
geo?: 'chile' | 'usa' | 'world' | string | object;
|
|
166
|
+
key?: string;
|
|
167
|
+
projection?: 'mercator' | 'equalEarth' | 'albersUsa';
|
|
168
|
+
columns?: number;
|
|
169
|
+
[key: string]: unknown;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface Issue { code: string; message: string; fix?: string }
|
|
173
|
+
export interface LintReport { ok: boolean; type: ChartType; errors: Issue[]; warnings: Issue[]; suggestions: Issue[] }
|
|
174
|
+
export interface SafeResult extends Omit<LintReport, 'ok'> { ok: boolean; svg: string | null; description: string }
|
|
175
|
+
|
|
176
|
+
export declare class PlotError extends Error { hint?: string }
|
|
177
|
+
|
|
178
|
+
/** Draws and returns an SVG string. Throws PlotError with a fix hint when the spec cannot be drawn. */
|
|
179
|
+
export declare function plot(spec: Spec): string;
|
|
180
|
+
/** Never throws: returns the SVG plus errors, warnings and design suggestions. */
|
|
181
|
+
export declare function safePlot(spec: Spec): SafeResult;
|
|
182
|
+
/** Reviews a spec and suggests improvements without drawing. */
|
|
183
|
+
export declare function lint(spec: Spec): LintReport;
|
|
184
|
+
/** Text description of the chart (also in the SVG <desc>). */
|
|
185
|
+
export declare function describe(spec: Spec): string;
|
|
186
|
+
/** Browser: draws into an element with tooltips, responsive width, time sliders and drill-down. */
|
|
187
|
+
export declare function render(target: string | Element, spec: Spec, opts?: { controls?: boolean }): { readonly svg: SVGSVGElement | null; readonly spec: Spec; update(spec: Spec): unknown; destroy(): void };
|
|
188
|
+
/** Self-contained HTML page with one or more interactive charts. */
|
|
189
|
+
export declare function toHTML(specs: Spec | Spec[], opts?: { title?: string; lang?: string; columns?: number }): string;
|
|
190
|
+
/** Adds tooltips to a container that already holds a plotagents SVG. */
|
|
191
|
+
export declare function attach(root: Element): void;
|
|
192
|
+
export declare function resolve(spec: Spec): Spec;
|
|
193
|
+
|
|
194
|
+
export declare const schema: Record<string, unknown>;
|
|
195
|
+
/** Library-wide defaults (font, textScale, locale, theme, palette…). The spec always wins. `configure(null)` resets. */
|
|
196
|
+
export declare function configure(options?: Partial<Spec> | null): Partial<Spec>;
|
|
197
|
+
export declare function registerGeo(name: string, featureCollection: object, aliases?: string[]): object;
|
|
198
|
+
export declare const palettes: Record<string, string[]>;
|
|
199
|
+
export declare const ramps: Record<string, string[]>;
|
|
200
|
+
export declare function themeFor(spec: Spec): Theme;
|
|
201
|
+
export declare function timeValues(spec: Spec): (string | number)[];
|
|
202
|
+
export declare function validatePalette(colors: string[], opts?: { mode?: 'light' | 'dark'; surface?: string; pairs?: 'adjacent' | 'all' }): { ok: boolean; checks: { name: string; status: 'pass' | 'warn' | 'fail'; detail: string }[] };
|
|
203
|
+
export declare function bundleSource(): string | null;
|
|
204
|
+
export declare function toolDefinition(opts?: { name?: string; flavor?: 'anthropic' | 'openai' }): Record<string, unknown>;
|
|
205
|
+
export declare const themes: Record<'papel' | 'noche' | 'light' | 'dark', Theme>;
|
|
206
|
+
export declare function getTheme(t?: Spec['theme']): Theme;
|
|
207
|
+
export declare const TYPES: ChartType[];
|
|
208
|
+
export declare function squarify<T extends { value: number }>(items: T[], x: number, y: number, w: number, h: number): (T & { x: number; y: number; w: number; h: number })[];
|
|
209
|
+
export declare function makeFormat(fmt?: Format, locale?: string, values?: number[]): ((v: number) => string) & { type: string };
|
|
210
|
+
export declare function formatNumber(v: number, decimals?: number, locale?: string, trim?: boolean): string;
|
|
211
|
+
export declare function formatCompact(v: number, locale?: string, decimals?: number): string;
|
|
212
|
+
|
|
213
|
+
export default plot;
|
package/package.json
CHANGED
|
@@ -1,6 +1,76 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plotagents",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Beautiful charts from one JSON spec, built for AI agents: bars, lines, multi-level treemaps, sunbursts, sankeys and seaborn-style plots (regplot, hist, kde, box, violin…). Accessible SVG, time sliders, JSON themes, zero dependencies.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"module": "./src/index.js",
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./index.d.ts",
|
|
12
|
+
"default": "./src/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./schema.json": "./schema.json",
|
|
15
|
+
"./browser": "./dist/plotagents.js",
|
|
16
|
+
"./browser/geo": "./dist/plotagents-geo.js",
|
|
17
|
+
"./geo/chile": "./src/geo/chile.js",
|
|
18
|
+
"./geo/world": "./src/geo/world.js",
|
|
19
|
+
"./geo/usa": "./src/geo/usa.js"
|
|
20
|
+
},
|
|
21
|
+
"bin": {
|
|
22
|
+
"plotagents": "bin/plotagents.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"src",
|
|
26
|
+
"dist",
|
|
27
|
+
"docs",
|
|
28
|
+
"bin",
|
|
29
|
+
"index.d.ts",
|
|
30
|
+
"schema.json",
|
|
31
|
+
"README.md",
|
|
32
|
+
"AGENTS.md",
|
|
33
|
+
"LICENSE"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"test": "node --test test/*.test.js",
|
|
37
|
+
"build": "node scripts/bundle.js",
|
|
38
|
+
"bench": "node scripts/bench.js",
|
|
39
|
+
"prepublishOnly": "node scripts/bundle.js && node --test test/*.test.js",
|
|
40
|
+
"examples": "node examples/build.js",
|
|
41
|
+
"site": "node scripts/build-site.js",
|
|
42
|
+
"schema": "node -e \"import('./src/index.js').then(m=>process.stdout.write(JSON.stringify(m.schema,null,2)))\" > schema.json"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"chart",
|
|
46
|
+
"plot",
|
|
47
|
+
"svg",
|
|
48
|
+
"dataviz",
|
|
49
|
+
"visualization",
|
|
50
|
+
"treemap",
|
|
51
|
+
"sankey",
|
|
52
|
+
"seaborn",
|
|
53
|
+
"regplot",
|
|
54
|
+
"violin",
|
|
55
|
+
"radar",
|
|
56
|
+
"sunburst",
|
|
57
|
+
"ai",
|
|
58
|
+
"agents",
|
|
59
|
+
"llm",
|
|
60
|
+
"tool-use"
|
|
61
|
+
],
|
|
62
|
+
"author": "Carlos Navarrete <cnavarreteliz@gmail.com>",
|
|
63
|
+
"license": "MIT",
|
|
64
|
+
"repository": {
|
|
65
|
+
"type": "git",
|
|
66
|
+
"url": "git+https://github.com/carlosnavarreteliz/plotagents.git"
|
|
67
|
+
},
|
|
68
|
+
"homepage": "https://carlosnavarrete.cl/plotagents/",
|
|
69
|
+
"bugs": {
|
|
70
|
+
"url": "https://github.com/carlosnavarreteliz/plotagents/issues"
|
|
71
|
+
},
|
|
72
|
+
"engines": {
|
|
73
|
+
"node": ">=18"
|
|
74
|
+
},
|
|
75
|
+
"sideEffects": false
|
|
76
|
+
}
|