From 4cc840af4d1ff4cc330186cf01a0b3ad738c0cb0 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Sun, 8 Dec 2024 19:32:51 +0100 Subject: [PATCH] add step function to fine tune screener --- src/routes/stock-screener/+page.svelte | 135 +++++++++++++++++-------- 1 file changed, 92 insertions(+), 43 deletions(-) diff --git a/src/routes/stock-screener/+page.svelte b/src/routes/stock-screener/+page.svelte index 5f48a9ff..24340ca0 100644 --- a/src/routes/stock-screener/+page.svelte +++ b/src/routes/stock-screener/+page.svelte @@ -1939,6 +1939,40 @@ const handleKeyDown = (event) => { } } + async function stepSizeValue(value, condition) { + const match = value.toString().match(/^(-?[\d.]+)([KMB%]?)$/); + if (!match) return value; + + let [_, number, suffix] = match; + number = parseFloat(number); + + // Step sizes for each suffix + const stepMap = { + B: 0.1, // Billion + M: 10, // Million (default step) + K: 100, // Thousand + "%": 1, // Percent + "": 1, // Plain numbers + }; + + let step = 1; + + number += condition === "add" ? step : -step; + + // Round to 2 decimal places for consistency + number = parseFloat(number?.toFixed(2)); + const newValue = suffix ? `${number}${suffix}` : Math?.round(number); + await handleChangeValue(newValue); + } + + async function handleValueInput(event) { + const newValue = event.target.value; + if (newValue?.length > 0) { + console.log("yes"); + await handleChangeValue(newValue); + } + } + async function popularStrategy(state: string) { ruleOfList = []; const strategies = { @@ -2725,7 +2759,7 @@ const handleKeyDown = (event) => { {#if !["sma20", "sma50", "sma100", "sma200", "ema20", "ema50", "ema100", "ema200", "grahamNumber", "analystRating", "halalStocks", "score", "sector", "industry", "country"]?.includes(row?.rule)} { class="flex items-center justify-start gap-x-1" > -
+
+ + handleValueInput(e)} + class=" ios-zoom-fix block max-w-[4.8rem] rounded-sm placeholder:text-gray-200 font-normal p-1 text-sm shadow-sm focus:border-blue-500 focus:ring-blue-500 bg-secondary" + /> + +
+ + +
@@ -2894,46 +2983,6 @@ const handleKeyDown = (event) => { - - - - -