console-toolkit 1.2.8 → 1.2.10
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 +70 -25
- package/package.json +26 -6
- package/src/alphanumeric/arrows.d.ts +48 -0
- package/src/alphanumeric/arrows.js +23 -0
- package/src/alphanumeric/fractions.d.ts +65 -0
- package/src/alphanumeric/fractions.js +49 -0
- package/src/alphanumeric/number-formatters.d.ts +91 -0
- package/src/alphanumeric/number-formatters.js +45 -1
- package/src/alphanumeric/roman.d.ts +15 -0
- package/src/alphanumeric/roman.js +12 -0
- package/src/alphanumeric/unicode-cultural-numbers.d.ts +65 -0
- package/src/alphanumeric/unicode-cultural-numbers.js +1 -0
- package/src/alphanumeric/unicode-letters.d.ts +32 -0
- package/src/alphanumeric/unicode-letters.js +8 -0
- package/src/alphanumeric/unicode-numbers.d.ts +44 -0
- package/src/alphanumeric/unicode-numbers.js +21 -0
- package/src/alphanumeric/utils.d.ts +45 -0
- package/src/alphanumeric/utils.js +26 -0
- package/src/ansi/csi.d.ts +141 -0
- package/src/ansi/csi.js +51 -2
- package/src/ansi/index.d.ts +26 -0
- package/src/ansi/sgr-constants.d.ts +173 -0
- package/src/ansi/sgr-state.d.ts +91 -0
- package/src/ansi/sgr-state.js +45 -0
- package/src/ansi/sgr.d.ts +587 -0
- package/src/ansi/sgr.js +426 -6
- package/src/box.d.ts +160 -0
- package/src/box.js +113 -12
- package/src/charts/bars/block-frac-grouped.d.ts +12 -0
- package/src/charts/bars/block-frac-grouped.js +6 -0
- package/src/charts/bars/block-frac.d.ts +34 -0
- package/src/charts/bars/block-frac.js +13 -0
- package/src/charts/bars/block-grouped.d.ts +12 -0
- package/src/charts/bars/block-grouped.js +6 -0
- package/src/charts/bars/block.d.ts +43 -0
- package/src/charts/bars/block.js +13 -0
- package/src/charts/bars/draw-grouped.d.ts +41 -0
- package/src/charts/bars/draw-grouped.js +4 -0
- package/src/charts/bars/draw-stacked.d.ts +47 -0
- package/src/charts/bars/draw-stacked.js +4 -0
- package/src/charts/bars/frac-grouped.d.ts +32 -0
- package/src/charts/bars/frac-grouped.js +13 -0
- package/src/charts/bars/plain-grouped.d.ts +12 -0
- package/src/charts/bars/plain-grouped.js +6 -0
- package/src/charts/bars/plain.d.ts +75 -0
- package/src/charts/bars/plain.js +27 -0
- package/src/charts/columns/block-frac-grouped.d.ts +12 -0
- package/src/charts/columns/block-frac-grouped.js +6 -0
- package/src/charts/columns/block-frac.d.ts +39 -0
- package/src/charts/columns/block-frac.js +13 -0
- package/src/charts/columns/block-grouped.d.ts +12 -0
- package/src/charts/columns/block-grouped.js +6 -0
- package/src/charts/columns/block.d.ts +43 -0
- package/src/charts/columns/block.js +13 -0
- package/src/charts/columns/draw-grouped.d.ts +41 -0
- package/src/charts/columns/draw-grouped.js +4 -0
- package/src/charts/columns/draw-stacked.d.ts +39 -0
- package/src/charts/columns/draw-stacked.js +4 -0
- package/src/charts/columns/frac-grouped.d.ts +37 -0
- package/src/charts/columns/frac-grouped.js +13 -0
- package/src/charts/columns/plain-grouped.d.ts +12 -0
- package/src/charts/columns/plain-grouped.js +6 -0
- package/src/charts/columns/plain.d.ts +32 -0
- package/src/charts/columns/plain.js +13 -0
- package/src/charts/themes/default.d.ts +6 -0
- package/src/charts/themes/default.js +1 -0
- package/src/charts/themes/rainbow-reversed.d.ts +6 -0
- package/src/charts/themes/rainbow-reversed.js +2 -1
- package/src/charts/themes/rainbow.d.ts +6 -0
- package/src/charts/themes/rainbow.js +1 -0
- package/src/charts/utils.d.ts +79 -0
- package/src/charts/utils.js +32 -4
- package/src/draw-block-frac.d.ts +16 -0
- package/src/draw-block-frac.js +14 -0
- package/src/draw-block.d.ts +53 -0
- package/src/draw-block.js +25 -1
- package/src/meta.d.ts +84 -0
- package/src/meta.js +64 -0
- package/src/output/show.d.ts +55 -0
- package/src/output/show.js +28 -0
- package/src/output/updater.d.ts +114 -0
- package/src/output/updater.js +58 -4
- package/src/output/writer.d.ts +87 -0
- package/src/output/writer.js +57 -5
- package/src/panel.d.ts +402 -0
- package/src/panel.js +219 -5
- package/src/plot/bitmap.d.ts +80 -0
- package/src/plot/bitmap.js +33 -4
- package/src/plot/draw-line.d.ts +13 -0
- package/src/plot/draw-line.js +8 -0
- package/src/plot/draw-rect.d.ts +13 -0
- package/src/plot/draw-rect.js +38 -30
- package/src/plot/index.d.ts +39 -0
- package/src/plot/index.js +22 -0
- package/src/plot/to-quads.d.ts +10 -0
- package/src/plot/to-quads.js +5 -0
- package/src/spinner/index.d.ts +4 -0
- package/src/spinner/index.js +0 -2
- package/src/spinner/spin.d.ts +13 -0
- package/src/spinner/spin.js +13 -2
- package/src/spinner/spinner.d.ts +69 -0
- package/src/spinner/spinner.js +30 -2
- package/src/spinner/spinners.d.ts +34 -0
- package/src/spinner/spinners.js +23 -9
- package/src/strings/clip.d.ts +21 -0
- package/src/strings/clip.js +10 -0
- package/src/strings/parse.d.ts +23 -0
- package/src/strings/parse.js +7 -0
- package/src/strings/split.d.ts +38 -0
- package/src/strings/split.js +15 -0
- package/src/strings.d.ts +44 -0
- package/src/strings.js +34 -4
- package/src/style.d.ts +462 -0
- package/src/style.js +58 -4
- package/src/symbols.d.ts +167 -0
- package/src/symbols.js +91 -7
- package/src/table/draw-borders.d.ts +38 -0
- package/src/table/draw-borders.js +10 -2
- package/src/table/index.d.ts +8 -0
- package/src/table/index.js +1 -0
- package/src/table/table.d.ts +234 -0
- package/src/table/table.js +59 -1
- package/src/themes/blocks/unicode-half.d.ts +6 -0
- package/src/themes/blocks/unicode-half.js +1 -0
- package/src/themes/blocks/unicode-thin.d.ts +6 -0
- package/src/themes/blocks/unicode-thin.js +1 -0
- package/src/themes/lines/ascii-compact.d.ts +6 -0
- package/src/themes/lines/ascii-compact.js +1 -0
- package/src/themes/lines/ascii-dots.d.ts +6 -0
- package/src/themes/lines/ascii-dots.js +1 -0
- package/src/themes/lines/ascii-girder.d.ts +6 -0
- package/src/themes/lines/ascii-girder.js +1 -0
- package/src/themes/lines/ascii-github.d.ts +6 -0
- package/src/themes/lines/ascii-github.js +1 -0
- package/src/themes/lines/ascii-reddit.d.ts +6 -0
- package/src/themes/lines/ascii-reddit.js +1 -0
- package/src/themes/lines/ascii-rounded.d.ts +6 -0
- package/src/themes/lines/ascii-rounded.js +1 -0
- package/src/themes/lines/ascii.d.ts +6 -0
- package/src/themes/lines/ascii.js +1 -0
- package/src/themes/lines/unicode-bold.d.ts +6 -0
- package/src/themes/lines/unicode-bold.js +1 -0
- package/src/themes/lines/unicode-rounded.d.ts +6 -0
- package/src/themes/lines/unicode-rounded.js +1 -0
- package/src/themes/lines/unicode.d.ts +6 -0
- package/src/themes/lines/unicode.js +1 -0
- package/src/themes/utils.d.ts +33 -0
- package/src/themes/utils.js +7 -0
- package/src/turtle/draw-line-art.d.ts +19 -0
- package/src/turtle/draw-line-art.js +7 -0
- package/src/turtle/draw-unicode.d.ts +19 -0
- package/src/turtle/draw-unicode.js +8 -0
- package/src/turtle/index.d.ts +21 -0
- package/src/turtle/index.js +8 -0
- package/src/turtle/turtle.d.ts +269 -0
- package/src/turtle/turtle.js +124 -4
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {ChartDatum, ChartDataInput, ChartTheme, DrawItemInfo} from '../utils.js';
|
|
2
|
+
import {SgrState} from '../../ansi/sgr-state.js';
|
|
3
|
+
|
|
4
|
+
/** Options for stacked bar/column charts. */
|
|
5
|
+
export interface StackedChartOptions {
|
|
6
|
+
/** Maximum value for scaling (default: auto). */
|
|
7
|
+
maxValue?: number;
|
|
8
|
+
/** Gap between rows in lines. */
|
|
9
|
+
gap?: number;
|
|
10
|
+
/** Chart theme. */
|
|
11
|
+
theme?: ChartTheme;
|
|
12
|
+
/** Custom draw function for individual items.
|
|
13
|
+
* @param datum - The chart data item or null.
|
|
14
|
+
* @param size - Allocated size in characters.
|
|
15
|
+
* @param info - Drawing info.
|
|
16
|
+
* @param options - Options.
|
|
17
|
+
* @returns The drawn string.
|
|
18
|
+
*/
|
|
19
|
+
drawItem?: (datum: ChartDatum | null, size: number, info: DrawItemInfo, options: StackedChartOptions) => string;
|
|
20
|
+
/** Size of each rectangle in characters. */
|
|
21
|
+
rectSize?: number;
|
|
22
|
+
/** Initial SGR state. */
|
|
23
|
+
initState?: SgrState | string | null;
|
|
24
|
+
/** If true, reverse the drawing direction. */
|
|
25
|
+
reverse?: boolean;
|
|
26
|
+
/** Additional custom options. */
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Function that draws a single row of a chart.
|
|
31
|
+
* @param data - Array of chart data items.
|
|
32
|
+
* @param width - Available width in characters.
|
|
33
|
+
* @param maxValue - Maximum value for scaling.
|
|
34
|
+
* @param options - Optional chart options.
|
|
35
|
+
* @returns The drawn row as a string or string array.
|
|
36
|
+
*/
|
|
37
|
+
type DrawRowFn = (data: ChartDatum[], width: number, maxValue: number, options?: StackedChartOptions) => string | string[];
|
|
38
|
+
|
|
39
|
+
/** Creates a stacked bar chart drawing function from a row-drawing function.
|
|
40
|
+
* @param drawRow - The row-drawing function.
|
|
41
|
+
* @returns A chart-drawing function.
|
|
42
|
+
*/
|
|
43
|
+
export function drawChart(
|
|
44
|
+
drawRow: DrawRowFn
|
|
45
|
+
): (values: ChartDataInput, width: number, options?: StackedChartOptions) => string[];
|
|
46
|
+
|
|
47
|
+
export default drawChart;
|
|
@@ -1,6 +1,10 @@
|
|
|
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
|
+
*/
|
|
4
8
|
export const drawChart =
|
|
5
9
|
drawRow =>
|
|
6
10
|
(values, width, options = {}) => {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {ChartDatum, ChartDataInput} from '../utils.js';
|
|
2
|
+
import {SgrState} from '../../ansi/sgr-state.js';
|
|
3
|
+
import {GroupedChartOptions} from './draw-grouped.js';
|
|
4
|
+
|
|
5
|
+
/** Options for fractional grouped bar charts. */
|
|
6
|
+
export interface FracGroupedBarOptions extends GroupedChartOptions {
|
|
7
|
+
/** Size of each rectangle in characters. */
|
|
8
|
+
rectSize?: number;
|
|
9
|
+
/** Initial SGR state. */
|
|
10
|
+
initState?: SgrState | string | null;
|
|
11
|
+
/** If true, reverse the drawing direction. */
|
|
12
|
+
reverse?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Draws a single grouped bar row using fractional width block characters.
|
|
16
|
+
* @param data - Chart data items.
|
|
17
|
+
* @param width - Available width.
|
|
18
|
+
* @param maxValue - Maximum value.
|
|
19
|
+
* @param options - Options.
|
|
20
|
+
* @returns Array of strings for the row.
|
|
21
|
+
*/
|
|
22
|
+
export function drawRow(data: ChartDatum[], width: number, maxValue: number, options?: FracGroupedBarOptions): string[];
|
|
23
|
+
|
|
24
|
+
/** Draws a complete fractional grouped bar chart.
|
|
25
|
+
* @param values - Chart data.
|
|
26
|
+
* @param width - Available width.
|
|
27
|
+
* @param options - Options.
|
|
28
|
+
* @returns Array of strings representing the chart.
|
|
29
|
+
*/
|
|
30
|
+
export function drawChart(values: ChartDataInput, width: number, options?: FracGroupedBarOptions): string[];
|
|
31
|
+
|
|
32
|
+
export default drawChart;
|
|
@@ -7,6 +7,13 @@ 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
|
+
*/
|
|
10
17
|
export const drawRow = (data, width, maxValue, options = {}) => {
|
|
11
18
|
const {reverse, rectSize = 1, initState = {}} = options,
|
|
12
19
|
blocks = data.map(datum => {
|
|
@@ -28,6 +35,12 @@ export const drawRow = (data, width, maxValue, options = {}) => {
|
|
|
28
35
|
return result.map(line => optimize(line));
|
|
29
36
|
};
|
|
30
37
|
|
|
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
|
+
*/
|
|
31
44
|
export const drawChart = drawGroupedChart(drawRow);
|
|
32
45
|
|
|
33
46
|
export default drawChart;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {ChartDataInput} from '../utils.js';
|
|
2
|
+
import {GroupedChartOptions} from './draw-grouped.js';
|
|
3
|
+
|
|
4
|
+
/** Draws a complete plain grouped bar chart.
|
|
5
|
+
* @param values - Chart data.
|
|
6
|
+
* @param width - Available width.
|
|
7
|
+
* @param options - Options.
|
|
8
|
+
* @returns Array of strings representing the chart.
|
|
9
|
+
*/
|
|
10
|
+
export function drawChart(values: ChartDataInput, width: number, options?: GroupedChartOptions): string[];
|
|
11
|
+
|
|
12
|
+
export default drawChart;
|
|
@@ -1,6 +1,12 @@
|
|
|
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
|
+
*/
|
|
4
10
|
export const drawChart = drawGroupedChart(drawRow);
|
|
5
11
|
|
|
6
12
|
export default drawChart;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {ChartDatum, ChartDataInput, DrawItemInfo} from '../utils.js';
|
|
2
|
+
import {SgrState} from '../../ansi/sgr-state.js';
|
|
3
|
+
import {StackedChartOptions} from './draw-stacked.js';
|
|
4
|
+
|
|
5
|
+
/** Options for plain bar charts. */
|
|
6
|
+
export interface PlainBarOptions extends StackedChartOptions {
|
|
7
|
+
/** Custom draw function for a single bar item.
|
|
8
|
+
* @param datum - The chart data item or null.
|
|
9
|
+
* @param size - Allocated size in characters.
|
|
10
|
+
* @param info - Drawing info.
|
|
11
|
+
* @param options - Options.
|
|
12
|
+
* @returns The drawn string.
|
|
13
|
+
*/
|
|
14
|
+
drawItem?: (datum: ChartDatum | null, size: number, info: DrawItemInfo, options: PlainBarOptions) => string;
|
|
15
|
+
/** Size of each rectangle in characters. */
|
|
16
|
+
rectSize?: number;
|
|
17
|
+
/** Initial SGR state. */
|
|
18
|
+
initState?: SgrState | string | null;
|
|
19
|
+
/** If true, reverse the drawing direction. */
|
|
20
|
+
reverse?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Default draw function for a single bar item.
|
|
24
|
+
* @param datum - The chart data item.
|
|
25
|
+
* @param size - Allocated size.
|
|
26
|
+
* @param info - Drawing info.
|
|
27
|
+
* @param options - Options.
|
|
28
|
+
* @returns The drawn string.
|
|
29
|
+
*/
|
|
30
|
+
export function defaultDrawItem(datum: ChartDatum | null, size: number, info: DrawItemInfo, options: PlainBarOptions): string;
|
|
31
|
+
|
|
32
|
+
/** Options for `drawItemLabel()`. */
|
|
33
|
+
export interface DrawItemLabelOptions {
|
|
34
|
+
/** If true, reverse the drawing direction. */
|
|
35
|
+
reverse?: boolean;
|
|
36
|
+
/** If true, truncate the label to fit. */
|
|
37
|
+
truncate?: boolean;
|
|
38
|
+
/** If true, use ellipsis when truncating. */
|
|
39
|
+
useEllipsis?: boolean;
|
|
40
|
+
/** Initial SGR state. */
|
|
41
|
+
initState?: SgrState | string | null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Draws a bar item with a text label.
|
|
45
|
+
* @param datum - The chart data item.
|
|
46
|
+
* @param size - Allocated size.
|
|
47
|
+
* @param info - Drawing info.
|
|
48
|
+
* @param options - Label options.
|
|
49
|
+
* @returns The drawn string.
|
|
50
|
+
*/
|
|
51
|
+
export function drawItemLabel(datum: ChartDatum | null, size: number, info: DrawItemInfo, options: DrawItemLabelOptions): string;
|
|
52
|
+
|
|
53
|
+
/** Draws a single stacked bar row.
|
|
54
|
+
* @param data - Array of chart data items.
|
|
55
|
+
* @param width - Available width.
|
|
56
|
+
* @param maxValue - Maximum value for scaling.
|
|
57
|
+
* @param options - Bar options.
|
|
58
|
+
* @returns The drawn row as a string or string array.
|
|
59
|
+
*/
|
|
60
|
+
export function drawRow(
|
|
61
|
+
data: ChartDatum[],
|
|
62
|
+
width: number,
|
|
63
|
+
maxValue: number,
|
|
64
|
+
options?: PlainBarOptions
|
|
65
|
+
): string | string[];
|
|
66
|
+
|
|
67
|
+
/** Draws a complete plain stacked bar chart.
|
|
68
|
+
* @param values - Chart data.
|
|
69
|
+
* @param width - Available width.
|
|
70
|
+
* @param options - Bar options.
|
|
71
|
+
* @returns Array of strings representing the chart.
|
|
72
|
+
*/
|
|
73
|
+
export function drawChart(values: ChartDataInput, width: number, options?: PlainBarOptions): string[];
|
|
74
|
+
|
|
75
|
+
export default drawChart;
|
package/src/charts/bars/plain.js
CHANGED
|
@@ -10,6 +10,13 @@ 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
|
+
*/
|
|
13
20
|
export const defaultDrawItem = (datum, size, _, {initState = {}}) =>
|
|
14
21
|
datum
|
|
15
22
|
? style
|
|
@@ -19,6 +26,13 @@ export const defaultDrawItem = (datum, size, _, {initState = {}}) =>
|
|
|
19
26
|
.text((datum.symbol || defaultSymbol).repeat(size))
|
|
20
27
|
: '';
|
|
21
28
|
|
|
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
|
+
*/
|
|
22
36
|
export const drawItemLabel = (datum, size, _, {reverse, truncate, useEllipsis = true, initState = {}}) => {
|
|
23
37
|
if (!datum) return '';
|
|
24
38
|
const symbol = datum.symbol || ' ';
|
|
@@ -37,6 +51,13 @@ export const drawItemLabel = (datum, size, _, {reverse, truncate, useEllipsis =
|
|
|
37
51
|
.text(label);
|
|
38
52
|
};
|
|
39
53
|
|
|
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
|
+
*/
|
|
40
61
|
export const drawRow = (data, width, maxValue, options = {}) => {
|
|
41
62
|
const {drawItem = defaultDrawItem, rectSize = 0, theme = defaultTheme, initState, reverse} = options,
|
|
42
63
|
{symbol = ' ', state = null, colorState} = theme?.empty || {},
|
|
@@ -58,6 +79,12 @@ export const drawRow = (data, width, maxValue, options = {}) => {
|
|
|
58
79
|
return new Array(rectSize).fill(row);
|
|
59
80
|
};
|
|
60
81
|
|
|
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
|
+
*/
|
|
61
88
|
export const drawChart = drawStackedChart(drawRow);
|
|
62
89
|
|
|
63
90
|
export default drawChart;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {ChartDataInput} from '../utils.js';
|
|
2
|
+
import {GroupedColumnChartOptions} from './draw-grouped.js';
|
|
3
|
+
|
|
4
|
+
/** Draws a complete fractional block grouped column chart.
|
|
5
|
+
* @param values - Chart data.
|
|
6
|
+
* @param width - Available width.
|
|
7
|
+
* @param options - Options.
|
|
8
|
+
* @returns Array of strings representing the chart.
|
|
9
|
+
*/
|
|
10
|
+
export function drawChart(values: ChartDataInput, width: number, options?: GroupedColumnChartOptions): string[];
|
|
11
|
+
|
|
12
|
+
export default drawChart;
|
|
@@ -1,6 +1,12 @@
|
|
|
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
|
+
*/
|
|
4
10
|
export const drawChart = drawGroupedChart(drawColumn);
|
|
5
11
|
|
|
6
12
|
export default drawChart;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {ChartDatum, ChartDataInput} from '../utils.js';
|
|
2
|
+
import {SgrState} from '../../ansi/sgr-state.js';
|
|
3
|
+
import {StackedColumnChartOptions} from './draw-stacked.js';
|
|
4
|
+
|
|
5
|
+
/** Options for fractional block column charts. */
|
|
6
|
+
export interface BlockFracColumnOptions extends StackedColumnChartOptions {
|
|
7
|
+
/** Size of each rectangle in characters. */
|
|
8
|
+
rectSize?: number;
|
|
9
|
+
/** Initial SGR state. */
|
|
10
|
+
initState?: SgrState | string | null;
|
|
11
|
+
/** If true, reverse the drawing direction. */
|
|
12
|
+
reverse?: boolean;
|
|
13
|
+
/** If true, draw an empty border when fractional part is 0. */
|
|
14
|
+
drawEmptyBorder?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Draws a single stacked column using fractional block characters.
|
|
18
|
+
* @param data - Chart data items.
|
|
19
|
+
* @param width - Available width.
|
|
20
|
+
* @param maxValue - Maximum value.
|
|
21
|
+
* @param options - Options.
|
|
22
|
+
* @returns Array of strings for the column.
|
|
23
|
+
*/
|
|
24
|
+
export function drawColumn(
|
|
25
|
+
data: ChartDatum[],
|
|
26
|
+
width: number,
|
|
27
|
+
maxValue: number,
|
|
28
|
+
options?: BlockFracColumnOptions
|
|
29
|
+
): string[];
|
|
30
|
+
|
|
31
|
+
/** Draws a complete fractional block stacked column chart.
|
|
32
|
+
* @param values - Chart data.
|
|
33
|
+
* @param width - Available width.
|
|
34
|
+
* @param options - Options.
|
|
35
|
+
* @returns Array of strings representing the chart.
|
|
36
|
+
*/
|
|
37
|
+
export function drawChart(values: ChartDataInput, width: number, options?: BlockFracColumnOptions): string[];
|
|
38
|
+
|
|
39
|
+
export default drawChart;
|
|
@@ -8,6 +8,13 @@ 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
|
+
*/
|
|
11
18
|
export const drawColumn = (data, width, maxValue, options = {}) => {
|
|
12
19
|
const {reverse, drawEmptyBorder, initState} = options,
|
|
13
20
|
rectSize = Math.max(0, options.rectSize ?? 0.5),
|
|
@@ -25,6 +32,12 @@ export const drawColumn = (data, width, maxValue, options = {}) => {
|
|
|
25
32
|
return result.map(line => optimize(line));
|
|
26
33
|
};
|
|
27
34
|
|
|
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
|
+
*/
|
|
28
41
|
export const drawChart = drawStackedChart(drawColumn);
|
|
29
42
|
|
|
30
43
|
export default drawChart;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {ChartDataInput} from '../utils.js';
|
|
2
|
+
import {GroupedColumnChartOptions} from './draw-grouped.js';
|
|
3
|
+
|
|
4
|
+
/** Draws a complete block grouped column chart.
|
|
5
|
+
* @param values - Chart data.
|
|
6
|
+
* @param width - Available width.
|
|
7
|
+
* @param options - Options.
|
|
8
|
+
* @returns Array of strings representing the chart.
|
|
9
|
+
*/
|
|
10
|
+
export function drawChart(values: ChartDataInput, width: number, options?: GroupedColumnChartOptions): string[];
|
|
11
|
+
|
|
12
|
+
export default drawChart;
|
|
@@ -1,6 +1,12 @@
|
|
|
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
|
+
*/
|
|
4
10
|
export const drawChart = drawGroupedChart(drawColumn);
|
|
5
11
|
|
|
6
12
|
export default drawChart;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {ChartDatum, ChartDataInput} from '../utils.js';
|
|
2
|
+
import {SgrState} from '../../ansi/sgr-state.js';
|
|
3
|
+
import {LineTheme} from '../../themes/utils.js';
|
|
4
|
+
import {StackedColumnChartOptions} from './draw-stacked.js';
|
|
5
|
+
|
|
6
|
+
/** Options for block column charts. */
|
|
7
|
+
export interface BlockColumnOptions extends StackedColumnChartOptions {
|
|
8
|
+
/** Block theme for drawing. */
|
|
9
|
+
blockTheme?: LineTheme;
|
|
10
|
+
/** Size of each rectangle in characters. */
|
|
11
|
+
rectSize?: number;
|
|
12
|
+
/** Initial SGR state. */
|
|
13
|
+
initState?: SgrState | string | null;
|
|
14
|
+
/** If true, reverse the drawing direction. */
|
|
15
|
+
reverse?: boolean;
|
|
16
|
+
/** If set, draw the top border. */
|
|
17
|
+
t?: number;
|
|
18
|
+
/** If set, draw the bottom border. */
|
|
19
|
+
b?: number;
|
|
20
|
+
/** If set, draw the left border. */
|
|
21
|
+
l?: number;
|
|
22
|
+
/** If set, draw the right border. */
|
|
23
|
+
r?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Draws a single stacked column using block-drawing characters.
|
|
27
|
+
* @param data - Chart data items.
|
|
28
|
+
* @param width - Available width.
|
|
29
|
+
* @param maxValue - Maximum value.
|
|
30
|
+
* @param options - Options.
|
|
31
|
+
* @returns Array of strings for the column.
|
|
32
|
+
*/
|
|
33
|
+
export function drawColumn(data: ChartDatum[], width: number, maxValue: number, options?: BlockColumnOptions): string[];
|
|
34
|
+
|
|
35
|
+
/** Draws a complete block stacked column chart.
|
|
36
|
+
* @param values - Chart data.
|
|
37
|
+
* @param width - Available width.
|
|
38
|
+
* @param options - Options.
|
|
39
|
+
* @returns Array of strings representing the chart.
|
|
40
|
+
*/
|
|
41
|
+
export function drawChart(values: ChartDataInput, width: number, options?: BlockColumnOptions): string[];
|
|
42
|
+
|
|
43
|
+
export default drawChart;
|
|
@@ -9,6 +9,13 @@ 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
|
+
*/
|
|
12
19
|
export const drawColumn = (data, width, maxValue, options = {}) => {
|
|
13
20
|
const {reverse, blockTheme = defaultBlockTheme, rectSize = 0, initState = {}} = options,
|
|
14
21
|
sizes = allocateSizes(data, maxValue, width),
|
|
@@ -32,6 +39,12 @@ export const drawColumn = (data, width, maxValue, options = {}) => {
|
|
|
32
39
|
return result.map(line => optimize(line));
|
|
33
40
|
};
|
|
34
41
|
|
|
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
|
+
*/
|
|
35
48
|
export const drawChart = drawStackedChart(drawColumn);
|
|
36
49
|
|
|
37
50
|
export default drawChart;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {ChartDatum, ChartDataInput, ChartTheme} from '../utils.js';
|
|
2
|
+
import {SgrState} from '../../ansi/sgr-state.js';
|
|
3
|
+
|
|
4
|
+
/** Options for grouped column charts. */
|
|
5
|
+
export interface GroupedColumnChartOptions {
|
|
6
|
+
/** Maximum value for scaling (default: auto). */
|
|
7
|
+
maxValue?: number;
|
|
8
|
+
/** Gap between groups in characters. */
|
|
9
|
+
groupGap?: number;
|
|
10
|
+
/** Gap between items within a group. */
|
|
11
|
+
gap?: number;
|
|
12
|
+
/** Chart theme. */
|
|
13
|
+
theme?: ChartTheme;
|
|
14
|
+
/** Size of each rectangle in characters. */
|
|
15
|
+
rectSize?: number;
|
|
16
|
+
/** Initial SGR state. */
|
|
17
|
+
initState?: SgrState | string | null;
|
|
18
|
+
/** If true, reverse the drawing direction. */
|
|
19
|
+
reverse?: boolean;
|
|
20
|
+
/** Additional custom options. */
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Function that draws a single column of a chart.
|
|
25
|
+
* @param data - Array of chart data items.
|
|
26
|
+
* @param width - Available width in characters.
|
|
27
|
+
* @param maxValue - Maximum value for scaling.
|
|
28
|
+
* @param options - Optional chart options.
|
|
29
|
+
* @returns Array of strings for the column.
|
|
30
|
+
*/
|
|
31
|
+
type DrawColumnFn = (data: ChartDatum[], width: number, maxValue: number, options?: GroupedColumnChartOptions) => string[];
|
|
32
|
+
|
|
33
|
+
/** Creates a grouped column chart drawing function from a column-drawing function.
|
|
34
|
+
* @param drawColumn - The column-drawing function.
|
|
35
|
+
* @returns A chart-drawing function.
|
|
36
|
+
*/
|
|
37
|
+
export function drawChart(
|
|
38
|
+
drawColumn: DrawColumnFn
|
|
39
|
+
): (values: ChartDataInput, width: number, options?: GroupedColumnChartOptions) => string[];
|
|
40
|
+
|
|
41
|
+
export default drawChart;
|
|
@@ -3,6 +3,10 @@ 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
|
+
*/
|
|
6
10
|
export const drawChart =
|
|
7
11
|
drawColumn =>
|
|
8
12
|
(values, width, options = {}) => {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {ChartDatum, ChartDataInput, ChartTheme} from '../utils.js';
|
|
2
|
+
import {SgrState} from '../../ansi/sgr-state.js';
|
|
3
|
+
|
|
4
|
+
/** Options for stacked column charts. */
|
|
5
|
+
export interface StackedColumnChartOptions {
|
|
6
|
+
/** Maximum value for scaling (default: auto). */
|
|
7
|
+
maxValue?: number;
|
|
8
|
+
/** Gap between columns in characters. */
|
|
9
|
+
gap?: number;
|
|
10
|
+
/** Chart theme. */
|
|
11
|
+
theme?: ChartTheme;
|
|
12
|
+
/** Size of each rectangle in characters. */
|
|
13
|
+
rectSize?: number;
|
|
14
|
+
/** Initial SGR state. */
|
|
15
|
+
initState?: SgrState | string | null;
|
|
16
|
+
/** If true, reverse the drawing direction. */
|
|
17
|
+
reverse?: boolean;
|
|
18
|
+
/** Additional custom options. */
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Function that draws a single column of a chart.
|
|
23
|
+
* @param data - Array of chart data items.
|
|
24
|
+
* @param width - Available width in characters.
|
|
25
|
+
* @param maxValue - Maximum value for scaling.
|
|
26
|
+
* @param options - Optional chart options.
|
|
27
|
+
* @returns Array of strings for the column.
|
|
28
|
+
*/
|
|
29
|
+
type DrawColumnFn = (data: ChartDatum[], width: number, maxValue: number, options?: StackedColumnChartOptions) => string[];
|
|
30
|
+
|
|
31
|
+
/** Creates a stacked column chart drawing function from a column-drawing function.
|
|
32
|
+
* @param drawColumn - The column-drawing function.
|
|
33
|
+
* @returns A chart-drawing function.
|
|
34
|
+
*/
|
|
35
|
+
export function drawChart(
|
|
36
|
+
drawColumn: DrawColumnFn
|
|
37
|
+
): (values: ChartDataInput, width: number, options?: StackedColumnChartOptions) => string[];
|
|
38
|
+
|
|
39
|
+
export default drawChart;
|
|
@@ -3,6 +3,10 @@ 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
|
+
*/
|
|
6
10
|
export const drawChart =
|
|
7
11
|
drawColumn =>
|
|
8
12
|
(values, width, options = {}) => {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {ChartDatum, ChartDataInput} from '../utils.js';
|
|
2
|
+
import {SgrState} from '../../ansi/sgr-state.js';
|
|
3
|
+
import {GroupedColumnChartOptions} from './draw-grouped.js';
|
|
4
|
+
|
|
5
|
+
/** Options for fractional grouped column charts. */
|
|
6
|
+
export interface FracGroupedColumnOptions extends GroupedColumnChartOptions {
|
|
7
|
+
/** Size of each rectangle in characters. */
|
|
8
|
+
rectSize?: number;
|
|
9
|
+
/** Initial SGR state. */
|
|
10
|
+
initState?: SgrState | string | null;
|
|
11
|
+
/** If true, reverse the drawing direction. */
|
|
12
|
+
reverse?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Draws a single grouped column using fractional height block characters.
|
|
16
|
+
* @param data - Chart data items.
|
|
17
|
+
* @param width - Available width.
|
|
18
|
+
* @param maxValue - Maximum value.
|
|
19
|
+
* @param options - Options.
|
|
20
|
+
* @returns Array of strings for the column.
|
|
21
|
+
*/
|
|
22
|
+
export function drawColumn(
|
|
23
|
+
data: ChartDatum[],
|
|
24
|
+
width: number,
|
|
25
|
+
maxValue: number,
|
|
26
|
+
options?: FracGroupedColumnOptions
|
|
27
|
+
): string[];
|
|
28
|
+
|
|
29
|
+
/** Draws a complete fractional grouped column chart.
|
|
30
|
+
* @param values - Chart data.
|
|
31
|
+
* @param width - Available width.
|
|
32
|
+
* @param options - Options.
|
|
33
|
+
* @returns Array of strings representing the chart.
|
|
34
|
+
*/
|
|
35
|
+
export function drawChart(values: ChartDataInput, width: number, options?: FracGroupedColumnOptions): string[];
|
|
36
|
+
|
|
37
|
+
export default drawChart;
|
|
@@ -7,6 +7,13 @@ 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
|
+
*/
|
|
10
17
|
export const drawColumn = (data, width, maxValue, options = {}) => {
|
|
11
18
|
const {reverse, rectSize = 1, initState = {}} = options,
|
|
12
19
|
blocks = data.map(datum => {
|
|
@@ -22,6 +29,12 @@ export const drawColumn = (data, width, maxValue, options = {}) => {
|
|
|
22
29
|
return result.map(line => optimize(line));
|
|
23
30
|
};
|
|
24
31
|
|
|
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
|
+
*/
|
|
25
38
|
export const drawChart = drawGroupedChart(drawColumn);
|
|
26
39
|
|
|
27
40
|
export default drawChart;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {ChartDataInput} from '../utils.js';
|
|
2
|
+
import {GroupedColumnChartOptions} from './draw-grouped.js';
|
|
3
|
+
|
|
4
|
+
/** Draws a complete plain grouped column chart.
|
|
5
|
+
* @param values - Chart data.
|
|
6
|
+
* @param width - Available width.
|
|
7
|
+
* @param options - Options.
|
|
8
|
+
* @returns Array of strings representing the chart.
|
|
9
|
+
*/
|
|
10
|
+
export function drawChart(values: ChartDataInput, width: number, options?: GroupedColumnChartOptions): string[];
|
|
11
|
+
|
|
12
|
+
export default drawChart;
|
|
@@ -1,6 +1,12 @@
|
|
|
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
|
+
*/
|
|
4
10
|
export const drawChart = drawGroupedChart(drawColumn);
|
|
5
11
|
|
|
6
12
|
export default drawChart;
|