Ignore:
Timestamp:
Apr 13, 2019, 8:05:15 PM (6 years ago)
Author:
roby
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/client/modules/Elezioni/grafici/jpgraph_iconplot.php

    r2 r265  
    11<?php
    22//=======================================================================
    3 // File:        JPGRAPH_ICONPLOT.PHP
    4 // Description: PHP4 Graph Plotting library. Extension module.
    5 // Created:     2004-02-18
    6 // Ver:         $Id: jpgraph_iconplot.php 781 2006-10-08 08:07:47Z ljp $
     3// File:        JPGRAPH_ICONPLOT.PHP
     4// Description: Extension module to add icons to plots
     5// Created:     2004-02-18
     6// Ver:         $Id: jpgraph_iconplot.php 1404 2009-06-28 15:25:41Z ljp $
    77//
    8 // Copyright (c) Aditus Consulting. All rights reserved.
     8// Copyright (c) Asial Corporation. All rights reserved.
    99//========================================================================
    1010
     
    2525
    2626
    27     function IconPlot($aFile="",$aX=0,$aY=0,$aScale=1.0,$aMix=100) {
    28         $this->iFile = $aFile;
    29         $this->iX=$aX;
    30         $this->iY=$aY;
    31         $this->iScale= $aScale;
    32         if( $aMix < 0 || $aMix > 100 ) {
    33             JpGraphError::RaiseL(8001); //('Mix value for icon must be between 0 and 100.');
    34         }
    35         $this->iMix = $aMix ;
     27    function __construct($aFile="",$aX=0,$aY=0,$aScale=1.0,$aMix=100) {
     28        $this->iFile = $aFile;
     29        $this->iX=$aX;
     30        $this->iY=$aY;
     31        $this->iScale= $aScale;
     32        if( $aMix < 0 || $aMix > 100 ) {
     33            JpGraphError::RaiseL(8001); //('Mix value for icon must be between 0 and 100.');
     34        }
     35        $this->iMix = $aMix ;
    3636    }
    3737
    3838    function SetCountryFlag($aFlag,$aX=0,$aY=0,$aScale=1.0,$aMix=100,$aStdSize=3) {
    39         $this->iCountryFlag = $aFlag;
    40         $this->iX=$aX;
    41         $this->iY=$aY;
    42         $this->iScale= $aScale;
    43         if( $aMix < 0 || $aMix > 100 ) {
    44             JpGraphError::RaiseL(8001);//'Mix value for icon must be between 0 and 100.');
    45         }
    46         $this->iMix = $aMix;
    47         $this->iCountryStdSize = $aStdSize;
     39        $this->iCountryFlag = $aFlag;
     40        $this->iX=$aX;
     41        $this->iY=$aY;
     42        $this->iScale= $aScale;
     43        if( $aMix < 0 || $aMix > 100 ) {
     44            JpGraphError::RaiseL(8001);//'Mix value for icon must be between 0 and 100.');
     45        }
     46        $this->iMix = $aMix;
     47        $this->iCountryStdSize = $aStdSize;
    4848    }
    4949
    5050    function SetPos($aX,$aY) {
    51         $this->iX=$aX;
    52         $this->iY=$aY;
     51        $this->iX=$aX;
     52        $this->iY=$aY;
    5353    }
    5454
    5555    function CreateFromString($aStr) {
    56         $this->iImgString = $aStr;
     56        $this->iImgString = $aStr;
    5757    }
    5858
    5959    function SetScalePos($aX,$aY) {
    60         $this->iScalePosX = $aX;
    61         $this->iScalePosY = $aY;
     60        $this->iScalePosX = $aX;
     61        $this->iScalePosY = $aY;
    6262    }
    6363
    6464    function SetScale($aScale) {
    65         $this->iScale = $aScale;
     65        $this->iScale = $aScale;
    6666    }
    6767
    6868    function SetMix($aMix) {
    69         if( $aMix < 0 || $aMix > 100 ) {
    70             JpGraphError::RaiseL(8001);//('Mix value for icon must be between 0 and 100.');
    71         }
    72         $this->iMix = $aMix ;
     69        if( $aMix < 0 || $aMix > 100 ) {
     70            JpGraphError::RaiseL(8001);//('Mix value for icon must be between 0 and 100.');
     71        }
     72        $this->iMix = $aMix ;
    7373    }
    7474
    7575    function SetAnchor($aXAnchor='left',$aYAnchor='center') {
    76         if( !in_array($aXAnchor,$this->iAnchors) ||
    77             !in_array($aYAnchor,$this->iAnchors) ) {
    78             JpGraphError::RaiseL(8002);//("Anchor position for icons must be one of 'top', 'bottom', 'left', 'right' or 'center'");
    79         }
    80         $this->iHorAnchor=$aXAnchor;
    81         $this->iVertAnchor=$aYAnchor;
     76        if( !in_array($aXAnchor,$this->iAnchors) ||
     77        !in_array($aYAnchor,$this->iAnchors) ) {
     78            JpGraphError::RaiseL(8002);//("Anchor position for icons must be one of 'top', 'bottom', 'left', 'right' or 'center'");
     79        }
     80        $this->iHorAnchor=$aXAnchor;
     81        $this->iVertAnchor=$aYAnchor;
    8282    }
    83    
     83
    8484    function PreStrokeAdjust($aGraph) {
    85         // Nothing to do ...
     85        // Nothing to do ...
    8686    }
    8787
    8888    function DoLegend($aGraph) {
    89         // Nothing to do ...
     89        // Nothing to do ...
    9090    }
    9191
    9292    function Max() {
    93         return array(false,false);
     93        return array(false,false);
    9494    }
    9595
     
    105105
    106106    function Min() {
    107         return array(false,false);
     107        return array(false,false);
    108108    }
    109109
    110110    function StrokeMargin(&$aImg) {
    111         return true;
     111        return true;
    112112    }
    113113
    114     function Stroke($aImg,$axscale,$ayscale) {
    115         $this->StrokeWithScale($aImg,$axscale,$ayscale);
     114    function Stroke($aImg,$axscale=null,$ayscale=null) {
     115        $this->StrokeWithScale($aImg,$axscale,$ayscale);
    116116    }
    117117
    118118    function StrokeWithScale($aImg,$axscale,$ayscale) {
    119         if( $this->iScalePosX === null ||
    120             $this->iScalePosY === null ) {
    121             $this->_Stroke($aImg);
    122         }
    123         else {
    124             $this->_Stroke($aImg,
    125                           round($axscale->Translate($this->iScalePosX)),
    126                           round($ayscale->Translate($this->iScalePosY)));
    127         }
     119        if( $this->iScalePosX === null || $this->iScalePosY === null ||
     120                $axscale === null || $ayscale === null ) {
     121            $this->_Stroke($aImg);
     122        }
     123        else {
     124            $this->_Stroke($aImg,
     125                round($axscale->Translate($this->iScalePosX)),
     126                round($ayscale->Translate($this->iScalePosY)));
     127        }
    128128    }
    129129
    130130    function GetWidthHeight() {
    131         $dummy=0;
    132         return $this->_Stroke($dummy,null,null,true);
     131        $dummy=0;
     132        return $this->_Stroke($dummy,null,null,true);
    133133    }
    134134
    135135    function _Stroke($aImg,$x=null,$y=null,$aReturnWidthHeight=false) {
    136         if( $this->iFile != '' && $this->iCountryFlag != '' ) {
    137             JpGraphError::RaiseL(8003);//('It is not possible to specify both an image file and a country flag for the same icon.');   
    138         }
    139         if( $this->iFile != '' ) {
    140             $gdimg = Graph::LoadBkgImage('',$this->iFile);
    141         }
    142         elseif( $this->iImgString != '') {
    143             $gdimg = Image::CreateFromString($this->iImgString);
    144         }
     136        if( $this->iFile != '' && $this->iCountryFlag != '' ) {
     137            JpGraphError::RaiseL(8003);//('It is not possible to specify both an image file and a country flag for the same icon.');
     138        }
     139        if( $this->iFile != '' ) {
     140            $gdimg = Graph::LoadBkgImage('',$this->iFile);
     141        }
     142        elseif( $this->iImgString != '') {
     143            $gdimg = Image::CreateFromString($this->iImgString);
     144        }
    145145
    146         else {
    147             if( ! class_exists('FlagImages',false) ) {
    148                 JpGraphError::RaiseL(8004);//('In order to use Country flags as icons you must include the "jpgraph_flags.php" file.');
    149             }
    150             $fobj = new FlagImages($this->iCountryStdSize);
    151             $dummy='';
    152             $gdimg = $fobj->GetImgByName($this->iCountryFlag,$dummy);
    153         }
     146        else {
     147            if( ! class_exists('FlagImages',false) ) {
     148                JpGraphError::RaiseL(8004);//('In order to use Country flags as icons you must include the "jpgraph_flags.php" file.');
     149            }
     150            $fobj = new FlagImages($this->iCountryStdSize);
     151            $dummy='';
     152            $gdimg = $fobj->GetImgByName($this->iCountryFlag,$dummy);
     153        }
    154154
    155         $iconw = imagesx($gdimg);
    156         $iconh = imagesy($gdimg);
    157        
    158         if( $aReturnWidthHeight ) {
    159             return array(round($iconw*$this->iScale),round($iconh*$this->iScale));
    160         }
     155        $iconw = imagesx($gdimg);
     156        $iconh = imagesy($gdimg);
    161157
    162         if( $x !== null && $y !== null ) {
    163             $this->iX = $x; $this->iY = $y;
    164         }
    165         if( $this->iX >= 0  && $this->iX <= 1.0 ) {
    166             $w = imagesx($aImg->img);
    167             $this->iX = round($w*$this->iX);
    168         }
    169         if( $this->iY >= 0  && $this->iY <= 1.0 ) {
    170             $h = imagesy($aImg->img);
    171             $this->iY = round($h*$this->iY);
    172         }
     158        if( $aReturnWidthHeight ) {
     159            return array(round($iconw*$this->iScale),round($iconh*$this->iScale));
     160        }
    173161
    174         if( $this->iHorAnchor == 'center' )
    175             $this->iX -= round($iconw*$this->iScale/2);
    176         if( $this->iHorAnchor == 'right' )
    177             $this->iX -= round($iconw*$this->iScale);
    178         if( $this->iVertAnchor == 'center' )
    179             $this->iY -= round($iconh*$this->iScale/2);
    180         if( $this->iVertAnchor == 'bottom' )
    181             $this->iY -= round($iconh*$this->iScale);
     162        if( $x !== null && $y !== null ) {
     163            $this->iX = $x; $this->iY = $y;
     164        }
     165        if( $this->iX >= 0  && $this->iX <= 1.0 ) {
     166            $w = imagesx($aImg->img);
     167            $this->iX = round($w*$this->iX);
     168        }
     169        if( $this->iY >= 0  && $this->iY <= 1.0 ) {
     170            $h = imagesy($aImg->img);
     171            $this->iY = round($h*$this->iY);
     172        }
    182173
    183         $aImg->CopyMerge($gdimg,$this->iX,$this->iY,0,0,
    184                          round($iconw*$this->iScale),round($iconh*$this->iScale),
    185                          $iconw,$iconh,
    186                          $this->iMix);
     174        if( $this->iHorAnchor == 'center' )
     175        $this->iX -= round($iconw*$this->iScale/2);
     176        if( $this->iHorAnchor == 'right' )
     177        $this->iX -= round($iconw*$this->iScale);
     178        if( $this->iVertAnchor == 'center' )
     179        $this->iY -= round($iconh*$this->iScale/2);
     180        if( $this->iVertAnchor == 'bottom' )
     181        $this->iY -= round($iconh*$this->iScale);
     182
     183        $aImg->CopyMerge($gdimg,$this->iX,$this->iY,0,0,
     184        round($iconw*$this->iScale),round($iconh*$this->iScale),
     185        $iconw,$iconh,
     186        $this->iMix);
    187187    }
    188188}
Note: See TracChangeset for help on using the changeset viewer.