function DrawLabelRotated($im, $x, $y, $angle, $text, $font, $padding, $linkname, $textcolour, $bgcolour, $outlinecolour, &$map, $direction) { list($strwidth, $strheight)=$this->myimagestringsize($font, $text); if(abs($angle)>90) $angle -= 180; if($angle < -180) $angle +=360; $rangle = -deg2rad($angle); $extra=3; $x1= $x - ($strwidth / 2) - $padding - $extra; $x2= $x + ($strwidth / 2) + $padding + $extra; $y1= $y - ($strheight / 2) - $padding - $extra; $y2= $y + ($strheight / 2) + $padding + $extra; // a box. the last point is the start point for the text. $points = array($x1,$y1, $x1,$y2, $x2,$y2, $x2,$y1, $x-$strwidth/2, $y+$strheight/2 + 1); $npoints = count($points)/2; RotateAboutPoint($points, $x,$y, $rangle); if ($bgcolour != array ( -1, -1, -1 )) { $bgcol=myimagecolorallocate($im, $bgcolour[0], $bgcolour[1], $bgcolour[2]); # imagefilledrectangle($im, $x1, $y1, $x2, $y2, $bgcol); wimagefilledpolygon($im,$points,4,$bgcol); } if ($outlinecolour != array ( -1, -1, -1 )) { $outlinecol=myimagecolorallocate($im, $outlinecolour[0], $outlinecolour[1], $outlinecolour[2]); # imagerectangle($im, $x1, $y1, $x2, $y2, $outlinecol); wimagepolygon($im,$points,4,$outlinecol); } $textcol=myimagecolorallocate($im, $textcolour[0], $textcolour[1], $textcolour[2]); $this->myimagestring($im, $font, $points[8], $points[9], $text, $textcol,$angle); $areaname = "LINK:L".$map->links[$linkname]->id.':'.($direction+2); // the rectangle is about half the size in the HTML, and easier to optimise/detect in the browser if($angle==0) { $map->imap->addArea("Rectangle", $areaname, '', array($x1, $y1, $x2, $y2)); wm_debug ("Adding Rectangle imagemap for $areaname\n"); } else { $map->imap->addArea("Polygon", $areaname, '', $points); wm_debug ("Adding Poly imagemap for $areaname\n"); } }
function draw_curve($image, &$curvepoints, $widths, $outlinecolour, $fillcolours, $linkname, &$map, $q2_percent = 50, $unidirectional = FALSE) { // now we have a 'spine' - all the central points for this curve. // time to flesh it out to the right width, and figure out where to draw arrows and bandwidth boxes... // get the full length of the curve from the last point $totaldistance = $curvepoints[count($curvepoints) - 1][2]; // find where the in and out arrows will join (normally halfway point) $halfway = $totaldistance * ($q2_percent / 100); $dirs = array(OUT, IN); // for a unidirectional map, we just ignore the second half (direction = -1) if ($unidirectional) { $halfway = $totaldistance; $dirs = array(OUT); } // loop increment, start point, width, labelpos, fillcolour, outlinecolour, commentpos $arrowsettings[OUT] = array(+1, 0, $widths[OUT], 0, $fillcolours[OUT], $outlinecolour, 5); $arrowsettings[IN] = array(-1, count($curvepoints) - 1, $widths[IN], 0, $fillcolours[IN], $outlinecolour, 95); // we calculate the arrow size up here, so that we can decide on the // minimum length for a link. The arrowheads are the limiting factor. list($arrowsize[IN], $arrowwidth[IN]) = calc_arrowsize($widths[IN], $map, $linkname); list($arrowsize[OUT], $arrowwidth[OUT]) = calc_arrowsize($widths[OUT], $map, $linkname); // the 1.2 here is empirical. It ought to be 1 in theory. // in practice, a link this short is useless anyway, especially with bwlabels. $minimumlength = 1.2 * ($arrowsize[IN] + $arrowsize[OUT]); # warn("$linkname: Total: $totaldistance $arrowsize $arrowwidth $minimumlength\n"); if ($totaldistance <= $minimumlength) { wm_warn("Skipping drawing very short link ({$linkname}). Impossible to draw! Try changing WIDTH or ARROWSTYLE? [WMWARN01]\n"); return; } list($halfway_x, $halfway_y, $halfwayindex) = find_distance_coords($curvepoints, $halfway); // loop over direction here // direction is 1.0 for the first half (forwards through the pointlist), and -1.0 for the second half (backwards from the end) // - used as a multiplier on anything that looks forwards or backwards through the list foreach ($dirs as $dir) { $direction = $arrowsettings[$dir][0]; // $width = $widths[$dir]; // this is the last index before the arrowhead starts list($pre_mid_x, $pre_mid_y, $pre_midindex) = find_distance_coords($curvepoints, $halfway - $direction * $arrowsize[$dir]); $there_points = array(); $back_points = array(); $arrowpoints = array(); # if ($direction < 0) { $start=count($curvepoints) - 1; } # else { $start=0; } $start = $arrowsettings[$dir][1]; for ($i = $start; $i != $pre_midindex; $i += $direction) { // for each point on the spine, produce two points normal to it's direction, // each is $width away from the spine, but we build up the two lists in the opposite order, // so that when they are joined together, we get one continuous line $dx = $curvepoints[$i + $direction][0] - $curvepoints[$i][0]; $dy = $curvepoints[$i + $direction][1] - $curvepoints[$i][1]; $l = sqrt($dx * $dx + $dy * $dy); $nx = $dy / $l; $ny = -$dx / $l; $there_points[] = $curvepoints[$i][0] + $direction * $widths[$dir] * $nx; $there_points[] = $curvepoints[$i][1] + $direction * $widths[$dir] * $ny; $back_points[] = $curvepoints[$i][0] - $direction * $widths[$dir] * $nx; $back_points[] = $curvepoints[$i][1] - $direction * $widths[$dir] * $ny; } // all the normal line is done, now lets add an arrowhead on $adx = $halfway_x - $pre_mid_x; $ady = $halfway_y - $pre_mid_y; $l = sqrt($adx * $adx + $ady * $ady); $anx = $ady / $l; $any = -$adx / $l; $there_points[] = $pre_mid_x + $direction * $widths[$dir] * $anx; $there_points[] = $pre_mid_y + $direction * $widths[$dir] * $any; $there_points[] = $pre_mid_x + $direction * $arrowwidth[$dir] * $anx; $there_points[] = $pre_mid_y + $direction * $arrowwidth[$dir] * $any; $there_points[] = $halfway_x; $there_points[] = $halfway_y; $there_points[] = $pre_mid_x - $direction * $arrowwidth[$dir] * $anx; $there_points[] = $pre_mid_y - $direction * $arrowwidth[$dir] * $any; $there_points[] = $pre_mid_x - $direction * $widths[$dir] * $anx; $there_points[] = $pre_mid_y - $direction * $widths[$dir] * $any; // all points done, now combine the lists, and produce the final result. $metapts = ""; $y = array_pop($back_points); $x = array_pop($back_points); do { $metapts .= " {$x} {$y}"; $there_points[] = $x; $there_points[] = $y; $y = array_pop($back_points); $x = array_pop($back_points); } while (!is_null($y)); $arrayindex = 1; if ($direction < 0) { $arrayindex = 0; } if (!is_null($fillcolours[$arrayindex])) { wimagefilledpolygon($image, $there_points, count($there_points) / 2, $arrowsettings[$dir][4]); } else { wm_debug("Not drawing {$linkname} ({$dir}) fill because there is no fill colour\n"); } # $areaname = "LINK:" . $linkname. ":$dir"; $areaname = "LINK:L" . $map->links[$linkname]->id . ":{$dir}"; $map->imap->addArea("Polygon", $areaname, '', $there_points); wm_debug("Adding Poly imagemap for {$areaname}\n"); if (!is_null($outlinecolour)) { wimagepolygon($image, $there_points, count($there_points) / 2, $arrowsettings[$dir][5]); } else { wm_debug("Not drawing {$linkname} ({$dir}) outline because there is no outline colour\n"); } } }