4DToday.com
Home Directory Classifieds Reference Archives
Site Info
About 4DToday.com
Contact Us
Version française
Quote
Developers (721)
4D Developers (589)
Web Developers (334)
Tools Publishers (193)
Instructors (164)
Web Hosts (60)
Resellers (87)
Software Publishers (296)
Search Developers
Products (382)
Plug-Ins (111)
Components (48)
Code Libraries (9)
Books (7)
Tools (42)
Vertical Applications (144)
Search Products
User Groups
All User Groups (22)
Classified Ads (22)
Help Wanted (6)
Opportunities Wanted (13)
Hardware Wanted (0)
Hardware for Sale (0)
Software Wanted (1)
Software for Sale (0)
Other (0)
Resources
4D
4D, Inc.
4D International
4D Wiki
4D Partner Central
4D Beginner's Center
4D Online Documentation
4D 2004 Example Applications
4D Example Databases
4D BugDisplayer
4D, Inc. Training
Message Lists
4D Mailing Lists
4D Tech Google Group
iNUG Archives (Nabble)
iNUG Archives (Gmane)
iNUG Message Index
Other
4D Code Exchange
4D Resources
Sviluppo4D.it (Italy)
4D Sources (4D Plugin API, 4D Pop & Miyako
Quote
The smallest good deed is better than the grandest good intention.
Duguet  
  Suggest a Quote  
Direct from 4D Summmit
Developer News
There are no news items at this time.
 Submit Future News    Archive 
Technical Tip
Rotate GRAPH x axis
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.

C_PICTURE(MyGraph)
GRAPH ( MyGraph ; graphNumber | graphSettings ; xLabels {; yElements} {; yElements2 ; ... ; yElementsN} )
Graph_Pic_RotateXLabels(->MyGraph {;rotate degree} )


  // ----------------------------------------------------
  // Keith,  8/10/2017, 09:49:29
  // ----------------------------------------------------
  // Method: Graph_Pic_RotateXLabels
  // -
  // INPUT1: Pointer - to SVG Picture from the Graph command
  // {INPUT2}: Real - degrees to rotate (90 is vertical; 22.5 is Default)
  // OUTPUT:  None - INPUT1 is changed
  // ----------------------------------------------------

$Options:=SVG_Get_options
$Options:=$Options ?- 6  //silence the beep on err
SVG_SET_OPTIONS ($Options)


C_POINTER($picPtr;$1)
C_REAL($rotate;$2)
C_LONGINT($x;$y;$maxW;$w;$h)

$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

SVG_SET_XY ($aRef{$i};$x;$y)
SVG_ROTATION_CENTERED ($aRef{$i};$rotate)

End for

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

$picPtr->:=SVG_Export_to_picture ($svg)

End if

SVG_CLEAR ($svg)
  Submit a Tip    Archive 
Spotlight
Active4D 64-bit
Active4D 64-bit Active4D is now available for 4D v12 64-bit Server! Take full advantage of your 64-bit hardware with the power of Active4D.
  Suggest a Spotlight  
Survey Results
Today, we asked you...
Do you have succession plans with your key customers?
Survey Results

Your vote: (no vote)
Total votes received: 21

Survey submitted by David Eddy
  Suggest a Survey  
Events
There are no events scheduled for the upcoming fortnight.
  Submit an Event