@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 +1 -1
- package/src/omdCoordinatePlane.js +16 -6
package/package.json
CHANGED
|
@@ -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
|
|
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
|
|
355
|
-
const
|
|
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(
|
|
371
|
-
label.setText(
|
|
372
|
-
label.setFontSize(
|
|
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();
|