Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
91 changes: 2 additions & 89 deletions src/anim/AnimationMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,55 +84,6 @@ function setCookie(cookieName, value, expireDays) {

const ANIMATION_SPEED_DEFAULT = 75;

// TODO: Move these out of global space into animation manager?

function controlKey(keyASCII) {
return (
keyASCII === 8 ||
keyASCII === 9 ||
keyASCII === 37 ||
keyASCII === 38 ||
keyASCII === 39 ||
keyASCII === 40 ||
keyASCII === 46
);
}

function returnSubmit(field, func, maxSize, intOnly) {
if (maxSize !== undefined) {
field.size = maxSize;
}
return function (event) {
let keyASCII = 0;
if (window.event) {
// IE
keyASCII = event.keyCode;
} else if (event.which) {
// Netscape/Firefox/Opera
keyASCII = event.which;
}

if (keyASCII === 13) {
func();
return false;
} else if (
keyASCII === 59 ||
keyASCII === 45 ||
keyASCII === 46 ||
keyASCII === 190 ||
keyASCII === 173
) {
return false;
} else if (
(maxSize !== undefined && field.value.length >= maxSize) ||
(intOnly && (keyASCII < 48 || keyASCII > 57))
) {
if (!controlKey(keyASCII)) return false;
}
return true;
};
}

function addControlToAnimationBar(animBarRef, type, name, callback) {
const element = document.createElement('input');

Expand Down Expand Up @@ -276,7 +227,7 @@ export default class AnimationManager extends EventListener {
/>
);

let tableEntry = document.createElement('td');
const tableEntry = document.createElement('td');

const controlBar = document.getElementById('GeneralAnimationControls');

Expand All @@ -295,7 +246,7 @@ export default class AnimationManager extends EventListener {
midLevel = document.createElement('tr');
bottomLevel = document.createElement('td');
bottomLevel.align = 'center';
let txtNode = document.createTextNode('Animation Speed');
const txtNode = document.createTextNode('Animation Speed');
midLevel.appendChild(bottomLevel);
bottomLevel.classList.add('txt-node');
bottomLevel.appendChild(txtNode);
Expand All @@ -312,45 +263,10 @@ export default class AnimationManager extends EventListener {

addDivisorToAnimationBar(animBarRef);

let width = getCookie('VisualizationWidth');
width = width == null || width === '' ? 1500 : parseInt(width);

let height = getCookie('VisualizationHeight');
height = height == null || height === '' ? 555 : parseInt(height);

canvas.width = width;
canvas.height = height;

tableEntry = document.createElement('td');
txtNode = document.createTextNode('Canvas height:');
tableEntry.classList.add('txt-node');
tableEntry.appendChild(txtNode);
controlBar.appendChild(tableEntry);

this.heightEntry = addControlToAnimationBar(animBarRef, 'Text', canvas.height, () =>
returnSubmit(
this.heightEntry,
() =>
this.changeSize(
document.documentElement.clientWidth,
parseInt(this.heightEntry.value),
),
4,
true,
),
);

this.heightEntry.size = 4;
this.sizeButton = addControlToAnimationBar(animBarRef, 'Button', 'Change Canvas Size', () =>
this.changeSize(),
);

this.addListener('AnimationStarted', this, this.animStarted);
this.addListener('AnimationEnded', this, this.animEnded);
this.addListener('AnimationWaiting', this, this.animWaiting);
this.addListener('AnimationUndoUnavailable', this, this.animUndoUnavailable);
this.objectManager.width = canvas.width;
this.objectManager.height = canvas.height;
}

lerp(from, to, percent) {
Expand Down Expand Up @@ -397,14 +313,11 @@ export default class AnimationManager extends EventListener {
if (width > 100) {
canvas.width = width;
this.animatedObjects.width = width;
setCookie('VisualizationWidth', String(width), 30);
}
if (height > 100) {
canvas.height = height;
this.animatedObjects.height = height;
setCookie('VisualizationHeight', String(height), 30);
}
this.heightEntry.value = canvas.height;

this.animatedObjects.draw();
this.fireEvent('CanvasSizeChanged', { width: canvas.width, height: canvas.height });
Expand Down
27 changes: 20 additions & 7 deletions src/css/AlgoScreen.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,22 @@
}

.VisualizationMainPage #mainContent {
/* padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */
background: #ffffff;
width: 100vw;
font-family: 'Roboto', Helvetica Neue, Helvetica, Arial, sans-serif;
flex: 1;
flex-direction: column;
display: flex;
overflow: hidden;
}

.VisualizationMainPage #container {
background: #ffffff;
/* margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
text-align: left; /* this overrides the text-align: center on the body element. */
height: 100vh;
display: flex;
flex-direction: column;
}

.VisualizationMainPage #toggle {
Expand Down Expand Up @@ -83,7 +90,10 @@
}

.VisualizationMainPage .viewport {
display: flex;
position: relative;
flex: 1;
overflow: hidden;
}

.VisualizationMainPage #generalAnimationControlSection {
Expand Down Expand Up @@ -126,12 +136,6 @@
color: white;
}

.VisualizationMainPage #container {
background: #ffffff;
margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
text-align: left; /* this overrides the text-align: center on the body element. */
}

.VisualizationMainPage #footer a:visited {
text-decoration: none;
color: white;
Expand Down Expand Up @@ -623,6 +627,10 @@ input[type='checkbox'] {
flex-direction: column;
gap: 8px;
}

.VisualizationMainPage #mainContent {
overflow-x: auto;
}
}

/* Pseudocode Icon */
Expand Down Expand Up @@ -1055,3 +1063,8 @@ input[type='checkbox'] {
color: white !important;
border: none !important;
}

#canvas {
width: 100%;
height: 100%;
}
24 changes: 24 additions & 0 deletions src/css/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -676,11 +676,35 @@ input::placeholder {

.side-panel {
width: 100%;
position: static;
padding: 0;
border: none;
}

.content a {
width: 100%;
}

.outer-flex {
flex-direction: column;
width: 100%;
margin: 0;
}

.inner-flex button.button {
margin: 5% 0 0 0;
width: 100%;
border: none;
}

.dsa-filter {
border: none;
}

#blob-container {
position: static;
padding-bottom: 1rem;
}
}

@media screen and (min-width: 1000px) {
Expand Down
2 changes: 1 addition & 1 deletion src/modals/BigOModals.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const ToggleBlurCell = ({ text, width, force }) => {
<td
style={{ width: width }}
className={isBlurred ? 'blur big_o_cell' : 'big_o_cell'}
onClick={() => isBlurred ? setIsBlurred(false) : setIsBlurred(true)}
onClick={() => (isBlurred ? setIsBlurred(false) : setIsBlurred(true))}
>
{applyEquationClass(text, force)}
</td>
Expand Down
9 changes: 7 additions & 2 deletions src/screens/AlgoScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,16 @@ const AlgoScreen = ({ theme, toggleTheme }) => {
}

const updateDimensions = () => {
animManagRef.current.changeSize(document.body.clientWidth);
animManagRef.current.changeSize(
canvasRef.current.clientWidth,
canvasRef.current.clientHeight,
);
};

window.addEventListener('resize', updateDimensions);

updateDimensions();

return () => {
window.removeEventListener('resize', updateDimensions);
};
Expand Down Expand Up @@ -284,7 +289,7 @@ const AlgoScreen = ({ theme, toggleTheme }) => {
</div>

<div className="viewport">
<canvas id="canvas" width={0} height="505" ref={canvasRef}></canvas>
<canvas id="canvas" ref={canvasRef}></canvas>
{infoModalEnabled && (
<div
className={`modal info-modal ${
Expand Down
10 changes: 6 additions & 4 deletions src/screens/HomeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ const HomeScreen = ({ theme, toggleTheme }) => {
}
/>
</div>
{/* Blob Gimmick */}
<div id="blob-container">
<Blob />
</div>
<div className="mid-flex">
<div className="inner-flex">
<SearchFilter filteredAlgoList={filteredAlgoList} />
Expand All @@ -131,9 +127,15 @@ const HomeScreen = ({ theme, toggleTheme }) => {
)}
</div>
</div>

{/* Blob Gimmick */}
<div id="blob-container">
<Blob />
</div>
</>
}
/>

<Route path="/about" element={<AboutScreen />} />
</Routes>
</div>
Expand Down