| 1 |
% Copyright 2019 by Till Tantau |
| 2 |
% |
| 3 |
% This file may be distributed and/or modified |
| 4 |
% |
| 5 |
% 1. under the LaTeX Project Public License and/or |
| 6 |
% 2. under the GNU Public License. |
| 7 |
% |
| 8 |
% See the file doc/generic/pgf/licenses/LICENSE for more details. |
| 9 |
|
| 10 |
\ProvidesFileRCS{pgfmoduledatavisualization.code.tex} |
| 11 |
|
| 12 |
\usepgfmodule{oo,shapes}% |
| 13 |
\usepgflibrary{fpu}% |
| 14 |
|
| 15 |
|
| 16 |
% This module defines the basic framework for data visualization. |
| 17 |
|
| 18 |
% In order to visualize data, you first need data. The format for this |
| 19 |
% data is not specified, indeed, different formats are possible. A |
| 20 |
% data point is created each time the command \pgfdatapoint is |
| 21 |
% used. The "parameters" of the data point are just the current values |
| 22 |
% of the keys or macros in the current scope. |
| 23 |
% |
| 24 |
% A set of data points created using the \pgfdata command. |
| 25 |
% When a data point is created, a number of signals are emitted, see |
| 26 |
% the description of \pgfdatapoint. To actually visualize something, |
| 27 |
% objects should be created that listen to these signals and that |
| 28 |
% handle them. |
| 29 |
% |
| 30 |
% The following class manages a data visualization |
| 31 |
|
| 32 |
\pgfooclass{data visualization} |
| 33 |
{% |
| 34 |
% Class data visualization |
| 35 |
% |
| 36 |
% This class is used to "manage" a data visualization. It provides |
| 37 |
% methods for hooking into the data visualization process and its |
| 38 |
% constructor initializes the signals that are issued during a data |
| 39 |
% visualization. |
| 40 |
% |
| 41 |
% When a data visualization object is created, a whole bunch of |
| 42 |
% signal objects. You should then create objects that connect to |
| 43 |
% these signals. They will be emitted when datapoints come |
| 44 |
% available. |
| 45 |
% |
| 46 |
% It is permissible to have several data visualization objects |
| 47 |
% active at the same time. |
| 48 |
% |
| 49 |
% To use a data visualization object, you should (possibly |
| 50 |
% repeatedly) call the method add data() or the macro \pgfdata. You should also |
| 51 |
% create transformation, mapping and visualization objects. Then, |
| 52 |
% you should, first, call the method survey, which will "survey" the |
| 53 |
% data, allowing the mapping and bounding objects to compute the |
| 54 |
% correct ranges. You may then create further objects based on this |
| 55 |
% data. Then, you should call the "visualize" method, which will |
| 56 |
% invoke the visualization signals for the data points. |
| 57 |
|
| 58 |
|
| 59 |
% These attribute store code that should be executed at certain |
| 60 |
% points. The order is the following: |
| 61 |
% |
| 62 |
% 1. "before survey" code |
| 63 |
% 2. "begin survey" phase signal |
| 64 |
% 3. "at start survey" code |
| 65 |
% 4. data points are processed |
| 66 |
% 5. "at end survey" code |
| 67 |
% 6. "end survey" phase signal |
| 68 |
% 7. "after survey" code |
| 69 |
% |
| 70 |
% The first seven points will be repeated until the method "do |
| 71 |
% another survey" is no longer called during a survey. |
| 72 |
% |
| 73 |
% 8. "before visualization" code |
| 74 |
% 9. "begin visualization" phase signal |
| 75 |
% 10. "at start visualization" code |
| 76 |
% 11. data points are processed once more |
| 77 |
% 12. "at end visualization" code |
| 78 |
% 13. "end visualization" phase signal |
| 79 |
% 14. "after visualization" code |
| 80 |
\attribute before survey;% |
| 81 |
\attribute at start survey;% |
| 82 |
\attribute at end survey;% |
| 83 |
\attribute after survey;% |
| 84 |
\attribute before visualization;% |
| 85 |
\attribute at start visualization;% |
| 86 |
\attribute at end visualization;% |
| 87 |
\attribute after visualization;% |
| 88 |
|
| 89 |
% |
| 90 |
% Survey counts and handling |
| 91 |
% |
| 92 |
|
| 93 |
\attribute survey count=1;% |
| 94 |
% Each time a survey is done before the visualization is done, this |
| 95 |
% count is incremented. Normally, there is only one survey, but |
| 96 |
% objects may request another survey or even more surveys to be |
| 97 |
% done, giving them a chance to setup further internal values. By |
| 98 |
% accessing this count (via the get survey count method), you can |
| 99 |
% find out which survey is currently being done. |
| 100 |
|
| 101 |
\attribute number of surveys=1;% |
| 102 |
% By increasing this count, you can request additional surveys to be |
| 103 |
% done. |
| 104 |
|
| 105 |
|
| 106 |
% Stores the to-be-visualized data |
| 107 |
\attribute data;% |
| 108 |
|
| 109 |
|
| 110 |
% Stores the signal objects |
| 111 |
\attribute prepare datapoint signal;% |
| 112 |
\attribute map datapoint signal;% |
| 113 |
\attribute transform datapoint signal;% |
| 114 |
\attribute visualize datapoint signal;% |
| 115 |
\attribute finish datapoint signal;% |
| 116 |
\attribute survey datapoint signal;% |
| 117 |
\attribute phase signal;% |
| 118 |
\attribute path signal;% |
| 119 |
\attribute direction signal;% |
| 120 |
\attribute style signal;% |
| 121 |
|
| 122 |
|
| 123 |
% Constructor |
| 124 |
% |
| 125 |
% Inits the signals |
| 126 |
\method data visualization() { |
| 127 |
\pgfoonew{prepare datapoint signal}=new signal()% |
| 128 |
\pgfoonew{map datapoint signal}=new signal()% |
| 129 |
\pgfoonew{transform datapoint signal}=new signal()% |
| 130 |
\pgfoonew{visualize datapoint signal}=new signal()% |
| 131 |
\pgfoonew{finish datapoint signal}=new signal()% |
| 132 |
\pgfoonew{survey datapoint signal}=new signal()% |
| 133 |
\pgfoonew{phase signal}=new signal()% |
| 134 |
\pgfoonew{path signal}=new signal()% |
| 135 |
\pgfoonew{direction signal}=new signal()% |
| 136 |
\pgfoonew{style signal}=new signal()% |
| 137 |
% |
| 138 |
% Store this object in a key |
| 139 |
% |
| 140 |
\pgfoothis.get handle(\pgf@dv@me) |
| 141 |
\pgfkeyslet{/pgf/data visualization/obj}\pgf@dv@me |
| 142 |
}% |
| 143 |
|
| 144 |
% The phase signal will emit the following constants: |
| 145 |
\def\pgfdvbeforesurvey{1}% |
| 146 |
\def\pgfdvbeginsurvey{2}% |
| 147 |
\def\pgfdvendsurvey{3}% |
| 148 |
\def\pgfdvaftersurvey{4}% |
| 149 |
\def\pgfdvbeforevisualization{5}% |
| 150 |
\def\pgfdvbeginvisualization{6}% |
| 151 |
\def\pgfdvendvisualization{7}% |
| 152 |
\def\pgfdvaftervisualization{8}% |
| 153 |
|
| 154 |
% The path signale will meit the following constants: |
| 155 |
\def\pgfdvpathmovetotoken{5}% |
| 156 |
\def\pgfdvpathlinetotoken{6}% |
| 157 |
\def\pgfdvdirectionfromtoken{7}% |
| 158 |
\def\pgfdvdirectiontotoken{8}% |
| 159 |
\def\pgfdvdirectionattoken{9}% |
| 160 |
|
| 161 |
% Method |
| 162 |
% |
| 163 |
% Connect the object #1's slot "#2" to the signal named "#3" |
| 164 |
\method connect(#1,#2,#3) { |
| 165 |
\pgfoovalueof{#3}.connect(#1,#2) |
| 166 |
}% |
| 167 |
|
| 168 |
% Method |
| 169 |
% |
| 170 |
% Add data that is to be visualized. The code #1 should call the |
| 171 |
% \pgfdatapoint macro for each data point it creates. |
| 172 |
\method add data(#1) { |
| 173 |
\pgf@dv@stripped@add#1\pgf@stop |
| 174 |
}% |
| 175 |
\def\pgf@dv@stripped@add#1\pgf@stop{% |
| 176 |
\pgfooappend{data}{#1}% |
| 177 |
}% |
| 178 |
|
| 179 |
|
| 180 |
% Setters |
| 181 |
\method before survey(#1) { |
| 182 |
\pgfooappend{before survey}{#1} |
| 183 |
}% |
| 184 |
\method at start survey(#1) { |
| 185 |
\pgfooappend{at start survey}{#1} |
| 186 |
}% |
| 187 |
\method before visualization(#1) { |
| 188 |
\pgfooappend{before visualization}{#1} |
| 189 |
}% |
| 190 |
\method at start visualization(#1) { |
| 191 |
\pgfooappend{at start visualization}{#1} |
| 192 |
}% |
| 193 |
|
| 194 |
% Method |
| 195 |
\method at end survey(#1) { |
| 196 |
\pgfooprefix{at end survey}{#1} |
| 197 |
}% |
| 198 |
\method after survey(#1) { |
| 199 |
\pgfooprefix{after survey}{#1} |
| 200 |
}% |
| 201 |
\method at end visualization(#1) { |
| 202 |
\pgfooprefix{at end visualization}{#1} |
| 203 |
}% |
| 204 |
\method after visualization(#1) { |
| 205 |
\pgfooprefix{after visualization}{#1} |
| 206 |
}% |
| 207 |
|
| 208 |
|
| 209 |
% Method |
| 210 |
% |
| 211 |
% Copy the signals to macros. This is just for efficiency (ha!) |
| 212 |
\method prepare signal macros() { |
| 213 |
\pgfooget{prepare datapoint signal}\pgf@signalpreparedatapoint |
| 214 |
\pgfooget{map datapoint signal}\pgf@signalmapdatapoint |
| 215 |
\pgfooget{transform datapoint signal}\pgf@signaltransformdatapoint |
| 216 |
\pgfooget{visualize datapoint signal}\pgf@signalvisualizedatapoint |
| 217 |
\pgfooget{finish datapoint signal}\pgf@signalfinishdatapoint |
| 218 |
\pgfooget{survey datapoint signal}\pgf@signalsurveydatapoint |
| 219 |
\pgfooget{phase signal}\pgf@signalphase |
| 220 |
\pgfooget{path signal}\pgf@signalpath |
| 221 |
\pgfooget{direction signal}\pgf@signaldirection |
| 222 |
\pgfooget{style signal}\pgf@signalstyle |
| 223 |
}% |
| 224 |
|
| 225 |
|
| 226 |
% Survey method |
| 227 |
% |
| 228 |
% Call this method to "survey" the data. This should be done before |
| 229 |
% the "visualize" method is called. |
| 230 |
\method survey() { |
| 231 |
% Survey phase. |
| 232 |
\let\pgfdatapoint=\pgfdatapoint@surveyphase% |
| 233 |
\pgfoothis.prepare signal macros() |
| 234 |
\pgfooset{survey count}{1} |
| 235 |
\pgfutil@loop |
| 236 |
\[email protected](\pgfdvbeforesurvey) |
| 237 |
\pgfoovalueof{before survey}% |
| 238 |
\[email protected](\pgfdvbeginsurvey) |
| 239 |
\pgfoovalueof{at start survey} |
| 240 |
\pgfoovalueof{data}% |
| 241 |
\pgfoovalueof{at end survey} |
| 242 |
\[email protected](\pgfdvendsurvey)% |
| 243 |
\pgfoovalueof{after survey} |
| 244 |
\[email protected](\pgfdvaftersurvey) |
| 245 |
\c@pgf@counta=\pgfoovalueof{survey count}\relax |
| 246 |
\c@pgf@countb=\pgfoovalueof{number of surveys}\relax |
| 247 |
\ifnum\c@pgf@counta<\c@pgf@countb |
| 248 |
\advance\c@pgf@counta by1\relax |
| 249 |
\pgfooeset{survey count}{\the\c@pgf@counta} |
| 250 |
\pgfutil@repeat |
| 251 |
}% |
| 252 |
|
| 253 |
% Getter |
| 254 |
\method get survey count(#1) { |
| 255 |
\pgfooget{survey count}{#1} |
| 256 |
}% |
| 257 |
|
| 258 |
% Request another survey to be done |
| 259 |
\method do an additional survey() { |
| 260 |
\c@pgf@counta=\pgfoovalueof{number of surveys}\relax |
| 261 |
\advance\c@pgf@counta by1\relax |
| 262 |
\pgfooeset{number of surveys}{\the\c@pgf@counta} |
| 263 |
}% |
| 264 |
|
| 265 |
% Visualize method |
| 266 |
% |
| 267 |
% This method will cause the actual visualization. |
| 268 |
\method visualize() { |
| 269 |
% Visualization phase. |
| 270 |
\let\pgfdatapoint=\pgfdatapoint@visualizationphase% |
| 271 |
\pgfoothis.prepare signal macros() |
| 272 |
\[email protected](\pgfdvbeforevisualization)% |
| 273 |
\pgfoovalueof{before visualization} |
| 274 |
\[email protected](\pgfdvbeginvisualization)% |
| 275 |
\pgfoovalueof{at start visualization} |
| 276 |
\pgfoovalueof{data}% |
| 277 |
\pgfoovalueof{at end visualization} |
| 278 |
\[email protected](\pgfdvendvisualization)% |
| 279 |
\pgfoovalueof{after visualization} |
| 280 |
\[email protected](\pgfdvaftervisualization)% |
| 281 |
}% |
| 282 |
}% |
| 283 |
|
| 284 |
|
| 285 |
% |
| 286 |
% The data point keys |
| 287 |
% |
| 288 |
% Unlike other keys, the subkeys of /data point/ can simply be set |
| 289 |
% directly. If the key has not been initialized, it will automatically |
| 290 |
% be. |
| 291 |
\pgfkeys{/data point/.unknown/.code={% |
| 292 |
\pgfkeyssetvalue{/data point/\pgfkeyscurrentname}{#1} |
| 293 |
}, |
| 294 |
}% |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
% Create and handle a data point |
| 300 |
% |
| 301 |
% Description: |
| 302 |
% |
| 303 |
% This command is called by the survey and the visualize methods |
| 304 |
% whenever a complete data point has been produced. Depending on the |
| 305 |
% current circumstances, different signals will be emitted. |
| 306 |
% |
| 307 |
% The data that is represented by the data point is not given as a |
| 308 |
% parameter. Rather, it is stored in macros and keys, that is, the |
| 309 |
% data point is conceptually given by the settings of all the keys and |
| 310 |
% macros in the local scope. |
| 311 |
% |
| 312 |
% There are two phases to data processing: In the survey phase data |
| 313 |
% points are produced and handled in order to find out things like |
| 314 |
% their number or the minimum and maximum values of attributes, so |
| 315 |
% that axes and picture sizes can be prepared correctly. In the |
| 316 |
% visualization phase, data point are actually shown. |
| 317 |
% |
| 318 |
% During the survey phase, for each data point the signal |
| 319 |
% "surveydatapoint" is emitted. |
| 320 |
% |
| 321 |
% During the visualization phase, more signals are emitted. A prepare |
| 322 |
% signal is emitted first, giving all objects a |
| 323 |
% chance to "prepare" for the data point. Note that it is permissible |
| 324 |
% for an object to manipulate the data point here (and also |
| 325 |
% in later on). |
| 326 |
% |
| 327 |
% Next, the command \pgfdvmapdatapointtocanvas is called. Mainly, |
| 328 |
% the effect of this command is to setup the keys /data point/canvas x |
| 329 |
% and /data point/canvas y, see the description of this command for |
| 330 |
% more details. |
| 331 |
% |
| 332 |
% The next step consists of signaling "visualize data point". Objects |
| 333 |
% listening to this will cause some form of visualization of the |
| 334 |
% data point to occur. |
| 335 |
% |
| 336 |
% Before the visualization is started, it is checked whether the key |
| 337 |
% /data point/name is set (to a non-empty value). If so, |
| 338 |
% a coordinate is created with the given canvas x and y values and |
| 339 |
% this key's value as name. |
| 340 |
% |
| 341 |
% Finally, finish data point allows objects to do any final processing |
| 342 |
% of the data point. |
| 343 |
|
| 344 |
\def\pgfdatapoint@surveyphase{% |
| 345 |
\[email protected]()% |
| 346 |
\[email protected]()% |
| 347 |
\[email protected]()% |
| 348 |
}% |
| 349 |
|
| 350 |
\def\pgfdatapoint@visualizationphase{% |
| 351 |
\[email protected]()% |
| 352 |
\pgfdvmapdatapointtocanvas% |
| 353 |
\pgfkeysifdefined{/data point/name} |
| 354 |
{% |
| 355 |
\pgfcoordinate{\pgfkeysvalueof{/data point/name}}{\pgfpointdvdatapoint}% |
| 356 |
}{}% |
| 357 |
\[email protected]()% |
| 358 |
\[email protected]()% |
| 359 |
}% |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
% Compute a position of a data point |
| 364 |
% |
| 365 |
% Description: |
| 366 |
% |
| 367 |
% This command uses a special signal to compute the position where a |
| 368 |
% data point should be visualized on the canvas. In detail, the |
| 369 |
% following happens: |
| 370 |
% |
| 371 |
% A local scope is created and the |
| 372 |
% transformation matrix is reset. Then, two signals are emitted: First, |
| 373 |
% "map data points" and then "transform data point". The first |
| 374 |
% lets listening objects "map" the object by setting up |
| 375 |
% attributes of the data point. The second asks objects |
| 376 |
% listening to this signal to transform the current transformation |
| 377 |
% matrix. After the signals, we compute where |
| 378 |
% the origin lies inside this transformed coordinate system. Then the |
| 379 |
% two keys /data point/canvas x and /data point/canvas y are set to |
| 380 |
% the values of this position. The local scope ends (but the settings |
| 381 |
% of the keys persist by a bit of magic), thus restoring the |
| 382 |
% transformation matrix to its original value. |
| 383 |
|
| 384 |
\def\pgfdvmapdatapointtocanvas{% |
| 385 |
{% |
| 386 |
\pgfpointdvlocaldatapoint |
| 387 |
% Smuggle outside group |
| 388 |
\expandafter% |
| 389 |
}% |
| 390 |
\edef\pgf@marshal{% |
| 391 |
\noexpand\pgfkeyssetvalue{/data point/canvas x}{\the\pgf@x} |
| 392 |
\noexpand\pgfkeyssetvalue{/data point/canvas y}{\the\pgf@y} |
| 393 |
}% |
| 394 |
\pgf@marshal% |
| 395 |
}% |
| 396 |
|
| 397 |
% Help functions for locating a canvas data point |
| 398 |
% |
| 399 |
% Description: |
| 400 |
% |
| 401 |
% The first function returns the data point computed by a |
| 402 |
% canvasposition... call. |
| 403 |
|
| 404 |
\def\pgfpointdvdatapoint{% |
| 405 |
\pgfqpoint{\pgfkeysvalueof{/data point/canvas x}}{\pgfkeysvalueof{/data point/canvas y}}% |
| 406 |
}% |
| 407 |
|
| 408 |
\def\pgfpointdvlocaldatapoint{% |
| 409 |
{% |
| 410 |
% only returns the data point in \pgf@x and \pgf@y, does not set |
| 411 |
% canvas x and canvas y |
| 412 |
\[email protected]()% |
| 413 |
\pgftransformreset% |
| 414 |
\[email protected]()% |
| 415 |
\pgfpointtransformed{\pgfpointorigin}% |
| 416 |
}% |
| 417 |
}% |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
% |
| 422 |
% Special path constructions commands |
| 423 |
% |
| 424 |
% |
| 425 |
% The following commands are used to construct paths based on |
| 426 |
% datapoints. |
| 427 |
% |
| 428 |
% Normally, all these methods need to do is to compute the current |
| 429 |
% canvas position of the current data point and then do a moveto, |
| 430 |
% lineto or some other operation to this position. |
| 431 |
% |
| 432 |
% However, when the coordinate system is weird, like with polar |
| 433 |
% coordinates or spherical or log-polar coordinate or whatever, a |
| 434 |
% straight line "along an attribute" is no longer a straight line. |
| 435 |
% In this case, two actions can be taken: |
| 436 |
% |
| 437 |
% 1. The problem can be ignored, resulting in a wrong line. |
| 438 |
% 2. Some clever algorithm kicks in an replaces the straight line by |
| 439 |
% the correct replacement. |
| 440 |
% |
| 441 |
% As always, when a computer tries to be clever, things can go |
| 442 |
% wrong... Nevertheless, some support for the second method is |
| 443 |
% given. This works as follows: Objects can register to the data |
| 444 |
% visualization path signal. This signal is emitted every time the |
| 445 |
% lineto or moveto commands are executed. If an object reacts to such |
| 446 |
% a command and handles it, it should set |
| 447 |
% \pgfdvhandledtrue. |
| 448 |
|
| 449 |
\newif\ifpgfdvhandled |
| 450 |
|
| 451 |
\def\pgfdv@generic#1#2#3{% |
| 452 |
{% |
| 453 |
\pgfdvhandledfalse% |
| 454 |
\[email protected]()% |
| 455 |
#1.emit(#2)% |
| 456 |
\ifpgfdvhandled% |
| 457 |
\else% |
| 458 |
\pgf@process{% |
| 459 |
\pgftransformreset% |
| 460 |
\[email protected]()% |
| 461 |
\pgfpointtransformed{\pgfpointorigin}% |
| 462 |
}% |
| 463 |
#3{}% |
| 464 |
\fi% |
| 465 |
}% |
| 466 |
}% |
| 467 |
|
| 468 |
|
| 469 |
% Handle a moveto |
| 470 |
% |
| 471 |
% This command has no parameters since the target of the moveto is |
| 472 |
% given by the canvas position of the current local data point. |
| 473 |
\def\pgfpathdvmoveto{% |
| 474 |
\pgfdv@generic{\pgf@signalpath}{\pgfdvpathmovetotoken}{\pgfpathmoveto} |
| 475 |
}% |
| 476 |
|
| 477 |
|
| 478 |
% Handle a lineto |
| 479 |
% |
| 480 |
% This command has no parameters since the target of the moveto is |
| 481 |
% given by the canvas position of the current local data point. |
| 482 |
\def\pgfpathdvlineto{% |
| 483 |
\pgfdv@generic{\pgf@signalpath}{\pgfdvpathlinetotoken}{\pgfpathlineto} |
| 484 |
}% |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
% Compute a normalized vector at the current point pointing along a |
| 489 |
% line from #1 to #2. |
| 490 |
% |
| 491 |
% #1 = code for setting the attributes of the first point |
| 492 |
% #2 = code for setting the attributes of the second point |
| 493 |
% |
| 494 |
% The current point should be a point on a line from #1 to |
| 495 |
% #2. Both points as well as the current point are |
| 496 |
% localized on the canvas and a vector pointing from the first point |
| 497 |
% to the second one is returned. However, for instance in polar |
| 498 |
% coordinates the vector may actually "point along" the angle axis. |
| 499 |
% |
| 500 |
% Internally, this command first sets up the first data point and then |
| 501 |
% emits a "direction" signal with the \pgfdvpathdirectionfromtoken set and |
| 502 |
% then sets up the second point and emits the corresponding |
| 503 |
% ...totoken. Finally, the \pgfdvpathdirectionattoken is emitted. |
| 504 |
% |
| 505 |
|
| 506 |
\def\pgfpointdvdirection#1#2{% |
| 507 |
{ |
| 508 |
{ |
| 509 |
#1 |
| 510 |
\pgfdv@generic{\pgf@signaldirection}{\pgfdvdirectionfromtoken}{\xdef\pgf@dv@from{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}} |
| 511 |
} |
| 512 |
{ |
| 513 |
#2 |
| 514 |
\pgfdv@generic{\pgf@signaldirection}{\pgfdvdirectiontotoken}{\xdef\pgf@dv@to{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}} |
| 515 |
} |
| 516 |
{\pgfdv@generic{\pgf@signaldirection}{\pgfdvdirectionattoken}{% |
| 517 |
\pgf@process{ |
| 518 |
\pgfpointnormalised{% |
| 519 |
\pgfpointdiff{\pgf@dv@from}{\pgf@dv@to} |
| 520 |
} |
| 521 |
}}} |
| 522 |
} |
| 523 |
}% |
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
% |
| 530 |
% |
| 531 |
% Data parsing and formatting |
| 532 |
% |
| 533 |
% |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
% Run the rendering pipeline on a dataset and/or save the dataset. |
| 538 |
% |
| 539 |
% #1 = options with path /pgf/data/ |
| 540 |
% #2 = optionally data given inline in curly braces. |
| 541 |
% |
| 542 |
% Description: |
| 543 |
% |
| 544 |
% This command is used to define a data set. For a single data |
| 545 |
% visualization, multiple data sets can be defined, they will |
| 546 |
% accumulate. Data can be in different formats, as specified by the |
| 547 |
% "format" key, and you can define new formats. |
| 548 |
% |
| 549 |
% The settings of the following keys are important: |
| 550 |
% |
| 551 |
% /pgf/data visualization/obj |
| 552 |
% contains a handle to the dv-object |
| 553 |
% |
| 554 |
% /pgf/data/format |
| 555 |
% stores the format (see below) |
| 556 |
% |
| 557 |
% /pgf/data/read from file |
| 558 |
% determines where the data is. |
| 559 |
% |
| 560 |
% /pgf/data/store in group |
| 561 |
% when nonempty, the data is stored here instead of being fed to the |
| 562 |
% rendering pipeline |
| 563 |
% |
| 564 |
% /pgf/data/use group |
| 565 |
% when nonempty, data that has previously been stored here using |
| 566 |
% |define group| is read from here and all other keys are ignored |
| 567 |
% |
| 568 |
% If "read from file" is empty, the data is stored in the argument that |
| 569 |
% follows. Otherwise, the data is read from the specified source file. |
| 570 |
% This data is stored in an internal variable, which is local to the |
| 571 |
% current group. |
| 572 |
% |
| 573 |
% After the group, the key "/pgf/data/continue code" will be |
| 574 |
% executed. |
| 575 |
% |
| 576 |
% When the data is actually used later on (during a survey or a |
| 577 |
% visualization), independently of what source is used, a format |
| 578 |
% handler is started for each data set. This works as follows: first, |
| 579 |
% the handler's startup code is executed. Then for each line of the |
| 580 |
% data file/the data given inline, the line handler function is |
| 581 |
% called. Finally, the data format end handler is called. |
| 582 |
% |
| 583 |
% The format handler's job is to call \pgfdatapoint each time a |
| 584 |
% complete data point has been produced. |
| 585 |
% |
| 586 |
% Example: |
| 587 |
% |
| 588 |
% \pgfoonew \dv=new data visualization() |
| 589 |
% \pgfoonew \obj=new attribute mapper(...) |
| 590 |
% ... |
| 591 |
% |
| 592 |
% \pgfkeys{/pgf/data/.cd, |
| 593 |
% column 1=dax/low, |
| 594 |
% column 2=dax/high, |
| 595 |
% column 3=dax/entry, |
| 596 |
% column 4=dax/exit} |
| 597 |
% |
| 598 |
% \pgfdata[format=space separated columns] |
| 599 |
% { |
| 600 |
% % today |
| 601 |
% 2000 2300 2100 2200 |
| 602 |
% 2000 2350 2200 2500 |
| 603 |
% 2200 2300 2250 2260 |
| 604 |
% 1800 2260 2260 1900 |
| 605 |
% 2000 2300 2100 2200 |
| 606 |
% } |
| 607 |
% |
| 608 |
% \pgfdata[format=comma separated columns] |
| 609 |
% { |
| 610 |
% % yesterday |
| 611 |
% 2000, 2350, 2200, 2250 |
| 612 |
% 2200, 2300, 2250, 2260 |
| 613 |
% } |
| 614 |
% |
| 615 |
% \pgfdata[read from file=data.csv,format=comma separated columns] |
| 616 |
% |
| 617 |
% \dv.survey() |
| 618 |
% \dv.visualize() |
| 619 |
|
| 620 |
\def\pgfdata{\pgfutil@ifnextchar[{\pgf@datagroup@data@opt}{\pgf@datagroup@data@opt[]}}%}% |
| 621 |
\def\pgf@datagroup@data@opt[#1]{% |
| 622 |
% Ok, add one data thing... |
| 623 |
\begingroup% |
| 624 |
\pgfkeys{/pgf/data/.cd,/pgf/every data/.try,#1}% |
| 625 |
\pgfkeysgetvalue{/pgf/data/continue code}\pgf@dv@cont@code% |
| 626 |
\global\let\pgf@dv@cont@code\pgf@dv@cont@code% |
| 627 |
\pgfkeysgetvalue{/pgf/data/use group}\pgf@dv@use@group% |
| 628 |
\ifx\pgf@dv@use@group\pgfutil@empty% |
| 629 |
\pgf@dv@do@adddata{\pgfkeysvalueof{/pgf/data visualization/obj}.add data(\pgf@do@data{#1})}% |
| 630 |
\expandafter\pgf@datagroup@data@opt@cont% |
| 631 |
\else% |
| 632 |
\expandafter\ifx\csname pgf@dv@group@@\pgf@dv@use@group\endcsname\relax% |
| 633 |
\pgferror{Undefined data group '\pgf@dv@use@group'}% |
| 634 |
\else% |
| 635 |
{% |
| 636 |
\pgfkeys{/pgf/data/define group/.code=}% no redefinitions during use |
| 637 |
\csname pgf@dv@group@@\pgf@dv@use@group\endcsname% |
| 638 |
}% |
| 639 |
\fi% |
| 640 |
\endgroup% |
| 641 |
\expandafter\pgf@dv@cont@code% |
| 642 |
\fi% |
| 643 |
}% |
| 644 |
\def\pgf@datagroup@data@opt@cont{% |
| 645 |
\pgfkeysgetvalue{/pgf/data/format}\pgf@dv@format% |
| 646 |
\expandafter\let\expandafter\pgf@dv@format@catcodes\csname pgfdv@format@\pgf@dv@format @catcodes\endcsname% |
| 647 |
\ifx\pgf@dv@format@catcodes\relax |
| 648 |
\pgferror{Unknown data format '\pgf@dv@format'}% |
| 649 |
\else% |
| 650 |
\pgfkeysgetvalue{/pgf/data/read from file}\pgf@dv@source% |
| 651 |
\ifx\pgf@dv@source\pgfutil@empty% |
| 652 |
\let\pgf@next\pgf@datagroup@grab@inline% |
| 653 |
\else% |
| 654 |
\let\pgf@next\pgf@datagroup@grab@external% |
| 655 |
\fi% |
| 656 |
\pgf@next% |
| 657 |
}% |
| 658 |
|
| 659 |
\def\pgf@datagroup@grab@inline{% |
| 660 |
\pgfutil@ifnextchar\bgroup{% |
| 661 |
\begingroup% |
| 662 |
\catcode`\^^M=\active% |
| 663 |
\pgf@dv@format@catcodes% |
| 664 |
\pgf@datagroup@grab@@inline}% |
| 665 |
{\pgferror{Opening brace expected}}% |
| 666 |
}% |
| 667 |
\def\pgf@datagroup@grab@external{% |
| 668 |
\fi% |
| 669 |
\endgroup% |
| 670 |
\pgf@dv@do@adddata{\pgfkeysvalueof{/pgf/data visualization/obj}.add data({{{\pgf@datagroup@do@external}}})}% |
| 671 |
\pgf@dv@cont@code% |
| 672 |
}% |
| 673 |
|
| 674 |
\def\pgf@dv@do@adddata#1{% |
| 675 |
\pgfkeysgetvalue{/pgf/data/store in group}\pgf@dv@temp% |
| 676 |
\ifx\pgf@dv@temp\pgfutil@empty% |
| 677 |
#1% |
| 678 |
\else% |
| 679 |
\expandafter\pgfutil@g@addto@macro\csname pgf@dv@group@@\pgf@dv@temp\endcsname{#1}% |
| 680 |
\fi% |
| 681 |
}% |
| 682 |
|
| 683 |
{\catcode`\^=7 \catcode`\^^M=13 |
| 684 |
\gdef\pgf@datagroup@grab@@inline#1{% |
| 685 |
\endgroup% |
| 686 |
\pgf@dv@do@adddata{\pgfkeysvalueof{/pgf/data visualization/obj}.add data({{{\pgf@datagroup@do@inline#1^^M\pgf@@eol}}})}% |
| 687 |
\fi% |
| 688 |
\endgroup% |
| 689 |
\pgf@dv@cont@code% |
| 690 |
}% |
| 691 |
}% |
| 692 |
\def\pgf@@eol{\pgf@eol}% |
| 693 |
|
| 694 |
\def\pgf@do@data#1#2{% |
| 695 |
\begingroup% |
| 696 |
\pgfkeys{/pgf/data/.cd,/pgf/every data/.try,#1}% |
| 697 |
\pgfkeysgetvalue{/pgf/data/format}\pgf@dv@format% |
| 698 |
\expandafter\let\expandafter\pgf@dv@format@line\csname pgfdv@format@\pgf@dv@format @line\endcsname% |
| 699 |
\expandafter\let\expandafter\pgf@dv@format@emptyline\csname pgfdv@format@\pgf@dv@format @empty\endcsname% |
| 700 |
\csname pgfdv@format@\pgfkeysvalueof{/pgf/data/format}@startup\endcsname% |
| 701 |
#2% |
| 702 |
\csname pgfdv@format@\pgfkeysvalueof{/pgf/data/format}@end\endcsname% |
| 703 |
\endgroup% |
| 704 |
}% |
| 705 |
|
| 706 |
|
| 707 |
% |
| 708 |
% Read external file |
| 709 |
% |
| 710 |
|
| 711 |
\def\pgf@datagroup@do@external{% |
| 712 |
\csname pgfdv@format@\pgfkeysvalueof{/pgf/data/format}@catcodes\endcsname% |
| 713 |
\immediate\openin\r@pgf@reada=\pgfkeysvalueof{/pgf/data/read from file} % |
| 714 |
\ifeof\r@pgf@reada\relax |
| 715 |
\pgferror{Data file '\pgfkeysvalueof{/pgf/data/read from file}' not found}% |
| 716 |
\else |
| 717 |
\pgf@datagroup@readline% |
| 718 |
\fi |
| 719 |
\immediate\closein\r@pgf@reada% |
| 720 |
}% |
| 721 |
|
| 722 |
\def\pgf@partext{\par}% |
| 723 |
\def\pgf@datagroup@readline{% |
| 724 |
\endlinechar=-1 % suppress white space at end; this is local to `\pgfdata` |
| 725 |
\immediate\read\r@pgf@reada to \pgf@temp% |
| 726 |
\ifx\pgf@temp\pgf@partext% |
| 727 |
\pgf@dv@format@emptyline% |
| 728 |
\else% |
| 729 |
\ifx\pgf@temp\pgfutil@empty% |
| 730 |
\pgf@dv@format@emptyline% |
| 731 |
\else% |
| 732 |
\expandafter\pgf@dv@format@line\pgf@temp\pgfeol% |
| 733 |
\fi% |
| 734 |
\fi% |
| 735 |
\ifeof\r@pgf@reada\else\expandafter\pgf@datagroup@readline\fi% |
| 736 |
}% |
| 737 |
|
| 738 |
|
| 739 |
% |
| 740 |
% Read inline data |
| 741 |
% |
| 742 |
|
| 743 |
\def\pgf@datagroup@do@inline{% |
| 744 |
\pgf@dv@handle@line% |
| 745 |
}% |
| 746 |
|
| 747 |
{\catcode`\^=7 \catcode`\^^M=13 |
| 748 |
\gdef\pgf@dv@handle@line{% |
| 749 |
\pgfutil@ifnextchar^^M{\pgf@dv@format@emptyline\expandafter\pgf@dv@handle@line\pgfutil@gobble}% |
| 750 |
{\pgfutil@ifnextchar\pgf@@eol{\pgfutil@gobble}{\pgf@dv@handle@nonemptyline}}% |
| 751 |
}% |
| 752 |
\gdef\pgf@dv@handle@nonemptyline#1^^M{% |
| 753 |
\pgf@dv@format@line#1\pgfeol% |
| 754 |
\pgf@dv@handle@line% |
| 755 |
}% |
| 756 |
}% |
| 757 |
|
| 758 |
\pgfkeys{ |
| 759 |
/pgf/data/data visualization obj/.initial=\undefined, |
| 760 |
/pgf/data/format/.initial=table,% the default format |
| 761 |
/pgf/data/read from file/.initial=, |
| 762 |
/pgf/data/inline/.style={read from file=}, |
| 763 |
/pgf/data/continue code/.initial=, |
| 764 |
/pgf/data/store in group/.initial=, |
| 765 |
/pgf/data/new group/.code={\expandafter\global\expandafter\let\csname pgf@dv@group@@#1\endcsname\pgfutil@empty}, |
| 766 |
/pgf/data/use group/.initial=, |
| 767 |
}% |
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
% Define a data format |
| 775 |
% |
| 776 |
% #1 = format name |
| 777 |
% #2 = catcode code |
| 778 |
% #3 = startup code |
| 779 |
% #4 = line arguments |
| 780 |
% #5 = line code |
| 781 |
% #6 = empty line code |
| 782 |
% #7 = end code |
| 783 |
% |
| 784 |
% Description: |
| 785 |
% |
| 786 |
% This command defines a new data format for data visualization. When |
| 787 |
% a data set is visualized and the format is set to #1, this handler |
| 788 |
% is used to parse the data. |
| 789 |
% |
| 790 |
% In detail, the \pgfdata command will select a source. Before this |
| 791 |
% source is read, #2 will be executed to setup the |
| 792 |
% catcodes. Additionally, each time the data is parsed, #3 will be |
| 793 |
% called. Then, for each nonempty line of the source, the |
| 794 |
% command #5 is executed, where the line will be matched against the |
| 795 |
% argument pattern given in #4. For empty lines, #6 will be executed |
| 796 |
% instead. At the end of the source, #7 will be executed. |
| 797 |
|
| 798 |
\def\pgfdeclaredataformat#1#2#3#4#5#6#7{% |
| 799 |
\expandafter\def\csname pgfdv@format@#1@catcodes\endcsname{#2}% |
| 800 |
\expandafter\def\csname pgfdv@format@#1@startup\endcsname{#3}% |
| 801 |
\expandafter\def\csname pgfdv@format@#1@line\endcsname#4\pgfeol{#5}% |
| 802 |
\expandafter\def\csname pgfdv@format@#1@empty\endcsname{#6}% |
| 803 |
\expandafter\def\csname pgfdv@format@#1@end\endcsname{#7}% |
| 804 |
}% |
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
% |
| 809 |
% Predefined standard formats |
| 810 |
% |
| 811 |
|
| 812 |
% TeX code format |
| 813 |
% |
| 814 |
% Description: |
| 815 |
% |
| 816 |
% The lines of the data set are assumed to contain executable TeX |
| 817 |
% code that will call \pgfdatapoint. |
| 818 |
% |
| 819 |
% Example: |
| 820 |
% |
| 821 |
% \pgfdatavisualizationrender[format=TeX code] |
| 822 |
% \dataset{ |
| 823 |
% \pgfkeyssetvalue{/data point/x}{5} |
| 824 |
% \pgfkeyssetvalue{/data point/y}{5} |
| 825 |
% \pgfdatapoint |
| 826 |
% \pgfkeyssetvalue{/data point/x}{6} |
| 827 |
% \pgfkeyssetvalue{/data point/y}{6} |
| 828 |
% \pgfdatapoint |
| 829 |
% } |
| 830 |
|
| 831 |
\pgfdeclaredataformat{TeX code}{}{}{#1}{#1 }{}{}% |
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
% Key-value lines format |
| 836 |
% |
| 837 |
% Description: |
| 838 |
% |
| 839 |
% The lines of the data set are passed to \pgfkeys with the path set |
| 840 |
% to /data point. |
| 841 |
% |
| 842 |
% Example: |
| 843 |
% |
| 844 |
% \data[format=named] { |
| 845 |
% x=5, y=6, hi=9 |
| 846 |
% x=7, y=6, lo=10 |
| 847 |
% } |
| 848 |
|
| 849 |
\pgfdeclaredataformat{named}{}{}{#1}{\pgf@dv@parse@named#1,\pgf@stop}{}{}% |
| 850 |
\def\pgf@dv@parse@named{% |
| 851 |
\pgfutil@ifnextchar\pgf@stop{\pgfdatapoint\pgfutil@gobble}{\pgf@dv@parse@named@} |
| 852 |
}% |
| 853 |
\def\pgf@dv@parse@named@#1=#2,#3\pgf@stop{% |
| 854 |
\foreach \pgf@dv@temp in {#2} {% |
| 855 |
\def\pgf@dv@tempb{/data point/#1=}% |
| 856 |
\expandafter\expandafter\expandafter\pgfkeys% |
| 857 |
\expandafter\expandafter\expandafter{\expandafter\pgf@dv@tempb\pgf@dv@temp}% |
| 858 |
\pgf@dv@parse@named#3\pgf@stop% |
| 859 |
} |
| 860 |
}% |
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
% Table format |
| 867 |
% |
| 868 |
% Description: |
| 869 |
% |
| 870 |
% A table consists of a head line, which contains the attribute names |
| 871 |
% of the values that will be found in the following lines. Each line |
| 872 |
% (except for the headline) contains one data point. |
| 873 |
% |
| 874 |
% Inside each line the data points are separated by a separator like a |
| 875 |
% comma or a space or a colon. The separator can be configured using |
| 876 |
% the key /pgf/data/separator (leave the separator empty or set it to |
| 877 |
% \space for a space as separator). The default separator is a comma. |
| 878 |
% |
| 879 |
% Some tables will miss the headline. In this case, using the |
| 880 |
% /pgf/data/headline key you can provide a headline yourself. |
| 881 |
% |
| 882 |
% Example: |
| 883 |
% |
| 884 |
% \data[format=table] { |
| 885 |
% x y |
| 886 |
% 10 5 |
| 887 |
% 11 6 |
| 888 |
% 6 7 |
| 889 |
% } |
| 890 |
% |
| 891 |
% \data[format=table,separator={,}] { |
| 892 |
% x, y |
| 893 |
% 10, 5 |
| 894 |
% 11, 6 |
| 895 |
% 6, 7 |
| 896 |
% } |
| 897 |
% |
| 898 |
% \data[format=table,headline=x y] { |
| 899 |
% 10 5 |
| 900 |
% 11 6 |
| 901 |
% 6 7 |
| 902 |
% } |
| 903 |
|
| 904 |
\pgfdeclaredataformat{table} |
| 905 |
{} % no catcodes |
| 906 |
{ |
| 907 |
\pgfkeysgetvalue{/pgf/data/headline}\pgf@dv@headline |
| 908 |
\pgfkeysgetvalue{/pgf/data/separator}\pgf@dv@separator |
| 909 |
\ifx\pgf@dv@separator\pgfutil@empty |
| 910 |
\let\pgf@dv@separator\space |
| 911 |
\fi |
| 912 |
\ifx\pgf@dv@separator\pgf@dv@spacetext |
| 913 |
\let\pgf@dv@separator\space |
| 914 |
\fi |
| 915 |
\expandafter\def\expandafter\pgf@dv@till@separator% |
| 916 |
\expandafter##\expandafter1\pgf@dv@separator{\pgf@dv@table@handle{##1}} |
| 917 |
\expandafter\def\expandafter\pgf@dv@till@separator@head% |
| 918 |
\expandafter##\expandafter1\pgf@dv@separator{\pgf@dv@head@handle{##1}} |
| 919 |
\ifx\pgf@dv@headline\pgfutil@empty |
| 920 |
% Ok, read headline from file |
| 921 |
\pgfdv@firstlinetrue |
| 922 |
\else |
| 923 |
% Headline already set |
| 924 |
\pgfdv@firstlinefalse |
| 925 |
\expandafter\pgf@dv@parse@headline\expandafter{\pgf@dv@headline} |
| 926 |
\fi |
| 927 |
} |
| 928 |
{#1} % special line pattern, so read everything |
| 929 |
{ |
| 930 |
\ifpgfdv@firstline |
| 931 |
\pgfdv@firstlinefalse |
| 932 |
\pgf@dv@parse@headline{#1} |
| 933 |
\else |
| 934 |
{ |
| 935 |
\c@pgf@counta=0\relax% keep track of attribute number |
| 936 |
\def\pgf@marshal{\pgf@dv@parse@table#1} |
| 937 |
\expandafter\expandafter\expandafter\pgf@marshal% |
| 938 |
\expandafter\pgf@dv@separator\expandafter\pgfeol\pgf@dv@separator |
| 939 |
\pgfdatapoint |
| 940 |
} |
| 941 |
\fi |
| 942 |
} |
| 943 |
{}% ignore empty lines |
| 944 |
{}% no special end code |
| 945 |
|
| 946 |
\newif\ifpgfdv@firstline |
| 947 |
|
| 948 |
\pgfkeys{ |
| 949 |
/pgf/data/separator/.initial={,}, |
| 950 |
/pgf/data/headline/.initial= |
| 951 |
}% |
| 952 |
\def\pgf@dv@spacetext{\space}% |
| 953 |
|
| 954 |
\def\pgf@dv@parse@table{% |
| 955 |
\pgfutil@ifnextchar"% Special, but ignored right now... |
| 956 |
{\pgferror{csv with quotes not yet implemented}} |
| 957 |
{\pgf@dv@till@separator} |
| 958 |
}% |
| 959 |
\def\pgf@dv@table@handle#1{% |
| 960 |
\def\pgf@temp{#1}% |
| 961 |
\ifx\pgf@temp\pgfeoltext% |
| 962 |
% Bingo! Stop |
| 963 |
\let\pgf@next=\relax% |
| 964 |
\else% |
| 965 |
\advance\c@pgf@counta by1\relax% |
| 966 |
\pgfkeysgetvalue{/pgf/data/table/attribute \the\c@pgf@counta}\pgf@dv@target |
| 967 |
\ifx\pgf@dv@target\relax% |
| 968 |
\edef\pgf@dv@target{attribute \the\c@pgf@counta} |
| 969 |
\pgfkeyslet{/pgf/data/table/attribute \the\c@pgf@counta}\pgf@dv@target |
| 970 |
\fi |
| 971 |
\pgfkeyssetvalue{/data point/\pgf@dv@target}{#1} |
| 972 |
\let\pgf@next=\pgf@dv@parse@table% |
| 973 |
\fi% |
| 974 |
\pgf@next% |
| 975 |
}% |
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
\def\pgf@dv@parse@headline#1{ |
| 980 |
\c@pgf@counta=0\relax% keep track of attribute number |
| 981 |
\def\pgf@marshal{\pgf@dv@doparse@headline#1} |
| 982 |
\expandafter\expandafter\expandafter\pgf@marshal% |
| 983 |
\expandafter\pgf@dv@separator\expandafter\pgfeol\pgf@dv@separator |
| 984 |
}% |
| 985 |
|
| 986 |
\def\pgf@dv@doparse@headline{% |
| 987 |
\pgfutil@ifnextchar"% Special, but ignored right now... |
| 988 |
{\pgferror{csv with quotes not yet implemented}} |
| 989 |
{\pgf@dv@till@separator@head} |
| 990 |
}% |
| 991 |
\def\pgf@dv@head@handle#1{% |
| 992 |
\def\pgf@temp{#1}% |
| 993 |
\ifx\pgf@temp\pgfeoltext% |
| 994 |
% Bingo! Stop |
| 995 |
\let\pgf@next=\relax% |
| 996 |
\else% |
| 997 |
\advance\c@pgf@counta by1\relax% |
| 998 |
\pgfkeyssetvalue{/pgf/data/table/attribute \the\c@pgf@counta}{#1} |
| 999 |
\let\pgf@next=\pgf@dv@doparse@headline% |
| 1000 |
\fi% |
| 1001 |
\pgf@next% |
| 1002 |
}% |
| 1003 |
|
| 1004 |
\def\pgfeoltext{\pgfeol}% |
| 1005 |
|
| 1006 |
|
| 1007 |
% |
| 1008 |
% |
| 1009 |
% Micro math kernel for dv |
| 1010 |
% |
| 1011 |
% |
| 1012 |
|
| 1013 |
% The idea behind the following methods is to "abstract away" which |
| 1014 |
% math engine is used. In the future, something fancy build on luatex |
| 1015 |
% might be used, so it would we should not rely directly on the |
| 1016 |
% fpu library code. |
| 1017 |
% |
| 1018 |
% The system works as follows: First, you "enter" a number into the |
| 1019 |
% engine. When you do so, it is converted into some internal |
| 1020 |
% representation that cannot be accessed any more and is called a |
| 1021 |
% "math variable" henceforth. All commands of the |
| 1022 |
% math system only work on math variables. |
| 1023 |
% |
| 1024 |
% In order to "exit" a value stored in a math variable from the |
| 1025 |
% engine, some other macros can be used. |
| 1026 |
% |
| 1027 |
% Operations like addition or multiplication take two math variables |
| 1028 |
% and store the result in another math variable. |
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
% Store a value in a math variable of the math engine |
| 1033 |
% |
| 1034 |
% #1 = a math variable (a macro name) that is to store the value |
| 1035 |
% #2 = an expression describing a number |
| 1036 |
% |
| 1037 |
% |
| 1038 |
% Description: |
| 1039 |
% |
| 1040 |
% The #2 should be an expression that evaluates to a number. However, |
| 1041 |
% due to the way the pgf math engine(s) work, currently, there are |
| 1042 |
% several restrictions/the syntax is not as simple as one might |
| 1043 |
% hope. Fortunately, the syntax is hopefully compatible with |
| 1044 |
% easier-to-use future systems. |
| 1045 |
% |
| 1046 |
% The syntax is as follows: #2 may be |
| 1047 |
% |
| 1048 |
% 1. a simple high-precision number. This number is currently directly |
| 1049 |
% passed to \pgfmathfloatparsenumber, so typical permissible values |
| 1050 |
% are "100" or "10000000000000" or "nan" or "-5.673543345345e9000" |
| 1051 |
% |
| 1052 |
% 2. a mathematical expression, which *must* be surrounded by |
| 1053 |
% parentheses. From a "mathematical" point of view these |
| 1054 |
% parentheses are superfluous, but the they are used to help pgf |
| 1055 |
% distinguish expressions from high-precision numbers. (If, in the |
| 1056 |
% future, expressions may contain high precision numbers, the |
| 1057 |
% parentheses will simply be ignored.) |
| 1058 |
% |
| 1059 |
% The expression is evaluated using \pgfmathparse, which means that |
| 1060 |
% TeX-precision is used. This means, for instance, that numbers |
| 1061 |
% larger than about 16500 will create error messages. |
| 1062 |
% |
| 1063 |
% The advantage is that you may say write things like "(5+6)" or |
| 1064 |
% "(pi/2)". |
| 1065 |
% |
| 1066 |
% 3. In case #2 starts with an exclamation mark (indicating an |
| 1067 |
% "escape"), everything following the mark is simply evaluated by |
| 1068 |
% TeX. The effect of evaluating #2 should be that the math |
| 1069 |
% variable "\pgfdvmathvalue" is set to some value. This value will |
| 1070 |
% then be transferred to #1. |
| 1071 |
% |
| 1072 |
% 4. In case #2 is the result of calling \pgfdvmathexitbyserializing, the |
| 1073 |
% "serialized" value is restored. The idea is that the serialized |
| 1074 |
% will turn its internal representation of a number into something |
| 1075 |
% that can be stored as a text somewhere. |
| 1076 |
% |
| 1077 |
% Currently, "@" at the beginning of #2 is used to indicate that |
| 1078 |
% what follows is a serialized version of a math variable. |
| 1079 |
% |
| 1080 |
% In order to determine which of the above cases is to be used for a |
| 1081 |
% variable, the first symbol #2 is checked, *after* the first symbol |
| 1082 |
% of #2 has been expanded once (using \expandafter once). |
| 1083 |
% |
| 1084 |
% Example: |
| 1085 |
% |
| 1086 |
% \pgfdvmathenter{\mymacro}{20000000000000} |
| 1087 |
% \pgfdvmathenter{\mymacro}{(5+pi)} |
| 1088 |
% \pgfdvmathenter{\mymacro}{!\pgfdvmathadd{\pgfdvmathvalue}{\a}{\b}} |
| 1089 |
% |
| 1090 |
% \pgfdvmathenter{\foo}{5} |
| 1091 |
% \pgfdvmathexitbyserializing{\somevalue}{\foo} |
| 1092 |
% \pgfdvmathenter{\mymacro}{\somevalue} |
| 1093 |
|
| 1094 |
\def\pgfdvmathenter#1#2{% |
| 1095 |
\expandafter\pgfdvmathenter@check\expandafter#1#2\pgfdvmath@end% |
| 1096 |
}% |
| 1097 |
\def\pgfdvmathenter@check#1{% |
| 1098 |
\pgfutil@ifnextchar @{\pgfdvmath@internal#1}{% |
| 1099 |
\pgfutil@ifnextchar ({\pgfdvmath@expression#1}{%) |
| 1100 |
\pgfutil@ifnextchar !{\pgfdvmath@execute#1}{\pgfdvmath@normal#1}}}% |
| 1101 |
}% |
| 1102 |
|
| 1103 |
\def\pgfdvmath@internal#1@#2\pgfdvmath@end{% |
| 1104 |
\def#1{#2}% |
| 1105 |
}% |
| 1106 |
\def\pgfdvmath@expression#1(#2)#3\pgfdvmath@end{% |
| 1107 |
\pgfmathparse{#2}% |
| 1108 |
\pgfmathfloatparsenumber{\pgfmathresult}% |
| 1109 |
\let#1=\pgfmathresult% |
| 1110 |
}% |
| 1111 |
\def\pgfdvmath@execute#1!#2\pgfdvmath@end{% |
| 1112 |
#2% |
| 1113 |
\let#1=\pgfdvmathvalue% |
| 1114 |
}% |
| 1115 |
\def\pgfdvmath@normal#1#2\pgfdvmath@end{% |
| 1116 |
\pgfmathfloatparsenumber{#2}% |
| 1117 |
\let#1=\pgfmathresult% |
| 1118 |
}% |
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
% Print a math variable in the math engine using \pgfmathprintnumber |
| 1123 |
% |
| 1124 |
% #1 = math variable |
| 1125 |
% |
| 1126 |
% Description: |
| 1127 |
% |
| 1128 |
% See the description of \pgfmathprintnumber |
| 1129 |
% |
| 1130 |
% Example: |
| 1131 |
% |
| 1132 |
% \pgfdvmathenter{\mymacro}{20000000000000} |
| 1133 |
% \pgfdvmathexitbyprinting{\mymacro} |
| 1134 |
|
| 1135 |
\def\pgfdvmathexitbyprinting#1{% |
| 1136 |
\pgfmathprintnumber{#1}% |
| 1137 |
}% |
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
% Exit a math variable as a number in a scientific and portable number |
| 1142 |
% format in a macro |
| 1143 |
% |
| 1144 |
% #1 = macro in which to store the value |
| 1145 |
% #2 = math variable |
| 1146 |
% |
| 1147 |
% Description: |
| 1148 |
% |
| 1149 |
% You can exit a number using this operation. You can then directly |
| 1150 |
% reenter the number using \pgfdvmathenter |
| 1151 |
% |
| 1152 |
% Example: |
| 1153 |
% |
| 1154 |
% \pgfdvmathenter{\mynumber}{20000000000000} |
| 1155 |
% \pgfdvmathexitbyscientificformat{\mymacro}{\mynumber} |
| 1156 |
|
| 1157 |
\def\pgfdvmathexitbyscientificformat#1#2{% |
| 1158 |
\edef#1{\pgfmathfloatvalueof#2}% |
| 1159 |
}% |
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
% Exit a math variable as a "serialized" (= string-based) |
| 1164 |
% version. |
| 1165 |
% |
| 1166 |
% #1 = macro in which to store the value |
| 1167 |
% #2 = math variable |
| 1168 |
% |
| 1169 |
% Description: |
| 1170 |
% |
| 1171 |
% The serialized version can be reentered using |
| 1172 |
% \pgfmathenter and is similar to \pgfdvmathexitbyscientificformat, |
| 1173 |
% but exiting and entering are (a bit) faster. |
| 1174 |
% |
| 1175 |
% Example: |
| 1176 |
% |
| 1177 |
% \pgfdvmathenter{\mynumber}{20000000000000} |
| 1178 |
% \pgfdvmathexitbyserializing{\mymacro}{\mynumber} |
| 1179 |
|
| 1180 |
\def\pgfdvmathexitbyserializing#1#2{% |
| 1181 |
\edef#1{@#2}% |
| 1182 |
}% |
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
% Operations on two numbers |
| 1189 |
% |
| 1190 |
% #1 = macro that should store the result of applying the |
| 1191 |
% corresponding operation to the following: |
| 1192 |
% #2 = entered number |
| 1193 |
% #3 = entered number |
| 1194 |
% |
| 1195 |
% Description: |
| 1196 |
% |
| 1197 |
% Sets #1 to the result of applying an operation to #2 and #3 |
| 1198 |
% |
| 1199 |
% Example: |
| 1200 |
% |
| 1201 |
% \pgfdvmathenter{\a}{2000} |
| 1202 |
% \pgfdvmathenter{\b}{5+6} |
| 1203 |
% \pgfdvmathadd{\c}{\a}{\b} |
| 1204 |
|
| 1205 |
\def\pgfdvmathadd#1#2#3{% |
| 1206 |
\pgfmathfloatadd{#2}{#3}% |
| 1207 |
\let#1=\pgfmathresult% |
| 1208 |
}% |
| 1209 |
\def\pgfdvmathsub#1#2#3{% |
| 1210 |
\pgfmathfloatsubtract{#2}{#3}% |
| 1211 |
\let#1=\pgfmathresult% |
| 1212 |
}% |
| 1213 |
\def\pgfdvmathmul#1#2#3{% |
| 1214 |
\pgfmathfloatmultiply{#2}{#3}% |
| 1215 |
\let#1=\pgfmathresult% |
| 1216 |
}% |
| 1217 |
\def\pgfdvmathdiv#1#2#3{% |
| 1218 |
\pgfmathfloatdivide{#2}{#3}% |
| 1219 |
\let#1=\pgfmathresult% |
| 1220 |
}% |
| 1221 |
|
| 1222 |
% Multiply by small number |
| 1223 |
% |
| 1224 |
% #1 = macro that should store the result of applying the |
| 1225 |
% corresponding operation to the following: |
| 1226 |
% #2 = entered number |
| 1227 |
% #3 = fixed point number like 2 or 0.5, but not 10000000000 |
| 1228 |
% |
| 1229 |
% Description: |
| 1230 |
% |
| 1231 |
% Sets #1 to the result of applying an operation to #2 and #3 |
| 1232 |
% |
| 1233 |
% Example: |
| 1234 |
% |
| 1235 |
% \pgfdvmathenter{\a}{2000} |
| 1236 |
% \pgfdvmathadd{\b}{\a}{0.2} |
| 1237 |
% % \b now stores 400 |
| 1238 |
|
| 1239 |
\def\pgfdvmathmulfixed#1#2#3{% |
| 1240 |
\pgfmathfloatmultiplyfixed{#2}{#3}% |
| 1241 |
\let#1=\pgfmathresult% |
| 1242 |
}% |
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
% Log, ln and exponent functions |
| 1247 |
% |
| 1248 |
% #1 = a math variable |
| 1249 |
% #2 = a math variable |
| 1250 |
% |
| 1251 |
% Description |
| 1252 |
% |
| 1253 |
% \pgfdvmathln will compute #1 = ln(#2) |
| 1254 |
% \pgfdvmathlog will compute #1 = log_{10}(#2) |
| 1255 |
% \pgfdvmathexp will compute #1 = exp(#2) |
| 1256 |
% \pgfdvmathpowten will compute #1 = 10^{#2} |
| 1257 |
|
| 1258 |
\def\pgfdvmathln#1#2{% |
| 1259 |
\pgfmathfloatln{#2}% |
| 1260 |
\let#1=\pgfmathresult% |
| 1261 |
}% |
| 1262 |
|
| 1263 |
\def\pgfdvmathlog#1#2{% |
| 1264 |
\pgfmathfloatln{#2}% |
| 1265 |
\pgfmathfloatmultiply{\pgfmathresult}{\pgfdvmathalwaysloge}% |
| 1266 |
\let#1=\pgfmathresult% |
| 1267 |
}% |
| 1268 |
|
| 1269 |
\def\pgfdvmathexp#1#2{% |
| 1270 |
\pgfmathfloatexp{#2}% |
| 1271 |
\let#1=\pgfmathresult% |
| 1272 |
}% |
| 1273 |
|
| 1274 |
\def\pgfdvmathpowten#1#2{% |
| 1275 |
\pgfmathfloattofixed{#2}% |
| 1276 |
\let\pgf@dv@temp=\pgfmathresult% |
| 1277 |
\pgfmathround{\pgf@dv@temp}% |
| 1278 |
\let\pgf@dv@temp@round=\pgfmathresult% |
| 1279 |
\pgf@x=\pgf@dv@temp@round pt% |
| 1280 |
\pgf@x=-\pgf@x% |
| 1281 |
\advance\pgf@x by\pgf@dv@temp pt\relax% |
| 1282 |
\ifdim\pgf@x>0.0002pt% |
| 1283 |
\pgfmathfloatmultiply{#2}{\pgfdvmathalwayslnten}% |
| 1284 |
\pgfmathfloatexp{\pgfmathresult}% |
| 1285 |
\else |
| 1286 |
\ifdim\pgf@x<-0.0002pt% |
| 1287 |
\pgfmathfloatmultiply{#2}{\pgfdvmathalwayslnten}% |
| 1288 |
\pgfmathfloatexp{\pgfmathresult}% |
| 1289 |
\else |
| 1290 |
\pgf@x=\pgf@dv@temp@round sp% |
| 1291 |
\c@pgf@counta=\pgf@x% |
| 1292 |
\pgfmathfloatcreate{1}{1.0}{\the\c@pgf@counta}% |
| 1293 |
\fi |
| 1294 |
\fi |
| 1295 |
\let#1=\pgfmathresult% |
| 1296 |
}% |
| 1297 |
|
| 1298 |
|
| 1299 |
% Floor functions |
| 1300 |
% |
| 1301 |
% #1 = a math variable |
| 1302 |
% #2 = a math variable |
| 1303 |
% |
| 1304 |
% Description |
| 1305 |
% |
| 1306 |
% Sets #1 to the largest integer less or equal to #2 |
| 1307 |
|
| 1308 |
\def\pgfdvmathfloor#1#2{% |
| 1309 |
\pgfmathifisint{#2}{% |
| 1310 |
\let#1=#2% |
| 1311 |
}{% |
| 1312 |
\pgfmathfloatgetflags#2\c@pgf@counta% |
| 1313 |
\ifcase\c@pgf@counta |
| 1314 |
\let#1=\pgfdvmathalwayszero% |
| 1315 |
\or |
| 1316 |
\pgfmathfloatfloor{#2}% |
| 1317 |
\let#1=\pgfmathresult% |
| 1318 |
\or |
| 1319 |
\pgfmathfloatsubtract{\pgfdvmathalwaysone}{#2}% |
| 1320 |
\pgfmathfloatfloor{\pgfmathresult}% |
| 1321 |
\pgfmathfloatsubtract{\pgfdvmathalwayszero}{\pgfmathresult}% |
| 1322 |
\let#1=\pgfmathresult% |
| 1323 |
\or\let#1=#2% |
| 1324 |
\or\let#1=#2% |
| 1325 |
\or\let#1=#2% |
| 1326 |
\fi% |
| 1327 |
}% |
| 1328 |
}% |
| 1329 |
|
| 1330 |
|
| 1331 |
% Advanced unary operations |
| 1332 |
% |
| 1333 |
% #1 = macro that should store the result of applying the |
| 1334 |
% operation to an entered number |
| 1335 |
% #2 = the operation (as a string like "ln") |
| 1336 |
% #3 = entered number |
| 1337 |
% |
| 1338 |
% Description: |
| 1339 |
% |
| 1340 |
% Sets #1 to the result of applying #2 to #3 |
| 1341 |
% |
| 1342 |
% Example: |
| 1343 |
% |
| 1344 |
% \pgfdvmathenter{\a}{2000} |
| 1345 |
% \pgfdvmathunaryop{\b}{ln}{\a} |
| 1346 |
|
| 1347 |
\def\pgfdvmathunaryop#1#2#3{% |
| 1348 |
\csname pgfmathfloat#2\endcsname{#3}% |
| 1349 |
\let#1=\pgfmathresult% |
| 1350 |
}% |
| 1351 |
|
| 1352 |
|
| 1353 |
% Advanced binary operations |
| 1354 |
% |
| 1355 |
% #1 = macro that should store the result of applying the |
| 1356 |
% operation to two entered number |
| 1357 |
% #2 = the operation (as a string like "veclen") |
| 1358 |
% #3 = first argument (an entered number) |
| 1359 |
% #4 = second argument (an entered number) |
| 1360 |
% |
| 1361 |
% Description: |
| 1362 |
% |
| 1363 |
% Sets #1 to the result of applying #2 to #3 |
| 1364 |
% |
| 1365 |
% Example: |
| 1366 |
% |
| 1367 |
% \pgfdvmathenter{\a}{3} |
| 1368 |
% \pgfdvmathenter{\b}{4} |
| 1369 |
% \pgfdvmathbinop{\c}{veclen}{\a}{\b} |
| 1370 |
|
| 1371 |
\def\pgfdvmathbinop#1#2#3#4{% |
| 1372 |
\csname pgfmathfloat#2\endcsname{#3}{#4}% |
| 1373 |
\let#1=\pgfmathresult% |
| 1374 |
}% |
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
% Comparing values |
| 1379 |
% |
| 1380 |
% #1 = first math variable |
| 1381 |
% #2 = second math variable |
| 1382 |
% #3 = code to-be-executed if #1 < #2 |
| 1383 |
% #4 = code to-be-executed if #1 >= #2 |
| 1384 |
% |
| 1385 |
% |
| 1386 |
% Example: |
| 1387 |
% |
| 1388 |
% \pgfdvmathenter{\a}{3} |
| 1389 |
% \pgfdvmathenter{\b}{4} |
| 1390 |
% \pgfdvmathifless{\a}{\b}{yes}{should not happen} |
| 1391 |
|
| 1392 |
\def\pgfdvmathifless#1#2#3#4{% |
| 1393 |
\pgfmathfloatlessthan{#1}{#2}% |
| 1394 |
\ifpgfmathfloatcomparison#3\else#4\fi% |
| 1395 |
}% |
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
% |
| 1401 |
% |
| 1402 |
% Standard objects for data visualization |
| 1403 |
% |
| 1404 |
% |
| 1405 |
|
| 1406 |
|
| 1407 |
% |
| 1408 |
% Transformers |
| 1409 |
% |
| 1410 |
|
| 1411 |
\pgfooclass{linear transformer} |
| 1412 |
{% |
| 1413 |
% Class linear transformer |
| 1414 |
% |
| 1415 |
% This class is a transformer class. It reacts to the transform |
| 1416 |
% datapoint signal. When this signal is raised, it will shift the |
| 1417 |
% coordinate system as follows: If the current value of /data |
| 1418 |
% point/this.attribute is 0, then the system is shifted to the |
| 1419 |
% current value of this.origin. If the current value is 1, the |
| 1420 |
% system is shifted to this.origin + this.unit vector. For other |
| 1421 |
% values of /data point/this.attribuate, the shift is interpolated |
| 1422 |
% between these two values. |
| 1423 |
|
| 1424 |
|
| 1425 |
\attribute attribute;% |
| 1426 |
% The attribute (/data point/this.attribute) by which |
| 1427 |
% the unit vector is multiplied. If it is empty (which is |
| 1428 |
% different from 0), no transformation is done at all. |
| 1429 |
|
| 1430 |
\attribute origin = \pgfpointorigin;% |
| 1431 |
% The shift in case the /data point/this.attribute is 0. |
| 1432 |
|
| 1433 |
\attribute unit vector;% |
| 1434 |
% The coordinate system is additionally shifted by this amount |
| 1435 |
% times the current value of /data point/this.attribute. |
| 1436 |
|
| 1437 |
|
| 1438 |
% Constructor |
| 1439 |
% |
| 1440 |
% #1 = attribute that is being transformed. Example: x |
| 1441 |
% #2 = a vector corresponding to one unit of #1. |
| 1442 |
% Example: \pgfpoint{1cm}{0cm} |
| 1443 |
\method linear transformer(#1,#2) { |
| 1444 |
\pgfooset{attribute}{#1} |
| 1445 |
\pgf@process{#2} |
| 1446 |
\edef\pgf@temp{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}} |
| 1447 |
\pgfoolet{unit vector}\pgf@temp% |
| 1448 |
}% |
| 1449 |
|
| 1450 |
% Method |
| 1451 |
\method default connects() { |
| 1452 |
\pgfoothis.get handle(\pgf@dv@me) |
| 1453 |
\pgfkeysvalueof{/pgf/data visualization/obj}.connect(\pgf@dv@me,transform,transform datapoint signal) |
| 1454 |
}% |
| 1455 |
|
| 1456 |
% Setter |
| 1457 |
\method set origin(#1) { |
| 1458 |
\pgf@process{#1} |
| 1459 |
\edef\pgf@temp{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}} |
| 1460 |
\pgfoolet{origin}\pgf@temp% |
| 1461 |
}% |
| 1462 |
|
| 1463 |
% Slot |
| 1464 |
% |
| 1465 |
% This slot should be connected to the transform datapoint |
| 1466 |
% signal. When this signal is emitted, the coordinate system will be |
| 1467 |
% shifted according to the current value of the attribute. |
| 1468 |
\method transform() { |
| 1469 |
\pgfkeysgetvalue{/data point/\pgfoovalueof{attribute}}\pgf@dv@val% |
| 1470 |
\ifx\pgf@dv@val\pgfutil@empty% |
| 1471 |
\else% |
| 1472 |
\ifx\pgf@dv@val\relax% |
| 1473 |
\else% |
| 1474 |
\pgfdvmathenter{\pgf@dv@math@var}{\pgf@dv@val}% |
| 1475 |
\pgfdvmathexitbyscientificformat{\pgf@dv@val}{\pgf@dv@math@var}% |
| 1476 |
\pgftransformshift{\pgfoovalueof{origin}}% |
| 1477 |
\pgfmathfloatgetexponent\pgf@dv@math@var\c@pgf@counta% |
| 1478 |
\ifnum\c@pgf@counta<-3\relax% |
| 1479 |
\else% |
| 1480 |
\pgftransformshift{\pgfpointscale{\pgf@dv@val}{\pgfoovalueof{unit vector}}}% |
| 1481 |
\fi% |
| 1482 |
\fi% |
| 1483 |
\fi% |
| 1484 |
}% |
| 1485 |
}% |
| 1486 |
|
| 1487 |
|
| 1488 |
% |
| 1489 |
% Numerical mapping of attributes to other attributes |
| 1490 |
% |
| 1491 |
|
| 1492 |
\pgfooclass{interval mapper} |
| 1493 |
{% |
| 1494 |
% Class interval mapper |
| 1495 |
% |
| 1496 |
% This interval mapper reacts to the map datapoint signal. Its purpose is to |
| 1497 |
% map one attribute to another attribute. For the first attribute, |
| 1498 |
% an intervals is specified. |
| 1499 |
% |
| 1500 |
% In addition to the in interval [a,b] there is also an outinterval |
| 1501 |
% [c,d]. Values in the range [a,b] are linearly mapped to the |
| 1502 |
% range [c,d] and the result is stored in the second attribute. |
| 1503 |
% |
| 1504 |
% For instance, if the first range is [10,20] and the second range |
| 1505 |
% is [0,100], then 10 is mapped to 0, 11 is mapped to 10, 20 is |
| 1506 |
% mapped to 100 and 30 is mapped to 200. |
| 1507 |
% |
| 1508 |
% It is permissible to specify an additional non-linear |
| 1509 |
% transformation function f. In this case, for an input value x the |
| 1510 |
% position of f(x) inside the interval [f(a),f(b)] is determined and |
| 1511 |
% this position is linearly mapped to [c,d]. |
| 1512 |
% |
| 1513 |
% For example, if f(x) = log_10 (x) and the first range [a,b] = |
| 1514 |
% [10,1000] and the second range is [1,2], then 10 is mapped to 1, |
| 1515 |
% 100 is mapped to 1.5 (since f(100) = 3 lies in the middle |
| 1516 |
% between f(10) = 2 and f(1000) = 4) and 100000 is mapped to 3. |
| 1517 |
|
| 1518 |
|
| 1519 |
\attribute in;% |
| 1520 |
% The name of the input attribute. If the value of this attribute |
| 1521 |
% is empty or undefined, no mapping is done. |
| 1522 |
% |
| 1523 |
% The in attribute may have a subkey called .../const. If this key |
| 1524 |
% has a value different from \relax, it will always be used instead |
| 1525 |
% of the in attribute itself. This can be useful to temporarily |
| 1526 |
% set a constant value to a key inside a mapping chain. |
| 1527 |
% |
| 1528 |
% If the subkey /is min or max is set to "min" or "max", the mapping |
| 1529 |
% will always be done to the respective out min or out max values. |
| 1530 |
|
| 1531 |
\attribute out;% |
| 1532 |
% The name of the output attribute. |
| 1533 |
|
| 1534 |
\attribute trans;% |
| 1535 |
% Stores (more or less) the transformation function. |
| 1536 |
|
| 1537 |
\attribute out min;% |
| 1538 |
% Start of the second range (the value of c). |
| 1539 |
|
| 1540 |
\attribute out min;% |
| 1541 |
% End of the second range (the value of d). |
| 1542 |
|
| 1543 |
\attribute trans in min;% |
| 1544 |
% Transformed value of the start of the first range (the value |
| 1545 |
% f(a)). |
| 1546 |
|
| 1547 |
\attribute scale;% |
| 1548 |
% The scaling factor, that is, the value of (f(b)-f(a))/(d-c). |
| 1549 |
|
| 1550 |
|
| 1551 |
% Constructor |
| 1552 |
% |
| 1553 |
% #1 = input attribute. Example: velocity. |
| 1554 |
% #2 = output attribute. Example: x |
| 1555 |
% #3 = optional transformation function. The input value for this |
| 1556 |
% function is stored in entered number \pgfvalue. |
| 1557 |
% The output of the function should be stored in the |
| 1558 |
% same entered number. |
| 1559 |
% |
| 1560 |
% The intervals are set using setter methods later on. |
| 1561 |
% |
| 1562 |
\method interval mapper(#1,#2,#3) { |
| 1563 |
\pgfooset{in}{#1} |
| 1564 |
\pgfooset{out}{#2} |
| 1565 |
\def\pgf@temp{#3}% |
| 1566 |
\ifx\pgf@temp\pgfutil@empty% |
| 1567 |
\else% |
| 1568 |
\pgfooset{trans}{% |
| 1569 |
#3% |
| 1570 |
}% |
| 1571 |
\fi% |
| 1572 |
}% |
| 1573 |
|
| 1574 |
% Method |
| 1575 |
\method default connects() { |
| 1576 |
\pgfoothis.get handle(\pgf@dv@me) |
| 1577 |
\pgfkeysvalueof{/pgf/data visualization/obj}.connect(\pgf@dv@me,map,map datapoint signal) |
| 1578 |
}% |
| 1579 |
|
| 1580 |
% Method |
| 1581 |
% |
| 1582 |
% #1 = in interval minimum |
| 1583 |
% #2 = in interval maximum |
| 1584 |
% #3 = out interval minimum |
| 1585 |
% #4 = out interval maximum |
| 1586 |
% |
| 1587 |
% This method will (re)compute the correct mappings for the interval |
| 1588 |
% mapper. |
| 1589 |
\method set interval values(#1,#2,#3,#4) { |
| 1590 |
{% |
| 1591 |
\pgfdvmathenter{\pgf@in@interval@min}{#1} |
| 1592 |
\pgfdvmathenter{\pgf@in@interval@max}{#2} |
| 1593 |
\pgfdvmathenter{\pgf@out@interval@min}{#3} |
| 1594 |
\pgfdvmathenter{\pgf@out@interval@max}{#4} |
| 1595 |
% Let's start with the output, it's easier... |
| 1596 |
\pgfoolet{out min}{\pgf@out@interval@min} |
| 1597 |
\pgfoolet{out max}{\pgf@out@interval@max} |
| 1598 |
\pgfdvmathifless{\pgf@in@interval@min}{\pgf@in@interval@max}{% |
| 1599 |
\pgfdvmathsub{\pgf@out@diff}{\pgf@out@interval@max}{\pgf@out@interval@min} |
| 1600 |
\let\pgfvalue=\pgf@in@interval@min |
| 1601 |
\pgfoovalueof{trans} |
| 1602 |
\let\pgf@in@interval@min@transformed=\pgfvalue |
| 1603 |
\pgfoolet{trans in min}{\pgf@in@interval@min@transformed}% |
| 1604 |
\let\pgfvalue=\pgf@in@interval@max |
| 1605 |
\pgfoovalueof{trans} |
| 1606 |
\let\pgf@in@interval@max@transformed=\pgfvalue |
| 1607 |
\pgfdvmathsub{\pgf@diff@in@transformed}{\pgf@in@interval@max@transformed}{\pgf@in@interval@min@transformed} |
| 1608 |
% |
| 1609 |
% Precompute the scaling |
| 1610 |
% |
| 1611 |
\pgfdvmathdiv{\pgf@scale}{\pgf@out@diff}{\pgf@diff@in@transformed}% |
| 1612 |
\pgfoolet{scale}{\pgf@scale}% |
| 1613 |
}{% |
| 1614 |
\pgfoolet{scale}\pgf@dv@no@scale% |
| 1615 |
}% |
| 1616 |
}% |
| 1617 |
}% |
| 1618 |
\def\pgf@dv@no@scale{noscale}% |
| 1619 |
|
| 1620 |
% Slot |
| 1621 |
\method map() { |
| 1622 |
\pgfooget{scale}\pgf@dv@scale |
| 1623 |
\ifx\pgf@dv@scale\pgfutil@empty% |
| 1624 |
% not yet setup |
| 1625 |
\else% |
| 1626 |
\pgfkeysgetvalue{/data point/\pgfoovalueof{in}/is min or max}\pgf@dv@is% |
| 1627 |
\ifx\pgf@dv@is\pgf@min@text% |
| 1628 |
\pgf@dv@set@out@min% |
| 1629 |
\else% |
| 1630 |
\ifx\pgf@dv@is\pgf@max@text% |
| 1631 |
\pgf@dv@set@out@max% |
| 1632 |
\else% |
| 1633 |
\ifx\pgf@dv@scale\pgf@dv@no@scale% |
| 1634 |
\pgf@dv@mapper@goto@mid% |
| 1635 |
\else% |
| 1636 |
\pgfkeysgetvalue{/data point/\pgfoovalueof{in}/const}\pgf@dv@external@value% |
| 1637 |
\ifx\pgf@dv@external@value\relax% |
| 1638 |
\pgfkeysgetvalue{/data point/\pgfoovalueof{in}}\pgf@dv@external@value% |
| 1639 |
\fi% |
| 1640 |
\ifx\pgf@dv@external@value\pgfutil@empty% |
| 1641 |
\pgf@dv@mapper@pos@check% |
| 1642 |
\else% |
| 1643 |
\ifx\pgf@dv@external@value\relax% |
| 1644 |
\pgf@dv@mapper@pos@check% |
| 1645 |
\else% |
| 1646 |
\pgfdvmathenter{\pgfvalue}{\pgf@dv@external@value}% |
| 1647 |
\pgf@dv@mapper@trans |
| 1648 |
\fi% |
| 1649 |
\fi% |
| 1650 |
\fi% |
| 1651 |
\fi% |
| 1652 |
\fi% |
| 1653 |
\fi% |
| 1654 |
}% |
| 1655 |
|
| 1656 |
\def\pgf@dv@set@out@min{% |
| 1657 |
\pgfkeyslet{/data point/\pgfoovalueof{out}/is min or max}\pgf@min@text% |
| 1658 |
\pgfooget{out min}{\pgf@minmax@temp}% |
| 1659 |
\pgf@dv@set@out@now% |
| 1660 |
}% |
| 1661 |
\def\pgf@dv@set@out@max{% |
| 1662 |
\pgfkeyslet{/data point/\pgfoovalueof{out}/is min or max}\pgf@max@text% |
| 1663 |
\pgfooget{out max}{\pgf@minmax@temp}% |
| 1664 |
\pgf@dv@set@out@now% |
| 1665 |
}% |
| 1666 |
\def\pgf@dv@set@out@now{% |
| 1667 |
\pgfkeysgetvalue{/data point/\pgfoovalueof{out}/offset}\pgf@dv@external@offset% |
| 1668 |
\ifx\pgf@dv@external@offset\relax\else% |
| 1669 |
\ifx\pgf@dv@external@offset\pgfutil@empty\else% |
| 1670 |
\pgfdvmathenter{\pgfvalue}{\pgf@minmax@temp}% |
| 1671 |
\pgfdvmathenter{\pgf@dv@offset}{\pgf@dv@external@offset}% |
| 1672 |
\pgfdvmathadd{\pgfvalue}{\pgfvalue}{\pgf@dv@offset} |
| 1673 |
\pgfdvmathexitbyserializing{\pgf@minmax@temp}{\pgfvalue}% |
| 1674 |
\fi |
| 1675 |
\fi |
| 1676 |
\pgfkeyslet{/data point/\pgfoovalueof{out}}\pgf@minmax@temp% |
| 1677 |
}% |
| 1678 |
|
| 1679 |
\def\pgf@dv@mapper@trans{ |
| 1680 |
\pgfooget{trans in min}{\pgf@dv@trans@in@min}% |
| 1681 |
\pgfooget{scale}{\pgf@dv@scale}% |
| 1682 |
\pgfooget{out min}{\pgf@dv@out@min}% |
| 1683 |
\pgfoovalueof{trans}% |
| 1684 |
\pgfdvmathsub{\pgfvalue}{\pgfvalue}{\pgf@dv@trans@in@min}% |
| 1685 |
\pgfdvmathmul{\pgfvalue}{\pgfvalue}{\pgf@dv@scale}% |
| 1686 |
\pgfdvmathadd{\pgfvalue}{\pgfvalue}{\pgf@dv@out@min}% |
| 1687 |
\pgfkeysgetvalue{/data point/\pgfoovalueof{out}/offset}\pgf@dv@external@offset% |
| 1688 |
\ifx\pgf@dv@external@offset\relax\else% |
| 1689 |
\ifx\pgf@dv@external@offset\pgfutil@empty\else% |
| 1690 |
\pgfdvmathenter{\pgf@dv@offset}{\pgf@dv@external@offset}% |
| 1691 |
\pgfdvmathadd{\pgfvalue}{\pgfvalue}{\pgf@dv@offset} |
| 1692 |
\fi |
| 1693 |
\fi |
| 1694 |
\pgfdvmathexitbyserializing{\pgf@temp}{\pgfvalue}% |
| 1695 |
\pgfkeyslet{/data point/\pgfoovalueof{out}}\pgf@temp% |
| 1696 |
}% |
| 1697 |
|
| 1698 |
\def\pgf@dv@mapper@pos@check{% |
| 1699 |
\pgfkeysgetvalue{/data point/\pgfoovalueof{in}/out pos}\pgf@dv@pos@value% |
| 1700 |
\ifx\pgf@dv@pos@value\relax\else\if\pgf@dv@pos@value\pgfutil@empty\else% |
| 1701 |
\pgfmathsetmacro{\pgf@dv@pos@num}{\pgf@dv@pos@value}% |
| 1702 |
\pgfmathsetmacro{\pgf@dv@pos@num@prime}{1-\pgf@dv@pos@num}% |
| 1703 |
% Ok, compute transformed min position: |
| 1704 |
\pgfooget{out min}{\pgf@out@interval@min} |
| 1705 |
\pgfooget{out max}{\pgf@out@interval@max} |
| 1706 |
\pgfdvmathmulfixed{\pgf@out@interval@min}{\pgf@out@interval@min}{\pgf@dv@pos@num@prime} |
| 1707 |
\pgfdvmathmulfixed{\pgf@out@interval@max}{\pgf@out@interval@max}{\pgf@dv@pos@num} |
| 1708 |
\pgfdvmathadd{\pgf@out@val}{\pgf@out@interval@min}{\pgf@out@interval@max}% |
| 1709 |
\pgfdvmathexitbyserializing{\pgf@temp}{\pgf@out@val}% |
| 1710 |
\pgfkeyslet{/data point/\pgfoovalueof{out}}\pgf@temp% |
| 1711 |
\fi\fi% |
| 1712 |
}% |
| 1713 |
|
| 1714 |
\def\pgf@dv@mapper@goto@mid{% |
| 1715 |
% Ok, compute transformed min position: |
| 1716 |
\pgfooget{out min}{\pgf@out@interval@min} |
| 1717 |
\pgfooget{out max}{\pgf@out@interval@max} |
| 1718 |
\pgfdvmathmulfixed{\pgf@out@interval@min}{\pgf@out@interval@min}{.5} |
| 1719 |
\pgfdvmathmulfixed{\pgf@out@interval@max}{\pgf@out@interval@max}{.5} |
| 1720 |
\pgfdvmathadd{\pgf@out@val}{\pgf@out@interval@min}{\pgf@out@interval@max}% |
| 1721 |
\pgfdvmathexitbyserializing{\pgf@temp}{\pgf@out@val}% |
| 1722 |
\pgfkeyslet{/data point/\pgfoovalueof{out}}\pgf@temp% |
| 1723 |
}% |
| 1724 |
}% |
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
%\newif\ifpgf@dvclip |
| 1731 |
\newif\ifpgf@dvignore |
| 1732 |
|
| 1733 |
\pgfooclass{scaling mapper} |
| 1734 |
{% |
| 1735 |
% Class scaling mapper |
| 1736 |
% |
| 1737 |
% A scaling mapper is (mainly) used to scale an attribute in such a way |
| 1738 |
% that it can be rendered easily on a page. The idea is that you |
| 1739 |
% specify some attribute and a desired target interval size (like |
| 1740 |
% [0,5]). The scaling mapper will then survey the data and will setup a |
| 1741 |
% interval mapper in such a way that the minimum value present in the data is |
| 1742 |
% mapped to 0 and the maximum to 5. However, it is also possible to, |
| 1743 |
% say, only have the maximum value mapped to 5 and have 0 be mapped |
| 1744 |
% to 0. Other, more complicated specifications are also possible. |
| 1745 |
% |
| 1746 |
% The scaling mapper internally creates several objects: First, a surveyor |
| 1747 |
% for determining the minimum and maximum values of the attribute |
| 1748 |
% and a interval mapper for then mapping the values to the scaled |
| 1749 |
% values. Additionally, interval objects are needed. |
| 1750 |
|
| 1751 |
\attribute in;% |
| 1752 |
% The to-be-scaled attribute; |
| 1753 |
|
| 1754 |
\attribute out;% |
| 1755 |
% The attribute storing the scaled value. |
| 1756 |
|
| 1757 |
\attribute in range obj;% |
| 1758 |
% This interval keep track of the range of the in attribute |
| 1759 |
|
| 1760 |
\attribute scaling spec;% |
| 1761 |
% A specification of how the scaling should be performed. |
| 1762 |
% |
| 1763 |
% The format is the following: |
| 1764 |
% |
| 1765 |
% #1 at #2 and #3 at #4 |
| 1766 |
% |
| 1767 |
% Here, #2 and #4 must be numbers. #1 and #3 can either be numbers |
| 1768 |
% or #1 can be the text "min" and #3 can be the text "max". |
| 1769 |
% |
| 1770 |
% The effect of such a specification is the following: The value #1 |
| 1771 |
% is mapped to #2, the value #3 is mapped to #4 and values between |
| 1772 |
% #1 and #3 (or outside this range) are mapped linearly to a value |
| 1773 |
% between (or outside) #2 and #4. In case #1 is set to "min", the |
| 1774 |
% smallest observed value of the in-attribute is mapped to #3 and |
| 1775 |
% similarly for a value of "max" for #3. |
| 1776 |
% |
| 1777 |
% Additionally, as for a interval mapper, a function f might be specified |
| 1778 |
% that deforms the linear mapping. In case f is specified, |
| 1779 |
% f(#1) is mapped to #2 and f(#3) is mapped to #4. |
| 1780 |
|
| 1781 |
\attribute spec maps min;% |
| 1782 |
% When the scaling spec maps "min" to some value, rather than some |
| 1783 |
% specific value to that value, then spec maps min will be set to |
| 1784 |
% \pgfutil@firstoftwo, otherwise to \pgfutil@secondoftwo |
| 1785 |
|
| 1786 |
\attribute spec maps max;% |
| 1787 |
% Like spec maps min |
| 1788 |
|
| 1789 |
\attribute function;% |
| 1790 |
% Stores the function |
| 1791 |
|
| 1792 |
\attribute interval mapper;% |
| 1793 |
% Stores the interval mapper object |
| 1794 |
|
| 1795 |
\attribute range surveyor;% |
| 1796 |
% Stores the range surveyor object |
| 1797 |
|
| 1798 |
|
| 1799 |
% Constructor |
| 1800 |
% |
| 1801 |
% #1 = in attribute |
| 1802 |
% #2 = out attribute |
| 1803 |
% #3 = scaling specification |
| 1804 |
% #4 = optional function |
| 1805 |
% |
| 1806 |
\method scaling mapper(#1,#2,#3,#4) { |
| 1807 |
% |
| 1808 |
% Save the parameters in attributes |
| 1809 |
% |
| 1810 |
\pgfooset{in}{#1} |
| 1811 |
\pgfooset{out}{#2} |
| 1812 |
\pgfooset{scaling spec}{#3} |
| 1813 |
\pgfooset{function}{#4} |
| 1814 |
% |
| 1815 |
% Now setup the objects for the before survey phase |
| 1816 |
% |
| 1817 |
% |
| 1818 |
% First, the in range interval |
| 1819 |
\pgfoonew \pgf@dv@in@range@obj=new interval(,) |
| 1820 |
\pgfoolet{in range obj}\pgf@dv@in@range@obj |
| 1821 |
% Second, the in range surveyor. We do not need to store this |
| 1822 |
% object, it will "do its work in the background" |
| 1823 |
\pgfoonew \pgf@dv@range@obj=new range surveyor(#1,\pgf@dv@in@range@obj) |
| 1824 |
\pgf@dv@[email protected] connects() |
| 1825 |
\pgfoolet{range surveyor}\pgf@dv@range@obj |
| 1826 |
% |
| 1827 |
% |
| 1828 |
% The interval mapper: |
| 1829 |
% |
| 1830 |
\pgfoonew{interval mapper}=new interval mapper(#1,#2,#4) |
| 1831 |
\pgfoovalueof{interval mapper}.default connects() |
| 1832 |
}% |
| 1833 |
|
| 1834 |
% Method |
| 1835 |
\method default connects() { |
| 1836 |
\pgfoothis.get handle(\pgf@dv@me) |
| 1837 |
\pgfkeysvalueof{/pgf/data visualization/obj}.connect(\pgf@dv@me,phase,phase signal) |
| 1838 |
}% |
| 1839 |
|
| 1840 |
% Getter |
| 1841 |
% |
| 1842 |
% Returns an interval object that stores the range of the in |
| 1843 |
% attribute. |
| 1844 |
\method get in range interval() { |
| 1845 |
\pgfooget{in range obj}\pgfdvinrangeinterval |
| 1846 |
}% |
| 1847 |
|
| 1848 |
|
| 1849 |
% Getter |
| 1850 |
% |
| 1851 |
% Returns the out attribute. |
| 1852 |
% |
| 1853 |
\method get out() { |
| 1854 |
\pgfooget{out}\pgfdvout |
| 1855 |
}% |
| 1856 |
|
| 1857 |
% Getter |
| 1858 |
% |
| 1859 |
% Returns the function attribute. |
| 1860 |
% |
| 1861 |
\method get function(#1) { |
| 1862 |
\pgfooget{function}#1 |
| 1863 |
}% |
| 1864 |
|
| 1865 |
% Method |
| 1866 |
% |
| 1867 |
% #1 = a included in value |
| 1868 |
% |
| 1869 |
% This method only affects the survey. The value #1 is recorded as |
| 1870 |
% if it were encountered for the in attribute at some point. |
| 1871 |
% |
| 1872 |
\method include in value(#1) { |
| 1873 |
\pgfoovalueof{range surveyor}.include attribute value({#1}) |
| 1874 |
}% |
| 1875 |
|
| 1876 |
|
| 1877 |
% Method |
| 1878 |
% |
| 1879 |
% #1 = value for the attribute |
| 1880 |
% |
| 1881 |
% Sets the attribute to the (evaluated) given value (evaluation |
| 1882 |
% using \pgfmathparse). When the value is evaluated, the values of |
| 1883 |
% \pgfdvmin and \pgfdvmax will be set to the minimum and maximum |
| 1884 |
% values of the in interval. (See \pgfdvmathenter with the "!"-notation). |
| 1885 |
% |
| 1886 |
% In case #1 is set to the special value "min", it evaluates to |
| 1887 |
% \pgfdvmin, when set to "max" it evaluates to \pgfdvmax. |
| 1888 |
% |
| 1889 |
\method set in to(#1) {% |
| 1890 |
\edef\pgf@temp{#1}% |
| 1891 |
\ifx\pgf@temp\pgf@min@text% |
| 1892 |
\pgf@dv@lib@set@mm% |
| 1893 |
\let\pgf@dv@value\pgfdvmin% |
| 1894 |
\pgfoovalueof{spec maps min}{\pgfkeyslet{/data point/\pgfoovalueof{in}/is min or max}\pgf@min@text}{}% |
| 1895 |
\else% |
| 1896 |
\ifx\pgf@temp\pgf@max@text% |
| 1897 |
\pgf@dv@lib@set@mm% |
| 1898 |
\let\pgf@dv@value\pgfdvmax% |
| 1899 |
\pgfoovalueof{spec maps min}{\pgfkeyslet{/data point/\pgfoovalueof{in}/is min or max}\pgf@max@text}{}% |
| 1900 |
\else% |
| 1901 |
\pgfdvmathenter{\pgf@dv@value}{\pgf@temp}% |
| 1902 |
\fi% |
| 1903 |
\fi% |
| 1904 |
\pgfdvmathexitbyserializing{\pgf@dv@serial}{\pgf@dv@value}% |
| 1905 |
\pgfkeyslet{/data point/\pgfoovalueof{in}}\pgf@dv@serial% |
| 1906 |
}% |
| 1907 |
\def\pgf@dv@lib@set@mm{ |
| 1908 |
\pgfooget{in range obj}\pgfdvinrangeinterval |
| 1909 |
\pgfdvinrangeinterval.get min and max()% |
| 1910 |
}% |
| 1911 |
|
| 1912 |
|
| 1913 |
% Slot |
| 1914 |
\method phase(#1) { |
| 1915 |
\ifx#1\pgfdvendsurvey |
| 1916 |
% Ok, we setup the interval mapper. |
| 1917 |
% |
| 1918 |
% We start by computing the interval borders: |
| 1919 |
\pgfoovalueof{in range obj}.get min and max() |
| 1920 |
\ifx\pgfdvmin\pgfutil@empty% undefined, since no data points |
| 1921 |
\else% |
| 1922 |
\pgfooget{scaling spec}\pgf@temp% |
| 1923 |
\expandafter\pgf@lib@dv@parse@scaling\pgf@temp\pgf@stop% |
| 1924 |
\pgfoovalueof{interval mapper}.set interval values(% |
| 1925 |
\pgf@lib@dv@min,\pgf@lib@dv@max,% |
| 1926 |
\pgf@lib@dv@min@at,\pgf@lib@dv@max@at) |
| 1927 |
\fi |
| 1928 |
\fi |
| 1929 |
}% |
| 1930 |
|
| 1931 |
|
| 1932 |
% Internal helper |
| 1933 |
\def\pgf@lib@dv@parse@scaling#1 at#2and #3 at#4\pgf@stop{% |
| 1934 |
\def\pgf@lib@dv@min{#1}% |
| 1935 |
\pgfdvmathenter{\pgf@lib@dv@min@at@mv}{#2} |
| 1936 |
\def\pgf@lib@dv@max{#3}% |
| 1937 |
\pgfdvmathenter{\pgf@lib@dv@max@at@mv}{#4} |
| 1938 |
\ifx\pgf@lib@dv@min\pgf@min@text% |
| 1939 |
\let\pgf@lib@dv@min@mv\pgfdvmin |
| 1940 |
\pgfoolet{spec maps min}\pgfutil@firstoftwo% |
| 1941 |
\else |
| 1942 |
\pgfdvmathenter{\pgf@lib@dv@min@mv}{\pgf@lib@dv@min} |
| 1943 |
\pgfoolet{spec maps min}\pgfutil@secondoftwo% |
| 1944 |
\fi |
| 1945 |
\ifx\pgf@lib@dv@max\pgf@max@text% |
| 1946 |
\let\pgf@lib@dv@max@mv\pgfdvmax |
| 1947 |
\pgfoolet{spec maps max}\pgfutil@firstoftwo% |
| 1948 |
\else |
| 1949 |
\pgfdvmathenter{\pgf@lib@dv@max@mv}{\pgf@lib@dv@max} |
| 1950 |
\pgfoolet{spec maps max}\pgfutil@secondoftwo% |
| 1951 |
\fi |
| 1952 |
\pgfdvmathexitbyserializing{\pgf@lib@dv@min}{\pgf@lib@dv@min@mv} |
| 1953 |
\pgfdvmathexitbyserializing{\pgf@lib@dv@min@at}{\pgf@lib@dv@min@at@mv} |
| 1954 |
\pgfdvmathexitbyserializing{\pgf@lib@dv@max}{\pgf@lib@dv@max@mv} |
| 1955 |
\pgfdvmathexitbyserializing{\pgf@lib@dv@max@at}{\pgf@lib@dv@max@at@mv} |
| 1956 |
}% |
| 1957 |
\def\pgf@min@text{min}% |
| 1958 |
\def\pgf@max@text{max}% |
| 1959 |
}% |
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
% |
| 1966 |
% Surveyors |
| 1967 |
% |
| 1968 |
|
| 1969 |
\pgfooclass{range surveyor} |
| 1970 |
{% |
| 1971 |
% Class range surveyor |
| 1972 |
% |
| 1973 |
% A range surveyor is used only in the survey phase. Its job is to |
| 1974 |
% determine the minimum and maximum values of an attribute that are |
| 1975 |
% "seen" during the survey phase. Based on this value, the size of, |
| 1976 |
% say, an axis can be determined later on. |
| 1977 |
% |
| 1978 |
% You can also set the key "sub attributes" of the attribute. In |
| 1979 |
% this case, this key should contain -- as the name suggests -- a |
| 1980 |
% list of subkeys that should also be taken into account for the |
| 1981 |
% computation of the minimum and maximum value. Inside the "sub |
| 1982 |
% attributes" key, each subkey should be surrounded by a call of |
| 1983 |
% \pgfdvsub. For instance, if there are two sub attributes "/data |
| 1984 |
% point/velocity/min" and "/data point/velocity/max" for a key |
| 1985 |
% "/data point/velocity", then "/data point/velocity/sub attributes" |
| 1986 |
% should be set to "\pgfdvsub{/min}\pgfdvsub{/max}". |
| 1987 |
|
| 1988 |
\attribute attribute;% |
| 1989 |
% The to-be-surveyed attribute |
| 1990 |
|
| 1991 |
\attribute interval obj;% |
| 1992 |
% The interval object that protocols the minimum and maximum |
| 1993 |
% values. |
| 1994 |
|
| 1995 |
|
| 1996 |
% Constructor |
| 1997 |
% |
| 1998 |
% #1 = the attribute |
| 1999 |
% #2 = handle to the interval object |
| 2000 |
% |
| 2001 |
\method range surveyor(#1,#2) { |
| 2002 |
\pgfooset{attribute}{#1} |
| 2003 |
\pgfoolet{interval obj}#2 |
| 2004 |
}% |
| 2005 |
|
| 2006 |
% Method |
| 2007 |
\method default connects() { |
| 2008 |
\pgfoothis.get handle(\pgf@dv@me) |
| 2009 |
\pgfkeysvalueof{/pgf/data visualization/obj}.connect(\pgf@dv@me,survey,survey datapoint signal) |
| 2010 |
}% |
| 2011 |
|
| 2012 |
% Method |
| 2013 |
% |
| 2014 |
% #1 = a value |
| 2015 |
% |
| 2016 |
% Adjust the interval as if during the survey this value were |
| 2017 |
% encountered |
| 2018 |
\method include attribute value(#1) { |
| 2019 |
\pgf@dv@assign@val@stripped#1\pgf@stop% |
| 2020 |
\pgfoovalueof{interval obj}.adjust(\pgf@dv@range@surv) |
| 2021 |
}% |
| 2022 |
\def\pgf@dv@assign@val@stripped#1\pgf@stop{% |
| 2023 |
\def\pgf@dv@val{#1} |
| 2024 |
}% |
| 2025 |
|
| 2026 |
% Slot |
| 2027 |
% |
| 2028 |
% This slot should be connected to the survey datapoint signal. For |
| 2029 |
% each datapoint, this method will call the adjust method of the |
| 2030 |
% interval. |
| 2031 |
% |
| 2032 |
\method survey() { |
| 2033 |
\let\pgfdvsub\pgf@dv@range@surv@sub |
| 2034 |
\pgfdvsub{}% |
| 2035 |
\pgfkeysvalueof{/data point/\pgfoovalueof{attribute}/sub attributes} |
| 2036 |
}% |
| 2037 |
|
| 2038 |
\def\pgf@dv@range@surv@sub#1{ |
| 2039 |
\pgfkeysgetvalue{/data point/\pgfoovalueof{attribute}#1}\pgf@dv@val% |
| 2040 |
\ifx\pgf@dv@val\relax% |
| 2041 |
\else% |
| 2042 |
\edef\pgf@dv@val{\pgf@dv@val}% |
| 2043 |
\ifx\pgf@dv@val\pgfutil@empty% |
| 2044 |
\else% |
| 2045 |
\pgfoovalueof{interval obj}.adjust(\pgf@dv@range@surv)% |
| 2046 |
\fi% |
| 2047 |
\fi% |
| 2048 |
}% |
| 2049 |
|
| 2050 |
\def\pgf@dv@range@surv{% |
| 2051 |
\pgfdvmathenter{\pgf@dv@value}{\pgf@dv@val}% |
| 2052 |
% Now, protocol value |
| 2053 |
\ifx\pgfdvmin\pgfutil@empty% |
| 2054 |
\let\pgfdvmin\pgf@dv@value% |
| 2055 |
\else% |
| 2056 |
\pgfdvmathifless{\pgf@dv@value}{\pgfdvmin}{\let\pgfdvmin\pgf@dv@value}{}% |
| 2057 |
\fi% |
| 2058 |
\ifx\pgfdvmax\pgfutil@empty% |
| 2059 |
\let\pgfdvmax\pgf@dv@value% |
| 2060 |
\else% |
| 2061 |
\pgfdvmathifless{\pgfdvmax}{\pgf@dv@value}{\let\pgfdvmax\pgf@dv@value}{}% |
| 2062 |
\fi% |
| 2063 |
}% |
| 2064 |
}% |
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
% |
| 2069 |
% Visualizers |
| 2070 |
% |
| 2071 |
|
| 2072 |
\usepgflibrary{plothandlers}% |
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
\pgfooclass{plot handler visualizer} |
| 2077 |
{% |
| 2078 |
% Class plot handler visualizer |
| 2079 |
% |
| 2080 |
% This visualizer uses one or more plot handlers to visualize data points. |
| 2081 |
% As the data points are processed, the canvas positions of the data |
| 2082 |
% points are recorded. At the end of a group of data points, the |
| 2083 |
% recorded stream of canvas position is visualized (rendered) |
| 2084 |
% using plot handlers. For instance, when the lineto plot handler |
| 2085 |
% is used, the data points are connected by straight lines, when the |
| 2086 |
% curveto plot handler is used, they are connected by smooth curves |
| 2087 |
% and so on. |
| 2088 |
% |
| 2089 |
% Since plot lines are not drawn immediately, but only at the end, |
| 2090 |
% when everything has been collected, multiple plot handlers can |
| 2091 |
% coexist peacefully at the same time. |
| 2092 |
% |
| 2093 |
% You can specify a "filter", which will cause only those data |
| 2094 |
% points to be visualized by the visualizer that pass the test. The |
| 2095 |
% filter should set \pgfdvfilterpassedfalse for to-be-filtered data |
| 2096 |
% point. |
| 2097 |
% |
| 2098 |
% You can specify "projection code" that changes the canvas x and |
| 2099 |
% canvas y positions. This projection code allows you to draw, say, |
| 2100 |
% projected points instead of the actual data point. |
| 2101 |
% |
| 2102 |
% The keys /data point/<name>/execute at begin and /data |
| 2103 |
% point/<name>/execute at end, where <name> is the name of |
| 2104 |
% the visualizer, should store code that is to be executed directly |
| 2105 |
% before and after the stream of coordinates is created. Typically, |
| 2106 |
% these keys will store commands to use the path created by the plot |
| 2107 |
% handler. |
| 2108 |
|
| 2109 |
\attribute handlers;% |
| 2110 |
% The to-be-used handlers |
| 2111 |
|
| 2112 |
\attribute name;% |
| 2113 |
% The attribute |
| 2114 |
|
| 2115 |
\attribute filter=\pgfdvnamedvisualizerfilter;% |
| 2116 |
% Filter code |
| 2117 |
|
| 2118 |
\attribute positions;% |
| 2119 |
% An internal protocol of the positions on the stream |
| 2120 |
|
| 2121 |
\attribute cache;% |
| 2122 |
% An internal cache. Positions are first inserted into this |
| 2123 |
% cache. Every 100 steps this cache is moved to positions. The idea |
| 2124 |
% behind this is that it will avoid the quadratic time increase that |
| 2125 |
% is normally caused when a protocol is build in TeX. |
| 2126 |
|
| 2127 |
\attribute projection code;% |
| 2128 |
% This code is empty by default. However, you can set it for |
| 2129 |
% instance to the following |
| 2130 |
% |
| 2131 |
% \pgfkeyssetvalue{/data point/y=0}\pgfdvmapdatapointtocanvas |
| 2132 |
% |
| 2133 |
% in order to visualize the data point with its y-coordinate |
| 2134 |
% replaced by 0. |
| 2135 |
|
| 2136 |
% Constructor |
| 2137 |
% |
| 2138 |
% #1 = A name |
| 2139 |
% #2 = A comma-separated list of handlers like |
| 2140 |
% "\pgfplothandlerlineto,\pgfplothandlercurveto" |
| 2141 |
% |
| 2142 |
\method plot handler visualizer(#1,#2) { |
| 2143 |
\pgfooset{name}{#1} |
| 2144 |
\pgfooset{handlers}{#2} |
| 2145 |
}% |
| 2146 |
|
| 2147 |
% Method |
| 2148 |
\method default connects() { |
| 2149 |
\pgfoothis.get handle(\pgf@dv@me) |
| 2150 |
\pgfkeysvalueof{/pgf/data visualization/obj}.connect(\pgf@dv@me,protocol,visualize datapoint signal) |
| 2151 |
\pgfkeysvalueof{/pgf/data visualization/obj}.connect(\pgf@dv@me,phase,phase signal) |
| 2152 |
}% |
| 2153 |
|
| 2154 |
% Setter |
| 2155 |
\method set filter(#1) { |
| 2156 |
\pgfooset{filter}{#1} |
| 2157 |
}% |
| 2158 |
|
| 2159 |
% Setter |
| 2160 |
\method set projection code(#1) { |
| 2161 |
\pgfooset{projection code}{#1} |
| 2162 |
}% |
| 2163 |
|
| 2164 |
% Slot |
| 2165 |
\method protocol() { |
| 2166 |
\pgfdvfilterpassedtrue |
| 2167 |
\pgfoovalueof{filter} |
| 2168 |
\ifpgfdvfilterpassed% |
| 2169 |
\pgf@dv@line@cache@it |
| 2170 |
\fi% |
| 2171 |
}% |
| 2172 |
|
| 2173 |
\def\pgf@dv@line@cache@it{ |
| 2174 |
% Cache it |
| 2175 |
\pgfooget{cache}\pgf@dv@cache |
| 2176 |
\pgfkeysgetvalue{/data point/outlier}\pgf@temp% |
| 2177 |
\ifx\pgf@temp\pgfutil@empty |
| 2178 |
{% |
| 2179 |
\pgfoovalueof{projection code} |
| 2180 |
\xdef\pgf@dv@add{\noexpand\pgf@dv@ph{\pgfkeysvalueof{/data |
| 2181 |
point/canvas x}}{\pgfkeysvalueof{/data point/canvas y}}}% |
| 2182 |
} |
| 2183 |
\else% |
| 2184 |
% An outlier! |
| 2185 |
\gdef\pgf@dv@add{\pgf@dv@outliner}% |
| 2186 |
\fi% |
| 2187 |
\expandafter\expandafter\expandafter\def% |
| 2188 |
\expandafter\expandafter\expandafter\pgf@dv@cache% |
| 2189 |
\expandafter\expandafter\expandafter{\expandafter\pgf@dv@cache\pgf@dv@add}% |
| 2190 |
% Possibly flush cache |
| 2191 |
\global\advance\pgf@lib@dv@cache@count by1\relax% |
| 2192 |
\ifnum\pgf@lib@dv@cache@count=100\relax% |
| 2193 |
\global\pgf@lib@dv@cache@count=0\relax% |
| 2194 |
% Append cache to positions |
| 2195 |
\pgfooget{positions}\pgf@dv@temp |
| 2196 |
\expandafter\expandafter\expandafter\def% |
| 2197 |
\expandafter\expandafter\expandafter\pgf@dv@temp% |
| 2198 |
\expandafter\expandafter\expandafter{\expandafter\pgf@dv@temp\pgf@dv@cache}% |
| 2199 |
\pgfoolet{positions}\pgf@dv@temp |
| 2200 |
\let\pgf@dv@cache\pgfutil@empty |
| 2201 |
\fi |
| 2202 |
\pgfoolet{cache}\pgf@dv@cache |
| 2203 |
}% |
| 2204 |
|
| 2205 |
% Slot |
| 2206 |
\method phase(#1) {% |
| 2207 |
\ifx#1\pgfdvendvisualization% |
| 2208 |
\pgfoothis.render()% |
| 2209 |
\fi% |
| 2210 |
}% |
| 2211 |
|
| 2212 |
% Internal method |
| 2213 |
\method render() { |
| 2214 |
\pgfscope |
| 2215 |
\pgfooget{handlers}\tikz@dv@temp@list |
| 2216 |
\foreach\tikz@dv@temp in\tikz@dv@temp@list{ |
| 2217 |
\ifx\tikz@dv@temp\pgfutil@empty |
| 2218 |
\else |
| 2219 |
\pgfkeysvalueof{/data point/\pgfoovalueof{name}/execute at begin} |
| 2220 |
\tikz@dv@temp |
| 2221 |
\pgfdvnewstreamtrue |
| 2222 |
\pgfoovalueof{positions} |
| 2223 |
\pgfoovalueof{cache} |
| 2224 |
\ifpgfdvnewstream\else\pgfplotstreamend\fi |
| 2225 |
\pgfkeysvalueof{/data point/\pgfoovalueof{name}/execute at end} |
| 2226 |
\fi |
| 2227 |
} |
| 2228 |
\endpgfscope |
| 2229 |
\pgfoolet{positions}\pgfutil@empty |
| 2230 |
\pgfoolet{cache}\pgfutil@empty |
| 2231 |
}% |
| 2232 |
|
| 2233 |
\def\pgf@dv@ph#1#2{\ifpgfdvnewstream\pgfplotstreamstart\pgfdvnewstreamfalse\fi\pgfplotstreampoint{\pgfqpoint{#1}{#2}}}% |
| 2234 |
\def\pgf@dv@outliner{\ifpgfdvnewstream\else\pgfplotstreamend\pgfdvnewstreamtrue\fi}% |
| 2235 |
}% |
| 2236 |
|
| 2237 |
\newif\ifpgfdvnewstream |
| 2238 |
\newcount\pgf@lib@dv@cache@count |
| 2239 |
|
| 2240 |
\pgfkeys{% |
| 2241 |
/data point/outlier/.initial=, |
| 2242 |
/data point/outlier/.default=true, |
| 2243 |
}% |
| 2244 |
|
| 2245 |
|
| 2246 |
% A possible filter for unnamed visualizers |
| 2247 |
% |
| 2248 |
% #1 = Text to be compared with key /data point/set |
| 2249 |
% |
| 2250 |
% Description: |
| 2251 |
% |
| 2252 |
% In a data visualization with multiple visualizers, data points |
| 2253 |
% typically "belong" only to a single visualizer. It is, thus, |
| 2254 |
% necessary to filter data points according to the current |
| 2255 |
% visualizer. This current visualizer is assumed to be stored in /data |
| 2256 |
% point/visualizer. |
| 2257 |
% |
| 2258 |
% When objects allow you to set a filter, you can use this filter to |
| 2259 |
% test against /data point/set being equal to #1. |
| 2260 |
|
| 2261 |
\def\pgfdvvisualizerfilter#1{% |
| 2262 |
\pgfkeysgetvalue{/data point/set}\pgf@dv@visualizer% |
| 2263 |
\def\pgf@temp{#1}% |
| 2264 |
\ifx\pgf@temp\pgf@dv@visualizer% |
| 2265 |
\else |
| 2266 |
\pgfdvfilterpassedfalse |
| 2267 |
\fi% |
| 2268 |
}% |
| 2269 |
|
| 2270 |
|
| 2271 |
|
| 2272 |
% A filter for named visualizer |
| 2273 |
% |
| 2274 |
% Description: |
| 2275 |
% |
| 2276 |
% This filter works like \pgfdvvisualizerfilter, only it assumes the |
| 2277 |
% the object defines a "name" attribute. In this case, the value of |
| 2278 |
% /data point/set is tested against this attribute. |
| 2279 |
|
| 2280 |
\def\pgfdvnamedvisualizerfilter{% |
| 2281 |
\pgfkeysgetvalue{/data point/set}\pgf@dv@visualizer% |
| 2282 |
\pgfooget{name}\pgf@temp% |
| 2283 |
\ifx\pgf@temp\pgf@dv@visualizer% |
| 2284 |
\else |
| 2285 |
\pgfdvfilterpassedfalse |
| 2286 |
\fi% |
| 2287 |
}% |
| 2288 |
|
| 2289 |
|
| 2290 |
|
| 2291 |
\pgfooclass{rectangle visualizer} |
| 2292 |
{% |
| 2293 |
% Class rectangle visualizer |
| 2294 |
% |
| 2295 |
% This visualizer visualizes a datapoint as a rectangle. It needs |
| 2296 |
% a name, so that /data point/<name>/attribute 1 and /data |
| 2297 |
% point/<name>/attribute 2 store two attributes names a1 to a2. Then, |
| 2298 |
% provided the current value of /data point/set equals name, for |
| 2299 |
% each data point a rectangle between (a1/min,a2/min) and |
| 2300 |
% (a1/max,a2/max) is created. |
| 2301 |
|
| 2302 |
|
| 2303 |
\attribute name;% |
| 2304 |
% The name |
| 2305 |
|
| 2306 |
\attribute a1;% |
| 2307 |
\attribute a2;% |
| 2308 |
% The attributes, filled from /data point/<name>/attribute 1 and 2 |
| 2309 |
|
| 2310 |
|
| 2311 |
% Constructor |
| 2312 |
% |
| 2313 |
% #1 = first attribute |
| 2314 |
% #2 = second attribute |
| 2315 |
% |
| 2316 |
\method rectangle visualizer(#1) { |
| 2317 |
\pgfooset{name}{#1} |
| 2318 |
}% |
| 2319 |
|
| 2320 |
% Method |
| 2321 |
\method default connects() { |
| 2322 |
\pgfoothis.get handle(\pgf@dv@me) |
| 2323 |
\pgfkeysvalueof{/pgf/data visualization/obj}.connect(\pgf@dv@me,visualize,visualize datapoint signal) |
| 2324 |
\pgfkeysvalueof{/pgf/data visualization/obj}.connect(\pgf@dv@me,phase,phase signal) |
| 2325 |
}% |
| 2326 |
|
| 2327 |
% Slot |
| 2328 |
\method phase(#1) {% |
| 2329 |
\ifx#1\pgfdvbeginsurvey% |
| 2330 |
\pgfooeset{a1}{/data point/\pgfkeysvalueof{/data point/\pgfoovalueof{name}/attribute 1}} |
| 2331 |
\pgfooeset{a2}{/data point/\pgfkeysvalueof{/data point/\pgfoovalueof{name}/attribute 2}} |
| 2332 |
\pgfkeyssetvalue{\pgfoovalueof{a1}/sub attributes}{\pgfdvsub{/min}\pgfdvsub{/max}} |
| 2333 |
\pgfkeyssetvalue{\pgfoovalueof{a2}/sub attributes}{\pgfdvsub{/min}\pgfdvsub{/max}} |
| 2334 |
\fi% |
| 2335 |
}% |
| 2336 |
|
| 2337 |
% Slot |
| 2338 |
\method visualize() { |
| 2339 |
{ |
| 2340 |
\pgfkeysgetvalue{/data point/set}\pgf@dv@visualizer% |
| 2341 |
\pgfooget{name}\pgf@temp% |
| 2342 |
\ifx\pgf@temp\pgf@dv@visualizer% |
| 2343 |
\pgf@dv@rect@do |
| 2344 |
\fi |
| 2345 |
} |
| 2346 |
}% |
| 2347 |
|
| 2348 |
\def\pgf@dv@rect@do{ |
| 2349 |
\pgfkeysgetvalue{\pgfoovalueof{a1}/min}\pgf@dv@amin |
| 2350 |
\ifx\pgf@dv@amin\relax\else\ifx\pgf@dv@amin\pgfutil@empty\else |
| 2351 |
\pgfkeysgetvalue{\pgfoovalueof{a1}/max}\pgf@dv@amax |
| 2352 |
\ifx\pgf@dv@amax\relax\else\ifx\pgf@dv@amax\pgfutil@empty\else |
| 2353 |
\pgfkeysgetvalue{\pgfoovalueof{a2}/min}\pgf@dv@bmin |
| 2354 |
\ifx\pgf@dv@bmin\relax\else\ifx\pgf@dv@bmin\pgfutil@empty\else |
| 2355 |
\pgfkeysgetvalue{\pgfoovalueof{a2}/max}\pgf@dv@bmax |
| 2356 |
\ifx\pgf@dv@bmax\relax\else\ifx\pgf@dv@bmax\pgfutil@empty\else |
| 2357 |
\pgfkeysvalueof{/data point/\pgfoovalueof{name}/execute at begin} |
| 2358 |
\pgfkeyssetvalue{\pgfoovalueof{a1}}{\pgf@dv@amin} |
| 2359 |
\pgfkeyssetvalue{\pgfoovalueof{a2}}{\pgf@dv@bmin} |
| 2360 |
\pgfpathdvmoveto |
| 2361 |
\pgfkeyssetvalue{\pgfoovalueof{a2}}{\pgf@dv@bmax} |
| 2362 |
\pgfpathdvlineto |
| 2363 |
\pgfkeyssetvalue{\pgfoovalueof{a1}}{\pgf@dv@amax} |
| 2364 |
\pgfpathdvlineto |
| 2365 |
\pgfkeyssetvalue{\pgfoovalueof{a2}}{\pgf@dv@bmin} |
| 2366 |
\pgfpathdvlineto |
| 2367 |
\pgfkeyssetvalue{\pgfoovalueof{a1}}{\pgf@dv@amin} |
| 2368 |
\pgfpathdvlineto |
| 2369 |
\pgfpathclose |
| 2370 |
\pgfkeysvalueof{/data point/\pgfoovalueof{name}/execute at end} |
| 2371 |
\fi\fi |
| 2372 |
\fi\fi |
| 2373 |
\fi\fi |
| 2374 |
\fi\fi |
| 2375 |
}% |
| 2376 |
}% |
| 2377 |
|
| 2378 |
\newcount\pgf@lib@dv@cache@count |
| 2379 |
|
| 2380 |
|
| 2381 |
|
| 2382 |
% |
| 2383 |
% Label positioning classes |
| 2384 |
% |
| 2385 |
|
| 2386 |
\pgfooclass{label visualizer} |
| 2387 |
{% |
| 2388 |
% Class label visualizer |
| 2389 |
% |
| 2390 |
% The job of this class is to visualize a label of a curve or some |
| 2391 |
% other object. |
| 2392 |
% |
| 2393 |
% The idea is as follows: This class monitors a certain |
| 2394 |
% attribute. When this attribute reaches a certain value for the |
| 2395 |
% first time, the following happens: A normalized vector of the line |
| 2396 |
% connecting the current canvas position to the canvas position of |
| 2397 |
% the previous data point is computed and stored in pgf@x/pgf@y. The |
| 2398 |
% coordinate system is shifted so that the current data point is at |
| 2399 |
% the origin. Then, some drawing code is executed. |
| 2400 |
|
| 2401 |
\attribute attribute;% |
| 2402 |
% The monitored attribute |
| 2403 |
|
| 2404 |
\attribute filter;% |
| 2405 |
% Filter code, see plot handler visualizer doc. |
| 2406 |
|
| 2407 |
\attribute threshold;% |
| 2408 |
% When the attribute exceeds this threshold, the drawing code is |
| 2409 |
% executed |
| 2410 |
|
| 2411 |
\attribute before canvas position=;% |
| 2412 |
% Stores canvas position of the data point before the interesting one |
| 2413 |
|
| 2414 |
\attribute canvas position=;% |
| 2415 |
% Stores canvas position of the data point |
| 2416 |
|
| 2417 |
\attribute code;% |
| 2418 |
% To-be-executed code when the label should be drawn |
| 2419 |
|
| 2420 |
|
| 2421 |
% Constructor |
| 2422 |
% |
| 2423 |
% #1 = attribute |
| 2424 |
% #2 = a macro, storing the threshold |
| 2425 |
% #3 = code |
| 2426 |
% #4 = filter code |
| 2427 |
% |
| 2428 |
\method label visualizer(#1,#2,#3,#4) { |
| 2429 |
\pgfooset{attribute}{#1} |
| 2430 |
\expandafter\pgfdvmathenter\expandafter{\expandafter\pgf@temp\expandafter}\expandafter{#2} |
| 2431 |
\pgfoolet{threshold}\pgf@temp |
| 2432 |
\pgfooset{code}{#3} |
| 2433 |
\pgfooset{filter}{#4} |
| 2434 |
}% |
| 2435 |
|
| 2436 |
% Method |
| 2437 |
\method default connects() { |
| 2438 |
\pgfoothis.get handle(\pgf@dv@me) |
| 2439 |
\pgfkeysvalueof{/pgf/data visualization/obj}.connect(\pgf@dv@me,test,visualize datapoint signal) |
| 2440 |
\pgfkeysvalueof{/pgf/data visualization/obj}.connect(\pgf@dv@me,phase,phase signal) |
| 2441 |
}% |
| 2442 |
|
| 2443 |
% Slot |
| 2444 |
\method test() { |
| 2445 |
\pgfdvfilterpassedtrue |
| 2446 |
\pgfoovalueof{filter} |
| 2447 |
\ifpgfdvfilterpassed% |
| 2448 |
\pgfooget{attribute}\pgf@dv@attribute |
| 2449 |
\ifx\pgf@dv@attribute\pgfutil@empty% |
| 2450 |
% nothing to do (anymore) |
| 2451 |
\else% |
| 2452 |
\pgf@dv@label@vis@record |
| 2453 |
\fi% |
| 2454 |
\fi% |
| 2455 |
}% |
| 2456 |
|
| 2457 |
\def\pgf@dv@label@vis@record{ |
| 2458 |
% Record current position |
| 2459 |
\edef\pgf@dv@pos{% |
| 2460 |
\noexpand\pgfqpoint% |
| 2461 |
{\pgfkeysvalueof{/data point/canvas x}}% |
| 2462 |
{\pgfkeysvalueof{/data point/canvas y}}}% |
| 2463 |
\pgfooget{canvas position}\pgf@dv@temp% |
| 2464 |
\pgfoolet{before canvas position}\pgf@dv@temp% |
| 2465 |
\pgfoolet{canvas position}\pgf@dv@pos% |
| 2466 |
% Now check threshold |
| 2467 |
\pgfooget{threshold}\pgf@dv@thres% |
| 2468 |
\ifx\pgf@dv@thres\pgfutil@empty% |
| 2469 |
\else% |
| 2470 |
% Hmm, have to check, whether the value is, indeed, correct |
| 2471 |
\pgfkeysgetvalue{/data point/\pgfoovalueof{attribute}}\pgf@dv@val |
| 2472 |
\ifx\pgf@dv@val\relax% |
| 2473 |
\else\ifx\pgf@dv@val\pgfutil@empty% |
| 2474 |
\else% |
| 2475 |
\pgfdvmathenter{\pgf@dv@value}{\pgf@dv@val}% |
| 2476 |
\pgfooget{threshold}{\pgf@dv@thres} |
| 2477 |
% Now, protocol value |
| 2478 |
\pgfdvmathifless{\pgf@dv@value}{\pgf@dv@thres}{}{% |
| 2479 |
\pgfoolet{attribute}\pgfutil@empty% Stop! |
| 2480 |
}% |
| 2481 |
\fi\fi% |
| 2482 |
\fi% |
| 2483 |
}% |
| 2484 |
|
| 2485 |
% Slot |
| 2486 |
\method phase(#1) {% |
| 2487 |
\ifx#1\pgfdvendvisualization% |
| 2488 |
\scope |
| 2489 |
\pgfcoordinate{label visualizer coordinate}{\pgfoovalueof{canvas position}} |
| 2490 |
\pgfcoordinate{label visualizer coordinate'}{\pgfoovalueof{before canvas position}} |
| 2491 |
\pgfoovalueof{code} |
| 2492 |
\endscope |
| 2493 |
\fi% |
| 2494 |
}% |
| 2495 |
}% |
| 2496 |
|
| 2497 |
|
| 2498 |
|
| 2499 |
% |
| 2500 |
% Style sheets |
| 2501 |
% |
| 2502 |
\pgfooclass{style attribute} |
| 2503 |
{% |
| 2504 |
% Class style attribute |
| 2505 |
% |
| 2506 |
% Instances of this class are used to select a style based on the |
| 2507 |
% current value of an attribute. |
| 2508 |
% |
| 2509 |
% Instances of this class monitor an attribute. Whenever the "style" |
| 2510 |
% signal is raised, the object investigates the current value of the |
| 2511 |
% attribute. It then looks up /pgf/data visualization/style |
| 2512 |
% sheets/<name of style sheet>/<value of the attribute> and executes |
| 2513 |
% this key, provided it is defined. If it not defined, the key |
| 2514 |
% /pgf/data visualization/style sheets/<name of style sheet>/default |
| 2515 |
% style is executed with the value as a parameter. |
| 2516 |
|
| 2517 |
\attribute attribute;% |
| 2518 |
% The name of the attribute |
| 2519 |
|
| 2520 |
\attribute style sheet name;% |
| 2521 |
% The styling function |
| 2522 |
|
| 2523 |
% Constructor |
| 2524 |
% |
| 2525 |
% #1 = attribute (including, if present, /data point/) |
| 2526 |
% #2 = style sheet name |
| 2527 |
% |
| 2528 |
\method style attribute(#1,#2) { |
| 2529 |
\pgfooset{attribute}{#1} |
| 2530 |
\pgfooset{style sheet name}{#2} |
| 2531 |
}% |
| 2532 |
|
| 2533 |
% Method |
| 2534 |
\method default connects() { |
| 2535 |
\pgfoothis.get handle(\pgf@dv@me) |
| 2536 |
\pgfkeysvalueof{/pgf/data visualization/obj}.connect(\pgf@dv@me,invoke style,style signal) |
| 2537 |
}% |
| 2538 |
|
| 2539 |
% Slots |
| 2540 |
\method invoke style() { |
| 2541 |
\pgfooget{attribute}\pgf@dv@temp |
| 2542 |
\pgfkeysgetvalue{\pgf@dv@temp}\pgf@dv@temp@val |
| 2543 |
\ifx\pgf@dv@temp@val\pgfutil@empty%do nothing |
| 2544 |
\else\ifx\pgf@dv@temp@val\relax%do nothing |
| 2545 |
\else% |
| 2546 |
\pgfkeysifdefined{\pgf@dv@temp/\pgf@dv@temp@val}{\pgfkeysgetvalue{\pgf@dv@temp/\pgf@dv@temp@val}\pgf@dv@temp@val}{}% redirect |
| 2547 |
\edef\pgf@temp{/pgf/data visualization/style sheets/\pgfoovalueof{style sheet name}} |
| 2548 |
\pgfkeysifassignable{\pgf@temp/\pgf@dv@temp@val}{% |
| 2549 |
\pgfkeysalso{\pgf@temp/\pgf@dv@temp@val}}{% |
| 2550 |
\pgfkeysalso{\pgf@temp/default style/.expand once=\pgf@dv@temp@val} |
| 2551 |
} |
| 2552 |
\fi\fi% |
| 2553 |
}% |
| 2554 |
}% |
| 2555 |
|
| 2556 |
|
| 2557 |
% Declares a new style sheet |
| 2558 |
% |
| 2559 |
% #1 = name of style sheet |
| 2560 |
% #2 = settings |
| 2561 |
% |
| 2562 |
% Description: |
| 2563 |
% |
| 2564 |
% This is a shortcut for doing a /.cd to /pgf/data visualization/style sheets/#1 |
| 2565 |
|
| 2566 |
\def\pgfdvdeclarestylesheet#1#2{ |
| 2567 |
\pgfkeys{/pgf/data visualization/style sheets/#1/.cd,#2} |
| 2568 |
}% |
| 2569 |
|
| 2570 |
|
| 2571 |
|
| 2572 |
|
| 2573 |
|
| 2574 |
|
| 2575 |
|
| 2576 |
|
| 2577 |
|
| 2578 |
% |
| 2579 |
% Legend container class |
| 2580 |
% |
| 2581 |
|
| 2582 |
\pgfooclass{legend} |
| 2583 |
{% |
| 2584 |
% Class legend |
| 2585 |
% |
| 2586 |
% This class is used to collect entries into a legend. The idea is |
| 2587 |
% that, say, for each line of a picture you would like to have an |
| 2588 |
% entry in a legend. Then you prepare these entries and send |
| 2589 |
% them to a legend container object. It will collect the entries |
| 2590 |
% and, at the end, arrange them in rows and columns by |
| 2591 |
% separating them using \pgfdvnextcell and \pgfdvendrow. |
| 2592 |
% |
| 2593 |
% By surrounding the resulting arrangement by a call to \pgfmatrix or |
| 2594 |
% a call to \halign you can then create a legend. |
| 2595 |
% |
| 2596 |
% To specify how the entries should be arranged, a size |
| 2597 |
% specification and two directions are needed. |
| 2598 |
% |
| 2599 |
% For the size specification you specify either the ideal number of |
| 2600 |
% columns and the maximum number of rows or you specify the ideal |
| 2601 |
% number of rows and the maximum number of columns. In the first |
| 2602 |
% case, the class first tries to create as many columns as specified |
| 2603 |
% by the "ideal" parameter. If there are less entries than this |
| 2604 |
% parameter, you obviously get less columns, namely as many as there |
| 2605 |
% are entries, each column containing only one entry. If there are |
| 2606 |
% more entries that the ideal number of columns, you get multiple |
| 2607 |
% columns, each containing as many entries to make sure that the |
| 2608 |
% ideal number is met. However, if a column would get more than the |
| 2609 |
% specified maximum number of elements per column, you get more |
| 2610 |
% columns that the ideal number -- to ensure that no column contains |
| 2611 |
% more than the desired number. The case is symmetric, but with the |
| 2612 |
% roles of columns and rows exchanged. |
| 2613 |
% |
| 2614 |
% Here is an example: You specify that you want 2 columns, ideally, |
| 2615 |
% each having a maximum of 4 entries. Here is what you would get: |
| 2616 |
% |
| 2617 |
% Number of entries & Number of resulting columns ... & ... and rows |
| 2618 |
% 1 & 1 & 1 |
| 2619 |
% 2 & 2 & 1 |
| 2620 |
% 3 & 2 & 2 |
| 2621 |
% 4 & 2 & 2 |
| 2622 |
% 5 & 2 & 3 |
| 2623 |
% 6 & 2 & 3 |
| 2624 |
% 7 & 2 & 4 |
| 2625 |
% 8 & 2 & 4 |
| 2626 |
% 9 & 3 & 4 |
| 2627 |
% 10 & 3 & 4 |
| 2628 |
% 11 & 3 & 4 |
| 2629 |
% 12 & 3 & 4 |
| 2630 |
% 13 & 4 & 4 |
| 2631 |
% |
| 2632 |
% |
| 2633 |
% Once the number of columns and rows has been computed, the next |
| 2634 |
% step is to "fill" the table. For this, eight strategies may be |
| 2635 |
% specified: right then down, right then up, left then down, left |
| 2636 |
% then up, up then right, up then left, down then right, down then |
| 2637 |
% left. A strategy like "right then up" means the following: Each |
| 2638 |
% new entry should placed right of the previous entry in the |
| 2639 |
% arrangement. However, once the maximum number of elements in a row |
| 2640 |
% has been reached, the a new row should be started that is placed |
| 2641 |
% above ("up") then just-assembled row. |
| 2642 |
% |
| 2643 |
% |
| 2644 |
% |
| 2645 |
% |
| 2646 |
% Example: |
| 2647 |
% |
| 2648 |
% You create an object \legend and then call |
| 2649 |
% |
| 2650 |
% \pgfoofnew \legend=new legend(columns,2,3,down then right) |
| 2651 |
% \legend.add entry(first) |
| 2652 |
% \legend.add entry(second) |
| 2653 |
% \legend.add entry(third) |
| 2654 |
% \legend.add entry(fourth) |
| 2655 |
% \legend.add entry(fifth) |
| 2656 |
% \legend.add entry(sixth) |
| 2657 |
% \legend.add entry(seventh) |
| 2658 |
% \legend.get arrangement(\arrangement) |
| 2659 |
% |
| 2660 |
% Then \arrangement will expand to |
| 2661 |
% |
| 2662 |
% first \pgfdvnextcell fourth \pgfdvnextcell seventh \pgfdvendrow |
| 2663 |
% second \pgfdvnextcell fifth \pgfdvnextcell third \pgfdvendrow |
| 2664 |
% third \pgfdvendrow sixth \pgfdvnextcell \pgfdvendrow |
| 2665 |
% |
| 2666 |
% By saying \let\pgfdvendrow=\\ and \let\pgfdvnextcell=&, you |
| 2667 |
% can use \arrangement inside a table. |
| 2668 |
|
| 2669 |
|
| 2670 |
\attribute entries;% |
| 2671 |
% Collects the entries |
| 2672 |
|
| 2673 |
\attribute columns or rows;% |
| 2674 |
% Specifies whether columns or rows are specified |
| 2675 |
|
| 2676 |
\attribute ideal;% |
| 2677 |
% The ideal number of columns/rows |
| 2678 |
|
| 2679 |
\attribute max;% |
| 2680 |
% The maximum number of entries per column/row |
| 2681 |
|
| 2682 |
\attribute strategy;% |
| 2683 |
% Specifies how the matrix should be filled |
| 2684 |
|
| 2685 |
\attribute number of entries=0;% |
| 2686 |
% Counts the number of entries that have been stored |
| 2687 |
|
| 2688 |
|
| 2689 |
% Constructor |
| 2690 |
% |
| 2691 |
% #1 = "columns" or "rows" -> specifies whether the ideal number and |
| 2692 |
% the max entries number refer to columns or the row |
| 2693 |
% #2 = the ideal number of #1's |
| 2694 |
% #3 = the maximum number of entries in a #1 |
| 2695 |
% #4 = one of the eight strategies |
| 2696 |
% |
| 2697 |
\method legend(#1,#2,#3,#4) { |
| 2698 |
\pgfooset{columns or rows}{#1} |
| 2699 |
\pgfooset{ideal}{#2} |
| 2700 |
\pgfooset{max}{#3} |
| 2701 |
\pgfooset{strategy}{#4} |
| 2702 |
}% |
| 2703 |
|
| 2704 |
% Method |
| 2705 |
\method default connects() { |
| 2706 |
}% |
| 2707 |
|
| 2708 |
% Method |
| 2709 |
\method add entry(#1) { |
| 2710 |
\pgfooappend{entries}{{#1}} |
| 2711 |
\c@pgf@counta=\pgfoovalueof{number of entries}\relax% |
| 2712 |
\advance\c@pgf@counta by1\relax% |
| 2713 |
\pgfooeset{number of entries}{\the\c@pgf@counta} |
| 2714 |
}% |
| 2715 |
|
| 2716 |
% Method |
| 2717 |
\method get arrangement(#1) { |
| 2718 |
{ |
| 2719 |
% |
| 2720 |
% Step 1: Compute the desired number of rows or columns |
| 2721 |
% |
| 2722 |
% |
| 2723 |
% Compute the ideal number of entries per row/column (called |
| 2724 |
% "target" in the following) and entries per column/row (called |
| 2725 |
% "per target" in the following) |
| 2726 |
% |
| 2727 |
% if (number of entries > ideal) |
| 2728 |
\ifnum\pgfoovalueof{number of entries}>\pgfoovalueof{ideal}\relax% |
| 2729 |
% { |
| 2730 |
% if (ideal * max > number of entries) |
| 2731 |
\c@pgf@counta=\pgfoovalueof{ideal}\relax% |
| 2732 |
\multiply\c@pgf@counta by\pgfoovalueof{max}\relax% |
| 2733 |
\ifnum\c@pgf@counta>\pgfoovalueof{number of entries}\relax |
| 2734 |
% { |
| 2735 |
% target = ideal; |
| 2736 |
% per target = ceil (number of entries / ideal); |
| 2737 |
\c@pgf@counta=\pgfoovalueof{ideal}\relax% |
| 2738 |
\c@pgf@countb=\pgfoovalueof{number of entries}\relax |
| 2739 |
\advance\c@pgf@countb by-1\relax |
| 2740 |
\divide\c@pgf@countb by\c@pgf@counta\relax% |
| 2741 |
\advance\c@pgf@countb by1\relax% |
| 2742 |
% } |
| 2743 |
% else |
| 2744 |
% { |
| 2745 |
% target = ceil(number of entries / max); |
| 2746 |
% per target = max; |
| 2747 |
\else |
| 2748 |
\c@pgf@countb=\pgfoovalueof{max}\relax% |
| 2749 |
\c@pgf@counta=\pgfoovalueof{number of entries}\relax |
| 2750 |
\advance\c@pgf@counta by-1\relax |
| 2751 |
\divide\c@pgf@counta by\c@pgf@countb\relax% |
| 2752 |
\advance\c@pgf@counta by1\relax% |
| 2753 |
\fi |
| 2754 |
% } |
| 2755 |
% } |
| 2756 |
% else |
| 2757 |
% { |
| 2758 |
% target = number of entries; |
| 2759 |
% per target = 1; |
| 2760 |
% } |
| 2761 |
\else |
| 2762 |
\c@pgf@counta=\pgfoovalueof{number of entries}\relax% |
| 2763 |
\c@pgf@countb=1\relax% |
| 2764 |
\fi% |
| 2765 |
% |
| 2766 |
% Ensure that counta = rows, countb = columns |
| 2767 |
% |
| 2768 |
\pgfooget{columns or rows}\pgf@temp |
| 2769 |
\ifx\pgf@temp\pgf@dv@columnstext% |
| 2770 |
\c@pgf@countc=\c@pgf@counta\relax |
| 2771 |
\c@pgf@counta=\c@pgf@countb\relax |
| 2772 |
\c@pgf@countb=\c@pgf@countc\relax |
| 2773 |
\fi |
| 2774 |
%\edef\temp{rows: \the\c@pgf@counta, columns: \the\c@pgf@countb}\temp |
| 2775 |
% |
| 2776 |
% Now arrange the matrix |
| 2777 |
% |
| 2778 |
\csname pgf@dv@legend@init@\pgfoovalueof{strategy}\endcsname |
| 2779 |
\expandafter\let\expandafter\pgf@dv@updater\csname pgf@dv@legend@update@\pgfoovalueof{strategy}\endcsname |
| 2780 |
\pgfooget{entries}\pgf@temp |
| 2781 |
\expandafter\pgf@dv@legend@arrange\pgf@temp\pgf@stop |
| 2782 |
% |
| 2783 |
% Now assemble the matrix |
| 2784 |
% |
| 2785 |
\edef\pgf@dv@row@list{1,...,\the\c@pgf@counta} |
| 2786 |
\edef\pgf@dv@column@list{1,...,\the\c@pgf@countb} |
| 2787 |
\global\let\pgf@dv@matrix\pgfutil@empty |
| 2788 |
\foreach \pgf@dv@row in \pgf@dv@row@list |
| 2789 |
{ |
| 2790 |
\global\let\pgf@dv@matrix@row\pgf@dv@first@mark |
| 2791 |
\foreach \pgf@dv@column in \pgf@dv@column@list |
| 2792 |
{ |
| 2793 |
\expandafter\let\expandafter\pgf@temp\csname pgf@dv@legend@entry@\pgf@dv@row @\pgf@dv@column\endcsname |
| 2794 |
\ifx\pgf@temp\relax |
| 2795 |
\let\pgf@temp\pgfutil@empty |
| 2796 |
\fi |
| 2797 |
\ifx\pgf@dv@matrix@row\pgf@dv@first@mark |
| 2798 |
\global\let\pgf@dv@matrix@row\pgf@temp |
| 2799 |
\else |
| 2800 |
\expandafter\pgfutil@g@addto@macro\expandafter\pgf@dv@matrix@row\expandafter{\expandafter\pgfdvnextcell\pgf@temp} |
| 2801 |
\fi |
| 2802 |
} |
| 2803 |
\pgfutil@g@addto@macro\pgf@dv@matrix@row{\pgfdvendrow} |
| 2804 |
\expandafter\pgfutil@g@addto@macro\expandafter\pgf@dv@matrix\expandafter{\pgf@dv@matrix@row} |
| 2805 |
} |
| 2806 |
\global\let\pgf@dv@matrix@row\relax |
| 2807 |
} |
| 2808 |
\let#1\pgf@dv@matrix |
| 2809 |
\global\let\pgf@dv@matrix\relax |
| 2810 |
}% |
| 2811 |
|
| 2812 |
\def\pgf@dv@first@mark{\pgf@dv@first@mark}% |
| 2813 |
|
| 2814 |
\def\pgf@dv@legend@arrange{% |
| 2815 |
\pgfutil@ifnextchar\pgf@stop{\pgfutil@gobble}{\pgf@dv@legend@handle@entry} |
| 2816 |
}% |
| 2817 |
|
| 2818 |
\def\pgf@dv@legend@handle@entry#1{ |
| 2819 |
\expandafter\def\csname pgf@dv@legend@entry@\the\c@pgf@countc @\the\c@pgf@countd\endcsname{#1}% |
| 2820 |
\pgf@dv@updater% |
| 2821 |
\pgf@dv@legend@arrange% |
| 2822 |
}% |
| 2823 |
|
| 2824 |
\expandafter\def\csname pgf@dv@legend@init@down then right\endcsname{% |
| 2825 |
\c@pgf@countc=1\relax% |
| 2826 |
\c@pgf@countd=1\relax% |
| 2827 |
}% |
| 2828 |
|
| 2829 |
\expandafter\def\csname pgf@dv@legend@update@down then right\endcsname{% |
| 2830 |
\advance\c@pgf@countc by1\relax |
| 2831 |
\ifnum\c@pgf@countc>\c@pgf@counta\relax% |
| 2832 |
\c@pgf@countc=1\relax% |
| 2833 |
\advance\c@pgf@countd by1\relax% |
| 2834 |
\fi% |
| 2835 |
}% |
| 2836 |
|
| 2837 |
\expandafter\def\csname pgf@dv@legend@init@right then down\endcsname{% |
| 2838 |
\c@pgf@countc=1\relax% |
| 2839 |
\c@pgf@countd=1\relax% |
| 2840 |
}% |
| 2841 |
|
| 2842 |
\expandafter\def\csname pgf@dv@legend@update@right then down\endcsname{% |
| 2843 |
\advance\c@pgf@countd by1\relax |
| 2844 |
\ifnum\c@pgf@countd>\c@pgf@countb\relax% |
| 2845 |
\c@pgf@countd=1\relax% |
| 2846 |
\advance\c@pgf@countc by1\relax% |
| 2847 |
\fi% |
| 2848 |
}% |
| 2849 |
|
| 2850 |
\expandafter\def\csname pgf@dv@legend@init@up then right\endcsname{% |
| 2851 |
\c@pgf@countc=\c@pgf@counta\relax% |
| 2852 |
\c@pgf@countd=1\relax% |
| 2853 |
}% |
| 2854 |
|
| 2855 |
\expandafter\def\csname pgf@dv@legend@update@up then right\endcsname{% |
| 2856 |
\advance\c@pgf@countc by-1\relax |
| 2857 |
\ifnum\c@pgf@countc=0\relax% |
| 2858 |
\c@pgf@countc=\c@pgf@counta\relax% |
| 2859 |
\advance\c@pgf@countd by1\relax% |
| 2860 |
\fi% |
| 2861 |
}% |
| 2862 |
|
| 2863 |
\expandafter\def\csname pgf@dv@legend@init@right then up\endcsname{% |
| 2864 |
\c@pgf@countc=\c@pgf@counta\relax% |
| 2865 |
\c@pgf@countd=1\relax% |
| 2866 |
}% |
| 2867 |
|
| 2868 |
\expandafter\def\csname pgf@dv@legend@update@right then up\endcsname{% |
| 2869 |
\advance\c@pgf@countd by1\relax |
| 2870 |
\ifnum\c@pgf@countd>\c@pgf@countb\relax% |
| 2871 |
\c@pgf@countd=1\relax% |
| 2872 |
\advance\c@pgf@countc by-1\relax% |
| 2873 |
\fi% |
| 2874 |
}% |
| 2875 |
|
| 2876 |
\expandafter\def\csname pgf@dv@legend@init@left then up\endcsname{% |
| 2877 |
\c@pgf@countc=\c@pgf@counta\relax% |
| 2878 |
\c@pgf@countd=\c@pgf@countb\relax% |
| 2879 |
}% |
| 2880 |
|
| 2881 |
\expandafter\def\csname pgf@dv@legend@update@left then up\endcsname{% |
| 2882 |
\advance\c@pgf@countd by-1\relax |
| 2883 |
\ifnum\c@pgf@countd=0\relax% |
| 2884 |
\c@pgf@countd=\c@pgf@countb\relax% |
| 2885 |
\advance\c@pgf@countc by-1\relax% |
| 2886 |
\fi% |
| 2887 |
}% |
| 2888 |
|
| 2889 |
\expandafter\def\csname pgf@dv@legend@init@up then left\endcsname{% |
| 2890 |
\c@pgf@countc=\c@pgf@counta\relax% |
| 2891 |
\c@pgf@countd=\c@pgf@countb\relax% |
| 2892 |
}% |
| 2893 |
|
| 2894 |
\expandafter\def\csname pgf@dv@legend@update@up then left\endcsname{% |
| 2895 |
\advance\c@pgf@countc by-1\relax |
| 2896 |
\ifnum\c@pgf@countc=0\relax% |
| 2897 |
\c@pgf@countc=\c@pgf@counta\relax% |
| 2898 |
\advance\c@pgf@countd by-1\relax% |
| 2899 |
\fi% |
| 2900 |
}% |
| 2901 |
|
| 2902 |
\expandafter\def\csname pgf@dv@legend@init@left then down\endcsname{% |
| 2903 |
\c@pgf@countc=1\relax% |
| 2904 |
\c@pgf@countd=\c@pgf@countb\relax% |
| 2905 |
}% |
| 2906 |
|
| 2907 |
\expandafter\def\csname pgf@dv@legend@update@left then down\endcsname{% |
| 2908 |
\advance\c@pgf@countd by-1\relax |
| 2909 |
\ifnum\c@pgf@countd=0\relax% |
| 2910 |
\c@pgf@countd=\c@pgf@countb\relax% |
| 2911 |
\advance\c@pgf@countc by1\relax% |
| 2912 |
\fi% |
| 2913 |
}% |
| 2914 |
|
| 2915 |
\expandafter\def\csname pgf@dv@legend@init@down then left\endcsname{% |
| 2916 |
\c@pgf@countc=1\relax% |
| 2917 |
\c@pgf@countd=\c@pgf@countb\relax% |
| 2918 |
}% |
| 2919 |
|
| 2920 |
\expandafter\def\csname pgf@dv@legend@update@down then left\endcsname{% |
| 2921 |
\advance\c@pgf@countc by1\relax |
| 2922 |
\ifnum\c@pgf@countc>\c@pgf@countb\relax% |
| 2923 |
\c@pgf@countc=1\relax% |
| 2924 |
\advance\c@pgf@countd by-1\relax% |
| 2925 |
\fi% |
| 2926 |
}% |
| 2927 |
|
| 2928 |
\def\pgf@dv@columnstext{columns}% |
| 2929 |
}% |
| 2930 |
|
| 2931 |
|
| 2932 |
|
| 2933 |
% |
| 2934 |
% Help classes |
| 2935 |
% |
| 2936 |
|
| 2937 |
\pgfooclass{interval} |
| 2938 |
{% |
| 2939 |
% Class interval |
| 2940 |
% |
| 2941 |
% Instances of this class store intervals. When either the min or |
| 2942 |
% the max value is empty, this corresponds to "not yet set", (not to |
| 2943 |
% "infinity). |
| 2944 |
|
| 2945 |
\attribute min;% |
| 2946 |
% The minimum value of the interval |
| 2947 |
|
| 2948 |
\attribute max;% |
| 2949 |
% The maximum value of the interval |
| 2950 |
|
| 2951 |
% Constructor |
| 2952 |
% |
| 2953 |
% #1 = initial minimum value |
| 2954 |
% #2 = initial maximum value |
| 2955 |
% |
| 2956 |
\method interval(#1,#2) { |
| 2957 |
\pgfooset{min}{#1} |
| 2958 |
\pgfooset{max}{#2} |
| 2959 |
}% |
| 2960 |
|
| 2961 |
% Method |
| 2962 |
\method default connects() { |
| 2963 |
}% |
| 2964 |
|
| 2965 |
% Sets the minimum/maximum to a new value |
| 2966 |
\method set min(#1) { |
| 2967 |
\pgfooset{min}{#1} |
| 2968 |
}% |
| 2969 |
\method set max(#1) { |
| 2970 |
\pgfooset{max}{#1} |
| 2971 |
}% |
| 2972 |
\method let min(#1) { |
| 2973 |
\pgfoolet{min}{#1} |
| 2974 |
}% |
| 2975 |
\method let max(#1) { |
| 2976 |
\pgfoolet{max}{#1} |
| 2977 |
}% |
| 2978 |
|
| 2979 |
% Getter |
| 2980 |
% |
| 2981 |
% Returns the current values of the minimum and maximum in the |
| 2982 |
% macros \pgfdvmin and \pgfdvmax. |
| 2983 |
\method get min and max() { |
| 2984 |
\pgfooget{min}\pgfdvmin |
| 2985 |
\pgfooget{max}\pgfdvmax |
| 2986 |
}% |
| 2987 |
|
| 2988 |
% Adjusts the minimum and maximum values |
| 2989 |
% |
| 2990 |
% #1 = some code. When this code is executed, the values of |
| 2991 |
% \pgfdvmin and \pgfdvmax will be set to the current values of |
| 2992 |
% the minimum/maximum. The code may change these values. The |
| 2993 |
% changed values will then be stored. |
| 2994 |
% |
| 2995 |
% This method does nothing that cannot be achieved also by calling |
| 2996 |
% set/get methods, but it is easier to use and faster. |
| 2997 |
\method adjust(#1) { |
| 2998 |
{% |
| 2999 |
\pgfooget{min}\pgfdvmin |
| 3000 |
\pgfooget{max}\pgfdvmax |
| 3001 |
#1% |
| 3002 |
\pgfoolet{min}\pgfdvmin |
| 3003 |
\pgfoolet{max}\pgfdvmax |
| 3004 |
}% |
| 3005 |
}% |
| 3006 |
}% |
| 3007 |
|
| 3008 |
|
| 3009 |
|
| 3010 |
\pgfooclass{count} |
| 3011 |
{% |
| 3012 |
% Class count |
| 3013 |
% |
| 3014 |
% This class can be used to count the number of data points that are |
| 3015 |
% present or that have a certain property. By default, for every |
| 3016 |
% data point a counter is incremented and the value of this counter |
| 3017 |
% is stored in an attribute. You can also specify an increment for |
| 3018 |
% the counter. You can specify that certain data points should |
| 3019 |
% not have an effect on the counter. |
| 3020 |
|
| 3021 |
|
| 3022 |
\attribute attribute;% |
| 3023 |
% The attribute that will be set to the current value of the counter |
| 3024 |
|
| 3025 |
\attribute val=0;% |
| 3026 |
% The current value of the counter |
| 3027 |
|
| 3028 |
\attribute max=0;% |
| 3029 |
% The current value of the counter |
| 3030 |
|
| 3031 |
\attribute step=1;% |
| 3032 |
% The stepping by which the counter is incremented for each |
| 3033 |
% datapoint |
| 3034 |
|
| 3035 |
\attribute start val=0;% |
| 3036 |
% The start value of the counter |
| 3037 |
|
| 3038 |
\attribute filter=;% |
| 3039 |
% This attribute stores some code that is executed for each |
| 3040 |
% data point. If the data point sets the TeX-if ifpgfdvfilterpassed to |
| 3041 |
% true, then the counter is not incremented. |
| 3042 |
|
| 3043 |
|
| 3044 |
% Constructor |
| 3045 |
% |
| 3046 |
% #1 = The attribute in which the counter value is stored |
| 3047 |
% |
| 3048 |
\method count(#1) { |
| 3049 |
\pgfooset{attribute}{#1} |
| 3050 |
}% |
| 3051 |
|
| 3052 |
% Method |
| 3053 |
\method default connects() { |
| 3054 |
\pgfoothis.get handle(\pgf@dv@me) |
| 3055 |
\pgfkeysvalueof{/pgf/data visualization/obj}.connect(\pgf@dv@me,apply,prepare datapoint signal) |
| 3056 |
\pgfkeysvalueof{/pgf/data visualization/obj}.connect(\pgf@dv@me,phase,phase signal) |
| 3057 |
}% |
| 3058 |
|
| 3059 |
% Getter |
| 3060 |
\method get max(#1) { |
| 3061 |
\pgfooget{max}{#1} |
| 3062 |
}% |
| 3063 |
|
| 3064 |
% Setter |
| 3065 |
\method set value(#1) { |
| 3066 |
\pgfooset{val}{#1} |
| 3067 |
\pgfkeyssetvalue{/data point/\pgfoovalueof{attribute}}{#1}% |
| 3068 |
}% |
| 3069 |
|
| 3070 |
% Setter |
| 3071 |
\method set start value(#1) { |
| 3072 |
\pgfooset{start val}{#1} |
| 3073 |
\pgfooset{max}{#1} |
| 3074 |
}% |
| 3075 |
|
| 3076 |
% Setter |
| 3077 |
\method set filter(#1) { |
| 3078 |
\pgfooset{filter}{#1} |
| 3079 |
}% |
| 3080 |
|
| 3081 |
% Setter |
| 3082 |
\method set step(#1) { |
| 3083 |
\pgfooset{step}{#1} |
| 3084 |
}% |
| 3085 |
|
| 3086 |
% Slot |
| 3087 |
\method apply() { |
| 3088 |
\pgfdvfilterpassedtrue% |
| 3089 |
\pgfoovalueof{filter}% |
| 3090 |
\ifpgfdvfilterpassed% |
| 3091 |
\pgfmathparse{\pgfoovalueof{val}+\pgfoovalueof{step}}% |
| 3092 |
\pgfoolet{val}\pgfmathresult% |
| 3093 |
\pgfkeyslet{/data point/\pgfoovalueof{attribute}}\pgfmathresult% |
| 3094 |
\ifdim\pgfmathresult pt>\pgfoovalueof{max}pt\relax% |
| 3095 |
\pgfoolet{max}\pgfmathresult% |
| 3096 |
\fi% |
| 3097 |
\pgfooget{max}\pgfmathresult% |
| 3098 |
\pgfkeyslet{/data point/\pgfoovalueof{attribute}/max}\pgfmathresult% |
| 3099 |
\fi% |
| 3100 |
}% |
| 3101 |
|
| 3102 |
% Slot |
| 3103 |
\method phase(#1) { |
| 3104 |
\ifx#1\pgfdvbeginsurvey |
| 3105 |
\pgfooeset{val}{\pgfoovalueof{start val}} |
| 3106 |
\else \ifx#1\pgfdvbeginvisualization |
| 3107 |
\pgfooeset{val}{\pgfoovalueof{start val}} |
| 3108 |
\fi\fi |
| 3109 |
}% |
| 3110 |
}% |
| 3111 |
|
| 3112 |
\newif\ifpgfdvfilterpassed |
| 3113 |
|
| 3114 |
|
| 3115 |
|
| 3116 |
|
| 3117 |
\pgfooclass{accumulator} |
| 3118 |
{% |
| 3119 |
% Class accumulator |
| 3120 |
% |
| 3121 |
% This class is used to keep track of the sum of the values of some |
| 3122 |
% attribute. When this object is connected to some attribute, the |
| 3123 |
% subkey attribute/sum will always contain the sum of all values in |
| 3124 |
% all previous data points with respect to this |
| 3125 |
% attribute. Furthermore, the subkey attribute/prev key will hold |
| 3126 |
% the previous sum, which is sometimes also useful to have access |
| 3127 |
% to. |
| 3128 |
|
| 3129 |
\attribute attribute;% |
| 3130 |
% The attribute to-be-accumulated |
| 3131 |
|
| 3132 |
\attribute sum;% |
| 3133 |
% The initial value of the sum |
| 3134 |
|
| 3135 |
% Constructor |
| 3136 |
% |
| 3137 |
% #1 = to-be-accumulated attribute |
| 3138 |
\method accumulator(#1) { |
| 3139 |
\pgfooset{attribute}{#1} |
| 3140 |
\pgfoothis.reset() |
| 3141 |
}% |
| 3142 |
|
| 3143 |
% Method |
| 3144 |
\method default connects() { |
| 3145 |
\pgfoothis.get handle(\pgf@dv@me) |
| 3146 |
\pgfkeysvalueof{/pgf/data visualization/obj}.connect(\pgf@dv@me,apply,prepare datapoint signal) |
| 3147 |
\pgfkeysvalueof{/pgf/data visualization/obj}.connect(\pgf@dv@me,phase,phase signal) |
| 3148 |
}% |
| 3149 |
|
| 3150 |
% Slot |
| 3151 |
\method apply() {% |
| 3152 |
% Save old sum |
| 3153 |
\pgfkeysgetvalue{/data point/\pgfoovalueof{attribute}/sum}\pgf@temp% |
| 3154 |
\pgfkeyslet{/data point/\pgfoovalueof{attribute}/prev sum}\pgf@temp% |
| 3155 |
% Add new attribute... |
| 3156 |
\pgfkeysgetvalue{/data point/\pgfoovalueof{attribute}}{\pgf@temp@b}% |
| 3157 |
\pgfdvmathenter{\pgf@dv@new@val}{\pgf@temp@b}% |
| 3158 |
% ... to sum |
| 3159 |
\pgfooget{sum}\pgf@dv@sum% |
| 3160 |
\pgfdvmathadd{\pgf@dv@sum}{\pgf@dv@new@val}{\pgf@dv@sum}% |
| 3161 |
\pgfoolet{sum}\pgf@dv@sum |
| 3162 |
% Record in attribute |
| 3163 |
\pgfdvmathexitbyscientificformat{\pgf@dv@serial@sum}{\pgf@dv@sum} |
| 3164 |
\pgfkeyslet{/data point/\pgfoovalueof{attribute}/sum}\pgf@dv@serial@sum |
| 3165 |
}% |
| 3166 |
|
| 3167 |
% Method |
| 3168 |
% |
| 3169 |
% Use this method to reset the sum at any point. |
| 3170 |
% |
| 3171 |
\method reset() { |
| 3172 |
\pgfdvmathenter{\pgf@dv@temp}{0} |
| 3173 |
\pgfoolet{sum}{\pgf@dv@temp} |
| 3174 |
\pgfdvmathexitbyserializing{\pgf@dv@zero}{\pgf@dv@temp} |
| 3175 |
\pgfkeyslet{/data point/\pgfoovalueof{attribute}/prev sum}{\pgf@dv@zero} |
| 3176 |
\pgfkeyslet{/data point/\pgfoovalueof{attribute}/sum}{\pgf@dv@zero} |
| 3177 |
}% |
| 3178 |
|
| 3179 |
% Slot |
| 3180 |
\method phase(#1) { |
| 3181 |
\ifx#1\pgfdvbeginsurvey |
| 3182 |
\pgfoothis.reset() |
| 3183 |
\else \ifx#1\pgfdvbeginvisualization |
| 3184 |
\pgfoothis.reset() |
| 3185 |
\fi\fi |
| 3186 |
}% |
| 3187 |
}% |
| 3188 |
|
| 3189 |
|
| 3190 |
|
| 3191 |
|
| 3192 |
|
| 3193 |
|
| 3194 |
|
| 3195 |
% |
| 3196 |
% |
| 3197 |
% Help keys and, attributes |
| 3198 |
% |
| 3199 |
% |
| 3200 |
|
| 3201 |
\pgfkeys{% do not even think of changing the values of the following: |
| 3202 |
/data point/always true/.initial=true, |
| 3203 |
/data point/always false/.initial=false, |
| 3204 |
/data point/always 0/.initial=0, |
| 3205 |
/data point/always 1/.initial=1, |
| 3206 |
/data point/always empty/.initial=, |
| 3207 |
/data point/always pgfusepath stroke/.initial=\pgfusepath{stroke}, |
| 3208 |
}% |
| 3209 |
|
| 3210 |
\pgfdvmathenter{\pgfdvmathalwaysloge}{0.434294481903252}% |
| 3211 |
\pgfdvmathenter{\pgfdvmathalwayslnten}{2.302585092994046}% |
| 3212 |
\pgfdvmathenter{\pgfdvmathalwayszero}{0}% |
| 3213 |
\pgfdvmathenter{\pgfdvmathalwaysone}{1}% |
| 3214 |
|
| 3215 |
|
| 3216 |
\endinput |