console-toolkit 1.2.14 → 1.3.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.
Files changed (88) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -0
  3. package/llms-full.txt +64 -4
  4. package/package.json +6 -6
  5. package/src/alphanumeric/arrows.js +0 -23
  6. package/src/alphanumeric/fractions.js +0 -49
  7. package/src/alphanumeric/number-formatters.js +0 -44
  8. package/src/alphanumeric/roman.js +0 -12
  9. package/src/alphanumeric/unicode-cultural-numbers.js +0 -1
  10. package/src/alphanumeric/unicode-letters.js +0 -8
  11. package/src/alphanumeric/unicode-numbers.js +0 -21
  12. package/src/alphanumeric/utils.js +0 -26
  13. package/src/ansi/csi.js +0 -49
  14. package/src/ansi/sgr-state.js +7 -50
  15. package/src/ansi/sgr.js +0 -420
  16. package/src/box.d.ts +4 -1
  17. package/src/box.js +15 -115
  18. package/src/charts/bars/block-frac-grouped.js +0 -6
  19. package/src/charts/bars/block-frac.js +1 -14
  20. package/src/charts/bars/block-grouped.js +0 -6
  21. package/src/charts/bars/block.js +1 -14
  22. package/src/charts/bars/draw-grouped.js +0 -4
  23. package/src/charts/bars/draw-stacked.js +0 -4
  24. package/src/charts/bars/frac-grouped.js +2 -14
  25. package/src/charts/bars/plain-grouped.js +0 -6
  26. package/src/charts/bars/plain.js +1 -28
  27. package/src/charts/columns/block-frac-grouped.js +0 -6
  28. package/src/charts/columns/block-frac.js +0 -13
  29. package/src/charts/columns/block-grouped.js +0 -6
  30. package/src/charts/columns/block.js +0 -13
  31. package/src/charts/columns/draw-grouped.js +1 -5
  32. package/src/charts/columns/draw-stacked.js +0 -4
  33. package/src/charts/columns/frac-grouped.js +1 -13
  34. package/src/charts/columns/plain-grouped.js +0 -6
  35. package/src/charts/columns/plain.js +0 -13
  36. package/src/charts/themes/default.js +0 -1
  37. package/src/charts/themes/rainbow-reversed.js +0 -1
  38. package/src/charts/themes/rainbow.js +0 -1
  39. package/src/charts/utils.js +2 -28
  40. package/src/draw-block-frac.js +0 -14
  41. package/src/draw-block.js +0 -24
  42. package/src/meta.js +0 -64
  43. package/src/output/show.d.ts +8 -3
  44. package/src/output/show.js +7 -38
  45. package/src/output/updater.d.ts +8 -3
  46. package/src/output/updater.js +4 -51
  47. package/src/output/writer.js +1 -53
  48. package/src/panel.d.ts +16 -10
  49. package/src/panel.js +21 -276
  50. package/src/plot/bitmap.js +5 -33
  51. package/src/plot/draw-line.js +0 -8
  52. package/src/plot/draw-rect.js +25 -103
  53. package/src/plot/index.js +0 -22
  54. package/src/plot/to-quads.js +3 -6
  55. package/src/spinner/spin.js +23 -20
  56. package/src/spinner/spinner.d.ts +16 -2
  57. package/src/spinner/spinner.js +22 -34
  58. package/src/spinner/spinners.js +0 -16
  59. package/src/strings/clip.js +0 -10
  60. package/src/strings/parse.js +0 -7
  61. package/src/strings/split.js +0 -15
  62. package/src/strings.d.ts +2 -0
  63. package/src/strings.js +2 -32
  64. package/src/style.js +2 -58
  65. package/src/symbols.js +0 -84
  66. package/src/table/draw-borders.js +0 -9
  67. package/src/table/index.d.ts +1 -1
  68. package/src/table/index.js +0 -1
  69. package/src/table/table.js +3 -58
  70. package/src/themes/blocks/unicode-half.js +0 -1
  71. package/src/themes/blocks/unicode-thin.js +0 -1
  72. package/src/themes/lines/ascii-compact.js +5 -9
  73. package/src/themes/lines/ascii-dots.js +2 -7
  74. package/src/themes/lines/ascii-girder.js +4 -7
  75. package/src/themes/lines/ascii-github.js +5 -9
  76. package/src/themes/lines/ascii-reddit.js +5 -9
  77. package/src/themes/lines/ascii-rounded.js +5 -9
  78. package/src/themes/lines/ascii.js +5 -9
  79. package/src/themes/lines/unicode-bold.js +8 -14
  80. package/src/themes/lines/unicode-rounded.js +8 -14
  81. package/src/themes/lines/unicode.js +8 -14
  82. package/src/themes/utils.d.ts +6 -0
  83. package/src/themes/utils.js +6 -7
  84. package/src/turtle/draw-line-art.js +26 -18
  85. package/src/turtle/draw-unicode.js +0 -8
  86. package/src/turtle/index.d.ts +1 -1
  87. package/src/turtle/index.js +0 -8
  88. package/src/turtle/turtle.js +0 -120
package/src/box.js CHANGED
@@ -1,15 +1,7 @@
1
1
  import {addAlias} from './meta.js';
2
2
  import {getLength, clipStrings, toStrings} from './strings.js';
3
3
 
4
- /** A rectangular text container where all strings have equal display width.
5
- * Provides methods for padding, stacking, clipping, and flipping.
6
- * @see {@link https://github.com/uhop/console-toolkit/wiki/Module:-box}
7
- */
8
4
  export class Box {
9
- /** Creates a new Box.
10
- * @param {Box|string|string[]|*} s - Input data. If a Box, it is copied. If `normalized` is true, the array is used as-is.
11
- * @param {boolean} [normalized=false] - If true, assumes strings are already equal width and takes ownership of the array.
12
- */
13
5
  constructor(s, normalized) {
14
6
  if (s instanceof Box) {
15
7
  this.box = [...s.box]; // copy
@@ -18,22 +10,13 @@ export class Box {
18
10
  }
19
11
  }
20
12
 
21
- /** The display width of the box (length of the first string, or 0 if empty). */
22
13
  get width() {
23
14
  return this.box.length ? getLength(this.box[0]) : 0;
24
15
  }
25
- /** The number of rows in the box. */
26
16
  get height() {
27
17
  return this.box.length;
28
18
  }
29
19
 
30
- /** Creates a Box from various input types.
31
- * @param {import('./strings.js').StringsInput} s - Input: Box, object with toBox()/toPanel(), function, string, array, etc.
32
- * @param {object} [options] - Options.
33
- * @param {string} [options.symbol=' '] - The padding character.
34
- * @param {'left'|'l'|'right'|'r'|'center'|'c'} [options.align='left'] - Alignment for shorter strings.
35
- * @returns {Box} A new Box instance.
36
- */
37
20
  static make(s, options) {
38
21
  main: for (;;) {
39
22
  switch (typeof s) {
@@ -83,73 +66,44 @@ export class Box {
83
66
  );
84
67
  }
85
68
 
86
- /** Creates a blank Box filled with a symbol.
87
- * @param {number} width - The width of the box.
88
- * @param {number} height - The height of the box.
89
- * @param {string} [symbol=' '] - The fill character.
90
- * @returns {Box} A new blank Box.
91
- */
92
69
  static makeBlank(width, height, symbol = ' ') {
93
- return new Box(height <= 0 ? [] : new Array(height).fill(symbol.repeat(width)), true);
70
+ return new Box(height <= 0 ? [] : new Array(height).fill(width <= 0 ? '' : symbol.repeat(width)), true);
94
71
  }
95
72
 
96
- /** Returns the underlying array of strings.
97
- * @returns {string[]} The box content.
98
- */
99
73
  toStrings() {
100
74
  return this.box;
101
75
  }
102
76
 
103
- /** Creates a shallow copy of this Box.
104
- * @returns {Box} A new Box with the same content.
105
- */
106
77
  clone() {
107
78
  return new Box(this);
108
79
  }
109
80
 
110
- /** Clips all strings to a given display width.
111
- * @param {number} width - The maximum display width.
112
- * @param {object} [options] - Options passed to `clip()`.
113
- * @returns {Box} A new clipped Box.
114
- */
115
81
  clip(width, options) {
116
82
  return Box.make(clipStrings(this.box, width, options));
117
83
  }
118
84
 
119
85
  // padding
120
86
 
121
- /** Pads the box on both left and right sides.
122
- * @param {number} left - Left padding amount.
123
- * @param {number} right - Right padding amount.
124
- * @param {string} [symbol=' '] - The padding character.
125
- * @returns {Box} A new padded Box.
126
- */
127
87
  padLeftRight(left, right, symbol = ' ') {
128
- const paddingLeft = symbol.repeat(left),
129
- paddingRight = symbol.repeat(right);
88
+ if (left <= 0 && right <= 0) return this.clone();
89
+ const paddingLeft = left > 0 ? symbol.repeat(left) : '',
90
+ paddingRight = right > 0 ? symbol.repeat(right) : '';
130
91
  return new Box(
131
92
  this.box.map(s => paddingLeft + s + paddingRight),
132
93
  true
133
94
  );
134
95
  }
135
96
 
136
- /** Pads the box on both top and bottom sides.
137
- * @param {number} top - Top padding amount (number of rows).
138
- * @param {number} bottom - Bottom padding amount (number of rows).
139
- * @param {string} [symbol=' '] - The padding character.
140
- * @returns {Box} A new padded Box.
141
- */
142
97
  padTopBottom(top, bottom, symbol = ' ') {
143
- const padding = symbol.repeat(this.width);
144
- return new Box([...new Array(top).fill(padding), ...this.box, ...new Array(bottom).fill(padding)], true);
98
+ if (top <= 0 && bottom <= 0) return this.clone();
99
+ const padding = symbol.repeat(this.width),
100
+ t = top > 0 ? top : 0,
101
+ b = bottom > 0 ? bottom : 0;
102
+ return new Box([...new Array(t).fill(padding), ...this.box, ...new Array(b).fill(padding)], true);
145
103
  }
146
104
 
147
- /** Pads the box on the right side.
148
- * @param {number} n - Right padding amount.
149
- * @param {string} [symbol=' '] - The padding character.
150
- * @returns {Box} A new padded Box.
151
- */
152
105
  padRight(n, symbol = ' ') {
106
+ if (n <= 0) return this.clone();
153
107
  const padding = symbol.repeat(n);
154
108
  return new Box(
155
109
  this.box.map(s => s + padding),
@@ -157,12 +111,8 @@ export class Box {
157
111
  );
158
112
  }
159
113
 
160
- /** Pads the box on the left side.
161
- * @param {number} n - Left padding amount.
162
- * @param {string} [symbol=' '] - The padding character.
163
- * @returns {Box} A new padded Box.
164
- */
165
114
  padLeft(n, symbol = ' ') {
115
+ if (n <= 0) return this.clone();
166
116
  const padding = symbol.repeat(n);
167
117
  return new Box(
168
118
  this.box.map(s => padding + s),
@@ -170,38 +120,18 @@ export class Box {
170
120
  );
171
121
  }
172
122
 
173
- /** Pads the box on the top side.
174
- * @param {number} n - Top padding amount (number of rows).
175
- * @param {string} [symbol=' '] - The padding character.
176
- * @returns {Box} A new padded Box.
177
- */
178
123
  padTop(n, symbol = ' ') {
124
+ if (n <= 0) return this.clone();
179
125
  const padding = symbol.repeat(this.width);
180
126
  return new Box([...new Array(n).fill(padding), ...this.box], true);
181
127
  }
182
128
 
183
- /** Pads the box on the bottom side.
184
- * @param {number} n - Bottom padding amount (number of rows).
185
- * @param {string} [symbol=' '] - The padding character.
186
- * @returns {Box} A new padded Box.
187
- */
188
129
  padBottom(n, symbol = ' ') {
130
+ if (n <= 0) return this.clone();
189
131
  const padding = symbol.repeat(this.width);
190
132
  return new Box([...this.box, ...new Array(n).fill(padding)], true);
191
133
  }
192
134
 
193
- /** Pads the box on all sides (CSS padding order: top, right, bottom, left).
194
- * - `pad(t)` → equal padding on all sides.
195
- * - `pad(t, r)` → top/bottom = t, left/right = r.
196
- * - `pad(t, r, b)` → top = t, left/right = r, bottom = b.
197
- * - `pad(t, r, b, l)` → individual padding.
198
- * @param {number} t - Top padding.
199
- * @param {number|string} [r] - Right padding or symbol.
200
- * @param {number|string} [b] - Bottom padding or symbol.
201
- * @param {number|string} [l] - Left padding or symbol.
202
- * @param {string} [symbol=' '] - The padding character.
203
- * @returns {Box} A new padded Box.
204
- */
205
135
  pad(t, r, b, l, symbol = ' ') {
206
136
  // implemented the CSS padding order
207
137
  if (typeof r != 'number') {
@@ -220,11 +150,6 @@ export class Box {
220
150
 
221
151
  // removing
222
152
 
223
- /** Removes rows from the box.
224
- * @param {number} y - The starting row index.
225
- * @param {number} n - The number of rows to remove.
226
- * @returns {Box} A new Box with rows removed.
227
- */
228
153
  removeRows(y, n) {
229
154
  const result = [...this.box];
230
155
  result.splice(y, n);
@@ -233,13 +158,6 @@ export class Box {
233
158
 
234
159
  // stack
235
160
 
236
- /** Stacks another box below this one.
237
- * @param {import('./strings.js').StringsInput} box - The box to add at the bottom.
238
- * @param {object} [options] - Options.
239
- * @param {string} [options.symbol=' '] - The padding character for width alignment.
240
- * @param {'left'|'l'|'right'|'r'|'center'|'c'} [options.align='left'] - Horizontal alignment if widths differ.
241
- * @returns {Box} A new combined Box.
242
- */
243
161
  addBottom(box, {symbol = ' ', align = 'left'} = {}) {
244
162
  let a = this,
245
163
  b = toBox(box);
@@ -267,13 +185,6 @@ export class Box {
267
185
  return new Box([...a.box, ...b.box], true);
268
186
  }
269
187
 
270
- /** Stacks another box to the right of this one.
271
- * @param {import('./strings.js').StringsInput} box - The box to add on the right.
272
- * @param {object} [options] - Options.
273
- * @param {string} [options.symbol=' '] - The padding character for height alignment.
274
- * @param {'top'|'t'|'bottom'|'b'|'center'|'c'} [options.align='top'] - Vertical alignment if heights differ.
275
- * @returns {Box} A new combined Box.
276
- */
277
188
  addRight(box, {symbol = ' ', align = 'top'} = {}) {
278
189
  box = toBox(box);
279
190
  const ah = this.height,
@@ -284,24 +195,19 @@ export class Box {
284
195
  true
285
196
  );
286
197
 
287
- let t = 0,
288
- b = 0;
198
+ let t = 0;
289
199
  const diff = Math.abs(ah - bh);
290
200
  switch (align) {
291
201
  case 'top':
292
202
  case 't':
293
203
  t = 0;
294
- b = diff;
295
204
  break;
296
205
  case 'bottom':
297
206
  case 'b':
298
207
  t = diff;
299
- b = 0;
300
208
  break;
301
209
  default: // center
302
- const half = diff >> 1;
303
- t = half;
304
- b = half + (diff & 1 ? 1 : 0);
210
+ t = diff >> 1;
305
211
  break;
306
212
  }
307
213
 
@@ -336,9 +242,6 @@ export class Box {
336
242
 
337
243
  // flipping
338
244
 
339
- /** Flips the box vertically (reverses the row order).
340
- * @returns {Box} A new vertically flipped Box.
341
- */
342
245
  flipV() {
343
246
  return new Box(this.box.toReversed(), true);
344
247
  }
@@ -346,9 +249,6 @@ export class Box {
346
249
 
347
250
  addAlias(Box, 'toBox', 'clone');
348
251
 
349
- /** Alias for `Box.make()`. Converts its argument to a Box.
350
- * @type {typeof Box.make}
351
- */
352
252
  export const toBox = Box.make;
353
253
 
354
254
  export default Box;
@@ -1,12 +1,6 @@
1
1
  import {drawRow} from './block-frac.js';
2
2
  import drawGroupedChart from './draw-grouped.js';
3
3
 
4
- /** Draws a complete fractional block grouped bar chart.
5
- * @param {any[]} values - Chart data.
6
- * @param {number} width - Available width.
7
- * @param {object} [options] - Options.
8
- * @returns {string[]} Array of strings representing the chart.
9
- */
10
4
  export const drawChart = drawGroupedChart(drawRow);
11
5
 
12
6
  export default drawChart;
@@ -8,13 +8,6 @@ import {drawRealHeightBlock} from '../../draw-block-frac.js';
8
8
  // data = [datum]
9
9
  // datum = {value, colorState, symbol, state}
10
10
 
11
- /** Draws a single stacked bar row using fractional block characters.
12
- * @param {object[]} data - Normalized data series.
13
- * @param {number} width - Total width.
14
- * @param {number} maxValue - Maximum value for scaling.
15
- * @param {object} [options] - Options including `reverse`, `drawEmptyBorder`, `rectSize`, `initState`.
16
- * @returns {string[]} The drawn row lines.
17
- */
18
11
  export const drawRow = (data, width, maxValue, options = {}) => {
19
12
  const {reverse, drawEmptyBorder, initState = {}} = options,
20
13
  rectSize = Math.max(0, options.rectSize ?? 0.5),
@@ -28,7 +21,7 @@ export const drawRow = (data, width, maxValue, options = {}) => {
28
21
  true
29
22
  );
30
23
  }),
31
- result = new Array(blocks[0].box.length).fill('');
24
+ result = blocks.length ? new Array(blocks[0].box.length).fill('') : [];
32
25
  if (reverse) blocks.reverse();
33
26
  for (const block of blocks) {
34
27
  for (let i = 0; i < block.box.length; ++i) {
@@ -38,12 +31,6 @@ export const drawRow = (data, width, maxValue, options = {}) => {
38
31
  return result.map(line => optimize(line));
39
32
  };
40
33
 
41
- /** Draws a complete fractional block stacked bar chart.
42
- * @param {any[]} values - Chart data.
43
- * @param {number} width - Available width.
44
- * @param {object} [options] - Options.
45
- * @returns {string[]} Array of strings representing the chart.
46
- */
47
34
  export const drawChart = drawStackedChart(drawRow);
48
35
 
49
36
  export default drawChart;
@@ -1,12 +1,6 @@
1
1
  import {drawRow} from './block.js';
2
2
  import drawGroupedChart from './draw-grouped.js';
3
3
 
4
- /** Draws a complete block grouped bar chart.
5
- * @param {any[]} values - Chart data.
6
- * @param {number} width - Available width.
7
- * @param {object} [options] - Options.
8
- * @returns {string[]} Array of strings representing the chart.
9
- */
10
4
  export const drawChart = drawGroupedChart(drawRow);
11
5
 
12
6
  export default drawChart;
@@ -9,13 +9,6 @@ import defaultBlockTheme from '../../themes/blocks/unicode-half.js';
9
9
  // data = [datum]
10
10
  // datum = {value, colorState, symbol, state}
11
11
 
12
- /** Draws a single stacked bar row using block-drawing characters.
13
- * @param {object[]} data - Normalized data series.
14
- * @param {number} width - Total width.
15
- * @param {number} maxValue - Maximum value for scaling.
16
- * @param {object} [options] - Options including `reverse`, `blockTheme`, `rectSize`, `initState`.
17
- * @returns {string[]} The drawn row lines.
18
- */
19
12
  export const drawRow = (data, width, maxValue, options = {}) => {
20
13
  const {reverse, blockTheme = defaultBlockTheme, rectSize = 0, initState = {}} = options,
21
14
  sizes = allocateSizes(data, maxValue, width),
@@ -35,7 +28,7 @@ export const drawRow = (data, width, maxValue, options = {}) => {
35
28
  true
36
29
  );
37
30
  }),
38
- result = new Array(blocks[0].box.length).fill('');
31
+ result = blocks.length ? new Array(blocks[0].box.length).fill('') : [];
39
32
  if (reverse) blocks.reverse();
40
33
  for (const block of blocks) {
41
34
  for (let i = 0; i < block.box.length; ++i) {
@@ -45,12 +38,6 @@ export const drawRow = (data, width, maxValue, options = {}) => {
45
38
  return result.map(line => optimize(line));
46
39
  };
47
40
 
48
- /** Draws a complete block stacked bar chart.
49
- * @param {any[]} values - Chart data.
50
- * @param {number} width - Available width.
51
- * @param {object} [options] - Block bar options.
52
- * @returns {string[]} Array of strings representing the chart.
53
- */
54
41
  export const drawChart = drawStackedChart(drawRow);
55
42
 
56
43
  export default drawChart;
@@ -1,10 +1,6 @@
1
1
  import defaultTheme from '../themes/default.js';
2
2
  import {normalizeData} from '../utils.js';
3
3
 
4
- /** Creates a grouped bar chart drawing function from a row-drawing function.
5
- * @param {Function} drawRow - Function `(data, width, maxValue, options) => string|string[]`.
6
- * @returns {Function} Chart drawing function `(values, width, options) => string[]`.
7
- */
8
4
  export const drawChart =
9
5
  drawRow =>
10
6
  (values, width, options = {}) => {
@@ -1,10 +1,6 @@
1
1
  import defaultTheme from '../themes/default.js';
2
2
  import {normalizeData, sumValues} from '../utils.js';
3
3
 
4
- /** Creates a stacked bar chart drawing function from a row-drawing function.
5
- * @param {Function} drawRow - Function `(data, width, maxValue, options) => string|string[]`.
6
- * @returns {Function} Chart drawing function `(values, width, options) => string[]`.
7
- */
8
4
  export const drawChart =
9
5
  drawRow =>
10
6
  (values, width, options = {}) => {
@@ -7,14 +7,8 @@ import drawGroupedChart from './draw-grouped.js';
7
7
  // data = [datum]
8
8
  // datum = {value, colorState, symbol, state}
9
9
 
10
- /** Draws a single grouped bar row using fractional width block characters.
11
- * @param {object[]} data - Normalized data series.
12
- * @param {number} width - Total width.
13
- * @param {number} maxValue - Maximum value for scaling.
14
- * @param {object} [options] - Options including `reverse`, `rectSize`, `initState`.
15
- * @returns {string[]} The drawn row lines.
16
- */
17
10
  export const drawRow = (data, width, maxValue, options = {}) => {
11
+ if (!maxValue) maxValue = 1;
18
12
  const {reverse, rectSize = 1, initState = {}} = options,
19
13
  blocks = data.map(datum => {
20
14
  if (!datum) return Box.makeBlank(0, rectSize);
@@ -25,7 +19,7 @@ export const drawRow = (data, width, maxValue, options = {}) => {
25
19
  true
26
20
  );
27
21
  }),
28
- result = new Array(blocks[0].box.length).fill('');
22
+ result = blocks.length ? new Array(blocks[0].box.length).fill('') : [];
29
23
  if (reverse) blocks.reverse();
30
24
  for (const block of blocks) {
31
25
  for (let i = 0; i < block.box.length; ++i) {
@@ -35,12 +29,6 @@ export const drawRow = (data, width, maxValue, options = {}) => {
35
29
  return result.map(line => optimize(line));
36
30
  };
37
31
 
38
- /** Draws a complete fractional grouped bar chart.
39
- * @param {any[]} values - Chart data.
40
- * @param {number} width - Available width.
41
- * @param {object} [options] - Options.
42
- * @returns {string[]} Array of strings representing the chart.
43
- */
44
32
  export const drawChart = drawGroupedChart(drawRow);
45
33
 
46
34
  export default drawChart;
@@ -1,12 +1,6 @@
1
1
  import {drawRow} from './plain.js';
2
2
  import drawGroupedChart from './draw-grouped.js';
3
3
 
4
- /** Draws a complete plain grouped bar chart.
5
- * @param {any[]} values - Chart data.
6
- * @param {number} width - Available width.
7
- * @param {object} [options] - Options.
8
- * @returns {string[]} Array of strings representing the chart.
9
- */
10
4
  export const drawChart = drawGroupedChart(drawRow);
11
5
 
12
6
  export default drawChart;
@@ -10,13 +10,6 @@ import defaultTheme from '../themes/default.js';
10
10
 
11
11
  const defaultSymbol = vBlocks8th[7];
12
12
 
13
- /** Default draw function for a single bar item.
14
- * @param {object} datum - Data item with `value`, `colorState`, `symbol`, `state`.
15
- * @param {number} size - Allocated size in characters.
16
- * @param {object} _ - Context (index, data, sizes, etc.).
17
- * @param {object} options - Draw options.
18
- * @returns {string} Styled string.
19
- */
20
13
  export const defaultDrawItem = (datum, size, _, {initState = {}}) =>
21
14
  datum
22
15
  ? style
@@ -24,15 +17,8 @@ export const defaultDrawItem = (datum, size, _, {initState = {}}) =>
24
17
  .addState(datum.colorState || {})
25
18
  .addState(datum.state || {})
26
19
  .text((datum.symbol || defaultSymbol).repeat(size))
27
- : '';
20
+ : ' '.repeat(size);
28
21
 
29
- /** Draws a bar item with a text label instead of a filled symbol.
30
- * @param {object} datum - Data item with `label`, `symbol`, `colorState`, `state`.
31
- * @param {number} size - Allocated size.
32
- * @param {object} _ - Context.
33
- * @param {object} options - Draw options including `reverse`, `truncate`, `useEllipsis`.
34
- * @returns {string} Styled string.
35
- */
36
22
  export const drawItemLabel = (datum, size, _, {reverse, truncate, useEllipsis = true, initState = {}}) => {
37
23
  if (!datum) return '';
38
24
  const symbol = datum.symbol || ' ';
@@ -51,13 +37,6 @@ export const drawItemLabel = (datum, size, _, {reverse, truncate, useEllipsis =
51
37
  .text(label);
52
38
  };
53
39
 
54
- /** Draws a single stacked bar row.
55
- * @param {object[]} data - Normalized data series.
56
- * @param {number} width - Total width.
57
- * @param {number} maxValue - Maximum value for scaling.
58
- * @param {object} [options] - Options including `drawItem`, `rectSize`, `theme`, `initState`, `reverse`.
59
- * @returns {string|string[]} The drawn row(s).
60
- */
61
40
  export const drawRow = (data, width, maxValue, options = {}) => {
62
41
  const {drawItem = defaultDrawItem, rectSize = 0, theme = defaultTheme, initState, reverse} = options,
63
42
  {symbol = ' ', state = null, colorState} = theme?.empty || {},
@@ -79,12 +58,6 @@ export const drawRow = (data, width, maxValue, options = {}) => {
79
58
  return new Array(rectSize).fill(row);
80
59
  };
81
60
 
82
- /** Draws a complete plain stacked bar chart.
83
- * @param {any[]} values - Chart data.
84
- * @param {number} width - Available width.
85
- * @param {object} [options] - Bar options.
86
- * @returns {string[]} Array of strings representing the chart.
87
- */
88
61
  export const drawChart = drawStackedChart(drawRow);
89
62
 
90
63
  export default drawChart;
@@ -1,12 +1,6 @@
1
1
  import {drawColumn} from './block-frac.js';
2
2
  import drawGroupedChart from './draw-grouped.js';
3
3
 
4
- /** Draws a complete fractional block grouped column chart.
5
- * @param {any[]} values - Chart data.
6
- * @param {number} width - Available height.
7
- * @param {object} [options] - Options.
8
- * @returns {string[]} Array of strings representing the chart.
9
- */
10
4
  export const drawChart = drawGroupedChart(drawColumn);
11
5
 
12
6
  export default drawChart;
@@ -8,13 +8,6 @@ import {drawRealWidthBlock} from '../../draw-block-frac.js';
8
8
  // data = [datum]
9
9
  // datum = {value, colorState, symbol, state}
10
10
 
11
- /** Draws a single stacked column using fractional block characters.
12
- * @param {object[]} data - Normalized data series.
13
- * @param {number} width - Total height.
14
- * @param {number} maxValue - Maximum value for scaling.
15
- * @param {object} [options] - Options including `reverse`, `drawEmptyBorder`, `rectSize`, `initState`.
16
- * @returns {string[]} The drawn column lines.
17
- */
18
11
  export const drawColumn = (data, width, maxValue, options = {}) => {
19
12
  const {reverse, drawEmptyBorder, initState} = options,
20
13
  rectSize = Math.max(0, options.rectSize ?? 0.5),
@@ -32,12 +25,6 @@ export const drawColumn = (data, width, maxValue, options = {}) => {
32
25
  return result.map(line => optimize(line));
33
26
  };
34
27
 
35
- /** Draws a complete fractional block stacked column chart.
36
- * @param {any[]} values - Chart data.
37
- * @param {number} width - Available height.
38
- * @param {object} [options] - Options.
39
- * @returns {string[]} Array of strings representing the chart.
40
- */
41
28
  export const drawChart = drawStackedChart(drawColumn);
42
29
 
43
30
  export default drawChart;
@@ -1,12 +1,6 @@
1
1
  import {drawColumn} from './block.js';
2
2
  import drawGroupedChart from './draw-grouped.js';
3
3
 
4
- /** Draws a complete block grouped column chart.
5
- * @param {any[]} values - Chart data.
6
- * @param {number} width - Available height.
7
- * @param {object} [options] - Options.
8
- * @returns {string[]} Array of strings representing the chart.
9
- */
10
4
  export const drawChart = drawGroupedChart(drawColumn);
11
5
 
12
6
  export default drawChart;
@@ -9,13 +9,6 @@ import defaultBlockTheme from '../../themes/blocks/unicode-half.js';
9
9
  // data = [datum]
10
10
  // datum = {value, colorState, symbol, state}
11
11
 
12
- /** Draws a single stacked column using block-drawing characters.
13
- * @param {object[]} data - Normalized data series.
14
- * @param {number} width - Total height.
15
- * @param {number} maxValue - Maximum value for scaling.
16
- * @param {object} [options] - Options including `reverse`, `blockTheme`, `rectSize`, `initState`.
17
- * @returns {string[]} The drawn column lines.
18
- */
19
12
  export const drawColumn = (data, width, maxValue, options = {}) => {
20
13
  const {reverse, blockTheme = defaultBlockTheme, rectSize = 0, initState = {}} = options,
21
14
  sizes = allocateSizes(data, maxValue, width),
@@ -39,12 +32,6 @@ export const drawColumn = (data, width, maxValue, options = {}) => {
39
32
  return result.map(line => optimize(line));
40
33
  };
41
34
 
42
- /** Draws a complete block stacked column chart.
43
- * @param {any[]} values - Chart data.
44
- * @param {number} width - Available height.
45
- * @param {object} [options] - Options.
46
- * @returns {string[]} Array of strings representing the chart.
47
- */
48
35
  export const drawChart = drawStackedChart(drawColumn);
49
36
 
50
37
  export default drawChart;
@@ -3,10 +3,6 @@ import {normalizeData} from '../utils.js';
3
3
  import Panel from '../../panel.js';
4
4
  import style from '../../style.js';
5
5
 
6
- /** Creates a grouped column chart drawing function from a column-drawing function.
7
- * @param {Function} drawColumn - Function `(data, width, maxValue, options) => string[]`.
8
- * @returns {Function} Chart drawing function `(values, width, options) => string[]`.
9
- */
10
6
  export const drawChart =
11
7
  drawColumn =>
12
8
  (values, width, options = {}) => {
@@ -20,7 +16,7 @@ export const drawChart =
20
16
  const newData = [];
21
17
  data.forEach(series => {
22
18
  newData.push(...series);
23
- if (series.length < maxSeriesLength) newData.push(...new Array(maxSeriesLength - series.length).fill(null));
19
+ for (let i = series.length; i < maxSeriesLength; ++i) newData.push(null);
24
20
  });
25
21
 
26
22
  const max =
@@ -3,10 +3,6 @@ import {normalizeData, sumValues} from '../utils.js';
3
3
  import Panel from '../../panel.js';
4
4
  import style from '../../style.js';
5
5
 
6
- /** Creates a stacked column chart drawing function from a column-drawing function.
7
- * @param {Function} drawColumn - Function `(data, width, maxValue, options) => string[]`.
8
- * @returns {Function} Chart drawing function `(values, width, options) => string[]`.
9
- */
10
6
  export const drawChart =
11
7
  drawColumn =>
12
8
  (values, width, options = {}) => {
@@ -7,14 +7,8 @@ import drawGroupedChart from './draw-grouped.js';
7
7
  // data = [datum]
8
8
  // datum = {value, colorState, symbol, state}
9
9
 
10
- /** Draws a single grouped column using fractional height block characters.
11
- * @param {object[]} data - Normalized data series.
12
- * @param {number} width - Total height.
13
- * @param {number} maxValue - Maximum value for scaling.
14
- * @param {object} [options] - Options including `reverse`, `rectSize`, `initState`.
15
- * @returns {string[]} The drawn column lines.
16
- */
17
10
  export const drawColumn = (data, width, maxValue, options = {}) => {
11
+ if (!maxValue) maxValue = 1;
18
12
  const {reverse, rectSize = 1, initState = {}} = options,
19
13
  blocks = data.map(datum => {
20
14
  if (!datum) return Box.makeBlank(rectSize, 0);
@@ -29,12 +23,6 @@ export const drawColumn = (data, width, maxValue, options = {}) => {
29
23
  return result.map(line => optimize(line));
30
24
  };
31
25
 
32
- /** Draws a complete fractional grouped column chart.
33
- * @param {any[]} values - Chart data.
34
- * @param {number} width - Available height.
35
- * @param {object} [options] - Options.
36
- * @returns {string[]} Array of strings representing the chart.
37
- */
38
26
  export const drawChart = drawGroupedChart(drawColumn);
39
27
 
40
28
  export default drawChart;
@@ -1,12 +1,6 @@
1
1
  import {drawColumn} from './plain.js';
2
2
  import drawGroupedChart from './draw-grouped.js';
3
3
 
4
- /** Draws a complete plain grouped column chart.
5
- * @param {any[]} values - Chart data.
6
- * @param {number} width - Available height.
7
- * @param {object} [options] - Options.
8
- * @returns {string[]} Array of strings representing the chart.
9
- */
10
4
  export const drawChart = drawGroupedChart(drawColumn);
11
5
 
12
6
  export default drawChart;