Brambleberry Weight of Oils Lye Calculator

Brambleberry Weight of Oils Lye Calculator :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #ddd; –card-background: #ffffff; –shadow: 0 2px 5px rgba(0,0,0,0.1); } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6; color: var(–text-color); background-color: var(–background-color); 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 { background-color: var(–primary-color); color: white; padding: 20px; text-align: center; border-radius: 8px 8px 0 0; margin-bottom: 20px; } header h1 { margin: 0; font-size: 2em; } .calculator-section { margin-bottom: 30px; padding: 20px; border: 1px solid var(–border-color); border-radius: 8px; background-color: var(–card-background); } .calculator-section h2 { color: var(–primary-color); text-align: center; margin-top: 0; } .input-group { margin-bottom: 20px; text-align: left; } .input-group label { display: block; margin-bottom: 8px; font-weight: bold; color: var(–primary-color); } .input-group input[type="number"], .input-group select { width: calc(100% – 20px); padding: 10px; border: 1px solid var(–border-color); border-radius: 4px; font-size: 1em; box-sizing: border-box; /* Include padding and border in the element's total width and height */ } .input-group .helper-text { font-size: 0.8em; color: #666; display: block; margin-top: 5px; } .error-message { color: #dc3545; font-size: 0.8em; margin-top: 5px; display: none; /* Hidden by default */ } .error-message.visible { display: block; } .button-group { text-align: center; margin-top: 20px; display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; } .button-group button { padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; font-size: 1em; transition: background-color 0.3s ease; min-width: 120px; } .btn-calculate { background-color: var(–primary-color); color: white; } .btn-calculate:hover { background-color: #003b73; } .btn-reset { background-color: #6c757d; color: white; } .btn-reset:hover { background-color: #5a6268; } .btn-copy { background-color: var(–success-color); color: white; } .btn-copy:hover { background-color: #218838; } #results { margin-top: 30px; padding: 20px; border: 1px solid var(–border-color); border-radius: 8px; background-color: var(–primary-color); color: white; text-align: center; box-shadow: var(–shadow); } #results h3 { margin-top: 0; color: white; } #results .main-result { font-size: 2.5em; font-weight: bold; margin: 15px 0; padding: 15px; background-color: rgba(255, 255, 255, 0.2); border-radius: 5px; } #results .intermediate-results div, #results .calculation-explanation { margin-bottom: 10px; font-size: 1.1em; } #results .calculation-explanation { font-style: italic; opacity: 0.9; } table { width: 100%; border-collapse: collapse; margin-top: 20px; box-shadow: var(–shadow); } th, td { padding: 10px; text-align: left; border: 1px solid var(–border-color); } th { background-color: var(–primary-color); color: white; } tr:nth-child(even) { background-color: #e9ecef; } caption { font-size: 1.1em; margin-bottom: 10px; font-weight: bold; color: var(–primary-color); text-align: left; } #chartContainer { margin-top: 30px; text-align: center; padding: 20px; border: 1px solid var(–border-color); border-radius: 8px; background-color: var(–card-background); } #chartContainer canvas { max-width: 100%; height: auto; } .article-section { margin-top: 40px; padding: 20px; border-radius: 8px; background-color: var(–card-background); box-shadow: var(–shadow); } .article-section h2, .article-section h3 { color: var(–primary-color); margin-bottom: 15px; } .article-section h3 { margin-top: 20px; } .article-section p { margin-bottom: 15px; } .article-section ul, .article-section ol { margin-left: 20px; margin-bottom: 15px; } .article-section li { margin-bottom: 8px; } .faq-item { margin-bottom: 15px; } .faq-item .question { font-weight: bold; color: var(–primary-color); cursor: pointer; display: block; padding: 5px; border-radius: 4px; transition: background-color 0.3s ease; } .faq-item .question:hover { background-color: #e9ecef; } .faq-item .answer { display: none; padding: 10px; margin-top: 5px; border-left: 3px solid var(–primary-color); background-color: #f1f3f5; border-radius: 0 4px 4px 4px; } .internal-links { margin-top: 40px; padding: 20px; border-radius: 8px; background-color: var(–card-background); box-shadow: var(–shadow); } .internal-links h2 { color: var(–primary-color); text-align: center; margin-top: 0; } .internal-links ul { list-style: none; padding: 0; text-align: center; } .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; } footer { text-align: center; margin-top: 40px; padding: 20px; font-size: 0.9em; color: #6c757d; } /* Responsive adjustments */ @media (max-width: 768px) { .container { margin: 10px; padding: 15px; } header h1 { font-size: 1.8em; } .button-group { flex-direction: column; align-items: center; } .button-group button { width: 90%; max-width: 300px; margin-bottom: 10px; } #results .main-result { font-size: 2em; } }

Brambleberry Weight of Oils Lye Calculator

Accurate Lye Calculation for Your Soapmaking Needs

Soap Lye Calculator

Olive Oil Coconut Oil Palm Oil Shea Butter Castor Oil Avocado Oil Sweet Almond Oil Select the primary oil in your recipe.
Enter the total weight of all oils in your recipe in grams.
Amount of unsaponified oils for moisturizing properties (typically 3-8%).
Ratio of water to lye (e.g., 2 means 2 parts water for 1 part lye).

Your Soap Recipe Results:

Saponification Value: 0 g NaOH / 100g oil
Lye Needed: 0 g
Water Needed: 0 g
0 g Lye
Formula: (Total Oil Weight / 100) * Saponification Value * (1 – (Superfat Percentage / 100))

Saponification Values

Saponification Values (SAP) for Common Oils (NaOH)
Oil Type SAP Value (g NaOH / 100g Oil) Iodine Value Linoleic Oleic Palmitic Stearic Lauric Myristic Linolenic RSPO
Olive Oil0.13480–967-16%69-77%9-15%2-4%0%0%0-1%N/A
Coconut Oil0.1837–101-3%5-9%8-10%3-5%45-50%15-20%0%N/A
Palm Oil0.14144–5510-16%39-45%40-45%4-6%0%0%0-1%Yes
Shea Butter0.12850-600-2%35-45%35-45%3-8%0%0%0-1%Yes
Castor Oil0.12780–901-5%20-28%0-1%0-1%0%0%4-7%N/A
Avocado Oil0.12970–8510-20%60-75%10-20%1-3%0%0%0-1%N/A
Sweet Almond Oil0.13682-9115-25%65-75%4-7%2-3%0%0%0-1%N/A

Lye & Water Requirements Over Time

Chart shows the required Lye and Water amounts for varying oil weights, keeping superfat and water ratio constant.

What is the Brambleberry Weight of Oils Lye Calculator?

The Brambleberry Weight of Oils Lye Calculator is a specialized tool designed for soap makers to accurately determine the precise amount of Sodium Hydroxide (NaOH), commonly known as lye, required for a specific soap recipe. This calculator is crucial because it takes into account the exact weight and type of oils used in the formulation. Soap making, or saponification, is a chemical reaction where fats (oils and butters) react with an alkali (lye) to produce soap and glycerin. An imbalance in the lye amount can lead to soap that is either lye-heavy (caustic and unsafe to use) or oil-heavy (soft, greasy, and doesn't lather well). The Brambleberry Weight of Oils Lye Calculator helps ensure the perfect balance for a safe, effective, and high-quality bar of soap.

This tool is essential for anyone involved in the craft of soap making, from hobbyists experimenting with their first batches to professional soap artisans producing for commercial sale. Understanding the saponification process and using a reliable lye calculator like this one is fundamental to producing consistent results. It allows soap makers to confidently create custom recipes by adjusting oil blends and superfat levels without guesswork.

A common misconception is that all oils require the same amount of lye. This is incorrect. Different oils have unique fatty acid profiles, which dictate their Saponification (SAP) value – the amount of lye needed to saponify a specific weight of that oil. For instance, hard oils like coconut oil require more lye per gram than softer oils like olive oil. Another misconception is that superfatting is optional; while it reduces the total lye needed, it's a vital step for creating moisturizing soap.

Weight of Oils Lye Calculator Formula and Mathematical Explanation

The core of the Brambleberry Weight of Oils Lye Calculator relies on understanding the Saponification (SAP) value of each oil and adjusting for superfatting and water content. Here's a breakdown of the formula and its components:

The Calculation Steps:

  1. Determine the Saponification (SAP) Value: Each oil has a specific SAP value, which is the number of grams of lye (NaOH) required to saponify 100 grams of that particular oil. These values are empirically determined and readily available in tables (like the one provided with this calculator).
  2. Calculate Lye for Specific Oil Weight: Using the total weight of the oil(s) and their respective SAP values, we calculate the theoretical lye needed. If you have a blend of oils, you calculate the lye needed for each oil and sum them up. However, for simplicity and common usage, often the SAP value of the *primary* oil is used, or an average SAP value for a blend is referenced. Our calculator uses the SAP value of the selected primary oil for illustrative purposes, but a more advanced calculator would account for blends. The formula for a single oil is:
    Theoretical Lye (grams) = (Total Oil Weight in grams / 100) * SAP Value
  3. Adjust for Superfat: Superfatting means using slightly less lye than theoretically needed, leaving a small percentage of the oils unsaponified. This makes the soap more moisturizing and less drying. To calculate the adjusted lye, we reduce the theoretical lye by the superfat percentage.
    Adjusted Lye (grams) = Theoretical Lye (grams) * (1 – (Superfat Percentage / 100))
  4. Calculate Water Amount: The amount of water used affects the trace time and the final hardness of the soap. It's typically calculated based on a ratio to the lye weight. A common range for the water-to-lye ratio is between 1:1 and 3:1.
    Water Required (grams) = Adjusted Lye (grams) * Water to Lye Ratio

Variables:

Variable Meaning Unit Typical Range / Notes
Total Oil Weight The combined weight of all oils and butters in the soap recipe. grams (g) 50g – 5000g+ (depending on batch size)
SAP Value (Sodium Hydroxide) The amount of NaOH needed to saponify 100g of a specific oil. Varies by oil type. grams of NaOH per 100g of oil (g/100g) 0.100 – 0.200 (approx.)
Superfat Percentage The percentage of oils left unsaponified for moisturizing properties. Percent (%) 3% – 8% (common); 0% – 20% (extreme cases)
Water to Lye Ratio The ratio of water weight to lye weight in the recipe. Ratio (e.g., 2:1) 1.5 – 3.0 (common); can be adjusted
Adjusted Lye The final calculated amount of lye needed after accounting for superfat. grams (g) Calculated
Water Needed The calculated amount of water for the batch. grams (g) Calculated

Practical Examples (Real-World Use Cases)

Understanding the Brambleberry Weight of Oils Lye Calculator is best done through practical examples:

Example 1: Basic Olive Oil Soap

Scenario: A beginner soap maker wants to make a simple, gentle soap using only Olive Oil. They plan a batch using 500 grams of Olive Oil, desire a 5% superfat, and prefer a 2:1 water-to-lye ratio.

Inputs:

  • Oil Type: Olive Oil
  • Total Weight of Oils: 500 g
  • Superfat Percentage: 5%
  • Water to Lye Ratio: 2

Calculation:

  • SAP Value for Olive Oil: 0.134 g NaOH / 100g oil
  • Theoretical Lye = (500 g / 100) * 0.134 = 5 * 0.134 = 67 g NaOH
  • Adjusted Lye = 67 g * (1 – (5 / 100)) = 67 g * 0.95 = 63.65 g NaOH
  • Water Needed = 63.65 g * 2 = 127.3 g Water

Calculator Output:

  • SAP Value: 0.134 g NaOH / 100g oil
  • Lye Needed: 63.7 g (rounded)
  • Water Needed: 127.3 g (rounded)
  • Main Result: 63.7 g Lye

Interpretation: This soap maker needs approximately 63.7 grams of lye and 127.3 grams of water for their 500-gram olive oil batch to ensure it's safe and moisturizing.

Example 2: Coconut Oil Heavy Blend with Lower Water Ratio

Scenario: An experienced soap maker wants a hard, cleansing bar with lots of lather. They decide on a recipe with 300 grams of Coconut Oil and 200 grams of Palm Oil (total 500g oils). They want a 3% superfat and a lower water ratio of 1.7:1 to speed up curing.

Note: This calculator uses the selected oil's SAP value. For blends, a more advanced tool or manual calculation considering each oil's SAP is recommended. For this example, let's assume we select Coconut Oil as primary for calculation demonstration. A true blend calculation would be more complex.

Inputs (using Coconut Oil's SAP):

  • Oil Type: Coconut Oil
  • Total Weight of Oils: 500 g
  • Superfat Percentage: 3%
  • Water to Lye Ratio: 1.7

Calculation (using Coconut Oil SAP = 0.183):

  • Theoretical Lye = (500 g / 100) * 0.183 = 5 * 0.183 = 91.5 g NaOH
  • Adjusted Lye = 91.5 g * (1 – (3 / 100)) = 91.5 g * 0.97 = 88.76 g NaOH
  • Water Needed = 88.76 g * 1.7 = 150.89 g Water

Calculator Output (if Coconut Oil selected):

  • SAP Value: 0.183 g NaOH / 100g oil
  • Lye Needed: 88.8 g (rounded)
  • Water Needed: 150.9 g (rounded)
  • Main Result: 88.8 g Lye

Interpretation: For this blend, using Coconut Oil's SAP value as a proxy, the soap maker would need approximately 88.8 grams of lye and 150.9 grams of water. If Palm Oil were the primary selected, the lye amount would be slightly different (approx. 70.5g adjusted lye). This highlights the importance of using accurate SAP values for blends, ideally summing the lye needed for each oil individually.

How to Use This Brambleberry Weight of Oils Lye Calculator

Using the Brambleberry Weight of Oils Lye Calculator is straightforward. Follow these simple steps to get accurate lye measurements for your soap recipes:

Step-by-Step Instructions:

  1. Select Primary Oil: Choose the main oil or butter in your recipe from the 'Oil Type' dropdown. While this calculator simplifies by using one SAP value, remember that complex oil blends require individual calculations for each oil for maximum accuracy.
  2. Enter Total Oil Weight: Input the total weight of *all* oils and butters you are using in your soap batch, measured in grams. Ensure accuracy here, as it's the foundation of the calculation.
  3. Specify Superfat Percentage: Enter your desired superfat percentage. A common range is 3% to 8%. This leaves a small amount of oil unsaponified, making the soap gentler and more moisturizing on the skin.
  4. Set Water-to-Lye Ratio: Input the ratio of water to lye you wish to use. A higher ratio (e.g., 2.5 or 3) results in a thinner 'trace' (when the soap mixture thickens) and a longer cure time, often producing a harder bar. A lower ratio (e.g., 1.5 or 2) results in a faster trace and potentially a softer bar that cures faster.
  5. Click 'Calculate': Once all inputs are entered, click the 'Calculate' button.
  6. Review Results: The calculator will display the calculated Saponification Value (SAP) for the selected oil, the exact amount of Lye Needed (adjusted for superfat), and the Water Needed based on your specified ratio. The primary result, the amount of Lye needed, will be prominently displayed.
  7. Use 'Reset' Button: If you need to start over or clear the current inputs, click the 'Reset' button. This will restore the default values.
  8. Use 'Copy Results' Button: To easily save or transfer your calculated values, click the 'Copy Results' button. This copies the main result, intermediate values, and key assumptions to your clipboard.

How to Read Results:

  • SAP Value: This is a reference number showing how much lye (NaOH) reacts with 100g of the selected oil.
  • Lye Needed: This is the critical number. It's the precise weight of lye (NaOH) you need to measure out for your recipe, already adjusted for your chosen superfat level. Always measure lye by weight, never volume.
  • Water Needed: This is the weight of distilled water you'll need to dissolve your lye into. Always use distilled water to avoid impurities that can affect your soap.
  • Main Result: This is the highlighted, final recommended amount of lye.

Decision-Making Guidance:

The calculated values are your guide. The 'Lye Needed' should be measured meticulously using a digital scale. The 'Water Needed' should also be weighed. Adjusting the 'Superfat Percentage' allows you to fine-tune the moisturizing qualities of your soap. Higher superfat means more moisturizing but potentially a softer bar and faster rancidity if oils used are highly unsaturated. Adjusting the 'Water to Lye Ratio' impacts trace time and cure time; experiment to find what works best for your process and desired soap properties.

Key Factors That Affect Brambleberry Weight of Oils Lye Calculator Results

Several factors influence the accuracy and application of the lye calculation. Understanding these nuances is key to successful soap making:

  • Oil Type and Blend: This is the most significant factor. Different oils have vastly different fatty acid profiles and, consequently, different SAP values. Coconut oil requires much more lye than olive oil. When using a blend, the weighted average of SAP values matters. Using only the primary oil's SAP can lead to inaccuracies in complex blends.
  • Superfat Percentage Accuracy: The superfat level directly reduces the calculated lye. A higher superfat means less lye and more free oils in the final product. Ensure you consistently apply your desired superfat level; deviating significantly can alter the soap's properties (e.g., too low superfat can make it drying, too high can make it soft or prone to rancidity).
  • Water Usage and Ratio: While the water amount is calculated based on the lye, the ratio chosen impacts the saponification process itself. Higher water can slow down trace and curing. Lower water can speed up trace but may lead to a more challenging emulsion or a more brittle bar if trace is too fast. It doesn't change the *amount* of lye needed but affects the soap's behavior and final characteristics.
  • Lye Purity: The SAP values are based on 100% pure Sodium Hydroxide (NaOH). Commercial lye can sometimes contain impurities or be slightly less concentrated. Always use high-quality lye, preferably labeled as 100% Sodium Hydroxide. If your lye is known to be less pure (e.g., 98%), you may need to adjust calculations slightly upwards.
  • Temperature: Temperature doesn't change the *amount* of lye required but significantly impacts the saponification reaction rate and trace. Working with lye and water at specific temperatures (often between 100-130°F or 38-54°C) is crucial for a smooth process.
  • Accuracy of Measurement: Soap making is chemistry. Precise measurements are paramount. Always use a calibrated digital scale to weigh both oils and lye. Measuring lye by volume is highly inaccurate and dangerous. Even small deviations in lye weight can render a batch unusable or unsafe.
  • Potassium Hydroxide (KOH) vs. Sodium Hydroxide (NaOH): This calculator specifically addresses NaOH for bar soaps. Potassium Hydroxide (KOH) is used for liquid soaps and has entirely different SAP values. Ensure you are using the correct lye type for your project.
  • Additives: While additives like exfoliants or colorants don't usually change the required lye amount, ingredients like sugars can accelerate trace or cause scorching. Clays might absorb some water. Understanding how additives interact with your base recipe is important for consistency.

Frequently Asked Questions (FAQ)

What is Saponification Value (SAP)?
Saponification Value (SAP) is the amount of a specific alkali (like Sodium Hydroxide or Potassium Hydroxide) required to neutralize or saponify 1 gram of fat or oil. For lye calculators, it's typically expressed as grams of NaOH per 100 grams of oil.
Can I use this calculator for liquid soap?
No, this calculator is specifically for bar soap using Sodium Hydroxide (NaOH). Liquid soaps require Potassium Hydroxide (KOH), which has different SAP values and calculation methods.
My soap came out soft. What went wrong?
A soft soap can result from several factors: insufficient lye (leading to excess oils), too much water relative to oils, using too many liquid oils (like olive or sunflower) without enough hard oils (like coconut, palm, or shea butter), or not allowing adequate cure time. Double-check your lye calculation and oil blend.
What does 'trace' mean in soap making?
Trace refers to the point in the soap making process when the mixture has thickened enough that drizzling some of the mixture across the surface leaves a visible trail or 'trace' before sinking back in. It indicates that the saponification process is well underway.
Is it safe to handle lye?
Lye is a caustic substance and requires careful handling. Always wear safety goggles, gloves, and protective clothing. Work in a well-ventilated area, and always add lye slowly to water (never water to lye) to avoid dangerous splashing and fumes. Keep pets and children away during the process.
Why use distilled water instead of tap water?
Tap water contains minerals and impurities that can react with lye and oils, potentially affecting the final soap's quality, color, lather, or shelf life. Distilled water is pure H2O, ensuring a clean reaction and consistent results.
What happens if I use too much lye?
Using too much lye results in a lye-heavy soap. This soap will be harsh, caustic, and can cause skin irritation or chemical burns. It will feel drying and may even be unusable. It's crucial to use an accurate lye calculator and weigh ingredients precisely.
How important is the cure time for soap?
Cure time (typically 4-6 weeks for cold process soap) allows the saponification process to complete fully and excess water to evaporate. This results in a harder, milder, longer-lasting bar of soap with better lather. Skipping or shortening the cure time can lead to a soft, mushy bar that's still caustic.
Can I use this calculator if I have a recipe with multiple oils?
This specific calculator uses the SAP value of the *selected primary oil*. For recipes with multiple oils (a blend), it is highly recommended to use a more advanced lye calculator that accounts for each oil's specific SAP value and weight, summing the lye required for each individually before adjusting for superfat. This ensures maximum accuracy for complex blends.

© 2023 Your Brand Name. All rights reserved.

var oilSAPValues = { olive: 0.134, coconut: 0.183, palm: 0.141, shea: 0.128, castor: 0.127, avocado: 0.129, sweet_almond: 0.136 }; var oilIUPACNames = { olive: 'Olive Oil', coconut: 'Coconut Oil', palm: 'Palm Oil', shea: 'Shea Butter', castor: 'Castor Oil', avocado: 'Avocado Oil', sweet_almond: 'Sweet Almond Oil' }; var chart; function toggleFaq(element) { var answer = element.nextElementSibling; if (answer.style.display === "block") { answer.style.display = "none"; element.style.borderRadius = "4px"; } else { answer.style.display = "block"; element.style.borderRadius = "4px 4px 0 0"; } } function validateInput(inputId, errorId, min, max, isRequired = true) { var input = document.getElementById(inputId); var errorElement = document.getElementById(errorId); var value = parseFloat(input.value); var isValid = true; if (isRequired && (input.value === "" || isNaN(value))) { errorElement.textContent = "This field is required."; errorElement.classList.add('visible'); isValid = false; } else if (!isNaN(value)) { if (value max) { errorElement.textContent = "Value cannot be greater than " + max + "."; errorElement.classList.add('visible'); isValid = false; } else { errorElement.textContent = ""; errorElement.classList.remove('visible'); } } else { errorElement.textContent = ""; errorElement.classList.remove('visible'); } return isValid; } function calculateLye() { var oilType = document.getElementById("oilType").value; var oilWeightGrams = parseFloat(document.getElementById("oilWeightGrams").value); var superfatPercentage = parseFloat(document.getElementById("superfatPercentage").value); var waterRatio = parseFloat(document.getElementById("waterRatio").value); var isValid = true; isValid = validateInput('oilWeightGrams', 'oilWeightGramsError', 0) && isValid; isValid = validateInput('superfatPercentage', 'superfatPercentageError', 0, 100) && isValid; isValid = validateInput('waterRatio', 'waterRatioError', 0.1) && isValid; if (!isValid) { // Clear results if inputs are invalid document.getElementById("lyeRequiredGrams").textContent = "Lye Needed: 0 g"; document.getElementById("waterRequiredGrams").textContent = "Water Needed: 0 g"; document.getElementById("sapValue").textContent = "Saponification Value: 0 g NaOH / 100g oil"; document.getElementById("mainResult").textContent = "0 g Lye"; return; } var sapValuePer100g = oilSAPValues[oilType] || 0; var sapValue = sapValuePer100g; // Use directly as g/100g var theoreticalLye = (oilWeightGrams / 100) * sapValue; var adjustedLye = theoreticalLye * (1 – (superfatPercentage / 100)); var waterRequired = adjustedLye * waterRatio; // Update results display document.getElementById("sapValue").textContent = "Saponification Value: " + sapValue.toFixed(3) + " g NaOH / 100g oil"; document.getElementById("lyeRequiredGrams").textContent = "Lye Needed: " + adjustedLye.toFixed(1) + " g"; document.getElementById("waterRequiredGrams").textContent = "Water Needed: " + waterRequired.toFixed(1) + " g"; document.getElementById("mainResult").textContent = adjustedLye.toFixed(1) + " g Lye"; updateLyeChartData(); // Update chart after calculation } function resetForm() { document.getElementById("oilType").value = "olive"; document.getElementById("oilWeightGrams").value = "500"; document.getElementById("superfatPercentage").value = "5"; document.getElementById("waterRatio").value = "2"; // Clear errors document.getElementById("oilWeightGramsError").textContent = ""; document.getElementById("oilWeightGramsError").classList.remove('visible'); document.getElementById("superfatPercentageError").textContent = ""; document.getElementById("superfatPercentageError").classList.remove('visible'); document.getElementById("waterRatioError").textContent = ""; document.getElementById("waterRatioError").classList.remove('visible'); calculateLye(); // Recalculate with default values } function copyResults() { var mainResult = document.getElementById("mainResult").textContent; var sapValue = document.getElementById("sapValue").textContent; var lyeRequired = document.getElementById("lyeRequiredGrams").textContent; var waterRequired = document.getElementById("waterRequiredGrams").textContent; var explanation = document.querySelector(".calculation-explanation").textContent; var resultsText = "— Soap Lye Calculation Results —\n\n"; resultsText += "Key Assumption:\n"; resultsText += "- " + sapValue + "\n"; resultsText += "- Superfat: " + document.getElementById("superfatPercentage").value + "%\n"; resultsText += "- Water/Lye Ratio: " + document.getElementById("waterRatio").value + ":1\n"; resultsText += "- Oil Weight: " + document.getElementById("oilWeightGrams").value + "g\n\n"; resultsText += "Calculated Values:\n"; resultsText += "- " + lyeRequired + "\n"; resultsText += "- " + waterRequired + "\n\n"; resultsText += "Primary Result:\n"; resultsText += mainResult + "\n\n"; resultsText += "Formula Used:\n"; resultsText += explanation; // Use Clipboard API to copy navigator.clipboard.writeText(resultsText).then(function() { // Optional: provide user feedback, e.g., a temporary message var originalText = document.querySelector(".btn-copy").textContent; document.querySelector(".btn-copy").textContent = "Copied!"; setTimeout(function() { document.querySelector(".btn-copy").textContent = originalText; }, 2000); }).catch(function(err) { console.error('Failed to copy text: ', err); // Fallback for older browsers or if clipboard API fails prompt("Copy the following text:", resultsText); }); } function updateLyeChartData() { var oilType = document.getElementById("oilType").value; var superfatPercentage = parseFloat(document.getElementById("superfatPercentage").value); var waterRatio = parseFloat(document.getElementById("waterRatio").value); var sapValuePer100g = oilSAPValues[oilType] || 0; var oilWeights = []; var lyeAmounts = []; var waterAmounts = []; // Generate data for chart (e.g., for oil weights from 100g to 1000g) for (var i = 100; i <= 1000; i += 100) { oilWeights.push(i); var theoreticalLye = (i / 100) * sapValuePer100g; var adjustedLye = theoreticalLye * (1 – (superfatPercentage / 100)); var waterRequired = adjustedLye * waterRatio; lyeAmounts.push(adjustedLye); waterAmounts.push(waterRequired); } // Update chart if (chart) { chart.data.labels = oilWeights.map(function(w) { return w + "g Oil"; }); chart.data.datasets[0].data = lyeAmounts; chart.data.datasets[1].data = waterAmounts; chart.options.plugins.title.text = 'Lye and Water Needs for ' + oilIUPACNames[oilType] + ' (Superfat: ' + superfatPercentage + '%, Water/Lye Ratio: ' + waterRatio + ')'; chart.update(); } } function initializeChart() { var ctx = document.getElementById('lyeWaterChart').getContext('2d'); var oilType = document.getElementById("oilType").value; var superfatPercentage = parseFloat(document.getElementById("superfatPercentage").value); var waterRatio = parseFloat(document.getElementById("waterRatio").value); var sapValuePer100g = oilSAPValues[oilType] || 0; var oilWeights = []; var lyeAmounts = []; var waterAmounts = []; for (var i = 100; i <= 1000; i += 100) { oilWeights.push(i); var theoreticalLye = (i / 100) * sapValuePer100g; var adjustedLye = theoreticalLye * (1 – (superfatPercentage / 100)); var waterRequired = adjustedLye * waterRatio; lyeAmounts.push(adjustedLye); waterAmounts.push(waterRequired); } chart = new Chart(ctx, { type: 'line', data: { labels: oilWeights.map(function(w) { return w + "g Oil"; }), datasets: [{ label: 'Lye Needed (g)', data: lyeAmounts, borderColor: 'rgb(255, 99, 132)', backgroundColor: 'rgba(255, 99, 132, 0.2)', tension: 0.1, fill: false }, { label: 'Water Needed (g)', data: waterAmounts, borderColor: 'rgb(54, 162, 235)', backgroundColor: 'rgba(54, 162, 235, 0.2)', tension: 0.1, fill: false }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { title: { display: true, text: 'Lye and Water Needs for ' + oilIUPACNames[oilType] + ' (Superfat: ' + superfatPercentage + '%, Water/Lye Ratio: ' + waterRatio + ')' }, legend: { position: 'top', } }, scales: { x: { title: { display: true, text: 'Total Oil Weight (grams)' } }, y: { title: { display: true, text: 'Amount (grams)' }, beginAtZero: true } } } }); } // Initialize chart on load window.onload = function() { // Ensure Chart.js is loaded before initializing if (typeof Chart === 'undefined') { var script = document.createElement('script'); script.src = 'https://cdn.jsdelivr.net/npm/chart.js'; script.onload = function() { initializeChart(); }; document.head.appendChild(script); } else { initializeChart(); } calculateLye(); // Initial calculation on load };

Leave a Comment