@graspologic/layout-core
Advanced tools
Comparing version 0.7.0-5 to 0.7.0-6
@@ -49,2 +49,10 @@ "use strict"; | ||
/** | ||
* Resumes the layout process | ||
*/ | ||
resume() { | ||
this._halted = false; | ||
} | ||
/** | ||
* Returns true if the layout is halted | ||
@@ -114,7 +122,7 @@ */ | ||
this._halted = false; | ||
this.resume(); | ||
this._complete = false; | ||
this.clearTickListener(); | ||
return new Promise(resolve => { | ||
this.executeStep(); | ||
this.executeStep(true); | ||
this._tickListener = this.on('tick', () => { | ||
@@ -142,21 +150,25 @@ if (this._complete) { | ||
* Executes one step of the layout algorithm | ||
* @param loop If executeStep should loop | ||
*/ | ||
executeStep() { | ||
this.performUnitOfWork(); // Advance the annealing clock | ||
async executeStep(loop = false) { | ||
if (!this._halted) { | ||
this._complete = false; | ||
await this.performUnitOfWork(); // Advance the annealing clock | ||
const ticking = this._clock.tick(); | ||
const ticking = this._clock.tick(); | ||
if (!ticking) { | ||
this._complete = true; | ||
} // Perform the next layout step on the event queue | ||
if (!ticking) { | ||
this._complete = true; | ||
} // Perform the next layout step on the event queue | ||
if (ticking && !this._halted) { | ||
this._global.setTimeout(this.executeStep, 0); | ||
} // Emit the tick event | ||
if (ticking && !this._halted && loop) { | ||
this._global.setTimeout(this.executeStep, 0); | ||
} // Emit the tick event | ||
this.emit('tick', this.getProgress()); | ||
this.emit('tick', this.getProgress()); | ||
} | ||
} | ||
@@ -163,0 +175,0 @@ |
@@ -47,4 +47,9 @@ "use strict"; | ||
layout(graph) { | ||
this._worker = this._createWorker(); // Listen for completion | ||
this._worker = this._createWorker(); // Initialize the worker | ||
this.sendMessage(_types.WorkerMessageType.Initialize, { | ||
graph: graph.serialize(), | ||
configuration: this._configuration | ||
}); // Listen for completion | ||
const result = new Promise((resolve, reject) => { | ||
@@ -58,3 +63,9 @@ this._worker.onmessage = ev => { | ||
if (type === _types.WorkerMessageType.Progress) { | ||
const progressPayload = payload; | ||
this.emit('progress', payload); | ||
if (!progressPayload.isComplete) { | ||
// Execute the next step | ||
this.sendMessage(_types.WorkerMessageType.ExecuteStep); | ||
} | ||
} else if (type === _types.WorkerMessageType.Complete) { | ||
@@ -68,8 +79,5 @@ this.reset(); | ||
}; | ||
}); // kick off the layout | ||
}); // Execute the first step | ||
this.sendMessage(_types.WorkerMessageType.Execute, { | ||
graph: graph.serialize(), | ||
configuration: this._configuration | ||
}); | ||
this.sendMessage(_types.WorkerMessageType.ExecuteStep); | ||
return result; | ||
@@ -104,2 +112,3 @@ } | ||
this.sendMessage(_types.WorkerMessageType.Resume); | ||
this.sendMessage(_types.WorkerMessageType.ExecuteStep); | ||
} | ||
@@ -106,0 +115,0 @@ /** |
@@ -24,7 +24,17 @@ "use strict"; | ||
/** | ||
* Tells the worker to execute the layout | ||
* Tells the worker to prepare for layout | ||
*/ | ||
WorkerMessageType["Initialize"] = "INITIALIZE"; | ||
/** | ||
* Tells the worker to execute the layout in its entirety | ||
*/ | ||
WorkerMessageType["Execute"] = "EXECUTE"; | ||
/** | ||
* Tells the worker to execute a single step of the layout | ||
*/ | ||
WorkerMessageType["ExecuteStep"] = "EXECUTE_STEP"; | ||
/** | ||
* Tells the worker to halt layout | ||
@@ -31,0 +41,0 @@ */ |
@@ -42,2 +42,10 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
/** | ||
* Resumes the layout process | ||
*/ | ||
resume() { | ||
this._halted = false; | ||
} | ||
/** | ||
* Returns true if the layout is halted | ||
@@ -107,7 +115,7 @@ */ | ||
this._halted = false; | ||
this.resume(); | ||
this._complete = false; | ||
this.clearTickListener(); | ||
return new Promise(resolve => { | ||
this.executeStep(); | ||
this.executeStep(true); | ||
this._tickListener = this.on('tick', () => { | ||
@@ -135,23 +143,27 @@ if (this._complete) { | ||
* Executes one step of the layout algorithm | ||
* @param loop If executeStep should loop | ||
*/ | ||
executeStep() { | ||
this.performUnitOfWork(); // Advance the annealing clock | ||
async executeStep(loop = false) { | ||
if (!this._halted) { | ||
this._complete = false; | ||
await this.performUnitOfWork(); // Advance the annealing clock | ||
const ticking = this._clock.tick(); | ||
const ticking = this._clock.tick(); | ||
if (!ticking) { | ||
this._complete = true; | ||
} // Perform the next layout step on the event queue | ||
if (!ticking) { | ||
this._complete = true; | ||
} // Perform the next layout step on the event queue | ||
if (ticking && !this._halted) { | ||
this._global.setTimeout(this.executeStep, 0); | ||
} // Emit the tick event | ||
if (ticking && !this._halted && loop) { | ||
this._global.setTimeout(this.executeStep, 0); | ||
} // Emit the tick event | ||
this.emit('tick', this.getProgress()); | ||
this.emit('tick', this.getProgress()); | ||
} | ||
} | ||
} |
@@ -38,4 +38,9 @@ /*! | ||
layout(graph) { | ||
this._worker = this._createWorker(); // Listen for completion | ||
this._worker = this._createWorker(); // Initialize the worker | ||
this.sendMessage(WorkerMessageType.Initialize, { | ||
graph: graph.serialize(), | ||
configuration: this._configuration | ||
}); // Listen for completion | ||
const result = new Promise((resolve, reject) => { | ||
@@ -49,3 +54,9 @@ this._worker.onmessage = ev => { | ||
if (type === WorkerMessageType.Progress) { | ||
const progressPayload = payload; | ||
this.emit('progress', payload); | ||
if (!progressPayload.isComplete) { | ||
// Execute the next step | ||
this.sendMessage(WorkerMessageType.ExecuteStep); | ||
} | ||
} else if (type === WorkerMessageType.Complete) { | ||
@@ -59,8 +70,5 @@ this.reset(); | ||
}; | ||
}); // kick off the layout | ||
}); // Execute the first step | ||
this.sendMessage(WorkerMessageType.Execute, { | ||
graph: graph.serialize(), | ||
configuration: this._configuration | ||
}); | ||
this.sendMessage(WorkerMessageType.ExecuteStep); | ||
return result; | ||
@@ -95,2 +103,3 @@ } | ||
this.sendMessage(WorkerMessageType.Resume); | ||
this.sendMessage(WorkerMessageType.ExecuteStep); | ||
} | ||
@@ -97,0 +106,0 @@ /** |
@@ -16,7 +16,17 @@ /** | ||
/** | ||
* Tells the worker to execute the layout | ||
* Tells the worker to prepare for layout | ||
*/ | ||
WorkerMessageType["Initialize"] = "INITIALIZE"; | ||
/** | ||
* Tells the worker to execute the layout in its entirety | ||
*/ | ||
WorkerMessageType["Execute"] = "EXECUTE"; | ||
/** | ||
* Tells the worker to execute a single step of the layout | ||
*/ | ||
WorkerMessageType["ExecuteStep"] = "EXECUTE_STEP"; | ||
/** | ||
* Tells the worker to halt layout | ||
@@ -23,0 +33,0 @@ */ |
@@ -40,2 +40,6 @@ /*! | ||
/** | ||
* Resumes the layout process | ||
*/ | ||
resume(): void; | ||
/** | ||
* Returns true if the layout is halted | ||
@@ -83,4 +87,5 @@ */ | ||
* Executes one step of the layout algorithm | ||
* @param loop If executeStep should loop | ||
*/ | ||
private executeStep; | ||
executeStep(loop?: boolean): Promise<void>; | ||
/** | ||
@@ -99,3 +104,3 @@ * Gets the name of the layout algorithm | ||
*/ | ||
protected abstract performUnitOfWork(): void; | ||
protected abstract performUnitOfWork(): void | Promise<void>; | ||
} |
@@ -17,6 +17,14 @@ /*! | ||
/** | ||
* Tells the worker to execute the layout | ||
* Tells the worker to prepare for layout | ||
*/ | ||
Initialize = "INITIALIZE", | ||
/** | ||
* Tells the worker to execute the layout in its entirety | ||
*/ | ||
Execute = "EXECUTE", | ||
/** | ||
* Tells the worker to execute a single step of the layout | ||
*/ | ||
ExecuteStep = "EXECUTE_STEP", | ||
/** | ||
* Tells the worker to halt layout | ||
@@ -64,5 +72,5 @@ */ | ||
* | ||
* The shape of the "Execute" message type payload | ||
* The shape of the "Initialize" message type payload | ||
*/ | ||
export interface ExecuteMessagePayload<Configuration> { | ||
export interface InitializeMessagePayload<Configuration> { | ||
/** | ||
@@ -77,1 +85,7 @@ * The graph to execute layout on | ||
} | ||
/** | ||
* Represents a base progress payload object | ||
*/ | ||
export interface ProgressPayload { | ||
isComplete: boolean; | ||
} |
@@ -88,6 +88,14 @@ // Generated by dts-bundle v0.7.3 | ||
/** | ||
* Tells the worker to execute the layout | ||
* Tells the worker to prepare for layout | ||
*/ | ||
Initialize = "INITIALIZE", | ||
/** | ||
* Tells the worker to execute the layout in its entirety | ||
*/ | ||
Execute = "EXECUTE", | ||
/** | ||
* Tells the worker to execute a single step of the layout | ||
*/ | ||
ExecuteStep = "EXECUTE_STEP", | ||
/** | ||
* Tells the worker to halt layout | ||
@@ -135,5 +143,5 @@ */ | ||
* | ||
* The shape of the "Execute" message type payload | ||
* The shape of the "Initialize" message type payload | ||
*/ | ||
export interface ExecuteMessagePayload<Configuration> { | ||
export interface InitializeMessagePayload<Configuration> { | ||
/** | ||
@@ -148,2 +156,8 @@ * The graph to execute layout on | ||
} | ||
/** | ||
* Represents a base progress payload object | ||
*/ | ||
export interface ProgressPayload { | ||
isComplete: boolean; | ||
} | ||
} | ||
@@ -180,2 +194,6 @@ | ||
/** | ||
* Resumes the layout process | ||
*/ | ||
resume(): void; | ||
/** | ||
* Returns true if the layout is halted | ||
@@ -218,2 +236,7 @@ */ | ||
/** | ||
* Executes one step of the layout algorithm | ||
* @param loop If executeStep should loop | ||
*/ | ||
executeStep(loop?: boolean): Promise<void>; | ||
/** | ||
* Gets the name of the layout algorithm | ||
@@ -231,3 +254,3 @@ * @returns The name | ||
*/ | ||
protected abstract performUnitOfWork(): void; | ||
protected abstract performUnitOfWork(): void | Promise<void>; | ||
} | ||
@@ -234,0 +257,0 @@ } |
@@ -40,2 +40,6 @@ /*! | ||
/** | ||
* Resumes the layout process | ||
*/ | ||
resume(): void; | ||
/** | ||
* Returns true if the layout is halted | ||
@@ -83,4 +87,5 @@ */ | ||
* Executes one step of the layout algorithm | ||
* @param loop If executeStep should loop | ||
*/ | ||
private executeStep; | ||
executeStep(loop?: boolean): Promise<void>; | ||
/** | ||
@@ -99,3 +104,3 @@ * Gets the name of the layout algorithm | ||
*/ | ||
protected abstract performUnitOfWork(): void; | ||
protected abstract performUnitOfWork(): void | Promise<void>; | ||
} |
@@ -33,2 +33,8 @@ import { EventEmitterImpl } from '@graspologic/common'; | ||
/** | ||
* Resumes the layout process | ||
*/ | ||
resume() { | ||
this._halted = false; | ||
} | ||
/** | ||
* Returns true if the layout is halted | ||
@@ -81,7 +87,7 @@ */ | ||
this._global.console.log(`execute ${this.getName()}, %s nodes, %s edges`, this.graph.nodes.count, this.graph.edges.count); | ||
this._halted = false; | ||
this.resume(); | ||
this._complete = false; | ||
this.clearTickListener(); | ||
return new Promise(resolve => { | ||
this.executeStep(); | ||
this.executeStep(true); | ||
this._tickListener = this.on('tick', () => { | ||
@@ -106,17 +112,21 @@ if (this._complete) { | ||
* Executes one step of the layout algorithm | ||
* @param loop If executeStep should loop | ||
*/ | ||
executeStep() { | ||
this.performUnitOfWork(); | ||
// Advance the annealing clock | ||
const ticking = this._clock.tick(); | ||
if (!ticking) { | ||
this._complete = true; | ||
async executeStep(loop = false) { | ||
if (!this._halted) { | ||
this._complete = false; | ||
await this.performUnitOfWork(); | ||
// Advance the annealing clock | ||
const ticking = this._clock.tick(); | ||
if (!ticking) { | ||
this._complete = true; | ||
} | ||
// Perform the next layout step on the event queue | ||
if (ticking && !this._halted && loop) { | ||
this._global.setTimeout(this.executeStep, 0); | ||
} | ||
// Emit the tick event | ||
this.emit('tick', this.getProgress()); | ||
} | ||
// Perform the next layout step on the event queue | ||
if (ticking && !this._halted) { | ||
this._global.setTimeout(this.executeStep, 0); | ||
} | ||
// Emit the tick event | ||
this.emit('tick', this.getProgress()); | ||
} | ||
} |
@@ -34,2 +34,7 @@ /*! | ||
this._worker = this._createWorker(); | ||
// Initialize the worker | ||
this.sendMessage(WorkerMessageType.Initialize, { | ||
graph: graph.serialize(), | ||
configuration: this._configuration, | ||
}); | ||
// Listen for completion | ||
@@ -40,3 +45,8 @@ const result = new Promise((resolve, reject) => { | ||
if (type === WorkerMessageType.Progress) { | ||
const progressPayload = payload; | ||
this.emit('progress', payload); | ||
if (!progressPayload.isComplete) { | ||
// Execute the next step | ||
this.sendMessage(WorkerMessageType.ExecuteStep); | ||
} | ||
} | ||
@@ -53,7 +63,4 @@ else if (type === WorkerMessageType.Complete) { | ||
}); | ||
// kick off the layout | ||
this.sendMessage(WorkerMessageType.Execute, { | ||
graph: graph.serialize(), | ||
configuration: this._configuration, | ||
}); | ||
// Execute the first step | ||
this.sendMessage(WorkerMessageType.ExecuteStep); | ||
return result; | ||
@@ -81,2 +88,3 @@ } | ||
this.sendMessage(WorkerMessageType.Resume); | ||
this.sendMessage(WorkerMessageType.ExecuteStep); | ||
} | ||
@@ -83,0 +91,0 @@ /** |
@@ -17,6 +17,14 @@ /*! | ||
/** | ||
* Tells the worker to execute the layout | ||
* Tells the worker to prepare for layout | ||
*/ | ||
Initialize = "INITIALIZE", | ||
/** | ||
* Tells the worker to execute the layout in its entirety | ||
*/ | ||
Execute = "EXECUTE", | ||
/** | ||
* Tells the worker to execute a single step of the layout | ||
*/ | ||
ExecuteStep = "EXECUTE_STEP", | ||
/** | ||
* Tells the worker to halt layout | ||
@@ -64,5 +72,5 @@ */ | ||
* | ||
* The shape of the "Execute" message type payload | ||
* The shape of the "Initialize" message type payload | ||
*/ | ||
export interface ExecuteMessagePayload<Configuration> { | ||
export interface InitializeMessagePayload<Configuration> { | ||
/** | ||
@@ -77,1 +85,7 @@ * The graph to execute layout on | ||
} | ||
/** | ||
* Represents a base progress payload object | ||
*/ | ||
export interface ProgressPayload { | ||
isComplete: boolean; | ||
} |
@@ -14,6 +14,14 @@ /** | ||
/** | ||
* Tells the worker to execute the layout | ||
* Tells the worker to prepare for layout | ||
*/ | ||
WorkerMessageType["Initialize"] = "INITIALIZE"; | ||
/** | ||
* Tells the worker to execute the layout in its entirety | ||
*/ | ||
WorkerMessageType["Execute"] = "EXECUTE"; | ||
/** | ||
* Tells the worker to execute a single step of the layout | ||
*/ | ||
WorkerMessageType["ExecuteStep"] = "EXECUTE_STEP"; | ||
/** | ||
* Tells the worker to halt layout | ||
@@ -20,0 +28,0 @@ */ |
{ | ||
"name": "@graspologic/layout-core", | ||
"version": "0.7.0-5", | ||
"version": "0.7.0-6", | ||
"license": "MIT", | ||
@@ -23,4 +23,4 @@ "main": "dist/cjs/index.js", | ||
"dependencies": { | ||
"@graspologic/common": "0.7.0-5", | ||
"@graspologic/graph": "0.7.0-5", | ||
"@graspologic/common": "0.7.0-6", | ||
"@graspologic/graph": "0.7.0-6", | ||
"typedoc": "0.19.2" | ||
@@ -27,0 +27,0 @@ }, |
@@ -67,2 +67,9 @@ /*! | ||
/** | ||
* Resumes the layout process | ||
*/ | ||
public resume() { | ||
this._halted = false | ||
} | ||
/** | ||
* Returns true if the layout is halted | ||
@@ -131,3 +138,3 @@ */ | ||
) | ||
this._halted = false | ||
this.resume() | ||
this._complete = false | ||
@@ -137,3 +144,3 @@ this.clearTickListener() | ||
return new Promise(resolve => { | ||
this.executeStep() | ||
this.executeStep(true) | ||
this._tickListener = this.on('tick', () => { | ||
@@ -160,19 +167,24 @@ if (this._complete) { | ||
* Executes one step of the layout algorithm | ||
* @param loop If executeStep should loop | ||
*/ | ||
private executeStep() { | ||
this.performUnitOfWork() | ||
public async executeStep(loop = false) { | ||
if (!this._halted) { | ||
this._complete = false | ||
// Advance the annealing clock | ||
const ticking = this._clock.tick() | ||
if (!ticking) { | ||
this._complete = true | ||
} | ||
await this.performUnitOfWork() | ||
// Perform the next layout step on the event queue | ||
if (ticking && !this._halted) { | ||
this._global.setTimeout(this.executeStep, 0) | ||
// Advance the annealing clock | ||
const ticking = this._clock.tick() | ||
if (!ticking) { | ||
this._complete = true | ||
} | ||
// Perform the next layout step on the event queue | ||
if (ticking && !this._halted && loop) { | ||
this._global.setTimeout(this.executeStep, 0) | ||
} | ||
// Emit the tick event | ||
this.emit('tick', this.getProgress()) | ||
} | ||
// Emit the tick event | ||
this.emit('tick', this.getProgress()) | ||
} | ||
@@ -195,3 +207,3 @@ | ||
*/ | ||
protected abstract performUnitOfWork(): void | ||
protected abstract performUnitOfWork(): void | Promise<void> | ||
} |
@@ -8,3 +8,4 @@ /*! | ||
WorkerMessage, | ||
ExecuteMessagePayload, | ||
InitializeMessagePayload, | ||
ProgressPayload, | ||
} from './types' | ||
@@ -57,2 +58,8 @@ import { EventEmitterImpl } from '@graspologic/common' | ||
// Initialize the worker | ||
this.sendMessage(WorkerMessageType.Initialize, { | ||
graph: graph.serialize(), | ||
configuration: this._configuration, | ||
} as InitializeMessagePayload<Configuration>) | ||
// Listen for completion | ||
@@ -63,3 +70,9 @@ const result = new Promise<TickProgress>((resolve, reject) => { | ||
if (type === WorkerMessageType.Progress) { | ||
const progressPayload = payload as ProgressPayload | ||
this.emit('progress', payload) | ||
if (!progressPayload.isComplete) { | ||
// Execute the next step | ||
this.sendMessage(WorkerMessageType.ExecuteStep) | ||
} | ||
} else if (type === WorkerMessageType.Complete) { | ||
@@ -75,7 +88,5 @@ this.reset() | ||
// kick off the layout | ||
this.sendMessage(WorkerMessageType.Execute, { | ||
graph: graph.serialize(), | ||
configuration: this._configuration, | ||
} as ExecuteMessagePayload<Configuration>) | ||
// Execute the first step | ||
this.sendMessage(WorkerMessageType.ExecuteStep) | ||
return result | ||
@@ -106,2 +117,3 @@ } | ||
this.sendMessage(WorkerMessageType.Resume) | ||
this.sendMessage(WorkerMessageType.ExecuteStep) | ||
} | ||
@@ -108,0 +120,0 @@ |
@@ -20,7 +20,17 @@ /*! | ||
/** | ||
* Tells the worker to execute the layout | ||
* Tells the worker to prepare for layout | ||
*/ | ||
Initialize = 'INITIALIZE', | ||
/** | ||
* Tells the worker to execute the layout in its entirety | ||
*/ | ||
Execute = 'EXECUTE', | ||
/** | ||
* Tells the worker to execute a single step of the layout | ||
*/ | ||
ExecuteStep = 'EXECUTE_STEP', | ||
/** | ||
* Tells the worker to halt layout | ||
@@ -77,5 +87,5 @@ */ | ||
* | ||
* The shape of the "Execute" message type payload | ||
* The shape of the "Initialize" message type payload | ||
*/ | ||
export interface ExecuteMessagePayload<Configuration> { | ||
export interface InitializeMessagePayload<Configuration> { | ||
/** | ||
@@ -91,1 +101,8 @@ * The graph to execute layout on | ||
} | ||
/** | ||
* Represents a base progress payload object | ||
*/ | ||
export interface ProgressPayload { | ||
isComplete: boolean | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
241661
2900
+ Added@graspologic/common@0.7.0-6(transitive)
+ Added@graspologic/graph@0.7.0-6(transitive)
+ Added@graspologic/memstore@0.7.0-6(transitive)
- Removed@graspologic/common@0.7.0-5(transitive)
- Removed@graspologic/graph@0.7.0-5(transitive)
- Removed@graspologic/memstore@0.7.0-5(transitive)
Updated@graspologic/common@0.7.0-6
Updated@graspologic/graph@0.7.0-6