From d01292ed4fa2877d626daa4e20354068afdbb8c0 Mon Sep 17 00:00:00 2001 From: Fabio Critone Date: Mon, 9 Sep 2024 14:15:40 +0200 Subject: [PATCH 1/6] Update main.js --- src/main.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.js b/src/main.js index f531621..5981741 100644 --- a/src/main.js +++ b/src/main.js @@ -819,10 +819,16 @@ class MiniGraphCard extends LitElement { // Doesn't matter if minBoundRange is NaN because this will be false if so if (diff > 0) { - boundary = [ - boundary[0] - diff / 2, - boundary[1] + diff / 2, - ]; + if (min !== undefined && max === undefined) { + boundary[1] += diff; + } else if (max !== undefined && min === undefined) { + boundary[0] -= diff; + } else { + boundary = [ + boundary[0] - diff / 2, + boundary[1] + diff / 2, + ]; + } } } From 81b0365f0bb397b201835acf72b271463caa7545 Mon Sep 17 00:00:00 2001 From: Fabio Critone Date: Wed, 11 Sep 2024 12:21:56 +0200 Subject: [PATCH 2/6] added soft bound handling - @akloeckner --- src/main.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.js b/src/main.js index 5981741..44ba649 100644 --- a/src/main.js +++ b/src/main.js @@ -819,10 +819,16 @@ class MiniGraphCard extends LitElement { // Doesn't matter if minBoundRange is NaN because this will be false if so if (diff > 0) { - if (min !== undefined && max === undefined) { - boundary[1] += diff; - } else if (max !== undefined && min === undefined) { - boundary[0] -= diff; + const weights = [ + min !== undefined && min[0] !== '~' ? 0 : 1, + max !== undefined && max[0] !== '~' ? 0 : 1, + ]; + const sum = weights[0] + weights[1]; + if (sum > 0) { + boundary = [ + boundary[0] - diff * weights[0] / sum, + boundary[1] + diff * weights[1] / sum, + ]; } else { boundary = [ boundary[0] - diff / 2, From d478dec8639670a4702b34fce5c00225514e6281 Mon Sep 17 00:00:00 2001 From: Fabio Critone Date: Wed, 11 Sep 2024 14:39:46 +0200 Subject: [PATCH 3/6] updated the behavior in case of a soft bound present --- src/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.js b/src/main.js index 44ba649..93878ec 100644 --- a/src/main.js +++ b/src/main.js @@ -820,8 +820,8 @@ class MiniGraphCard extends LitElement { // Doesn't matter if minBoundRange is NaN because this will be false if so if (diff > 0) { const weights = [ - min !== undefined && min[0] !== '~' ? 0 : 1, - max !== undefined && max[0] !== '~' ? 0 : 1, + min !== undefined && min[0] !== '~' ? 0 : (max === undefined && min !== undefined ? 0 : 1), + max !== undefined && max[0] !== '~' ? 0 : (min === undefined && min !== undefined ? 0 : 1), ]; const sum = weights[0] + weights[1]; if (sum > 0) { From dfb0a97977d36e66393be0e5f87f985427c45579 Mon Sep 17 00:00:00 2001 From: Fabio Critone Date: Wed, 11 Sep 2024 15:00:55 +0200 Subject: [PATCH 4/6] removed redundant code --- src/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.js b/src/main.js index 93878ec..148769f 100644 --- a/src/main.js +++ b/src/main.js @@ -820,8 +820,8 @@ class MiniGraphCard extends LitElement { // Doesn't matter if minBoundRange is NaN because this will be false if so if (diff > 0) { const weights = [ - min !== undefined && min[0] !== '~' ? 0 : (max === undefined && min !== undefined ? 0 : 1), - max !== undefined && max[0] !== '~' ? 0 : (min === undefined && min !== undefined ? 0 : 1), + min !== undefined && min[0] !== '~' ? 0 : (max === undefined ? 0 : 1), + max !== undefined && max[0] !== '~' ? 0 : (min === undefined ? 0 : 1), ]; const sum = weights[0] + weights[1]; if (sum > 0) { From f4573773ba95c51f61d12f5e90c67ccad3feb359 Mon Sep 17 00:00:00 2001 From: Fabio Critone Date: Wed, 11 Sep 2024 18:48:02 +0200 Subject: [PATCH 5/6] simplified the code Co-authored-by: akloeckner --- src/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.js b/src/main.js index 148769f..06f2894 100644 --- a/src/main.js +++ b/src/main.js @@ -820,7 +820,7 @@ class MiniGraphCard extends LitElement { // Doesn't matter if minBoundRange is NaN because this will be false if so if (diff > 0) { const weights = [ - min !== undefined && min[0] !== '~' ? 0 : (max === undefined ? 0 : 1), + min !== undefined && min[0] !== '~' || max === undefined ? 0 : 1, max !== undefined && max[0] !== '~' ? 0 : (min === undefined ? 0 : 1), ]; const sum = weights[0] + weights[1]; From 3b358955321dc1f6e98a7c25c2f3d86767b2ee62 Mon Sep 17 00:00:00 2001 From: Fabio Critone Date: Wed, 11 Sep 2024 18:49:04 +0200 Subject: [PATCH 6/6] other half of the code simplifying --- src/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.js b/src/main.js index 06f2894..a31127c 100644 --- a/src/main.js +++ b/src/main.js @@ -821,7 +821,7 @@ class MiniGraphCard extends LitElement { if (diff > 0) { const weights = [ min !== undefined && min[0] !== '~' || max === undefined ? 0 : 1, - max !== undefined && max[0] !== '~' ? 0 : (min === undefined ? 0 : 1), + max !== undefined && max[0] !== '~' || min === undefined ? 0 : 1, ]; const sum = weights[0] + weights[1]; if (sum > 0) {