@tuicomponents/chart 0.2.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/README.md ADDED
@@ -0,0 +1,294 @@
1
+ # @tuicomponents/chart
2
+
3
+ A comprehensive terminal charting library for rendering data visualizations in ANSI and markdown formats.
4
+
5
+ ## Features
6
+
7
+ - **11 chart types**: bar, bar-vertical, bar-stacked, bar-stacked-vertical, line, area, area-stacked, scatter, pie, donut, heatmap
8
+ - **Dual rendering**: ANSI (colored terminal output) and markdown (plain text with backtick styling)
9
+ - **High-resolution graphics**: Braille character rendering for smooth curves and precise positioning
10
+ - **Automatic scaling**: Smart tick computation with nice round numbers
11
+ - **Multi-series support**: Multiple data series with distinct visual styles
12
+ - **Flexible configuration**: Customizable dimensions, axes, legends, and styling
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @tuicomponents/chart
18
+ # or
19
+ pnpm add @tuicomponents/chart
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ ```typescript
25
+ import { createChart } from "@tuicomponents/chart";
26
+
27
+ const chart = createChart();
28
+
29
+ const result = chart.render(
30
+ {
31
+ type: "bar",
32
+ series: [
33
+ {
34
+ name: "Sales",
35
+ data: [
36
+ { x: "Q1", y: 120 },
37
+ { x: "Q2", y: 150 },
38
+ { x: "Q3", y: 180 },
39
+ { x: "Q4", y: 200 },
40
+ ],
41
+ },
42
+ ],
43
+ showValues: true,
44
+ },
45
+ { renderMode: "ansi" }
46
+ );
47
+
48
+ console.log(result.output);
49
+ ```
50
+
51
+ ## Chart Types
52
+
53
+ ### Bar Charts
54
+
55
+ ```typescript
56
+ // Horizontal bar chart
57
+ { type: "bar", series: [...] }
58
+
59
+ // Vertical bar chart (column chart)
60
+ { type: "bar-vertical", series: [...], height: 8 }
61
+
62
+ // Stacked horizontal bars
63
+ { type: "bar-stacked", series: [series1, series2, ...] }
64
+
65
+ // Stacked vertical bars
66
+ { type: "bar-stacked-vertical", series: [series1, series2, ...] }
67
+ ```
68
+
69
+ ### Line & Area Charts
70
+
71
+ ```typescript
72
+ // Line chart with height blocks
73
+ { type: "line", series: [...], lineStyle: "blocks" }
74
+
75
+ // High-resolution braille line chart
76
+ { type: "line", series: [...], lineStyle: "braille" }
77
+
78
+ // Filled area chart
79
+ { type: "area", series: [...] }
80
+
81
+ // Stacked area chart
82
+ { type: "area-stacked", series: [series1, series2] }
83
+ ```
84
+
85
+ ### Scatter Plot
86
+
87
+ ```typescript
88
+ // Scatter with character markers
89
+ {
90
+ type: "scatter",
91
+ series: [{
92
+ name: "Data",
93
+ data: [
94
+ { x: 10, y: 20 },
95
+ { x: 30, y: 50 },
96
+ { x: 50, y: 30 },
97
+ ]
98
+ }],
99
+ scatterStyle: "dots" // or "braille" for high-resolution
100
+ }
101
+ ```
102
+
103
+ ### Pie & Donut Charts
104
+
105
+ ```typescript
106
+ // Pie chart
107
+ {
108
+ type: "pie",
109
+ series: [{
110
+ name: "Revenue",
111
+ data: [
112
+ { label: "Sales", x: "Sales", y: 45 },
113
+ { label: "Support", x: "Support", y: 30 },
114
+ { label: "Other", x: "Other", y: 25 },
115
+ ]
116
+ }]
117
+ }
118
+
119
+ // Donut chart with center label
120
+ {
121
+ type: "donut",
122
+ series: [...],
123
+ centerLabel: "100%",
124
+ innerRadius: 0.5 // 0-0.9, controls hole size
125
+ }
126
+ ```
127
+
128
+ ### Heatmap
129
+
130
+ ```typescript
131
+ {
132
+ type: "heatmap",
133
+ series: [{
134
+ name: "Activity",
135
+ data: [
136
+ { x: "Mon", y: 10, label: "9am" },
137
+ { x: "Tue", y: 50, label: "9am" },
138
+ { x: "Wed", y: 90, label: "9am" },
139
+ { x: "Mon", y: 30, label: "10am" },
140
+ // ... more cells
141
+ ]
142
+ }],
143
+ heatmapStyle: "blocks" // "blocks", "ascii", or "numeric"
144
+ }
145
+ ```
146
+
147
+ ## Configuration Options
148
+
149
+ ### Chart Input Schema
150
+
151
+ | Property | Type | Default | Description |
152
+ | -------------- | ------- | -------- | --------------------------------------------------------------- |
153
+ | `type` | string | required | Chart type (see above) |
154
+ | `series` | array | required | Data series array |
155
+ | `title` | string | - | Chart title |
156
+ | `width` | number | 40 | Width in characters |
157
+ | `height` | number | 10 | Height in lines |
158
+ | `showValues` | boolean | false | Display values on data points |
159
+ | `showAxes` | boolean | true | Display axes |
160
+ | `lineStyle` | string | "blocks" | Line rendering: "blocks", "braille", "dots" |
161
+ | `barStyle` | string | "block" | Bar fill: "block", "shaded", "light", "hash", "equals", "arrow" |
162
+ | `scatterStyle` | string | "dots" | Scatter rendering: "dots", "braille" |
163
+ | `heatmapStyle` | string | "blocks" | Heatmap rendering: "blocks", "ascii", "numeric" |
164
+ | `xAxis` | object | - | X-axis configuration |
165
+ | `yAxis` | object | - | Y-axis configuration |
166
+ | `legend` | object | - | Legend configuration |
167
+ | `grid` | object | - | Grid line configuration |
168
+
169
+ ### Data Point Schema
170
+
171
+ ```typescript
172
+ {
173
+ x: string | number, // Category or x-value
174
+ y: number, // Numeric y-value
175
+ label?: string // Optional custom label
176
+ }
177
+ ```
178
+
179
+ ### Axis Configuration
180
+
181
+ ```typescript
182
+ {
183
+ label?: string, // Axis title
184
+ min?: number, // Minimum value (auto-computed if not set)
185
+ max?: number, // Maximum value (auto-computed if not set)
186
+ tickCount?: number, // Number of ticks (default: 5)
187
+ showTicks?: boolean, // Show tick marks (default: true)
188
+ format?: string, // "number", "percent", "compact", "currency"
189
+ decimals?: number // Decimal places
190
+ }
191
+ ```
192
+
193
+ ### Legend Configuration
194
+
195
+ ```typescript
196
+ {
197
+ position?: string, // "none", "top", "bottom", "right", "inline"
198
+ boxed?: boolean // Use boxed style
199
+ }
200
+ ```
201
+
202
+ ## Render Modes
203
+
204
+ ### ANSI Mode
205
+
206
+ Produces colored terminal output using ANSI escape codes. Best for interactive terminal applications.
207
+
208
+ ```typescript
209
+ chart.render(input, { renderMode: "ansi", theme: yourTheme });
210
+ ```
211
+
212
+ ### Markdown Mode
213
+
214
+ Produces plain text output using backticks for visual distinction. Best for embedding in markdown documents or environments without ANSI support.
215
+
216
+ ```typescript
217
+ chart.render(input, { renderMode: "markdown" });
218
+ ```
219
+
220
+ ## Render Result
221
+
222
+ ```typescript
223
+ interface RenderResult {
224
+ output: string; // The rendered chart string
225
+ actualWidth: number; // Actual width in characters
226
+ lineCount: number; // Number of lines
227
+ }
228
+ ```
229
+
230
+ ## Advanced Usage
231
+
232
+ ### Direct Layout Access
233
+
234
+ For advanced use cases, you can compute layouts separately from rendering:
235
+
236
+ ```typescript
237
+ import {
238
+ computeBarLayout,
239
+ computeLineLayout,
240
+ computeScatterLayout,
241
+ computePieLayout,
242
+ computeHeatmapLayout,
243
+ renderBarChartAnsi,
244
+ renderLineChartMarkdown,
245
+ } from "@tuicomponents/chart";
246
+
247
+ // Compute layout
248
+ const layout = computeBarLayout(chartInput);
249
+
250
+ // Render with custom options
251
+ const output = renderBarChartAnsi(layout, { theme, input: chartInput });
252
+ ```
253
+
254
+ ### Braille Canvas
255
+
256
+ The library includes a `BrailleCanvas` class for high-resolution terminal graphics:
257
+
258
+ ```typescript
259
+ import { BrailleCanvas } from "@tuicomponents/chart";
260
+
261
+ const canvas = new BrailleCanvas(40, 10); // width, height in chars
262
+ canvas.setDot(x, y, seriesIndex);
263
+ canvas.drawLine(x1, y1, x2, y2, seriesIndex);
264
+ canvas.drawCircle(cx, cy, radius, seriesIndex);
265
+ const rendered = canvas.render();
266
+ ```
267
+
268
+ ## Character Sets
269
+
270
+ ### Height Blocks
271
+
272
+ `▁▂▃▄▅▆▇█` - 8 levels for line/area charts
273
+
274
+ ### Bar Fill Styles
275
+
276
+ - block: `████████`
277
+ - shaded: `▓▓▓▓▓▓▓▓`
278
+ - light: `░░░░░░░░`
279
+ - hash: `########`
280
+ - equals: `========`
281
+ - arrow: `>>>>>>>>`
282
+
283
+ ### Heatmap Intensity
284
+
285
+ - blocks: `░▒▓█` (4 levels)
286
+ - ascii: `.:*#` (4 levels, markdown-friendly)
287
+
288
+ ### Scatter Markers
289
+
290
+ `● ■ ▲ ◆ +` - 5 distinct markers for multi-series
291
+
292
+ ## License
293
+
294
+ UNLICENSED