@khanacademy/perseus 57.2.0 → 57.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -29386,7 +29386,28 @@ const LockedEllipse = props => {
29386
29386
  }));
29387
29387
  };
29388
29388
 
29389
+ function clampDomain(domain, graphBounds) {
29390
+ // If the domain is invalid, return the graph bounds
29391
+ if (domain[0] > domain[1]) {
29392
+ return graphBounds;
29393
+ }
29394
+
29395
+ // If the domain is outside the graph bounds, return null
29396
+ if (domain[0] < graphBounds[0] && domain[1] < graphBounds[0] || domain[0] > graphBounds[1] && domain[1] > graphBounds[1]) {
29397
+ return null;
29398
+ }
29399
+
29400
+ // Clamp the function to the bounds of the graph to prevent memory
29401
+ // leaks when the domain is set to something like [-Infinity, Infinity].
29402
+ const min = Math.max(domain[0], graphBounds[0]);
29403
+ const max = Math.min(domain[1], graphBounds[1]);
29404
+ return [min, max];
29405
+ }
29406
+
29389
29407
  const LockedFunction = props => {
29408
+ const {
29409
+ range
29410
+ } = useGraphConfig();
29390
29411
  const [equation, setEquation] = React.useState();
29391
29412
  const {
29392
29413
  color,
@@ -29396,8 +29417,7 @@ const LockedFunction = props => {
29396
29417
  } = props;
29397
29418
  const plotProps = {
29398
29419
  color: perseusCore.lockedFigureColors[color],
29399
- style: strokeStyle,
29400
- domain
29420
+ style: strokeStyle
29401
29421
  };
29402
29422
  const hasAria = !!props.ariaLabel;
29403
29423
  React.useEffect(() => {
@@ -29408,6 +29428,12 @@ const LockedFunction = props => {
29408
29428
  if (typeof equation === "undefined") {
29409
29429
  return null;
29410
29430
  }
29431
+ const clampedDomain = directionalAxis === "x" ? clampDomain(domain, range[0]) : clampDomain(domain, range[1]);
29432
+
29433
+ // The domain entirely is outside the bounds of the graph. Don't render.
29434
+ if (clampedDomain === null) {
29435
+ return null;
29436
+ }
29411
29437
  return /*#__PURE__*/React__namespace.createElement("g", {
29412
29438
  className: "locked-function",
29413
29439
  "aria-label": hasAria ? props.ariaLabel : undefined,
@@ -29416,11 +29442,13 @@ const LockedFunction = props => {
29416
29442
  }, directionalAxis === "x" && /*#__PURE__*/React__namespace.createElement(mafs.Plot.OfX, _extends__default["default"]({
29417
29443
  y: x => equation.eval({
29418
29444
  x
29419
- })
29445
+ }),
29446
+ domain: clampedDomain
29420
29447
  }, plotProps)), directionalAxis === "y" && /*#__PURE__*/React__namespace.createElement(mafs.Plot.OfY, _extends__default["default"]({
29421
29448
  x: y => equation.eval({
29422
29449
  y
29423
- })
29450
+ }),
29451
+ domain: clampedDomain
29424
29452
  }, plotProps)));
29425
29453
  };
29426
29454
 
@@ -42011,7 +42039,7 @@ const addLibraryVersionToPerseusDebug = (libraryName, libraryVersion) => {
42011
42039
 
42012
42040
  // This file is processed by a Rollup plugin (replace) to inject the production
42013
42041
  const libName = "@khanacademy/perseus";
42014
- const libVersion = "57.2.0";
42042
+ const libVersion = "57.2.1";
42015
42043
  addLibraryVersionToPerseusDebug(libName, libVersion);
42016
42044
 
42017
42045
  const apiVersion = {