@teachinglab/omd 0.7.35 → 0.7.37

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.
@@ -491,8 +491,7 @@ export class omdEquationStack extends jsvgGroup {
491
491
  let eqIndex = -1;
492
492
  for (let i = seq.steps.length - 1; i >= 0; i--) {
493
493
  const st = seq.steps[i];
494
- const name = st?.constructor?.name;
495
- if (st instanceof omdEquationNode || name === 'omdEquationNode') { eqIndex = i; break; }
494
+ if (st instanceof omdEquationNode || st?.type === 'omdEquationNode') { eqIndex = i; break; }
496
495
  }
497
496
  if (eqIndex === -1) return false;
498
497
 
@@ -500,8 +499,7 @@ export class omdEquationStack extends jsvgGroup {
500
499
  let startIndex = eqIndex;
501
500
  for (let i = eqIndex; i >= 0; i--) {
502
501
  const st = seq.steps[i];
503
- const name = st?.constructor?.name;
504
- if (st instanceof omdOperationDisplayNode || name === 'omdOperationDisplayNode') { startIndex = i; break; }
502
+ if (st instanceof omdOperationDisplayNode || st?.type === 'omdOperationDisplayNode') { startIndex = i; break; }
505
503
  }
506
504
  // Remove DOM children and steps from startIndex to end
507
505
  for (let i = seq.steps.length - 1; i >= startIndex; i--) {
@@ -546,7 +544,7 @@ export class omdEquationStack extends jsvgGroup {
546
544
 
547
545
  // Safety: ensure dot/line counts match equations and prune orphan dots
548
546
  try {
549
- const isEquation = (s) => (s instanceof omdEquationNode) || (s?.constructor?.name === 'omdEquationNode');
547
+ const isEquation = (s) => (s instanceof omdEquationNode) || (s?.type === 'omdEquationNode');
550
548
  const equationsCount = Array.isArray(seq.steps) ? seq.steps.filter(isEquation).length : 0;
551
549
 
552
550
  // Remove dots whose equationRef is no longer present in steps
@@ -535,8 +535,9 @@ export class omdDisplay {
535
535
  // Detect step visualizer directly on node (getSequence returns underlying sequence only)
536
536
  let hasStepVisualizer = false;
537
537
  if (this.node) {
538
- const ctorName = this.node.constructor?.name;
539
- hasStepVisualizer = (ctorName === 'omdStepVisualizer') || this.node.type === 'omdStepVisualizer' || (typeof omdStepVisualizer !== 'undefined' && this.node instanceof omdStepVisualizer);
538
+ hasStepVisualizer =
539
+ this.node.type === 'omdStepVisualizer' ||
540
+ (typeof omdStepVisualizer !== 'undefined' && this.node instanceof omdStepVisualizer);
540
541
  }
541
542
 
542
543
  if (hasStepVisualizer) {
@@ -997,7 +997,7 @@ export class omdEquationSequenceNode extends omdNode {
997
997
  // If visibility is explicitly false, skip
998
998
  if (step.visible === false) continue;
999
999
  // Prefer equation nodes when present
1000
- if (step.constructor?.name === 'omdEquationNode') {
1000
+ if (step instanceof omdEquationNode || step.type === 'omdEquationNode') {
1001
1001
  chosenIndex = i;
1002
1002
  break;
1003
1003
  }
@@ -1278,4 +1278,4 @@ export class omdEquationSequenceNode extends omdNode {
1278
1278
  this.computeDimensions();
1279
1279
  this.updateLayout();
1280
1280
  }
1281
- }
1281
+ }
@@ -388,7 +388,7 @@ export class omdStepVisualizerLayout {
388
388
  // Debug all steps and their properties
389
389
 
390
390
  sv.steps.forEach((step, i) => {
391
- if (step && (step instanceof omdEquationNode || step.constructor.name === 'omdEquationNode')) {
391
+ if (step && (step instanceof omdEquationNode || step.type === 'omdEquationNode')) {
392
392
 
393
393
  } else {
394
394
 
@@ -410,7 +410,7 @@ export class omdStepVisualizerLayout {
410
410
  // Check for hidden intermediate steps between consecutive visible major steps (stepMark = 0)
411
411
  const visibleMajorSteps = [];
412
412
  sv.steps.forEach((step, stepIndex) => {
413
- if (step && (step instanceof omdEquationNode || step.constructor.name === 'omdEquationNode')) {
413
+ if (step && (step instanceof omdEquationNode || step.type === 'omdEquationNode')) {
414
414
  if (step.stepMark === 0 && step.visible === true) {
415
415
  visibleMajorSteps.push(stepIndex);
416
416
 
@@ -431,7 +431,7 @@ export class omdStepVisualizerLayout {
431
431
  let hiddenIntermediateCount = 0;
432
432
  for (let j = previousMajorStepIndex + 1; j < currentMajorStepIndex; j++) {
433
433
  const step = sv.steps[j];
434
- if (step && (step instanceof omdEquationNode || step.constructor.name === 'omdEquationNode')) {
434
+ if (step && (step instanceof omdEquationNode || step.type === 'omdEquationNode')) {
435
435
  if (step.stepMark > 0 && step.visible === false) {
436
436
  hiddenIntermediateCount++;
437
437
 
@@ -498,7 +498,7 @@ export class omdStepVisualizerLayout {
498
498
  // Count intermediate steps between these two major steps
499
499
  for (let i = fromStepIndex + 1; i < toStepIndex; i++) {
500
500
  const step = sv.steps[i];
501
- if (step && (step instanceof omdEquationNode || step.constructor.name === 'omdEquationNode')) {
501
+ if (step && (step instanceof omdEquationNode || step.type === 'omdEquationNode')) {
502
502
  // Count intermediate steps (stepMark > 0) that are currently hidden
503
503
  if (step.stepMark !== undefined && step.stepMark > 0 && step.visible === false) {
504
504
 
@@ -680,7 +680,7 @@ export class omdStepVisualizerLayout {
680
680
  let majorStepAfterIndex = -1;
681
681
  for (let i = lastIntermediateStepIndex + 1; i < sv.steps.length; i++) {
682
682
  const step = sv.steps[i];
683
- if (step && (step instanceof omdEquationNode || step.constructor.name === 'omdEquationNode')) {
683
+ if (step && (step instanceof omdEquationNode || step.type === 'omdEquationNode')) {
684
684
  if (step.stepMark === 0 && step.visible === true) {
685
685
  majorStepAfterIndex = i;
686
686
 
@@ -774,7 +774,7 @@ export class omdStepVisualizerLayout {
774
774
  // Show all intermediate steps between the previous and current major steps
775
775
  for (let i = previousStepIndex + 1; i < majorStepIndex; i++) {
776
776
  const step = sv.steps[i];
777
- if (step && (step instanceof omdEquationNode || step.constructor.name === 'omdEquationNode')) {
777
+ if (step && (step instanceof omdEquationNode || step.type === 'omdEquationNode')) {
778
778
  if (step.stepMark > 0) {
779
779
 
780
780
  this._showStep(step);
@@ -890,4 +890,4 @@ export class omdStepVisualizerLayout {
890
890
 
891
891
 
892
892
  }
893
- }
893
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teachinglab/omd",
3
- "version": "0.7.35",
3
+ "version": "0.7.37",
4
4
  "description": "omd",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",
@@ -348,11 +348,14 @@ export class omdCoordinatePlane extends jsvgGroup {
348
348
  addTickLabel(gridHolder, isXAxis, pos, value) {
349
349
  const label = this.createNumericLabel(value);
350
350
  if (isXAxis) {
351
- const lx = Math.max(10, Math.min(pos - 10, this.width - 30));
351
+ const labelWidth = label.width || 20;
352
+ const lx = Math.max(10, Math.min(pos - labelWidth / 2, this.width - labelWidth - 10));
352
353
  label.setPosition(lx, this.height - this.paddingBottom + this.tickLabelOffsetPx);
353
354
  } else {
354
- const lx = Math.max(5, this.paddingLeft - (this.tickLabelOffsetPx + 20));
355
- const ly = Math.max(7.5, Math.min(pos - 7.5, this.height - 15));
355
+ const labelWidth = label.width || 20;
356
+ const labelHeight = label.height || 15;
357
+ const lx = Math.max(5, this.paddingLeft - (this.tickLabelOffsetPx + labelWidth));
358
+ const ly = Math.max(labelHeight / 2, Math.min(pos - labelHeight / 2, this.height - labelHeight));
356
359
  label.setPosition(lx, ly);
357
360
  }
358
361
  gridHolder.addChild(label);
@@ -366,10 +369,17 @@ export class omdCoordinatePlane extends jsvgGroup {
366
369
  }
367
370
 
368
371
  createNumericLabel(text) {
372
+ const textString = String(text);
373
+ const fontSize = 9;
374
+ const horizontalPadding = 6;
375
+ const verticalPadding = 4;
376
+ const estimatedCharWidth = fontSize * 0.58;
377
+ const labelWidth = Math.max(20, Math.ceil(textString.length * estimatedCharWidth) + horizontalPadding * 2);
378
+ const labelHeight = fontSize + verticalPadding * 2;
369
379
  const label = new jsvgTextBox();
370
- label.setWidthAndHeight(20, 15);
371
- label.setText(String(text));
372
- label.setFontSize(9);
380
+ label.setWidthAndHeight(labelWidth, labelHeight);
381
+ label.setText(textString);
382
+ label.setFontSize(fontSize);
373
383
  label.setFontColor(this.getAllowedColor("black"));
374
384
  label.setAlignment("center");
375
385
  label.setVerticalCentering();