Alright, let's break this down. We're talking about a dataset version diff explorer. That means we need a UI to compare two versions of a dataset. The goal is to visually represent changes – schema, distribution, and annotations. And we're in the Neo-Brutal / Y2K aesthetic, which means bold, raw, and a bit chaotic.
First, the core elements: it's a comparison tool. So we need two versions side-by-side (or clickable toggles?), a navigation bar to flip between diff modes (schema, distribution, annotation), and a main display area to render the differences. The trick is to make this raw and loud.
Visual Language
2-3px black borders. Done. Hard shadows, offset with hard black shadows? Let's go with a chunky 4px solid black border plus a slight 2px offset shadow for a sticker-like effect. Contrast is king, so we'll use pure white (#fff) for backgrounds, and pure black (#000) for text. Colors? Acid green, hot pink, electric cyan. Let's hit the user with a 2-color background grid. Yellow and purple? Maybe. Acid green borders, black text on neon pink. Glitch fonts are a must. Let's use Courier New, Times New Roman, maybe a Windows-styled pixel font. I'll simulate that with CSS font-family: 'Courier New'. Overlapping, z-order chaos – put some "ERROR" or "DELETED" badges floating around.
Layout Strategy
We are going with a fixed layout. A sticky header at the top – like a retro OS window bar. Then, a navigation bar with toggle buttons for Schema, Distribution, Annotations. They'll be massive. Then the content area. For schema diff, we'll have two columns: "Version A" and "Version B", with rows for fields. Deletions get a strikethrough and red background. Additions get green background, highlighted with color: yellow; background: purple. Font size will be huge, like 40px. Tables are a good start, let's keep the table borders hard. border: 2px solid black; border-collapse: separate; border-spacing: 2px; That will look fun.
We'll use mix-blend-mode on row highlights. We'll use clip-path for some skewed edges.
Animation/Interactivity
On hover, buttons will invert colors: yellow background, black text. We'll add a glitch text effect (CSS keyframes with text-shadow offset). On click, tabs will jab. We need a custom cursor: cursor: crosshair or cursor: url(...), auto. A custom cursor shape is too complex to implement in this demo, so I'll rely on a standard cursor but keep the raw feel via other means. Scrollbars: we can use a webkit custom style to give it a retro, blocky appearance.
Implementation Plan
We'll start with a basic HTML structure. A container, a header, a nav, and main sections (three, for the diff types). Show Section 1 by default. Sections 2 & 3 hidden. Use JS to handle tab switching. We'll also need JS to generate random sample differences. Schema diff will generate tables. Distribution diff will use canvas for bar charts with glitch animations. Annotation diff will use before/after images with a draggable slider. But we might simplify for the prototype: We'll simulate the bar chart and annotation images with CSS divs, perhaps simple histogram bars with neon colors, and overlaid "before" and "after" images with a blend mode.
Glitch Effect: We can create a glitch-text class with keyframes changing text-shadow: 2px 0 red, -2px 0 blue; and transform: skew(...). We'll use this on headings and big labels.
Marquee: Add a horizontal <div class="marquee"><span>DATASET DIFF EXPLORER v1.0</span></div> with CSS animation translateX.
Two columns. Table with border: 2px solid black;. Rows have border-bottom: 2px dotted black;. Removed row: background: repeating-linear-gradient(45deg, #ffcccc, #ffcccc 5px, #ff9999 5px, #ff9999 10px);. Added row: background: var(--acid-green); color: black;. Modified row: background: var(--cyan);. Overlap a "DELETED" badge with position: absolute; right: 0; top: 0; background: red; color: white;.
Distribution Section:
We'll have a canvas for a bar chart of, say, the class distribution. We'll draw two sets of bars for version A and version B, overlapping partially with mix-blend-mode: difference? That could be cool. Or we can simply have side-by-side bars with labels. But to fit the raw aesthetic, we'll use a canvas with custom drawn bars and glitch text labels. We'll have a "Play" button to animate the transition between versions using GSAP for bar heights. That's doable.
Annotations Section:
We'll simulate a bounding box change. A container with an image placeholder (grid pattern). Two overlaid divs representing old and new annotations. Old is red with dashed border. New is acid green solid. Use a slider that controls the width of the top layer via clip-path. A simple range input styled like a Windows slider? We'll style it with CSS borders.
GSAP: We'll include the library via CDN. We'll write a script to animate bars on tab switch to Distribution.
JavaScript Logic:
We'll have a data structure representing three diff types. The schema diff will be an array of objects: { field: "age", old: "integer", new: "float", change: "modified" }. We'll generate it pseudo-randomly on load.
We'll have functions to render:
renderSchemaDiff(version) - we'll pre-render both versions? Actually, we'll show the diff view: Two columns side by side, with same rows for unchanged, and highlighted rows for changes.
Better: When in the schema tab, we display a comparison table with rows aligned. We'll list all fields that existed in either version. For fields present in both but changed, we show the old value in left, new in right, with changed styling. For deletions, right column empty with strikethrough. For additions, left empty with strikethrough? Actually we could list all fields from version A in left column, and all fields from version B in right column, aligning by field name. That's the cleanest approach: a table with headers "Field", "Version A", "Version B". Rows will be the union of field names. If a field is in only one version, the other column is blank but styled as "DELETED" or "ADDED". We'll show field names in first column.
We'll also support multiple row highlighting.
Distribution: We'll have a canvas element. We'll compute histogram for both versions (simulate with random numbers). We'll have a function drawHistogram(version) to animate bar heights using GSAP. We'll have a toggle button to switch between "Overlay" and "Side-by-side" views? Keep it simple: show both as two sets of bars with blending.
Annotations: We'll simulate an image of a scene (a grid pattern). We'll have two annotation rectangles: old version (red) and new version (green). We'll create a simple range input that changes the width of an overlay container that has the new annotation, to simulate a "wipe" effect. We'll also add a "Change type" selector that randomly updates the rectangles to show updates like moved, added, removed.
Tech Stack:
We'll implement as a single HTML file, with inline CSS and JavaScript. We'll use Tailwind via CDN? Actually, using Tailwind for this kind of specific, raw design might require too many custom styles; it's easier to write custom CSS to get the exact bold borders and glitch effects. However, to fulfill the "Technical Stack" mention in the prompt, we should incorporate Tailwind classes? The prompt says "Technical Stack: Tailwind CSS: ...". So we need to use Tailwind. Okay, we'll include Tailwind via CDN and use utility classes for layout, spacing, borders, colors, and also custom style tags for the raw effects like clip-path, custom fonts, glitch animations. We'll use Tailwind's arbitrary values for border widths e.g. border-[3px].
GSAP via CDN. We'll use GSAP to animate the histogram bars when switching versions.
Alpine.js? Not necessary, plain JS is fine.
We'll include a WebGL shader? For a visualizer, maybe not needed. We'll skip WebGL to keep it manageable but still cool.
Execution:
Write the HTML skeleton. Include Tailwind CDN. GSAP CDN.
Define custom fonts in CSS: font-family: 'Courier New', 'Times New Roman', monospace; We can import a pixel font? Too much.
Add the glitch animation keyframes.
Build the header with a marquee.
Build nav: 3 big buttons.
Build 3 sections, hidden by default, use hidden class to toggle. We'll add a container with relative to allow overlapping? We'll keep each section distinct.
Schema Diff Implementation:
We'll create a table. The first column is field name. Second A, third B.
We'll predefine a set of fields. Some will have same type (unchanged). Some will have changed type (modified). Some will be only in A (deleted). Some only in B (added).
We'll color rows based on change type. For unchanged: white bg, black text. For modified: bg var(--cyan) (custom CSS variable). For deleted: bg #ffcccc with strikethrough on the right cell? Actually the row is the field, so if field is deleted, it appears in A column but not B. We'll show empty cell with strikethrough on the field name maybe? Or the whole row? Let's decide: The union of fields, so deleted field appears in A column with value, B column empty. We'll style empty cell with a "MISSING" placeholder. The row could be highlighted as "deleted" (maybe red). Added field appears with empty A cell, value in B cell. Row highlighted as "added" (green).
We'll also show a "change type" badge.
Distribution Diff Implementation:
We'll define a set of classes (like "cat", "dog", "bird", etc). For each version, we'll have a count. We'll generate random counts. We'll draw a bar chart with class labels on x-axis, counts on y-axis.
We'll use canvas with a fixed size. We'll clear and draw bars. We'll draw two sets: Version A bars in solid pink, Version B bars in outline or with blend mode. Or we can draw them side by side.
Better: Side by side grouped bars: for each class, two bars next to each other. That's easier to compare. We'll animate the heights from one version to another when the user clicks a "Compare" button? Actually we want to show the diff between versions A and B. The UI will have a "Version A" and "Version B" but we already have the two datasets known. So we can simply show both together. We'll have a toggle "Show Diff Only" that highlights differences. That could be interesting. But for simplicity, show both side by side and maybe color code differences.
We'll generate an array of objects for each class: { class: 'cat', a: 100, b: 150 }. We'll draw bars for A and B. We'll also output a table of percentage changes.
But we need to fit the raw aesthetic: Use a canvas with pixelated bars (no anti-aliasing?), maybe draw rectangles with fillRect. We'll add glitchy text labels.
We'll use GSAP to animate values: we'll have a currentStats variable that interpolates from A to B when switching to distribution tab? Actually the diff explorer is always comparing fixed versions A and B. So we can just render the static bar chart. But if we want animation, we could have a "Play diff" button that animates the transition from version A to version B using GSAP, but that might be confusing. Instead we'll have a "Refresh Data" button that simulates loading new diff data. That can trigger animation of bars growing.
We'll keep it simple: When the distribution tab is shown, we'll draw the bars with a growing animation from 0 to their values using GSAP.
Annotations Diff Implementation:
We'll simulate an image with a grid pattern. We'll have two layers: layer A (red bounding boxes), layer B (green bounding boxes). We'll have a slider that reveals layer B on top, revealing differences. We'll also have a list of annotation changes with labels like "Bounding box updated: (x,y,w,h)". We'll style these as sticky notes or popups.
We'll support adding, deleting, modifying boxes. We'll have a random generator that creates diff scenarios.
Interactivity:
When clicking tab buttons, we hide all sections and show the relevant one. Also we trigger specific init functions for that section (e.g., initDistribution(), initAnnotations()). We'll use GSAP to animate the bars or other elements when the section becomes visible.
CSS Styling Details:
Use Tailwind's border-black, bg-white, text-black, font-mono (which maps to Courier). For font sizes: text-4xl, text-6xl.
For the glitch text effect, we'll create a CSS class .glitch that does animation: glitch 1s infinite. We'll apply to headings.
For the marquee: We'll create a div with overflow-hidden, inner span with whitespace-nowrap and animate translateX.
For distribution: We'll generate random class counts.
js
const classes = ['person', 'car', 'bicycle', 'dog', 'cat', 'tree', 'building', 'sign'];
let distData = []; // will store {class, a, b}
function generateDistributionData() {
distData = classes.map(cls => {
const a = Math.floor(Math.random() * 1000) + 100;
const b = Math.floor(Math.random() * 1000) + 100;
return { class: cls, a, b };
});
// compute totals
const totalA = distData.reduce((sum, d) => sum + d.a, 0);
const totalB = distData.reduce((sum, d) => sum + d.b, 0);
document.getElementById('total-a').textContent = totalA;
document.getElementById('total-b').textContent = totalB;
document.getElementById('total-delta').textContent = (totalB - totalA);
// Draw histogram
drawHistogram();
}
The histogram drawing: We'll use canvas.
We need to draw bars for each class side by side. We'll set margins. We'll determine max count for scaling.
We'll draw axes? Maybe just bars with labels below.
We'll use bars for version A in hot pink (#ff00ff) and for version B in cyan or acid green.
We'll implement a drawHistogram() that draws bars. We'll also add a GSAP animation that sets a progress variable from 0 to 1 and draws bars accordingly. We'll animate on each render.
Simplest: We'll draw bars with height proportional to value. We'll use ctx.fillRect. We'll draw the bars from bottom up.
We'll set canvas width 900, height 500. Margins: left 60, right 20, top 40, bottom 60. Plot width = 900 - left - right. Bar group width = plot width / classes.length. Within each group, two bars with some spacing.
We'll also label class names.
We'll create an animation using GSAP: animate an object { t: 0 } to { t: 1 } over 1 second, and on update, redraw using t to scale bar heights.
We'll store targetHeights array for A and B bars, and during animation multiply by t.
But we can also just grow bars from 0 to target using GSAP's from tween on the values directly.
Better: We'll define a function drawHistogram(progress) where progress is between 0 and 1. We'll clear canvas, draw axes, and for each class, draw two bars with height *= progress.
We'll then call gsap.to({ progress: 0 }, { progress: 1, duration: 1, onUpdate: () => drawHistogram(this.targets()[0].progress) }) when the tab is activated or when new data generated.
But we should ensure we don't start multiple animations. We'll manage that.
Annotations: We need a canvas-like but using DOM elements for bounding boxes.
We'll have a container with position relative. Inside we have a grid background.
We'll generate random boxes for old and new versions. Each box is an absolute positioned div with border.
We'll generate an array of oldBoxes and newBoxes with random x, y, width, height (percentage or pixels). We'll ensure they are within container size.
We'll generate a diff: some boxes are same but moved? We'll just randomly generate separate sets. For simplicity, we'll treat each version independently. The diff list will be computed: If a box in new has similar position to an old one, we might treat as modified. But for the demo, we can just randomly generate and then randomly mark some as added/deleted/modified. We'll generate a list of changes for the UI.
Implementation:
js
We'll also handle the slider: The #new-annotations container has a clip-path that we update based on slider value. We can set clip-path: inset(0 ${100 - value}% 0 0)? Actually we want to reveal from left as slider moves right: That's achieved by clip-path: inset(0 0 0 value%) if value is the amount revealed from left? Wait: If we want to reveal the new layer as the slider moves to the right, we want the visible portion of the new layer to be from left edge up to the slider handle position. So we can set clip-path: inset(0 0 0 X%) where X is the percentage of hidden left? Let's think: clip-path: inset(top right bottom left). If we want to show from left to some X% of width, we need to hide the right part. Actually we want to clip the right side: so we want clip-path: inset(0 0 0 0) shows full. To reveal gradually from left, we want the right side to be hidden? No, the new layer is on top; we want to see the part of new layer that is to the left of the handle, i.e., up to a certain x position. So we want to show the left portion and hide the rest. That's clip-path: inset(0 0 0 0) shows all. To hide the right part, we set right inset to (100% - percentage). So inset(0 ${100-percent}% 0 0)? Actually if we want to show exactly p% of the width from the left, we need to cut off the right side by (100-p)%. So clip-path: inset(0 (100-p)% 0 0). For example p=50%: right inset = 50%. So inset(0 50% 0 0). That works. But we have also left, top, bottom. We'll set left=0, bottom=0, top=0. So we need to compute right = 100 - value.
But the slider is 0-100. We'll listen to input event on the range. We'll set new-annotations.style.clipPath = 'inset(0 ' + (100 - value) + '% 0 0)'. Also we'll position the handle at left: value% (with some offset). We'll set handle style left: value%.
Better: We'll set new-annotations clip-path: inset(0 0 0 0) and use width of an inner wrapper? Actually using clip-path on the container is fine.
Now we need to make the initial slider handle position and clip-path reflect the value.
We'll also have a "GENERATE NEW DIFF" button that re-runs generateAnnotations() and also resets slider to 50% maybe.
We'll also tab switching: When distribution tab is activated, we call generateDistributionData(). When annotations tab is activated, we call generateAnnotations() if not already done, or we could call each time.
We'll also want to reinitialize GSAP animation for distribution each time we switch to that tab and maybe when data is regenerated.
We'll write initDistribution() that draws histogram with animation.
We'll also ensure the canvas is correctly sized, maybe use devicePixelRatio? Not needed.
Tweaking the Glitch and Aesthetic
We want more raw: we can add some random margin variations to elements. But we need to keep it systematic.
We can add a "glitch" effect to the table rows on hover: maybe a slight shift.
We can also add a "scanline" overlay using CSS repeating linear gradient with fixed position and low opacity.
We'll add a .scanlines div covering the whole page with pointer-events none, a repeating linear gradient with transparent and rgba(0,0,0,0.1) lines. That gives CRT vibe.
We'll also add a random "ERROR" badge that floats somewhere.
We'll include a "pixel" font via Google Fonts: 'Press Start 2P' maybe. But that would add extra request. We can just use 'Courier New' and 'Times New Roman' which are raw.
We'll also use uppercase text mostly.
Now, putting JS together:
We'll wrap code in document.addEventListener('DOMContentLoaded', ...).
Define global variables.
Initialize:
Bind tab buttons.
Set initial active tab (schema).
Call renderSchemaDiff().
Call generateDistributionData()? Not until tab click.
For annotations, we can generate later.
We'll also set up the slider for annotations.
Potential enhancements:
Add a "glitch" effect to the canvas drawing: randomly offset some bars horizontally by a few pixels for a frame? That might be complex. But we could simulate by randomly translating the canvas context for some bars.
Add a "Marquee" that scrolls random warning messages: "WARNING: DATA MAY BE CORRUPTED", "CACHE MISS", etc.
We'll keep it within scope.
Testing mentally:
The tabs must work. The table should show differences.
Distribution: drawHistogram should draw both bars. We'll implement drawHistogram function that loops over distData, calculates x positions, draws rectangles. We'll also draw labels.
We'll need to calculate scaling: maxVal = Math.max(...distData.map(d => Math.max(d.a, d.b))). Then bar height = (value / maxVal) * (plotHeight - margins). We'll leave some headroom.
We'll also draw axis lines? Maybe not, but a bottom line.
We'll use ctx.strokeRect for outline bars? We want fill. For version A: fill with #ff00ff. For version B: fill with #00ff00? That may be too bright. Use cyan. But we also need to color bars based on significance? Maybe for distribution diff we want to highlight classes that changed significantly (e.g., >10% difference). We could compare percentages and color accordingly. But we can skip.
Annotations: The boxes must be within the container. The container we set a fixed aspect ratio? We'll set the container dimensions equal to canvas or a fixed size, perhaps width 100% of parent, but we need a fixed height for coordinates. We'll set container style width: 100%; height: 500px; and then we need to compute actual width in JS to place boxes. We'll get the container's width via clientWidth and adjust. But if responsive, we might need to recalc on resize. For simplicity, we'll set a fixed pixel size: 900x500. We'll set container style width: 900px; height: 500px; max-width: 100%; but it might overflow. Alternatively, we can use percentage coordinates. That is easier: generate boxes with left, top as percentage. Then we set left: x%, top: y%, width: w%, height: h%. This will be responsive. So we'll generate random values between 0 and (100 - w). We'll store as percentages.
Let's adjust: In randomBox, we generate wPct = random 10-30%, hPct similar. Then xPct = random 0 to (100 - wPct). Similarly yPct. Then set style left: xPct%, top: yPct%, width: wPct%, height: hPct%. That ensures containers of any dimension work.
We'll need to compute overlap in percentages for diff detection. That's fine.
We'll adjust container to be responsive: it will have a fixed aspect ratio? We'll set style aspect-ratio: 16/9; and height auto? But we need a defined height for the demo. We'll set container width: 100%; max-width: 800px; aspect-ratio: 16/9; This will work. We'll set the parent flex to center.
We'll update the drawing accordingly.
Now writing the actual code. We'll produce the final output with all HTML, CSS, JS.
We must ensure that we don't use external images; grid background fine.
Let's refine the CSS for the "hard border" and "hard shadow" to create a consistent look. We'll define a utility class .hard-border with border: 3px solid black; and .hard-shadow with box-shadow: 4px 4px 0 0 #000; but we want offset maybe. We'll apply to tab buttons: shadow-[4px_4px_0_0_black]. That is fine.
We'll also add a "sticker" effect: some elements have transform: rotate(-1deg); or random small rotations. We'll add to the summary box maybe.
We'll add a "glitch" animation to the whole app on random intervals? Might be too much.
We'll also add a random error message: "SYSTEM READY" or "CACHE MISS".
We'll also use data-text attribute for glitch text effect on hover? Not needed.
Implementation flow:
We'll start building the HTML, then add CSS, then JS. We'll test each section logically.
One challenge: The tab buttons should indicate active state. We'll add active class to the active button: style with bg-(hot-pink) and maybe different shadow.
We'll manage that in JS: on tab click, remove active from all buttons, add to clicked. Also hide all sections, show target.
We'll also ensure that when switching to distribution or annotations, we trigger the respective init if it's the first time or we want to refresh.
We'll create a flag distributionInitialized, annotationsInitialized.
For distribution, we want to animate each time we switch to it, so we'll call animateHistogram() on tab show, perhaps after generating data if not yet generated. We'll generate data on first load for convenience? Actually we can generate on demand. We'll do: on first time showing distribution, call generateDistributionData() and set initialized true. Subsequent times we just animate again? Possibly we can regenerate data each time we click the tab for more "freshness"? The prompt says "design a dataset version diff explorer", so it's okay to show static diff. We'll keep it simple: generate once and animate on show.
Better: We'll generate data each time we switch to distribution to make it lively. But then the numbers would change each time, which may be confusing because it's supposed to be comparing specific versions. However, it's a demo. We'll generate once and animate when the tab becomes visible. That's fine.
But we also want to have a "GENERATE NEW DIFF" button in annotations only. For distribution we could also have a refresh but not necessary.
We'll proceed with generating data once on page load for all three diffs. That way they are ready. But we need to store them globally and then render when tab is clicked.
Simplify: On page load, generate all data (schemaData, distributionData, annotationData) and pre-render schema (since it's default). For distribution, we can pre-draw but hidden? We can draw off-screen? Better to draw only when shown to ensure canvas dimensions are correct (canvas may not have dimensions if hidden). Actually canvas has width/height attributes; if it's in a hidden div, drawing still works. But we might have to compute container width? We'll get the canvas element's width/height from attributes. That's fine. So we can pre-draw distribution on load. But we want animation when the tab is first shown. We can set a flag so that when the section is shown for the first time, we trigger the animation. Or we can animate when data is generated.
We'll do: On tab click, if the section hasn't been initialized (i.e., not yet had its content prepared), we call a prepareSection function that renders/hydrates and then maybe animates. We'll have a prepared object mapping section id to boolean.
For schema, we'll prepare on load.
For distribution, we'll prepare on load: generate data, set up canvas, and then call animateHistogram() which will grow bars from 0. But we want that animation to happen when the tab is shown, not on load if we are not viewing it. So we could set a flag that the data is ready but animation hasn't played. On tab show, if not yet animated, we trigger the animation and set animated flag.
Alternatively, we'll just animate every time we switch to that tab. That might be okay. We'll call drawHistogram(0) initially, then animate to 1 on tab show. That will cause bars to grow from 0 every time we click the tab. That might be annoying if you switch back and forth; but it's fine for a demo.
Let's implement: On load, we generate distribution data and call drawHistogram(0) to draw empty bars. Then on tab show, we animate to 1 using GSAP. That means the first time we show, bars will grow from 0 to full. When we hide and show again, they'll again grow from 0? That would require storing the previous progress and maybe reseting to 0 before animating. If we want animate only once, we can store a flag and not reset. But to keep it simple, we'll animate every time we click the tab. That is consistent.
But we need to clear the canvas and redraw at progress 0 before starting animation. We'll store a GSAP timeline? We'll just do:
We'll call animateHistogram() when the distribution tab is clicked. But we need to ensure drawHistogram(0) is called to clear? Actually the animation starts from current t. If we start from 0 each time, we need to set obj.t=0 before tween. So we'll just create a new object each time with { t: 0 }.
But if the user clicks repeatedly, we may have multiple concurrent tweens. We could kill previous tweens, but not crucial.
We'll also need drawHistogram to be able to accept t between 0 and 1.
We'll implement drawHistogram(progress).
Now, proper canvas drawing:
js
function drawHistogram(progress) {
const canvas = document.getElementById('histogram-canvas');
const ctx = canvas.getContext('2d');
const width = canvas.width;
const height = canvas.height;
const margin = { top: 40, right: 20, bottom: 60, left: 60 };
const plotWidth = width - margin.left - margin.right;
const plotHeight = height - margin.top - margin.bottom;
// Clear
ctx.clearRect(0, 0, width, height);
// Draw axes
ctx.strokeStyle = 'black';
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(margin.left, margin.top);
ctx.lineTo(margin.left, height - margin.bottom);
ctx.lineTo(width - margin.right, height - margin.bottom);
ctx.stroke();
// Compute max
let max = 0;
distData.forEach(d => { if (d.a > max) max = d.a; if (d.b > max) max = d.b; });
// Add some headroom
max = max * 1.1;
const groupWidth = plotWidth / distData.length;
const barWidth = groupWidth * 0.4; // each bar width 40% of group, with gap
distData.forEach((d, i) => {
const groupX = margin.left + i * groupWidth;
const aHeight = (d.a / max) * plotHeight * progress;
const bHeight = (d.b / max) * plotHeight * progress;
// Draw A bar (left)
const aX = groupX + (groupWidth - 2*barWidth)/2;
const aY = height - margin.bottom - aHeight;
ctx.fillStyle = '#ff00ff'; // hot pink
ctx.fillRect(aX, aY, barWidth, aHeight);
// Draw B bar (right)
const bX = aX + barWidth;
const bY = height - margin.bottom - bHeight;
ctx.fillStyle = '#00ffff'; // cyan
ctx.fillRect(bX, bY, barWidth, bHeight);
// Draw label
ctx.fillStyle = 'black';
ctx.font = '14px "Courier New"';
ctx.textAlign = 'center';
ctx.fillText(d.class, groupX + groupWidth/2, height - margin.bottom + 20);
// Draw values on top of bars? maybe
if (progress > 0.8) {
ctx.fillStyle = 'black';
ctx.fillText(d.a, aX + barWidth/2, aY - 5);
ctx.fillText(d.b, bX + barWidth/2, bY - 5);
}
});
}
We should also add a title for the histogram: "Class Distribution Comparison" above canvas. We can put it in the HTML.
Annotations slider:
We'll get the slider element: document.getElementById('compare-slider'). Add event listener input to update new-annotations clip-path and handle position.
The handle is separate div with id slider-handle. We'll update its left style.
We'll also set initial values.
Also we need to ensure that the new-annotations element has a class that we can adjust. We'll set its style directly.
Gap: The clip-path should update as slider moves.
We'll also set the handle's left to value% but need to adjust because handle's anchor point is its left edge? We'll set left: calc(${value}% - 1px) or just set left: ${value}% and ensure the handle width is accounted. We'll use transform: translateX(-50%) to center on the line. So we set left: ${value}% and transform: translateX(-50%). But the handle might be styled with border, it's fine.
We'll add CSS: #slider-handle { transform: translateX(-50%); }. But we might also want the handle's left to be at the exact point of the clipping line? Actually the clipping line is at the border between old and new. The handle should sit on that line. So we set left: ${value}% and transform translateX(-50%) ensures the center of handle aligns.
We'll set new-annotations clip-path to inset(0 0 0 ${value}%)? Wait: As slider increases, we want to reveal more of the new layer? The new layer is on top; we want to compare by sliding a divider. Typically, the top layer (new) is revealed from left as slider moves right. So at 0% we see only old (top layer hidden entirely right). At 100% we see only new (top layer fully visible). So we want to show left portion of new layer equal to slider value. So we need to hide the right part beyond the slider. That means we set clip-path: inset(0 0 0 ${value}%)? Let's test: At value=0, we want new layer hidden. inset(0 0 0 0) shows full. inset(0 0 0 100%) hides all (because left inset = 100%, meaning 100% of the left side is cut). Actually the syntax: inset(top right bottom left). So if we set inset(0 0 0 0) it's full. If we set left=100%, it means cut 100% from left, effectively hiding everything. That's not what we want. We want to cut from right. So set right = (100 - value)%. Because we want to keep left part of width = value%, and cut the rest from right. So inset(0 ${100 - value}% 0 0). At value=0, right=100% -> everything cut, hidden. At value=100, right=0% -> full visible. That matches.
Thus: clip-path: inset(0 ${100 - value}% 0 0).
We'll update that in the input event.
We'll also need to handle the handle position: left: ${value}%.
We'll also update the initial clip-path on page load.
Now, we also need to be careful: The new-annotations container is a child of the main container and covers the whole area. So the clip-path will work relative to its own size.
We'll add the event listener.
Two more bits:
We should make the UI more raw: add some "pixels" patterns. We could add a background pattern of crosshatch to the body.
Add a "PLEASE WAIT" loading animation? Not needed.
Potential issues: The canvas may appear blurry on high DPI screens. We could set width and height to double the CSS size and scale down. But it's okay.
Let's now write the full code.
We'll also add a random glitch effect to the headings using ::before and ::after with content duplication. But we'll keep simple.
We'll also add a "glitch" class to the main title only.
Finalize: We'll output the HTML file content, with all inline CSS and JS.
We'll ensure to include Tailwind and GSAP from CDNs.
We'll also include a script to update the current date/time in the marquee? Not needed.