|
9 | 9 |
|
10 | 10 | <script src="../scripts/JSRootCore.js" type="text/javascript"></script> |
11 | 11 |
|
12 | | - <script type='text/javascript'> |
| 12 | +</head> |
| 13 | + |
| 14 | +<body> |
| 15 | + |
| 16 | + <div id="user_tooltip">Place for info</div> |
| 17 | + |
| 18 | + <form action=""> |
| 19 | + <input type="radio" name="kind" id="btn1" value="Tooltip"> Tooltip |
| 20 | + <input type="radio" name="kind" id="btn2" value="Click"> Click |
| 21 | + <input type="radio" name="kind" id="btn3" value="Dblclick"> Doubleclk |
| 22 | + </form> |
| 23 | + |
| 24 | + <div id="object_draw" style="width:800px; height:600px"></div> |
| 25 | + |
| 26 | + <div id="tooltip_draw" style="width:400px; height:300px"></div> |
| 27 | + |
| 28 | +<script type='text/javascript'> |
13 | 29 |
|
14 | | - var cnt = 0; |
| 30 | + var cnt = 0, kind = ""; |
| 31 | + |
| 32 | + function UserHandler(info) { |
| 33 | + if (!info) { |
| 34 | + d3.select("#user_tooltip").html("No tooltip"); |
| 35 | + return false; |
| 36 | + } |
| 37 | + |
| 38 | + // set tooltip info |
| 39 | + d3.select("#user_tooltip").html("name: " + info.name + " bin: " + info.bin + " cont: " + info.cont); |
| 40 | + |
| 41 | + var h1 = JSROOT.CreateTH1(20); |
| 42 | + // copy content from TH2 to TH1 |
| 43 | + for (var n=0;n<20;n++) |
| 44 | + h1.setBinContent(n+1, info.obj.getBinContent(n+1, info.biny)); |
| 45 | + h1.fName = "tooltip"; |
| 46 | + h1.fTitle = "Projection of biny=" + info.biny; |
| 47 | + JSROOT.redraw("tooltip_draw", h1); |
| 48 | + return true; // means event is handled and can be ignored |
| 49 | + } |
15 | 50 |
|
16 | 51 | function updateGUI() { |
17 | 52 | // if getting histogram from THttpServer as JSON string, one should parse it like: |
|
36 | 71 |
|
37 | 72 | JSROOT.redraw('object_draw', histo, "colz", function(painter) { |
38 | 73 | // in callback call painter object is returned |
39 | | - if ((cnt!==1) || !painter) return; |
40 | | - |
41 | | - painter.ConfigureUserTooltipCallback(function(info) { |
42 | | - |
43 | | - if (info==null) |
44 | | - return d3.select("#user_tooltip").html("No tooltip"); |
45 | | - |
46 | | - // set tooltip info |
47 | | - d3.select("#user_tooltip").html("object " + info.name + " bin " + info.bin + " cont " + info.cont); |
48 | | - |
49 | | - var h1 = JSROOT.CreateTH1(20); |
50 | | - // copy content from TH2 to TH1 |
51 | | - for (var n=0;n<20;n++) |
52 | | - h1.setBinContent(n+1, info.obj.getBinContent(n+1, info.biny)); |
53 | | - h1.fName = "tooltip"; |
54 | | - h1.fTitle = "Projection of biny=" + info.biny; |
55 | | - JSROOT.redraw("tooltip_draw", h1); |
56 | | - }); |
| 74 | + if (!painter) return; |
| 75 | + |
| 76 | + var chkd = document.getElementById("btn1").checked; |
| 77 | + |
| 78 | + painter.ConfigureUserTooltipCallback(chkd ? UserHandler : null); |
| 79 | + |
| 80 | + chkd = document.getElementById("btn2").checked; |
| 81 | + |
| 82 | + painter.ConfigureUserClickHandler(chkd ? UserHandler : null); |
| 83 | + |
| 84 | + chkd = document.getElementById("btn3").checked; |
| 85 | + |
| 86 | + painter.ConfigureUserDblclickHandler(chkd ? UserHandler : null); |
57 | 87 | }); |
58 | 88 | } |
59 | 89 |
|
|
64 | 94 |
|
65 | 95 | </script> |
66 | 96 |
|
67 | | - |
68 | | -</head> |
69 | | - |
70 | | -<body> |
71 | | - |
72 | | - <div id="user_tooltip">Place for tooltip</div> |
73 | | - |
74 | | - <div id="object_draw" style="width:800px; height:600px"></div> |
75 | | - |
76 | | - <div id="tooltip_draw" style="width:400px; height:300px"></div> |
77 | | - |
78 | 97 | </body> |
79 | 98 | </html> |
80 | 99 |
|
0 commit comments