algorithm-visualizer
Advanced tools
| 'use strict'; | ||
| Object.defineProperty(exports, '__esModule', { value: true }); | ||
| var Randomize; | ||
| (function (Randomize) { | ||
| function Integer(options) { | ||
| var _a = options || {}, _b = _a.min, min = _b === void 0 ? 1 : _b, _c = _a.max, max = _c === void 0 ? 9 : _c; | ||
| return Math.random() * (max - min + 1) + min | 0; | ||
| } | ||
| Randomize.Integer = Integer; | ||
| function Double(options) { | ||
| var _a = options || {}, _b = _a.min, min = _b === void 0 ? 0 : _b, _c = _a.max, max = _c === void 0 ? 1 : _c; | ||
| return Math.random() * (max - min) + min; | ||
| } | ||
| Randomize.Double = Double; | ||
| function String(options) { | ||
| var _a = options || {}, _b = _a.length, length = _b === void 0 ? 16 : _b, _c = _a.letters, letters = _c === void 0 ? 'abcdefghijklmnopqrstuvwxyz' : _c; | ||
| var text = ''; | ||
| for (var i = 0; i < length; i++) { | ||
| text += letters[Integer({ min: 0, max: letters.length - 1 })]; | ||
| } | ||
| return text; | ||
| } | ||
| Randomize.String = String; | ||
| function Array2D(options) { | ||
| var _a = options || {}, _b = _a.N, N = _b === void 0 ? 10 : _b, _c = _a.M, M = _c === void 0 ? 10 : _c, _d = _a.value, value = _d === void 0 ? function () { return Integer(); } : _d, _e = _a.sorted, sorted = _e === void 0 ? false : _e; | ||
| var D = []; | ||
| for (var i = 0; i < N; i++) { | ||
| D.push([]); | ||
| for (var j = 0; j < M; j++) { | ||
| D[i].push(value(i, j)); | ||
| } | ||
| if (sorted) | ||
| D[i].sort(function (a, b) { return a - b; }); | ||
| } | ||
| return D; | ||
| } | ||
| Randomize.Array2D = Array2D; | ||
| function Array1D(options) { | ||
| var _a = options || {}, _b = _a.N, N = _b === void 0 ? 10 : _b, _c = _a.value, value = _c === void 0 ? function () { return Integer(); } : _c, _d = _a.sorted, sorted = _d === void 0 ? false : _d; | ||
| return Array2D({ | ||
| N: 1, | ||
| M: N, | ||
| value: value && (function (i, j) { return value(j); }), | ||
| sorted: sorted, | ||
| })[0]; | ||
| } | ||
| Randomize.Array1D = Array1D; | ||
| function Graph(options) { | ||
| var _a = options || {}, _b = _a.N, N = _b === void 0 ? 5 : _b, _c = _a.ratio, ratio = _c === void 0 ? .3 : _c, _d = _a.value, value = _d === void 0 ? function () { return Integer(); } : _d, _e = _a.directed, directed = _e === void 0 ? true : _e, _f = _a.weighted, weighted = _f === void 0 ? false : _f; | ||
| var G = new Array(N); | ||
| for (var i = 0; i < N; i++) { | ||
| G[i] = new Array(N); | ||
| } | ||
| for (var i = 0; i < N; i++) { | ||
| for (var j = 0; j < N; j++) { | ||
| if (i === j) { | ||
| G[i][j] = 0; | ||
| } | ||
| else if (directed || i < j) { | ||
| G[i][j] = Math.random() < ratio ? weighted ? value(i, j) : 1 : 0; | ||
| } | ||
| else { | ||
| G[i][j] = G[j][i]; | ||
| } | ||
| } | ||
| } | ||
| return G; | ||
| } | ||
| Randomize.Graph = Graph; | ||
| })(Randomize || (Randomize = {})); | ||
| var Randomize$1 = Randomize; | ||
| var MAX_COMMANDS = 1000000; | ||
| var MAX_OBJECTS = 100; | ||
| /** | ||
| * @ignore | ||
| */ | ||
| var Commander = /** @class */ (function () { | ||
| function Commander(iArguments) { | ||
| Commander.objectCount++; | ||
| var className = this.constructor.name; | ||
| this.key = Commander.randomizeKey(); | ||
| this.command(className, iArguments); | ||
| } | ||
| Commander.command = function (key, method, iArguments) { | ||
| var args = Array.from(iArguments); | ||
| this.commands.push({ | ||
| key: key, | ||
| method: method, | ||
| args: JSON.parse(JSON.stringify(args)), | ||
| }); | ||
| if (this.commands.length > MAX_COMMANDS) | ||
| throw new Error('Too Many Commands'); | ||
| if (this.objectCount > MAX_OBJECTS) | ||
| throw new Error('Too Many Objects'); | ||
| }; | ||
| Commander.randomizeKey = function () { | ||
| return Randomize$1.String({ length: 8, letters: 'abcdefghijklmnopqrstuvwxyz0123456789' }); | ||
| }; | ||
| /** | ||
| * Remove the tracer. | ||
| */ | ||
| Commander.prototype.destroy = function () { | ||
| Commander.objectCount--; | ||
| this.command('destroy', arguments); | ||
| }; | ||
| Commander.prototype.command = function (method, iArguments) { | ||
| Commander.command(this.key, method, iArguments); | ||
| }; | ||
| Commander.prototype.toJSON = function () { | ||
| return this.key; | ||
| }; | ||
| /** | ||
| * @ignore | ||
| */ | ||
| Commander.commands = []; | ||
| Commander.objectCount = 0; | ||
| return Commander; | ||
| }()); | ||
| if (!process.env.ALGORITHM_VISUALIZER) { | ||
| var axios_1 = require('axios'); | ||
| var opn_1 = require('opn'); | ||
| process.on('beforeExit', function () { | ||
| axios_1.post('https://algorithm-visualizer.org/api/visualizations', { content: JSON.stringify(Commander.commands) }) | ||
| .then(function (response) { return opn_1(response.data, { wait: false }); }) | ||
| .catch(console.error) | ||
| .finally(function () { return process.exit(); }); | ||
| }); | ||
| } | ||
| /*! ***************************************************************************** | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
| this file except in compliance with the License. You may obtain a copy of the | ||
| License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
| WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
| MERCHANTABLITY OR NON-INFRINGEMENT. | ||
| See the Apache Version 2.0 License for specific language governing permissions | ||
| and limitations under the License. | ||
| ***************************************************************************** */ | ||
| /* global Reflect, Promise */ | ||
| var extendStatics = function(d, b) { | ||
| extendStatics = Object.setPrototypeOf || | ||
| ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
| function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
| return extendStatics(d, b); | ||
| }; | ||
| function __extends(d, b) { | ||
| extendStatics(d, b); | ||
| function __() { this.constructor = d; } | ||
| d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
| } | ||
| /** | ||
| * @ignore | ||
| */ | ||
| var Layout = /** @class */ (function (_super) { | ||
| __extends(Layout, _super); | ||
| /** | ||
| * Create a layout. | ||
| * | ||
| * @param children The child views to contain. | ||
| */ | ||
| function Layout(children) { | ||
| return _super.call(this, arguments) || this; | ||
| } | ||
| /** | ||
| * Set a view as the root view. | ||
| * | ||
| * @param root | ||
| */ | ||
| Layout.setRoot = function (root) { | ||
| this.command(null, 'setRoot', arguments); | ||
| }; | ||
| /** | ||
| * Add a child to the layout. | ||
| * | ||
| * @param child | ||
| * @param index The index to add the child to. | ||
| */ | ||
| Layout.prototype.add = function (child, index) { | ||
| this.command('add', arguments); | ||
| }; | ||
| /** | ||
| * Remove a child from the layout. | ||
| * | ||
| * @param child | ||
| */ | ||
| Layout.prototype.remove = function (child) { | ||
| this.command('remove', arguments); | ||
| }; | ||
| /** | ||
| * Remove all the child views from the layout. | ||
| */ | ||
| Layout.prototype.removeAll = function () { | ||
| this.command('removeAll', arguments); | ||
| }; | ||
| return Layout; | ||
| }(Commander)); | ||
| var VerticalLayout = /** @class */ (function (_super) { | ||
| __extends(VerticalLayout, _super); | ||
| function VerticalLayout() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return VerticalLayout; | ||
| }(Layout)); | ||
| var HorizontalLayout = /** @class */ (function (_super) { | ||
| __extends(HorizontalLayout, _super); | ||
| function HorizontalLayout() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return HorizontalLayout; | ||
| }(Layout)); | ||
| /** | ||
| * @ignore | ||
| */ | ||
| var Tracer = /** @class */ (function (_super) { | ||
| __extends(Tracer, _super); | ||
| /** | ||
| * Create a tracer. | ||
| * | ||
| * @param title | ||
| */ | ||
| function Tracer(title) { | ||
| return _super.call(this, arguments) || this; | ||
| } | ||
| /** | ||
| * Pause to show changes in all tracers. | ||
| * | ||
| * @param lineNumber The line number to indicate when paused. If omitted, the line calling this method will be indicated. | ||
| */ | ||
| Tracer.delay = function (lineNumber) { | ||
| this.command(null, 'delay', arguments); | ||
| }; | ||
| /** | ||
| * Reset the tracer. | ||
| */ | ||
| Tracer.prototype.reset = function () { | ||
| this.command('reset', arguments); | ||
| }; | ||
| return Tracer; | ||
| }(Commander)); | ||
| var LogTracer = /** @class */ (function (_super) { | ||
| __extends(LogTracer, _super); | ||
| function LogTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| /** | ||
| * Set initial log to show. | ||
| * | ||
| * @param log | ||
| */ | ||
| LogTracer.prototype.set = function (log) { | ||
| this.command('set', arguments); | ||
| }; | ||
| /** | ||
| * Print log. | ||
| * | ||
| * @param message | ||
| */ | ||
| LogTracer.prototype.print = function (message) { | ||
| this.command('print', arguments); | ||
| }; | ||
| /** | ||
| * Print log and put a line break. | ||
| * | ||
| * @param message | ||
| */ | ||
| LogTracer.prototype.println = function (message) { | ||
| this.command('println', arguments); | ||
| }; | ||
| /** | ||
| * Print formatted log. | ||
| * | ||
| * @param format Refer to [sprintf-js](https://github.com/alexei/sprintf.js#format-specification). | ||
| * @param args | ||
| */ | ||
| LogTracer.prototype.printf = function (format) { | ||
| var args = []; | ||
| for (var _i = 1; _i < arguments.length; _i++) { | ||
| args[_i - 1] = arguments[_i]; | ||
| } | ||
| this.command('printf', arguments); | ||
| }; | ||
| return LogTracer; | ||
| }(Tracer)); | ||
| var Array2DTracer = /** @class */ (function (_super) { | ||
| __extends(Array2DTracer, _super); | ||
| function Array2DTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| /** | ||
| * Set a two-dimensional array to visualize. | ||
| * | ||
| * @param array2d | ||
| */ | ||
| Array2DTracer.prototype.set = function (array2d) { | ||
| this.command('set', arguments); | ||
| }; | ||
| /** | ||
| * Notify that a value has been changed. | ||
| * | ||
| * @param x The row index of the array. | ||
| * @param y The column index of the array. | ||
| * @param v The new value to change to. | ||
| */ | ||
| Array2DTracer.prototype.patch = function (x, y, v) { | ||
| this.command('patch', arguments); | ||
| }; | ||
| /** | ||
| * Stop notifying that a value has been changed. | ||
| * | ||
| * @param x The row index of the array. | ||
| * @param y The column index of the array. | ||
| */ | ||
| Array2DTracer.prototype.depatch = function (x, y) { | ||
| this.command('depatch', arguments); | ||
| }; | ||
| /** | ||
| * Select indices of the array. | ||
| * | ||
| * @param sx The row index to select inclusively from. | ||
| * @param sy The column index to select inclusively from. | ||
| * @param ex The row index to select inclusively to. If omitted, it will only select index `sx`. | ||
| * @param ey The column index to select inclusively to. If omitted, it will only select index `sy`. | ||
| */ | ||
| Array2DTracer.prototype.select = function (sx, sy, ex, ey) { | ||
| this.command('select', arguments); | ||
| }; | ||
| /** | ||
| * Select indices of a row of the array. | ||
| * | ||
| * @param x The row index to select. | ||
| * @param sy The column index to select inclusively from. | ||
| * @param ey The column index to select inclusively to. | ||
| */ | ||
| Array2DTracer.prototype.selectRow = function (x, sy, ey) { | ||
| this.command('selectRow', arguments); | ||
| }; | ||
| /** | ||
| * Select indices of a column of the array. | ||
| * | ||
| * @param y The column index to select. | ||
| * @param sx The row index to select inclusively from. | ||
| * @param ex The row index to select inclusively to. | ||
| */ | ||
| Array2DTracer.prototype.selectCol = function (y, sx, ex) { | ||
| this.command('selectCol', arguments); | ||
| }; | ||
| /** | ||
| * Stop selecting indices of the array. | ||
| * | ||
| * @param sx The row index to stop selecting inclusively from. | ||
| * @param sy The column index to stop selecting inclusively from. | ||
| * @param ex The row index to stop selecting inclusively to. If omitted, it will only stop selecting index `sx`. | ||
| * @param ey The column index to stop selecting inclusively to. If omitted, it will only stop selecting index `sy`. | ||
| */ | ||
| Array2DTracer.prototype.deselect = function (sx, sy, ex, ey) { | ||
| this.command('deselect', arguments); | ||
| }; | ||
| /** | ||
| * Stop selecting indices of a row of the array. | ||
| * | ||
| * @param x The row index to stop selecting. | ||
| * @param sy The column index to stop selecting inclusively from. | ||
| * @param ey The column index to stop selecting inclusively to. | ||
| */ | ||
| Array2DTracer.prototype.deselectRow = function (x, sy, ey) { | ||
| this.command('deselectRow', arguments); | ||
| }; | ||
| /** | ||
| * Stop selecting indices of a column of the array. | ||
| * | ||
| * @param y The column index to stop selecting. | ||
| * @param sx The row index to stop selecting inclusively from. | ||
| * @param ex The row index to stop selecting inclusively to. | ||
| */ | ||
| Array2DTracer.prototype.deselectCol = function (y, sx, ex) { | ||
| this.command('deselectCol', arguments); | ||
| }; | ||
| return Array2DTracer; | ||
| }(Tracer)); | ||
| var Array1DTracer = /** @class */ (function (_super) { | ||
| __extends(Array1DTracer, _super); | ||
| function Array1DTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| /** | ||
| * Set an array to visualize. | ||
| * | ||
| * @param array1d | ||
| */ | ||
| Array1DTracer.prototype.set = function (array1d) { | ||
| this.command('set', arguments); | ||
| }; | ||
| /** | ||
| * Notify that a value has been changed. | ||
| * | ||
| * @param x The index of the array. | ||
| * @param v The new value to change to. | ||
| */ | ||
| Array1DTracer.prototype.patch = function (x, v) { | ||
| this.command('patch', arguments); | ||
| }; | ||
| /** | ||
| * Stop notifying that a value has been changed. | ||
| * | ||
| * @param x The index of the array. | ||
| */ | ||
| Array1DTracer.prototype.depatch = function (x) { | ||
| this.command('depatch', arguments); | ||
| }; | ||
| /** | ||
| * Select indices of the array. | ||
| * | ||
| * @param sx The index to select inclusively from. | ||
| * @param ex The index to select inclusively to. If omitted, it will only select index `sx`. | ||
| */ | ||
| Array1DTracer.prototype.select = function (sx, ex) { | ||
| this.command('select', arguments); | ||
| }; | ||
| /** | ||
| * Stop selecting indices of the array. | ||
| * | ||
| * @param sx The index to stop selecting inclusively from. | ||
| * @param ex The index to stop selecting inclusively to. If omitted, it will only stop selecting index `sx`. | ||
| */ | ||
| Array1DTracer.prototype.deselect = function (sx, ex) { | ||
| this.command('deselect', arguments); | ||
| }; | ||
| /** | ||
| * Synchronize with a chart tracer. | ||
| * | ||
| * @param chartTracer | ||
| */ | ||
| Array1DTracer.prototype.chart = function (chartTracer) { | ||
| this.command('chart', arguments); | ||
| }; | ||
| return Array1DTracer; | ||
| }(Tracer)); | ||
| var ChartTracer = /** @class */ (function (_super) { | ||
| __extends(ChartTracer, _super); | ||
| function ChartTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return ChartTracer; | ||
| }(Array1DTracer)); | ||
| var GraphTracer = /** @class */ (function (_super) { | ||
| __extends(GraphTracer, _super); | ||
| function GraphTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| /** | ||
| * Set an adjacency matrix to visualize. | ||
| * | ||
| * @param array2d | ||
| */ | ||
| GraphTracer.prototype.set = function (array2d) { | ||
| this.command('set', arguments); | ||
| }; | ||
| /** | ||
| * Make the graph directed. | ||
| * | ||
| * @param isDirected | ||
| */ | ||
| GraphTracer.prototype.directed = function (isDirected) { | ||
| this.command('directed', arguments); | ||
| return this; | ||
| }; | ||
| /** | ||
| * Make the graph weighted. | ||
| * | ||
| * @param isWeighted | ||
| */ | ||
| GraphTracer.prototype.weighted = function (isWeighted) { | ||
| this.command('weighted', arguments); | ||
| return this; | ||
| }; | ||
| /** | ||
| * Arrange nodes on a circular layout. | ||
| */ | ||
| GraphTracer.prototype.layoutCircle = function () { | ||
| this.command('layoutCircle', arguments); | ||
| return this; | ||
| }; | ||
| /** | ||
| * Arrange nodes on a tree layout. | ||
| * | ||
| * @param root The id of a root node. | ||
| * @param sorted Whether to sort sibling nodes. | ||
| */ | ||
| GraphTracer.prototype.layoutTree = function (root, sorted) { | ||
| this.command('layoutTree', arguments); | ||
| return this; | ||
| }; | ||
| /** | ||
| * Arrange nodes randomly. | ||
| */ | ||
| GraphTracer.prototype.layoutRandom = function () { | ||
| this.command('layoutRandom', arguments); | ||
| return this; | ||
| }; | ||
| /** | ||
| * Add a node. | ||
| * | ||
| * @param id | ||
| * @param weight | ||
| * @param x The x position between `-160` and `+160`. | ||
| * @param y The y position between `-160` and `+160`. | ||
| */ | ||
| GraphTracer.prototype.addNode = function (id, weight, x, y) { | ||
| this.command('addNode', arguments); | ||
| }; | ||
| /** | ||
| * Update a node. | ||
| * | ||
| * @param id | ||
| * @param weight | ||
| * @param x The x position between `-160` and `+160`. | ||
| * @param y The y position between `-160` and `+160`. | ||
| */ | ||
| GraphTracer.prototype.updateNode = function (id, weight, x, y) { | ||
| this.command('updateNode', arguments); | ||
| }; | ||
| /** | ||
| * Remove a node. | ||
| * | ||
| * @param id | ||
| */ | ||
| GraphTracer.prototype.removeNode = function (id) { | ||
| this.command('removeNode', arguments); | ||
| }; | ||
| /** | ||
| * Add an edge. | ||
| * | ||
| * @param source The id of the node where the edge starts. | ||
| * @param target The id of the node where the edge ends. | ||
| * @param weight | ||
| */ | ||
| GraphTracer.prototype.addEdge = function (source, target, weight) { | ||
| this.command('addEdge', arguments); | ||
| }; | ||
| /** | ||
| * Update an edge. | ||
| * | ||
| * @param source The id of the node where the edge starts. | ||
| * @param target The id of the node where the edge ends. | ||
| * @param weight | ||
| */ | ||
| GraphTracer.prototype.updateEdge = function (source, target, weight) { | ||
| this.command('updateEdge', arguments); | ||
| }; | ||
| /** | ||
| * Remove an edge. | ||
| * | ||
| * @param source The id of the node where the edge starts. | ||
| * @param target The id of the node where the edge ends. | ||
| */ | ||
| GraphTracer.prototype.removeEdge = function (source, target) { | ||
| this.command('removeEdge', arguments); | ||
| }; | ||
| /** | ||
| * Visit a node. | ||
| * | ||
| * @param target The id of the node to visit. | ||
| * @param source The id of the node to visit from. | ||
| * @param weight The weight of `target` to set to. | ||
| */ | ||
| GraphTracer.prototype.visit = function (target, source, weight) { | ||
| this.command('visit', arguments); | ||
| }; | ||
| /** | ||
| * Leave after visiting a node. | ||
| * | ||
| * @param target The id of the node to leave. | ||
| * @param source The id of the node to leave to. | ||
| * @param weight The weight of `target` to set to. | ||
| */ | ||
| GraphTracer.prototype.leave = function (target, source, weight) { | ||
| this.command('leave', arguments); | ||
| }; | ||
| /** | ||
| * Select a node. | ||
| * | ||
| * @param target The id of the node to select. | ||
| * @param source The id of the node to select from. | ||
| */ | ||
| GraphTracer.prototype.select = function (target, source) { | ||
| this.command('select', arguments); | ||
| }; | ||
| /** | ||
| * Stop selecting a node. | ||
| * | ||
| * @param target The id of the node to stop selecting. | ||
| * @param source The id of the node to stop selecting from. | ||
| */ | ||
| GraphTracer.prototype.deselect = function (target, source) { | ||
| this.command('deselect', arguments); | ||
| }; | ||
| /** | ||
| * Synchronize with a log tracer. | ||
| * | ||
| * @param logTracer | ||
| */ | ||
| GraphTracer.prototype.log = function (logTracer) { | ||
| this.command('log', arguments); | ||
| }; | ||
| return GraphTracer; | ||
| }(Tracer)); | ||
| exports.Array1DTracer = Array1DTracer; | ||
| exports.Array2DTracer = Array2DTracer; | ||
| exports.ChartTracer = ChartTracer; | ||
| exports.Commander = Commander; | ||
| exports.GraphTracer = GraphTracer; | ||
| exports.HorizontalLayout = HorizontalLayout; | ||
| exports.Layout = Layout; | ||
| exports.LogTracer = LogTracer; | ||
| exports.Randomize = Randomize$1; | ||
| exports.Tracer = Tracer; | ||
| exports.VerticalLayout = VerticalLayout; |
| var Randomize; | ||
| (function (Randomize) { | ||
| function Integer(options) { | ||
| var _a = options || {}, _b = _a.min, min = _b === void 0 ? 1 : _b, _c = _a.max, max = _c === void 0 ? 9 : _c; | ||
| return Math.random() * (max - min + 1) + min | 0; | ||
| } | ||
| Randomize.Integer = Integer; | ||
| function Double(options) { | ||
| var _a = options || {}, _b = _a.min, min = _b === void 0 ? 0 : _b, _c = _a.max, max = _c === void 0 ? 1 : _c; | ||
| return Math.random() * (max - min) + min; | ||
| } | ||
| Randomize.Double = Double; | ||
| function String(options) { | ||
| var _a = options || {}, _b = _a.length, length = _b === void 0 ? 16 : _b, _c = _a.letters, letters = _c === void 0 ? 'abcdefghijklmnopqrstuvwxyz' : _c; | ||
| var text = ''; | ||
| for (var i = 0; i < length; i++) { | ||
| text += letters[Integer({ min: 0, max: letters.length - 1 })]; | ||
| } | ||
| return text; | ||
| } | ||
| Randomize.String = String; | ||
| function Array2D(options) { | ||
| var _a = options || {}, _b = _a.N, N = _b === void 0 ? 10 : _b, _c = _a.M, M = _c === void 0 ? 10 : _c, _d = _a.value, value = _d === void 0 ? function () { return Integer(); } : _d, _e = _a.sorted, sorted = _e === void 0 ? false : _e; | ||
| var D = []; | ||
| for (var i = 0; i < N; i++) { | ||
| D.push([]); | ||
| for (var j = 0; j < M; j++) { | ||
| D[i].push(value(i, j)); | ||
| } | ||
| if (sorted) | ||
| D[i].sort(function (a, b) { return a - b; }); | ||
| } | ||
| return D; | ||
| } | ||
| Randomize.Array2D = Array2D; | ||
| function Array1D(options) { | ||
| var _a = options || {}, _b = _a.N, N = _b === void 0 ? 10 : _b, _c = _a.value, value = _c === void 0 ? function () { return Integer(); } : _c, _d = _a.sorted, sorted = _d === void 0 ? false : _d; | ||
| return Array2D({ | ||
| N: 1, | ||
| M: N, | ||
| value: value && (function (i, j) { return value(j); }), | ||
| sorted: sorted, | ||
| })[0]; | ||
| } | ||
| Randomize.Array1D = Array1D; | ||
| function Graph(options) { | ||
| var _a = options || {}, _b = _a.N, N = _b === void 0 ? 5 : _b, _c = _a.ratio, ratio = _c === void 0 ? .3 : _c, _d = _a.value, value = _d === void 0 ? function () { return Integer(); } : _d, _e = _a.directed, directed = _e === void 0 ? true : _e, _f = _a.weighted, weighted = _f === void 0 ? false : _f; | ||
| var G = new Array(N); | ||
| for (var i = 0; i < N; i++) { | ||
| G[i] = new Array(N); | ||
| } | ||
| for (var i = 0; i < N; i++) { | ||
| for (var j = 0; j < N; j++) { | ||
| if (i === j) { | ||
| G[i][j] = 0; | ||
| } | ||
| else if (directed || i < j) { | ||
| G[i][j] = Math.random() < ratio ? weighted ? value(i, j) : 1 : 0; | ||
| } | ||
| else { | ||
| G[i][j] = G[j][i]; | ||
| } | ||
| } | ||
| } | ||
| return G; | ||
| } | ||
| Randomize.Graph = Graph; | ||
| })(Randomize || (Randomize = {})); | ||
| var Randomize$1 = Randomize; | ||
| var MAX_COMMANDS = 1000000; | ||
| var MAX_OBJECTS = 100; | ||
| /** | ||
| * @ignore | ||
| */ | ||
| var Commander = /** @class */ (function () { | ||
| function Commander(iArguments) { | ||
| Commander.objectCount++; | ||
| var className = this.constructor.name; | ||
| this.key = Commander.randomizeKey(); | ||
| this.command(className, iArguments); | ||
| } | ||
| Commander.command = function (key, method, iArguments) { | ||
| var args = Array.from(iArguments); | ||
| this.commands.push({ | ||
| key: key, | ||
| method: method, | ||
| args: JSON.parse(JSON.stringify(args)), | ||
| }); | ||
| if (this.commands.length > MAX_COMMANDS) | ||
| throw new Error('Too Many Commands'); | ||
| if (this.objectCount > MAX_OBJECTS) | ||
| throw new Error('Too Many Objects'); | ||
| }; | ||
| Commander.randomizeKey = function () { | ||
| return Randomize$1.String({ length: 8, letters: 'abcdefghijklmnopqrstuvwxyz0123456789' }); | ||
| }; | ||
| /** | ||
| * Remove the tracer. | ||
| */ | ||
| Commander.prototype.destroy = function () { | ||
| Commander.objectCount--; | ||
| this.command('destroy', arguments); | ||
| }; | ||
| Commander.prototype.command = function (method, iArguments) { | ||
| Commander.command(this.key, method, iArguments); | ||
| }; | ||
| Commander.prototype.toJSON = function () { | ||
| return this.key; | ||
| }; | ||
| /** | ||
| * @ignore | ||
| */ | ||
| Commander.commands = []; | ||
| Commander.objectCount = 0; | ||
| return Commander; | ||
| }()); | ||
| if (!process.env.ALGORITHM_VISUALIZER) { | ||
| var axios_1 = require('axios'); | ||
| var opn_1 = require('opn'); | ||
| process.on('beforeExit', function () { | ||
| axios_1.post('https://algorithm-visualizer.org/api/visualizations', { content: JSON.stringify(Commander.commands) }) | ||
| .then(function (response) { return opn_1(response.data, { wait: false }); }) | ||
| .catch(console.error) | ||
| .finally(function () { return process.exit(); }); | ||
| }); | ||
| } | ||
| /*! ***************************************************************************** | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
| this file except in compliance with the License. You may obtain a copy of the | ||
| License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
| WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
| MERCHANTABLITY OR NON-INFRINGEMENT. | ||
| See the Apache Version 2.0 License for specific language governing permissions | ||
| and limitations under the License. | ||
| ***************************************************************************** */ | ||
| /* global Reflect, Promise */ | ||
| var extendStatics = function(d, b) { | ||
| extendStatics = Object.setPrototypeOf || | ||
| ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
| function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
| return extendStatics(d, b); | ||
| }; | ||
| function __extends(d, b) { | ||
| extendStatics(d, b); | ||
| function __() { this.constructor = d; } | ||
| d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
| } | ||
| /** | ||
| * @ignore | ||
| */ | ||
| var Layout = /** @class */ (function (_super) { | ||
| __extends(Layout, _super); | ||
| /** | ||
| * Create a layout. | ||
| * | ||
| * @param children The child views to contain. | ||
| */ | ||
| function Layout(children) { | ||
| return _super.call(this, arguments) || this; | ||
| } | ||
| /** | ||
| * Set a view as the root view. | ||
| * | ||
| * @param root | ||
| */ | ||
| Layout.setRoot = function (root) { | ||
| this.command(null, 'setRoot', arguments); | ||
| }; | ||
| /** | ||
| * Add a child to the layout. | ||
| * | ||
| * @param child | ||
| * @param index The index to add the child to. | ||
| */ | ||
| Layout.prototype.add = function (child, index) { | ||
| this.command('add', arguments); | ||
| }; | ||
| /** | ||
| * Remove a child from the layout. | ||
| * | ||
| * @param child | ||
| */ | ||
| Layout.prototype.remove = function (child) { | ||
| this.command('remove', arguments); | ||
| }; | ||
| /** | ||
| * Remove all the child views from the layout. | ||
| */ | ||
| Layout.prototype.removeAll = function () { | ||
| this.command('removeAll', arguments); | ||
| }; | ||
| return Layout; | ||
| }(Commander)); | ||
| var VerticalLayout = /** @class */ (function (_super) { | ||
| __extends(VerticalLayout, _super); | ||
| function VerticalLayout() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return VerticalLayout; | ||
| }(Layout)); | ||
| var HorizontalLayout = /** @class */ (function (_super) { | ||
| __extends(HorizontalLayout, _super); | ||
| function HorizontalLayout() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return HorizontalLayout; | ||
| }(Layout)); | ||
| /** | ||
| * @ignore | ||
| */ | ||
| var Tracer = /** @class */ (function (_super) { | ||
| __extends(Tracer, _super); | ||
| /** | ||
| * Create a tracer. | ||
| * | ||
| * @param title | ||
| */ | ||
| function Tracer(title) { | ||
| return _super.call(this, arguments) || this; | ||
| } | ||
| /** | ||
| * Pause to show changes in all tracers. | ||
| * | ||
| * @param lineNumber The line number to indicate when paused. If omitted, the line calling this method will be indicated. | ||
| */ | ||
| Tracer.delay = function (lineNumber) { | ||
| this.command(null, 'delay', arguments); | ||
| }; | ||
| /** | ||
| * Reset the tracer. | ||
| */ | ||
| Tracer.prototype.reset = function () { | ||
| this.command('reset', arguments); | ||
| }; | ||
| return Tracer; | ||
| }(Commander)); | ||
| var LogTracer = /** @class */ (function (_super) { | ||
| __extends(LogTracer, _super); | ||
| function LogTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| /** | ||
| * Set initial log to show. | ||
| * | ||
| * @param log | ||
| */ | ||
| LogTracer.prototype.set = function (log) { | ||
| this.command('set', arguments); | ||
| }; | ||
| /** | ||
| * Print log. | ||
| * | ||
| * @param message | ||
| */ | ||
| LogTracer.prototype.print = function (message) { | ||
| this.command('print', arguments); | ||
| }; | ||
| /** | ||
| * Print log and put a line break. | ||
| * | ||
| * @param message | ||
| */ | ||
| LogTracer.prototype.println = function (message) { | ||
| this.command('println', arguments); | ||
| }; | ||
| /** | ||
| * Print formatted log. | ||
| * | ||
| * @param format Refer to [sprintf-js](https://github.com/alexei/sprintf.js#format-specification). | ||
| * @param args | ||
| */ | ||
| LogTracer.prototype.printf = function (format) { | ||
| var args = []; | ||
| for (var _i = 1; _i < arguments.length; _i++) { | ||
| args[_i - 1] = arguments[_i]; | ||
| } | ||
| this.command('printf', arguments); | ||
| }; | ||
| return LogTracer; | ||
| }(Tracer)); | ||
| var Array2DTracer = /** @class */ (function (_super) { | ||
| __extends(Array2DTracer, _super); | ||
| function Array2DTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| /** | ||
| * Set a two-dimensional array to visualize. | ||
| * | ||
| * @param array2d | ||
| */ | ||
| Array2DTracer.prototype.set = function (array2d) { | ||
| this.command('set', arguments); | ||
| }; | ||
| /** | ||
| * Notify that a value has been changed. | ||
| * | ||
| * @param x The row index of the array. | ||
| * @param y The column index of the array. | ||
| * @param v The new value to change to. | ||
| */ | ||
| Array2DTracer.prototype.patch = function (x, y, v) { | ||
| this.command('patch', arguments); | ||
| }; | ||
| /** | ||
| * Stop notifying that a value has been changed. | ||
| * | ||
| * @param x The row index of the array. | ||
| * @param y The column index of the array. | ||
| */ | ||
| Array2DTracer.prototype.depatch = function (x, y) { | ||
| this.command('depatch', arguments); | ||
| }; | ||
| /** | ||
| * Select indices of the array. | ||
| * | ||
| * @param sx The row index to select inclusively from. | ||
| * @param sy The column index to select inclusively from. | ||
| * @param ex The row index to select inclusively to. If omitted, it will only select index `sx`. | ||
| * @param ey The column index to select inclusively to. If omitted, it will only select index `sy`. | ||
| */ | ||
| Array2DTracer.prototype.select = function (sx, sy, ex, ey) { | ||
| this.command('select', arguments); | ||
| }; | ||
| /** | ||
| * Select indices of a row of the array. | ||
| * | ||
| * @param x The row index to select. | ||
| * @param sy The column index to select inclusively from. | ||
| * @param ey The column index to select inclusively to. | ||
| */ | ||
| Array2DTracer.prototype.selectRow = function (x, sy, ey) { | ||
| this.command('selectRow', arguments); | ||
| }; | ||
| /** | ||
| * Select indices of a column of the array. | ||
| * | ||
| * @param y The column index to select. | ||
| * @param sx The row index to select inclusively from. | ||
| * @param ex The row index to select inclusively to. | ||
| */ | ||
| Array2DTracer.prototype.selectCol = function (y, sx, ex) { | ||
| this.command('selectCol', arguments); | ||
| }; | ||
| /** | ||
| * Stop selecting indices of the array. | ||
| * | ||
| * @param sx The row index to stop selecting inclusively from. | ||
| * @param sy The column index to stop selecting inclusively from. | ||
| * @param ex The row index to stop selecting inclusively to. If omitted, it will only stop selecting index `sx`. | ||
| * @param ey The column index to stop selecting inclusively to. If omitted, it will only stop selecting index `sy`. | ||
| */ | ||
| Array2DTracer.prototype.deselect = function (sx, sy, ex, ey) { | ||
| this.command('deselect', arguments); | ||
| }; | ||
| /** | ||
| * Stop selecting indices of a row of the array. | ||
| * | ||
| * @param x The row index to stop selecting. | ||
| * @param sy The column index to stop selecting inclusively from. | ||
| * @param ey The column index to stop selecting inclusively to. | ||
| */ | ||
| Array2DTracer.prototype.deselectRow = function (x, sy, ey) { | ||
| this.command('deselectRow', arguments); | ||
| }; | ||
| /** | ||
| * Stop selecting indices of a column of the array. | ||
| * | ||
| * @param y The column index to stop selecting. | ||
| * @param sx The row index to stop selecting inclusively from. | ||
| * @param ex The row index to stop selecting inclusively to. | ||
| */ | ||
| Array2DTracer.prototype.deselectCol = function (y, sx, ex) { | ||
| this.command('deselectCol', arguments); | ||
| }; | ||
| return Array2DTracer; | ||
| }(Tracer)); | ||
| var Array1DTracer = /** @class */ (function (_super) { | ||
| __extends(Array1DTracer, _super); | ||
| function Array1DTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| /** | ||
| * Set an array to visualize. | ||
| * | ||
| * @param array1d | ||
| */ | ||
| Array1DTracer.prototype.set = function (array1d) { | ||
| this.command('set', arguments); | ||
| }; | ||
| /** | ||
| * Notify that a value has been changed. | ||
| * | ||
| * @param x The index of the array. | ||
| * @param v The new value to change to. | ||
| */ | ||
| Array1DTracer.prototype.patch = function (x, v) { | ||
| this.command('patch', arguments); | ||
| }; | ||
| /** | ||
| * Stop notifying that a value has been changed. | ||
| * | ||
| * @param x The index of the array. | ||
| */ | ||
| Array1DTracer.prototype.depatch = function (x) { | ||
| this.command('depatch', arguments); | ||
| }; | ||
| /** | ||
| * Select indices of the array. | ||
| * | ||
| * @param sx The index to select inclusively from. | ||
| * @param ex The index to select inclusively to. If omitted, it will only select index `sx`. | ||
| */ | ||
| Array1DTracer.prototype.select = function (sx, ex) { | ||
| this.command('select', arguments); | ||
| }; | ||
| /** | ||
| * Stop selecting indices of the array. | ||
| * | ||
| * @param sx The index to stop selecting inclusively from. | ||
| * @param ex The index to stop selecting inclusively to. If omitted, it will only stop selecting index `sx`. | ||
| */ | ||
| Array1DTracer.prototype.deselect = function (sx, ex) { | ||
| this.command('deselect', arguments); | ||
| }; | ||
| /** | ||
| * Synchronize with a chart tracer. | ||
| * | ||
| * @param chartTracer | ||
| */ | ||
| Array1DTracer.prototype.chart = function (chartTracer) { | ||
| this.command('chart', arguments); | ||
| }; | ||
| return Array1DTracer; | ||
| }(Tracer)); | ||
| var ChartTracer = /** @class */ (function (_super) { | ||
| __extends(ChartTracer, _super); | ||
| function ChartTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return ChartTracer; | ||
| }(Array1DTracer)); | ||
| var GraphTracer = /** @class */ (function (_super) { | ||
| __extends(GraphTracer, _super); | ||
| function GraphTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| /** | ||
| * Set an adjacency matrix to visualize. | ||
| * | ||
| * @param array2d | ||
| */ | ||
| GraphTracer.prototype.set = function (array2d) { | ||
| this.command('set', arguments); | ||
| }; | ||
| /** | ||
| * Make the graph directed. | ||
| * | ||
| * @param isDirected | ||
| */ | ||
| GraphTracer.prototype.directed = function (isDirected) { | ||
| this.command('directed', arguments); | ||
| return this; | ||
| }; | ||
| /** | ||
| * Make the graph weighted. | ||
| * | ||
| * @param isWeighted | ||
| */ | ||
| GraphTracer.prototype.weighted = function (isWeighted) { | ||
| this.command('weighted', arguments); | ||
| return this; | ||
| }; | ||
| /** | ||
| * Arrange nodes on a circular layout. | ||
| */ | ||
| GraphTracer.prototype.layoutCircle = function () { | ||
| this.command('layoutCircle', arguments); | ||
| return this; | ||
| }; | ||
| /** | ||
| * Arrange nodes on a tree layout. | ||
| * | ||
| * @param root The id of a root node. | ||
| * @param sorted Whether to sort sibling nodes. | ||
| */ | ||
| GraphTracer.prototype.layoutTree = function (root, sorted) { | ||
| this.command('layoutTree', arguments); | ||
| return this; | ||
| }; | ||
| /** | ||
| * Arrange nodes randomly. | ||
| */ | ||
| GraphTracer.prototype.layoutRandom = function () { | ||
| this.command('layoutRandom', arguments); | ||
| return this; | ||
| }; | ||
| /** | ||
| * Add a node. | ||
| * | ||
| * @param id | ||
| * @param weight | ||
| * @param x The x position between `-160` and `+160`. | ||
| * @param y The y position between `-160` and `+160`. | ||
| */ | ||
| GraphTracer.prototype.addNode = function (id, weight, x, y) { | ||
| this.command('addNode', arguments); | ||
| }; | ||
| /** | ||
| * Update a node. | ||
| * | ||
| * @param id | ||
| * @param weight | ||
| * @param x The x position between `-160` and `+160`. | ||
| * @param y The y position between `-160` and `+160`. | ||
| */ | ||
| GraphTracer.prototype.updateNode = function (id, weight, x, y) { | ||
| this.command('updateNode', arguments); | ||
| }; | ||
| /** | ||
| * Remove a node. | ||
| * | ||
| * @param id | ||
| */ | ||
| GraphTracer.prototype.removeNode = function (id) { | ||
| this.command('removeNode', arguments); | ||
| }; | ||
| /** | ||
| * Add an edge. | ||
| * | ||
| * @param source The id of the node where the edge starts. | ||
| * @param target The id of the node where the edge ends. | ||
| * @param weight | ||
| */ | ||
| GraphTracer.prototype.addEdge = function (source, target, weight) { | ||
| this.command('addEdge', arguments); | ||
| }; | ||
| /** | ||
| * Update an edge. | ||
| * | ||
| * @param source The id of the node where the edge starts. | ||
| * @param target The id of the node where the edge ends. | ||
| * @param weight | ||
| */ | ||
| GraphTracer.prototype.updateEdge = function (source, target, weight) { | ||
| this.command('updateEdge', arguments); | ||
| }; | ||
| /** | ||
| * Remove an edge. | ||
| * | ||
| * @param source The id of the node where the edge starts. | ||
| * @param target The id of the node where the edge ends. | ||
| */ | ||
| GraphTracer.prototype.removeEdge = function (source, target) { | ||
| this.command('removeEdge', arguments); | ||
| }; | ||
| /** | ||
| * Visit a node. | ||
| * | ||
| * @param target The id of the node to visit. | ||
| * @param source The id of the node to visit from. | ||
| * @param weight The weight of `target` to set to. | ||
| */ | ||
| GraphTracer.prototype.visit = function (target, source, weight) { | ||
| this.command('visit', arguments); | ||
| }; | ||
| /** | ||
| * Leave after visiting a node. | ||
| * | ||
| * @param target The id of the node to leave. | ||
| * @param source The id of the node to leave to. | ||
| * @param weight The weight of `target` to set to. | ||
| */ | ||
| GraphTracer.prototype.leave = function (target, source, weight) { | ||
| this.command('leave', arguments); | ||
| }; | ||
| /** | ||
| * Select a node. | ||
| * | ||
| * @param target The id of the node to select. | ||
| * @param source The id of the node to select from. | ||
| */ | ||
| GraphTracer.prototype.select = function (target, source) { | ||
| this.command('select', arguments); | ||
| }; | ||
| /** | ||
| * Stop selecting a node. | ||
| * | ||
| * @param target The id of the node to stop selecting. | ||
| * @param source The id of the node to stop selecting from. | ||
| */ | ||
| GraphTracer.prototype.deselect = function (target, source) { | ||
| this.command('deselect', arguments); | ||
| }; | ||
| /** | ||
| * Synchronize with a log tracer. | ||
| * | ||
| * @param logTracer | ||
| */ | ||
| GraphTracer.prototype.log = function (logTracer) { | ||
| this.command('log', arguments); | ||
| }; | ||
| return GraphTracer; | ||
| }(Tracer)); | ||
| export { Array1DTracer, Array2DTracer, ChartTracer, Commander, GraphTracer, HorizontalLayout, Layout, LogTracer, Randomize$1 as Randomize, Tracer, VerticalLayout }; |
| (function (global, factory) { | ||
| typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
| typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
| (global = global || self, factory(global.AlgorithmVisualizer = {})); | ||
| }(this, function (exports) { 'use strict'; | ||
| var Randomize; | ||
| (function (Randomize) { | ||
| function Integer(options) { | ||
| var _a = options || {}, _b = _a.min, min = _b === void 0 ? 1 : _b, _c = _a.max, max = _c === void 0 ? 9 : _c; | ||
| return Math.random() * (max - min + 1) + min | 0; | ||
| } | ||
| Randomize.Integer = Integer; | ||
| function Double(options) { | ||
| var _a = options || {}, _b = _a.min, min = _b === void 0 ? 0 : _b, _c = _a.max, max = _c === void 0 ? 1 : _c; | ||
| return Math.random() * (max - min) + min; | ||
| } | ||
| Randomize.Double = Double; | ||
| function String(options) { | ||
| var _a = options || {}, _b = _a.length, length = _b === void 0 ? 16 : _b, _c = _a.letters, letters = _c === void 0 ? 'abcdefghijklmnopqrstuvwxyz' : _c; | ||
| var text = ''; | ||
| for (var i = 0; i < length; i++) { | ||
| text += letters[Integer({ min: 0, max: letters.length - 1 })]; | ||
| } | ||
| return text; | ||
| } | ||
| Randomize.String = String; | ||
| function Array2D(options) { | ||
| var _a = options || {}, _b = _a.N, N = _b === void 0 ? 10 : _b, _c = _a.M, M = _c === void 0 ? 10 : _c, _d = _a.value, value = _d === void 0 ? function () { return Integer(); } : _d, _e = _a.sorted, sorted = _e === void 0 ? false : _e; | ||
| var D = []; | ||
| for (var i = 0; i < N; i++) { | ||
| D.push([]); | ||
| for (var j = 0; j < M; j++) { | ||
| D[i].push(value(i, j)); | ||
| } | ||
| if (sorted) | ||
| D[i].sort(function (a, b) { return a - b; }); | ||
| } | ||
| return D; | ||
| } | ||
| Randomize.Array2D = Array2D; | ||
| function Array1D(options) { | ||
| var _a = options || {}, _b = _a.N, N = _b === void 0 ? 10 : _b, _c = _a.value, value = _c === void 0 ? function () { return Integer(); } : _c, _d = _a.sorted, sorted = _d === void 0 ? false : _d; | ||
| return Array2D({ | ||
| N: 1, | ||
| M: N, | ||
| value: value && (function (i, j) { return value(j); }), | ||
| sorted: sorted, | ||
| })[0]; | ||
| } | ||
| Randomize.Array1D = Array1D; | ||
| function Graph(options) { | ||
| var _a = options || {}, _b = _a.N, N = _b === void 0 ? 5 : _b, _c = _a.ratio, ratio = _c === void 0 ? .3 : _c, _d = _a.value, value = _d === void 0 ? function () { return Integer(); } : _d, _e = _a.directed, directed = _e === void 0 ? true : _e, _f = _a.weighted, weighted = _f === void 0 ? false : _f; | ||
| var G = new Array(N); | ||
| for (var i = 0; i < N; i++) { | ||
| G[i] = new Array(N); | ||
| } | ||
| for (var i = 0; i < N; i++) { | ||
| for (var j = 0; j < N; j++) { | ||
| if (i === j) { | ||
| G[i][j] = 0; | ||
| } | ||
| else if (directed || i < j) { | ||
| G[i][j] = Math.random() < ratio ? weighted ? value(i, j) : 1 : 0; | ||
| } | ||
| else { | ||
| G[i][j] = G[j][i]; | ||
| } | ||
| } | ||
| } | ||
| return G; | ||
| } | ||
| Randomize.Graph = Graph; | ||
| })(Randomize || (Randomize = {})); | ||
| var Randomize$1 = Randomize; | ||
| var MAX_COMMANDS = 1000000; | ||
| var MAX_OBJECTS = 100; | ||
| /** | ||
| * @ignore | ||
| */ | ||
| var Commander = /** @class */ (function () { | ||
| function Commander(iArguments) { | ||
| Commander.objectCount++; | ||
| var className = this.constructor.name; | ||
| this.key = Commander.randomizeKey(); | ||
| this.command(className, iArguments); | ||
| } | ||
| Commander.command = function (key, method, iArguments) { | ||
| var args = Array.from(iArguments); | ||
| this.commands.push({ | ||
| key: key, | ||
| method: method, | ||
| args: JSON.parse(JSON.stringify(args)), | ||
| }); | ||
| if (this.commands.length > MAX_COMMANDS) | ||
| throw new Error('Too Many Commands'); | ||
| if (this.objectCount > MAX_OBJECTS) | ||
| throw new Error('Too Many Objects'); | ||
| }; | ||
| Commander.randomizeKey = function () { | ||
| return Randomize$1.String({ length: 8, letters: 'abcdefghijklmnopqrstuvwxyz0123456789' }); | ||
| }; | ||
| /** | ||
| * Remove the tracer. | ||
| */ | ||
| Commander.prototype.destroy = function () { | ||
| Commander.objectCount--; | ||
| this.command('destroy', arguments); | ||
| }; | ||
| Commander.prototype.command = function (method, iArguments) { | ||
| Commander.command(this.key, method, iArguments); | ||
| }; | ||
| Commander.prototype.toJSON = function () { | ||
| return this.key; | ||
| }; | ||
| /** | ||
| * @ignore | ||
| */ | ||
| Commander.commands = []; | ||
| Commander.objectCount = 0; | ||
| return Commander; | ||
| }()); | ||
| if (!process.env.ALGORITHM_VISUALIZER) { | ||
| var axios_1 = require('axios'); | ||
| var opn_1 = require('opn'); | ||
| process.on('beforeExit', function () { | ||
| axios_1.post('https://algorithm-visualizer.org/api/visualizations', { content: JSON.stringify(Commander.commands) }) | ||
| .then(function (response) { return opn_1(response.data, { wait: false }); }) | ||
| .catch(console.error) | ||
| .finally(function () { return process.exit(); }); | ||
| }); | ||
| } | ||
| /*! ***************************************************************************** | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
| this file except in compliance with the License. You may obtain a copy of the | ||
| License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
| WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
| MERCHANTABLITY OR NON-INFRINGEMENT. | ||
| See the Apache Version 2.0 License for specific language governing permissions | ||
| and limitations under the License. | ||
| ***************************************************************************** */ | ||
| /* global Reflect, Promise */ | ||
| var extendStatics = function(d, b) { | ||
| extendStatics = Object.setPrototypeOf || | ||
| ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
| function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
| return extendStatics(d, b); | ||
| }; | ||
| function __extends(d, b) { | ||
| extendStatics(d, b); | ||
| function __() { this.constructor = d; } | ||
| d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
| } | ||
| /** | ||
| * @ignore | ||
| */ | ||
| var Layout = /** @class */ (function (_super) { | ||
| __extends(Layout, _super); | ||
| /** | ||
| * Create a layout. | ||
| * | ||
| * @param children The child views to contain. | ||
| */ | ||
| function Layout(children) { | ||
| return _super.call(this, arguments) || this; | ||
| } | ||
| /** | ||
| * Set a view as the root view. | ||
| * | ||
| * @param root | ||
| */ | ||
| Layout.setRoot = function (root) { | ||
| this.command(null, 'setRoot', arguments); | ||
| }; | ||
| /** | ||
| * Add a child to the layout. | ||
| * | ||
| * @param child | ||
| * @param index The index to add the child to. | ||
| */ | ||
| Layout.prototype.add = function (child, index) { | ||
| this.command('add', arguments); | ||
| }; | ||
| /** | ||
| * Remove a child from the layout. | ||
| * | ||
| * @param child | ||
| */ | ||
| Layout.prototype.remove = function (child) { | ||
| this.command('remove', arguments); | ||
| }; | ||
| /** | ||
| * Remove all the child views from the layout. | ||
| */ | ||
| Layout.prototype.removeAll = function () { | ||
| this.command('removeAll', arguments); | ||
| }; | ||
| return Layout; | ||
| }(Commander)); | ||
| var VerticalLayout = /** @class */ (function (_super) { | ||
| __extends(VerticalLayout, _super); | ||
| function VerticalLayout() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return VerticalLayout; | ||
| }(Layout)); | ||
| var HorizontalLayout = /** @class */ (function (_super) { | ||
| __extends(HorizontalLayout, _super); | ||
| function HorizontalLayout() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return HorizontalLayout; | ||
| }(Layout)); | ||
| /** | ||
| * @ignore | ||
| */ | ||
| var Tracer = /** @class */ (function (_super) { | ||
| __extends(Tracer, _super); | ||
| /** | ||
| * Create a tracer. | ||
| * | ||
| * @param title | ||
| */ | ||
| function Tracer(title) { | ||
| return _super.call(this, arguments) || this; | ||
| } | ||
| /** | ||
| * Pause to show changes in all tracers. | ||
| * | ||
| * @param lineNumber The line number to indicate when paused. If omitted, the line calling this method will be indicated. | ||
| */ | ||
| Tracer.delay = function (lineNumber) { | ||
| this.command(null, 'delay', arguments); | ||
| }; | ||
| /** | ||
| * Reset the tracer. | ||
| */ | ||
| Tracer.prototype.reset = function () { | ||
| this.command('reset', arguments); | ||
| }; | ||
| return Tracer; | ||
| }(Commander)); | ||
| var LogTracer = /** @class */ (function (_super) { | ||
| __extends(LogTracer, _super); | ||
| function LogTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| /** | ||
| * Set initial log to show. | ||
| * | ||
| * @param log | ||
| */ | ||
| LogTracer.prototype.set = function (log) { | ||
| this.command('set', arguments); | ||
| }; | ||
| /** | ||
| * Print log. | ||
| * | ||
| * @param message | ||
| */ | ||
| LogTracer.prototype.print = function (message) { | ||
| this.command('print', arguments); | ||
| }; | ||
| /** | ||
| * Print log and put a line break. | ||
| * | ||
| * @param message | ||
| */ | ||
| LogTracer.prototype.println = function (message) { | ||
| this.command('println', arguments); | ||
| }; | ||
| /** | ||
| * Print formatted log. | ||
| * | ||
| * @param format Refer to [sprintf-js](https://github.com/alexei/sprintf.js#format-specification). | ||
| * @param args | ||
| */ | ||
| LogTracer.prototype.printf = function (format) { | ||
| var args = []; | ||
| for (var _i = 1; _i < arguments.length; _i++) { | ||
| args[_i - 1] = arguments[_i]; | ||
| } | ||
| this.command('printf', arguments); | ||
| }; | ||
| return LogTracer; | ||
| }(Tracer)); | ||
| var Array2DTracer = /** @class */ (function (_super) { | ||
| __extends(Array2DTracer, _super); | ||
| function Array2DTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| /** | ||
| * Set a two-dimensional array to visualize. | ||
| * | ||
| * @param array2d | ||
| */ | ||
| Array2DTracer.prototype.set = function (array2d) { | ||
| this.command('set', arguments); | ||
| }; | ||
| /** | ||
| * Notify that a value has been changed. | ||
| * | ||
| * @param x The row index of the array. | ||
| * @param y The column index of the array. | ||
| * @param v The new value to change to. | ||
| */ | ||
| Array2DTracer.prototype.patch = function (x, y, v) { | ||
| this.command('patch', arguments); | ||
| }; | ||
| /** | ||
| * Stop notifying that a value has been changed. | ||
| * | ||
| * @param x The row index of the array. | ||
| * @param y The column index of the array. | ||
| */ | ||
| Array2DTracer.prototype.depatch = function (x, y) { | ||
| this.command('depatch', arguments); | ||
| }; | ||
| /** | ||
| * Select indices of the array. | ||
| * | ||
| * @param sx The row index to select inclusively from. | ||
| * @param sy The column index to select inclusively from. | ||
| * @param ex The row index to select inclusively to. If omitted, it will only select index `sx`. | ||
| * @param ey The column index to select inclusively to. If omitted, it will only select index `sy`. | ||
| */ | ||
| Array2DTracer.prototype.select = function (sx, sy, ex, ey) { | ||
| this.command('select', arguments); | ||
| }; | ||
| /** | ||
| * Select indices of a row of the array. | ||
| * | ||
| * @param x The row index to select. | ||
| * @param sy The column index to select inclusively from. | ||
| * @param ey The column index to select inclusively to. | ||
| */ | ||
| Array2DTracer.prototype.selectRow = function (x, sy, ey) { | ||
| this.command('selectRow', arguments); | ||
| }; | ||
| /** | ||
| * Select indices of a column of the array. | ||
| * | ||
| * @param y The column index to select. | ||
| * @param sx The row index to select inclusively from. | ||
| * @param ex The row index to select inclusively to. | ||
| */ | ||
| Array2DTracer.prototype.selectCol = function (y, sx, ex) { | ||
| this.command('selectCol', arguments); | ||
| }; | ||
| /** | ||
| * Stop selecting indices of the array. | ||
| * | ||
| * @param sx The row index to stop selecting inclusively from. | ||
| * @param sy The column index to stop selecting inclusively from. | ||
| * @param ex The row index to stop selecting inclusively to. If omitted, it will only stop selecting index `sx`. | ||
| * @param ey The column index to stop selecting inclusively to. If omitted, it will only stop selecting index `sy`. | ||
| */ | ||
| Array2DTracer.prototype.deselect = function (sx, sy, ex, ey) { | ||
| this.command('deselect', arguments); | ||
| }; | ||
| /** | ||
| * Stop selecting indices of a row of the array. | ||
| * | ||
| * @param x The row index to stop selecting. | ||
| * @param sy The column index to stop selecting inclusively from. | ||
| * @param ey The column index to stop selecting inclusively to. | ||
| */ | ||
| Array2DTracer.prototype.deselectRow = function (x, sy, ey) { | ||
| this.command('deselectRow', arguments); | ||
| }; | ||
| /** | ||
| * Stop selecting indices of a column of the array. | ||
| * | ||
| * @param y The column index to stop selecting. | ||
| * @param sx The row index to stop selecting inclusively from. | ||
| * @param ex The row index to stop selecting inclusively to. | ||
| */ | ||
| Array2DTracer.prototype.deselectCol = function (y, sx, ex) { | ||
| this.command('deselectCol', arguments); | ||
| }; | ||
| return Array2DTracer; | ||
| }(Tracer)); | ||
| var Array1DTracer = /** @class */ (function (_super) { | ||
| __extends(Array1DTracer, _super); | ||
| function Array1DTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| /** | ||
| * Set an array to visualize. | ||
| * | ||
| * @param array1d | ||
| */ | ||
| Array1DTracer.prototype.set = function (array1d) { | ||
| this.command('set', arguments); | ||
| }; | ||
| /** | ||
| * Notify that a value has been changed. | ||
| * | ||
| * @param x The index of the array. | ||
| * @param v The new value to change to. | ||
| */ | ||
| Array1DTracer.prototype.patch = function (x, v) { | ||
| this.command('patch', arguments); | ||
| }; | ||
| /** | ||
| * Stop notifying that a value has been changed. | ||
| * | ||
| * @param x The index of the array. | ||
| */ | ||
| Array1DTracer.prototype.depatch = function (x) { | ||
| this.command('depatch', arguments); | ||
| }; | ||
| /** | ||
| * Select indices of the array. | ||
| * | ||
| * @param sx The index to select inclusively from. | ||
| * @param ex The index to select inclusively to. If omitted, it will only select index `sx`. | ||
| */ | ||
| Array1DTracer.prototype.select = function (sx, ex) { | ||
| this.command('select', arguments); | ||
| }; | ||
| /** | ||
| * Stop selecting indices of the array. | ||
| * | ||
| * @param sx The index to stop selecting inclusively from. | ||
| * @param ex The index to stop selecting inclusively to. If omitted, it will only stop selecting index `sx`. | ||
| */ | ||
| Array1DTracer.prototype.deselect = function (sx, ex) { | ||
| this.command('deselect', arguments); | ||
| }; | ||
| /** | ||
| * Synchronize with a chart tracer. | ||
| * | ||
| * @param chartTracer | ||
| */ | ||
| Array1DTracer.prototype.chart = function (chartTracer) { | ||
| this.command('chart', arguments); | ||
| }; | ||
| return Array1DTracer; | ||
| }(Tracer)); | ||
| var ChartTracer = /** @class */ (function (_super) { | ||
| __extends(ChartTracer, _super); | ||
| function ChartTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return ChartTracer; | ||
| }(Array1DTracer)); | ||
| var GraphTracer = /** @class */ (function (_super) { | ||
| __extends(GraphTracer, _super); | ||
| function GraphTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| /** | ||
| * Set an adjacency matrix to visualize. | ||
| * | ||
| * @param array2d | ||
| */ | ||
| GraphTracer.prototype.set = function (array2d) { | ||
| this.command('set', arguments); | ||
| }; | ||
| /** | ||
| * Make the graph directed. | ||
| * | ||
| * @param isDirected | ||
| */ | ||
| GraphTracer.prototype.directed = function (isDirected) { | ||
| this.command('directed', arguments); | ||
| return this; | ||
| }; | ||
| /** | ||
| * Make the graph weighted. | ||
| * | ||
| * @param isWeighted | ||
| */ | ||
| GraphTracer.prototype.weighted = function (isWeighted) { | ||
| this.command('weighted', arguments); | ||
| return this; | ||
| }; | ||
| /** | ||
| * Arrange nodes on a circular layout. | ||
| */ | ||
| GraphTracer.prototype.layoutCircle = function () { | ||
| this.command('layoutCircle', arguments); | ||
| return this; | ||
| }; | ||
| /** | ||
| * Arrange nodes on a tree layout. | ||
| * | ||
| * @param root The id of a root node. | ||
| * @param sorted Whether to sort sibling nodes. | ||
| */ | ||
| GraphTracer.prototype.layoutTree = function (root, sorted) { | ||
| this.command('layoutTree', arguments); | ||
| return this; | ||
| }; | ||
| /** | ||
| * Arrange nodes randomly. | ||
| */ | ||
| GraphTracer.prototype.layoutRandom = function () { | ||
| this.command('layoutRandom', arguments); | ||
| return this; | ||
| }; | ||
| /** | ||
| * Add a node. | ||
| * | ||
| * @param id | ||
| * @param weight | ||
| * @param x The x position between `-160` and `+160`. | ||
| * @param y The y position between `-160` and `+160`. | ||
| */ | ||
| GraphTracer.prototype.addNode = function (id, weight, x, y) { | ||
| this.command('addNode', arguments); | ||
| }; | ||
| /** | ||
| * Update a node. | ||
| * | ||
| * @param id | ||
| * @param weight | ||
| * @param x The x position between `-160` and `+160`. | ||
| * @param y The y position between `-160` and `+160`. | ||
| */ | ||
| GraphTracer.prototype.updateNode = function (id, weight, x, y) { | ||
| this.command('updateNode', arguments); | ||
| }; | ||
| /** | ||
| * Remove a node. | ||
| * | ||
| * @param id | ||
| */ | ||
| GraphTracer.prototype.removeNode = function (id) { | ||
| this.command('removeNode', arguments); | ||
| }; | ||
| /** | ||
| * Add an edge. | ||
| * | ||
| * @param source The id of the node where the edge starts. | ||
| * @param target The id of the node where the edge ends. | ||
| * @param weight | ||
| */ | ||
| GraphTracer.prototype.addEdge = function (source, target, weight) { | ||
| this.command('addEdge', arguments); | ||
| }; | ||
| /** | ||
| * Update an edge. | ||
| * | ||
| * @param source The id of the node where the edge starts. | ||
| * @param target The id of the node where the edge ends. | ||
| * @param weight | ||
| */ | ||
| GraphTracer.prototype.updateEdge = function (source, target, weight) { | ||
| this.command('updateEdge', arguments); | ||
| }; | ||
| /** | ||
| * Remove an edge. | ||
| * | ||
| * @param source The id of the node where the edge starts. | ||
| * @param target The id of the node where the edge ends. | ||
| */ | ||
| GraphTracer.prototype.removeEdge = function (source, target) { | ||
| this.command('removeEdge', arguments); | ||
| }; | ||
| /** | ||
| * Visit a node. | ||
| * | ||
| * @param target The id of the node to visit. | ||
| * @param source The id of the node to visit from. | ||
| * @param weight The weight of `target` to set to. | ||
| */ | ||
| GraphTracer.prototype.visit = function (target, source, weight) { | ||
| this.command('visit', arguments); | ||
| }; | ||
| /** | ||
| * Leave after visiting a node. | ||
| * | ||
| * @param target The id of the node to leave. | ||
| * @param source The id of the node to leave to. | ||
| * @param weight The weight of `target` to set to. | ||
| */ | ||
| GraphTracer.prototype.leave = function (target, source, weight) { | ||
| this.command('leave', arguments); | ||
| }; | ||
| /** | ||
| * Select a node. | ||
| * | ||
| * @param target The id of the node to select. | ||
| * @param source The id of the node to select from. | ||
| */ | ||
| GraphTracer.prototype.select = function (target, source) { | ||
| this.command('select', arguments); | ||
| }; | ||
| /** | ||
| * Stop selecting a node. | ||
| * | ||
| * @param target The id of the node to stop selecting. | ||
| * @param source The id of the node to stop selecting from. | ||
| */ | ||
| GraphTracer.prototype.deselect = function (target, source) { | ||
| this.command('deselect', arguments); | ||
| }; | ||
| /** | ||
| * Synchronize with a log tracer. | ||
| * | ||
| * @param logTracer | ||
| */ | ||
| GraphTracer.prototype.log = function (logTracer) { | ||
| this.command('log', arguments); | ||
| }; | ||
| return GraphTracer; | ||
| }(Tracer)); | ||
| exports.Array1DTracer = Array1DTracer; | ||
| exports.Array2DTracer = Array2DTracer; | ||
| exports.ChartTracer = ChartTracer; | ||
| exports.Commander = Commander; | ||
| exports.GraphTracer = GraphTracer; | ||
| exports.HorizontalLayout = HorizontalLayout; | ||
| exports.Layout = Layout; | ||
| exports.LogTracer = LogTracer; | ||
| exports.Randomize = Randomize$1; | ||
| exports.Tracer = Tracer; | ||
| exports.VerticalLayout = VerticalLayout; | ||
| Object.defineProperty(exports, '__esModule', { value: true }); | ||
| })); |
+21
| MIT License | ||
| Copyright (c) 2019 Jinseo Jason Park | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
@@ -1,10 +0,42 @@ | ||
| import { Array2DTracer, ChartTracer } from './'; | ||
| declare class Array1DTracer extends Array2DTracer { | ||
| import { ChartTracer, Tracer } from './'; | ||
| export default class Array1DTracer extends Tracer { | ||
| /** | ||
| * Set an array to visualize. | ||
| * | ||
| * @param array1d | ||
| */ | ||
| set(array1d?: any[]): void; | ||
| /** | ||
| * Notify that a value has been changed. | ||
| * | ||
| * @param x The index of the array. | ||
| * @param v The new value to change to. | ||
| */ | ||
| patch(x: number, v?: any): void; | ||
| /** | ||
| * Stop notifying that a value has been changed. | ||
| * | ||
| * @param x The index of the array. | ||
| */ | ||
| depatch(x: number): void; | ||
| /** | ||
| * Select indices of the array. | ||
| * | ||
| * @param sx The index to select inclusively from. | ||
| * @param ex The index to select inclusively to. If omitted, it will only select index `sx`. | ||
| */ | ||
| select(sx: number, ex?: number): void; | ||
| /** | ||
| * Stop selecting indices of the array. | ||
| * | ||
| * @param sx The index to stop selecting inclusively from. | ||
| * @param ex The index to stop selecting inclusively to. If omitted, it will only stop selecting index `sx`. | ||
| */ | ||
| deselect(sx: number, ex?: number): void; | ||
| /** | ||
| * Synchronize with a chart tracer. | ||
| * | ||
| * @param chartTracer | ||
| */ | ||
| chart(chartTracer: ChartTracer): void; | ||
| } | ||
| export default Array1DTracer; |
| import { Tracer } from './'; | ||
| declare class Array2DTracer extends Tracer { | ||
| export default class Array2DTracer extends Tracer { | ||
| /** | ||
| * Set a two-dimensional array to visualize. | ||
| * | ||
| * @param array2d | ||
| */ | ||
| set(array2d?: any[][]): void; | ||
| /** | ||
| * Notify that a value has been changed. | ||
| * | ||
| * @param x The row index of the array. | ||
| * @param y The column index of the array. | ||
| * @param v The new value to change to. | ||
| */ | ||
| patch(x: number, y: number, v?: any): void; | ||
| /** | ||
| * Stop notifying that a value has been changed. | ||
| * | ||
| * @param x The row index of the array. | ||
| * @param y The column index of the array. | ||
| */ | ||
| depatch(x: number, y: number): void; | ||
| /** | ||
| * Select indices of the array. | ||
| * | ||
| * @param sx The row index to select inclusively from. | ||
| * @param sy The column index to select inclusively from. | ||
| * @param ex The row index to select inclusively to. If omitted, it will only select index `sx`. | ||
| * @param ey The column index to select inclusively to. If omitted, it will only select index `sy`. | ||
| */ | ||
| select(sx: number, sy: number, ex?: number, ey?: number): void; | ||
| /** | ||
| * Select indices of a row of the array. | ||
| * | ||
| * @param x The row index to select. | ||
| * @param sy The column index to select inclusively from. | ||
| * @param ey The column index to select inclusively to. | ||
| */ | ||
| selectRow(x: number, sy: number, ey: number): void; | ||
| /** | ||
| * Select indices of a column of the array. | ||
| * | ||
| * @param y The column index to select. | ||
| * @param sx The row index to select inclusively from. | ||
| * @param ex The row index to select inclusively to. | ||
| */ | ||
| selectCol(y: number, sx: number, ex: number): void; | ||
| /** | ||
| * Stop selecting indices of the array. | ||
| * | ||
| * @param sx The row index to stop selecting inclusively from. | ||
| * @param sy The column index to stop selecting inclusively from. | ||
| * @param ex The row index to stop selecting inclusively to. If omitted, it will only stop selecting index `sx`. | ||
| * @param ey The column index to stop selecting inclusively to. If omitted, it will only stop selecting index `sy`. | ||
| */ | ||
| deselect(sx: number, sy: number, ex?: number, ey?: number): void; | ||
| /** | ||
| * Stop selecting indices of a row of the array. | ||
| * | ||
| * @param x The row index to stop selecting. | ||
| * @param sy The column index to stop selecting inclusively from. | ||
| * @param ey The column index to stop selecting inclusively to. | ||
| */ | ||
| deselectRow(x: number, sy: number, ey: number): void; | ||
| /** | ||
| * Stop selecting indices of a column of the array. | ||
| * | ||
| * @param y The column index to stop selecting. | ||
| * @param sx The row index to stop selecting inclusively from. | ||
| * @param ex The row index to stop selecting inclusively to. | ||
| */ | ||
| deselectCol(y: number, sx: number, ex: number): void; | ||
| } | ||
| export default Array2DTracer; |
| import { Array1DTracer } from './'; | ||
| declare class ChartTracer extends Array1DTracer { | ||
| export default class ChartTracer extends Array1DTracer { | ||
| } | ||
| export default ChartTracer; |
@@ -0,1 +1,4 @@ | ||
| /** | ||
| * @ignore | ||
| */ | ||
| interface Command { | ||
@@ -6,13 +9,22 @@ key: string | null; | ||
| } | ||
| declare class Commander { | ||
| private static keyRandomizer; | ||
| /** | ||
| * @ignore | ||
| */ | ||
| export default abstract class Commander { | ||
| /** | ||
| * @ignore | ||
| */ | ||
| static commands: Command[]; | ||
| private static objectCount; | ||
| static commands: Command[]; | ||
| static command(key: string | null, method: string, iArguments: IArguments): void; | ||
| private readonly key; | ||
| constructor(iArguments: IArguments); | ||
| protected constructor(iArguments: IArguments); | ||
| protected static command(key: string | null, method: string, iArguments: IArguments): void; | ||
| private static randomizeKey; | ||
| /** | ||
| * Remove the tracer. | ||
| */ | ||
| destroy(): void; | ||
| command(method: string, iArguments: IArguments): void; | ||
| toJSON(): string; | ||
| protected command(method: string, iArguments: IArguments): void; | ||
| protected toJSON(): string; | ||
| } | ||
| export default Commander; | ||
| export {}; |
| import { LogTracer, Tracer } from './'; | ||
| declare class GraphTracer extends Tracer { | ||
| export default class GraphTracer extends Tracer { | ||
| /** | ||
| * Set an adjacency matrix to visualize. | ||
| * | ||
| * @param array2d | ||
| */ | ||
| set(array2d?: any[][]): void; | ||
| /** | ||
| * Make the graph directed. | ||
| * | ||
| * @param isDirected | ||
| */ | ||
| directed(isDirected?: boolean): this; | ||
| /** | ||
| * Make the graph weighted. | ||
| * | ||
| * @param isWeighted | ||
| */ | ||
| weighted(isWeighted?: boolean): this; | ||
| /** | ||
| * Arrange nodes on a circular layout. | ||
| */ | ||
| layoutCircle(): this; | ||
| /** | ||
| * Arrange nodes on a tree layout. | ||
| * | ||
| * @param root The id of a root node. | ||
| * @param sorted Whether to sort sibling nodes. | ||
| */ | ||
| layoutTree(root?: any, sorted?: boolean): this; | ||
| /** | ||
| * Arrange nodes randomly. | ||
| */ | ||
| layoutRandom(): this; | ||
| addNode(id: any, weight?: any, x?: number, y?: number, visitedCount?: number, selectedCount?: number): void; | ||
| updateNode(id: any, weight?: any, x?: number, y?: number, visitedCount?: number, selectedCount?: number): void; | ||
| /** | ||
| * Add a node. | ||
| * | ||
| * @param id | ||
| * @param weight | ||
| * @param x The x position between `-160` and `+160`. | ||
| * @param y The y position between `-160` and `+160`. | ||
| */ | ||
| addNode(id: any, weight?: any, x?: number, y?: number): void; | ||
| /** | ||
| * Update a node. | ||
| * | ||
| * @param id | ||
| * @param weight | ||
| * @param x The x position between `-160` and `+160`. | ||
| * @param y The y position between `-160` and `+160`. | ||
| */ | ||
| updateNode(id: any, weight?: any, x?: number, y?: number): void; | ||
| /** | ||
| * Remove a node. | ||
| * | ||
| * @param id | ||
| */ | ||
| removeNode(id: any): void; | ||
| addEdge(source: any, target: any, weight?: any, visitedCount?: number, selectedCount?: number): void; | ||
| updateEdge(source: any, target: any, weight?: any, visitedCount?: number, selectedCount?: number): void; | ||
| /** | ||
| * Add an edge. | ||
| * | ||
| * @param source The id of the node where the edge starts. | ||
| * @param target The id of the node where the edge ends. | ||
| * @param weight | ||
| */ | ||
| addEdge(source: any, target: any, weight?: any): void; | ||
| /** | ||
| * Update an edge. | ||
| * | ||
| * @param source The id of the node where the edge starts. | ||
| * @param target The id of the node where the edge ends. | ||
| * @param weight | ||
| */ | ||
| updateEdge(source: any, target: any, weight?: any): void; | ||
| /** | ||
| * Remove an edge. | ||
| * | ||
| * @param source The id of the node where the edge starts. | ||
| * @param target The id of the node where the edge ends. | ||
| */ | ||
| removeEdge(source: any, target: any): void; | ||
| /** | ||
| * Visit a node. | ||
| * | ||
| * @param target The id of the node to visit. | ||
| * @param source The id of the node to visit from. | ||
| * @param weight The weight of `target` to set to. | ||
| */ | ||
| visit(target: any, source?: any, weight?: any): void; | ||
| /** | ||
| * Leave after visiting a node. | ||
| * | ||
| * @param target The id of the node to leave. | ||
| * @param source The id of the node to leave to. | ||
| * @param weight The weight of `target` to set to. | ||
| */ | ||
| leave(target: any, source?: any, weight?: any): void; | ||
| /** | ||
| * Select a node. | ||
| * | ||
| * @param target The id of the node to select. | ||
| * @param source The id of the node to select from. | ||
| */ | ||
| select(target: any, source?: any): void; | ||
| /** | ||
| * Stop selecting a node. | ||
| * | ||
| * @param target The id of the node to stop selecting. | ||
| * @param source The id of the node to stop selecting from. | ||
| */ | ||
| deselect(target: any, source?: any): void; | ||
| /** | ||
| * Synchronize with a log tracer. | ||
| * | ||
| * @param logTracer | ||
| */ | ||
| log(logTracer: LogTracer): void; | ||
| } | ||
| export default GraphTracer; |
| import { Layout } from './'; | ||
| declare class HorizontalLayout extends Layout { | ||
| export default class HorizontalLayout extends Layout { | ||
| } | ||
| export default HorizontalLayout; |
@@ -1,9 +0,35 @@ | ||
| import { Commander } from './'; | ||
| declare class Layout extends Commander { | ||
| static setRoot(child: Commander): void; | ||
| constructor(children: [Commander]); | ||
| add(child: Commander, index?: Number): void; | ||
| remove(child: Commander): void; | ||
| import { Commander, Tracer } from './'; | ||
| /** | ||
| * @ignore | ||
| */ | ||
| export default abstract class Layout extends Commander { | ||
| /** | ||
| * Create a layout. | ||
| * | ||
| * @param children The child views to contain. | ||
| */ | ||
| constructor(children: (Layout | Tracer)[]); | ||
| /** | ||
| * Set a view as the root view. | ||
| * | ||
| * @param root | ||
| */ | ||
| static setRoot(root: Layout | Tracer): void; | ||
| /** | ||
| * Add a child to the layout. | ||
| * | ||
| * @param child | ||
| * @param index The index to add the child to. | ||
| */ | ||
| add(child: Layout | Tracer, index?: Number): void; | ||
| /** | ||
| * Remove a child from the layout. | ||
| * | ||
| * @param child | ||
| */ | ||
| remove(child: Layout | Tracer): void; | ||
| /** | ||
| * Remove all the child views from the layout. | ||
| */ | ||
| removeAll(): void; | ||
| } | ||
| export default Layout; |
| import { Tracer } from './'; | ||
| declare class LogTracer extends Tracer { | ||
| export default class LogTracer extends Tracer { | ||
| /** | ||
| * Set initial log to show. | ||
| * | ||
| * @param log | ||
| */ | ||
| set(log?: string): void; | ||
| /** | ||
| * Print log. | ||
| * | ||
| * @param message | ||
| */ | ||
| print(message: any): void; | ||
| /** | ||
| * Print log and put a line break. | ||
| * | ||
| * @param message | ||
| */ | ||
| println(message: any): void; | ||
| /** | ||
| * Print formatted log. | ||
| * | ||
| * @param format Refer to [sprintf-js](https://github.com/alexei/sprintf.js#format-specification). | ||
| * @param args | ||
| */ | ||
| printf(format: string, ...args: any[]): void; | ||
| } | ||
| export default LogTracer; |
@@ -1,54 +0,98 @@ | ||
| declare class Randomizer { | ||
| create(): any; | ||
| declare namespace Randomize { | ||
| type IntegerOptions = { | ||
| /** | ||
| * The inclusive lower bound. | ||
| */ | ||
| min?: number; | ||
| /** | ||
| * The inclusive upper bound. | ||
| */ | ||
| max?: number; | ||
| }; | ||
| function Integer(options?: IntegerOptions): number; | ||
| type DoubleOptions = { | ||
| /** | ||
| * The inclusive lower bound. | ||
| */ | ||
| min?: number; | ||
| /** | ||
| * The exclusive upper bound. | ||
| */ | ||
| max?: number; | ||
| }; | ||
| function Double(options?: DoubleOptions): number; | ||
| type StringOptions = { | ||
| length?: number; | ||
| /** | ||
| * The character set to generate a random string from. | ||
| */ | ||
| letters?: string; | ||
| }; | ||
| function String(options?: StringOptions): string; | ||
| type Array2DOptions = { | ||
| /** | ||
| * The number of rows. | ||
| */ | ||
| N?: number; | ||
| /** | ||
| * The number of columns. | ||
| */ | ||
| M?: number; | ||
| /** | ||
| * The function to generate the value of each element. | ||
| * | ||
| * @param i The row index of an element to generate the value of. | ||
| * @param j The column index of an element to generate the value of. | ||
| */ | ||
| value?: (i: number, j: number) => any; | ||
| /** | ||
| * Whether to sort each row. | ||
| */ | ||
| sorted?: boolean; | ||
| }; | ||
| function Array2D(options?: Array2DOptions): any[][]; | ||
| type Array1DOptions = { | ||
| /** | ||
| * The number of elements. | ||
| */ | ||
| N?: number; | ||
| /** | ||
| * The function to generate the value of each element. | ||
| * | ||
| * @param i The index of an element to generate the value of. | ||
| */ | ||
| value?: (i: number) => any; | ||
| /** | ||
| * Whether to sort the array. | ||
| */ | ||
| sorted?: boolean; | ||
| }; | ||
| function Array1D(options?: Array1DOptions): any[]; | ||
| type GraphOptions = { | ||
| /** | ||
| * The number of nodes. | ||
| */ | ||
| N?: number; | ||
| /** | ||
| * The probability that an edge between any two nodes is generated. | ||
| */ | ||
| ratio?: number; | ||
| /** | ||
| * The function to generate the weight of each edge. | ||
| * | ||
| * @param source The id of the node where the edge starts. | ||
| * @param target The id of the node where the edge ends. | ||
| */ | ||
| value?: (i: number, j: number) => any; | ||
| /** | ||
| * Whether to make the graph directed. | ||
| */ | ||
| directed?: boolean; | ||
| /** | ||
| * Whether to make the graph weighted. | ||
| */ | ||
| weighted?: boolean; | ||
| }; | ||
| function Graph(options?: GraphOptions): any[][]; | ||
| } | ||
| declare class Integer extends Randomizer { | ||
| private readonly _min; | ||
| private readonly _max; | ||
| constructor(min?: number, max?: number); | ||
| create(): number; | ||
| } | ||
| declare class Double extends Randomizer { | ||
| private readonly _min; | ||
| private readonly _max; | ||
| constructor(min?: number, max?: number); | ||
| create(): number; | ||
| } | ||
| declare class String extends Randomizer { | ||
| private readonly _length; | ||
| private readonly _letters; | ||
| constructor(length?: number, letters?: string); | ||
| create(): string; | ||
| } | ||
| declare class Array2D extends Randomizer { | ||
| private readonly _N; | ||
| private readonly _M; | ||
| private readonly _randomizer; | ||
| private _sorted; | ||
| constructor(N?: number, M?: number, randomizer?: Randomizer); | ||
| sorted(sorted?: boolean): this; | ||
| create(): any[][]; | ||
| } | ||
| declare class Array1D extends Array2D { | ||
| constructor(N?: number, randomizer?: Randomizer); | ||
| create(): any[]; | ||
| } | ||
| declare class Graph extends Randomizer { | ||
| private readonly _N; | ||
| private readonly _ratio; | ||
| private _randomizer; | ||
| private _directed; | ||
| private _weighted; | ||
| constructor(N?: number, ratio?: number, randomizer?: Randomizer); | ||
| directed(directed?: boolean): this; | ||
| weighted(weighted?: boolean): this; | ||
| create(): any[][]; | ||
| } | ||
| declare const _default: { | ||
| Integer: typeof Integer; | ||
| Double: typeof Double; | ||
| String: typeof String; | ||
| Array1D: typeof Array1D; | ||
| Array2D: typeof Array2D; | ||
| Graph: typeof Graph; | ||
| }; | ||
| export default _default; | ||
| export default Randomize; |
| import { Commander } from './'; | ||
| declare class Tracer extends Commander { | ||
| /** | ||
| * @ignore | ||
| */ | ||
| export default abstract class Tracer extends Commander { | ||
| /** | ||
| * Create a tracer. | ||
| * | ||
| * @param title | ||
| */ | ||
| constructor(title?: string); | ||
| /** | ||
| * Pause to show changes in all tracers. | ||
| * | ||
| * @param lineNumber The line number to indicate when paused. If omitted, the line calling this method will be indicated. | ||
| */ | ||
| static delay(lineNumber?: Number): void; | ||
| constructor(title?: string); | ||
| set(): void; | ||
| /** | ||
| * Reset the tracer. | ||
| */ | ||
| reset(): void; | ||
| } | ||
| export default Tracer; |
| import { Layout } from './'; | ||
| declare class VerticalLayout extends Layout { | ||
| export default class VerticalLayout extends Layout { | ||
| } | ||
| export default VerticalLayout; |
+14
-5
| { | ||
| "name": "algorithm-visualizer", | ||
| "version": "2.3.3", | ||
| "version": "2.3.4", | ||
| "description": "Visualization Library for JavaScript", | ||
@@ -11,5 +11,10 @@ "keywords": [ | ||
| ], | ||
| "main": "dist/index.cjs.js", | ||
| "module": "dist/index.esm.js", | ||
| "browser": "dist/index.umd.js", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/algorithm-visualizer/tracers.js.git" | ||
| }, | ||
| "license": "MIT", | ||
| "main": "dist/algorithm-visualizer.cjs.js", | ||
| "module": "dist/algorithm-visualizer.esm.js", | ||
| "browser": "dist/algorithm-visualizer.umd.js", | ||
| "types": "dist/types", | ||
@@ -22,5 +27,7 @@ "dependencies": { | ||
| "@types/node": "^12.0.8", | ||
| "gh-pages": "^2.0.1", | ||
| "rollup": "^1.15.1", | ||
| "rollup-plugin-typescript2": "^0.21.1", | ||
| "tslib": "^1.10.0", | ||
| "typedoc": "^0.14.2", | ||
| "typescript": "^3.5.1" | ||
@@ -31,4 +38,6 @@ }, | ||
| "build": "rm -rf dist && rollup -c", | ||
| "docs": "typedoc", | ||
| "test": "node ./test", | ||
| "prepublishOnly": "npm run build" | ||
| "prepublishOnly": "npm run build", | ||
| "postpublish": "npm run docs && gh-pages -d docs" | ||
| }, | ||
@@ -35,0 +44,0 @@ "files": [ |
+2
-2
@@ -1,2 +0,2 @@ | ||
| # tracers.js | ||
| # tracers.js [](https://www.npmjs.com/package/algorithm-visualizer) | ||
@@ -24,3 +24,3 @@ > This repository is part of the project [Algorithm Visualizer](https://github.com/algorithm-visualizer). | ||
| Check out the [API reference](https://github.com/algorithm-visualizer/algorithm-visualizer/wiki) for more information. | ||
| Check out the [API reference](https://algorithm-visualizer.github.io/tracers.js/) for more information. | ||
@@ -27,0 +27,0 @@ ## Contributing |
| 'use strict'; | ||
| Object.defineProperty(exports, '__esModule', { value: true }); | ||
| /*! ***************************************************************************** | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
| this file except in compliance with the License. You may obtain a copy of the | ||
| License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
| WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
| MERCHANTABLITY OR NON-INFRINGEMENT. | ||
| See the Apache Version 2.0 License for specific language governing permissions | ||
| and limitations under the License. | ||
| ***************************************************************************** */ | ||
| /* global Reflect, Promise */ | ||
| var extendStatics = function(d, b) { | ||
| extendStatics = Object.setPrototypeOf || | ||
| ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
| function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
| return extendStatics(d, b); | ||
| }; | ||
| function __extends(d, b) { | ||
| extendStatics(d, b); | ||
| function __() { this.constructor = d; } | ||
| d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
| } | ||
| var Randomizer = /** @class */ (function () { | ||
| function Randomizer() { | ||
| } | ||
| Randomizer.prototype.create = function () { | ||
| return null; | ||
| }; | ||
| return Randomizer; | ||
| }()); | ||
| var Integer = /** @class */ (function (_super) { | ||
| __extends(Integer, _super); | ||
| function Integer(min, max) { | ||
| if (min === void 0) { min = 1; } | ||
| if (max === void 0) { max = 9; } | ||
| var _this = _super.call(this) || this; | ||
| _this._min = min; | ||
| _this._max = max; | ||
| return _this; | ||
| } | ||
| Integer.prototype.create = function () { | ||
| return Math.random() * (this._max - this._min + 1) + this._min | 0; | ||
| }; | ||
| return Integer; | ||
| }(Randomizer)); | ||
| var Double = /** @class */ (function (_super) { | ||
| __extends(Double, _super); | ||
| function Double(min, max) { | ||
| if (min === void 0) { min = 0; } | ||
| if (max === void 0) { max = 1; } | ||
| var _this = _super.call(this) || this; | ||
| _this._min = min; | ||
| _this._max = max; | ||
| return _this; | ||
| } | ||
| Double.prototype.create = function () { | ||
| return Math.random() * (this._max - this._min) + this._min; | ||
| }; | ||
| return Double; | ||
| }(Randomizer)); | ||
| var String = /** @class */ (function (_super) { | ||
| __extends(String, _super); | ||
| function String(length, letters) { | ||
| if (length === void 0) { length = 16; } | ||
| if (letters === void 0) { letters = 'abcdefghijklmnopqrstuvwxyz'; } | ||
| var _this = _super.call(this) || this; | ||
| _this._length = length; | ||
| _this._letters = letters; | ||
| return _this; | ||
| } | ||
| String.prototype.create = function () { | ||
| var text = ''; | ||
| var randomizer = new Integer(0, this._letters.length - 1); | ||
| for (var i = 0; i < this._length; i++) { | ||
| text += this._letters[randomizer.create()]; | ||
| } | ||
| return text; | ||
| }; | ||
| return String; | ||
| }(Randomizer)); | ||
| var Array2D = /** @class */ (function (_super) { | ||
| __extends(Array2D, _super); | ||
| function Array2D(N, M, randomizer) { | ||
| if (N === void 0) { N = 10; } | ||
| if (M === void 0) { M = 10; } | ||
| if (randomizer === void 0) { randomizer = new Integer(); } | ||
| var _this = _super.call(this) || this; | ||
| _this._N = N; | ||
| _this._M = M; | ||
| _this._randomizer = randomizer; | ||
| _this._sorted = false; | ||
| return _this; | ||
| } | ||
| Array2D.prototype.sorted = function (sorted) { | ||
| if (sorted === void 0) { sorted = true; } | ||
| this._sorted = sorted; | ||
| return this; | ||
| }; | ||
| Array2D.prototype.create = function () { | ||
| var D = []; | ||
| for (var i = 0; i < this._N; i++) { | ||
| D.push([]); | ||
| for (var j = 0; j < this._M; j++) { | ||
| D[i].push(this._randomizer.create()); | ||
| } | ||
| if (this._sorted) | ||
| D[i].sort(function (a, b) { return a - b; }); | ||
| } | ||
| return D; | ||
| }; | ||
| return Array2D; | ||
| }(Randomizer)); | ||
| var Array1D = /** @class */ (function (_super) { | ||
| __extends(Array1D, _super); | ||
| function Array1D(N, randomizer) { | ||
| return _super.call(this, 1, N, randomizer) || this; | ||
| } | ||
| Array1D.prototype.create = function () { | ||
| return _super.prototype.create.call(this)[0]; | ||
| }; | ||
| return Array1D; | ||
| }(Array2D)); | ||
| var Graph = /** @class */ (function (_super) { | ||
| __extends(Graph, _super); | ||
| function Graph(N, ratio, randomizer) { | ||
| if (N === void 0) { N = 5; } | ||
| if (ratio === void 0) { ratio = .3; } | ||
| if (randomizer === void 0) { randomizer = new Integer(); } | ||
| var _this = _super.call(this) || this; | ||
| _this._N = N; | ||
| _this._ratio = ratio; | ||
| _this._randomizer = randomizer; | ||
| _this._directed = true; | ||
| _this._weighted = false; | ||
| return _this; | ||
| } | ||
| Graph.prototype.directed = function (directed) { | ||
| if (directed === void 0) { directed = true; } | ||
| this._directed = directed; | ||
| return this; | ||
| }; | ||
| Graph.prototype.weighted = function (weighted) { | ||
| if (weighted === void 0) { weighted = true; } | ||
| this._weighted = weighted; | ||
| return this; | ||
| }; | ||
| Graph.prototype.create = function () { | ||
| var G = new Array(this._N); | ||
| for (var i = 0; i < this._N; i++) { | ||
| G[i] = new Array(this._N); | ||
| } | ||
| for (var i = 0; i < this._N; i++) { | ||
| for (var j = 0; j < this._N; j++) { | ||
| if (i === j) { | ||
| G[i][j] = 0; | ||
| } | ||
| else if (this._directed || i < j) { | ||
| G[i][j] = Math.random() < this._ratio ? this._weighted ? this._randomizer.create() : 1 : 0; | ||
| } | ||
| else { | ||
| G[i][j] = G[j][i]; | ||
| } | ||
| } | ||
| } | ||
| return G; | ||
| }; | ||
| return Graph; | ||
| }(Randomizer)); | ||
| var Randomize = { | ||
| Integer: Integer, | ||
| Double: Double, | ||
| String: String, | ||
| Array1D: Array1D, | ||
| Array2D: Array2D, | ||
| Graph: Graph, | ||
| }; | ||
| var MAX_COMMANDS = 1000000; | ||
| var MAX_OBJECTS = 100; | ||
| var Commander = /** @class */ (function () { | ||
| function Commander(iArguments) { | ||
| Commander.objectCount++; | ||
| var className = this.constructor.name; | ||
| this.key = Commander.keyRandomizer.create(); | ||
| this.command(className, iArguments); | ||
| } | ||
| Commander.command = function (key, method, iArguments) { | ||
| var args = Array.from(iArguments); | ||
| this.commands.push({ | ||
| key: key, | ||
| method: method, | ||
| args: JSON.parse(JSON.stringify(args)), | ||
| }); | ||
| if (this.commands.length > MAX_COMMANDS) | ||
| throw new Error('Too Many Commands'); | ||
| if (this.objectCount > MAX_OBJECTS) | ||
| throw new Error('Too Many Objects'); | ||
| }; | ||
| Commander.prototype.destroy = function () { | ||
| Commander.objectCount--; | ||
| this.command('destroy', arguments); | ||
| }; | ||
| Commander.prototype.command = function (method, iArguments) { | ||
| Commander.command(this.key, method, iArguments); | ||
| }; | ||
| Commander.prototype.toJSON = function () { | ||
| return this.key; | ||
| }; | ||
| Commander.keyRandomizer = new Randomize.String(8, 'abcdefghijklmnopqrstuvwxyz0123456789'); | ||
| Commander.objectCount = 0; | ||
| Commander.commands = []; | ||
| return Commander; | ||
| }()); | ||
| var ALGORITHM_VISUALIZER = process.env.ALGORITHM_VISUALIZER; | ||
| if (!ALGORITHM_VISUALIZER) { | ||
| var axios_1 = require('axios'); | ||
| var opn_1 = require('opn'); | ||
| process.on('beforeExit', function () { | ||
| axios_1.post('https://algorithm-visualizer.org/api/visualizations', { content: JSON.stringify(Commander.commands) }) | ||
| .then(function (response) { return opn_1(response.data, { wait: false }); }) | ||
| .catch(console.error) | ||
| .finally(function () { return process.exit(); }); | ||
| }); | ||
| } | ||
| var Layout = /** @class */ (function (_super) { | ||
| __extends(Layout, _super); | ||
| function Layout(children) { | ||
| return _super.call(this, arguments) || this; | ||
| } | ||
| Layout.setRoot = function (child) { | ||
| this.command(null, 'setRoot', arguments); | ||
| }; | ||
| Layout.prototype.add = function (child, index) { | ||
| this.command('add', arguments); | ||
| }; | ||
| Layout.prototype.remove = function (child) { | ||
| this.command('remove', arguments); | ||
| }; | ||
| Layout.prototype.removeAll = function () { | ||
| this.command('removeAll', arguments); | ||
| }; | ||
| return Layout; | ||
| }(Commander)); | ||
| var VerticalLayout = /** @class */ (function (_super) { | ||
| __extends(VerticalLayout, _super); | ||
| function VerticalLayout() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return VerticalLayout; | ||
| }(Layout)); | ||
| var HorizontalLayout = /** @class */ (function (_super) { | ||
| __extends(HorizontalLayout, _super); | ||
| function HorizontalLayout() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return HorizontalLayout; | ||
| }(Layout)); | ||
| var Tracer = /** @class */ (function (_super) { | ||
| __extends(Tracer, _super); | ||
| function Tracer(title) { | ||
| return _super.call(this, arguments) || this; | ||
| } | ||
| Tracer.delay = function (lineNumber) { | ||
| this.command(null, 'delay', arguments); | ||
| }; | ||
| Tracer.prototype.set = function () { | ||
| this.command('set', arguments); | ||
| }; | ||
| Tracer.prototype.reset = function () { | ||
| this.command('reset', arguments); | ||
| }; | ||
| return Tracer; | ||
| }(Commander)); | ||
| var LogTracer = /** @class */ (function (_super) { | ||
| __extends(LogTracer, _super); | ||
| function LogTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| LogTracer.prototype.set = function (log) { | ||
| this.command('set', arguments); | ||
| }; | ||
| LogTracer.prototype.print = function (message) { | ||
| this.command('print', arguments); | ||
| }; | ||
| LogTracer.prototype.println = function (message) { | ||
| this.command('println', arguments); | ||
| }; | ||
| LogTracer.prototype.printf = function (format) { | ||
| var args = []; | ||
| for (var _i = 1; _i < arguments.length; _i++) { | ||
| args[_i - 1] = arguments[_i]; | ||
| } | ||
| this.command('printf', arguments); | ||
| }; | ||
| return LogTracer; | ||
| }(Tracer)); | ||
| var Array2DTracer = /** @class */ (function (_super) { | ||
| __extends(Array2DTracer, _super); | ||
| function Array2DTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| Array2DTracer.prototype.set = function (array2d) { | ||
| this.command('set', arguments); | ||
| }; | ||
| Array2DTracer.prototype.patch = function (x, y, v) { | ||
| this.command('patch', arguments); | ||
| }; | ||
| Array2DTracer.prototype.depatch = function (x, y) { | ||
| this.command('depatch', arguments); | ||
| }; | ||
| Array2DTracer.prototype.select = function (sx, sy, ex, ey) { | ||
| this.command('select', arguments); | ||
| }; | ||
| Array2DTracer.prototype.selectRow = function (x, sy, ey) { | ||
| this.command('selectRow', arguments); | ||
| }; | ||
| Array2DTracer.prototype.selectCol = function (y, sx, ex) { | ||
| this.command('selectCol', arguments); | ||
| }; | ||
| Array2DTracer.prototype.deselect = function (sx, sy, ex, ey) { | ||
| this.command('deselect', arguments); | ||
| }; | ||
| Array2DTracer.prototype.deselectRow = function (x, sy, ey) { | ||
| this.command('deselectRow', arguments); | ||
| }; | ||
| Array2DTracer.prototype.deselectCol = function (y, sx, ex) { | ||
| this.command('deselectCol', arguments); | ||
| }; | ||
| return Array2DTracer; | ||
| }(Tracer)); | ||
| var Array1DTracer = /** @class */ (function (_super) { | ||
| __extends(Array1DTracer, _super); | ||
| function Array1DTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| Array1DTracer.prototype.set = function (array1d) { | ||
| this.command('set', arguments); | ||
| }; | ||
| Array1DTracer.prototype.patch = function (x, v) { | ||
| this.command('patch', arguments); | ||
| }; | ||
| Array1DTracer.prototype.depatch = function (x) { | ||
| this.command('depatch', arguments); | ||
| }; | ||
| Array1DTracer.prototype.select = function (sx, ex) { | ||
| this.command('select', arguments); | ||
| }; | ||
| Array1DTracer.prototype.deselect = function (sx, ex) { | ||
| this.command('deselect', arguments); | ||
| }; | ||
| Array1DTracer.prototype.chart = function (chartTracer) { | ||
| this.command('chart', arguments); | ||
| }; | ||
| return Array1DTracer; | ||
| }(Array2DTracer)); | ||
| var ChartTracer = /** @class */ (function (_super) { | ||
| __extends(ChartTracer, _super); | ||
| function ChartTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return ChartTracer; | ||
| }(Array1DTracer)); | ||
| var GraphTracer = /** @class */ (function (_super) { | ||
| __extends(GraphTracer, _super); | ||
| function GraphTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| GraphTracer.prototype.set = function (array2d) { | ||
| this.command('set', arguments); | ||
| }; | ||
| GraphTracer.prototype.directed = function (isDirected) { | ||
| this.command('directed', arguments); | ||
| return this; | ||
| }; | ||
| GraphTracer.prototype.weighted = function (isWeighted) { | ||
| this.command('weighted', arguments); | ||
| return this; | ||
| }; | ||
| GraphTracer.prototype.layoutCircle = function () { | ||
| this.command('layoutCircle', arguments); | ||
| return this; | ||
| }; | ||
| GraphTracer.prototype.layoutTree = function (root, sorted) { | ||
| this.command('layoutTree', arguments); | ||
| return this; | ||
| }; | ||
| GraphTracer.prototype.layoutRandom = function () { | ||
| this.command('layoutRandom', arguments); | ||
| return this; | ||
| }; | ||
| GraphTracer.prototype.addNode = function (id, weight, x, y, visitedCount, selectedCount) { | ||
| this.command('addNode', arguments); | ||
| }; | ||
| GraphTracer.prototype.updateNode = function (id, weight, x, y, visitedCount, selectedCount) { | ||
| this.command('updateNode', arguments); | ||
| }; | ||
| GraphTracer.prototype.removeNode = function (id) { | ||
| this.command('removeNode', arguments); | ||
| }; | ||
| GraphTracer.prototype.addEdge = function (source, target, weight, visitedCount, selectedCount) { | ||
| this.command('addEdge', arguments); | ||
| }; | ||
| GraphTracer.prototype.updateEdge = function (source, target, weight, visitedCount, selectedCount) { | ||
| this.command('updateEdge', arguments); | ||
| }; | ||
| GraphTracer.prototype.removeEdge = function (source, target) { | ||
| this.command('removeEdge', arguments); | ||
| }; | ||
| GraphTracer.prototype.visit = function (target, source, weight) { | ||
| this.command('visit', arguments); | ||
| }; | ||
| GraphTracer.prototype.leave = function (target, source, weight) { | ||
| this.command('leave', arguments); | ||
| }; | ||
| GraphTracer.prototype.select = function (target, source) { | ||
| this.command('select', arguments); | ||
| }; | ||
| GraphTracer.prototype.deselect = function (target, source) { | ||
| this.command('deselect', arguments); | ||
| }; | ||
| GraphTracer.prototype.log = function (logTracer) { | ||
| this.command('log', arguments); | ||
| }; | ||
| return GraphTracer; | ||
| }(Tracer)); | ||
| exports.Array1DTracer = Array1DTracer; | ||
| exports.Array2DTracer = Array2DTracer; | ||
| exports.ChartTracer = ChartTracer; | ||
| exports.Commander = Commander; | ||
| exports.GraphTracer = GraphTracer; | ||
| exports.HorizontalLayout = HorizontalLayout; | ||
| exports.Layout = Layout; | ||
| exports.LogTracer = LogTracer; | ||
| exports.Randomize = Randomize; | ||
| exports.Tracer = Tracer; | ||
| exports.VerticalLayout = VerticalLayout; |
| /*! ***************************************************************************** | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
| this file except in compliance with the License. You may obtain a copy of the | ||
| License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
| WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
| MERCHANTABLITY OR NON-INFRINGEMENT. | ||
| See the Apache Version 2.0 License for specific language governing permissions | ||
| and limitations under the License. | ||
| ***************************************************************************** */ | ||
| /* global Reflect, Promise */ | ||
| var extendStatics = function(d, b) { | ||
| extendStatics = Object.setPrototypeOf || | ||
| ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
| function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
| return extendStatics(d, b); | ||
| }; | ||
| function __extends(d, b) { | ||
| extendStatics(d, b); | ||
| function __() { this.constructor = d; } | ||
| d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
| } | ||
| var Randomizer = /** @class */ (function () { | ||
| function Randomizer() { | ||
| } | ||
| Randomizer.prototype.create = function () { | ||
| return null; | ||
| }; | ||
| return Randomizer; | ||
| }()); | ||
| var Integer = /** @class */ (function (_super) { | ||
| __extends(Integer, _super); | ||
| function Integer(min, max) { | ||
| if (min === void 0) { min = 1; } | ||
| if (max === void 0) { max = 9; } | ||
| var _this = _super.call(this) || this; | ||
| _this._min = min; | ||
| _this._max = max; | ||
| return _this; | ||
| } | ||
| Integer.prototype.create = function () { | ||
| return Math.random() * (this._max - this._min + 1) + this._min | 0; | ||
| }; | ||
| return Integer; | ||
| }(Randomizer)); | ||
| var Double = /** @class */ (function (_super) { | ||
| __extends(Double, _super); | ||
| function Double(min, max) { | ||
| if (min === void 0) { min = 0; } | ||
| if (max === void 0) { max = 1; } | ||
| var _this = _super.call(this) || this; | ||
| _this._min = min; | ||
| _this._max = max; | ||
| return _this; | ||
| } | ||
| Double.prototype.create = function () { | ||
| return Math.random() * (this._max - this._min) + this._min; | ||
| }; | ||
| return Double; | ||
| }(Randomizer)); | ||
| var String = /** @class */ (function (_super) { | ||
| __extends(String, _super); | ||
| function String(length, letters) { | ||
| if (length === void 0) { length = 16; } | ||
| if (letters === void 0) { letters = 'abcdefghijklmnopqrstuvwxyz'; } | ||
| var _this = _super.call(this) || this; | ||
| _this._length = length; | ||
| _this._letters = letters; | ||
| return _this; | ||
| } | ||
| String.prototype.create = function () { | ||
| var text = ''; | ||
| var randomizer = new Integer(0, this._letters.length - 1); | ||
| for (var i = 0; i < this._length; i++) { | ||
| text += this._letters[randomizer.create()]; | ||
| } | ||
| return text; | ||
| }; | ||
| return String; | ||
| }(Randomizer)); | ||
| var Array2D = /** @class */ (function (_super) { | ||
| __extends(Array2D, _super); | ||
| function Array2D(N, M, randomizer) { | ||
| if (N === void 0) { N = 10; } | ||
| if (M === void 0) { M = 10; } | ||
| if (randomizer === void 0) { randomizer = new Integer(); } | ||
| var _this = _super.call(this) || this; | ||
| _this._N = N; | ||
| _this._M = M; | ||
| _this._randomizer = randomizer; | ||
| _this._sorted = false; | ||
| return _this; | ||
| } | ||
| Array2D.prototype.sorted = function (sorted) { | ||
| if (sorted === void 0) { sorted = true; } | ||
| this._sorted = sorted; | ||
| return this; | ||
| }; | ||
| Array2D.prototype.create = function () { | ||
| var D = []; | ||
| for (var i = 0; i < this._N; i++) { | ||
| D.push([]); | ||
| for (var j = 0; j < this._M; j++) { | ||
| D[i].push(this._randomizer.create()); | ||
| } | ||
| if (this._sorted) | ||
| D[i].sort(function (a, b) { return a - b; }); | ||
| } | ||
| return D; | ||
| }; | ||
| return Array2D; | ||
| }(Randomizer)); | ||
| var Array1D = /** @class */ (function (_super) { | ||
| __extends(Array1D, _super); | ||
| function Array1D(N, randomizer) { | ||
| return _super.call(this, 1, N, randomizer) || this; | ||
| } | ||
| Array1D.prototype.create = function () { | ||
| return _super.prototype.create.call(this)[0]; | ||
| }; | ||
| return Array1D; | ||
| }(Array2D)); | ||
| var Graph = /** @class */ (function (_super) { | ||
| __extends(Graph, _super); | ||
| function Graph(N, ratio, randomizer) { | ||
| if (N === void 0) { N = 5; } | ||
| if (ratio === void 0) { ratio = .3; } | ||
| if (randomizer === void 0) { randomizer = new Integer(); } | ||
| var _this = _super.call(this) || this; | ||
| _this._N = N; | ||
| _this._ratio = ratio; | ||
| _this._randomizer = randomizer; | ||
| _this._directed = true; | ||
| _this._weighted = false; | ||
| return _this; | ||
| } | ||
| Graph.prototype.directed = function (directed) { | ||
| if (directed === void 0) { directed = true; } | ||
| this._directed = directed; | ||
| return this; | ||
| }; | ||
| Graph.prototype.weighted = function (weighted) { | ||
| if (weighted === void 0) { weighted = true; } | ||
| this._weighted = weighted; | ||
| return this; | ||
| }; | ||
| Graph.prototype.create = function () { | ||
| var G = new Array(this._N); | ||
| for (var i = 0; i < this._N; i++) { | ||
| G[i] = new Array(this._N); | ||
| } | ||
| for (var i = 0; i < this._N; i++) { | ||
| for (var j = 0; j < this._N; j++) { | ||
| if (i === j) { | ||
| G[i][j] = 0; | ||
| } | ||
| else if (this._directed || i < j) { | ||
| G[i][j] = Math.random() < this._ratio ? this._weighted ? this._randomizer.create() : 1 : 0; | ||
| } | ||
| else { | ||
| G[i][j] = G[j][i]; | ||
| } | ||
| } | ||
| } | ||
| return G; | ||
| }; | ||
| return Graph; | ||
| }(Randomizer)); | ||
| var Randomize = { | ||
| Integer: Integer, | ||
| Double: Double, | ||
| String: String, | ||
| Array1D: Array1D, | ||
| Array2D: Array2D, | ||
| Graph: Graph, | ||
| }; | ||
| var MAX_COMMANDS = 1000000; | ||
| var MAX_OBJECTS = 100; | ||
| var Commander = /** @class */ (function () { | ||
| function Commander(iArguments) { | ||
| Commander.objectCount++; | ||
| var className = this.constructor.name; | ||
| this.key = Commander.keyRandomizer.create(); | ||
| this.command(className, iArguments); | ||
| } | ||
| Commander.command = function (key, method, iArguments) { | ||
| var args = Array.from(iArguments); | ||
| this.commands.push({ | ||
| key: key, | ||
| method: method, | ||
| args: JSON.parse(JSON.stringify(args)), | ||
| }); | ||
| if (this.commands.length > MAX_COMMANDS) | ||
| throw new Error('Too Many Commands'); | ||
| if (this.objectCount > MAX_OBJECTS) | ||
| throw new Error('Too Many Objects'); | ||
| }; | ||
| Commander.prototype.destroy = function () { | ||
| Commander.objectCount--; | ||
| this.command('destroy', arguments); | ||
| }; | ||
| Commander.prototype.command = function (method, iArguments) { | ||
| Commander.command(this.key, method, iArguments); | ||
| }; | ||
| Commander.prototype.toJSON = function () { | ||
| return this.key; | ||
| }; | ||
| Commander.keyRandomizer = new Randomize.String(8, 'abcdefghijklmnopqrstuvwxyz0123456789'); | ||
| Commander.objectCount = 0; | ||
| Commander.commands = []; | ||
| return Commander; | ||
| }()); | ||
| var ALGORITHM_VISUALIZER = process.env.ALGORITHM_VISUALIZER; | ||
| if (!ALGORITHM_VISUALIZER) { | ||
| var axios_1 = require('axios'); | ||
| var opn_1 = require('opn'); | ||
| process.on('beforeExit', function () { | ||
| axios_1.post('https://algorithm-visualizer.org/api/visualizations', { content: JSON.stringify(Commander.commands) }) | ||
| .then(function (response) { return opn_1(response.data, { wait: false }); }) | ||
| .catch(console.error) | ||
| .finally(function () { return process.exit(); }); | ||
| }); | ||
| } | ||
| var Layout = /** @class */ (function (_super) { | ||
| __extends(Layout, _super); | ||
| function Layout(children) { | ||
| return _super.call(this, arguments) || this; | ||
| } | ||
| Layout.setRoot = function (child) { | ||
| this.command(null, 'setRoot', arguments); | ||
| }; | ||
| Layout.prototype.add = function (child, index) { | ||
| this.command('add', arguments); | ||
| }; | ||
| Layout.prototype.remove = function (child) { | ||
| this.command('remove', arguments); | ||
| }; | ||
| Layout.prototype.removeAll = function () { | ||
| this.command('removeAll', arguments); | ||
| }; | ||
| return Layout; | ||
| }(Commander)); | ||
| var VerticalLayout = /** @class */ (function (_super) { | ||
| __extends(VerticalLayout, _super); | ||
| function VerticalLayout() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return VerticalLayout; | ||
| }(Layout)); | ||
| var HorizontalLayout = /** @class */ (function (_super) { | ||
| __extends(HorizontalLayout, _super); | ||
| function HorizontalLayout() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return HorizontalLayout; | ||
| }(Layout)); | ||
| var Tracer = /** @class */ (function (_super) { | ||
| __extends(Tracer, _super); | ||
| function Tracer(title) { | ||
| return _super.call(this, arguments) || this; | ||
| } | ||
| Tracer.delay = function (lineNumber) { | ||
| this.command(null, 'delay', arguments); | ||
| }; | ||
| Tracer.prototype.set = function () { | ||
| this.command('set', arguments); | ||
| }; | ||
| Tracer.prototype.reset = function () { | ||
| this.command('reset', arguments); | ||
| }; | ||
| return Tracer; | ||
| }(Commander)); | ||
| var LogTracer = /** @class */ (function (_super) { | ||
| __extends(LogTracer, _super); | ||
| function LogTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| LogTracer.prototype.set = function (log) { | ||
| this.command('set', arguments); | ||
| }; | ||
| LogTracer.prototype.print = function (message) { | ||
| this.command('print', arguments); | ||
| }; | ||
| LogTracer.prototype.println = function (message) { | ||
| this.command('println', arguments); | ||
| }; | ||
| LogTracer.prototype.printf = function (format) { | ||
| var args = []; | ||
| for (var _i = 1; _i < arguments.length; _i++) { | ||
| args[_i - 1] = arguments[_i]; | ||
| } | ||
| this.command('printf', arguments); | ||
| }; | ||
| return LogTracer; | ||
| }(Tracer)); | ||
| var Array2DTracer = /** @class */ (function (_super) { | ||
| __extends(Array2DTracer, _super); | ||
| function Array2DTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| Array2DTracer.prototype.set = function (array2d) { | ||
| this.command('set', arguments); | ||
| }; | ||
| Array2DTracer.prototype.patch = function (x, y, v) { | ||
| this.command('patch', arguments); | ||
| }; | ||
| Array2DTracer.prototype.depatch = function (x, y) { | ||
| this.command('depatch', arguments); | ||
| }; | ||
| Array2DTracer.prototype.select = function (sx, sy, ex, ey) { | ||
| this.command('select', arguments); | ||
| }; | ||
| Array2DTracer.prototype.selectRow = function (x, sy, ey) { | ||
| this.command('selectRow', arguments); | ||
| }; | ||
| Array2DTracer.prototype.selectCol = function (y, sx, ex) { | ||
| this.command('selectCol', arguments); | ||
| }; | ||
| Array2DTracer.prototype.deselect = function (sx, sy, ex, ey) { | ||
| this.command('deselect', arguments); | ||
| }; | ||
| Array2DTracer.prototype.deselectRow = function (x, sy, ey) { | ||
| this.command('deselectRow', arguments); | ||
| }; | ||
| Array2DTracer.prototype.deselectCol = function (y, sx, ex) { | ||
| this.command('deselectCol', arguments); | ||
| }; | ||
| return Array2DTracer; | ||
| }(Tracer)); | ||
| var Array1DTracer = /** @class */ (function (_super) { | ||
| __extends(Array1DTracer, _super); | ||
| function Array1DTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| Array1DTracer.prototype.set = function (array1d) { | ||
| this.command('set', arguments); | ||
| }; | ||
| Array1DTracer.prototype.patch = function (x, v) { | ||
| this.command('patch', arguments); | ||
| }; | ||
| Array1DTracer.prototype.depatch = function (x) { | ||
| this.command('depatch', arguments); | ||
| }; | ||
| Array1DTracer.prototype.select = function (sx, ex) { | ||
| this.command('select', arguments); | ||
| }; | ||
| Array1DTracer.prototype.deselect = function (sx, ex) { | ||
| this.command('deselect', arguments); | ||
| }; | ||
| Array1DTracer.prototype.chart = function (chartTracer) { | ||
| this.command('chart', arguments); | ||
| }; | ||
| return Array1DTracer; | ||
| }(Array2DTracer)); | ||
| var ChartTracer = /** @class */ (function (_super) { | ||
| __extends(ChartTracer, _super); | ||
| function ChartTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return ChartTracer; | ||
| }(Array1DTracer)); | ||
| var GraphTracer = /** @class */ (function (_super) { | ||
| __extends(GraphTracer, _super); | ||
| function GraphTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| GraphTracer.prototype.set = function (array2d) { | ||
| this.command('set', arguments); | ||
| }; | ||
| GraphTracer.prototype.directed = function (isDirected) { | ||
| this.command('directed', arguments); | ||
| return this; | ||
| }; | ||
| GraphTracer.prototype.weighted = function (isWeighted) { | ||
| this.command('weighted', arguments); | ||
| return this; | ||
| }; | ||
| GraphTracer.prototype.layoutCircle = function () { | ||
| this.command('layoutCircle', arguments); | ||
| return this; | ||
| }; | ||
| GraphTracer.prototype.layoutTree = function (root, sorted) { | ||
| this.command('layoutTree', arguments); | ||
| return this; | ||
| }; | ||
| GraphTracer.prototype.layoutRandom = function () { | ||
| this.command('layoutRandom', arguments); | ||
| return this; | ||
| }; | ||
| GraphTracer.prototype.addNode = function (id, weight, x, y, visitedCount, selectedCount) { | ||
| this.command('addNode', arguments); | ||
| }; | ||
| GraphTracer.prototype.updateNode = function (id, weight, x, y, visitedCount, selectedCount) { | ||
| this.command('updateNode', arguments); | ||
| }; | ||
| GraphTracer.prototype.removeNode = function (id) { | ||
| this.command('removeNode', arguments); | ||
| }; | ||
| GraphTracer.prototype.addEdge = function (source, target, weight, visitedCount, selectedCount) { | ||
| this.command('addEdge', arguments); | ||
| }; | ||
| GraphTracer.prototype.updateEdge = function (source, target, weight, visitedCount, selectedCount) { | ||
| this.command('updateEdge', arguments); | ||
| }; | ||
| GraphTracer.prototype.removeEdge = function (source, target) { | ||
| this.command('removeEdge', arguments); | ||
| }; | ||
| GraphTracer.prototype.visit = function (target, source, weight) { | ||
| this.command('visit', arguments); | ||
| }; | ||
| GraphTracer.prototype.leave = function (target, source, weight) { | ||
| this.command('leave', arguments); | ||
| }; | ||
| GraphTracer.prototype.select = function (target, source) { | ||
| this.command('select', arguments); | ||
| }; | ||
| GraphTracer.prototype.deselect = function (target, source) { | ||
| this.command('deselect', arguments); | ||
| }; | ||
| GraphTracer.prototype.log = function (logTracer) { | ||
| this.command('log', arguments); | ||
| }; | ||
| return GraphTracer; | ||
| }(Tracer)); | ||
| export { Array1DTracer, Array2DTracer, ChartTracer, Commander, GraphTracer, HorizontalLayout, Layout, LogTracer, Randomize, Tracer, VerticalLayout }; |
| (function (global, factory) { | ||
| typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
| typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
| (global = global || self, factory(global.AlgorithmVisualizer = {})); | ||
| }(this, function (exports) { 'use strict'; | ||
| /*! ***************************************************************************** | ||
| Copyright (c) Microsoft Corporation. All rights reserved. | ||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
| this file except in compliance with the License. You may obtain a copy of the | ||
| License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
| WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
| MERCHANTABLITY OR NON-INFRINGEMENT. | ||
| See the Apache Version 2.0 License for specific language governing permissions | ||
| and limitations under the License. | ||
| ***************************************************************************** */ | ||
| /* global Reflect, Promise */ | ||
| var extendStatics = function(d, b) { | ||
| extendStatics = Object.setPrototypeOf || | ||
| ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
| function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
| return extendStatics(d, b); | ||
| }; | ||
| function __extends(d, b) { | ||
| extendStatics(d, b); | ||
| function __() { this.constructor = d; } | ||
| d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
| } | ||
| var Randomizer = /** @class */ (function () { | ||
| function Randomizer() { | ||
| } | ||
| Randomizer.prototype.create = function () { | ||
| return null; | ||
| }; | ||
| return Randomizer; | ||
| }()); | ||
| var Integer = /** @class */ (function (_super) { | ||
| __extends(Integer, _super); | ||
| function Integer(min, max) { | ||
| if (min === void 0) { min = 1; } | ||
| if (max === void 0) { max = 9; } | ||
| var _this = _super.call(this) || this; | ||
| _this._min = min; | ||
| _this._max = max; | ||
| return _this; | ||
| } | ||
| Integer.prototype.create = function () { | ||
| return Math.random() * (this._max - this._min + 1) + this._min | 0; | ||
| }; | ||
| return Integer; | ||
| }(Randomizer)); | ||
| var Double = /** @class */ (function (_super) { | ||
| __extends(Double, _super); | ||
| function Double(min, max) { | ||
| if (min === void 0) { min = 0; } | ||
| if (max === void 0) { max = 1; } | ||
| var _this = _super.call(this) || this; | ||
| _this._min = min; | ||
| _this._max = max; | ||
| return _this; | ||
| } | ||
| Double.prototype.create = function () { | ||
| return Math.random() * (this._max - this._min) + this._min; | ||
| }; | ||
| return Double; | ||
| }(Randomizer)); | ||
| var String = /** @class */ (function (_super) { | ||
| __extends(String, _super); | ||
| function String(length, letters) { | ||
| if (length === void 0) { length = 16; } | ||
| if (letters === void 0) { letters = 'abcdefghijklmnopqrstuvwxyz'; } | ||
| var _this = _super.call(this) || this; | ||
| _this._length = length; | ||
| _this._letters = letters; | ||
| return _this; | ||
| } | ||
| String.prototype.create = function () { | ||
| var text = ''; | ||
| var randomizer = new Integer(0, this._letters.length - 1); | ||
| for (var i = 0; i < this._length; i++) { | ||
| text += this._letters[randomizer.create()]; | ||
| } | ||
| return text; | ||
| }; | ||
| return String; | ||
| }(Randomizer)); | ||
| var Array2D = /** @class */ (function (_super) { | ||
| __extends(Array2D, _super); | ||
| function Array2D(N, M, randomizer) { | ||
| if (N === void 0) { N = 10; } | ||
| if (M === void 0) { M = 10; } | ||
| if (randomizer === void 0) { randomizer = new Integer(); } | ||
| var _this = _super.call(this) || this; | ||
| _this._N = N; | ||
| _this._M = M; | ||
| _this._randomizer = randomizer; | ||
| _this._sorted = false; | ||
| return _this; | ||
| } | ||
| Array2D.prototype.sorted = function (sorted) { | ||
| if (sorted === void 0) { sorted = true; } | ||
| this._sorted = sorted; | ||
| return this; | ||
| }; | ||
| Array2D.prototype.create = function () { | ||
| var D = []; | ||
| for (var i = 0; i < this._N; i++) { | ||
| D.push([]); | ||
| for (var j = 0; j < this._M; j++) { | ||
| D[i].push(this._randomizer.create()); | ||
| } | ||
| if (this._sorted) | ||
| D[i].sort(function (a, b) { return a - b; }); | ||
| } | ||
| return D; | ||
| }; | ||
| return Array2D; | ||
| }(Randomizer)); | ||
| var Array1D = /** @class */ (function (_super) { | ||
| __extends(Array1D, _super); | ||
| function Array1D(N, randomizer) { | ||
| return _super.call(this, 1, N, randomizer) || this; | ||
| } | ||
| Array1D.prototype.create = function () { | ||
| return _super.prototype.create.call(this)[0]; | ||
| }; | ||
| return Array1D; | ||
| }(Array2D)); | ||
| var Graph = /** @class */ (function (_super) { | ||
| __extends(Graph, _super); | ||
| function Graph(N, ratio, randomizer) { | ||
| if (N === void 0) { N = 5; } | ||
| if (ratio === void 0) { ratio = .3; } | ||
| if (randomizer === void 0) { randomizer = new Integer(); } | ||
| var _this = _super.call(this) || this; | ||
| _this._N = N; | ||
| _this._ratio = ratio; | ||
| _this._randomizer = randomizer; | ||
| _this._directed = true; | ||
| _this._weighted = false; | ||
| return _this; | ||
| } | ||
| Graph.prototype.directed = function (directed) { | ||
| if (directed === void 0) { directed = true; } | ||
| this._directed = directed; | ||
| return this; | ||
| }; | ||
| Graph.prototype.weighted = function (weighted) { | ||
| if (weighted === void 0) { weighted = true; } | ||
| this._weighted = weighted; | ||
| return this; | ||
| }; | ||
| Graph.prototype.create = function () { | ||
| var G = new Array(this._N); | ||
| for (var i = 0; i < this._N; i++) { | ||
| G[i] = new Array(this._N); | ||
| } | ||
| for (var i = 0; i < this._N; i++) { | ||
| for (var j = 0; j < this._N; j++) { | ||
| if (i === j) { | ||
| G[i][j] = 0; | ||
| } | ||
| else if (this._directed || i < j) { | ||
| G[i][j] = Math.random() < this._ratio ? this._weighted ? this._randomizer.create() : 1 : 0; | ||
| } | ||
| else { | ||
| G[i][j] = G[j][i]; | ||
| } | ||
| } | ||
| } | ||
| return G; | ||
| }; | ||
| return Graph; | ||
| }(Randomizer)); | ||
| var Randomize = { | ||
| Integer: Integer, | ||
| Double: Double, | ||
| String: String, | ||
| Array1D: Array1D, | ||
| Array2D: Array2D, | ||
| Graph: Graph, | ||
| }; | ||
| var MAX_COMMANDS = 1000000; | ||
| var MAX_OBJECTS = 100; | ||
| var Commander = /** @class */ (function () { | ||
| function Commander(iArguments) { | ||
| Commander.objectCount++; | ||
| var className = this.constructor.name; | ||
| this.key = Commander.keyRandomizer.create(); | ||
| this.command(className, iArguments); | ||
| } | ||
| Commander.command = function (key, method, iArguments) { | ||
| var args = Array.from(iArguments); | ||
| this.commands.push({ | ||
| key: key, | ||
| method: method, | ||
| args: JSON.parse(JSON.stringify(args)), | ||
| }); | ||
| if (this.commands.length > MAX_COMMANDS) | ||
| throw new Error('Too Many Commands'); | ||
| if (this.objectCount > MAX_OBJECTS) | ||
| throw new Error('Too Many Objects'); | ||
| }; | ||
| Commander.prototype.destroy = function () { | ||
| Commander.objectCount--; | ||
| this.command('destroy', arguments); | ||
| }; | ||
| Commander.prototype.command = function (method, iArguments) { | ||
| Commander.command(this.key, method, iArguments); | ||
| }; | ||
| Commander.prototype.toJSON = function () { | ||
| return this.key; | ||
| }; | ||
| Commander.keyRandomizer = new Randomize.String(8, 'abcdefghijklmnopqrstuvwxyz0123456789'); | ||
| Commander.objectCount = 0; | ||
| Commander.commands = []; | ||
| return Commander; | ||
| }()); | ||
| var ALGORITHM_VISUALIZER = process.env.ALGORITHM_VISUALIZER; | ||
| if (!ALGORITHM_VISUALIZER) { | ||
| var axios_1 = require('axios'); | ||
| var opn_1 = require('opn'); | ||
| process.on('beforeExit', function () { | ||
| axios_1.post('https://algorithm-visualizer.org/api/visualizations', { content: JSON.stringify(Commander.commands) }) | ||
| .then(function (response) { return opn_1(response.data, { wait: false }); }) | ||
| .catch(console.error) | ||
| .finally(function () { return process.exit(); }); | ||
| }); | ||
| } | ||
| var Layout = /** @class */ (function (_super) { | ||
| __extends(Layout, _super); | ||
| function Layout(children) { | ||
| return _super.call(this, arguments) || this; | ||
| } | ||
| Layout.setRoot = function (child) { | ||
| this.command(null, 'setRoot', arguments); | ||
| }; | ||
| Layout.prototype.add = function (child, index) { | ||
| this.command('add', arguments); | ||
| }; | ||
| Layout.prototype.remove = function (child) { | ||
| this.command('remove', arguments); | ||
| }; | ||
| Layout.prototype.removeAll = function () { | ||
| this.command('removeAll', arguments); | ||
| }; | ||
| return Layout; | ||
| }(Commander)); | ||
| var VerticalLayout = /** @class */ (function (_super) { | ||
| __extends(VerticalLayout, _super); | ||
| function VerticalLayout() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return VerticalLayout; | ||
| }(Layout)); | ||
| var HorizontalLayout = /** @class */ (function (_super) { | ||
| __extends(HorizontalLayout, _super); | ||
| function HorizontalLayout() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return HorizontalLayout; | ||
| }(Layout)); | ||
| var Tracer = /** @class */ (function (_super) { | ||
| __extends(Tracer, _super); | ||
| function Tracer(title) { | ||
| return _super.call(this, arguments) || this; | ||
| } | ||
| Tracer.delay = function (lineNumber) { | ||
| this.command(null, 'delay', arguments); | ||
| }; | ||
| Tracer.prototype.set = function () { | ||
| this.command('set', arguments); | ||
| }; | ||
| Tracer.prototype.reset = function () { | ||
| this.command('reset', arguments); | ||
| }; | ||
| return Tracer; | ||
| }(Commander)); | ||
| var LogTracer = /** @class */ (function (_super) { | ||
| __extends(LogTracer, _super); | ||
| function LogTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| LogTracer.prototype.set = function (log) { | ||
| this.command('set', arguments); | ||
| }; | ||
| LogTracer.prototype.print = function (message) { | ||
| this.command('print', arguments); | ||
| }; | ||
| LogTracer.prototype.println = function (message) { | ||
| this.command('println', arguments); | ||
| }; | ||
| LogTracer.prototype.printf = function (format) { | ||
| var args = []; | ||
| for (var _i = 1; _i < arguments.length; _i++) { | ||
| args[_i - 1] = arguments[_i]; | ||
| } | ||
| this.command('printf', arguments); | ||
| }; | ||
| return LogTracer; | ||
| }(Tracer)); | ||
| var Array2DTracer = /** @class */ (function (_super) { | ||
| __extends(Array2DTracer, _super); | ||
| function Array2DTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| Array2DTracer.prototype.set = function (array2d) { | ||
| this.command('set', arguments); | ||
| }; | ||
| Array2DTracer.prototype.patch = function (x, y, v) { | ||
| this.command('patch', arguments); | ||
| }; | ||
| Array2DTracer.prototype.depatch = function (x, y) { | ||
| this.command('depatch', arguments); | ||
| }; | ||
| Array2DTracer.prototype.select = function (sx, sy, ex, ey) { | ||
| this.command('select', arguments); | ||
| }; | ||
| Array2DTracer.prototype.selectRow = function (x, sy, ey) { | ||
| this.command('selectRow', arguments); | ||
| }; | ||
| Array2DTracer.prototype.selectCol = function (y, sx, ex) { | ||
| this.command('selectCol', arguments); | ||
| }; | ||
| Array2DTracer.prototype.deselect = function (sx, sy, ex, ey) { | ||
| this.command('deselect', arguments); | ||
| }; | ||
| Array2DTracer.prototype.deselectRow = function (x, sy, ey) { | ||
| this.command('deselectRow', arguments); | ||
| }; | ||
| Array2DTracer.prototype.deselectCol = function (y, sx, ex) { | ||
| this.command('deselectCol', arguments); | ||
| }; | ||
| return Array2DTracer; | ||
| }(Tracer)); | ||
| var Array1DTracer = /** @class */ (function (_super) { | ||
| __extends(Array1DTracer, _super); | ||
| function Array1DTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| Array1DTracer.prototype.set = function (array1d) { | ||
| this.command('set', arguments); | ||
| }; | ||
| Array1DTracer.prototype.patch = function (x, v) { | ||
| this.command('patch', arguments); | ||
| }; | ||
| Array1DTracer.prototype.depatch = function (x) { | ||
| this.command('depatch', arguments); | ||
| }; | ||
| Array1DTracer.prototype.select = function (sx, ex) { | ||
| this.command('select', arguments); | ||
| }; | ||
| Array1DTracer.prototype.deselect = function (sx, ex) { | ||
| this.command('deselect', arguments); | ||
| }; | ||
| Array1DTracer.prototype.chart = function (chartTracer) { | ||
| this.command('chart', arguments); | ||
| }; | ||
| return Array1DTracer; | ||
| }(Array2DTracer)); | ||
| var ChartTracer = /** @class */ (function (_super) { | ||
| __extends(ChartTracer, _super); | ||
| function ChartTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| return ChartTracer; | ||
| }(Array1DTracer)); | ||
| var GraphTracer = /** @class */ (function (_super) { | ||
| __extends(GraphTracer, _super); | ||
| function GraphTracer() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| GraphTracer.prototype.set = function (array2d) { | ||
| this.command('set', arguments); | ||
| }; | ||
| GraphTracer.prototype.directed = function (isDirected) { | ||
| this.command('directed', arguments); | ||
| return this; | ||
| }; | ||
| GraphTracer.prototype.weighted = function (isWeighted) { | ||
| this.command('weighted', arguments); | ||
| return this; | ||
| }; | ||
| GraphTracer.prototype.layoutCircle = function () { | ||
| this.command('layoutCircle', arguments); | ||
| return this; | ||
| }; | ||
| GraphTracer.prototype.layoutTree = function (root, sorted) { | ||
| this.command('layoutTree', arguments); | ||
| return this; | ||
| }; | ||
| GraphTracer.prototype.layoutRandom = function () { | ||
| this.command('layoutRandom', arguments); | ||
| return this; | ||
| }; | ||
| GraphTracer.prototype.addNode = function (id, weight, x, y, visitedCount, selectedCount) { | ||
| this.command('addNode', arguments); | ||
| }; | ||
| GraphTracer.prototype.updateNode = function (id, weight, x, y, visitedCount, selectedCount) { | ||
| this.command('updateNode', arguments); | ||
| }; | ||
| GraphTracer.prototype.removeNode = function (id) { | ||
| this.command('removeNode', arguments); | ||
| }; | ||
| GraphTracer.prototype.addEdge = function (source, target, weight, visitedCount, selectedCount) { | ||
| this.command('addEdge', arguments); | ||
| }; | ||
| GraphTracer.prototype.updateEdge = function (source, target, weight, visitedCount, selectedCount) { | ||
| this.command('updateEdge', arguments); | ||
| }; | ||
| GraphTracer.prototype.removeEdge = function (source, target) { | ||
| this.command('removeEdge', arguments); | ||
| }; | ||
| GraphTracer.prototype.visit = function (target, source, weight) { | ||
| this.command('visit', arguments); | ||
| }; | ||
| GraphTracer.prototype.leave = function (target, source, weight) { | ||
| this.command('leave', arguments); | ||
| }; | ||
| GraphTracer.prototype.select = function (target, source) { | ||
| this.command('select', arguments); | ||
| }; | ||
| GraphTracer.prototype.deselect = function (target, source) { | ||
| this.command('deselect', arguments); | ||
| }; | ||
| GraphTracer.prototype.log = function (logTracer) { | ||
| this.command('log', arguments); | ||
| }; | ||
| return GraphTracer; | ||
| }(Tracer)); | ||
| exports.Array1DTracer = Array1DTracer; | ||
| exports.Array2DTracer = Array2DTracer; | ||
| exports.ChartTracer = ChartTracer; | ||
| exports.Commander = Commander; | ||
| exports.GraphTracer = GraphTracer; | ||
| exports.HorizontalLayout = HorizontalLayout; | ||
| exports.Layout = Layout; | ||
| exports.LogTracer = LogTracer; | ||
| exports.Randomize = Randomize; | ||
| exports.Tracer = Tracer; | ||
| exports.VerticalLayout = VerticalLayout; | ||
| Object.defineProperty(exports, '__esModule', { value: true }); | ||
| })); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
80789
41.02%18
5.88%2317
57.3%4
-20%7
40%