Beispiel #1
0
 /**
  * Build a graph onto disk using Artichow library
  *
  * @param	string	$file    	Image file name to use if we save onto disk
  * @param	string	$fileurl	Url path to show image if saved onto disk
  * @return	void
  */
 private function draw_artichow($file, $fileurl)
 {
     global $artichow_defaultfont;
     dol_syslog(get_class($this) . "::draw_artichow this->type=" . join(',', $this->type));
     if (!defined('SHADOW_RIGHT_TOP')) {
         define('SHADOW_RIGHT_TOP', 3);
     }
     if (!defined('LEGEND_BACKGROUND')) {
         define('LEGEND_BACKGROUND', 2);
     }
     if (!defined('LEGEND_LINE')) {
         define('LEGEND_LINE', 1);
     }
     // Create graph
     $classname = '';
     if (!isset($this->type[0]) || $this->type[0] == 'bars') {
         $classname = 'BarPlot';
     } else {
         if ($this->type[0] == 'lines') {
             $classname = 'LinePlot';
         } else {
             $classname = 'TypeUnknown';
         }
     }
     include_once ARTICHOW_PATH . $classname . '.class.php';
     // Definition de couleurs
     $bgcolor = new Color($this->bgcolor[0], $this->bgcolor[1], $this->bgcolor[2]);
     $bgcolorgrid = new Color($this->bgcolorgrid[0], $this->bgcolorgrid[1], $this->bgcolorgrid[2]);
     $colortrans = new Color(0, 0, 0, 100);
     $colorsemitrans = new Color(255, 255, 255, 60);
     $colorgradient = new LinearGradient(new Color(235, 235, 235), new Color(255, 255, 255), 0);
     $colorwhite = new Color(255, 255, 255);
     // Graph
     $graph = new Graph($this->width, $this->height);
     $graph->border->hide();
     $graph->setAntiAliasing(true);
     if (isset($this->title)) {
         $graph->title->set($this->title);
         //print $artichow_defaultfont;exit;
         $graph->title->setFont(new $artichow_defaultfont(10));
     }
     if (is_array($this->bgcolor)) {
         $graph->setBackgroundColor($bgcolor);
     } else {
         $graph->setBackgroundGradient($colorgradient);
     }
     $group = new PlotGroup();
     //$group->setSpace(5, 5, 0, 0);
     $paddleft = 50;
     $paddright = 10;
     $strl = dol_strlen(max(abs($this->MaxValue), abs($this->MinValue)));
     if ($strl > 6) {
         $paddleft += $strl * 4;
     }
     $group->setPadding($paddleft, $paddright);
     // Width on left and right for Y axis values
     $group->legend->setSpace(0);
     $group->legend->setPadding(2, 2, 2, 2);
     $group->legend->setPosition(NULL, 0.1);
     $group->legend->setBackgroundColor($colorsemitrans);
     if (is_array($this->bgcolorgrid)) {
         $group->grid->setBackgroundColor($bgcolorgrid);
     } else {
         $group->grid->setBackgroundColor($colortrans);
     }
     if ($this->hideXGrid) {
         $group->grid->hideVertical(true);
     }
     if ($this->hideYGrid) {
         $group->grid->hideHorizontal(true);
     }
     // On boucle sur chaque lot de donnees
     $legends = array();
     $i = 0;
     $nblot = count($this->data[0]) - 1;
     while ($i < $nblot) {
         $x = 0;
         $values = array();
         foreach ($this->data as $key => $valarray) {
             $legends[$x] = $valarray[0];
             $values[$x] = $valarray[$i + 1];
             $x++;
         }
         // We fix unknown values to null
         $newvalues = array();
         foreach ($values as $val) {
             $newvalues[] = is_numeric($val) ? $val : null;
         }
         if ($this->type[0] == 'bars') {
             //print "Lot de donnees $i<br>";
             //print_r($values);
             //print '<br>';
             $color = new Color($this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2], 20);
             $colorbis = new Color(min($this->datacolor[$i][0] + 50, 255), min($this->datacolor[$i][1] + 50, 255), min($this->datacolor[$i][2] + 50, 255), 50);
             $colorgrey = new Color(100, 100, 100);
             $colorborder = new Color($this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2]);
             if ($this->mode == 'side') {
                 $plot = new BarPlot($newvalues, $i + 1, $nblot);
             }
             if ($this->mode == 'depth') {
                 $plot = new BarPlot($newvalues, 1, 1, ($nblot - $i - 1) * 5);
             }
             $plot->barBorder->setColor($colorgrey);
             //$plot->setBarColor($color);
             $plot->setBarGradient(new LinearGradient($colorbis, $color, 90));
             if ($this->mode == 'side') {
                 $plot->setBarPadding(0.1, 0.1);
             }
             if ($this->mode == 'depth') {
                 $plot->setBarPadding(0.1, 0.4);
             }
             if ($this->mode == 'side') {
                 $plot->setBarSpace(5);
             }
             if ($this->mode == 'depth') {
                 $plot->setBarSpace(2);
             }
             $plot->barShadow->setSize($this->SetShading);
             $plot->barShadow->setPosition(SHADOW_RIGHT_TOP);
             $plot->barShadow->setColor(new Color(160, 160, 160, 50));
             $plot->barShadow->smooth(TRUE);
             //$plot->setSize(1, 0.96);
             //$plot->setCenter(0.5, 0.52);
             // Le mode automatique est plus efficace
             $plot->SetYMax($this->MaxValue);
             $plot->SetYMin($this->MinValue);
         }
         if ($this->type[0] == 'lines') {
             $color = new Color($this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2], 20);
             $colorbis = new Color(min($this->datacolor[$i][0] + 20, 255), min($this->datacolor[$i][1] + 20, 255), min($this->datacolor[$i][2] + 20, 255), 60);
             $colorter = new Color(min($this->datacolor[$i][0] + 50, 255), min($this->datacolor[$i][1] + 50, 255), min($this->datacolor[$i][2] + 50, 255), 90);
             $plot = new LinePlot($newvalues);
             //$plot->setSize(1, 0.96);
             //$plot->setCenter(0.5, 0.52);
             $plot->setColor($color);
             $plot->setThickness(1);
             // Set line background gradient
             $plot->setFillGradient(new LinearGradient($colorter, $colorbis, 90));
             $plot->xAxis->setLabelText($legends);
             // Le mode automatique est plus efficace
             $plot->SetYMax($this->MaxValue);
             $plot->SetYMin($this->MinValue);
             //$plot->setYAxis(0);
             //$plot->hideLine(true);
         }
         //$plot->reduce(80);		// Evite temps d'affichage trop long et nombre de ticks absisce satures
         $group->legend->setTextFont(new $artichow_defaultfont(10));
         // This is to force Artichow to use awFileFontDriver to
         // solve a bug in Artichow with UTF8
         if (count($this->Legend)) {
             if ($this->type[0] == 'bars') {
                 $group->legend->add($plot, $this->Legend[$i], LEGEND_BACKGROUND);
             }
             if ($this->type[0] == 'lines') {
                 $group->legend->add($plot, $this->Legend[$i], LEGEND_LINE);
             }
         }
         $group->add($plot);
         $i++;
     }
     $group->axis->bottom->setLabelText($legends);
     $group->axis->bottom->label->setFont(new $artichow_defaultfont(7));
     //print $group->axis->bottom->getLabelNumber();
     if ($this->labelInterval > 0) {
         $group->axis->bottom->setLabelInterval($this->labelInterval);
     }
     $graph->add($group);
     // Generate file
     $graph->draw($file);
     $this->_stringtoshow = '<!-- Build using ' . $this->_library . ' --><img src="' . $fileurl . '" title="' . dol_escape_htmltag($this->title ? $this->title : $this->YLabel) . '" alt="' . dol_escape_htmltag($this->title ? $this->title : $this->YLabel) . '">';
 }
Beispiel #2
0
            $plot->setBarSize(0.60);

            $plot->setYAxis(PLOT_LEFT);
            $plot->setYMax("20");

            $group->add($plot);
            if ($k == 1) $group->legend->add($plot, $legendy1, LEGEND_BACKGROUND);



            $plot = new BarPlot($datay2[$k], $k, $nb_data-1);

            $plot->barBorder->setColor(new Color(0, 0, 0, 30));

            $plot->setBarPadding(0.1, 0.1);
            $plot->setBarSpace(0);

            $plot->barShadow->setSize(0);
            $plot->barShadow->setPosition(SHADOW_RIGHT_TOP);
            $plot->barShadow->setColor(new Color(180, 180, 180, 10));
            $plot->barShadow->smooth(TRUE);

            $plot->label->move(0, -6);
            $plot->label->setFont(new Tuffy(7));
            $plot->label->setAngle(90);
            $plot->label->setAlign(NULL, LABEL_TOP);
            $plot->label->setPadding(3, 1, 0, 6);

            $plot->setBarColor($colors[2]);
            $plot->setBarSize(0.60);
Beispiel #3
0
$group = new PlotGroup();
$group->setSpace(6, 6, 5, 5);
$group->setBackgroundGradient(new LinearGradient(new Color(235, 235, 235), new White(), 0));
$group->setPadding(40, 10, 10, 50);
$group->axis->left->setLabelPrecision(2);
$group->axis->bottom->label->hide(TRUE);
$group->axis->bottom->hideTicks(TRUE);
$group->grid->setType(LINE_DASHED);
$group->grid->hideHorizontal(TRUE);
$gradients = array(new LinearGradient(new Color(30, 30, 160, 10), new Color(120, 120, 160, 10), 0), new LinearGradient(new Color(30, 160, 30, 10), new Color(120, 160, 120, 10), 0), new LinearGradient(new Color(160, 30, 30, 10), new Color(160, 120, 120, 10), 0));
for ($n = 0; $n < 3; $n++) {
    $x = array();
    for ($i = 0; $i < 6; $i++) {
        $x[] = (cos($i * M_PI / 100) / ($n + 1) * mt_rand(600, 900) / 1000 - 0.5) * ($n % 2 ? -0.5 : 1) + ($n % 2 ? -0.4 : 0);
    }
    $plot = new BarPlot($x, $n + 1, 3);
    $plot->setXAxis(PLOT_BOTTOM);
    $plot->barShadow->setSize(1);
    $plot->barShadow->setPosition(SHADOW_RIGHT_TOP);
    $plot->barShadow->setColor(new Color(160, 160, 160, 10));
    $plot->barBorder->setColor($gradients[$n]->from);
    $plot->setBarGradient($gradients[$n]);
    $plot->setBarSpace(2);
    $group->legend->add($plot, 'Bar#' . ($n + 1), LEGEND_BACKGROUND);
    $group->add($plot);
}
$group->legend->setModel(LEGEND_MODEL_BOTTOM);
$group->legend->setPosition(NULL, 0.86);
$group->legend->shadow->hide();
$graph->add($group);
$graph->draw();
Beispiel #4
0
	/**
	 * 		Build a graph onto disk using Artichow library
	 *    	@param      file    Image file name on disk
	 */
	function draw_artichow($file)
	{
		dol_syslog("DolGraph.class::draw_artichow this->type=".$this->type);

		if (! defined('SHADOW_RIGHT_TOP'))  define('SHADOW_RIGHT_TOP',3);
		if (! defined('LEGEND_BACKGROUND')) define('LEGEND_BACKGROUND',2);
		if (! defined('LEGEND_LINE'))       define('LEGEND_LINE',1);

		// Create graph
		$classname='';
		if ($this->type == 'bars')  $classname='BarPlot';
		if ($this->type == 'lines') $classname='LinePlot';
		include_once DOL_DOCUMENT_ROOT."/includes/artichow/".$classname.".class.php";

		// Definition de couleurs
		$bgcolor=new Color($this->bgcolor[0],$this->bgcolor[1],$this->bgcolor[2]);
		$bgcolorgrid=new Color($this->bgcolorgrid[0],$this->bgcolorgrid[1],$this->bgcolorgrid[2]);
		$colortrans=new Color(0,0,0,100);
		$colorsemitrans=new Color(255,255,255,60);
		$colorgradient= new LinearGradient(new Color(235, 235, 235),new Color(255, 255, 255),0);
		$colorwhite=new Color(255,255,255);

		// Graph
		$graph = new Graph($this->width, $this->height);
		$graph->border->hide();
		$graph->setAntiAliasing(true);
		if (isset($this->title))
		{
			$graph->title->set($this->title);
			$graph->title->setFont(new Tuffy(10));
		}

		if (is_array($this->bgcolor)) $graph->setBackgroundColor($bgcolor);
		else $graph->setBackgroundGradient($colorgradient);

		$group = new PlotGroup;
		//$group->setSpace(5, 5, 0, 0);

		$paddleft=50;
		$paddright=10;
		$strl=dol_strlen(max(abs($this->MaxValue),abs($this->MinValue)));
		if ($strl > 6) $paddleft += ($strln * 4);
		$group->setPadding($paddleft, $paddright);		// Width on left and right for Y axis values
		$group->legend->setSpace(0);
		$group->legend->setPadding(2,2,2,2);
		$group->legend->setPosition(NULL,0.1);
		$group->legend->setBackgroundColor($colorsemitrans);

		if (is_array($this->bgcolorgrid)) $group->grid->setBackgroundColor($bgcolorgrid);
		else $group->grid->setBackgroundColor($colortrans);

		if ($this->hideXGrid)	$group->grid->hideVertical(true);
		if ($this->hideYGrid)	$group->grid->hideHorizontal(true);

		// On boucle sur chaque lot de donnees
		$legends=array();
		$i=0;
		$nblot=sizeof($this->data[0])-1;

		while ($i < $nblot)
		{
			$j=0;
			$values=array();
			foreach($this->data as $key => $valarray)
			{
				$legends[$j] = $valarray[0];
				$values[$j]  = $valarray[$i+1];
				$j++;
			}

			// Artichow ne gere pas les valeurs inconnues
			// Donc si inconnu, on la fixe a null
			$newvalues=array();
			foreach($values as $val)
			{
				$newvalues[]=(is_numeric($val) ? $val : null);
			}


			if ($this->type == 'bars')
			{
				//print "Lot de donnees $i<br>";
				//print_r($values);
				//print '<br>';

				$color=new Color($this->datacolor[$i][0],$this->datacolor[$i][1],$this->datacolor[$i][2],20);
				$colorbis=new Color(min($this->datacolor[$i][0]+50,255),min($this->datacolor[$i][1]+50,255),min($this->datacolor[$i][2]+50,255),50);

				$colorgrey=new Color(100,100,100);
				$colorborder=new Color($this->datacolor[$i][0],$this->datacolor[$i][1],$this->datacolor[$i][2]);

				if ($this->mode == 'side')  $plot = new BarPlot($newvalues, $i+1, $nblot);
				if ($this->mode == 'depth') $plot = new BarPlot($newvalues, 1, 1, ($nblot-$i-1)*5);

				$plot->barBorder->setColor($colorgrey);
				//$plot->setBarColor($color);
				$plot->setBarGradient( new LinearGradient($colorbis, $color, 90) );

				if ($this->mode == 'side')  $plot->setBarPadding(0.1, 0.1);
				if ($this->mode == 'depth') $plot->setBarPadding(0.1, 0.4);
				if ($this->mode == 'side')  $plot->setBarSpace(5);
				if ($this->mode == 'depth') $plot->setBarSpace(2);

				$plot->barShadow->setSize($this->SetShading);
				$plot->barShadow->setPosition(SHADOW_RIGHT_TOP);
				$plot->barShadow->setColor(new Color(160, 160, 160, 50));
				$plot->barShadow->smooth(TRUE);
				//$plot->setSize(1, 0.96);
				//$plot->setCenter(0.5, 0.52);

				// Le mode automatique est plus efficace
				$plot->SetYMax($this->MaxValue);
				$plot->SetYMin($this->MinValue);
			}

			if ($this->type == 'lines')
			{
				$color=new Color($this->datacolor[$i][0],$this->datacolor[$i][1],$this->datacolor[$i][2],20);
				$colorbis=new Color(min($this->datacolor[$i][0]+20,255),min($this->datacolor[$i][1]+20,255),min($this->datacolor[$i][2]+20,255),60);
				$colorter=new Color(min($this->datacolor[$i][0]+50,255),min($this->datacolor[$i][1]+50,255),min($this->datacolor[$i][2]+50,255),90);

				$plot = new LinePlot($newvalues);
				//$plot->setSize(1, 0.96);
				//$plot->setCenter(0.5, 0.52);

				$plot->setColor($color);
				$plot->setThickness(1);

				// Set line background gradient
				$plot->setFillGradient( new LinearGradient($colorter, $colorbis, 90) );

				$plot->xAxis->setLabelText($legends);

				// Le mode automatique est plus efficace
				$plot->SetYMax($this->MaxValue);
				$plot->SetYMin($this->MinValue);
				//$plot->setYAxis(0);
				//$plot->hideLine(true);
			}

			//$plot->reduce(80);		// Evite temps d'affichage trop long et nombre de ticks absisce satures

			$group->legend->setTextFont(new Tuffy(10)); // This is to force Artichow to use awFileFontDriver to
														// solve a bug in Artichow with UTF8
			if (sizeof($this->Legend))
			{
				if ($this->type == 'bars')  $group->legend->add($plot, $this->Legend[$i], LEGEND_BACKGROUND);
				if ($this->type == 'lines') $group->legend->add($plot, $this->Legend[$i], LEGEND_LINE);
			}
			$group->add($plot);

			$i++;
		}

		$group->axis->bottom->setLabelText($legends);
		$group->axis->bottom->label->setFont(new Tuffy(7));

		//print $group->axis->bottom->getLabelNumber();
		if ($this->labelInterval > 0) $group->axis->bottom->setLabelInterval($this->labelInterval);

		$graph->add($group);

		// Generate file
		$graph->draw($file);
	}
Beispiel #5
0
$darkColor = array(new Color(40, 55, 120, 10), new Color(55, 120, 40, 10));
$axis = array(PLOT_LEFT, PLOT_RIGHT);
$group->axis->left->setColor($darkColor[0]);
$group->axis->left->label->setColor($darkColor[0]);
$group->axis->right->setColor($darkColor[1]);
$group->axis->right->label->setColor($darkColor[1]);
$group->setBackgroundGradient(new LinearGradient(new Color(225, 225, 225), new Color(255, 255, 255), 0));
for ($n = 0; $n < 2; $n++) {
    $x = array();
    for ($i = 0; $i < 4; $i++) {
        $x[] = (cos($i * M_PI / 100) / ($n + 1) * mt_rand(700, 1300) / 1000 - 0.5) * ($n % 2 ? -0.5 : 1) + ($n % 2 ? -0.4 : 0) + 1;
    }
    $plot = new BarPlot($x, $n + 1, 2);
    $plot->barBorder->setColor(new Color(0, 0, 0, 30));
    $plot->setBarPadding(0.1, 0.1);
    $plot->setBarSpace(5);
    $plot->barShadow->setSize(3);
    $plot->barShadow->setPosition(SHADOW_RIGHT_TOP);
    $plot->barShadow->setColor(new Color(180, 180, 180, 10));
    $plot->barShadow->smooth(TRUE);
    $plot->label->set($x);
    $plot->label->move(0, -6);
    $plot->label->setFont(new Tuffy(7));
    $plot->label->setAngle(90);
    $plot->label->setAlign(NULL, LABEL_TOP);
    $plot->label->setPadding(3, 1, 0, 6);
    $plot->label->setCallbackFunction("labelFormat");
    $plot->setBarColor($colors[$n]);
    $plot->setYAxis($axis[$n]);
    $group->add($plot);
}
    return round($value, 2);
}
$graph = new Graph(500, 400);
$graph->setAntiAliasing(TRUE);
$group = new PlotGroup();
$group->setSpace(5, 5, 15, 15);
$group->setPadding(40, 40, 25, 25);
$group->axis->left->setLabelPrecision(2);
for ($n = 0; $n < 4; $n++) {
    $x = array();
    for ($i = 0; $i < 6; $i++) {
        $x[] = (cos($i * M_PI / 100) / ($n + 1) * mt_rand(700, 1300) / 1000 - 0.5) * ($n % 2 ? -0.5 : 1) + ($n % 2 ? -0.4 : 0) + 0.3;
    }
    $plot = new BarPlot($x, floor($n / 2) + 1, 2, ($n % 2 === 0) * 6);
    $plot->barBorder->setColor(color());
    $plot->setBarSpace(12);
    $plot->barShadow->setSize(4);
    $plot->barShadow->setPosition(SHADOW_RIGHT_TOP);
    $plot->barShadow->setColor(new Color(180, 180, 180, 10));
    $plot->barShadow->smooth(TRUE);
    $plot->label->set($x);
    $plot->label->move(0, -12);
    $plot->label->setFont(new Font1());
    $plot->label->setAngle(90);
    $plot->label->setInterval(2);
    $plot->label->setAlign(NULL, LABEL_TOP);
    $plot->label->setBackgroundGradient(new LinearGradient(new Color(250, 250, 250, 10), new Color(255, 200, 200, 30), 0));
    $plot->label->border->setColor(new Color(20, 20, 20, 20));
    $plot->label->setPadding(3, 1, 1, 0);
    $plot->label->setCallbackFunction("labelFormat");
    $plot->setBarColor(color(5));