/dev/adei-asec

To get this branch, use:
bzr branch http://darksoft.org/webbzr/dev/adei-asec

« back to all changes in this revision

Viewing changes to js/graph.js

  • Committer: Suren A. Chilingaryan
  • Date: 2011-03-15 02:47:05 UTC
  • mfrom: (210.1.3 adei)
  • Revision ID: csa@dside.dyndns.org-20110315024705-qljn30gwin8yrkne
Integration of work of students with fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
    this.height = 0;
16
16
    this.width = 0;
17
17
    
18
 
    this.device = this.getDevice();   
 
18
    this.idevice = isiDevice();   
19
19
    this.startX = 0; 
20
20
    this.startY = 0;
21
21
    this.curX = 0;  
26
26
    this.throwLeft = 0;
27
27
    this.test = 0;
28
28
    this.onlyLegend = 0;
29
 
    if (this.device == "iPhone" || this.device == "iPad"){
30
 
              this.fader = new Animator().addSubject(new NumericalStyleSubject($('graph_image_div'), 'opacity', 1, 0.13));
 
29
    
 
30
    if (this.idevice) {
 
31
        this.fader = new Animator().addSubject(new NumericalStyleSubject($('graph_image_div'), 'opacity', 1, 0.13));        
31
32
    }
32
 
 
33
33
    
34
34
    if (this.frame) {
35
35
        this.img = this.frame.getElementsByTagName('img')[0];
70
70
}
71
71
 
72
72
 
73
 
/** Checks if user is running on iPhone/iPod or iPad
74
 
 * if running on safari with iPhone returns "iPhone" if with iPad returns "iPad"
75
 
 */
76
 
GRAPH.prototype.getDevice = function() {
77
 
  if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))
78
 
  {
79
 
    return "iPhone";
80
 
  }
81
 
  else if (navigator.userAgent.match(/iPad/i))
82
 
  {
83
 
    return "iPad";
84
 
  } 
85
 
  else {
86
 
    return "other than iPad iPod iPhone";
87
 
  }
88
 
  
89
 
  
90
 
}
91
 
 
92
73
GRAPH.prototype.onImageLoad = function(self) {
93
74
    return function() {
94
75
        adei.SetSuccessStatus(self.onload_message?self.onload_message:translate("Done"));  
95
 
  if(self.fader!=0){
96
 
    self.AnimatorEffects(self,2);   
97
 
  } 
98
76
 
 
77
        if(self.fader){
 
78
            self.AnimatorEffects(self,2);   
 
79
        } 
99
80
    }
100
81
}
101
82
 
342
323
                        this.window.ZoomIn(x);
343
324
                }
344
325
            break;
345
 
/*          default:
346
 
                alert(adei.key);*/
 
326
//          default:
 
327
//                if(this.fader) this.fader.reverse();
347
328
        }
348
329
}
349
330
 
384
365
 
385
366
GRAPH.prototype.onMouseMove = function (self) {
386
367
    return function ( point, dragging, resizing ) {
 
368
 
387
369
//      if (self.config.GetModule() != "graph") return;
388
370
    
389
371
        if ((!point)||((point.x < self.margins.left)||(point.x > (self.width - self.margins.right)))||
579
561
           // alert(direction);
580
562
            if(direction != 0)
581
563
            {    
582
 
              if(self.fader != 0){
 
564
              if(self.fader != 0) {
583
565
                self.AnimatorEffects(self,1);}
584
 
              self.window.Swipe(direction);
 
566
                self.window.Swipe(direction);
585
567
              //alert(direction);
586
568
              //self.window.Apply();
587
569
              //startValuesSet = 0;
588
570
            }
589
571
        }
590
572
        else if(self.onlyLegend === 1 && self.swiping === 0){
 
573
            var iphone = isiPhone();
 
574
            if(!iphone) {
591
575
                var x = adeiMathPreciseAdd(self.xmin, self.xsize*(self.startX - self.margins.left) / self.real_width);
592
576
                var y = new Array();
593
577
                for (var i = 0; i < self.axis.length; i++) {
594
578
                    y[i] = self.ymax[i] - (self.ymax[i] - self.ymin[i])*(self.startY - self.margins.top) / self.real_height;
595
579
                }
596
580
                   
597
 
                        var params = {
 
581
                    var params = {
598
582
                    xmin: self.xmin.toString(),
599
583
                    xmax: self.xmax.toString(),
600
584
                    ymin: self.ymin,
615
599
                  alert('GetLegend request is failed');
616
600
                    }
617
601
                });
618
 
          self.onlyLegend = 0;
 
602
                
 
603
                self.onlyLegend = 0;
 
604
          }
619
605
        }
620
 
        
621
 
        
622
 
 
623
606
     }
624
607
}
625
608
 
653
636
      gestureValues.x = adeiMathPreciseAdd(self.xmin, self.xsize*(self.startX - self.margins.left) / self.real_width);
654
637
     // alert(self.margins.left);
655
638
      gestureValues.marginsLeft = self.margins.left;
656
 
      gestureValues.device = self.device;
 
639
      gestureValues.device = self.idevice;
657
640
      gestureValues.y = new Array();
658
641
      for (var i = 0; i < self.axis.length; i++) {
659
642
        gestureValues.y[i] = self.ymax[i] - (self.ymax[i] - self.ymin[i])*(self.startY - self.margins.top) / self.real_height;        
660
643
      }
661
644
      if(self.fader != 0){self.AnimatorEffects(self,1);}
 
645
      gestureValues.scale = scale;
662
646
      gestureValues.startX = self.startX;
663
 
      gestureValues.angle = angle;
664
 
      gestureValues.scale = scale;
665
647
      self.window.PinchZoom(gestureValues);
666
648
      self.startValuesSet = 0;      
667
 
      self.window.Apply();
668
 
      
 
649
      self.window.Apply();      
669
650
  } 
670
651
}
671
 
/*
 
652
 
672
653
GRAPH.prototype.onOrientationChange = function(self){
673
654
  return function(e){
674
 
    self.updateOrientation();
675
 
  }
676
 
}
677
 
 
678
 
 
679
 
//test
680
 
GRAPH.prototype.updateOrientation = function(self){
681
 
  switch(window.orientation){
682
 
    case 0: //normal portrait
683
 
      alert("Normal");
684
 
      break; 
685
 
    case -90: //right landscape
686
 
      alert("Right");
687
 
      break;
688
 
    case 90: //left landscape
689
 
      alert("Left");
690
 
      break;
691
 
    case 180: //Upsidedown portrait
692
 
      alert("UpsideDown");
693
 
      break;
694
 
    default:
695
 
      break;
696
 
    
697
 
  }
698
 
}
699
 
*/
 
655
        if(self.fader != 0){self.AnimatorEffects(self,1);}
 
656
        self.window.Apply();
 
657
  }
 
658
}
 
659
 
 
660
 
700
661
/**Gets direction of Swipe gesture
701
662
 * When user swipes the screen with 1 finger, calculates heading and return an integer.
702
663
 * Return values:
803
764
    this.config.SetupGeometry(this.frame);
804
765
}
805
766
 
 
767
GRAPH.prototype.ConfigureFunction = function(self) {
 
768
    return function () {
 
769
        return self.Configure();
 
770
    }
 
771
}
 
772
 
806
773
GRAPH.prototype.Configure = function() {
807
774
            this.real_height = this.img.height - this.margins.top - this.margins.bottom;
808
775
            this.real_width = this.img.width - this.margins.left - this.margins.right;
812
779
                var new_height = this.img.height;
813
780
                
814
781
                if (this.crop) {
815
 
                    
816
 
                    if ((new_width != this.width)||(new_height != this.height)) {
 
782
                  if ((new_width != this.width)||(new_height != this.height)) {
817
783
                        this.width = new_width;
818
784
                        this.height = new_height;
819
785
                        this.crop.setParams();  // DS. this action slows evertything down after several steps
820
 
                    }
 
786
                  }
821
787
                } else {
822
 
                    var tooltip;
823
 
                    if (this.exporter) 
 
788
                  var tooltip;
 
789
                  if (this.exporter) 
824
790
                        tooltip = " (" + this.exporter.GetTooltip() + ")";
825
 
                    else
 
791
                  else
826
792
                        tooltip = "";
827
793
 
828
 
      if(this.device == "iPhone" || this.device == "iPad")
829
 
      {
830
 
                this.crop = new Cropper.Img("graph_image", {
831
 
    /*     onEndCrop:  this.onEndCrop(this),
832
 
      onCancelCrop: this.onCancelCrop(this),
833
 
      onClick: this.onClick(this),
834
 
      onDblClick: this.onDblClick(this),
835
 
      onDblSelClick: this.onApply(this),
836
 
      onMouseScroll: this.onMouseScroll(this),
837
 
      onMouseMove: this.onMouseMove(this),
838
 
      */
839
 
      //onOrientationChange: this.onOrientationChange(this),
840
 
      onTouchStart: this.onTouchStart(this),
841
 
      onTouchMove:this.onTouchMove(this),
842
 
      onTouchEnd:this.onTouchEnd(this),
843
 
      onGestureStart:this.onGestureStart(this),
844
 
      onGestureMove:this.onGestureMove(this),
845
 
      onGestureEnd:this.onGestureEnd(this),   
846
 
      onApplyClick: this.onApply(this),
847
 
      onSaveClick: this.onSave(this),
848
 
      extraButtons: this.extraButtons,
849
 
      margins: this.crop_margins,
850
 
      allWidth: this.allWidth,
851
 
      allHeight: this.allHeight,
852
 
      monitorImage: false,
853
 
      imageReady: true
854
 
      /*,
855
 
      tooltips: new Object({
856
 
          'apply': translate('Zoom to the Selection'),
857
 
          'save': translate('Export Selected Data') + tooltip
858
 
      })*/
859
 
        });
860
 
        
861
 
      this.width = new_width;
862
 
      this.height = new_height;
863
 
  
864
 
      }
865
 
      else{
 
794
                  if(this.idevice) {
 
795
                        this.crop = new Cropper.Img("graph_image", {
 
796
                            onOrientationChange: this.onOrientationChange(this),
 
797
                            onTouchStart: this.onTouchStart(this),
 
798
                            onTouchMove:this.onTouchMove(this),
 
799
                            onTouchEnd:this.onTouchEnd(this),
 
800
                            onGestureStart:this.onGestureStart(this),
 
801
                            onGestureMove:this.onGestureMove(this),
 
802
                            onGestureEnd:this.onGestureEnd(this),   
 
803
                            onApplyClick: this.onApply(this),
 
804
                            onSaveClick: this.onSave(this),
 
805
                            extraButtons: this.extraButtons,
 
806
                            margins: this.crop_margins,
 
807
                            allWidth: this.allWidth,
 
808
                            allHeight: this.allHeight,
 
809
                            monitorImage: false,
 
810
                            imageReady: true
 
811
                        });
 
812
                        
 
813
                        this.width = new_width;
 
814
                        this.height = new_height;
 
815
                  } else {
866
816
                    this.crop = new Cropper.Img("graph_image", {
867
817
                        onEndCrop:  this.onEndCrop(this),
868
818
                        onCancelCrop: this.onCancelCrop(this),
884
834
                            'save': translate('Export Selected Data') + tooltip
885
835
                        })
886
836
                    });
887
 
                    
888
837
                    this.width = new_width;
889
838
                    this.height = new_height;
890
 
                  }
891
839
                }
 
840
              }
 
841
              
 
842
              if ((this.crop)&&(!this.crop.initialized)) {
 
843
                this.crop = null;
 
844
                setTimeout(this.ConfigureFunction(this), 1000);
 
845
              }
892
846
                
893
847
            }
894
 
 
895
 
 
896
848
}
897
849
 
898
850