@ggterm/core 0.2.0 → 0.2.5

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 ADDED
@@ -0,0 +1,102 @@
1
+ # @ggterm/core
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@ggterm/core.svg)](https://www.npmjs.com/package/@ggterm/core)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@ggterm/core.svg)](https://www.npmjs.com/package/@ggterm/core)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ A Grammar of Graphics for Terminal User Interfaces.
8
+
9
+ **ggterm** is a TypeScript library implementing Leland Wilkinson's Grammar of Graphics for terminal-based rendering. Create publication-quality data visualizations directly in your terminal.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install @ggterm/core
15
+ ```
16
+
17
+ ## Quick Example
18
+
19
+ ```typescript
20
+ import { gg, geom_point, geom_line } from '@ggterm/core'
21
+
22
+ const data = [
23
+ { x: 1, y: 10 },
24
+ { x: 2, y: 25 },
25
+ { x: 3, y: 18 },
26
+ { x: 4, y: 30 }
27
+ ]
28
+
29
+ const plot = gg(data)
30
+ .aes({ x: 'x', y: 'y' })
31
+ .geom(geom_point())
32
+ .geom(geom_line())
33
+ .labs({ title: 'My Plot', x: 'Time', y: 'Value' })
34
+
35
+ console.log(plot.render({ width: 60, height: 20 }))
36
+ ```
37
+
38
+ ## Features
39
+
40
+ - **20+ Geometry Types**: point, line, bar, histogram, boxplot, violin, area, heatmap, contour, and more
41
+ - **50+ Scales**: Continuous, discrete, color (viridis, brewer), date/time
42
+ - **Faceting**: `facet_wrap()` and `facet_grid()` for multi-panel plots
43
+ - **Themes**: Customizable themes for different visual styles
44
+ - **Export**: Convert to Vega-Lite for publication-quality PNG/SVG output
45
+
46
+ ## Available Geoms
47
+
48
+ ```typescript
49
+ // Points and Lines
50
+ geom_point(), geom_line(), geom_path(), geom_step(), geom_smooth()
51
+
52
+ // Bars and Areas
53
+ geom_bar(), geom_col(), geom_histogram(), geom_area(), geom_ribbon()
54
+
55
+ // Distributions
56
+ geom_boxplot(), geom_violin(), geom_density_2d(), geom_qq()
57
+
58
+ // 2D Plots
59
+ geom_tile(), geom_raster(), geom_contour(), geom_contour_filled()
60
+
61
+ // Annotations
62
+ geom_text(), geom_label(), geom_hline(), geom_vline(), geom_abline()
63
+
64
+ // Uncertainty
65
+ geom_errorbar(), geom_errorbarh(), geom_crossbar(), geom_linerange(), geom_pointrange()
66
+ ```
67
+
68
+ ## Color Support
69
+
70
+ Works in terminals with truecolor, 256-color, and 16-color support:
71
+
72
+ ```typescript
73
+ plot.render({
74
+ width: 80,
75
+ height: 24,
76
+ colorMode: 'truecolor' // or '256', '16', 'none'
77
+ })
78
+ ```
79
+
80
+ ## Export to Vega-Lite
81
+
82
+ ```typescript
83
+ import { plotSpecToVegaLite } from '@ggterm/core'
84
+
85
+ const vegaSpec = plotSpecToVegaLite(plot.spec())
86
+ // Use with Vega-Embed to render PNG/SVG in browsers
87
+ ```
88
+
89
+ ## Framework Integrations
90
+
91
+ - **React**: `@ggterm/opentui`
92
+ - **Vue**: `@ggterm/vue`
93
+ - **Svelte**: `@ggterm/svelte`
94
+ - **Solid**: `@ggterm/solid`
95
+
96
+ ## Documentation
97
+
98
+ Full documentation and examples: [github.com/shandley/ggterm](https://github.com/shandley/ggterm)
99
+
100
+ ## License
101
+
102
+ MIT
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Canvas - Abstract 2D buffer for terminal rendering
3
+ */
4
+ import type { Canvas, CanvasCell, RGBA } from '../types';
5
+ /**
6
+ * Default colors
7
+ */
8
+ export declare const DEFAULT_FG: RGBA;
9
+ export declare const DEFAULT_BG: RGBA;
10
+ /**
11
+ * Concrete Canvas implementation
12
+ */
13
+ export declare class TerminalCanvas implements Canvas {
14
+ readonly width: number;
15
+ readonly height: number;
16
+ cells: CanvasCell[][];
17
+ constructor(width: number, height: number);
18
+ /**
19
+ * Set a cell at the given position
20
+ */
21
+ setCell(x: number, y: number, cell: Partial<CanvasCell>): void;
22
+ /**
23
+ * Get a cell at the given position
24
+ */
25
+ getCell(x: number, y: number): CanvasCell;
26
+ /**
27
+ * Clear the canvas
28
+ */
29
+ clear(): void;
30
+ /**
31
+ * Draw a character at position
32
+ */
33
+ drawChar(x: number, y: number, char: string, fg?: RGBA): void;
34
+ /**
35
+ * Draw a string horizontally starting at position
36
+ */
37
+ drawString(x: number, y: number, str: string, fg?: RGBA): void;
38
+ /**
39
+ * Draw a horizontal line
40
+ */
41
+ drawHLine(x: number, y: number, length: number, char?: string, fg?: RGBA): void;
42
+ /**
43
+ * Draw a vertical line
44
+ */
45
+ drawVLine(x: number, y: number, length: number, char?: string, fg?: RGBA): void;
46
+ /**
47
+ * Draw a point marker
48
+ */
49
+ drawPoint(x: number, y: number, fg?: RGBA, shape?: string): void;
50
+ /**
51
+ * Fill a rectangular region
52
+ */
53
+ fillRect(x: number, y: number, width: number, height: number, char?: string, fg?: RGBA, bg?: RGBA): void;
54
+ /**
55
+ * Draw a box border
56
+ */
57
+ drawBox(x: number, y: number, width: number, height: number, style?: 'single' | 'double' | 'rounded', fg?: RGBA): void;
58
+ /**
59
+ * Render canvas to plain string (no colors)
60
+ */
61
+ toString(): string;
62
+ /**
63
+ * Render canvas to ANSI-colored string
64
+ */
65
+ toAnsiString(): string;
66
+ }
67
+ /**
68
+ * Create a new canvas
69
+ */
70
+ export declare function createCanvas(width: number, height: number): TerminalCanvas;
71
+ //# sourceMappingURL=canvas.d.ts.map
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Canvas exports
3
+ */
4
+ export { TerminalCanvas, createCanvas, DEFAULT_FG, DEFAULT_BG } from './canvas';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * geom_area - Area geometry
3
+ */
4
+ import type { Geom } from '../types';
5
+ export interface AreaOptions {
6
+ alpha?: number;
7
+ color?: string;
8
+ fill?: string;
9
+ }
10
+ /**
11
+ * Render filled area under a line
12
+ */
13
+ export declare function geom_area(options?: AreaOptions): Geom;
14
+ /**
15
+ * Render a ribbon (band between ymin and ymax)
16
+ */
17
+ export declare function geom_ribbon(options?: AreaOptions): Geom;
18
+ //# sourceMappingURL=area.d.ts.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * geom_boxplot - Boxplot geometry
3
+ */
4
+ import type { Geom } from '../types';
5
+ export interface BoxplotOptions {
6
+ /** Width of the box (default: 0.75) */
7
+ width?: number;
8
+ /** Coefficient for whisker length (default: 1.5 * IQR) */
9
+ coef?: number;
10
+ /** Show outliers (default: true) */
11
+ outliers?: boolean;
12
+ /** Show notch (default: false) */
13
+ notch?: boolean;
14
+ /** Alpha transparency */
15
+ alpha?: number;
16
+ /** Border color */
17
+ color?: string;
18
+ /** Fill color */
19
+ fill?: string;
20
+ }
21
+ /**
22
+ * Render boxplot (box and whisker plot)
23
+ */
24
+ export declare function geom_boxplot(options?: BoxplotOptions): Geom;
25
+ //# sourceMappingURL=boxplot.d.ts.map
@@ -0,0 +1,31 @@
1
+ /**
2
+ * geom_line - Line geometry
3
+ */
4
+ import type { Geom } from '../types';
5
+ export interface LineOptions {
6
+ linewidth?: number;
7
+ linetype?: 'solid' | 'dashed' | 'dotted';
8
+ alpha?: number;
9
+ color?: string;
10
+ }
11
+ /**
12
+ * Connect data points with lines
13
+ */
14
+ export declare function geom_line(options?: LineOptions): Geom;
15
+ /**
16
+ * Add a horizontal reference line
17
+ */
18
+ export declare function geom_hline(options: {
19
+ yintercept: number;
20
+ linetype?: 'solid' | 'dashed' | 'dotted';
21
+ color?: string;
22
+ }): Geom;
23
+ /**
24
+ * Add a vertical reference line
25
+ */
26
+ export declare function geom_vline(options: {
27
+ xintercept: number;
28
+ linetype?: 'solid' | 'dashed' | 'dotted';
29
+ color?: string;
30
+ }): Geom;
31
+ //# sourceMappingURL=line.d.ts.map
@@ -0,0 +1,33 @@
1
+ /**
2
+ * geom_segment - Line segments from (x, y) to (xend, yend)
3
+ */
4
+ import type { Geom } from '../types';
5
+ export interface SegmentOptions {
6
+ /** Line width (default: 1) */
7
+ linewidth?: number;
8
+ /** Line type (default: 'solid') */
9
+ linetype?: 'solid' | 'dashed' | 'dotted';
10
+ /** Opacity (default: 1) */
11
+ alpha?: number;
12
+ /** Fixed color for all segments */
13
+ color?: string;
14
+ /** Add arrow to end (default: false) */
15
+ arrow?: boolean;
16
+ /** Arrow type (default: 'closed') */
17
+ arrowType?: 'open' | 'closed';
18
+ }
19
+ /**
20
+ * Draw line segments between pairs of points
21
+ *
22
+ * Required aesthetics: x, y, xend, yend
23
+ * Optional aesthetics: color, alpha
24
+ */
25
+ export declare function geom_segment(options?: SegmentOptions): Geom;
26
+ /**
27
+ * Draw curves between points (alias for segment with potential future curve support)
28
+ */
29
+ export declare function geom_curve(options?: SegmentOptions & {
30
+ /** Curvature amount (-1 to 1, default: 0.5) */
31
+ curvature?: number;
32
+ }): Geom;
33
+ //# sourceMappingURL=segment.d.ts.map
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Main rendering pipeline
3
+ *
4
+ * Orchestrates the full flow from PlotSpec to rendered output.
5
+ */
6
+ import type { PlotSpec, RenderOptions } from '../types';
7
+ import { TerminalCanvas } from '../canvas/canvas';
8
+ /**
9
+ * Layout configuration for plot elements
10
+ */
11
+ export interface PlotLayout {
12
+ width: number;
13
+ height: number;
14
+ margins: {
15
+ top: number;
16
+ right: number;
17
+ bottom: number;
18
+ left: number;
19
+ };
20
+ plotArea: {
21
+ x: number;
22
+ y: number;
23
+ width: number;
24
+ height: number;
25
+ };
26
+ legendArea?: {
27
+ x: number;
28
+ y: number;
29
+ width: number;
30
+ height: number;
31
+ };
32
+ }
33
+ /**
34
+ * Calculate layout based on render options and content
35
+ */
36
+ export declare function calculateLayout(spec: PlotSpec, options: RenderOptions): PlotLayout;
37
+ /**
38
+ * Render a plot specification to a canvas
39
+ */
40
+ export declare function renderToCanvas(spec: PlotSpec, options: RenderOptions): TerminalCanvas;
41
+ /**
42
+ * Render a plot specification to a string
43
+ */
44
+ export declare function renderToString(spec: PlotSpec, options: RenderOptions): string;
45
+ //# sourceMappingURL=pipeline.d.ts.map
@@ -0,0 +1,33 @@
1
+ /**
2
+ * stat_bin - Bin continuous data for histograms
3
+ */
4
+ import type { DataSource, Stat } from '../types';
5
+ export interface StatBinParams {
6
+ /** Number of bins (default: 30) */
7
+ bins?: number;
8
+ /** Bin width (overrides bins if specified) */
9
+ binwidth?: number;
10
+ /** Center of one bin */
11
+ center?: number;
12
+ /** Boundary between bins */
13
+ boundary?: number;
14
+ }
15
+ /**
16
+ * Compute bins for histogram data
17
+ */
18
+ export declare function computeBins(data: DataSource, field: string, params?: StatBinParams): {
19
+ bins: BinResult[];
20
+ binWidth: number;
21
+ };
22
+ export interface BinResult {
23
+ x: number;
24
+ xmin: number;
25
+ xmax: number;
26
+ count: number;
27
+ density: number;
28
+ }
29
+ /**
30
+ * Create stat_bin transformation
31
+ */
32
+ export declare function stat_bin(params?: StatBinParams): Stat;
33
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1,28 @@
1
+ /**
2
+ * stat_boxplot - Compute summary statistics for boxplots
3
+ */
4
+ import type { Stat } from '../types';
5
+ export interface StatBoxplotParams {
6
+ /** Coefficient for whisker length (default: 1.5 * IQR) */
7
+ coef?: number;
8
+ }
9
+ export interface BoxplotResult {
10
+ x: string | number;
11
+ lower: number;
12
+ q1: number;
13
+ median: number;
14
+ q3: number;
15
+ upper: number;
16
+ outliers: number[];
17
+ notchlower?: number;
18
+ notchupper?: number;
19
+ }
20
+ /**
21
+ * Compute boxplot statistics for a group of values
22
+ */
23
+ export declare function computeBoxplotStats(values: number[], coef?: number): Omit<BoxplotResult, 'x'>;
24
+ /**
25
+ * Create stat_boxplot transformation
26
+ */
27
+ export declare function stat_boxplot(params?: StatBoxplotParams): Stat;
28
+ //# sourceMappingURL=boxplot.d.ts.map
@@ -0,0 +1,33 @@
1
+ /**
2
+ * stat_smooth - Smoothing and regression lines
3
+ */
4
+ import type { DataSource, Stat } from '../types';
5
+ export interface StatSmoothParams {
6
+ /** Method: 'lm' (linear), 'loess', 'lowess' (default: 'lm') */
7
+ method?: 'lm' | 'loess' | 'lowess';
8
+ /** Span for loess smoothing (default: 0.75) */
9
+ span?: number;
10
+ /** Number of points to evaluate (default: 80) */
11
+ n?: number;
12
+ /** Include standard error bands (default: true) */
13
+ se?: boolean;
14
+ /** Confidence level for SE bands (default: 0.95) */
15
+ level?: number;
16
+ }
17
+ export interface SmoothResult {
18
+ x: number;
19
+ y: number;
20
+ ymin?: number;
21
+ ymax?: number;
22
+ se?: number;
23
+ [key: string]: unknown;
24
+ }
25
+ /**
26
+ * Compute smoothed values
27
+ */
28
+ export declare function computeSmooth(data: DataSource, xField: string, yField: string, params?: StatSmoothParams): DataSource;
29
+ /**
30
+ * Create stat_smooth transformation
31
+ */
32
+ export declare function stat_smooth(params?: StatSmoothParams): Stat;
33
+ //# sourceMappingURL=smooth.d.ts.map
@@ -0,0 +1,32 @@
1
+ /**
2
+ * stat_summary - Summarize y values at each unique x
3
+ */
4
+ import type { DataSource, Stat } from '../types';
5
+ export type SummaryFun = (values: number[]) => number;
6
+ export interface StatSummaryParams {
7
+ /** Function to compute y value (default: mean) */
8
+ fun?: 'mean' | 'median' | 'min' | 'max' | 'sum' | SummaryFun;
9
+ /** Function to compute ymin (default: min) */
10
+ funMin?: 'mean' | 'median' | 'min' | 'max' | 'sum' | 'se_lower' | 'sd_lower' | SummaryFun;
11
+ /** Function to compute ymax (default: max) */
12
+ funMax?: 'mean' | 'median' | 'min' | 'max' | 'sum' | 'se_upper' | 'sd_upper' | SummaryFun;
13
+ /** Preset: 'mean_se', 'mean_sd', 'mean_cl_normal', 'median_range' */
14
+ funData?: 'mean_se' | 'mean_sd' | 'mean_cl_normal' | 'median_range';
15
+ }
16
+ export interface SummaryResult {
17
+ x: string | number;
18
+ y: number;
19
+ ymin?: number;
20
+ ymax?: number;
21
+ n: number;
22
+ [key: string]: unknown;
23
+ }
24
+ /**
25
+ * Compute summary statistics for each group
26
+ */
27
+ export declare function computeSummary(data: DataSource, xField: string, yField: string, params?: StatSummaryParams): DataSource;
28
+ /**
29
+ * Create stat_summary transformation
30
+ */
31
+ export declare function stat_summary(params?: StatSummaryParams): Stat;
32
+ //# sourceMappingURL=summary.d.ts.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Default theme for ggterm
3
+ */
4
+ import type { Theme } from '../types';
5
+ /**
6
+ * Minimal default theme
7
+ */
8
+ export declare function defaultTheme(): Theme;
9
+ /**
10
+ * Minimal theme with no decorations
11
+ */
12
+ export declare function themeMinimal(): Theme;
13
+ /**
14
+ * Dark theme
15
+ */
16
+ export declare function themeDark(): Theme;
17
+ /**
18
+ * Classic theme (ggplot2 style)
19
+ */
20
+ export declare function themeClassic(): Theme;
21
+ /**
22
+ * Empty theme (just the plot area)
23
+ */
24
+ export declare function themeVoid(): Theme;
25
+ //# sourceMappingURL=default.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ggterm/core",
3
- "version": "0.2.0",
3
+ "version": "0.2.5",
4
4
  "description": "Grammar of Graphics engine for terminals",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -35,12 +35,12 @@
35
35
  "license": "MIT",
36
36
  "repository": {
37
37
  "type": "git",
38
- "url": "https://github.com/handleylab/ggterm.git",
38
+ "url": "https://github.com/shandley/ggterm.git",
39
39
  "directory": "packages/core"
40
40
  },
41
- "homepage": "https://github.com/handleylab/ggterm#readme",
41
+ "homepage": "https://github.com/shandley/ggterm#readme",
42
42
  "bugs": {
43
- "url": "https://github.com/handleylab/ggterm/issues"
43
+ "url": "https://github.com/shandley/ggterm/issues"
44
44
  },
45
45
  "peerDependencies": {},
46
46
  "devDependencies": {
package/dist/demo.d.ts DELETED
@@ -1,6 +0,0 @@
1
- /**
2
- * Comprehensive Demo - Showcases all geometries and aesthetics
3
- * Run with: npx bun packages/core/src/demo.ts
4
- */
5
- export {};
6
- //# sourceMappingURL=demo.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"demo.d.ts","sourceRoot":"","sources":["../src/demo.ts"],"names":[],"mappings":"AAAA;;;GAGG"}