From 0c35d0de6018dc874f2558135bab96cc640a44c9 Mon Sep 17 00:00:00 2001
From: Frank Sauerburger <frank@sauerburger.com>
Date: Fri, 20 Aug 2021 13:11:17 +0200
Subject: [PATCH] Add fallback for non-subset binning

---
 uhepp-js/src/components/UheppHistUI.jsx | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/uhepp-js/src/components/UheppHistUI.jsx b/uhepp-js/src/components/UheppHistUI.jsx
index 5cb81b1..829d100 100644
--- a/uhepp-js/src/components/UheppHistUI.jsx
+++ b/uhepp-js/src/components/UheppHistUI.jsx
@@ -249,8 +249,6 @@ const UheppHistUIWithSyst = ({
     setRebin(uhepp.bins.rebin || uhepp.bins.edges)
     setDensity(uhepp.bins.density_width)
     onReset()
-
-
   }
 
   const handleRebin = (e) => {
@@ -276,9 +274,22 @@ const UheppHistUIWithSyst = ({
     setIsClean(false)
   }
 
+  // Fallback to original rebin or original binning
+  const takeFirstIfSubset = (rebin, orig) => {
+    let isSubset = true
+    rebin.forEach(e => {
+      if (orig.indexOf(e) < 0) {
+        isSubset = false
+      }
+    })
+    return isSubset ? rebin : orig
+  }
+  const rebin_singleFallback = rebin.length > 1 ? rebin : (uhepp.bins.rebin)
+  const rebin_subsetFallback = takeFirstIfSubset(rebin_singleFallback, uhepp.bins.edges)
+
   const uhepp_derived = Object.assign({}, uhepp,
       {bins: Object.assign({}, uhepp.bins, {
-          rebin: rebin.length > 1 ? rebin : (uhepp.bins.rebin),
+          rebin: rebin_subsetFallback,
           include_underflow,
           include_overflow,
           density_width,
-- 
GitLab