/adei/ui

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/ui

« back to all changes in this revision

Viewing changes to classes/draw.php

  • Committer: Aram Yeghikyan
  • Date: 2008-12-02 13:00:06 UTC
  • Revision ID: eghikyan@gmail.com-20081202130006-2786zkp6xe9njsd2
Axis and other staff

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
 
 
3
$props["login"] = "0";
 
4
global $ADEI_ROOTDIR;
 
5
require_once($ADEI_ROOTDIR."/adei_ui.php");
 
6
 
 
7
 
3
8
include($JPGRAPH_PATH . "/jpgraph.php");
4
9
include($JPGRAPH_PATH . "/jpgraph_line.php");
 
10
include($JPGRAPH_PATH . "/jpgraph_log.php");
5
11
include($JPGRAPH_PATH . "/jpgraph_date.php");
6
12
include($JPGRAPH_PATH . "/jpgraph_canvas.php");
7
13
include($JPGRAPH_PATH . "/jpgraph_canvtools.php");
31
37
 
32
38
 var $precision_mode;           // Requested precision
33
39
 var $precision;                // Actual graph precision in pixels
 
40
 var $settings;
34
41
 
35
42
 const MARKS_NEVER = 0;
36
43
 const MARKS_DEFAULT = 1;
56
63
    global $GRAPH_INDICATE_MISSING_DATA;
57
64
    global $GRAPH_INDICATE_DATA_DENSITY;
58
65
 
 
66
    global $ADEI_ROOTDIR;
 
67
 
59
68
    if ($props) $this->req = &$props;
60
69
    else $this->req = new DATARequest();
61
70
 
131
140
        
132
141
        $this->ready = false;
133
142
    }
 
143
 
 
144
    // Added by Aram for reading XML config file
 
145
    $pathToConfigFile = $ADEI_ROOTDIR."/config.xml";
 
146
    if(!file_exists($pathToConfigFile)){
 
147
        die("Configurtion file does not exists: ".$pathToConfigFile);
 
148
    }
 
149
    $this->settings = simplexml_load_file($pathToConfigFile);
 
150
    if(!is_object($this->settings)){
 
151
        die("Error while loading configuration file: ".$pathToConfigFile);
 
152
    }
 
153
 
134
154
 }
135
155
 
136
156
 static function FindMarksMode($mode) {
245
265
    if ($x === false) {
246
266
        if (isset($this->req->props['x'])) $x = $this->req->props['x'];
247
267
        else throw new ADEIException(translate("The X coordinate is not specified"));
248
 
 
249
268
    }
250
269
    if ($y === false) {
251
270
        if (isset($this->req->props['y'])) $y = $this->req->props['y'];
456
475
    for ($i=0;$i<$size;$i++)
457
476
        $values[$i] = array();
458
477
 
459
 
 
 
478
        /* 1 due to prevent scale(true,true)*/
460
479
    if (($iv->y_min)||($iv->y_max)) {
461
480
        $min = $iv->y_min;
462
481
        $max = $iv->y_max;
480
499
    }
481
500
    
482
501
    
 
502
    if($this->req->srv["reader"] == "VGReader"){
 
503
        // VGReader
 
504
        $useYAxixMinMax = false;
 
505
        $maskManager = new MaskManagerClass($this->settings);
 
506
        $maskArray = $maskManager->getMaskStructureAsArray($this->req->props['db_name'], "0");
 
507
        $axisManager = new AxisManagerClass($this->settings);
 
508
        $axisArray = $axisManager->getAxisOfUser("0");
 
509
        //print_r($maskArray);
 
510
        $itemIdsAxisIdsArray = array();
 
511
        $numberOfItemsPerAxis = array();
 
512
        foreach($maskArray["postfixes"] as $postfix){
 
513
                $itemsIds = $postfix["itemIds"];
 
514
                for($i=0; $i<sizeof($postfix["itemIds"]); $i++){
 
515
                    $itemIdsAxisIdsArray[$postfix["itemIds"][$i]] = $postfix["axisIds"][$i];
 
516
                    $itemIdToAxisArray[$postfix["itemIds"][$i]] = $axisArray[$postfix["axisIds"][$i]];
 
517
                    if(isset($axisArray[$postfix["axisIds"][$i]]["RangeBegin"]) || isset($axisArray[$postfix["axisIds"][$i]]["RangeEnd"])){
 
518
                        $useYAxixMinMax = true;
 
519
                    }
 
520
                    if(isset($numberOfItemsPerAxis[$postfix["itemIds"][$i]])){
 
521
                        $numberOfItemsPerAxis[$postfix["axisIds"][$i]] = 1;
 
522
                    }else{
 
523
                        $numberOfItemsPerAxis[$postfix["axisIds"][$i]]++;
 
524
                    }
 
525
                }
 
526
                $axisIdsUniq = array_unique($postfix["axisIds"]);
 
527
                $axisIdsUniq = array_values($axisIdsUniq);
 
528
        }
 
529
        //print_r($maskArray);
 
530
        //print_r($axisArray);
 
531
        //print_r($itemIdToAxisArray);
 
532
        //print_r($itemsIds);
 
533
        //print_r($axisIdsUniq);
 
534
    }
 
535
    foreach($points as $t => $v) {
483
536
 
484
 
    foreach($points as $t => $v) {
485
537
        if ($v) {
486
538
            if ($this->show_gaps) {
487
539
                $gapinfo = $points->missing_data();
488
540
                if ($gapinfo) array_push($mvalue, 1);
489
541
                else array_push($mvalue, 0);
490
542
            }
491
 
 
492
543
            $amount++;
493
 
 
494
544
            if ($missing) {
495
545
/*              if ($time_on_addon) {
496
546
                    if ($this->show_gaps) {
509
559
                $missing = false;
510
560
            }
511
561
 
512
 
 
513
562
            array_push($time, $t);
514
 
            if (($min)||($max)) {
 
563
            if (($min)||($max)||$useYAxixMinMax) {
515
564
                foreach ($v as $key => $value) {
 
565
                    if(isset($itemIdToAxisArray[$key]["RangeBegin"])){
 
566
                        $min = $itemIdToAxisArray[$key]["RangeBegin"];
 
567
                    }
 
568
                    if(isset($itemIdToAxisArray[$key]["RangeEnd"])){
 
569
                        $max = $itemIdToAxisArray[$key]["RangeEnd"];
 
570
                    }
516
571
                    if ($at_max[$key]) {
517
572
                        if ($value > $max) {
518
573
                            $value = "";
697
752
 
698
753
 
699
754
    $this->graph = new Graph($this->width, $this->height, "auto");
700
 
    $this->graph->img->SetMargin($GRAPH_MARGINS['left'],$GRAPH_MARGINS['top'],$GRAPH_MARGINS['right'],$GRAPH_MARGINS['bottom']);
 
755
    $this->graph->SetMargin($GRAPH_MARGINS['left'], $GRAPH_MARGINS['right'],$GRAPH_MARGINS['top'],$GRAPH_MARGINS['bottom']);
 
756
    $this->graph->SetMarginColor('#FAFAFA');
 
757
    $this->graph->SetBox(true);
701
758
    $this->graph->SetTickDensity(TICKD_NORMAL, TICKD_SPARSE);
702
759
 
703
760
//    $this->graph->SetTickDensity(TICKD_SPARSE, TICKD_VERYSPARSE);
969
1026
    }
970
1027
 
971
1028
    $no_data = true;
972
 
    for ($i = 0; $i < $size; $i++) {
973
 
/*
974
 
        $f = fopen("/tmp/xxx.7", "a+");
975
 
        fwrite($f, print_r($iv, true) . "\n");
976
 
        fwrite($f, $i . " of " . $size . "\n");
977
 
        fwrite($f, date("r", ceil($iv->window_start)) . " - " . date("r", floor($iv->window_start + $iv->window_size)) . "\n");
978
 
        fwrite($f, print_r($time, true));
979
 
        fwrite($f, print_r($values[$i], true));
980
 
        fclose($f);
981
 
*/
982
 
        if (sizeof($time) > 0) {
983
 
 
984
 
            $empty_data = true;
985
 
            foreach ($values[$i] as $val) {
986
 
                if ($val !== NULL) {
987
 
                    $empty_data = false;
988
 
                    break;
989
 
                }
990
 
            }
991
 
 
992
 
            if ($empty_data) continue;
993
 
        
994
 
        
995
 
            $plot = new LinePlot($values[$i], $time);
996
 
            if (sizeof($GRAPH_COLORS)) {
997
 
                $color = $GRAPH_COLORS[$i%sizeof($GRAPH_COLORS)];
998
 
                $plot->SetColor($color);
999
 
                if ($GRAPH_LINE_WEIGHT) {
1000
 
                    $plot->SetWeight($GRAPH_LINE_WEIGHT);
1001
 
                }
1002
 
            }
1003
 
            
1004
 
            
1005
 
            if ($marks) {
1006
 
                $plot->mark->SetType($mtype);
1007
 
                if ($GRAPH_ACCURACY_MARKS_SIZE) $plot->mark->SetSize($GRAPH_ACCURACY_MARKS_SIZE);
1008
 
                $plot->mark->SetFillColor(($color&&($size>1))?$color:$marks);
1009
 
            }
1010
 
            
1011
 
            $this->graph->Add($plot);
1012
 
            $no_data = false;
 
1029
    $firstPlot = true;
 
1030
    $graphIndex = 0;
 
1031
    $plot = new LinePlot(array($values[0][0]), array($time[0]));
 
1032
    $this->graph->Add($plot);
 
1033
    $this->graph->yaxis->Hide();
 
1034
    if($this->req->srv["reader"] == "VGReader"){
 
1035
        // VGReader
 
1036
        $maskManager = new MaskManagerClass($this->settings);
 
1037
        $maskArray = $maskManager->getMaskStructureAsArray($this->req->props['db_name'], "0");
 
1038
        $axisManager = new AxisManagerClass($this->settings);
 
1039
        $axisArray = $axisManager->getAxisOfUser("0");
 
1040
        //print_r($maskArray);
 
1041
        $itemIdsAxisIdsArray = array();
 
1042
        $numberOfItemsPerAxis = array();
 
1043
        foreach($maskArray["postfixes"] as $postfix){
 
1044
                $itemsIds = $postfix["itemIds"];
 
1045
                for($i=0; $i<sizeof($postfix["itemIds"]); $i++){
 
1046
                    $itemIdsAxisIdsArray[$postfix["itemIds"][$i]] = $postfix["axisIds"][$i];
 
1047
                    if(isset($numberOfItemsPerAxis[$postfix["itemIds"][$i]])){
 
1048
                        $numberOfItemsPerAxis[$postfix["axisIds"][$i]] = 1;
 
1049
                    }else{
 
1050
                        $numberOfItemsPerAxis[$postfix["axisIds"][$i]]++;
 
1051
                    }
 
1052
                }
 
1053
                $axisIdsUniq = array_unique($postfix["axisIds"]);
 
1054
                $axisIdsUniq = array_values($axisIdsUniq);
 
1055
        }
 
1056
        //print_r($itemsIds);
 
1057
        //print_r($itemIdsAxisIdsArray);
 
1058
        //print_r($numberOfItemsPerAxis);
 
1059
        $counterNumberOfItemsPerAxis = $numberOfItemsPerAxis;
 
1060
        // Inicialization of the axis 
 
1061
        $myType = array("lin", "log");
 
1062
        for($i=0; $i<sizeof($axisIdsUniq); $i++){
 
1063
            $this->graph->SetYScale($i,'lin', $axisArray[$i]["RangeBegin"]*1.1, $axisArray[$i]["RangeEnd"]*1.1);
 
1064
        }
 
1065
        //print_r($axisIdsUniq);
 
1066
        $tittle = array();
 
1067
        for ($i = 0; $i < $size; $i++){
 
1068
            if (sizeof($time) > 0) {
 
1069
                $empty_data = true;
 
1070
                foreach ($values[$i] as $val) {
 
1071
                    if ($val !== NULL) {
 
1072
                        $empty_data = false;
 
1073
                        break;
 
1074
                    }
 
1075
                }
 
1076
                if ($empty_data){
 
1077
                    continue;
 
1078
                }
 
1079
                $idOfAxisOnPlot = array_search($itemIdsAxisIdsArray[$itemsIds[$i]], $axisIdsUniq);
 
1080
                $plot = new LinePlot($values[$i], $time);
 
1081
                if (sizeof($GRAPH_COLORS)){
 
1082
                    $baseColor = $GRAPH_COLORS[$idOfAxisOnPlot];
 
1083
                    $color =  $baseColor;
 
1084
                    $plot->SetColor($color);
 
1085
                    if ($GRAPH_LINE_WEIGHT){
 
1086
                        $plot->SetWeight($GRAPH_LINE_WEIGHT);
 
1087
                    }
 
1088
                }
 
1089
                if ($marks) {
 
1090
                    $plot->mark->SetType($mtype);
 
1091
                    if ($GRAPH_ACCURACY_MARKS_SIZE) $plot->mark->SetSize($GRAPH_ACCURACY_MARKS_SIZE);
 
1092
                    $plot->mark->SetFillColor(($color&&($size>1))?$color:$marks);
 
1093
                }
 
1094
                //echo "ID:".$idOfAxisOnPlot."\n";
 
1095
                $this->graph->AddY($idOfAxisOnPlot, $plot);
 
1096
                $this->graph->ynaxis[$idOfAxisOnPlot]->SetColor($baseColor);
 
1097
                $this->graph->ynaxis[$idOfAxisOnPlot]->title->Set($axisArray[$idOfAxisOnPlot]["Name"]." ".$axisArray[$idOfAxisOnPlot]["RangeBegin"]."-".$axisArray[$idOfAxisOnPlot]["RangeEnd"]);
 
1098
                $this->graph->ynaxis[$idOfAxisOnPlot]->title->SetColor($baseColor);
 
1099
                
 
1100
                $no_data = false;
 
1101
            }
 
1102
        }
 
1103
        //$this->graph->SetYDeltaDist(50);
 
1104
        //$this->graph->SetMargin($GRAPH_MARGINS['left'], $GRAPH_MARGINS['right'] + sizeof($axisIdsUniq)*20,$GRAPH_MARGINS['top'],$GRAPH_MARGINS['bottom']);
 
1105
        $this->graph->SetMargin($GRAPH_MARGINS['left'], 50*sizeof($axisIdsUniq),$GRAPH_MARGINS['top'],$GRAPH_MARGINS['bottom']);
 
1106
        $GRAPH_MARGINS['right'] = 50*sizeof($axisIdsUniq);
 
1107
        
 
1108
    }else{
 
1109
        // NOT VGREADER CASE
 
1110
        for ($i = 0; $i < $size; $i++) {
 
1111
            if (sizeof($time) > 0) {
 
1112
 
 
1113
                $empty_data = true;
 
1114
                foreach ($values[$i] as $val) {
 
1115
                    if ($val !== NULL) {
 
1116
                        $empty_data = false;
 
1117
                        break;
 
1118
                    }
 
1119
                }
 
1120
                if ($empty_data) continue;
 
1121
                $plot = new LinePlot($values[$i], $time);
 
1122
                if (sizeof($GRAPH_COLORS)) {
 
1123
                    $color = $GRAPH_COLORS[$i%sizeof($GRAPH_COLORS)];
 
1124
                    $plot->SetColor($color);
 
1125
                    if ($GRAPH_LINE_WEIGHT) {
 
1126
                        $plot->SetWeight($GRAPH_LINE_WEIGHT);
 
1127
                    }
 
1128
                }
 
1129
                if ($marks) {
 
1130
                    $plot->mark->SetType($mtype);
 
1131
                    if ($GRAPH_ACCURACY_MARKS_SIZE) $plot->mark->SetSize($GRAPH_ACCURACY_MARKS_SIZE);
 
1132
                    $plot->mark->SetFillColor(($color&&($size>1))?$color:$marks);
 
1133
                }
 
1134
                    $this->graph->SetYScale($i,'lin');
 
1135
                    $this->graph->AddY($i, $plot);
 
1136
                    $this->graph->ynaxis[$i]->title->Set("N".$i);
 
1137
                $no_data = false;
 
1138
            }
1013
1139
        }
1014
1140
    }
1015
 
    
1016
1141
    if ($no_data) {
1017
1142
        $range = date("c", ceil($iv->window_start)) . " and " . date("c", floor($iv->window_start + $iv->window_size));
1018
1143
        throw new ADEIException(translate("No data between: %s", $range), ADEIException::NO_DATA);
1064
1189
            eval("\$mtype=$GRAPH_DENSITY_POINTS_TYPE;");
1065
1190
        } 
1066
1191
 
1067
 
 
1068
1192
        $plot->mark->SetType($mtype);
1069
1193
        $plot->mark->SetColor($GRAPH_DENSITY_POINTS_OUTLINE);
1070
1194
        $plot->mark->SetFillColor($GRAPH_DENSITY_POINTS_COLOR);
1075
1199
 
1076
1200
    $this->graph_interval = $iv;
1077
1201
    $this->precision = $precision;
1078
 
    
1079
 
//    print_r($mvalue);
1080
 
//    echo $realmin . "\n";
1081
 
 
1082
 
        
1083
 
    
1084
 
/*    $graph->img->SetMargin(40,110,20,40);
1085
 
    //$graph ->xaxis->scale-> SetDateFormat( 'Y-m-d');
1086
 
    $graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,6); 
1087
 
    $graph->xaxis->SetLabelAngle(45);
1088
 
    $graph->SetShadow();
1089
 
 
1090
 
    $graph->ygrid->Show(true,true);
1091
 
$Size = sizeof($Data->TimeSeries);
1092
 
for($i=3; $i<6;$i++){
1093
 
    $lineplot[$i]=new LinePlot($Data->TimeSeries[$i]["Value"], $Data->TimeSeries[$i]["Time"]);
1094
 
    $lineplot[$i]->SetColor($Data->TimeSeries[$i]["Color"]);
1095
 
    $lineplot[$i]->SetLegend($Data->TimeSeries[$i]["Name"]);
1096
 
    $graph->Add($lineplot[$i]);
1097
 
}
1098
 
$graph->Stroke($TempDir."Lin-".$FileName.".png");
1099
 
    
1100
 
*/
1101
 
 
1102
 
 
1103
 
 
1104
 
//        $graph = new Graph($this->width, $this->heigh /*, "auto"*/);
1105
 
//      $graph->SetScale('intlin'/* ymin, ymax, xmin, xmax */);
1106
 
        
1107
 
        // foreach masks
1108
 
//      $lineplot = new LinePlot($dataarray);
1109
1202
 }
1110
1203
 
1111
1204
 
1196
1289
        "margins" => array($GRAPH_MARGINS['left'],$GRAPH_MARGINS['top'],$GRAPH_MARGINS['right'],$GRAPH_MARGINS['bottom'])
1197
1290
    );
1198
1291
 }
1199
 
 
 
1292
 function getGradient($beginColor, $endColor, $numberOfSteps, $stepId){
 
1293
    $beginColor = array(
 
1294
        hexdec(substr($beginColor, 1, 2)),
 
1295
        hexdec(substr($beginColor, 3, 2)),
 
1296
        hexdec(substr($beginColor, 5, 2))
 
1297
    );
 
1298
    $endColor = array(
 
1299
        hexdec(substr($endColor, 1, 2)),
 
1300
        hexdec(substr($endColor, 3, 2)),
 
1301
        hexdec(substr($endColor, 5, 2))
 
1302
    );
 
1303
    for($i=0; $i<3; $i++){
 
1304
        $step[$i] = ($endColor[$i] - $beginColor[$i])/$numberOfSteps;
 
1305
    }
 
1306
    $color = "";
 
1307
    for($j=0; $j<3; $j++){
 
1308
        $decColor = $beginColor[$j] + $stepId*$step[$j];
 
1309
        $decColor < 15?$element = "0".dechex($decColor): $element = dechex($decColor);
 
1310
        $color .= $element;
 
1311
    }
 
1312
    return $color;
 
1313
 }
1200
1314
 static function Display($file = false) {
1201
1315
    global $TMP_PATH;
1202
1316