summaryrefslogtreecommitdiffstats
path: root/htdocs/cropper/smokeping-zoom.js
blob: 90fcd3f67c2225762c3f64bdec617f2bc35674e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// example with minimum dimensions
var myCropper;

var StartEpoch = 0;
var EndEpoch = 0;

function changeRRDImage(coords,dimensions){

    var SelectLeft = Math.min(coords.x1,coords.x2);

    var SelectRight = Math.max(coords.x1,coords.x2);

    if (SelectLeft == SelectRight)
         return; // abort if nothing is selected.

    var RRDLeft  = 67;        // difference between left border of RRD image and content
    var RRDRight = 26;        // difference between right border of RRD image and content
    var RRDImgWidth  = $('zoom').getDimensions().width;       // Width of the Smokeping RRD Graphik
    var RRDImgUsable = RRDImgWidth - RRDRight - RRDLeft;  

    if (StartEpoch == 0) 
        StartEpoch = $('epoch_start').value;
    if (EndEpoch  == 0)
        EndEpoch = $('epoch_end').value;
    var DivEpoch = EndEpoch - StartEpoch; 

    var Target = $('target').value;

    // Generate Selected Range in Unix Timestamps

    StartEpoch = Math.floor(StartEpoch + (((SelectLeft  - RRDLeft) / RRDImgUsable ) * DivEpoch));
    EndEpoch  = Math.ceil(StartEpoch + (((SelectRight - RRDLeft) / RRDImgUsable ) * DivEpoch));

    // construct Image URL

    $('zoom').src = myURL + "?displaymode=a;start=" + genStart+ ";end=" + genEnd + ";target=" + Target;
    myCropper.setParams();

};

Event.observe( 
           window, 
           'load', 
           function() { 
               myCropper = new Cropper.Img( 
                               'zoom', 
                                        { 
                                                minHeight: $('zoom').getDimensions().height,
                                                maxHeight: $('zoom').getDimensions().height,
                                                onEndCrop: changeRRDImage
                                        } 
                                ) 
                   }
           );