simple-ascii-chart-cli 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -966
- package/dist/cli.js +58 -17
- package/dist/tests/cli.test.d.ts +1 -0
- package/dist/tests/cli.test.js +38 -0
- package/dist/tests/validators.test.d.ts +1 -0
- package/dist/tests/validators.test.js +93 -0
- package/dist/validators.d.ts +9 -0
- package/dist/validators.js +157 -0
- package/package.json +16 -28
- package/dist/constants/index.d.ts +0 -19
- package/dist/constants/index.js +0 -22
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -4
- package/dist/services/coords.d.ts +0 -113
- package/dist/services/coords.js +0 -228
- package/dist/services/defaults.d.ts +0 -41
- package/dist/services/defaults.js +0 -119
- package/dist/services/draw.d.ts +0 -83
- package/dist/services/draw.js +0 -183
- package/dist/services/overrides.d.ts +0 -60
- package/dist/services/overrides.js +0 -262
- package/dist/services/plot.d.ts +0 -3
- package/dist/services/plot.js +0 -213
- package/dist/services/settings.d.ts +0 -21
- package/dist/services/settings.js +0 -67
- package/dist/types/index.d.ts +0 -61
- package/dist/types/index.js +0 -2
package/dist/services/draw.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.drawShift = exports.drawLine = exports.drawCustomLine = exports.drawChart = exports.drawGraph = exports.drawAxis = exports.drawYAxisEnd = exports.drawXAxisEnd = void 0;
|
|
20
|
-
var constants_1 = require("../constants");
|
|
21
|
-
var coords_1 = require("./coords");
|
|
22
|
-
var drawXAxisEnd = function (_a) {
|
|
23
|
-
var hasPlaceToRender = _a.hasPlaceToRender, axisCenter = _a.axisCenter, yPos = _a.yPos, graph = _a.graph, yShift = _a.yShift, i = _a.i, scaledX = _a.scaledX, shift = _a.shift, signShift = _a.signShift, axisSymbols = _a.axisSymbols, pointXShift = _a.pointXShift;
|
|
24
|
-
var yShiftWhenOccupied = hasPlaceToRender ? -1 : 0;
|
|
25
|
-
var yShiftWhenHasAxisCenter = axisCenter ? 1 : 0;
|
|
26
|
-
var graphY = yPos + yShiftWhenOccupied + yShiftWhenHasAxisCenter;
|
|
27
|
-
var graphX = scaledX + yShift - i + 2 + shift;
|
|
28
|
-
graph[graphY][graphX] = pointXShift[pointXShift.length - 1 - i];
|
|
29
|
-
// Add X tick only for the last value
|
|
30
|
-
if (pointXShift.length - 1 === i) {
|
|
31
|
-
graph[yPos + signShift][scaledX + yShift + 2 + shift] = (axisSymbols === null || axisSymbols === void 0 ? void 0 : axisSymbols.x) || constants_1.AXIS.x;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
exports.drawXAxisEnd = drawXAxisEnd;
|
|
35
|
-
var drawYAxisEnd = function (_a) {
|
|
36
|
-
var graph = _a.graph, scaledY = _a.scaledY, yShift = _a.yShift, axis = _a.axis, pointY = _a.pointY, transformLabel = _a.transformLabel, axisSymbols = _a.axisSymbols, expansionX = _a.expansionX, expansionY = _a.expansionY;
|
|
37
|
-
// make sure position is not taken already
|
|
38
|
-
if (graph[scaledY + 1][axis.x + yShift + 1] !== (axisSymbols === null || axisSymbols === void 0 ? void 0 : axisSymbols.y)) {
|
|
39
|
-
var pointYShift = (0, coords_1.toArray)(transformLabel(pointY, { axis: 'y', xRange: expansionX, yRange: expansionY }));
|
|
40
|
-
for (var i = 0; i < pointYShift.length; i += 1) {
|
|
41
|
-
graph[scaledY + 1][axis.x + yShift - i] = pointYShift[pointYShift.length - 1 - i];
|
|
42
|
-
}
|
|
43
|
-
graph[scaledY + 1][axis.x + yShift + 1] = (axisSymbols === null || axisSymbols === void 0 ? void 0 : axisSymbols.y) || constants_1.AXIS.y;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
exports.drawYAxisEnd = drawYAxisEnd;
|
|
47
|
-
var drawAxis = function (_a) {
|
|
48
|
-
var graph = _a.graph, hideXAxis = _a.hideXAxis, hideYAxis = _a.hideYAxis, axisCenter = _a.axisCenter, axisSymbols = _a.axisSymbols, axis = _a.axis;
|
|
49
|
-
graph.forEach(function (line, index) {
|
|
50
|
-
line.forEach(function (_, curr) {
|
|
51
|
-
var lineChar = '';
|
|
52
|
-
if (curr === axis.x && !hideYAxis) {
|
|
53
|
-
if (index === 0) {
|
|
54
|
-
lineChar = (axisSymbols === null || axisSymbols === void 0 ? void 0 : axisSymbols.n) || constants_1.AXIS.n;
|
|
55
|
-
}
|
|
56
|
-
else if (index === graph.length - 1 && !axisCenter && !(hideYAxis || hideXAxis)) {
|
|
57
|
-
lineChar = (axisSymbols === null || axisSymbols === void 0 ? void 0 : axisSymbols.nse) || constants_1.AXIS.nse;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
lineChar = (axisSymbols === null || axisSymbols === void 0 ? void 0 : axisSymbols.ns) || constants_1.AXIS.ns;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else if (index === axis.y && !hideXAxis) {
|
|
64
|
-
if (curr === line.length - 1) {
|
|
65
|
-
lineChar = (axisSymbols === null || axisSymbols === void 0 ? void 0 : axisSymbols.e) || constants_1.AXIS.e;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
lineChar = (axisSymbols === null || axisSymbols === void 0 ? void 0 : axisSymbols.we) || constants_1.AXIS.we;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (lineChar) {
|
|
72
|
-
// eslint-disable-next-line
|
|
73
|
-
line[curr] = lineChar;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
exports.drawAxis = drawAxis;
|
|
79
|
-
var drawGraph = function (_a) {
|
|
80
|
-
var plotWidth = _a.plotWidth, plotHeight = _a.plotHeight, emptySymbol = _a.emptySymbol;
|
|
81
|
-
var callback = function () { return (0, coords_1.toEmpty)(plotWidth + 2, emptySymbol); };
|
|
82
|
-
return Array.from({ length: plotHeight + 2 }, callback);
|
|
83
|
-
};
|
|
84
|
-
exports.drawGraph = drawGraph;
|
|
85
|
-
var drawChart = function (_a) {
|
|
86
|
-
var graph = _a.graph;
|
|
87
|
-
return "\n".concat(graph.map(function (line) { return line.join(''); }).join('\n'), "\n");
|
|
88
|
-
};
|
|
89
|
-
exports.drawChart = drawChart;
|
|
90
|
-
var drawCustomLine = function (_a) {
|
|
91
|
-
var sortedCoords = _a.sortedCoords, scaledX = _a.scaledX, scaledY = _a.scaledY, input = _a.input, index = _a.index, lineFormatter = _a.lineFormatter, graph = _a.graph;
|
|
92
|
-
// custom line formatter
|
|
93
|
-
var lineFormatterArgs = {
|
|
94
|
-
x: sortedCoords[index][0],
|
|
95
|
-
y: sortedCoords[index][1],
|
|
96
|
-
plotX: scaledX + 1,
|
|
97
|
-
plotY: scaledY + 1,
|
|
98
|
-
index: index,
|
|
99
|
-
input: input[0],
|
|
100
|
-
};
|
|
101
|
-
var customSymbols = lineFormatter(lineFormatterArgs);
|
|
102
|
-
if (Array.isArray(customSymbols)) {
|
|
103
|
-
customSymbols.forEach(function (_a) {
|
|
104
|
-
var symbolX = _a.x, symbolY = _a.y, symbol = _a.symbol;
|
|
105
|
-
graph[symbolY][symbolX] = symbol;
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
graph[customSymbols.y][customSymbols.x] = customSymbols.symbol;
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
exports.drawCustomLine = drawCustomLine;
|
|
113
|
-
var drawLine = function (_a) {
|
|
114
|
-
var index = _a.index, arr = _a.arr, graph = _a.graph, scaledX = _a.scaledX, scaledY = _a.scaledY, plotHeight = _a.plotHeight, emptySymbol = _a.emptySymbol, chartSymbols = _a.chartSymbols;
|
|
115
|
-
if (index - 1 >= 0) {
|
|
116
|
-
var _b = __read(arr[index - 1], 2), prevX_1 = _b[0], prevY_1 = _b[1];
|
|
117
|
-
var _c = __read(arr[index], 2), currX = _c[0], currY_1 = _c[1];
|
|
118
|
-
Array((0, coords_1.distance)(currY_1, prevY_1))
|
|
119
|
-
.fill('')
|
|
120
|
-
.forEach(function (_, steps, array) {
|
|
121
|
-
if (Math.round(prevY_1) > Math.round(currY_1)) {
|
|
122
|
-
graph[scaledY + 1][scaledX] = (chartSymbols === null || chartSymbols === void 0 ? void 0 : chartSymbols.nse) || constants_1.CHART.nse;
|
|
123
|
-
if (steps === array.length - 1) {
|
|
124
|
-
graph[scaledY - steps][scaledX] = (chartSymbols === null || chartSymbols === void 0 ? void 0 : chartSymbols.wns) || constants_1.CHART.wns;
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
graph[scaledY - steps][scaledX] = (chartSymbols === null || chartSymbols === void 0 ? void 0 : chartSymbols.ns) || constants_1.CHART.ns;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
graph[scaledY + steps + 2][scaledX] = (chartSymbols === null || chartSymbols === void 0 ? void 0 : chartSymbols.wsn) || constants_1.CHART.wsn;
|
|
132
|
-
graph[scaledY + steps + 1][scaledX] = (chartSymbols === null || chartSymbols === void 0 ? void 0 : chartSymbols.ns) || constants_1.CHART.ns;
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
if (Math.round(prevY_1) < Math.round(currY_1)) {
|
|
136
|
-
graph[scaledY + 1][scaledX] = (chartSymbols === null || chartSymbols === void 0 ? void 0 : chartSymbols.sne) || constants_1.CHART.sne;
|
|
137
|
-
// The same Y values
|
|
138
|
-
}
|
|
139
|
-
else if (Math.round(prevY_1) === Math.round(currY_1)) {
|
|
140
|
-
// Add line only if space is not occupied already - valid case for small similar Y
|
|
141
|
-
if (graph[scaledY + 1][scaledX] === emptySymbol) {
|
|
142
|
-
graph[scaledY + 1][scaledX] = (chartSymbols === null || chartSymbols === void 0 ? void 0 : chartSymbols.we) || constants_1.CHART.we;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
var distanceX = (0, coords_1.distance)(currX, prevX_1);
|
|
146
|
-
Array(distanceX ? distanceX - 1 : 0)
|
|
147
|
-
.fill('')
|
|
148
|
-
.forEach(function (_, steps) {
|
|
149
|
-
var thisY = plotHeight - Math.round(prevY_1);
|
|
150
|
-
graph[thisY][Math.round(prevX_1) + steps + 1] = (chartSymbols === null || chartSymbols === void 0 ? void 0 : chartSymbols.we) || constants_1.CHART.we;
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
// plot the last coordinate
|
|
154
|
-
if (arr.length - 1 === index) {
|
|
155
|
-
graph[scaledY + 1][scaledX + 1] = (chartSymbols === null || chartSymbols === void 0 ? void 0 : chartSymbols.we) || constants_1.CHART.we;
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
exports.drawLine = drawLine;
|
|
159
|
-
var drawShift = function (_a) {
|
|
160
|
-
var graph = _a.graph, plotWidth = _a.plotWidth, emptySymbol = _a.emptySymbol, scaledCoords = _a.scaledCoords, xShift = _a.xShift, yShift = _a.yShift;
|
|
161
|
-
// shift graph
|
|
162
|
-
graph.push((0, coords_1.toEmpty)(plotWidth + 2, emptySymbol)); // bottom
|
|
163
|
-
// check step
|
|
164
|
-
var step = plotWidth;
|
|
165
|
-
scaledCoords.forEach(function (_a, index) {
|
|
166
|
-
var _b = __read(_a, 1), x = _b[0];
|
|
167
|
-
if (scaledCoords[index - 1]) {
|
|
168
|
-
var current = x - scaledCoords[index - 1][0];
|
|
169
|
-
step = current <= step ? current : step;
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
// x coords overlap
|
|
173
|
-
var hasToBeMoved = step < xShift;
|
|
174
|
-
if (hasToBeMoved)
|
|
175
|
-
graph.push((0, coords_1.toEmpty)(plotWidth + 1, emptySymbol));
|
|
176
|
-
graph.forEach(function (line) {
|
|
177
|
-
for (var i = 0; i <= yShift; i += 1) {
|
|
178
|
-
line.unshift(emptySymbol); // left
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
return { hasToBeMoved: hasToBeMoved };
|
|
182
|
-
};
|
|
183
|
-
exports.drawShift = drawShift;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Colors, Formatter, Graph, Legend, Symbols, Threshold } from '../types';
|
|
2
|
-
export declare const setTitle: ({ title, graph, backgroundSymbol, plotWidth, yShift, }: {
|
|
3
|
-
title: string;
|
|
4
|
-
graph: Graph;
|
|
5
|
-
backgroundSymbol: string;
|
|
6
|
-
plotWidth: number;
|
|
7
|
-
yShift: number;
|
|
8
|
-
}) => void;
|
|
9
|
-
export declare const addXLable: ({ graph, plotWidth, yShift, backgroundSymbol, xLabel, }: {
|
|
10
|
-
xLabel: string;
|
|
11
|
-
graph: Graph;
|
|
12
|
-
backgroundSymbol: string;
|
|
13
|
-
plotWidth: number;
|
|
14
|
-
yShift: number;
|
|
15
|
-
}) => void;
|
|
16
|
-
export declare const addYLabel: ({ graph, backgroundSymbol, yLabel, }: {
|
|
17
|
-
graph: Graph;
|
|
18
|
-
backgroundSymbol: string;
|
|
19
|
-
yLabel: string;
|
|
20
|
-
}) => void;
|
|
21
|
-
export declare const addLegend: ({ graph, legend, backgroundSymbol, color, symbols, fillArea, }: {
|
|
22
|
-
graph: Graph;
|
|
23
|
-
legend: Legend;
|
|
24
|
-
backgroundSymbol: string;
|
|
25
|
-
color?: Colors | undefined;
|
|
26
|
-
symbols?: Symbols | undefined;
|
|
27
|
-
fillArea?: boolean | undefined;
|
|
28
|
-
}) => void;
|
|
29
|
-
export declare const addBorder: ({ graph, borderSymbol }: {
|
|
30
|
-
graph: Graph;
|
|
31
|
-
borderSymbol: string;
|
|
32
|
-
}) => void;
|
|
33
|
-
export declare const addBackgroundSymbol: ({ graph, backgroundSymbol, emptySymbol, }: {
|
|
34
|
-
graph: Graph;
|
|
35
|
-
backgroundSymbol: string;
|
|
36
|
-
emptySymbol: string;
|
|
37
|
-
}) => void;
|
|
38
|
-
export declare const addThresholds: ({ graph, thresholds, axis, plotWidth, plotHeight, expansionX, expansionY, }: {
|
|
39
|
-
graph: Graph;
|
|
40
|
-
thresholds: Threshold[];
|
|
41
|
-
axis: {
|
|
42
|
-
x: number;
|
|
43
|
-
y: number;
|
|
44
|
-
};
|
|
45
|
-
plotWidth: number;
|
|
46
|
-
plotHeight: number;
|
|
47
|
-
expansionX: number[];
|
|
48
|
-
expansionY: number[];
|
|
49
|
-
}) => void;
|
|
50
|
-
export declare const setFillArea: ({ graph, chartSymbols, }: {
|
|
51
|
-
graph: Graph;
|
|
52
|
-
chartSymbols: Symbols['chart'];
|
|
53
|
-
}) => void;
|
|
54
|
-
export declare const removeEmptyLines: ({ graph, backgroundSymbol, }: {
|
|
55
|
-
graph: Graph;
|
|
56
|
-
backgroundSymbol: string;
|
|
57
|
-
}) => void;
|
|
58
|
-
export declare const getTransformLabel: ({ formatter }: {
|
|
59
|
-
formatter?: Formatter | undefined;
|
|
60
|
-
}) => Formatter;
|
|
@@ -1,262 +0,0 @@
|
|
|
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.getTransformLabel = exports.removeEmptyLines = exports.setFillArea = exports.addThresholds = exports.addBackgroundSymbol = exports.addBorder = exports.addLegend = exports.addYLabel = exports.addXLable = exports.setTitle = void 0;
|
|
29
|
-
var constants_1 = require("../constants");
|
|
30
|
-
var coords_1 = require("./coords");
|
|
31
|
-
var settings_1 = require("./settings");
|
|
32
|
-
var setTitle = function (_a) {
|
|
33
|
-
var title = _a.title, graph = _a.graph, backgroundSymbol = _a.backgroundSymbol, plotWidth = _a.plotWidth, yShift = _a.yShift;
|
|
34
|
-
// add one line for the title
|
|
35
|
-
graph.unshift((0, coords_1.toEmpty)(plotWidth + yShift + 2, backgroundSymbol)); // top
|
|
36
|
-
Array.from(title).forEach(function (letter, index) {
|
|
37
|
-
graph[0][index] = letter;
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
exports.setTitle = setTitle;
|
|
41
|
-
var addXLable = function (_a) {
|
|
42
|
-
var graph = _a.graph, plotWidth = _a.plotWidth, yShift = _a.yShift, backgroundSymbol = _a.backgroundSymbol, xLabel = _a.xLabel;
|
|
43
|
-
var totalWidth = graph[0].length;
|
|
44
|
-
var labelLength = (0, coords_1.toArray)(xLabel).length;
|
|
45
|
-
var startingPosition = Math.round((totalWidth - labelLength) / 2);
|
|
46
|
-
// add one line for the xLabel
|
|
47
|
-
graph.push((0, coords_1.toEmpty)(plotWidth + yShift + 2, backgroundSymbol)); // bottom
|
|
48
|
-
Array.from(xLabel).forEach(function (letter, index) {
|
|
49
|
-
graph[graph.length - 1][startingPosition + index] = letter;
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
exports.addXLable = addXLable;
|
|
53
|
-
var addYLabel = function (_a) {
|
|
54
|
-
var graph = _a.graph, backgroundSymbol = _a.backgroundSymbol, yLabel = _a.yLabel;
|
|
55
|
-
var totalHeight = graph.length;
|
|
56
|
-
var labelLength = (0, coords_1.toArray)(yLabel).length;
|
|
57
|
-
var startingPosition = Math.round((totalHeight - labelLength) / 2) - 1;
|
|
58
|
-
var label = Array.from(yLabel);
|
|
59
|
-
// add one line for the xLabel
|
|
60
|
-
graph.forEach(function (line, position) {
|
|
61
|
-
line.unshift(backgroundSymbol); // left
|
|
62
|
-
if (position > startingPosition && label[position - startingPosition - 1]) {
|
|
63
|
-
graph[position][0] = label[position - startingPosition - 1];
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
exports.addYLabel = addYLabel;
|
|
68
|
-
var addLegend = function (_a) {
|
|
69
|
-
// calculate legend width as the longest label
|
|
70
|
-
// adds 2 for one space and color indicator
|
|
71
|
-
var graph = _a.graph, legend = _a.legend, backgroundSymbol = _a.backgroundSymbol, color = _a.color, symbols = _a.symbols, fillArea = _a.fillArea;
|
|
72
|
-
var series = Array.isArray(legend.series) ? legend.series : [legend.series];
|
|
73
|
-
var legendWidth = 2 + series.reduce(function (acc, label) { return Math.max(acc, (0, coords_1.toArray)(label).length); }, 0);
|
|
74
|
-
var _loop_1 = function (i) {
|
|
75
|
-
graph.forEach(function (line, lineIndex) {
|
|
76
|
-
if (legend.position === 'left') {
|
|
77
|
-
line.unshift(backgroundSymbol); // left
|
|
78
|
-
series.forEach(function (label, index) {
|
|
79
|
-
if (lineIndex !== index)
|
|
80
|
-
return;
|
|
81
|
-
// get chart symbols for series
|
|
82
|
-
var chartSymbols = (0, settings_1.getChartSymbols)(color, index, symbols === null || symbols === void 0 ? void 0 : symbols.chart, fillArea);
|
|
83
|
-
var reversedLabel = __spreadArray(__spreadArray([
|
|
84
|
-
chartSymbols.area,
|
|
85
|
-
backgroundSymbol
|
|
86
|
-
], __read(Array.from(label)), false), __read(Array(legendWidth - label.length - 2).fill(backgroundSymbol)), false).reverse();
|
|
87
|
-
if (reversedLabel[i]) {
|
|
88
|
-
// eslint-disable-next-line no-param-reassign
|
|
89
|
-
line[0] = reversedLabel[i];
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
if (legend.position === 'right') {
|
|
94
|
-
line.push(backgroundSymbol);
|
|
95
|
-
series.forEach(function (label, index) {
|
|
96
|
-
// get chart symbols for series
|
|
97
|
-
var chartSymbols = (0, settings_1.getChartSymbols)(color, index, symbols === null || symbols === void 0 ? void 0 : symbols.chart, fillArea);
|
|
98
|
-
var newSymbol = __spreadArray(__spreadArray([
|
|
99
|
-
chartSymbols.area,
|
|
100
|
-
backgroundSymbol
|
|
101
|
-
], __read(Array.from(label)), false), __read(Array(legendWidth - label.length - 2).fill(backgroundSymbol)), false);
|
|
102
|
-
if (lineIndex === index) {
|
|
103
|
-
// eslint-disable-next-line no-param-reassign
|
|
104
|
-
line[line.length - 1] = newSymbol[i];
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
// prepare space for legend
|
|
111
|
-
// and then place the legend
|
|
112
|
-
for (var i = 0; i < legendWidth; i += 1) {
|
|
113
|
-
_loop_1(i);
|
|
114
|
-
}
|
|
115
|
-
if (legend.position === 'top') {
|
|
116
|
-
series.reverse().forEach(function (label, index) {
|
|
117
|
-
graph.unshift((0, coords_1.toEmpty)(graph[0].length, backgroundSymbol)); // top
|
|
118
|
-
// get chart symbols for series
|
|
119
|
-
var chartSymbols = (0, settings_1.getChartSymbols)(color, index, symbols === null || symbols === void 0 ? void 0 : symbols.chart, fillArea);
|
|
120
|
-
var newSymbol = __spreadArray([chartSymbols.area, backgroundSymbol], __read(Array.from(label)), false);
|
|
121
|
-
graph[index].forEach(function (_, symbolIndex) {
|
|
122
|
-
if (newSymbol[symbolIndex]) {
|
|
123
|
-
// eslint-disable-next-line no-param-reassign
|
|
124
|
-
graph[0][symbolIndex] = newSymbol[symbolIndex];
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
if (legend.position === 'bottom') {
|
|
130
|
-
series.forEach(function (label, index) {
|
|
131
|
-
graph.push((0, coords_1.toEmpty)(graph[0].length, backgroundSymbol)); // bottom
|
|
132
|
-
// get chart symbols for series
|
|
133
|
-
var chartSymbols = (0, settings_1.getChartSymbols)(color, index, symbols === null || symbols === void 0 ? void 0 : symbols.chart, fillArea);
|
|
134
|
-
var newSymbol = __spreadArray([chartSymbols.area, backgroundSymbol], __read(Array.from(label)), false);
|
|
135
|
-
graph[index].forEach(function (_, symbolIndex) {
|
|
136
|
-
if (newSymbol[symbolIndex]) {
|
|
137
|
-
// eslint-disable-next-line no-param-reassign
|
|
138
|
-
graph[graph.length - 1][symbolIndex] = newSymbol[symbolIndex];
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
exports.addLegend = addLegend;
|
|
145
|
-
var addBorder = function (_a) {
|
|
146
|
-
var graph = _a.graph, borderSymbol = _a.borderSymbol;
|
|
147
|
-
graph.forEach(function (line) {
|
|
148
|
-
line.unshift(borderSymbol); // left
|
|
149
|
-
line.push(borderSymbol); // right
|
|
150
|
-
});
|
|
151
|
-
graph.unshift((0, coords_1.toEmpty)(graph[0].length, borderSymbol)); // top
|
|
152
|
-
graph.push((0, coords_1.toEmpty)(graph[0].length, borderSymbol)); // bottom
|
|
153
|
-
};
|
|
154
|
-
exports.addBorder = addBorder;
|
|
155
|
-
var addBackgroundSymbol = function (_a) {
|
|
156
|
-
var graph = _a.graph, backgroundSymbol = _a.backgroundSymbol, emptySymbol = _a.emptySymbol;
|
|
157
|
-
graph.forEach(function (line) {
|
|
158
|
-
for (var index = 0; index < line.length; index += 1) {
|
|
159
|
-
if (line[index] === emptySymbol) {
|
|
160
|
-
// eslint-disable-next-line
|
|
161
|
-
line[index] = backgroundSymbol;
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
};
|
|
169
|
-
exports.addBackgroundSymbol = addBackgroundSymbol;
|
|
170
|
-
var addThresholds = function (_a) {
|
|
171
|
-
var graph = _a.graph, thresholds = _a.thresholds, axis = _a.axis, plotWidth = _a.plotWidth, plotHeight = _a.plotHeight, expansionX = _a.expansionX, expansionY = _a.expansionY;
|
|
172
|
-
var mappedThreshold = thresholds.map(function (_a) {
|
|
173
|
-
var thresholdX = _a.x, thresholdY = _a.y;
|
|
174
|
-
var x = axis.x, y = axis.y;
|
|
175
|
-
if (thresholdX) {
|
|
176
|
-
x = thresholdX;
|
|
177
|
-
}
|
|
178
|
-
if (thresholdY) {
|
|
179
|
-
y = thresholdY;
|
|
180
|
-
}
|
|
181
|
-
return [x, y];
|
|
182
|
-
});
|
|
183
|
-
// add threshold line
|
|
184
|
-
(0, coords_1.getPlotCoords)(mappedThreshold, plotWidth, plotHeight, expansionX, expansionY).forEach(function (_a, thresholdNumber) {
|
|
185
|
-
var _b, _c;
|
|
186
|
-
var _d = __read(_a, 2), x = _d[0], y = _d[1];
|
|
187
|
-
var _e = __read((0, coords_1.toPlot)(plotWidth, plotHeight)(x, y), 2), scaledX = _e[0], scaledY = _e[1];
|
|
188
|
-
// display x threshold only if it's in the graph
|
|
189
|
-
if (((_b = thresholds[thresholdNumber]) === null || _b === void 0 ? void 0 : _b.x) && graph[0][scaledX]) {
|
|
190
|
-
graph.forEach(function (_, index) {
|
|
191
|
-
var _a, _b;
|
|
192
|
-
if (graph[index][scaledX]) {
|
|
193
|
-
graph[index][scaledX] = ((_a = thresholds[thresholdNumber]) === null || _a === void 0 ? void 0 : _a.color)
|
|
194
|
-
? "".concat((0, settings_1.getAnsiColor)(((_b = thresholds[thresholdNumber]) === null || _b === void 0 ? void 0 : _b.color) || 'ansiRed')).concat(constants_1.CHART.ns, "\u001B[0m")
|
|
195
|
-
: constants_1.CHART.ns;
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
// display y threshold only if it's in the graph
|
|
200
|
-
if (((_c = thresholds[thresholdNumber]) === null || _c === void 0 ? void 0 : _c.y) && graph[scaledY]) {
|
|
201
|
-
graph[scaledY].forEach(function (_, index) {
|
|
202
|
-
var _a, _b;
|
|
203
|
-
if (graph[scaledY][index]) {
|
|
204
|
-
graph[scaledY][index] = ((_a = thresholds[thresholdNumber]) === null || _a === void 0 ? void 0 : _a.color)
|
|
205
|
-
? "".concat((0, settings_1.getAnsiColor)(((_b = thresholds[thresholdNumber]) === null || _b === void 0 ? void 0 : _b.color) || 'ansiRed')).concat(constants_1.CHART.we, "\u001B[0m")
|
|
206
|
-
: constants_1.CHART.we;
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
};
|
|
212
|
-
exports.addThresholds = addThresholds;
|
|
213
|
-
var setFillArea = function (_a) {
|
|
214
|
-
var graph = _a.graph, chartSymbols = _a.chartSymbols;
|
|
215
|
-
graph.forEach(function (xValues, yIndex) {
|
|
216
|
-
xValues.forEach(function (xSymbol, xIndex) {
|
|
217
|
-
var _a;
|
|
218
|
-
if (xSymbol === (chartSymbols === null || chartSymbols === void 0 ? void 0 : chartSymbols.nse) ||
|
|
219
|
-
xSymbol === (chartSymbols === null || chartSymbols === void 0 ? void 0 : chartSymbols.wsn) ||
|
|
220
|
-
xSymbol === (chartSymbols === null || chartSymbols === void 0 ? void 0 : chartSymbols.we) ||
|
|
221
|
-
xSymbol === (chartSymbols === null || chartSymbols === void 0 ? void 0 : chartSymbols.area)) {
|
|
222
|
-
if ((_a = graph[yIndex + 1]) === null || _a === void 0 ? void 0 : _a[xIndex]) {
|
|
223
|
-
graph[yIndex + 1][xIndex] = chartSymbols.area || constants_1.CHART.area;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
};
|
|
229
|
-
exports.setFillArea = setFillArea;
|
|
230
|
-
var removeEmptyLines = function (_a) {
|
|
231
|
-
var graph = _a.graph, backgroundSymbol = _a.backgroundSymbol;
|
|
232
|
-
// clean up empty lines after shift
|
|
233
|
-
// when there are occupied positions and shift is not needed
|
|
234
|
-
// there might be empty lines at the bottom
|
|
235
|
-
var elementsToRemove = [];
|
|
236
|
-
graph.forEach(function (line, position) {
|
|
237
|
-
if (line.every(function (symbol) { return symbol === backgroundSymbol; })) {
|
|
238
|
-
// collect empty line positions and remove them later
|
|
239
|
-
elementsToRemove.push(position);
|
|
240
|
-
}
|
|
241
|
-
// remove empty lines from the beginning
|
|
242
|
-
if (graph.every(function (currentLine) { return currentLine[0] === backgroundSymbol; })) {
|
|
243
|
-
graph.forEach(function (currentLine) { return currentLine.shift(); });
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
// reverse to remove from the end, otherwise positions will be shifted
|
|
247
|
-
elementsToRemove.reverse().forEach(function (position) {
|
|
248
|
-
graph.splice(position, 1);
|
|
249
|
-
});
|
|
250
|
-
};
|
|
251
|
-
exports.removeEmptyLines = removeEmptyLines;
|
|
252
|
-
var getTransformLabel = function (_a) {
|
|
253
|
-
var formatter = _a.formatter;
|
|
254
|
-
var transformLabel = function (value, helpers) {
|
|
255
|
-
if (formatter) {
|
|
256
|
-
return formatter(value, helpers);
|
|
257
|
-
}
|
|
258
|
-
return (0, settings_1.defaultFormatter)(value, helpers);
|
|
259
|
-
};
|
|
260
|
-
return transformLabel;
|
|
261
|
-
};
|
|
262
|
-
exports.getTransformLabel = getTransformLabel;
|
package/dist/services/plot.d.ts
DELETED