`).join('');
}
generateInsights(specs) {
const insights = [];
const awgNum = this.parseAWGNumber(specs.awg);
// AWG Category Insight
if (awgNum >= 18) {
insights.push({
type: 'Application Range',
text: 'Fine gauge wire - ideal for low-current electronics, sensors, and signal transmission. Common in medical devices and precision instruments.'
});
} else if (awgNum >= 12) {
insights.push({
type: 'Application Range',
text: 'Medium gauge wire - suitable for general electronics, moderate current applications, and industrial controls.'
});
} else {
insights.push({
type: 'Application Range',
text: 'Heavy gauge wire - designed for high-current power applications, motor connections, and main distribution circuits.'
});
}
// Current Capacity Insight
if (specs.current_a < 1) {
insights.push({
type: 'Current Capacity',
text: 'Low current capacity - perfect for signal transmission and communication applications where power consumption is minimal.'
});
} else if (specs.current_a < 10) {
insights.push({
type: 'Current Capacity',
text: 'Moderate current capacity - suitable for most electronic devices, LED lighting, and control circuits.'
});
} else {
insights.push({
type: 'Current Capacity',
text: 'High current capacity - appropriate for power distribution, motor drives, and high-power equipment connections.'
});
}
// Engineering Recommendation
const nextLargerAWG = awgNum + 2;
const nextSmallerAWG = awgNum - 2;
insights.push({
type: 'Engineering Tip',
text: `For safety margin, consider AWG ${nextLargerAWG} (+33% current capacity) or for cost optimization, AWG ${nextSmallerAWG} might suffice if current allows.`
});
// Medical Device Compliance
if (awgNum >= 18 && awgNum <= 24) {
insights.push({
type: 'Medical Device Note',
text: 'This gauge range is commonly used in medical applications. Ensure biocompatible insulation materials and sterilization compatibility for patient-contact devices.'
});
}
// Frequency Performance
if (specs.frequency_hz > 10000) {
insights.push({
type: 'High-Frequency Performance',
text: 'Excellent for high-frequency applications. Consider skin effect and proximity effect for bundled cables at frequencies above 1 MHz.'
});
}
return insights;
}
populateReferenceTable() {
const tableBody = document.getElementById('reference-table-body');
awgData.forEach(row => {
const tr = document.createElement('tr');
tr.dataset.awg = row.awg;
tr.innerHTML = `
${row.awg} |
${row.diameter_mm.toFixed(3)} |
${row.diameter_in.toFixed(4)} |
${row.area_mm2.toFixed(1)} |
${row.resistance_ohm_km.toFixed(3)} |
${row.current_a} |
`;
tr.addEventListener('click', () => {
this.selectFromTable(row);
});
tableBody.appendChild(tr);
});
}
selectFromTable(rowData) {
// Parse AWG number for calculation
const awgNumber = this.parseAWGNumber(rowData.awg);
this.inputs.awg.value = awgNumber;
this.activeInput = 'awg';
this.calculate();
// Scroll to top of calculator
document.querySelector('.calculator-main').scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
highlightTableRow(awg) {
// Remove previous highlights
document.querySelectorAll('.ref-table tr').forEach(row => {
row.classList.remove('highlighted');
});
// Find and highlight closest AWG
const awgNumber = this.parseAWGNumber(awg);
const closestAWG = this.findClosestAWG(awgNumber);
document.querySelectorAll('.ref-table tr').forEach(row => {
if (row.dataset.awg && row.dataset.awg.includes(closestAWG.toString())) {
row.classList.add('highlighted');
}
});
}
findClosestAWG(targetAWG) {
const standardAWGs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 24, 26, 28, 30];
return standardAWGs.reduce((prev, curr) => {
return (Math.abs(curr - targetAWG) < Math.abs(prev - targetAWG) ? curr : prev);
});
}
parseAWGNumber(awgString) {
// Handle special cases like "0000 (4/0)"
if (typeof awgString === 'string') {
if (awgString.includes('0000') || awgString.includes('4/0')) return -3;
if (awgString.includes('000') || awgString.includes('3/0')) return -2;
if (awgString.includes('00') || awgString.includes('2/0')) return -1;
if (awgString.includes('0') && awgString.includes('1/0')) return 0;
// Extract number from string
const match = awgString.match(/\d+/);
return match ? parseInt(match[0]) : 0;
}
return awgString;
}
formatAWG(awgNumber) {
if (awgNumber <= 0) {
const zeros = Math.abs(awgNumber) + 1;
return '0'.repeat(zeros) + ` (${zeros}/0)`;
}
return Math.round(awgNumber).toString();
}
formatAWGNumber(awgNumber) {
if (awgNumber <= 0) {
return Math.abs(awgNumber) + 1;
}
return Math.round(awgNumber);
}
formatFrequency(freq) {
if (freq >= 1000000) {
return (freq / 1000000).toFixed(1) + 'M';
} else if (freq >= 1000) {
return (freq / 1000).toFixed(1) + 'k';
} else {
return Math.round(freq).toString();
}
}
getCurrentAWG() {
const awgInput = this.inputs.awg.value;
return awgInput ? parseFloat(awgInput) : 0;
}
clearResults() {
Object.values(this.results).forEach(element => {
if (element.id === 'result-current') {
element.textContent = '-- A';
} else {
element.innerHTML = '--
' +
element.innerHTML.match(/(.*?)<\/span>/)?.[1] || '' +
'';
}
});
}
animateUpdate() {
document.querySelectorAll('.result-card').forEach(card => {
card.classList.add('updated');
setTimeout(() => {
card.classList.remove('updated');
}, 500);
});
}
}
// Utility Functions
function clearAllInputs() {
document.querySelectorAll('.input-field').forEach(input => {
input.value = '';
});
document.querySelectorAll('.result-card').forEach(card => {
card.classList.add('calculating');
});
setTimeout(() => {
document.querySelectorAll('.result-card').forEach(card => {
card.classList.remove('calculating');
});
calculator.clearResults();
// Reset insights
document.getElementById('insights-content').innerHTML = `
Getting Started
Enter any known wire specification in the input fields above. All equivalent values will be calculated automatically using industry-standard engineering formulas.
Engineering Note
AWG sizing is logarithmic - each 3 AWG increase doubles the cross-sectional area. Each 6 AWG increase doubles the diameter.
Pro Tip
Current capacity shown is for free air conditions. Derate by 80% for bundled cables or enclosed installations per NEC guidelines.
`;
// Remove table highlights
document.querySelectorAll('.ref-table tr').forEach(row => {
row.classList.remove('highlighted');
});
}, 800);
}
// Initialize calculator
const calculator = new AWGCalculator();
// Sample data population for demonstration
function loadSampleData() {
const examples = [
{ field: 'awg', value: '14', label: 'AWG 14 (Common household)' },
{ field: 'diameterMm', value: '1.628', label: '1.628mm diameter' },
{ field: 'currentCapacity', value: '15', label: '15A requirement' }
];
// Add sample buttons for user guidance
const sampleButtons = document.createElement('div');
sampleButtons.style.cssText = `
display: flex;
gap: 0.5rem;
margin-top: 1rem;
flex-wrap: wrap;
`;
examples.forEach(example => {
const btn = document.createElement('button');
btn.textContent = `Try: ${example.label}`;
btn.style.cssText = `
background: var(--light-blue-tint);
border: 1px solid var(--technical-blue);
color: var(--technical-blue);
padding: 0.5rem 0.75rem;
border-radius: 0.375rem;
cursor: pointer;
font-size: 0.75rem;
transition: all 0.2s ease-in-out;
`;
btn.addEventListener('click', () => {
calculator.inputs[example.field].value = example.value;
calculator.activeInput = example.field;
calculator.calculate();
});
btn.addEventListener('mouseenter', () => {
btn.style.background = 'var(--technical-blue)';
btn.style.color = 'white';
});
btn.addEventListener('mouseleave', () => {
btn.style.background = 'var(--light-blue-tint)';
btn.style.color = 'var(--technical-blue)';
});
sampleButtons.appendChild(btn);
});
document.querySelector('.clear-btn').parentNode.appendChild(sampleButtons);
}
// Initialize sample data
loadSampleData();
// Add copy functionality for results
document.querySelectorAll('.result-card').forEach(card => {
card.addEventListener('click', () => {
const value = card.querySelector('.result-value').textContent;
navigator.clipboard.writeText(value).then(() => {
// Show feedback
const originalBg = card.style.background;
card.style.background = 'rgba(40, 167, 69, 0.1)';
card.style.borderLeftColor = 'var(--success-green)';
setTimeout(() => {
card.style.background = originalBg;
card.style.borderLeftColor = 'var(--technical-blue)';
}, 1000);
});
});
card.style.cursor = 'pointer';
card.title = 'Click to copy value';
});
console.log('Professional AWG Calculator initialized successfully');