Life is islands of ecstasy in an ocean of ennui, and after the age of thirty land is seldom seen. At best, we wander from one much-worn sandbar to the next, soon familiar with each grain of sand we see.
Submitted by Keith Culotta, Computer Dimensions, Inc.
Sometimes the GRAPH command will produce a graph with an overcrowded x axis. This routine takes the graph and rotates the x axis labels so they will not overlap.
Create the Graph and pass a pointer to it as the first parameter of the method. The labels will be rotated 22.5 degrees unless another number is passed as the second parameter.
$picPtr:=$1 If (Count parameters>1) $rotate:=$2 Else $rotate:=22.5 End if
$svg:=SVG_Open_picture ($picPtr->)
$ref:=SVG_Find_ID ($svg;"ID_x_values") // this is the x labels group If ($ref="") $ref:=SVG_Find_ID ($svg;"ID_x$value") // debug inspired by v16R4 - this is where it beeped End if
If ($ref#"") ARRAY TEXT($aRef;0) SVG_ELEMENTS_TO_ARRAYS ($ref;->$aRef) // get all the x labels $size:=Size of array($aRef) For ($i;1;$size) SVG_SET_ATTRIBUTES ($aRef{$i};"text-anchor";"start") // they were middle
$tmpS:=SVG_New // get the size of this label $refT:=SVG_Add_object ($tmpS;$aRef{$i}) SVG_SET_XY ($refT;0;0) $tmpP:=SVG_Export_to_picture ($tmpS) PICTURE PROPERTIES($tmpP;$w;$h) SVG_CLEAR ($tmpS)
$maxW:=Choose($maxW<$w;$w;$maxW)
DOM GET XML ATTRIBUTE BY NAME($aRef{$i};"x";$x) DOM GET XML ATTRIBUTE BY NAME($aRef{$i};"y";$y) $x:=$x-$h // shift to taste $y:=$y-$h
DOM GET XML ATTRIBUTE BY NAME($svg;"viewBox";$refT) ARRAY TEXT($aCoord;0) Parse_TextToArray ($refT;->$aCoord;" ") $x:=Num($aCoord{1}) // shift labels left $y:=Num($aCoord{2}) $w:=Num($aCoord{3}) $h:=Num($aCoord{4})+($maxW*2) // guess SVG_SET_VIEWBOX ($svg;$x;$y;$w;$h) // rotated labels make the picture taller