From 059b9645d6baed8c8c006bc598d68490f37edc93 Mon Sep 17 00:00:00 2001
From: Marcus Poeckelmann <marcus.poeckelmann@informatik.uni-halle.de>
Date: Wed, 15 Mar 2023 16:19:52 +0100
Subject: [PATCH] v2.5.1: added method to place the brushing tool a specific
 position

---
 README     |  2 +-
 catview.js | 37 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/README b/README
index 0176752..a3c801b 100644
--- a/README
+++ b/README
@@ -1,6 +1,6 @@
 Thank you for using CATview - the Colored & Aligned Texts view.
 
-This is version 2.5.
+This is version 2.5.1
 
 For information about the features and usage of CATview, please visit:
 https://catview.uzi.uni-halle.de
diff --git a/catview.js b/catview.js
index ca7bb63..d6e2ec8 100644
--- a/catview.js
+++ b/catview.js
@@ -22,7 +22,7 @@
  SOFTWARE.
 */
 
-// CATview - the Colored & Aligned Texts view - version 2.5
+// CATview - the Colored & Aligned Texts view - version 2.5.1
 const CATview = new function() {
   this.debug = false;
 
@@ -1636,6 +1636,41 @@ const CATview = new function() {
       return false;
   };
 
+  // place brush at a specific position (defined by indices)
+  this.place_brush = function(_from, _to, _trigger_callback, _trigger_end_callback){
+    if(CATview.debug)
+      console.log('CATview.place_brush: ' + _from + ', ' + _to);
+
+    // enable brush as it might be currently uninitialized
+    CATview.enable_brush();
+
+    // save the new interval
+    let brush_range = _to - _from + 1;
+    CATview.brush_from_edge = _from;
+    CATview.brush_to_edge = _to;
+    CATview.brush_range = brush_range;
+
+    // draw the new interval
+    if(CATview.x_inverted) {
+      CATview.brush.move(d3.select(".brush"),
+        [_to + 1.0 + CATview.brush_offset_to, _from + 1.0 + CATview.brush_offset_from].map(CATview.scale_edges));
+    }
+    else {
+      CATview.brush.move(d3.select(".brush"),
+        [_from + 1.0 + CATview.brush_offset_from, _to + 1.0 + CATview.brush_offset_to].map(CATview.scale_edges))
+    }
+
+    // may trigger callbacks
+    if (_trigger_callback && CATview.brush_callback != null) {
+      CATview.brush_callback(_from, _to); //, from_name, to_name);
+    }
+    if (_trigger_end_callback && CATview.brush_end_callback != null) {
+      CATview.brush_end_callback(_from, _to); //, from_name, to_name);
+    }
+
+    return true;
+  }
+
   // set the callback after brushing
   this.set_brush_callback = function(brush_callback) {
     CATview.brush_callback = brush_callback;
-- 
GitLab