From ef040467772668410e7d23b136cecdbce453848c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marcus=20P=C3=B6ckelmann?=
 <marcus.poeckelmann@informatik.uni-halle.de>
Date: Wed, 17 Nov 2021 14:04:03 +0100
Subject: [PATCH] Bugfix: initial inverted edges-axis

---
 catview.js | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/catview.js b/catview.js
index 5e4b62a..352c717 100644
--- a/catview.js
+++ b/catview.js
@@ -936,7 +936,8 @@ const CATview = new function() {
 
     if(CATview.content){
       CATview.set_margins();
-      CATview.set_scale_x();
+      CATview.set_scale_x(0, CATview.edges.length + 1);
+      CATview.scale_edges_original = CATview.scale_edges.copy();
       // relocate the content container
       CATview.svg.select(".content").attr("transform", "translate(" + CATview.margin.left + "," + CATview.margin.top + ")");
       CATview.draw_zebra_stripes();
@@ -991,8 +992,6 @@ const CATview = new function() {
 
     let new_scale = d3.event.transform.k;
     let new_translate = CATview.vertical == true ? (d3.event.transform.y/new_scale) : (d3.event.transform.x/new_scale);
-    if(CATview.x_inverted)
-      new_translate = -new_translate;
 
     if(CATview.content){
 
@@ -1039,10 +1038,14 @@ const CATview = new function() {
       CATview.translate = new_translate;
       CATview.scale = new_scale;
 
-
       // calculate the edges within this new zoom
       let new_from = Math.ceil(CATview.scale_edges_original.invert(new_from_pixel));
       let new_to = Math.floor(CATview.scale_edges_original.invert(new_to_pixel));
+      if(CATview.x_inverted){
+        let swap = new_from;
+        new_from = new_to;
+        new_to = swap;
+      }
       if(new_from != CATview.from || new_to != CATview.to) {
         // refresh the content only if edges within the new zoom have changed
         CATview.refresh_content(new_from, new_to);
-- 
GitLab