@teachinglab/omd 0.7.36 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teachinglab/omd",
3
- "version": "0.7.36",
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();