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

Feature: Expand EE flow from AdUnitBox or DateTimeBranch #903

Merged
merged 12 commits into from
Jan 1, 2025
6 changes: 6 additions & 0 deletions packages/explorable-explanations/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
Multi-Sellers
</label>
</div>
<div id="auto-expand-div">
<label for="auto-expand">
<input type="checkbox" name="auto-expand" id="auto-expand" checked>
Auto Expand
</label>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const app = {
p: null,
igp: null,
up: null,
isAutoExpand: true,
isMultiSeller: false,
cancelPromise: false,
isInteractiveMode: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import app from '../app';
import config from '../config';
import { addCanvasEventListener } from '../utils';
import { addCanvasEventListener, isInsideBox } from '../utils';

const INFO_ICON_SIZE = 16;
const INFO_ICON_SPACING = 3;
Expand Down Expand Up @@ -67,13 +67,11 @@ const Box = ({
p.image(p.infoIcon, iconX, iconY, INFO_ICON_SIZE, INFO_ICON_SIZE);

const callback = (mouseX, mouseY) => {
if (
mouseX >= iconX &&
mouseX <= iconX + INFO_ICON_SIZE &&
mouseY >= iconY &&
mouseY <= iconY + INFO_ICON_SIZE
) {
if (isInsideBox(mouseX, mouseY, iconX, iconY, INFO_ICON_SIZE)) {
app.p.cursor('pointer');
console.log(info); // eslint-disable-line no-console
} else {
app.p.cursor('default');
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import app from '../app';
import config from '../config';
import Box from './box';
import { delay, wipeAndRecreateInterestCanvas } from '../utils';
import FlowExpander from './flowExpander';

const LEFT_MARGIN = 70; // Margin from the left side of the canvas
const EXPAND_ICON_SIZE = 20;
const EXPAND_ICON_SIZE = config.timeline.expandIconSize;

let spacing, renderedBranchIds, endpoints;

Expand Down Expand Up @@ -142,7 +143,15 @@ const Branches = async ({
})
);

return endpoints;
if (app.isAutoExpand) {
return endpoints[1];
}

const nextTip = await FlowExpander({
nextTipCoordinates: endpoints,
});

return nextTip;
};

const drawDateTimeBranch = (x, y, branch) => {
Expand All @@ -155,6 +164,11 @@ const drawDateTimeBranch = (x, y, branch) => {
p.text(`${branch.date}`, x, y + 35);
p.text(`${branch.time}`, x, y + 50);

if (app.isAutoExpand) {
p.pop();
return { x: x, y: y + 30 };
}

p.image(
p.expandIcon,
x - EXPAND_ICON_SIZE / 2,
Expand All @@ -179,6 +193,10 @@ const drawBoxesBranch = (x, y, branch) => {
color: branch?.color || flow.colors.box.background,
});

if (app.isAutoExpand) {
return { x: x, y: y + 30 };
}

p.image(
p.expandIcon,
x - EXPAND_ICON_SIZE / 2,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Internal dependencies
*/
import app from '../app';
import config from '../config';
import { isInsideCircle } from '../utils';

const FlowExpander = async ({ nextTipCoordinates }) => {
const p = app.p;
const iconSize = config.timeline.expandIconSize;
const iconRadius = iconSize / 2;

p.mouseMoved = ({ offsetX, offsetY }) => {
amovar18 marked this conversation as resolved.
Show resolved Hide resolved
let hoveringOverSomething = false;
nextTipCoordinates.forEach(({ x, y }) => {
if (isInsideCircle(offsetX, offsetY, x, y + 27, iconRadius)) {
hoveringOverSomething = true;
}
});
if (hoveringOverSomething) {
p.cursor('pointer');
} else {
p.cursor('default');
}
};

const endpoint = await new Promise((resolve) => {
p.mouseClicked = ({ offsetX, offsetY }) => {
nextTipCoordinates.forEach(({ x, y }) => {
if (isInsideCircle(offsetX, offsetY, x, y + 27, iconRadius)) {
p.mouseClicked(false);
p.mouseMoved(false);
resolve({ x, y });
return;
}
});
};
});

nextTipCoordinates.forEach(({ x, y }) => {
p.push();
p.noStroke();
p.circle(x, y + 27, 25);
p.pop();

if (endpoint.x !== x) {
p.push();
p.tint(255, 90);
p.image(p.expandIcon, x - iconRadius, y + 17, iconSize, iconSize);
p.pop();
} else {
p.push();
p.rotate(p.TWO_PI / 2, [1, 1, 0]);
p.image(p.expandIcon, -x - iconRadius, -y - 35, iconSize, iconSize);
p.pop();
}
});

return endpoint;
};

export default FlowExpander;
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export { default as Box } from './box';
export { default as Branches } from './branches';
export { default as ProgressLine } from './progressLine';
export { default as RippleEffect } from './rippleEffect';
export { default as FlowExpander } from './flowExpander';
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const config = {
width: 30,
height: 30,
},
expandIconSize: 20,
circles: [
{
type: 'advertiser',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,11 @@ app.handleControls = () => {
'change',
app.toggleInteractiveMode
);
document
.getElementById('auto-expand')
.addEventListener('change', (event) => {
app.isAutoExpand = event.target.checked;
});
}

const minifiedBubbleContainerRect =
Expand Down Expand Up @@ -536,6 +541,8 @@ export const interestGroupSketch = (p) => {
app.speedMultiplier = props.speedMultiplier;
}

app.isAutoExpand = props.autoExpand;

if (
props.expandedBubbleX &&
props.expandedBubbleY &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ auction.setUpAdUnitCode = (index) => {
],
},
callBack: (returnValue) => {
app.auction.nextTipCoordinates = returnValue[1];
app.auction.nextTipCoordinates = returnValue;
},
});
};
Expand Down Expand Up @@ -174,7 +174,7 @@ auction.setupBranches = (index) => {
],
},
callBack: (returnValue) => {
app.auction.nextTipCoordinates = returnValue[1];
app.auction.nextTipCoordinates = returnValue;
},
});
};
Expand Down
Loading
Loading