diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..403adbc --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +.DS_Store +node_modules +/dist + + +# local env files +.env.local +.env.*.local + +# Log files +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* + +# Editor directories and files +.idea +.vscode +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d3aa313 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Najmul H. Bappy + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..09deec5 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# algo + +## Project setup +``` +npm install +``` + +### Compiles and hot-reloads for development +``` +npm run serve +``` + +### Compiles and minifies for production +``` +npm run build +``` + +### Lints and fixes files +``` +npm run lint +``` + +### Customize configuration +See [Configuration Reference](https://cli.vuejs.org/config/). diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 0000000..e955840 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,5 @@ +module.exports = { + presets: [ + '@vue/cli-plugin-babel/preset' + ] +} diff --git a/base.js b/base.js deleted file mode 100644 index be58444..0000000 --- a/base.js +++ /dev/null @@ -1,116 +0,0 @@ -// class for sorting -class sortData { - constructor(data) { - this.data = data; - } - selectionSort() {} - bubbleSort() {} - stopSort() { - return false; - } -} - -//get selected algorithm -function getAlgo() { - var algo = document.getElementsByName("algo-name"); - for (var i = 0; i < algo.length; i++) { - if (algo[i].checked) { - return algo[i].value; - } - } -} - -// function for changing specific bar color filtering with data -// d => single data, color => hexa color code -function changeBarColor(d, color) { - var smi = heightScale(d); - svg.selectAll("rect").each(function (d, i) { - if (smi == d3.select(this).attr("height")) { - d3.select(this).style("fill", color); - } - }); -} - -// function for generating random data -function randomData(max, range) { - data = []; - n = 0; - while (n < max) { - d = Math.floor(Math.random() * range) + 1; - if (data.includes(d) != true) { - data.push(d); - n++; - } - } - return data; -} - -//function for creating chart. Note: data is an array of integer value -function createChart(data) { - svg = d3.select("#chart").append("svg"); - - bandScale = d3.scaleBand().domain(data).range([0, areaWidth]).padding(0.1); - - svg.attr("width", areaWidth).attr("height", areaHeight); - - svg - .selectAll("rect") - .data(data) - .enter() - .append("rect") - .attr("x", function (d, i) { - return bandScale(d); - }) - .attr("y", function (d) { - return areaHeight - heightScale(d); - }) - .attr("width", function () { - return bandScale.bandwidth(); - }) - .attr("height", function (d) { - return heightScale(d); - }) - .style("fill", "rgb(173, 216, 230)"); - - svg - .selectAll("text") - .data(data) - .enter() - .append("text") - .text(function (d) { - return d; - }) - .attr("x", function (d, i) { - return bandScale(d) + 10; - }) - .attr("y", function (d) { - return areaHeight - 15; - }) - .style("width", bandScale.bandwidth) - .style("fill", "black") - .style("font-size", areaWidth / data.length / 3) - .style("font-family", "sans-serif") - .style("z-index", 1); -} - -// bar visualization while sorting. Bar Swapping -function swapBar(data) { - var dOrder = data.map(function (d) { - return d; - }); - bandScale.domain(dOrder); - svg - .transition() - .duration(750) - .selectAll("rect") - .attr("x", function (d) { - return bandScale(d); - }); - svg - .transition() - .duration(750) - .selectAll("text") - .attr("x", function (d) { - return bandScale(d) + 5; - }); -} diff --git a/function.js b/function.js deleted file mode 100644 index 71ad81e..0000000 --- a/function.js +++ /dev/null @@ -1,121 +0,0 @@ -var svg, - bandScale, - text, - maxElement = 15, - dataRange = maxElement * 2, - areaHeight = 150, - areaWidth = 800, - time = 300, - traverseColor = "#ffcaa1", - smallestColor = "#ab87ff", - unsortedColor = "#add8e6"; - -// generating random data -var data = randomData(maxElement, dataRange); -function setSpeed() { - time = document.getElementById("speed").value; -} -//a d3 function for scaling height for all the data this function -var heightScale = d3 - .scaleLinear() - .domain([0, d3.max(data)]) - .range([0, areaHeight]); - -// initialized a chart with random value -createChart(data); - -let Sort = new sortData(data); -Sort.selectionSort = function () { - const timer = (ms) => new Promise((res) => setTimeout(res, ms)); - async function sort() { - // We need to wrap the loop into an async function for this to work - for (var i = 0; i < data.length; i++) { - smallest = data[i]; - pos = i; - changeBarColor(smallest, smallestColor); - await timer(time); - for (var j = i + 1; j < data.length; j++) { - changeBarColor(data[j], traverseColor); - if (smallest > data[j]) { - await timer(time); - changeBarColor(smallest, unsortedColor); - smallest = data[j]; - pos = j; - } - - changeBarColor(smallest, smallestColor); - await timer(time); - changeBarColor(data[j], unsortedColor); - } - if (data[i] != smallest) { - temp = data[i]; - data[i] = smallest; - data[pos] = temp; - - var swooshAudio = new Audio( - "/algorithm-visualizer/sound-effects/swoosh.mp3" - ); - swooshAudio.play(); - } - changeBarColor(smallest, "#56b4d3"); - swapBar(data); - await timer(time); // then the created Promise can be awaited - } - svg.selectAll("rect").style("fill", "#56b4d3"); - var completeAudio = new Audio( - "/algorithm-visualizer/sound-effects/complete.mp3" - ); - completeAudio.play(); - } - sort(); -}; - -Sort.bubbleSort = function () { - const timer = (ms) => new Promise((res) => setTimeout(res, ms)); - async function sort() { - var temp; - for (i = 0; i < data.length - 1; i++) { - changeBarColor(data[0], smallestColor); - await timer(time); - for (j = 0; j < data.length - i - 1; j++) { - await timer(time); - changeBarColor(data[j + 1], traverseColor); - await timer(time); - if (data[j] > data[j + 1]) { - temp = data[j]; - data[j] = data[j + 1]; - data[j + 1] = temp; - changeBarColor(data[j + 1], smallestColor); - var swooshAudio = new Audio("./sound-effects/swoosh.mp3"); - swooshAudio.play(); - swapBar(data); - await timer(time); - } else { - changeBarColor(data[j + 1], smallestColor); - } - changeBarColor(data[j], unsortedColor); - } - } - svg.selectAll("rect").style("fill", "#56b4d3"); - var completeAudio = new Audio( - "/algorithm-visualizer/sound-effects/complete.mp3" - ); - completeAudio.play(); - } - sort(); -}; - -document.getElementById("sort").addEventListener("click", function () { - if (getAlgo() == "selection-sort") { - Sort.selectionSort(); - } else if (getAlgo() == "bubble-sort") { - Sort.bubbleSort(); - } -}); - -document.getElementById("random-data").addEventListener("click", function () { - var data = randomData(maxElement, dataRange); - Sort.stopSort(); - svg.remove(); - createChart(data); -}); diff --git a/index.html b/index.html deleted file mode 100644 index e10623d..0000000 --- a/index.html +++ /dev/null @@ -1,56 +0,0 @@ - - -
- - - -Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: