Guest User

Untitled

a guest
Jan 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. documentclass{article}
  2. usepackage[dvipsnames]{xcolor}
  3. usepackage{tikz,ifthen}
  4. usetikzlibrary{calc}
  5.  
  6. colorlet{color0}{blue!40}
  7. colorlet{color1}{orange!60}
  8. colorlet{color2}{OliveGreen!40}
  9. colorlet{color3}{yellow!60}
  10. colorlet{color4}{red!60}
  11. colorlet{color5}{blue!60!cyan!60}
  12. colorlet{color6}{cyan!60!yellow!60}
  13. colorlet{color7}{red!60!cyan!60}
  14. colorlet{color8}{red!60!blue!60}
  15. colorlet{color9}{orange!60!cyan!60}
  16.  
  17.  
  18. makeatletter
  19. tikzset{%
  20. dc tag/.style={align=center},
  21. dc legend/.style={align=left,anchor=west},
  22. dc sector/.style={fill=Cj,line join=round}
  23. }
  24.  
  25. pgfkeys{/DiagCirc/.cd,
  26. % liste of Name/Value
  27. value list/.store in=Value@list,
  28. % circular : 360 - semi circular 180
  29. angle max/.store in=Angle@max,
  30. angle max=360,
  31. % radius of the diagram
  32. radius/.store in=R@dius,
  33. radius=4cm,
  34. % composition of the legend
  35. % V value
  36. % N name
  37. % P percent
  38. % A angle
  39. % Cj color
  40. legend/.store in=L@gend,
  41. legend=,
  42. % location of the legend
  43. legend location/.store in=Legend@Loc,
  44. legend location={($(R@dius,R@dius)+(.5,-.5)$)},
  45. % poisition of the node in the sector
  46. % 0 center, 1 on the edge, 1.++ external
  47. factor/.store in=F@ctor,
  48. factor=.80,
  49. % composition of the node in the sector
  50. tags/.store in=T@gs,
  51. tags=,
  52. % correction of round errors in percents
  53. percent corr/.store in=C@rrP,
  54. percent corr=,
  55. % correction of round errors in angles
  56. angle corr/.store in=C@rrA,
  57. angle corr=,
  58. % individual shift
  59. shift sector/.store in=Shift@j,
  60. shift sector=,
  61. % more nodes in the sectors, or new legeng
  62. sup loop/.store in=Sup@Loop,
  63. sup loop=,
  64. % code of the diagram
  65. diagram/.code={%
  66. % Calculation of the sum
  67. pgfmathsetmacroS@m{0}
  68. foreach i/y in Value@list {xdefS@m{S@m+i}}
  69. pgfmathsetmacroS@m{S@m}
  70. pgfmathsetmacroC@eff{Angle@max/S@m}
  71.  
  72. % beginning of the first sector
  73. xdef@ngleA{0}
  74.  
  75. % main loop
  76. foreach V/N [count=j from 0] in Value@list {%
  77.  
  78. % calculation of the current angle
  79. pgfmathsetmacroA{V*C@eff}
  80.  
  81. % superior limit of the sector
  82. pgfmathsetmacro@ngleB{@ngleA+A} ;
  83.  
  84. % mean angle
  85. pgfmathsetmacroMedA{(@ngleA+@ngleB)/2} ;
  86.  
  87. % color
  88. pgfmathtruncatemacro@k{mod(j,10)}
  89. defCj{color@k}
  90.  
  91. % individual shift
  92. ifthenelse{equal{Shift@j}{}}{%
  93. edefSh@ft{0}}{%
  94. pgfmathparse{array({Shift@j},j)}
  95. edefSh@ft{pgfmathresult}
  96. }
  97.  
  98. % drawing of the sector
  99. draw[dc sector,shift={(MedA:Sh@ft)}] (0,0)
  100. -- (@ngleA:R@dius) arc (@ngleA:@ngleB:R@dius)
  101. node[midway] (DCj) {} -- cycle ;
  102.  
  103. % low limit of the next sector
  104. xdef@ngleA{@ngleB} ;
  105.  
  106. % current percent correction
  107. pgfmathtruncatemacroP{round(V/S@m*100)}
  108. ifthenelse{equal{C@rrP}{}}{}{%
  109. pgfmathparse{array({C@rrP},j)}
  110. pgfmathtruncatemacroP{P+pgfmathresult}
  111. }
  112. edefP{P,%}
  113.  
  114. % current angle and corection
  115. pgfmathtruncatemacroA{round(A)}
  116. ifthenelse{equal{C@rrA}{}}{}{%
  117. pgfmathparse{array({C@rrA},j)}
  118. pgfmathtruncatemacroA{A+pgfmathresult}
  119. edefA{A,degre}
  120. }
  121.  
  122. % the sector node
  123. ifthenelse{equal{T@gs}{}}{}{%
  124. DiagNode[dc tag]{F@ctor} {T@gs} ;
  125. }
  126.  
  127. % the legend
  128. ifthenelse{equal{L@gend}{}}{}{%
  129. begin{scope}[shift=Legend@Loc]
  130. draw[fill=Cj] (0,-.5*j)
  131. rectangle ++(.25,.25) ++(0,-.15)
  132. node[dc legend] {strutL@gend} ;
  133. end{scope}
  134. }
  135.  
  136. % some more stuff
  137. Sup@Loop ;
  138. }
  139.  
  140. } % end of diagram code
  141. }
  142. makeatother
  143.  
  144. % Node on the j sector
  145. newcommand{DiagNode}[2][]{node[#1] at ($(0,0)!#2!(DCj)$)}
  146.  
  147. begin{document}
  148.  
  149.  
  150.  
  151. hfillbegin{tikzpicture}
  152. path[%
  153. % style options
  154. dc tag/.append style={font=bfseriessmall},
  155. % diagram options
  156. /DiagCirc/.cd,
  157. radius=2.3cm,
  158. legend=N, % décrire la légende avec :
  159. % composition of the legend
  160. % V value
  161. % N name
  162. % P percent
  163. % A angle
  164. % Cj color
  165. value list={31/Compact,18/Bridge,11/Reflex},
  166. angle max=360, % semi-circular
  167. factor=.75,
  168. tags=P, % custom sector nodes
  169. diagram] ;
  170.  
  171. % titre
  172. node[font=footnotesizebfseries,draw,inner sep=4pt,
  173. anchor=south]
  174. at (current bounding box.north)
  175. {Répartion des modèles d'appareils photo};
  176.  
  177. node[font=largebfseries,anchor=north]
  178. at (current bounding box.south)
  179. {Diagramme circulaire};
  180.  
  181. end{tikzpicture}hfillstrut
  182. end{document}
Add Comment
Please, Sign In to add comment