Add configurable label font size; bump to 0.76
- New "Label size (mm)" field controlling the numeric-label font size, defaulting to a clean 9 mm (was the inherited Inkscape value 8.89194) - Pin k8s deployment to image tag 0.76
This commit is contained in:
+6
-5
@@ -8,7 +8,7 @@ from fontTools.pens.svgPathPen import SVGPathPen
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
VERSION = "0.75"
|
||||
VERSION = "0.76"
|
||||
|
||||
_LOGO_PATH = pathlib.Path(__file__).parent / 'static' / 'logo.png'
|
||||
_LOGO_B64 = base64.b64encode(_LOGO_PATH.read_bytes()).decode()
|
||||
@@ -93,7 +93,7 @@ def _text_to_paths(text, x, y, font_size, anchor='start', fill='#1a1a1a', wrap_t
|
||||
|
||||
|
||||
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):
|
||||
use_paths=True, log_scale=False, custom_labels=None, label_size=9):
|
||||
if log_scale:
|
||||
if min_val <= 0 or max_val <= 0:
|
||||
raise ValueError("Logarithmic scale requires min and max values greater than 0.")
|
||||
@@ -197,10 +197,10 @@ def generate_svg(unit, min_val, max_val, range_label, big_ticks, small_ticks, la
|
||||
x = big_xs[idx]
|
||||
label = custom_labels[k] if custom_labels else _fmt(big_vals[idx])
|
||||
if use_paths:
|
||||
parts.append(' ' + _text_to_paths(label, x, 101.49598, 8.89194, anchor='middle'))
|
||||
parts.append(' ' + _text_to_paths(label, x, 101.49598, label_size, anchor='middle'))
|
||||
else:
|
||||
parts.append(
|
||||
f' <text style="font-size:8.89194px;font-family:\'ГОСТ тип А\',monospace;fill:#1a1a1a"'
|
||||
f' <text style="font-size:{label_size:.5f}px;font-family:\'ГОСТ тип А\',monospace;fill:#1a1a1a"'
|
||||
f' text-anchor="middle" x="{x:.5f}" y="101.49598">{escape(label)}</text>'
|
||||
)
|
||||
|
||||
@@ -226,10 +226,11 @@ def generate():
|
||||
log_scale = request.form.get('scale_type', 'linear') == 'log'
|
||||
|
||||
custom_labels = [s.strip() for s in request.form.get('labels', '').split(',') if s.strip()] or None
|
||||
label_size = max(0.5, min(25.0, float(request.form.get('label_size', 9))))
|
||||
|
||||
try:
|
||||
svg = generate_svg(unit, min_val, max_val, range_label, big_ticks, small_ticks,
|
||||
label_count, use_paths, log_scale, custom_labels)
|
||||
label_count, use_paths, log_scale, custom_labels, label_size)
|
||||
except ValueError as err:
|
||||
return Response(str(err), status=400, mimetype='text/plain')
|
||||
return Response(svg, mimetype='image/svg+xml')
|
||||
|
||||
Reference in New Issue
Block a user