Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- documentclass{article}
- usepackage[dvipsnames]{xcolor}
- usepackage{tikz,ifthen}
- usetikzlibrary{calc}
- colorlet{color0}{blue!40}
- colorlet{color1}{orange!60}
- colorlet{color2}{OliveGreen!40}
- colorlet{color3}{yellow!60}
- colorlet{color4}{red!60}
- colorlet{color5}{blue!60!cyan!60}
- colorlet{color6}{cyan!60!yellow!60}
- colorlet{color7}{red!60!cyan!60}
- colorlet{color8}{red!60!blue!60}
- colorlet{color9}{orange!60!cyan!60}
- makeatletter
- tikzset{%
- dc tag/.style={align=center},
- dc legend/.style={align=left,anchor=west},
- dc sector/.style={fill=Cj,line join=round}
- }
- pgfkeys{/DiagCirc/.cd,
- % liste of Name/Value
- value list/.store in=Value@list,
- % circular : 360 - semi circular 180
- angle max/.store in=Angle@max,
- angle max=360,
- % radius of the diagram
- radius/.store in=R@dius,
- radius=4cm,
- % composition of the legend
- % V value
- % N name
- % P percent
- % A angle
- % Cj color
- legend/.store in=L@gend,
- legend=,
- % location of the legend
- legend location/.store in=Legend@Loc,
- legend location={($(R@dius,R@dius)+(.5,-.5)$)},
- % poisition of the node in the sector
- % 0 center, 1 on the edge, 1.++ external
- factor/.store in=F@ctor,
- factor=.80,
- % composition of the node in the sector
- tags/.store in=T@gs,
- tags=,
- % correction of round errors in percents
- percent corr/.store in=C@rrP,
- percent corr=,
- % correction of round errors in angles
- angle corr/.store in=C@rrA,
- angle corr=,
- % individual shift
- shift sector/.store in=Shift@j,
- shift sector=,
- % more nodes in the sectors, or new legeng
- sup loop/.store in=Sup@Loop,
- sup loop=,
- % code of the diagram
- diagram/.code={%
- % Calculation of the sum
- pgfmathsetmacroS@m{0}
- foreach i/y in Value@list {xdefS@m{S@m+i}}
- pgfmathsetmacroS@m{S@m}
- pgfmathsetmacroC@eff{Angle@max/S@m}
- % beginning of the first sector
- xdef@ngleA{0}
- % main loop
- foreach V/N [count=j from 0] in Value@list {%
- % calculation of the current angle
- pgfmathsetmacroA{V*C@eff}
- % superior limit of the sector
- pgfmathsetmacro@ngleB{@ngleA+A} ;
- % mean angle
- pgfmathsetmacroMedA{(@ngleA+@ngleB)/2} ;
- % color
- pgfmathtruncatemacro@k{mod(j,10)}
- defCj{color@k}
- % individual shift
- ifthenelse{equal{Shift@j}{}}{%
- edefSh@ft{0}}{%
- pgfmathparse{array({Shift@j},j)}
- edefSh@ft{pgfmathresult}
- }
- % drawing of the sector
- draw[dc sector,shift={(MedA:Sh@ft)}] (0,0)
- -- (@ngleA:R@dius) arc (@ngleA:@ngleB:R@dius)
- node[midway] (DCj) {} -- cycle ;
- % low limit of the next sector
- xdef@ngleA{@ngleB} ;
- % current percent correction
- pgfmathtruncatemacroP{round(V/S@m*100)}
- ifthenelse{equal{C@rrP}{}}{}{%
- pgfmathparse{array({C@rrP},j)}
- pgfmathtruncatemacroP{P+pgfmathresult}
- }
- edefP{P,%}
- % current angle and corection
- pgfmathtruncatemacroA{round(A)}
- ifthenelse{equal{C@rrA}{}}{}{%
- pgfmathparse{array({C@rrA},j)}
- pgfmathtruncatemacroA{A+pgfmathresult}
- edefA{A,degre}
- }
- % the sector node
- ifthenelse{equal{T@gs}{}}{}{%
- DiagNode[dc tag]{F@ctor} {T@gs} ;
- }
- % the legend
- ifthenelse{equal{L@gend}{}}{}{%
- begin{scope}[shift=Legend@Loc]
- draw[fill=Cj] (0,-.5*j)
- rectangle ++(.25,.25) ++(0,-.15)
- node[dc legend] {strutL@gend} ;
- end{scope}
- }
- % some more stuff
- Sup@Loop ;
- }
- } % end of diagram code
- }
- makeatother
- % Node on the j sector
- newcommand{DiagNode}[2][]{node[#1] at ($(0,0)!#2!(DCj)$)}
- begin{document}
- hfillbegin{tikzpicture}
- path[%
- % style options
- dc tag/.append style={font=bfseriessmall},
- % diagram options
- /DiagCirc/.cd,
- radius=2.3cm,
- legend=N, % décrire la légende avec :
- % composition of the legend
- % V value
- % N name
- % P percent
- % A angle
- % Cj color
- value list={31/Compact,18/Bridge,11/Reflex},
- angle max=360, % semi-circular
- factor=.75,
- tags=P, % custom sector nodes
- diagram] ;
- % titre
- node[font=footnotesizebfseries,draw,inner sep=4pt,
- anchor=south]
- at (current bounding box.north)
- {Répartion des modèles d'appareils photo};
- node[font=largebfseries,anchor=north]
- at (current bounding box.south)
- {Diagramme circulaire};
- end{tikzpicture}hfillstrut
- end{document}
Add Comment
Please, Sign In to add comment