UNPKG

pddl-gantt

Version:

Plan visualization for AI-Planning plans. The package includes HTML components for Gantt, swimlane and line plot visualization of plan originating from AI Planning solvers.

55 lines 2.14 kB
/* -------------------------------------------------------------------------------------------- * Copyright (c) Jan Dolejsi 2020. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. * ------------------------------------------------------------------------------------------ */ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.SwimLane = void 0; /** * Swim lane visualization for activities that may run in sequence or in parallel. * This utility helps placing activities into the lane, so they do not overlap. */ class SwimLane { /** * Constructs the swim lane * @param separation separation enforced between bars in the sane lane (default is 0) */ constructor(separation = 0) { this.separation = separation; /** Lanes and the width at which the last step in each of them ends. */ this.subLaneEnds = []; } /** * Finds the first available lane that is not already occupied at offset leftOffset * @param leftOffset offset from the left for the new step to be placed * @param width step width */ placeNext(leftOffset, width) { let availableLane = -1; for (let index = 0; index < this.subLaneEnds.length; index++) { if (this.subLaneEnds[index] + this.separation < leftOffset) { availableLane = index; break; } } if (availableLane < 0) { // no lane was available, must create a new one this.subLaneEnds.push(0); availableLane = this.subLaneEnds.length - 1; } // adjust the lane end to the end of the newly placed activity this.subLaneEnds[availableLane] = leftOffset + width; return availableLane; } laneCount() { return this.subLaneEnds.length; } laneEnd(idx) { if (idx >= this.subLaneEnds.length) { throw new Error('Lane does not exist'); } return this.subLaneEnds[idx]; } } exports.SwimLane = SwimLane; //# sourceMappingURL=SwimLane.js.map