@khanacademy/perseus 57.1.0 → 57.2.0

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
@@ -25414,7 +25414,7 @@ class GradedGroupAnswerBar extends React__namespace.Component {
25414
25414
  }, nextQuestion));
25415
25415
  }
25416
25416
  }
25417
- const fontSize = 17;
25417
+ const fontSize$1 = 17;
25418
25418
  const styles$j = {
25419
25419
  answerBar: {
25420
25420
  display: "flex",
@@ -25439,7 +25439,7 @@ const styles$j = {
25439
25439
  flexDirection: "row",
25440
25440
  alignItems: "center",
25441
25441
  fontWeight: "bold",
25442
- fontSize: fontSize
25442
+ fontSize: fontSize$1
25443
25443
  }
25444
25444
  };
25445
25445
 
@@ -28126,6 +28126,7 @@ const defaultGraphConfig = {
28126
28126
  width: 0,
28127
28127
  height: 0,
28128
28128
  labels: [],
28129
+ labelLocation: "onAxis",
28129
28130
  disableKeyboardInteraction: false,
28130
28131
  interactiveColor: "var(--mafs-blue)"
28131
28132
  };
@@ -28349,6 +28350,8 @@ function escapeIfUnescaped(character) {
28349
28350
  }
28350
28351
  }
28351
28352
 
28353
+ // Exported for testing purposes
28354
+ const fontSize = 14;
28352
28355
  function AxisLabels(_ref) {
28353
28356
  let {
28354
28357
  i18n
@@ -28357,24 +28360,27 @@ function AxisLabels(_ref) {
28357
28360
  range,
28358
28361
  labels,
28359
28362
  width,
28360
- height
28363
+ height,
28364
+ labelLocation
28361
28365
  } = useGraphConfig();
28362
28366
  const {
28363
28367
  strings
28364
28368
  } = i18n;
28365
- const yAxisLabelLocation = [0, range[Y][MAX]];
28366
- const xAxisLabelLocation = [range[X][MAX], 0];
28367
- const [xAxisLabelText, yAxisLabelText] = labels;
28368
28369
  const graphInfo = {
28369
28370
  range,
28370
28371
  width,
28371
28372
  height
28372
28373
  };
28373
- const [x1, y1] = pointToPixel(xAxisLabelLocation, graphInfo);
28374
- // The default location for the y-axis-label is at the maximum y point
28375
- // This is just underneath the tick line for that point. The -24 moves the
28376
- // label up one grid square, so it sits on top of the graph
28377
- const [x2, y2] = mafs.vec.add(pointToPixel(yAxisLabelLocation, graphInfo), [0, -24]);
28374
+
28375
+ // Get the position of the main axis labels
28376
+ const [xAxisLabelLocation, yAxisLabelLocation] = getLabelPosition(graphInfo, labelLocation);
28377
+ const [xAxisLabelText, yAxisLabelText] = labels;
28378
+
28379
+ // Get the transform for the labels
28380
+ const {
28381
+ xLabelTransform,
28382
+ yLabelTransform
28383
+ } = getLabelTransform(labelLocation);
28378
28384
  const {
28379
28385
  TeX
28380
28386
  } = getDependencies();
@@ -28382,23 +28388,72 @@ function AxisLabels(_ref) {
28382
28388
  "aria-label": strings.xAxis,
28383
28389
  style: {
28384
28390
  position: "absolute",
28385
- left: x1,
28386
- top: y1,
28387
- fontSize: "14px",
28388
- transform: "translate(7px, -50%)"
28391
+ left: xAxisLabelLocation[X],
28392
+ top: xAxisLabelLocation[Y],
28393
+ fontSize: fontSize + "px",
28394
+ transform: xLabelTransform
28389
28395
  }
28390
28396
  }, /*#__PURE__*/React__default["default"].createElement(TeX, null, replaceOutsideTeX(xAxisLabelText))), /*#__PURE__*/React__default["default"].createElement("span", {
28391
28397
  "aria-label": strings.yAxis,
28392
28398
  style: {
28393
28399
  position: "absolute",
28394
- left: x2,
28395
- top: y2,
28396
- fontSize: "14px",
28397
- transform: "translate(-50%, 0px)"
28400
+ left: yAxisLabelLocation[X],
28401
+ top: yAxisLabelLocation[Y],
28402
+ fontSize: fontSize + "px",
28403
+ transform: yLabelTransform
28398
28404
  }
28399
28405
  }, /*#__PURE__*/React__default["default"].createElement(TeX, null, replaceOutsideTeX(yAxisLabelText))));
28400
28406
  }
28401
28407
 
28408
+ /* Get the transform for the labels based on the labelLocation
28409
+ * Exported for testing purposes.
28410
+ */
28411
+ const getLabelTransform = labelLocation => {
28412
+ // onAxis is the default label location
28413
+ const isOnAxis = labelLocation === undefined || labelLocation === "onAxis";
28414
+ const xLabelTransform = isOnAxis ? "translate(7px, -50%)" : "translate(-50%, -50%)";
28415
+ const yLabelTransform = isOnAxis ? "translate(-50%, 0px)" : "translate(-50%, 0px) rotate(-90deg)";
28416
+ return {
28417
+ xLabelTransform,
28418
+ yLabelTransform
28419
+ };
28420
+ };
28421
+
28422
+ /* Calculate the position of the main axis labels based on the labelLocation
28423
+ * and the ranges of the graph. Exported for testing purposes.
28424
+ */
28425
+ const getLabelPosition = (graphInfo, labelLocation) => {
28426
+ // If the labels are placed along the edge of the graph, we need to place them at the
28427
+ // center of the graph, which is the average of the min and max values of the axes.
28428
+ if (labelLocation === "alongEdge") {
28429
+ // Offset the labels by a certain amount based on the range of the graph, to ensure that
28430
+ // the labels do not overlap with the axis tick if they are out of the graph bounds.
28431
+ const xAxisLabelOffset = graphInfo.range[Y][MIN] >= 0 ? [0, fontSize * 3] // Move the label down by 3 font sizes if the y-axis min is positive
28432
+ : [0, fontSize]; // Move the label down by 1 font size if the y-axis min is negative
28433
+ const yAxisLabelOffset = graphInfo.range[X][MIN] >= 0 ? [-fontSize * 3, -fontSize] // Move the label left by 3 font sizes if the x-axis min is positive
28434
+ : [-fontSize, -fontSize]; // Move the label left by 1 font size if the x-axis min is negative
28435
+
28436
+ // Calculate the location of the labels to be halfway between the min and max values of the axes
28437
+ const xAxisLabelLocation = [(graphInfo.range[X][MIN] + graphInfo.range[X][MAX]) / 2, graphInfo.range[Y][MIN]];
28438
+ const yAxisLabelLocation = [graphInfo.range[X][MIN], (graphInfo.range[Y][MIN] + graphInfo.range[Y][MAX]) / 2];
28439
+
28440
+ // Convert the Vector2 coordinates to pixel coordinates and add the offsets
28441
+ const xLabel = mafs.vec.add(pointToPixel(xAxisLabelLocation, graphInfo), xAxisLabelOffset);
28442
+ const yLabel = mafs.vec.add(pointToPixel(yAxisLabelLocation, graphInfo), yAxisLabelOffset);
28443
+ return [xLabel, yLabel];
28444
+ }
28445
+
28446
+ // Otherwise, the labels are placed on the axes (default), and we need to
28447
+ // place them at the end of the axis, which is the maximum value of the axis.
28448
+ const xLabelInitial = [graphInfo.range[X][MAX], 0];
28449
+ const yLabelInitial = [0, graphInfo.range[Y][MAX]];
28450
+ const yLabelOffset = [0, -fontSize * 2]; // Move the y-axis label up by 2 font sizes
28451
+
28452
+ const xLabel = pointToPixel(xLabelInitial, graphInfo);
28453
+ const yLabel = mafs.vec.add(pointToPixel(yLabelInitial, graphInfo), yLabelOffset);
28454
+ return [xLabel, yLabel];
28455
+ };
28456
+
28402
28457
  // The size of the ticks and labels in pixels
28403
28458
  const tickSize = 10;
28404
28459
  const tickLabelSize = 14;
@@ -34747,6 +34802,7 @@ const MafsGraph = props => {
34747
34802
  state,
34748
34803
  dispatch,
34749
34804
  labels,
34805
+ labelLocation,
34750
34806
  readOnly,
34751
34807
  fullGraphAriaLabel,
34752
34808
  fullGraphAriaDescription
@@ -34827,6 +34883,7 @@ const MafsGraph = props => {
34827
34883
  width,
34828
34884
  height,
34829
34885
  labels,
34886
+ labelLocation,
34830
34887
  disableKeyboardInteraction: disableInteraction,
34831
34888
  // If the graph is read-only or static, we want to make it
34832
34889
  // visually clear that the graph is no longer interactive.
@@ -41954,7 +42011,7 @@ const addLibraryVersionToPerseusDebug = (libraryName, libraryVersion) => {
41954
42011
 
41955
42012
  // This file is processed by a Rollup plugin (replace) to inject the production
41956
42013
  const libName = "@khanacademy/perseus";
41957
- const libVersion = "57.1.0";
42014
+ const libVersion = "57.2.0";
41958
42015
  addLibraryVersionToPerseusDebug(libName, libVersion);
41959
42016
 
41960
42017
  const apiVersion = {