Aidan Do Logo

Sorting Visualizer of Sorting Visualizers

HTML Vanilla JavaScript AWS Lambda AWS S3 Python Tailwind CSS

Once YouTubers started making videos about it, sorting visualizers became a popular portfolio project. A sorting visualizer is a tool that displays an array of rectangles (essentially a bar chart) being sorted by height, employing different algorithms such as quick sort, insertion sort, merge sort, etc. For example:

I never considered building one until I thought it would be funny to create a sorting visualizer where the items being sorted were sorting visualizer projects. I also wanted to improve the UI/UX in many of the projects. So I decided to build one. Here's a live demo:

View full project >
[0]

Project Purpose and Goal

The project was primarily designed for entertainment and educational purposes, with the following goals:

I also wanted to include the main features of a sorting visualizer (albeit in simpler forms), such as highlighting, sound, and well-known algorithms.

[1]

Technologies Used

I used HTML and Vanilla JavaScript with Tailwind CSS on the front end. The colour selection, spacing, layout utilities, and built-in responsive prefixes in Tailwind CSS are helpful. I considered using React for this project but decided it was overkill for its relatively small size.

I wanted to build this application without a backend, but GitHub API requires a personal access token, which shouldn't be embedded in the front end for security reasons. Additionally, GitHub API search results take a few seconds to complete; I didn't want to slow down the page's initial load, so I needed to cache the results somewhere. I used AWS Lambda (with Python) to query GitHub API since an entire server was overkill for this project. It's okay if results are a day old so a daily compute job works fine. I stored the results in an AWS S3 bucket as a JSON file. With this setup, I could run this application for less than 3 cents a year.

View GitHub repo >
[2]

Challenges

There were two main challenges in this project:

  1. Generating the sort sounds
  2. Making it responsive

I had to use the Web Audio API to generate the sort sounds, which I'd never used before. Initially, I thought it would be straightforward, but my first attempt at creating these sounds was very jarring, with noticeable artifacts and snaps (sound warning):

After researching sound theory, understanding how frequencies work, and exploring some music theory techniques, I figured out a few crucial points:

The end result is a soft sound without any artefacts:

The other challenge was making it responsive, as some interactive elements required extra consideration. I initially designed project details to be shown via popover:

Old popover approach to displaying project details

However, this doesn't work on mobile, so I decided to display the project details on a card somewhere, and I needed a widget to select a project. I tried using the native slider, but it was difficult to style the slider, and it was challenging to accurately line up the select knob with the project bar chart (considering each browser renders sliders slightly differently). So, I created a custom slider with JavaScript.

I also needed to reduce the number of projects on smaller screens so the bar chat would fit on the screen. I used JavaScript to reduce the number of projects based on screen size. Additionally, because there are fewer items, the sorting rate needs to be adjusted so that the sorting does not happen too quickly.

Making the site responsive was a fairly elaborate process, but the result was worth it:

Another benefit of making the site responsive was that getting feedback from friends is easy, as it was convenient to pull out my phone in a social situation.

[3]

To Wrap Up

Overall, I'm happy with how the project turned out. I managed to learn some new things:

While it would have been nice to include a few more features, such as:

However, I achieved the project's main goals and may add these features in the future.

[4]

Let's Build Together

Whether you're looking for an engineer, have a question or want to connect, feel free to reach out at:

aidando73@gmail.com