Sub Wiring Calculator

Sub Wiring Calculator: Estimate Your Electrical Wire Costs :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #ccc; –card-background: #fff; –shadow: 0 2px 5px rgba(0,0,0,0.1); } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(–background-color); color: var(–text-color); line-height: 1.6; margin: 0; padding: 0; } .container { max-width: 1000px; margin: 20px auto; padding: 20px; background-color: var(–card-background); border-radius: 8px; box-shadow: var(–shadow); } header { text-align: center; margin-bottom: 30px; padding-bottom: 20px; border-bottom: 1px solid var(–border-color); } h1 { color: var(–primary-color); margin-bottom: 10px; } h2, h3 { color: var(–primary-color); margin-top: 25px; margin-bottom: 15px; } .calculator-section { margin-bottom: 40px; padding: 25px; background-color: var(–card-background); border-radius: 8px; box-shadow: var(–shadow); } .loan-calc-container { display: flex; flex-direction: column; gap: 15px; } .input-group { display: flex; flex-direction: column; gap: 5px; } .input-group label { font-weight: bold; color: var(–primary-color); } .input-group input[type="number"], .input-group input[type="text"], .input-group select { padding: 10px; border: 1px solid var(–border-color); border-radius: 4px; font-size: 1rem; width: 100%; box-sizing: border-box; } .input-group input[type="number"]:focus, .input-group input[type="text"]:focus, .input-group select:focus { outline: none; border-color: var(–primary-color); box-shadow: 0 0 0 2px rgba(0, 74, 153, 0.2); } .input-group .helper-text { font-size: 0.85em; color: #666; } .error-message { color: red; font-size: 0.8em; margin-top: 5px; min-height: 1.2em; /* Prevent layout shifts */ } .button-group { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; } .btn { padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; font-size: 1rem; font-weight: bold; transition: background-color 0.3s ease; text-align: center; flex-grow: 1; } .btn-primary { background-color: var(–primary-color); color: white; } .btn-primary:hover { background-color: #003366; } .btn-secondary { background-color: #6c757d; color: white; } .btn-secondary:hover { background-color: #5a6268; } .btn-success { background-color: var(–success-color); color: white; } .btn-success:hover { background-color: #218838; } #results { margin-top: 30px; padding: 20px; background-color: var(–primary-color); color: white; border-radius: 8px; text-align: center; box-shadow: var(–shadow); } #results h3 { color: white; margin-bottom: 15px; } .main-result { font-size: 2.5em; font-weight: bold; margin-bottom: 15px; color: #fff; /* Ensure it's white */ } .intermediate-values { display: flex; justify-content: space-around; flex-wrap: wrap; gap: 15px; margin-bottom: 20px; font-size: 0.9em; } .intermediate-values div { text-align: center; padding: 10px; background-color: rgba(255, 255, 255, 0.1); border-radius: 5px; flex: 1; min-width: 120px; } .intermediate-values span { display: block; font-weight: bold; font-size: 1.2em; } .formula-explanation { font-size: 0.9em; color: rgba(255, 255, 255, 0.8); margin-top: 15px; } table { width: 100%; border-collapse: collapse; margin-top: 20px; margin-bottom: 30px; box-shadow: var(–shadow); } th, td { padding: 12px; text-align: left; border: 1px solid var(–border-color); } thead { background-color: var(–primary-color); color: white; } tbody tr:nth-child(even) { background-color: #e9ecef; } caption { font-size: 1.1em; font-weight: bold; color: var(–primary-color); margin-bottom: 10px; text-align: left; } canvas { display: block; margin: 20px auto; background-color: var(–card-background); border-radius: 8px; box-shadow: var(–shadow); } .article-content { margin-top: 40px; padding: 25px; background-color: var(–card-background); border-radius: 8px; box-shadow: var(–shadow); } .article-content h2 { border-bottom: 2px solid var(–primary-color); padding-bottom: 5px; } .article-content h3 { color: #0056b3; margin-top: 20px; } .article-content p { margin-bottom: 15px; } .article-content ul, .article-content ol { margin-left: 20px; margin-bottom: 15px; } .article-content li { margin-bottom: 8px; } .faq-item { margin-bottom: 15px; padding: 10px; border-left: 3px solid var(–primary-color); background-color: #f1f1f1; border-radius: 4px; } .faq-item strong { color: var(–primary-color); } .internal-links { margin-top: 30px; padding: 20px; background-color: #e9ecef; border-radius: 8px; } .internal-links h3 { color: var(–primary-color); margin-top: 0; } .internal-links ul { list-style: none; padding: 0; } .internal-links li { margin-bottom: 10px; } .internal-links a { color: var(–primary-color); text-decoration: none; font-weight: bold; } .internal-links a:hover { text-decoration: underline; } .internal-links p { font-size: 0.9em; color: #555; margin-top: 5px; } @media (min-width: 768px) { .button-group { justify-content: flex-end; } .btn { flex-grow: 0; } }

Sub Wiring Calculator

Estimate the cost of electrical wire for your subpanel installation.

Sub Panel Wire Cost Estimator

Enter the total length of wire run in feet.
14 AWG 12 AWG 10 AWG 8 AWG 6 AWG 4 AWG 2 AWG 1/0 AWG 2/0 AWG 3/0 AWG 4/0 AWG
Select the appropriate wire gauge based on amperage and distance.
Estimate the number of individual circuits the sub panel will serve.
NM-B (Non-Metallic Sheathed – Romex) THHN (Thermoplastic High Heat-resistant Nylon-coated)
Choose the type of wire you are using. THHN is typically used in conduit.
Enter the cost per foot for conduit if THHN wire is being run through it. Leave as 0 if not applicable.
Enter the estimated cost per foot for the selected wire gauge and type. This is per conductor.

Estimated Sub Wiring Costs

Total Conductors 0
Total Wire Length (ft) 0.00
Total Conduit Length (ft) 0.00
$0.00
Calculation: (Total Conductors * Total Wire Length * Wire Cost Per Foot) + (Total Conduit Length * Conduit Cost Per Foot)

Cost Breakdown Table

Component Quantity Unit Cost Total Cost
Wire (Conductors) 0 $0.00 $0.00
Conduit 0 $0.00 $0.00
Grand Total $0.00

Cost Distribution Chart

Chart shows the percentage breakdown of wire cost vs. conduit cost.

Sub Wiring Calculator: Estimate Your Electrical Wire Costs

What is Sub Panel Wiring?

Sub panel wiring refers to the electrical connections made between a main electrical service panel and a secondary panel, known as a subpanel. A subpanel is installed to expand electrical capacity, distribute power more efficiently to specific areas of a building, or isolate certain circuits for safety or convenience. This process involves running electrical cables or conduits containing wires from the main panel to the subpanel, and then connecting individual circuits from the subpanel to various loads like outlets, lights, and appliances.

Who should use a sub wiring calculator?

  • Homeowners planning to add a subpanel for an addition, workshop, garage, or to upgrade their electrical system.
  • Electricians and contractors estimating material costs for subpanel installation projects.
  • DIY enthusiasts undertaking electrical projects who need to budget for wiring materials.

Common misconceptions about sub panel wiring:

  • "Any wire will do." Incorrect. Wire gauge, type, and material must be chosen based on the amperage, distance, and local electrical codes to ensure safety and prevent overheating.
  • "Conduit is always required." Not necessarily. NM-B cable (like Romex) can be used for runs within finished walls and ceilings, while THHN wire in conduit is often required for exposed runs, underground, or in certain jurisdictions.
  • "The number of circuits doesn't affect wire cost." While the number of circuits dictates the number of breakers and the subpanel size, the primary wire cost is driven by the main feeder wires to the subpanel and the length of those runs, plus the individual branch circuits. Our calculator focuses on the feeder and estimates based on circuit count.

Sub Wiring Cost Formula and Mathematical Explanation

The core of the sub wiring cost calculation involves determining the total length of wire and conduit needed, and then multiplying by their respective costs per unit. Additional conductors are needed for the subpanel feeder compared to a simple circuit.

Step-by-Step Derivation:

  1. Determine Total Conductors: A standard subpanel feeder requires at least three conductors: one hot (L1), one neutral (N), and one ground (G). If the subpanel is fed from a 240V circuit, it will require two hot conductors (L1 and L2), one neutral (N), and one ground (G), totaling four conductors. For simplicity and common residential setups, we'll assume a 3-wire (L1, N, G) or 4-wire (L1, L2, N, G) feed. The number of individual circuits also adds to the total number of conductors needed for branch circuits, but the primary cost driver for the feeder is the main run. Our calculator simplifies this by calculating the feeder conductors and then adding a factor for branch circuits. For this calculator, we'll assume the feeder requires 3 conductors (L1, N, G) plus the number of circuits for branch wiring.
  2. Calculate Total Wire Length: This is the distance from the main panel to the subpanel multiplied by the number of conductors needed for the feeder. For branch circuits, it's the distance multiplied by the number of circuits. A common simplification is to use the feeder distance for the main run and add a percentage or average length per circuit. For this calculator, we'll use the primary distance for the feeder conductors and a simplified approach for branch circuits.
  3. Calculate Total Conduit Length: If conduit is used, its length will typically match the total wire length for the run.
  4. Calculate Wire Cost: Multiply the total length of wire by the number of conductors and the cost per foot of the wire.
  5. Calculate Conduit Cost: Multiply the total length of conduit by the cost per foot of the conduit.
  6. Sum Costs: Add the total wire cost and the total conduit cost to get the grand total.

Variables Used:

Variable Meaning Unit Typical Range
Distance Length of the wire run from the main panel to the subpanel. Feet (ft) 10 – 200+
Wire Gauge (AWG) Standard measurement of wire thickness. Lower numbers mean thicker wire. AWG 14 – 4/0
Number of Circuits Estimated number of individual circuits the subpanel will serve. Count 2 – 40+
Wire Type Material and insulation type of the electrical wire. Type NM-B, THHN, etc.
Conduit Cost Per Foot Cost of the protective conduit material per linear foot. $/ft 0.50 – 3.00+
Wire Cost Per Foot Cost of the electrical wire per linear foot, per conductor. $/ft 0.20 – 10.00+ (Varies greatly by gauge)
Total Conductors Number of individual wires needed for the feeder and branch circuits. Count 3 – 6+ (Feeder) + Circuits
Total Wire Length Total linear feet of wire required. Feet (ft) Distance * Total Conductors
Total Conduit Length Total linear feet of conduit required. Feet (ft) Distance (if conduit used)

Mathematical Formula:

Total Cost = (Total Conductors * Distance * Wire Cost Per Foot) + (Distance * Conduit Cost Per Foot)

Note: This formula simplifies the calculation by assuming the primary wire run length is the same for all conductors and conduit. It also assumes a standard number of conductors for the feeder (e.g., 3 or 4) plus the number of circuits for branch wiring.

Practical Examples (Real-World Use Cases)

Example 1: Garage Subpanel Installation

Scenario: A homeowner is installing a 100-amp subpanel in their detached garage, located 60 feet from the main house panel. They plan to run 12 circuits and will use THHN wire inside 1-inch PVC conduit.

  • Distance: 60 ft
  • Wire Gauge: 1 AWG (for 100A feeder)
  • Number of Circuits: 12
  • Wire Type: THHN
  • Conduit Cost Per Foot: $1.75
  • Wire Cost Per Foot (1 AWG THHN): $3.50 (per conductor)

Calculations:

  • Total Conductors (Feeder: L1, L2, N, G = 4) + Circuits (12) = 16 conductors. (Simplified calculator might use feeder conductors + circuits for estimation) Let's use the calculator's logic: 3 (base feeder) + 12 circuits = 15 conductors.
  • Total Wire Length = 15 conductors * 60 ft = 900 ft
  • Total Conduit Length = 60 ft (assuming conduit covers the main feeder run)
  • Wire Cost = 900 ft * $3.50/ft = $3150.00
  • Conduit Cost = 60 ft * $1.75/ft = $105.00
  • Estimated Total Cost: $3150.00 + $105.00 = $3255.00

Interpretation: The bulk of the cost comes from the wire itself, especially for a higher amperage feeder like 100A requiring a thicker gauge. Conduit adds a moderate cost.

Example 2: Basement Finishing Subpanel

Scenario: A homeowner is finishing their basement and needs a subpanel for new lighting and outlets. The subpanel will be located 40 feet from the main panel. They estimate needing 8 circuits and will use NM-B cable (Romex) run through finished walls.

  • Distance: 40 ft
  • Wire Gauge: 10 AWG (for 30A feeder, assuming typical basement loads)
  • Number of Circuits: 8
  • Wire Type: NM-B
  • Conduit Cost Per Foot: $0.00 (not applicable)
  • Wire Cost Per Foot (10 AWG NM-B): $1.20 (per conductor)

Calculations:

  • Total Conductors (Feeder: L1, N, G = 3) + Circuits (8) = 11 conductors.
  • Total Wire Length = 11 conductors * 40 ft = 440 ft
  • Total Conduit Length = 0 ft
  • Wire Cost = 440 ft * $1.20/ft = $528.00
  • Conduit Cost = 0 ft * $0.00/ft = $0.00
  • Estimated Total Cost: $528.00 + $0.00 = $528.00

Interpretation: Using NM-B cable and running fewer circuits significantly reduces the material cost compared to the garage example, as conduit is avoided and the wire gauge is smaller.

How to Use This Sub Wiring Calculator

Our Sub Wiring Calculator is designed to provide a quick and easy estimate for the cost of electrical wire and conduit needed for a subpanel installation. Follow these steps:

  1. Enter Distance: Input the approximate length in feet from your main electrical panel to where the subpanel will be located.
  2. Select Wire Gauge: Choose the appropriate wire gauge (AWG) based on the amperage rating of the subpanel feeder and local electrical codes. Consult an electrician if unsure. Common gauges for subpanels range from 6 AWG to 2/0 AWG or larger for higher loads.
  3. Estimate Number of Circuits: Provide an estimate of how many individual circuits (e.g., for lights, outlets, appliances) the subpanel will serve. This helps estimate the total conductors needed.
  4. Choose Wire Type: Select the type of wire you plan to use. NM-B is common for interior runs within framing, while THHN is used inside conduit.
  5. Input Costs: Enter the estimated cost per foot for conduit (if applicable) and the cost per foot for the selected wire gauge and type. These prices can be found at local electrical supply stores or online retailers.
  6. View Results: The calculator will instantly display the estimated total cost, broken down into intermediate values like total conductors, total wire length, and total conduit length.
  7. Review Breakdown: Examine the cost breakdown table for a clearer view of wire vs. conduit expenses.
  8. Analyze Chart: The chart visually represents the proportion of your estimated cost attributed to wire versus conduit.

How to read results: The main result is your estimated total material cost for the wire and conduit. Intermediate values provide insight into the quantities driving that cost. The table and chart offer further detail.

Decision-making guidance: Use these estimates to budget for your project. If the cost seems high, consider if a smaller subpanel or fewer circuits are feasible, or if alternative wiring methods (like NM-B instead of THHN in conduit where permitted) could save money.

Key Factors That Affect Sub Wiring Results

Several factors significantly influence the total cost of sub panel wiring materials:

  1. Wire Gauge (AWG): This is arguably the biggest cost driver. Higher amperage requirements (e.g., 100A, 200A) necessitate thicker wires (lower AWG numbers), which are considerably more expensive per foot.
  2. Distance: The longer the run from the main panel to the subpanel, the more wire and conduit are needed, directly increasing material costs.
  3. Number of Conductors: A standard subpanel feeder requires multiple conductors (hot, neutral, ground). The more circuits the subpanel serves, the more individual branch circuit wires are needed, increasing the total conductor length.
  4. Wire Type and Material: Copper wire is standard and more expensive than aluminum (though aluminum is rarely used for subpanel feeders due to safety concerns and termination issues). Different insulation types (like THHN vs. NM-B) and jacketing also affect price.
  5. Conduit Usage: Running wire inside conduit (like EMT, PVC, or RMC) adds significant cost due to the price of the conduit itself, fittings, and potentially labor if not included in DIY estimates. However, conduit is often required by code for protection and safety.
  6. Local Electrical Codes and Regulations: Codes dictate minimum wire sizes, acceptable wiring methods (e.g., conduit requirements), and grounding/bonding requirements, all of which can impact material choices and costs.
  7. Market Prices and Availability: The cost of copper, aluminum, and plastic fluctuates based on global markets. Availability can also influence pricing.
  8. Installation Complexity: While this calculator focuses on materials, the complexity of the run (e.g., drilling through studs, navigating obstacles, underground burial) affects overall project cost, including labor.

Frequently Asked Questions (FAQ)

Q1: How many conductors do I need for a subpanel feeder?
A1: Typically, you need at least three conductors for a 120/240V subpanel: two hot wires (L1, L2) and one neutral (N). A ground wire (G) is also required, making it a 4-wire feeder. Some older or specific setups might use a 3-wire feeder (L1, L2, G) if the neutral is bonded at the main panel and not needed at the subpanel, but a 4-wire feeder is standard practice for safety and code compliance. Our calculator uses a simplified approach for estimation.
Q2: What is the difference between NM-B and THHN wire for subpanels?
A2: NM-B (Non-Metallic Sheathed Cable, often called Romex) is a cable assembly containing insulated conductors and a ground wire, all within a plastic jacket. It's suitable for dry, protected interior locations within framing. THHN (Thermoplastic High Heat-resistant Nylon-coated) is a type of individual insulated wire conductor. THHN wires are typically pulled through conduit, which provides physical protection and is required for exposed runs, underground, or in wet locations.
Q3: Can I use the same wire gauge for all circuits?
A3: No. The wire gauge for individual branch circuits depends on the amperage of the breaker protecting that circuit and the type of appliance or device it serves. The feeder wires to the subpanel must be sized for the total load the subpanel is expected to handle, which is usually a much larger gauge than individual branch circuits.
Q4: How do I determine the correct wire gauge for my subpanel feeder?
A4: The wire gauge is determined by the amperage rating of the subpanel and the distance of the run. You'll need to consult the National Electrical Code (NEC) or local codes, which provide tables (like NEC Table 310.16) for sizing conductors based on ampacity, temperature rating, and installation conditions. Consulting a qualified electrician is highly recommended.
Q5: Does the calculator include the cost of the subpanel itself or breakers?
A5: No, this calculator specifically estimates the cost of the electrical wire and conduit materials for the run between the main panel and the subpanel. It does not include the cost of the subpanel enclosure, busbars, or individual circuit breakers.
Q6: What if my run is very long? How does that affect cost?
A6: Longer runs significantly increase costs because you need more feet of wire and conduit. Additionally, voltage drop becomes a concern with long runs. The NEC often requires larger gauge wires for long runs to compensate for voltage drop, further increasing material costs.
Q7: Is it cheaper to use aluminum wire instead of copper?
A7: While aluminum wire is generally less expensive than copper wire of the same gauge, it is not typically recommended or permitted for subpanel feeders in residential applications due to safety concerns, expansion/contraction issues, and the need for specialized termination devices. Copper is the standard for safety and reliability in these applications.
Q8: Can I reuse old wire for a subpanel run?
A8: It is strongly advised against reusing old or salvaged wire for a subpanel installation. Electrical codes require new materials to be used for safety and to ensure they meet current standards. Old wire may be degraded, damaged, or not rated for the required amperage or installation method.
var distanceInput = document.getElementById('distance'); var wireGaugeSelect = document.getElementById('wireGauge'); var numCircuitsInput = document.getElementById('numCircuits'); var wireTypeSelect = document.getElementById('wireType'); var conduitCostPerFtInput = document.getElementById('conduitCostPerFt'); var wireCostPerFtInput = document.getElementById('wireCostPerFt'); var distanceError = document.getElementById('distanceError'); var wireGaugeError = document.getElementById('wireGaugeError'); var numCircuitsError = document.getElementById('numCircuitsError'); var wireTypeError = document.getElementById('wireTypeError'); var conduitCostPerFtError = document.getElementById('conduitCostPerFtError'); var wireCostPerFtError = document.getElementById('wireCostPerFtError'); var totalConductorsSpan = document.getElementById('totalConductors'); var totalWireLengthSpan = document.getElementById('totalWireLength'); var totalConduitLengthSpan = document.getElementById('totalConduitLength'); var mainResultSpan = document.getElementById('mainResult'); var tableConductors = document.getElementById('tableConductors'); var tableWireUnitCost = document.getElementById('tableWireUnitCost'); var tableWireTotalCost = document.getElementById('tableWireTotalCost'); var tableConduitQuantity = document.getElementById('tableConduitQuantity'); var tableConduitUnitCost = document.getElementById('tableConduitUnitCost'); var tableConduitTotalCost = document.getElementById('tableConduitTotalCost'); var tableGrandTotal = document.getElementById('tableGrandTotal'); var costChart; var chartContext = document.getElementById('costChart').getContext('2d'); var wireGaugeData = { '14': { costFactor: 0.30, ampacity: 15 }, '12': { costFactor: 0.45, ampacity: 20 }, '10': { costFactor: 0.70, ampacity: 30 }, '8': { costFactor: 1.10, ampacity: 40 }, '6': { costFactor: 1.80, ampacity: 55 }, '4': { costFactor: 2.80, ampacity: 70 }, '2': { costFactor: 4.50, ampacity: 95 }, '1/0': { costFactor: 7.00, ampacity: 115 }, '2/0': { costFactor: 8.50, ampacity: 130 }, '3/0': { costFactor: 10.00, ampacity: 150 }, '4/0': { costFactor: 13.00, ampacity: 175 } }; function validateInput(inputElement, errorElement, minValue, maxValue) { var value = parseFloat(inputElement.value); var isValid = true; errorElement.textContent = "; if (isNaN(value)) { errorElement.textContent = 'Please enter a valid number.'; isValid = false; } else if (inputElement.type === 'number' && inputElement.min !== undefined && value maxValue) { errorElement.textContent = 'Value cannot exceed ' + maxValue + '.'; isValid = false; } return isValid ? value : null; } function calculateSubWiringCosts() { var distance = validateInput(distanceInput, distanceError, 1); var numCircuits = validateInput(numCircuitsInput, numCircuitsError, 1); var conduitCostPerFt = validateInput(conduitCostPerFtInput, conduitCostPerFtError, 0); var wireCostPerFtInputVal = validateInput(wireCostPerFtInput, wireCostPerFtError, 0); var wireGauge = wireGaugeSelect.value; var wireType = wireTypeSelect.value; if (distance === null || numCircuits === null || conduitCostPerFt === null || wireCostPerFtInputVal === null) { resetResults(); return; } // Simplified conductor calculation: 3 for feeder (L1, N, G) + number of circuits // A more robust calculation would consider 4 conductors for 240V feeders and potentially derating factors. var baseFeederConductors = 3; var totalConductors = baseFeederConductors + numCircuits; var totalWireLength = distance * totalConductors; var totalConduitLength = distance; // Assuming conduit runs the same length as the wire run var selectedWireData = wireGaugeData[wireGauge]; var effectiveWireCostPerFt = wireCostPerFtInputVal; // Use user input directly var totalWireCost = totalWireLength * effectiveWireCostPerFt; var totalConduitCost = totalConduitLength * conduitCostPerFt; var grandTotal = totalWireCost + totalConduitCost; totalConductorsSpan.textContent = totalConductors; totalWireLengthSpan.textContent = totalWireLength.toFixed(2); totalConduitLengthSpan.textContent = totalConduitLength.toFixed(2); mainResultSpan.textContent = '$' + grandTotal.toFixed(2); // Update table tableConductors.textContent = totalConductors; tableWireUnitCost.textContent = '$' + effectiveWireCostPerFt.toFixed(2); tableWireTotalCost.textContent = '$' + totalWireCost.toFixed(2); tableConduitQuantity.textContent = totalConduitLength.toFixed(0); tableConduitUnitCost.textContent = '$' + conduitCostPerFt.toFixed(2); tableConduitTotalCost.textContent = '$' + totalConduitCost.toFixed(2); tableGrandTotal.textContent = '$' + grandTotal.toFixed(2); updateChart(totalWireCost, totalConduitCost); } function resetResults() { totalConductorsSpan.textContent = '0'; totalWireLengthSpan.textContent = '0.00'; totalConduitLengthSpan.textContent = '0.00'; mainResultSpan.textContent = '$0.00'; tableConductors.textContent = '0'; tableWireUnitCost.textContent = '$0.00'; tableWireTotalCost.textContent = '$0.00'; tableConduitQuantity.textContent = '0'; tableConduitUnitCost.textContent = '$0.00'; tableConduitTotalCost.textContent = '$0.00'; tableGrandTotal.textContent = '$0.00′; if (costChart) { costChart.destroy(); } } function resetCalculator() { distanceInput.value = 50; wireGaugeSelect.value = '10'; // Default to a common gauge numCircuitsInput.value = 10; wireTypeSelect.value = 'NM-B'; conduitCostPerFtInput.value = 1.50; wireCostPerFtInput.value = 0.80; // Default cost for 10 AWG NM-B // Clear errors distanceError.textContent = "; wireGaugeError.textContent = "; numCircuitsError.textContent = "; wireTypeError.textContent = "; conduitCostPerFtError.textContent = "; wireCostPerFtError.textContent = "; calculateSubWiringCosts(); } function copyResults() { var mainResult = mainResultSpan.textContent; var totalConductors = totalConductorsSpan.textContent; var totalWireLength = totalWireLengthSpan.textContent; var totalConduitLength = totalConduitLengthSpan.textContent; var wireCost = tableWireTotalCost.textContent; var conduitCost = tableConduitTotalCost.textContent; var assumptions = "Key Assumptions:\n" + "Distance: " + distanceInput.value + " ft\n" + "Wire Gauge: " + wireGaugeSelect.value + "\n" + "Number of Circuits: " + numCircuitsInput.value + "\n" + "Wire Type: " + wireTypeSelect.options[wireTypeSelect.selectedIndex].text + "\n" + "Conduit Cost/ft: $" + conduitCostPerFtInput.value + "\n" + "Wire Cost/ft: $" + wireCostPerFtInput.value; var textToCopy = "— Sub Wiring Cost Estimate —\n\n" + "Total Estimated Cost: " + mainResult + "\n\n" + "Breakdown:\n" + "Wire Cost: " + wireCost + "\n" + "Conduit Cost: " + conduitCost + "\n\n" + "Quantities:\n" + "Total Conductors: " + totalConductors + "\n" + "Total Wire Length: " + totalWireLength + " ft\n" + "Total Conduit Length: " + totalConduitLength + " ft\n\n" + assumptions; navigator.clipboard.writeText(textToCopy).then(function() { // Optional: Show a confirmation message var copyButton = document.querySelector('.btn-primary'); var originalText = copyButton.textContent; copyButton.textContent = 'Copied!'; setTimeout(function() { copyButton.textContent = originalText; }, 1500); }).catch(function(err) { console.error('Failed to copy text: ', err); // Fallback for older browsers or if clipboard API fails alert('Failed to copy. Please manually select and copy the text above.'); }); } function updateChart(wireCost, conduitCost) { if (costChart) { costChart.destroy(); } var totalCost = wireCost + conduitCost; var wirePercentage = totalCost > 0 ? (wireCost / totalCost) * 100 : 0; var conduitPercentage = totalCost > 0 ? (conduitCost / totalCost) * 100 : 0; costChart = new Chart(chartContext, { type: 'pie', data: { labels: ['Wire Cost', 'Conduit Cost'], datasets: [{ label: 'Cost Distribution', data: [wireCost, conduitCost], backgroundColor: [ 'rgba(0, 74, 153, 0.7)', // Primary color for wire 'rgba(108, 117, 125, 0.7)' // Secondary color for conduit ], borderColor: [ 'rgba(0, 74, 153, 1)', 'rgba(108, 117, 125, 1)' ], borderWidth: 1 }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'top', }, title: { display: true, text: 'Cost Breakdown: Wire vs. Conduit' } } } }); } // Initial calculation and chart setup document.addEventListener('DOMContentLoaded', function() { resetCalculator(); // Set default values and calculate // Add event listeners to inputs for real-time updates distanceInput.addEventListener('input', calculateSubWiringCosts); wireGaugeSelect.addEventListener('change', calculateSubWiringCosts); numCircuitsInput.addEventListener('input', calculateSubWiringCosts); wireTypeSelect.addEventListener('change', calculateSubWiringCosts); conduitCostPerFtInput.addEventListener('input', calculateSubWiringCosts); wireCostPerFtInput.addEventListener('input', calculateSubWiringCosts); });

Leave a Comment