Add reciprocal (1/x) scale mapping
This commit is contained in:
+1
-1
@@ -15,7 +15,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: m1730-generator
|
||||
image: git.baumann.gr/adebaumann/m1730-generator:0.81
|
||||
image: git.baumann.gr/adebaumann/m1730-generator:0.82
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 5000
|
||||
|
||||
+14
-1
@@ -8,7 +8,7 @@ from fontTools.pens.svgPathPen import SVGPathPen
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
VERSION = "0.81"
|
||||
VERSION = "0.82"
|
||||
|
||||
_LOGO_PATH = pathlib.Path(__file__).parent / 'static' / 'logo.png'
|
||||
_LOGO_B64 = base64.b64encode(_LOGO_PATH.read_bytes()).decode()
|
||||
@@ -362,6 +362,19 @@ def generate_svg(unit, min_val, max_val, range_label, big_ticks, small_ticks, la
|
||||
def major_value(i):
|
||||
return min_val + span * (i / big_ticks) ** 2
|
||||
|
||||
elif scale_type == 'reciprocal':
|
||||
if min_val <= 0 or max_val <= 0:
|
||||
raise ValueError("Reciprocal scale requires min and max values greater than 0.")
|
||||
if max_val <= min_val:
|
||||
raise ValueError("Reciprocal scale requires max value greater than min.")
|
||||
k = 1.0 / min_val - 1.0 / max_val # always positive
|
||||
|
||||
def value_to_x(v):
|
||||
return ZERO_X + SCALE_LEN * (1.0 / v - 1.0 / max_val) / k
|
||||
|
||||
def major_value(i):
|
||||
return 1.0 / (1.0 / max_val + i / big_ticks * k)
|
||||
|
||||
else:
|
||||
span = max_val - min_val
|
||||
|
||||
|
||||
@@ -322,6 +322,8 @@
|
||||
title="Square-root scale — ticks crowd at the low end; used for RMS current/power meters. Min must be ≥ 0">√</button>
|
||||
<button type="button" class="mode-btn" data-scale="log"
|
||||
title="Values spaced logarithmically — requires min and max greater than 0">Log</button>
|
||||
<button type="button" class="mode-btn" data-scale="reciprocal"
|
||||
title="Reciprocal (1/x) scale — values decrease left to right; used for resistance (ohms) scales. Min and Max must be greater than 0, Max greater than Min">1/x</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
@@ -442,6 +444,9 @@
|
||||
if (!(parseFloat(maxInput.value) > 0)) maxInput.value = '100';
|
||||
} else if (btn.dataset.scale === 'sqrt') {
|
||||
if (parseFloat(minInput.value) < 0) minInput.value = '0';
|
||||
} else if (btn.dataset.scale === 'reciprocal') {
|
||||
if (!(parseFloat(minInput.value) > 0)) minInput.value = '1';
|
||||
if (!(parseFloat(maxInput.value) > parseFloat(minInput.value))) maxInput.value = String(parseFloat(minInput.value) * 10);
|
||||
}
|
||||
}
|
||||
doGenerate();
|
||||
|
||||
Reference in New Issue
Block a user