diff --git a/web/app.py b/web/app.py
index b25585b..5f87b58 100644
--- a/web/app.py
+++ b/web/app.py
@@ -1,4 +1,5 @@
import base64
+import math
import pathlib
from flask import Flask, render_template, request, Response
from html import escape
@@ -7,7 +8,7 @@ from fontTools.pens.svgPathPen import SVGPathPen
app = Flask(__name__)
-VERSION = "0.72"
+VERSION = "0.75"
_LOGO_PATH = pathlib.Path(__file__).parent / 'static' / 'logo.png'
_LOGO_B64 = base64.b64encode(_LOGO_PATH.read_bytes()).decode()
@@ -49,9 +50,16 @@ def _unit_font_size(unit: str) -> float:
def _fmt(v: float) -> str:
- if v == int(v):
- return str(int(v))
- return f"{v:.4g}"
+ # Snap near-integers — log-scale geometric values accumulate FP error
+ # (e.g. 9999.9999), which would otherwise miss the integer case.
+ r = round(v)
+ if abs(v - r) < 1e-9 * max(1.0, abs(v)):
+ return str(int(r))
+ # 4 significant figures in fixed-point notation (never scientific).
+ exp = math.floor(math.log10(abs(v)))
+ decimals = max(0, 4 - 1 - exp)
+ s = f"{v:.{decimals}f}"
+ return s.rstrip('0').rstrip('.') if '.' in s else s
def _text_to_paths(text, x, y, font_size, anchor='start', fill='#1a1a1a', wrap_transform=None):
@@ -84,12 +92,48 @@ def _text_to_paths(text, x, y, font_size, anchor='start', fill='#1a1a1a', wrap_t
return inner
-def generate_svg(unit, min_val, max_val, range_label, big_ticks, small_ticks, label_count, use_paths=True):
- big_interval = SCALE_LEN / big_ticks
- big_xs = [ZERO_X + i * big_interval for i in range(big_ticks + 1)]
+def generate_svg(unit, min_val, max_val, range_label, big_ticks, small_ticks, label_count,
+ use_paths=True, log_scale=False, custom_labels=None):
+ if log_scale:
+ if min_val <= 0 or max_val <= 0:
+ raise ValueError("Logarithmic scale requires min and max values greater than 0.")
+ lmin, lmax = math.log(min_val), math.log(max_val)
+ lspan = lmax - lmin
+ if lspan == 0:
+ raise ValueError("Logarithmic scale requires min and max values to differ.")
- label_count = max(2, min(label_count, big_ticks + 1))
- label_indices = [round(k * big_ticks / (label_count - 1)) for k in range(label_count)]
+ def value_to_x(v):
+ return ZERO_X + SCALE_LEN * (math.log(v) - lmin) / lspan
+
+ def major_value(i):
+ return min_val * (max_val / min_val) ** (i / big_ticks)
+ else:
+ span = max_val - min_val
+
+ def value_to_x(v):
+ if span == 0:
+ return ZERO_X
+ return ZERO_X + SCALE_LEN * (v - min_val) / span
+
+ def major_value(i):
+ return min_val + (max_val - min_val) * i / big_ticks
+
+ big_interval = SCALE_LEN / big_ticks
+ # Major ticks are always physically evenly spaced; only their values differ.
+ big_xs = [ZERO_X + i * big_interval for i in range(big_ticks + 1)]
+ big_vals = [major_value(i) for i in range(big_ticks + 1)]
+
+ # Custom labels, when supplied, override the calculated numbers and set the count.
+ if custom_labels:
+ label_count = max(1, min(len(custom_labels), big_ticks + 1))
+ custom_labels = custom_labels[:label_count]
+ else:
+ label_count = max(2, min(label_count, big_ticks + 1))
+
+ if label_count == 1:
+ label_indices = [0]
+ else:
+ label_indices = [round(k * big_ticks / (label_count - 1)) for k in range(label_count)]
parts = [
'',
@@ -135,22 +179,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" />'
)
- # Minor ticks
+ # Minor ticks — evenly spaced in value, then positioned by the scale mapping.
+ # On a linear scale this is uniform; on a log scale they crowd toward the high end.
if small_ticks > 0:
sub = small_ticks + 1
for i in range(big_ticks):
for j in range(1, small_ticks + 1):
- x = big_xs[i] + j * big_interval / sub
+ v = big_vals[i] + j * (big_vals[i + 1] - big_vals[i]) / sub
+ x = value_to_x(v)
parts.append(
f'