🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

algorithm-visualizer

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

algorithm-visualizer - npm Package Compare versions

Comparing version
2.3.2
to
2.3.3
+457
dist/index.cjs.js
'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 });
}));
import { Array2DTracer, ChartTracer } from './';
declare class Array1DTracer extends Array2DTracer {
set(array1d?: any[]): void;
patch(x: number, v?: any): void;
depatch(x: number): void;
select(sx: number, ex?: number): void;
deselect(sx: number, ex?: number): void;
chart(chartTracer: ChartTracer): void;
}
export default Array1DTracer;
import { Tracer } from './';
declare class Array2DTracer extends Tracer {
set(array2d?: any[][]): void;
patch(x: number, y: number, v?: any): void;
depatch(x: number, y: number): void;
select(sx: number, sy: number, ex?: number, ey?: number): void;
selectRow(x: number, sy: number, ey: number): void;
selectCol(y: number, sx: number, ex: number): void;
deselect(sx: number, sy: number, ex?: number, ey?: number): void;
deselectRow(x: number, sy: number, ey: number): void;
deselectCol(y: number, sx: number, ex: number): void;
}
export default Array2DTracer;
import { Array1DTracer } from './';
declare class ChartTracer extends Array1DTracer {
}
export default ChartTracer;
interface Command {
key: string | null;
method: string;
args: Array<any>;
}
declare class Commander {
private static keyRandomizer;
private static objectCount;
static commands: Command[];
static command(key: string | null, method: string, iArguments: IArguments): void;
private readonly key;
constructor(iArguments: IArguments);
destroy(): void;
command(method: string, iArguments: IArguments): void;
toJSON(): string;
}
export default Commander;
import { LogTracer, Tracer } from './';
declare class GraphTracer extends Tracer {
set(array2d?: any[][]): void;
directed(isDirected?: boolean): this;
weighted(isWeighted?: boolean): this;
layoutCircle(): this;
layoutTree(root?: any, sorted?: boolean): this;
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;
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;
removeEdge(source: any, target: any): void;
visit(target: any, source?: any, weight?: any): void;
leave(target: any, source?: any, weight?: any): void;
select(target: any, source?: any): void;
deselect(target: any, source?: any): void;
log(logTracer: LogTracer): void;
}
export default GraphTracer;
import { Layout } from './';
declare class HorizontalLayout extends Layout {
}
export default HorizontalLayout;
export { default as Randomize } from './Randomize';
export { default as Commander } from './Commander';
export { default as Layout } from './Layout';
export { default as VerticalLayout } from './VerticalLayout';
export { default as HorizontalLayout } from './HorizontalLayout';
export { default as Tracer } from './Tracer';
export { default as LogTracer } from './LogTracer';
export { default as Array2DTracer } from './Array2DTracer';
export { default as Array1DTracer } from './Array1DTracer';
export { default as ChartTracer } from './ChartTracer';
export { default as GraphTracer } from './GraphTracer';
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;
removeAll(): void;
}
export default Layout;
import { Tracer } from './';
declare class LogTracer extends Tracer {
set(log?: string): void;
print(message: any): void;
println(message: any): void;
printf(format: string, ...args: any[]): void;
}
export default LogTracer;
declare class Randomizer {
create(): 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;
import { Commander } from './';
declare class Tracer extends Commander {
static delay(lineNumber?: Number): void;
constructor(title?: string);
set(): void;
reset(): void;
}
export default Tracer;
import { Layout } from './';
declare class VerticalLayout extends Layout {
}
export default VerticalLayout;
+22
-24
{
"name": "algorithm-visualizer",
"version": "2.3.2",
"version": "2.3.3",
"description": "Visualization Library for JavaScript",

@@ -11,28 +11,26 @@ "keywords": [

],
"main": "dist/algorithm-visualizer.js",
"types": "dist/algorithm-visualizer.d.ts",
"scripts": {
"build": "node ./node_modules/webpack/bin/webpack --bail --progress --config webpack.config.js",
"prepublish": "npm run build"
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"browser": "dist/index.umd.js",
"types": "dist/types",
"dependencies": {
"axios": "^0.18.0",
"opn": "^5.4.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/algorithm-visualizer/tracers.js.git"
},
"license": "MIT",
"devDependencies": {
"@types/node": "^10.12.18",
"clean-webpack-plugin": "^0.1.19",
"dts-bundle": "^0.7.3",
"ts-loader": "^5.3.3",
"typescript": "^3.2.4",
"uglifyjs-webpack-plugin": "^1.2.7",
"webpack": "^4.15.1",
"webpack-cli": "^3.0.8",
"webpack-node-externals": "^1.7.2"
"@types/node": "^12.0.8",
"rollup": "^1.15.1",
"rollup-plugin-typescript2": "^0.21.1",
"tslib": "^1.10.0",
"typescript": "^3.5.1"
},
"dependencies": {
"axios": "^0.18.0",
"opn": "^5.4.0"
}
"scripts": {
"dev": "rollup -c -w",
"build": "rm -rf dist && rollup -c",
"test": "node ./test",
"prepublishOnly": "npm run build"
},
"files": [
"dist"
]
}
# tracers.js
> `tracers.js` is a visualization library for JavaScript.
> This repository is part of the project [Algorithm Visualizer](https://github.com/algorithm-visualizer).
This repository is part of the project [Algorithm Visualizer](https://github.com/algorithm-visualizer).
`tracers.js` is a visualization library for JavaScript.
You can use it on [algorithm-visualizer.org](https://algorithm-visualizer.org/) or locally on your machine.

@@ -16,3 +17,3 @@ ## Installation

```js
import { LogTracer } from 'algorithm-visualizer';
const { LogTracer } = require('algorithm-visualizer');

@@ -19,0 +20,0 @@ const logTracer = new LogTracer('Scratch Paper');

!function webpackUniversalModuleDefinition(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.AlgorithmVisualizer=r():t.AlgorithmVisualizer=r()}("undefined"!=typeof self?self:this,function(){return function(t){var r={};function __webpack_require__(e){if(r[e])return r[e].exports;var o=r[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,__webpack_require__),o.l=!0,o.exports}return __webpack_require__.m=t,__webpack_require__.c=r,__webpack_require__.d=function(t,r,e){__webpack_require__.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:e})},__webpack_require__.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},__webpack_require__.t=function(t,r){if(1&r&&(t=__webpack_require__(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(__webpack_require__.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var o in t)__webpack_require__.d(e,o,function(r){return t[r]}.bind(null,o));return e},__webpack_require__.n=function(t){var r=t&&t.__esModule?function getDefault(){return t.default}:function getModuleExports(){return t};return __webpack_require__.d(r,"a",r),r},__webpack_require__.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},__webpack_require__.p="",__webpack_require__(__webpack_require__.s=0)}([function(t,r,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var o=e(1);r.Randomize=o.default;var n=e(2);r.Commander=n.default;var a=e(5);r.Layout=a.default;var i=e(6);r.VerticalLayout=i.default;var c=e(7);r.HorizontalLayout=c.default;var u=e(8);r.Tracer=u.default;var p=e(9);r.LogTracer=p.default;var s=e(10);r.Array2DTracer=s.default;var _=e(11);r.Array1DTracer=_.default;var f=e(12);r.ChartTracer=f.default;var d=e(13);r.GraphTracer=d.default},function(t,r,e){"use strict";var o=this&&this.__extends||function(){var t=function(r,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])})(r,e)};return function(r,e){function __(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)}}();Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function Randomizer(){}return Randomizer.prototype.create=function(){return null},Randomizer}(),a=function(t){function Integer(r,e){void 0===r&&(r=1),void 0===e&&(e=9);var o=t.call(this)||this;return o._min=r,o._max=e,o}return o(Integer,t),Integer.prototype.create=function(){return Math.random()*(this._max-this._min+1)+this._min|0},Integer}(n),i=(function(t){function Double(r,e){void 0===r&&(r=0),void 0===e&&(e=1);var o=t.call(this)||this;return o._min=r,o._max=e,o}o(Double,t),Double.prototype.create=function(){return Math.random()*(this._max-this._min)+this._min}}(n),function(t){function String(r,e){void 0===r&&(r=16),void 0===e&&(e="abcdefghijklmnopqrstuvwxyz");var o=t.call(this)||this;return o._length=r,o._letters=e,o}return o(String,t),String.prototype.create=function(){for(var t="",r=new a(0,this._letters.length-1),e=0;e<this._length;e++)t+=this._letters[r.create()];return t},String}(n)),c=function(t){function Array2D(r,e,o){void 0===r&&(r=10),void 0===e&&(e=10),void 0===o&&(o=new a);var n=t.call(this)||this;return n._N=r,n._M=e,n._randomizer=o,n._sorted=!1,n}return o(Array2D,t),Array2D.prototype.sorted=function(t){return void 0===t&&(t=!0),this._sorted=t,this},Array2D.prototype.create=function(){for(var t=[],r=0;r<this._N;r++){t.push([]);for(var e=0;e<this._M;e++)t[r].push(this._randomizer.create());this._sorted&&t[r].sort(function(t,r){return t-r})}return t},Array2D}(n),u=function(t){function Array1D(r,e){return t.call(this,1,r,e)||this}return o(Array1D,t),Array1D.prototype.create=function(){return t.prototype.create.call(this)[0]},Array1D}(c),p=function(t){function Graph(r,e,o){void 0===r&&(r=5),void 0===e&&(e=.3),void 0===o&&(o=new a);var n=t.call(this)||this;return n._N=r,n._ratio=e,n._randomizer=o,n._directed=!0,n._weighted=!1,n}return o(Graph,t),Graph.prototype.directed=function(t){return void 0===t&&(t=!0),this._directed=t,this},Graph.prototype.weighted=function(t){return void 0===t&&(t=!0),this._weighted=t,this},Graph.prototype.create=function(){for(var t=new Array(this._N),r=0;r<this._N;r++)t[r]=new Array(this._N);for(r=0;r<this._N;r++)for(var e=0;e<this._N;e++)r===e?t[r][e]=0:this._directed||r<e?t[r][e]=Math.random()<this._ratio?this._weighted?this._randomizer.create():1:0:t[r][e]=t[e][r];return t},Graph}(n);r.default={Integer:a,String:i,Array1D:u,Array2D:c,Graph:p}},function(t,r,e){"use strict";Object.defineProperty(r,"__esModule",{value:!0});var o=e(0),n=function(){function Commander(t){Commander.objectCount++;var r=this.constructor.name;this.key=Commander.keyRandomizer.create(),this.command(r,t)}return Commander.command=function(t,r,e){var o=Array.from(e);if(this.commands.push({key:t,method:r,args:JSON.parse(JSON.stringify(o))}),this.commands.length>1e6)throw new Error("Too Many Commands");if(this.objectCount>100)throw new Error("Too Many Objects")},Commander.prototype.destroy=function(){Commander.objectCount--,this.command("destroy",arguments)},Commander.prototype.command=function(t,r){Commander.command(this.key,t,r)},Commander.prototype.toJSON=function(){return this.key},Commander.keyRandomizer=new o.Randomize.String(8,"abcdefghijklmnopqrstuvwxyz0123456789"),Commander.objectCount=0,Commander.commands=[],Commander}();if(!process.env.ALGORITHM_VISUALIZER){var a=e(3),i=e(4);process.on("beforeExit",function(){a.post("https://algorithm-visualizer.org/api/visualizations",{content:JSON.stringify(n.commands)}).then(function(t){return i(t.data,{wait:!1})}).catch(console.error).finally(function(){return process.exit()})})}r.default=n},function(t,r){t.exports=require("axios")},function(t,r){t.exports=require("opn")},function(t,r,e){"use strict";var o=this&&this.__extends||function(){var t=function(r,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])})(r,e)};return function(r,e){function __(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)}}();Object.defineProperty(r,"__esModule",{value:!0});var n=function(t){function Layout(r){return t.call(this,arguments)||this}return o(Layout,t),Layout.setRoot=function(t){this.command(null,"setRoot",arguments)},Layout.prototype.add=function(t,r){this.command("add",arguments)},Layout.prototype.remove=function(t){this.command("remove",arguments)},Layout.prototype.removeAll=function(){this.command("removeAll",arguments)},Layout}(e(0).Commander);r.default=n},function(t,r,e){"use strict";var o=this&&this.__extends||function(){var t=function(r,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])})(r,e)};return function(r,e){function __(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)}}();Object.defineProperty(r,"__esModule",{value:!0});var n=function(t){function VerticalLayout(){return null!==t&&t.apply(this,arguments)||this}return o(VerticalLayout,t),VerticalLayout}(e(0).Layout);r.default=n},function(t,r,e){"use strict";var o=this&&this.__extends||function(){var t=function(r,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])})(r,e)};return function(r,e){function __(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)}}();Object.defineProperty(r,"__esModule",{value:!0});var n=function(t){function HorizontalLayout(){return null!==t&&t.apply(this,arguments)||this}return o(HorizontalLayout,t),HorizontalLayout}(e(0).Layout);r.default=n},function(t,r,e){"use strict";var o=this&&this.__extends||function(){var t=function(r,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])})(r,e)};return function(r,e){function __(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)}}();Object.defineProperty(r,"__esModule",{value:!0});var n=function(t){function Tracer(r){return t.call(this,arguments)||this}return o(Tracer,t),Tracer.delay=function(t){this.command(null,"delay",arguments)},Tracer.prototype.set=function(){this.command("set",arguments)},Tracer.prototype.reset=function(){this.command("reset",arguments)},Tracer}(e(0).Commander);r.default=n},function(t,r,e){"use strict";var o=this&&this.__extends||function(){var t=function(r,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])})(r,e)};return function(r,e){function __(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)}}();Object.defineProperty(r,"__esModule",{value:!0});var n=function(t){function LogTracer(){return null!==t&&t.apply(this,arguments)||this}return o(LogTracer,t),LogTracer.prototype.set=function(t){this.command("set",arguments)},LogTracer.prototype.print=function(t){this.command("print",arguments)},LogTracer.prototype.println=function(t){this.command("println",arguments)},LogTracer.prototype.printf=function(t){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];this.command("printf",arguments)},LogTracer}(e(0).Tracer);r.default=n},function(t,r,e){"use strict";var o=this&&this.__extends||function(){var t=function(r,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])})(r,e)};return function(r,e){function __(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)}}();Object.defineProperty(r,"__esModule",{value:!0});var n=function(t){function Array2DTracer(){return null!==t&&t.apply(this,arguments)||this}return o(Array2DTracer,t),Array2DTracer.prototype.set=function(t){this.command("set",arguments)},Array2DTracer.prototype.patch=function(t,r,e){this.command("patch",arguments)},Array2DTracer.prototype.depatch=function(t,r){this.command("depatch",arguments)},Array2DTracer.prototype.select=function(t,r,e,o){this.command("select",arguments)},Array2DTracer.prototype.selectRow=function(t,r,e){this.command("selectRow",arguments)},Array2DTracer.prototype.selectCol=function(t,r,e){this.command("selectCol",arguments)},Array2DTracer.prototype.deselect=function(t,r,e,o){this.command("deselect",arguments)},Array2DTracer.prototype.deselectRow=function(t,r,e){this.command("deselectRow",arguments)},Array2DTracer.prototype.deselectCol=function(t,r,e){this.command("deselectCol",arguments)},Array2DTracer}(e(0).Tracer);r.default=n},function(t,r,e){"use strict";var o=this&&this.__extends||function(){var t=function(r,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])})(r,e)};return function(r,e){function __(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)}}();Object.defineProperty(r,"__esModule",{value:!0});var n=function(t){function Array1DTracer(){return null!==t&&t.apply(this,arguments)||this}return o(Array1DTracer,t),Array1DTracer.prototype.set=function(t){this.command("set",arguments)},Array1DTracer.prototype.patch=function(t,r){this.command("patch",arguments)},Array1DTracer.prototype.depatch=function(t){this.command("depatch",arguments)},Array1DTracer.prototype.select=function(t,r){this.command("select",arguments)},Array1DTracer.prototype.deselect=function(t,r){this.command("deselect",arguments)},Array1DTracer.prototype.chart=function(t){this.command("chart",arguments)},Array1DTracer}(e(0).Array2DTracer);r.default=n},function(t,r,e){"use strict";var o=this&&this.__extends||function(){var t=function(r,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])})(r,e)};return function(r,e){function __(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)}}();Object.defineProperty(r,"__esModule",{value:!0});var n=function(t){function ChartTracer(){return null!==t&&t.apply(this,arguments)||this}return o(ChartTracer,t),ChartTracer}(e(0).Array1DTracer);r.default=n},function(t,r,e){"use strict";var o=this&&this.__extends||function(){var t=function(r,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)r.hasOwnProperty(e)&&(t[e]=r[e])})(r,e)};return function(r,e){function __(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)}}();Object.defineProperty(r,"__esModule",{value:!0});var n=function(t){function GraphTracer(){return null!==t&&t.apply(this,arguments)||this}return o(GraphTracer,t),GraphTracer.prototype.set=function(t){this.command("set",arguments)},GraphTracer.prototype.directed=function(t){return this.command("directed",arguments),this},GraphTracer.prototype.weighted=function(t){return this.command("weighted",arguments),this},GraphTracer.prototype.layoutCircle=function(){return this.command("layoutCircle",arguments),this},GraphTracer.prototype.layoutTree=function(t,r){return this.command("layoutTree",arguments),this},GraphTracer.prototype.layoutRandom=function(){return this.command("layoutRandom",arguments),this},GraphTracer.prototype.addNode=function(t,r,e,o,n,a){this.command("addNode",arguments)},GraphTracer.prototype.updateNode=function(t,r,e,o,n,a){this.command("updateNode",arguments)},GraphTracer.prototype.removeNode=function(t){this.command("removeNode",arguments)},GraphTracer.prototype.addEdge=function(t,r,e,o,n){this.command("addEdge",arguments)},GraphTracer.prototype.updateEdge=function(t,r,e,o,n){this.command("updateEdge",arguments)},GraphTracer.prototype.removeEdge=function(t,r){this.command("removeEdge",arguments)},GraphTracer.prototype.visit=function(t,r,e){this.command("visit",arguments)},GraphTracer.prototype.leave=function(t,r,e){this.command("leave",arguments)},GraphTracer.prototype.select=function(t,r){this.command("select",arguments)},GraphTracer.prototype.deselect=function(t,r){this.command("deselect",arguments)},GraphTracer.prototype.log=function(t){this.command("log",arguments)},GraphTracer}(e(0).Tracer);r.default=n}])});
import { Array2DTracer, ChartTracer } from './';
class Array1DTracer extends Array2DTracer {
set(array1d?: any[]) {
this.command('set', arguments);
}
patch(x: number, v?: any) {
this.command('patch', arguments);
}
depatch(x: number) {
this.command('depatch', arguments);
}
select(sx: number, ex?: number) {
this.command('select', arguments);
}
deselect(sx: number, ex?: number) {
this.command('deselect', arguments);
}
chart(chartTracer: ChartTracer) {
this.command('chart', arguments);
}
}
export default Array1DTracer;
import { Tracer } from './';
class Array2DTracer extends Tracer {
set(array2d?: any[][]) {
this.command('set', arguments);
}
patch(x: number, y: number, v?: any) {
this.command('patch', arguments);
}
depatch(x: number, y: number) {
this.command('depatch', arguments);
}
select(sx: number, sy: number, ex?: number, ey?: number) {
this.command('select', arguments);
}
selectRow(x: number, sy: number, ey: number) {
this.command('selectRow', arguments);
}
selectCol(y: number, sx: number, ex: number) {
this.command('selectCol', arguments);
}
deselect(sx: number, sy: number, ex?: number, ey?: number) {
this.command('deselect', arguments);
}
deselectRow(x: number, sy: number, ey: number) {
this.command('deselectRow', arguments);
}
deselectCol(y: number, sx: number, ex: number) {
this.command('deselectCol', arguments);
}
}
export default Array2DTracer;
import { Array1DTracer } from './';
class ChartTracer extends Array1DTracer {
}
export default ChartTracer;
import { Randomize } from './';
const MAX_COMMANDS = 1000000;
const MAX_OBJECTS = 100;
interface Command {
key: string | null,
method: string,
args: Array<any>,
}
class Commander {
private static keyRandomizer = new Randomize.String(8, 'abcdefghijklmnopqrstuvwxyz0123456789');
private static objectCount = 0;
public static commands: Command[] = [];
static command(key: string | null, method: string, iArguments: IArguments) {
const args = Array.from(iArguments);
this.commands.push({
key,
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');
}
private readonly key: string;
constructor(iArguments: IArguments) {
Commander.objectCount++;
const className = (<any>this).constructor.name;
this.key = Commander.keyRandomizer.create();
this.command(className, iArguments);
}
destroy() {
Commander.objectCount--;
this.command('destroy', arguments);
}
command(method: string, iArguments: IArguments) {
Commander.command(this.key, method, iArguments);
}
toJSON() {
return this.key;
}
}
const {ALGORITHM_VISUALIZER} = process.env;
if (!ALGORITHM_VISUALIZER) {
const axios = require('axios');
const opn = require('opn');
process.on('beforeExit', () => {
axios.post('https://algorithm-visualizer.org/api/visualizations', {content: JSON.stringify(Commander.commands)})
.then((response: any) => opn(response.data, {wait: false}))
.catch(console.error)
.finally(() => process.exit());
});
}
export default Commander;
import { LogTracer, Tracer } from './';
class GraphTracer extends Tracer {
set(array2d?: any[][]) {
this.command('set', arguments);
}
directed(isDirected?: boolean) {
this.command('directed', arguments);
return this;
}
weighted(isWeighted?: boolean) {
this.command('weighted', arguments);
return this;
}
layoutCircle() {
this.command('layoutCircle', arguments);
return this;
}
layoutTree(root?: any, sorted?: boolean) {
this.command('layoutTree', arguments);
return this;
}
layoutRandom() {
this.command('layoutRandom', arguments);
return this;
}
addNode(id: any, weight?: any, x?: number, y?: number, visitedCount?: number, selectedCount?: number) {
this.command('addNode', arguments);
}
updateNode(id: any, weight?: any, x?: number, y?: number, visitedCount?: number, selectedCount?: number) {
this.command('updateNode', arguments);
}
removeNode(id: any) {
this.command('removeNode', arguments);
}
addEdge(source: any, target: any, weight?: any, visitedCount?: number, selectedCount?: number) {
this.command('addEdge', arguments);
}
updateEdge(source: any, target: any, weight?: any, visitedCount?: number, selectedCount?: number) {
this.command('updateEdge', arguments);
}
removeEdge(source: any, target: any) {
this.command('removeEdge', arguments);
}
visit(target: any, source?: any, weight?: any) {
this.command('visit', arguments);
}
leave(target: any, source?: any, weight?: any) {
this.command('leave', arguments);
}
select(target: any, source?: any) {
this.command('select', arguments);
}
deselect(target: any, source?: any) {
this.command('deselect', arguments);
}
log(logTracer: LogTracer) {
this.command('log', arguments);
}
}
export default GraphTracer;
import { Layout } from './';
class HorizontalLayout extends Layout {
}
export default HorizontalLayout;
export { default as Randomize } from './Randomize';
export { default as Commander } from './Commander';
export { default as Layout } from './Layout';
export { default as VerticalLayout } from './VerticalLayout';
export { default as HorizontalLayout } from './HorizontalLayout';
export { default as Tracer } from './Tracer';
export { default as LogTracer } from './LogTracer';
export { default as Array2DTracer } from './Array2DTracer';
export { default as Array1DTracer } from './Array1DTracer';
export { default as ChartTracer } from './ChartTracer';
export { default as GraphTracer } from './GraphTracer';
import { Commander } from './';
class Layout extends Commander {
static setRoot(child: Commander) {
this.command(null, 'setRoot', arguments);
}
constructor(children: [Commander]) {
super(arguments);
}
add(child: Commander, index?: Number) {
this.command('add', arguments);
}
remove(child: Commander) {
this.command('remove', arguments);
}
removeAll() {
this.command('removeAll', arguments);
}
}
export default Layout;
import { Tracer } from './';
class LogTracer extends Tracer {
set(log?: string) {
this.command('set', arguments);
}
print(message: any) {
this.command('print', arguments);
}
println(message: any) {
this.command('println', arguments);
}
printf(format: string, ...args: any[]) {
this.command('printf', arguments);
}
}
export default LogTracer;
class Randomizer {
create(): any {
return null;
}
}
class Integer extends Randomizer {
private readonly _min: number;
private readonly _max: number;
constructor(min: number = 1, max: number = 9) {
super();
this._min = min;
this._max = max;
}
create(): number {
return Math.random() * (this._max - this._min + 1) + this._min | 0;
}
}
class Double extends Randomizer {
private readonly _min: number;
private readonly _max: number;
constructor(min: number = 0, max: number = 1) {
super();
this._min = min;
this._max = max;
}
create(): number {
return Math.random() * (this._max - this._min) + this._min;
}
}
class String extends Randomizer {
private readonly _length: number;
private readonly _letters: string;
constructor(length: number = 16, letters: string = 'abcdefghijklmnopqrstuvwxyz') {
super();
this._length = length;
this._letters = letters;
}
create(): string {
let text = '';
const randomizer = new Integer(0, this._letters.length - 1);
for (let i = 0; i < this._length; i++) {
text += this._letters[randomizer.create()];
}
return text;
}
}
class Array2D extends Randomizer {
private readonly _N: number;
private readonly _M: number;
private readonly _randomizer: Randomizer;
private _sorted: boolean;
constructor(N: number = 10, M: number = 10, randomizer: Randomizer = new Integer()) {
super();
this._N = N;
this._M = M;
this._randomizer = randomizer;
this._sorted = false;
}
sorted(sorted = true): this {
this._sorted = sorted;
return this;
}
create(): any[][] {
const D: any[][] = [];
for (let i = 0; i < this._N; i++) {
D.push([]);
for (let j = 0; j < this._M; j++) {
D[i].push(this._randomizer.create());
}
if (this._sorted) D[i].sort((a, b) => a - b);
}
return D;
}
}
class Array1D extends Array2D {
constructor(N?: number, randomizer?: Randomizer) {
super(1, N, randomizer);
}
create(): any[] {
return super.create()[0];
}
}
class Graph extends Randomizer {
private readonly _N: number;
private readonly _ratio: number;
private _randomizer: Randomizer;
private _directed: boolean;
private _weighted: boolean;
constructor(N: number = 5, ratio: number = .3, randomizer: Randomizer = new Integer()) {
super();
this._N = N;
this._ratio = ratio;
this._randomizer = randomizer;
this._directed = true;
this._weighted = false;
}
directed(directed: boolean = true): this {
this._directed = directed;
return this;
}
weighted(weighted: boolean = true): this {
this._weighted = weighted;
return this;
}
create(): any[][] {
const G: any[][] = new Array(this._N);
for (let i = 0; i < this._N; i++) {
G[i] = new Array(this._N);
}
for (let i = 0; i < this._N; i++) {
for (let 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;
}
}
export default {
Integer,
String,
Array1D,
Array2D,
Graph,
};
import { Commander } from './';
class Tracer extends Commander {
static delay(lineNumber?: Number) {
this.command(null, 'delay', arguments);
}
constructor(title?: string) {
super(arguments);
}
set() {
this.command('set', arguments);
}
reset() {
this.command('reset', arguments);
}
}
export default Tracer;
import { Layout } from './';
class VerticalLayout extends Layout {
}
export default VerticalLayout;
const { LogTracer, VerticalLayout } = require('../dist/algorithm-visualizer');
const logTracer = new LogTracer();
new VerticalLayout([logTracer]);
logTracer.set('haahahahaa: ');
for (let i = 0; i < 3; i++)
logTracer.print('tt ee ss tt').delay();
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"types": [
"node"
],
"lib": [
"es6"
],
"target": "es5",
"declaration": true
}
}
const nodeExternals = require('webpack-node-externals');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const path = require('path');
const buildPath = path.resolve(__dirname, 'dist');
const srcPath = path.resolve(__dirname, 'src');
module.exports = [{
entry: srcPath,
externals: [nodeExternals()],
output: {
path: buildPath,
filename: 'algorithm-visualizer.js',
library: 'AlgorithmVisualizer',
libraryTarget: 'umd',
globalObject: `(typeof self !== 'undefined' ? self : this)`,
},
node: {
process: false,
},
module: {
rules: [
{ test: /\.ts$/, use: 'ts-loader', include: srcPath },
],
},
resolve: {
extensions: ['.ts'],
},
plugins: [
new CleanWebpackPlugin([buildPath]),
new DtsBundlePlugin(),
],
optimization: {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
keep_classnames: true,
keep_fnames: true,
},
}),
],
},
mode: 'production',
}];
function DtsBundlePlugin() {
}
DtsBundlePlugin.prototype.apply = function (compiler) {
compiler.plugin('done', function () {
const dts = require('dts-bundle');
dts.bundle({
name: 'algorithm-visualizer',
main: path.resolve(srcPath, 'index.d.ts'),
out: path.resolve(buildPath, 'algorithm-visualizer.d.ts'),
removeSource: true,
});
});
};