diff --git a/src/App.css b/src/App.css index fe77481..ad02042 100644 --- a/src/App.css +++ b/src/App.css @@ -1,38 +1,37 @@ .App { - font-family: "Nunito", sans-serif; - display: flex; - flex-direction: column; - align-items: center; text-align: center; - background-color: #f2f2f2; + color: #fafafa; + padding: 1vh; } -.container { - display: flex; - align-items: flex-end; - justify-content: center; - margin: 25px; - padding: 25px; +svg { + height: 14vmin; + pointer-events: none; } -.container-small { - display: flex; - align-items: flex-end; - justify-content: center; - margin: 5px; - padding: 15px; +@media (prefers-reduced-motion: no-preference) { + svg { + animation: App-logo-spin infinite 20s linear; + } } -.bars { - height: 100px; +.App-header { + background-color: #282c34; + min-height: 30vh; + text-align: left; + font-size: calc(10px + 2vmin); + color: white; } -.card { - background: white; - border-radius: 15px; - box-shadow: 0px 5px 15px 0px #ddd; +.App-link { + color: #61dafb; } -.controls { - display: flex; +@keyframes App-logo-spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } } diff --git a/src/App.js b/src/App.js index 0346e13..548b41b 100644 --- a/src/App.js +++ b/src/App.js @@ -1,253 +1,26 @@ -import React, { useState } from "react"; - -import { IconButton } from "@material-ui/core"; -import { - PlayArrow, - Pause, - SkipPrevious, - SkipNext, - RotateLeft, - SettingsInputAntennaTwoTone, -} from "@material-ui/icons"; -import Bar from "./components/Bar"; -import Form from "./components/Form"; - import "./App.css"; +import Playground from "./Playground.js"; +var randomColor = Math.floor(Math.random() * 16777215).toString(16); -// algorithms -import bubbleSort from "./algorithms/bubbleSort"; -import mergeSort from "./algorithms/mergeSort"; -import quickSort from "./algorithms/quickSort"; - -class App extends React.Component { - state = { - array: [], - colorKey: [], - arraySteps: [], - colorSteps: [], - currentStep: 0, - timeouts: [], - algorithm: "Bubble Sort", - barCount: 10, - delay: 200, - }; - - ALGO_SET = { - "Bubble Sort": bubbleSort, - "Merge Sort": mergeSort, - "Quick Sort": quickSort, - }; - - componentDidMount() { - this.generateBars(); - } - - generateSteps = () => { - let array = this.state.array.slice(); - let steps = this.state.arraySteps.slice(); - let colorSteps = this.state.colorSteps.slice(); - - this.ALGO_SET[this.state.algorithm](array, 0, steps, colorSteps); - - this.setState({ - arraySteps: steps, - colorSteps: colorSteps, - }); - }; - - setTimeouts() { - let steps = this.state.arraySteps; - let colorSteps = this.state.colorSteps; - - this.clearTimeouts(); - let timeouts = []; - let i = 0; - - while (i < steps.length - this.state.currentStep) { - let timeout = setTimeout(() => { - let currentStep = this.state.currentStep; - this.setState({ - array: steps[currentStep], - colorKey: colorSteps[currentStep], - currentStep: currentStep + 1, - }); - }, this.state.delay * i); - timeouts.push(timeout); - i++; - } - - this.setState({ - timeouts: timeouts, - }); - } - - stepBack = () => { - if (this.state.currentStep === 0) return; - this.clearTimeouts(); - - let currentStep = this.state.currentStep - 1; - this.setState({ - array: this.state.arraySteps[currentStep], - colorKey: this.state.colorSteps[currentStep], - currentStep: currentStep, - }); - }; - - stepForward = () => { - if (this.state.currentStep >= this.state.arraySteps.length - 1) return; - this.clearTimeouts(); - - let currentStep = this.state.currentStep + 1; - this.setState({ - array: this.state.arraySteps[currentStep], - colorKey: this.state.colorSteps[currentStep], - currentStep: currentStep, - }); - }; - - changeAlgorithm = (event) => { - this.setState( - { - algorithm: event.target.value, - currentStep: 0, - arraySteps: [ - this.state.arraySteps[ - this.state.currentStep === 0 ? 0 : this.state.currentStep - 1 - ], - ], - }, - () => this.generateSteps() - ); - this.clearTimeouts(); - this.clearColorKey(); - }; - - changeBarCount = (barCount) => { - this.setState({ barCount: barCount }, () => this.generateBars()); - // setBarCount(barCount); - //() => generateBars(); - }; - - changeDelay = (event) => { - this.clearTimeouts(); - this.setState({ - delay: parseInt(event.target.value), - }); - }; - - clearTimeouts = () => { - this.state.timeouts.forEach((timeout) => clearTimeout(timeout)); - this.setState({ - timeouts: [], - }); - }; - - clearColorKey = () => { - let blankKey = new Array(parseInt(this.state.barCount)).fill(0); - this.setState({ - colorKey: blankKey, - colorSteps: [blankKey], - }); - }; - - generateBars = () => { - this.clearTimeouts(); - this.clearColorKey(); - - let barCount = parseInt(this.state.barCount); - let barsTemp = []; - - for (let i = 0; i < barCount; i++) { - barsTemp.push(Math.floor(Math.random() * 90) + 10); - } - - this.setState( - { - array: barsTemp, - arraySteps: [barsTemp], - barCount: barCount, - currentStep: 0, - }, - () => this.generateSteps() - ); - }; - - render() { - let barsDiv = this.state.array.map((value, index) => ( - - )); - let playButton; - - // Set player controls - if ( - this.state.timeouts.length !== 0 && - this.state.currentStep !== this.state.arraySteps.length - ) { - playButton = ( - this.clearTimeouts()}> - - - ); - } else if (this.state.currentStep === this.state.arraySteps.length) { - playButton = ( - this.generateBars()}> - - - ); - } else { - playButton = ( - this.setTimeouts()}> - - - ); - } - - return ( +var current = "#" + randomColor; +function App() { + return ( + <>
-
{barsDiv}
- -
- this.generateBars()}> - - - - - - {playButton} - - - - -
- -
-
- - this.changeBarCount(e.target.value)} - /> - - -
+
+ + + + + + + +
+

Guillotine-cutter App

+
- ); - } + + ); } export default App; diff --git a/src/App.test.js b/src/App.test.js new file mode 100644 index 0000000..1f03afe --- /dev/null +++ b/src/App.test.js @@ -0,0 +1,8 @@ +import { render, screen } from '@testing-library/react'; +import App from './App'; + +test('renders learn react link', () => { + render(); + const linkElement = screen.getByText(/learn react/i); + expect(linkElement).toBeInTheDocument(); +}); diff --git a/src/Playground.js b/src/Playground.js new file mode 100644 index 0000000..494eabf --- /dev/null +++ b/src/Playground.js @@ -0,0 +1,70 @@ +class Rectangle { + constructor(height, width) { + this.height = height; + this.width = width; + } + get area() { + return this.calcArea(); + } + calcArea() { + return this.height * this.width; + } +} + +const rect1 = new Rectangle(30, 50); +const rect2 = new Rectangle(40, 50); +const rect3 = new Rectangle(10, 20); + +const tab = [rect1.area, rect2.area, rect3.area]; +const sortedtab = tab.sort(function (tab, temp) { + return tab - temp; +}); +const prettytab = sortedtab.toString(); + +let Sheet = { w: 10, h: 5 }; +const Square = { w: 4, h: 4 }; + +let activities = [ + ["Work", 9], + ["Eat", 1], + ["Commute", 2], + ["Play Game", 1], + ["Sleep", 7], +]; +console.table(activities); +// loop the outer array +for (let i = 0; i < activities.length; i++) { + // get the size of the inner array + var innerArrayLength = activities[i].length; + // loop the inner array + for (let j = 0; j < innerArrayLength; j++) { + console.log("[" + i + "," + j + "] = " + activities[i][j]); + } +} + +/* + + +There are a few ways of doing this, so I'll just give an example of a simple to understand (if somewhat inefficient) method that should still give fairly decent results. + + Start by ordering your boxes from largest to smallest. + Presume that your first box is going to be square (it won't end up that way, but it will end close). Take sqrt(area[1]) to get the length of its side. Take that width as the width you want for your first column. + Given that width, fill as many more rows as you can in that column. + Add up how much total area you have put in the column; resize its width to be match that (it will now be a little thinner). + Repeat steps 1-3 for the rest of the available boxes. When you get to the point where the target width for your first box in the column is wider than the amount of space you have left, just use that width. + The remaining boxes should cleanly fit into that remaining space in that column. + +This will give you aligned columns, with varying height divisions. As an alternative, you can flip "row" and "column" to get constant row divisions with varying column splits. + + +*/ + +export default function Playground(props) { + return ( + <> +

{props.title}

+

Here is where the magic will happen.

+

Soon enough.

+ + ); +} diff --git a/src/algorithms/bubbleSort.js b/src/algorithms/bubbleSort.js deleted file mode 100644 index fd96a6b..0000000 --- a/src/algorithms/bubbleSort.js +++ /dev/null @@ -1,27 +0,0 @@ -import { swap } from "../helpers/helpers.js"; - -const bubbleSort = (array, position, arraySteps, colorSteps) => { - let colorKey = colorSteps[colorSteps.length - 1].slice(); - - for (let i = 0; i < array.length - 1; i++) { - for (let j = 0; j < array.length - i - 1; j++) { - if (array[j] > array[j + 1]) { - array = swap(array, j, j + 1); - } - arraySteps.push(array.slice()); - colorKey[j] = 1; - colorKey[j + 1] = 1; - colorSteps.push(colorKey.slice()); - colorKey[j] = 0; - colorKey[j + 1] = 0; - } - colorKey[array.length - 1 - i] = 2; - arraySteps.push(array.slice()); - colorSteps.push(colorKey.slice()); - } - - colorSteps[colorSteps.length - 1] = new Array(array.length).fill(2); - return; -}; - -export default bubbleSort; diff --git a/src/algorithms/mergeSort.js b/src/algorithms/mergeSort.js deleted file mode 100644 index 6fa9b4f..0000000 --- a/src/algorithms/mergeSort.js +++ /dev/null @@ -1,67 +0,0 @@ -import { insertStep } from "../helpers/helpers.js"; - -function mergeSort(array, position, arraySteps, colorSteps) { - if (array.length === 1) return array; - let mid = Math.floor(array.length / 2); - - // Split and work recursively - let arrayA = mergeSort(array.slice(0, mid), position, arraySteps, colorSteps); - let arrayB = mergeSort( - array.slice(mid), - position + mid, - arraySteps, - colorSteps - ); - - let arrayNew = merge(arrayA, arrayB, position, arraySteps, colorSteps); - arraySteps.push(arraySteps[arraySteps.length - 1].slice()); - colorSteps.push( - colorSteps[colorSteps.length - 1].fill( - arrayNew.length === arraySteps[0].length ? 2 : 0 - ) - ); - return arrayNew; -} - -const merge = (arrayA, arrayB, position, arraySteps, colorSteps) => { - let arrayNew = []; - let A = 0; - let B = 0; - - while (arrayA.length > 0 && arrayB.length > 0) { - if (arrayA[A] < arrayB[B]) { - arrayNew.push(arrayA.shift()); - insertStep(arrayNew, position, arraySteps); - } else { - arrayNew.push(arrayB.shift()); - insertStep(arrayNew, position, arraySteps); - } - updateColor(position, colorSteps, arrayNew.length - 1, [], []); - } - - // concatenate remaining values - - if (arrayA.length !== 0 || arrayB.length !== 0) { - updateColor(position, colorSteps, arrayNew.length, arrayA, arrayB); - arrayNew = arrayNew.concat(arrayA); - arrayNew = arrayNew.concat(arrayB); - insertStep(arrayNew, position, arraySteps); - } - - return arrayNew; -}; - -function updateColor(position, colorSteps, start, arrayA, arrayB) { - let colorKey = colorSteps[colorSteps.length - 1].slice(); - let end = position + start + arrayA.length + arrayB.length; - start = start + position; - - if (end === start) { - colorKey.fill(1, start, end + 1); - } else { - colorKey.fill(1, start, end); - } - colorSteps.push(colorKey); -} - -export default mergeSort; diff --git a/src/algorithms/quickSort.js b/src/algorithms/quickSort.js deleted file mode 100644 index 4aa0d16..0000000 --- a/src/algorithms/quickSort.js +++ /dev/null @@ -1,80 +0,0 @@ -import { swap, insertStep } from "../helpers/helpers.js"; - -const quickSort = (array, position, arraySteps, colorSteps) => { - if (array.length < 2) { - insertStep(array, position, arraySteps); - - let colorKey = colorSteps[colorSteps.length - 1].slice(); - colorKey[position] = 2; - colorSteps.push(colorKey); - return; - } - - // pick median of three numbers as pivot and sent it to back - swap(array, pickPivot(array), array.length - 1); - insertStep(array, position, arraySteps); - colorSteps.push(colorSteps[colorSteps.length - 1].slice()); - - let pivot = array[array.length - 1]; - let A = 0; - let B = array.length - 1; - - // swap small value from right with big value from left - while (A < B) { - while (array[A] < pivot) { - insertStep(array, position, arraySteps); - let colorKey = colorSteps[colorSteps.length - 1].slice(); - colorKey = colorKey.map((key) => (key === 2 ? 2 : 0)); - colorKey[position + A] = 1; - colorKey[position + B] = 1; - colorSteps.push(colorKey); - A++; - } - while (array[B] >= pivot) { - insertStep(array, position, arraySteps); - let colorKey = colorSteps[colorSteps.length - 1].slice(); - colorKey = colorKey.map((key) => (key === 2 ? 2 : 0)); - colorKey[position + A] = 1; - colorKey[position + B] = 1; - colorSteps.push(colorKey); - B--; - } - if (A < B) { - swap(array, A, B); - insertStep(array, position, arraySteps); - let colorKey = colorSteps[colorSteps.length - 1].slice(); - colorKey = colorKey.map((key) => (key === 2 ? 2 : 0)); - colorKey[position + A] = 1; - colorKey[position + B] = 1; - colorSteps.push(colorKey); - } - } - - // swap big value with pivot - let bigIndex = Math.max(A, B); - - swap(array, bigIndex, array.length - 1); - insertStep(array, position, arraySteps); - let colorKey = colorSteps[colorSteps.length - 1].slice(); - colorKey[position + bigIndex] = 2; - colorSteps.push(colorKey); - - // recurse on two halves - quickSort(array.slice(0, A), position, arraySteps, colorSteps); - quickSort(array.slice(A + 1), position + A + 1, arraySteps, colorSteps); - - return; -}; - -function pickPivot(array) { - let A = array[0]; - let B = array[Math.floor(array.length / 2)]; - let C = array[array.length - 1]; - - let middleValue = [A, B, C].sort()[1]; - let middleIndex = array.indexOf(middleValue); - - return middleIndex; -} - -export default quickSort; diff --git a/src/components/Bar.css b/src/components/Bar.css deleted file mode 100644 index 07c5a3a..0000000 --- a/src/components/Bar.css +++ /dev/null @@ -1,5 +0,0 @@ -.bar { - background: black; - margin: 2.5px; - width: 5px; -} diff --git a/src/components/Bar.js b/src/components/Bar.js deleted file mode 100644 index d0c0b59..0000000 --- a/src/components/Bar.js +++ /dev/null @@ -1,19 +0,0 @@ -import React from "react"; -import "./Bar.css"; - -export default function Bar({ length, colorKey }) { - const COLOR_SET = ["lightgrey", "grey", "#F51057"]; - - let color = COLOR_SET[colorKey]; - - let style = { - height: length, - backgroundColor: color, - }; - - return ( - <> -
- - ); -} diff --git a/src/components/Counter.js b/src/components/Counter.js deleted file mode 100644 index e83517c..0000000 --- a/src/components/Counter.js +++ /dev/null @@ -1,27 +0,0 @@ -import React from "react"; - -export default class Counter extends React.Component { - constructor(props) { - super(props); - this.state = { - array: [], - }; - } - - resetArray() { - const array = []; - for (let i = 0; i < 100; i++) { - array.push(Math.floor(Math.random() * 100)); - } - this.setState(array); - } - - render() { - const array = this.state; - return ( -
- -
- ); - } -} diff --git a/src/components/Form.js b/src/components/Form.js deleted file mode 100644 index 94dda83..0000000 --- a/src/components/Form.js +++ /dev/null @@ -1,38 +0,0 @@ -import React from "react"; -import { - FormControl, - FormControlLabel, - FormLabel, - Radio, - RadioGroup, -} from "@material-ui/core"; - -export default function Form({ - formLabel, - values, - labels, - currentValue, - onChange, -}) { - return ( - <> -
- - {formLabel} - - {values.map((value, index) => { - return ( - } - label={labels[index]} - /> - ); - })} - - -
- - ); -} diff --git a/src/components/MainSection.css b/src/components/MainSection.css deleted file mode 100644 index f29f4a2..0000000 --- a/src/components/MainSection.css +++ /dev/null @@ -1,22 +0,0 @@ -.MainSection { - background: #363c58; - text-align: center; - flex: 1; - padding: 1vw; - /* height of the whole site (both columns) */ - min-height: 75vw; - /* === */ -} - -.MainSection > p { - padding: 5vw; -} - -.MainSection > .ProgressBar { - margin: 2vw auto; - width: 30vw; -} - -.MainSection > input { - padding: 2vw; -} diff --git a/src/components/MainSection.js b/src/components/MainSection.js deleted file mode 100644 index 65e4d23..0000000 --- a/src/components/MainSection.js +++ /dev/null @@ -1,25 +0,0 @@ -import { React, useState } from "react"; -import "./MainSection.css"; -import MainSheet from "./MainSheet.js"; -import ProgressBar from "react-bootstrap/ProgressBar"; - -export default function MainSection() { - const [rangeval, setRangeval] = useState(50); - return ( -
-

MainSection

- - - setRangeval(e.target.value)} - /> -
- ); -} diff --git a/src/components/MainSheet.css b/src/components/MainSheet.css deleted file mode 100644 index a24a121..0000000 --- a/src/components/MainSheet.css +++ /dev/null @@ -1,20 +0,0 @@ -.MainSheet { - width: 65vw; - height: 30vw; - background: #3f476c; - border: solid #9b1cfc; - margin: auto; - position: relative; -} - -.MainSheet > p { - width: 300px; - height: 100px; - padding: 20px; - - position: absolute; - top: 50%; - left: 50%; - - margin: -70px 0 0 -170px; -} diff --git a/src/components/MainSheet.js b/src/components/MainSheet.js deleted file mode 100644 index 6b94acb..0000000 --- a/src/components/MainSheet.js +++ /dev/null @@ -1,11 +0,0 @@ -import React from "react"; -import "./MainSheet.css"; - -export default function MainSheet() { - return ( -
-

Place for a sheet.

-

-
- ); -} diff --git a/src/components/Navbar.css b/src/components/Navbar.css deleted file mode 100644 index 688309e..0000000 --- a/src/components/Navbar.css +++ /dev/null @@ -1,17 +0,0 @@ -.Navbar { - background: #191e36; - text-align: center; - flex: 0 0 12vw; - padding: 1vw; -} - -.Navbar > p { - color: white; - transition: 0.3s; - -webkit-transition: 0.3s; -} - -.Navbar > p:hover { - color: #191e36; - background: #9b1cfc; -} diff --git a/src/components/Navbar.js b/src/components/Navbar.js deleted file mode 100644 index 48ac51f..0000000 --- a/src/components/Navbar.js +++ /dev/null @@ -1,15 +0,0 @@ -import React from "react"; -import "./Navbar.css"; -import styled from "styled-components"; - -export default function Navbar() { - return ( -
-

Navbar

-

Example

-

Example

-

Example

-

Example

-
- ); -} diff --git a/src/helpers/helpers.js b/src/helpers/helpers.js deleted file mode 100644 index f1f77c0..0000000 --- a/src/helpers/helpers.js +++ /dev/null @@ -1,12 +0,0 @@ -export function swap(array, indexA, indexB) { - let temp = array[indexA]; - array[indexA] = array[indexB]; - array[indexB] = temp; - return array; -} - -export function insertStep(arrayNew, position, arraySteps) { - let currentStep = arraySteps[arraySteps.length - 1].slice(); - currentStep.splice(position, arrayNew.length, ...arrayNew); - arraySteps.push(currentStep); -} diff --git a/src/index.css b/src/index.css index a5657a8..44f26d9 100644 --- a/src/index.css +++ b/src/index.css @@ -1,13 +1,14 @@ -@import url("https://fonts.googleapis.com/css2?family=Nunito:wght@200&display=swap"); -html { - scroll-behavior: smooth; -} - body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", - "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", "Nunito", + "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; + background-color: #282c34; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", + monospace; } diff --git a/src/index.js b/src/index.js index bde2a7e..ef2edf8 100644 --- a/src/index.js +++ b/src/index.js @@ -1,11 +1,17 @@ -import React from "react"; -import ReactDOM from "react-dom"; -import App from "./App.js"; -import "./index.css"; +import React from 'react'; +import ReactDOM from 'react-dom'; +import './index.css'; +import App from './App'; +import reportWebVitals from './reportWebVitals'; ReactDOM.render( , - document.getElementById("root") + document.getElementById('root') ); + +// If you want to start measuring performance in your app, pass a function +// to log results (for example: reportWebVitals(console.log)) +// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals +reportWebVitals(); diff --git a/src/logo.svg b/src/logo.svg new file mode 100644 index 0000000..9dfc1c0 --- /dev/null +++ b/src/logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/reportWebVitals.js b/src/reportWebVitals.js new file mode 100644 index 0000000..5253d3a --- /dev/null +++ b/src/reportWebVitals.js @@ -0,0 +1,13 @@ +const reportWebVitals = onPerfEntry => { + if (onPerfEntry && onPerfEntry instanceof Function) { + import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { + getCLS(onPerfEntry); + getFID(onPerfEntry); + getFCP(onPerfEntry); + getLCP(onPerfEntry); + getTTFB(onPerfEntry); + }); + } +}; + +export default reportWebVitals; diff --git a/src/setupTests.js b/src/setupTests.js new file mode 100644 index 0000000..8f2609b --- /dev/null +++ b/src/setupTests.js @@ -0,0 +1,5 @@ +// jest-dom adds custom jest matchers for asserting on DOM nodes. +// allows you to do things like: +// expect(element).toHaveTextContent(/react/i) +// learn more: https://github.com/testing-library/jest-dom +import '@testing-library/jest-dom';