Skip to content

Commit

Permalink
Feature/fix deletion bug (#19)
Browse files Browse the repository at this point in the history
Fixed deletion but and update application seo

---------

Co-authored-by: Komlan Kodoh <[email protected]>
  • Loading branch information
komlanKodoh and Komlan Kodoh authored Feb 19, 2024
1 parent c382aa1 commit 7b0488c
Show file tree
Hide file tree
Showing 44 changed files with 1,504 additions and 1,099 deletions.
21 changes: 12 additions & 9 deletions website/GraphUniverse/Algorithm/AlgorithmCommands.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { AnyValue } from "@/utils/types";
import GraphUniverse from "../GraphUniverse";

export type ComandConfiguraiton = {
delay: number;
}
export type ComandConfiguraiton = {
delay: number;
isStep: boolean;
explanation: string | null;
};

export const DefaultCommandConfiguration : Readonly<ComandConfiguraiton> = {
delay: 0
export const DefaultCommandConfiguration: Readonly<ComandConfiguraiton> = {
delay: 0,
isStep: false,
explanation: null,
} as const;


export interface AlgorithmCommand<V = AnyValue, E = AnyValue> {
execute(universe: GraphUniverse) : void;
rollBack() : void;
cofiguration(): ComandConfiguraiton;
execute(universe: GraphUniverse): void;
rollBack(): void;
cofiguration(): ComandConfiguraiton;
}
111 changes: 85 additions & 26 deletions website/GraphUniverse/Algorithm/AlgorithmExecutor.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,103 @@
import { GraphAlgorithm } from './GraphAlgorithm';
import { GraphAlgorithm } from "./GraphAlgorithm";
import GraphUniverse from "../GraphUniverse";
import { sleep } from '@/utils/helpers';
import { sleep } from "@/utils/helpers";
import { AlgorithmCommand } from "./AlgorithmCommands";

export class GraphAlgorithmExecution {
private universe : GraphUniverse;
private isExecuting: boolean = false;
private graphAlgorithm: GraphAlgorithm;
private universe: GraphUniverse;
private isExecuting: boolean = false;
private executionCancelRequested: boolean = false;
private algorithmSteps: IterableIterator<AlgorithmCommand>;

constructor(graphAlgorithm: GraphAlgorithm, universe: GraphUniverse) {
this.universe = universe;
this.graphAlgorithm = graphAlgorithm;
}
private pauseRequestCallBack: (() => void) | null = null;

async StartExecution() {
let nextInstructions = this.graphAlgorithm.nexts();
constructor(graphAlgorithm: GraphAlgorithm, universe: GraphUniverse) {
this.universe = universe;
this.algorithmSteps = GraphAlgorithmExecution.getAlgorithmIterator(graphAlgorithm);
}

while (nextInstructions.length > 0) {
for (const instruction of nextInstructions) {
instruction.execute(this.universe);

if (instruction.cofiguration().delay === 0){
continue;
}
private static *getAlgorithmIterator(
graphAlgorithm: GraphAlgorithm
): IterableIterator<AlgorithmCommand> {
let nextInstructions = graphAlgorithm.nexts();

await sleep(instruction.cofiguration().delay * 100);
}
while (nextInstructions.length > 0) {
for (const instruction of nextInstructions) {
yield instruction;
}

nextInstructions = this.graphAlgorithm.nexts();
}
nextInstructions = graphAlgorithm.nexts();
}
}

async PauseExecution() {
private async ExecuteNext(applyDelay: boolean): Promise<AlgorithmCommand | null> {
const { value: instruction, done } = this.algorithmSteps.next();

if (done) {
return null;
}

async MoveForward() {
instruction.execute(this.universe);

if (instruction.cofiguration().delay !== 0 && applyDelay) {
await sleep(instruction.cofiguration().delay * 100);
}

async MoveBackward() {
return instruction;
}

async StartExecution() {
this.isExecuting = true;

while (await this.ExecuteNext(true)) {
if (this.executionCancelRequested) {
this.isExecuting = false;
this.executionCancelRequested = false;

this.pauseRequestCallBack && this.pauseRequestCallBack();
break;
}
}
}

this.isExecuting = false;
}

async PauseExecution() {
this.executionCancelRequested = true;

return new Promise<void>((resolve) => {
this.pauseRequestCallBack = resolve;
});
}

async MoveForward() {
this.isExecuting = true;

while (true) {
const instruction = await this.ExecuteNext(true);

if (instruction === null) {
this.isExecuting = false;
break;
}

if (instruction?.cofiguration().isStep) {
break;
}

if (this.executionCancelRequested) {
this.isExecuting = false;
this.executionCancelRequested = false;

this.pauseRequestCallBack && this.pauseRequestCallBack();
break;
}
}

return this.ExecuteNext(false);
}

async MoveBackward() {
throw new Error("Not implemented");
}
}
44 changes: 44 additions & 0 deletions website/GraphUniverse/Embeddings/DormantEmbedding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Vertex } from "../Graph/Graph";
import GraphUniverse from "../GraphUniverse";
import Embedding, { WellKnownGraphUniverseEmbedding } from "./Embedding";

export default class DormantEmbeding<V, E> implements Embedding<V, E> {
private readonly universe: GraphUniverse<V, E>;

constructor(graphUniverse: GraphUniverse<V, E>) {
this.universe = graphUniverse;
}

wellKnownEmbedingName(): WellKnownGraphUniverseEmbedding {
return WellKnownGraphUniverseEmbedding.DormantEmbedding;
}

name(): string {
throw new Error("Method not implemented.");
}

uninstall(): void {
// The doermand engine does not need to do anything for uninstall because it does not attach any information to the vertexes
}

update(delta: number): void {
// The dormant embedding does not need to be updated it applies no specific rendering to nodes
}

moveVertex(target: Vertex<V>, x: number, y: number): void {
console.log(x, y)
this.universe.renderingController.moveVertex(target, x, y);
}

free(target: Vertex<V>): void {
// The dormant embeding has not need to free nodes as it does ever control them in any way
}

control(target: Vertex<V>): void {
// The dormant embeding has not need to control nodes nodes as it does ever free them since it never controls them
}

initialize(): void {
// The dormant embeding does not need to initialize anything since it does not apply any rendering to nodes
}
}
98 changes: 69 additions & 29 deletions website/GraphUniverse/Embeddings/Embedding.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,77 @@
import GraphUniverseComponent from "@/GraphUniverse/GraphUniverseComponent";
import { Vertex } from "@/GraphUniverse/Graph/Graph";
import { initialize } from "next/dist/server/lib/render-server";
import GraphUniverse from "../GraphUniverse";
import { GraphUniverseState } from "../States/GraphUniverseState";
import { AnyValue } from "@/utils/types";
import PhysicsBasedEmbedding from "./PhysicsBasedEmbedding";
import DormantEmbeding from "./DormantEmbedding";

/**
* A graph embedding defines how nodes should display on a string. For example a physics based embedding would mimic
* physical forces to create a graph embedding. On the other hand a community based embedding might group nodes so
* that nodes of the same community are close to one another
*/
export default interface Embedding<T, E> extends GraphUniverseComponent<T, E> {
/**
* Update the graph embedding with consideration to the delta time that has passed.
* @param delta The time that has based since the last invocation of this method
*/
update(delta: number): void;

/**
* Request that a vertex be moved at a particular position within the graph embedding
* @param target vertex to move
* @param x The new x position of the target vertex
* @param y The new y position of the target vertex
*/
moveVertex(target: Vertex<T>, x: number, y: number): void;

/**
* Requests that the physics embedding frees the given vertex of any bound that it may apply to vertex
* in order to obtain the graph embedding
* @param target
*/
free(target: Vertex<T>): void;

/**
* Requests that the physics embedding takes back control of the given vertex and any bound that it may apply to vertex
* in order to obtain the graph embedding
* @param target
*/
control(target: Vertex<T>): void;
}
export default interface Embedding<V = AnyValue, E = AnyValue> extends GraphUniverseComponent<V, E> {
/**
* Return the name that should be attributed to this embedding
*/
wellKnownEmbedingName(): WellKnownGraphUniverseEmbedding;

/**
* Uninstall and deallocates any ressources that has been allocated during the installation phases
*/
uninstall(): void;

/**
* Update the graph embedding with consideration to the delta time that has passed.
* @param delta The time that has based since the last invocation of this method
*/
update(delta: number): void;

/**
* Request that a vertex be moved at a particular position within the graph embedding
* @param target vertex to move
* @param x The new x position of the target vertex
* @param y The new y position of the target vertex
*/
moveVertex(target: Vertex<V>, x: number, y: number): void;

/**
* Requests that the physics embedding frees the given vertex of any bound that it may apply to vertex
* in order to obtain the graph embedding
* @param target
*/
free(target: Vertex<V>): void;

/**
* Requests that the physics embedding takes back control of the given vertex and any bound that it may apply to vertex
* in order to obtain the graph embedding
* @param target
*/
control(target: Vertex<V>): void;
}

export enum WellKnownGraphUniverseEmbedding {
PhysicsBasedEmbedding,
DormantEmbedding,
}

type EmbedingMap = {
[K in WellKnownGraphUniverseEmbedding]: (universe: GraphUniverse) => Embedding;
};

export class EmbeddingFActory {
private static embeddingMap: EmbedingMap = {
[WellKnownGraphUniverseEmbedding.DormantEmbedding]: (universe) => new DormantEmbeding(universe),
[WellKnownGraphUniverseEmbedding.PhysicsBasedEmbedding]: (universe) =>
new PhysicsBasedEmbedding(universe),
} as const;

static getEmbedding(
editorState: WellKnownGraphUniverseEmbedding,
universe: GraphUniverse<any, any>
): Embedding<any, any> {
return this.embeddingMap[editorState](universe);
}
}
Loading

0 comments on commit 7b0488c

Please sign in to comment.