Skip to content

Commit 6476468

Browse files
committed
[webgui] adjust tutorials to newest JSROOT
1 parent 4fbde62 commit 6476468

File tree

3 files changed

+36
-32
lines changed

3 files changed

+36
-32
lines changed

tutorials/webgui/panel/controller/TestPanel.controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ sap.ui.define([
2424
}
2525

2626
if (msg.indexOf("MODEL:")==0) {
27-
var data = JSROOT.parse(msg.substr(6));
27+
var data = JSON.parse(msg.substr(6));
2828
if (data)
2929
this.getView().setModel(new JSONModel(data));
3030
} else {

tutorials/webgui/ping/ping.html

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@
33
<head>
44
<meta charset="utf-8">
55
<title>RWebWindow latency test</title>
6-
<script src="jsrootsys/scripts/JSRoot.core.js" type="text/javascript"></script>
76
</head>
87

98
<body>
10-
<button onclick="SendMsg('halt')">Halt</button>
11-
<button onclick="ToggleDrawing()">Draw</button>
9+
<button id="halt_btn">Halt</button>
10+
<button id="toggle_btn">Draw</button>
1211
<p>Main: <b id="output">Msg</b></p>
1312
<div id="clients"></div>
1413
<div id="draw" style="position: absolute; left: 0px; right: 0px; bottom: 0px; height: 50%; overflow:hidden"></div>
1514
</body>
1615

17-
<script>
16+
<script type="module">
17+
18+
import { connectWebWindow } from '/jsrootsys/modules/webwindow.mjs';
19+
20+
import { redraw, cleanup } from '/jsrootsys/modules/draw.mjs';
21+
22+
import { createHistogram } from '/jsrootsys/modules/core.mjs';
1823

1924
class PingPongHandler {
2025
constructor(is_main, out_id) {
@@ -83,7 +88,7 @@
8388
}
8489

8590
if (this.is_main && this.hist)
86-
JSROOT.redraw("draw", this.hist);
91+
redraw("draw", this.hist);
8792

8893
}, msec);
8994
}
@@ -157,15 +162,15 @@
157162
for (let n = 0; n < nclients; ++n) {
158163
let sub_handler = new PingPongHandler(false, "out" + n);
159164
sub_handler.cnt = 10000*(n+1);
160-
JSROOT.connectWebWindow( { receiver: sub_handler, socket_kind: this.handle.kind } );
165+
connectWebWindow( { receiver: sub_handler, socket_kind: this.handle.kind } );
161166
this.clients.push(sub_handler);
162167
}
163168
}
164169

165170
createHistogram() {
166171
let mean = this.sum[0] > 10 ? this.sum[1] / this.sum[0] : 50;
167172

168-
this.hist = JSROOT.createHistogram("TH1I", 100);
173+
this.hist = createHistogram("TH1I", 100);
169174
this.hist.fTitle = "Roundtrip time";
170175
this.hist.fXaxis.fTitle = "ms";
171176
this.hist.fXaxis.fXmax = 100;
@@ -183,29 +188,30 @@
183188

184189
let main_handler = new PingPongHandler(true);
185190

186-
function SendMsg(txt) {
191+
document.getElementById('halt_btn').onclick = () => {
187192
if (main_handler && main_handler.handle)
188-
main_handler.handle.send(txt);
189-
}
193+
main_handler.handle.send('halt');
194+
};
195+
196+
document.getElementById('toggle_btn').onclick = () => {
190197

191-
function ToggleDrawing() {
192198
let draw = document.getElementById("draw");
193199
if (!draw) return;
194200

195201
if (main_handler.hist) {
196-
JSROOT.cleanup(draw);
202+
cleanup(draw);
197203
main_handler.clearHistogram();
198204
draw.style.display = "none";
199205
return;
200206
}
201207

202208
main_handler.createHistogram();
203209
draw.style.display = "";
204-
}
210+
};
205211

206212
// important this line, which need to be specially handled
207213
// line MUST always end with "({" symbols
208-
JSROOT.connectWebWindow({
214+
connectWebWindow({
209215
receiver: main_handler
210216
});
211217

tutorials/webgui/webwindow/client.html

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,51 @@
33
<head>
44
<meta charset="utf-8">
55
<title>RWebWindow test</title>
6-
<script src="jsrootsys/scripts/JSRoot.core.js" type="text/javascript"></script>
76
</head>
87

98
<body>
10-
<button onclick="SendMsg('get_text')">Text</button>
11-
<button onclick="SendMsg('get_binary')">Binary</button>
12-
<button onclick="SendMsg('halt')">Halt</button>
9+
<button onclick="sendMsg('get_text')">Text</button>
10+
<button onclick="sendMsg('get_binary')">Binary</button>
11+
<button onclick="sendMsg('halt')">Halt</button>
1312
<div id="main"></div>
1413
</body>
1514

16-
<script>
15+
<script type="module">
16+
17+
import { connectWebWindow } from '/jsrootsys/modules/webwindow.mjs';
1718

1819
let conn_handle = null;
1920

20-
function SendMsg(txt) {
21+
globalThis.sendMsg = txt => {
2122
if (conn_handle)
2223
conn_handle.send(txt);
2324
}
2425

25-
function AddOutput(msg) {
26+
function addOutput(msg) {
2627
document.getElementById("main").innerHTML += msg + "<br>";
2728
}
2829

29-
JSROOT.connectWebWindow({
30-
// prereq: "2d", /* one could specify different JSROOT components like 2d or geom
31-
// prereq_logdiv: "main", /* div id where loading of JSROOT scripts will be logged */
32-
// callback: function(handle) { AddOutput("init done"); }, /* if necessary, initial callback can be cacthed */
30+
connectWebWindow({
3331
receiver: {
3432
// method called when connection to server is established
35-
onWebsocketOpened: function(handle) {
33+
onWebsocketOpened(handle) {
3634
handle.send("Init msg from client");
3735
conn_handle = handle;
38-
AddOutput("Connected");
36+
addOutput("Connected");
3937
},
4038

4139
// method with new message from server
42-
onWebsocketMsg: function(handle, msg, offset) {
40+
onWebsocketMsg(handle, msg, offset) {
4341
if (typeof msg != "string") {
4442
let arr = new Float32Array(msg, offset);
45-
AddOutput("bin: " + arr.toString());
43+
addOutput("bin: " + arr.toString());
4644
} else {
47-
AddOutput("txt: " + msg);
45+
addOutput("txt: " + msg);
4846
}
4947
},
5048

5149
// method called when connection is gone
52-
onWebsocketClosed: function(handle) {
50+
onWebsocketClosed(handle) {
5351
conn_handle = null;
5452
// when connection closed, close panel as well
5553
if (window) window.close();

0 commit comments

Comments
 (0)