User:Pumbaa80/Diagram generator
From Wikimedia Commons, the free media repository
Contents |
[edit] Description
This script generates chart diagrams, like the one shown on the right. It's highly configurable (see Explanation section below). Output files are in SVG format. What you need to do to run it:
- Install AHK, the Scripting language for MS-Windows from www.autohotkey.com (sorry guys, Windows only!)
- Save the script below to anything.ahk
- Create an input file like the one below and save it to your hard disk
- Run the script by double-clicking it, select input and output files
- Done.
[edit] The Script
| This file is licensed under the Creative Commons Attribution ShareAlike 3.0 License. In short: you are free to share and make derivative works of the file under the conditions that you appropriately attribute it, and that you distribute it only under a license identical to this one. Official license This licensing tag was added to this file as part of the GFDL licensing update. Alemannisch | Беларуская (тарашкевіца) | Català | Česky | Deutsch | Deutsch (Sie-Form) | Ελληνικά | English | Español | Eesti | Suomi | Français | Hrvatski | Հայերեն | Italiano | 한국어 | Lietuvių | Македонски | Polski | Português | Português do Brasil | Русский | Svenska | ไทย | Vèneto | Tiếng Việt | +/− |
#NoTrayIcon
FileSelectFile, INI, 3,,Select input file
;FileSelectFile, INI, 3,,Eingabedatei wählen
if INI=
exitapp
FileSelectFile, SVG, S16,,Select output file,*.svg
;FileSelectFile, SVG, S16,,Ausgabedatei wählen,*.svg
if SVG=
ExitApp
IfExist, %SVG%
FileDelete %SVG%
IniRead,numberofcharts,%INI%,General,numberofcharts
IniRead,minlevel,%INI%,General,minlevel
IniRead,maxlevel,%INI%,General,maxlevel
IniRead,usemarkers,%INI%,General,usemarkers,1
IniRead,markersize,%INI%,General,markersize,2
IniRead,linewd,%INI%,General,linewd,.5
IniRead,diagramwidth,%INI%,General,diagramwidth
IniRead,background,%INI%,General,background
IniRead,inverted,%INI%,General,inverted
IniRead,label,%INI%,Axes,labelx
StringSplit,labelx,label,`,
IniRead,label,%INI%,Axes,labely
StringSplit,labely,label,`,
IniRead,fontsizex,%INI%,Axes,fontsizex,2
IniRead,fontsizey,%INI%,Axes,fontsizey,2
IniRead,fontsizelegend,%INI%,Legend,fontsize
Loop, %numberofcharts%
{
IniRead,legend%a_index%,%INI%,Legend,%a_index%
IniRead,data,%INI%,Data,%a_index%
StringSplit,data%a_index%_,data,`,
IniRead,colour,%INI%,Colors,%a_index%
StringSplit,colour%a_index%_,colour,`,
}
height:= maxlevel - minlevel + 7
width:= diagramwidth + 15
browsewidth:=width/height*800
FileAppend,
(
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg>
<svg version="1.1" baseProfile="full"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
preserveAspectRatio="xMidYMid meet" zoomAndPan="magnify"
viewBox="-10 -50 %width%0 %height%0"
width="%browsewidth%" height="800" >`n`n<defs>
<clipPath id="upper">
<rect x="-1" y="0" width="2" height="1"/>
</clipPath>
<clipPath id="lower">
<rect x="-1" y="-1" width="2" height="1"/>
</clipPath>`n
),%SVG%
Loop, %numberofcharts%
{
colour1 := colour%a_index%_2
if colour1 =
colour1 := colour%a_index%_1
colour2 := colour%a_index%_3
if usemarkers=1
{
FileAppend,
(
<g id="symbol%a_index%" transform="rotate(-45) scale(%markersize%)">
<circle r="1.2" fill="%background%"/>
<circle r="1"/>`n
),%SVG%
if colour2 =
FileAppend,<circle r=".8" fill="%colour1%"/>`n</g>`n,%SVG%
else
FileAppend,
(
<circle r=".8" fill="%colour1%" clip-path="url(#lower)"/>
<circle r=".8" fill="%colour2%" clip-path="url(#upper)"/>
</g>`n
),%SVG%
} else
FileAppend <g id="symbol%a_index%"></g>,%SVG%
}
FileAppend,
(
</defs>`n
<rect width="100`%" height="100`%" fill="%background%" x="-10" y="-50"/>`n
),%SVG%
h := maxlevel - minlevel + 1
Loop, %h%
{
FileAppend,
(
<line x1="10" x2="%diagramwidth%0"
y1="%a_index%0" y2="%a_index%0"
stroke="lightgray" stroke-width=".1"/>`n
),%SVG%
}
offset:=fontsizey/3
FileAppend, <g transform="translate(0`,%offset%)">`n,%SVG%
Loop, %h%
{
if inverted=1
text:=labely%a_index%
else
{
t:= h-a_index+1
text:=labely%t%
}
FileAppend,<text x="0" y="%a_index%0" font-size="%fontsizey%" text-anchor="end">%text%</text>`n,%SVG%
}
FileAppend, </g>`n<g fill="none" stroke-linecap="round" stroke-linejoin="round">`n,%SVG%
Loop, %numberofcharts%
{
i:= numberofcharts - a_index + 1
backwd:=2*linewd
FileAppend,<polyline stroke="%background%" stroke-width="%backwd%" points=",%SVG%
Loop
{
y := data%i%_%a_index%
if y=
break
if inverted!=1
y := 2 + maxlevel - minlevel - y
FileAppend %a_index%0`,%y%0 %a_space%,%SVG%
}
FileAppend,"/>`n,%SVG%
col:=colour%i%_1
FileAppend,<polyline stroke="%col%" stroke-width="%linewd%" points=",%SVG%
Loop
{
y := data%i%_%a_index%
if y=
break
if inverted!=1
y := 2 + maxlevel - minlevel - y
FileAppend %a_index%0`,%y%0 %a_space%,%SVG%
}
FileAppend,"/>`n,%SVG%
}
FileAppend,</g>`n,%SVG%
Loop, %numberofcharts%
{
i:= numberofcharts - a_index +1
Loop
{
y := data%i%_%a_index%
if y=
break
if inverted!=1
y := height-y
FileAppend,<use xlink:href="#symbol%i%" transform="translate(%a_index%0`,%y%0)"/>`n,%SVG%
}
}
offset:=fontsizex/3
FileAppend,`n<g transform="translate(%offset%) rotate(-90)">`n,%SVG%
Loop, %width%
{
text:=labelx%a_index%
FileAppend,<text x="0" y="%a_index%0" font-size="%fontsizex%">%text%</text>`n,%SVG%
}
FileAppend,</g>`n,%SVG%
Loop, %numberofcharts%
{
y:= 10+(a_index-1)*fontsizelegend*1.2
ytext:=y+fontsizelegend/3
x:=10*(diagramwidth+2)
x1:=x-2*markersize
x2:=x+2*markersize
xtext:=x+4*markersize
col:=colour%a_index%_1
text:=legend%a_index%
FileAppend,
(
<line x1="%x1%" x2="%x2%" y1="%y%" y2="%y%" stroke="%col%" stroke-width="%linewd%"/>
<use xlink:href="#symbol%a_index%" transform="translate(%x%,%y%)"/>
<text x="%xtext%" y="%ytext%" font-size="%fontsizelegend%">%text%</text>`n
),%SVG%
}
FileAppend,</svg>`n,%SVG%
[edit] Input File Example
[General] background=white numberofcharts=12 diagramwidth=52 minlevel=1 maxlevel=12 inverted=1 usemarkers=1 markersize=1.5 linewd=.8 [Axes] labelx=Saisonstart,,10.09.2005,,17.09.2005,,17.09.2005,,01.10.2005,,08.10.2005,,16.10.2005,,23.10.2005,,30.10.2005,,05.11.2005,,19.11.2005,,26.11.2005,,29.11.2005,,04.12.2005,,11.12.2005,,23.12.2005,,06.01.2006,,14.01.2006,,21.01.2006,,27.01.2006,,03.02.2006,,28.02.2006,,05.03.2006,,Viertelfinal,,Halbfinal,,Final labely=1,2,3,4,5,6,7,8,9,10,11,12 fontsizex=6 fontsizey=6 [Legend] fontsize=7 1=HC Davos 2=ZSC Lions 3=SC Bern 4=EV Zug 5=Rapperswil-Jona Lakers 6=HC Lugano 7=HC Ambri-Piotta 8=HC Servette Genève 9=Kloten Flyers 10=Fribourg-Gottéron 11=SCL Tigers 12=EHC Basel [Colors] 1=#f8e30e,#353d90 2=#5063aa,white 3=#e44120,#f8e30e 4=#abd8da,#5063aa 5=#353d90,#e44120 6=black,#f8e30e 7=#c0c0bf,#353d90,white 8=#7d2519 9=#e44120,#5bc0e9,white 10=#e44120,#abd8da 11=#f8e30e,black,#e44120 12=black,#e44120,white [Data] 1=1,7,7,5,9,8,9,7,5,6,7,8,5,5,5,5,4,5,4,4,3,3,4,4,5,4,4,3,3,3,3,3,3,3,3,3,3,4,3,3,3,3,3,3,3,3 2=2,8,4,9,7,3,4,6,4,5,4,4,4,4,4,4,6,7,8,8,5,7,8,8,8,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,7,8,9,10,10 3=3,4,6,7,5,1,1,2,1,1,1,2,2,2,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,2,2,2,2,1,1,1 4=4,2,2,2,2,2,2,1,2,2,3,3,3,3,2,2,2,2,2,3,4,4,3,3,3,3,3,4,4,5,5,6,8,8,9,9,6,8,9,8,6,6,7,5,5 5=5,7,3,8,4,7,6,9,10,8,9,9,10,7,8,8,7,6,6,6,7,5,7,7,7,6,5,5,5,4,4,4,4,4,5,4,4,3,4,4,4,4,4,4,4,4 6=6,9,9,6,6,9,5,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,1,1,1,1,2,2,2,2 7=7,1,5,4,8,6,7,8,8,10,10,10,9,6,6,7,8,8,9,9,9,8,5,5,6,7,6,6,6,7,7,7,6,6,6,6,7,5,5,5,5,5,5,6,6 8=8,3,1,1,3,4,8,5,6,4,5,5,8,8,7,6,5,4,5,5,6,9,9,9,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11 9=9,6,8,3,1,5,3,4,7,7,6,7,7,9,9,9,9,10,7,7,8,6,6,6,4,5,7,7,7,6,6,5,5,5,4,5,5,7,6,6,8,10,9,8,8,8 10=10,11,11,11,12,12,12,12,12,11,12,12,12,12,12,12,11,11,11,10,10,10,10,10,9,8,8,8,8,8,8,8,7,7,7,7,8,6,7,7,9,8,10,10,9,9 11=11,10,12,12,11,11,11,11,11,12,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12 12=12,12,10,10,10,10,10,10,9,9,8,6,6,10,10,10,10,9,10,11,11,11,11,11,11,11,11,11,11,11,11,10,10,9,8,8,9,9,8,9,7,9,6,7,7
[edit] Input File Explanation
[edit] General
- background: define the global background color here. Colors can be given by name or by their RGB values. See Wikipedia for details.
- numberofcharts: this defines how much of the Legend, Colors and Data sections will be read and drawn.
- diagramwidth: Guess what - the desired width of the diagram; must be an integer
- minlevel/maxlevel: the top and bottom boundaries of the diagram; must be integers
- inverted: if this equals 1, the diagram will be drawn top-to-bottom; otherwise bottom-to-top
- usemarkers: if this equals 0, markers are omitted
- markersize: this also affects the width of the lines in the legend, even if usemarkers is 0
- linewd: the width of the lines connecting the (virtual) markers
[edit] Axes
- labelx: Comma separated list of labels to be shown on top of the diagram
- labely: Comma separated list of labels to be shown to the left of the diagram (ascending order)
[edit] Legend
- no need to explain this, I hope
[edit] Colors
- x=color1,color2,color3 or x=color1,color2: Colors of diagram #x - color1 is the color of the lines, color2 and color3 give the color(s) of the markers.
[edit] Data
- a=a1,a2,a3,...: Values taken by diagram #a; these can be floating point numbers