UNPKG

simple-ascii-chart

Version:
393 lines (392 loc) 8.91 kB
"use strict"; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; Object.defineProperty(exports, "__esModule", { value: true }); var plot_1 = require("./services/plot"); var examples = [ [ [ [1, 2], [2, 3], ], { title: 'simple example' }, ], [ [ [1, 2], [2, 3], [3, 4], [4, 1], ], { title: 'bar chart', width: 10, barChart: true, height: 10 }, ], [ [ [-1, 2], [2, 3], [3, 4], [4, 1], ], { title: 'horizontal bar chart', width: 20, horizontalBarChart: true, height: 10 }, ], [ [ [1, 2], [2, 3], [3, 4], [4, 1], ], { title: 'area', width: 20, fillArea: true, height: 10 }, ], [ [ [1, 2], [2, 3], [3, 4], [4, 1], ], { title: 'labels', width: 20, xLabel: 'x', yLabel: 'y', height: 10 }, ], [ [ [ [1, 2], [2, 3], [3, 4], [4, 1], ], [ [1, -2], [2, -3], [3, 3], [4, 0], ], ], { title: 'legend', width: 20, legend: { position: 'bottom', series: ['first', 'second'] }, xLabel: 'x', yLabel: 'y', height: 10, }, ], [ [ [ [1, 2], [2, 3], [3, 4], [4, 1], ], [ [1, -2], [2, -3], [3, 3], [4, 0], ], [ [1, -6], [2, -3], [3, 3], [4, 0], ], [ [1, -2], [2, -3], [3, 3], [4, 0], [5, 3], ], ], { title: 'multiline', width: 20, height: 10, }, ], [ [ [1, 2], [2, 3], [3, 4], [4, 8], ], { title: 'yRange', width: 20, height: 10, yRange: [1, 3] }, ], [ [ [1, 2], [2, 3], [3, 4], [4, 1], ], { title: 'yRange', width: 20, height: 10, yRange: [0, 5] }, ], [ [ [1, 2], [2, 3], [3, 4], [4, 1], [5, 5], [6, 10], ], { title: 'showTickLabel', width: 20, height: 10, showTickLabel: true }, ], [ [ [1, 2], [2, 3], [5, 5], [6, 10], ], { title: 'hideXAxis', width: 20, height: 10, hideXAxis: true }, ], [ [ [1, 2], [2, 3], [5, 5], [6, 10], ], { title: 'hideYAxis', width: 20, height: 10, hideYAxis: true }, ], [ [ [-1, 2], [1, 2], [2, 3], [5, 5], [6, -2], ], { title: 'axisCenter', width: 20, height: 10, axisCenter: [0, 0], showTickLabel: true }, ], [ [ [-1, 2], [1, 2], [2, 3], [5, 5], [6, -2], ], { title: 'lineFormatter', width: 20, height: 10, lineFormatter: function (props) { var output = [{ x: props.plotX, y: props.plotY, symbol: '█' }]; var _a = __read(props.toPlotCoordinates(props.minX, props.minY), 1), minX = _a[0]; var i = minX; while (i <= props.plotX) { output.push({ x: i, y: props.plotY, symbol: '█' }); i += 1; } return output; }, }, ], [ [ [-1, 2], [1, 2], [2, 3], [5, 5], [6, -2], ], { title: 'lineFormatter', width: 20, height: 10, lineFormatter: function (props) { var output = [{ x: props.plotX, y: props.plotY, symbol: '█' }]; var _a = __read(props.toPlotCoordinates(props.x, props.minY), 2), _ = _a[0], maxY = _a[1]; var i = props.plotY; while (i <= maxY + 1) { output.push({ x: props.plotX, y: i, symbol: '█' }); i += 1; } return output; }, }, ], [ [ [-1, 2], [1, 2], [2, 3], [5, 5], [6, -2], ], { title: 'symbols', width: 20, height: 10, symbols: { background: '█', border: 'A', empty: 'B', }, }, ], [ [ [1, 2], [2, 3], [3, 4], [4, 1], ], { title: 'colors', width: 20, color: 'ansiGreen', height: 10 }, ], [ [ [ [1, 2], [2, 3], [3, 4], [4, 1], ], [ [1, 3], [2, 1], [3, 0], [4, 4], ], ], { title: 'colors with legend', width: 20, thresholds: [{ x: 2, y: 2, color: 'ansiBlue' }], color: ['ansiGreen', 'ansiMagenta'], height: 10, legend: { position: 'bottom', series: ['first', 'second'] }, }, ], [ [ [1, 1], [2, 4], [3, 4], [4, 2], [5, -1], [6, 3], [7, -1], [8, 9], ], { width: 40, title: 'thresholds', thresholds: [ { y: 5, x: 5, color: 'ansiBlue', }, { y: 2, color: 'ansiGreen', }, ], }, ], [ [ [0, 3], [1, 2], [2, 3], [3, 4], [4, -2], [5, -5], [6, 2], [7, 0], ], { title: 'with axis center', color: 'ansiGreen', showTickLabel: true, width: 40, axisCenter: [0, 2], }, ], [ [ [0, 3], [1, 2], [2, 3], [3, 4], [4, -2], [5, -5], [6, 2], [7, 0], ], { title: 'bar chart with colors', color: 'ansiGreen', barChart: true, showTickLabel: true, width: 40, axisCenter: [0, 0], }, ], [ [ [0, 3], [1, 2], [2, 3], [3, 4], [4, -2], [5, -5], [6, 2], [7, 0], ], { title: 'horizontal bar chart with axis center', horizontalBarChart: true, showTickLabel: true, width: 40, height: 20, axisCenter: [3, 1], }, ], [ [ [1, 0], [2, 20], [3, 29], ], { height: 10, horizontalBarChart: true, width: 20, showTickLabel: true }, ], [ [ [1, 0], [2, 20], [3, 29], ], { height: 10, barChart: true, width: 20, showTickLabel: true }, ], ]; var hasFilter = examples.some(function (_a) { var _b = __read(_a, 2), only = _b[1].only; return only !== undefined; }); console.clear(); examples .filter(function (example) { return (hasFilter ? example[1].only : true); }) .forEach(function (_a) { var _b = __read(_a, 2), data = _b[0], options = _b[1]; console.log((0, plot_1.plot)(data, options)); });