simple-ascii-chart-cli 1.0.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/LICENSE +21 -0
- package/README.md +1074 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +134 -0
- package/dist/constants/index.d.ts +19 -0
- package/dist/constants/index.js +22 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/services/coords.d.ts +113 -0
- package/dist/services/coords.js +228 -0
- package/dist/services/defaults.d.ts +41 -0
- package/dist/services/defaults.js +119 -0
- package/dist/services/draw.d.ts +83 -0
- package/dist/services/draw.js +183 -0
- package/dist/services/overrides.d.ts +60 -0
- package/dist/services/overrides.js +262 -0
- package/dist/services/plot.d.ts +3 -0
- package/dist/services/plot.js +213 -0
- package/dist/services/settings.d.ts +21 -0
- package/dist/services/settings.js +67 -0
- package/dist/types/index.d.ts +61 -0
- package/dist/types/index.js +2 -0
- package/package.json +69 -0
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __assign = (this && this.__assign) || function () {
|
|
4
|
+
__assign = Object.assign || function(t) {
|
|
5
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
6
|
+
s = arguments[i];
|
|
7
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
8
|
+
t[p] = s[p];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
return __assign.apply(this, arguments);
|
|
13
|
+
};
|
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
26
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
27
|
+
}) : function(o, v) {
|
|
28
|
+
o["default"] = v;
|
|
29
|
+
});
|
|
30
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
38
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
39
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
var yargs = __importStar(require("yargs"));
|
|
42
|
+
var index_1 = __importDefault(require("./index"));
|
|
43
|
+
var argv = yargs
|
|
44
|
+
.option('input', {
|
|
45
|
+
alias: 'i',
|
|
46
|
+
type: 'string',
|
|
47
|
+
demandOption: true,
|
|
48
|
+
})
|
|
49
|
+
.option('options', {
|
|
50
|
+
alias: 'o',
|
|
51
|
+
type: 'string',
|
|
52
|
+
description: 'plot settings',
|
|
53
|
+
})
|
|
54
|
+
.option('height', {
|
|
55
|
+
alias: 'h',
|
|
56
|
+
type: 'number',
|
|
57
|
+
description: 'plot height',
|
|
58
|
+
})
|
|
59
|
+
.option('hideXAxis', {
|
|
60
|
+
type: 'boolean',
|
|
61
|
+
description: 'hide x axis',
|
|
62
|
+
})
|
|
63
|
+
.option('hideYAxis', {
|
|
64
|
+
type: 'boolean',
|
|
65
|
+
description: 'hide Y axis',
|
|
66
|
+
})
|
|
67
|
+
.option('fillArea', {
|
|
68
|
+
type: 'boolean',
|
|
69
|
+
description: 'fill plot area',
|
|
70
|
+
})
|
|
71
|
+
.option('width', {
|
|
72
|
+
alias: 'w',
|
|
73
|
+
type: 'number',
|
|
74
|
+
description: 'plot width',
|
|
75
|
+
})
|
|
76
|
+
.option('title', {
|
|
77
|
+
alias: 't',
|
|
78
|
+
type: 'string',
|
|
79
|
+
description: 'plot title',
|
|
80
|
+
})
|
|
81
|
+
.option('xLabel', {
|
|
82
|
+
type: 'string',
|
|
83
|
+
description: 'x axis label',
|
|
84
|
+
})
|
|
85
|
+
.option('color', {
|
|
86
|
+
alias: 'c',
|
|
87
|
+
type: 'array',
|
|
88
|
+
description: 'plot colors',
|
|
89
|
+
})
|
|
90
|
+
.option('axisCenter', {
|
|
91
|
+
type: 'array',
|
|
92
|
+
description: 'plot center coordinates',
|
|
93
|
+
})
|
|
94
|
+
.option('yLabel', {
|
|
95
|
+
type: 'string',
|
|
96
|
+
description: 'y axis label',
|
|
97
|
+
}).argv;
|
|
98
|
+
var withError = function (cb) {
|
|
99
|
+
try {
|
|
100
|
+
cb();
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
process.stderr.write('Oops! Something went wrong!\n');
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var execute = function (_a) {
|
|
108
|
+
var input = _a.input, options = _a.options;
|
|
109
|
+
withError(function () {
|
|
110
|
+
var output = (0, index_1.default)(input, options);
|
|
111
|
+
process.stdout.write(output);
|
|
112
|
+
process.exit(0);
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
var prepareParams = function (_a) {
|
|
116
|
+
var input = _a.input, options = _a.options, width = _a.width, height = _a.height, hideYAxis = _a.hideYAxis, hideXAxis = _a.hideXAxis, fillArea = _a.fillArea, title = _a.title, xLabel = _a.xLabel, yLabel = _a.yLabel, color = _a.color, axisCenter = _a.axisCenter;
|
|
117
|
+
var currentOptions = options ? JSON.parse(options) : {};
|
|
118
|
+
return {
|
|
119
|
+
input: JSON.parse(input),
|
|
120
|
+
options: __assign(__assign({}, currentOptions), { width: width, height: height, hideYAxis: hideYAxis, hideXAxis: hideXAxis, title: title, xLabel: xLabel, yLabel: yLabel, fillArea: fillArea, color: color, axisCenter: axisCenter }),
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
if (argv instanceof Promise) {
|
|
124
|
+
argv.then(function (parameters) {
|
|
125
|
+
withError(function () {
|
|
126
|
+
execute(prepareParams(parameters));
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
withError(function () {
|
|
132
|
+
execute(prepareParams(argv));
|
|
133
|
+
});
|
|
134
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const AXIS: {
|
|
2
|
+
n: string;
|
|
3
|
+
ns: string;
|
|
4
|
+
y: string;
|
|
5
|
+
nse: string;
|
|
6
|
+
x: string;
|
|
7
|
+
we: string;
|
|
8
|
+
e: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const CHART: {
|
|
11
|
+
we: string;
|
|
12
|
+
wns: string;
|
|
13
|
+
ns: string;
|
|
14
|
+
nse: string;
|
|
15
|
+
wsn: string;
|
|
16
|
+
sne: string;
|
|
17
|
+
area: string;
|
|
18
|
+
};
|
|
19
|
+
export declare const EMPTY = " ";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EMPTY = exports.CHART = exports.AXIS = void 0;
|
|
4
|
+
exports.AXIS = {
|
|
5
|
+
n: '▲',
|
|
6
|
+
ns: '│',
|
|
7
|
+
y: '┤',
|
|
8
|
+
nse: '└',
|
|
9
|
+
x: '┬',
|
|
10
|
+
we: '─',
|
|
11
|
+
e: '▶',
|
|
12
|
+
};
|
|
13
|
+
exports.CHART = {
|
|
14
|
+
we: '━',
|
|
15
|
+
wns: '┓',
|
|
16
|
+
ns: '┃',
|
|
17
|
+
nse: '┗',
|
|
18
|
+
wsn: '┛',
|
|
19
|
+
sne: '┏',
|
|
20
|
+
area: '█',
|
|
21
|
+
};
|
|
22
|
+
exports.EMPTY = ' ';
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { SingleLine, Point, MultiLine } from '../types/index';
|
|
2
|
+
/**
|
|
3
|
+
* Creates an array filled with empty strings.
|
|
4
|
+
* @param {number} size - The size of the array.
|
|
5
|
+
* @param {string} empty - The value to fill the array with (default: EMPTY).
|
|
6
|
+
* @returns {string[]} - An array of empty strings.
|
|
7
|
+
*/
|
|
8
|
+
export declare const toEmpty: (size: number, empty?: string) => string[];
|
|
9
|
+
/**
|
|
10
|
+
* Converts a number or string to an array of its characters.
|
|
11
|
+
* @param {number | string} input - The input to convert.
|
|
12
|
+
* @returns {string[]} - An array of characters.
|
|
13
|
+
*/
|
|
14
|
+
export declare const toArray: (input: number | string) => string[];
|
|
15
|
+
/**
|
|
16
|
+
* Removes duplicate values from an array.
|
|
17
|
+
* @param {number[]} array - The input array.
|
|
18
|
+
* @returns {number[]} - An array with unique values.
|
|
19
|
+
*/
|
|
20
|
+
export declare const toUnique: (array: number[]) => number[];
|
|
21
|
+
/**
|
|
22
|
+
* Calculates the distance between two points.
|
|
23
|
+
* @param {number} x - The x-coordinate of the first point.
|
|
24
|
+
* @param {number} y - The y-coordinate of the second point.
|
|
25
|
+
* @returns {number} - The distance between the points.
|
|
26
|
+
*/
|
|
27
|
+
export declare const distance: (x: number, y: number) => number;
|
|
28
|
+
/**
|
|
29
|
+
* Flattens a multi-line array into a single array of points.
|
|
30
|
+
* @param {MultiLine} array - The multi-line array.
|
|
31
|
+
* @returns {Point[]} - A flat array of points.
|
|
32
|
+
*/
|
|
33
|
+
export declare const toFlat: (array: MultiLine) => Point[];
|
|
34
|
+
/**
|
|
35
|
+
* Converts a multi-line array into arrays of unique x and y values.
|
|
36
|
+
* @param {MultiLine} array - The multi-line array.
|
|
37
|
+
* @returns {[number[], number[]]} - Arrays of unique x and y values.
|
|
38
|
+
*/
|
|
39
|
+
export declare const toArrays: (array: MultiLine) => [number[], number[]];
|
|
40
|
+
/**
|
|
41
|
+
* Sorts a single-line array of points in ascending order by the first value of each point.
|
|
42
|
+
* @param {SingleLine} array - The single-line array to sort.
|
|
43
|
+
* @returns {SingleLine} - The sorted array.
|
|
44
|
+
*/
|
|
45
|
+
export declare const toSorted: (array: SingleLine) => SingleLine;
|
|
46
|
+
/**
|
|
47
|
+
* Converts a coordinate (x, y) to plot coordinates in the specified plot dimensions.
|
|
48
|
+
* @param {number} plotWidth - The width of the plot.
|
|
49
|
+
* @param {number} plotHeight - The height of the plot.
|
|
50
|
+
* @returns {function} - A function that takes (x, y) and returns plot coordinates [scaledX, scaledY].
|
|
51
|
+
*/
|
|
52
|
+
export declare const toPlot: (plotWidth: number, plotHeight: number) => (x: number, y: number) => number[];
|
|
53
|
+
/**
|
|
54
|
+
* Finds the maximum or minimum value in a single-line array of points.
|
|
55
|
+
* @param {SingleLine} arr - The single-line array to find extrema in.
|
|
56
|
+
* @param {string} type - 'max' for maximum, 'min' for minimum (default is 'max').
|
|
57
|
+
* @param {number} position - The position of the value within each point (default is 1).
|
|
58
|
+
* @returns {number} - The maximum or minimum value found in the array.
|
|
59
|
+
*/
|
|
60
|
+
export declare const getExtrema: (arr: SingleLine, type?: 'max' | 'min', position?: number) => number;
|
|
61
|
+
/**
|
|
62
|
+
* Finds the maximum value in an array of numbers.
|
|
63
|
+
* @param {number[]} arr - The array of numbers to find the maximum in.
|
|
64
|
+
* @returns {number} - The maximum value in the array.
|
|
65
|
+
*/
|
|
66
|
+
export declare const getMax: (arr: number[]) => number;
|
|
67
|
+
/**
|
|
68
|
+
* Finds the minimum value in an array of numbers.
|
|
69
|
+
* @param {number[]} arr - The array of numbers to find the minimum in.
|
|
70
|
+
* @returns {number} - The minimum value in the array.
|
|
71
|
+
*/
|
|
72
|
+
export declare const getMin: (arr: number[]) => number;
|
|
73
|
+
/**
|
|
74
|
+
* Returns a function that scales coordinates to fit within a plot.
|
|
75
|
+
* @param {[number, number]} domain - The domain range (min and max values).
|
|
76
|
+
* @param {[number, number]} range - The range within which to scale.
|
|
77
|
+
* @returns {(value: number) => number} - A function for scaling coordinates.
|
|
78
|
+
*/
|
|
79
|
+
export declare const scaler: ([domainMin, domainMax]: number[], [rangeMin, rangeMax]: number[]) => (domainValue: number) => number;
|
|
80
|
+
/**
|
|
81
|
+
* Scales a point's coordinates to fit within a plot.
|
|
82
|
+
* @param {Point} point - The point to scale.
|
|
83
|
+
* @param {number} plotWidth - The width of the plot.
|
|
84
|
+
* @param {number} plotHeight - The height of the plot.
|
|
85
|
+
* @param {number[]} rangeX - The range of x values.
|
|
86
|
+
* @param {number[]} rangeY - The range of y values.
|
|
87
|
+
* @returns {Point} - The scaled point.
|
|
88
|
+
*/
|
|
89
|
+
export declare const toCoordinates: (point: Point, plotWidth: number, plotHeight: number, rangeX: number[], rangeY: number[]) => Point;
|
|
90
|
+
/**
|
|
91
|
+
* Scales a list of coordinates to fit within a plot.
|
|
92
|
+
* @param {SingleLine} coordinates - The list of coordinates to scale.
|
|
93
|
+
* @param {number} plotWidth - The width of the plot.
|
|
94
|
+
* @param {number} plotHeight - The height of the plot.
|
|
95
|
+
* @param {number[]} [rangeX] - The range of x values (defaults to min and max from coordinates).
|
|
96
|
+
* @param {number[]} [rangeY] - The range of y values (defaults to min and max from coordinates).
|
|
97
|
+
* @returns {SingleLine} - The scaled list of coordinates.
|
|
98
|
+
*/
|
|
99
|
+
export declare const getPlotCoords: (coordinates: SingleLine, plotWidth: number, plotHeight: number, rangeX?: number[], rangeY?: number[]) => SingleLine;
|
|
100
|
+
/**
|
|
101
|
+
* Gets the center point for an axis.
|
|
102
|
+
* @param {Point | void} axisCenter - The center point of the axis (optional).
|
|
103
|
+
* @param {number} plotWidth - The width of the plot.
|
|
104
|
+
* @param {number} plotHeight - The height of the plot.
|
|
105
|
+
* @param {number[]} rangeX - The range of x values.
|
|
106
|
+
* @param {number[]} rangeY - The range of y values.
|
|
107
|
+
* @param {number[]} initialValue - The initial value for the axis.
|
|
108
|
+
* @returns {Point} - The center point of the axis.
|
|
109
|
+
*/
|
|
110
|
+
export declare const getAxisCenter: (axisCenter: Point | void, plotWidth: number, plotHeight: number, rangeX: number[], rangeY: number[], initialValue: number[]) => {
|
|
111
|
+
x: number;
|
|
112
|
+
y: number;
|
|
113
|
+
};
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.getAxisCenter = exports.getPlotCoords = exports.toCoordinates = exports.scaler = exports.getMin = exports.getMax = exports.getExtrema = exports.toPlot = exports.toSorted = exports.toArrays = exports.toFlat = exports.distance = exports.toUnique = exports.toArray = exports.toEmpty = void 0;
|
|
29
|
+
var index_1 = require("../constants/index");
|
|
30
|
+
/**
|
|
31
|
+
* Creates an array filled with empty strings.
|
|
32
|
+
* @param {number} size - The size of the array.
|
|
33
|
+
* @param {string} empty - The value to fill the array with (default: EMPTY).
|
|
34
|
+
* @returns {string[]} - An array of empty strings.
|
|
35
|
+
*/
|
|
36
|
+
var toEmpty = function (size, empty) {
|
|
37
|
+
if (empty === void 0) { empty = index_1.EMPTY; }
|
|
38
|
+
return Array(size >= 0 ? size : 0).fill(empty);
|
|
39
|
+
};
|
|
40
|
+
exports.toEmpty = toEmpty;
|
|
41
|
+
/**
|
|
42
|
+
* Converts a number or string to an array of its characters.
|
|
43
|
+
* @param {number | string} input - The input to convert.
|
|
44
|
+
* @returns {string[]} - An array of characters.
|
|
45
|
+
*/
|
|
46
|
+
var toArray = function (input) { return input.toString().split(''); };
|
|
47
|
+
exports.toArray = toArray;
|
|
48
|
+
/**
|
|
49
|
+
* Removes duplicate values from an array.
|
|
50
|
+
* @param {number[]} array - The input array.
|
|
51
|
+
* @returns {number[]} - An array with unique values.
|
|
52
|
+
*/
|
|
53
|
+
var toUnique = function (array) { return __spreadArray([], __read(new Set(array)), false); };
|
|
54
|
+
exports.toUnique = toUnique;
|
|
55
|
+
/**
|
|
56
|
+
* Calculates the distance between two points.
|
|
57
|
+
* @param {number} x - The x-coordinate of the first point.
|
|
58
|
+
* @param {number} y - The y-coordinate of the second point.
|
|
59
|
+
* @returns {number} - The distance between the points.
|
|
60
|
+
*/
|
|
61
|
+
var distance = function (x, y) { return Math.abs(Math.round(x) - Math.round(y)); };
|
|
62
|
+
exports.distance = distance;
|
|
63
|
+
/**
|
|
64
|
+
* Flattens a multi-line array into a single array of points.
|
|
65
|
+
* @param {MultiLine} array - The multi-line array.
|
|
66
|
+
* @returns {Point[]} - A flat array of points.
|
|
67
|
+
*/
|
|
68
|
+
var toFlat = function (array) {
|
|
69
|
+
var _a;
|
|
70
|
+
return (_a = []).concat.apply(_a, __spreadArray([], __read(array), false));
|
|
71
|
+
};
|
|
72
|
+
exports.toFlat = toFlat;
|
|
73
|
+
/**
|
|
74
|
+
* Converts a multi-line array into arrays of unique x and y values.
|
|
75
|
+
* @param {MultiLine} array - The multi-line array.
|
|
76
|
+
* @returns {[number[], number[]]} - Arrays of unique x and y values.
|
|
77
|
+
*/
|
|
78
|
+
var toArrays = function (array) {
|
|
79
|
+
var rangeX = [];
|
|
80
|
+
var rangeY = [];
|
|
81
|
+
(0, exports.toFlat)(array).forEach(function (_a) {
|
|
82
|
+
var _b = __read(_a, 2), x = _b[0], y = _b[1];
|
|
83
|
+
rangeX.push(x);
|
|
84
|
+
rangeY.push(y);
|
|
85
|
+
});
|
|
86
|
+
return [(0, exports.toUnique)(rangeX), (0, exports.toUnique)(rangeY)];
|
|
87
|
+
};
|
|
88
|
+
exports.toArrays = toArrays;
|
|
89
|
+
/**
|
|
90
|
+
* Sorts a single-line array of points in ascending order by the first value of each point.
|
|
91
|
+
* @param {SingleLine} array - The single-line array to sort.
|
|
92
|
+
* @returns {SingleLine} - The sorted array.
|
|
93
|
+
*/
|
|
94
|
+
var toSorted = function (array) {
|
|
95
|
+
return array.sort(function (_a, _b) {
|
|
96
|
+
var _c = __read(_a, 1), x1 = _c[0];
|
|
97
|
+
var _d = __read(_b, 1), x2 = _d[0];
|
|
98
|
+
if (x1 < x2) {
|
|
99
|
+
return -1;
|
|
100
|
+
}
|
|
101
|
+
if (x1 > x2) {
|
|
102
|
+
return 1;
|
|
103
|
+
}
|
|
104
|
+
return 0;
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
exports.toSorted = toSorted;
|
|
108
|
+
/**
|
|
109
|
+
* Converts a coordinate (x, y) to plot coordinates in the specified plot dimensions.
|
|
110
|
+
* @param {number} plotWidth - The width of the plot.
|
|
111
|
+
* @param {number} plotHeight - The height of the plot.
|
|
112
|
+
* @returns {function} - A function that takes (x, y) and returns plot coordinates [scaledX, scaledY].
|
|
113
|
+
*/
|
|
114
|
+
var toPlot = function (plotWidth, plotHeight) { return function (x, y) { return [
|
|
115
|
+
Math.round((x / plotWidth) * plotWidth),
|
|
116
|
+
plotHeight - 1 - Math.round((y / plotHeight) * plotHeight),
|
|
117
|
+
]; }; };
|
|
118
|
+
exports.toPlot = toPlot;
|
|
119
|
+
/**
|
|
120
|
+
* Finds the maximum or minimum value in a single-line array of points.
|
|
121
|
+
* @param {SingleLine} arr - The single-line array to find extrema in.
|
|
122
|
+
* @param {string} type - 'max' for maximum, 'min' for minimum (default is 'max').
|
|
123
|
+
* @param {number} position - The position of the value within each point (default is 1).
|
|
124
|
+
* @returns {number} - The maximum or minimum value found in the array.
|
|
125
|
+
*/
|
|
126
|
+
var getExtrema = function (arr, type, position) {
|
|
127
|
+
if (type === void 0) { type = 'max'; }
|
|
128
|
+
if (position === void 0) { position = 1; }
|
|
129
|
+
return arr.reduce(function (previous, curr) { return Math[type](previous, curr[position]); }, type === 'max' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY);
|
|
130
|
+
};
|
|
131
|
+
exports.getExtrema = getExtrema;
|
|
132
|
+
/**
|
|
133
|
+
* Finds the maximum value in an array of numbers.
|
|
134
|
+
* @param {number[]} arr - The array of numbers to find the maximum in.
|
|
135
|
+
* @returns {number} - The maximum value in the array.
|
|
136
|
+
*/
|
|
137
|
+
var getMax = function (arr) {
|
|
138
|
+
return arr.reduce(function (previous, curr) { return Math.max(previous, curr); }, Number.NEGATIVE_INFINITY);
|
|
139
|
+
};
|
|
140
|
+
exports.getMax = getMax;
|
|
141
|
+
/**
|
|
142
|
+
* Finds the minimum value in an array of numbers.
|
|
143
|
+
* @param {number[]} arr - The array of numbers to find the minimum in.
|
|
144
|
+
* @returns {number} - The minimum value in the array.
|
|
145
|
+
*/
|
|
146
|
+
var getMin = function (arr) {
|
|
147
|
+
return arr.reduce(function (previous, curr) { return Math.min(previous, curr); }, Number.POSITIVE_INFINITY);
|
|
148
|
+
};
|
|
149
|
+
exports.getMin = getMin;
|
|
150
|
+
/**
|
|
151
|
+
* Returns a function that scales coordinates to fit within a plot.
|
|
152
|
+
* @param {[number, number]} domain - The domain range (min and max values).
|
|
153
|
+
* @param {[number, number]} range - The range within which to scale.
|
|
154
|
+
* @returns {(value: number) => number} - A function for scaling coordinates.
|
|
155
|
+
*/
|
|
156
|
+
var scaler = function (_a, _b) {
|
|
157
|
+
var _c = __read(_a, 2), domainMin = _c[0], domainMax = _c[1];
|
|
158
|
+
var _d = __read(_b, 2), rangeMin = _d[0], rangeMax = _d[1];
|
|
159
|
+
var domainLength = Math.sqrt(Math.abs(Math.pow((domainMax - domainMin), 2))) || 1;
|
|
160
|
+
var rangeLength = Math.sqrt(Math.pow((rangeMax - rangeMin), 2));
|
|
161
|
+
return function (domainValue) {
|
|
162
|
+
return rangeMin + (rangeLength * (domainValue - domainMin)) / domainLength;
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
exports.scaler = scaler;
|
|
166
|
+
/**
|
|
167
|
+
* Scales a point's coordinates to fit within a plot.
|
|
168
|
+
* @param {Point} point - The point to scale.
|
|
169
|
+
* @param {number} plotWidth - The width of the plot.
|
|
170
|
+
* @param {number} plotHeight - The height of the plot.
|
|
171
|
+
* @param {number[]} rangeX - The range of x values.
|
|
172
|
+
* @param {number[]} rangeY - The range of y values.
|
|
173
|
+
* @returns {Point} - The scaled point.
|
|
174
|
+
*/
|
|
175
|
+
var toCoordinates = function (point, plotWidth, plotHeight, rangeX, rangeY) {
|
|
176
|
+
var getXCoord = (0, exports.scaler)(rangeX, [0, plotWidth - 1]);
|
|
177
|
+
var getYCoord = (0, exports.scaler)(rangeY, [0, plotHeight - 1]);
|
|
178
|
+
var toScale = function (_a) {
|
|
179
|
+
var _b = __read(_a, 2), x = _b[0], y = _b[1];
|
|
180
|
+
return [getXCoord(x), getYCoord(y)];
|
|
181
|
+
};
|
|
182
|
+
return toScale(point);
|
|
183
|
+
};
|
|
184
|
+
exports.toCoordinates = toCoordinates;
|
|
185
|
+
/**
|
|
186
|
+
* Scales a list of coordinates to fit within a plot.
|
|
187
|
+
* @param {SingleLine} coordinates - The list of coordinates to scale.
|
|
188
|
+
* @param {number} plotWidth - The width of the plot.
|
|
189
|
+
* @param {number} plotHeight - The height of the plot.
|
|
190
|
+
* @param {number[]} [rangeX] - The range of x values (defaults to min and max from coordinates).
|
|
191
|
+
* @param {number[]} [rangeY] - The range of y values (defaults to min and max from coordinates).
|
|
192
|
+
* @returns {SingleLine} - The scaled list of coordinates.
|
|
193
|
+
*/
|
|
194
|
+
var getPlotCoords = function (coordinates, plotWidth, plotHeight, rangeX, rangeY) {
|
|
195
|
+
var getXCoord = (0, exports.scaler)(rangeX || [(0, exports.getExtrema)(coordinates, 'min', 0), (0, exports.getExtrema)(coordinates, 'max', 0)], [0, plotWidth - 1]);
|
|
196
|
+
var getYCoord = (0, exports.scaler)(rangeY || [(0, exports.getExtrema)(coordinates, 'min'), (0, exports.getExtrema)(coordinates)], [
|
|
197
|
+
0,
|
|
198
|
+
plotHeight - 1,
|
|
199
|
+
]);
|
|
200
|
+
var toScale = function (_a) {
|
|
201
|
+
var _b = __read(_a, 2), x = _b[0], y = _b[1];
|
|
202
|
+
return [getXCoord(x), getYCoord(y)];
|
|
203
|
+
};
|
|
204
|
+
return coordinates.map(toScale);
|
|
205
|
+
};
|
|
206
|
+
exports.getPlotCoords = getPlotCoords;
|
|
207
|
+
/**
|
|
208
|
+
* Gets the center point for an axis.
|
|
209
|
+
* @param {Point | void} axisCenter - The center point of the axis (optional).
|
|
210
|
+
* @param {number} plotWidth - The width of the plot.
|
|
211
|
+
* @param {number} plotHeight - The height of the plot.
|
|
212
|
+
* @param {number[]} rangeX - The range of x values.
|
|
213
|
+
* @param {number[]} rangeY - The range of y values.
|
|
214
|
+
* @param {number[]} initialValue - The initial value for the axis.
|
|
215
|
+
* @returns {Point} - The center point of the axis.
|
|
216
|
+
*/
|
|
217
|
+
var getAxisCenter = function (axisCenter, plotWidth, plotHeight, rangeX, rangeY, initialValue) {
|
|
218
|
+
var axis = { x: initialValue[0], y: initialValue[1] };
|
|
219
|
+
// calculate axis position
|
|
220
|
+
if (axisCenter) {
|
|
221
|
+
var _a = __read((0, exports.toCoordinates)(axisCenter, plotWidth, plotHeight, rangeX, rangeY), 2), centerX = _a[0], centerY = _a[1];
|
|
222
|
+
var _b = __read((0, exports.toPlot)(plotWidth, plotHeight)(centerX, centerY), 2), plotCenterX = _b[0], plotCenterY = _b[1];
|
|
223
|
+
axis.x = plotCenterX;
|
|
224
|
+
axis.y = plotCenterY + 1;
|
|
225
|
+
}
|
|
226
|
+
return axis;
|
|
227
|
+
};
|
|
228
|
+
exports.getAxisCenter = getAxisCenter;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Symbols, MultiLine, Formatter, Coordinates } from '../types';
|
|
2
|
+
export declare const getSymbols: ({ symbols }: {
|
|
3
|
+
symbols?: Symbols | undefined;
|
|
4
|
+
}) => {
|
|
5
|
+
axisSymbols: {
|
|
6
|
+
n: string;
|
|
7
|
+
ns: string;
|
|
8
|
+
y: string;
|
|
9
|
+
nse: string;
|
|
10
|
+
x: string;
|
|
11
|
+
we: string;
|
|
12
|
+
e: string;
|
|
13
|
+
};
|
|
14
|
+
emptySymbol: string;
|
|
15
|
+
backgroundSymbol: string;
|
|
16
|
+
borderSymbol: string | undefined;
|
|
17
|
+
};
|
|
18
|
+
export declare const getChartSize: ({ input, width, height, }: {
|
|
19
|
+
input: MultiLine;
|
|
20
|
+
width?: number | undefined;
|
|
21
|
+
height?: number | undefined;
|
|
22
|
+
}) => {
|
|
23
|
+
minX: number;
|
|
24
|
+
plotWidth: number;
|
|
25
|
+
plotHeight: number;
|
|
26
|
+
expansionX: number[];
|
|
27
|
+
expansionY: number[];
|
|
28
|
+
};
|
|
29
|
+
export declare const getLabelShift: ({ input, transformLabel, expansionX, expansionY, minX, }: {
|
|
30
|
+
input: MultiLine;
|
|
31
|
+
transformLabel: Formatter;
|
|
32
|
+
expansionX: number[];
|
|
33
|
+
expansionY: number[];
|
|
34
|
+
minX: number;
|
|
35
|
+
}) => {
|
|
36
|
+
xShift: number;
|
|
37
|
+
yShift: number;
|
|
38
|
+
};
|
|
39
|
+
export declare const getInput: ({ rawInput }: {
|
|
40
|
+
rawInput: Coordinates;
|
|
41
|
+
}) => MultiLine;
|