Fix sqrt minor ticks: crowd toward low end via squared position

This commit is contained in:
2026-07-14 19:27:40 +02:00
parent 73917aca1e
commit 846fe2d235
2 changed files with 15 additions and 6 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ spec:
spec: spec:
containers: containers:
- name: m1730-generator - name: m1730-generator
image: git.baumann.gr/adebaumann/m1730-generator:0.78 image: git.baumann.gr/adebaumann/m1730-generator:0.79
imagePullPolicy: Always imagePullPolicy: Always
ports: ports:
- containerPort: 5000 - containerPort: 5000
+14 -5
View File
@@ -8,7 +8,7 @@ from fontTools.pens.svgPathPen import SVGPathPen
app = Flask(__name__) app = Flask(__name__)
VERSION = "0.78" VERSION = "0.79"
_LOGO_PATH = pathlib.Path(__file__).parent / 'static' / 'logo.png' _LOGO_PATH = pathlib.Path(__file__).parent / 'static' / 'logo.png'
_LOGO_B64 = base64.b64encode(_LOGO_PATH.read_bytes()).decode() _LOGO_B64 = base64.b64encode(_LOGO_PATH.read_bytes()).decode()
@@ -444,14 +444,23 @@ def generate_svg(unit, min_val, max_val, range_label, big_ticks, small_ticks, la
f' style="stroke:#1a1a1a;stroke-width:0.555;stroke-linecap:butt" />' f' style="stroke:#1a1a1a;stroke-width:0.555;stroke-linecap:butt" />'
) )
# Minor ticks — evenly spaced in value, then positioned by the scale mapping. # Minor ticks — placement depends on scale type:
# On a linear scale this is uniform; on a log scale they crowd toward the high end. # linear: uniform physical spacing (= uniform value spacing)
# log: linear value interpolation between geometric major values
# (crowds toward high end of each interval)
# sqrt: sqrt of fractional position within each interval, giving
# consistent high-end crowding across all intervals; using
# value interpolation instead would concentrate the crowding
# only near zero (where sqrt is steepest) and look linear elsewhere.
if small_ticks > 0: if small_ticks > 0:
sub = small_ticks + 1 sub = small_ticks + 1
for i in range(big_ticks): for i in range(big_ticks):
for j in range(1, small_ticks + 1): for j in range(1, small_ticks + 1):
v = big_vals[i] + j * (big_vals[i + 1] - big_vals[i]) / sub if scale_type == 'sqrt':
x = value_to_x(v) x = big_xs[i] + (j / sub) ** 2 * (big_xs[i + 1] - big_xs[i])
else:
v = big_vals[i] + j * (big_vals[i + 1] - big_vals[i]) / sub
x = value_to_x(v)
parts.append( parts.append(
f' <line x1="{x:.5f}" y1="{BAR_Y}" x2="{x:.5f}" y2="{BAR_Y - SMALL_H:.5f}"' f' <line x1="{x:.5f}" y1="{BAR_Y}" x2="{x:.5f}" y2="{BAR_Y - SMALL_H:.5f}"'
f' style="stroke:#1a1a1a;stroke-width:0.302;stroke-linecap:butt" />' f' style="stroke:#1a1a1a;stroke-width:0.302;stroke-linecap:butt" />'