@teachinglab/omd 0.2.1 → 0.2.2
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 +33 -5
package/package.json
CHANGED
|
@@ -131,6 +131,28 @@ export class omdCoordinatePlane extends jsvgGroup {
|
|
|
131
131
|
const lastTick = Math.floor(max);
|
|
132
132
|
const minLabelSpacing = 10;
|
|
133
133
|
|
|
134
|
+
// If forceAllTickLabels is false, choose a label multiple (5,10,15,...) that avoids overlap.
|
|
135
|
+
let labelMultiple = null;
|
|
136
|
+
if (!this.forceAllTickLabels && this.showTickLabels) {
|
|
137
|
+
const span = Math.abs(lastTick - firstTick);
|
|
138
|
+
// try multiples of 5 up to a reasonable cap based on span
|
|
139
|
+
const maxMultiple = Math.max(5, Math.ceil(span / 2) * 5);
|
|
140
|
+
for (let candidate = 5; candidate <= maxMultiple; candidate += 5) {
|
|
141
|
+
const positions = [];
|
|
142
|
+
let lastPos = -Infinity;
|
|
143
|
+
let ok = true;
|
|
144
|
+
for (let v = firstTick; v <= lastTick; v += interval) {
|
|
145
|
+
const isEdgeTick = v === firstTick || v === lastTick;
|
|
146
|
+
if (isEdgeTick || Number.isInteger(v / candidate)) {
|
|
147
|
+
const p = this.computeAxisPos(isXAxis, v);
|
|
148
|
+
if (Math.abs(p - lastPos) < minLabelSpacing) { ok = false; break; }
|
|
149
|
+
positions.push(p);
|
|
150
|
+
lastPos = p;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (ok && positions.length > 0) { labelMultiple = candidate; break; }
|
|
154
|
+
}
|
|
155
|
+
}
|
|
134
156
|
let lastLabelPos = -Infinity;
|
|
135
157
|
let zeroLineDrawn = false;
|
|
136
158
|
|
|
@@ -148,11 +170,17 @@ export class omdCoordinatePlane extends jsvgGroup {
|
|
|
148
170
|
}
|
|
149
171
|
|
|
150
172
|
const isEdgeTick = value === firstTick || value === lastTick;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
173
|
+
|
|
174
|
+
let shouldShowLabel = false;
|
|
175
|
+
if (this.showTickLabels) {
|
|
176
|
+
if (this.forceAllTickLabels) {
|
|
177
|
+
shouldShowLabel = true;
|
|
178
|
+
} else if (labelMultiple) {
|
|
179
|
+
shouldShowLabel = isEdgeTick || Number.isInteger(value / labelMultiple);
|
|
180
|
+
} else {
|
|
181
|
+
shouldShowLabel = isEdgeTick || Math.abs(pos - lastLabelPos) >= minLabelSpacing;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
156
184
|
|
|
157
185
|
if (shouldShowLabel) {
|
|
158
186
|
this.addTickLabel(gridHolder, isXAxis, pos, value);
|