Ticket #6: zoomin-0.1.patch

File zoomin-0.1.patch, 2.1 KB (added by runesk, at 2009-10-21T09:10:10+02:00)

A patch for zoomin to make right-to-left-select in graphs

  • zoomin-0.

    diff -ruN zoomin-0.1/zoom.js zoomin-0.1-new/zoom.js
    old new  
    1 var zoom_leftMost; 
     1var zoom_start; 
     2var graph_target; 
    23 
    34function zoom_reset() { 
    45    var sb = document.getElementById('selectionBox'); 
     
    1718    var ev = (window.event) ? event : e; 
    1819    var el = (ev.target) ? ev.target : ev.srcElement; 
    1920    var sb = document.getElementById('selectionBox'); 
    20     sb.style.width = (ev.clientX - sb.offsetLeft) + "px"; 
     21    if (zoom_start < ev.clientX) { 
     22      sb.style.width = (ev.clientX - zoom_start) + "px"; 
     23    } else { 
     24      sb.style.width = (zoom_start - ev.clientX) + "px"; 
     25      sb.style.left = ev.clientX + "px"; 
     26    }     
    2127} 
    2228 
    2329function zoom_onclick_step2(e) { 
    2430    var ev = (window.event) ? event : e; 
    25     var el = (ev.target) ? ev.target : ev.srcElement; 
    2631    var sb = document.getElementById('selectionBox'); 
    27     var rightMost = ev.clientX - el.x; 
    28     var graphUrl = el.getAttribute("src"); 
    29     window.location.href = "/munin/zoom.php?x1=" + zoom_leftMost + "&x2=" + rightMost + "&graph=" + escape(graphUrl); 
     32    var rightMost, leftMost 
     33    if(zoom_start < ev.clientX) { 
     34      rightMost = ev.clientX - graph_target.x; 
     35      leftMost = zoom_start - graph_target.x; 
     36    } else { 
     37      leftMost = ev.clientX - graph_target.x; 
     38      rightMost = zoom_start - graph_target.x; 
     39    } 
     40    var graphUrl = graph_target.getAttribute("src"); 
     41    window.location.href = "/munin/zoom.php?x1=" + leftMost + "&x2=" + rightMost + "&graph=" + escape(graphUrl); 
    3042    zoom_reset(); 
    3143} 
    3244 
     
    3547    var el = (ev.target) ? ev.target : ev.srcElement; 
    3648    var sb = document.getElementById('selectionBox'); 
    3749    sb.style.display = 'block'; 
    38     zoom_leftMost = ev.clientX - el.x; 
     50    zoom_start = ev.clientX; 
     51    graph_target = el; 
    3952    sb.style.left = ev.clientX + "px"; 
    4053    sb.style.width = "1px"; 
    4154    sb.style.top = (el.y + 35) + "px"; // Constant 
    4255    el.onmousemove = zoom_selectionbox_resize; 
    4356    sb.onmousemove = zoom_selectionbox_resize; 
     57    sb.onclick = zoom_onclick_step2; 
    4458    el.onclick = zoom_onclick_step2; 
    4559} 
    4660