Tire Rim Size Calculator

Tire Rim Size Calculator: Calculate Your Tire Fitment :root { –primary-color: #004a99; –secondary-color: #007bff; –success-color: #28a745; –danger-color: #dc3545; –light-gray: #f8f9fa; –dark-gray: #343a40; –white: #ffffff; –border-color: #dee2e6; } body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; line-height: 1.6; color: var(–dark-gray); background-color: var(–light-gray); margin: 0; padding: 0; } .container { max-width: 1200px; margin: 20px auto; padding: 20px; background-color: var(–white); border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); display: grid; grid-template-columns: 1fr; gap: 30px; } @media (min-width: 992px) { .container { grid-template-columns: 1fr 1fr; } } header { background-color: var(–primary-color); color: var(–white); padding: 20px; text-align: center; border-radius: 8px 8px 0 0; margin: -20px -20px 20px -20px; } h1 { margin: 0; font-size: 2.5em; } .subtitle { font-size: 1.1em; opacity: 0.9; } .loan-calc-container, .article-content { background-color: var(–white); padding: 30px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05); } .input-group { margin-bottom: 20px; position: relative; } .input-group label { display: block; margin-bottom: 8px; font-weight: bold; color: var(–primary-color); } .input-group input, .input-group select { width: calc(100% – 22px); padding: 10px; border: 1px solid var(–border-color); border-radius: 4px; font-size: 1em; box-sizing: border-box; } .input-group input:focus, .input-group select:focus { outline: none; border-color: var(–secondary-color); box-shadow: 0 0 0 0.2rem rgba(0, 74, 153, 0.25); } .input-group .helper-text { font-size: 0.85em; color: #6c757d; margin-top: 5px; display: block; } .error-message { color: var(–danger-color); font-size: 0.8em; margin-top: 5px; display: block; height: 1.2em; /* Reserve space for error message */ } .results-container { background-color: var(–primary-color); color: var(–white); padding: 30px; border-radius: 8px; margin-top: 20px; text-align: center; box-shadow: 0 4px 12px rgba(0, 74, 153, 0.3); } .results-container h3 { margin-top: 0; color: var(–white); font-size: 1.8em; } .primary-result { font-size: 2.5em; font-weight: bold; margin: 10px 0; display: inline-block; padding: 10px 20px; background-color: var(–success-color); border-radius: 5px; box-shadow: 0 2px 6px rgba(40, 167, 69, 0.4); } .intermediate-results div { margin-bottom: 15px; font-size: 1.2em; opacity: 0.95; } .intermediate-results span { font-weight: bold; color: var(–white); } .formula-explanation { font-size: 0.9em; margin-top: 20px; opacity: 0.85; } .button-group { display: flex; justify-content: space-around; margin-top: 25px; gap: 15px; } .button-group button, .button-group input[type="button"] { padding: 12px 25px; border: none; border-radius: 5px; font-size: 1.1em; font-weight: bold; cursor: pointer; transition: background-color 0.3s ease, transform 0.2s ease; flex-grow: 1; } .btn-calculate { background-color: var(–secondary-color); color: var(–white); } .btn-calculate:hover { background-color: #0056b3; transform: translateY(-2px); } .btn-reset { background-color: #6c757d; color: var(–white); } .btn-reset:hover { background-color: #5a6268; transform: translateY(-2px); } .btn-copy { background-color: var(–primary-color); color: var(–white); } .btn-copy:hover { background-color: #003d73; transform: translateY(-2px); } table { width: 100%; border-collapse: collapse; margin-top: 30px; } th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid var(–border-color); } th { background-color: var(–primary-color); color: var(–white); font-weight: bold; } tr:nth-child(even) { background-color: var(–light-gray); } caption { font-size: 1.2em; font-weight: bold; margin-bottom: 15px; color: var(–primary-color); caption-side: top; text-align: left; } canvas { margin-top: 30px; border: 1px solid var(–border-color); border-radius: 4px; background-color: var(–white); } .article-content h2, .article-content h3 { color: var(–primary-color); margin-top: 30px; margin-bottom: 15px; } .article-content h2 { border-bottom: 2px solid var(–secondary-color); padding-bottom: 8px; } .article-content p { margin-bottom: 15px; } .article-content ul, .article-content ol { margin-bottom: 15px; padding-left: 20px; } .article-content li { margin-bottom: 8px; } .variable-table { margin-top: 20px; width: 100%; border-collapse: collapse; } .variable-table th, .variable-table td { border: 1px solid var(–border-color); padding: 10px; text-align: left; } .variable-table th { background-color: var(–secondary-color); color: var(–white); } .variable-table tr:nth-child(even) { background-color: var(–light-gray); } .faq-list { margin-top: 20px; } .faq-list h3 { margin-top: 20px; margin-bottom: 10px; color: var(–dark-gray); } .faq-list p { margin-bottom: 10px; font-style: italic; color: #555; } .related-links ul { list-style: none; padding: 0; } .related-links li { margin-bottom: 15px; padding: 10px; background-color: var(–light-gray); border-left: 4px solid var(–primary-color); border-radius: 4px; } .related-links a { color: var(–primary-color); text-decoration: none; font-weight: bold; } .related-links a:hover { text-decoration: underline; } .related-links span { display: block; font-size: 0.9em; color: #6c757d; margin-top: 5px; } .calc-output-item { margin-bottom: 10px; font-size: 1.1em; } .calc-output-label { font-weight: bold; color: var(–primary-color); } .calc-output-value { font-weight: bold; color: var(–dark-gray); } .chart-container { text-align: center; margin-top: 30px; background-color: var(–white); padding: 20px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05); } .chart-caption { font-size: 1.1em; margin-bottom: 15px; color: var(–primary-color); font-weight: bold; }

Tire Rim Size Calculator

Ensure Perfect Tire Fitment and Performance

Calculate Your Tire Rim Size

Measure from the ground up to the top of your current tire.
The diameter of the wheel you want to install.
The desired overall diameter of your new tire setup.

Your Tire Fitment Results

Required Tire Section Width (approx.): inches
Required Tire Aspect Ratio (approx.): %
Diameter Difference: inches
Formula Used:
Tire Section Width (W) ≈ Rim Width (RW) * Aspect Ratio (AR/100) * 2
Aspect Ratio (AR) = (Target Diameter – Rim Diameter) / 2 / (Target Diameter – Rim Diameter) * 100
Diameter Difference = Target Tire Diameter – Current Tire Diameter

What is a Tire Rim Size Calculator?

A tire rim size calculator is a sophisticated online tool designed to help vehicle owners, enthusiasts, and mechanics determine the correct tire dimensions that will fit a specific wheel rim and achieve a desired overall tire diameter. It bridges the gap between your vehicle's current tire setup and your intended modifications, ensuring compatibility, performance, and safety. This tire rim size calculator is crucial for anyone looking to upgrade or replace their wheels and tires, preventing common issues like speedometer inaccuracies, rubbing, or poor handling.

Who should use it:

  • Vehicle owners planning to install larger or smaller rims.
  • Enthusiasts seeking to alter their vehicle's stance or performance.
  • Anyone replacing worn tires and considering different sizes.
  • Mechanics and tire shops verifying fitment specifications.

Common misconceptions:

  • Myth: Any tire will fit any rim if the bolt pattern matches. Reality: Rim diameter and width are critical for tire bead seating and structural integrity.
  • Myth: Larger rims always mean a rougher ride. Reality: Tire sidewall height and profile play a significant role; a balance is key.
  • Myth: Changing tire size won't affect speedometer readings. Reality: The tire rim size calculator highlights how diameter changes impact readings.

Tire Rim Size Calculator Formula and Mathematical Explanation

The core of the tire rim size calculator relies on understanding the relationship between tire diameter, rim diameter, tire width, and aspect ratio. The primary goal is to find a tire that, when mounted on a new rim, results in an overall diameter close to the original or a specified target, while maintaining safe bead sealing.

The calculator uses these key relationships:

  1. Overall Tire Diameter (D): This is the total height of the tire from the road surface to the top of the tire. It's calculated using the rim diameter (R), tire section width (W), and aspect ratio (AR):
    D = R + 2 * (W * AR / 100)
    Where AR is the aspect ratio percentage (e.g., 50 for a 50% sidewall height relative to width).
  2. Tire Section Width (W): This is the widest point of the tire's sidewall when inflated on the specified rim.
  3. Aspect Ratio (AR): This is the ratio of the tire's sidewall height to its section width, expressed as a percentage.
  4. Rim Diameter (R): The diameter of the wheel rim itself.

Given the current tire diameter and the new rim diameter, the tire rim size calculator works backward or forward to suggest compatible tire sizes. To find the required tire profile (aspect ratio and section width) for a target diameter on a new rim, we can rearrange:

First, calculate the required total sidewall height (SH):

SH = (Target Tire Diameter - New Rim Diameter) / 2

Then, to find the aspect ratio, we need an estimated tire width. A common heuristic relates rim width to tire width. For simplicity in this calculator, we estimate the necessary aspect ratio directly based on the diameters and then imply the required tire width.

A simplified approach focuses on achieving the target diameter:

1. Calculate Diameter Difference:

Diameter Difference = Target Tire Diameter - Current Tire Diameter

This shows how much the overall diameter will change.

2. Estimate Required Sidewall Height for Target Diameter:

Required Sidewall Height = (Target Tire Diameter - New Rim Diameter) / 2

3. Estimate Required Aspect Ratio:

This requires assuming a tire section width. A common reference point is that the required tire section width (W) is often around 1.5 to 2 times the rim diameter (R). Let's assume a relationship where W is proportional to R for estimation purposes, or more accurately, derived from common tire sizes. A simpler approximation within the calculator's scope is to focus on achieving the target diameter.

The calculator calculates:

  • Diameter Difference: The net change in overall tire diameter.
  • Required Tire Section Width (approx.): Based on common ratios to rim diameter and desired aspect ratio range. A typical calculation might estimate a range, e.g., 1.8 * Rim Diameter.
  • Required Tire Aspect Ratio (approx.): This is derived to make the overall diameter match the target. If SH is the required sidewall height and W is the estimated section width, then AR ≈ (SH / W) * 100. The calculator implies this by finding a tire size that fits the target diameter.

Variables Table:

Variable Name Meaning Unit Typical Range
Current Tire Overall Diameter The height of the existing tire from the ground to its top. Inches 15 – 35 inches
New Rim Diameter The diameter of the wheel rim itself. Inches 13 – 26 inches
Target Tire Overall Diameter The desired final height of the tire. Inches 15 – 35 inches
Tire Section Width (W) The widest point of the tire's sidewall. Inches 6 – 15 inches
Aspect Ratio (AR) Sidewall height as a percentage of section width. % 30% – 80%
Diameter Difference Change in overall tire diameter compared to stock. Inches -3 to +3 inches (common)

Practical Examples (Real-World Use Cases)

Understanding the tire rim size calculator is best done through examples. These scenarios illustrate how the tool aids in making informed decisions about tire fitment.

Example 1: Upgrading to Larger Rims

Scenario: A car owner wants to replace their 16-inch rims with 18-inch rims. Their current tires have an overall diameter of 26 inches. They want to maintain a similar overall diameter to avoid significant speedometer error and ensure clearance.

Inputs:

  • Current Tire Overall Diameter: 26.0 inches
  • New Rim Diameter: 18 inches
  • Target Tire Overall Diameter: 26.0 inches (maintaining stock height)

Calculation:

The tire rim size calculator computes:

  • Diameter Difference: 0.0 inches
  • Required Tire Section Width (approx.): ~8.5 inches
  • Required Tire Aspect Ratio (approx.): ~38.9%

Primary Result: The calculator might suggest a tire size like 245/40R18 or 255/35R18, as these have overall diameters very close to 26 inches. The calculation shows that to keep the overall diameter at 26 inches with an 18-inch rim, a shorter, wider tire with a lower aspect ratio is needed compared to the stock setup (which likely had a larger aspect ratio on the 16-inch rim).

Interpretation: This confirms that a direct swap to a tire matching the new rim diameter might not yield the same ride height. The tool helps identify the correct tire profile (section width and aspect ratio) needed to achieve the desired overall diameter. This tire rim size calculator prevents the common mistake of simply buying the widest tire that fits the rim without considering the overall diameter goal.

Example 2: Increasing Tire Diameter for Off-Roading

Scenario: A truck owner is upgrading to larger off-road tires. They are keeping their current 15-inch rims but want to increase the overall tire diameter from 30 inches to 33 inches for better ground clearance and off-road capability.

Inputs:

  • Current Tire Overall Diameter: 30.0 inches
  • New Rim Diameter: 15 inches
  • Target Tire Overall Diameter: 33.0 inches

Calculation:

The tire rim size calculator calculates:

  • Diameter Difference: +3.0 inches
  • Required Tire Section Width (approx.): ~10.5 inches
  • Required Tire Aspect Ratio (approx.): ~76.7%

Primary Result: The calculator indicates a significant increase in overall diameter. It might suggest a tire size like 265/75R15 or 31×10.50R15 (which has a diameter around 31 inches, but 33s are also common). The output emphasizes the need for a much taller sidewall (higher aspect ratio) to achieve the larger overall diameter on the same 15-inch rim. The tire rim size calculator highlights the substantial increase required.

Interpretation: This result informs the user that a 33-inch tire will be considerably taller than their current 30-inch tires. The calculation helps determine the necessary tire profile. It also implies potential issues: the larger diameter might cause rubbing against fenders or suspension components, requiring potential modifications like a lift kit. This tool is vital for planning such modifications accurately.

How to Use This Tire Rim Size Calculator

Using the tire rim size calculator is straightforward. Follow these steps to get accurate tire fitment information:

  1. Measure Current Tire Diameter: If you don't know your current tire's overall diameter, measure it from the ground to the highest point of the tire. Alternatively, find the stock tire size (e.g., P215/65R15) and use an online tire size calculator or consult your vehicle's manual.
  2. Input Rim Diameter: Enter the diameter of the wheel rim you intend to install. This is usually stamped on the rim itself or found in the wheel specifications.
  3. Input Target Tire Diameter: Enter your desired overall tire diameter. This could be the same as your current diameter to maintain stock settings, or a different value if you're aiming for a specific look or performance characteristic (like larger tires for off-roading).
  4. Calculate: Click the "Calculate Fit" button.

How to interpret results:

  • Primary Result (e.g., "Ideal Tire Size"): This is the suggested tire size or a key metric like the required aspect ratio or width that achieves your target diameter.
  • Intermediate Values: These provide crucial details:
    • Required Tire Section Width (approx.): Gives you an idea of the tire's width needed.
    • Required Tire Aspect Ratio (approx.): Indicates the sidewall height relative to the width.
    • Diameter Difference: Shows the change from your current tire diameter. A positive number means a larger tire, negative means smaller. Small differences (under 1-2%) are generally best for speedometer accuracy.
  • Formula Explanation: Understand the math behind the results.

Decision-making guidance:

  • Speedometer Accuracy: Aim for a Diameter Difference close to 0%. Significant changes will alter your speedometer and odometer readings. A general rule of thumb is to keep the change within +/- 3%.
  • Clearance: Larger diameter tires might rub against fenders, suspension components, or brake lines. Always check for clearance before finalizing your purchase. This tire rim size calculator provides diameter estimates, but physical fitment must be verified.
  • Gearing: Larger tires effectively change your vehicle's gear ratio, potentially impacting acceleration and fuel economy. Consider using a gear ratio calculator if making substantial diameter changes.
  • Load Rating & Speed Rating: Ensure the suggested tires meet or exceed your vehicle manufacturer's recommendations for safety and performance.

Key Factors That Affect Tire Rim Size Results

While the tire rim size calculator provides valuable estimates, several real-world factors influence the final fitment and performance:

  1. Tire Manufacturer Variations: Tire dimensions can vary slightly between brands and models, even if they share the same size designation (e.g., 215/65R15). Always check manufacturer specifications.
  2. Rim Width: The calculator often assumes a typical rim width or calculates based on diameter. However, the actual width of the rim you choose significantly affects the tire's bulge and bead seating. A rim that is too narrow or too wide for a tire can be unsafe.
  3. Vehicle Suspension: Stock suspension geometry, aftermarket lift kits, or lowering kits dramatically impact tire clearance. A tire rim size calculator result might fit on one vehicle but rub on another due to suspension differences.
  4. Tire Pressure: Tire pressure affects the tire's overall diameter and stiffness. Maintain recommended pressures for optimal performance and accurate calculator results.
  5. Load Index: The weight capacity of the tire (load index) is critical for safety. Ensure your chosen tires can support your vehicle's weight, especially when considering larger, heavier off-road tires.
  6. Intended Use: Are you seeking comfort, fuel efficiency, off-road capability, or track performance? The optimal tire size balance depends on your primary driving needs. A tire rim size calculator helps achieve dimensional goals, but the tire's compound and tread pattern are equally important.
  7. Brake Clearance: Larger rims may be necessary to clear larger brake calipers, especially on performance vehicles. The tire rim size calculator focuses on diameter but doesn't account for caliper interference.
  8. Rubbing and Fender Clearance: Tire width and offset play a crucial role in whether a tire rubs against the fender liner or body panels, particularly during turns or suspension travel. This requires careful consideration beyond just diameter.

Frequently Asked Questions (FAQ)

Q1: Will changing my tire size affect my car's MPG?

Yes. Larger, heavier tires generally decrease fuel economy due to increased rolling resistance and rotational mass. Conversely, smaller, lighter tires might improve MPG slightly. The change in diameter also affects perceived gearing, potentially impacting fuel consumption.

Q2: How much can I change my tire diameter before my speedometer is inaccurate?

Generally, keeping the overall tire diameter change within +/- 3% of the original equipment (OE) size is recommended to maintain reasonable speedometer and odometer accuracy. The tire rim size calculator helps quantify this difference.

Q3: Can I mix tire sizes on my vehicle?

For most vehicles, especially those with All-Wheel Drive (AWD) or Four-Wheel Drive (4WD), it is strongly recommended to use tires of the same size (diameter, width, aspect ratio) on all four wheels. Mixing sizes can damage the drivetrain and affect handling. Always consult your owner's manual.

Q4: What is the difference between tire width and rim width?

Tire section width is the maximum width of the tire itself. Rim width is the distance between the inside edges of the rim flanges, where the tire bead seats. These two measurements must be compatible; a tire manufacturer specifies a range of acceptable rim widths for each tire size.

Q5: Does a lower aspect ratio tire provide a harsher ride?

Typically, yes. A lower aspect ratio means a shorter, stiffer sidewall, which transmits more road imperfections to the cabin, resulting in a harsher ride. A higher aspect ratio means a taller, more flexible sidewall, offering a more comfortable ride.

Q6: What does "P215/65R15" mean on my tire?

This is a P-metric tire size code: 'P' for Passenger car, '215' for the section width in millimeters, '65' for the aspect ratio (65% of width), 'R' for Radial construction, and '15' for the rim diameter in inches. Our tire rim size calculator uses these principles.

Q7: Can I fit larger tires without a lift kit?

It depends on the vehicle and the size increase. Minor increases might fit without rubbing, especially if combined with appropriate wheel offsets. However, significant increases in tire diameter or width often require suspension modifications like a lift kit or fender modifications to prevent rubbing.

Q8: What happens if my new tire is wider than recommended for the rim?

Mounting a tire on a rim narrower than recommended can cause the tire bead to not seat properly, leading to air leaks or even catastrophic failure. It can also negatively affect handling as the tire sidewalls will be overly stressed.

© 2023 Your Company Name. All rights reserved.

function calculateTireFit() { var currentTireDiameterInput = document.getElementById("currentTireDiameter"); var newRimDiameterInput = document.getElementById("newRimDiameter"); var targetTireDiameterInput = document.getElementById("targetTireDiameter"); var currentTireDiameterError = document.getElementById("currentTireDiameterError"); var newRimDiameterError = document.getElementById("newRimDiameterError"); var targetTireDiameterError = document.getElementById("targetTireDiameterError"); var requiredTireWidthSpan = document.getElementById("requiredTireWidth"); var requiredAspectRatioSpan = document.getElementById("requiredAspectRatio"); var diameterDifferenceSpan = document.getElementById("diameterDifference"); var primaryResultSpan = document.getElementById("primaryResult"); var resultsContainer = document.getElementById("resultsContainer"); // Clear previous errors and results currentTireDiameterError.textContent = ""; newRimDiameterError.textContent = ""; targetTireDiameterError.textContent = ""; primaryResultSpan.textContent = "–"; resultsContainer.style.display = 'none'; // Get input values and validate var currentTireDiameter = parseFloat(currentTireDiameterInput.value); var newRimDiameter = parseFloat(newRimDiameterInput.value); var targetTireDiameter = parseFloat(targetTireDiameterInput.value); var isValid = true; if (isNaN(currentTireDiameter) || currentTireDiameter <= 0) { currentTireDiameterError.textContent = "Please enter a valid positive number for current tire diameter."; isValid = false; } if (isNaN(newRimDiameter) || newRimDiameter <= 0) { newRimDiameterError.textContent = "Please enter a valid positive number for new rim diameter."; isValid = false; } if (isNaN(targetTireDiameter) || targetTireDiameter = targetTireDiameter) { targetTireDiameterError.textContent = "Target tire diameter must be larger than rim diameter."; isValid = false; } if (isValid && currentTireDiameter 0) { requiredAspectRatio = (requiredSidewallHeight / estimatedTireWidth) * 100; } // Clamp aspect ratio to a reasonable range (e.g., 30% to 80%) for better suggestions requiredAspectRatio = Math.max(30, Math.min(80, requiredAspectRatio)); // Display results diameterDifferenceSpan.textContent = diameterDifference.toFixed(1); requiredTireWidthSpan.textContent = estimatedTireWidth.toFixed(1); requiredAspectRatioSpan.textContent = requiredAspectRatio.toFixed(1); // Primary result: Focus on achieving the target diameter. // A common way to express this is the target diameter itself and the key parameters. primaryResultSpan.textContent = `Target Diameter: ${targetTireDiameter.toFixed(1)} inches`; resultsContainer.style.display = 'block'; // Call chart update function updateChart(currentTireDiameter, targetTireDiameter, newRimDiameter); } function resetCalculator() { document.getElementById("currentTireDiameter").value = ""; document.getElementById("newRimDiameter").value = ""; document.getElementById("targetTireDiameter").value = ""; document.getElementById("currentTireDiameterError").textContent = ""; document.getElementById("newRimDiameterError").textContent = ""; document.getElementById("targetTireDiameterError").textContent = ""; document.getElementById("requiredTireWidth").textContent = "–"; document.getElementById("requiredAspectRatio").textContent = "–"; document.getElementById("diameterDifference").textContent = "–"; document.getElementById("primaryResult").textContent = "–"; document.getElementById("resultsContainer").style.display = 'none'; // Clear chart var ctx = document.getElementById("tireFitChart").getContext("2d"); ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); // Optionally redraw with default state or just leave blank } function copyResults() { var currentTireDiameter = document.getElementById("currentTireDiameter").value; var newRimDiameter = document.getElementById("newRimDiameter").value; var targetTireDiameter = document.getElementById("targetTireDiameter").value; var diameterDifference = document.getElementById("diameterDifference").textContent; var requiredTireWidth = document.getElementById("requiredTireWidth").textContent; var requiredAspectRatio = document.getElementById("requiredAspectRatio").textContent; var primaryResult = document.getElementById("primaryResult").textContent; var summary = "Tire Rim Size Calculator Results:\n"; summary += "———————————-\n"; summary += "Current Tire Diameter: " + currentTireDiameter + " inches\n"; summary += "New Rim Diameter: " + newRimDiameter + " inches\n"; summary += "Target Tire Diameter: " + targetTireDiameter + " inches\n"; summary += "———————————-\n"; summary += "Diameter Difference: " + diameterDifference + " inches\n"; summary += "Required Tire Width (approx.): " + requiredTireWidth + " inches\n"; summary += "Required Tire Aspect Ratio (approx.): " + requiredAspectRatio + " %\n"; summary += "———————————-\n"; summary += "Main Result: " + primaryResult + "\n"; // Use navigator.clipboard for modern browsers, fallback for older ones if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(summary).then(function() { alert("Results copied to clipboard!"); }).catch(function(err) { console.error("Could not copy text: ", err); fallbackCopyTextToClipboard(summary); }); } else { fallbackCopyTextToClipboard(summary); } } function fallbackCopyTextToClipboard(text) { var textArea = document.createElement("textarea"); textArea.value = text; textArea.style.position = "fixed"; // Avoid scrolling to bottom textArea.style.left = "-9999px"; textArea.style.top = "-9999px"; document.body.appendChild(textArea); textArea.focus(); textArea.select(); try { var successful = document.execCommand('copy'); var msg = successful ? 'successful' : 'unsuccessful'; alert('Results ' + msg + ' copied to clipboard!'); } catch (err) { alert('Oops, unable to copy'); } document.body.removeChild(textArea); } // Chart Functionality (using pure Canvas) function updateChart(currentDiameter, targetDiameter, rimDiameter) { var canvas = document.getElementById('tireFitChart'); var ctx = canvas.getContext('2d'); ctx.clearRect(0, 0, canvas.width, canvas.height); // Clear previous drawing var chartHeight = canvas.height; var chartWidth = canvas.width; var padding = 40; // Padding around the chart // Data var currentTireData = { label: "Current Tire Diameter", value: currentDiameter, color: "rgba(0, 74, 153, 0.7)" // Primary color }; var targetTireData = { label: "Target Tire Diameter", value: targetDiameter, color: "rgba(40, 167, 69, 0.7)" // Success color }; var rimDiameterData = { label: "Rim Diameter", value: rimDiameter, color: "rgba(255, 193, 7, 0.7)" // Warning color }; var dataPoints = [rimDiameterData, currentTireData, targetTireData].sort(function(a, b) { return a.value – b.value; }); // Find max value for scaling var maxValue = Math.max(currentDiameter, targetDiameter, rimDiameter); maxValue = maxValue * 1.1; // Add 10% buffer // Draw Y-axis label ctx.fillStyle = "var(–dark-gray)"; ctx.font = "14px Arial"; ctx.textAlign = "center"; ctx.fillText("Diameter (inches)", padding / 2, chartHeight / 2 – 20); // Draw X-axis line ctx.beginPath(); ctx.moveTo(padding, chartHeight – padding); ctx.lineTo(chartWidth – padding, chartHeight – padding); ctx.strokeStyle = "#ccc"; ctx.stroke(); // Draw Y-axis line (representing zero or minimum diameter) ctx.beginPath(); ctx.moveTo(padding, padding); ctx.lineTo(padding, chartHeight – padding); ctx.strokeStyle = "#ccc"; ctx.stroke(); // Draw data points and labels var dataPointsToDraw = [rimDiameterData, currentTireData, targetTireData]; // Preserve original order for clarity var barWidth = (chartWidth – 2 * padding) / dataPointsToDraw.length * 0.7; // Make bars narrower than full available space var gapBetweenBars = (chartWidth – 2 * padding – barWidth * dataPointsToDraw.length) / (dataPointsToDraw.length + 1); dataPointsToDraw.forEach(function(point, index) { var barHeight = (point.value / maxValue) * (chartHeight – 2 * padding); var xPos = padding + gapBetweenBars + index * (barWidth + gapBetweenBars); var yPos = chartHeight – padding – barHeight; // Draw bar ctx.fillStyle = point.color; ctx.fillRect(xPos, yPos, barWidth, barHeight); // Draw value label above the bar ctx.fillStyle = "var(–dark-gray)"; ctx.font = "12px Arial"; ctx.textAlign = "center"; ctx.fillText(point.value.toFixed(1), xPos + barWidth / 2, yPos – 10); // Draw label below the bar ctx.fillStyle = "var(–primary-color)"; ctx.font = "13px Arial"; ctx.fillText(point.label, xPos + barWidth / 2, chartHeight – padding + 20); }); // Draw max value line on Y axis ctx.fillStyle = "#6c757d"; ctx.font = "12px Arial"; ctx.textAlign = "right"; ctx.fillText(maxValue.toFixed(1), padding – 10, padding); ctx.beginPath(); ctx.moveTo(padding – 5, padding); ctx.lineTo(padding, padding); ctx.strokeStyle = "#ccc"; ctx.stroke(); } // Initial chart draw on load (optional, can be done after first calculation) document.addEventListener("DOMContentLoaded", function() { var canvas = document.getElementById('tireFitChart'); // Ensure canvas exists before trying to get context if (canvas) { var ctx = canvas.getContext('2d'); ctx.canvas.width = canvas.parentElement.offsetWidth – 40; // Adjust width based on container padding ctx.canvas.height = 300; // Set a fixed height updateChart(26, 26, 15); // Draw initial state or placeholder } });

Leave a Comment