Publi-Script Forums

Publishing Applications => Illustrator support => Topic started by: chardonnay on September 06, 2007, 04:40:27 PM

Title: Graphs
Post by: chardonnay on September 06, 2007, 04:40:27 PM
Hi all !

We have a project to accomplish that contains lots of graphs in it.
I have some questions:

In Illustrator, it is possible to create pie-graphs (and make them visually attractive as I found out:

1. How do I automatically set the percentages outside of the pie? Example: 50/50 splits the pie in half, I also would like to see those values set as text '50%'; '50%', surrounding the pie. Possible?

2. Is there a plugin or application that has more 'advanced' ways of creating graphs (suitable for printed media)?

Excuse me if I am ignorant in this, it's only that I have not created graphs for a long period, any suggestion would be gladly appreciated.

TIA, Erwin
Title: Re: Graphs
Post by: Erik Youngren on September 06, 2007, 11:11:40 PM
I'm not totally understanding what you mean by #1. If you enter the values in the fields it splits it up automatically. You have to add the labels manually.

I don't know of any plug-ins, but that doesn't mean they don't exist.
Title: Re: Graphs
Post by: Publi-Script on September 07, 2007, 09:50:43 AM
Hi Erwin,

Actually, you can set your labels in the top row of your graph data so in your case your data would look like:
Note that you will have to calculate your label percentages yourself.
Set your labels to appear inside the wedges.

Once your graphs are done, you can ONLY select the labels and scale them proportionally (Making sure you put the "origin" of the scale tool on the center of your pie chart). This will eventually set the labels outiside of your wedges and exactly in the center of each outside arc. You only need to set the type size of your labels and you are set.

I do not know of  a way to do this automatically nor do I know of a Plug-in that would do the trick. There might be a way to accomplish this with Applescript but I haven't checked yet.

Also: You might want to try the 3D Extrude and Bevel filter, this really makes the graphs pop out.
Title: Re: Graphs
Post by: chardonnay on September 07, 2007, 10:31:54 AM
This helps, thanks !
Title: Re: Graphs
Post by: larsen67 on September 07, 2007, 12:24:24 PM
Have you looked at making the graph object dynamic you may be able to script importing it's data that way. I haven't been able to work this out though.
Title: Re: Graphs
Post by: larsen67 on September 10, 2007, 03:27:47 AM
I had a look at the dynanic aspect again (had to refresh my memory it's been some time since I last did this). Create a template file containing 1 pie chart style graph as per michel's suggestion (no need for any data yet) in the in the variables pallet with the graph object selected make object dynamic. From there you can now import XML containing your multiple graph information. Once this is done you can colour the live graph with basic fills strokes etc when you accept this the information will then be applied to all the graphs contained in the datsets. (it is best to start with the pie chart that contains the most sections) the nice thing about using variables is that any changes made to the first dataset are applied throughout so updating colours fonts etc is made very easy and all your info is contained in the one template file. I would imagine if you have lots of graphs of similar styles then you could save quite a bit of time with this method. The XML itself when opened is pretty easy to interprit and I would not envisage it being too difficult to create a script to write this information from a database program such as excel or FMP. Here is a basic sample of graph XML code you can try importing.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20001102//EN"    "" [
   <!ENTITY ns_graphs "">
   <!ENTITY ns_vars "">
   <!ENTITY ns_imrep "">
   <!ENTITY ns_custom "">
   <!ENTITY ns_flows "">
<!ENTITY ns_extend "">
<variableSets  xmlns="&ns_vars;">
   <variableSet  varSetName="binding1" locked="none">
         <variable  varName="Variable1" trait="graphdata" category="&ns_graphs;"></variable>
      <v:sampleDataSets  xmlns="&ns_custom;" xmlns:v="&ns_vars;">
         <v:sampleDataSet  dataSetName="Marks Graph 1">
               <data  numDataColumns="8">
                  <propertyRow  key="name">
                        <value  key="name"></value>
         <v:sampleDataSet  dataSetName="Marks Graph 2">
               <data  numDataColumns="7">
                  <propertyRow  key="name">
                        <value  key="name"></value>
         <v:sampleDataSet  dataSetName="Marks Graph 3">
               <data  numDataColumns="6">
                  <propertyRow  key="name">
                        <value  key="name"></value>
         <v:sampleDataSet  dataSetName="Marks Graph 4">
               <data  numDataColumns="4">
                  <propertyRow  key="name">
                        <value  key="name"></value>
         <v:sampleDataSet  dataSetName="Marks Graph 5">
               <data  numDataColumns="3">
                  <propertyRow  key="name">
                        <value  key="name"></value>
         <v:sampleDataSet  dataSetName="Marks Graph 6">
               <data  numDataColumns="2">
                  <propertyRow  key="name">
                        <value  key="name"></value>

Just save from text edit as plain text with .xml extension.
It is also possible to script the import and export of XML from illustrator and to output each dataset to file. Where you can crack open the graph and use none basic fills like patterns and raster effect etc.
Title: Re: Graphs
Post by: chardonnay on September 10, 2007, 03:30:28 PM
Larsen: thanks for your valuable information. My scripting-experience is however zero-to-none, so I have to further investigate this before I can use this to automate it to our advantage.

The project indeed contains mainly similar graphs, only containing different data (values) and oncoming periodically, so it is worthwile to automate this.

Other than the things I can find on the internet, could you point me some references to books in which I can find more about this?

Thanks again !
Title: Re: Graphs
Post by: Publi-Script on September 10, 2007, 05:09:29 PM
I tried Larsen's dynamic data trick but couldn't make it work. Somehow the resulting text file is not compatible with what Illustrator expects. I also did the reverse and exported a set of variables from Illustrator. Sure enough, comparing the two text files, they were different (something about a line feed character at the beginning of each paragraph). I also never found the "text only" in textEdit.
Title: Re: Graphs
Post by: larsen67 on September 11, 2007, 03:52:54 AM
I have just thought that I never checked that the posted code would work after posting. I have done this this morning and all is fine at this end. Draw one plain pie chart and import the saved text file. What I explained poorly is I have text edit use plain text and not rich text and save to Unicode (UTF-8) as that is what is specified in the .xml head then keep .xml and don't Append when saving. You should then get a list available from the drop down menu of datasets in illustrator. I did also make some ground on trying to script this feature too. I will play some more when I get the chance.
Title: Re: Graphs
Post by: larsen67 on September 11, 2007, 05:44:31 AM
Michel, for what its worth here is where I got to playing with this. Its partially hard coded while I play but is working fine for me no issues with the xml being invalid. I would not know how to deal with database info for writing as I don't have any of these yet. I would most likely rsort to csv or tdt

001   property Default_Path : (path to desktop as Unicode text)
002   property The_XML : Default_Path & "Import_Variables.xml" as text
004   property XML_Head : "<?xml version=\"1.0\" encoding=\"utf-8\"?>
005   <!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20001102//EN\"    \"\" [
006        <!ENTITY ns_graphs \"\">
007        <!ENTITY ns_vars \"\">
008        <!ENTITY ns_imrep \"\">
009        <!ENTITY ns_custom \"\">
010        <!ENTITY ns_flows \"\">
011   <!ENTITY ns_extend \"\">
012   ]>
013   <svg>
014   <variableSets  xmlns=\"&ns_vars;\">
015        <variableSet  varSetName=\"binding1\" locked=\"none\">"
016   property XML_Vari_Start : "<variables>"
017   property XML_Vari_Finish : "</variables>"
018   property XML_Data_Start : "<v:sampleDataSets  xmlns=\"&ns_custom;\" xmlns:v=\"&ns_vars;\">"
019   property XML_Data_Finish : "</v:sampleDataSets>"
020   property XML_EOF : "     </variableSet>
021   </variableSets>
022   </svg>"
024   property Var_Count : 0
025   property DataSet_Count : 0
026   property Var_Textual : {} -- to check against DB
027   property Var_Image : {} -- to check against DB
028   property Var_Graph : {} -- to check against DB
029   property Var_Visibility : {} -- to check against DB
030   property Var_Unknown : {} -- to check against DB
032   tell application "Adobe Illustrator"
033        activate
034        tell document 1
035             set Var_Count to count of variables
036             if Var_Count = 0 then
037                  display dialog "This file has no variables?" giving up after 2
038             else
039                  set DataSet_Count to count of datasets
040                  if DataSet_Count is not 1 then
041                       display dialog "This file has " & DataSet_Count & " datasets" buttons {"Cancel", "Replace"} default button 1
042                  end if
043                  -- Record all variable names & types to lists
044                  set Var_Textual to name of (every variable whose kind is textual) as list
045                  set Var_Image to name of (every variable whose kind is image) as list
046                  set Var_Graph to name of (every variable whose kind is graph) as list
047                  set Var_Visibility to name of (every variable whose kind is visibility) as list
048                  set Var_Unknown to name of (every variable whose kind is unknown) as list
049                  --
050                  my Write_XML(XML_Head)
051                  my Write_XML(XML_Vari_Start)
052                  my Write_XML(my Write_Variables())
053                  my Write_XML(XML_Vari_Finish)
054                  my Write_XML(XML_Data_Start)
055                  my Write_XML(my Write_DataSets())
056                  my Write_XML(XML_Data_Finish)
057                  my Write_XML(XML_EOF)
058                  --
059                  import variables from The_XML
060                  beep 3
061                  display dialog "Your XML has been importedů" giving up after 2
062                  set DataSet_Count to count of datasets
063                  repeat with i from 1 to DataSet_Count
064                       display dataset i
065                       delay 1
066                  end repeat
067                  display dataset 1
068             end if
069        end tell
070   end tell
072   -- Don't know why yet but errors with empty lists so I've commented them out for now
073   on Write_Variables()
074        set The_Variables to ""
075        (* if Var_Textual is not {} then
076             repeat with i from 1 to length of Var_Textual
077                  set This_String to "<variable  varName=\"" & ((item i of Var_Textual) as text) & "\" trait=\"textcontent\" category=\"&ns_flows;\"></variable>"
078                  set end of The_Variables to This_String & return
079             end repeat
080        end if *)
081        if Var_Image is not {} then
082             repeat with i from 1 to length of Var_Image
083                  set This_String to "<variable  varName=\"" & ((item i of Var_Image) as text) & "\" trait=\"fileref\" category=\"&ns_vars;\"></variable>"
084                  set The_Variables to The_Variables & This_String
085             end repeat
086        end if
087        (* if Var_Graph is not {} then
088             repeat with i from 1 to length of Var_Graph
089                  set This_String to "<variable  varName=\"" & ((item i of Var_Graph) as text) & "\" trait=\"graphdata\" category=\"&ns_graphs;\"></variable>"
090                  set end of The_Variables to This_String & return
091             end repeat
092        end if
093        if Var_Visibility is not {} then
094             repeat with i from 1 to length of Var_Visibility
095                  -- not done this yet
096                  set end of The_Variables to This_String & return
097             end repeat
098        end if
099        if Var_Unknown is not {} then
100             repeat with i from 1 to length of Var_Unknown
101                  -- not done this yet
102                  set end of The_Variables to This_String & return
103             end repeat
104        end if *)
105        return The_Variables
106   end Write_Variables
108   -- So far this is hard coded to my Var_Image to test
109   on Write_DataSets()
110        return "<v:sampleDataSet  dataSetName=\"Marks Image 1\">
111                       <Marks_Test_Image>file:///Marks-G5/Users/marklarsen/Desktop/XML/Variable Image Links/New Link 1.tif</Marks_Test_Image>
112                  </v:sampleDataSet>
113                       <v:sampleDataSet  dataSetName=\"Marks Image 2\">
114                       <Marks_Test_Image>file:///Marks-G5/Users/marklarsen/Desktop/XML/Variable Image Links/New Link 2.tif</Marks_Test_Image>
115                  </v:sampleDataSet>
116                  <v:sampleDataSet  dataSetName=\"Marks Image 3\">
117                       <Marks_Test_Image>file:///Marks-G5/Users/marklarsen/Desktop/XML/Variable Image Links/New Link 3.tif</Marks_Test_Image>
118                  </v:sampleDataSet>
119                  <v:sampleDataSet  dataSetName=\"Marks Image 4\">
120                       <Marks_Test_Image>file:///Marks-G5/Users/marklarsen/Desktop/XML/Variable Image Links/New Link 4.tif</Marks_Test_Image>
121                  </v:sampleDataSet>
122                       <v:sampleDataSet  dataSetName=\"Marks Image 5\">
123                       <Marks_Test_Image>file:///Marks-G5/Users/marklarsen/Desktop/XML/Variable Image Links/New Link 5.tif</Marks_Test_Image>
124                  </v:sampleDataSet>
125                  <v:sampleDataSet  dataSetName=\"Marks Image 6\">
126                       <Marks_Test_Image>file:///Marks-G5/Users/marklarsen/Desktop/XML/Variable Image Links/New Link 6.tif</Marks_Test_Image>
127                  </v:sampleDataSet>"
128   end Write_DataSets
130   on Write_XML(XML_Code)
131        try
132             open for access file the The_XML with write permission
133             write XML_Code & return to file the The_XML starting at eof
134             close access file the The_XML
135        on error
136             close access file the The_XML
137        end try
138   end Write_XML