Domain and Range from a Graph Calculator

Domain and Range from a Graph Calculator | Understanding Functions :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #ddd; –shadow-color: 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: 960px; margin: 20px auto; padding: 20px; background-color: #fff; border-radius: 8px; box-shadow: 0 4px 15px var(–shadow-color); display: flex; flex-direction: column; } header { text-align: center; margin-bottom: 30px; padding-bottom: 20px; border-bottom: 1px solid var(–border-color); } header h1 { color: var(–primary-color); margin-bottom: 10px; } .calculator-section { margin-bottom: 40px; padding-bottom: 30px; border-bottom: 1px solid var(–border-color); } .calculator-section:last-of-type { border-bottom: none; margin-bottom: 0; padding-bottom: 0; } .input-group { margin-bottom: 20px; padding: 15px; background-color: var(–background-color); border-radius: 6px; border: 1px solid var(–border-color); } .input-group label { display: block; margin-bottom: 8px; font-weight: bold; color: var(–primary-color); } .input-group input[type="text"], .input-group input[type="number"] { width: calc(100% – 22px); /* Account for padding and border */ padding: 10px; border: 1px solid var(–border-color); border-radius: 4px; font-size: 1rem; margin-bottom: 5px; } .input-group small { display: block; color: #666; font-size: 0.85rem; } .error-message { color: #dc3545; font-size: 0.85rem; margin-top: 5px; min-height: 1.2em; /* Prevent layout shifts */ } .button-group { display: flex; gap: 10px; margin-top: 20px; justify-content: center; } button { padding: 12px 25px; border: none; border-radius: 5px; cursor: pointer; font-size: 1rem; transition: background-color 0.3s ease; font-weight: bold; } .btn-primary { background-color: var(–primary-color); color: #fff; } .btn-primary:hover { background-color: #003a70; } .btn-secondary { background-color: #6c757d; color: #fff; } .btn-secondary:hover { background-color: #5a6268; } .btn-success { background-color: var(–success-color); color: #fff; } .btn-success:hover { background-color: #218838; } #results { margin-top: 30px; padding: 25px; background-color: var(–primary-color); color: #fff; border-radius: 8px; text-align: center; box-shadow: inset 0 2px 5px rgba(0,0,0,0.2); } #results h2 { margin-top: 0; margin-bottom: 15px; font-size: 1.8rem; } .result-item { margin-bottom: 15px; font-size: 1.1rem; } .result-item strong { display: block; font-size: 1.3rem; color: var(–success-color); margin-top: 5px; } .formula-explanation { margin-top: 20px; font-size: 0.95rem; color: #eee; opacity: 0.8; } canvas { margin-top: 20px; border: 1px solid var(–border-color); background-color: #fff; border-radius: 4px; } table { width: 100%; border-collapse: collapse; margin-top: 30px; box-shadow: 0 2px 8px var(–shadow-color); } caption { font-size: 1.2rem; font-weight: bold; color: var(–primary-color); margin-bottom: 15px; text-align: left; } th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid var(–border-color); } thead { background-color: var(–primary-color); color: #fff; } tbody tr:nth-child(even) { background-color: #f2f2f2; } tbody tr:hover { background-color: #e9ecef; } .article-content { margin-top: 40px; padding-top: 30px; border-top: 1px solid var(–border-color); } .article-content h2, .article-content h3 { color: var(–primary-color); margin-top: 30px; margin-bottom: 15px; } .article-content h2 { font-size: 1.8rem; } .article-content h3 { font-size: 1.4rem; } .article-content p, .article-content ul, .article-content ol { margin-bottom: 20px; font-size: 1.05rem; } .article-content ul, .article-content ol { padding-left: 30px; } .article-content li { margin-bottom: 10px; } .faq-item { margin-bottom: 20px; padding: 15px; background-color: var(–background-color); border-radius: 6px; border: 1px solid var(–border-color); } .faq-item strong { color: var(–primary-color); display: block; margin-bottom: 8px; font-size: 1.1rem; } .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.95rem; color: #555; } .input-group input:focus, button:focus { outline: 2px solid var(–primary-color); outline-offset: 2px; } .result-item strong { font-size: 1.4rem; } #results { background-color: var(–primary-color); color: #fff; } #results h2 { color: #fff; } .btn-copy { background-color: #ffc107; color: #212529; } .btn-copy:hover { background-color: #e0a800; } @media (max-width: 768px) { .container { margin: 10px; padding: 15px; } button { padding: 10px 20px; font-size: 0.95rem; } .button-group { flex-wrap: wrap; justify-content: center; } .result-item strong { font-size: 1.2rem; } #results h2 { font-size: 1.5rem; } }

Domain and Range from a Graph Calculator

Easily determine the domain and range of any function by analyzing its graph.

Graph Input

Describe your graph using interval notation. Use 'inf' for infinity. For piecewise functions, you may need to analyze segments separately or represent the combined intervals.

Enter interval notation for the horizontal extent of the graph.
Enter interval notation for the vertical extent of the graph.

Your Graph's Domain & Range

Domain

Range

Input Interpretation

The domain represents all possible x-values the function can take, and the range represents all possible y-values. We determine these by observing the horizontal and vertical extent of the graph, respectively.

Graph Visualization (Example)

Dynamic chart illustrating function behavior.

Summary Table

Key Values from Graph Analysis
Metric Value Description
Input Domain N/A The interval(s) of x-values you entered.
Input Range N/A The interval(s) of y-values you entered.
Calculated Domain N/A The confirmed domain based on your input.
Calculated Range N/A The confirmed range based on your input.

What is Domain and Range from a Graph?

The terms "domain" and "range" are fundamental concepts in mathematics, particularly when studying functions. When we analyze a function's graphical representation, understanding its domain and range provides crucial insights into its behavior and limitations. The domain and range from a graph calculator serves as an essential tool for students and educators to quickly and accurately determine these properties by visual inspection of the plotted function. Essentially, it helps answer the questions: "What x-values does the graph cover?" (domain) and "What y-values does the graph cover?" (range).

Who Should Use a Domain and Range Calculator?

This calculator is invaluable for several groups:

  • Students: High school and college students learning about functions, algebra, pre-calculus, and calculus will find it immensely helpful for homework, practice, and understanding graphical representations.
  • Educators: Teachers can use it to create examples, demonstrate concepts, and quickly verify results when teaching about functions and their properties.
  • Mathematical Enthusiasts: Anyone interested in exploring mathematical concepts visually and understanding function behavior will benefit from this tool.

Common Misconceptions about Domain and Range from a Graph

  • Confusing Domain and Range: A frequent error is mixing up the horizontal (domain) and vertical (range) axes. Always remember: Domain is about x, Range is about y.
  • Ignoring Discontinuities or Breaks: Graphs might have holes, jumps, or asymptotes. A simple visual scan might miss these, leading to incorrect interval notation if not carefully examined.
  • Assuming Symmetry without Verification: While some graphs are symmetric, you cannot assume the domain or range is perfectly symmetrical around an axis or point without checking the graph's extent.
  • Overlooking Infinity: For functions that extend indefinitely, forgetting to include infinity symbols ('inf') or the correct bracket type (parenthesis for open, square bracket for closed) is common.

Domain and Range from a Graph Calculator Formula and Mathematical Explanation

While this calculator doesn't perform complex algebraic manipulations to find the domain and range (as you would for an algebraic function definition), it interprets your visual input of the graph's extent. The "formula" is essentially a process of observation and notation conversion.

Step-by-Step Derivation (from observation):

  1. Observe the Horizontal Extent (for Domain): Mentally trace the graph from left to right. Identify the smallest x-value the graph reaches and the largest x-value it reaches.
  2. Identify Endpoints and Intervals: Note whether the graph includes the extreme x-values (closed circle, solid line ending) or approaches them without reaching (open circle, dashed line, arrow).
  3. Determine Domain Notation: Write the domain using interval notation. If the graph extends infinitely to the left or right, use '-inf' or 'inf' respectively. Use square brackets `[` or `]` for included endpoints and parentheses `(` or `)` for excluded endpoints. For disconnected parts of the graph, use the union symbol `∪`.
  4. Observe the Vertical Extent (for Range): Mentally trace the graph from bottom to top. Identify the smallest y-value the graph reaches and the largest y-value it reaches.
  5. Identify Endpoints and Intervals: Similar to the domain, note whether the graph includes the extreme y-values or approaches them.
  6. Determine Range Notation: Write the range using interval notation, applying the same rules for infinity and included/excluded endpoints as used for the domain.

Variable Explanations

In the context of this calculator, the "variables" are the interpreted boundaries of your graph.

Variables in Domain & Range Analysis
Variable Meaning Unit Typical Range
x Independent variable, representing horizontal position. Units of measurement (e.g., meters, seconds, unitless) Varies based on graph; analyzed for domain.
y Dependent variable, representing vertical position. Units of measurement (e.g., meters, seconds, unitless) Varies based on graph; analyzed for range.
Domain The set of all possible x-values for which the function is defined, as observed from the graph's horizontal extent. Units of measurement Can be a single interval, multiple intervals, or all real numbers (`(-inf, inf)`).
Range The set of all possible y-values the function takes, as observed from the graph's vertical extent. Units of measurement Can be a single interval, multiple intervals, or all real numbers (`(-inf, inf)`).
Interval Notation A standard mathematical notation to represent a set of numbers between two endpoints. Examples: (a, b), [a, b], (a, b], [a, b), (-inf, a), [b, inf). N/A N/A
'inf' / '-inf' Represents positive and negative infinity, respectively. Used when a graph extends without bound. N/A N/A
( / ) Parentheses indicate that the endpoint is *not* included in the interval (e.g., an open circle). N/A N/A
[ / ] Square brackets indicate that the endpoint *is* included in the interval (e.g., a closed circle or the end of a solid line). N/A N/A
Union symbol, used to combine multiple disjoint intervals (e.g., domain of `y = 1/x` is `(-inf, 0) U (0, inf)`). N/A N/A

Practical Examples (Real-World Use Cases)

Example 1: A Simple Parabola

Consider the graph of the function f(x) = x^2. This is a standard upward-opening parabola with its vertex at the origin (0,0).

  • Graph Observation: The parabola extends infinitely to the left and right, covering all possible x-values. The vertex is at y=0, and the parabola extends infinitely upwards.
  • Input for Calculator:
    • Domain: (-inf, inf)
    • Range: [0, inf)
  • Calculator Output:
    • Domain: (-inf, inf)
    • Range: [0, inf)
  • Interpretation: This function is defined for all real numbers (domain) and its output values are always zero or positive (range).

Example 2: A Rational Function with an Asymptote

Consider the graph of the function g(x) = 1/x. This graph has a vertical asymptote at x=0 and a horizontal asymptote at y=0.

  • Graph Observation: The graph exists in the first and third quadrants. It approaches the y-axis (x=0) but never touches it, extending infinitely up and down. It also approaches the x-axis (y=0) but never touches it, extending infinitely left and right.
  • Input for Calculator:
    • Domain: (-inf, 0) U (0, inf)
    • Range: (-inf, 0) U (0, inf)
  • Calculator Output:
    • Domain: (-inf, 0) U (0, inf)
    • Range: (-inf, 0) U (0, inf)
  • Interpretation: The function is defined for all real numbers except x=0 (domain). It can produce any real number output except y=0 (range).

Example 3: A Closed Interval Function

Consider a function defined only on a specific segment, like a line segment from (-2, 1) to (4, 7), including the endpoints.

  • Graph Observation: The graph is a straight line segment. The x-values range from -2 to 4, inclusive. The y-values range from 1 to 7, inclusive.
  • Input for Calculator:
    • Domain: [-2, 4]
    • Range: [1, 7]
  • Calculator Output:
    • Domain: [-2, 4]
    • Range: [1, 7]
  • Interpretation: The function is only defined for x-values between -2 and 4, and its output values are restricted to the range between 1 and 7.

How to Use This Domain and Range from a Graph Calculator

Using the calculator is straightforward and designed for intuitive interaction.

  1. Examine Your Graph: Have the graph of your function readily available.
  2. Identify Horizontal Extent: Look at the graph and determine the complete set of x-values it covers. Pay close attention to the leftmost and rightmost points, arrows indicating infinite extension, open circles (excluded), and closed circles (included).
  3. Enter Domain Input: In the "X-values Covered by Graph (Domain)" input field, type the identified x-intervals using correct interval notation. Use `(-inf, inf)` for all real numbers, `[` or `]` for included endpoints, and `(` or `)` for excluded endpoints. Use the union symbol `∪` if there are separate intervals.
  4. Identify Vertical Extent: Now, examine the graph's vertical coverage. Determine the lowest and highest y-values the graph reaches. Note any endpoints or infinite extensions similarly to how you analyzed the x-values.
  5. Enter Range Input: In the "Y-values Covered by Graph (Range)" input field, type the identified y-intervals using correct interval notation.
  6. Click Calculate: Press the "Calculate Domain & Range" button.
  7. Review Results: The calculator will display the confirmed Domain and Range, along with a summary of your inputs and a basic explanation. The chart will attempt to visualize a generalized version of the input intervals.
  8. Interpret: Understand what the calculated domain and range signify about the function's possible inputs and outputs.
  9. Reset or Copy: Use the "Reset" button to clear the fields for a new calculation, or "Copy Results" to save the output.

Key Factors That Affect Domain and Range Results

While this calculator primarily relies on your interpretation of the graph, understanding the underlying mathematical reasons behind a function's domain and range is crucial. These factors influence the shape and extent of any graph:

  1. Division by Zero: Functions involving division are undefined where the denominator is zero. This often leads to vertical asymptotes and gaps in the domain (e.g., `f(x) = 1/x`).
  2. Even Roots of Negative Numbers: Functions involving square roots (or any even root) are undefined for negative inputs under the radical. This restricts the domain (e.g., `f(x) = sqrt(x)` has domain `[0, inf)`).
  3. Logarithms of Non-Positive Numbers: Logarithmic functions are only defined for positive arguments. This restricts the domain (e.g., `f(x) = log(x)` has domain `(0, inf)`).
  4. Asymptotes (Vertical and Horizontal): Vertical asymptotes often create breaks in the domain, while horizontal asymptotes can indicate limits on the range as x approaches infinity.
  5. Piecewise Definitions: Functions defined by different rules over different intervals will have domains and ranges that are the union of the domains and ranges of their respective pieces.
  6. Real-World Constraints: In applied mathematics, practical limitations often dictate domain and range. For example, time cannot be negative (domain constraint), and population size cannot be fractional or negative (range constraint).
  7. Function Type: Polynomials generally have domains of all real numbers. Rational functions have restrictions where the denominator is zero. Trigonometric functions like sine and cosine have all real numbers as their domain but restricted ranges.
  8. Graph Endpoints and Holes: Explicitly defined endpoints (closed or open circles) or holes in a graph directly dictate excluded or included points in the domain and range.

Frequently Asked Questions (FAQ)

Q1: What's the difference between interval notation and set notation for domain and range?

Interval notation uses parentheses and brackets to denote ranges of numbers (e.g., `(2, 5]`). Set notation uses curly braces and inequality symbols (e.g., `{x | 2 < x <= 5}`). Both represent the same values, but interval notation is often more concise for continuous or piecewise continuous functions.

Q2: How do I represent infinity in interval notation?

Use the symbol `inf` for positive infinity and `-inf` for negative infinity. Always use parentheses `(` `)` with infinity, as infinity cannot be included in a set. For example, `[0, inf)` means all numbers greater than or equal to 0.

Q3: What if my graph has multiple separate pieces?

Use the union symbol `∪` to connect the separate intervals. For instance, if a function is defined for x values less than -1 and also for x values greater than 1, the domain would be written as `(-inf, -1) U (1, inf)`.

Q4: Does every function have a domain and range?

Yes, every function is defined by a domain (the set of valid inputs) and produces a range (the set of resulting outputs). The question is whether these sets are all real numbers or restricted subsets.

Q5: How can I be sure I've found the *entire* domain and range from a graph?

Carefully examine the graph's full horizontal and vertical extent. Look for arrows indicating infinite behavior, check for any gaps, holes, or asymptotes, and ensure you've considered all parts of the graph.

Q6: What does it mean if the domain and range are the same?

It means the set of all possible x-values is identical to the set of all possible y-values. The identity function, `f(x) = x`, is a prime example, with both domain and range as `(-inf, inf)`.

Q7: Can the range be restricted even if the domain is all real numbers?

Absolutely. The classic example is the parabola `f(x) = x^2`. Its domain is `(-inf, inf)`, but its range is restricted to `[0, inf)` because squaring any real number results in a non-negative number.

Q8: How does the calculator handle piecewise functions?

The calculator takes your direct input for the domain and range intervals. For piecewise functions, you would typically determine the domain and range of each piece separately and then combine them using the union symbol `∪` in the input fields.

Related Tools and Internal Resources

function validateInput(inputId, errorMessageId, description) { var input = document.getElementById(inputId); var errorDiv = document.getElementById(errorMessageId); var value = input.value.trim(); if (value === "") { errorDiv.textContent = "This field cannot be empty."; return false; } // Basic interval notation check (can be expanded for more complex validation) // This regex allows for numbers, inf, -, (, ), [, ], U var intervalRegex = /^(-?inf|[\d\.]+)\s*([\]\)])|(\[|())\s*(-?inf|[\d\.]+)\s*([\]\)])|(-?inf|[\d\.]+)\s*([\]\)])\s*U\s*(\[|())\s*(-?inf|[\d\.]+)\s*([\]\)])/i; if (!intervalRegex.test(value)) { errorDiv.textContent = "Invalid interval notation format. Use formats like (-inf, 5], [0, 10), (-inf, inf), or (-inf, 0) U (0, inf)."; return false; } // Check for specific invalid patterns like opening with ')' or closing with '(' if (value.startsWith(')') || value.endsWith('(') || value.includes(')(') || value.includes('][') || value.includes('))') || value.includes('((')) { errorDiv.textContent = "Invalid interval notation sequence."; return false; } // Check for numbers after 'inf' or before '-inf' in a way that's not possible if (value.includes('inf)') || value.includes('(-inf')) { // This is more complex, but we can check basic structure. // A more robust parser would be needed for full validation. } errorDiv.textContent = ""; return true; } function parseIntervals(intervalString) { var result = { min: -Infinity, max: Infinity, hasMin: false, hasMax: false, isMinIncluded: false, isMaxIncluded: false, unionParts: [] }; if (!intervalString || intervalString.trim() === "") return null; var parts = intervalString.split('U').map(function(part) { return part.trim(); }); for (var i = 0; i = currentMax) { console.error("Invalid interval: min >= max in part " + part); return null; // Indicate invalid interval } result.unionParts.push({ min: currentMin, max: currentMax, isMinIncluded: minIsBracket, isMaxIncluded: maxIsBracket }); } else { console.error("Could not parse interval part: " + part); return null; // Indicate invalid interval } } if (result.unionParts.length === 0) return null; // Consolidate for simple display if possible (e.g., if all parts combine to one) // For this calculator, we'll just return the parsed parts. return result; } function calculateDomainAndRange() { var isValidX = validateInput("x-values", "x-values-error", "Domain"); var isValidY = validateInput("y-values", "y-values-error", "Range"); if (!isValidX || !isValidY) { document.getElementById("results").style.display = "none"; return; } var xValuesInput = document.getElementById("x-values").value; var yValuesInput = document.getElementById("y-values").value; var domainData = parseIntervals(xValuesInput); var rangeData = parseIntervals(yValuesInput); if (!domainData || !rangeData) { document.getElementById("results").style.display = "none"; console.error("Failed to parse interval data."); return; // Parsing failed } var calculatedDomainStr = xValuesInput; var calculatedRangeStr = yValuesInput; document.getElementById("calculated-domain").textContent = calculatedDomainStr; document.getElementById("calculated-range").textContent = calculatedRangeStr; var inputInterpretation = ""; if (xValuesInput === "(-inf, inf)") { inputInterpretation += "The function is defined for all real numbers. "; } else { inputInterpretation += "The function's horizontal extent is limited to the specified domain intervals. "; } if (yValuesInput === "(-inf, inf)") { inputInterpretation += "The function can output any real number. "; } else { inputInterpretation += "The function's output values are restricted to the specified range intervals. "; } document.getElementById("input-interpretation").textContent = inputInterpretation; document.getElementById("table-domain-input").textContent = xValuesInput; document.getElementById("table-range-input").textContent = yValuesInput; document.getElementById("table-domain-calculated").textContent = calculatedDomainStr; document.getElementById("table-range-calculated").textContent = calculatedRangeStr; document.getElementById("results").style.display = "block"; updateChart(domainData, rangeData); } function resetCalculator() { document.getElementById("x-values").value = "(-inf, inf)"; document.getElementById("y-values").value = "[0, inf)"; document.getElementById("x-values-error").textContent = ""; document.getElementById("y-values-error").textContent = ""; document.getElementById("results").style.display = "none"; updateChart({ min: -Infinity, max: Infinity, unionParts: [{min: -Infinity, max: Infinity, isMinIncluded: false, isMaxIncluded: false}] }, { min: 0, max: Infinity, unionParts: [{min: 0, max: Infinity, isMinIncluded: true, isMaxIncluded: false}] }); } function copyResults() { var domain = document.getElementById("calculated-domain").textContent; var range = document.getElementById("calculated-range").textContent; var interpretation = document.getElementById("input-interpretation").textContent; var tableDomainInput = document.getElementById("table-domain-input").textContent; var tableRangeInput = document.getElementById("table-range-input").textContent; var textToCopy = "Domain and Range Calculator Results:\n\n"; textToCopy += "— Your Inputs —\n"; textToCopy += "Domain Input: " + tableDomainInput + "\n"; textToCopy += "Range Input: " + tableRangeInput + "\n\n"; textToCopy += "— Calculated Results —\n"; textToCopy += "Domain: " + domain + "\n"; textToCopy += "Range: " + range + "\n"; textToCopy += "Interpretation: " + interpretation + "\n"; if (navigator.clipboard && window.isSecureContext) { navigator.clipboard.writeText(textToCopy).then(function() { alert('Results copied to clipboard!'); }).catch(function(err) { console.error('Failed to copy: ', err); // Fallback for older browsers or insecure contexts var textArea = document.createElement("textarea"); textArea.value = textToCopy; textArea.style.position = "fixed"; // Avoid scrolling to bottom textArea.style.left = "-9999px"; document.body.setAttribute("append", textArea); textArea.focus(); document.execCommand('copy'); document.body.removeChild(textArea); alert('Results copied to clipboard!'); }); } else { // Fallback for older browsers or insecure contexts var textArea = document.createElement("textarea"); textArea.value = textToCopy; textArea.style.position = "fixed"; // Avoid scrolling to bottom textArea.style.left = "-9999px"; document.body.setAttribute("append", textArea); textArea.focus(); document.execCommand('copy'); document.body.removeChild(textArea); alert('Results copied to clipboard!'); } } function updateChart(domainData, rangeData) { var ctx = document.getElementById('functionChart').getContext('2d'); // Clear previous chart ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); var chartWidth = ctx.canvas.width; var chartHeight = ctx.canvas.height; var centerX = chartWidth / 2; var centerY = chartHeight / 2; var scaleX = chartWidth / 10; // Assuming roughly -5 to 5 range for visibility var scaleY = chartHeight / 10; // Assuming roughly -5 to 5 range for visibility // Draw Axes ctx.beginPath(); ctx.strokeStyle = '#ccc'; ctx.lineWidth = 1; // X-axis ctx.moveTo(0, centerY); ctx.lineTo(chartWidth, centerY); // Y-axis ctx.moveTo(centerX, 0); ctx.lineTo(centerX, chartHeight); ctx.stroke(); // Draw Labels for Axes ctx.fillStyle = '#666′; ctx.font = '12px Arial'; // X-axis labels for (var x = -5; x <= 5; x++) { ctx.fillText(x, centerX + x * scaleX – (ctx.measureText(x).width / 2), centerY + 15); } // Y-axis labels for (var y = -5; y <= 5; y++) { ctx.fillText(y, centerX – 25, centerY – y * scaleY + (ctx.measureText(y).width / 2)); } // Draw Domain Markers ctx.beginPath(); ctx.strokeStyle = 'rgba(0, 74, 153, 0.7)'; // Primary color ctx.lineWidth = 3; ctx.setLineDash([5, 5]); var xAxisMin = -5 * scaleX; // Corresponds to x = -5 var xAxisMax = 5 * scaleX; // Corresponds to x = 5 if (domainData && domainData.unionParts) { domainData.unionParts.forEach(function(part) { var startX = part.min === -Infinity ? xAxisMin : centerX + part.min * scaleX; var endX = part.max === Infinity ? xAxisMax : centerX + part.max * scaleX; // Clamp to visible canvas area startX = Math.max(0, startX); endX = Math.min(chartWidth, endX); if (startX = 0 && dotX = 0 && dotX <= chartWidth) { ctx.beginPath(); ctx.fillStyle = 'rgba(0, 74, 153, 0.7)'; ctx.arc(dotX, chartHeight – 10, 5, 0, 2 * Math.PI); ctx.fill(); } } }); } ctx.stroke(); ctx.setLineDash([]); // Reset line dash // Draw Range Markers ctx.beginPath(); ctx.strokeStyle = 'rgba(40, 167, 69, 0.7)'; // Success color ctx.lineWidth = 3; ctx.setLineDash([5, 5]); var yAxisMin = chartHeight – (5 * scaleY); // Corresponds to y = -5 var yAxisMax = 0 + (5 * scaleY); // Corresponds to y = 5 if (rangeData && rangeData.unionParts) { rangeData.unionParts.forEach(function(part) { var startY = part.max === Infinity ? yAxisMin : centerY – part.max * scaleY; // Higher y value first var endY = part.min === -Infinity ? yAxisMax : centerY – part.min * scaleY; // Lower y value second // Clamp to visible canvas area startY = Math.max(0, startY); endY = Math.min(chartHeight, endY); if (startY = 0 && dotY = 0 && dotY <= chartHeight) { ctx.beginPath(); ctx.fillStyle = 'rgba(40, 167, 69, 0.7)'; ctx.arc(chartWidth – 10, dotY, 5, 0, 2 * Math.PI); ctx.fill(); } } }); } ctx.stroke(); ctx.setLineDash([]); // Reset line dash // Labels for markers ctx.fillStyle = '#333'; ctx.font = '14px Arial'; ctx.fillText('Domain Extent', 10, chartHeight – 15); ctx.fillText('Range Extent', chartWidth – 100, 15); } // Initialize with default values and chart document.addEventListener('DOMContentLoaded', function() { resetCalculator(); // Initial chart draw with defaults updateChart({ min: -Infinity, max: Infinity, unionParts: [{min: -Infinity, max: Infinity, isMinIncluded: false, isMaxIncluded: false}] }, { min: 0, max: Infinity, unionParts: [{min: 0, max: Infinity, isMinIncluded: true, isMaxIncluded: false}] }); });

Leave a Comment