Add reciprocal (1/x) scale mapping
This commit is contained in:
+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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user