4
;; Create a top-level window containing a canvas displaying a simple
5
;; graph with data points that can be moved interactively.
8
;; w - Name to use for new top-level window.
10
(defun mkPlot ( &optional (w '.plot ) &aux c font x y item)
13
(wm :title w "Plot Demonstration " : w)
14
(wm :iconname w "Plot")
17
(message (conc w '.msg) :font :Adobe-Times-Medium-R-Normal-*-180-* :width 400
18
:bd 2 :relief "raised" :text "This window displays a canvas widget containing a simple 2-dimensional plot. You can doctor the data by dragging any of the points with mouse button 1.")
19
(canvas c :relief "raised" :width 450 :height 300)
20
(button (conc w '.ok) :text "OK" :command "destroy " : w)
21
(pack (conc w '.msg) (conc w '.c) :side "top" :fill "x")
22
(pack (conc w '.ok) :side "bottom" :pady 5)
24
(setq font :Adobe-helvetica-medium-r-*-180-*)
26
(funcall c :create "line" 100 250 400 250 :width 2)
27
(funcall c :create "line" 100 250 100 50 :width 2)
28
(funcall c :create "text" 225 20 :text "A Simple Plot" :font font :fill "brown")
31
(setq x (+ 100 (* i 30)))
32
(funcall c :create "line" x 250 x 245 :width 2)
33
(funcall c :create "text" x 254 :text (* 10 i) :anchor "n" :font font))
36
(setq y (- 250 (* i 40)))
37
(funcall c :create "line" 100 y 105 y :width 2)
38
(funcall c :create "text" 96 y :text (* i 50) : ".0" :anchor "e" :font font))
40
(sloop for point in '((12 56) (20 94) (33 98) (32 120) (61 180)
43
(setq x (+ 100 (* 3 (nth 0 point))))
44
(setq y (- 250 (truncate (* 4 (nth 1 point)) 5)))
45
(setq item (funcall c :create "oval" (- x 6) (- y 6)
46
(+ x 6) (+ y 6) :width 1 :outline "black"
47
:fill "SkyBlue2" :return 'string ))
48
(funcall c :addtag "point" "withtag" item)
52
(funcall c :bind "point" "<Any-Enter>" c : " itemconfig current -fill red")
53
(funcall c :bind "point" "<Any-Leave>" c : " itemconfig current -fill SkyBlue2")
54
(funcall c :bind "point" "<1>" `(plotdown ',c |%x| |%y|))
55
(funcall c :bind "point" "<ButtonRelease-1>" c : " dtag selected")
56
(bind c "<B1-Motion>" `(plotmove ',c |%x| |%y|))
62
(defun plotDown (w x y)
63
(funcall w :dtag "selected")
64
(funcall w :addtag "selected" "withtag" "current")
65
(funcall w :raise "current")
70
(defun plotMove (w x y &aux )
71
(let ((oldx plotlastX)
73
;; Note plotmove may be called recursively... since
74
;; the funcall may call something which calls this.
75
;; so we must set the global plotlastx before the funcall..
78
(funcall w :move "selected" (- x oldx) (- y oldy))