FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gnuplot-old/term/js/gnuplot_mouse.js at gnuplot-4-4-alpha · gnuplot/gnuplot-old · GitHub
gnuplot
gnuplot-old
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
gnuplot-old
/
term
/
js
/
gnuplot_mouse.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
389 lines (345 loc) · 11.4 KB
Breadcrumbs
gnuplot-old
/
term
/
js
/
gnuplot_mouse.js
Copy path
File metadata and controls
389 lines (345 loc) · 11.4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
/*
* $Id: gnuplot_mouse.js,v 1.7 2009/05/30 17:55:42 sfeam Exp $
*/
// Mousing code for use with gnuplot's 'canvas' terminal driver.
// The functions defined here assume that the javascript plot produced by
// gnuplot initializes the plot boundary and scaling parameters.
var
mousex
=
0
;
var
mousey
=
0
;
var
plotx
=
0
;
var
ploty
=
0
;
var
scaled_x
=
0
;
var
scaled_y
=
0
;
// These will be initialized by the gnuplot canvas-drawing function
var
plot_xmin
=
0
;
var
plot_xmax
=
0
;
var
plot_ybot
=
0
;
var
plot_ytop
=
0
;
var
plot_width
=
0
var
plot_height
=
0
var
plot_term_ymax
=
0
;
var
plot_axis_xmin
=
0
;
var
plot_axis_xmax
=
0
;
var
plot_axis_width
=
0
;
var
plot_axis_height
=
0
;
var
plot_axis_ymin
=
0
;
var
plot_axis_ymax
=
0
;
var
plot_axis_x2min
=
"none"
;
var
plot_axis_y2min
=
"none"
;
var
plot_logaxis_x
=
0
;
var
plot_logaxis_y
=
0
;
var
grid_lines
=
true
;
var
zoom_text
=
false
;
// These are the equivalent parameters while zooming
var
zoom_axis_xmin
=
0
;
var
zoom_axis_xmax
=
0
;
var
zoom_axis_ymin
=
0
;
var
zoom_axis_ymax
=
0
;
var
zoom_axis_x2min
=
0
;
var
zoom_axis_x2max
=
0
;
var
zoom_axis_y2min
=
0
;
var
zoom_axis_y2max
=
0
;
var
zoom_axis_width
=
0
;
var
zoom_axis_height
=
0
;
var
zoom_temp_xmin
=
0
;
var
zoom_temp_ymin
=
0
;
var
zoom_temp_x2min
=
0
;
var
zoom_temp_y2min
=
0
;
var
zoom_in_progress
=
false
;
function
gnuplot_init
(
)
{
if
(
document
.
getElementById
(
"gnuplot_canvas"
)
)
document
.
getElementById
(
"gnuplot_canvas"
)
.
onmousemove
=
mouse_update
;
if
(
document
.
getElementById
(
"gnuplot_canvas"
)
)
document
.
getElementById
(
"gnuplot_canvas"
)
.
onmouseup
=
zoom_in
;
if
(
document
.
getElementById
(
"gnuplot_canvas"
)
)
document
.
getElementById
(
"gnuplot_canvas"
)
.
onmousedown
=
saveclick
;
if
(
document
.
getElementById
(
"gnuplot_canvas"
)
)
document
.
getElementById
(
"gnuplot_canvas"
)
.
onkeypress
=
do_hotkey
;
if
(
document
.
getElementById
(
"gnuplot_grid_icon"
)
)
document
.
getElementById
(
"gnuplot_grid_icon"
)
.
onmouseup
=
toggle_grid
;
if
(
document
.
getElementById
(
"gnuplot_textzoom_icon"
)
)
document
.
getElementById
(
"gnuplot_textzoom_icon"
)
.
onmouseup
=
toggle_zoom_text
;
if
(
document
.
getElementById
(
"gnuplot_rezoom_icon"
)
)
document
.
getElementById
(
"gnuplot_rezoom_icon"
)
.
onmouseup
=
rezoom
;
if
(
document
.
getElementById
(
"gnuplot_unzoom_icon"
)
)
document
.
getElementById
(
"gnuplot_unzoom_icon"
)
.
onmouseup
=
unzoom
;
mouse_update
(
)
;
}
function
getMouseCoordsWithinTarget
(
event
)
{
var
coords
=
{
x
:
0
,
y
:
0
}
;
if
(
!
event
)
// then we're in a non-DOM (probably IE) browser
{
event
=
window
.
event
;
if
(
event
)
{
coords
.
x
=
event
.
offsetX
;
coords
.
y
=
event
.
offsetY
;
}
}
else
// we assume DOM modeled javascript
{
var
Element
=
event
.
target
;
var
CalculatedTotalOffsetLeft
=
0
;
var
CalculatedTotalOffsetTop
=
0
;
while
(
Element
.
offsetParent
)
{
CalculatedTotalOffsetLeft
+=
Element
.
offsetLeft
;
CalculatedTotalOffsetTop
+=
Element
.
offsetTop
;
Element
=
Element
.
offsetParent
;
}
coords
.
x
=
event
.
pageX
-
CalculatedTotalOffsetLeft
;
coords
.
y
=
event
.
pageY
-
CalculatedTotalOffsetTop
;
}
mousex
=
coords
.
x
;
mousey
=
coords
.
y
;
}
function
mouse_update
(
e
)
{
getMouseCoordsWithinTarget
(
e
)
;
plotx
=
mousex
-
plot_xmin
;
ploty
=
-
(
mousey
-
plot_ybot
)
;
// Limit tracking to the interior of the plot
if
(
plotx
<
0
||
ploty
<
0
)
return
;
if
(
mousex
>
plot_xmax
||
mousey
<
plot_ytop
)
return
;
var
axis_xmin
=
(
zoomed
)
?
zoom_axis_xmin
:
plot_axis_xmin
;
var
axis_xmax
=
(
zoomed
)
?
zoom_axis_xmax
:
plot_axis_xmax
;
var
axis_ymin
=
(
zoomed
)
?
zoom_axis_ymin
:
plot_axis_ymin
;
var
axis_ymax
=
(
zoomed
)
?
zoom_axis_ymax
:
plot_axis_ymax
;
if
(
plot_logaxis_x
!=
0
)
{
x
=
Math
.
log
(
axis_xmax
)
-
Math
.
log
(
axis_xmin
)
;
x
=
x
*
(
plotx
/
(
plot_xmax
-
plot_xmin
)
)
+
Math
.
log
(
axis_xmin
)
;
x
=
Math
.
exp
(
x
)
;
}
else
{
x
=
axis_xmin
+
(
plotx
/
(
plot_xmax
-
plot_xmin
)
)
*
(
axis_xmax
-
axis_xmin
)
;
}
if
(
plot_logaxis_y
!=
0
)
{
y
=
Math
.
log
(
axis_ymax
)
-
Math
.
log
(
axis_ymin
)
;
y
=
y
*
(
-
ploty
/
(
plot_ytop
-
plot_ybot
)
)
+
Math
.
log
(
axis_ymin
)
;
y
=
Math
.
exp
(
y
)
;
}
else
{
y
=
axis_ymin
-
(
ploty
/
(
plot_ytop
-
plot_ybot
)
)
*
(
axis_ymax
-
axis_ymin
)
;
}
if
(
plot_axis_x2min
!=
"none"
)
{
axis_x2min
=
(
zoomed
)
?
zoom_axis_x2min
:
plot_axis_x2min
;
axis_x2max
=
(
zoomed
)
?
zoom_axis_x2max
:
plot_axis_x2max
;
x2
=
axis_x2min
+
(
plotx
/
(
plot_xmax
-
plot_xmin
)
)
*
(
axis_x2max
-
axis_x2min
)
;
if
(
document
.
getElementById
(
active_plot_name
+
"_x2"
)
)
document
.
getElementById
(
active_plot_name
+
"_x2"
)
.
innerHTML
=
x2
.
toPrecision
(
4
)
;
}
if
(
plot_axis_y2min
!=
"none"
)
{
axis_y2min
=
(
zoomed
)
?
zoom_axis_y2min
:
plot_axis_y2min
;
axis_y2max
=
(
zoomed
)
?
zoom_axis_y2max
:
plot_axis_y2max
;
y2
=
axis_y2min
-
(
ploty
/
(
plot_ytop
-
plot_ybot
)
)
*
(
axis_y2max
-
axis_y2min
)
;
if
(
document
.
getElementById
(
active_plot_name
+
"_y2"
)
)
document
.
getElementById
(
active_plot_name
+
"_y2"
)
.
innerHTML
=
y2
.
toPrecision
(
4
)
;
}
if
(
document
.
getElementById
(
active_plot_name
+
"_x"
)
)
document
.
getElementById
(
active_plot_name
+
"_x"
)
.
innerHTML
=
x
.
toPrecision
(
4
)
;
if
(
document
.
getElementById
(
active_plot_name
+
"_y"
)
)
document
.
getElementById
(
active_plot_name
+
"_y"
)
.
innerHTML
=
y
.
toPrecision
(
4
)
;
// Echo the zoom box interactively
if
(
zoom_in_progress
)
{
ctx
.
strokeStyle
=
"rgba(128,128,128,0.20)"
;
ctx
.
strokeRect
(
plot_xmin
+
zoom_temp_plotx
,
plot_ybot
-
zoom_temp_ploty
,
plotx
-
zoom_temp_plotx
,
-
(
ploty
-
zoom_temp_ploty
)
)
;
}
}
function
saveclick
(
event
)
{
mouse_update
(
event
)
;
// Limit tracking to the interior of the plot
if
(
plotx
<
0
||
ploty
<
0
)
return
;
if
(
mousex
>
plot_xmax
||
mousey
<
plot_ytop
)
return
;
if
(
event
.
which
==
null
)
/* IE case */
button
=
(
event
.
button
<
2
)
?
"LEFT"
:
(
(
event
.
button
==
4
)
?
"MIDDLE"
:
"RIGHT"
)
;
else
/* All others */
button
=
(
event
.
which
<
2
)
?
"LEFT"
:
(
(
event
.
which
==
2
)
?
"MIDDLE"
:
"RIGHT"
)
;
if
(
button
==
"LEFT"
)
{
ctx
.
strokeStyle
=
"black"
;
ctx
.
strokeRect
(
mousex
,
mousey
,
1
,
1
)
;
click
=
" "
+
x
.
toPrecision
(
4
)
+
", "
+
y
.
toPrecision
(
4
)
;
ctx
.
drawText
(
"sans"
,
9
,
mousex
,
mousey
,
click
)
;
}
// Save starting corner of zoom box
else
{
zoom_temp_xmin
=
x
;
zoom_temp_ymin
=
y
;
if
(
plot_axis_x2min
!=
"none"
)
zoom_temp_x2min
=
x2
;
if
(
plot_axis_y2min
!=
"none"
)
zoom_temp_y2min
=
y2
;
// Only used to echo the zoom box interactively
zoom_temp_plotx
=
plotx
;
zoom_temp_ploty
=
ploty
;
zoom_in_progress
=
true
;
}
return
false
;
// Nobody else should respond to this event
}
function
zoom_in
(
event
)
{
if
(
!
zoom_in_progress
)
return
false
;
mouse_update
(
event
)
;
if
(
event
.
which
==
null
)
/* IE case */
button
=
(
event
.
button
<
2
)
?
"LEFT"
:
(
(
event
.
button
==
4
)
?
"MIDDLE"
:
"RIGHT"
)
;
else
/* All others */
button
=
(
event
.
which
<
2
)
?
"LEFT"
:
(
(
event
.
which
==
2
)
?
"MIDDLE"
:
"RIGHT"
)
;
// Save ending corner of zoom box
if
(
button
!=
"LEFT"
)
{
if
(
x
>
zoom_temp_xmin
)
{
zoom_axis_xmin
=
zoom_temp_xmin
;
zoom_axis_xmax
=
x
;
if
(
plot_axis_x2min
!=
"none"
)
{
zoom_axis_x2min
=
zoom_temp_x2min
;
zoom_axis_x2max
=
x2
;
}
}
else
{
zoom_axis_xmin
=
x
;
zoom_axis_xmax
=
zoom_temp_xmin
;
if
(
plot_axis_x2min
!=
"none"
)
{
zoom_axis_x2min
=
x2
;
zoom_axis_x2max
=
zoom_temp_x2min
;
}
}
if
(
y
>
zoom_temp_ymin
)
{
zoom_axis_ymin
=
zoom_temp_ymin
;
zoom_axis_ymax
=
y
;
if
(
plot_axis_y2min
!=
"none"
)
{
zoom_axis_y2min
=
zoom_temp_y2min
;
zoom_axis_y2max
=
y2
;
}
}
else
{
zoom_axis_ymin
=
y
;
zoom_axis_ymax
=
zoom_temp_ymin
;
if
(
plot_axis_y2min
!=
"none"
)
{
zoom_axis_y2min
=
y2
;
zoom_axis_y2max
=
zoom_temp_y2min
;
}
}
zoom_axis_width
=
zoom_axis_xmax
-
zoom_axis_xmin
;
zoom_axis_height
=
zoom_axis_ymax
-
zoom_axis_ymin
;
zoom_in_progress
=
false
;
rezoom
(
event
)
;
}
return
false
;
// Nobody else should respond to this event
}
function
toggle_grid
(
e
)
{
if
(
!
grid_lines
)
grid_lines
=
true
;
else
grid_lines
=
false
;
ctx
.
clearRect
(
0
,
0
,
plot_term_xmax
,
plot_term_ymax
)
;
gnuplot_canvas
(
)
;
}
function
toggle_zoom_text
(
e
)
{
if
(
!
zoom_text
)
zoom_text
=
true
;
else
zoom_text
=
false
;
ctx
.
clearRect
(
0
,
0
,
plot_term_xmax
,
plot_term_ymax
)
;
gnuplot_canvas
(
)
;
}
function
rezoom
(
e
)
{
if
(
zoom_axis_width
>
0
)
zoomed
=
true
;
ctx
.
clearRect
(
0
,
0
,
plot_term_xmax
,
plot_term_ymax
)
;
gnuplot_canvas
(
)
;
}
function
unzoom
(
e
)
{
zoomed
=
false
;
ctx
.
clearRect
(
0
,
0
,
plot_term_xmax
,
plot_term_ymax
)
;
gnuplot_canvas
(
)
;
}
function
zoomXY
(
x
,
y
)
{
zoom
=
new
Object
;
var
xreal
,
yreal
;
zoom
.
x
=
x
;
zoom
.
y
=
y
;
zoom
.
clip
=
false
;
if
(
plot_logaxis_x
!=
0
)
{
xreal
=
Math
.
log
(
plot_axis_xmax
)
-
Math
.
log
(
plot_axis_xmin
)
;
xreal
=
Math
.
log
(
plot_axis_xmin
)
+
(
x
-
plot_xmin
)
*
xreal
/
plot_width
;
zoom
.
x
=
Math
.
log
(
zoom_axis_xmax
)
-
Math
.
log
(
zoom_axis_xmin
)
;
zoom
.
x
=
plot_xmin
+
(
xreal
-
Math
.
log
(
zoom_axis_xmin
)
)
*
plot_width
/
zoom
.
x
;
}
else
{
xreal
=
plot_axis_xmin
+
(
x
-
plot_xmin
)
*
(
plot_axis_width
/
plot_width
)
;
zoom
.
x
=
plot_xmin
+
(
xreal
-
zoom_axis_xmin
)
*
(
plot_width
/
zoom_axis_width
)
;
}
if
(
plot_logaxis_y
!=
0
)
{
yreal
=
Math
.
log
(
plot_axis_ymax
)
-
Math
.
log
(
plot_axis_ymin
)
;
yreal
=
Math
.
log
(
plot_axis_ymin
)
+
(
plot_ybot
-
y
)
*
yreal
/
plot_height
;
zoom
.
y
=
Math
.
log
(
zoom_axis_ymax
)
-
Math
.
log
(
zoom_axis_ymin
)
;
zoom
.
y
=
plot_ybot
-
(
yreal
-
Math
.
log
(
zoom_axis_ymin
)
)
*
plot_height
/
zoom
.
y
;
}
else
{
yreal
=
plot_axis_ymin
+
(
plot_ybot
-
y
)
*
(
plot_axis_height
/
plot_height
)
;
zoom
.
y
=
plot_ybot
-
(
yreal
-
zoom_axis_ymin
)
*
(
plot_height
/
zoom_axis_height
)
;
}
// Limit the zoomed plot to the original plot area
if
(
x
>
plot_xmax
)
{
zoom
.
x
=
x
;
if
(
plot_axis_y2min
==
"none"
)
{
zoom
.
y
=
y
;
return
zoom
;
}
if
(
plot_ybot
<=
y
&&
y
<=
plot_ybot
+
15
)
zoom
.
clip
=
true
;
}
else
if
(
x
<
plot_xmin
)
zoom
.
x
=
x
;
else
if
(
zoom
.
x
<
plot_xmin
)
{
zoom
.
x
=
plot_xmin
;
zoom
.
clip
=
true
;
}
else
if
(
zoom
.
x
>
plot_xmax
)
{
zoom
.
x
=
plot_xmax
;
zoom
.
clip
=
true
;
}
if
(
y
<
plot_ytop
)
{
zoom
.
y
=
y
;
if
(
plot_axis_x2min
==
"none"
)
{
zoom
.
x
=
x
;
zoom
.
clip
=
false
;
return
zoom
;
}
}
else
if
(
y
>
plot_ybot
)
zoom
.
y
=
y
;
else
if
(
zoom
.
y
>
plot_ybot
)
{
zoom
.
y
=
plot_ybot
;
zoom
.
clip
=
true
;
}
else
if
(
zoom
.
y
<
plot_ytop
)
{
zoom
.
y
=
plot_ytop
;
zoom
.
clip
=
true
;
}
return
zoom
;
}
function
zoomW
(
w
)
{
return
(
w
*
plot_axis_width
/
zoom_axis_width
)
;
}
function
zoomH
(
h
)
{
return
(
h
*
plot_axis_height
/
zoom_axis_height
)
;
}
function
do_hotkey
(
event
)
{
keychar
=
String
.
fromCharCode
(
event
.
charCode
?
event
.
charCode
:
event
.
keyCode
)
;
switch
(
keychar
)
{
case
'e'
:
ctx
.
clearRect
(
0
,
0
,
plot_term_xmax
,
plot_term_ymax
)
;
gnuplot_canvas
(
)
;
break
;
case
'g'
:
toggle_grid
(
)
;
break
;
case
'n'
:
rezoom
(
)
;
break
;
case
'r'
:
ctx
.
lineWidth
=
0.5
;
ctx
.
strokeStyle
=
"rgba(128,128,128,0.50)"
;
ctx
.
moveTo
(
plot_xmin
,
mousey
)
;
ctx
.
lineTo
(
plot_xmax
,
mousey
)
;
ctx
.
moveTo
(
mousex
,
plot_ybot
)
;
ctx
.
lineTo
(
mousex
,
plot_ytop
)
;
ctx
.
stroke
(
)
;
break
;
case
'p'
:
case
'u'
:
unzoom
(
)
;
break
;
case
''
:
zoom_in_progress
=
false
;
break
;
// Arrow keys
case
'%'
:
// ctx.drawText("sans", 10, mousex, mousey, "<");
break
;
case
'\''
:
// ctx.drawText("sans", 10, mousex, mousey, ">");
break
;
case
'&'
:
// ctx.drawText("sans", 10, mousex, mousey, "^");
break
;
case
'('
:
// ctx.drawText("sans", 10, mousex, mousey, "v");
break
;
default
:
// ctx.drawText("sans", 10, mousex, mousey, keychar);
return
true
;
// Let someone else handle it
break
;
}
return
false
;
// Nobody else should respond to this keypress
}
Back
|
FazBrowse Home
|
New Git URL