Debian Codegraph @

texmf-dist/tex/latex/wheelchart/wheelchart.sty

raw
1 %% wheelchart.sty
2 %% Copyright 2022-2026 Matthias Floré
3 %
4 % This work may be distributed and/or modified under the
5 % conditions of the LaTeX Project Public License, either version 1.3c
6 % of this license or (at your option) any later version.
7 % The latest version of this license is in
8 % http://www.latex-project.org/lppl.txt
9 % and version 1.3c or later is part of all distributions of LaTeX
10 % version 2005/12/01 or later.
11 %
12 % This work has the LPPL maintenance status `maintained'.
13 %
14 % The Current Maintainer of this work is Matthias Floré.
15 %
16 % This work consists of the files wheelchart.pdf, wheelchart.sty,
17 % wheelchart.tex and README.md.
18 \NeedsTeXFormat{LaTeX2e}
19 \RequirePackage{tikz}
20 \usetikzlibrary{calc}
21 \ProvidesExplPackage{wheelchart}{2026/04/19}{6.0}{Diagrams with circular or other shapes using TikZ and LaTeX3}
22
23 %%> \subsection{Variables}
24
25 \newcounter { g__wheelchart_WCcount_counter }
26
27 \bool_new:N \l__wheelchart_arc_bool
28 \bool_new:N \l__wheelchart_contour_bool
29 \bool_new:N \g__wheelchart_def_angle_radius_shift_bool
30 \bool_new:N \l__wheelchart_discrete_bool
31 \bool_new:N \l__wheelchart_etoc_use_name_bool
32 \bool_new:N \l__wheelchart_legend_only_bool
33 \bool_new:N \l__wheelchart_legend_row_bool
34 \bool_new:N \l__wheelchart_lines_ext_dir_bool
35 \bool_new:N \l__wheelchart_middle_fill_bool
36 \bool_new:N \l__wheelchart_pie_bool
37 \bool_new:N \l__wheelchart_plot_bool
38 \bool_new:N \l__wheelchart_slices_bool
39 \bool_new:N \l__wheelchart_wheel_lines_bool
40
41 \box_new:N \l__wheelchart_arc_data_box
42 \box_new:N \g__wheelchart_if_text_box
43
44 \clist_new:N \l__wheelchart_header_clist
45 \clist_new:N \g__wheelchart_slice_range_for_loop_clist
46 \clist_new:N \l__wheelchart_slice_range_local_clist
47
48 \fp_new:N \l__wheelchart_abs_half_angle_minus_new_angle_minus_gap_polar_fp
49 \fp_new:N \l__wheelchart_anchor_xsep_fp
50 \fp_new:N \l__wheelchart_anchor_ysep_fp
51 \fp_new:N \g__wheelchart_angle_fp
52 \fp_new:N \l__wheelchart_arc_around_line_fp
53 \fp_new:N \l__wheelchart_arc_data_angle_pos_fp
54 \fp_new:N \l__wheelchart_arc_data_angle_shift_fp
55 \fp_new:N \g__wheelchart_arc_data_aux_i_fp
56 \fp_new:N \g__wheelchart_arc_data_aux_ii_fp
57 \fp_new:N \l__wheelchart_arc_data_dir_fp
58 \fp_const:Nn \c__wheelchart_arc_data_end_factor_center_fp { 0.5 }
59 \fp_const:Nn \c__wheelchart_arc_data_end_factor_left_fp { 1 }
60 \fp_const:Nn \c__wheelchart_arc_data_end_factor_right_fp { 0 }
61 \fp_new:N \l__wheelchart_arc_data_line_sep_factor_fp
62 \fp_new:N \l__wheelchart_arc_data_lines_pos_fp
63 \fp_new:N \l__wheelchart_arc_data_lines_shift_fp
64 \fp_new:N \l__wheelchart_arc_data_pos_fp
65 \fp_new:N \l__wheelchart_arc_data_radius_plot_false_fp
66 \fp_new:N \l__wheelchart_arc_data_sep_fp
67 \fp_new:N \g__wheelchart_arc_data_slice_length_fp
68 \fp_new:N \l__wheelchart_arc_data_start_angle_plot_false_fp
69 \fp_const:Nn \c__wheelchart_arc_data_start_factor_center_fp { -0.5 }
70 \fp_const:Nn \c__wheelchart_arc_data_start_factor_left_fp { 0 }
71 \fp_const:Nn \c__wheelchart_arc_data_start_factor_right_fp { -1 }
72 \fp_new:N \l__wheelchart_arc_data_text_pos_fp
73 \fp_new:N \l__wheelchart_arc_data_total_angle_plot_false_fp
74 \fp_new:N \l__wheelchart_arc_pos_fp
75 \fp_new:N \l__wheelchart_arc_radius_fp
76 \fp_new:N \l__wheelchart_arc_sep_fp
77 \fp_new:N \l__wheelchart_arc_start_angle_fp
78 \fp_new:N \l__wheelchart_coord_determinant_fp
79 \fp_new:N \g__wheelchart_coord_x_fp
80 \fp_new:N \g__wheelchart_coord_y_fp
81 \fp_new:N \l__wheelchart_counter_or_clockwise_fp
82 \fp_new:N \g__wheelchart_def_angle_angle_fp
83 \fp_new:N \l__wheelchart_discrete_end_length_fp
84 \fp_new:N \l__wheelchart_discrete_factor_fp
85 \fp_new:N \l__wheelchart_discrete_inner_length_fp
86 \fp_new:N \l__wheelchart_discrete_level_fp
87 \fp_new:N \l__wheelchart_discrete_level_end_length_fp
88 \fp_new:N \l__wheelchart_discrete_level_start_length_fp
89 \fp_new:N \l__wheelchart_discrete_levels_sum_fp
90 \fp_new:N \l__wheelchart_discrete_outer_length_fp
91 \fp_new:N \l__wheelchart_discrete_start_length_fp
92 \fp_new:N \l__wheelchart_discrete_sublevel_end_length_fp
93 \fp_new:N \l__wheelchart_discrete_sublevel_start_length_fp
94 \fp_new:N \l__wheelchart_gap_fp
95 \fp_new:N \l__wheelchart_gap_max_angle_fp
96 \fp_new:N \l__wheelchart_gap_max_angle_def_fp
97 \fp_new:N \l__wheelchart_gap_polar_fp
98 \fp_new:N \l__wheelchart_gap_radius_fp
99 \fp_new:N \g__wheelchart_half_ex_over_one_cm_fp
100 \fp_new:N \l__wheelchart_inner_data_angle_pos_fp
101 \fp_new:N \l__wheelchart_inner_data_angle_shift_fp
102 \fp_new:N \l__wheelchart_inner_data_pos_fp
103 \fp_new:N \l__wheelchart_inner_data_sep_fp
104 \fp_new:c { g__wheelchart_inner~end_x_fp }
105 \fp_new:c { g__wheelchart_inner~end_y_fp }
106 \fp_new:N \l__wheelchart_inner_radius_fp
107 \fp_new:c { g__wheelchart_inner~start_x_fp }
108 \fp_new:c { g__wheelchart_inner~start_y_fp }
109 \fp_new:N \l__wheelchart_lines_fp
110 \fp_new:N \l__wheelchart_lines_angle_pos_fp
111 \fp_new:N \l__wheelchart_lines_angle_shift_fp
112 \fp_new:N \l__wheelchart_lines_ext_fp
113 \fp_new:N \l__wheelchart_lines_ext_dirsep_fp
114 \fp_new:N \l__wheelchart_lines_ext_fixed_left_fp
115 \fp_new:N \l__wheelchart_lines_ext_fixed_right_fp
116 \fp_new:N \l__wheelchart_lines_pos_fp
117 \fp_new:N \l__wheelchart_lines_sep_fp
118 \fp_new:N \g__wheelchart_new_angle_fp
119 \fp_new:c { g__wheelchart_outer~end_x_fp }
120 \fp_new:c { g__wheelchart_outer~end_y_fp }
121 \fp_new:N \l__wheelchart_outer_radius_fp
122 \fp_new:c { g__wheelchart_outer~start_x_fp }
123 \fp_new:c { g__wheelchart_outer~start_y_fp }
124 \fp_new:N \g__wheelchart_previous_coord_x_fp
125 \fp_new:N \g__wheelchart_previous_coord_y_fp
126 \fp_new:N \l__wheelchart_samples_fp
127 \fp_new:N \l__wheelchart_slices_angle_fp
128 \fp_new:N \l__wheelchart_slices_angle_pos_fp
129 \fp_new:N \l__wheelchart_slices_angle_shift_fp
130 \fp_new:N \l__wheelchart_slices_arc_A_fp
131 \fp_new:N \l__wheelchart_slices_arc_A_abs_fp
132 \fp_new:N \l__wheelchart_slices_arc_angle_fp
133 \fp_new:N \l__wheelchart_slices_arc_B_fp
134 \fp_new:N \l__wheelchart_slices_arc_coord_fp
135 \fp_new:N \l__wheelchart_slices_arc_rotate_fp
136 \fp_new:N \l__wheelchart_slices_arrow_A_fp
137 \fp_new:N \l__wheelchart_slices_arrow_B_fp
138 \fp_new:N \l__wheelchart_slices_arrow_coord_fp
139 \fp_new:N \l__wheelchart_slices_inner_end_angle_shift_fp
140 \fp_new:N \l__wheelchart_slices_inner_start_angle_shift_fp
141 \fp_new:N \g__wheelchart_slices_orientation_fp
142 \fp_new:N \l__wheelchart_slices_orientation_new_angle_fp
143 \fp_new:N \l__wheelchart_slices_outer_end_angle_shift_fp
144 \fp_new:N \l__wheelchart_slices_outer_start_angle_shift_fp
145 \fp_new:N \l__wheelchart_slices_pos_fp
146 \fp_new:N \l__wheelchart_slices_sep_fp
147 \fp_new:N \l__wheelchart_start_angle_fp
148 \fp_new:N \l__wheelchart_total_angle_fp
149 \fp_new:N \l__wheelchart_total_count_fp
150 \fp_new:N \l__wheelchart_wheel_data_angle_pos_fp
151 \fp_new:N \l__wheelchart_wheel_data_angle_shift_fp
152 \fp_new:N \l__wheelchart_wheel_data_pos_fp
153 \fp_new:N \l__wheelchart_wheel_data_sep_fp
154
155 \int_new:N \g__wheelchart_discrete_count_int
156 \int_new:N \l__wheelchart_discrete_levels_int
157 \int_new:N \l__wheelchart_discrete_partitioning_first_index_int
158 \int_new:N \l__wheelchart_discrete_partitioning_second_index_int
159 \int_new:N \l__wheelchart_discrete_sort_int
160 \int_new:N \l__wheelchart_discrete_space_at_borders_int
161 \int_set:Nn \l__wheelchart_discrete_space_at_borders_int { -1 }
162 \int_new:N \l__wheelchart_discrete_sublevels_int
163 \int_new:N \l__wheelchart_etoc_count_total_pages_int
164 \int_new:N \l__wheelchart_legend_columns_int
165 \int_new:N \l__wheelchart_legend_rows_int
166 \int_new:N \l__wheelchart_lines_ext_bottom_dir_int
167 \int_new:N \l__wheelchart_lines_ext_dir_int
168 \int_const:Nn \c__wheelchart_lines_ext_dir_left_int { -1 }
169 \int_const:Nn \c__wheelchart_lines_ext_dir_right_int { 1 }
170 \int_new:N \l__wheelchart_lines_ext_top_dir_int
171 \int_new:N \l__wheelchart_max_list_items_int
172
173 \regex_const:Nn \c__wheelchart_braces_regex { \{(.+)\} }
174 \regex_const:Nn \c__wheelchart_key_braces_regex { [\w\s]+\{(.+)\} }
175
176 \seq_new:N \l__wheelchart_arc_data_seq
177 \seq_new:N \l__wheelchart_discrete_coefficients_first_seq
178 \seq_new:N \l__wheelchart_discrete_coefficients_second_seq
179 \seq_new:N \l__wheelchart_discrete_points_seq
180 \seq_new:N \l__wheelchart_list_seq
181 \seq_new:N \l__wheelchart_list_items_seq
182
183 \tl_new:N \WClegend
184 \tl_const:Nn \c__wheelchart_arc_around_text_aux_tl
185 {
186 sign ( \l__wheelchart_arc_data_dir_fp ) *
187 (
188 \cs:w c__wheelchart_arc_data_start_factor_\l__wheelchart_arc_data_align_tl _fp \cs_end:
189 + \cs:w c__wheelchart_arc_data_end_factor_\l__wheelchart_arc_data_align_tl _fp \cs_end:
190 )
191 }
192 \tl_new:N \l__wheelchart_arc_data_align_tl
193 \tl_new:N \l__wheelchart_data_anchor_tl
194 \tl_new:N \l__wheelchart_etoc_level_tl
195 \tl_new:N \l__wheelchart_etoc_name_tl
196 \tl_new:N \l__wheelchart_expand_list_tl
197 \tl_new:N \l__wheelchart_expand_list_items_tl
198 \tl_new:N \l__wheelchart_inner_plot_variable_tl
199 \tl_new:N \l__wheelchart_key_name_tl
200 \tl_new:N \l__wheelchart_key_range_tl
201 \tl_new:N \l__wheelchart_legend_row_tl
202 \tl_new:N \g__wheelchart_name_tl
203 \tl_new:N \l__wheelchart_outer_plot_variable_tl
204 \tl_new:N \l__wheelchart_plot_variable_tl
205 \tl_new:N \l__wheelchart_slice_range_index_tl
206 \tl_new:N \l__wheelchart_slices_tl
207 \tl_new:N \g__wheelchart_totalcount_tl
208 \tl_new:N \l__wheelchart_type_tl
209 \tl_set:Nn \l__wheelchart_type_tl { default }
210
211 %%> \subsection{Functions}
212
213 \cs_generate_variant:Nn \seq_set_split:Nnn { Nen , Neo , Nnf }
214 \cs_generate_variant:Nn \tl_build_put_right:Nn { NV }
215
216 \cs_new_protected:Npn \__wheelchart_arc_around_text_plot_false:nn #1#2
217 {
218 \fp_set:Nn \l__wheelchart_arc_start_angle_fp
219 {
220 \__wheelchart_def_angle_plot_false:nnnnn
221 { \WCcount }
222 { \l__wheelchart_arc_data_angle_pos_fp }
223 {
224 ( 0.5 * \c__wheelchart_arc_around_text_aux_tl + #2 - 0.5 ) * \g__wheelchart_arc_data_aux_ii_fp
225 + \l__wheelchart_arc_data_angle_shift_fp
226 }
227 { \l__wheelchart_arc_pos_fp }
228 { \l__wheelchart_arc_sep_fp + \g__wheelchart_half_ex_over_one_cm_fp }
229 }
230 \path
231 [ draw , / wheelchart / arc_style , / wheelchart / arc_#1_half ]
232 ( \fp_use:N \l__wheelchart_arc_start_angle_fp \c_colon_str \fp_use:N \l__wheelchart_arc_radius_fp )
233 arc
234 [
235 start~angle = \fp_use:N \l__wheelchart_arc_start_angle_fp ,
236 end~angle =
237 \__wheelchart_def_angle_plot_false:nnnnn
238 { \WCcount }
239 {#2}
240 { 0 }
241 { \l__wheelchart_arc_pos_fp }
242 { \l__wheelchart_arc_sep_fp + \g__wheelchart_half_ex_over_one_cm_fp } ,
243 radius = \fp_use:N \l__wheelchart_arc_radius_fp
244 ]
245 ;
246 }
247
248 \cs_new_protected:Npn \__wheelchart_arc_around_text_plot_true:nnn #1#2#3
249 {
250 \__wheelchart_convex_comb_coord_plot:nnnnnnn
251 { draw , / wheelchart / arc_style , / wheelchart / arc_#1_half }
252 { 1 }
253 { 0 }
254 {
255 \l__wheelchart_plot_variable_tl *
256 \fp_eval:n
257 {
258 \l__wheelchart_arc_data_angle_pos_fp + 0.5 * \g__wheelchart_arc_data_aux_ii_fp *
259 ( \c__wheelchart_arc_around_text_aux_tl + #2 )
260 }
261 + (#3) * ( 1 - \l__wheelchart_plot_variable_tl )
262 }
263 { \l__wheelchart_plot_variable_tl * \l__wheelchart_arc_data_angle_shift_fp }
264 { \l__wheelchart_arc_pos_fp }
265 { \l__wheelchart_arc_sep_fp }
266 }
267
268 \cs_new_protected:Npn \__wheelchart_caption_and_title:nnnnn #1#2#3#4#5
269 {
270 \__wheelchart_if_text:nnn {#1} { o }
271 {
272 \node [ anchor = #2 , align = #3 , / wheelchart / #1_style ]
273 at ( $ (#4) + ( 0 , { #5 * ( \pgfkeysvalueof { / wheelchart / #1~sep } ) } ) $ )
274 { \pgfkeysvalueof { / wheelchart / #1 } } ;
275 }
276 }
277
278 \cs_new:Npn \__wheelchart_convex_comb_coord_aux:n #1 { (#1) }
279
280 \cs_generate_variant:Nn \__wheelchart_convex_comb_coord_aux:n { o }
281
282 \cs_new:Npn \__wheelchart_convex_comb_coord_def:nnnn #1#2#3#4
283 {
284 $
285 (
286 \__wheelchart_inner_plot:nn
287 {
288 \fp_eval:n
289 {
290 ( 1 - (#1) ) * \cs:w g__wheelchart_slice_inner_start_angle_\WCcount _fp \cs_end:
291 + (#1) * \cs:w g__wheelchart_slice_inner_end_angle_\WCcount _fp \cs_end:
292 + \l__wheelchart_counter_or_clockwise_fp * (#2)
293 }
294 }
295 { \fp_eval:n { \cs:w g__wheelchart_inner_radius_\WCcount _fp \cs_end: - (#4) } }
296 )
297 ! { \fp_eval:n {#3} } !
298 (
299 \__wheelchart_outer_plot:nn
300 {
301 \fp_eval:n
302 {
303 ( 1 - (#1) ) * \cs:w g__wheelchart_slice_outer_start_angle_\WCcount _fp \cs_end:
304 + (#1) * \cs:w g__wheelchart_slice_outer_end_angle_\WCcount _fp \cs_end:
305 + \l__wheelchart_counter_or_clockwise_fp * (#2)
306 }
307 }
308 { \fp_eval:n { \cs:w g__wheelchart_outer_radius_\WCcount _fp \cs_end: + (#4) } }
309 )
310 $%note the () around the #i's to keep these contents together
311 }
312
313 \cs_new_protected:Npn \__wheelchart_convex_comb_coord_plot_aux:nnnn #1#2#3#4
314 {
315 \path [#1] plot
316 [
317 domain = {#2} \c_colon_str {#3} ,
318 samples = \fp_use:c { g__wheelchart_samples_\WCcount _fp } ,
319 variable = \l__wheelchart_plot_variable_tl
320 ]
321 ( {#4} ) ;
322 }
323
324 \cs_generate_variant:Nn \__wheelchart_convex_comb_coord_plot_aux:nnnn { nnno }
325
326 \cs_new_protected:Npn \__wheelchart_convex_comb_coord_plot:nnnnnnn #1#2#3#4#5#6#7
327 {
328 \__wheelchart_convex_comb_coord_plot_aux:nnno {#1} {#2} {#3}
329 { \__wheelchart_convex_comb_coord_def:nnnn {#4} {#5} {#6} { \g__wheelchart_half_ex_over_one_cm_fp + (#7) } }
330 }
331
332 \cs_new_protected:Npn \__wheelchart_def_angle_aux:
333 {
334 \fp_gset:Nn \g__wheelchart_def_angle_angle_fp
335 {
336 atand
337 (
338 (
339 \pgf@xx * ( \y { l__wheelchart_def_angle_2 } - \y { l__wheelchart_def_angle_1 } )
340 - \pgf@xy * ( \x { l__wheelchart_def_angle_2 } - \x { l__wheelchart_def_angle_1 } )
341 )
342 / \l__wheelchart_coord_determinant_fp ,
343 (
344 \pgf@yy * ( \x { l__wheelchart_def_angle_2 } - \x { l__wheelchart_def_angle_1 } )
345 - \pgf@yx * ( \y { l__wheelchart_def_angle_2 } - \y { l__wheelchart_def_angle_1 } )
346 )
347 / \l__wheelchart_coord_determinant_fp
348 )
349 }%\pgf@xx and so on are necessary if an option such as [x={(-0.5,0)},y={(0,0.5)}] is given to the tikzpicture
350 }
351
352 \cs_new_protected:Npn \__wheelchart_def_angle:nnnn #1#2#3#4
353 {
354 \bool_if:NTF \l__wheelchart_plot_bool
355 {
356 \path let
357 \p { l__wheelchart_def_angle_1 } = \__wheelchart_point_plot_true:nnnnn { \WCcount } {#1} {#2} { 0 } {#4} ,
358 \p { l__wheelchart_def_angle_2 } = \__wheelchart_point_plot_true:nnnnn { \WCcount } {#1} {#2} { 1 } {#4}
359 in
360 [
361 / utils / exec =
362 {
363 \bool_gset:Nn \g__wheelchart_def_angle_radius_shift_bool
364 {
365 \fp_compare_p:n
366 {
367 \y { l__wheelchart_def_angle_2 } - \y { l__wheelchart_def_angle_1 } == 0
368 &&
369 \x { l__wheelchart_def_angle_2 } - \x { l__wheelchart_def_angle_1 } == 0
370 }
371 }
372 \bool_if:NF \g__wheelchart_def_angle_radius_shift_bool
373 { \__wheelchart_def_angle_aux: }
374 }
375 ]
376 ;
377 \bool_if:NT \g__wheelchart_def_angle_radius_shift_bool
378 {
379 \path let
380 \p { l__wheelchart_def_angle_1 } =
381 \__wheelchart_point_plot_true:nnnnn { \WCcount } {#1} {#2} { 0 }
382 { \fp_eval:n { (#4) + 1 / \cs:w g__wheelchart_samples_\WCcount _fp \cs_end: } } ,
383 \p { l__wheelchart_def_angle_2 } =
384 \__wheelchart_point_plot_true:nnnnn { \WCcount } {#1} {#2} { 1 }
385 { \fp_eval:n { (#4) + 1 / \cs:w g__wheelchart_samples_\WCcount _fp \cs_end: } }
386 in [ / utils / exec = { \__wheelchart_def_angle_aux: } ]
387 ;
388 }
389 \pgfmathparse { Mod ( \fp_use:N \g__wheelchart_def_angle_angle_fp , 360 ) }
390 }
391 {
392 \pgfmathparse { Mod ( \__wheelchart_def_angle_plot_false:nnnnn { \WCcount } {#1} {#2} {#3} {#4} , 360 ) }
393 }
394 }
395
396 \cs_new:Npn \__wheelchart_def_angle_plot_false_aux_angle:nn #1#2
397 {
398 ( 1 - (#2) ) *
399 (
400 \cs:w g__wheelchart_slice_outer_start_angle_#1_fp \cs_end:
401 - \cs:w g__wheelchart_slice_inner_start_angle_#1_fp \cs_end:
402 )
403 + (#2) * ( \cs:w g__wheelchart_slice_outer_end_angle_#1_fp \cs_end: - \cs:w g__wheelchart_slice_inner_end_angle_#1_fp \cs_end: )
404 }
405
406 \cs_new:Npn \__wheelchart_def_angle_plot_false:nnnnn #1#2#3#4#5
407 {
408 \fp_eval:n
409 {
410 \fp_compare:nNnTF { \__wheelchart_def_angle_plot_false_aux_angle:nn {#1} {#2} } = { 0 }
411 { 0 }
412 {
413 asind
414 (
415 (
416 sqrt
417 (
418 ( \cs:w g__wheelchart_outer_radius_#1_fp \cs_end: + \cs:w g__wheelchart_inner_radius_#1_fp \cs_end: ) ^ 2
419 - \cs:w g__wheelchart_outer_radius_#1_fp \cs_end: * \cs:w g__wheelchart_inner_radius_#1_fp \cs_end: *
420 (
421 2 + 2 * cosd ( \__wheelchart_def_angle_plot_false_aux_angle:nn {#1} {#2} )
422 + \cs:w g__wheelchart_outer_radius_#1_fp \cs_end: * \cs:w g__wheelchart_inner_radius_#1_fp \cs_end:
423 *
424 (
425 (
426 sind ( \__wheelchart_def_angle_plot_false_aux_angle:nn {#1} {#2} )
427 / \__wheelchart_def_radius:nnn {#1} {#4} {#5}
428 )
429 ^ 2
430 )
431 )
432 )
433 + \cs:w g__wheelchart_inner_radius_#1_fp \cs_end: *
434 (
435 \cs:w g__wheelchart_inner_radius_#1_fp \cs_end:
436 - \cs:w g__wheelchart_outer_radius_#1_fp \cs_end:
437 * cosd ( \__wheelchart_def_angle_plot_false_aux_angle:nn {#1} {#2} )
438 )
439 / \__wheelchart_def_radius:nnn {#1} {#4} {#5}
440 )
441 * \cs:w g__wheelchart_outer_radius_#1_fp \cs_end: * sind ( \__wheelchart_def_angle_plot_false_aux_angle:nn {#1} {#2} )
442 /
443 (
444 ( \cs:w g__wheelchart_outer_radius_#1_fp \cs_end: + \cs:w g__wheelchart_inner_radius_#1_fp \cs_end: ) ^ 2
445 - 2 * \cs:w g__wheelchart_outer_radius_#1_fp \cs_end: * \cs:w g__wheelchart_inner_radius_#1_fp \cs_end:
446 * ( 1 + cosd ( \__wheelchart_def_angle_plot_false_aux_angle:nn {#1} {#2} ) )
447 )
448 )
449 }
450 + ( 1 - (#2) ) * ( \cs:w g__wheelchart_slice_inner_start_angle_#1_fp \cs_end: )
451 + (#2) * ( \cs:w g__wheelchart_slice_inner_end_angle_#1_fp \cs_end: )
452 + \l__wheelchart_counter_or_clockwise_fp * (#3)
453 }
454 }
455
456 \cs_new_protected:Npn \__wheelchart_def_coord:nnnn #1#2#3#4
457 {
458 \path let \p { l__wheelchart_coord } =
459 ( \cs:w __wheelchart_#2_plot:nn \cs_end: {#4} { \fp_use:c { g__wheelchart_#2_radius_\WCcount _fp } } )
460 in
461 [
462 / utils / exec =
463 {
464 \fp_gset:cn { g__wheelchart_#1_x_fp }
465 {
466 ( \pgf@yy * \x { l__wheelchart_coord } - \pgf@yx * \y { l__wheelchart_coord } ) / \l__wheelchart_coord_determinant_fp
467 }
468 \fp_gset:cn { g__wheelchart_#1_y_fp }
469 {
470 ( \pgf@xx * \y { l__wheelchart_coord } - \pgf@xy * \x { l__wheelchart_coord } ) / \l__wheelchart_coord_determinant_fp
471 }
472 }
473 ]
474 coordinate ( g__wheelchart_slice_\WCcount _#2~#3_coordinate ) at ( \p { l__wheelchart_coord } )
475 ;
476 }
477
478 \cs_new_protected:Npn \__wheelchart_def_fp:nn #1#2
479 {
480 \pgfmathparse { \pgfkeysvalueof { / wheelchart / #2 } }
481 \fp_set:cn { l__wheelchart_#1_fp } { \pgfmathresult }
482 }
483
484 \cs_new_protected:Npn \__wheelchart_def_gap:nn #1#2
485 {
486 \fp_gset:cn { g__wheelchart_#1_gap_\WCcount _fp }
487 {
488 (#2) * sind ( min ( \l__wheelchart_abs_half_angle_minus_new_angle_minus_gap_polar_fp , \l__wheelchart_gap_max_angle_def_fp ) )
489 <
490 \l__wheelchart_gap_fp
491 ?
492 min ( \cs:w g__wheelchart_abs_half_angle_minus_new_angle_\WCcount _fp \cs_end: , \l__wheelchart_gap_max_angle_def_fp )
493 :
494 asind ( min ( \l__wheelchart_gap_fp / ( (#2) + 1 - sign (#2) ) , 1 ) ) + \l__wheelchart_gap_polar_fp
495 %note the min ( ... , 1 ) so that the asind is always defined
496 %also note the + 1 - sign (#2) so that the denominator is also nonzero if #2 = 0
497 }
498 }
499
500 \cs_new_protected:Npn \__wheelchart_def_inner_radius:
501 {
502 \bool_if:NTF \l__wheelchart_pie_bool
503 { \fp_set:Nn \l__wheelchart_inner_radius_fp { 0 } }
504 {
505 \pgfmathparse { \pgfkeysvalueof { / wheelchart / inner~radius } }
506 \fp_set:Nn \l__wheelchart_inner_radius_fp { \pgfmathresult + \l__wheelchart_gap_radius_fp }
507 }
508 }
509
510 \cs_new_protected:Npn \__wheelchart_def_orientation:
511 {%determine the orientation, this is necessary even if no plot is used, for example if
512 %inner radius > outer radius then \g__wheelchart_slices_orientation_fp is different from
513 %\l__wheelchart_counter_or_clockwise_fp
514 \fp_set:Nn \l__wheelchart_slices_orientation_new_angle_fp
515 {
516 \g__wheelchart_angle_fp +
517 (
518 \g__wheelchart_new_angle_fp == \g__wheelchart_angle_fp
519 ?
520 \l__wheelchart_counter_or_clockwise_fp * \l__wheelchart_total_angle_fp
521 :
522 \g__wheelchart_new_angle_fp - \g__wheelchart_angle_fp
523 )
524 / \cs:w g__wheelchart_samples_1_fp \cs_end:
525 }
526 \path let
527 \p { l__wheelchart_slices_orientation_1 } =
528 (
529 \__wheelchart_outer_plot:nn
530 { \fp_use:N \g__wheelchart_angle_fp }
531 { \fp_use:c { g__wheelchart_outer_radius_1_fp } }
532 ) ,
533 \p { l__wheelchart_slices_orientation_2 } =
534 (
535 \__wheelchart_outer_plot:nn
536 { \fp_use:N \l__wheelchart_slices_orientation_new_angle_fp }
537 { \fp_use:c { g__wheelchart_outer_radius_1_fp } }
538 ) ,
539 \p { l__wheelchart_slices_orientation_3 } =
540 (
541 \__wheelchart_inner_plot:nn
542 { \fp_use:N \l__wheelchart_slices_orientation_new_angle_fp }
543 { \fp_use:c { g__wheelchart_inner_radius_1_fp } }
544 ) ,
545 \p { l__wheelchart_slices_orientation_4 } =
546 (
547 \__wheelchart_inner_plot:nn
548 { \fp_use:N \g__wheelchart_angle_fp }
549 { \fp_use:c { g__wheelchart_inner_radius_1_fp } }
550 )
551 in
552 [
553 / utils / exec =
554 {
555 \fp_gset:Nn \g__wheelchart_slices_orientation_fp
556 {
557 sign
558 (
559 0.1 * \y { l__wheelchart_slices_orientation_1 }
560 * ( \x { l__wheelchart_slices_orientation_4 } - \x { l__wheelchart_slices_orientation_2 } )
561 + 0.1 * \y { l__wheelchart_slices_orientation_2 }
562 * ( \x { l__wheelchart_slices_orientation_1 } - \x { l__wheelchart_slices_orientation_3 } )
563 + 0.1 * \y { l__wheelchart_slices_orientation_3 }
564 * ( \x { l__wheelchart_slices_orientation_2 } - \x { l__wheelchart_slices_orientation_4 } )
565 + 0.1 * \y { l__wheelchart_slices_orientation_4 }
566 * ( \x { l__wheelchart_slices_orientation_3 } - \x { l__wheelchart_slices_orientation_1 } )
567 )
568 * sign ( \l__wheelchart_coord_determinant_fp )
569 }
570 }
571 ]
572 ;%the terms are multiplied with 0.1 to try to avoid an overflow
573 \fp_compare:nNnT { \g__wheelchart_slices_orientation_fp } = { 0 }
574 { \fp_gset_eq:NN \g__wheelchart_slices_orientation_fp \l__wheelchart_counter_or_clockwise_fp }
575 }
576
577 \cs_new_protected:Npn \__wheelchart_def_outer_radius:
578 {
579 \pgfmathparse { \pgfkeysvalueof { / wheelchart / outer~radius } }
580 \fp_set:Nn \l__wheelchart_outer_radius_fp { \pgfmathresult - \l__wheelchart_gap_radius_fp }
581 }
582
583 \cs_new:Npn \__wheelchart_def_radius:nnn #1#2#3
584 {
585 \fp_eval:n
586 {
587 ( 1 - (#2) ) * ( \cs:w g__wheelchart_inner_radius_#1_fp \cs_end: - (#3) )
588 + (#2) * ( \cs:w g__wheelchart_outer_radius_#1_fp \cs_end: + (#3) )
589 }
590 }
591
592 \cs_new_protected:Npn \__wheelchart_def_slice_angle:nnnn #1#2#3#4
593 {
594 \fp_gzero_new:c { g__wheelchart_slice_#1_#2_angle_\WCcount _fp }
595 \bool_if:NTF \l__wheelchart_plot_bool
596 {
597 \fp_gset:cn { g__wheelchart_slice_#1_#2_angle_\WCcount _fp }
598 {
599 \cs:w g__wheelchart_#3angle_fp \cs_end: +
600 (
601 \l__wheelchart_counter_or_clockwise_fp *
602 ( (#4) * \cs:w g__wheelchart_#1_gap_\WCcount _fp \cs_end: + \cs:w l__wheelchart_slices_#1_#2_angle_shift_fp \cs_end: )
603 )
604 }
605 }
606 {
607 \fp_gset:cn { g__wheelchart_slice_#1_#2_angle_\WCcount _fp }
608 {
609 \cs:w g__wheelchart_#3angle_fp \cs_end: +
610 (
611 \l__wheelchart_counter_or_clockwise_fp *
612 (
613 (#4) * \cs:w g__wheelchart_#1_gap_\WCcount _fp \cs_end: + \cs:w l__wheelchart_slices_#1_#2_angle_shift_fp \cs_end:
614 - asind
615 (
616 \cs:w g__wheelchart_inner_radius_\WCcount _fp \cs_end:
617 * sind ( \cs:w l__wheelchart_slices_#1_#2_angle_shift_fp \cs_end: )
618 / \cs:w g__wheelchart_outer_radius_\WCcount _fp \cs_end:
619 )
620 )
621 )
622 }
623 }
624 }
625
626 \cs_new_protected:Npn \__wheelchart_def_slice_keys:n #1
627 {
628 {%note the double braces {{...}} so that the contents is in a group
629 %and in particular, pgfkeys which are specific to the current slice are local for this slice
630 \clist_if_in:NVT \l__wheelchart_slice_range_local_clist \WCcount
631 {
632 \pgfkeys { / wheelchart , slice_final /. expanded = { \exp_not:v { l__wheelchart_slice_\WCcount _keys_clist } } }
633 \pgfkeys{ / wheelchart , slice_final_style }
634 }
635 #1
636 }
637 }
638
639 \cs_new_protected:Npn \__wheelchart_def_WClegend:
640 {
641 \int_set:Nn \l__wheelchart_legend_columns_int
642 { \fp_eval:n { ceil ( \WCtotalcount / ceil ( \WCtotalcount / ( \pgfkeysvalueof { / wheelchart / legend~columns } ) ) ) } }
643 \tl_build_begin:N \WClegend
644 \int_compare:nNnTF { \l__wheelchart_legend_columns_int } = { 1 }
645 { \int_step_inline:nnn { 2 } { \WCtotalcount } { \__wheelchart_legend_append:nn {##1} { \\ } } }
646 {
647 \int_set:Nn \l__wheelchart_legend_rows_int
648 { \fp_eval:n { ceil ( \WCtotalcount / \l__wheelchart_legend_columns_int ) } }
649 \int_step_inline:nn { \l__wheelchart_legend_rows_int - 1 }
650 {
651 \int_step_inline:nn { \l__wheelchart_legend_columns_int - 2 }
652 { \__wheelchart_legend_append:nn { ##1 + \l__wheelchart_legend_rows_int * ####1 } { & } }
653 \int_compare:nNnF { ##1 + ( \l__wheelchart_legend_columns_int - 1 ) * \l__wheelchart_legend_rows_int } > { \WCtotalcount }
654 {
655 \__wheelchart_legend_append:nn
656 { ##1 + ( \l__wheelchart_legend_columns_int - 1 ) * \l__wheelchart_legend_rows_int }
657 { & }
658 }
659 \__wheelchart_legend_append:nn { ##1 + 1 } { \\ }
660 }
661 \int_step_inline:nn { \l__wheelchart_legend_columns_int - 2 }
662 { \__wheelchart_legend_append:nn { \l__wheelchart_legend_rows_int * ( ##1 + 1 ) } { & } }
663 \int_compare:nNnF { \l__wheelchart_legend_columns_int * \l__wheelchart_legend_rows_int } > { \WCtotalcount }
664 { \__wheelchart_legend_append:nn { \l__wheelchart_legend_columns_int * \l__wheelchart_legend_rows_int } { & } }
665 }
666 \__wheelchart_legend_append:nn { 1 } { \\ }%at the moment it is unnecessary to set g__wheelchart_WCcount_counter to 1
667 %but this is done to be future-proof if the contents of \WClegend would be parsed in a way that prohibits the value for
668 %g__wheelchart_WCcount_counter to be larger than \WCtotalcount
669 \tl_build_end:N \WClegend
670 \cs_set:Npn \WCcount { \theg__wheelchart_WCcount_counter }
671 \cs_set:Npn \WCpercentage { \cs:w l__wheelchart_WCpercentage_\theg__wheelchart_WCcount_counter \cs_end: }
672 \cs_set:Npn \WCpercentagerounded { \cs:w l__wheelchart_WCpercentagerounded_\theg__wheelchart_WCcount_counter \cs_end: }
673 \str_if_eq:eeTF { \l__wheelchart_type_tl } { etoc }
674 {
675 \cs_set:Npn \WCetocthelinkedname
676 { \cs:w g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _the_linked_name_\theg__wheelchart_WCcount_counter \cs_end: }
677 \cs_set:Npn \WCetocthelinkednumber
678 { \cs:w g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _the_linked_number_\theg__wheelchart_WCcount_counter \cs_end: }
679 \cs_set:Npn \WCetocthelinkedpage
680 { \cs:w g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _the_linked_page_\theg__wheelchart_WCcount_counter \cs_end: }
681 \cs_set:Npn \WCetocthename
682 { \cs:w g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _the_name_\theg__wheelchart_WCcount_counter \cs_end: }
683 \cs_set:Npn \WCetocthenumber
684 { \cs:w g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _the_number_\theg__wheelchart_WCcount_counter \cs_end: }
685 \cs_set:Npn \WCetocthepage
686 { \cs:w g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _the_page_\theg__wheelchart_WCcount_counter \cs_end: }
687 \cs_set:Npn \WCetocthenumberofpages
688 { \cs:w g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _the_number_of_pages_\theg__wheelchart_WCcount_counter \cs_end: }
689 }
690 {
691 \clist_if_empty:NTF \l__wheelchart_header_clist
692 {
693 \int_step_inline:nn { \l__wheelchart_max_list_items_int }
694 {
695 \cs_set:cpn { WCvar\int_to_Alph:n {##1} }
696 { \cs:w l__wheelchart_item_WCvar\int_to_Alph:n {##1}_\theg__wheelchart_WCcount_counter \cs_end: }
697 }
698 }
699 {
700 \int_step_inline:nn { \l__wheelchart_max_list_items_int }
701 {
702 \cs_set:cpn { \pgfkeysvalueof { / wheelchart / header~prefix } \clist_item:Nn \l__wheelchart_header_clist {##1} }
703 {
704 \cs:w
705 l__wheelchart_item_\pgfkeysvalueof { / wheelchart / header~prefix }
706 \clist_item:Nn \l__wheelchart_header_clist {##1}_\theg__wheelchart_WCcount_counter
707 \cs_end:
708 }
709 }
710 }
711 }
712 \setcounter { g__wheelchart_WCcount_counter } { 1 }
713 }
714
715 \cs_new:Npn \__wheelchart_diff_atan:nnnn #1#2#3#4
716 {
717 Mod
718 (
719 \fp_eval:n
720 {
721 \g__wheelchart_slices_orientation_fp *
722 (
723 atand
724 (
725 \cs:w g__wheelchart_#3_y_fp \cs_end: - \cs:w g__wheelchart_#4_y_fp \cs_end: ,
726 \cs:w g__wheelchart_#3_x_fp \cs_end: - \cs:w g__wheelchart_#4_x_fp \cs_end:
727 )
728 - atand
729 (
730 \cs:w g__wheelchart_#1_y_fp \cs_end: - \cs:w g__wheelchart_#2_y_fp \cs_end: ,
731 \cs:w g__wheelchart_#1_x_fp \cs_end: - \cs:w g__wheelchart_#2_x_fp \cs_end:
732 )
733 )
734 }
735 ,
736 360
737 )%note the Mod 360 because for example cos(90/2)\neq cos(-270/2)
738 }
739
740 \cs_new_protected:Npn \__wheelchart_discrete_algorithm:
741 {
742 \__wheelchart_def_fp:nn { discrete_factor } { discrete~factor }
743 \__wheelchart_def_fp:nn { gap_radius } { gap~radius }
744 \__wheelchart_def_outer_radius:
745 \__wheelchart_def_inner_radius:
746 \int_compare:nNnT { \l__wheelchart_discrete_space_at_borders_int } = { -1 }
747 {
748 \pgfkeys
749 {
750 / errors / boolean~expected /. expanded =
751 { discrete~space~at~borders }
752 { \pgfkeysvalueof { / wheelchart / discrete~space~at~borders } }
753 }
754 }
755 \seq_clear:N \l__wheelchart_discrete_points_seq
756 \bool_if:NTF \l__wheelchart_plot_bool
757 {
758 \__wheelchart_def_fp:nn { samples } { samples }
759 \fp_zero:N \l__wheelchart_discrete_outer_length_fp
760 \__wheelchart_discrete_def_coord:nn { outer } { 0 }
761 \int_step_inline:nn { \fp_use:N \l__wheelchart_samples_fp - 1 }
762 {
763 \__wheelchart_discrete_def_coord:nn { outer } {##1}
764 \fp_add:Nn \l__wheelchart_discrete_outer_length_fp
765 {
766 sqrt
767 (
768 ( \g__wheelchart_coord_x_fp - \g__wheelchart_previous_coord_x_fp ) ^ 2
769 + ( \g__wheelchart_coord_y_fp - \g__wheelchart_previous_coord_y_fp ) ^ 2
770 )
771 }
772 }
773 \__wheelchart_discrete_def_coord:nn { inner } { \l__wheelchart_samples_fp - 1 }
774 \fp_set:Nn \l__wheelchart_discrete_end_length_fp
775 {
776 sqrt
777 (
778 ( \g__wheelchart_coord_x_fp - \g__wheelchart_previous_coord_x_fp ) ^ 2
779 + ( \g__wheelchart_coord_y_fp - \g__wheelchart_previous_coord_y_fp ) ^ 2
780 )
781 }
782 \fp_zero:N \l__wheelchart_discrete_inner_length_fp
783 \int_step_inline:nnnn { \fp_use:N \l__wheelchart_samples_fp - 2 } { -1 } { 0 }
784 {
785 \__wheelchart_discrete_def_coord:nn { inner } {##1}
786 \fp_add:Nn \l__wheelchart_discrete_inner_length_fp
787 {
788 sqrt
789 (
790 ( \g__wheelchart_coord_x_fp - \g__wheelchart_previous_coord_x_fp ) ^ 2
791 + ( \g__wheelchart_coord_y_fp - \g__wheelchart_previous_coord_y_fp ) ^ 2
792 )
793 }
794 }
795 \__wheelchart_discrete_def_coord:nn { outer } { 0 }
796 \fp_set:Nn \l__wheelchart_discrete_start_length_fp
797 {
798 sqrt
799 (
800 ( \g__wheelchart_coord_x_fp - \g__wheelchart_previous_coord_x_fp ) ^ 2
801 + ( \g__wheelchart_coord_y_fp - \g__wheelchart_previous_coord_y_fp ) ^ 2
802 )
803 }
804 }
805 {
806 \fp_set:Nn \l__wheelchart_discrete_outer_length_fp
807 { abs ( \l__wheelchart_total_angle_fp * deg * \l__wheelchart_outer_radius_fp ) }
808 \fp_set:Nn \l__wheelchart_discrete_end_length_fp { abs ( \l__wheelchart_outer_radius_fp - \l__wheelchart_inner_radius_fp ) }
809 \fp_set:Nn \l__wheelchart_discrete_inner_length_fp
810 { abs ( \l__wheelchart_total_angle_fp * deg * \l__wheelchart_inner_radius_fp ) }
811 %note the abs ( ... ) because \l__wheelchart_total_angle_fp can be negative
812 %and \l__wheelchart_outer_radius_fp can be smaller than \l__wheelchart_inner_radius_fp
813 \fp_set_eq:NN \l__wheelchart_discrete_start_length_fp \l__wheelchart_discrete_end_length_fp
814 }
815 \str_case:enF { \pgfkeysvalueof { / wheelchart / discrete~partitioning } }
816 {
817 { radius }
818 {
819 \int_set:Nn \l__wheelchart_discrete_partitioning_first_index_int { 1 }
820 \int_set:Nn \l__wheelchart_discrete_partitioning_second_index_int { 2 }
821 \fp_set_eq:NN \l__wheelchart_discrete_level_start_length_fp \l__wheelchart_discrete_inner_length_fp
822 \fp_set_eq:NN \l__wheelchart_discrete_level_end_length_fp \l__wheelchart_discrete_outer_length_fp
823 \fp_set_eq:NN \l__wheelchart_discrete_sublevel_start_length_fp \l__wheelchart_discrete_start_length_fp
824 \fp_set_eq:NN \l__wheelchart_discrete_sublevel_end_length_fp \l__wheelchart_discrete_end_length_fp
825 }
826 { angle }
827 {
828 \int_set:Nn \l__wheelchart_discrete_partitioning_first_index_int { 2 }
829 \int_set:Nn \l__wheelchart_discrete_partitioning_second_index_int { 1 }
830 \fp_set_eq:NN \l__wheelchart_discrete_level_start_length_fp \l__wheelchart_discrete_start_length_fp
831 \fp_set_eq:NN \l__wheelchart_discrete_level_end_length_fp \l__wheelchart_discrete_end_length_fp
832 \fp_set_eq:NN \l__wheelchart_discrete_sublevel_start_length_fp \l__wheelchart_discrete_inner_length_fp
833 \fp_set_eq:NN \l__wheelchart_discrete_sublevel_end_length_fp \l__wheelchart_discrete_outer_length_fp
834 \int_set:Nn \l__wheelchart_discrete_sort_int { 3 - \l__wheelchart_discrete_sort_int }
835 }
836 }
837 {
838 \pgfkeys
839 {
840 / errors / unknown~choice~value /. expanded =
841 { discrete~partitioning }
842 { \pgfkeysvalueof { / wheelchart / discrete~partitioning } }
843 }
844 }
845 \int_set:Nn \l__wheelchart_discrete_levels_int
846 {
847 \fp_eval:n
848 {
849 max
850 (
851 round
852 (
853 sqrt
854 (
855 (
856 ( \l__wheelchart_discrete_sublevel_start_length_fp + \l__wheelchart_discrete_sublevel_end_length_fp )
857 * \l__wheelchart_discrete_factor_fp
858 / ( \l__wheelchart_discrete_level_start_length_fp + \l__wheelchart_discrete_level_end_length_fp )
859 )
860 * \WCtotalnum
861 )
862 )
863 ,
864 1
865 )
866 }
867 }
868 \int_gzero:N \g__wheelchart_discrete_count_int
869 \fp_zero:N \l__wheelchart_discrete_levels_sum_fp
870 \int_step_inline:nn { \l__wheelchart_discrete_levels_int - 1 }
871 {
872 \fp_set:Nn \l__wheelchart_discrete_level_fp
873 {
874 ( ##1 - 0.5 * ( 1 + \l__wheelchart_discrete_space_at_borders_int ) )
875 / ( \l__wheelchart_discrete_levels_int - \l__wheelchart_discrete_space_at_borders_int )
876 }
877 \fp_add:Nn \l__wheelchart_discrete_levels_sum_fp { \l__wheelchart_discrete_level_fp }
878 \int_set:Nn \l__wheelchart_discrete_sublevels_int
879 {
880 \fp_eval:n
881 {
882 round
883 (
884 (
885 (
886 ( ##1 ) * \l__wheelchart_discrete_level_start_length_fp
887 + \l__wheelchart_discrete_levels_sum_fp
888 * ( \l__wheelchart_discrete_level_end_length_fp - \l__wheelchart_discrete_level_start_length_fp )
889 )
890 /
891 (
892 \l__wheelchart_discrete_levels_int * 0.5
893 * ( \l__wheelchart_discrete_level_start_length_fp + \l__wheelchart_discrete_level_end_length_fp )
894 )
895 )
896 * \WCtotalnum - \g__wheelchart_discrete_count_int
897 )
898 }
899 }
900 \int_gadd:Nn \g__wheelchart_discrete_count_int { \l__wheelchart_discrete_sublevels_int }
901 \int_compare:nNnTF { \l__wheelchart_discrete_sublevels_int } = { 1 }
902 {
903 \seq_put_right:Ne \l__wheelchart_discrete_points_seq
904 {
905 0.5
906 /
907 \fp_use:N \l__wheelchart_discrete_level_fp
908 }
909 }
910 {
911 \int_step_inline:nn { \l__wheelchart_discrete_sublevels_int }
912 {
913 \seq_put_right:Ne \l__wheelchart_discrete_points_seq
914 {
915 \fp_eval:n
916 {
917 ( ####1 - 0.5 * ( 1 + \l__wheelchart_discrete_space_at_borders_int ) )
918 / ( \l__wheelchart_discrete_sublevels_int - \l__wheelchart_discrete_space_at_borders_int )
919 }
920 %the denominator is 0 if \l__wheelchart_discrete_sublevels_int = \l__wheelchart_discrete_space_at_borders_int = 1
921 %thus the case when \l__wheelchart_discrete_sublevels_int = 1 is treated separately above
922 /
923 \fp_use:N \l__wheelchart_discrete_level_fp
924 }
925 }
926 }
927 }
928 \int_compare:nNnTF { \l__wheelchart_discrete_levels_int } = { 1 }
929 { \fp_set:Nn \l__wheelchart_discrete_level_fp { 0.5 } }
930 {
931 \fp_set:Nn \l__wheelchart_discrete_level_fp
932 {
933 1 - 0.5 * ( 1 - \l__wheelchart_discrete_space_at_borders_int )
934 / ( \l__wheelchart_discrete_levels_int - \l__wheelchart_discrete_space_at_borders_int )
935 }
936 }
937 \int_set:Nn \l__wheelchart_discrete_sublevels_int { \fp_eval:n { round ( \WCtotalnum - \g__wheelchart_discrete_count_int ) } }
938 \int_compare:nNnTF { \l__wheelchart_discrete_sublevels_int } = { 1 }
939 {
940 \seq_put_right:Ne \l__wheelchart_discrete_points_seq
941 {
942 0.5
943 /
944 \fp_use:N \l__wheelchart_discrete_level_fp
945 }
946 }
947 {
948 \int_step_inline:nn { \l__wheelchart_discrete_sublevels_int }
949 {
950 \seq_put_right:Ne \l__wheelchart_discrete_points_seq
951 {
952 \fp_eval:n
953 {
954 ( ##1 - 0.5 * ( 1 + \l__wheelchart_discrete_space_at_borders_int ) )
955 / ( \l__wheelchart_discrete_sublevels_int - \l__wheelchart_discrete_space_at_borders_int )
956 }
957 /
958 \fp_use:N \l__wheelchart_discrete_level_fp
959 }
960 }
961 }
962 \seq_sort:Nn \l__wheelchart_discrete_points_seq
963 {
964 \seq_set_split:Nnn \l__wheelchart_discrete_coefficients_first_seq { / } {##1}
965 \seq_set_split:Nnn \l__wheelchart_discrete_coefficients_second_seq { / } {##2}
966 \fp_compare:nNnTF
967 { \seq_item:Nn \l__wheelchart_discrete_coefficients_first_seq { \l__wheelchart_discrete_sort_int } }
968 >
969 { \seq_item:Nn \l__wheelchart_discrete_coefficients_second_seq { \l__wheelchart_discrete_sort_int } }
970 { \sort_return_swapped: }
971 { \sort_return_same: }
972 }
973 \int_gzero:N \g__wheelchart_discrete_count_int
974 \__wheelchart_for_loop:n
975 {
976 \pgfkeysvalueof { / wheelchart / before~slices }
977 \int_step_inline:nn { \fp_eval:n { round ( \cs:w g__wheelchart_value_\WCcount _fp \cs_end: ) } }
978 %note that \fp_eval:n { round ( ... ) } is necessary even when the value is an integer because pgfmath
979 %could have added .0 and then \int_step_inline:nn { \cs:w g__wheelchart_value_\WCcount _fp \cs_end: } would give the messages
980 %Missing character: There is no . in font nullfont! Missing character: There is no 0 in font nullfont!
981 {
982 \int_gincr:N \g__wheelchart_discrete_count_int
983 \cs_set:Npe \WCcountdiscrete { \int_use:N \g__wheelchart_discrete_count_int }
984 \seq_set_split:Nne \l__wheelchart_discrete_coefficients_first_seq { / }
985 { \seq_item:Nn \l__wheelchart_discrete_points_seq { \g__wheelchart_discrete_count_int } }
986 %Naturally, an error occurs if the sum of the rounded values of the key value is
987 %greater than the rounded value of \WCtotalnum.
988 %For example if there are 2 values 1.6 and 1.7 then these numbers are 4 and 3 and then there is no 4-th item in the list.
989 %However only positive integer values make practical sense for this diagram.
990 \bool_if:NTF \l__wheelchart_plot_bool
991 {
992 \coordinate ( g__wheelchart_slice_##1_####1_coordinate ) at
993 (
994 $
995 (
996 \__wheelchart_inner_plot:nn
997 {
998 \fp_eval:n
999 {
1000 \l__wheelchart_start_angle_fp + \l__wheelchart_counter_or_clockwise_fp * \l__wheelchart_total_angle_fp *
1001 (
1002 \seq_item:Nn \l__wheelchart_discrete_coefficients_first_seq
1003 { \l__wheelchart_discrete_partitioning_first_index_int }
1004 )
1005 }
1006 }
1007 { \fp_use:N \l__wheelchart_inner_radius_fp }
1008 )
1009 !
1010 {
1011 \seq_item:Nn \l__wheelchart_discrete_coefficients_first_seq
1012 { \l__wheelchart_discrete_partitioning_second_index_int }
1013 }
1014 !
1015 (
1016 \__wheelchart_outer_plot:nn
1017 {
1018 \fp_eval:n
1019 {
1020 \l__wheelchart_start_angle_fp + \l__wheelchart_counter_or_clockwise_fp * \l__wheelchart_total_angle_fp *
1021 (
1022 \seq_item:Nn \l__wheelchart_discrete_coefficients_first_seq
1023 { \l__wheelchart_discrete_partitioning_first_index_int }
1024 )
1025 }
1026 }
1027 { \fp_use:N \l__wheelchart_outer_radius_fp }
1028 )
1029 $
1030 ) ;
1031 }
1032 {
1033 \coordinate ( g__wheelchart_slice_##1_####1_coordinate ) at
1034 (
1035 \fp_eval:n
1036 {
1037 \l__wheelchart_start_angle_fp + \l__wheelchart_counter_or_clockwise_fp * \l__wheelchart_total_angle_fp *
1038 (
1039 \seq_item:Nn \l__wheelchart_discrete_coefficients_first_seq
1040 { \l__wheelchart_discrete_partitioning_first_index_int }
1041 )
1042 }
1043 \c_colon_str
1044 \fp_eval:n
1045 {
1046 \l__wheelchart_inner_radius_fp
1047 + \seq_item:Nn \l__wheelchart_discrete_coefficients_first_seq
1048 { \l__wheelchart_discrete_partitioning_second_index_int }
1049 * ( \l__wheelchart_outer_radius_fp - \l__wheelchart_inner_radius_fp )
1050 }
1051 ) ;
1052 }
1053 \pic [ / wheelchart / slices_style ] at ( g__wheelchart_slice_##1_####1_coordinate )
1054 { code = { \pgfkeysvalueof { / wheelchart / discrete~pic } } } ;
1055 }
1056 \pgfkeysvalueof { / wheelchart / after~slices }
1057 }
1058 }
1059
1060 \cs_new_protected:Npn \__wheelchart_discrete_def_coord:nn #1#2
1061 {
1062 \fp_gset_eq:NN \g__wheelchart_previous_coord_x_fp \g__wheelchart_coord_x_fp
1063 \fp_gset_eq:NN \g__wheelchart_previous_coord_y_fp \g__wheelchart_coord_y_fp
1064 \__wheelchart_def_coord:nnnn
1065 { coord }
1066 {#1}
1067 {}
1068 {
1069 \fp_eval:n
1070 {
1071 \l__wheelchart_start_angle_fp + ( ( #2 ) / ( \l__wheelchart_samples_fp - 1 ) )
1072 * \l__wheelchart_counter_or_clockwise_fp * \l__wheelchart_total_angle_fp
1073 }
1074 }
1075 }
1076
1077 \cs_new_protected:Npn \__wheelchart_for_loop:n #1
1078 {
1079 \__wheelchart_for_loop_initial:n
1080 {
1081 \__wheelchart_def_slice_keys:n
1082 {
1083 \cs_set_eq:Nc \WCpercentage { l__wheelchart_WCpercentage_\WCcount }
1084 \cs_set_eq:Nc \WCpercentagerounded { l__wheelchart_WCpercentagerounded_\WCcount }
1085 \cs_set:Npe \WCdataangle
1086 { \fp_use:c { g__wheelchart_WCdataangle_\WCcount _fp } }
1087 \cs_set:Npe \WCmidangle
1088 { \fp_use:c { g__wheelchart_WCmidangle_\WCcount _fp } }
1089 \pgfkeysvalueof { / wheelchart / for~loop~start }%this must be placed after the definition of macros such as \WCpercentage
1090 %so that these macros can be used in the key for loop start
1091 \begin { scope }
1092 [
1093 shift = { ( \WCmidangle \c_colon_str \fp_use:c { g__wheelchart_explode_\WCcount _fp } ) } ,
1094 / wheelchart / slices_scope
1095 ]
1096 #1
1097 \end { scope }
1098 \pgfkeysvalueof { / wheelchart / for~loop~end }
1099 }
1100 }
1101 }
1102
1103 \cs_new_protected:Npn \__wheelchart_for_loop_initial:n #1
1104 {
1105 \str_case:en { \l__wheelchart_type_tl }
1106 {
1107 { default }
1108 {
1109 \clist_if_empty:NTF \l__wheelchart_header_clist
1110 {
1111 \int_step_inline:nn { \WCtotalcount }
1112 {
1113 \cs_set:Npe \WCcount {##1}
1114 \int_step_inline:nn { \l__wheelchart_max_list_items_int }
1115 { \cs_set_eq:cc { WCvar\int_to_Alph:n {####1} } { l__wheelchart_item_WCvar\int_to_Alph:n {####1}_##1 } }
1116 #1
1117 }
1118 }
1119 {
1120 \int_step_inline:nn { \WCtotalcount }
1121 {
1122 \cs_set:Npe \WCcount {##1}
1123 \int_step_inline:nn { \l__wheelchart_max_list_items_int }
1124 {
1125 \cs_set_eq:cc
1126 { \pgfkeysvalueof { / wheelchart / header~prefix } \clist_item:Nn \l__wheelchart_header_clist {####1} }
1127 {
1128 l__wheelchart_item_\pgfkeysvalueof { / wheelchart / header~prefix }
1129 \clist_item:Nn \l__wheelchart_header_clist {####1}_##1
1130 }
1131 }
1132 #1
1133 }
1134 }
1135 }
1136 { totalcount }
1137 {
1138 \int_step_inline:nn { \WCtotalcount }
1139 {
1140 \cs_set:Npe \WCcount {##1}
1141 #1
1142 }
1143 }
1144 { etoc }
1145 {
1146 \int_step_inline:nn { \WCtotalcount }
1147 {
1148 \cs_set:Npe \WCcount {##1}
1149 \cs_set_eq:Nc \WCetocthelinkedname { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _the_linked_name_##1 }
1150 \cs_set_eq:Nc \WCetocthelinkednumber { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _the_linked_number_##1 }
1151 \cs_set_eq:Nc \WCetocthelinkedpage { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _the_linked_page_##1 }
1152 \cs_set_eq:Nc \WCetocthename { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _the_name_##1 }
1153 \cs_set_eq:Nc \WCetocthenumber { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _the_number_##1 }
1154 \cs_set_eq:Nc \WCetocthepage { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _the_page_##1 }
1155 \cs_set_eq:Nc \WCetocthenumberofpages { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _the_number_of_pages_##1 }
1156 #1
1157 }
1158 }
1159 }
1160 }
1161
1162 \cs_new_protected:Npn \__wheelchart_gdef_count_fp:nn #1#2
1163 {
1164 \fp_gzero_new:c { g__wheelchart_#1_\WCcount _fp }
1165 \pgfmathparse { \pgfkeysvalueof { / wheelchart / #2 } }
1166 \fp_gset:cn { g__wheelchart_#1_\WCcount _fp } { \pgfmathresult }
1167 }
1168
1169 \cs_new_protected:Npn \__wheelchart_if_text:nnn #1#2#3
1170 {
1171 %https://tex.stackexchange.com/questions/42280/expand-away-empty-macros-within-ifthenelse
1172 %https://tex.stackexchange.com/questions/44919/proper-way-to-detect-empty-blank-text
1173 \begin { pgfinterruptpicture }
1174 \DeclareDocumentCommand \\ {#2} {}
1175 %for arc data, \\ is used with seq_set_split so has no optional argument thus then #2 is empty
1176 %otherwise, #2 is o
1177 %no s because an optional star does not apply in a node
1178 %no ! because a space between \\ and its optional argument is allowed in a node
1179 %https://tex.stackexchange.com/questions/459853/savebox-within-tikzpicture-results-in-an-empty-savebox
1180 \hbox_gset:Nn \g__wheelchart_if_text_box { \pgfkeysvalueof { / wheelchart / #1 } }
1181 \end { pgfinterruptpicture }
1182 \dim_compare:nNnT { \box_wd:N \g__wheelchart_if_text_box } > { 0 pt }
1183 { {#3} }
1184 }
1185
1186 \cs_new_protected:Npn \__wheelchart_initial:n #1
1187 {
1188 \str_case:en { \l__wheelchart_type_tl }
1189 {
1190 { default }
1191 {
1192 \tl_if_empty:nTF {#1}
1193 { \cs_set:Npn \WCtotalcount { 0 } }
1194 {
1195 \cs:w seq_set_split:Ne\l__wheelchart_expand_list_tl \cs_end:
1196 \l__wheelchart_list_seq
1197 { \pgfkeysvalueof { / wheelchart / separator~rows } }
1198 {#1}
1199 \cs_set:Npe \WCtotalcount { \seq_count:N \l__wheelchart_list_seq }
1200 \int_zero:N \l__wheelchart_max_list_items_int
1201 \seq_map_indexed_inline:Nn \l__wheelchart_list_seq
1202 {
1203 \cs:w seq_set_split:Ne\l__wheelchart_expand_list_items_tl \cs_end:
1204 \l__wheelchart_list_items_seq
1205 { \pgfkeysvalueof { / wheelchart / separator~columns } }
1206 {##2}
1207 \int_compare:nNnT { \seq_count:N \l__wheelchart_list_items_seq } > { \l__wheelchart_max_list_items_int }
1208 { \int_set:Nn \l__wheelchart_max_list_items_int { \seq_count:N \l__wheelchart_list_items_seq } }
1209 %make sure that the namespace l__wheelchart_item_ below is unique
1210 \clist_if_empty:NTF \l__wheelchart_header_clist
1211 {
1212 \seq_map_indexed_inline:Nn \l__wheelchart_list_items_seq
1213 { \cs_set:cpn { l__wheelchart_item_WCvar\int_to_Alph:n {####1}_##1 } {####2} }
1214 }
1215 {
1216 \seq_map_indexed_inline:Nn \l__wheelchart_list_items_seq
1217 {
1218 \cs_set:cpn
1219 {
1220 l__wheelchart_item_\pgfkeysvalueof { / wheelchart / header~prefix }
1221 \clist_item:Nn \l__wheelchart_header_clist {####1}_##1
1222 }
1223 {####2}
1224 }
1225 }
1226 }
1227 }
1228 }
1229 { totalcount }
1230 {
1231 \cs_set:Npe \WCtotalcount { \fp_use:N \l__wheelchart_total_count_fp }
1232 \cs_set:Npn \WCvarA { 1 }
1233 \cs_set:Npn \WCvarB {}
1234 \cs_set:Npn \WCvarC {}
1235 }
1236 { etoc }
1237 {
1238 \bool_if:NTF \l__wheelchart_etoc_use_name_bool
1239 {
1240 \int_if_exist:cTF { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _count_int }
1241 { \cs_set:Npe \WCtotalcount { \int_use:c { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _count_int } } }
1242 { \cs_set:Npn \WCtotalcount { 0 } }
1243 }
1244 {
1245 \IfPackageLoadedF { etoc }
1246 { \PackageError { wheelchart } { The~package~etoc~must~be~loaded~to~use~the~key~etoc~level } {} }
1247 \etocsetlevel { part } { 0 }
1248 \etocsetlevel { chapter } { 0 }
1249 \etocsetlevel { section } { 0 }
1250 \etocsetlevel { subsection } { 0 }
1251 \etocsetlevel { subsubsection } { 0 }
1252 \etocsetlevel { paragraph } { 0 }
1253 \etocsetlevel { subparagraph } { 0 }
1254 \etocsetlevel { \l__wheelchart_etoc_level_tl } { -1 }%these level changes are local to the current group
1255 \etocsetnexttocdepth { -1 }%only for the next toc
1256 \etocsetstyle { \l__wheelchart_etoc_level_tl } {} {}
1257 {
1258 \int_compare:nNnT { \cs:w g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _count_int \cs_end: } > { 0 }
1259 {
1260 \cs_gset:cpe
1261 {
1262 g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl
1263 _the_number_of_pages_\int_use:c { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _count_int }
1264 }
1265 {
1266 \int_eval:n
1267 {
1268 \etocthepage -
1269 \cs:w
1270 g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl
1271 _the_page_\int_use:c { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _count_int }
1272 \cs_end:
1273 }
1274 }
1275 }
1276 \int_gincr:c { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _count_int }
1277 \cs_gset_eq:cN
1278 {
1279 g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl
1280 _the_linked_name_\int_use:c { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _count_int }
1281 }
1282 \etocthelinkedname
1283 \cs_gset_eq:cN
1284 {
1285 g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl
1286 _the_linked_number_\int_use:c { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _count_int }
1287 }
1288 \etocthelinkednumber
1289 \cs_gset_eq:cN
1290 {
1291 g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl
1292 _the_linked_page_\int_use:c { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _count_int }
1293 }
1294 \etocthelinkedpage
1295 \cs_gset_eq:cN
1296 {
1297 g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl
1298 _the_name_\int_use:c { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _count_int }
1299 }
1300 \etocthename
1301 \cs_gset_eq:cN
1302 {
1303 g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl
1304 _the_number_\int_use:c { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _count_int }
1305 }
1306 \etocthenumber
1307 \cs_gset_eq:cN
1308 {
1309 g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl
1310 _the_page_\int_use:c { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _count_int }
1311 }
1312 \etocthepage
1313 }
1314 {}
1315 \int_gzero_new:c { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _count_int }
1316 \pgfkeysvalueof { / wheelchart / etoc~code }
1317 \int_compare:nNnT { \cs:w g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _count_int \cs_end: } > { 0 }
1318 {
1319 \cs_gset:cpe
1320 {
1321 g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl
1322 _the_number_of_pages_\int_use:c { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _count_int }
1323 }
1324 {
1325 \int_eval:n
1326 {
1327 \l__wheelchart_etoc_count_total_pages_int + 1 -
1328 \cs:w
1329 g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl
1330 _the_page_\int_use:c { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _count_int }
1331 \cs_end:
1332 }
1333 }
1334 }
1335 \cs_set:Npe \WCtotalcount { \int_use:c { g__wheelchart_etoc_item_\l__wheelchart_etoc_name_tl _count_int } }
1336 }
1337 }
1338 }
1339 \cs_set:Npn \WCtotalnum { 0 }
1340 \__wheelchart_for_loop_initial:n
1341 {
1342 \__wheelchart_def_slice_keys:n
1343 { \__wheelchart_gdef_count_fp:nn { value } { value } }
1344 \cs_set:Npe \WCtotalnum { \fp_eval:n { \WCtotalnum + \cs:w g__wheelchart_value_\WCcount _fp \cs_end: } }
1345 }
1346 \int_step_inline:nn { \WCtotalcount }
1347 {
1348 \cs_set:cpe { l__wheelchart_WCpercentage_##1 }
1349 { \fp_eval:n { \cs:w g__wheelchart_value_##1_fp \cs_end: / ( \WCtotalnum / 100 ) } }
1350 \cs_set:cpe { l__wheelchart_WCpercentagerounded_##1 }
1351 { \fp_eval:n { round ( \cs:w l__wheelchart_WCpercentage_##1 \cs_end: , \pgfkeysvalueof { / wheelchart / perc~precision } ) } }
1352 }
1353 }
1354
1355 \cs_new_protected:Npn \__wheelchart_inner_and_wheel_data:n #1
1356 {
1357 \__wheelchart_if_text:nnn { #1~data } { o }
1358 {
1359 \__wheelchart_def_fp:nn { #1_data_angle_pos } { #1~data~angle~pos }
1360 \__wheelchart_def_fp:nn { #1_data_angle_shift } { #1~data~angle~shift }
1361 \__wheelchart_def_fp:nn { #1_data_pos } { #1~data~pos }
1362 \__wheelchart_def_fp:nn { #1_data_sep } { #1~data~sep }
1363 \node [ align = left , / wheelchart / #1_data_style ] at
1364 \cs:w __wheelchart_point_plot_\bool_to_str:N \l__wheelchart_plot_bool :nnnnn \cs_end:
1365 { \WCcount }
1366 { \cs:w l__wheelchart_#1_data_angle_pos_fp \cs_end: }
1367 { \cs:w l__wheelchart_#1_data_angle_shift_fp \cs_end: }
1368 { \cs:w l__wheelchart_#1_data_pos_fp \cs_end: }
1369 { \cs:w l__wheelchart_#1_data_sep_fp \cs_end: }
1370 { \pgfkeysvalueof { / wheelchart / #1~data } } ;
1371 }
1372 }
1373
1374 \cs_new:Npn \__wheelchart_inner_plot:nn #1#2
1375 { {#1} \c_colon_str {#2} }
1376
1377 \cs_new_protected:Npn \__wheelchart_legend_append:nn #1#2
1378 {
1379 \tl_build_put_right:NV \WClegend \l__wheelchart_legend_row_tl%note the V specifier so that \WClegend can also be combined
1380 %with an S column of the package siunitx and so that \WClegend can be used in a tblr environment of the package tabularray
1381 \tl_build_put_right:Nn \WClegend { \protect \setcounter { g__wheelchart_WCcount_counter } }%note the \protect for in case that
1382 %\WClegend would be parsed in a particular way
1383 %note that the counter g__wheelchart_WCcount_counter is defined globally and at the end of the previous \l__wheelchart_legend_row_tl
1384 %so that this value is defined and has the right value at the start of the next \l__wheelchart_legend_row_tl
1385 %if \WClegend is used in a tblr environment of the package tabularray then \UseTblrLibrary{counter} is required
1386 \tl_build_put_right:Ne \WClegend { { \int_eval:n {#1} } }
1387 \tl_build_put_right:Nn \WClegend {#2}
1388 }
1389
1390 \cs_new:Npn \__wheelchart_mod:n #1
1391 {
1392 \int_eval:n
1393 {
1394 \int_mod:nn { (#1) - \int_compare:nNnTF {#1} > { 0 } { 1 } { 0 } } { \g__wheelchart_totalcount_tl }
1395 + \int_compare:nNnTF {#1} > { 0 } { 1 } { \g__wheelchart_totalcount_tl }
1396 }
1397 }
1398
1399 \cs_new:Npn \__wheelchart_outer_plot:nn #1#2
1400 { {#1} \c_colon_str {#2} }
1401
1402 \cs_new:Npn \__wheelchart_point_plot_false:nnnnn #1#2#3#4#5
1403 { ( \__wheelchart_def_angle_plot_false:nnnnn {#1} {#2} {#3} {#4} {#5} \c_colon_str \__wheelchart_def_radius:nnn {#1} {#4} {#5} ) }
1404
1405 \cs_new:Npn \__wheelchart_point_plot_true:nnnnn #1#2#3#4#5
1406 { \__wheelchart_convex_comb_coord_aux:o { \__wheelchart_convex_comb_coord_def:nnnn {#2} {#3} {#4} {#5} } }
1407
1408 \cs_new_protected:Npn \__wheelchart_slices_arc:nnnnnn #1#2#3#4#5#6
1409 {
1410 {
1411 [
1412 / utils / exec =
1413 {
1414 \pgfmathparse {#1}
1415 \fp_set:Nn \l__wheelchart_slices_arc_A_fp { \pgfmathresult }
1416 #6
1417 \fp_set:Nn \l__wheelchart_slices_arc_A_abs_fp { abs ( \l__wheelchart_slices_arc_A_fp ) }
1418 \fp_compare:nNnF { \l__wheelchart_slices_arc_A_abs_fp } < { 0.01 }
1419 {
1420 \pgfmathparse {#2}
1421 \fp_set:Nn \l__wheelchart_slices_arc_B_fp { \pgfmathresult }
1422 \fp_set:Nn \l__wheelchart_slices_arc_rotate_fp
1423 {
1424 atand
1425 (
1426 \cs:w g__wheelchart_#3_y_fp \cs_end: - \cs:w g__wheelchart_#4_y_fp \cs_end: ,
1427 \cs:w g__wheelchart_#3_x_fp \cs_end: - \cs:w g__wheelchart_#4_x_fp \cs_end:
1428 )
1429 }
1430 \fp_set:Nn \l__wheelchart_slices_arc_coord_fp
1431 {
1432 \l__wheelchart_slices_arc_A_fp < 0 && \l__wheelchart_slices_arc_B_fp < 0
1433 ?
1434 0
1435 :
1436 \l__wheelchart_slices_arc_B_fp
1437 }
1438 \fp_set:Nn \l__wheelchart_slices_arc_angle_fp
1439 {
1440 \l__wheelchart_slices_arc_A_fp < 0 && \l__wheelchart_slices_arc_B_fp < 0
1441 ?
1442 acosd
1443 (
1444 2 /
1445 (
1446 ( min ( \l__wheelchart_slices_arc_B_fp , 0 ) - 1 )
1447 * ( ( 1 / \l__wheelchart_slices_arc_A_fp ) + \l__wheelchart_slices_arc_A_fp )
1448 )
1449 )
1450 :
1451 atand ( ( \l__wheelchart_slices_arc_A_fp - ( 1 / \l__wheelchart_slices_arc_A_fp ) ) / 2 )
1452 }%note the min ( \l__wheelchart_slices_arc_B_fp , 0 ) so that the acosd is always defined
1453 }
1454 }
1455 ]
1456 \fp_compare:nNnTF { \l__wheelchart_slices_arc_A_abs_fp } < { 0.01 }
1457 {#5}
1458 {
1459 \fp_compare:nNnT { \l__wheelchart_slices_arc_B_fp } < { 1 }
1460 {
1461 \fp_compare:nNnF { \l__wheelchart_slices_arc_coord_fp } = { 0 }
1462 {
1463 --
1464 (
1465 $
1466 ( g__wheelchart_slice_\WCcount _#3_coordinate )
1467 ! { \fp_eval:n { \l__wheelchart_slices_arc_coord_fp / 2 } } !
1468 ( g__wheelchart_slice_\WCcount _#4_coordinate )
1469 $
1470 )
1471 }
1472 arc
1473 [
1474 start~angle =
1475 {
1476 \fp_eval:n
1477 {
1478 \l__wheelchart_slices_arc_rotate_fp
1479 - \g__wheelchart_slices_orientation_fp * \l__wheelchart_slices_arc_angle_fp
1480 }
1481 } ,
1482 end~angle =
1483 {
1484 \fp_eval:n
1485 {
1486 \l__wheelchart_slices_arc_rotate_fp + \g__wheelchart_slices_orientation_fp *
1487 ( sign ( \l__wheelchart_slices_arc_A_fp ) * 180 + \l__wheelchart_slices_arc_angle_fp )
1488 }
1489 } ,
1490 radius =
1491 {
1492 \fp_eval:n
1493 {
1494 0.25 * ( 1 - \l__wheelchart_slices_arc_B_fp )
1495 * abs ( ( 1 / \l__wheelchart_slices_arc_A_fp ) + \l__wheelchart_slices_arc_A_fp )
1496 * sqrt
1497 (
1498 ( \cs:w g__wheelchart_#3_x_fp \cs_end: - \cs:w g__wheelchart_#4_x_fp \cs_end: ) ^ 2
1499 + ( \cs:w g__wheelchart_#3_y_fp \cs_end: - \cs:w g__wheelchart_#4_y_fp \cs_end: ) ^ 2
1500 )
1501 }
1502 }
1503 ]
1504 }
1505 \fp_compare:nNnF { \l__wheelchart_slices_arc_coord_fp } = { 0 }
1506 {#5}
1507 }
1508 }
1509 }
1510
1511 \cs_new_protected:Npn \__wheelchart_slices_arrow:nnnnn #1#2#3#4#5
1512 {
1513 {
1514 [
1515 / utils / exec =
1516 {
1517 \pgfmathparse {#1}
1518 \fp_set:Nn \l__wheelchart_slices_arrow_A_fp { \pgfmathresult }
1519 \fp_compare:nNnF { \l__wheelchart_slices_arrow_A_fp } = { 0 }
1520 {
1521 \pgfmathparse {#2}
1522 \fp_set:Nn \l__wheelchart_slices_arrow_B_fp { \pgfmathresult }
1523 \fp_set:Nn \l__wheelchart_slices_arrow_coord_fp
1524 {
1525 \l__wheelchart_slices_arrow_A_fp < 0 && \l__wheelchart_slices_arrow_B_fp < 0 ? 0 : \l__wheelchart_slices_arrow_B_fp
1526 }
1527 }
1528 }
1529 ]
1530 \fp_compare:nNnTF { \l__wheelchart_slices_arrow_A_fp } = { 0 }
1531 {#5}
1532 {
1533 \fp_compare:nNnT { \l__wheelchart_slices_arrow_B_fp } < { 1 }
1534 {
1535 \fp_compare:nNnF { \l__wheelchart_slices_arrow_coord_fp } = { 0 }
1536 {
1537 --
1538 (
1539 $
1540 ( g__wheelchart_slice_\WCcount _#3_coordinate )
1541 ! { \fp_eval:n { \l__wheelchart_slices_arrow_coord_fp / 2 } } !
1542 ( g__wheelchart_slice_\WCcount _#4_coordinate )
1543 $
1544 )
1545 }
1546 --
1547 (
1548 \fp_eval:n
1549 {
1550 (
1551 \cs:w g__wheelchart_#3_x_fp \cs_end: + \cs:w g__wheelchart_#4_x_fp \cs_end: +
1552 (
1553 \g__wheelchart_slices_orientation_fp * ( \l__wheelchart_slices_arrow_coord_fp - 1 )
1554 * \l__wheelchart_slices_arrow_A_fp
1555 * ( \cs:w g__wheelchart_#3_y_fp \cs_end: - \cs:w g__wheelchart_#4_y_fp \cs_end: )
1556 )
1557 )
1558 / 2
1559 }
1560 ,
1561 \fp_eval:n
1562 {
1563 (
1564 \cs:w g__wheelchart_#3_y_fp \cs_end: + \cs:w g__wheelchart_#4_y_fp \cs_end: +
1565 (
1566 \g__wheelchart_slices_orientation_fp * ( \l__wheelchart_slices_arrow_coord_fp - 1 )
1567 * \l__wheelchart_slices_arrow_A_fp
1568 * ( \cs:w g__wheelchart_#4_x_fp \cs_end: - \cs:w g__wheelchart_#3_x_fp \cs_end: )
1569 )
1570 )
1571 / 2
1572 }
1573 )
1574 \fp_compare:nNnF { \l__wheelchart_slices_arrow_coord_fp } = { 0 }
1575 {
1576 --
1577 (
1578 $
1579 ( g__wheelchart_slice_\WCcount _#4_coordinate )
1580 ! { \fp_eval:n { \l__wheelchart_slices_arrow_coord_fp / 2 } } !
1581 ( g__wheelchart_slice_\WCcount _#3_coordinate )
1582 $
1583 )
1584 }
1585 }
1586 #5
1587 }
1588 }
1589 }
1590
1591 \cs_new:Npn \__wheelchart_slices_to:nn #1#2
1592 {
1593 to
1594 [
1595 out = { \fp_eval:n { - \g__wheelchart_slices_orientation_fp * sign ( \l__wheelchart_coord_determinant_fp ) * (#1) } } ,
1596 in = { \fp_eval:n { \g__wheelchart_slices_orientation_fp * sign ( \l__wheelchart_coord_determinant_fp ) * ( (#2) - 180 ) } } ,
1597 relative
1598 ]
1599 }
1600
1601 \cs_new:Npn \__wheelchart_wheel_lines_aux:nn #1#2
1602 {
1603 \fp_eval:n
1604 {
1605 ( 1 - (#1) / max ( round ( \cs:w g__wheelchart_value_\WCcount _fp \cs_end: ) , 1 ) )
1606 * \cs:w g__wheelchart_slice_#2_start_angle_\WCcount _fp \cs_end:
1607 + (#1) * \cs:w g__wheelchart_slice_#2_end_angle_\WCcount _fp \cs_end:
1608 / max ( round ( \cs:w g__wheelchart_value_\WCcount _fp \cs_end: ) , 1 )
1609 }
1610 }
1611
1612 \AtBeginDocument { \IfPackageLoadedT { tabularray } { \SetTblrOuter { expand+ = \WClegend } } }
1613
1614 %%> \subsection{Pgfkeys}
1615
1616 \pgfkeys
1617 {
1618 / wheelchart /. is~family ,
1619 / wheelchart ,
1620 after~slices /. initial = {} ,
1621 anchor~xsep /. initial = 5 ,
1622 anchor~ysep /. initial = 5 ,
1623 arc /. style =
1624 {
1625 bool_set_true = \l__wheelchart_arc_bool ,
1626 arc_style /. style = {#1}
1627 } ,
1628 arc_style /. style = {} ,
1629 arc~around~line /. initial = 1 ,
1630 arc~around~text /. default = true ,%this key is not set up with /.is choice or \bool_set:Nn
1631 %so that for example \WCvarA can be used as value for this key
1632 arc~around~text /. initial = false ,
1633 arc~data /. initial = {} ,
1634 arc~data~align /. code = { \tl_set:Nn \l__wheelchart_arc_data_align_tl {#1} } ,%this key is not set up with /.is choice
1635 %so that for example \WCvarA can be used as value for this key
1636 arc~data~align = center ,
1637 arc~data~angle~pos /. initial = 0.5 ,
1638 arc~data~angle~shift /. initial = 0 ,
1639 arc~data~dir /. initial = 1 ,
1640 arc~data~expand /. initial = n ,
1641 arc~data~line~sep~factor /. initial = 1 ,
1642 arc~data~lines~pos /. initial = 0.5 ,
1643 arc~data~lines~shift /. initial = 0 ,
1644 arc~data~pos /. initial = 1 ,
1645 arc~data~sep /. initial = 1 ex / 1 cm ,
1646 arc~data~style /. style = { arc_data_style /. style = {#1} } ,
1647 arc_data_style /. style = {} ,
1648 arc~first~half /. style = { arc_first_half /. style = {#1} } ,
1649 arc_first_half /. style = {} ,
1650 arc~pos /. initial = 1 ,
1651 arc~second~half /. style = { arc_second_half /. style = {#1} } ,
1652 arc_second_half /. style = {} ,
1653 arc~sep /. initial = 1 ex / 1 cm ,
1654 at /. initial = { ( 0 , 0 ) } ,
1655 before~slices /. initial = {} ,
1656 bool_set_true /. code = \bool_set_true:N #1 ,
1657 caption /. initial = {} ,
1658 caption~left /. initial = {} ,
1659 caption~left~sep /. initial = 0.5 ,
1660 caption~left~style /. style = { caption~left_style /. style = {#1} } ,
1661 caption~left_style /. style = {} ,
1662 caption~sep /. initial = 0.5 ,
1663 caption~style /. style = { caption_style /. style = {#1} } ,
1664 caption_style /. style = {} ,
1665 contour /. style =
1666 {
1667 bool_set_true = \l__wheelchart_contour_bool ,
1668 contour_style /. style = {#1}
1669 } ,
1670 contour_style /. style = {} ,
1671 counterclockwise /. is~choice ,
1672 counterclockwise / false /. code = { \fp_set:Nn \l__wheelchart_counter_or_clockwise_fp { -1 } } ,
1673 counterclockwise / false /. value~forbidden ,
1674 counterclockwise / true /. code = { \fp_set:Nn \l__wheelchart_counter_or_clockwise_fp { 1 } } ,
1675 counterclockwise / true /. value~forbidden ,
1676 counterclockwise /. default = true ,
1677 counterclockwise = false ,
1678 data /. initial = { \WCvarC } ,
1679 data~angle~pos /. initial = 0.5 ,
1680 data~angle~shift /. initial = 0 ,
1681 data~pos /. initial = 1 ,
1682 data~sep /. initial = 0.2 ,
1683 data~style /. style = { data_style /. style = {#1} } ,
1684 data_style /. style = {} ,
1685 discrete /. is~choice ,
1686 discrete / false /. code = \bool_set_false:N \l__wheelchart_discrete_bool ,
1687 discrete / false /. value~forbidden ,
1688 discrete / true /. code = \bool_set_true:N \l__wheelchart_discrete_bool ,
1689 discrete / true /. value~forbidden ,
1690 discrete /. default = true ,
1691 discrete = false ,
1692 discrete~factor /. initial = 1 ,
1693 discrete~partitioning /. initial = radius ,
1694 discrete~pic /. initial = {} ,
1695 discrete~sort /. is~choice ,
1696 discrete~sort / angle /. code = { \int_set:Nn \l__wheelchart_discrete_sort_int { 1 } } ,
1697 discrete~sort / angle /. value~forbidden ,
1698 discrete~sort / radius /. code = { \int_set:Nn \l__wheelchart_discrete_sort_int { 2 } } ,
1699 discrete~sort / radius /. value~forbidden ,
1700 discrete~sort = angle ,
1701 discrete~space~at~borders /. is~choice ,%this key is not set up with /.is if because an initial value is unwanted for this key
1702 discrete~space~at~borders / false /. code = { \int_set:Nn \l__wheelchart_discrete_space_at_borders_int { 1 } } ,
1703 discrete~space~at~borders / false /. value~forbidden ,
1704 discrete~space~at~borders / true /. code = { \int_set:Nn \l__wheelchart_discrete_space_at_borders_int { 0 } } ,
1705 discrete~space~at~borders / true /. value~forbidden ,
1706 discrete~space~at~borders /. default = true ,
1707 domain /. style~args /. expanded = { ##1 \c_colon_str ##2 }
1708 {
1709 counterclockwise ,
1710 start~angle = {##1} ,
1711 total~angle = { (##2) - (##1) }
1712 } ,
1713 etoc~code /. initial = { \tableofcontents } ,
1714 etoc~count~total~pages /. code = { \int_set:Nn \l__wheelchart_etoc_count_total_pages_int {#1} } ,
1715 etoc~level /. code =
1716 {
1717 \tl_set:Nn \l__wheelchart_type_tl { etoc }
1718 \tl_set:Nn \l__wheelchart_etoc_level_tl {#1}
1719 } ,
1720 etoc~name /. code = { \tl_set:Nn \l__wheelchart_etoc_name_tl {#1} } ,
1721 etoc~name = {} ,
1722 etoc~use~name /. code =
1723 {
1724 \tl_set:Nn \l__wheelchart_etoc_name_tl {#1}
1725 \tl_set:Nn \l__wheelchart_type_tl { etoc }
1726 \bool_set_true:N \l__wheelchart_etoc_use_name_bool
1727 } ,
1728 expand~list /. is~choice ,
1729 expand~list / false /. code = { \tl_set:Nn \l__wheelchart_expand_list_tl { n } } ,
1730 expand~list / false /. value~forbidden ,
1731 expand~list / once /. code = { \tl_set:Nn \l__wheelchart_expand_list_tl { o } } ,
1732 expand~list / once /. value~forbidden ,
1733 expand~list / true /. code = { \tl_set:Nn \l__wheelchart_expand_list_tl { e } } ,
1734 expand~list / true /. value~forbidden ,
1735 expand~list = once ,
1736 expand~list~items /. is~choice ,
1737 expand~list~items / false /. code = { \tl_set:Nn \l__wheelchart_expand_list_items_tl { n } } ,
1738 expand~list~items / false /. value~forbidden ,
1739 expand~list~items / once /. code = { \tl_set:Nn \l__wheelchart_expand_list_items_tl { o } } ,
1740 expand~list~items / once /. value~forbidden ,
1741 expand~list~items / true /. code = { \tl_set:Nn \l__wheelchart_expand_list_items_tl { e } } ,
1742 expand~list~items / true /. value~forbidden ,
1743 expand~list~items = false ,
1744 explode /. initial = 0 ,
1745 explode /. default = 0.2 ,
1746 for~loop~end /. initial = {} ,
1747 for~loop~start /. initial = {} ,
1748 gap /. initial = 0 ,
1749 gap /. default = 0.05 ,
1750 gap~max~angle /. initial = 180 ,
1751 gap~polar /. initial = 0 ,
1752 gap~polar /. default = 1 ,
1753 gap~radius /. initial = 0 ,
1754 gap~radius /. default = 0.05 ,%the same default value as for gap
1755 header /. code = { \clist_set:Nn \l__wheelchart_header_clist {#1} } ,
1756 header~prefix /. initial = WC ,
1757 inner~data /. initial = {} ,
1758 inner~data~angle~pos /. initial = 0.5 ,
1759 inner~data~angle~shift /. initial = 0 ,
1760 inner~data~pos /. initial = 0 ,
1761 inner~data~sep /. initial = 0.2 ,
1762 inner~data~style /. style = { inner_data_style /. style = {#1} } ,
1763 inner_data_style /. style = {} ,
1764 inner~plot /. style =
1765 {
1766 bool_set_true = \l__wheelchart_plot_bool ,
1767 / utils / exec = { \cs_set:Npn \__wheelchart_inner_plot:nn ##1##2 {#1} } ,
1768 slices~inner =
1769 {
1770 -- plot
1771 [
1772 domain =
1773 \fp_use:c { g__wheelchart_slice_inner_end_angle_\WCcount _fp }
1774 \c_colon_str
1775 \fp_use:c { g__wheelchart_slice_inner_start_angle_\WCcount _fp } ,
1776 samples = \fp_use:c { g__wheelchart_samples_\WCcount _fp } ,
1777 variable = \l__wheelchart_inner_plot_variable_tl ,
1778 / wheelchart / inner_plot_style
1779 ]
1780 (
1781 \__wheelchart_inner_plot:nn
1782 { \l__wheelchart_inner_plot_variable_tl }
1783 { \fp_use:c { g__wheelchart_inner_radius_\WCcount _fp } }
1784 )
1785 }
1786 } ,
1787 inner~plot~style /. style = { inner_plot_style /. style = {#1} } ,
1788 inner_plot_style /. style = {} ,
1789 inner~radius /. initial = 2 ,
1790 legend /. initial = {} ,
1791 legend~columns /. initial = 1 ,
1792 legend~entry /. initial = {} ,
1793 legend~only /. code = \bool_set:Nn \l__wheelchart_legend_only_bool { \cs:w c_#1_bool \cs_end: } ,
1794 legend~only /. default = true ,
1795 legend~only = false ,
1796 legend~row /. code =
1797 {
1798 \bool_set_true:N \l__wheelchart_legend_row_bool
1799 \tl_set:Nn \l__wheelchart_legend_row_tl {#1}
1800 } ,
1801 lines /. initial = 0 ,
1802 lines /. default = 1 ,
1803 lines~angle~pos /. initial = 0.5 ,
1804 lines~angle~shift /. initial = 0 ,
1805 lines~ext /. initial = 0 ,
1806 lines~ext /. default = 0.5 ,
1807 lines~ext~bottom~dir /. code = { \int_set_eq:Nc \l__wheelchart_lines_ext_bottom_dir_int { c__wheelchart_lines_ext_dir_#1_int } } ,
1808 lines~ext~bottom~dir = right ,
1809 lines~ext~dir /. code =
1810 {
1811 \bool_set_true:N \l__wheelchart_lines_ext_dir_bool
1812 \int_set_eq:Nc \l__wheelchart_lines_ext_dir_int { c__wheelchart_lines_ext_dir_#1_int }
1813 } ,
1814 lines~ext~dirsep /. initial = 0 ,
1815 lines~ext~fixed /. default = true ,%this key is not set up with /.is choice or \bool_set:Nn
1816 %so that for example \WCvarA can be used as value for this key
1817 lines~ext~fixed /. initial = false ,
1818 lines~ext~fixed~left /. initial =
1819 {
1820 \fp_eval:n
1821 {
1822 \l__wheelchart_lines_ext_dir_int *
1823 (
1824 \cs:w g__wheelchart_outer_radius_\WCcount _fp \cs_end: + \l__wheelchart_lines_sep_fp
1825 + \l__wheelchart_lines_fp + \l__wheelchart_lines_ext_fp
1826 )
1827 }
1828 } ,
1829 lines~ext~fixed~right /. initial =
1830 {
1831 \fp_eval:n
1832 {
1833 \l__wheelchart_lines_ext_dir_int *
1834 (
1835 \cs:w g__wheelchart_outer_radius_\WCcount _fp \cs_end: + \l__wheelchart_lines_sep_fp
1836 + \l__wheelchart_lines_fp + \l__wheelchart_lines_ext_fp
1837 )
1838 }
1839 } ,
1840 lines~ext~left~anchor /. initial = mid~east ,
1841 lines~ext~right~anchor /. initial = mid~west ,
1842 lines~ext~top~dir /. code = { \int_set_eq:Nc \l__wheelchart_lines_ext_top_dir_int { c__wheelchart_lines_ext_dir_#1_int } } ,
1843 lines~ext~top~dir = right ,
1844 lines~pos /. initial = 1 ,
1845 lines~sep /. initial = 0.2 ,
1846 lines~style /. style = { lines_style /. style = {#1} } ,
1847 lines_style /. style = {} ,
1848 middle /. initial = {} ,
1849 middle~fill /. style =
1850 {
1851 bool_set_true = \l__wheelchart_middle_fill_bool ,
1852 middle_fill /. style = {#1}
1853 } ,
1854 middle_fill /. style = {} ,
1855 middle~style /. style = { middle_style /. style = {#1} } ,
1856 middle_style /. style = {} ,
1857 name /. code = { \tl_gset:Ne \g__wheelchart_name_tl {#1} } ,
1858 name = wheelchart@name ,
1859 outer~plot /. style =
1860 {
1861 bool_set_true = \l__wheelchart_plot_bool ,
1862 / utils / exec = { \cs_set:Npn \__wheelchart_outer_plot:nn ##1##2 {#1} } ,
1863 slices~outer =
1864 {
1865 -- plot
1866 [
1867 domain =
1868 \fp_use:c { g__wheelchart_slice_outer_start_angle_\WCcount _fp }
1869 \c_colon_str
1870 \fp_use:c { g__wheelchart_slice_outer_end_angle_\WCcount _fp } ,
1871 samples = \fp_use:c { g__wheelchart_samples_\WCcount _fp } ,
1872 variable = \l__wheelchart_outer_plot_variable_tl ,
1873 / wheelchart / outer_plot_style
1874 ]
1875 (
1876 \__wheelchart_outer_plot:nn
1877 { \l__wheelchart_outer_plot_variable_tl }
1878 { \fp_use:c { g__wheelchart_outer_radius_\WCcount _fp } }
1879 )
1880 }
1881 } ,
1882 outer~plot~style /. style = { outer_plot_style /. style = {#1} } ,
1883 outer_plot_style /. style = {} ,
1884 outer~radius /. initial = 3 ,
1885 perc~precision /. initial = 0 ,
1886 pie /. code = \bool_set:Nn \l__wheelchart_pie_bool { \cs:w c_#1_bool \cs_end: } ,
1887 pie /. default = true ,
1888 pie = false ,
1889 plot /. style =
1890 {
1891 inner~plot = {#1} ,
1892 outer~plot = {#1}
1893 } ,
1894 plot~style /. style =
1895 {
1896 inner~plot~style = {#1} ,
1897 outer~plot~style = {#1}
1898 } ,
1899 radius /. style~2~args =
1900 {
1901 inner~radius = {#1} ,
1902 outer~radius = {#2}
1903 } ,
1904 samples /. initial = 25 ,%the same number as /tikz/samples
1905 separator~columns /. initial = / ,
1906 separator~rows /. initial = { , } ,
1907 slice_final /. style = { slice_final_style /. style = {#1} } ,
1908 slice_final_style /. style = {} ,
1909 slices /. code =
1910 {
1911 \bool_set_true:N \l__wheelchart_slices_bool
1912 \tl_set:Nn \l__wheelchart_slices_tl {#1}
1913 } ,
1914 slices~angle~pos /. initial = 0.5 ,
1915 slices~angle~shift /. initial = 0 ,
1916 slices~arc /. style~2~args =
1917 {
1918 slices~start~arc = { - (#1) } {#2} ,
1919 slices~end~arc = {#1} {#2}
1920 } ,
1921 slices~arc~inner~end /. is~choice ,
1922 slices~arc~inner~end / false /. style = {} ,
1923 slices~arc~inner~end / false /. value~forbidden ,
1924 slices~arc~inner~end / true /. style =
1925 { slices~arc~match = { inner } { 1 } { -1 } { 1 } { inner~end } { inner~start } { outer~end } } ,
1926 slices~arc~inner~end / true /. value~forbidden ,
1927 slices~arc~inner~end /. initial = false ,
1928 slices~arc~inner~end /. default = true ,
1929 slices~arc~inner~end~start /. is~choice ,
1930 slices~arc~inner~end~start / false /. style = {} ,
1931 slices~arc~inner~end~start / false /. value~forbidden ,
1932 slices~arc~inner~end~start / true /. style =
1933 { slices~arc~match = { inner } { 1 } { 1 } { 1 } { inner~end } { inner~start } { outer~end } } ,
1934 slices~arc~inner~end~start / true /. value~forbidden ,
1935 slices~arc~inner~end~start /. initial = false ,
1936 slices~arc~inner~end~start /. default = true ,
1937 slices~arc~inner~start /. is~choice ,
1938 slices~arc~inner~start / false /. style = {} ,
1939 slices~arc~inner~start / false /. value~forbidden ,
1940 slices~arc~inner~start / true /. style =
1941 { slices~arc~match = { inner } { 1 } { -1 } { -1 } { inner~start } { inner~end } { outer~start } } ,
1942 slices~arc~inner~start / true /. value~forbidden ,
1943 slices~arc~inner~start /. initial = false ,
1944 slices~arc~inner~start /. default = true ,
1945 slices~arc~inner~start~end /. is~choice ,
1946 slices~arc~inner~start~end / false /. style = {} ,
1947 slices~arc~inner~start~end / false /. value~forbidden ,
1948 slices~arc~inner~start~end / true /. style =
1949 { slices~arc~match = { inner } { -1 } { -1 } { -1 } { inner~start } { inner~end } { outer~start } } ,
1950 slices~arc~inner~start~end / true /. value~forbidden ,
1951 slices~arc~inner~start~end /. initial = false ,
1952 slices~arc~inner~start~end /. default = true ,
1953 slices~arc~match /. style~n~args = { 7 }
1954 {
1955 slices~end~arc = { (#2) * tan ( \__wheelchart_diff_atan:nnnn {#7} {#6} {#5} {#6} / 2 ) } { 0 } ,
1956 slices~start~arc = { (#3) * tan ( \__wheelchart_diff_atan:nnnn {#7} {#6} {#5} {#6} / 2 ) } { 0 } ,
1957 slices~#1~arc = { (#4) * tan ( \__wheelchart_diff_atan:nnnn {#5} {#7} {#6} {#7} / 2 ) } { 0 }
1958 } ,
1959 slices~arc~outer~end /. is~choice ,
1960 slices~arc~outer~end / false /. style = {} ,
1961 slices~arc~outer~end / false /. value~forbidden ,
1962 slices~arc~outer~end / true /. style =
1963 { slices~arc~match = { outer } { -1 } { 1 } { -1 } { outer~end } { outer~start } { inner~end } } ,
1964 slices~arc~outer~end / true /. value~forbidden ,
1965 slices~arc~outer~end /. initial = false ,
1966 slices~arc~outer~end /. default = true ,
1967 slices~arc~outer~end~start /. is~choice ,
1968 slices~arc~outer~end~start / false /. style = {} ,
1969 slices~arc~outer~end~start / false /. value~forbidden ,
1970 slices~arc~outer~end~start / true /. style =
1971 { slices~arc~match = { outer } { -1 } { -1 } { -1 } { outer~end } { outer~start } { inner~end } } ,
1972 slices~arc~outer~end~start / true /. value~forbidden ,
1973 slices~arc~outer~end~start /. initial = false ,
1974 slices~arc~outer~end~start /. default = true ,
1975 slices~arc~outer~start /. is~choice ,
1976 slices~arc~outer~start / false /. style = {} ,
1977 slices~arc~outer~start / false /. value~forbidden ,
1978 slices~arc~outer~start / true /. style =
1979 { slices~arc~match = { outer } { -1 } { 1 } { 1 } { outer~start } { outer~end } { inner~start } } ,
1980 slices~arc~outer~start / true /. value~forbidden ,
1981 slices~arc~outer~start /. initial = false ,
1982 slices~arc~outer~start /. default = true ,
1983 slices~arc~outer~start~end /. is~choice ,
1984 slices~arc~outer~start~end / false /. style = {} ,
1985 slices~arc~outer~start~end / false /. value~forbidden ,
1986 slices~arc~outer~start~end / true /. style =
1987 { slices~arc~match = { outer } { 1 } { 1 } { 1 } { outer~start } { outer~end } { inner~start } } ,
1988 slices~arc~outer~start~end / true /. value~forbidden ,
1989 slices~arc~outer~start~end /. initial = false ,
1990 slices~arc~outer~start~end /. default = true ,
1991 slices~Arrow /. style =
1992 {
1993 slices~end =
1994 {
1995 -- ( \WCpoint { 1 } {#1} { 0.5 } { 0 } )
1996 -- ( \WCpoint { 1 } { 0 } { 0 } { 0 } )
1997 } ,
1998 slices~start =
1999 {
2000 -- ( \WCpoint { 0 } {#1} { 0.5 } { 0 } )
2001 -- cycle
2002 }
2003 } ,
2004 slices~arrow /. style~2~args =
2005 {
2006 slices~start~arrow = { - (#1) } {#2} ,
2007 slices~end~arrow = {#1} {#2}
2008 } ,
2009 slices~end /. initial = { -- ( g__wheelchart_slice_\WCcount _inner~end_coordinate ) } ,
2010 slices~end~arc /. style~2~args =
2011 {
2012 slices~end =
2013 {
2014 \__wheelchart_slices_arc:nnnnnn
2015 {#1}
2016 {#2}
2017 { outer~end }
2018 { inner~end }
2019 { -- ( g__wheelchart_slice_\WCcount _inner~end_coordinate ) }
2020 {}
2021 }
2022 } ,
2023 slices~end~arrow /. style~2~args =
2024 {
2025 slices~end =
2026 {
2027 \__wheelchart_slices_arrow:nnnnn
2028 {#1}
2029 {#2}
2030 { outer~end }
2031 { inner~end }
2032 { -- ( g__wheelchart_slice_\WCcount _inner~end_coordinate ) }
2033 }
2034 } ,
2035 slices~end~to /. style~2~args =
2036 {
2037 slices~end =
2038 {
2039 \__wheelchart_slices_to:nn {#2} {#1}
2040 ( g__wheelchart_slice_\WCcount _inner~end_coordinate )
2041 }
2042 } ,
2043 slices~inner /. initial =
2044 {
2045 \fp_compare:nNnT { \cs:w g__wheelchart_inner_radius_\WCcount _fp \cs_end: } > { 0 }
2046 {
2047 \fp_compare:nNnT
2048 { \cs:w g__wheelchart_inner_gap_\WCcount _fp \cs_end: }
2049 <
2050 { \cs:w g__wheelchart_abs_half_angle_minus_new_angle_\WCcount _fp \cs_end: }
2051 {
2052 arc
2053 [
2054 start~angle = \fp_use:c { g__wheelchart_slice_inner_end_angle_\WCcount _fp } ,
2055 end~angle = \fp_use:c { g__wheelchart_slice_inner_start_angle_\WCcount _fp } ,
2056 radius = \fp_use:c { g__wheelchart_inner_radius_\WCcount _fp }
2057 ]
2058 }
2059 }
2060 } ,
2061 slices~inner~angle~reduce /. style =
2062 {
2063 slices~inner~end~angle~shift = { - (#1) } ,
2064 slices~inner~start~angle~shift = {#1}
2065 } ,
2066 slices~inner~angle~shift /. style =
2067 {
2068 slices~inner~end~angle~shift = {#1} ,
2069 slices~inner~start~angle~shift = {#1}
2070 } ,
2071 slices~inner~arc /. style~2~args =
2072 {
2073 slices~inner =
2074 {
2075 \__wheelchart_slices_arc:nnnnnn
2076 {#1}
2077 {#2}
2078 { inner~end }
2079 { inner~start }
2080 { -- ( g__wheelchart_slice_\WCcount _inner~start_coordinate ) }
2081 {}
2082 }
2083 } ,
2084 slices~inner~arc~tangent /. is~choice ,
2085 slices~inner~arc~tangent / false /. code = {} ,
2086 slices~inner~arc~tangent / false /. value~forbidden ,
2087 slices~inner~arc~tangent / true /. style =
2088 {
2089 slices~inner =
2090 {
2091 \__wheelchart_slices_arc:nnnnnn
2092 { \__wheelchart_diff_atan:nnnn { outer~start } { inner~start } { outer~end } { inner~end } }
2093 { 0 }
2094 { inner~end }
2095 { inner~start }
2096 { -- ( g__wheelchart_slice_\WCcount _inner~start_coordinate ) }
2097 {
2098 \fp_compare:nNnTF { \l__wheelchart_slices_arc_A_fp } > { 359.99 }
2099 { \fp_set:Nn \l__wheelchart_slices_arc_A_fp { 1 } }
2100 { \fp_set:Nn \l__wheelchart_slices_arc_A_fp { tand ( 45 - \l__wheelchart_slices_arc_A_fp / 4 ) } }
2101 }
2102 }
2103 } ,
2104 slices~inner~arc~tangent / true /. value~forbidden ,
2105 slices~inner~arc~tangent /. initial = false ,
2106 slices~inner~arc~tangent /. default = true ,
2107 slices~inner~arrow /. style~2~args =
2108 {
2109 slices~inner =
2110 {
2111 \__wheelchart_slices_arrow:nnnnn
2112 {#1}
2113 {#2}
2114 { inner~end }
2115 { inner~start }
2116 { -- ( g__wheelchart_slice_\WCcount _inner~start_coordinate ) }
2117 }
2118 } ,
2119 slices~inner~end~angle~shift /. initial = 0 ,
2120 slices~inner~start~angle~shift /. initial = 0 ,
2121 slices~inner~to /. style~2~args =
2122 {
2123 slices~inner =
2124 {
2125 \__wheelchart_slices_to:nn {#2} {#1}
2126 ( g__wheelchart_slice_\WCcount _inner~start_coordinate )
2127 }
2128 } ,
2129 slices~outer /. initial =
2130 {
2131 arc
2132 [
2133 start~angle = \fp_use:c { g__wheelchart_slice_outer_start_angle_\WCcount _fp } ,
2134 end~angle = \fp_use:c { g__wheelchart_slice_outer_end_angle_\WCcount _fp } ,
2135 radius = \fp_use:c { g__wheelchart_outer_radius_\WCcount _fp }
2136 ]
2137 } ,
2138 slices~outer~angle~reduce /. style =
2139 {
2140 slices~outer~end~angle~shift = { - (#1) } ,
2141 slices~outer~start~angle~shift = {#1}
2142 } ,
2143 slices~outer~angle~shift /. style =
2144 {
2145 slices~outer~end~angle~shift = {#1} ,
2146 slices~outer~start~angle~shift = {#1}
2147 } ,
2148 slices~outer~arc /. style~2~args =
2149 {
2150 slices~outer =
2151 {
2152 \__wheelchart_slices_arc:nnnnnn
2153 {#1}
2154 {#2}
2155 { outer~start }
2156 { outer~end }
2157 { -- ( g__wheelchart_slice_\WCcount _outer~end_coordinate ) }
2158 {}
2159 }
2160 } ,
2161 slices~outer~arc~tangent /. is~choice ,
2162 slices~outer~arc~tangent / false /. code = {} ,
2163 slices~outer~arc~tangent / false /. value~forbidden ,
2164 slices~outer~arc~tangent / true /. style =
2165 {
2166 slices~outer =
2167 {
2168 \__wheelchart_slices_arc:nnnnnn
2169 { \__wheelchart_diff_atan:nnnn { outer~start } { inner~start } { outer~end } { inner~end } }
2170 { 0 }
2171 { outer~start }
2172 { outer~end }
2173 { -- ( g__wheelchart_slice_\WCcount _outer~end_coordinate ) }
2174 {
2175 \fp_compare:nNnTF { \l__wheelchart_slices_arc_A_fp } > { 359.99 }
2176 { \fp_set:Nn \l__wheelchart_slices_arc_A_fp { 1 } }
2177 {
2178 \fp_compare:nNnTF { \l__wheelchart_slices_arc_A_fp } = { 180 }
2179 { \fp_set:Nn \l__wheelchart_slices_arc_A_fp { 0 } }
2180 { \fp_set:Nn \l__wheelchart_slices_arc_A_fp { cotd ( 45 - \l__wheelchart_slices_arc_A_fp / 4 ) } }
2181 }
2182 }
2183 }
2184 } ,
2185 slices~outer~arc~tangent / true /. value~forbidden ,
2186 slices~outer~arc~tangent /. initial = false ,
2187 slices~outer~arc~tangent /. default = true ,
2188 slices~outer~arrow /. style~2~args =
2189 {
2190 slices~outer =
2191 {
2192 \__wheelchart_slices_arrow:nnnnn
2193 {#1}
2194 {#2}
2195 { outer~start }
2196 { outer~end }
2197 { -- ( g__wheelchart_slice_\WCcount _outer~end_coordinate ) }
2198 }
2199 } ,
2200 slices~outer~end~angle~shift /. initial = 0 ,
2201 slices~outer~start~angle~shift /. initial = 0 ,
2202 slices~outer~to /. style~2~args =
2203 {
2204 slices~outer =
2205 {
2206 \__wheelchart_slices_to:nn {#1} {#2}
2207 ( g__wheelchart_slice_\WCcount _outer~end_coordinate )
2208 }
2209 } ,
2210 slices~pos /. initial = 0.5 ,
2211 slices~scope /. style = { slices_scope /. style = {#1} } ,
2212 slices_scope /. style = {} ,
2213 slices~sep /. initial = 0 ,
2214 slices~start /. initial = { -- cycle } ,
2215 slices~start~arc /. style~2~args =
2216 {
2217 slices~start =
2218 {
2219 \__wheelchart_slices_arc:nnnnnn
2220 {#1}
2221 {#2}
2222 { inner~start }
2223 { outer~start }
2224 { -- cycle }
2225 {}
2226 }
2227 } ,
2228 slices~start~arrow /. style~2~args =
2229 {
2230 slices~start =
2231 {
2232 \__wheelchart_slices_arrow:nnnnn
2233 {#1}
2234 {#2}
2235 { inner~start }
2236 { outer~start }
2237 { -- cycle }
2238 }
2239 } ,
2240 slices~start~to /. style~2~args = { slices~start = { \__wheelchart_slices_to:nn {#1} {#2} cycle } } ,
2241 slices~style /. style = { slices_style /. style = {#1} } ,
2242 slices_style /. style = {} ,
2243 slices~style = { \WCvarB } ,
2244 slices~to /. style~2~args =
2245 {
2246 slices~end~to = {#1} {#2} ,
2247 slices~start~to = { - (#1) } { - (#2) }
2248 } ,
2249 start~angle /. initial = 90 ,
2250 start~half /. style =
2251 {
2252 start~angle =
2253 {
2254 (#1) -
2255 \fp_eval:n
2256 {
2257 \l__wheelchart_counter_or_clockwise_fp * \cs:w g__wheelchart_value_1_fp \cs_end: * 0.5
2258 * ( \l__wheelchart_total_angle_fp / \WCtotalnum )
2259 }
2260 }
2261 } ,
2262 start~half /. default = 90 ,
2263 title /. initial = {} ,
2264 title~left /. initial = {} ,
2265 title~left~sep /. initial = 0.5 ,
2266 title~left~style /. style = { title~left_style /. style = {#1} } ,
2267 title~left_style /. style = {} ,
2268 title~sep /. initial = 0.5 ,
2269 title~style /. style = { title_style /. style = {#1} } ,
2270 title_style /. style = {} ,
2271 total~angle /. initial = 360 ,
2272 total~count /. code =
2273 {
2274 \tl_set:Nn \l__wheelchart_type_tl { totalcount }
2275 \pgfmathparse {#1}
2276 \fp_set:Nn \l__wheelchart_total_count_fp { \pgfmathresult }
2277 } ,
2278 triangle~proportional~area /. style~2~args =
2279 {
2280 domain /. expanded = 0 \c_colon_str 1 ,
2281 plot = { { (##2) * sqrt ( 1 - (##1) ) * (#1) / 2 } , { - sqrt ( 1 - (##1) ) * (#2) } } ,
2282 radius = { -1 } { 1 } ,
2283 samples = 2 ,
2284 wheel~data~pos = 0.5
2285 } ,
2286 triangle~proportional~height /. style~2~args =
2287 {
2288 domain /. expanded = 0 \c_colon_str 1 ,
2289 plot = { { (##2) * ( 1 - (##1) ) * (#1) / 2 } , { ( (##1) - 1 ) * (#2) } } ,
2290 radius = { -1 } { 1 } ,
2291 samples = 2 ,
2292 wheel~data~pos = 0.5
2293 } ,
2294 value /. initial = { \WCvarA } ,
2295 WC_list /. code~2~args =
2296 {
2297 \cs_set:cpn {#1}
2298 { \use:e { \clist_item:nn {#2} { \int_mod:nn { \WCcount - 1 } { \clist_count:n {#2} } + 1 } } }
2299 %note the \use:e so that \WClist<name> also works when given as an argument to pgfmath
2300 %if the list contains a macro, for example
2301 %\begin{tikzpicture}
2302 %\def\n{1}
2303 %\wheelchart[
2304 % value=\WClistA,
2305 % WClistA=\n
2306 %]{\exampleforthismanual}
2307 %\end{tikzpicture}
2308 %https://tex.stackexchange.com/questions/671298/clist-item-and-pgfmathsetmacro-causing-an-error
2309 } ,
2310 wheel~data /. initial = {} ,
2311 wheel~data~angle~pos /. initial = 0.5 ,
2312 wheel~data~angle~shift /. initial = 0 ,
2313 wheel~data~pos /. initial = 0.66 ,
2314 wheel~data~sep /. initial = 0 ,
2315 wheel~data~style /. style = { wheel_data_style /. style = {#1} } ,
2316 wheel_data_style /. style = {} ,
2317 wheel~lines /. style =
2318 {
2319 bool_set_true = \l__wheelchart_wheel_lines_bool ,
2320 wheel_lines /. style = {#1}
2321 } ,
2322 wheel_lines /. style = {} ,
2323 xbar /. style~2~args =
2324 {
2325 domain /. expanded = 0 \c_colon_str {#1} ,
2326 plot = { {##1} , {##2} } ,
2327 radius = { 0 } {#2} ,
2328 samples = 2 ,
2329 wheel~data~pos = 0.5
2330 } ,
2331 ybar /. style~2~args =
2332 {
2333 domain /. expanded = 0 \c_colon_str {#2} ,
2334 plot = { {##2} , {##1} } ,
2335 radius = { 0 } {#1} ,
2336 samples = 2 ,
2337 wheel~data~pos = 0.5
2338 } ,
2339 }
2340
2341 \pgfkeys
2342 {
2343 / wheelchart /. unknown /. code =
2344 {
2345 \tl_set:Ne \l__wheelchart_key_name_tl { \pgfkeyscurrentname }%it is necessary to define \l__wheelchart_key_name_tl
2346 %because \pgfkeyscurrentname will be overwritten by / errors / unknown~key /. expanded
2347 \regex_if_match:NVTF \c__wheelchart_braces_regex \l__wheelchart_key_name_tl
2348 {
2349 \tl_set:Ne \l__wheelchart_key_range_tl { \pgfkeyscurrentname }
2350 \regex_replace_all:NnN \c__wheelchart_braces_regex {} \l__wheelchart_key_name_tl
2351 \regex_replace_all:NnN \c__wheelchart_key_braces_regex { \1 } \l__wheelchart_key_range_tl
2352 \str_if_eq:eeTF { \l__wheelchart_key_range_tl } { list }
2353 {
2354 \pgfkeys { / wheelchart , WC_list = { l__wheelchart_list_\l__wheelchart_key_name_tl } {#1} }
2355 \pgfkeys
2356 {
2357 / wheelchart ,
2358 \l__wheelchart_key_name_tl /. expand~once = { \cs:w l__wheelchart_list_\l__wheelchart_key_name_tl \cs_end: }
2359 }
2360 }
2361 {
2362 \clist_gclear:N \g__wheelchart_slice_range_for_loop_clist
2363 \foreach \l__wheelchart_slice_range_index_tl [ parse = true ] in \l__wheelchart_key_range_tl
2364 {
2365 \clist_gput_right:Ne \g__wheelchart_slice_range_for_loop_clist
2366 { \fp_eval:n { \l__wheelchart_slice_range_index_tl } }
2367 }
2368 \clist_map_inline:Nn \g__wheelchart_slice_range_for_loop_clist
2369 {
2370 \clist_if_in:NnF \l__wheelchart_slice_range_local_clist {##1}
2371 { \clist_put_right:Nn \l__wheelchart_slice_range_local_clist {##1} }
2372 \clist_if_exist:cF { l__wheelchart_slice_##1_keys_clist }
2373 { \clist_new:c { l__wheelchart_slice_##1_keys_clist } }
2374 \str_if_eq:eeTF { \l__wheelchart_key_name_tl } { slice }
2375 { \clist_put_right:cn { l__wheelchart_slice_##1_keys_clist } {#1} }
2376 {
2377 \clist_put_right:ce { l__wheelchart_slice_##1_keys_clist }
2378 { \exp_not:V \l__wheelchart_key_name_tl \exp_not:n { = {#1} } }
2379 }
2380 }
2381 }
2382 }
2383 {
2384 \str_if_eq:eeTF { \str_range:Nnn \l__wheelchart_key_name_tl { 1 } { 6 } } { WClist }
2385 { \pgfkeys { / wheelchart , WC_list = { \l__wheelchart_key_name_tl } {#1} } }
2386 { \pgfkeys { / errors / unknown~key /. expanded = { \l__wheelchart_key_name_tl } {#1} } }
2387 }
2388 }
2389 }%this gives an error message if a key of the form <unknown key for wheelchart>{<range>} is given
2390
2391 %%> \subsection{Additional commands}
2392
2393 \NewExpandableDocumentCommand \WCangle { O { \WCcount } m m m m }
2394 { \__wheelchart_def_angle_plot_false:nnnnn { \__wheelchart_mod:n {#1} } {#2} {#3} {#4} {#5} }
2395
2396 \NewExpandableDocumentCommand \WCcoordinate { O { \WCcount } m }
2397 { g__wheelchart_slice_\__wheelchart_mod:n {#1}_#2_coordinate }
2398
2399 \NewExpandableDocumentCommand \WCpoint { O { \WCcount } m m m m }
2400 { \WCangle [#1] {#2} {#3} {#4} {#5} \c_colon_str \WCradius [#1] {#4} {#5} }
2401
2402 \NewExpandableDocumentCommand \WCradius { O { \WCcount } m m }
2403 { \__wheelchart_def_radius:nnn { \__wheelchart_mod:n {#1} } {#2} {#3} }
2404
2405 %%> \subsection{The command \textbackslash wheelchart}
2406
2407 \NewDocumentCommand \wheelchart { O {} m }
2408 {
2409 {%note the double braces {{...}} so that the contents is in a group and so that & can be used in pgfmath in a tabular
2410 \pgfkeys { / wheelchart , #1 }
2411 \IfPackageLoadedTF { siunitx }
2412 { \cs_set:Npn \WCperc { \qty { \WCpercentagerounded } { \percent } } }
2413 { \cs_set:Npn \WCperc { \WCpercentagerounded \, \% } }%the definition of \WCperc is placed inside the command \wheelchart
2414 %so that \WCperc is not defined outside this command
2415 \bool_if:NTF \l__wheelchart_legend_only_bool
2416 {
2417 \__wheelchart_initial:n {#2}
2418 \bool_if:NT \l__wheelchart_legend_row_bool
2419 { \__wheelchart_def_WClegend: }
2420 \pgfkeysvalueof { / wheelchart / legend }
2421 }
2422 {
2423 \fp_set:Nn \l__wheelchart_coord_determinant_fp { \pgf@yy * \pgf@xx - \pgf@yx * \pgf@xy }
2424 \__wheelchart_def_fp:nn { total_angle } { total~angle }
2425 \__wheelchart_initial:n {#2}
2426 \tl_gset:Ne \g__wheelchart_totalcount_tl { \WCtotalcount }%\WCtotalcount is local and \g__wheelchart_totalcount_tl is global
2427 %because it is used in commands such as \WCangle thus must be available after the command \wheelchart
2428 \__wheelchart_def_fp:nn { start_angle } { start~angle }
2429 \fp_gset_eq:NN \g__wheelchart_angle_fp \l__wheelchart_start_angle_fp
2430 \__wheelchart_for_loop_initial:n
2431 {
2432 \__wheelchart_def_slice_keys:n
2433 {
2434 \cs_set_eq:Nc \WCpercentage { l__wheelchart_WCpercentage_\WCcount }
2435 \cs_set_eq:Nc \WCpercentagerounded { l__wheelchart_WCpercentagerounded_\WCcount }
2436 \fp_compare:nNnTF { \WCcount } = { \WCtotalcount }
2437 {
2438 \fp_gset:Nn \g__wheelchart_new_angle_fp
2439 { \l__wheelchart_start_angle_fp + \l__wheelchart_counter_or_clockwise_fp * \l__wheelchart_total_angle_fp }
2440 }
2441 {
2442 \fp_gset:Nn \g__wheelchart_new_angle_fp
2443 {
2444 \g__wheelchart_angle_fp +
2445 (
2446 \l__wheelchart_counter_or_clockwise_fp * \cs:w g__wheelchart_value_\WCcount _fp \cs_end:
2447 * ( \l__wheelchart_total_angle_fp / \WCtotalnum )
2448 )
2449 }
2450 }
2451 \__wheelchart_gdef_count_fp:nn { data_angle_pos } { data~angle~pos }
2452 \__wheelchart_def_fp:nn { gap } { gap }
2453 \__wheelchart_def_fp:nn { gap_max_angle } { gap~max~angle }
2454 \__wheelchart_def_fp:nn { gap_polar } { gap~polar }
2455 \__wheelchart_def_fp:nn { gap_radius } { gap~radius }
2456 \__wheelchart_gdef_count_fp:nn { samples } { samples }
2457 \__wheelchart_def_fp:nn { slices_inner_start_angle_shift } { slices~inner~start~angle~shift }
2458 \__wheelchart_def_fp:nn { slices_inner_end_angle_shift } { slices~inner~end~angle~shift }
2459 \__wheelchart_def_fp:nn { slices_outer_end_angle_shift } { slices~outer~end~angle~shift }
2460 \__wheelchart_def_fp:nn { slices_outer_start_angle_shift } { slices~outer~start~angle~shift }
2461 \__wheelchart_def_outer_radius:
2462 \__wheelchart_def_inner_radius:
2463 \fp_gzero_new:c { g__wheelchart_inner_radius_\WCcount _fp }
2464 \fp_gset_eq:cN { g__wheelchart_inner_radius_\WCcount _fp } \l__wheelchart_inner_radius_fp
2465 \fp_gzero_new:c { g__wheelchart_outer_radius_\WCcount _fp }
2466 \fp_gset_eq:cN { g__wheelchart_outer_radius_\WCcount _fp } \l__wheelchart_outer_radius_fp
2467 \fp_gzero_new:c { g__wheelchart_abs_half_angle_minus_new_angle_\WCcount _fp }
2468 \fp_gset:cn { g__wheelchart_abs_half_angle_minus_new_angle_\WCcount _fp }
2469 { abs ( \g__wheelchart_angle_fp - \g__wheelchart_new_angle_fp ) / 2 }
2470 \fp_set:Nn \l__wheelchart_abs_half_angle_minus_new_angle_minus_gap_polar_fp
2471 { \cs:w g__wheelchart_abs_half_angle_minus_new_angle_\WCcount _fp \cs_end: - \l__wheelchart_gap_polar_fp }
2472 \fp_gzero_new:c { g__wheelchart_outer_gap_\WCcount _fp }
2473 \fp_gzero_new:c { g__wheelchart_inner_gap_\WCcount _fp }
2474 \bool_if:NTF \l__wheelchart_plot_bool
2475 {
2476 \fp_gset_eq:cN { g__wheelchart_outer_gap_\WCcount _fp } \l__wheelchart_gap_polar_fp
2477 \fp_gset_eq:cN { g__wheelchart_inner_gap_\WCcount _fp } \l__wheelchart_gap_polar_fp
2478 }
2479 {
2480 \fp_set:Nn \l__wheelchart_gap_max_angle_def_fp
2481 {
2482 \cs:w g__wheelchart_inner_radius_\WCcount _fp \cs_end: > 0
2483 ?
2484 90
2485 :
2486 (
2487 sind ( \l__wheelchart_abs_half_angle_minus_new_angle_minus_gap_polar_fp ) < 0.001
2488 ?
2489 (
2490 90 < \l__wheelchart_gap_max_angle_fp && \l__wheelchart_gap_max_angle_fp < 180
2491 ?
2492 \l__wheelchart_gap_max_angle_fp
2493 :
2494 90
2495 )
2496 :
2497 (
2498 \l__wheelchart_gap_max_angle_fp < 90 || \l__wheelchart_gap_max_angle_fp > 180
2499 ?
2500 180
2501 :
2502 \l__wheelchart_gap_max_angle_fp
2503 )
2504 )
2505 }
2506 \__wheelchart_def_gap:nn { outer } { \cs:w g__wheelchart_outer_radius_\WCcount _fp \cs_end: }
2507 \__wheelchart_def_gap:nn { inner } { \cs:w g__wheelchart_inner_radius_\WCcount _fp \cs_end: }
2508 \fp_compare:nNnT { \l__wheelchart_abs_half_angle_minus_new_angle_minus_gap_polar_fp } > { 0.01 }
2509 {
2510 \fp_gset:cn { g__wheelchart_inner_radius_\WCcount _fp }
2511 {
2512 max
2513 (
2514 \l__wheelchart_gap_fp
2515 / sind
2516 (
2517 min
2518 (
2519 \l__wheelchart_abs_half_angle_minus_new_angle_minus_gap_polar_fp ,
2520 \l__wheelchart_gap_max_angle_def_fp
2521 )
2522 )
2523 ,
2524 \cs:w g__wheelchart_inner_radius_\WCcount _fp \cs_end:
2525 )
2526 }
2527 }
2528 }
2529 \__wheelchart_def_slice_angle:nnnn { inner } { end } { new_ } { -1 }
2530 \__wheelchart_def_slice_angle:nnnn { inner } { start } {} { 1 }
2531 \__wheelchart_def_slice_angle:nnnn { outer } { end } { new_ } { -1 }
2532 \__wheelchart_def_slice_angle:nnnn { outer } { start } {} { 1 }
2533 \__wheelchart_def_angle:nnnn { 0.5 } { 0 } { 0.5 } { 0 }
2534 \cs_set:Npe \WCmidangle { \pgfmathresult }
2535 \__wheelchart_gdef_count_fp:nn { data_angle_shift } { data~angle~shift }
2536 \__wheelchart_gdef_count_fp:nn { data_pos } { data~pos }
2537 \__wheelchart_gdef_count_fp:nn { data_sep } { data~sep }
2538 \__wheelchart_def_angle:nnnn
2539 { \cs:w g__wheelchart_data_angle_pos_\WCcount _fp \cs_end: }
2540 { \cs:w g__wheelchart_data_angle_shift_\WCcount _fp \cs_end: }
2541 { \cs:w g__wheelchart_data_pos_\WCcount _fp \cs_end: }
2542 { \cs:w g__wheelchart_data_sep_\WCcount _fp \cs_end: }
2543 \cs_set:Npe \WCdataangle { \pgfmathresult }
2544 \__wheelchart_gdef_count_fp:nn { explode } { explode }
2545 \pgfkeysvalueof { / wheelchart / for~loop~start }%this must be placed after the definition of macros such as
2546 %\WCpercentage so that these macros can be used in the key for loop start
2547 \int_compare:nNnT { \WCcount } = { 1 }
2548 {
2549 \begin { scope }
2550 [
2551 shift = { ( \WCmidangle \c_colon_str \fp_use:c { g__wheelchart_explode_\WCcount _fp } ) } ,
2552 / wheelchart / slices_scope
2553 ]
2554 \__wheelchart_def_orientation:
2555 \end { scope }
2556 }
2557 \fp_gzero_new:c { g__wheelchart_WCdataangle_\WCcount _fp }
2558 \fp_gset:cn { g__wheelchart_WCdataangle_\WCcount _fp } { \WCdataangle }
2559 \fp_gzero_new:c { g__wheelchart_WCmidangle_\WCcount _fp }
2560 \fp_gset:cn { g__wheelchart_WCmidangle_\WCcount _fp } { \WCmidangle }
2561 \fp_gset_eq:NN \g__wheelchart_angle_fp \g__wheelchart_new_angle_fp
2562 \pgfkeysvalueof { / wheelchart / for~loop~end }
2563 }
2564 }
2565 \begin { scope } [ shift /. expanded = { \pgfkeysvalueof { / wheelchart / at } } ]
2566 \begin { scope } [ local~bounding~box /. expanded = \g__wheelchart_name_tl ]
2567 \bool_if:NT \l__wheelchart_middle_fill_bool
2568 {
2569 \bool_if:NF \l__wheelchart_plot_bool
2570 {
2571 \__wheelchart_def_inner_radius:
2572 \fill [ / wheelchart / middle_fill ]
2573 \fp_compare:nNnTF { \l__wheelchart_total_angle_fp } = { 360 }
2574 { ( 0 , 0 ) circle [ radius = \fp_use:N \l__wheelchart_inner_radius_fp ] }
2575 {
2576 ( 0 , 0 )
2577 -- ( \fp_use:N \l__wheelchart_start_angle_fp \c_colon_str \fp_use:N \l__wheelchart_inner_radius_fp )
2578 arc
2579 [
2580 start~angle = \fp_use:N \l__wheelchart_start_angle_fp ,
2581 end~angle =
2582 \fp_eval:n
2583 {
2584 \l__wheelchart_start_angle_fp
2585 + \l__wheelchart_counter_or_clockwise_fp * \l__wheelchart_total_angle_fp
2586 }
2587 ,
2588 radius = \fp_use:N \l__wheelchart_inner_radius_fp
2589 ]
2590 -- cycle
2591 }
2592 ;
2593 }
2594 }
2595 \bool_if:NTF \l__wheelchart_discrete_bool
2596 { \__wheelchart_discrete_algorithm: }
2597 {
2598 \__wheelchart_for_loop:n
2599 {
2600 \pgfkeysvalueof { / wheelchart / before~slices }
2601 \bool_if:NTF \l__wheelchart_slices_bool
2602 {
2603 \__wheelchart_def_fp:nn { slices_angle_pos } { slices~angle~pos }
2604 \__wheelchart_def_fp:nn { slices_angle_shift } { slices~angle~shift }
2605 \__wheelchart_def_fp:nn { slices_pos } { slices~pos }
2606 \__wheelchart_def_fp:nn { slices_sep } { slices~sep }
2607 \__wheelchart_def_angle:nnnn
2608 { \l__wheelchart_slices_angle_pos_fp }
2609 { \l__wheelchart_slices_angle_shift_fp }
2610 { \l__wheelchart_slices_pos_fp }
2611 { \l__wheelchart_slices_sep_fp }
2612 \fp_set:Nn \l__wheelchart_slices_angle_fp { \pgfmathresult }
2613 \begin { scope }
2614 [
2615 shift /. expanded =
2616 {
2617 \cs:w __wheelchart_point_plot_\bool_to_str:N \l__wheelchart_plot_bool :nnnnn \cs_end:
2618 { \WCcount }
2619 { \l__wheelchart_slices_angle_pos_fp }
2620 { \l__wheelchart_slices_angle_shift_fp }
2621 { \l__wheelchart_slices_pos_fp }
2622 { \l__wheelchart_slices_sep_fp }
2623 } ,
2624 rotate = \fp_use:N \l__wheelchart_slices_angle_fp
2625 ]
2626 \fill [ / wheelchart / slices_style ] \l__wheelchart_slices_tl
2627 \end { scope }
2628 }
2629 {
2630 %We do not use the let operation in the path \fill[/wheelchart/slices_style] ... because then
2631 %\n, \p, \x and \y can not be used as macro names inside the argument of a key which is applied
2632 %on this path such as the key slices inner arc.
2633 \__wheelchart_def_coord:nnnn { inner~end } { inner } { end }
2634 { \fp_use:c { g__wheelchart_slice_inner_end_angle_\WCcount _fp } }
2635 \__wheelchart_def_coord:nnnn { inner~start } { inner } { start }
2636 { \fp_use:c { g__wheelchart_slice_inner_start_angle_\WCcount _fp } }
2637 \__wheelchart_def_coord:nnnn { outer~end } { outer } { end }
2638 { \fp_use:c { g__wheelchart_slice_outer_end_angle_\WCcount _fp } }
2639 \__wheelchart_def_coord:nnnn { outer~start } { outer } { start }
2640 { \fp_use:c { g__wheelchart_slice_outer_start_angle_\WCcount _fp } }
2641 \fill [ / wheelchart / slices_style ]
2642 ( g__wheelchart_slice_\WCcount _outer~start_coordinate )
2643 \pgfkeysvalueof { / wheelchart / slices~outer }
2644 \pgfkeysvalueof { / wheelchart / slices~end }
2645 \pgfkeysvalueof { / wheelchart / slices~inner }
2646 \pgfkeysvalueof { / wheelchart / slices~start }
2647 ;
2648 }
2649 \pgfkeysvalueof { / wheelchart / after~slices }
2650 }
2651 }
2652 \__wheelchart_for_loop:n
2653 {
2654 \bool_if:NT \l__wheelchart_wheel_lines_bool
2655 %this is placed inside \__wheelchart_for_loop:n so that wheel lines can be applied for specific slices
2656 {
2657 \int_step_inline:nnn { 0 } { \fp_eval:n { round ( \cs:w g__wheelchart_value_\WCcount _fp \cs_end: ) } }
2658 %note the \fp_eval:n { round ( ... ) } to avoid the messages Missing character: There is no ... in font nullfont!
2659 {
2660 \bool_if:NTF \l__wheelchart_plot_bool
2661 {
2662 \draw [ / wheelchart / wheel_lines ]
2663 (
2664 \__wheelchart_inner_plot:nn
2665 { \__wheelchart_wheel_lines_aux:nn {####1} { inner } }
2666 { \fp_use:c { g__wheelchart_inner_radius_\WCcount _fp } }
2667 )
2668 --
2669 (
2670 \__wheelchart_outer_plot:nn
2671 { \__wheelchart_wheel_lines_aux:nn {####1} { outer } }
2672 { \fp_use:c { g__wheelchart_outer_radius_\WCcount _fp } }
2673 )
2674 ;
2675 }
2676 {
2677 \draw [ / wheelchart / wheel_lines ]
2678 (
2679 \__wheelchart_wheel_lines_aux:nn {####1} { inner }
2680 \c_colon_str
2681 \fp_use:c { g__wheelchart_inner_radius_\WCcount _fp }
2682 )
2683 --
2684 (
2685 \__wheelchart_wheel_lines_aux:nn {####1} { outer }
2686 \c_colon_str
2687 \fp_use:c { g__wheelchart_outer_radius_\WCcount _fp }
2688 )
2689 ;
2690 }
2691 }
2692 }
2693 }
2694 \bool_if:NT \l__wheelchart_contour_bool
2695 {
2696 \bool_if:NF \l__wheelchart_plot_bool
2697 {
2698 \__wheelchart_def_outer_radius:
2699 \__wheelchart_def_inner_radius:
2700 \fp_compare:nNnTF { \l__wheelchart_total_angle_fp } = { 360 }
2701 {
2702 \draw [ / wheelchart / contour_style ]
2703 ( 0 , 0 ) circle [ radius = \fp_use:N \l__wheelchart_inner_radius_fp ] ;
2704 \draw [ / wheelchart / contour_style ]
2705 ( 0 , 0 ) circle [ radius = \fp_use:N \l__wheelchart_outer_radius_fp ] ;
2706 }
2707 {
2708 \draw [ / wheelchart / contour_style ]
2709 ( \fp_use:N \l__wheelchart_start_angle_fp \c_colon_str \fp_use:N \l__wheelchart_inner_radius_fp )
2710 arc
2711 [
2712 start~angle = \fp_use:N \l__wheelchart_start_angle_fp ,
2713 end~angle =
2714 \fp_eval:n
2715 {
2716 \l__wheelchart_start_angle_fp
2717 + \l__wheelchart_counter_or_clockwise_fp * \l__wheelchart_total_angle_fp
2718 }
2719 ,
2720 radius = \fp_use:N \l__wheelchart_inner_radius_fp
2721 ]
2722 --
2723 (
2724 \fp_eval:n
2725 {
2726 \l__wheelchart_start_angle_fp
2727 + \l__wheelchart_counter_or_clockwise_fp * \l__wheelchart_total_angle_fp
2728 }
2729 \c_colon_str
2730 \fp_use:N \l__wheelchart_outer_radius_fp
2731 )
2732 arc
2733 [
2734 start~angle =
2735 \fp_eval:n
2736 {
2737 \l__wheelchart_start_angle_fp
2738 + \l__wheelchart_counter_or_clockwise_fp * \l__wheelchart_total_angle_fp
2739 }
2740 ,
2741 end~angle = \fp_use:N \l__wheelchart_start_angle_fp ,
2742 radius = \fp_use:N \l__wheelchart_outer_radius_fp
2743 ]
2744 -- cycle ;
2745 }
2746 }
2747 }
2748 \__wheelchart_for_loop:n
2749 {
2750 \__wheelchart_def_fp:nn { lines } { lines }
2751 \__wheelchart_def_fp:nn { lines_angle_pos } { lines~angle~pos }
2752 \__wheelchart_def_fp:nn { lines_angle_shift } { lines~angle~shift }
2753 \__wheelchart_def_fp:nn { lines_ext } { lines~ext }
2754 \__wheelchart_def_fp:nn { lines_pos } { lines~pos }
2755 \__wheelchart_def_fp:nn { lines_sep } { lines~sep }
2756 \fp_compare:nNnF { \l__wheelchart_lines_ext_fp } = { 0 }
2757 {
2758 \bool_if:NF \l__wheelchart_lines_ext_dir_bool
2759 {
2760 \__wheelchart_def_fp:nn { lines_ext_dirsep } { lines~ext~dirsep }
2761 \int_set:Nn \l__wheelchart_lines_ext_dir_int
2762 {
2763 \fp_eval:n
2764 {
2765 (
2766 \WCdataangle < 90 - \l__wheelchart_lines_ext_dirsep_fp
2767 ?
2768 1
2769 :
2770 (
2771 \WCdataangle <= 90 + \l__wheelchart_lines_ext_dirsep_fp
2772 ?
2773 \l__wheelchart_lines_ext_top_dir_int
2774 :
2775 (
2776 \WCdataangle < 270 - \l__wheelchart_lines_ext_dirsep_fp
2777 ?
2778 -1
2779 :
2780 (
2781 \WCdataangle <= 270 + \l__wheelchart_lines_ext_dirsep_fp
2782 ?
2783 \l__wheelchart_lines_ext_bottom_dir_int
2784 :
2785 1
2786 )
2787 )
2788 )
2789 )
2790 }
2791 }
2792 }
2793 \__wheelchart_def_fp:nn { lines_ext_fixed_left } { lines~ext~fixed~left }
2794 \__wheelchart_def_fp:nn { lines_ext_fixed_right } { lines~ext~fixed~right }
2795 }
2796 \fp_compare:nF { \l__wheelchart_lines_fp == 0 && \l__wheelchart_lines_ext_fp == 0 }
2797 {
2798 \draw [ / wheelchart / lines_style ] let \p { l__wheelchart_lines_1 } =
2799 \cs:w __wheelchart_point_plot_\bool_to_str:N \l__wheelchart_plot_bool :nnnnn \cs_end:
2800 { \WCcount }
2801 { \cs:w g__wheelchart_data_angle_pos_\WCcount _fp \cs_end: }
2802 { \cs:w g__wheelchart_data_angle_shift_\WCcount _fp \cs_end: }
2803 { \cs:w g__wheelchart_data_pos_\WCcount _fp \cs_end: }
2804 { \l__wheelchart_lines_sep_fp + \l__wheelchart_lines_fp }
2805 in
2806 \cs:w __wheelchart_point_plot_\bool_to_str:N \l__wheelchart_plot_bool :nnnnn \cs_end:
2807 { \WCcount }
2808 { \l__wheelchart_lines_angle_pos_fp }
2809 { \l__wheelchart_lines_angle_shift_fp }
2810 { \l__wheelchart_lines_pos_fp }
2811 { \l__wheelchart_lines_sep_fp }
2812 -- ( \p { l__wheelchart_lines_1 } )
2813 \fp_compare:nNnF { \l__wheelchart_lines_ext_fp } = { 0 }
2814 {
2815 \str_case:enF { \pgfkeysvalueof { / wheelchart / lines~ext~fixed } }
2816 {
2817 { true }
2818 {
2819 --
2820 (
2821 {
2822 \fp_eval:n
2823 {
2824 \l__wheelchart_lines_ext_dir_int == 1
2825 ?
2826 \l__wheelchart_lines_ext_fixed_right_fp
2827 :
2828 \l__wheelchart_lines_ext_fixed_left_fp
2829 }
2830 }
2831 ,
2832 \y { l__wheelchart_lines_1 }
2833 )
2834 }
2835 { false }
2836 { --++ ( { \fp_eval:n { \l__wheelchart_lines_ext_dir_int * \l__wheelchart_lines_ext_fp } } , 0 ) }
2837 }
2838 {
2839 \pgfkeys
2840 {
2841 / errors / boolean~expected /. expanded =
2842 { lines~ext~fixed }
2843 { \pgfkeysvalueof { / wheelchart / lines~ext~fixed } }
2844 }
2845 }
2846 coordinate
2847 [
2848 shift =
2849 {
2850 (
2851 {
2852 \fp_eval:n
2853 {
2854 \l__wheelchart_lines_ext_dir_int * \cs:w g__wheelchart_data_sep_\WCcount _fp \cs_end:
2855 }
2856 } ,
2857 0
2858 )
2859 }
2860 ]
2861 ( g__wheelchart_data_coordinate )
2862 }
2863 ;
2864 }
2865 \__wheelchart_if_text:nnn { data } { o }
2866 {
2867 \fp_compare:nNnTF { \l__wheelchart_lines_ext_fp } = { 0 }
2868 {
2869 \__wheelchart_def_fp:nn { anchor_xsep } { anchor~xsep }
2870 \__wheelchart_def_fp:nn { anchor_ysep } { anchor~ysep }
2871 \pgfmathparse
2872 {
2873 ( \WCdataangle == 0 ? "west" \c_colon_str
2874 ( \WCdataangle == 90 ? "south" \c_colon_str
2875 ( \WCdataangle == 180 ? "east" \c_colon_str
2876 ( \WCdataangle == 270 ? "north" \c_colon_str
2877 ( \WCdataangle <= \fp_use:N \l__wheelchart_anchor_ysep_fp ? "west" \c_colon_str
2878 ( \WCdataangle < 90 - \fp_use:N \l__wheelchart_anchor_xsep_fp ? "south~west" \c_colon_str
2879 ( \WCdataangle <= 90 + \fp_use:N \l__wheelchart_anchor_xsep_fp ? "south" \c_colon_str
2880 ( \WCdataangle < 180 - \fp_use:N \l__wheelchart_anchor_ysep_fp ? "south~east" \c_colon_str
2881 ( \WCdataangle <= 180 + \fp_use:N \l__wheelchart_anchor_ysep_fp ? "east" \c_colon_str
2882 ( \WCdataangle < 270 - \fp_use:N \l__wheelchart_anchor_xsep_fp ? "north~east" \c_colon_str
2883 ( \WCdataangle <= 270 + \fp_use:N \l__wheelchart_anchor_xsep_fp ? "north" \c_colon_str
2884 ( \WCdataangle < 360 - \fp_use:N \l__wheelchart_anchor_ysep_fp ? "north~west" \c_colon_str
2885 "west"
2886 ))))))))))))
2887 }
2888 \tl_set:Ne \l__wheelchart_data_anchor_tl { \pgfmathresult }
2889 \coordinate
2890 [
2891 at =
2892 \cs:w __wheelchart_point_plot_\bool_to_str:N \l__wheelchart_plot_bool :nnnnn \cs_end:
2893 { \WCcount }
2894 { \cs:w g__wheelchart_data_angle_pos_\WCcount _fp \cs_end: }
2895 { \cs:w g__wheelchart_data_angle_shift_\WCcount _fp \cs_end: }
2896 { \cs:w g__wheelchart_data_pos_\WCcount _fp \cs_end: }
2897 {
2898 \cs:w g__wheelchart_data_sep_\WCcount _fp \cs_end: +
2899 (
2900 \l__wheelchart_lines_fp == 0
2901 ?
2902 0
2903 :
2904 \l__wheelchart_lines_sep_fp + \l__wheelchart_lines_fp
2905 )
2906 }
2907 ]
2908 ( g__wheelchart_data_coordinate ) ;
2909 }
2910 {
2911 \pgfmathparse { \int_use:N \l__wheelchart_lines_ext_dir_int == 1 ? "right" \c_colon_str "left" }
2912 \tl_set:Ne \l__wheelchart_data_anchor_tl
2913 { \pgfkeysvalueof { / wheelchart / lines~ext~\pgfmathresult \c_space_tl anchor } }
2914 }
2915 \node [ anchor = \l__wheelchart_data_anchor_tl , align = left , / wheelchart / data_style ]
2916 at ( g__wheelchart_data_coordinate )
2917 { \pgfkeysvalueof { / wheelchart / data } } ;%a separate \node and not at the end of the \draw with lines_style
2918 %so that the key lines style is not passed to this \node
2919 }
2920 \__wheelchart_def_fp:nn { arc_around_line } { arc~around~line }
2921 \__wheelchart_def_fp:nn { arc_data_angle_pos } { arc~data~angle~pos }
2922 \__wheelchart_def_fp:nn { arc_data_angle_shift } { arc~data~angle~shift }
2923 \__wheelchart_def_fp:nn { arc_data_dir } { arc~data~dir }
2924 %these are needed for arc data and arc
2925 \pgfinterruptpicture%
2926 \fp_gset:Nn \g__wheelchart_half_ex_over_one_cm_fp { 0.5 ex / 1 cm }%
2927 \endpgfinterruptpicture%
2928 \fp_gset:Nn \g__wheelchart_arc_data_aux_ii_fp { 0 }
2929 \__wheelchart_if_text:nnn { arc~data } {}
2930 {
2931 \cs_set:Npn \WCperc { \WCpercentagerounded { \, } { \% } }%so that \WCperc follows the arc if used in arc data
2932 %this redefinition of \WCperc is local to the group of arc data
2933 \__wheelchart_def_fp:nn { arc_data_pos } { arc~data~pos }
2934 \__wheelchart_def_fp:nn { arc_data_sep } { arc~data~sep }
2935 \__wheelchart_def_fp:nn { arc_data_line_sep_factor } { arc~data~line~sep~factor }
2936 \__wheelchart_def_fp:nn { arc_data_lines_pos } { arc~data~lines~pos }
2937 \__wheelchart_def_fp:nn { arc_data_lines_shift } { arc~data~lines~shift }
2938 \cs:w seq_set_split:Nn\pgfkeysvalueof { / wheelchart / arc~data~expand } \cs_end:
2939 \l__wheelchart_arc_data_seq
2940 { \\ }
2941 { \pgfkeysvalueof { / wheelchart / arc~data } }
2942 \seq_map_indexed_inline:Nn \l__wheelchart_arc_data_seq
2943 {
2944 \fp_set:Nn \l__wheelchart_arc_data_text_pos_fp
2945 {
2946 \l__wheelchart_arc_data_pos_fp + 4 * \g__wheelchart_slices_orientation_fp *
2947 (
2948 ####1 - 1 - \l__wheelchart_arc_data_lines_pos_fp * ( \seq_count:N \l__wheelchart_arc_data_seq - 1 )
2949 + \l__wheelchart_arc_data_lines_shift_fp
2950 )
2951 * sign ( \l__wheelchart_arc_data_dir_fp )
2952 * \l__wheelchart_arc_data_line_sep_factor_fp * \g__wheelchart_half_ex_over_one_cm_fp
2953 /
2954 (
2955 \cs:w g__wheelchart_outer_radius_\WCcount _fp \cs_end:
2956 - \cs:w g__wheelchart_inner_radius_\WCcount _fp \cs_end:
2957 + 2 * \l__wheelchart_arc_data_sep_fp
2958 )
2959 }%the sign is needed because \l__wheelchart_arc_data_dir_fp is not necessarily 1 or -1
2960 \hbox_set:Nn \l__wheelchart_arc_data_box
2961 { \pgfinterruptpicture {####2} \endpgfinterruptpicture }
2962 \fp_gset:Nn \g__wheelchart_arc_data_slice_length_fp { 1 }%this is necessary if the value is 0
2963 \bool_if:NTF \l__wheelchart_plot_bool
2964 {
2965 \__wheelchart_convex_comb_coord_plot:nnnnnnn
2966 {
2967 overlay ,
2968 decorate ,
2969 decoration =
2970 {
2971 text~along~path ,
2972 text =
2973 { {} { \fp_gset:Nn \g__wheelchart_arc_data_slice_length_fp { \pgfdecoratedpathlength } } } ,
2974 raise = -0.5 ex ,
2975 text~align = \l__wheelchart_arc_data_align_tl ,
2976 / wheelchart / arc_data_style
2977 }
2978 }%get the length of the path
2979 %note the option overlay so that this does not increase the bounding box
2980 %note the {} at the start of text and the braces around \fp_gset:Nn ...
2981 %so that the compilation does not stall
2982 { 0 }
2983 { 1 }
2984 { \l__wheelchart_plot_variable_tl }
2985 { 0 }
2986 { \l__wheelchart_arc_data_text_pos_fp }
2987 { \l__wheelchart_arc_data_sep_fp }
2988 \__wheelchart_convex_comb_coord_plot:nnnnnnn
2989 {
2990 decorate ,
2991 decoration =
2992 {
2993 text~along~path ,
2994 text =
2995 {
2996 { { \fp_gset:Nn \g__wheelchart_arc_data_aux_i_fp { \the \pgfdecoratedcompleteddistance } } }
2997 ####2
2998 {
2999 {
3000 \fp_gset:Nn \g__wheelchart_arc_data_aux_i_fp
3001 {
3002 ( \the \pgfdecoratedcompleteddistance - \g__wheelchart_arc_data_aux_i_fp )
3003 / \g__wheelchart_arc_data_slice_length_fp
3004 }
3005 }
3006 }
3007 } ,
3008 raise = -0.5 ex ,
3009 text~align = \l__wheelchart_arc_data_align_tl ,
3010 / wheelchart / arc_data_style
3011 }
3012 }%note the double braces around \fp_gset:Nn ...
3013 %so that for example arc data=text {\qty{5}{\percent}} is allowed
3014 %note that \def\mytext{}\path[decorate,decoration={text along path,text={\mytext}}] (0,0)--(1,1);
3015 %gives the message Missing character: There is no ... in font nullfont!, then
3016 %text={\pgfkeysvalueof { / wheelchart / arc~data }{}} can be used
3017 %if the \fp_gset:Nn ... would not be present
3018 { \fp_use:c { c__wheelchart_arc_data_start_factor_\l__wheelchart_arc_data_align_tl _fp } }
3019 { \fp_use:c { c__wheelchart_arc_data_end_factor_\l__wheelchart_arc_data_align_tl _fp } }
3020 {
3021 \l__wheelchart_plot_variable_tl * \l__wheelchart_arc_data_dir_fp * 1.1
3022 * ( \dim_to_fp:n { \box_wd:N \l__wheelchart_arc_data_box } / \g__wheelchart_arc_data_slice_length_fp )
3023 + \l__wheelchart_arc_data_angle_pos_fp
3024 }
3025 { \l__wheelchart_arc_data_angle_shift_fp }
3026 { \l__wheelchart_arc_data_text_pos_fp }
3027 { \l__wheelchart_arc_data_sep_fp }
3028 }
3029 {
3030 \fp_set:Nn \l__wheelchart_arc_data_radius_plot_false_fp
3031 {
3032 \__wheelchart_def_radius:nnn
3033 { \WCcount }
3034 { \l__wheelchart_arc_data_text_pos_fp }
3035 { \l__wheelchart_arc_data_sep_fp + \g__wheelchart_half_ex_over_one_cm_fp }
3036 }
3037 \fp_set:Nn \l__wheelchart_arc_data_total_angle_plot_false_fp
3038 {
3039 \box_wd:N \l__wheelchart_arc_data_box * 1.1 /
3040 (
3041 sqrt ( abs ( \l__wheelchart_coord_determinant_fp ) )%this is necessary if an option such as
3042 %[x={(-0.5,0)},y={(0,0.5)}] is given to the tikzpicture
3043 * \l__wheelchart_arc_data_radius_plot_false_fp * deg
3044 )
3045 }
3046 \fp_set:Nn \l__wheelchart_arc_data_start_angle_plot_false_fp
3047 {
3048 \__wheelchart_def_angle_plot_false:nnnnn
3049 { \WCcount }
3050 { \l__wheelchart_arc_data_angle_pos_fp }
3051 { \l__wheelchart_arc_data_angle_shift_fp }
3052 { \l__wheelchart_arc_data_text_pos_fp }
3053 { \l__wheelchart_arc_data_sep_fp + \g__wheelchart_half_ex_over_one_cm_fp }
3054 + \l__wheelchart_counter_or_clockwise_fp * \l__wheelchart_arc_data_dir_fp
3055 * \cs:w c__wheelchart_arc_data_start_factor_\l__wheelchart_arc_data_align_tl _fp \cs_end:
3056 * \l__wheelchart_arc_data_total_angle_plot_false_fp
3057 }
3058 \path
3059 [
3060 decorate ,
3061 decoration =
3062 {
3063 text~along~path ,
3064 text =
3065 {
3066 { { \fp_gset:Nn \g__wheelchart_arc_data_aux_i_fp { \the \pgfdecoratedcompleteddistance } } }
3067 ####2
3068 {
3069 {
3070 \fp_gset:Nn \g__wheelchart_arc_data_aux_i_fp
3071 {
3072 ( \the \pgfdecoratedcompleteddistance - \g__wheelchart_arc_data_aux_i_fp )
3073 / \l__wheelchart_arc_data_radius_plot_false_fp
3074 }
3075 }
3076 }
3077 } ,
3078 raise = -0.5 ex ,
3079 text~align = \l__wheelchart_arc_data_align_tl ,
3080 / wheelchart / arc_data_style
3081 }
3082 ]
3083 (
3084 \fp_use:N \l__wheelchart_arc_data_start_angle_plot_false_fp
3085 \c_colon_str
3086 \fp_use:N \l__wheelchart_arc_data_radius_plot_false_fp
3087 )
3088 arc
3089 [
3090 start~angle = \fp_use:N \l__wheelchart_arc_data_start_angle_plot_false_fp ,
3091 end~angle =
3092 \fp_eval:n
3093 {
3094 \l__wheelchart_arc_data_start_angle_plot_false_fp
3095 + \l__wheelchart_counter_or_clockwise_fp * \l__wheelchart_arc_data_dir_fp
3096 * \l__wheelchart_arc_data_total_angle_plot_false_fp
3097 }
3098 ,
3099 radius = \fp_use:N \l__wheelchart_arc_data_radius_plot_false_fp
3100 ]
3101 ;
3102 }
3103 \fp_compare:nNnF { \g__wheelchart_arc_data_aux_i_fp } > { 0 }
3104 {
3105 \PackageWarning { wheelchart }
3106 {
3107 The~arc~data~in~slice~\WCcount \c_space_tl did~(possibly)~not~fit.~
3108 Increase~the~absolute~value~of~arc~data~dir.
3109 }%refer to \WCcount and not to \pgfkeysvalueof { / wheelchart / arc~data }
3110 %because the latter is not necessarily unique
3111 }
3112 \int_compare:nNnT {####1} = { \fp_use:N \l__wheelchart_arc_around_line_fp }
3113 { \fp_gset_eq:NN \g__wheelchart_arc_data_aux_ii_fp \g__wheelchart_arc_data_aux_i_fp }
3114 }
3115 }
3116 \bool_if:NT \l__wheelchart_arc_bool
3117 {
3118 \__wheelchart_def_fp:nn { arc_pos } { arc~pos }
3119 \__wheelchart_def_fp:nn { arc_sep } { arc~sep }
3120 \str_case:enF { \pgfkeysvalueof { / wheelchart / arc~around~text } }
3121 {
3122 { true }
3123 {
3124 \bool_if:NTF \l__wheelchart_plot_bool
3125 {
3126 \__wheelchart_arc_around_text_plot_true:nnn { first } { -1 } { 0 }
3127 \__wheelchart_arc_around_text_plot_true:nnn { second } { 1 } { 1 }
3128 }
3129 {
3130 \fp_gset:Nn \g__wheelchart_arc_data_aux_ii_fp
3131 {
3132 \g__wheelchart_arc_data_aux_ii_fp
3133 / ( sqrt ( abs ( \l__wheelchart_coord_determinant_fp ) ) * deg )
3134 }
3135 \fp_set:Nn \l__wheelchart_arc_radius_fp
3136 {
3137 \__wheelchart_def_radius:nnn
3138 { \WCcount }
3139 { \l__wheelchart_arc_pos_fp }
3140 { \l__wheelchart_arc_sep_fp + \g__wheelchart_half_ex_over_one_cm_fp }
3141 }
3142 \__wheelchart_arc_around_text_plot_false:nn { first } { 0 }
3143 \__wheelchart_arc_around_text_plot_false:nn { second } { 1 }
3144 }
3145 }
3146 { false }
3147 {
3148 \bool_if:NTF \l__wheelchart_plot_bool
3149 {
3150 \__wheelchart_convex_comb_coord_plot:nnnnnnn
3151 { draw , / wheelchart / arc_style }
3152 { 0 }
3153 { 1 }
3154 { \l__wheelchart_plot_variable_tl }
3155 { 0 }
3156 { \l__wheelchart_arc_pos_fp }
3157 { \l__wheelchart_arc_sep_fp }
3158 }
3159 {
3160 \fp_set:Nn \l__wheelchart_arc_radius_fp
3161 {
3162 \__wheelchart_def_radius:nnn
3163 { \WCcount }
3164 { \l__wheelchart_arc_pos_fp }
3165 { \l__wheelchart_arc_sep_fp + \g__wheelchart_half_ex_over_one_cm_fp }
3166 }
3167 \fp_set:Nn \l__wheelchart_arc_start_angle_fp
3168 {
3169 \__wheelchart_def_angle_plot_false:nnnnn
3170 { \WCcount }
3171 { 0 }
3172 { 0 }
3173 { \l__wheelchart_arc_pos_fp }
3174 { \l__wheelchart_arc_sep_fp + \g__wheelchart_half_ex_over_one_cm_fp }
3175 }
3176 \path
3177 [ draw , / wheelchart / arc_style ]
3178 ( \fp_use:N \l__wheelchart_arc_start_angle_fp \c_colon_str \fp_use:N \l__wheelchart_arc_radius_fp )
3179 arc
3180 [
3181 start~angle = \fp_use:N \l__wheelchart_arc_start_angle_fp ,
3182 end~angle =
3183 \__wheelchart_def_angle_plot_false:nnnnn
3184 { \WCcount }
3185 { 1 }
3186 { 0 }
3187 { \l__wheelchart_arc_pos_fp }
3188 { \l__wheelchart_arc_sep_fp + \g__wheelchart_half_ex_over_one_cm_fp } ,
3189 radius = \fp_use:N \l__wheelchart_arc_radius_fp
3190 ]
3191 ;
3192 }
3193 }
3194 }
3195 {
3196 \pgfkeys
3197 {
3198 / errors / boolean~expected /. expanded =
3199 { arc~around~text }
3200 { \pgfkeysvalueof { / wheelchart / arc~around~text } }
3201 }
3202 }
3203 }
3204 \__wheelchart_inner_and_wheel_data:n { inner }
3205 \__wheelchart_inner_and_wheel_data:n { wheel }
3206 \pgfkeysvalueof { / wheelchart / legend~entry }
3207 }
3208 \bool_if:NT \l__wheelchart_legend_row_bool
3209 { \__wheelchart_def_WClegend: }
3210 \__wheelchart_if_text:nnn { middle } { o }
3211 { \node [ align = center , / wheelchart / middle_style ] at ( 0 , 0 ) { \pgfkeysvalueof { / wheelchart / middle } } ; }
3212 \pgfkeysvalueof { / wheelchart / legend }
3213 \end { scope }
3214 \__wheelchart_caption_and_title:nnnnn
3215 { caption~left } { north~west } { left } { \g__wheelchart_name_tl .south~west } { -1 }
3216 \__wheelchart_caption_and_title:nnnnn
3217 { caption } { north } { center } { \g__wheelchart_name_tl .south -| 0 , 0 } { -1 }
3218 \__wheelchart_caption_and_title:nnnnn
3219 { title~left } { south~west } { left } { \g__wheelchart_name_tl .north~west } { 1 }
3220 \__wheelchart_caption_and_title:nnnnn
3221 { title } { south } { center } { \g__wheelchart_name_tl .north -| 0 , 0 } { 1 }
3222 \end { scope }
3223 }
3224 }
3225 }
3226
3227 \endinput