function GetCodewords($aData, $aLevel = 1) { $n = count($aData); if ($n == 0) { JpGraphError::RaiseL(25014); } //'No data to calculate codewords on.'); $k = 1 << $aLevel + 1; $ck = array(); $m = 929; for ($i = 0; $i < $k; ++$i) { $ck[$i] = 0; } $t1 = $t2 = 0; for ($i = 0; $i < $n; ++$i) { $t1 = ($aData[$i] + $ck[$k - 1]) % $m; for ($j = $k - 1; $j > 0; --$j) { $t2 = $t1 * $this->iPolCoeff[$aLevel][$j] % $m; $ck[$j] = ($ck[$j - 1] + ($m - $t2)) % $m; } $t2 = $t1 * $this->iPolCoeff[$aLevel][0] % $m; $ck[0] = ($m - $t2) % $m; } for ($i = 0; $i < $k; ++$i) { if ($ck[$i] > 0) { $ck[$i] = $m - $ck[$i]; } } return array_reverse($ck); }
function GetPattern($aRow, $aCodeVal) { if (empty($this->iPatterns[$aRow % 3 * 3][$aCodeVal])) { JpGraphError::RaiseL(26007, $aCodeVal, $aRow); } //"GetPattern: Illegal Code Value = $aCodeVal (row=$aRow)\n\n"); return $this->iPatterns[$aRow % 3 * 3][$aCodeVal]; }
function SetType($aType, $aFileName = '', $aScale = 1.0) { $this->type = $aType; if ($aType == MARK_IMG && $aFileName == '') { JpGraphError::RaiseL(23003); } $this->iFileName = $aFileName; $this->iScale = $aScale; }
function SetType($aType, $aFileName = '', $aScale = 1.0) { $this->type = $aType; if ($aType == MARK_IMG && $aFileName == '') { JpGraphError::RaiseL(23003); //('A filename must be specified if you set the mark type to MARK_IMG.'); } $this->iFileName = $aFileName; $this->iScale = $aScale; }
/** * */ function ApplyGraph($graph) { $this->graph = $graph; $method_name = ''; if (get_class($graph) == 'Graph') { $method_name = 'SetupGraph'; } else { $method_name = 'Setup' . get_class($graph); } if (method_exists($this, $method_name)) { $this->{$method_name}($graph); } else { JpGraphError::RaiseL(30001, $method_name, $method_name); //Theme::%s() is not defined. \nPlease make %s(\$graph) function in your theme classs. } }
function File($family, $style = FS_NORMAL) { $fam = @$this->font_files[$family]; if (!$fam) { JpGraphError::RaiseL(25046, $family); //("Specified TTF font family (id=$family) is unknown or does not exist. Please note that TTF fonts are not distributed with JpGraph for copyright reasons. You can find the MS TTF WEB-fonts (arial, courier etc) for download at http://corefonts.sourceforge.net/"); } $ff = @$fam[$style]; // There are several optional file names. They are tried in order // and the first one found is used if (!is_array($ff)) { $ff = array($ff); } $jpgraph_font_dir = dirname(__FILE__) . '/fonts/'; foreach ($ff as $font_file) { // All font families are guaranteed to have the normal style if ($font_file === '') { JpGraphError::RaiseL(25047, $this->style_names[$style], $this->font_files[$family][FS_NORMAL]); } //('Style "'.$this->style_names[$style].'" is not available for font family '.$this->font_files[$family][FS_NORMAL].'.'); if (!$font_file) { JpGraphError::RaiseL(25048, $fam); //("Unknown font style specification [$fam]."); } // check jpgraph/src/fonts dir $jpgraph_font_file = $jpgraph_font_dir . $font_file; if (file_exists($jpgraph_font_file) === true && is_readable($jpgraph_font_file) === true) { $font_file = $jpgraph_font_file; break; } // check OS font dir if ($family >= FF_MINCHO && $family <= FF_PGOTHIC) { $font_file = MBTTF_DIR . $font_file; } else { $font_file = TTF_DIR . $font_file; } if (file_exists($font_file) === true && is_readable($font_file) === true) { break; } } if (!file_exists($font_file)) { JpGraphError::RaiseL(25049, $font_file); //("Font file \"$font_file\" is not readable or does not exist."); } return $font_file; }
function GetImg($aMark, $aIdx) { $n = $this->an[$aMark]; if (is_string($aIdx)) { if (!in_array($aIdx, $this->colors)) { JpGraphError::RaiseL(23001, $this->name, $aIdx); //('This marker "'.($this->name).'" does not exist in color: '.$aIdx); } $idx = $this->index[$aIdx]; } elseif (!is_integer($aIdx) || is_integer($aIdx) && $aIdx > $this->maxidx) { JpGraphError::RaiseL(23002, $this->name); //('Mark color index too large for marker "'.($this->name).'"'); } else { $idx = $aIdx; } return Image::CreateFromString(base64_decode($this->{$n}[$idx][1])); }
public function Convert($aTxt, $aFF) { if (LANGUAGE_GREEK) { if (GREEK_FROM_WINDOWS) { $unistring = LanguageConv::gr_win2uni($aTxt); } else { $unistring = LanguageConv::gr_iso2uni($aTxt); } return $unistring; } elseif (LANGUAGE_CYRILLIC) { if (CYRILLIC_FROM_WINDOWS && (!defined('LANGUAGE_CHARSET') || stristr(LANGUAGE_CHARSET, 'windows-1251'))) { $aTxt = convert_cyr_string($aTxt, "w", "k"); } if (!defined('LANGUAGE_CHARSET') || stristr(LANGUAGE_CHARSET, 'koi8-r') || stristr(LANGUAGE_CHARSET, 'windows-1251')) { $isostring = convert_cyr_string($aTxt, "k", "i"); $unistring = LanguageConv::iso2uni($isostring); } else { $unistring = $aTxt; } return $unistring; } elseif ($aFF === FF_SIMSUN) { // Do Chinese conversion if ($this->g2312 == null) { include_once 'jpgraph_gb2312.php'; $this->g2312 = new GB2312toUTF8(); } return $this->g2312->gb2utf8($aTxt); } elseif ($aFF === FF_BIG5) { if (!function_exists('iconv')) { JpGraphError::RaiseL(25006); //('Usage of FF_CHINESE (FF_BIG5) font family requires that your PHP setup has the iconv() function. By default this is not compiled into PHP (needs the "--width-iconv" when configured).'); } return iconv('BIG5', 'UTF-8', $aTxt); } elseif (ASSUME_EUCJP_ENCODING && ($aFF == FF_MINCHO || $aFF == FF_GOTHIC || $aFF == FF_PMINCHO || $aFF == FF_PGOTHIC)) { if (!function_exists('mb_convert_encoding')) { JpGraphError::RaiseL(25127); } return mb_convert_encoding($aTxt, 'UTF-8', 'EUC-JP'); } elseif ($aFF == FF_DAVID || $aFF == FF_MIRIAM || $aFF == FF_AHRON) { return LanguageConv::heb_iso2uni($aTxt); } else { return $aTxt; } }
function Bezier($datax, $datay, $attraction_factor = 1) { $this->n = count($datax); if ($this->n !== count($datay)) { JpGraphError::RaiseL(19003); } $idx = 0; foreach ($datax as $datumx) { for ($i = 0; $i < $attraction_factor; $i++) { $this->datax[$idx++] = $datumx; } } $idx = 0; foreach ($datay as $datumy) { for ($i = 0; $i < $attraction_factor; $i++) { $this->datay[$idx++] = $datumy; } } $this->n *= $attraction_factor; }
public function Set($aLocale) { if (in_array($aLocale, array_keys($this->iDayAbb))) { $this->iLocale = $aLocale; return true; // already cached nothing else to do! } $pLocale = setlocale(LC_TIME, 0); // get current locale for LC_TIME if (is_array($aLocale)) { foreach ($aLocale as $loc) { $res = @setlocale(LC_TIME, $loc); if ($res) { $aLocale = $loc; break; } } } else { $res = @setlocale(LC_TIME, $aLocale); } if (!$res) { JpGraphError::RaiseL(25007, $aLocale); //("You are trying to use the locale ($aLocale) which your PHP installation does not support. Hint: Use '' to indicate the default locale for this geographic region."); return false; } $this->iLocale = $aLocale; for ($i = 0, $ofs = 0 - strftime('%w'); $i < 7; $i++, $ofs++) { $day = strftime('%a', strtotime("{$ofs} day")); $day[0] = strtoupper($day[0]); $this->iDayAbb[$aLocale][] = $day[0]; $this->iShortDay[$aLocale][] = $day; } for ($i = 1; $i <= 12; ++$i) { list($short, $full) = explode('|', strftime("%b|%B", strtotime("2001-{$i}-01"))); $this->iShortMonth[$aLocale][] = ucfirst($short); $this->iMonthName[$aLocale][] = ucfirst($full); } setlocale(LC_TIME, $pLocale); return true; }
public function __construct($datax, $datay, $attraction_factor = 1) { // Adding control point multiple time will raise their attraction power over the curve $this->n = count($datax); if ($this->n !== count($datay)) { JpGraphError::RaiseL(19003); //('Bezier: Number of X and Y coordinates must be the same'); } $idx = 0; foreach ($datax as $datumx) { for ($i = 0; $i < $attraction_factor; $i++) { $this->datax[$idx++] = $datumx; } } $idx = 0; foreach ($datay as $datumy) { for ($i = 0; $i < $attraction_factor; $i++) { $this->datay[$idx++] = $datumy; } } $this->n *= $attraction_factor; }
public function E($aXMin, $aXMax, $aSteps = 50) { $this->iMin = $aXMin; $this->iMax = $aXMax; $this->iStepSize = ($aXMax - $aXMin) / $aSteps; if ($this->iXFunc != '') { $t = 'for($i=' . $aXMin . '; $i<=' . $aXMax . '; $i += ' . $this->iStepSize . ') {$ya[]=' . $this->iFunc . ';$xa[]=' . $this->iXFunc . ';}'; } elseif ($this->iFunc != '') { $t = 'for($x=' . $aXMin . '; $x<=' . $aXMax . '; $x += ' . $this->iStepSize . ') {$ya[]=' . $this->iFunc . ';$xa[]=$x;} $x=' . $aXMax . ';$ya[]=' . $this->iFunc . ';$xa[]=$x;'; } else { JpGraphError::RaiseL(24001); } //('FuncGenerator : No function specified. '); @eval($t); // If there is an error in the function specifcation this is the only // way we can discover that. if (empty($xa) || empty($ya)) { JpGraphError::RaiseL(24002); } //('FuncGenerator : Syntax error in function specification '); return array($xa, $ya); }
function __get($name) { if (strpos($name, 'raw_') !== false) { // if $name == 'raw_left_margin' , return $this->_left_margin; $variable_name = '_' . str_replace('raw_', '', $name); return $this->{$variable_name}; } $variable_name = '_' . $name; if (isset($this->{$variable_name})) { return $this->{$variable_name} * SUPERSAMPLING_SCALE; } else { JpGraphError::RaiseL('25132', $name); } }
function Stroke($img, $xscale, $yscale) { $n = $this->numpoints; if ($this->center) { $n--; } if (isset($this->coords[1])) { if (count($this->coords[1]) != $n) { JpGraphError::RaiseL(2003, count($this->coords[1]), $n); // ("Number of X and Y points are not equal. Number of X-points:".count($this->coords[1])." Number of Y-points:$numpoints"); } else { $exist_x = true; } } else { $exist_x = false; } if ($exist_x) { $xs = $this->coords[1][0]; } else { $xs = 0; } $ts = $this->iTupleSize; $this->csimareas = ''; for ($i = 0; $i < $n; ++$i) { //If value is NULL, then don't draw a bar at all if ($this->coords[0][$i * $ts] === null) { continue; } if ($exist_x) { $x = $this->coords[1][$i]; if ($x === null) { continue; } } else { $x = $i; } $xt = $xscale->Translate($x); $neg = $this->coords[0][$i * $ts] > $this->coords[0][$i * $ts + 1]; $yopen = $yscale->Translate($this->coords[0][$i * $ts]); $yclose = $yscale->Translate($this->coords[0][$i * $ts + 1]); $ymin = $yscale->Translate($this->coords[0][$i * $ts + 2]); $ymax = $yscale->Translate($this->coords[0][$i * $ts + 3]); $dx = floor($this->iWidth / 2); $xl = $xt - $dx; $xr = $xt + $dx; if ($neg) { $img->SetColor($this->iStockColor3); } else { $img->SetColor($this->iStockColor1); } $img->FilledRectangle($xl, $yopen, $xr, $yclose); $img->SetLineWeight($this->weight); if ($neg) { $img->SetColor($this->iStockColor2); } else { $img->SetColor($this->color); } $img->Rectangle($xl, $yopen, $xr, $yclose); if ($yopen < $yclose) { $ytop = $yopen; $ybottom = $yclose; } else { $ytop = $yclose; $ybottom = $yopen; } $img->SetColor($this->color); $img->Line($xt, $ytop, $xt, $ymax); $img->Line($xt, $ybottom, $xt, $ymin); if ($this->iEndLines) { $img->Line($xl, $ymax, $xr, $ymax); $img->Line($xl, $ymin, $xr, $ymin); } // A chance for subclasses to add things to the bar // for data point i $this->ModBox($img, $xscale, $yscale, $i, $xl, $xr, $neg); // Setup image maps if (!empty($this->csimtargets[$i])) { $this->csimareas .= '<area shape="rect" coords="' . round($xl) . ',' . round($ytop) . ',' . round($xr) . ',' . round($ybottom) . '" '; $this->csimareas .= ' href="' . $this->csimtargets[$i] . '"'; if (!empty($this->csimalts[$i])) { $sval = $this->csimalts[$i]; $this->csimareas .= " title=\"{$sval}\" alt=\"{$sval}\" "; } $this->csimareas .= " />\n"; } } return true; }
function SetOrientation($aDirection = 0) { if (is_numeric($aDirection)) { $this->dir = $aDirection; } elseif ($aDirection == "h") { $this->dir = 0; } elseif ($aDirection == "v") { $this->dir = 90; } else { JpGraphError::RaiseL(25051); } //(" Invalid direction specified for text."); }
function FilledRectangle($xl, $yt, $xr, $yb, $from_color, $to_color, $style = 1) { switch ($style) { case GRAD_VER: $steps = round(abs($xr - $xl)); $delta = $xr >= $xl ? 1 : -1; $this->GetColArray($from_color, $to_color, $steps, $colors, $this->numcolors); for ($i = 0, $x = $xl; $i < $steps; ++$i) { $this->img->current_color = $colors[$i]; $this->img->Line($x, $yt, $x, $yb); $x += $delta; } break; case GRAD_HOR: $steps = round(abs($yb - $yt)); $delta = $yb >= $yt ? 1 : -1; $this->GetColArray($from_color, $to_color, $steps, $colors, $this->numcolors); for ($i = 0, $y = $yt; $i < $steps; ++$i) { $this->img->current_color = $colors[$i]; $this->img->Line($xl, $y, $xr, $y); $y += $delta; } break; case GRAD_MIDHOR: $steps = round(abs($yb - $yt) / 2); $delta = $yb >= $yt ? 1 : -1; $this->GetColArray($from_color, $to_color, $steps, $colors, $this->numcolors); for ($y = $yt, $i = 0; $i < $steps; ++$i) { $this->img->current_color = $colors[$i]; $this->img->Line($xl, $y, $xr, $y); $y += $delta; } --$i; if (abs($yb - $yt) % 2 == 1) { --$steps; } for ($j = 0; $j < $steps; ++$j, --$i) { $this->img->current_color = $colors[$i]; $this->img->Line($xl, $y, $xr, $y); $y += $delta; } $this->img->Line($xl, $y, $xr, $y); break; case GRAD_MIDVER: $steps = round(abs($xr - $xl) / 2); $delta = $xr >= $xl ? 1 : -1; $this->GetColArray($from_color, $to_color, $steps, $colors, $this->numcolors); for ($x = $xl, $i = 0; $i < $steps; ++$i) { $this->img->current_color = $colors[$i]; $this->img->Line($x, $yb, $x, $yt); $x += $delta; } --$i; if (abs($xr - $xl) % 2 == 1) { --$steps; } for ($j = 0; $j < $steps; ++$j, --$i) { $this->img->current_color = $colors[$i]; $this->img->Line($x, $yb, $x, $yt); $x += $delta; } $this->img->Line($x, $yb, $x, $yt); break; case GRAD_WIDE_MIDVER: $diff = round(abs($xr - $xl)); $steps = floor(abs($diff) / 3); $firststep = $diff - 2 * $steps; $delta = $xr >= $xl ? 1 : -1; $this->GetColArray($from_color, $to_color, $firststep, $colors, $this->numcolors); for ($x = $xl, $i = 0; $i < $firststep; ++$i) { $this->img->current_color = $colors[$i]; $this->img->Line($x, $yb, $x, $yt); $x += $delta; } --$i; $this->img->current_color = $colors[$i]; for ($j = 0; $j < $steps; ++$j) { $this->img->Line($x, $yb, $x, $yt); $x += $delta; } for ($j = 0; $j < $steps; ++$j, --$i) { $this->img->current_color = $colors[$i]; $this->img->Line($x, $yb, $x, $yt); $x += $delta; } break; case GRAD_WIDE_MIDHOR: $diff = round(abs($yb - $yt)); $steps = floor(abs($diff) / 3); $firststep = $diff - 2 * $steps; $delta = $yb >= $yt ? 1 : -1; $this->GetColArray($from_color, $to_color, $firststep, $colors, $this->numcolors); for ($y = $yt, $i = 0; $i < $firststep; ++$i) { $this->img->current_color = $colors[$i]; $this->img->Line($xl, $y, $xr, $y); $y += $delta; } --$i; $this->img->current_color = $colors[$i]; for ($j = 0; $j < $steps; ++$j) { $this->img->Line($xl, $y, $xr, $y); $y += $delta; } for ($j = 0; $j < $steps; ++$j, --$i) { $this->img->current_color = $colors[$i]; $this->img->Line($xl, $y, $xr, $y); $y += $delta; } break; case GRAD_LEFT_REFLECTION: $steps1 = round(0.3 * abs($xr - $xl)); $delta = $xr >= $xl ? 1 : -1; $from_color = $this->img->rgb->Color($from_color); $adj = 1.4; $m = ($adj - 1.0) * (255 - min(255, min($from_color[0], min($from_color[1], $from_color[2])))); $from_color2 = array(min(255, $from_color[0] + $m), min(255, $from_color[1] + $m), min(255, $from_color[2] + $m)); $this->GetColArray($from_color2, $to_color, $steps1, $colors, $this->numcolors); $n = count($colors); for ($x = $xl, $i = 0; $i < $steps1 && $i < $n; ++$i) { $this->img->current_color = $colors[$i]; $this->img->Line($x, $yb, $x, $yt); $x += $delta; } $steps2 = max(1, round(0.08 * abs($xr - $xl))); $this->img->SetColor($to_color); for ($j = 0; $j < $steps2; ++$j) { $this->img->Line($x, $yb, $x, $yt); $x += $delta; } $steps = abs($xr - $xl) - $steps1 - $steps2; $this->GetColArray($to_color, $from_color, $steps, $colors, $this->numcolors); $n = count($colors); for ($i = 0; $i < $steps && $i < $n; ++$i) { $this->img->current_color = $colors[$i]; $this->img->Line($x, $yb, $x, $yt); $x += $delta; } break; case GRAD_RIGHT_REFLECTION: $steps1 = round(0.7 * abs($xr - $xl)); $delta = $xr >= $xl ? 1 : -1; $this->GetColArray($from_color, $to_color, $steps1, $colors, $this->numcolors); $n = count($colors); for ($x = $xl, $i = 0; $i < $steps1 && $i < $n; ++$i) { $this->img->current_color = $colors[$i]; $this->img->Line($x, $yb, $x, $yt); $x += $delta; } $steps2 = max(1, round(0.08 * abs($xr - $xl))); $this->img->SetColor($to_color); for ($j = 0; $j < $steps2; ++$j) { $this->img->Line($x, $yb, $x, $yt); $x += $delta; } $from_color = $this->img->rgb->Color($from_color); $adj = 1.4; $m = ($adj - 1.0) * (255 - min(255, min($from_color[0], min($from_color[1], $from_color[2])))); $from_color = array(min(255, $from_color[0] + $m), min(255, $from_color[1] + $m), min(255, $from_color[2] + $m)); $steps = abs($xr - $xl) - $steps1 - $steps2; $this->GetColArray($to_color, $from_color, $steps, $colors, $this->numcolors); $n = count($colors); for ($i = 0; $i < $steps && $i < $n; ++$i) { $this->img->current_color = $colors[$i]; $this->img->Line($x, $yb, $x, $yt); $x += $delta; } break; case GRAD_CENTER: $steps = ceil(min($yb - $yt + 1, $xr - $xl + 1) / 2); $this->GetColArray($from_color, $to_color, $steps, $colors, $this->numcolors); $dx = ($xr - $xl) / 2; $dy = ($yb - $yt) / 2; $x = $xl; $y = $yt; $x2 = $xr; $y2 = $yb; $n = count($colors); for ($x = $xl, $i = 0; $x < $xl + $dx && $y < $yt + $dy && $i < $n; ++$x, ++$y, --$x2, --$y2, ++$i) { $this->img->current_color = $colors[$i]; $this->img->Rectangle($x, $y, $x2, $y2); } $this->img->Line($x, $y, $x2, $y2); break; case GRAD_RAISED_PANEL: // right to left $steps1 = $xr - $xl; $delta = $xr >= $xl ? 1 : -1; $this->GetColArray($to_color, $from_color, $steps1, $colors, $this->numcolors); $n = count($colors); for ($x = $xl, $i = 0; $i < $steps1 && $i < $n; ++$i) { $this->img->current_color = $colors[$i]; $this->img->Line($x, $yb, $x, $yt); $x += $delta; } // left to right $xr -= 3; $xl += 3; $yb -= 3; $yt += 3; $steps2 = $xr - $xl; $delta = $xr >= $xl ? 1 : -1; for ($x = $xl, $j = $steps2; $j >= 0; --$j) { $this->img->current_color = $colors[$j]; $this->img->Line($x, $yb, $x, $yt); $x += $delta; } break; case GRAD_DIAGONAL: // use the longer dimension to determine the required number of steps. // first loop draws from one corner to the mid-diagonal and the second // loop draws from the mid-diagonal to the opposing corner. if ($xr - $xl > $yb - $yt) { // width is greater than height -> use x-dimension for steps $steps = $xr - $xl; $delta = $xr >= $xl ? 1 : -1; $this->GetColArray($from_color, $to_color, $steps * 2, $colors, $this->numcolors); $n = count($colors); for ($x = $xl, $i = 0; $i < $steps && $i < $n; ++$i) { $this->img->current_color = $colors[$i]; $y = $yt + $i / $steps * ($yb - $yt) * $delta; $this->img->Line($x, $yt, $xl, $y); $x += $delta; } for ($x = $xl, $i = 0; $i < $steps && $i < $n; ++$i) { $this->img->current_color = $colors[$steps + $i]; $y = $yt + $i / $steps * ($yb - $yt) * $delta; $this->img->Line($x, $yb, $xr, $y); $x += $delta; } } else { // height is greater than width -> use y-dimension for steps $steps = $yb - $yt; $delta = $yb >= $yt ? 1 : -1; $this->GetColArray($from_color, $to_color, $steps * 2, $colors, $this->numcolors); $n = count($colors); for ($y = $yt, $i = 0; $i < $steps && $i < $n; ++$i) { $this->img->current_color = $colors[$i]; $x = $xl + $i / $steps * ($xr - $xl) * $delta; $this->img->Line($x, $yt, $xl, $y); $y += $delta; } for ($y = $yt, $i = 0; $i < $steps && $i < $n; ++$i) { $this->img->current_color = $colors[$steps + $i]; $x = $xl + $i / $steps * ($xr - $xl) * $delta; $this->img->Line($x, $yb, $xr, $y); $x += $delta; } } break; default: JpGraphError::RaiseL(7001, $style); //("Unknown gradient style (=$style)."); break; } }
function SetTextLabelStart($aStart) { JpGraphError::RaiseL(11005); //('Specifying tick interval for a logarithmic scale is undefined. Remove any calls to SetTextLabelStart() or SetTextTickInterval() on the logarithmic scale.'); }
function _gdImgHandle($agdCanvas, $x, $y, $fx = 0, $fy = 0, $w = 0, $h = 0, $mix = 100) { if ($w == 0) { $w = @imagesx($agdCanvas); } if ($w === NULL) { JpGraphError::RaiseL(12007); //('Argument to MGraph::Add() is not a valid GD image handle.'); return; } if ($h == 0) { $h = @imagesy($agdCanvas); } $this->iGraphs[$this->iCnt++] = array($agdCanvas, $x, $y, $fx, $fy, $w, $h, $mix); }
function _StrokeRegularRose($dblImg, $value, $scaling, $xc, $yc, $r, $ri) { // _StrokeRegularRose($dblImg,$xc,$yc,$r,$ri) // Plot radial grid lines and remember the end position // and the angle for later use when plotting the labels switch ($this->iType) { case WINDROSE_TYPE4: $num = 4; break; case WINDROSE_TYPE8: $num = 8; break; case WINDROSE_TYPE16: $num = 16; break; default: JpGraphError::RaiseL(22015); //('You have specified an undefined Windrose plot type.'); } // Check if we should auto-position the angle for the // labels. Basically we try to find a firection with smallest // (or none) data. $this->SetAutoScaleAngle(true); $nlc = count($this->iLegColors); $nlw = count($this->iLegweights); $this->iRadialColorArray = $this->FixupIndexes($this->iRadialColorArray, $num); $this->iRadialWeightArray = $this->FixupIndexes($this->iRadialWeightArray, $num); $this->iRadialStyleArray = $this->FixupIndexes($this->iRadialStyleArray, $num); $txtpos = array(); $a = 2 * M_PI / $num; $dblImg->SetColor($this->iGridColor2); $dblImg->SetLineStyle($this->iRadialGridStyle); $dblImg->SetLineWeight($this->iRadialGridWeight); // Translate any name specified directions to the index // so we can easily use it in the loop below for ($i = 0; $i < $num; ++$i) { $xxc = round($xc + cos($a * $i) * $ri); $yyc = round($yc - sin($a * $i) * $ri); $x = round($xc + cos($a * $i) * $r); $y = round($yc - sin($a * $i) * $r); if (empty($this->iRadialColorArray[$i])) { $dblImg->SetColor($this->iGridColor2); } else { $dblImg->SetColor($this->iRadialColorArray[$i]); } if (empty($this->iRadialWeightArray[$i])) { $dblImg->SetLineWeight($this->iRadialGridWeight); } else { $dblImg->SetLineWeight($this->iRadialWeightArray[$i]); } if (empty($this->iRadialStyleArray[$i])) { $dblImg->SetLineStyle($this->iRadialGridStyle); } else { $dblImg->SetLineStyle($this->iRadialStyleArray[$i]); } $dblImg->StyleLine($xxc, $yyc, $x, $y); $txtpos[] = array($x, $y, $a * $i); } $dblImg->SetLineWeight(1); $lr = $scaling * $this->iLabelMargin; if ($this->iLabelPositioning == LBLPOSITION_CENTER) { $value->SetAlign('center', 'center'); } else { $value->SetAlign('left', 'top'); $value->SetMargin(0); $lr /= 2; } for ($i = 0; $i < $num; ++$i) { list($x, $y, $a) = $txtpos[$i]; // Set the position of the label if ($this->iLabelPositioning == LBLPOSITION_CENTER) { $dx = $dy = 0; } else { // LBLPOSIITON_EDGE if ($a >= 7 * M_PI / 4 || $a <= M_PI / 4) { $dx = 0; } if ($a >= M_PI / 4 && $a <= 3 * M_PI / 4) { $dx = ($a - M_PI / 4) * 2 / M_PI; } if ($a >= 3 * M_PI / 4 && $a <= 5 * M_PI / 4) { $dx = 1; } if ($a >= 5 * M_PI / 4 && $a <= 7 * M_PI / 4) { $dx = 1 - ($a - M_PI * 5 / 4) * 2 / M_PI; } if ($a >= 7 * M_PI / 4) { $dy = ($a - M_PI - 3 * M_PI / 4) * 2 / M_PI; } if ($a <= M_PI / 4) { $dy = 0.5 + $a * 2 / M_PI; } if ($a >= M_PI / 4 && $a <= 3 * M_PI / 4) { $dy = 1; } if ($a >= 3 * M_PI / 4 && $a <= 5 * M_PI / 4) { $dy = 1 - ($a - 3 * M_PI / 4) * 2 / M_PI; } if ($a >= 5 * M_PI / 4 && $a <= 7 * M_PI / 4) { $dy = 0; } } $value->Set($this->iAllDirectionLabels[$i * (16 / $num)]); $th = $value->GetHeight($dblImg); $tw = $value->GetWidth($dblImg); $xt = round($lr * cos($a) + $x) - $dx * $tw; $yt = round($y - $lr * sin($a)) - $dy * $th; $value->Stroke($dblImg, $xt, $yt); } if (__DEBUG) { $dblImg->SetColor("red"); $dblImg->Circle($xc, $yc, $lr + $r); } // Stroke all the legs reset($this->iData); $keys = array_keys($this->iData); foreach ($this->iData as $idx => $legdata) { $legdata = array_slice($legdata, 1); $nn = count($legdata); if (is_string($idx)) { $idx = strtoupper($idx); $idx = array_search($idx, $this->iAllDirectionLabels); if ($idx === false) { JpGraphError::RaiseL(22016); //('Windrose leg index must be numeric or direction label.'); } if ($idx % (16 / $num) !== 0) { JpGraphError::RaiseL(22017); //('Windrose data contains a direction which is not enabled. Please adjust what labels are displayed.'); } $idx /= 16 / $num; if (in_array($idx, $keys, 1)) { JpgraphError::RaiseL(22018, $idx); //('You have specified data for the same compass direction twice, once with text and once with index (Index='.$idx.')'); } } if ($idx < 0 || $idx > 15) { JpgraphError::RaiseL(22019); //('Index for direction must be between 0 and 15. You can\'t specify angles for a Regular Windplot, only index and compass directions.'); } $a = $idx * (360 / $num); $a *= M_PI / 180.0; $rri = $ri / $scaling; for ($j = 0; $j < $nn; ++$j) { // We want the non scaled original radius $legr = $this->scale->RelTranslate($legdata[$j], $r / $scaling, $ri / $scaling); $this->_StrokeWindLeg($dblImg, $xc, $yc, $a, $rri * $scaling, $legr * $scaling, $this->iLegweights[$j % $nlw] * $scaling, $this->iLegColors[$j % $nlc]); $rri += $legr; } } }
function Stroke($aImg) { // The way the path for the arrow is constructed is partly based // on some heuristics. This is not an exact science but draws the // path in a way that, for me, makes esthetic sence. For example // if the start and end activities are very close we make a small // detour to endter the target horixontally. If there are more // space between axctivities then no suh detour is made and the // target is "hit" directly vertical. I have tried to keep this // simple. no doubt this could become almost infinitive complex // and have some real AI. Feel free to modify this. // This will no-doubt be tweaked as times go by. One design aim // is to avoid having the user choose what types of arrow // he wants. // The arrow is drawn between (x1,y1) to (x2,y2) $x1 = $this->ix1; $x2 = $this->ix2; $y1 = $this->iy1; $y2 = $this->iy2; // Depending on if the target is below or above we have to // handle thi different. if ($y2 > $y1) { $arrowtype = ARROW_DOWN; $midy = round(($y2 - $y1) / 2 + $y1); if ($x2 > $x1) { switch ($this->iPathType) { case 0: $c = array($x1, $y1, $x1, $midy, $x2, $midy, $x2, $y2); break; case 1: case 2: case 3: $c = array($x1, $y1, $x2, $y1, $x2, $y2); break; default: JpGraphError::RaiseL(6032, $this->iPathType); //('Internal error: Unknown path type (='.$this->iPathType .') specified for link.'); exit(1); break; } } else { switch ($this->iPathType) { case 0: case 1: $c = array($x1, $y1, $x1, $midy, $x2, $midy, $x2, $y2); break; case 2: // Always extend out horizontally a bit from the first point // If we draw a link back in time (end to start) and the bars // are very close we also change the path so it comes in from // the left on the activity $c = array($x1, $y1, $x1 + $this->iPathExtend, $y1, $x1 + $this->iPathExtend, $midy, $x2, $midy, $x2, $y2); break; case 3: if ($y2 - $midy < 6) { $c = array($x1, $y1, $x1, $midy, $x2 - $this->iPathExtend, $midy, $x2 - $this->iPathExtend, $y2, $x2, $y2); $arrowtype = ARROW_RIGHT; } else { $c = array($x1, $y1, $x1, $midy, $x2, $midy, $x2, $y2); } break; default: JpGraphError::RaiseL(6032, $this->iPathType); //('Internal error: Unknown path type specified for link.'); exit(1); break; } } $arrow = new LinkArrow($x2, $y2, $arrowtype); } else { // Y2 < Y1 $arrowtype = ARROW_UP; $midy = round(($y1 - $y2) / 2 + $y2); if ($x2 > $x1) { switch ($this->iPathType) { case 0: case 1: $c = array($x1, $y1, $x1, $midy, $x2, $midy, $x2, $y2); break; case 3: if ($midy - $y2 < 8) { $arrowtype = ARROW_RIGHT; $c = array($x1, $y1, $x1, $y2, $x2, $y2); } else { $c = array($x1, $y1, $x1, $midy, $x2, $midy, $x2, $y2); } break; default: JpGraphError::RaiseL(6032, $this->iPathType); //('Internal error: Unknown path type specified for link.'); break; } } else { switch ($this->iPathType) { case 0: case 1: $c = array($x1, $y1, $x1, $midy, $x2, $midy, $x2, $y2); break; case 2: // Always extend out horizontally a bit from the first point $c = array($x1, $y1, $x1 + $this->iPathExtend, $y1, $x1 + $this->iPathExtend, $midy, $x2, $midy, $x2, $y2); break; case 3: if ($midy - $y2 < 16) { $arrowtype = ARROW_RIGHT; $c = array($x1, $y1, $x1, $midy, $x2 - $this->iPathExtend, $midy, $x2 - $this->iPathExtend, $y2, $x2, $y2); } else { $c = array($x1, $y1, $x1, $midy, $x2, $midy, $x2, $y2); } break; default: JpGraphError::RaiseL(6032, $this->iPathType); //('Internal error: Unknown path type specified for link.'); break; } } $arrow = new LinkArrow($x2, $y2, $arrowtype); } $aImg->SetColor($this->iColor); $aImg->SetLineWeight($this->iWeight); $aImg->Polygon($c); $aImg->SetLineWeight(1); $arrow->SetColor($this->iColor); $arrow->SetSize($this->iArrowSize); $arrow->SetType($this->iArrowType); $arrow->Stroke($aImg); }
static function Create($aBackend, $aEncoder, $aReport = false) { $backends = array('IMAGE', 'PS'); if (array_search($aBackend, $backends) === false) { if ($aReport) { JpGraphError::RaiseL(1011, $aBackend); } else { return false; } } $b = 'OutputBackend_' . $aBackend; return new $b($aEncoder); }
function Stroke($aStrokeFileName = "") { $n = count($this->plots); // Set Y-scale if (!$this->yscale->IsSpecified() && count($this->plots) > 0) { list($min, $max) = $this->GetPlotsYMinMax(); $this->yscale->AutoScale($this->img, 0, $max, $this->len / $this->ytick_factor); } // Set start position end length of scale (in absolute pixels) $this->yscale->SetConstants($this->posx, $this->len); // We need as many axis as there are data points $nbrpnts = $this->plots[0]->GetCount(); // If we have no titles just number the axis 1,2,3,... if ($this->axis_title == null) { for ($i = 0; $i < $nbrpnts; ++$i) { $this->axis_title[$i] = $i + 1; } } elseif (count($this->axis_title) < $nbrpnts) { JpGraphError::RaiseL(18007); } //("Number of titles does not match number of points in plot."); for ($i = 0; $i < $n; ++$i) { if ($nbrpnts != $this->plots[$i]->GetCount()) { JpGraphError::RaiseL(18008); } } //("Each radar plot must have the same number of data points."); if ($this->background_image != "") { $this->StrokeFrameBackground(); } else { $this->StrokeFrame(); } $astep = 2 * M_PI / $nbrpnts; // Prepare legends for ($i = 0; $i < $n; ++$i) { $this->plots[$i]->Legend($this); } $this->legend->Stroke($this->img); $this->footer->Stroke($this->img); if ($this->grid_depth == DEPTH_BACK) { // Draw axis and grid for ($i = 0, $a = M_PI / 2; $i < $nbrpnts; ++$i, $a += $astep) { $this->axis->Stroke($this->posy, $a, $grid[$i], $this->axis_title[$i], $i == 0); } } // Plot points $a = M_PI / 2; for ($i = 0; $i < $n; ++$i) { $this->plots[$i]->Stroke($this->img, $this->posy, $this->yscale, $a); } if ($this->grid_depth != DEPTH_BACK) { // Draw axis and grid for ($i = 0, $a = M_PI / 2; $i < $nbrpnts; ++$i, $a += $astep) { $this->axis->Stroke($this->posy, $a, $grid[$i], $this->axis_title[$i], $i == 0); } } $this->grid->Stroke($this->img, $grid); $this->StrokeTitles(); // Stroke texts if ($this->texts != null) { foreach ($this->texts as $t) { $t->Stroke($this->img); } } // Should we do any final image transformation if ($this->iImgTrans) { if (!class_exists('ImgTrans')) { require_once 'jpgraph_imgtrans.php'; } $tform = new ImgTrans($this->img->img); $this->img->img = $tform->Skew3D($this->iImgTransHorizon, $this->iImgTransSkewDist, $this->iImgTransDirection, $this->iImgTransHighQ, $this->iImgTransMinSize, $this->iImgTransFillColor, $this->iImgTransBorder); } // If the filename is given as the special "__handle" // then the image handler is returned and the image is NOT // streamed back if ($aStrokeFileName == _IMG_HANDLER) { return $this->img->img; } else { // Finally stream the generated picture $this->cache->PutAndStream($this->img, $this->cache_name, $this->inline, $aStrokeFileName); } }
function SetImgFormat($aFormat, $aQuality = 75) { $this->quality = $aQuality; $aFormat = strtolower($aFormat); $tst = true; $supported = imagetypes(); if ($aFormat == "auto") { if ($supported & IMG_PNG) { $this->img_format = "png"; } elseif ($supported & IMG_JPG) { $this->img_format = "jpeg"; } elseif ($supported & IMG_GIF) { $this->img_format = "gif"; } elseif ($supported & IMG_WBMP) { $this->img_format = "wbmp"; } elseif ($supported & IMG_XPM) { $this->img_format = "xpm"; } else { JpGraphError::RaiseL(25109); } //("Your PHP (and GD-lib) installation does not appear to support any known graphic formats. You need to first make sure GD is compiled as a module to PHP. If you also want to use JPEG images you must get the JPEG library. Please see the PHP docs for details."); return true; } else { if ($aFormat == "jpeg" || $aFormat == "png" || $aFormat == "gif" || $aFormat == "wbmp" || $aFormat == "xpm") { if ($aFormat == "jpeg" && !($supported & IMG_JPG)) { $tst = false; } elseif ($aFormat == "png" && !($supported & IMG_PNG)) { $tst = false; } elseif ($aFormat == "gif" && !($supported & IMG_GIF)) { $tst = false; } elseif ($aFormat == "wbmp" && !($supported & IMG_WBMP)) { $tst = false; } elseif ($aFormat == "xpm" && !($supported & IMG_XPM)) { $tst = false; } else { $this->img_format = $aFormat; return true; } } else { $tst = false; } if (!$tst) { JpGraphError::RaiseL(25110, $aFormat); } //(" Your PHP installation does not support the chosen graphic format: $aFormat"); } }
function AccLinePlot($plots) { $this->plots = $plots; $this->nbrplots = count($plots); $this->numpoints = $plots[0]->numpoints; // Verify that all plots have the same number of data points for ($i = 1; $i < $this->nbrplots; ++$i) { if ($plots[$i]->numpoints != $this->numpoints) { JpGraphError::RaiseL(10003); //('Each plot in an accumulated lineplot must have the same number of data points',0) } } for ($i = 0; $i < $this->nbrplots; ++$i) { $this->LineInterpolate($this->plots[$i]->coords[0]); } }
function __construct($aDir, $aPattern, $aMin, $aMax, $aColor = "black", $aWeight = 1, $aDepth = DEPTH_BACK) { $f = new RectPatternFactory(); $this->prect = $f->Create($aPattern, $aColor, $aWeight); if (is_numeric($aMin) && is_numeric($aMax) && $aMin > $aMax) { JpGraphError::RaiseL(16004); } //('Min value for plotband is larger than specified max value. Please correct.'); $this->dir = $aDir; $this->min = $aMin; $this->max = $aMax; $this->depth = $aDepth; }
function Stream($aFile = "") { $func = "image" . $this->img_format; if ($this->img_format == "jpeg" && $this->image_quality != null) { $res = @$func($this->img, $aFile, $this->image_quality); } else { if ($aFile != "") { $res = @$func($this->img, $aFile); } else { $res = @$func($this->img); } } if (!$res) { JpGraphError::RaiseL(12010, $aFile); } //("Can't create or stream image to file $aFile Check that PHP has enough permission to write a file to the current directory."); }
function PreStrokeAdjust($aGraph) { if (substr($aGraph->axtype, 0, 4) == "text" && isset($this->coords[1])) { JpGraphError::RaiseL(25123); //("JpGraph: You can't use a text X-scale with specified X-coords. Use a \"int\" or \"lin\" scale instead."); } return true; }
function Allocate($aColor, $aAlpha = 0.0) { list($r, $g, $b, $a) = $this->color($aColor); // If alpha is specified in the color string then this // takes precedence over the second argument if ($a > 0) { $aAlpha = $a; } if ($aAlpha < 0 || $aAlpha > 1) { JpGraphError::RaiseL(25080); //('Alpha parameter for color must be between 0.0 and 1.0'); } return imagecolorresolvealpha($this->img, $r, $g, $b, round($aAlpha * 127)); }
function __construct($datay, $datax = false) { if (count($datax) != count($datay) && is_array($datax)) { JpGraphError::RaiseL(20003); //("Scatterplot must have equal number of X and Y points."); } parent::__construct($datay, $datax); $this->mark = new PlotMark(); $this->mark->SetType(MARK_SQUARE); $this->mark->SetColor($this->color); $this->value->SetAlign('center', 'center'); $this->value->SetMargin(0); $this->link = new LineProperty(1, 'black', 'solid'); $this->link->iShow = false; }
function LineErrorPlot(&$datay, $datax = false) { $ly = array(); $ey = array(); $n = count($datay); if ($n % 3 != 0) { JpGraphError::RaiseL(4002); //('Error in input data to LineErrorPlot. Number of data points must be a multiple of 3'); } for ($i = 0; $i < $n; $i += 3) { $ly[] = $datay[$i]; $ey[] = $datay[$i] + $datay[$i + 1]; $ey[] = $datay[$i] + $datay[$i + 2]; } $this->ErrorPlot($ey, $datax); $this->line = new LinePlot($ly, $datax); }