Tick size adjustable

This commit is contained in:
2026-07-31 14:59:51 +02:00
parent cfe4b48856
commit c549b1724a
2 changed files with 52 additions and 2 deletions
+22 -2
View File
@@ -447,6 +447,12 @@ def generate_svg(
custom_labels=None, custom_labels=None,
label_size=5.1126, label_size=5.1126,
font_key=None, font_key=None,
major_len=MAJOR_LEN,
major_w=MAJOR_W,
medium_len=MEDIUM_LEN,
medium_w=MEDIUM_W,
small_len=SMALL_LEN,
small_w=SMALL_W,
): ):
fd = ( fd = (
_FONTS.get(font_key) or _FONTS.get(_DEFAULT_FONT) or next(iter(_FONTS.values())) _FONTS.get(font_key) or _FONTS.get(_DEFAULT_FONT) or next(iter(_FONTS.values()))
@@ -589,7 +595,7 @@ def generate_svg(
) )
for angle in big_angles: for angle in big_angles:
parts.append(_tick_line(angle, MAJOR_LEN, MAJOR_W)) parts.append(_tick_line(angle, major_len, major_w))
if small_ticks > 0: if small_ticks > 0:
sub = small_ticks + 1 sub = small_ticks + 1
@@ -604,7 +610,7 @@ def generate_svg(
v = big_vals[i] + j * (big_vals[i + 1] - big_vals[i]) / sub v = big_vals[i] + j * (big_vals[i + 1] - big_vals[i]) / sub
angle = value_to_angle(v) angle = value_to_angle(v)
length, width = ( length, width = (
(MEDIUM_LEN, MEDIUM_W) if j == medium_j else (SMALL_LEN, SMALL_W) (medium_len, medium_w) if j == medium_j else (small_len, small_w)
) )
parts.append(_tick_line(angle, length, width)) parts.append(_tick_line(angle, length, width))
@@ -678,6 +684,14 @@ def generate():
small_ticks = max(0, min(20, int(request.form.get("small_ticks", 4)))) small_ticks = max(0, min(20, int(request.form.get("small_ticks", 4))))
label_count = max(2, int(request.form.get("label_count", 6))) label_count = max(2, int(request.form.get("label_count", 6)))
label_size = max(0.5, min(25.0, float(request.form.get("label_size", 5.1126)))) label_size = max(0.5, min(25.0, float(request.form.get("label_size", 5.1126))))
major_len = max(0.1, min(25.0, float(request.form.get("major_len", MAJOR_LEN))))
major_w = max(0.01, min(10.0, float(request.form.get("major_w", MAJOR_W))))
medium_len = max(
0.1, min(25.0, float(request.form.get("medium_len", MEDIUM_LEN)))
)
medium_w = max(0.01, min(10.0, float(request.form.get("medium_w", MEDIUM_W))))
small_len = max(0.1, min(25.0, float(request.form.get("small_len", SMALL_LEN))))
small_w = max(0.01, min(10.0, float(request.form.get("small_w", SMALL_W))))
if request.form.get("max_is_inf") == "1": if request.form.get("max_is_inf") == "1":
max_val = math.inf max_val = math.inf
@@ -695,6 +709,12 @@ def generate():
custom_labels, custom_labels,
label_size, label_size,
font_key, font_key,
major_len,
major_w,
medium_len,
medium_w,
small_len,
small_w,
) )
except ValueError as err: except ValueError as err:
return Response(str(err), status=400, mimetype="text/plain") return Response(str(err), status=400, mimetype="text/plain")
+30
View File
@@ -378,6 +378,36 @@ Right</textarea>
<input name="label_size" type="number" step="any" min="0.5" max="25" value="5.1126" required> <input name="label_size" type="number" step="any" min="0.5" max="25" value="5.1126" required>
</div> </div>
</div> </div>
<div class="row row-2" style="margin-top:1.25rem">
<div class="field">
<label>Major tick length (mm)</label>
<input name="major_len" type="number" step="any" min="0.1" max="25" value="4.8" required>
</div>
<div class="field">
<label>Major tick thickness (mm)</label>
<input name="major_w" type="number" step="any" min="0.01" max="10" value="0.8" required>
</div>
</div>
<div class="row row-2" style="margin-top:1.25rem">
<div class="field">
<label>Middle tick length (mm)</label>
<input name="medium_len" type="number" step="any" min="0.1" max="25" value="3.1" required>
</div>
<div class="field">
<label>Middle tick thickness (mm)</label>
<input name="medium_w" type="number" step="any" min="0.01" max="10" value="0.38" required>
</div>
</div>
<div class="row row-2" style="margin-top:1.25rem">
<div class="field">
<label>Minor tick length (mm)</label>
<input name="small_len" type="number" step="any" min="0.1" max="25" value="1.8" required>
</div>
<div class="field">
<label>Minor tick thickness (mm)</label>
<input name="small_w" type="number" step="any" min="0.01" max="10" value="0.28" required>
</div>
</div>
<div class="row row-2" style="margin-top:1.25rem"> <div class="row row-2" style="margin-top:1.25rem">
<div class="field"> <div class="field">
<label>Font</label> <label>Font</label>