Tickd.ai
← The Tickd Guide

Comparisons

Claude 3.5 Sonnet vs Gemini 1.5 Pro for Building Interactive SVG Charts: Which Engine Generates Valid Responsive Math Without Clipping Label

Building responsive SVG charts from scratch requires flawless coordinate math. We test Claude 3.5 Sonnet and Gemini 1.5 Pro to see which LLM writes cleaner frontend code.

Updated 10/26/2026

The Developer’s Nightmare: Custom SVG Math

There is a specific kind of developer pain that only comes from writing custom SVG charts. Sure, you could pull in a heavy, bloated third-party charting library that ruins your bundle size. But if you want a lightweight, pixel-perfect, highly customized chart, writing raw <svg> elements in React or vanilla JavaScript is the gold standard.

Except, the math is brutal. You have to map dynamic data arrays onto a fixed coordinate system, calculate responsive viewports, ensure your padding accounts for dynamic text label lengths, and make sure your tooltips don't clip off the edges of the container.

We put the two reigning champions of developer-focused LLMs to the test: Anthropic’s /platforms/claude (3.5 Sonnet) and Google's /platforms/gemini (1.5 Pro). We wanted to see which engine could write a fully responsive, interactive SVG line chart component from scratch, without relying on external UI libraries, and without dropping a single NaN error in the browser console.

Which AI should I use for this?

Tickd is independent and not affiliated with any AI company.

The Test Suite

We gave both models the exact same prompt, demanding a production-ready React component:

`text Create a responsive, self-contained React component that renders an interactive multi-line SVG chart. - It must accept an array of data points: { date: string, revenue: number, signups: number }. - The SVG must scale responsively using viewBox and handle container resizing dynamically. - Calculate the y-axis scales dynamically based on data bounds, with clean tick intervals. - Include hover states that render a custom SVG tooltip showing both metrics. - Crucially: Ensure labels, axes, and the tooltip are fully padded and never clip outside the SVG bounds. - Write raw SVG elements only. Do not use Recharts, D3, or any other external visualization library. `

Let’s break down how both engines handled the math, the responsiveness, and the interactive states.

Test 1: Coordinate Mapping and Aspect Ratios

To draw a line chart, the LLM must map arbitrary data points (e.g., revenue values ranging from $4,000 to $12,500) to pixel coordinates within an SVG viewBox (e.g., 0 0 800 400).

Claude 3.5 Sonnet Sonnet tackled the coordinate mapping with absolute precision. It immediately calculated the minimum and maximum bounds of the dataset, added a 10% padding buffer to the top and bottom so the lines wouldn't touch the very edges of the frame, and wrote clean linear scaling functions:

`javascript const xScale = (index) => padding.left + (index / (data.length - 1)) * (svgWidth - padding.left - padding.right); const yScale = (val) => padding.top + (1 - (val - minVal) / (maxVal - minVal)) * (svgHeight - padding.top - padding.bottom); `

The resulting SVG coordinates were flawless. When rendered, the lines mapped beautifully to the grid lines it generated, and the math held up even when we passed empty arrays or single-item datasets (handled via a fallback check it thoughtfully included).

Gemini 1.5 Pro Gemini 1.5 Pro also understood the math, but its scaling calculations were slightly sloppier. It calculated the maximum bounds but forgot to establish a baseline minimum bound, meaning the chart always defaulted to a hard `y = 0` start. While this is fine for some datasets, it compresses the visual variance of data that fluctuates within a tight, high range (like server temperatures hovering between 80 and 85 degrees).

Test 2: Label Clipping and Responsive Paddings

One of the biggest issues with AI-generated SVGs is that they forget text is rendered from its anchor point. If you place a label at the far right edge of your SVG width, half the text will render outside the viewBox and get sliced off.

  • Claude 3.5 Sonnet solved this by calculating dynamic margins based on the string length of the largest y-axis tick. It also used the SVG attribute text-anchor="end" for the y-axis labels and text-anchor="middle" for the x-axis labels. It worked beautifully; no clipping occurred, even when we scaled the browser window down to mobile sizes.
  • Gemini 1.5 Pro hardcoded a left padding of 40px. When we fed it five-digit revenue values, the dollar signs and the first digits were completely clipped by the left edge of the SVG. It failed to adjust the coordinate map dynamically to account for text width.

Test 3: The Interactive Tooltip (The Ultimate Squeaky Wheel)

An interactive SVG chart needs to track mouse movements, find the nearest data point along the x-axis, and render a tooltip box containing the data. Doing this in vanilla React using only SVG elements (rather than absolute-positioned HTML divs) is incredibly tricky.

Claude 3.5 Sonnet Sonnet’s interactive implementation was brilliant. It set up an invisible background rectangle to capture all mouse pointer movements, calculated the nearest data index using a clean binary-search-like lookup, and updated a local `hoveredIndex` state.

For the tooltip itself, it rendered a <g> group containing a styled <rect> and two <text> elements. To prevent the tooltip from clipping when hovering over the last data point on the far right, Sonnet added a conditional offset:

`javascript const tooltipX = mouseX > svgWidth - 150 ? mouseX - 160 : mouseX + 10; `

This is an exceptionally thoughtful touch that many senior human developers miss on their first pass.

Gemini 1.5 Pro Gemini 1.5 Pro took a different path. It attempted to use standard HTML elements absolutely positioned on top of the SVG. While this approach can work, its React code suffered from state synchronization issues. The tooltip lagged behind the mouse cursor, and resizing the window caused the absolute HTML overlay to drift away from the actual SVG nodes.

If you want to troubleshoot complex component state loops in Gemini, our debug documentation over at /platforms/gemini/articles covers how to manage rendering lifecycles, but in this test, Gemini simply overcomplicated the layout architecture.

The Verdict: Which Engine Rules the SVG Canvas?

If you want a model that can perform solid geometry math, write clean JSX, and think three steps ahead about edge-case UI clipping, Claude 3.5 Sonnet is the undisputed champion.

To find out which LLM really makes your frontend engine tick, you have to look at how they handle raw math under pressure. Sonnet’s spatial intelligence and ability to construct self-contained, responsive mathematical coordinate maps makes it vastly superior for data visualization. Gemini 1.5 Pro is an impressive conversationalist, but Sonnet is the engineer you actually want writing your UI code.

For more advanced implementation guides, head over to our dev hub at /platforms/claude/articles.

claudegeminisvg-chartsfrontend-devcoding

Keep going

Build something with the prompt generator, decode the jargon in the glossary, or compare the tools on our platform deep-dives.