Debian Codegraph @

texmf-dist/tex/latex/pgfplots/libs/tikzlibrarypgfplots.clickable.code.tex

raw
1 %--------------------------------------------
2 %
3 % Package pgfplots, library for dynamic content in PDF files
4 % (clickable plots)
5 %
6 % Copyright 2007/2008 by Christian Feuersänger.
7 %
8 % This program is free software: you can redistribute it and/or modify
9 % it under the terms of the GNU General Public License as published by
10 % the Free Software Foundation, either version 3 of the License, or
11 % (at your option) any later version.
12 %
13 % This program is distributed in the hope that it will be useful,
14 % but WITHOUT ANY WARRANTY; without even the implied warranty of
15 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 % GNU General Public License for more details.
17 %
18 % You should have received a copy of the GNU General Public License
19 % along with this program. If not, see <http://www.gnu.org/licenses/>.
20 %
21 %--------------------------------------------
22
23 \pgfutil@ifundefined{pgfplotsset}{%
24 \PackageError{pgfplots}{Sorry, \string\usetikzlibrary{pgfplots.clickable} needs to hook into PGFPlots routines, disabling it -- please provide the command AFTER \string\usepackage{pgfplots}}{}%
25 \endinput
26 }{%
27 }%
28
29
30 \edef\pgfplotscatcodeDQ{\the\catcode`\"}%
31 \catcode`\"=12
32 \newif\ifpgfplots@clickable
33 \newif\ifpgfplots@annot@printable
34
35 \pgfqkeys{/pgfplots}{
36 @backgroundpath@hook/.add code={}{\pgfplots@create@clickable@plotarea@hook},
37 clickable/.is if=pgfplots@clickable,
38 clickable/.default=true,
39 clickable=true,
40 /pgfplots/execute at begin axis/.add={}{%
41 \pgfplots@clickable@beginaxis
42 },%
43 clickable coords code/.code={%
44 \def\pgfplots@clickable@init@@{%
45 \pgfplots@clickable@startcoordcollect
46 \pgfplotsset{%
47 /pgfplots/execute at end plot@@/.add={}{%
48 \pgfplots@clickable@endcoordcollect
49 },
50 /pgfplots/execute for finished point/.add={}{%
51 \pgfplots@clickable@coordcollect{#1}%
52 },%
53 }%
54 \let\pgfplots@clickable@init@@=\relax
55 }%
56 \pgfkeysalso{%
57 /pgfplots/execute at begin plot@@/.add={}{%
58 \pgfplots@clickable@init@@
59 },
60 }%
61 },
62 clickable coords/.style={
63 clickable coords code={\def\pgfplotsretval{#1}},
64 },
65 clickable coords/.default={(xy)},
66 annot/js fillColor/.initial={["RGB",1,1,.855]},
67 annot/point format/.initial={(\%.1f, \%.1f)},
68 annot/point format 3d/.initial={(\%.1f, \%.1f, \%.1f)},
69 annot/slope format/.initial={\%.1f*x \%+.1f},
70 annot/printable/.is if=pgfplots@annot@printable,
71 annot/printable/.default=true,
72 % Available are:
73 % Times-Roman font.Times
74 % Times-Bold font.TimesB
75 % Times-Italic font.TimesI
76 % Times-BoldItalic font.TimesBI
77 % Helvetica font.Helv
78 % Helvetica-Bold font.HelvB
79 % Helvetica-Oblique font.HelvI
80 % Helvetica-BoldOblique font.HelvBI
81 % Courier font.Cour
82 % Courier-Bold font.CourB
83 % Courier-Oblique font.CourI
84 % Courier-BoldOblique font.CourBI
85 % Symbol font.Symbol
86 % ZapfDingbats font.ZapfD
87 annot/font/.initial={font.Times},
88 % annot/font={"CMR10"},
89 annot/textSize/.initial=11,
90 annot/richtext/.initial=true,
91 annot/richtext/.default=true,
92 annot/popup size generic/.initial=auto,
93 annot/popup size snap/.initial=auto,
94 clickable coords size/.style={
95 /pgfplots/annot/popup size snap={#1},
96 },
97 annot/popup size/.style={
98 /pgfplots/annot/popup size generic={#1},
99 /pgfplots/annot/popup size snap={#1},
100 },
101 annot/width/.initial=,
102 annot/height/.initial=,
103 annot/jsname/.initial=,
104 annot/dim/.initial=2,
105 annot/xmin/.initial=,
106 annot/xmax/.initial=,
107 annot/ymin/.initial=,
108 annot/ymax/.initial=,
109 annot/zmin/.initial=,
110 annot/zmax/.initial=,
111 annot/xscale/.initial=, % "log" or "linear" or "log:<basis>"
112 annot/yscale/.initial=,
113 annot/zscale/.initial=,
114 annot/minminmin/.initial=,
115 annot/xaxis/.initial=,
116 annot/yaxis/.initial=,
117 annot/zaxis/.initial=,
118 % format:
119 % [<plot1coords>, <plot2coords>,...,<plotncoords>]
120 % with <ploticoords> = [<coord>,<coord>,....,<coord>]
121 % and <coord> = [ <x>, <y>, "text" ]
122 % for example:
123 % [[[0.0e0,-4.0849609e-1,": (0,0)"],[1.25e-1,-3.7412109e-1,": (3,1)"],[2.5e-1,-3.0849609e-1,": (2,1)"],[3.75e-1,-2.1162109e-1,": (3,3)"],[5.0e-1,-8.3496094e-2,": (1,1)"],[6.25e-1,7.5878906e-2,": (3,5)"],[7.5e-1,2.6650391e-1,": (2,3)"],[8.75e-1,4.8837891e-1,": (3,7)"],[1.0e0,7.4150391e-1,": (0,1)"]]]
124 annot/collected plots/.initial=,
125 annot/snap dist/.initial=4,
126 every semilogy axis/.append style={/pgfplots/annot/point format={(\%.1f, \%.1e)}},
127 every semilogx axis/.append style={/pgfplots/annot/point format={(\%.1e, \%.1f)}},
128 every loglog axis/.append style={/pgfplots/annot/point format={(\%.1e, \%.1e)}},
129 }
130
131 \pgfkeysifdefined{/pgfplots/annot/xy pattern}{%
132 }{%
133 \pgfkeyssetvalue{/pgfplots/annot/xy pattern}{(xy)}%
134 }%
135 \pgfkeysifdefined{/pgfplots/annot/no such coord}{%
136 }{%
137 \pgfkeyssetvalue{/pgfplots/annot/no such coord}{--}%
138 }%
139
140 % ATTENTION:
141 % The eforms package creates \begin{Form} and \end{Form} in \AtBeginDocument and \AtEndDocument!
142 \def\pgfplots@glob@TMPa{pgfsys-pdftex.def}
143 \ifx\pgfplots@glob@TMPa\pgfsysdriver
144 \RequirePackage[pdftex]{insdljs}
145 \RequirePackage[pdftex]{eforms}
146 \else
147 \def\pgfplots@glob@TMPa{pgfsys-dvipdfm.def}
148 \ifx\pgfplots@glob@TMPa\pgfsysdriver
149 \RequirePackage[dvipdfm]{insdljs}
150 \RequirePackage[dvipdfm]{eforms}
151 \else
152 \def\pgfplots@glob@TMPa{pgfsys-dvips.def}
153 \ifx\pgfplots@glob@TMPa\pgfsysdriver
154 \RequirePackage[dvips]{insdljs}
155 \RequirePackage[dvips]{eforms}
156 \else
157 \def\pgfplots@glob@TMPa{pgfsys-textures.def}
158 \ifx\pgfplots@glob@TMPa\pgfsysdriver
159 \RequirePackage[textures]{insdljs}
160 \RequirePackage[textures]{eforms}
161 \else
162 \RequirePackage{insdljs}
163 \RequirePackage{eforms}
164 \fi\fi\fi\fi
165
166 % Work-around for a bug in \begindljs of acrotex:
167 % if " is active, \begindljs will be wrong.
168 %--------------------------------------------------
169 % HAS BEEN FIXED IN THE MEANTIME
170 % \def\begindljs
171 % {%
172 % \iwvo{\string\begingroup}
173 % {\uccode`c=`\%\uppercase{\iwvo{\string\obeyspaces\string\obeylines\string\global\string\let\string^\string^M=\string\jsR c}}}
174 % {\escapechar=-1 \lccode`C=`\%\lowercase{\iwvo{\string\\catcode`\string\\"=12C}}}
175 % }
176 %--------------------------------------------------
177
178 % Bugfix to fix incompatibility when '<' and '>' are active (as for
179 % \usepackage[spanish]{babel}:
180 \def\write@objs@BUGGY
181 {%
182 \iwvo{\begingroup}
183 {\lccode`C=`\%\lowercase{\iwvo{\string\ccpdftex C}}}
184 {\lccode`C=`\%\lowercase{\iwvo{\string\input{dljscc.def}C\the\dljsobjtoks}}}
185 \iwvo{\endgroup}
186 \iwvo{\string\endinput}%
187 }
188 \def\write@objs@CORRECT
189 {%
190 \iwvo{\begingroup}
191 \iwvo{\string\catcode`\string\<=12 }
192 \iwvo{\string\catcode`\string\>=12 }
193 {\lccode`C=`\%\lowercase{\iwvo{\string\ccpdftex C}}}
194 {\lccode`C=`\%\lowercase{\iwvo{\string\input{dljscc.def}C\the\dljsobjtoks}}}
195 \iwvo{\endgroup}
196 \iwvo{\string\endinput}%
197 }
198 \pgfutil@IfUndefined{write@objs}{}{%
199 \ifx\write@objs\write@objs@BUGGY
200 \let\write@objs=\write@objs@CORRECT
201 \fi
202 }%
203
204 \def\pgfplots@clickable@no{0}
205
206 % This catcode-hackery is too much for me, I don't get '|' to work in
207 % conjunction with ltxdoc document style.
208 % So, I simply use \pgfplotsVERTBAR instead... *sigh*.
209
210 % this here is a bugfix to resolve an incompatibility between insdljs
211 % an \usepackage[spanish]{babel}:
212 \def\@roman#1{\romannumeral #1}%
213
214 % FIXME : write this stuff DIRECTLY into a pdf using \pdfobj! I don't
215 % need ANY TeX code inside of the methods. Maybe I can even use some
216 % sort of "include external .js file" command instead of /S /Javascript /JS
217 %
218 % FIXME : collect this stuff using \beginpgfplotsverbatim ...
219 % \endpgfplotsverbatim to avoid the \catcode problems! Who knows
220 % whether there are more of them...
221 %
222 % FIXME : using '\jobname' here produces a bug in insdljs :-(
223 % The problem: insdljs creates a macro named 'dlsj\jobname' or
224 % something like that, but if fails to use '\csname' properly. So:
225 % only normal letters are allowed inside of the argument here.
226 \begin{insDLJS}[processAnnotatedPlot]{pgfplotsJS}{pgfplots Clickable Plot Code}
227 /*********************************************************************************
228 * function sprintf() - written by Kevin van Zonneveld as part of the php to javascript
229 * conversion project.
230 *
231 * More info at: http://kevin.vanzonneveld.net/techblog/article/phpjs_licensing/
232 *
233 * This is version: 1.33
234 * php.js is copyright 2008 Kevin van Zonneveld.
235 *
236 * Portions copyright Michael White (http://crestidg.com), _argos, Jonas
237 * Raoni Soares Silva (http://www.jsfromhell.com), Legaev Andrey, Ates Goral
238 * (http://magnetiq.com), Philip Peterson, Martijn Wieringa, Webtoolkit.info
239 * (http://www.webtoolkit.info/), Carlos R. L. Rodrigues
240 * (http://www.jsfromhell.com), Ash Searle (http://hexmen.com/blog/),
241 * Erkekjetter, GeekFG (http://geekfg.blogspot.com), Johnny Mast
242 * (http://www.phpvrouwen.nl), marrtins, Alfonso Jimenez
243 * (http://www.alfonsojimenez.com), Aman Gupta, Arpad Ray
244 * (mailto:[email protected]), Karol Kowalski, Mirek Slugen, Thunder.m, Tyler
245 * Akins (http://rumkin.com), d3x, mdsjack (http://www.mdsjack.bo.it), Alex,
246 * Alexander Ermolaev (http://snippets.dzone.com/user/AlexanderErmolaev),
247 * Allan Jensen (http://www.winternet.no), Andrea Giammarchi
248 * (http://webreflection.blogspot.com), Arno, Bayron Guevara, Ben Bryan,
249 * Benjamin Lupton, Brad Touesnard, Brett Zamir, Cagri Ekin, Cord, David,
250 * David James, DxGx, FGFEmperor, Felix Geisendoerfer
251 * (http://www.debuggable.com/felix), FremyCompany, Gabriel Paderni, Howard
252 * Yeend, J A R, Leslie Hoare, Lincoln Ramsay, Luke Godfrey, MeEtc
253 * (http://yass.meetcweb.com), Mick@el, Nathan, Nick Callen, Ozh, Pedro Tainha
254 * (http://www.pedrotainha.com), Peter-Paul Koch
255 * (http://www.quirksmode.org/js/beat.html), Philippe Baumann, Sakimori,
256 * Sanjoy Roy, Simon Willison (http://simonwillison.net), Steve Clay, Steve
257 * Hilder, Steven Levithan (http://blog.stevenlevithan.com), T0bsn, Thiago
258 * Mata (http://thiagomata.blog.com), Tim Wiel, XoraX (http://www.xorax.info),
259 * Yannoo, baris ozdil, booeyOH, djmix, dptr1988, duncan, echo is bad, gabriel
260 * paderni, ger, gorthaur, jakes, john (http://www.jd-tech.net), kenneth,
261 * loonquawl, penutbutterjelly, stensi
262 *
263 * Dual licensed under the MIT (MIT-LICENSE.txt)
264 * and GPL (GPL-LICENSE.txt) licenses.
265 *
266 * Permission is hereby granted, free of charge, to any person obtaining a
267 * copy of this software and associated documentation files (the
268 * "Software"), to deal in the Software without restriction, including
269 * without limitation the rights to use, copy, modify, merge, publish,
270 * distribute, sublicense, and/or sell copies of the Software, and to
271 * permit persons to whom the Software is furnished to do so, subject to
272 * the following conditions:
273 *
274 * The above copyright notice and this permission notice shall be included
275 * in all copies or substantial portions of the Software.
276 *
277 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
278 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
279 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
280 * IN NO EVENT SHALL KEVIN VAN ZONNEVELD BE LIABLE FOR ANY CLAIM, DAMAGES
281 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
282 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
283 * OTHER DEALINGS IN THE SOFTWARE.
284 */
285 // ATTENTION: this method has been masked such that special characters of TeX and javascript
286 // don't produce problems.
287 function sprintf( ) {
288 // Return a formatted string
289 //
290 // + discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_sprintf/
291 // + version: 804.1712
292 // + original by: Ash Searle (http://hexmen.com/blog/)
293 // + namespaced by: Michael White (http://crestidg.com)
294 // * example 1: sprintf("\pgfplotsPERCENT01.2f", 123.1);
295 // * returns 1: 123.10
296
297 var regex = /\pgfplotsPERCENT\pgfplotsPERCENT\pgfplotsVERTBAR\pgfplotsPERCENT(\d+\$)?([-+\pgfplotsHASH0 ]*)(\*\d+\$\pgfplotsVERTBAR\*\pgfplotsVERTBAR\d+)?(\.(\*\d+\$\pgfplotsVERTBAR\*\pgfplotsVERTBAR\d+))?([scboxXuidfegEG])/g;
298 var a = arguments, i = 0, format = a[i++];
299
300 // pad()
301 var pad = function(str, len, chr, leftJustify) {
302 var padding = (str.length >= len) ? '' : Array(1 + len - str.length >>> 0).join(chr);
303 return leftJustify ? str + padding : padding + str;
304 };
305
306 // justify()
307 var justify = function(value, prefix, leftJustify, minWidth, zeroPad) {
308 var diff = minWidth - value.length;
309 if (diff > 0) {
310 if (leftJustify \pgfplotsVERTBAR\pgfplotsVERTBAR !zeroPad) {
311 value = pad(value, minWidth, ' ', leftJustify);
312 } else {
313 value = value.slice(0, prefix.length) + pad('', diff, '0', true) + value.slice(prefix.length);
314 }
315 }
316 return value;
317 };
318
319 // formatBaseX()
320 var formatBaseX = function(value, base, prefix, leftJustify, minWidth, precision, zeroPad) {
321 // Note: casts negative numbers to positive ones
322 var number = value >>> 0;
323 prefix = prefix && number && {'2': '0b', '8': '0', '16': '0x'}[base] \pgfplotsVERTBAR\pgfplotsVERTBAR '';
324 value = prefix + pad(number.toString(base), precision \pgfplotsVERTBAR\pgfplotsVERTBAR 0, '0', false);
325 return justify(value, prefix, leftJustify, minWidth, zeroPad);
326 };
327
328 // formatString()
329 var formatString = function(value, leftJustify, minWidth, precision, zeroPad) {
330 if (precision != null) {
331 value = value.slice(0, precision);
332 }
333 return justify(value, '', leftJustify, minWidth, zeroPad);
334 };
335
336 // finalFormat()
337 var doFormat = function(substring, valueIndex, flags, minWidth, _, precision, type) {
338 if (substring == '\pgfplotsPERCENT\pgfplotsPERCENT') return '\pgfplotsPERCENT';
339
340 // parse flags
341 var leftJustify = false, positivePrefix = '', zeroPad = false, prefixBaseX = false;
342 for (var j = 0; flags && j < flags.length; j++) switch (flags.charAt(j)) {
343 case ' ': positivePrefix = ' '; break;
344 case '+': positivePrefix = '+'; break;
345 case '-': leftJustify = true; break;
346 case '0': zeroPad = true; break;
347 case '\pgfplotsHASH': prefixBaseX = true; break;
348 }
349
350 // parameters may be null, undefined, empty-string or real valued
351 // we want to ignore null, undefined and empty-string values
352 if (!minWidth) {
353 minWidth = 0;
354 } else if (minWidth == '*') {
355 minWidth = +a[i++];
356 } else if (minWidth.charAt(0) == '*') {
357 minWidth = +a[minWidth.slice(1, -1)];
358 } else {
359 minWidth = +minWidth;
360 }
361
362 // Note: undocumented perl feature:
363 if (minWidth < 0) {
364 minWidth = -minWidth;
365 leftJustify = true;
366 }
367
368 if (!isFinite(minWidth)) {
369 throw new Error('sprintf: (minimum-)width must be finite');
370 }
371
372 if (!precision) {
373 precision = 'fFeE'.indexOf(type) > -1 ? 6 : (type == 'd') ? 0 : void(0);
374 } else if (precision == '*') {
375 precision = +a[i++];
376 } else if (precision.charAt(0) == '*') {
377 precision = +a[precision.slice(1, -1)];
378 } else {
379 precision = +precision;
380 }
381
382 // grab value using valueIndex if required?
383 var value = valueIndex ? a[valueIndex.slice(0, -1)] : a[i++];
384
385 switch (type) {
386 case 's': return formatString(String(value), leftJustify, minWidth, precision, zeroPad);
387 case 'c': return formatString(String.fromCharCode(+value), leftJustify, minWidth, precision, zeroPad);
388 case 'b': return formatBaseX(value, 2, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
389 case 'o': return formatBaseX(value, 8, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
390 case 'x': return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
391 case 'X': return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad).toUpperCase();
392 case 'u': return formatBaseX(value, 10, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
393 case 'i':
394 case 'd': {
395 var number = parseInt(+value);
396 var prefix = number < 0 ? '-' : positivePrefix;
397 value = prefix + pad(String(Math.abs(number)), precision, '0', false);
398 return justify(value, prefix, leftJustify, minWidth, zeroPad);
399 }
400 case 'e':
401 case 'E':
402 case 'f':
403 case 'F':
404 case 'g':
405 case 'G':
406 {
407 var number = +value;
408 var prefix = number < 0 ? '-' : positivePrefix;
409 var method = ['toExponential', 'toFixed', 'toPrecision']['efg'.indexOf(type.toLowerCase())];
410 var textTransform = ['toString', 'toUpperCase']['eEfFgG'.indexOf(type) \pgfplotsPERCENT 2];
411 value = prefix + Math.abs(number)[method](precision);
412 return justify(value, prefix, leftJustify, minWidth, zeroPad)[textTransform]();
413 }
414 default: return substring;
415 }
416 };
417
418 return format.replace(regex, doFormat);
419 }
420 /*********************************************************************************/
421
422 % see https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Inheritance
423
424 var lastPoint = null;
425 var posOnMouseDownX = -1;
426 var posOnMouseDownY = -1;
427
428 // preallocation.
429 var tmpArray1 = new Array(3);
430 var tmpArray2 = new Array(3);
431
432 var clickablePatternForXY="\pgfkeysvalueof{/pgfplots/annot/xy pattern}";
433 var clickableStringNoSuchCoord = "\pgfkeysvalueof{/pgfplots/annot/no such coord}";
434
435 var nan = Number.NaN;
436 var NAN = Number.NaN;
437 var inf = Number.POSITIVE_INFINITY;
438 var INF = Number.POSITIVE_INFINITY;
439
440 var pgfplotsAxisRegistry = new Object();
441 pgfplotsAxisRegistry["rectangle"] = function( axisAnnotObj ) { return new PGFPlotsAxis( axisAnnotObj ); }
442 pgfplotsAxisRegistry["ternary"] = function( axisAnnotObj ) { return new PGFPlotsTernaryAxis( axisAnnotObj ); }
443
444 function PGFPlotsClassExtend( child, superClass )
445 {
446 for (var property in superClass.prototype) {
447 if (typeof child.prototype[property] == "undefined")
448 child.prototype[property] = superClass.prototype[property];
449 }
450 return child;
451 }
452
453 function PGFPlotsCreateAxisFor( axisAnnotObj, docObject )
454 {
455 var ret = null;
456 if( pgfplotsAxisRegistry[axisAnnotObj.axisType] ) {
457 ret = pgfplotsAxisRegistry[axisAnnotObj.axisType](axisAnnotObj);
458 ret.docObject = docObject;
459 }
460 return ret;
461 }
462
463 function ClickableCoord(canvasx,canvasy, realx,realy, text)
464 {
465 this.dim=2;
466 this.canvasx=canvasx;
467 this.canvasy=canvasy;
468 this.realx=realx;
469 this.realy=realy;
470 this.text=text;
471 }
472 ClickableCoord.prototype =
473 {
474 dim : 0,
475 canvasx : 0,
476 canvasy : 0,
477 realx : 0,
478 realy : 0,
479 realz : 0,
480 text : "",
481 sourcePlotIdx : -1,
482 sourceCoordIdx : -1,
483
484 isSnapToNearestCoord : function() {
485 return this.sourcePlotIdx >= 0;
486 },
487
488 /**
489 * Takes an already existing TextField, changes its value to point.text and places it at (x,y).
490 * Additional \c displayOpts will be used to format it.
491 */
492 draw : function( docObject, canvas, displayOpts )
493 {
494 var charsX = 1;
495 var charsY = 1.5;
496 var popupSize = ( this.isSnapToNearestCoord() ? displayOpts.popupSizeSnap : displayOpts.popupSizeGeneric );
497 if( popupSize == "auto" ) {
498 charsX = Math.max( 5,this.text.length )/2;
499
500 } else {
501 var commaOff = popupSize.indexOf( "," );
502 if( commaOff >= 0 ) {
503 charsX = popupSize.substring( 0, commaOff );
504 charsY = popupSize.substring( commaOff+1 );
505 } else
506 charsX = popupSize;
507 }
508 // console.println( this.text );
509
510 if( !displayOpts.richText )
511 canvas.value = ""+this.text;
512 else {
513 canvas.richText=true;
514 var xmlValue = "<?xml version=\"1.0\"?>"+
515 "<body> " + % xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:xfa=\"http://www.xfa.org/schema/xfa-data/1.0/\" xfa:APIVersion=\"Acrobat:9.3.2\" xfa:spec=\"2.0.2\">" +
516 %"<p>"+
517 "<span>"+ % style="font-size:9.0pt;text-align:left;color:#7E0000;font-weight:normal;font-style:normal;font-family:Helvetica,sans-serif;font-stretch:normal"
518 this.text +
519 "</span>"+
520 %"</p>"+
521 "</body>";
522 canvas.richValue = util.xmlToSpans(xmlValue);
523 % debug helper:
524 % spans= new Array();
525 % spans[0] = new Object();
526 % spans[0].text = this.text;
527 % spans[0].textColor = ["RGB",0.5,0,0];
528 % canvas.richValue = spans;
529 % console.println(util.spansToXML(canvas.richValue));
530 }
531 var R = canvas.rect;
532 R[0] = this.canvasx;
533 R[1] = this.canvasy;
534 R[2] = R[0] + charsX*displayOpts.textSize;
535 R[3] = R[1] - charsY*displayOpts.textSize;
536 canvas.rect = R;
537 canvas.textFont = displayOpts.textFont;
538 canvas.textSize = displayOpts.textSize;
539 canvas.multiline = true;
540 canvas.fillColor = displayOpts.fillColor;//["RGB",1,1,.855];
541 canvas.doNotSpellCheck = true;
542 canvas.readonly = true;
543 if( displayOpts.printable )
544 canvas.display = display.visible;
545 else
546 canvas.display = display.noPrint;
547
548 var mark = docObject.getField( canvas.name + "mark");
549 if( mark ) {
550 R = mark.rect;
551 R[0]=this.canvasx-2;
552 R[1]=this.canvasy-2;
553 R[2]=R[0]+4;
554 R[3]=R[1]+4;
555 mark.value="";
556 mark.rect = R;
557 mark.fillColor = ["RGB",0,0,0];
558 mark.doNotSpellCheck = true;
559 mark.readonly = true;
560 if( displayOpts.printable )
561 mark.display = display.visible;
562 else
563 mark.display = display.noPrint;
564 }
565 }
566 }
567
568
569
570 function PGFPlotsAxis(properties) {
571 for (var property in properties)
572 this[property] = properties[property];
573 }
574 PGFPlotsAxis.prototype = {
575 /**
576 * @return an instance of ClickableCoord or null.
577 * The returned canvas coordinates are NOT yet initialised.
578 */
579 findNearest : function( point, rect, startSearchAt )
580 {
581 var actx;
582 var acty;
583 var minSoFar = 1e324;
584 var minPtSoFar = null;
585 var tmpPt = null;
586 var dist =0;
587 var startPlot = 0;
588 var startCoord = 0;
589 var collectedPlots = this.collectedPlots;
590 if( point.dim > 2 )
591 tmpPt = new ClickableCoord(0,0,0,0,"");
592
593 if( startSearchAt != null && startSearchAt.isSnapToNearestCoord() ) {
594 startPlot = startSearchAt.sourcePlotIdx;
595 startCoord= startSearchAt.sourceCoordIdx;
596 }
597 for( var i = startPlot; i<collectedPlots.length; ++i ) {
598 for( var j = startCoord; j<collectedPlots[i].length; ++j ) {
599 if( point.dim == 2 ) {
600 actx = collectedPlots[i][j][0] - point.realx;
601 acty = collectedPlots[i][j][1] - point.realy;
602 } else {
603 // dim > 2 should be compared using CANVAS coordinates, not real coordinates:
604 tmpPt.realx = collectedPlots[i][j][0];
605 tmpPt.realy = collectedPlots[i][j][1];
606 if( collectedPlots[i][j].length-1 >= 3 )
607 tmpPt.realz = collectedPlots[i][j][2];
608 else
609 tmpPt.realz = 0;
610 this.computeCanvasFor( tmpPt, rect );
611 actx = tmpPt.canvasx - point.canvasx;
612 acty = tmpPt.canvasy - point.canvasy;
613 }
614 dist = actx*actx + acty*acty;
615 if( dist < minSoFar ) {
616 if( minPtSoFar == null )
617 minPtSoFar = new ClickableCoord(-1,-1,0,0,"");
618 minPtSoFar.realx = collectedPlots[i][j][0];
619 minPtSoFar.realy = collectedPlots[i][j][1];
620 if( collectedPlots[i][j].length-1 >= 3 )
621 minPtSoFar.realz = collectedPlots[i][j][2];
622 else
623 minPtSoFar.realz = 0;
624 minPtSoFar.text= collectedPlots[i][j][ collectedPlots[i][j].length-1 ];
625 minPtSoFar.sourcePlotIdx = i;
626 minPtSoFar.sourceCoordIdx = j;
627 minSoFar = dist;
628 }
629 }
630 }
631 if( minPtSoFar )
632 this.computeCanvasFor(minPtSoFar,rect);
633 return minPtSoFar;
634 },
635
636 /**
637 * Returns either a ClickableCoord describing the point under the mouse cursor or a snap--to--nearest result near the mouse cursor.
638 *
639 * @param this the axis in which we shall search.
640 * @param x,y the input canvas coordinates
641 * @param canvas a pointer to the Drawing object (TextField) whose 'rect' field is the drawing canvas.
642 * @param startSearch either null or an instance of ClickableCoord for which isSnapToNearestCoord() returns true.
643 * If it is not null, the next matching point *after* it will be returned (or null if there is no matching snap--to--nearest coord after it).
644 * @return an instance of ClickableCoord or null in case the startSearch!=null and there are no further matches.
645 */
646 findClickableCoord : function( x,y, canvas, startSearch )
647 {
648 // Get and modify bounding box. The mouse movement is only accurate up to one point
649 // (mouseX and mouseY are integers), so the bounding box should be an integer as well.
650 var rect = canvas.rect; // rect = [ mincanvasx mincanvasy maxcanvasx maxcanvasy ]; relative to upper left corner
651 rect[0] = Math.round(rect[0]);
652 rect[1] = Math.round(rect[1]);
653 rect[2] = Math.round(rect[2]);
654 rect[3] = Math.round(rect[3]);
655 canvas.rect= rect;
656
657 var realx=-1;
658 var realy=-1;
659 if( this.dim == 2 ) {
660 // the following code inverts computeCanvasFor():
661 var minminminx = rect[0] + this.minminmin[0];
662 var minminminy = rect[3] + this.minminmin[1];
663 var vecx = x - minminminx;
664 var vecy = y - minminminy;
665 var A = [
666 [this.xaxis[0], this.yaxis[0]],
667 [this.xaxis[1], this.yaxis[1]] ];
668 var b = [ vecx, vecy ];
669
670 var rowpermut = [0, 1];
671 if( Math.abs(A[0][0]) < 0.0001 ) {
672 rowpermut[0] = 1;
673 rowpermut[1] = 0;
674 }
675 var pivot = -A[rowpermut[1]][0] / A[rowpermut[0]][0];
676 var unity = (b[rowpermut[1]] + pivot*b[rowpermut[0]]) / (A[rowpermut[1]][1] + pivot * A[rowpermut[0]][1]);
677 var unitx = (b[rowpermut[0]] - A[rowpermut[0]][1] * unity) / A[rowpermut[0]][0];
678
679 realx = this.xmin + unitx * (this.xmax - this.xmin);
680 realy = this.ymin + unity * (this.ymax - this.ymin);
681 //console.println( "unitx = " + unitx + "; unity " + unity );
682 }
683
684
685 var point = new ClickableCoord( x,y, realx, realy, clickablePatternForXY);
686 point.dim = this.dim;
687
688 if( startSearch && !startSearch.isSnapToNearestCoord() ) {
689 console.println( "WARNING: startSearch().isSnapToNearestCoord() has been expected!" );
690 startSearch = null;
691 }
692
693 var nearestClickableCoord = this.findNearest( point, rect, startSearch );
694 if( nearestClickableCoord ) {
695 if( getDist( point.canvasx,point.canvasy, nearestClickableCoord.canvasx, nearestClickableCoord.canvasy ) < this.snapDist ) {
696 return nearestClickableCoord;
697 }
698 }
699 if( startSearch )
700 point = null;
701 if( this.dim > 2 ) { // we didn't find a snap--to--nearest point.
702 point.text = clickableStringNoSuchCoord;
703 }
704
705 return point;
706 },
707
708 /**
709 * Takes point's real coordinates and computes its canvas coordinates. The result is written back into \c point.
710 */
711 computeCanvasFor : function( point, rect)
712 {
713 var unitx = (point.realx - this.xmin) / (this.xmax -this.xmin);
714 var unity = (point.realy - this.ymin) / (this.ymax -this.ymin);
715
716 point.canvasx = rect[0] + this.minminmin[0] + this.xaxis[0] * unitx + this.yaxis[0] * unity;
717 point.canvasy = rect[3] + this.minminmin[1] + this.xaxis[1] * unitx + this.yaxis[1] * unity;
718 if( this.dim >= 3 ) {
719 var unitz = (point.realz - this.zmin) / (this.zmax -this.zmin);
720 point.canvasx += this.zaxis[0] * unitz;
721 point.canvasy += this.zaxis[1] * unitz;
722 }
723 },
724
725 handleDragNDrop : function( formName, displayOpts )
726 {
727 if( this.dim == 3 )
728 return;
729
730 var result = this.docObject.getField( formName + "-result");
731 var result2 = this.docObject.getField( formName + "-result2");
732 var resultmark = this.docObject.getField( formName + "-resultmark");
733 var result2mark = this.docObject.getField( formName + "-result2mark");
734 var slope = this.docObject.getField( formName + "-slope" );
735 if( !result ) {
736 console.println( "WARNING: there is no TextField \"" + formName + "-result\" to display results for interactive element \"" + formName + "\"");
737 return;
738 }
739
740 var a = this.docObject.getField(formName);
741 if( ! a ) {
742 console.println( "Warning: there is no form named \"" + formName + "\"" );
743 return;
744 }
745 // dragging the mouse results in slope computation:
746 // placeClickableCoord shows the endpoint coords and returns the (transformed) coordinates into tmpArray1 and tmpArray2:
747 this.placeClickableCoord(
748 this.findClickableCoord( posOnMouseDownX, posOnMouseDownY, a, null ),
749 result, displayOpts, tmpArray1 );
750 this.placeClickableCoord(
751 this.findClickableCoord( mouseX, mouseY, a, null ),
752 result2, displayOpts, tmpArray2 );
753
754 var m = ( tmpArray2[1] - tmpArray1[1] ) / ( tmpArray2[0] - tmpArray1[0] );
755 var n = tmpArray1[1] - m * tmpArray1[0];
756
757 var slopePoint = new ClickableCoord(
758 0.5 * ( mouseX + posOnMouseDownX ),
759 0.5 * ( mouseY + posOnMouseDownY ),
760 -1,-1,
761 sprintf( displayOpts.slopeFormat, m, n ));
762 slopePoint.draw(
763 this.docObject,
764 slope,
765 displayOpts );
766
767 // FIXME! these document rights seem to forbid modifications to annotations, although they work for text fields!?
768 //var lineobj = this.getAnnot( a.page, formName + '-line' );
769 //console.println( 'lineobj = ' + lineobj );
770 //lineobj.points = [[mouseX,mouseY],[posOnMouseDownX,posOnMouseDownY]];
771 //lineobj.display = display.visible;
772 },
773
774 handleClick : function( formName, displayOpts )
775 {
776 var result = this.docObject.getField( formName + "-result");
777 var result2 = this.docObject.getField( formName + "-result2");
778 var resultmark = this.docObject.getField( formName + "-resultmark");
779 var result2mark = this.docObject.getField( formName + "-result2mark");
780 var slope = this.docObject.getField( formName + "-slope" );
781 if( !result ) {
782 console.println( "WARNING: there is no TextField \"" + formName + "-result\" to display results for interactive element \"" + formName + "\"");
783 return;
784 }
785 result2.display = display.hidden;
786 slope.display = display.hidden;
787 result2mark.display = display.hidden;
788
789 var a = this.docObject.getField(formName);
790 if( ! a ) {
791 console.println( "Warning: there is no form named \"" + formName + "\"" );
792 return;
793 }
794
795 var point = null;
796 var bSearchPoint = true;
797 if( lastPoint ) {
798 if( getDist( mouseX,mouseY, lastPoint.canvasx,lastPoint.canvasy) < this.snapDist ) {
799 if( lastPoint.isSnapToNearestCoord() )
800 ++lastPoint.sourceCoordIdx;
801 else
802 bSearchPoint = false;
803
804 } else
805 lastPoint = null; // no search restriction.
806 }
807 if( bSearchPoint )
808 point = this.findClickableCoord( mouseX, mouseY, a, lastPoint );
809
810 lastPoint = point;
811
812 // clicking twice onto the same point hides it:
813 if( point == null ) {
814 result.display = display.hidden;
815 resultmark.display = display.hidden;
816 return;
817 }
818
819 this.placeClickableCoord(
820 point,
821 result, displayOpts, null );
822 },
823
824 /**
825 * Changes all required Field values of \c plotRegionField, inserts the proper
826 * value and displays it at the pdf positions (x,y) .
827 *
828 * @param plotRegionField a reference to a Field object.
829 * @param x the x canvas coordinate where the annotation shall be placed and which is used to determine
830 * the annotation text.
831 * @param y the corresponding y coord.
832 * @param axis An object containing axis references.
833 * @param displayOpts An object for display flags.
834 * @param[out] retCoords will be filled with the point in axis coordinates (should have length axis.dim).
835 */
836 placeClickableCoord : function( point, textField, displayOpts, retCoords )
837 {
838 var transformedCoordx = point.realx;
839 var transformedCoordy = point.realy;
840
841 if( this.xscale.length >= 3 && this.xscale.substr(0,3) == "log" ) {
842 if( this.xscale.length > 4 ) // log:<basis>
843 point.realx = point.realx * Math.log( this.xscale.substr(4) );
844 else {
845 // pgfplots handles log plots base e INTERNALLY, but uses base 10 for display.
846 // convert to base 10:
847 transformedCoordx = point.realx / Math.log(10);
848 }
849 point.realx = Math.exp(point.realx);
850 }
851 if( this.yscale.length >= 3 && this.yscale.substr(0,3) == "log" ) {
852 if( this.yscale.length > 4 ) // log:<basis>
853 point.realy = point.realy * Math.log( this.yscale.substr(4) );
854 else {
855 // pgfplots handles log plots base e INTERNALLY, but uses base 10 for display.
856 // convert to base 10:
857 transformedCoordy = point.realy / Math.log(10);
858 }
859 point.realy = Math.exp(point.realy);
860 }
861 if( this.dim > 2 ) {
862 if( this.zscale.length >= 3 && this.zscale.substr(0,3) == "log" ) {
863 if( this.zscale.length > 4 ) // log:<basis>
864 point.realz = point.realz * Math.log( this.zscale.substr(4) );
865 else {
866 // pgfplots handles log plots base e INTERNALLY, but uses base 10 for display.
867 // convert to base 10:
868 transformedCoordz = point.realz / Math.log(10);
869 }
870 point.realz = Math.exp(point.realz);
871 }
872 }
873
874 // replace the text substring "(xy)" with the actual coordinates:
875 var coordOff = point.text.indexOf(clickablePatternForXY);
876 if( coordOff >= 0 ) {
877 point.text =
878 point.text.substring( 0, coordOff ) +
879 sprintf( displayOpts.pointFormat, point.realx,point.realy,point.realz) +
880 point.text.substr( coordOff+clickablePatternForXY.length );
881 }
882 point.draw( this.docObject, textField, displayOpts );
883
884 if( retCoords ) {
885 retCoords[0] = transformedCoordx;
886 retCoords[1] = transformedCoordy;
887 if( this.dim > 2 )
888 retCoords[2] = transformedCoordz;
889 }
890
891 }
892
893 }
894
895 function PGFPlotsTernaryAxis(properties) {
896 PGFPlotsAxis.call(this,properties);
897 }
898 PGFPlotsTernaryAxis.prototype = {
899 findClickableCoord : function( x,y, canvas, startSearch )
900 {
901 // Get and modify bounding box. The mouse movement is only accurate up to one point
902 // (mouseX and mouseY are integers), so the bounding box should be an integer as well.
903 var rect = canvas.rect; // rect = [ mincanvasx mincanvasy maxcanvasx maxcanvasy ]; relative to lower left corner
904 rect[0] = Math.round(rect[0]);
905 rect[1] = Math.round(rect[1]);
906 rect[2] = Math.round(rect[2]);
907 rect[3] = Math.round(rect[3]);
908 canvas.rect= rect;
909
910 var ternaryScale = 1 / ( rect[2] - rect[0] );
911 var X = ( x - rect[0] ) * ternaryScale;
912 var Y = ( y - rect[3] ) * ternaryScale;
913
914 var realx = 1.15470053837925 * Y; // 2/sqrt(3)
915 var realz = X - 0.5 * realx;
916 var realy = 1 - realx - realz;
917
918 if( realx < 0 \pgfplotsVERTBAR\pgfplotsVERTBAR realy < 0 \pgfplotsVERTBAR\pgfplotsVERTBAR realz < 0 )
919 return null;
920
921 var point = new ClickableCoord( x,y, realx, realy, clickablePatternForXY);
922 point.realz = realz;
923 point.dim = this.dim;
924
925 if( startSearch && !startSearch.isSnapToNearestCoord() ) {
926 console.println( "WARNING: startSearch().isSnapToNearestCoord() has been expected!" );
927 startSearch = null;
928 }
929
930 var nearestClickableCoord = this.findNearest( point, rect, startSearch );
931 if( nearestClickableCoord ) {
932 if( getDist( point.canvasx,point.canvasy, nearestClickableCoord.canvasx, nearestClickableCoord.canvasy ) < this.snapDist ) {
933 return nearestClickableCoord;
934 }
935 }
936 if( startSearch )
937 point = null;
938
939 return point;
940 },
941
942 /**
943 * Takes point's real coordinates and computes its canvas coordinates. The result is written back into \c point.
944 */
945 computeCanvasFor : function( point, rect)
946 {
947 var unitx = (point.realx - this.xmin) / (this.xmax -this.xmin);
948 var unity = (point.realy - this.ymin) / (this.ymax -this.ymin);
949 var unitz = (point.realz - this.zmin) / (this.zmax -this.zmin);
950
951 var ternaryScale = ( rect[2] - rect[0] );
952 point.canvasx = rect[0] + ternaryScale* 0.5 * (unitx + 2 * unitz);
953 point.canvasy = rect[3] + ternaryScale* 0.866025403784* unitx; // sqrt(3)/2
954 },
955 }
956 PGFPlotsClassExtend( PGFPlotsTernaryAxis, PGFPlotsAxis );
957
958
959
960 function getVecLen( t1,t2 ) {
961 return Math.sqrt( t1*t1 + t2*t2);
962 }
963 function getDist( x1,y1, x2,y2 ) {
964 var t1 = (x1-x2);
965 var t2 = (y1-y2);
966 return getVecLen(t1,t2);
967 }
968
969 function axisMouseDown(formName )
970 {
971 posOnMouseDownX = mouseX;
972 posOnMouseDownY = mouseY;
973 }
974
975 /**
976 * @param formName the name of the clickable button. It is expected to be as large as the underlying plot.
977 * @param axis an object with the fields
978 * - xmin, xmax
979 * - ymin, ymax
980 * - xscale, yscale
981 * @param displayOpts an object with the fields
982 * - pointFormat an sprintf format string to format the final point coordinates.
983 * The default is "(\pgfplotsPERCENT.2f,\pgfplotsPERCENT.2f)"
984 * - fillColor the fill color for the annotation. Options are
985 * transparent, gray, RGB or CMYK color. Default is
986 * ["RGB",1,1,.855]
987 * - textFont / textSize
988 */
989 function axisMouseUp(formName, axisAnnotObj, displayOpts)
990 {
991 var axis = PGFPlotsCreateAxisFor(axisAnnotObj,this);
992 if( axis == null )
993 return;
994
995 if( Math.abs( mouseX - posOnMouseDownX ) > 6 \pgfplotsVERTBAR\pgfplotsVERTBAR
996 Math.abs( mouseY - posOnMouseDownY ) > 6 )
997 {
998 axis.handleDragNDrop( formName, displayOpts );
999
1000 } else {
1001 axis.handleClick( formName, displayOpts );
1002 }
1003 }
1004
1005
1006 \end{insDLJS}
1007 %--------------------------------------------------
1008 % function hideClickableTextfields() {
1009 % for (var i = 0; i < this.numFields; i++) {
1010 % var fieldName = this.getNthFieldName(i);
1011 % console.println("checking Field " + fieldName + " ... ");
1012 % if( fieldName.substr( 0, 13 ) == "clickableplot" && fieldName.indexOf( "-result", 12 ) >= 0 ) {
1013 % console.println("hiding Field " + fieldName + " ... ");
1014 % this.getField( fieldName ).display = display.hidden;
1015 % }
1016 % }
1017 % }
1018 % hideClickableTextfields();
1019 %--------------------------------------------------
1020
1021
1022 \pgfkeysdef{/pgfplots/annot/xy pattern}{\pgfplots@clickable@xypat@error}%
1023 \pgfkeysdef{/pgfplots/annot/xy pattern/.initial}{\pgfplots@clickable@xypat@error}%
1024 \def\pgfplots@clickable@xypat@error{\pgfplots@error{Sorry, \string\pgfplotsset{annot/xy pattern/.initial=...} can only be assigned *before* \string\usepgfplotslibrary{clickable}}}%
1025
1026 \pgfkeysdef{/pgfplots/annot/no such coord}{\pgfplots@clickable@nosuchcoord@error}%
1027 \pgfkeysdef{/pgfplots/annot/no such coord/.initial}{\pgfplots@clickable@nosuchcoord@error}%
1028 \def\pgfplots@clickable@nosuchcoord@error{\pgfplots@error{Sorry, \string\pgfplotsset{annot/no such coord/.initial=...} can only be assigned *before* \string\usepgfplotslibrary{clickable}}}%
1029
1030 \def\pgfplots@clickable@beginaxis{%
1031 \pgfplotsapplistXglobalnewempty\pgfplots@clickable@collectedplots
1032 \gdef\pgfplots@clickable@collectedplots@isempty{1}%
1033 }%
1034
1035 \def\pgfplots@clickable@startcoordcollect{%
1036 \pgfplotsapplistXnewempty\pgfplots@clickable@collectedplot
1037 \def\pgfplots@clickable@collectedplot@isempty{1}%
1038 }%
1039
1040 {\catcode`\|=0 |catcode`|\=12 |gdef|pgfplots@clickable@bslash{\}}%
1041 {
1042 \catcode`\"=13
1043 \catcode`\|=13
1044 \catcode`\#=12
1045 \gdef\pgfplots@clickable@coordcollect@handlechars{%
1046 \def"{\string\\\string\"}%
1047 \def\#{#}%
1048 \expandafter\def\csname \string"\endcsname{\string\\\string\"}%
1049 \def|{\string"}%
1050 \def\n{\pgfplots@clickable@bslash\string\n}%
1051 \def\r{\pgfplots@clickable@bslash\string\r}%
1052 \def\t{\pgfplots@clickable@bslash\string\t}%
1053 \def\\{\pgfplots@clickable@bslash\pgfplots@clickable@bslash}%
1054 }%
1055 }
1056 \def\pgfplots@clickable@coordcollect#1{%
1057 \begingroup
1058 \ifx\pgfplots@current@point@x\pgfutil@empty
1059 \def\pgfmathresult{nan}%
1060 \else
1061 \pgfplotscoordmath{x}{tostring}\pgfplots@current@point@x
1062 \fi
1063 \let\pgfplots@current@point@x=\pgfmathresult
1064 %
1065 \ifx\pgfplots@current@point@y\pgfutil@empty
1066 \def\pgfmathresult{nan}%
1067 \else
1068 \pgfplotscoordmath{y}{tostring}\pgfplots@current@point@y
1069 \fi
1070 \let\pgfplots@current@point@y=\pgfmathresult
1071 %
1072 \ifpgfplots@curplot@threedim
1073 \ifx\pgfplots@current@point@z\pgfutil@empty
1074 \def\pgfmathresult{nan}%
1075 \else
1076 \pgfplotscoordmath{z}{tostring}\pgfplots@current@point@z
1077 \fi
1078 \let\pgfplots@current@point@z=\pgfmathresult
1079 \fi
1080 %
1081 \begingroup
1082 \pgfplots@clickable@coordcollect@handlechars
1083 #1%
1084 \xdef\pgfplots@glob@TMPa{\pgfplotsretval}%
1085 %\message{I have '\pgfplotsretval'}%
1086 \endgroup
1087 \xdef\pgfplots@glob@TMPa{\if1\pgfplots@clickable@collectedplot@isempty\else,\fi[\pgfplots@current@point@x,\pgfplots@current@point@y\ifpgfplots@curplot@threedim,\pgfplots@current@point@z\fi,"\pgfplots@glob@TMPa"]}%
1088 \endgroup
1089 \expandafter\pgfplotsapplistXpushback\expandafter{\pgfplots@glob@TMPa}\to\pgfplots@clickable@collectedplot
1090 \def\pgfplots@clickable@collectedplot@isempty{0}%
1091 }%
1092 \def\pgfplots@clickable@endcoordcollect{%
1093 \pgfplotsapplistXlet\pgfplots@clickable@collectedplot@=\pgfplots@clickable@collectedplot
1094 \if1\pgfplots@clickable@collectedplots@isempty
1095 \expandafter\pgfplotsapplistXglobalpushback\expandafter{\expandafter[\pgfplots@clickable@collectedplot@]}\to\pgfplots@clickable@collectedplots
1096 \else
1097 \expandafter\pgfplotsapplistXglobalpushback\expandafter{\expandafter,\expandafter[\pgfplots@clickable@collectedplot@]}\to\pgfplots@clickable@collectedplots
1098 \fi
1099 \gdef\pgfplots@clickable@collectedplots@isempty{0}%
1100 }%
1101
1102 % Creates an area which is clickable. A click produces a popup which
1103 % contains information about the point under the cursor.
1104 %
1105 % The complete (!) context needs to be provided using key-value-pairs,
1106 % either in '#1' or set before invocation of \pgfplotsclickablecreate.
1107 %
1108 % This command actually creates an AcroForm which employs javascript
1109 % whenever it is clicked. A javascript Object is created which
1110 % represents the context (axis limits and options). This javascript
1111 % object is available at runtime.
1112 %
1113 % @remark This method is public and it is NOT restricted to pgfplots.
1114 % The pgfplots hook simply initialises the required key-value-pairs in
1115 % '#1'.
1116 % @remark This method does not draw anything. It initialises only a
1117 % clickable area and javascript code.
1118 %
1119 % The required key-value-pairs are documented in the pdf-manual or can
1120 % be seen above.
1121 %
1122 % @attention Complete key-value validation is NOT performed here. It
1123 % can happen that invalid options will produce javascript bugs when
1124 % opened with Acrobat Reader. Use the javascript console to find them.
1125 \def\pgfplotsclickablecreate[#1]{%
1126 \def\pgfplots@loc@TMPa{#1}%
1127 \ifx\pgfplots@loc@TMPa\pgfutil@empty
1128 \else
1129 \pgfqkeys{/pgfplots/annot}{#1}%
1130 \fi
1131 \pgfkeysgetvalue{/pgfplots/annot/jsname}\pgfplots@clickable@uniquename
1132 \ifx\pgfplots@clickable@uniquename\pgfutil@empty
1133 \edef\pgfplots@clickable@uniquename{clickableplot\pgfplots@clickable@no}%
1134 \begingroup
1135 \c@pgf@counta=\pgfplots@clickable@no\relax
1136 \advance\c@pgf@counta by1
1137 \xdef\pgfplots@clickable@no{\the\c@pgf@counta}%
1138 \endgroup
1139 \fi
1140 %
1141 \pgfkeysgetvalue{/pgfplots/annot/collected plots}\pgfplots@clickable@collectedplots@@
1142 \ifx\pgfplots@clickable@collectedplots@@\pgfutil@empty
1143 \def\pgfplots@clickable@collectedplots@@{[]}%
1144 \fi
1145 %
1146 \edef\pgfplots@clickable@expanded@args{%
1147 {\pgfkeysvalueof{/pgfplots/annot/width}}%
1148 {\pgfkeysvalueof{/pgfplots/annot/height}}%
1149 {\pgfplots@clickable@uniquename}%
1150 {{
1151 axisType: "\pgfkeysvalueof{/pgfplots/axis type}",
1152 dim: \pgfkeysvalueof{/pgfplots/annot/dim},
1153 xmin: \pgfkeysvalueof{/pgfplots/annot/xmin},
1154 xmax: \pgfkeysvalueof{/pgfplots/annot/xmax},
1155 ymin: \pgfkeysvalueof{/pgfplots/annot/ymin},
1156 ymax: \pgfkeysvalueof{/pgfplots/annot/ymax},
1157 xscale: "\pgfkeysvalueof{/pgfplots/annot/xscale}",
1158 yscale: "\pgfkeysvalueof{/pgfplots/annot/yscale}",
1159 \ifnum\pgfkeysvalueof{/pgfplots/annot/dim}=3
1160 zmin: \pgfkeysvalueof{/pgfplots/annot/zmin},
1161 zmax: \pgfkeysvalueof{/pgfplots/annot/zmax},
1162 zscale: "\pgfkeysvalueof{/pgfplots/annot/zscale}",
1163 zaxis: \pgfkeysvalueof{/pgfplots/annot/z axis},
1164 \fi
1165 collectedPlots: \pgfplots@clickable@collectedplots@@,
1166 snapDist: \pgfkeysvalueof{/pgfplots/annot/snap dist},
1167 minminmin: \pgfkeysvalueof{/pgfplots/annot/minminmin},
1168 xaxis: \pgfkeysvalueof{/pgfplots/annot/x axis},
1169 yaxis: \pgfkeysvalueof{/pgfplots/annot/y axis}
1170 }}%
1171 {{
1172 pointFormat: "\ifnum\pgfkeysvalueof{/pgfplots/annot/dim}=3 \pgfkeysvalueof{/pgfplots/annot/point format 3d}\else \pgfkeysvalueof{/pgfplots/annot/point format}\fi",
1173 slopeFormat: "\pgfkeysvalueof{/pgfplots/annot/slope format}",
1174 fillColor:\pgfkeysvalueof{/pgfplots/annot/js fillColor},
1175 textFont:\pgfkeysvalueof{/pgfplots/annot/font},
1176 textSize:\pgfkeysvalueof{/pgfplots/annot/textSize},
1177 richText:\pgfkeysvalueof{/pgfplots/annot/richtext},
1178 popupSizeGeneric:"\pgfkeysvalueof{/pgfplots/annot/popup size generic}",
1179 popupSizeSnap:"\pgfkeysvalueof{/pgfplots/annot/popup size snap}",
1180 printable: \ifpgfplots@annot@printable true\else false\fi
1181 }}%
1182 }%
1183 \expandafter\pgfplots@create@clickable@plotarea\pgfplots@clickable@expanded@args
1184 }%
1185
1186 % Defines either \def\pgfplotsretval{1} if the current axis is
1187 % clickable or \def\pgfplotsretval{0} if not.
1188 %
1189 % The initial configuration is `1' for any 2d axis, `1' for 3d axes
1190 % with 'clickable coords' and `0' for 3d axes without `clickable
1191 % coords'.
1192 %
1193 % Overwrite \pgfplotsclickable@check@enable@axistype@<theaxistype> to
1194 % make axis type specific things.
1195 \def\pgfplotsclickable@check@enable{%
1196 \def\pgfplotsretval{1}%
1197 \ifpgfplots@threedim
1198 \ifx\pgfplots@clickable@collectedplots@@\pgfutil@empty
1199 \def\pgfplotsretval{0}%
1200 \fi
1201 \fi
1202 \csname pgfplotsclickable@check@enable@axistype@\pgfkeysvalueof{/pgfplots/axis type}\endcsname
1203 }%
1204
1205 % This thing is invoked from within pgfplots. It prepares and invokes
1206 % \pgfplotsclickablecreate.
1207 %
1208 \def\pgfplots@create@clickable@plotarea@hook{%
1209 \ifpgfplots@clickable
1210 \begingroup
1211 % communicate collected plot coordinates:
1212 \pgfplotsapplistXgloballet\pgfplots@clickable@collectedplots@@=\pgfplots@clickable@collectedplots
1213 \pgfplotsapplistXglobalnewempty\pgfplots@clickable@collectedplots
1214 \t@pgfplots@tokc=\expandafter{\pgfplots@clickable@collectedplots@@}%
1215 \edef\pgfplots@clickable@collectedplots@@{[\the\t@pgfplots@tokc]}%
1216 \pgfkeyslet{/pgfplots/annot/collected plots}\pgfplots@clickable@collectedplots@@
1217 %
1218 \pgfplotsclickable@check@enable
1219 \if1\pgfplotsretval
1220 %
1221 \pgfplotscoordmath{x}{datascaletrafo inverse}{\pgfplots@xmin}%
1222 \pgfplotscoordmath{x}{tostring}{\pgfmathresult}%
1223 \let\pgfplots@clickable@xmin=\pgfmathresult
1224 \pgfplotscoordmath{x}{datascaletrafo inverse}{\pgfplots@xmax}%
1225 \pgfplotscoordmath{x}{tostring}{\pgfmathresult}%
1226 \let\pgfplots@clickable@xmax=\pgfmathresult
1227 %
1228 \pgfplotscoordmath{y}{datascaletrafo inverse}{\pgfplots@ymin}%
1229 \pgfplotscoordmath{y}{tostring}{\pgfmathresult}%
1230 \let\pgfplots@clickable@ymin=\pgfmathresult
1231 \pgfplotscoordmath{y}{datascaletrafo inverse}{\pgfplots@ymax}%
1232 \pgfplotscoordmath{y}{tostring}{\pgfmathresult}%
1233 \let\pgfplots@clickable@ymax=\pgfmathresult
1234 %
1235 \ifpgfplots@threedim
1236 \pgfplotscoordmath{z}{datascaletrafo inverse}{\pgfplots@zmin}%
1237 \pgfplotscoordmath{z}{tostring}{\pgfmathresult}%
1238 \let\pgfplots@clickable@zmin=\pgfmathresult
1239 \pgfplotscoordmath{z}{datascaletrafo inverse}{\pgfplots@zmax}%
1240 \pgfplotscoordmath{z}{tostring}{\pgfmathresult}%
1241 \let\pgfplots@clickable@zmax=\pgfmathresult
1242 \fi
1243 %
1244 % Convert to user interface of clickable lib:
1245 \pgfplotspointbbdiagonal
1246 \edef\pgfplots@clickable@wd{\the\pgf@x}%
1247 \pgfkeyslet{/pgfplots/annot/width}\pgfplots@clickable@wd
1248 \edef\pgfplots@clickable@ht{\the\pgf@y}%
1249 \pgfkeyslet{/pgfplots/annot/height}\pgfplots@clickable@ht
1250 \pgfkeyslet{/pgfplots/annot/xmin}\pgfplots@clickable@xmin
1251 \pgfkeyslet{/pgfplots/annot/xmax}\pgfplots@clickable@xmax
1252 \pgfkeyslet{/pgfplots/annot/ymin}\pgfplots@clickable@ymin
1253 \pgfkeyslet{/pgfplots/annot/ymax}\pgfplots@clickable@ymax
1254 \ifpgfplots@xislinear
1255 \pgfkeyssetvalue{/pgfplots/annot/xscale}{linear}%
1256 \else
1257 \pgfkeyssetvalue{/pgfplots/annot/xscale}{log:\pgfkeysvalueof{/pgfplots/log basis x}}%
1258 \fi
1259 \ifpgfplots@yislinear
1260 \pgfkeyssetvalue{/pgfplots/annot/yscale}{linear}%
1261 \else
1262 \pgfkeyssetvalue{/pgfplots/annot/yscale}{log:\pgfkeysvalueof{/pgfplots/log basis y}}%
1263 \fi
1264 \ifpgfplots@threedim
1265 \pgfkeyslet{/pgfplots/annot/zmin}\pgfplots@clickable@zmin
1266 \pgfkeyslet{/pgfplots/annot/zmax}\pgfplots@clickable@zmax
1267 \ifpgfplots@zislinear
1268 \pgfkeyssetvalue{/pgfplots/annot/zscale}{linear}%
1269 \else
1270 \pgfkeyssetvalue{/pgfplots/annot/zscale}{log:\pgfkeysvalueof{/pgfplots/log basis z}}%
1271 \fi
1272 \fi
1273 %
1274 % note that \pgfplotspointbblowerleft has *not* been
1275 % transformed after \endtikzpicture in pgfplots.code.tex.
1276 % That's why I can use it here:
1277 \pgfpointdiff
1278 \pgfplotspointbblowerleft
1279 {\pgfplotspointminminmin}%
1280 \pgf@sys@bp@correct\pgf@x \pgf@sys@bp@correct\pgf@y
1281 \edef\pgfplots@loc@TMPa{[\pgf@sys@tonumber\pgf@x, \pgf@sys@tonumber\pgf@y]}%
1282 \pgfkeyslet{/pgfplots/annot/minminmin}\pgfplots@loc@TMPa
1283 %
1284 \pgfplotspointxaxis
1285 \pgf@sys@bp@correct\pgf@x \pgf@sys@bp@correct\pgf@y
1286 \edef\pgfplots@loc@TMPa{[\pgf@sys@tonumber\pgf@x, \pgf@sys@tonumber\pgf@y]}%
1287 \pgfkeyslet{/pgfplots/annot/x axis}\pgfplots@loc@TMPa
1288 %
1289 \pgfplotspointyaxis
1290 \pgf@sys@bp@correct\pgf@x \pgf@sys@bp@correct\pgf@y
1291 \edef\pgfplots@loc@TMPa{[\pgf@sys@tonumber\pgf@x, \pgf@sys@tonumber\pgf@y]}%
1292 \pgfkeyslet{/pgfplots/annot/y axis}\pgfplots@loc@TMPa
1293 %
1294 \ifpgfplots@threedim
1295 \pgfplotspointzaxis
1296 \pgf@sys@bp@correct\pgf@x \pgf@sys@bp@correct\pgf@y
1297 \edef\pgfplots@loc@TMPa{[\pgf@sys@tonumber\pgf@x, \pgf@sys@tonumber\pgf@y]}%
1298 \pgfkeyslet{/pgfplots/annot/z axis}\pgfplots@loc@TMPa
1299 \fi
1300 %
1301 \pgfkeyssetvalue{/pgfplots/annot/dim}{\ifpgfplots@threedim 3\else2\fi}%
1302 %
1303 %
1304 \pgfinterruptboundingbox%
1305 \pgftext[left,bottom,at=\lowerleftinnercorner]{\pgfplotsclickablecreate[]}%
1306 \endpgfinterruptboundingbox%
1307 \fi
1308 \endgroup
1309 \fi
1310 }
1311
1312 % This is the low-level method which creates Acroforms and Javascript
1313 % code.
1314 % #1: width
1315 % #2: height
1316 % #3: name
1317 % #4: the axisAnnotObj object (see javascript docs above)
1318 % #5: the displayOpts object (see javascript docs above)
1319 \def\pgfplots@create@clickable@plotarea#1#2#3#4#5{%
1320 %\tracingmacros=2\tracingcommands=2
1321 %\leavevmode
1322 %--------------------------------------------------
1323 % hyperref.sty implementation:
1324 %--------------------------------------------------
1325 % \PushButton[name=#3,borderwidth=0,bordersep=0,
1326 % onclick={processAnnotatedPlot("#3", #4, #5);}]{\vbox to #2{\hsize=#1\vfill\hfill}}%
1327 % \TextField[name=#3-result,hidden=true]{}%
1328 %--------------------------------------------------
1329 %
1330 %--------------------------------------------------
1331 % eforms.sty implementation:
1332 % it allows more customization.
1333 %--------------------------------------------------
1334 %
1335 % Hier kommen Annotation Directories zum Zuge!
1336 % -> siehe Annotations in pdf reference
1337 \def\pushButtonDefaults{
1338 \W{0}% border width
1339 \Border{0 0 0}%
1340 }%
1341 \def\textFieldDefaults{%
1342 \W{1}% border width
1343 \S{B}% border style ( one of SDBIU )
1344 \F{2}% "display" bitflag. 2^1= hidden (see "Annotation Flags" in pdf reference)
1345 %ATTENTION: \F 2 (hidden) produces INCOMPATIBILITIES with figure environment!?
1346 % ---> ok, that has been fixed by recent versions of hyperref.
1347 % (the pdf catalog may be incomplete in older hyperref pdftex drivers)
1348 \Ff{1}% "Field characteristics" bitflag. 2^0 = "read-only"
1349 }%
1350 \pushButton[
1351 %\A{/S/JavaScript/JS(processAnnotatedPlot("#3", #4, #5);)}%
1352 \AA{
1353 % /U = "mouse UP"
1354 % /D = "mouse DOWN"
1355 /U << /S/JavaScript/JS(axisMouseUp("#3", #4, #5);) >>
1356 /D << /S/JavaScript/JS(axisMouseDown("#3");) >>
1357 }%
1358 ]
1359 {#3}
1360 {#1}{#2}%
1361 \textField{#3-result}{0pt}{0pt}%
1362 \textField{#3-result2}{0pt}{0pt}%
1363 \textField{#3-resultmark}{0pt}{0pt}%
1364 \textField{#3-result2mark}{0pt}{0pt}%
1365 \textField{#3-slope}{0pt}{0pt}%
1366 % Unfortunately, line annotations can't be created/changed in acrobat
1367 % javascript due to right problems :-(
1368 %--------------------------------------------------
1369 % \hbox to 0pt{\vsize=0pt \pdfannot{
1370 % /Subtype /Line
1371 % /Open /false
1372 % /NM (#3-line)
1373 % /C
1374 % /CA
1375 % /Subj ()
1376 % /Contents ()
1377 % /L [0 0 0 0]
1378 % /LE [/None /OpenArrow] % PDF 1.4
1379 % % /Ff 194
1380 % }}%
1381 %--------------------------------------------------
1382 %
1383 %
1384 %\setLinkBbox[%
1385 % \Border{}%
1386 % \A{/S/JavaScript/JS(processme("#3");)}%
1387 % \rawPDF{/C[1 0 0] /NM (#3)}%
1388 % ]%
1389 % {#1}{#2}{}%
1390 }
1391
1392 \catcode`\"=\pgfplotscatcodeDQ
1393 \endinput