Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:cleanup: remove noise code Remove <resizeable-object-mixin> and present*, use formatting-item-list when applicable.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256: 5217336ae95bb2a78038a6cf7fcd47c85a2ece66d3ec7d45469a9497a333b357
User & Date: jack 2025-04-06 18:51:24
Context
2025-04-06
19:18
cosmetic changes check-in: 48a84e0c47 user: jack tags: master, trunk
18:51
cleanup: remove noise code check-in: 5217336ae9 user: jack tags: master, trunk
2024-09-19
11:01
modify the dataset protocol check-in: 18500c968b user: jack tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Code/clim-mixins.lisp.

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
;;; This file contains CLIM implementation of various utilities and mixins
;;; that may be used for interactive plots and other things.

(in-package #:eu.turtleware.polyclot.implementation)

(c:define-command-table polyclot)
(define-class <polyclot-view> (c:view) ())

;;; Why do we maintain tl/bl handler presentations? This is because the object
;;; may be moved on the screen (for instance by a formatting parent) - to
;;; effectively resize the object we need to compute the distance between the tl
;;; handler and the pointer position.
(define-class <resizeable-object-mixin> (c:standard-bounding-rectangle)
  (tl-presentation bl-presentation))

(c:define-presentation-type handler ())
(c:define-presentation-type tl-handler () :inherit-from 'handler)
(c:define-presentation-type br-handler () :inherit-from 'handler)

(c:define-presentation-method c:present ((object <resizeable-object-mixin>)
                                         (type <resizeable-object-mixin>)
                                         stream
                                         (view <polyclot-view>)
                                         &rest args)
  (declare (ignore type args))
  (c:with-bounding-rectangle* (x1 y1 x2 y2) object
    (c:draw-rectangle* stream x1 y1 x2 y2 :ink c:+light-pink+ :filled t)))

(c:define-presentation-method c:present :after ((object <resizeable-object-mixin>)
                                                (type <resizeable-object-mixin>)
                                                stream
                                                (view <polyclot-view>)
                                                &rest args)
  (declare (ignore type args))
  (c:with-bounding-rectangle* (x1 y1 x2 y2) object
    (setf (tl-presentation object)
          (c:with-output-as-presentation (stream object 'tl-handler)
            (c:draw-rectangle* stream x1 y1 (+ x1 20) (+ y1 20))))
    (setf (bl-presentation object)
          (c:with-output-as-presentation (stream object 'br-handler)
            (c:draw-rectangle* stream x2 y2 (- x2 20) (- y2 20))))))

(c:define-presentation-method c:highlight-presentation
    ((type handler) record stream state)
  (ecase state
    (:highlight
     (c:draw-design stream (climi::copy-bounding-rectangle record) :ink c:+blue+))
    (:unhighlight
     (c:dispatch-repaint stream record))))

(c:define-command (com-reshape-object :command-table polyclot)
    ((o '<resizeable-object-mixin>)
     (b 'c:standard-bounding-rectangle))
  (setf (c:rectangle-edges* o) (c:bounding-rectangle* b)))

(c:define-drag-and-drop-translator trn-move-plot
    (tl-handler (c:command :command-table polyclot) c:blank-area polyclot)
    (object destination-object x y)
  (c:with-bounding-rectangle* (x1 y1) (tl-presentation object)
    (c:with-bounding-rectangle* (:width w :height h) object
      (let* ((x1 (- (clim:pointer-event-x destination-object) (- x x1)))
             (y1 (- (clim:pointer-event-y destination-object) (- y y1)))
             (x2 (+ x1 w))
             (y2 (+ y1 h))
             (box (c:make-bounding-rectangle x1 y1 x2 y2)))
        `(com-reshape-object ,object ,box)))))

(c:define-drag-and-drop-translator trn-resize-plot
    (br-handler (c:command :command-table polyclot) c:blank-area polyclot)
    (object destination-object x y)
  (c:with-bounding-rectangle* (x1 y1) (tl-presentation object)
    (c:with-bounding-rectangle* (:x2 x2 :y2 y2) (bl-presentation object)
      (let* ((x2 (- (clim:pointer-event-x destination-object) (- x x2)))
             (y2 (- (clim:pointer-event-y destination-object) (- y y2)))
             (box (c:make-bounding-rectangle x1 y1 x2 y2)))
        `(com-reshape-object ,object ,box)))))



;;; Color utilities.
(defvar *contrasts* (make-hash-table))
(defun contrasting-ink (n k)
  (assert (and (<= 0 k n) (<= 1 n)))
  (if (<= n 8)
      (c:make-contrasting-inks n k)
      (aref (ensure-gethash (n *contrasts*)
              (multiple-value-bind (i h s)
                  (climi::color-ihs (c:make-contrasting-inks 1 0))
                (loop with result = (make-array n)
                      with step = (/ n)
                      repeat n
                      for k from 0
                      for hue = h then (+ hue step)
                      do (setf (aref result k) (climi::make-ihs-color i hue s))
                      finally (return result))))
            k)))

#+ (or)
(progn
  (define-class <test-object> (<resizeable-object-mixin>) ())
  (c:define-presentation-method c:present ((object <test-object>)
                                           (type <test-object>)
                                           stream
                                           (view <polyclot-view>)
                                           &rest args)
    (declare (ignore type args))
    (c:with-bounding-rectangle* (:center-x cx :center-y cy :width w :height h) object
      (c:draw-ellipse* stream cx cy (/ w 2) 0 0 (/ h 2))))

  (c:define-application-frame test-frame ()
    ((record1 :initform (<test-object>
                         :x1 100 :y1 100
                         :x2 200 :y2 200)
              :reader record1)
     (record2 :initform (<test-object>
                         :x1 100 :y1 100
                         :x2 200 :y2 200)
              :reader record2))
    (:command-table (polyclot))
    (:panes (xxx :application
                 :default-view (<polyclot-view>)
                 :display-function
                 (lambda (frame *standard-output*)
                   (c:present (record1 frame))))
            (yyy :application
                 :default-view (<polyclot-view>)
                 :display-function
                 (lambda (frame *standard-output*)
                   (c:formatting-table ()
                     (c:formatting-row ()
                       (c:formatting-cell (t :align-x :center :align-y :center)
                         (c:draw-rectangle* t 0 0 100 100 :ink c:+red+))
                       (c:formatting-cell (t :align-x :center :align-y :center :min-width 100 :min-height 100)
                         (c:present (record2 frame)))))))))

  (c:find-application-frame 'test-frame))








<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

















<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
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








































;;; This file contains CLIM implementation of various utilities and mixins
;;; that may be used for interactive plots and other things.

(in-package #:eu.turtleware.polyclot.implementation)

(c:define-command-table polyclot)
(define-class <polyclot-view> (c:view) ())








































































;;; Color utilities.
(defvar *contrasts* (make-hash-table))
(defun contrasting-ink (n k)
  (assert (and (<= 0 k n) (<= 1 n)))
  (if (<= n 8)
      (c:make-contrasting-inks n k)
      (aref (ensure-gethash (n *contrasts*)
              (multiple-value-bind (i h s)
                  (climi::color-ihs (c:make-contrasting-inks 1 0))
                (loop with result = (make-array n)
                      with step = (/ n)
                      repeat n
                      for k from 0
                      for hue = h then (+ hue step)
                      do (setf (aref result k) (climi::make-ihs-color i hue s))
                      finally (return result))))
            k)))








































Changes to Code/theme.lisp.

1
2
3
4
5
6
7
8
9
10
(in-package #:eu.turtleware.polyclot.implementation)

(define-class <theme> (<resizeable-object-mixin>)
  (title width height)
  (:default-initargs
   :title "(untitled)"
   :width 400 :height 300))

;;; When we draw a plot of a certain size of the theme then we work with for
;;; the following objects:


|







1
2
3
4
5
6
7
8
9
10
(in-package #:eu.turtleware.polyclot.implementation)

(define-class <theme> (c:standard-bounding-rectangle)
  (title width height)
  (:default-initargs
   :title "(untitled)"
   :width 400 :height 300))

;;; When we draw a plot of a certain size of the theme then we work with for
;;; the following objects:
︙︙

Changes to Demo/cl-bench-results.lisp.

︙︙
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

43
44
          (loop with *read-eval* = nil
                for file in (directory (merge-pathnames "CL-benchmark*.*" output-dir))
                for form = (with-open-file (stream file :direction :input)
                             (read stream))
                append (process-result form)))))

(define-demo-plot *bench*
    (let ((dataset (read-data "~/Warsztat/Repo/cl-bench/output/")))
      (<polyclot> :title "Common Lisp Benchmark"
                  :width 400 :height 300
                  :dataset dataset
                  :aesthetics (list :x "Test" :y "Time" :ink "Lisp")
                  :layers (list (<geom-bar>
                                 :bin-width (/ 1 20)
                                 :statistical-transformation i::+stat-identity+
                                 :position-adjustment (i::<position-dodge>)))
                  :scales (list (make-scale :discrete :x)
                                (make-scale :continuous :y)
                                (make-scale :discrete :ink))))
  "Common Lisp Bencharks example plot")

;; (find-application-frame 'a-repl :width 800 :height 600)








|

|










>
|

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
          (loop with *read-eval* = nil
                for file in (directory (merge-pathnames "CL-benchmark*.*" output-dir))
                for form = (with-open-file (stream file :direction :input)
                             (read stream))
                append (process-result form)))))

(define-demo-plot *bench*
    (let ((dataset (read-data "~/Workshop/repo/cl-bench/output/")))
      (<polyclot> :title "Common Lisp Benchmark"
                  :width 1600 :height 600
                  :dataset dataset
                  :aesthetics (list :x "Test" :y "Time" :ink "Lisp")
                  :layers (list (<geom-bar>
                                 :bin-width (/ 1 20)
                                 :statistical-transformation i::+stat-identity+
                                 :position-adjustment (i::<position-dodge>)))
                  :scales (list (make-scale :discrete :x)
                                (make-scale :continuous :y)
                                (make-scale :discrete :ink))))
  "Common Lisp Bencharks example plot")

(find-application-frame 'a-repl :width 800 :height 600)

Changes to Demo/demo.lisp.

︙︙
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  (format *debug-io* "~a~%----------------------~%" val)
  )



(defgeneric display (frame stream)
  (:method (frame stream)
    (print frame stream)))

(defun present* (object stream &key (type (presentation-type-of object)))
  (present object type :stream stream))

(define-application-frame polyclot-demo-frame ()
  ((plots :initarg :plots :accessor plots)
   (active :initarg :active :accessor active))
  (:command-table (my-command-table :inherit-from (polyclot)))
  (:pane :application :display-function #'display
   :borders nil







|
<
<
<







87
88
89
90
91
92
93
94



95
96
97
98
99
100
101
  (format *debug-io* "~a~%----------------------~%" val)
  )



(defgeneric display (frame stream)
  (:method (frame stream)
    (clime:present* frame stream)))




(define-application-frame polyclot-demo-frame ()
  ((plots :initarg :plots :accessor plots)
   (active :initarg :active :accessor active))
  (:command-table (my-command-table :inherit-from (polyclot)))
  (:pane :application :display-function #'display
   :borders nil
︙︙
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
          (mapcar #'symbol-value (plots frame)))))

(define-polyclot-demo-frame-command (com-nop :menu t) ())

(c:define-gesture-name :show-dataset :pointer-button-press (:left :meta))

(defmethod display ((frame polyclot-demo-frame) *standard-output*)
  (format-items (mapcar 'symbol-value (plots frame)) :printer #'present*)
  (terpri)
  (let ((active (active frame)))
    (if (null active)
        (format t "(select a plot)")
        (progn;formatting-item-list (*standard-output* :row-wise t)
          (dolist (plot active)
            (progn;formatting-cell ()
              (polyclot plot *standard-output*)))))))

(defparameter *frame*
  (find-application-frame 'polyclot-demo-frame
                          :plots *demo-plots*))







|




|

|



|
<
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

          (mapcar #'symbol-value (plots frame)))))

(define-polyclot-demo-frame-command (com-nop :menu t) ())

(c:define-gesture-name :show-dataset :pointer-button-press (:left :meta))

(defmethod display ((frame polyclot-demo-frame) *standard-output*)
  (format-items (mapcar 'symbol-value (plots frame)) :printer #'clime:present*)
  (terpri)
  (let ((active (active frame)))
    (if (null active)
        (format t "(select a plot)")
        (formatting-item-list (*standard-output* :row-wise t)
          (dolist (plot active)
            (formatting-cell ()
              (polyclot plot *standard-output*)))))))

(defparameter *frame*
  (find-application-frame 'polyclot-demo-frame :plots *demo-plots*))