Return Home

Cruise Size Comparisons

ProjectJavaScriptWebApp

Overview

I recently went on a western caribbean cruise on an older Royal Caribbean ship. I knew my ship (the Enchantment of the Seas) was on the smaller side, but I couldn't fully comprehend how much smaller it was until we were parked directly next to the Carnival Jubilee and the MSC World while in Costa Maya. On our top deck, the other ships towered over us. For reference, the Jubilee had 5 more passenger decks than our ship.

In that moment of "holy cow, our ship is small," I realized I wanted to be able to compare these different ships side by side on some kind of webapp, and made this ship comparison tool. It loads ship metadata from a JSON file, lets you search for and select two ships, and compares them in a side-by-side ocean view with tooltips and some basic statistics below.

The biggest roadblock I ran into was that clean PNG and SVG images of the ships are nearly impossible to source. There are *similar* images out there, but they are either class-specific, lacking updates to the ships, not very accurate, or not in the side profile format.

I ended up sourcing generic class images for the different ships. Carnival had a ship/class spreadsheet that I was able to source decent images from. In Royal Caribbean's case, I found a ship class spreadsheet someone else had generated, and broke out all the images, manually cropping and adding a transparent background. Claude generated a handful of generic images for different naval vessel classes (...so apologies if your favorite ship doesn't look like the real thing).

Try it out

Start typing to filter the fleet.

Search and select ships to see the shared waterline comparison.
Click on a ship to view more details.

Stats

The chart uses the currently selected ships and values loaded from the JSON dataset.

Ship Scaling Logic

This piece of code is probably the most significant concept in the project. The idea is simple. We have an image of a ship, and based on the real life size of the ship(s) they are scaled and compared accordingly. To make that happen, a single shared pixels-per-meter scale is computed from vertical and horizontal constraints (viewport limits), then applied so each ship's width, profile height, and draft stay proportional. On the smaller viewports, width caps and spacing change based on whether one ship or two ships are selected, so ships stay visible instead of collapsing.

// Compact layout gives different spacing and width caps for 1 ship vs 2 ships
const shipGap = compact ? (ships.length > 1 ? 12 : 8) : 20;
const horizontalPadding = compact ? (ships.length > 1 ? 16 : 8) : 32;
const compactShipMaxWidth = compact
    ? (ships.length > 1
        ? (stageWidth <= 420 ? Math.floor(stageWidth * 0.46) : Math.floor(stageWidth * 0.42))
        : Math.floor(stageWidth * 0.82))
    : Number.POSITIVE_INFINITY;

const perShipMaxWidth = Math.max(
    1,
    Math.min(
        Math.floor((stageWidth - horizontalPadding - (shipGap * (ships.length - 1))) / ships.length),
        compactShipMaxWidth
    )
);

// Shared pixels-per-meter scale picks the tighter of vertical vs horizontal fit
const pixelsPerMeter = Math.max(
    0.12,
    Math.min(heightBudget / maxTotalMeters, perShipMaxWidth / maxLength)
);

// Convert ship profile/draft meters to pixel heights.
function shipScale(ship, pixelsPerMeter, verticalBoost = 1) {
    const belowPx = Math.max(1, Math.round(ship.draftM * pixelsPerMeter * verticalBoost));
    const abovePx = Math.max(1, Math.round(ship.profileM * pixelsPerMeter * verticalBoost));
    return { belowPx, abovePx };
}

// Calculate how far to submerge the rendered ship against the wave.
function shipDraftOffset(belowPx, abovePx, waveLineFromBottom, shipCount, relativeSizeBiasPx = 0) {
    const formationTrim = shipCount > 1 ? MULTI_SHIP_OFFSET_TRIM : SINGLE_SHIP_OFFSET_TRIM;
    const minVisibleSubmergePx = Math.min(
        Math.max(MIN_SUBMERGE_PX, Math.round((belowPx + abovePx) * MIN_VISIBLE_SUBMERGE_RATIO)),
        Math.max(MIN_SUBMERGE_PX, Math.round(abovePx * MAX_SUBMERGE_RATIO_OF_ABOVE))
    );
    const maxVisibleSubmergePx = Math.max(minVisibleSubmergePx, Math.round(abovePx * MAX_SUBMERGE_RATIO_OF_ABOVE));
    const targetSubmergePx = Math.min(maxVisibleSubmergePx, Math.max(belowPx, minVisibleSubmergePx));
    return Math.round(targetSubmergePx - waveLineFromBottom + SHIP_ROW_BOTTOM_PADDING + formationTrim + relativeSizeBiasPx);
}

const scale = shipScale(ship, pixelsPerMeter, verticalBoost);
const relativeSizeBiasPx = ships.length > 1
    ? Math.round(((maxAbovePx - scale.abovePx) / Math.max(1, maxAbovePx)) * MAX_MULTI_SIZE_BIAS_PX)
    : 0;
const submergeOffset = shipDraftOffset(scale.belowPx, scale.abovePx, WAVE_LINE_FROM_BOTTOM, ships.length, relativeSizeBiasPx);

Data Normalization

Another important part of the project was normalizing mixed ship data into one comparison model. Cruise ships and naval vessels do not describe capacity the same way, so prior to rendering, each entry is converted into shared fields like length, draft, profile height, and a display-ready personnel value (in the case of Naval vessels, combining crew and passengers) before anything is drawn.

Code Reuse

When first prototyping the vizualization and multiselect feature, I was looking for a way to be able to search through and/or list hundreds of ships and limit UI clutter. The goal was to parse a large JSON file and have the multiselect feature automatically populate with data. I tried a few different approaches; radio buttons, a dropdown, eventually multi-level nested dropdowns (I despise these), and didn't like any of them.

I took a short break and realized that I had already very recently built a similar feature and even demoed it. The typeahead demo came full circle and I even added a silly little debounce function. This project uses the exact same search UI and typeahead logic as the demo.