UNPKG

algomin

Version:

Algomin - Viszualizing Distributed Algorithms

72 lines (63 loc) 1.74 kB
import {Parser} from "./parser/Parser"; import {Model} from "./model/Model"; import {View} from "./view/View"; import {Controller} from "./controller/Controller"; /** * Entrypoint class for Algomin */ export class Algomin { /** * @param target_div id of root div or HTMLElement */ constructor(target_div) { this._instructions = []; this._parser = new Parser(); this._model = new Model(); this._controller = new Controller(this._model); this._view = new View(target_div, this._controller); } /** * Parses an expression and automatically creates the Model Objects from it * @param expression */ parseExpression(expression){ this._instructions = this._parser.parseExpression(expression); this._model.createObjects(this._instructions); } /** * Creates the DOM-Elements and the Slider, then starts the model * @param expression */ start(expression= null){ if(expression){ this.parseExpression(expression); } this._view.createObjects(); this._view.createSlider(); this._model.start(); } /** * Stops the animation */ stop(){ this._model.stop(); } /** * Resets Algomin by clearing the model and view objects and stopping the animation */ reset(){ this._model.clearObjects(); this._view.clearObjects(); this._model.stop(); Model.time = 0; } get model(){ return this._model; } get view(){ return this._view; } get controller(){ return this._controller; } }