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

Fix: Interactive mode switching #878

Merged
merged 64 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
5cff780
Conifgure webpack to spit dist folder.
amovar18 Nov 24, 2024
924c1f9
Add styles to extension.
amovar18 Nov 24, 2024
fe6be1e
Use App exported from index.js
amovar18 Nov 24, 2024
e009e38
Remove circular dependency.
amovar18 Nov 24, 2024
60675df
Fix calculation in bubblr click listener.
amovar18 Nov 24, 2024
c5c55ce
Fix the bubbles calculation for interactive mode.
amovar18 Nov 24, 2024
31cf480
Move explorable explaination tab next to overview
mohdsayed Nov 25, 2024
8aed13d
Reduce font size of Interactive mode and multi seller
mohdsayed Nov 25, 2024
3837c21
Calculate height and width of the expanded bubble according to the pa…
amovar18 Nov 25, 2024
12c8e28
Calculate height and width of the expanded bubble according to the pa…
amovar18 Nov 25, 2024
5dba46c
Fix returning promise.
amovar18 Nov 25, 2024
ca3894f
Silence errors and handle ending of the loop.
amovar18 Nov 26, 2024
6674623
Add reset button to EE.
amovar18 Nov 26, 2024
ee943e3
Remvove react wrapper.
amovar18 Nov 26, 2024
195ba86
Fix undefined color error.
amovar18 Nov 26, 2024
5b58af8
Disable previous and next button when timeline ends.
amovar18 Nov 26, 2024
cb19cbd
Add DSP boxes for bidding.
amovar18 Nov 26, 2024
2bf6c85
Fix bubble generation for interactive mode.
amovar18 Nov 26, 2024
925b575
Add promise queue.
amovar18 Nov 27, 2024
390c88e
Implement new promise queue and modify next and previous function.
amovar18 Nov 27, 2024
1d3d327
Using window variable.
amovar18 Nov 27, 2024
42d548f
Fix promise queue.
amovar18 Nov 27, 2024
561aa0a
Modify promise queue.
amovar18 Nov 27, 2024
c301ca8
Fix bugs.
amovar18 Nov 27, 2024
e6b0d07
Fix errors.
amovar18 Nov 27, 2024
a91015c
Fix misc conditions.
amovar18 Nov 27, 2024
9775d04
Add mechanism for development mode.
amovar18 Nov 28, 2024
7c00ba0
Fix bugs in development mode.
amovar18 Nov 28, 2024
68615b6
Fix bubble generation calls.
amovar18 Nov 28, 2024
c50f8ae
Fix timeline issue of toggling.
amovar18 Nov 28, 2024
691f0c7
Remove unused config variables.
amovar18 Nov 28, 2024
6a26326
Do not disable the previous and next button.
amovar18 Nov 28, 2024
d90d75d
Fix bug.
amovar18 Nov 28, 2024
1ac458e
Add index visited.
amovar18 Nov 28, 2024
559e7c1
Add visited index number.
amovar18 Nov 28, 2024
03cc92b
Move state controllers to app.
amovar18 Nov 29, 2024
2aee360
Fix webpack config.
amovar18 Nov 29, 2024
c59393e
Code improvements
mohdsayed Nov 29, 2024
48608fe
Improve code
mohdsayed Nov 29, 2024
699a804
Add comment for utils.disableButtons.
amovar18 Nov 29, 2024
5f142e9
Fix cursor.
amovar18 Nov 29, 2024
cdad911
Fix disableButton call.
amovar18 Nov 29, 2024
bf6e4e8
Fix bug post merge.
amovar18 Nov 29, 2024
a1c4f22
Fix reference for circleVisitedIndex.
amovar18 Nov 29, 2024
e4d5d12
Add baseline displaying visited diagram.
amovar18 Nov 29, 2024
d0247f7
Adjust the number in the visited node.
amovar18 Nov 29, 2024
86a701f
Fix auction display on revisit.
amovar18 Nov 29, 2024
cf1fad3
Fix number display in interactive mode.
amovar18 Nov 29, 2024
058e3fa
Add next and previous button for inteeractive mode.
amovar18 Dec 2, 2024
b53f660
Fix logic of displaying flow.
amovar18 Dec 2, 2024
12be2f0
Fix bug.
amovar18 Dec 2, 2024
4a0b73d
Fix icons displaying on revisiting node.
amovar18 Dec 2, 2024
129e0fb
Fix post merge conflicts bug.
amovar18 Dec 2, 2024
50d2107
Fix post rebase.
amovar18 Dec 2, 2024
340c3b5
Comment out code.
amovar18 Dec 2, 2024
457dcf8
Fix failing lint.
amovar18 Dec 2, 2024
dc8955f
Fix linter
amovar18 Dec 2, 2024
2c323cc
Change PromiseQueue to promiseQueue.
amovar18 Dec 2, 2024
1c8542f
Add code improvements.
amovar18 Dec 2, 2024
5c8c0e4
Remove artifact.
amovar18 Dec 2, 2024
9dca0dd
Fix file name.
amovar18 Dec 2, 2024
9e0dc32
Fix mode switching.
amovar18 Dec 2, 2024
2b49238
Add .js to file imports.
amovar18 Dec 2, 2024
9ca3049
Rename file.
amovar18 Dec 2, 2024
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
2 changes: 1 addition & 1 deletion packages/explorable-explanations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
"dependencies": {
"p5": "^1.11.0"
}
}
}
2 changes: 1 addition & 1 deletion packages/explorable-explanations/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
d="M220-240v-480h80v480h-80Zm520 0L380-480l360-240v480Zm-80-240Zm0 90v-180l-136 90 136 90Z" />
</svg>
</button>
<button id="next-div" class="play-pause-button">
<button id="next-div" disabled class="play-pause-button">
<svg xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 -960 960 960" width="20px"
fill="#808080">
<path
Expand Down
5 changes: 5 additions & 0 deletions packages/explorable-explanations/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const app = {
circlePositions: [],
smallCirclePositions: [],
circlePublisherIndices: [],
expandIconPositions: [],
currentIndex: 0,
},
color: null,
Expand Down Expand Up @@ -57,6 +58,10 @@ const app = {
mouseY: 0,
shouldRespondToClick: true,
startTrackingMouse: true,
visitedIndexes: 1,
visitedIndexOrder: [],
visitedIndexOrderTracker: -1,
isRevisitingNodeInInteractiveMode: false,
};

export default app;
38 changes: 38 additions & 0 deletions packages/explorable-explanations/src/components/branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const Branches = async ({ x1, y1, branches, currentIndex }) => {
progress = 0;
renderedBranchIds = [];
endpoints = [];
const p = app.p;

const y2 = y1 + 50;
spacing = 300; // Calculate spacing based on canvas width
Expand All @@ -53,6 +54,37 @@ const Branches = async ({ x1, y1, branches, currentIndex }) => {

return new Promise((resolve) => {
const animate = () => {
if (app.isRevisitingNodeInInteractiveMode) {
const branchXEndpoint =
currentIndex * LEFT_MARGIN + 15 + (branches.length - 1) * spacing;

branches.forEach(({ id, type }, index) => {
const x = currentIndex * LEFT_MARGIN + 15 + index * spacing;
const y = y2 - 9;
let endpoint;
p.push();
p.stroke(0);
p.line(x, y, branchXEndpoint, y);
p.pop();
p.push();
p.stroke(0);
p.line(x, y, x, y + 20);
p.pop();
if (type === 'datetime') {
endpoint = drawDateTimeBranch(x, y, branches[index]);
}

if (type === 'box') {
endpoint = drawBoxesBranch(x, y, branches[index]);
}

endpoints.push(endpoint);

renderedBranchIds.push(id);
});
resolve(endpoints);
return;
}
if (app.cancelPromise) {
resolve(endpoints);
return;
Expand Down Expand Up @@ -117,6 +149,11 @@ const drawAnimatedTimeline = (x, y, branches) => {
return;
}

if (app.cancelPromise) {
resolve();
return;
}

if (progress >= i * spacing && !renderedBranchIds.includes(branch.id)) {
// Draw vertical line once the horizontal line reaches its position
p.push();
Expand Down Expand Up @@ -155,6 +192,7 @@ const drawAnimatedTimeline = (x, y, branches) => {

const drawDateTimeBranch = (x, y, branch) => {
const p = app.p;

p.push();
p.noStroke();
p.fill(0);
Expand Down
40 changes: 40 additions & 0 deletions packages/explorable-explanations/src/components/progressLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const ProgressLine = ({
};

return new Promise((resolve) => {
// eslint-disable-next-line complexity
const animate = () => {
if (app.cancelPromise) {
resolve();
Expand All @@ -69,6 +70,13 @@ const ProgressLine = ({
switch (direction) {
case 'right':
currentX += incrementBy;
if (app.isRevisitingNodeInInteractiveMode) {
p.line(x1, y1, x1 + width, y2);
drawArrow(x1 + width, y1, direction);
resolve({ x: x1 + width, y: y2 });
return;
}

if (currentX - x1 > width) {
resolve({ x: currentX, y: y2 });
return;
Expand All @@ -79,6 +87,14 @@ const ProgressLine = ({

case 'left':
targetX -= incrementBy;
if (app.isRevisitingNodeInInteractiveMode) {
p.line(x2, y2 + 10, targetX - width, y1 + 10);
drawArrow(targetX - width, y1 + 4, direction);
utils.drawText(text, targetX + width / 2, y1 + height / 2);
resolve({ x: targetX - width, y: y1 + 10 });
return;
}

if (x2 - targetX > width) {
utils.drawText(text, targetX + width / 2, y1 + height / 2);
resolve({ x: targetX, y: y1 + 10 });
Expand All @@ -90,6 +106,18 @@ const ProgressLine = ({

case 'down':
currentY += incrementBy;
if (app.isRevisitingNodeInInteractiveMode) {
p.line(x1, y1, x2, y1 + height);
drawArrow(x1, y1 + height, direction);
utils.drawText(
text,
x1 - (text.startsWith('$') ? 10 : width / 2),
y1 + height / 2
);
resolve({ x: x2, y: y1 + height });
return;
}

if (currentY - y1 > height) {
utils.drawText(
text,
Expand All @@ -105,6 +133,18 @@ const ProgressLine = ({

case 'up':
currentY -= incrementBy;
if (app.isRevisitingNodeInInteractiveMode) {
p.line(x1, y1, x2, y1 - height);
drawArrow(x1, y1 - height, direction);
utils.drawText(
text,
x1 + (text.startsWith('$') ? 10 : width / 2),
y1 - height / 2
);
resolve({ x: x2, y: y1 - height });
return;
}

if (y1 - currentY > height) {
utils.drawText(
text,
Expand Down
8 changes: 8 additions & 0 deletions packages/explorable-explanations/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const config = {
igGroupsCount: 3,
interestGroups: ['shoes', 'heels', 'phones'],
visited: false,
visitedIndex: null,
},
{
type: 'advertiser',
Expand All @@ -47,12 +48,14 @@ const config = {
igGroupsCount: 2,
interestGroups: ['stilletos', 'shorts'],
visited: false,
visitedIndex: null,
},
{
type: 'publisher',
website: 'pub1.com',
datetime: '2023-10-01 12:00',
visited: false,
visitedIndex: null,
},
{
type: 'advertiser',
Expand All @@ -61,6 +64,7 @@ const config = {
igGroupsCount: 2,
interestGroups: ['bike', 'car'],
visited: false,
visitedIndex: null,
},
{
type: 'advertiser',
Expand All @@ -69,12 +73,14 @@ const config = {
igGroupsCount: 3,
interestGroups: ['football', 'basketball', 'baseball'],
visited: false,
visitedIndex: null,
},
{
type: 'publisher',
website: 'pub2.com',
datetime: '2023-10-01 14:00',
visited: false,
visitedIndex: null,
},
{
type: 'advertiser',
Expand All @@ -83,6 +89,7 @@ const config = {
igGroupsCount: 3,
interestGroups: ['movies', 'series', 'books'],
visited: false,
visitedIndex: null,
},
{
type: 'advertiser',
Expand All @@ -91,6 +98,7 @@ const config = {
igGroupsCount: 3,
interestGroups: ['IGG220', 'IGG201', 'IG225'],
visited: false,
visitedIndex: null,
},
],
colors: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class PromiseQueue {
flow.clearBelowTimelineCircles();
app.cancelPromise = false;
app.timeline.isPaused = false;
if (this.queue.length === 0) {
return;
}
}
} catch (error) {
this.currentPromiseIndex++;
Expand Down Expand Up @@ -120,6 +123,7 @@ class PromiseQueue {
this.currentPromiseIndex = 0;
this.nextNodeSkipIndex = [];
this.nextStepSkipIndex = [];
this.skipToIndex = -1;
}
}

Expand Down
11 changes: 5 additions & 6 deletions packages/explorable-explanations/src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,11 @@ utils.delay = (ms) => {
};

utils.wipeAndRecreateMainCanvas = () => {
const { height, width } = utils.calculateCanvasDimensions();
const canvas = app.p.createCanvas(width, height);
canvas.parent('ps-canvas');
canvas.style('z-index', 0);
canvas.id('p5-canvas');
app.p.clear();
app.p.background(config.canvas.background);
app.p.textSize(config.canvas.fontSize);

app.timeline.drawTimelineLine();
app.timeline.drawTimeline(config.timeline);
};

utils.wipeAndRecreateInterestCanvas = () => {
Expand Down Expand Up @@ -321,4 +319,5 @@ utils.markVisitedValue = (index, value) => {
return circle;
});
};

export default utils;
63 changes: 39 additions & 24 deletions packages/explorable-explanations/src/modules/auctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import config from '../config';
import utils from '../lib/utils';
import { Box, ProgressLine, Branches, RippleEffect } from '../components';
import bubbles from './bubbles';
import PromiseQueue from '../lib/PromiseQueue';
import promiseQueue from '../lib/promiseQueue.js';

/**
* @module Auction
Expand Down Expand Up @@ -453,42 +453,57 @@ auction.draw = (index) => {
}

for (const step of steps) {
PromiseQueue.nextStepSkipIndex.push(PromiseQueue.queue.length - 1);
PromiseQueue.add(async () => {
promiseQueue.nextStepSkipIndex.push(promiseQueue.queue.length - 1);
promiseQueue.add(async () => {
const { component, props, callBack } = step;

const returnValue = await component(props); // eslint-disable-line no-await-in-loop

const delay = component === Box ? 1000 : 0;

if (props?.showBarrageAnimation) {
await bubbles.barrageAnimation(index); // eslint-disable-line no-await-in-loop
await utils.delay(500); // eslint-disable-line no-await-in-loop

utils.wipeAndRecreateInterestCanvas(); // eslint-disable-line no-await-in-loop
}

if (props?.showRippleEffect) {
const x = props.x();
const y = props.y();

// eslint-disable-next-line no-await-in-loop
await RippleEffect({
x: x + config.flow.box.width + 2,
y: y + config.flow.box.height / 2,
});
if (!app.isRevisitingNodeInInteractiveMode) {
if (props?.showBarrageAnimation) {
await bubbles.barrageAnimation(index); // eslint-disable-line no-await-in-loop

if (app.cancelPromise) {
return;
}

await utils.delay(500); // eslint-disable-line no-await-in-loop

utils.wipeAndRecreateInterestCanvas(); // eslint-disable-line no-await-in-loop
}

if (props?.showRippleEffect) {
const x = props.x();
const y = props.y();

if (app.cancelPromise) {
return;
}
// eslint-disable-next-line no-await-in-loop
await RippleEffect({
x: x + config.flow.box.width + 2,
y: y + config.flow.box.height / 2,
});
}
}

if (callBack) {
callBack(returnValue);
}
await utils.delay(delay); // eslint-disable-line no-await-in-loop
if (!app.isRevisitingNodeInInteractiveMode) {
if (app.cancelPromise) {
return;
}
await utils.delay(delay); // eslint-disable-line no-await-in-loop
}
});
}

PromiseQueue.add(async () => {
await utils.delay(2000);
flow.clearBelowTimelineCircles();
promiseQueue.add(() => {
if (!app.isRevisitingNodeInInteractiveMode) {
flow.clearBelowTimelineCircles();
}
});
};

Expand Down
Loading
Loading