blessed-components 1.0.0 → 1.1.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.
@@ -0,0 +1,171 @@
1
+ # Sparkline
2
+
3
+ Render compact numeric trends with Unicode or custom terminal glyphs.
4
+
5
+ ## Features
6
+
7
+ - Pure renderer with no Blessed import.
8
+ - Blessed adapter with `setData()` and `destroy()`.
9
+ - Automatic or explicit numeric domains.
10
+ - Peak-preserving downsampling for narrow terminals.
11
+ - Stable rendering for constant series.
12
+ - Empty-state text.
13
+ - Optional label, primary value, and summary.
14
+ - Custom glyph scales for Unicode or ASCII terminals.
15
+ - Dedicated tree-shakable subpath exports.
16
+
17
+ ## Installation
18
+
19
+ ```sh
20
+ npm install blessed blessed-components
21
+ ```
22
+
23
+ ## Pure renderer
24
+
25
+ ```ts
26
+ import { renderSparkline } from 'blessed-components/sparkline';
27
+
28
+ renderSparkline({
29
+ values: [1, 2, 3, 4, 5, 6, 7, 8],
30
+ width: 8,
31
+ });
32
+
33
+ // ▁▂▃▄▅▆▇█
34
+ ```
35
+
36
+ ### Metadata
37
+
38
+ ```ts
39
+ renderSparkline({
40
+ label: 'Weekly downloads',
41
+ value: '25.2M',
42
+ values: [1, 3, 2, 5, 8, 6],
43
+ width: 6,
44
+ summary: 'peak: 8M',
45
+ });
46
+
47
+ // Weekly downloads 25.2M
48
+ // ▁▃▂▅█▆ peak: 8M
49
+ ```
50
+
51
+ ### Explicit domain
52
+
53
+ ```ts
54
+ renderSparkline({
55
+ min: 0,
56
+ max: 100,
57
+ values: [0, 50, 100],
58
+ width: 3,
59
+ });
60
+
61
+ // ▁▄█
62
+ ```
63
+
64
+ ### ASCII mode
65
+
66
+ ```ts
67
+ renderSparkline({
68
+ characters: ['.', ':', '*', '#'],
69
+ values: [0, 30, 60, 100],
70
+ width: 4,
71
+ });
72
+ ```
73
+
74
+ ## Downsampling
75
+
76
+ `width` is the maximum number of samples rendered. When the source series is
77
+ wider, values are divided into ordered buckets and the maximum value from each
78
+ bucket is retained. This preserves short peaks that uniform point sampling can
79
+ hide.
80
+
81
+ Series shorter than `width` are not padded or interpolated.
82
+
83
+ ## Empty and constant series
84
+
85
+ Empty arrays render `No data` by default:
86
+
87
+ ```ts
88
+ renderSparkline({ values: [], width: 10 });
89
+ ```
90
+
91
+ Override with `emptyText`. Constant series use the middle glyph instead of
92
+ dividing by zero:
93
+
94
+ ```ts
95
+ renderSparkline({ values: [4, 4, 4], width: 3 });
96
+ // ▄▄▄
97
+ ```
98
+
99
+ ## Blessed adapter
100
+
101
+ ```ts
102
+ import blessed from 'blessed';
103
+ import { sparkline } from 'blessed-components/sparkline/blessed';
104
+
105
+ const screen = blessed.screen({ smartCSR: true });
106
+ const downloads = sparkline({
107
+ parent: screen,
108
+ box: {
109
+ top: 0,
110
+ left: 0,
111
+ width: 40,
112
+ height: 2,
113
+ },
114
+ data: {
115
+ label: 'Downloads',
116
+ values: [1, 3, 2, 5, 8, 6],
117
+ width: 20,
118
+ },
119
+ });
120
+
121
+ screen.render();
122
+
123
+ downloads.setData({
124
+ label: 'Downloads',
125
+ values: [2, 4, 6, 8],
126
+ width: 20,
127
+ });
128
+ screen.render();
129
+
130
+ downloads.destroy();
131
+ ```
132
+
133
+ The adapter never calls `screen.render()`. This lets applications batch
134
+ multiple component updates.
135
+
136
+ ## Renderer API
137
+
138
+ | Option | Type | Default | Description |
139
+ | --- | --- | --- | --- |
140
+ | `values` | `readonly number[]` | Required | Ordered finite numeric samples. |
141
+ | `width` | `number` | Required | Positive integer maximum sample count. |
142
+ | `min` | `number` | Series minimum | Lower domain bound. |
143
+ | `max` | `number` | Series maximum | Upper domain bound. |
144
+ | `characters` | `readonly string[]` | `▁▂▃▄▅▆▇█` | Ordered low-to-high glyph scale. |
145
+ | `emptyText` | `string` | `No data` | Output for an empty series. |
146
+ | `label` | `string` | — | Heading label. |
147
+ | `value` | `string \| number` | — | Primary heading value. |
148
+ | `summary` | `string` | — | Text appended after the graph. |
149
+
150
+ ## Terminal compatibility
151
+
152
+ - Glyphs should occupy one terminal cell.
153
+ - Use custom ASCII glyphs when Unicode support is unavailable.
154
+ - Text remains literal because the Blessed adapter disables tags.
155
+ - The component is display-only and never receives focus.
156
+ - Do not communicate meaning through glyph height or color alone; include
157
+ labels, values, or summaries when context matters.
158
+
159
+ ## Tree shaking
160
+
161
+ Use the pure entry when no Blessed element is needed:
162
+
163
+ ```ts
164
+ import { renderSparkline } from 'blessed-components/sparkline';
165
+ ```
166
+
167
+ Import the adapter separately:
168
+
169
+ ```ts
170
+ import { sparkline } from 'blessed-components/sparkline/blessed';
171
+ ```