Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Improve EE workflow logic and structure #907

Draft
wants to merge 45 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
df319db
First draft for ee workflow
mayan-000 Dec 20, 2024
ccf92d8
Setup vite, break code into classes, main, figure, and create basic r…
mayan-000 Dec 23, 2024
a976145
Add events and refactoring
mayan-000 Dec 23, 2024
e7e1307
Update events, update vars, callbacks logic
mayan-000 Dec 23, 2024
a92bd70
Bind this to init functions, update throw value of object once added …
mayan-000 Dec 23, 2024
4085525
Handle removal logic
mayan-000 Dec 23, 2024
6e0db10
Move some props to parent, and add text, image classes
mayan-000 Dec 23, 2024
55c14aa
Draw figures
mayan-000 Dec 23, 2024
0d115f3
Add group class and update logic
mayan-000 Dec 24, 2024
d54afc0
Remove typo
mayan-000 Dec 24, 2024
c48ba4a
Add redraw cb to components
mayan-000 Dec 24, 2024
36d6e00
Add arrow for line
mayan-000 Dec 24, 2024
3797ec5
Add Animator class to render animation, and integrate to main class
mayan-000 Dec 24, 2024
632acdb
Small refactoring
mohdsayed Dec 25, 2024
cab8c5b
Add documentation to the Main class
mohdsayed Dec 25, 2024
1d38fd4
Add dummy object as placeholder for the end of animation
mayan-000 Dec 26, 2024
956b102
Handle resetting of queues separately
mayan-000 Dec 26, 2024
921d911
Add docs
mayan-000 Dec 26, 2024
e956caa
Remove gitignore file
mayan-000 Dec 26, 2024
883e5b2
Remove line
mayan-000 Dec 26, 2024
2ad1860
Add more circles and flow, fix calculation to redraw correct elements…
mayan-000 Dec 26, 2024
6ac43a5
Call runner if animator ends
mayan-000 Dec 26, 2024
6dad0d6
Add factory class for figures, add IG bubbles and add sideEffect
mayan-000 Dec 31, 2024
9064ae1
Make var private and setup getter setter functions
mayan-000 Jan 1, 2025
f3641c1
Merge branch 'develop' into feat/ee-workflow
mayan-000 Jan 1, 2025
5905fa0
Add logic for travller class and integrate it to line's figurefactory…
mayan-000 Jan 3, 2025
8465f69
Handle traveller logic for grouped figures
mayan-000 Jan 6, 2025
f2d4de9
Use lerp for bubble travel
mayan-000 Jan 7, 2025
660d556
Fix jitter after redrawAll
mayan-000 Jan 7, 2025
8de30fa
Add comments
mayan-000 Jan 7, 2025
b2c4fa6
Change events name according to the p5
mayan-000 Jan 7, 2025
63a7b1a
Add capability to pass custom id to figure
mayan-000 Jan 7, 2025
0027917
Add optional id param to group and animator class
mayan-000 Jan 7, 2025
3c4cf2d
Update aid to animatorId, gid to GroupId and update the getter/setters
mayan-000 Jan 7, 2025
a2b189c
Add tags var, callbacks and update figure factory
mayan-000 Jan 7, 2025
6bf4d00
Update condition check for undefined case
mayan-000 Jan 7, 2025
499f196
Update callback name for resetting queue and redrawing and update calls
mayan-000 Jan 8, 2025
7d5b8cc
Add logic to handle prev button api, where figures are considered as …
mayan-000 Jan 9, 2025
bc11f28
Add next checkpoint navigation api, add complete travel travel to fas…
mayan-000 Jan 10, 2025
310fed4
If current checkpoint is last element of snapshot, skip this checkpoi…
mayan-000 Jan 10, 2025
701ce46
Handle reset function
mayan-000 Jan 10, 2025
d7cbe8f
Update logic for handling mouse move event in main class, use vars to…
mayan-000 Jan 20, 2025
c927161
Add next coordinate flag and calculation logic
mayan-000 Jan 20, 2025
2fde050
Calculate next tips for five directions and not rely on params
mayan-000 Jan 20, 2025
cea7fac
Add next tip helper to return five possible coordinates from last fig…
mayan-000 Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 89 additions & 15 deletions ee-workflow/src/components/animator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
/**
* Internal dependencies.
*/
import main from '../main';
import Figure from './figure';
import Line from './figure/line';
import FigureFactory from './figure/figureFactory';
import Group from './group';

/**
Expand All @@ -30,56 +29,131 @@ export default class Animator {
/**
* Unique id of the animator.
*/
id: string;
private id: string;

/**
* Array of objects to be animated. Can be figures or groups.
* The last object in the array is a dummy object that acts as a placeholder for the end of the animation.
*/
objects: Array<Figure | Group> = [];
private objects: Array<Figure | Group> = [];

/**
* Index of the current object being animated.
*/
index = 0;
private index = 0;

/**
* Flag to indicate if the animation should be saved in animatorSnapshot.
* If true, the animation will NOT be saved in animatorSnapshot.
*/
throw = false;
private throw = false;

/**
* Function to be executed when the animation ends.
*/
private sideEffectOnEnd: (() => void) | undefined;

/**
* Counter for the number of animations created.
*/
static animationCounter = 0;

constructor(objects: Array<Figure | Group>) {
constructor(
objects: Array<Figure | Group>,
figureFactory: FigureFactory,
id?: string
) {
Animator.animationCounter++;
this.id =
id ||
`animation-${Animator.animationCounter}` +
Math.random().toString(36).slice(2, 9);
Math.random().toString(36).slice(2, 9);
this.objects = [
...objects,
new Line(0, 0, 0, 0, main.backgroundColor.toString()), // last dummy object acts as a placeholder for the end of the animation
figureFactory.line({
x: 0,
y: 0,
endX: 0,
endY: 0,
}), // last dummy object acts as a placeholder for the end of the animation
];
this.objects.forEach((object) => object.setAid(this.id));
this.objects.forEach((object) => object.setAnimatorId(this.id));
}

/**
* Draws the current object in the animation sequence, and increments the index.
* If the index reaches the end of the sequence, it resets the index to 0.
* @param skipDraw - boolean indicating if the draw function should be skipped
* @returns boolean indicating if the animation has finished
*/
draw(): boolean {
this.objects[this.index].draw();
this.index++;

if (this.index === this.objects.length) {
draw(skipDraw = false): boolean {
if (this.index === this.objects.length - 1) {
this.index = 0;

if (!skipDraw) {
this.sideEffectOnEnd?.();
}

return true;
}

if (!skipDraw) {
this.objects[this.index].draw();
}

this.index++;

return false;
}

/**
* Resets the index of the animator to 0.
*/
resetIndex() {
this.index = 0;
}

/**
* Sets a side effect to be executed when the animation ends
* @param sideEffect - function to be executed when the animation ends
*/
setSideEffectOnEnd(sideEffect: () => void) {
this.sideEffectOnEnd = sideEffect;
}

/**
* Gets the unique id of the animator.
* @returns unique id of the animator
*/
getId(): string {
return this.id;
}

/**
* Gets the throw flag.
* @returns true if the animation will NOT be saved in animatorSnapshot.
*/
getThrow(): boolean {
return this.throw;
}

/**
* Sets the throw flag to true.
* If true, the animation will NOT be saved in animatorSnapshot.
* @param throwFlag - boolean indicating if the animation should be saved in animatorSnapshot
*/
setThrow(throwFlag: boolean) {
this.throw = throwFlag;
}

getObjects(): Array<Figure | Group> {
return this.objects;
}

removeObject(object: Figure | Group) {
const index = this.objects.indexOf(object);
if (index > -1) {
this.objects.splice(index, 1);
}
}
}
40 changes: 21 additions & 19 deletions ee-workflow/src/components/figure/box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Internal dependencies.
*/
import Figure from '.';
import main from '../../main';
import Main from '../../main';

/**
* Class for creating a box figure.
Expand All @@ -29,24 +29,34 @@ export default class Box extends Figure {
/**
* Width of the box.
*/
width: number;
private width: number;

/**
* Height of the box.
*/
height: number;
private height: number;

/**
* Callback defined by the user to be executed when the box is clicked.
*/
private customMouseClicked: (() => void) | undefined;

constructor(
canvasRuuner: Main,
x: number,
y: number,
width: number,
height: number,
id?: string,
fill?: string,
stroke?: string
stroke?: string,
tags?: string[],
mouseClicked?: () => void
) {
super(x, y, fill, stroke);
super(canvasRuuner, x, y, id, fill, stroke, tags);
this.width = width;
this.height = height;
this.customMouseClicked = mouseClicked;
}

draw() {
Expand All @@ -57,10 +67,10 @@ export default class Box extends Figure {
this.p5?.pop();
}

onHover() {
mouseMoved() {
this.savePreviousColors();
this.fill = 'red'; // TODO: Discuss the function
main.addFigure(this, true);
this.canvasRunner.addFigure(this, true);
}

onLeave() {
Expand All @@ -72,11 +82,12 @@ export default class Box extends Figure {
}

this.reApplyPreviousColors();
main.addFigure(this, true);
this.canvasRunner.addFigure(this, true);
}

onClick() {
mouseClicked() {
// TODO: Discuss the function
this.customMouseClicked?.();
}

isHovering(): boolean {
Expand All @@ -92,14 +103,6 @@ export default class Box extends Figure {
);
}

remove() {
this.p5?.push();
this.p5?.fill(main.backgroundColor);
this.p5?.stroke(main.backgroundColor);
this.p5?.rect(this.x, this.y, this.width, this.height);
this.p5?.pop();
}

reDraw(
x?: number,
y?: number,
Expand All @@ -108,13 +111,12 @@ export default class Box extends Figure {
fill?: string,
stroke?: string
) {
this.remove();
this.x = x ?? this.x;
this.y = y ?? this.y;
this.width = width ?? this.width;
this.height = height ?? this.height;
this.fill = fill || this.fill;
this.stroke = stroke || this.stroke;
main.reDrawAll();
this.canvasRunner.reDrawAll();
}
}
30 changes: 12 additions & 18 deletions ee-workflow/src/components/figure/circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Internal dependencies.
*/
import Figure from '.';
import main from '../../main';
import Main from '../../main';

/**
* Class for creating a circle figure.
Expand All @@ -29,16 +29,19 @@ export default class Circle extends Figure {
/**
* Diameter of the circle.
*/
diameter: number;
private diameter: number;

constructor(
canvasRunner: Main,
x: number,
y: number,
diameter: number,
id?: string,
fill?: string,
stroke?: string
stroke?: string,
tags?: string[]
) {
super(x, y, fill, stroke);
super(canvasRunner, x, y, id, fill, stroke, tags);
this.diameter = diameter;
}

Expand All @@ -50,10 +53,10 @@ export default class Circle extends Figure {
this.p5?.pop();
}

onHover() {
mouseMoved() {
this.savePreviousColors();
this.fill = 'red'; // TODO: Discuss the function
main.addFigure(this, true);
this.canvasRunner.addFigure(this, true);
}

onLeave() {
Expand All @@ -65,10 +68,10 @@ export default class Circle extends Figure {
}

this.reApplyPreviousColors();
main.addFigure(this, true);
this.canvasRunner.addFigure(this, true);
}

onClick() {
mouseClicked() {
// TODO: Discuss the function
}

Expand All @@ -83,27 +86,18 @@ export default class Circle extends Figure {
);
}

remove() {
this.p5?.push();
this.p5?.fill(main.backgroundColor);
this.p5?.stroke(main.backgroundColor);
this.p5?.circle(this.x, this.y, this.diameter + 1);
this.p5?.pop();
}

reDraw(
x?: number,
y?: number,
diameter?: number,
fill?: string,
stroke?: string
) {
this.remove();
this.x = x ?? this.x;
this.y = y ?? this.y;
this.diameter = diameter ?? this.diameter;
this.fill = fill || this.fill;
this.stroke = stroke || this.stroke;
main.reDrawAll();
this.canvasRunner.reDrawAll();
}
}
Loading
Loading